1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *******************************************************************/
21 #include <linux/blkdev.h>
22 #include <linux/delay.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/idr.h>
25 #include <linux/interrupt.h>
26 #include <linux/kthread.h>
27 #include <linux/slab.h>
28 #include <linux/pci.h>
29 #include <linux/spinlock.h>
30 #include <linux/ctype.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
48 #include "lpfc_version.h"
49 #include "lpfc_compat.h"
50 #include "lpfc_debugfs.h"
52 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
56 * To access this interface the user should:
57 * # mount -t debugfs none /sys/kernel/debug
59 * The lpfc debugfs directory hierarchy is:
60 * /sys/kernel/debug/lpfc/fnX/vportY
61 * where X is the lpfc hba function unique_id
62 * where Y is the vport VPI on that hba
64 * Debugging services available per vport:
66 * This is an ACSII readable file that contains a trace of the last
67 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
68 * See lpfc_debugfs.h for different categories of discovery events.
69 * To enable the discovery trace, the following module parameters must be set:
70 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
71 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
72 * EACH vport. X MUST also be a power of 2.
73 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
77 * This is an ACSII readable file that contains a trace of the last
78 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
79 * To enable the slow ring trace, the following module parameters must be set:
80 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
81 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
82 * the HBA. X MUST also be a power of 2.
84 static int lpfc_debugfs_enable = 1;
85 module_param(lpfc_debugfs_enable, int, S_IRUGO);
86 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
88 /* This MUST be a power of 2 */
89 static int lpfc_debugfs_max_disc_trc;
90 module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
91 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
92 "Set debugfs discovery trace depth");
94 /* This MUST be a power of 2 */
95 static int lpfc_debugfs_max_slow_ring_trc;
96 module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
97 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
98 "Set debugfs slow ring trace depth");
100 static int lpfc_debugfs_mask_disc_trc;
101 module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
102 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
103 "Set debugfs discovery trace mask");
105 #include <linux/debugfs.h>
107 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
108 static unsigned long lpfc_debugfs_start_time = 0L;
111 static struct lpfc_idiag idiag;
114 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
115 * @vport: The vport to gather the log info from.
116 * @buf: The buffer to dump log into.
117 * @size: The maximum amount of data to process.
120 * This routine gathers the lpfc discovery debugfs data from the @vport and
121 * dumps it to @buf up to @size number of bytes. It will start at the next entry
122 * in the log and process the log until the end of the buffer. Then it will
123 * gather from the beginning of the log and process until the current entry.
126 * Discovery logging will be disabled while while this routine dumps the log.
129 * This routine returns the amount of bytes that were dumped into @buf and will
133 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
135 int i, index, len, enable;
137 struct lpfc_debugfs_trc *dtp;
138 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
140 enable = lpfc_debugfs_enable;
141 lpfc_debugfs_enable = 0;
144 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
145 (lpfc_debugfs_max_disc_trc - 1);
146 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
147 dtp = vport->disc_trc + i;
150 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
152 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
153 dtp->seq_cnt, ms, dtp->fmt);
154 len += snprintf(buf+len, size-len, buffer,
155 dtp->data1, dtp->data2, dtp->data3);
157 for (i = 0; i < index; i++) {
158 dtp = vport->disc_trc + i;
161 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
163 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
164 dtp->seq_cnt, ms, dtp->fmt);
165 len += snprintf(buf+len, size-len, buffer,
166 dtp->data1, dtp->data2, dtp->data3);
169 lpfc_debugfs_enable = enable;
174 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
175 * @phba: The HBA to gather the log info from.
176 * @buf: The buffer to dump log into.
177 * @size: The maximum amount of data to process.
180 * This routine gathers the lpfc slow ring debugfs data from the @phba and
181 * dumps it to @buf up to @size number of bytes. It will start at the next entry
182 * in the log and process the log until the end of the buffer. Then it will
183 * gather from the beginning of the log and process until the current entry.
186 * Slow ring logging will be disabled while while this routine dumps the log.
189 * This routine returns the amount of bytes that were dumped into @buf and will
193 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
195 int i, index, len, enable;
197 struct lpfc_debugfs_trc *dtp;
198 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
201 enable = lpfc_debugfs_enable;
202 lpfc_debugfs_enable = 0;
205 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
206 (lpfc_debugfs_max_slow_ring_trc - 1);
207 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
208 dtp = phba->slow_ring_trc + i;
211 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
213 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
214 dtp->seq_cnt, ms, dtp->fmt);
215 len += snprintf(buf+len, size-len, buffer,
216 dtp->data1, dtp->data2, dtp->data3);
218 for (i = 0; i < index; i++) {
219 dtp = phba->slow_ring_trc + i;
222 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
224 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
225 dtp->seq_cnt, ms, dtp->fmt);
226 len += snprintf(buf+len, size-len, buffer,
227 dtp->data1, dtp->data2, dtp->data3);
230 lpfc_debugfs_enable = enable;
234 static int lpfc_debugfs_last_hbq = -1;
237 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
238 * @phba: The HBA to gather host buffer info from.
239 * @buf: The buffer to dump log into.
240 * @size: The maximum amount of data to process.
243 * This routine dumps the host buffer queue info from the @phba to @buf up to
244 * @size number of bytes. A header that describes the current hbq state will be
245 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
246 * until @size bytes have been dumped or all the hbq info has been dumped.
249 * This routine will rotate through each configured HBQ each time called.
252 * This routine returns the amount of bytes that were dumped into @buf and will
256 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
259 int cnt, i, j, found, posted, low;
260 uint32_t phys, raw_index, getidx;
261 struct lpfc_hbq_init *hip;
263 struct lpfc_hbq_entry *hbqe;
264 struct lpfc_dmabuf *d_buf;
265 struct hbq_dmabuf *hbq_buf;
267 if (phba->sli_rev != 3)
269 cnt = LPFC_HBQINFO_SIZE;
270 spin_lock_irq(&phba->hbalock);
272 /* toggle between multiple hbqs, if any */
273 i = lpfc_sli_hbq_count();
275 lpfc_debugfs_last_hbq++;
276 if (lpfc_debugfs_last_hbq >= i)
277 lpfc_debugfs_last_hbq = 0;
280 lpfc_debugfs_last_hbq = 0;
282 i = lpfc_debugfs_last_hbq;
284 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
286 hbqs = &phba->hbqs[i];
288 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
291 hip = lpfc_hbq_defs[i];
292 len += snprintf(buf+len, size-len,
293 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
294 hip->hbq_index, hip->profile, hip->rn,
295 hip->buffer_count, hip->init_count, hip->add_count, posted);
297 raw_index = phba->hbq_get[i];
298 getidx = le32_to_cpu(raw_index);
299 len += snprintf(buf+len, size-len,
300 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
301 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
302 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
304 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
305 for (j=0; j<hbqs->entry_count; j++) {
306 len += snprintf(buf+len, size-len,
307 "%03d: %08x %04x %05x ", j,
308 le32_to_cpu(hbqe->bde.addrLow),
309 le32_to_cpu(hbqe->bde.tus.w),
310 le32_to_cpu(hbqe->buffer_tag));
314 /* First calculate if slot has an associated posted buffer */
315 low = hbqs->hbqPutIdx - posted;
317 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
318 len += snprintf(buf+len, size-len, "Unused\n");
323 if ((j >= hbqs->hbqPutIdx) &&
324 (j < (hbqs->entry_count+low))) {
325 len += snprintf(buf+len, size-len, "Unused\n");
330 /* Get the Buffer info for the posted buffer */
331 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
332 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
333 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
334 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
335 len += snprintf(buf+len, size-len,
336 "Buf%d: %p %06x\n", i,
337 hbq_buf->dbuf.virt, hbq_buf->tag);
344 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
348 if (len > LPFC_HBQINFO_SIZE - 54)
351 spin_unlock_irq(&phba->hbalock);
355 static int lpfc_debugfs_last_hba_slim_off;
358 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
359 * @phba: The HBA to gather SLIM info from.
360 * @buf: The buffer to dump log into.
361 * @size: The maximum amount of data to process.
364 * This routine dumps the current contents of HBA SLIM for the HBA associated
365 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
368 * This routine will only dump up to 1024 bytes of data each time called and
369 * should be called multiple times to dump the entire HBA SLIM.
372 * This routine returns the amount of bytes that were dumped into @buf and will
376 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
384 spin_lock_irq(&phba->hbalock);
386 len += snprintf(buf+len, size-len, "HBA SLIM\n");
387 lpfc_memcpy_from_slim(buffer,
388 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
390 ptr = (uint32_t *)&buffer[0];
391 off = lpfc_debugfs_last_hba_slim_off;
393 /* Set it up for the next time */
394 lpfc_debugfs_last_hba_slim_off += 1024;
395 if (lpfc_debugfs_last_hba_slim_off >= 4096)
396 lpfc_debugfs_last_hba_slim_off = 0;
400 len += snprintf(buf+len, size-len,
401 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
402 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
403 *(ptr+5), *(ptr+6), *(ptr+7));
405 i -= (8 * sizeof(uint32_t));
406 off += (8 * sizeof(uint32_t));
409 spin_unlock_irq(&phba->hbalock);
414 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
415 * @phba: The HBA to gather Host SLIM info from.
416 * @buf: The buffer to dump log into.
417 * @size: The maximum amount of data to process.
420 * This routine dumps the current contents of host SLIM for the host associated
421 * with @phba to @buf up to @size bytes of data. The dump will contain the
422 * Mailbox, PCB, Rings, and Registers that are located in host memory.
425 * This routine returns the amount of bytes that were dumped into @buf and will
429 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
433 uint32_t word0, word1, word2, word3;
435 struct lpfc_pgp *pgpp;
436 struct lpfc_sli *psli = &phba->sli;
437 struct lpfc_sli_ring *pring;
440 spin_lock_irq(&phba->hbalock);
442 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
443 ptr = (uint32_t *)phba->slim2p.virt;
444 i = sizeof(MAILBOX_t);
446 len += snprintf(buf+len, size-len,
447 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
448 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
449 *(ptr+5), *(ptr+6), *(ptr+7));
451 i -= (8 * sizeof(uint32_t));
452 off += (8 * sizeof(uint32_t));
455 len += snprintf(buf+len, size-len, "SLIM PCB\n");
456 ptr = (uint32_t *)phba->pcb;
459 len += snprintf(buf+len, size-len,
460 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
461 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
462 *(ptr+5), *(ptr+6), *(ptr+7));
464 i -= (8 * sizeof(uint32_t));
465 off += (8 * sizeof(uint32_t));
468 for (i = 0; i < 4; i++) {
469 pgpp = &phba->port_gp[i];
470 pring = &psli->ring[i];
471 len += snprintf(buf+len, size-len,
472 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
473 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
474 i, pgpp->cmdGetInx, pring->numCiocb,
475 pring->next_cmdidx, pring->local_getidx,
476 pring->flag, pgpp->rspPutInx, pring->numRiocb);
479 if (phba->sli_rev <= LPFC_SLI_REV3) {
480 word0 = readl(phba->HAregaddr);
481 word1 = readl(phba->CAregaddr);
482 word2 = readl(phba->HSregaddr);
483 word3 = readl(phba->HCregaddr);
484 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
485 "HC:%08x\n", word0, word1, word2, word3);
487 spin_unlock_irq(&phba->hbalock);
492 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
493 * @vport: The vport to gather target node info from.
494 * @buf: The buffer to dump log into.
495 * @size: The maximum amount of data to process.
498 * This routine dumps the current target node list associated with @vport to
499 * @buf up to @size bytes of data. Each node entry in the dump will contain a
500 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
503 * This routine returns the amount of bytes that were dumped into @buf and will
507 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
511 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
512 struct lpfc_nodelist *ndlp;
513 unsigned char *statep, *name;
515 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
517 spin_lock_irq(shost->host_lock);
518 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
520 len += snprintf(buf+len, size-len,
521 "Missing Nodelist Entries\n");
525 switch (ndlp->nlp_state) {
526 case NLP_STE_UNUSED_NODE:
529 case NLP_STE_PLOGI_ISSUE:
532 case NLP_STE_ADISC_ISSUE:
535 case NLP_STE_REG_LOGIN_ISSUE:
538 case NLP_STE_PRLI_ISSUE:
541 case NLP_STE_UNMAPPED_NODE:
544 case NLP_STE_MAPPED_NODE:
547 case NLP_STE_NPR_NODE:
553 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
554 statep, ndlp->nlp_DID);
555 name = (unsigned char *)&ndlp->nlp_portname;
556 len += snprintf(buf+len, size-len,
557 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
558 *name, *(name+1), *(name+2), *(name+3),
559 *(name+4), *(name+5), *(name+6), *(name+7));
560 name = (unsigned char *)&ndlp->nlp_nodename;
561 len += snprintf(buf+len, size-len,
562 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
563 *name, *(name+1), *(name+2), *(name+3),
564 *(name+4), *(name+5), *(name+6), *(name+7));
565 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
566 ndlp->nlp_rpi, ndlp->nlp_flag);
568 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
569 if (ndlp->nlp_type & NLP_FC_NODE)
570 len += snprintf(buf+len, size-len, "FC_NODE ");
571 if (ndlp->nlp_type & NLP_FABRIC)
572 len += snprintf(buf+len, size-len, "FABRIC ");
573 if (ndlp->nlp_type & NLP_FCP_TARGET)
574 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
576 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
577 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
578 len += snprintf(buf+len, size-len, "usgmap:%x ",
580 len += snprintf(buf+len, size-len, "refcnt:%x",
581 atomic_read(&ndlp->kref.refcount));
582 len += snprintf(buf+len, size-len, "\n");
584 spin_unlock_irq(shost->host_lock);
590 * lpfc_debugfs_disc_trc - Store discovery trace log
591 * @vport: The vport to associate this trace string with for retrieval.
592 * @mask: Log entry classification.
593 * @fmt: Format string to be displayed when dumping the log.
594 * @data1: 1st data parameter to be applied to @fmt.
595 * @data2: 2nd data parameter to be applied to @fmt.
596 * @data3: 3rd data parameter to be applied to @fmt.
599 * This routine is used by the driver code to add a debugfs log entry to the
600 * discovery trace buffer associated with @vport. Only entries with a @mask that
601 * match the current debugfs discovery mask will be saved. Entries that do not
602 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
603 * printf when displaying the log.
606 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
607 uint32_t data1, uint32_t data2, uint32_t data3)
609 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
610 struct lpfc_debugfs_trc *dtp;
613 if (!(lpfc_debugfs_mask_disc_trc & mask))
616 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
617 !vport || !vport->disc_trc)
620 index = atomic_inc_return(&vport->disc_trc_cnt) &
621 (lpfc_debugfs_max_disc_trc - 1);
622 dtp = vport->disc_trc + index;
627 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
634 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
635 * @phba: The phba to associate this trace string with for retrieval.
636 * @fmt: Format string to be displayed when dumping the log.
637 * @data1: 1st data parameter to be applied to @fmt.
638 * @data2: 2nd data parameter to be applied to @fmt.
639 * @data3: 3rd data parameter to be applied to @fmt.
642 * This routine is used by the driver code to add a debugfs log entry to the
643 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
644 * @data3 are used like printf when displaying the log.
647 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
648 uint32_t data1, uint32_t data2, uint32_t data3)
650 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
651 struct lpfc_debugfs_trc *dtp;
654 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
655 !phba || !phba->slow_ring_trc)
658 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
659 (lpfc_debugfs_max_slow_ring_trc - 1);
660 dtp = phba->slow_ring_trc + index;
665 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
671 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
673 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
674 * @inode: The inode pointer that contains a vport pointer.
675 * @file: The file pointer to attach the log output.
678 * This routine is the entry point for the debugfs open file operation. It gets
679 * the vport from the i_private field in @inode, allocates the necessary buffer
680 * for the log, fills the buffer from the in-memory log for this vport, and then
681 * returns a pointer to that log in the private_data field in @file.
684 * This function returns zero if successful. On error it will return an negative
688 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
690 struct lpfc_vport *vport = inode->i_private;
691 struct lpfc_debug *debug;
695 if (!lpfc_debugfs_max_disc_trc) {
700 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
704 /* Round to page boundary */
705 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
706 size = PAGE_ALIGN(size);
708 debug->buffer = kmalloc(size, GFP_KERNEL);
709 if (!debug->buffer) {
714 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
715 file->private_data = debug;
723 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
724 * @inode: The inode pointer that contains a vport pointer.
725 * @file: The file pointer to attach the log output.
728 * This routine is the entry point for the debugfs open file operation. It gets
729 * the vport from the i_private field in @inode, allocates the necessary buffer
730 * for the log, fills the buffer from the in-memory log for this vport, and then
731 * returns a pointer to that log in the private_data field in @file.
734 * This function returns zero if successful. On error it will return an negative
738 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
740 struct lpfc_hba *phba = inode->i_private;
741 struct lpfc_debug *debug;
745 if (!lpfc_debugfs_max_slow_ring_trc) {
750 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
754 /* Round to page boundary */
755 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
756 size = PAGE_ALIGN(size);
758 debug->buffer = kmalloc(size, GFP_KERNEL);
759 if (!debug->buffer) {
764 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
765 file->private_data = debug;
773 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
774 * @inode: The inode pointer that contains a vport pointer.
775 * @file: The file pointer to attach the log output.
778 * This routine is the entry point for the debugfs open file operation. It gets
779 * the vport from the i_private field in @inode, allocates the necessary buffer
780 * for the log, fills the buffer from the in-memory log for this vport, and then
781 * returns a pointer to that log in the private_data field in @file.
784 * This function returns zero if successful. On error it will return an negative
788 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
790 struct lpfc_hba *phba = inode->i_private;
791 struct lpfc_debug *debug;
794 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
798 /* Round to page boundary */
799 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
800 if (!debug->buffer) {
805 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
807 file->private_data = debug;
815 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
816 * @inode: The inode pointer that contains a vport pointer.
817 * @file: The file pointer to attach the log output.
820 * This routine is the entry point for the debugfs open file operation. It gets
821 * the vport from the i_private field in @inode, allocates the necessary buffer
822 * for the log, fills the buffer from the in-memory log for this vport, and then
823 * returns a pointer to that log in the private_data field in @file.
826 * This function returns zero if successful. On error it will return an negative
830 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
832 struct lpfc_hba *phba = inode->i_private;
833 struct lpfc_debug *debug;
836 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
840 /* Round to page boundary */
841 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
842 if (!debug->buffer) {
847 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
848 LPFC_DUMPHBASLIM_SIZE);
849 file->private_data = debug;
857 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
858 * @inode: The inode pointer that contains a vport pointer.
859 * @file: The file pointer to attach the log output.
862 * This routine is the entry point for the debugfs open file operation. It gets
863 * the vport from the i_private field in @inode, allocates the necessary buffer
864 * for the log, fills the buffer from the in-memory log for this vport, and then
865 * returns a pointer to that log in the private_data field in @file.
868 * This function returns zero if successful. On error it will return an negative
872 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
874 struct lpfc_hba *phba = inode->i_private;
875 struct lpfc_debug *debug;
878 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
882 /* Round to page boundary */
883 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
884 if (!debug->buffer) {
889 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
890 LPFC_DUMPHOSTSLIM_SIZE);
891 file->private_data = debug;
899 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
901 struct lpfc_debug *debug;
907 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
911 /* Round to page boundary */
912 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
913 __func__, _dump_buf_data);
914 debug->buffer = _dump_buf_data;
915 if (!debug->buffer) {
920 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
921 file->private_data = debug;
929 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
931 struct lpfc_debug *debug;
937 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
941 /* Round to page boundary */
942 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
943 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
944 debug->buffer = _dump_buf_dif;
945 if (!debug->buffer) {
950 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
951 file->private_data = debug;
959 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
960 size_t nbytes, loff_t *ppos)
963 * The Data/DIF buffers only save one failing IO
964 * The write op is used as a reset mechanism after an IO has
965 * already been saved to the next one can be saved
967 spin_lock(&_dump_buf_lock);
969 memset((void *)_dump_buf_data, 0,
970 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
971 memset((void *)_dump_buf_dif, 0,
972 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
976 spin_unlock(&_dump_buf_lock);
982 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
983 * @inode: The inode pointer that contains a vport pointer.
984 * @file: The file pointer to attach the log output.
987 * This routine is the entry point for the debugfs open file operation. It gets
988 * the vport from the i_private field in @inode, allocates the necessary buffer
989 * for the log, fills the buffer from the in-memory log for this vport, and then
990 * returns a pointer to that log in the private_data field in @file.
993 * This function returns zero if successful. On error it will return an negative
997 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
999 struct lpfc_vport *vport = inode->i_private;
1000 struct lpfc_debug *debug;
1003 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1007 /* Round to page boundary */
1008 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1009 if (!debug->buffer) {
1014 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1015 LPFC_NODELIST_SIZE);
1016 file->private_data = debug;
1024 * lpfc_debugfs_lseek - Seek through a debugfs file
1025 * @file: The file pointer to seek through.
1026 * @off: The offset to seek to or the amount to seek by.
1027 * @whence: Indicates how to seek.
1030 * This routine is the entry point for the debugfs lseek file operation. The
1031 * @whence parameter indicates whether @off is the offset to directly seek to,
1032 * or if it is a value to seek forward or reverse by. This function figures out
1033 * what the new offset of the debugfs file will be and assigns that value to the
1034 * f_pos field of @file.
1037 * This function returns the new offset if successful and returns a negative
1038 * error if unable to process the seek.
1041 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1043 struct lpfc_debug *debug;
1046 debug = file->private_data;
1053 pos = file->f_pos + off;
1056 pos = debug->len - off;
1058 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1062 * lpfc_debugfs_read - Read a debugfs file
1063 * @file: The file pointer to read from.
1064 * @buf: The buffer to copy the data to.
1065 * @nbytes: The number of bytes to read.
1066 * @ppos: The position in the file to start reading from.
1069 * This routine reads data from from the buffer indicated in the private_data
1070 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1074 * This function returns the amount of data that was read (this could be less
1075 * than @nbytes if the end of the file was reached) or a negative error value.
1078 lpfc_debugfs_read(struct file *file, char __user *buf,
1079 size_t nbytes, loff_t *ppos)
1081 struct lpfc_debug *debug = file->private_data;
1083 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1088 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1089 * @inode: The inode pointer that contains a vport pointer. (unused)
1090 * @file: The file pointer that contains the buffer to release.
1093 * This routine frees the buffer that was allocated when the debugfs file was
1097 * This function returns zero.
1100 lpfc_debugfs_release(struct inode *inode, struct file *file)
1102 struct lpfc_debug *debug = file->private_data;
1104 kfree(debug->buffer);
1111 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1113 struct lpfc_debug *debug = file->private_data;
1115 debug->buffer = NULL;
1122 * ---------------------------------
1123 * iDiag debugfs file access methods
1124 * ---------------------------------
1126 * All access methods are through the proper SLI4 PCI function's debugfs
1129 * /sys/kernel/debug/lpfc/fn<#>/iDiag
1133 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1134 * @buf: The pointer to the user space buffer.
1135 * @nbytes: The number of bytes in the user space buffer.
1136 * @idiag_cmd: pointer to the idiag command struct.
1138 * This routine reads data from debugfs user space buffer and parses the
1139 * buffer for getting the idiag command and arguments. The while space in
1140 * between the set of data is used as the parsing separator.
1142 * This routine returns 0 when successful, it returns proper error code
1143 * back to the user space in error conditions.
1145 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1146 struct lpfc_idiag_cmd *idiag_cmd)
1149 char *pbuf, *step_str;
1152 /* Protect copy from user */
1153 if (!access_ok(VERIFY_READ, buf, nbytes))
1156 memset(mybuf, 0, sizeof(mybuf));
1157 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1158 bsize = min(nbytes, (sizeof(mybuf)-1));
1160 if (copy_from_user(mybuf, buf, bsize))
1163 step_str = strsep(&pbuf, "\t ");
1165 /* The opcode must present */
1169 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1170 if (idiag_cmd->opcode == 0)
1173 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1174 step_str = strsep(&pbuf, "\t ");
1177 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1183 * lpfc_idiag_open - idiag open debugfs
1184 * @inode: The inode pointer that contains a pointer to phba.
1185 * @file: The file pointer to attach the file operation.
1188 * This routine is the entry point for the debugfs open file operation. It
1189 * gets the reference to phba from the i_private field in @inode, it then
1190 * allocates buffer for the file operation, performs the necessary PCI config
1191 * space read into the allocated buffer according to the idiag user command
1192 * setup, and then returns a pointer to buffer in the private_data field in
1196 * This function returns zero if successful. On error it will return an
1197 * negative error value.
1200 lpfc_idiag_open(struct inode *inode, struct file *file)
1202 struct lpfc_debug *debug;
1204 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1208 debug->i_private = inode->i_private;
1209 debug->buffer = NULL;
1210 file->private_data = debug;
1216 * lpfc_idiag_release - Release idiag access file operation
1217 * @inode: The inode pointer that contains a vport pointer. (unused)
1218 * @file: The file pointer that contains the buffer to release.
1221 * This routine is the generic release routine for the idiag access file
1222 * operation, it frees the buffer that was allocated when the debugfs file
1226 * This function returns zero.
1229 lpfc_idiag_release(struct inode *inode, struct file *file)
1231 struct lpfc_debug *debug = file->private_data;
1233 /* Free the buffers to the file operation */
1234 kfree(debug->buffer);
1241 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1242 * @inode: The inode pointer that contains a vport pointer. (unused)
1243 * @file: The file pointer that contains the buffer to release.
1246 * This routine frees the buffer that was allocated when the debugfs file
1247 * was opened. It also reset the fields in the idiag command struct in the
1248 * case of command for write operation.
1251 * This function returns zero.
1254 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1256 struct lpfc_debug *debug = file->private_data;
1258 if (debug->op == LPFC_IDIAG_OP_WR) {
1259 switch (idiag.cmd.opcode) {
1260 case LPFC_IDIAG_CMD_PCICFG_WR:
1261 case LPFC_IDIAG_CMD_PCICFG_ST:
1262 case LPFC_IDIAG_CMD_PCICFG_CL:
1263 case LPFC_IDIAG_CMD_QUEACC_WR:
1264 case LPFC_IDIAG_CMD_QUEACC_ST:
1265 case LPFC_IDIAG_CMD_QUEACC_CL:
1266 memset(&idiag, 0, sizeof(idiag));
1273 /* Free the buffers to the file operation */
1274 kfree(debug->buffer);
1281 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1282 * @file: The file pointer to read from.
1283 * @buf: The buffer to copy the data to.
1284 * @nbytes: The number of bytes to read.
1285 * @ppos: The position in the file to start reading from.
1288 * This routine reads data from the @phba pci config space according to the
1289 * idiag command, and copies to user @buf. Depending on the PCI config space
1290 * read command setup, it does either a single register read of a byte
1291 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1292 * registers from the 4K extended PCI config space.
1295 * This function returns the amount of data that was read (this could be less
1296 * than @nbytes if the end of the file was reached) or a negative error value.
1299 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1302 struct lpfc_debug *debug = file->private_data;
1303 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1304 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1307 struct pci_dev *pdev;
1312 pdev = phba->pcidev;
1316 /* This is a user read operation */
1317 debug->op = LPFC_IDIAG_OP_RD;
1320 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1323 pbuffer = debug->buffer;
1328 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1329 where = idiag.cmd.data[0];
1330 count = idiag.cmd.data[1];
1334 /* Read single PCI config space register */
1336 case SIZE_U8: /* byte (8 bits) */
1337 pci_read_config_byte(pdev, where, &u8val);
1338 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1339 "%03x: %02x\n", where, u8val);
1341 case SIZE_U16: /* word (16 bits) */
1342 pci_read_config_word(pdev, where, &u16val);
1343 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1344 "%03x: %04x\n", where, u16val);
1346 case SIZE_U32: /* double word (32 bits) */
1347 pci_read_config_dword(pdev, where, &u32val);
1348 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1349 "%03x: %08x\n", where, u32val);
1351 case LPFC_PCI_CFG_BROWSE: /* browse all */
1359 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1363 /* Browse all PCI config space registers */
1364 offset_label = idiag.offset.last_rd;
1365 offset = offset_label;
1367 /* Read PCI config space */
1368 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1369 "%03x: ", offset_label);
1371 pci_read_config_dword(pdev, offset, &u32val);
1372 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1374 offset += sizeof(uint32_t);
1375 index -= sizeof(uint32_t);
1377 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1379 else if (!(index % (8 * sizeof(uint32_t)))) {
1380 offset_label += (8 * sizeof(uint32_t));
1381 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1382 "\n%03x: ", offset_label);
1386 /* Set up the offset for next portion of pci cfg read */
1387 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1388 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1389 idiag.offset.last_rd = 0;
1391 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1395 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1396 * @file: The file pointer to read from.
1397 * @buf: The buffer to copy the user data from.
1398 * @nbytes: The number of bytes to get.
1399 * @ppos: The position in the file to start reading from.
1401 * This routine get the debugfs idiag command struct from user space and
1402 * then perform the syntax check for PCI config space read or write command
1403 * accordingly. In the case of PCI config space read command, it sets up
1404 * the command in the idiag command struct for the debugfs read operation.
1405 * In the case of PCI config space write operation, it executes the write
1406 * operation into the PCI config space accordingly.
1408 * It returns the @nbytges passing in from debugfs user space when successful.
1409 * In case of error conditions, it returns proper error code back to the user
1413 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1414 size_t nbytes, loff_t *ppos)
1416 struct lpfc_debug *debug = file->private_data;
1417 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1418 uint32_t where, value, count;
1422 struct pci_dev *pdev;
1425 pdev = phba->pcidev;
1429 /* This is a user write operation */
1430 debug->op = LPFC_IDIAG_OP_WR;
1432 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1436 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1437 /* Sanity check on PCI config read command line arguments */
1438 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1440 /* Read command from PCI config space, set up command fields */
1441 where = idiag.cmd.data[0];
1442 count = idiag.cmd.data[1];
1443 if (count == LPFC_PCI_CFG_BROWSE) {
1444 if (where % sizeof(uint32_t))
1446 /* Starting offset to browse */
1447 idiag.offset.last_rd = where;
1448 } else if ((count != sizeof(uint8_t)) &&
1449 (count != sizeof(uint16_t)) &&
1450 (count != sizeof(uint32_t)))
1452 if (count == sizeof(uint8_t)) {
1453 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1455 if (where % sizeof(uint8_t))
1458 if (count == sizeof(uint16_t)) {
1459 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1461 if (where % sizeof(uint16_t))
1464 if (count == sizeof(uint32_t)) {
1465 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1467 if (where % sizeof(uint32_t))
1470 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1471 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1472 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1473 /* Sanity check on PCI config write command line arguments */
1474 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1476 /* Write command to PCI config space, read-modify-write */
1477 where = idiag.cmd.data[0];
1478 count = idiag.cmd.data[1];
1479 value = idiag.cmd.data[2];
1481 if ((count != sizeof(uint8_t)) &&
1482 (count != sizeof(uint16_t)) &&
1483 (count != sizeof(uint32_t)))
1485 if (count == sizeof(uint8_t)) {
1486 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1488 if (where % sizeof(uint8_t))
1490 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1491 pci_write_config_byte(pdev, where,
1493 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1494 rc = pci_read_config_byte(pdev, where, &u8val);
1496 u8val |= (uint8_t)value;
1497 pci_write_config_byte(pdev, where,
1501 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1502 rc = pci_read_config_byte(pdev, where, &u8val);
1504 u8val &= (uint8_t)(~value);
1505 pci_write_config_byte(pdev, where,
1510 if (count == sizeof(uint16_t)) {
1511 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1513 if (where % sizeof(uint16_t))
1515 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1516 pci_write_config_word(pdev, where,
1518 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1519 rc = pci_read_config_word(pdev, where, &u16val);
1521 u16val |= (uint16_t)value;
1522 pci_write_config_word(pdev, where,
1526 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1527 rc = pci_read_config_word(pdev, where, &u16val);
1529 u16val &= (uint16_t)(~value);
1530 pci_write_config_word(pdev, where,
1535 if (count == sizeof(uint32_t)) {
1536 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1538 if (where % sizeof(uint32_t))
1540 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1541 pci_write_config_dword(pdev, where, value);
1542 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1543 rc = pci_read_config_dword(pdev, where,
1547 pci_write_config_dword(pdev, where,
1551 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1552 rc = pci_read_config_dword(pdev, where,
1556 pci_write_config_dword(pdev, where,
1562 /* All other opecodes are illegal for now */
1567 memset(&idiag, 0, sizeof(idiag));
1572 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1573 * @file: The file pointer to read from.
1574 * @buf: The buffer to copy the data to.
1575 * @nbytes: The number of bytes to read.
1576 * @ppos: The position in the file to start reading from.
1579 * This routine reads data from the @phba SLI4 PCI function queue information,
1580 * and copies to user @buf.
1583 * This function returns the amount of data that was read (this could be less
1584 * than @nbytes if the end of the file was reached) or a negative error value.
1587 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
1590 struct lpfc_debug *debug = file->private_data;
1591 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1592 int len = 0, fcp_qidx;
1596 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
1599 pbuffer = debug->buffer;
1604 /* Get slow-path event queue information */
1605 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1606 "Slow-path EQ information:\n");
1607 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1609 "QE-COUNT[%04d], QE-SIZE[%04d], "
1610 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1611 phba->sli4_hba.sp_eq->queue_id,
1612 phba->sli4_hba.sp_eq->entry_count,
1613 phba->sli4_hba.sp_eq->entry_size,
1614 phba->sli4_hba.sp_eq->host_index,
1615 phba->sli4_hba.sp_eq->hba_index);
1617 /* Get fast-path event queue information */
1618 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1619 "Fast-path EQ information:\n");
1620 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
1621 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1623 "QE-COUNT[%04d], QE-SIZE[%04d], "
1624 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1625 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
1626 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
1627 phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
1628 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
1629 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
1631 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1633 /* Get mailbox complete queue information */
1634 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1635 "Slow-path MBX CQ information:\n");
1636 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1637 "Associated EQID[%02d]:\n",
1638 phba->sli4_hba.mbx_cq->assoc_qid);
1639 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1641 "QE-COUNT[%04d], QE-SIZE[%04d], "
1642 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1643 phba->sli4_hba.mbx_cq->queue_id,
1644 phba->sli4_hba.mbx_cq->entry_count,
1645 phba->sli4_hba.mbx_cq->entry_size,
1646 phba->sli4_hba.mbx_cq->host_index,
1647 phba->sli4_hba.mbx_cq->hba_index);
1649 /* Get slow-path complete queue information */
1650 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1651 "Slow-path ELS CQ information:\n");
1652 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1653 "Associated EQID[%02d]:\n",
1654 phba->sli4_hba.els_cq->assoc_qid);
1655 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1657 "QE-COUNT[%04d], QE-SIZE[%04d], "
1658 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1659 phba->sli4_hba.els_cq->queue_id,
1660 phba->sli4_hba.els_cq->entry_count,
1661 phba->sli4_hba.els_cq->entry_size,
1662 phba->sli4_hba.els_cq->host_index,
1663 phba->sli4_hba.els_cq->hba_index);
1665 /* Get fast-path complete queue information */
1666 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1667 "Fast-path FCP CQ information:\n");
1670 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1671 "Associated EQID[%02d]:\n",
1672 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
1673 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1675 "QE-COUNT[%04d], QE-SIZE[%04d], "
1676 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1677 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
1678 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
1679 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
1680 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
1681 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
1682 } while (++fcp_qidx < phba->cfg_fcp_eq_count);
1683 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1685 /* Get mailbox queue information */
1686 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1687 "Slow-path MBX MQ information:\n");
1688 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1689 "Associated CQID[%02d]:\n",
1690 phba->sli4_hba.mbx_wq->assoc_qid);
1691 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1693 "QE-COUNT[%04d], QE-SIZE[%04d], "
1694 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1695 phba->sli4_hba.mbx_wq->queue_id,
1696 phba->sli4_hba.mbx_wq->entry_count,
1697 phba->sli4_hba.mbx_wq->entry_size,
1698 phba->sli4_hba.mbx_wq->host_index,
1699 phba->sli4_hba.mbx_wq->hba_index);
1701 /* Get slow-path work queue information */
1702 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1703 "Slow-path ELS WQ information:\n");
1704 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1705 "Associated CQID[%02d]:\n",
1706 phba->sli4_hba.els_wq->assoc_qid);
1707 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1709 "QE-COUNT[%04d], QE-SIZE[%04d], "
1710 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1711 phba->sli4_hba.els_wq->queue_id,
1712 phba->sli4_hba.els_wq->entry_count,
1713 phba->sli4_hba.els_wq->entry_size,
1714 phba->sli4_hba.els_wq->host_index,
1715 phba->sli4_hba.els_wq->hba_index);
1717 /* Get fast-path work queue information */
1718 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1719 "Fast-path FCP WQ information:\n");
1720 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
1721 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1722 "Associated CQID[%02d]:\n",
1723 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
1724 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1726 "QE-COUNT[%04d], WQE-SIZE[%04d], "
1727 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1728 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
1729 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
1730 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
1731 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
1732 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
1734 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1736 /* Get receive queue information */
1737 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1738 "Slow-path RQ information:\n");
1739 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1740 "Associated CQID[%02d]:\n",
1741 phba->sli4_hba.hdr_rq->assoc_qid);
1742 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1744 "QE-COUNT[%04d], QE-SIZE[%04d], "
1745 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1746 phba->sli4_hba.hdr_rq->queue_id,
1747 phba->sli4_hba.hdr_rq->entry_count,
1748 phba->sli4_hba.hdr_rq->entry_size,
1749 phba->sli4_hba.hdr_rq->host_index,
1750 phba->sli4_hba.hdr_rq->hba_index);
1751 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1753 "QE-COUNT[%04d], QE-SIZE[%04d], "
1754 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1755 phba->sli4_hba.dat_rq->queue_id,
1756 phba->sli4_hba.dat_rq->entry_count,
1757 phba->sli4_hba.dat_rq->entry_size,
1758 phba->sli4_hba.dat_rq->host_index,
1759 phba->sli4_hba.dat_rq->hba_index);
1761 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1765 * lpfc_idiag_que_param_check - queue access command parameter sanity check
1766 * @q: The pointer to queue structure.
1767 * @index: The index into a queue entry.
1768 * @count: The number of queue entries to access.
1771 * The routine performs sanity check on device queue access method commands.
1774 * This function returns -EINVAL when fails the sanity check, otherwise, it
1778 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
1780 /* Only support single entry read or browsing */
1781 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
1783 if (index > q->entry_count - 1)
1789 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
1790 * @pbuffer: The pointer to buffer to copy the read data into.
1791 * @pque: The pointer to the queue to be read.
1792 * @index: The index into the queue entry.
1795 * This routine reads out a single entry from the given queue's index location
1796 * and copies it into the buffer provided.
1799 * This function returns 0 when it fails, otherwise, it returns the length of
1800 * the data read into the buffer provided.
1803 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
1809 if (!pbuffer || !pque)
1812 esize = pque->entry_size;
1813 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
1814 "QE-INDEX[%04d]:\n", index);
1817 pentry = pque->qe[index].address;
1819 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
1822 offset += sizeof(uint32_t);
1823 esize -= sizeof(uint32_t);
1824 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
1825 len += snprintf(pbuffer+len,
1826 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
1828 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
1834 * lpfc_idiag_queacc_read - idiag debugfs read port queue
1835 * @file: The file pointer to read from.
1836 * @buf: The buffer to copy the data to.
1837 * @nbytes: The number of bytes to read.
1838 * @ppos: The position in the file to start reading from.
1841 * This routine reads data from the @phba device queue memory according to the
1842 * idiag command, and copies to user @buf. Depending on the queue dump read
1843 * command setup, it does either a single queue entry read or browing through
1844 * all entries of the queue.
1847 * This function returns the amount of data that was read (this could be less
1848 * than @nbytes if the end of the file was reached) or a negative error value.
1851 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
1854 struct lpfc_debug *debug = file->private_data;
1855 uint32_t last_index, index, count;
1856 struct lpfc_queue *pque = NULL;
1860 /* This is a user read operation */
1861 debug->op = LPFC_IDIAG_OP_RD;
1864 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
1867 pbuffer = debug->buffer;
1872 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
1873 index = idiag.cmd.data[2];
1874 count = idiag.cmd.data[3];
1875 pque = (struct lpfc_queue *)idiag.ptr_private;
1879 /* Browse the queue starting from index */
1880 if (count == LPFC_QUE_ACC_BROWSE)
1883 /* Read a single entry from the queue */
1884 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
1886 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1890 /* Browse all entries from the queue */
1891 last_index = idiag.offset.last_rd;
1894 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
1895 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
1897 if (index > pque->entry_count - 1)
1901 /* Set up the offset for next portion of pci cfg read */
1902 if (index > pque->entry_count - 1)
1904 idiag.offset.last_rd = index;
1906 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1910 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
1911 * @file: The file pointer to read from.
1912 * @buf: The buffer to copy the user data from.
1913 * @nbytes: The number of bytes to get.
1914 * @ppos: The position in the file to start reading from.
1916 * This routine get the debugfs idiag command struct from user space and then
1917 * perform the syntax check for port queue read (dump) or write (set) command
1918 * accordingly. In the case of port queue read command, it sets up the command
1919 * in the idiag command struct for the following debugfs read operation. In
1920 * the case of port queue write operation, it executes the write operation
1921 * into the port queue entry accordingly.
1923 * It returns the @nbytges passing in from debugfs user space when successful.
1924 * In case of error conditions, it returns proper error code back to the user
1928 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
1929 size_t nbytes, loff_t *ppos)
1931 struct lpfc_debug *debug = file->private_data;
1932 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1933 uint32_t qidx, quetp, queid, index, count, offset, value;
1935 struct lpfc_queue *pque;
1938 /* This is a user write operation */
1939 debug->op = LPFC_IDIAG_OP_WR;
1941 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1945 /* Get and sanity check on command feilds */
1946 quetp = idiag.cmd.data[0];
1947 queid = idiag.cmd.data[1];
1948 index = idiag.cmd.data[2];
1949 count = idiag.cmd.data[3];
1950 offset = idiag.cmd.data[4];
1951 value = idiag.cmd.data[5];
1953 /* Sanity check on command line arguments */
1954 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
1955 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
1956 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
1957 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
1961 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
1962 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
1969 /* Slow-path event queue */
1970 if (phba->sli4_hba.sp_eq->queue_id == queid) {
1972 rc = lpfc_idiag_que_param_check(
1973 phba->sli4_hba.sp_eq, index, count);
1976 idiag.ptr_private = phba->sli4_hba.sp_eq;
1979 /* Fast-path event queue */
1980 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
1981 if (phba->sli4_hba.fp_eq[qidx]->queue_id == queid) {
1983 rc = lpfc_idiag_que_param_check(
1984 phba->sli4_hba.fp_eq[qidx],
1988 idiag.ptr_private = phba->sli4_hba.fp_eq[qidx];
1995 /* MBX complete queue */
1996 if (phba->sli4_hba.mbx_cq->queue_id == queid) {
1998 rc = lpfc_idiag_que_param_check(
1999 phba->sli4_hba.mbx_cq, index, count);
2002 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2005 /* ELS complete queue */
2006 if (phba->sli4_hba.els_cq->queue_id == queid) {
2008 rc = lpfc_idiag_que_param_check(
2009 phba->sli4_hba.els_cq, index, count);
2012 idiag.ptr_private = phba->sli4_hba.els_cq;
2015 /* FCP complete queue */
2018 if (phba->sli4_hba.fcp_cq[qidx]->queue_id == queid) {
2020 rc = lpfc_idiag_que_param_check(
2021 phba->sli4_hba.fcp_cq[qidx],
2026 phba->sli4_hba.fcp_cq[qidx];
2029 } while (++qidx < phba->cfg_fcp_eq_count);
2033 /* MBX work queue */
2034 if (phba->sli4_hba.mbx_wq->queue_id == queid) {
2036 rc = lpfc_idiag_que_param_check(
2037 phba->sli4_hba.mbx_wq, index, count);
2040 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2045 /* ELS work queue */
2046 if (phba->sli4_hba.els_wq->queue_id == queid) {
2048 rc = lpfc_idiag_que_param_check(
2049 phba->sli4_hba.els_wq, index, count);
2052 idiag.ptr_private = phba->sli4_hba.els_wq;
2055 /* FCP work queue */
2056 for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
2057 if (phba->sli4_hba.fcp_wq[qidx]->queue_id == queid) {
2059 rc = lpfc_idiag_que_param_check(
2060 phba->sli4_hba.fcp_wq[qidx],
2065 phba->sli4_hba.fcp_wq[qidx];
2073 if (phba->sli4_hba.hdr_rq->queue_id == queid) {
2075 rc = lpfc_idiag_que_param_check(
2076 phba->sli4_hba.hdr_rq, index, count);
2079 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2083 if (phba->sli4_hba.dat_rq->queue_id == queid) {
2085 rc = lpfc_idiag_que_param_check(
2086 phba->sli4_hba.dat_rq, index, count);
2089 idiag.ptr_private = phba->sli4_hba.dat_rq;
2101 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2102 if (count == LPFC_QUE_ACC_BROWSE)
2103 idiag.offset.last_rd = index;
2106 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2107 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2108 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2109 /* Additional sanity checks on write operation */
2110 pque = (struct lpfc_queue *)idiag.ptr_private;
2111 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2113 pentry = pque->qe[index].address;
2115 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2117 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2119 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2125 /* Clean out command structure on command error out */
2126 memset(&idiag, 0, sizeof(idiag));
2131 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2132 * @phba: The pointer to hba structure.
2133 * @pbuffer: The pointer to the buffer to copy the data to.
2134 * @len: The lenght of bytes to copied.
2135 * @drbregid: The id to doorbell registers.
2138 * This routine reads a doorbell register and copies its content to the
2139 * user buffer pointed to by @pbuffer.
2142 * This function returns the amount of data that was copied into @pbuffer.
2145 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2146 int len, uint32_t drbregid)
2154 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2155 "EQCQ-DRB-REG: 0x%08x\n",
2156 readl(phba->sli4_hba.EQCQDBregaddr));
2159 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2160 "MQ-DRB-REG: 0x%08x\n",
2161 readl(phba->sli4_hba.MQDBregaddr));
2164 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2165 "WQ-DRB-REG: 0x%08x\n",
2166 readl(phba->sli4_hba.WQDBregaddr));
2169 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2170 "RQ-DRB-REG: 0x%08x\n",
2171 readl(phba->sli4_hba.RQDBregaddr));
2181 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2182 * @file: The file pointer to read from.
2183 * @buf: The buffer to copy the data to.
2184 * @nbytes: The number of bytes to read.
2185 * @ppos: The position in the file to start reading from.
2188 * This routine reads data from the @phba device doorbell register according
2189 * to the idiag command, and copies to user @buf. Depending on the doorbell
2190 * register read command setup, it does either a single doorbell register
2191 * read or dump all doorbell registers.
2194 * This function returns the amount of data that was read (this could be less
2195 * than @nbytes if the end of the file was reached) or a negative error value.
2198 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2201 struct lpfc_debug *debug = file->private_data;
2202 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2203 uint32_t drb_reg_id, i;
2207 /* This is a user read operation */
2208 debug->op = LPFC_IDIAG_OP_RD;
2211 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2214 pbuffer = debug->buffer;
2219 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
2220 drb_reg_id = idiag.cmd.data[0];
2224 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2225 for (i = 1; i <= LPFC_DRB_MAX; i++)
2226 len = lpfc_idiag_drbacc_read_reg(phba,
2229 len = lpfc_idiag_drbacc_read_reg(phba,
2230 pbuffer, len, drb_reg_id);
2232 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2236 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2237 * @file: The file pointer to read from.
2238 * @buf: The buffer to copy the user data from.
2239 * @nbytes: The number of bytes to get.
2240 * @ppos: The position in the file to start reading from.
2242 * This routine get the debugfs idiag command struct from user space and then
2243 * perform the syntax check for port doorbell register read (dump) or write
2244 * (set) command accordingly. In the case of port queue read command, it sets
2245 * up the command in the idiag command struct for the following debugfs read
2246 * operation. In the case of port doorbell register write operation, it
2247 * executes the write operation into the port doorbell register accordingly.
2249 * It returns the @nbytges passing in from debugfs user space when successful.
2250 * In case of error conditions, it returns proper error code back to the user
2254 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2255 size_t nbytes, loff_t *ppos)
2257 struct lpfc_debug *debug = file->private_data;
2258 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2259 uint32_t drb_reg_id, value, reg_val;
2260 void __iomem *drb_reg;
2263 /* This is a user write operation */
2264 debug->op = LPFC_IDIAG_OP_WR;
2266 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2270 /* Sanity check on command line arguments */
2271 drb_reg_id = idiag.cmd.data[0];
2272 value = idiag.cmd.data[1];
2274 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2275 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2276 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2277 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2279 if (drb_reg_id > LPFC_DRB_MAX)
2281 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2282 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2284 if ((drb_reg_id > LPFC_DRB_MAX) &&
2285 (drb_reg_id != LPFC_DRB_ACC_ALL))
2290 /* Perform the write access operation */
2291 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2292 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2293 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2294 switch (drb_reg_id) {
2296 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2299 drb_reg = phba->sli4_hba.MQDBregaddr;
2302 drb_reg = phba->sli4_hba.WQDBregaddr;
2305 drb_reg = phba->sli4_hba.RQDBregaddr;
2311 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2313 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2314 reg_val = readl(drb_reg);
2317 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2318 reg_val = readl(drb_reg);
2321 writel(reg_val, drb_reg);
2322 readl(drb_reg); /* flush */
2327 /* Clean out command structure on command error out */
2328 memset(&idiag, 0, sizeof(idiag));
2332 #undef lpfc_debugfs_op_disc_trc
2333 static const struct file_operations lpfc_debugfs_op_disc_trc = {
2334 .owner = THIS_MODULE,
2335 .open = lpfc_debugfs_disc_trc_open,
2336 .llseek = lpfc_debugfs_lseek,
2337 .read = lpfc_debugfs_read,
2338 .release = lpfc_debugfs_release,
2341 #undef lpfc_debugfs_op_nodelist
2342 static const struct file_operations lpfc_debugfs_op_nodelist = {
2343 .owner = THIS_MODULE,
2344 .open = lpfc_debugfs_nodelist_open,
2345 .llseek = lpfc_debugfs_lseek,
2346 .read = lpfc_debugfs_read,
2347 .release = lpfc_debugfs_release,
2350 #undef lpfc_debugfs_op_hbqinfo
2351 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
2352 .owner = THIS_MODULE,
2353 .open = lpfc_debugfs_hbqinfo_open,
2354 .llseek = lpfc_debugfs_lseek,
2355 .read = lpfc_debugfs_read,
2356 .release = lpfc_debugfs_release,
2359 #undef lpfc_debugfs_op_dumpHBASlim
2360 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
2361 .owner = THIS_MODULE,
2362 .open = lpfc_debugfs_dumpHBASlim_open,
2363 .llseek = lpfc_debugfs_lseek,
2364 .read = lpfc_debugfs_read,
2365 .release = lpfc_debugfs_release,
2368 #undef lpfc_debugfs_op_dumpHostSlim
2369 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
2370 .owner = THIS_MODULE,
2371 .open = lpfc_debugfs_dumpHostSlim_open,
2372 .llseek = lpfc_debugfs_lseek,
2373 .read = lpfc_debugfs_read,
2374 .release = lpfc_debugfs_release,
2377 #undef lpfc_debugfs_op_dumpData
2378 static const struct file_operations lpfc_debugfs_op_dumpData = {
2379 .owner = THIS_MODULE,
2380 .open = lpfc_debugfs_dumpData_open,
2381 .llseek = lpfc_debugfs_lseek,
2382 .read = lpfc_debugfs_read,
2383 .write = lpfc_debugfs_dumpDataDif_write,
2384 .release = lpfc_debugfs_dumpDataDif_release,
2387 #undef lpfc_debugfs_op_dumpDif
2388 static const struct file_operations lpfc_debugfs_op_dumpDif = {
2389 .owner = THIS_MODULE,
2390 .open = lpfc_debugfs_dumpDif_open,
2391 .llseek = lpfc_debugfs_lseek,
2392 .read = lpfc_debugfs_read,
2393 .write = lpfc_debugfs_dumpDataDif_write,
2394 .release = lpfc_debugfs_dumpDataDif_release,
2397 #undef lpfc_debugfs_op_slow_ring_trc
2398 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
2399 .owner = THIS_MODULE,
2400 .open = lpfc_debugfs_slow_ring_trc_open,
2401 .llseek = lpfc_debugfs_lseek,
2402 .read = lpfc_debugfs_read,
2403 .release = lpfc_debugfs_release,
2406 static struct dentry *lpfc_debugfs_root = NULL;
2407 static atomic_t lpfc_debugfs_hba_count;
2410 * File operations for the iDiag debugfs
2412 #undef lpfc_idiag_op_pciCfg
2413 static const struct file_operations lpfc_idiag_op_pciCfg = {
2414 .owner = THIS_MODULE,
2415 .open = lpfc_idiag_open,
2416 .llseek = lpfc_debugfs_lseek,
2417 .read = lpfc_idiag_pcicfg_read,
2418 .write = lpfc_idiag_pcicfg_write,
2419 .release = lpfc_idiag_cmd_release,
2422 #undef lpfc_idiag_op_queInfo
2423 static const struct file_operations lpfc_idiag_op_queInfo = {
2424 .owner = THIS_MODULE,
2425 .open = lpfc_idiag_open,
2426 .read = lpfc_idiag_queinfo_read,
2427 .release = lpfc_idiag_release,
2430 #undef lpfc_idiag_op_queacc
2431 static const struct file_operations lpfc_idiag_op_queAcc = {
2432 .owner = THIS_MODULE,
2433 .open = lpfc_idiag_open,
2434 .llseek = lpfc_debugfs_lseek,
2435 .read = lpfc_idiag_queacc_read,
2436 .write = lpfc_idiag_queacc_write,
2437 .release = lpfc_idiag_cmd_release,
2440 #undef lpfc_idiag_op_drbacc
2441 static const struct file_operations lpfc_idiag_op_drbAcc = {
2442 .owner = THIS_MODULE,
2443 .open = lpfc_idiag_open,
2444 .llseek = lpfc_debugfs_lseek,
2445 .read = lpfc_idiag_drbacc_read,
2446 .write = lpfc_idiag_drbacc_write,
2447 .release = lpfc_idiag_cmd_release,
2453 * lpfc_debugfs_initialize - Initialize debugfs for a vport
2454 * @vport: The vport pointer to initialize.
2457 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
2458 * If not already created, this routine will create the lpfc directory, and
2459 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
2460 * also create each file used to access lpfc specific debugfs information.
2463 lpfc_debugfs_initialize(struct lpfc_vport *vport)
2465 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2466 struct lpfc_hba *phba = vport->phba;
2470 if (!lpfc_debugfs_enable)
2473 /* Setup lpfc root directory */
2474 if (!lpfc_debugfs_root) {
2475 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
2476 atomic_set(&lpfc_debugfs_hba_count, 0);
2477 if (!lpfc_debugfs_root) {
2478 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2479 "0408 Cannot create debugfs root\n");
2483 if (!lpfc_debugfs_start_time)
2484 lpfc_debugfs_start_time = jiffies;
2486 /* Setup funcX directory for specific HBA PCI function */
2487 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
2488 if (!phba->hba_debugfs_root) {
2489 phba->hba_debugfs_root =
2490 debugfs_create_dir(name, lpfc_debugfs_root);
2491 if (!phba->hba_debugfs_root) {
2492 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2493 "0412 Cannot create debugfs hba\n");
2496 atomic_inc(&lpfc_debugfs_hba_count);
2497 atomic_set(&phba->debugfs_vport_count, 0);
2500 snprintf(name, sizeof(name), "hbqinfo");
2501 phba->debug_hbqinfo =
2502 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2503 phba->hba_debugfs_root,
2504 phba, &lpfc_debugfs_op_hbqinfo);
2505 if (!phba->debug_hbqinfo) {
2506 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2507 "0411 Cannot create debugfs hbqinfo\n");
2511 /* Setup dumpHBASlim */
2512 if (phba->sli_rev < LPFC_SLI_REV4) {
2513 snprintf(name, sizeof(name), "dumpHBASlim");
2514 phba->debug_dumpHBASlim =
2515 debugfs_create_file(name,
2516 S_IFREG|S_IRUGO|S_IWUSR,
2517 phba->hba_debugfs_root,
2518 phba, &lpfc_debugfs_op_dumpHBASlim);
2519 if (!phba->debug_dumpHBASlim) {
2520 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2521 "0413 Cannot create debugfs "
2526 phba->debug_dumpHBASlim = NULL;
2528 /* Setup dumpHostSlim */
2529 if (phba->sli_rev < LPFC_SLI_REV4) {
2530 snprintf(name, sizeof(name), "dumpHostSlim");
2531 phba->debug_dumpHostSlim =
2532 debugfs_create_file(name,
2533 S_IFREG|S_IRUGO|S_IWUSR,
2534 phba->hba_debugfs_root,
2535 phba, &lpfc_debugfs_op_dumpHostSlim);
2536 if (!phba->debug_dumpHostSlim) {
2537 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2538 "0414 Cannot create debugfs "
2543 phba->debug_dumpHBASlim = NULL;
2545 /* Setup dumpData */
2546 snprintf(name, sizeof(name), "dumpData");
2547 phba->debug_dumpData =
2548 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2549 phba->hba_debugfs_root,
2550 phba, &lpfc_debugfs_op_dumpData);
2551 if (!phba->debug_dumpData) {
2552 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2553 "0800 Cannot create debugfs dumpData\n");
2558 snprintf(name, sizeof(name), "dumpDif");
2559 phba->debug_dumpDif =
2560 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2561 phba->hba_debugfs_root,
2562 phba, &lpfc_debugfs_op_dumpDif);
2563 if (!phba->debug_dumpDif) {
2564 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2565 "0801 Cannot create debugfs dumpDif\n");
2569 /* Setup slow ring trace */
2570 if (lpfc_debugfs_max_slow_ring_trc) {
2571 num = lpfc_debugfs_max_slow_ring_trc - 1;
2572 if (num & lpfc_debugfs_max_slow_ring_trc) {
2573 /* Change to be a power of 2 */
2574 num = lpfc_debugfs_max_slow_ring_trc;
2580 lpfc_debugfs_max_slow_ring_trc = (1 << i);
2582 "lpfc_debugfs_max_disc_trc changed to "
2583 "%d\n", lpfc_debugfs_max_disc_trc);
2587 snprintf(name, sizeof(name), "slow_ring_trace");
2588 phba->debug_slow_ring_trc =
2589 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2590 phba->hba_debugfs_root,
2591 phba, &lpfc_debugfs_op_slow_ring_trc);
2592 if (!phba->debug_slow_ring_trc) {
2593 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2594 "0415 Cannot create debugfs "
2595 "slow_ring_trace\n");
2598 if (!phba->slow_ring_trc) {
2599 phba->slow_ring_trc = kmalloc(
2600 (sizeof(struct lpfc_debugfs_trc) *
2601 lpfc_debugfs_max_slow_ring_trc),
2603 if (!phba->slow_ring_trc) {
2604 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2605 "0416 Cannot create debugfs "
2606 "slow_ring buffer\n");
2609 atomic_set(&phba->slow_ring_trc_cnt, 0);
2610 memset(phba->slow_ring_trc, 0,
2611 (sizeof(struct lpfc_debugfs_trc) *
2612 lpfc_debugfs_max_slow_ring_trc));
2616 snprintf(name, sizeof(name), "vport%d", vport->vpi);
2617 if (!vport->vport_debugfs_root) {
2618 vport->vport_debugfs_root =
2619 debugfs_create_dir(name, phba->hba_debugfs_root);
2620 if (!vport->vport_debugfs_root) {
2621 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2622 "0417 Can't create debugfs\n");
2625 atomic_inc(&phba->debugfs_vport_count);
2628 if (lpfc_debugfs_max_disc_trc) {
2629 num = lpfc_debugfs_max_disc_trc - 1;
2630 if (num & lpfc_debugfs_max_disc_trc) {
2631 /* Change to be a power of 2 */
2632 num = lpfc_debugfs_max_disc_trc;
2638 lpfc_debugfs_max_disc_trc = (1 << i);
2640 "lpfc_debugfs_max_disc_trc changed to %d\n",
2641 lpfc_debugfs_max_disc_trc);
2645 vport->disc_trc = kzalloc(
2646 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
2649 if (!vport->disc_trc) {
2650 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2651 "0418 Cannot create debugfs disc trace "
2655 atomic_set(&vport->disc_trc_cnt, 0);
2657 snprintf(name, sizeof(name), "discovery_trace");
2658 vport->debug_disc_trc =
2659 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2660 vport->vport_debugfs_root,
2661 vport, &lpfc_debugfs_op_disc_trc);
2662 if (!vport->debug_disc_trc) {
2663 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2664 "0419 Cannot create debugfs "
2665 "discovery_trace\n");
2668 snprintf(name, sizeof(name), "nodelist");
2669 vport->debug_nodelist =
2670 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2671 vport->vport_debugfs_root,
2672 vport, &lpfc_debugfs_op_nodelist);
2673 if (!vport->debug_nodelist) {
2674 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2675 "0409 Can't create debugfs nodelist\n");
2680 * iDiag debugfs root entry points for SLI4 device only
2682 if (phba->sli_rev < LPFC_SLI_REV4)
2685 snprintf(name, sizeof(name), "iDiag");
2686 if (!phba->idiag_root) {
2688 debugfs_create_dir(name, phba->hba_debugfs_root);
2689 if (!phba->idiag_root) {
2690 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2691 "2922 Can't create idiag debugfs\n");
2694 /* Initialize iDiag data structure */
2695 memset(&idiag, 0, sizeof(idiag));
2698 /* iDiag read PCI config space */
2699 snprintf(name, sizeof(name), "pciCfg");
2700 if (!phba->idiag_pci_cfg) {
2701 phba->idiag_pci_cfg =
2702 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2703 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
2704 if (!phba->idiag_pci_cfg) {
2705 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2706 "2923 Can't create idiag debugfs\n");
2709 idiag.offset.last_rd = 0;
2712 /* iDiag get PCI function queue information */
2713 snprintf(name, sizeof(name), "queInfo");
2714 if (!phba->idiag_que_info) {
2715 phba->idiag_que_info =
2716 debugfs_create_file(name, S_IFREG|S_IRUGO,
2717 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
2718 if (!phba->idiag_que_info) {
2719 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2720 "2924 Can't create idiag debugfs\n");
2725 /* iDiag access PCI function queue */
2726 snprintf(name, sizeof(name), "queAcc");
2727 if (!phba->idiag_que_acc) {
2728 phba->idiag_que_acc =
2729 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2730 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
2731 if (!phba->idiag_que_acc) {
2732 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2733 "2926 Can't create idiag debugfs\n");
2738 /* iDiag access PCI function doorbell registers */
2739 snprintf(name, sizeof(name), "drbAcc");
2740 if (!phba->idiag_drb_acc) {
2741 phba->idiag_drb_acc =
2742 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2743 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
2744 if (!phba->idiag_drb_acc) {
2745 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2746 "2927 Can't create idiag debugfs\n");
2757 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
2758 * @vport: The vport pointer to remove from debugfs.
2761 * When Debugfs is configured this routine removes debugfs file system elements
2762 * that are specific to this vport. It also checks to see if there are any
2763 * users left for the debugfs directories associated with the HBA and driver. If
2764 * this is the last user of the HBA directory or driver directory then it will
2765 * remove those from the debugfs infrastructure as well.
2768 lpfc_debugfs_terminate(struct lpfc_vport *vport)
2770 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2771 struct lpfc_hba *phba = vport->phba;
2773 if (vport->disc_trc) {
2774 kfree(vport->disc_trc);
2775 vport->disc_trc = NULL;
2777 if (vport->debug_disc_trc) {
2778 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
2779 vport->debug_disc_trc = NULL;
2781 if (vport->debug_nodelist) {
2782 debugfs_remove(vport->debug_nodelist); /* nodelist */
2783 vport->debug_nodelist = NULL;
2786 if (vport->vport_debugfs_root) {
2787 debugfs_remove(vport->vport_debugfs_root); /* vportX */
2788 vport->vport_debugfs_root = NULL;
2789 atomic_dec(&phba->debugfs_vport_count);
2791 if (atomic_read(&phba->debugfs_vport_count) == 0) {
2793 if (phba->debug_hbqinfo) {
2794 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
2795 phba->debug_hbqinfo = NULL;
2797 if (phba->debug_dumpHBASlim) {
2798 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
2799 phba->debug_dumpHBASlim = NULL;
2801 if (phba->debug_dumpHostSlim) {
2802 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
2803 phba->debug_dumpHostSlim = NULL;
2805 if (phba->debug_dumpData) {
2806 debugfs_remove(phba->debug_dumpData); /* dumpData */
2807 phba->debug_dumpData = NULL;
2810 if (phba->debug_dumpDif) {
2811 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
2812 phba->debug_dumpDif = NULL;
2815 if (phba->slow_ring_trc) {
2816 kfree(phba->slow_ring_trc);
2817 phba->slow_ring_trc = NULL;
2819 if (phba->debug_slow_ring_trc) {
2820 /* slow_ring_trace */
2821 debugfs_remove(phba->debug_slow_ring_trc);
2822 phba->debug_slow_ring_trc = NULL;
2828 if (phba->sli_rev == LPFC_SLI_REV4) {
2829 if (phba->idiag_drb_acc) {
2831 debugfs_remove(phba->idiag_drb_acc);
2832 phba->idiag_drb_acc = NULL;
2834 if (phba->idiag_que_acc) {
2836 debugfs_remove(phba->idiag_que_acc);
2837 phba->idiag_que_acc = NULL;
2839 if (phba->idiag_que_info) {
2841 debugfs_remove(phba->idiag_que_info);
2842 phba->idiag_que_info = NULL;
2844 if (phba->idiag_pci_cfg) {
2846 debugfs_remove(phba->idiag_pci_cfg);
2847 phba->idiag_pci_cfg = NULL;
2850 /* Finally remove the iDiag debugfs root */
2851 if (phba->idiag_root) {
2853 debugfs_remove(phba->idiag_root);
2854 phba->idiag_root = NULL;
2858 if (phba->hba_debugfs_root) {
2859 debugfs_remove(phba->hba_debugfs_root); /* fnX */
2860 phba->hba_debugfs_root = NULL;
2861 atomic_dec(&lpfc_debugfs_hba_count);
2864 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
2865 debugfs_remove(lpfc_debugfs_root); /* lpfc */
2866 lpfc_debugfs_root = NULL;