Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / drivers / scsi / lpfc / lpfc_debugfs.c
blobc1b773e649a4e3e76bb8285630e9ee570ee74462
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. *
6 * www.emulex.com *
7 * *
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/module.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/kthread.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/ctype.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
38 #include "lpfc_hw4.h"
39 #include "lpfc_hw.h"
40 #include "lpfc_sli.h"
41 #include "lpfc_sli4.h"
42 #include "lpfc_nl.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
45 #include "lpfc.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
49 #include "lpfc_version.h"
50 #include "lpfc_compat.h"
51 #include "lpfc_debugfs.h"
52 #include "lpfc_bsg.h"
54 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
56 * debugfs interface
58 * To access this interface the user should:
59 * # mount -t debugfs none /sys/kernel/debug
61 * The lpfc debugfs directory hierarchy is:
62 * /sys/kernel/debug/lpfc/fnX/vportY
63 * where X is the lpfc hba function unique_id
64 * where Y is the vport VPI on that hba
66 * Debugging services available per vport:
67 * discovery_trace
68 * This is an ACSII readable file that contains a trace of the last
69 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
70 * See lpfc_debugfs.h for different categories of discovery events.
71 * To enable the discovery trace, the following module parameters must be set:
72 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
73 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
74 * EACH vport. X MUST also be a power of 2.
75 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
76 * lpfc_debugfs.h .
78 * slow_ring_trace
79 * This is an ACSII readable file that contains a trace of the last
80 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
81 * To enable the slow ring trace, the following module parameters must be set:
82 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
83 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
84 * the HBA. X MUST also be a power of 2.
86 static int lpfc_debugfs_enable = 1;
87 module_param(lpfc_debugfs_enable, int, S_IRUGO);
88 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
90 /* This MUST be a power of 2 */
91 static int lpfc_debugfs_max_disc_trc;
92 module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
93 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
94 "Set debugfs discovery trace depth");
96 /* This MUST be a power of 2 */
97 static int lpfc_debugfs_max_slow_ring_trc;
98 module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
99 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
100 "Set debugfs slow ring trace depth");
102 static int lpfc_debugfs_mask_disc_trc;
103 module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
104 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
105 "Set debugfs discovery trace mask");
107 #include <linux/debugfs.h>
109 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
110 static unsigned long lpfc_debugfs_start_time = 0L;
112 /* iDiag */
113 static struct lpfc_idiag idiag;
116 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
117 * @vport: The vport to gather the log info from.
118 * @buf: The buffer to dump log into.
119 * @size: The maximum amount of data to process.
121 * Description:
122 * This routine gathers the lpfc discovery debugfs data from the @vport and
123 * dumps it to @buf up to @size number of bytes. It will start at the next entry
124 * in the log and process the log until the end of the buffer. Then it will
125 * gather from the beginning of the log and process until the current entry.
127 * Notes:
128 * Discovery logging will be disabled while while this routine dumps the log.
130 * Return Value:
131 * This routine returns the amount of bytes that were dumped into @buf and will
132 * not exceed @size.
134 static int
135 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
137 int i, index, len, enable;
138 uint32_t ms;
139 struct lpfc_debugfs_trc *dtp;
140 char *buffer;
142 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
143 if (!buffer)
144 return 0;
146 enable = lpfc_debugfs_enable;
147 lpfc_debugfs_enable = 0;
149 len = 0;
150 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
151 (lpfc_debugfs_max_disc_trc - 1);
152 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
153 dtp = vport->disc_trc + i;
154 if (!dtp->fmt)
155 continue;
156 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
157 snprintf(buffer,
158 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
159 dtp->seq_cnt, ms, dtp->fmt);
160 len += snprintf(buf+len, size-len, buffer,
161 dtp->data1, dtp->data2, dtp->data3);
163 for (i = 0; i < index; i++) {
164 dtp = vport->disc_trc + i;
165 if (!dtp->fmt)
166 continue;
167 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
168 snprintf(buffer,
169 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
170 dtp->seq_cnt, ms, dtp->fmt);
171 len += snprintf(buf+len, size-len, buffer,
172 dtp->data1, dtp->data2, dtp->data3);
175 lpfc_debugfs_enable = enable;
176 kfree(buffer);
178 return len;
182 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
183 * @phba: The HBA to gather the log info from.
184 * @buf: The buffer to dump log into.
185 * @size: The maximum amount of data to process.
187 * Description:
188 * This routine gathers the lpfc slow ring debugfs data from the @phba and
189 * dumps it to @buf up to @size number of bytes. It will start at the next entry
190 * in the log and process the log until the end of the buffer. Then it will
191 * gather from the beginning of the log and process until the current entry.
193 * Notes:
194 * Slow ring logging will be disabled while while this routine dumps the log.
196 * Return Value:
197 * This routine returns the amount of bytes that were dumped into @buf and will
198 * not exceed @size.
200 static int
201 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
203 int i, index, len, enable;
204 uint32_t ms;
205 struct lpfc_debugfs_trc *dtp;
206 char *buffer;
208 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
209 if (!buffer)
210 return 0;
212 enable = lpfc_debugfs_enable;
213 lpfc_debugfs_enable = 0;
215 len = 0;
216 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
217 (lpfc_debugfs_max_slow_ring_trc - 1);
218 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
219 dtp = phba->slow_ring_trc + i;
220 if (!dtp->fmt)
221 continue;
222 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
223 snprintf(buffer,
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);
229 for (i = 0; i < index; i++) {
230 dtp = phba->slow_ring_trc + i;
231 if (!dtp->fmt)
232 continue;
233 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
234 snprintf(buffer,
235 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
236 dtp->seq_cnt, ms, dtp->fmt);
237 len += snprintf(buf+len, size-len, buffer,
238 dtp->data1, dtp->data2, dtp->data3);
241 lpfc_debugfs_enable = enable;
242 kfree(buffer);
244 return len;
247 static int lpfc_debugfs_last_hbq = -1;
250 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
251 * @phba: The HBA to gather host buffer info from.
252 * @buf: The buffer to dump log into.
253 * @size: The maximum amount of data to process.
255 * Description:
256 * This routine dumps the host buffer queue info from the @phba to @buf up to
257 * @size number of bytes. A header that describes the current hbq state will be
258 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
259 * until @size bytes have been dumped or all the hbq info has been dumped.
261 * Notes:
262 * This routine will rotate through each configured HBQ each time called.
264 * Return Value:
265 * This routine returns the amount of bytes that were dumped into @buf and will
266 * not exceed @size.
268 static int
269 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
271 int len = 0;
272 int cnt, i, j, found, posted, low;
273 uint32_t phys, raw_index, getidx;
274 struct lpfc_hbq_init *hip;
275 struct hbq_s *hbqs;
276 struct lpfc_hbq_entry *hbqe;
277 struct lpfc_dmabuf *d_buf;
278 struct hbq_dmabuf *hbq_buf;
280 if (phba->sli_rev != 3)
281 return 0;
282 cnt = LPFC_HBQINFO_SIZE;
283 spin_lock_irq(&phba->hbalock);
285 /* toggle between multiple hbqs, if any */
286 i = lpfc_sli_hbq_count();
287 if (i > 1) {
288 lpfc_debugfs_last_hbq++;
289 if (lpfc_debugfs_last_hbq >= i)
290 lpfc_debugfs_last_hbq = 0;
292 else
293 lpfc_debugfs_last_hbq = 0;
295 i = lpfc_debugfs_last_hbq;
297 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
299 hbqs = &phba->hbqs[i];
300 posted = 0;
301 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
302 posted++;
304 hip = lpfc_hbq_defs[i];
305 len += snprintf(buf+len, size-len,
306 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
307 hip->hbq_index, hip->profile, hip->rn,
308 hip->buffer_count, hip->init_count, hip->add_count, posted);
310 raw_index = phba->hbq_get[i];
311 getidx = le32_to_cpu(raw_index);
312 len += snprintf(buf+len, size-len,
313 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
314 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
315 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
317 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
318 for (j=0; j<hbqs->entry_count; j++) {
319 len += snprintf(buf+len, size-len,
320 "%03d: %08x %04x %05x ", j,
321 le32_to_cpu(hbqe->bde.addrLow),
322 le32_to_cpu(hbqe->bde.tus.w),
323 le32_to_cpu(hbqe->buffer_tag));
324 i = 0;
325 found = 0;
327 /* First calculate if slot has an associated posted buffer */
328 low = hbqs->hbqPutIdx - posted;
329 if (low >= 0) {
330 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
331 len += snprintf(buf+len, size-len, "Unused\n");
332 goto skipit;
335 else {
336 if ((j >= hbqs->hbqPutIdx) &&
337 (j < (hbqs->entry_count+low))) {
338 len += snprintf(buf+len, size-len, "Unused\n");
339 goto skipit;
343 /* Get the Buffer info for the posted buffer */
344 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
345 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
346 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
347 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
348 len += snprintf(buf+len, size-len,
349 "Buf%d: %p %06x\n", i,
350 hbq_buf->dbuf.virt, hbq_buf->tag);
351 found = 1;
352 break;
354 i++;
356 if (!found) {
357 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
359 skipit:
360 hbqe++;
361 if (len > LPFC_HBQINFO_SIZE - 54)
362 break;
364 spin_unlock_irq(&phba->hbalock);
365 return len;
368 static int lpfc_debugfs_last_hba_slim_off;
371 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
372 * @phba: The HBA to gather SLIM info from.
373 * @buf: The buffer to dump log into.
374 * @size: The maximum amount of data to process.
376 * Description:
377 * This routine dumps the current contents of HBA SLIM for the HBA associated
378 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
380 * Notes:
381 * This routine will only dump up to 1024 bytes of data each time called and
382 * should be called multiple times to dump the entire HBA SLIM.
384 * Return Value:
385 * This routine returns the amount of bytes that were dumped into @buf and will
386 * not exceed @size.
388 static int
389 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
391 int len = 0;
392 int i, off;
393 uint32_t *ptr;
394 char *buffer;
396 buffer = kmalloc(1024, GFP_KERNEL);
397 if (!buffer)
398 return 0;
400 off = 0;
401 spin_lock_irq(&phba->hbalock);
403 len += snprintf(buf+len, size-len, "HBA SLIM\n");
404 lpfc_memcpy_from_slim(buffer,
405 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
407 ptr = (uint32_t *)&buffer[0];
408 off = lpfc_debugfs_last_hba_slim_off;
410 /* Set it up for the next time */
411 lpfc_debugfs_last_hba_slim_off += 1024;
412 if (lpfc_debugfs_last_hba_slim_off >= 4096)
413 lpfc_debugfs_last_hba_slim_off = 0;
415 i = 1024;
416 while (i > 0) {
417 len += snprintf(buf+len, size-len,
418 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
419 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
420 *(ptr+5), *(ptr+6), *(ptr+7));
421 ptr += 8;
422 i -= (8 * sizeof(uint32_t));
423 off += (8 * sizeof(uint32_t));
426 spin_unlock_irq(&phba->hbalock);
427 kfree(buffer);
429 return len;
433 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
434 * @phba: The HBA to gather Host SLIM info from.
435 * @buf: The buffer to dump log into.
436 * @size: The maximum amount of data to process.
438 * Description:
439 * This routine dumps the current contents of host SLIM for the host associated
440 * with @phba to @buf up to @size bytes of data. The dump will contain the
441 * Mailbox, PCB, Rings, and Registers that are located in host memory.
443 * Return Value:
444 * This routine returns the amount of bytes that were dumped into @buf and will
445 * not exceed @size.
447 static int
448 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
450 int len = 0;
451 int i, off;
452 uint32_t word0, word1, word2, word3;
453 uint32_t *ptr;
454 struct lpfc_pgp *pgpp;
455 struct lpfc_sli *psli = &phba->sli;
456 struct lpfc_sli_ring *pring;
458 off = 0;
459 spin_lock_irq(&phba->hbalock);
461 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
462 ptr = (uint32_t *)phba->slim2p.virt;
463 i = sizeof(MAILBOX_t);
464 while (i > 0) {
465 len += snprintf(buf+len, size-len,
466 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
467 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
468 *(ptr+5), *(ptr+6), *(ptr+7));
469 ptr += 8;
470 i -= (8 * sizeof(uint32_t));
471 off += (8 * sizeof(uint32_t));
474 len += snprintf(buf+len, size-len, "SLIM PCB\n");
475 ptr = (uint32_t *)phba->pcb;
476 i = sizeof(PCB_t);
477 while (i > 0) {
478 len += snprintf(buf+len, size-len,
479 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
480 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
481 *(ptr+5), *(ptr+6), *(ptr+7));
482 ptr += 8;
483 i -= (8 * sizeof(uint32_t));
484 off += (8 * sizeof(uint32_t));
487 for (i = 0; i < 4; i++) {
488 pgpp = &phba->port_gp[i];
489 pring = &psli->ring[i];
490 len += snprintf(buf+len, size-len,
491 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
492 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
493 i, pgpp->cmdGetInx, pring->numCiocb,
494 pring->next_cmdidx, pring->local_getidx,
495 pring->flag, pgpp->rspPutInx, pring->numRiocb);
498 if (phba->sli_rev <= LPFC_SLI_REV3) {
499 word0 = readl(phba->HAregaddr);
500 word1 = readl(phba->CAregaddr);
501 word2 = readl(phba->HSregaddr);
502 word3 = readl(phba->HCregaddr);
503 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
504 "HC:%08x\n", word0, word1, word2, word3);
506 spin_unlock_irq(&phba->hbalock);
507 return len;
511 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
512 * @vport: The vport to gather target node info from.
513 * @buf: The buffer to dump log into.
514 * @size: The maximum amount of data to process.
516 * Description:
517 * This routine dumps the current target node list associated with @vport to
518 * @buf up to @size bytes of data. Each node entry in the dump will contain a
519 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
521 * Return Value:
522 * This routine returns the amount of bytes that were dumped into @buf and will
523 * not exceed @size.
525 static int
526 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
528 int len = 0;
529 int cnt;
530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
531 struct lpfc_nodelist *ndlp;
532 unsigned char *statep, *name;
534 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
536 spin_lock_irq(shost->host_lock);
537 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
538 if (!cnt) {
539 len += snprintf(buf+len, size-len,
540 "Missing Nodelist Entries\n");
541 break;
543 cnt--;
544 switch (ndlp->nlp_state) {
545 case NLP_STE_UNUSED_NODE:
546 statep = "UNUSED";
547 break;
548 case NLP_STE_PLOGI_ISSUE:
549 statep = "PLOGI ";
550 break;
551 case NLP_STE_ADISC_ISSUE:
552 statep = "ADISC ";
553 break;
554 case NLP_STE_REG_LOGIN_ISSUE:
555 statep = "REGLOG";
556 break;
557 case NLP_STE_PRLI_ISSUE:
558 statep = "PRLI ";
559 break;
560 case NLP_STE_UNMAPPED_NODE:
561 statep = "UNMAP ";
562 break;
563 case NLP_STE_MAPPED_NODE:
564 statep = "MAPPED";
565 break;
566 case NLP_STE_NPR_NODE:
567 statep = "NPR ";
568 break;
569 default:
570 statep = "UNKNOWN";
572 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
573 statep, ndlp->nlp_DID);
574 name = (unsigned char *)&ndlp->nlp_portname;
575 len += snprintf(buf+len, size-len,
576 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
577 *name, *(name+1), *(name+2), *(name+3),
578 *(name+4), *(name+5), *(name+6), *(name+7));
579 name = (unsigned char *)&ndlp->nlp_nodename;
580 len += snprintf(buf+len, size-len,
581 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
582 *name, *(name+1), *(name+2), *(name+3),
583 *(name+4), *(name+5), *(name+6), *(name+7));
584 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
585 ndlp->nlp_rpi, ndlp->nlp_flag);
586 if (!ndlp->nlp_type)
587 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
588 if (ndlp->nlp_type & NLP_FC_NODE)
589 len += snprintf(buf+len, size-len, "FC_NODE ");
590 if (ndlp->nlp_type & NLP_FABRIC)
591 len += snprintf(buf+len, size-len, "FABRIC ");
592 if (ndlp->nlp_type & NLP_FCP_TARGET)
593 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
594 ndlp->nlp_sid);
595 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
596 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
597 len += snprintf(buf+len, size-len, "usgmap:%x ",
598 ndlp->nlp_usg_map);
599 len += snprintf(buf+len, size-len, "refcnt:%x",
600 atomic_read(&ndlp->kref.refcount));
601 len += snprintf(buf+len, size-len, "\n");
603 spin_unlock_irq(shost->host_lock);
604 return len;
606 #endif
609 * lpfc_debugfs_disc_trc - Store discovery trace log
610 * @vport: The vport to associate this trace string with for retrieval.
611 * @mask: Log entry classification.
612 * @fmt: Format string to be displayed when dumping the log.
613 * @data1: 1st data parameter to be applied to @fmt.
614 * @data2: 2nd data parameter to be applied to @fmt.
615 * @data3: 3rd data parameter to be applied to @fmt.
617 * Description:
618 * This routine is used by the driver code to add a debugfs log entry to the
619 * discovery trace buffer associated with @vport. Only entries with a @mask that
620 * match the current debugfs discovery mask will be saved. Entries that do not
621 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
622 * printf when displaying the log.
624 inline void
625 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
626 uint32_t data1, uint32_t data2, uint32_t data3)
628 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
629 struct lpfc_debugfs_trc *dtp;
630 int index;
632 if (!(lpfc_debugfs_mask_disc_trc & mask))
633 return;
635 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
636 !vport || !vport->disc_trc)
637 return;
639 index = atomic_inc_return(&vport->disc_trc_cnt) &
640 (lpfc_debugfs_max_disc_trc - 1);
641 dtp = vport->disc_trc + index;
642 dtp->fmt = fmt;
643 dtp->data1 = data1;
644 dtp->data2 = data2;
645 dtp->data3 = data3;
646 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
647 dtp->jif = jiffies;
648 #endif
649 return;
653 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
654 * @phba: The phba to associate this trace string with for retrieval.
655 * @fmt: Format string to be displayed when dumping the log.
656 * @data1: 1st data parameter to be applied to @fmt.
657 * @data2: 2nd data parameter to be applied to @fmt.
658 * @data3: 3rd data parameter to be applied to @fmt.
660 * Description:
661 * This routine is used by the driver code to add a debugfs log entry to the
662 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
663 * @data3 are used like printf when displaying the log.
665 inline void
666 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
667 uint32_t data1, uint32_t data2, uint32_t data3)
669 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
670 struct lpfc_debugfs_trc *dtp;
671 int index;
673 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
674 !phba || !phba->slow_ring_trc)
675 return;
677 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
678 (lpfc_debugfs_max_slow_ring_trc - 1);
679 dtp = phba->slow_ring_trc + index;
680 dtp->fmt = fmt;
681 dtp->data1 = data1;
682 dtp->data2 = data2;
683 dtp->data3 = data3;
684 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
685 dtp->jif = jiffies;
686 #endif
687 return;
690 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
692 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
693 * @inode: The inode pointer that contains a vport pointer.
694 * @file: The file pointer to attach the log output.
696 * Description:
697 * This routine is the entry point for the debugfs open file operation. It gets
698 * the vport from the i_private field in @inode, allocates the necessary buffer
699 * for the log, fills the buffer from the in-memory log for this vport, and then
700 * returns a pointer to that log in the private_data field in @file.
702 * Returns:
703 * This function returns zero if successful. On error it will return an negative
704 * error value.
706 static int
707 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
709 struct lpfc_vport *vport = inode->i_private;
710 struct lpfc_debug *debug;
711 int size;
712 int rc = -ENOMEM;
714 if (!lpfc_debugfs_max_disc_trc) {
715 rc = -ENOSPC;
716 goto out;
719 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
720 if (!debug)
721 goto out;
723 /* Round to page boundary */
724 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
725 size = PAGE_ALIGN(size);
727 debug->buffer = kmalloc(size, GFP_KERNEL);
728 if (!debug->buffer) {
729 kfree(debug);
730 goto out;
733 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
734 file->private_data = debug;
736 rc = 0;
737 out:
738 return rc;
742 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
743 * @inode: The inode pointer that contains a vport pointer.
744 * @file: The file pointer to attach the log output.
746 * Description:
747 * This routine is the entry point for the debugfs open file operation. It gets
748 * the vport from the i_private field in @inode, allocates the necessary buffer
749 * for the log, fills the buffer from the in-memory log for this vport, and then
750 * returns a pointer to that log in the private_data field in @file.
752 * Returns:
753 * This function returns zero if successful. On error it will return an negative
754 * error value.
756 static int
757 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
759 struct lpfc_hba *phba = inode->i_private;
760 struct lpfc_debug *debug;
761 int size;
762 int rc = -ENOMEM;
764 if (!lpfc_debugfs_max_slow_ring_trc) {
765 rc = -ENOSPC;
766 goto out;
769 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
770 if (!debug)
771 goto out;
773 /* Round to page boundary */
774 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
775 size = PAGE_ALIGN(size);
777 debug->buffer = kmalloc(size, GFP_KERNEL);
778 if (!debug->buffer) {
779 kfree(debug);
780 goto out;
783 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
784 file->private_data = debug;
786 rc = 0;
787 out:
788 return rc;
792 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
793 * @inode: The inode pointer that contains a vport pointer.
794 * @file: The file pointer to attach the log output.
796 * Description:
797 * This routine is the entry point for the debugfs open file operation. It gets
798 * the vport from the i_private field in @inode, allocates the necessary buffer
799 * for the log, fills the buffer from the in-memory log for this vport, and then
800 * returns a pointer to that log in the private_data field in @file.
802 * Returns:
803 * This function returns zero if successful. On error it will return an negative
804 * error value.
806 static int
807 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
809 struct lpfc_hba *phba = inode->i_private;
810 struct lpfc_debug *debug;
811 int rc = -ENOMEM;
813 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
814 if (!debug)
815 goto out;
817 /* Round to page boundary */
818 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
819 if (!debug->buffer) {
820 kfree(debug);
821 goto out;
824 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
825 LPFC_HBQINFO_SIZE);
826 file->private_data = debug;
828 rc = 0;
829 out:
830 return rc;
834 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
835 * @inode: The inode pointer that contains a vport pointer.
836 * @file: The file pointer to attach the log output.
838 * Description:
839 * This routine is the entry point for the debugfs open file operation. It gets
840 * the vport from the i_private field in @inode, allocates the necessary buffer
841 * for the log, fills the buffer from the in-memory log for this vport, and then
842 * returns a pointer to that log in the private_data field in @file.
844 * Returns:
845 * This function returns zero if successful. On error it will return an negative
846 * error value.
848 static int
849 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
851 struct lpfc_hba *phba = inode->i_private;
852 struct lpfc_debug *debug;
853 int rc = -ENOMEM;
855 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
856 if (!debug)
857 goto out;
859 /* Round to page boundary */
860 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
861 if (!debug->buffer) {
862 kfree(debug);
863 goto out;
866 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
867 LPFC_DUMPHBASLIM_SIZE);
868 file->private_data = debug;
870 rc = 0;
871 out:
872 return rc;
876 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
877 * @inode: The inode pointer that contains a vport pointer.
878 * @file: The file pointer to attach the log output.
880 * Description:
881 * This routine is the entry point for the debugfs open file operation. It gets
882 * the vport from the i_private field in @inode, allocates the necessary buffer
883 * for the log, fills the buffer from the in-memory log for this vport, and then
884 * returns a pointer to that log in the private_data field in @file.
886 * Returns:
887 * This function returns zero if successful. On error it will return an negative
888 * error value.
890 static int
891 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
893 struct lpfc_hba *phba = inode->i_private;
894 struct lpfc_debug *debug;
895 int rc = -ENOMEM;
897 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
898 if (!debug)
899 goto out;
901 /* Round to page boundary */
902 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
903 if (!debug->buffer) {
904 kfree(debug);
905 goto out;
908 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
909 LPFC_DUMPHOSTSLIM_SIZE);
910 file->private_data = debug;
912 rc = 0;
913 out:
914 return rc;
917 static int
918 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
920 struct lpfc_debug *debug;
921 int rc = -ENOMEM;
923 if (!_dump_buf_data)
924 return -EBUSY;
926 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
927 if (!debug)
928 goto out;
930 /* Round to page boundary */
931 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
932 __func__, _dump_buf_data);
933 debug->buffer = _dump_buf_data;
934 if (!debug->buffer) {
935 kfree(debug);
936 goto out;
939 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
940 file->private_data = debug;
942 rc = 0;
943 out:
944 return rc;
947 static int
948 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
950 struct lpfc_debug *debug;
951 int rc = -ENOMEM;
953 if (!_dump_buf_dif)
954 return -EBUSY;
956 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
957 if (!debug)
958 goto out;
960 /* Round to page boundary */
961 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
962 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
963 debug->buffer = _dump_buf_dif;
964 if (!debug->buffer) {
965 kfree(debug);
966 goto out;
969 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
970 file->private_data = debug;
972 rc = 0;
973 out:
974 return rc;
977 static ssize_t
978 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
979 size_t nbytes, loff_t *ppos)
982 * The Data/DIF buffers only save one failing IO
983 * The write op is used as a reset mechanism after an IO has
984 * already been saved to the next one can be saved
986 spin_lock(&_dump_buf_lock);
988 memset((void *)_dump_buf_data, 0,
989 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
990 memset((void *)_dump_buf_dif, 0,
991 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
993 _dump_buf_done = 0;
995 spin_unlock(&_dump_buf_lock);
997 return nbytes;
1001 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1002 * @inode: The inode pointer that contains a vport pointer.
1003 * @file: The file pointer to attach the log output.
1005 * Description:
1006 * This routine is the entry point for the debugfs open file operation. It gets
1007 * the vport from the i_private field in @inode, allocates the necessary buffer
1008 * for the log, fills the buffer from the in-memory log for this vport, and then
1009 * returns a pointer to that log in the private_data field in @file.
1011 * Returns:
1012 * This function returns zero if successful. On error it will return an negative
1013 * error value.
1015 static int
1016 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1018 struct lpfc_vport *vport = inode->i_private;
1019 struct lpfc_debug *debug;
1020 int rc = -ENOMEM;
1022 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1023 if (!debug)
1024 goto out;
1026 /* Round to page boundary */
1027 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1028 if (!debug->buffer) {
1029 kfree(debug);
1030 goto out;
1033 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1034 LPFC_NODELIST_SIZE);
1035 file->private_data = debug;
1037 rc = 0;
1038 out:
1039 return rc;
1043 * lpfc_debugfs_lseek - Seek through a debugfs file
1044 * @file: The file pointer to seek through.
1045 * @off: The offset to seek to or the amount to seek by.
1046 * @whence: Indicates how to seek.
1048 * Description:
1049 * This routine is the entry point for the debugfs lseek file operation. The
1050 * @whence parameter indicates whether @off is the offset to directly seek to,
1051 * or if it is a value to seek forward or reverse by. This function figures out
1052 * what the new offset of the debugfs file will be and assigns that value to the
1053 * f_pos field of @file.
1055 * Returns:
1056 * This function returns the new offset if successful and returns a negative
1057 * error if unable to process the seek.
1059 static loff_t
1060 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1062 struct lpfc_debug *debug;
1063 loff_t pos = -1;
1065 debug = file->private_data;
1067 switch (whence) {
1068 case 0:
1069 pos = off;
1070 break;
1071 case 1:
1072 pos = file->f_pos + off;
1073 break;
1074 case 2:
1075 pos = debug->len - off;
1077 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1081 * lpfc_debugfs_read - Read a debugfs file
1082 * @file: The file pointer to read from.
1083 * @buf: The buffer to copy the data to.
1084 * @nbytes: The number of bytes to read.
1085 * @ppos: The position in the file to start reading from.
1087 * Description:
1088 * This routine reads data from from the buffer indicated in the private_data
1089 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1090 * data to @buf.
1092 * Returns:
1093 * This function returns the amount of data that was read (this could be less
1094 * than @nbytes if the end of the file was reached) or a negative error value.
1096 static ssize_t
1097 lpfc_debugfs_read(struct file *file, char __user *buf,
1098 size_t nbytes, loff_t *ppos)
1100 struct lpfc_debug *debug = file->private_data;
1102 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1103 debug->len);
1107 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1108 * @inode: The inode pointer that contains a vport pointer. (unused)
1109 * @file: The file pointer that contains the buffer to release.
1111 * Description:
1112 * This routine frees the buffer that was allocated when the debugfs file was
1113 * opened.
1115 * Returns:
1116 * This function returns zero.
1118 static int
1119 lpfc_debugfs_release(struct inode *inode, struct file *file)
1121 struct lpfc_debug *debug = file->private_data;
1123 kfree(debug->buffer);
1124 kfree(debug);
1126 return 0;
1129 static int
1130 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1132 struct lpfc_debug *debug = file->private_data;
1134 debug->buffer = NULL;
1135 kfree(debug);
1137 return 0;
1141 * ---------------------------------
1142 * iDiag debugfs file access methods
1143 * ---------------------------------
1145 * All access methods are through the proper SLI4 PCI function's debugfs
1146 * iDiag directory:
1148 * /sys/kernel/debug/lpfc/fn<#>/iDiag
1152 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1153 * @buf: The pointer to the user space buffer.
1154 * @nbytes: The number of bytes in the user space buffer.
1155 * @idiag_cmd: pointer to the idiag command struct.
1157 * This routine reads data from debugfs user space buffer and parses the
1158 * buffer for getting the idiag command and arguments. The while space in
1159 * between the set of data is used as the parsing separator.
1161 * This routine returns 0 when successful, it returns proper error code
1162 * back to the user space in error conditions.
1164 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1165 struct lpfc_idiag_cmd *idiag_cmd)
1167 char mybuf[64];
1168 char *pbuf, *step_str;
1169 int i;
1170 size_t bsize;
1172 /* Protect copy from user */
1173 if (!access_ok(VERIFY_READ, buf, nbytes))
1174 return -EFAULT;
1176 memset(mybuf, 0, sizeof(mybuf));
1177 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1178 bsize = min(nbytes, (sizeof(mybuf)-1));
1180 if (copy_from_user(mybuf, buf, bsize))
1181 return -EFAULT;
1182 pbuf = &mybuf[0];
1183 step_str = strsep(&pbuf, "\t ");
1185 /* The opcode must present */
1186 if (!step_str)
1187 return -EINVAL;
1189 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1190 if (idiag_cmd->opcode == 0)
1191 return -EINVAL;
1193 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1194 step_str = strsep(&pbuf, "\t ");
1195 if (!step_str)
1196 return i;
1197 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1199 return i;
1203 * lpfc_idiag_open - idiag open debugfs
1204 * @inode: The inode pointer that contains a pointer to phba.
1205 * @file: The file pointer to attach the file operation.
1207 * Description:
1208 * This routine is the entry point for the debugfs open file operation. It
1209 * gets the reference to phba from the i_private field in @inode, it then
1210 * allocates buffer for the file operation, performs the necessary PCI config
1211 * space read into the allocated buffer according to the idiag user command
1212 * setup, and then returns a pointer to buffer in the private_data field in
1213 * @file.
1215 * Returns:
1216 * This function returns zero if successful. On error it will return an
1217 * negative error value.
1219 static int
1220 lpfc_idiag_open(struct inode *inode, struct file *file)
1222 struct lpfc_debug *debug;
1224 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1225 if (!debug)
1226 return -ENOMEM;
1228 debug->i_private = inode->i_private;
1229 debug->buffer = NULL;
1230 file->private_data = debug;
1232 return 0;
1236 * lpfc_idiag_release - Release idiag access file operation
1237 * @inode: The inode pointer that contains a vport pointer. (unused)
1238 * @file: The file pointer that contains the buffer to release.
1240 * Description:
1241 * This routine is the generic release routine for the idiag access file
1242 * operation, it frees the buffer that was allocated when the debugfs file
1243 * was opened.
1245 * Returns:
1246 * This function returns zero.
1248 static int
1249 lpfc_idiag_release(struct inode *inode, struct file *file)
1251 struct lpfc_debug *debug = file->private_data;
1253 /* Free the buffers to the file operation */
1254 kfree(debug->buffer);
1255 kfree(debug);
1257 return 0;
1261 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1262 * @inode: The inode pointer that contains a vport pointer. (unused)
1263 * @file: The file pointer that contains the buffer to release.
1265 * Description:
1266 * This routine frees the buffer that was allocated when the debugfs file
1267 * was opened. It also reset the fields in the idiag command struct in the
1268 * case of command for write operation.
1270 * Returns:
1271 * This function returns zero.
1273 static int
1274 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1276 struct lpfc_debug *debug = file->private_data;
1278 if (debug->op == LPFC_IDIAG_OP_WR) {
1279 switch (idiag.cmd.opcode) {
1280 case LPFC_IDIAG_CMD_PCICFG_WR:
1281 case LPFC_IDIAG_CMD_PCICFG_ST:
1282 case LPFC_IDIAG_CMD_PCICFG_CL:
1283 case LPFC_IDIAG_CMD_QUEACC_WR:
1284 case LPFC_IDIAG_CMD_QUEACC_ST:
1285 case LPFC_IDIAG_CMD_QUEACC_CL:
1286 memset(&idiag, 0, sizeof(idiag));
1287 break;
1288 default:
1289 break;
1293 /* Free the buffers to the file operation */
1294 kfree(debug->buffer);
1295 kfree(debug);
1297 return 0;
1301 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1302 * @file: The file pointer to read from.
1303 * @buf: The buffer to copy the data to.
1304 * @nbytes: The number of bytes to read.
1305 * @ppos: The position in the file to start reading from.
1307 * Description:
1308 * This routine reads data from the @phba pci config space according to the
1309 * idiag command, and copies to user @buf. Depending on the PCI config space
1310 * read command setup, it does either a single register read of a byte
1311 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1312 * registers from the 4K extended PCI config space.
1314 * Returns:
1315 * This function returns the amount of data that was read (this could be less
1316 * than @nbytes if the end of the file was reached) or a negative error value.
1318 static ssize_t
1319 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1320 loff_t *ppos)
1322 struct lpfc_debug *debug = file->private_data;
1323 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1324 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1325 int where, count;
1326 char *pbuffer;
1327 struct pci_dev *pdev;
1328 uint32_t u32val;
1329 uint16_t u16val;
1330 uint8_t u8val;
1332 pdev = phba->pcidev;
1333 if (!pdev)
1334 return 0;
1336 /* This is a user read operation */
1337 debug->op = LPFC_IDIAG_OP_RD;
1339 if (!debug->buffer)
1340 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1341 if (!debug->buffer)
1342 return 0;
1343 pbuffer = debug->buffer;
1345 if (*ppos)
1346 return 0;
1348 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1349 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1350 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1351 } else
1352 return 0;
1354 /* Read single PCI config space register */
1355 switch (count) {
1356 case SIZE_U8: /* byte (8 bits) */
1357 pci_read_config_byte(pdev, where, &u8val);
1358 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1359 "%03x: %02x\n", where, u8val);
1360 break;
1361 case SIZE_U16: /* word (16 bits) */
1362 pci_read_config_word(pdev, where, &u16val);
1363 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1364 "%03x: %04x\n", where, u16val);
1365 break;
1366 case SIZE_U32: /* double word (32 bits) */
1367 pci_read_config_dword(pdev, where, &u32val);
1368 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1369 "%03x: %08x\n", where, u32val);
1370 break;
1371 case LPFC_PCI_CFG_BROWSE: /* browse all */
1372 goto pcicfg_browse;
1373 break;
1374 default:
1375 /* illegal count */
1376 len = 0;
1377 break;
1379 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1381 pcicfg_browse:
1383 /* Browse all PCI config space registers */
1384 offset_label = idiag.offset.last_rd;
1385 offset = offset_label;
1387 /* Read PCI config space */
1388 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1389 "%03x: ", offset_label);
1390 while (index > 0) {
1391 pci_read_config_dword(pdev, offset, &u32val);
1392 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1393 "%08x ", u32val);
1394 offset += sizeof(uint32_t);
1395 if (offset >= LPFC_PCI_CFG_SIZE) {
1396 len += snprintf(pbuffer+len,
1397 LPFC_PCI_CFG_SIZE-len, "\n");
1398 break;
1400 index -= sizeof(uint32_t);
1401 if (!index)
1402 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1403 "\n");
1404 else if (!(index % (8 * sizeof(uint32_t)))) {
1405 offset_label += (8 * sizeof(uint32_t));
1406 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1407 "\n%03x: ", offset_label);
1411 /* Set up the offset for next portion of pci cfg read */
1412 if (index == 0) {
1413 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1414 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1415 idiag.offset.last_rd = 0;
1416 } else
1417 idiag.offset.last_rd = 0;
1419 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1423 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1424 * @file: The file pointer to read from.
1425 * @buf: The buffer to copy the user data from.
1426 * @nbytes: The number of bytes to get.
1427 * @ppos: The position in the file to start reading from.
1429 * This routine get the debugfs idiag command struct from user space and
1430 * then perform the syntax check for PCI config space read or write command
1431 * accordingly. In the case of PCI config space read command, it sets up
1432 * the command in the idiag command struct for the debugfs read operation.
1433 * In the case of PCI config space write operation, it executes the write
1434 * operation into the PCI config space accordingly.
1436 * It returns the @nbytges passing in from debugfs user space when successful.
1437 * In case of error conditions, it returns proper error code back to the user
1438 * space.
1440 static ssize_t
1441 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1442 size_t nbytes, loff_t *ppos)
1444 struct lpfc_debug *debug = file->private_data;
1445 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1446 uint32_t where, value, count;
1447 uint32_t u32val;
1448 uint16_t u16val;
1449 uint8_t u8val;
1450 struct pci_dev *pdev;
1451 int rc;
1453 pdev = phba->pcidev;
1454 if (!pdev)
1455 return -EFAULT;
1457 /* This is a user write operation */
1458 debug->op = LPFC_IDIAG_OP_WR;
1460 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1461 if (rc < 0)
1462 return rc;
1464 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1465 /* Sanity check on PCI config read command line arguments */
1466 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1467 goto error_out;
1468 /* Read command from PCI config space, set up command fields */
1469 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1470 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1471 if (count == LPFC_PCI_CFG_BROWSE) {
1472 if (where % sizeof(uint32_t))
1473 goto error_out;
1474 /* Starting offset to browse */
1475 idiag.offset.last_rd = where;
1476 } else if ((count != sizeof(uint8_t)) &&
1477 (count != sizeof(uint16_t)) &&
1478 (count != sizeof(uint32_t)))
1479 goto error_out;
1480 if (count == sizeof(uint8_t)) {
1481 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1482 goto error_out;
1483 if (where % sizeof(uint8_t))
1484 goto error_out;
1486 if (count == sizeof(uint16_t)) {
1487 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1488 goto error_out;
1489 if (where % sizeof(uint16_t))
1490 goto error_out;
1492 if (count == sizeof(uint32_t)) {
1493 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1494 goto error_out;
1495 if (where % sizeof(uint32_t))
1496 goto error_out;
1498 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1499 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1500 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1501 /* Sanity check on PCI config write command line arguments */
1502 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1503 goto error_out;
1504 /* Write command to PCI config space, read-modify-write */
1505 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1506 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1507 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
1508 /* Sanity checks */
1509 if ((count != sizeof(uint8_t)) &&
1510 (count != sizeof(uint16_t)) &&
1511 (count != sizeof(uint32_t)))
1512 goto error_out;
1513 if (count == sizeof(uint8_t)) {
1514 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1515 goto error_out;
1516 if (where % sizeof(uint8_t))
1517 goto error_out;
1518 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1519 pci_write_config_byte(pdev, where,
1520 (uint8_t)value);
1521 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1522 rc = pci_read_config_byte(pdev, where, &u8val);
1523 if (!rc) {
1524 u8val |= (uint8_t)value;
1525 pci_write_config_byte(pdev, where,
1526 u8val);
1529 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1530 rc = pci_read_config_byte(pdev, where, &u8val);
1531 if (!rc) {
1532 u8val &= (uint8_t)(~value);
1533 pci_write_config_byte(pdev, where,
1534 u8val);
1538 if (count == sizeof(uint16_t)) {
1539 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1540 goto error_out;
1541 if (where % sizeof(uint16_t))
1542 goto error_out;
1543 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1544 pci_write_config_word(pdev, where,
1545 (uint16_t)value);
1546 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1547 rc = pci_read_config_word(pdev, where, &u16val);
1548 if (!rc) {
1549 u16val |= (uint16_t)value;
1550 pci_write_config_word(pdev, where,
1551 u16val);
1554 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1555 rc = pci_read_config_word(pdev, where, &u16val);
1556 if (!rc) {
1557 u16val &= (uint16_t)(~value);
1558 pci_write_config_word(pdev, where,
1559 u16val);
1563 if (count == sizeof(uint32_t)) {
1564 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1565 goto error_out;
1566 if (where % sizeof(uint32_t))
1567 goto error_out;
1568 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1569 pci_write_config_dword(pdev, where, value);
1570 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1571 rc = pci_read_config_dword(pdev, where,
1572 &u32val);
1573 if (!rc) {
1574 u32val |= value;
1575 pci_write_config_dword(pdev, where,
1576 u32val);
1579 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1580 rc = pci_read_config_dword(pdev, where,
1581 &u32val);
1582 if (!rc) {
1583 u32val &= ~value;
1584 pci_write_config_dword(pdev, where,
1585 u32val);
1589 } else
1590 /* All other opecodes are illegal for now */
1591 goto error_out;
1593 return nbytes;
1594 error_out:
1595 memset(&idiag, 0, sizeof(idiag));
1596 return -EINVAL;
1600 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1601 * @file: The file pointer to read from.
1602 * @buf: The buffer to copy the data to.
1603 * @nbytes: The number of bytes to read.
1604 * @ppos: The position in the file to start reading from.
1606 * Description:
1607 * This routine reads data from the @phba pci bar memory mapped space
1608 * according to the idiag command, and copies to user @buf.
1610 * Returns:
1611 * This function returns the amount of data that was read (this could be less
1612 * than @nbytes if the end of the file was reached) or a negative error value.
1614 static ssize_t
1615 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1616 loff_t *ppos)
1618 struct lpfc_debug *debug = file->private_data;
1619 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1620 int offset_label, offset, offset_run, len = 0, index;
1621 int bar_num, acc_range, bar_size;
1622 char *pbuffer;
1623 void __iomem *mem_mapped_bar;
1624 uint32_t if_type;
1625 struct pci_dev *pdev;
1626 uint32_t u32val;
1628 pdev = phba->pcidev;
1629 if (!pdev)
1630 return 0;
1632 /* This is a user read operation */
1633 debug->op = LPFC_IDIAG_OP_RD;
1635 if (!debug->buffer)
1636 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1637 if (!debug->buffer)
1638 return 0;
1639 pbuffer = debug->buffer;
1641 if (*ppos)
1642 return 0;
1644 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1645 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1646 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1647 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1648 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1649 } else
1650 return 0;
1652 if (acc_range == 0)
1653 return 0;
1655 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1656 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1657 if (bar_num == IDIAG_BARACC_BAR_0)
1658 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1659 else if (bar_num == IDIAG_BARACC_BAR_1)
1660 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1661 else if (bar_num == IDIAG_BARACC_BAR_2)
1662 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1663 else
1664 return 0;
1665 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1666 if (bar_num == IDIAG_BARACC_BAR_0)
1667 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1668 else
1669 return 0;
1670 } else
1671 return 0;
1673 /* Read single PCI bar space register */
1674 if (acc_range == SINGLE_WORD) {
1675 offset_run = offset;
1676 u32val = readl(mem_mapped_bar + offset_run);
1677 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1678 "%05x: %08x\n", offset_run, u32val);
1679 } else
1680 goto baracc_browse;
1682 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1684 baracc_browse:
1686 /* Browse all PCI bar space registers */
1687 offset_label = idiag.offset.last_rd;
1688 offset_run = offset_label;
1690 /* Read PCI bar memory mapped space */
1691 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1692 "%05x: ", offset_label);
1693 index = LPFC_PCI_BAR_RD_SIZE;
1694 while (index > 0) {
1695 u32val = readl(mem_mapped_bar + offset_run);
1696 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1697 "%08x ", u32val);
1698 offset_run += sizeof(uint32_t);
1699 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1700 if (offset_run >= bar_size) {
1701 len += snprintf(pbuffer+len,
1702 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1703 break;
1705 } else {
1706 if (offset_run >= offset +
1707 (acc_range * sizeof(uint32_t))) {
1708 len += snprintf(pbuffer+len,
1709 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1710 break;
1713 index -= sizeof(uint32_t);
1714 if (!index)
1715 len += snprintf(pbuffer+len,
1716 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1717 else if (!(index % (8 * sizeof(uint32_t)))) {
1718 offset_label += (8 * sizeof(uint32_t));
1719 len += snprintf(pbuffer+len,
1720 LPFC_PCI_BAR_RD_BUF_SIZE-len,
1721 "\n%05x: ", offset_label);
1725 /* Set up the offset for next portion of pci bar read */
1726 if (index == 0) {
1727 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1728 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1729 if (idiag.offset.last_rd >= bar_size)
1730 idiag.offset.last_rd = 0;
1731 } else {
1732 if (offset_run >= offset +
1733 (acc_range * sizeof(uint32_t)))
1734 idiag.offset.last_rd = offset;
1736 } else {
1737 if (acc_range == LPFC_PCI_BAR_BROWSE)
1738 idiag.offset.last_rd = 0;
1739 else
1740 idiag.offset.last_rd = offset;
1743 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1747 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1748 * @file: The file pointer to read from.
1749 * @buf: The buffer to copy the user data from.
1750 * @nbytes: The number of bytes to get.
1751 * @ppos: The position in the file to start reading from.
1753 * This routine get the debugfs idiag command struct from user space and
1754 * then perform the syntax check for PCI bar memory mapped space read or
1755 * write command accordingly. In the case of PCI bar memory mapped space
1756 * read command, it sets up the command in the idiag command struct for
1757 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1758 * write operation, it executes the write operation into the PCI bar memory
1759 * mapped space accordingly.
1761 * It returns the @nbytges passing in from debugfs user space when successful.
1762 * In case of error conditions, it returns proper error code back to the user
1763 * space.
1765 static ssize_t
1766 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1767 size_t nbytes, loff_t *ppos)
1769 struct lpfc_debug *debug = file->private_data;
1770 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1771 uint32_t bar_num, bar_size, offset, value, acc_range;
1772 struct pci_dev *pdev;
1773 void __iomem *mem_mapped_bar;
1774 uint32_t if_type;
1775 uint32_t u32val;
1776 int rc;
1778 pdev = phba->pcidev;
1779 if (!pdev)
1780 return -EFAULT;
1782 /* This is a user write operation */
1783 debug->op = LPFC_IDIAG_OP_WR;
1785 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1786 if (rc < 0)
1787 return rc;
1789 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1790 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1792 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1793 if ((bar_num != IDIAG_BARACC_BAR_0) &&
1794 (bar_num != IDIAG_BARACC_BAR_1) &&
1795 (bar_num != IDIAG_BARACC_BAR_2))
1796 goto error_out;
1797 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1798 if (bar_num != IDIAG_BARACC_BAR_0)
1799 goto error_out;
1800 } else
1801 goto error_out;
1803 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1804 if (bar_num == IDIAG_BARACC_BAR_0) {
1805 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1806 LPFC_PCI_IF0_BAR0_SIZE;
1807 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1808 } else if (bar_num == IDIAG_BARACC_BAR_1) {
1809 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1810 LPFC_PCI_IF0_BAR1_SIZE;
1811 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1812 } else if (bar_num == IDIAG_BARACC_BAR_2) {
1813 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1814 LPFC_PCI_IF0_BAR2_SIZE;
1815 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1816 } else
1817 goto error_out;
1818 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1819 if (bar_num == IDIAG_BARACC_BAR_0) {
1820 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1821 LPFC_PCI_IF2_BAR0_SIZE;
1822 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1823 } else
1824 goto error_out;
1825 } else
1826 goto error_out;
1828 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1829 if (offset % sizeof(uint32_t))
1830 goto error_out;
1832 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1833 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1834 /* Sanity check on PCI config read command line arguments */
1835 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1836 goto error_out;
1837 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1838 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1839 if (offset > bar_size - sizeof(uint32_t))
1840 goto error_out;
1841 /* Starting offset to browse */
1842 idiag.offset.last_rd = offset;
1843 } else if (acc_range > SINGLE_WORD) {
1844 if (offset + acc_range * sizeof(uint32_t) > bar_size)
1845 goto error_out;
1846 /* Starting offset to browse */
1847 idiag.offset.last_rd = offset;
1848 } else if (acc_range != SINGLE_WORD)
1849 goto error_out;
1850 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1851 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1852 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1853 /* Sanity check on PCI bar write command line arguments */
1854 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1855 goto error_out;
1856 /* Write command to PCI bar space, read-modify-write */
1857 acc_range = SINGLE_WORD;
1858 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1859 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1860 writel(value, mem_mapped_bar + offset);
1861 readl(mem_mapped_bar + offset);
1863 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1864 u32val = readl(mem_mapped_bar + offset);
1865 u32val |= value;
1866 writel(u32val, mem_mapped_bar + offset);
1867 readl(mem_mapped_bar + offset);
1869 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1870 u32val = readl(mem_mapped_bar + offset);
1871 u32val &= ~value;
1872 writel(u32val, mem_mapped_bar + offset);
1873 readl(mem_mapped_bar + offset);
1875 } else
1876 /* All other opecodes are illegal for now */
1877 goto error_out;
1879 return nbytes;
1880 error_out:
1881 memset(&idiag, 0, sizeof(idiag));
1882 return -EINVAL;
1886 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1887 * @file: The file pointer to read from.
1888 * @buf: The buffer to copy the data to.
1889 * @nbytes: The number of bytes to read.
1890 * @ppos: The position in the file to start reading from.
1892 * Description:
1893 * This routine reads data from the @phba SLI4 PCI function queue information,
1894 * and copies to user @buf.
1896 * Returns:
1897 * This function returns the amount of data that was read (this could be less
1898 * than @nbytes if the end of the file was reached) or a negative error value.
1900 static ssize_t
1901 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
1902 loff_t *ppos)
1904 struct lpfc_debug *debug = file->private_data;
1905 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1906 int len = 0, fcp_qidx;
1907 char *pbuffer;
1909 if (!debug->buffer)
1910 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
1911 if (!debug->buffer)
1912 return 0;
1913 pbuffer = debug->buffer;
1915 if (*ppos)
1916 return 0;
1918 /* Get slow-path event queue information */
1919 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1920 "Slow-path EQ information:\n");
1921 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1922 "\tEQID[%02d], "
1923 "QE-COUNT[%04d], QE-SIZE[%04d], "
1924 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1925 phba->sli4_hba.sp_eq->queue_id,
1926 phba->sli4_hba.sp_eq->entry_count,
1927 phba->sli4_hba.sp_eq->entry_size,
1928 phba->sli4_hba.sp_eq->host_index,
1929 phba->sli4_hba.sp_eq->hba_index);
1931 /* Get fast-path event queue information */
1932 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1933 "Fast-path EQ information:\n");
1934 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
1935 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1936 "\tEQID[%02d], "
1937 "QE-COUNT[%04d], QE-SIZE[%04d], "
1938 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1939 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
1940 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
1941 phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
1942 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
1943 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
1945 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1947 /* Get mailbox complete queue information */
1948 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1949 "Slow-path MBX CQ information:\n");
1950 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1951 "Associated EQID[%02d]:\n",
1952 phba->sli4_hba.mbx_cq->assoc_qid);
1953 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1954 "\tCQID[%02d], "
1955 "QE-COUNT[%04d], QE-SIZE[%04d], "
1956 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1957 phba->sli4_hba.mbx_cq->queue_id,
1958 phba->sli4_hba.mbx_cq->entry_count,
1959 phba->sli4_hba.mbx_cq->entry_size,
1960 phba->sli4_hba.mbx_cq->host_index,
1961 phba->sli4_hba.mbx_cq->hba_index);
1963 /* Get slow-path complete queue information */
1964 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1965 "Slow-path ELS CQ information:\n");
1966 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1967 "Associated EQID[%02d]:\n",
1968 phba->sli4_hba.els_cq->assoc_qid);
1969 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1970 "\tCQID [%02d], "
1971 "QE-COUNT[%04d], QE-SIZE[%04d], "
1972 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1973 phba->sli4_hba.els_cq->queue_id,
1974 phba->sli4_hba.els_cq->entry_count,
1975 phba->sli4_hba.els_cq->entry_size,
1976 phba->sli4_hba.els_cq->host_index,
1977 phba->sli4_hba.els_cq->hba_index);
1979 /* Get fast-path complete queue information */
1980 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1981 "Fast-path FCP CQ information:\n");
1982 fcp_qidx = 0;
1983 do {
1984 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1985 "Associated EQID[%02d]:\n",
1986 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
1987 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1988 "\tCQID[%02d], "
1989 "QE-COUNT[%04d], QE-SIZE[%04d], "
1990 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1991 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
1992 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
1993 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
1994 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
1995 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
1996 } while (++fcp_qidx < phba->cfg_fcp_eq_count);
1997 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1999 /* Get mailbox queue information */
2000 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2001 "Slow-path MBX MQ information:\n");
2002 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2003 "Associated CQID[%02d]:\n",
2004 phba->sli4_hba.mbx_wq->assoc_qid);
2005 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2006 "\tWQID[%02d], "
2007 "QE-COUNT[%04d], QE-SIZE[%04d], "
2008 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2009 phba->sli4_hba.mbx_wq->queue_id,
2010 phba->sli4_hba.mbx_wq->entry_count,
2011 phba->sli4_hba.mbx_wq->entry_size,
2012 phba->sli4_hba.mbx_wq->host_index,
2013 phba->sli4_hba.mbx_wq->hba_index);
2015 /* Get slow-path work queue information */
2016 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2017 "Slow-path ELS WQ information:\n");
2018 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2019 "Associated CQID[%02d]:\n",
2020 phba->sli4_hba.els_wq->assoc_qid);
2021 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2022 "\tWQID[%02d], "
2023 "QE-COUNT[%04d], QE-SIZE[%04d], "
2024 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2025 phba->sli4_hba.els_wq->queue_id,
2026 phba->sli4_hba.els_wq->entry_count,
2027 phba->sli4_hba.els_wq->entry_size,
2028 phba->sli4_hba.els_wq->host_index,
2029 phba->sli4_hba.els_wq->hba_index);
2031 /* Get fast-path work queue information */
2032 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2033 "Fast-path FCP WQ information:\n");
2034 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
2035 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2036 "Associated CQID[%02d]:\n",
2037 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
2038 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2039 "\tWQID[%02d], "
2040 "QE-COUNT[%04d], WQE-SIZE[%04d], "
2041 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2042 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
2043 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
2044 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
2045 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
2046 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
2048 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2050 /* Get receive queue information */
2051 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2052 "Slow-path RQ information:\n");
2053 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2054 "Associated CQID[%02d]:\n",
2055 phba->sli4_hba.hdr_rq->assoc_qid);
2056 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2057 "\tHQID[%02d], "
2058 "QE-COUNT[%04d], QE-SIZE[%04d], "
2059 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2060 phba->sli4_hba.hdr_rq->queue_id,
2061 phba->sli4_hba.hdr_rq->entry_count,
2062 phba->sli4_hba.hdr_rq->entry_size,
2063 phba->sli4_hba.hdr_rq->host_index,
2064 phba->sli4_hba.hdr_rq->hba_index);
2065 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2066 "\tDQID[%02d], "
2067 "QE-COUNT[%04d], QE-SIZE[%04d], "
2068 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2069 phba->sli4_hba.dat_rq->queue_id,
2070 phba->sli4_hba.dat_rq->entry_count,
2071 phba->sli4_hba.dat_rq->entry_size,
2072 phba->sli4_hba.dat_rq->host_index,
2073 phba->sli4_hba.dat_rq->hba_index);
2075 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2079 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2080 * @q: The pointer to queue structure.
2081 * @index: The index into a queue entry.
2082 * @count: The number of queue entries to access.
2084 * Description:
2085 * The routine performs sanity check on device queue access method commands.
2087 * Returns:
2088 * This function returns -EINVAL when fails the sanity check, otherwise, it
2089 * returns 0.
2091 static int
2092 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
2094 /* Only support single entry read or browsing */
2095 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
2096 return -EINVAL;
2097 if (index > q->entry_count - 1)
2098 return -EINVAL;
2099 return 0;
2103 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2104 * @pbuffer: The pointer to buffer to copy the read data into.
2105 * @pque: The pointer to the queue to be read.
2106 * @index: The index into the queue entry.
2108 * Description:
2109 * This routine reads out a single entry from the given queue's index location
2110 * and copies it into the buffer provided.
2112 * Returns:
2113 * This function returns 0 when it fails, otherwise, it returns the length of
2114 * the data read into the buffer provided.
2116 static int
2117 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
2118 uint32_t index)
2120 int offset, esize;
2121 uint32_t *pentry;
2123 if (!pbuffer || !pque)
2124 return 0;
2126 esize = pque->entry_size;
2127 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2128 "QE-INDEX[%04d]:\n", index);
2130 offset = 0;
2131 pentry = pque->qe[index].address;
2132 while (esize > 0) {
2133 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2134 "%08x ", *pentry);
2135 pentry++;
2136 offset += sizeof(uint32_t);
2137 esize -= sizeof(uint32_t);
2138 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
2139 len += snprintf(pbuffer+len,
2140 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2142 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2144 return len;
2148 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2149 * @file: The file pointer to read from.
2150 * @buf: The buffer to copy the data to.
2151 * @nbytes: The number of bytes to read.
2152 * @ppos: The position in the file to start reading from.
2154 * Description:
2155 * This routine reads data from the @phba device queue memory according to the
2156 * idiag command, and copies to user @buf. Depending on the queue dump read
2157 * command setup, it does either a single queue entry read or browing through
2158 * all entries of the queue.
2160 * Returns:
2161 * This function returns the amount of data that was read (this could be less
2162 * than @nbytes if the end of the file was reached) or a negative error value.
2164 static ssize_t
2165 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
2166 loff_t *ppos)
2168 struct lpfc_debug *debug = file->private_data;
2169 uint32_t last_index, index, count;
2170 struct lpfc_queue *pque = NULL;
2171 char *pbuffer;
2172 int len = 0;
2174 /* This is a user read operation */
2175 debug->op = LPFC_IDIAG_OP_RD;
2177 if (!debug->buffer)
2178 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
2179 if (!debug->buffer)
2180 return 0;
2181 pbuffer = debug->buffer;
2183 if (*ppos)
2184 return 0;
2186 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2187 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2188 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2189 pque = (struct lpfc_queue *)idiag.ptr_private;
2190 } else
2191 return 0;
2193 /* Browse the queue starting from index */
2194 if (count == LPFC_QUE_ACC_BROWSE)
2195 goto que_browse;
2197 /* Read a single entry from the queue */
2198 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2200 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2202 que_browse:
2204 /* Browse all entries from the queue */
2205 last_index = idiag.offset.last_rd;
2206 index = last_index;
2208 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
2209 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2210 index++;
2211 if (index > pque->entry_count - 1)
2212 break;
2215 /* Set up the offset for next portion of pci cfg read */
2216 if (index > pque->entry_count - 1)
2217 index = 0;
2218 idiag.offset.last_rd = index;
2220 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2224 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2225 * @file: The file pointer to read from.
2226 * @buf: The buffer to copy the user data from.
2227 * @nbytes: The number of bytes to get.
2228 * @ppos: The position in the file to start reading from.
2230 * This routine get the debugfs idiag command struct from user space and then
2231 * perform the syntax check for port queue read (dump) or write (set) command
2232 * accordingly. In the case of port queue read command, it sets up the command
2233 * in the idiag command struct for the following debugfs read operation. In
2234 * the case of port queue write operation, it executes the write operation
2235 * into the port queue entry accordingly.
2237 * It returns the @nbytges passing in from debugfs user space when successful.
2238 * In case of error conditions, it returns proper error code back to the user
2239 * space.
2241 static ssize_t
2242 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
2243 size_t nbytes, loff_t *ppos)
2245 struct lpfc_debug *debug = file->private_data;
2246 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2247 uint32_t qidx, quetp, queid, index, count, offset, value;
2248 uint32_t *pentry;
2249 struct lpfc_queue *pque;
2250 int rc;
2252 /* This is a user write operation */
2253 debug->op = LPFC_IDIAG_OP_WR;
2255 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2256 if (rc < 0)
2257 return rc;
2259 /* Get and sanity check on command feilds */
2260 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
2261 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
2262 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2263 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2264 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
2265 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
2267 /* Sanity check on command line arguments */
2268 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2269 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2270 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2271 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
2272 goto error_out;
2273 if (count != 1)
2274 goto error_out;
2275 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2276 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
2277 goto error_out;
2278 } else
2279 goto error_out;
2281 switch (quetp) {
2282 case LPFC_IDIAG_EQ:
2283 /* Slow-path event queue */
2284 if (phba->sli4_hba.sp_eq->queue_id == queid) {
2285 /* Sanity check */
2286 rc = lpfc_idiag_que_param_check(
2287 phba->sli4_hba.sp_eq, index, count);
2288 if (rc)
2289 goto error_out;
2290 idiag.ptr_private = phba->sli4_hba.sp_eq;
2291 goto pass_check;
2293 /* Fast-path event queue */
2294 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
2295 if (phba->sli4_hba.fp_eq[qidx]->queue_id == queid) {
2296 /* Sanity check */
2297 rc = lpfc_idiag_que_param_check(
2298 phba->sli4_hba.fp_eq[qidx],
2299 index, count);
2300 if (rc)
2301 goto error_out;
2302 idiag.ptr_private = phba->sli4_hba.fp_eq[qidx];
2303 goto pass_check;
2306 goto error_out;
2307 break;
2308 case LPFC_IDIAG_CQ:
2309 /* MBX complete queue */
2310 if (phba->sli4_hba.mbx_cq->queue_id == queid) {
2311 /* Sanity check */
2312 rc = lpfc_idiag_que_param_check(
2313 phba->sli4_hba.mbx_cq, index, count);
2314 if (rc)
2315 goto error_out;
2316 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2317 goto pass_check;
2319 /* ELS complete queue */
2320 if (phba->sli4_hba.els_cq->queue_id == queid) {
2321 /* Sanity check */
2322 rc = lpfc_idiag_que_param_check(
2323 phba->sli4_hba.els_cq, index, count);
2324 if (rc)
2325 goto error_out;
2326 idiag.ptr_private = phba->sli4_hba.els_cq;
2327 goto pass_check;
2329 /* FCP complete queue */
2330 qidx = 0;
2331 do {
2332 if (phba->sli4_hba.fcp_cq[qidx]->queue_id == queid) {
2333 /* Sanity check */
2334 rc = lpfc_idiag_que_param_check(
2335 phba->sli4_hba.fcp_cq[qidx],
2336 index, count);
2337 if (rc)
2338 goto error_out;
2339 idiag.ptr_private =
2340 phba->sli4_hba.fcp_cq[qidx];
2341 goto pass_check;
2343 } while (++qidx < phba->cfg_fcp_eq_count);
2344 goto error_out;
2345 break;
2346 case LPFC_IDIAG_MQ:
2347 /* MBX work queue */
2348 if (phba->sli4_hba.mbx_wq->queue_id == queid) {
2349 /* Sanity check */
2350 rc = lpfc_idiag_que_param_check(
2351 phba->sli4_hba.mbx_wq, index, count);
2352 if (rc)
2353 goto error_out;
2354 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2355 goto pass_check;
2357 break;
2358 case LPFC_IDIAG_WQ:
2359 /* ELS work queue */
2360 if (phba->sli4_hba.els_wq->queue_id == queid) {
2361 /* Sanity check */
2362 rc = lpfc_idiag_que_param_check(
2363 phba->sli4_hba.els_wq, index, count);
2364 if (rc)
2365 goto error_out;
2366 idiag.ptr_private = phba->sli4_hba.els_wq;
2367 goto pass_check;
2369 /* FCP work queue */
2370 for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
2371 if (phba->sli4_hba.fcp_wq[qidx]->queue_id == queid) {
2372 /* Sanity check */
2373 rc = lpfc_idiag_que_param_check(
2374 phba->sli4_hba.fcp_wq[qidx],
2375 index, count);
2376 if (rc)
2377 goto error_out;
2378 idiag.ptr_private =
2379 phba->sli4_hba.fcp_wq[qidx];
2380 goto pass_check;
2383 goto error_out;
2384 break;
2385 case LPFC_IDIAG_RQ:
2386 /* HDR queue */
2387 if (phba->sli4_hba.hdr_rq->queue_id == queid) {
2388 /* Sanity check */
2389 rc = lpfc_idiag_que_param_check(
2390 phba->sli4_hba.hdr_rq, index, count);
2391 if (rc)
2392 goto error_out;
2393 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2394 goto pass_check;
2396 /* DAT queue */
2397 if (phba->sli4_hba.dat_rq->queue_id == queid) {
2398 /* Sanity check */
2399 rc = lpfc_idiag_que_param_check(
2400 phba->sli4_hba.dat_rq, index, count);
2401 if (rc)
2402 goto error_out;
2403 idiag.ptr_private = phba->sli4_hba.dat_rq;
2404 goto pass_check;
2406 goto error_out;
2407 break;
2408 default:
2409 goto error_out;
2410 break;
2413 pass_check:
2415 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2416 if (count == LPFC_QUE_ACC_BROWSE)
2417 idiag.offset.last_rd = index;
2420 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2421 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2422 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2423 /* Additional sanity checks on write operation */
2424 pque = (struct lpfc_queue *)idiag.ptr_private;
2425 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2426 goto error_out;
2427 pentry = pque->qe[index].address;
2428 pentry += offset;
2429 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2430 *pentry = value;
2431 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2432 *pentry |= value;
2433 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2434 *pentry &= ~value;
2436 return nbytes;
2438 error_out:
2439 /* Clean out command structure on command error out */
2440 memset(&idiag, 0, sizeof(idiag));
2441 return -EINVAL;
2445 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2446 * @phba: The pointer to hba structure.
2447 * @pbuffer: The pointer to the buffer to copy the data to.
2448 * @len: The lenght of bytes to copied.
2449 * @drbregid: The id to doorbell registers.
2451 * Description:
2452 * This routine reads a doorbell register and copies its content to the
2453 * user buffer pointed to by @pbuffer.
2455 * Returns:
2456 * This function returns the amount of data that was copied into @pbuffer.
2458 static int
2459 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2460 int len, uint32_t drbregid)
2463 if (!pbuffer)
2464 return 0;
2466 switch (drbregid) {
2467 case LPFC_DRB_EQCQ:
2468 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2469 "EQCQ-DRB-REG: 0x%08x\n",
2470 readl(phba->sli4_hba.EQCQDBregaddr));
2471 break;
2472 case LPFC_DRB_MQ:
2473 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2474 "MQ-DRB-REG: 0x%08x\n",
2475 readl(phba->sli4_hba.MQDBregaddr));
2476 break;
2477 case LPFC_DRB_WQ:
2478 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2479 "WQ-DRB-REG: 0x%08x\n",
2480 readl(phba->sli4_hba.WQDBregaddr));
2481 break;
2482 case LPFC_DRB_RQ:
2483 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2484 "RQ-DRB-REG: 0x%08x\n",
2485 readl(phba->sli4_hba.RQDBregaddr));
2486 break;
2487 default:
2488 break;
2491 return len;
2495 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2496 * @file: The file pointer to read from.
2497 * @buf: The buffer to copy the data to.
2498 * @nbytes: The number of bytes to read.
2499 * @ppos: The position in the file to start reading from.
2501 * Description:
2502 * This routine reads data from the @phba device doorbell register according
2503 * to the idiag command, and copies to user @buf. Depending on the doorbell
2504 * register read command setup, it does either a single doorbell register
2505 * read or dump all doorbell registers.
2507 * Returns:
2508 * This function returns the amount of data that was read (this could be less
2509 * than @nbytes if the end of the file was reached) or a negative error value.
2511 static ssize_t
2512 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2513 loff_t *ppos)
2515 struct lpfc_debug *debug = file->private_data;
2516 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2517 uint32_t drb_reg_id, i;
2518 char *pbuffer;
2519 int len = 0;
2521 /* This is a user read operation */
2522 debug->op = LPFC_IDIAG_OP_RD;
2524 if (!debug->buffer)
2525 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2526 if (!debug->buffer)
2527 return 0;
2528 pbuffer = debug->buffer;
2530 if (*ppos)
2531 return 0;
2533 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
2534 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2535 else
2536 return 0;
2538 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2539 for (i = 1; i <= LPFC_DRB_MAX; i++)
2540 len = lpfc_idiag_drbacc_read_reg(phba,
2541 pbuffer, len, i);
2542 else
2543 len = lpfc_idiag_drbacc_read_reg(phba,
2544 pbuffer, len, drb_reg_id);
2546 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2550 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2551 * @file: The file pointer to read from.
2552 * @buf: The buffer to copy the user data from.
2553 * @nbytes: The number of bytes to get.
2554 * @ppos: The position in the file to start reading from.
2556 * This routine get the debugfs idiag command struct from user space and then
2557 * perform the syntax check for port doorbell register read (dump) or write
2558 * (set) command accordingly. In the case of port queue read command, it sets
2559 * up the command in the idiag command struct for the following debugfs read
2560 * operation. In the case of port doorbell register write operation, it
2561 * executes the write operation into the port doorbell register accordingly.
2563 * It returns the @nbytges passing in from debugfs user space when successful.
2564 * In case of error conditions, it returns proper error code back to the user
2565 * space.
2567 static ssize_t
2568 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2569 size_t nbytes, loff_t *ppos)
2571 struct lpfc_debug *debug = file->private_data;
2572 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2573 uint32_t drb_reg_id, value, reg_val = 0;
2574 void __iomem *drb_reg;
2575 int rc;
2577 /* This is a user write operation */
2578 debug->op = LPFC_IDIAG_OP_WR;
2580 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2581 if (rc < 0)
2582 return rc;
2584 /* Sanity check on command line arguments */
2585 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2586 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
2588 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2589 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2590 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2591 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2592 goto error_out;
2593 if (drb_reg_id > LPFC_DRB_MAX)
2594 goto error_out;
2595 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2596 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2597 goto error_out;
2598 if ((drb_reg_id > LPFC_DRB_MAX) &&
2599 (drb_reg_id != LPFC_DRB_ACC_ALL))
2600 goto error_out;
2601 } else
2602 goto error_out;
2604 /* Perform the write access operation */
2605 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2606 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2607 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2608 switch (drb_reg_id) {
2609 case LPFC_DRB_EQCQ:
2610 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2611 break;
2612 case LPFC_DRB_MQ:
2613 drb_reg = phba->sli4_hba.MQDBregaddr;
2614 break;
2615 case LPFC_DRB_WQ:
2616 drb_reg = phba->sli4_hba.WQDBregaddr;
2617 break;
2618 case LPFC_DRB_RQ:
2619 drb_reg = phba->sli4_hba.RQDBregaddr;
2620 break;
2621 default:
2622 goto error_out;
2625 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2626 reg_val = value;
2627 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2628 reg_val = readl(drb_reg);
2629 reg_val |= value;
2631 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2632 reg_val = readl(drb_reg);
2633 reg_val &= ~value;
2635 writel(reg_val, drb_reg);
2636 readl(drb_reg); /* flush */
2638 return nbytes;
2640 error_out:
2641 /* Clean out command structure on command error out */
2642 memset(&idiag, 0, sizeof(idiag));
2643 return -EINVAL;
2647 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2648 * @phba: The pointer to hba structure.
2649 * @pbuffer: The pointer to the buffer to copy the data to.
2650 * @len: The lenght of bytes to copied.
2651 * @drbregid: The id to doorbell registers.
2653 * Description:
2654 * This routine reads a control register and copies its content to the
2655 * user buffer pointed to by @pbuffer.
2657 * Returns:
2658 * This function returns the amount of data that was copied into @pbuffer.
2660 static int
2661 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2662 int len, uint32_t ctlregid)
2665 if (!pbuffer)
2666 return 0;
2668 switch (ctlregid) {
2669 case LPFC_CTL_PORT_SEM:
2670 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2671 "Port SemReg: 0x%08x\n",
2672 readl(phba->sli4_hba.conf_regs_memmap_p +
2673 LPFC_CTL_PORT_SEM_OFFSET));
2674 break;
2675 case LPFC_CTL_PORT_STA:
2676 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2677 "Port StaReg: 0x%08x\n",
2678 readl(phba->sli4_hba.conf_regs_memmap_p +
2679 LPFC_CTL_PORT_STA_OFFSET));
2680 break;
2681 case LPFC_CTL_PORT_CTL:
2682 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2683 "Port CtlReg: 0x%08x\n",
2684 readl(phba->sli4_hba.conf_regs_memmap_p +
2685 LPFC_CTL_PORT_CTL_OFFSET));
2686 break;
2687 case LPFC_CTL_PORT_ER1:
2688 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2689 "Port Er1Reg: 0x%08x\n",
2690 readl(phba->sli4_hba.conf_regs_memmap_p +
2691 LPFC_CTL_PORT_ER1_OFFSET));
2692 break;
2693 case LPFC_CTL_PORT_ER2:
2694 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2695 "Port Er2Reg: 0x%08x\n",
2696 readl(phba->sli4_hba.conf_regs_memmap_p +
2697 LPFC_CTL_PORT_ER2_OFFSET));
2698 break;
2699 case LPFC_CTL_PDEV_CTL:
2700 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2701 "PDev CtlReg: 0x%08x\n",
2702 readl(phba->sli4_hba.conf_regs_memmap_p +
2703 LPFC_CTL_PDEV_CTL_OFFSET));
2704 break;
2705 default:
2706 break;
2708 return len;
2712 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2713 * @file: The file pointer to read from.
2714 * @buf: The buffer to copy the data to.
2715 * @nbytes: The number of bytes to read.
2716 * @ppos: The position in the file to start reading from.
2718 * Description:
2719 * This routine reads data from the @phba port and device registers according
2720 * to the idiag command, and copies to user @buf.
2722 * Returns:
2723 * This function returns the amount of data that was read (this could be less
2724 * than @nbytes if the end of the file was reached) or a negative error value.
2726 static ssize_t
2727 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2728 loff_t *ppos)
2730 struct lpfc_debug *debug = file->private_data;
2731 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2732 uint32_t ctl_reg_id, i;
2733 char *pbuffer;
2734 int len = 0;
2736 /* This is a user read operation */
2737 debug->op = LPFC_IDIAG_OP_RD;
2739 if (!debug->buffer)
2740 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2741 if (!debug->buffer)
2742 return 0;
2743 pbuffer = debug->buffer;
2745 if (*ppos)
2746 return 0;
2748 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2749 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2750 else
2751 return 0;
2753 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2754 for (i = 1; i <= LPFC_CTL_MAX; i++)
2755 len = lpfc_idiag_ctlacc_read_reg(phba,
2756 pbuffer, len, i);
2757 else
2758 len = lpfc_idiag_ctlacc_read_reg(phba,
2759 pbuffer, len, ctl_reg_id);
2761 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2765 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2766 * @file: The file pointer to read from.
2767 * @buf: The buffer to copy the user data from.
2768 * @nbytes: The number of bytes to get.
2769 * @ppos: The position in the file to start reading from.
2771 * This routine get the debugfs idiag command struct from user space and then
2772 * perform the syntax check for port and device control register read (dump)
2773 * or write (set) command accordingly.
2775 * It returns the @nbytges passing in from debugfs user space when successful.
2776 * In case of error conditions, it returns proper error code back to the user
2777 * space.
2779 static ssize_t
2780 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
2781 size_t nbytes, loff_t *ppos)
2783 struct lpfc_debug *debug = file->private_data;
2784 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2785 uint32_t ctl_reg_id, value, reg_val = 0;
2786 void __iomem *ctl_reg;
2787 int rc;
2789 /* This is a user write operation */
2790 debug->op = LPFC_IDIAG_OP_WR;
2792 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2793 if (rc < 0)
2794 return rc;
2796 /* Sanity check on command line arguments */
2797 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2798 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
2800 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2801 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2802 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2803 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
2804 goto error_out;
2805 if (ctl_reg_id > LPFC_CTL_MAX)
2806 goto error_out;
2807 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
2808 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
2809 goto error_out;
2810 if ((ctl_reg_id > LPFC_CTL_MAX) &&
2811 (ctl_reg_id != LPFC_CTL_ACC_ALL))
2812 goto error_out;
2813 } else
2814 goto error_out;
2816 /* Perform the write access operation */
2817 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2818 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2819 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2820 switch (ctl_reg_id) {
2821 case LPFC_CTL_PORT_SEM:
2822 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2823 LPFC_CTL_PORT_SEM_OFFSET;
2824 break;
2825 case LPFC_CTL_PORT_STA:
2826 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2827 LPFC_CTL_PORT_STA_OFFSET;
2828 break;
2829 case LPFC_CTL_PORT_CTL:
2830 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2831 LPFC_CTL_PORT_CTL_OFFSET;
2832 break;
2833 case LPFC_CTL_PORT_ER1:
2834 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2835 LPFC_CTL_PORT_ER1_OFFSET;
2836 break;
2837 case LPFC_CTL_PORT_ER2:
2838 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2839 LPFC_CTL_PORT_ER2_OFFSET;
2840 break;
2841 case LPFC_CTL_PDEV_CTL:
2842 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2843 LPFC_CTL_PDEV_CTL_OFFSET;
2844 break;
2845 default:
2846 goto error_out;
2849 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
2850 reg_val = value;
2851 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
2852 reg_val = readl(ctl_reg);
2853 reg_val |= value;
2855 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2856 reg_val = readl(ctl_reg);
2857 reg_val &= ~value;
2859 writel(reg_val, ctl_reg);
2860 readl(ctl_reg); /* flush */
2862 return nbytes;
2864 error_out:
2865 /* Clean out command structure on command error out */
2866 memset(&idiag, 0, sizeof(idiag));
2867 return -EINVAL;
2871 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
2872 * @phba: Pointer to HBA context object.
2873 * @pbuffer: Pointer to data buffer.
2875 * Description:
2876 * This routine gets the driver mailbox access debugfs setup information.
2878 * Returns:
2879 * This function returns the amount of data that was read (this could be less
2880 * than @nbytes if the end of the file was reached) or a negative error value.
2882 static int
2883 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
2885 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
2886 int len = 0;
2888 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
2889 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
2890 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
2891 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
2893 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2894 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
2895 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2896 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
2897 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2898 "mbx_word_cnt: %04d\n", mbx_word_cnt);
2899 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
2900 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
2902 return len;
2906 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
2907 * @file: The file pointer to read from.
2908 * @buf: The buffer to copy the data to.
2909 * @nbytes: The number of bytes to read.
2910 * @ppos: The position in the file to start reading from.
2912 * Description:
2913 * This routine reads data from the @phba driver mailbox access debugfs setup
2914 * information.
2916 * Returns:
2917 * This function returns the amount of data that was read (this could be less
2918 * than @nbytes if the end of the file was reached) or a negative error value.
2920 static ssize_t
2921 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
2922 loff_t *ppos)
2924 struct lpfc_debug *debug = file->private_data;
2925 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2926 char *pbuffer;
2927 int len = 0;
2929 /* This is a user read operation */
2930 debug->op = LPFC_IDIAG_OP_RD;
2932 if (!debug->buffer)
2933 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
2934 if (!debug->buffer)
2935 return 0;
2936 pbuffer = debug->buffer;
2938 if (*ppos)
2939 return 0;
2941 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
2942 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
2943 return 0;
2945 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
2947 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2951 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
2952 * @file: The file pointer to read from.
2953 * @buf: The buffer to copy the user data from.
2954 * @nbytes: The number of bytes to get.
2955 * @ppos: The position in the file to start reading from.
2957 * This routine get the debugfs idiag command struct from user space and then
2958 * perform the syntax check for driver mailbox command (dump) and sets up the
2959 * necessary states in the idiag command struct accordingly.
2961 * It returns the @nbytges passing in from debugfs user space when successful.
2962 * In case of error conditions, it returns proper error code back to the user
2963 * space.
2965 static ssize_t
2966 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
2967 size_t nbytes, loff_t *ppos)
2969 struct lpfc_debug *debug = file->private_data;
2970 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
2971 int rc;
2973 /* This is a user write operation */
2974 debug->op = LPFC_IDIAG_OP_WR;
2976 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2977 if (rc < 0)
2978 return rc;
2980 /* Sanity check on command line arguments */
2981 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
2982 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
2983 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
2984 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
2986 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
2987 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
2988 goto error_out;
2989 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
2990 (mbx_dump_map != LPFC_MBX_DMP_ALL))
2991 goto error_out;
2992 if (mbx_word_cnt > sizeof(MAILBOX_t))
2993 goto error_out;
2994 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
2995 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
2996 goto error_out;
2997 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
2998 (mbx_dump_map != LPFC_MBX_DMP_ALL))
2999 goto error_out;
3000 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3001 goto error_out;
3002 if (mbx_mbox_cmd != 0x9b)
3003 goto error_out;
3004 } else
3005 goto error_out;
3007 if (mbx_word_cnt == 0)
3008 goto error_out;
3009 if (rc != LPFC_MBX_DMP_ARG)
3010 goto error_out;
3011 if (mbx_mbox_cmd & ~0xff)
3012 goto error_out;
3014 /* condition for stop mailbox dump */
3015 if (mbx_dump_cnt == 0)
3016 goto reset_out;
3018 return nbytes;
3020 reset_out:
3021 /* Clean out command structure on command error out */
3022 memset(&idiag, 0, sizeof(idiag));
3023 return nbytes;
3025 error_out:
3026 /* Clean out command structure on command error out */
3027 memset(&idiag, 0, sizeof(idiag));
3028 return -EINVAL;
3032 * lpfc_idiag_extacc_avail_get - get the available extents information
3033 * @phba: pointer to lpfc hba data structure.
3034 * @pbuffer: pointer to internal buffer.
3035 * @len: length into the internal buffer data has been copied.
3037 * Description:
3038 * This routine is to get the available extent information.
3040 * Returns:
3041 * overall lenth of the data read into the internal buffer.
3043 static int
3044 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3046 uint16_t ext_cnt, ext_size;
3048 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3049 "\nAvailable Extents Information:\n");
3051 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3052 "\tPort Available VPI extents: ");
3053 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3054 &ext_cnt, &ext_size);
3055 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3056 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3058 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3059 "\tPort Available VFI extents: ");
3060 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3061 &ext_cnt, &ext_size);
3062 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3063 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3065 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3066 "\tPort Available RPI extents: ");
3067 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3068 &ext_cnt, &ext_size);
3069 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3070 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3072 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3073 "\tPort Available XRI extents: ");
3074 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3075 &ext_cnt, &ext_size);
3076 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3077 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3079 return len;
3083 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3084 * @phba: pointer to lpfc hba data structure.
3085 * @pbuffer: pointer to internal buffer.
3086 * @len: length into the internal buffer data has been copied.
3088 * Description:
3089 * This routine is to get the allocated extent information.
3091 * Returns:
3092 * overall lenth of the data read into the internal buffer.
3094 static int
3095 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3097 uint16_t ext_cnt, ext_size;
3098 int rc;
3100 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3101 "\nAllocated Extents Information:\n");
3103 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3104 "\tHost Allocated VPI extents: ");
3105 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
3106 &ext_cnt, &ext_size);
3107 if (!rc)
3108 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3109 "Port %d Extent %3d, Size %3d\n",
3110 phba->brd_no, ext_cnt, ext_size);
3111 else
3112 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3113 "N/A\n");
3115 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3116 "\tHost Allocated VFI extents: ");
3117 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
3118 &ext_cnt, &ext_size);
3119 if (!rc)
3120 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3121 "Port %d Extent %3d, Size %3d\n",
3122 phba->brd_no, ext_cnt, ext_size);
3123 else
3124 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3125 "N/A\n");
3127 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3128 "\tHost Allocated RPI extents: ");
3129 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
3130 &ext_cnt, &ext_size);
3131 if (!rc)
3132 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3133 "Port %d Extent %3d, Size %3d\n",
3134 phba->brd_no, ext_cnt, ext_size);
3135 else
3136 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3137 "N/A\n");
3139 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3140 "\tHost Allocated XRI extents: ");
3141 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
3142 &ext_cnt, &ext_size);
3143 if (!rc)
3144 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3145 "Port %d Extent %3d, Size %3d\n",
3146 phba->brd_no, ext_cnt, ext_size);
3147 else
3148 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3149 "N/A\n");
3151 return len;
3155 * lpfc_idiag_extacc_drivr_get - get driver extent information
3156 * @phba: pointer to lpfc hba data structure.
3157 * @pbuffer: pointer to internal buffer.
3158 * @len: length into the internal buffer data has been copied.
3160 * Description:
3161 * This routine is to get the driver extent information.
3163 * Returns:
3164 * overall lenth of the data read into the internal buffer.
3166 static int
3167 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3169 struct lpfc_rsrc_blks *rsrc_blks;
3170 int index;
3172 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3173 "\nDriver Extents Information:\n");
3175 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3176 "\tVPI extents:\n");
3177 index = 0;
3178 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3179 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3180 "\t\tBlock %3d: Start %4d, Count %4d\n",
3181 index, rsrc_blks->rsrc_start,
3182 rsrc_blks->rsrc_size);
3183 index++;
3185 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3186 "\tVFI extents:\n");
3187 index = 0;
3188 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
3189 list) {
3190 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3191 "\t\tBlock %3d: Start %4d, Count %4d\n",
3192 index, rsrc_blks->rsrc_start,
3193 rsrc_blks->rsrc_size);
3194 index++;
3197 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3198 "\tRPI extents:\n");
3199 index = 0;
3200 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
3201 list) {
3202 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3203 "\t\tBlock %3d: Start %4d, Count %4d\n",
3204 index, rsrc_blks->rsrc_start,
3205 rsrc_blks->rsrc_size);
3206 index++;
3209 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3210 "\tXRI extents:\n");
3211 index = 0;
3212 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
3213 list) {
3214 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3215 "\t\tBlock %3d: Start %4d, Count %4d\n",
3216 index, rsrc_blks->rsrc_start,
3217 rsrc_blks->rsrc_size);
3218 index++;
3221 return len;
3225 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3226 * @file: The file pointer to read from.
3227 * @buf: The buffer to copy the user data from.
3228 * @nbytes: The number of bytes to get.
3229 * @ppos: The position in the file to start reading from.
3231 * This routine get the debugfs idiag command struct from user space and then
3232 * perform the syntax check for extent information access commands and sets
3233 * up the necessary states in the idiag command struct accordingly.
3235 * It returns the @nbytges passing in from debugfs user space when successful.
3236 * In case of error conditions, it returns proper error code back to the user
3237 * space.
3239 static ssize_t
3240 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3241 size_t nbytes, loff_t *ppos)
3243 struct lpfc_debug *debug = file->private_data;
3244 uint32_t ext_map;
3245 int rc;
3247 /* This is a user write operation */
3248 debug->op = LPFC_IDIAG_OP_WR;
3250 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3251 if (rc < 0)
3252 return rc;
3254 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3256 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3257 goto error_out;
3258 if (rc != LPFC_EXT_ACC_CMD_ARG)
3259 goto error_out;
3260 if (!(ext_map & LPFC_EXT_ACC_ALL))
3261 goto error_out;
3263 return nbytes;
3264 error_out:
3265 /* Clean out command structure on command error out */
3266 memset(&idiag, 0, sizeof(idiag));
3267 return -EINVAL;
3271 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3272 * @file: The file pointer to read from.
3273 * @buf: The buffer to copy the data to.
3274 * @nbytes: The number of bytes to read.
3275 * @ppos: The position in the file to start reading from.
3277 * Description:
3278 * This routine reads data from the proper extent information according to
3279 * the idiag command, and copies to user @buf.
3281 * Returns:
3282 * This function returns the amount of data that was read (this could be less
3283 * than @nbytes if the end of the file was reached) or a negative error value.
3285 static ssize_t
3286 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3287 loff_t *ppos)
3289 struct lpfc_debug *debug = file->private_data;
3290 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3291 char *pbuffer;
3292 uint32_t ext_map;
3293 int len = 0;
3295 /* This is a user read operation */
3296 debug->op = LPFC_IDIAG_OP_RD;
3298 if (!debug->buffer)
3299 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3300 if (!debug->buffer)
3301 return 0;
3302 pbuffer = debug->buffer;
3303 if (*ppos)
3304 return 0;
3305 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3306 return 0;
3308 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3309 if (ext_map & LPFC_EXT_ACC_AVAIL)
3310 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3311 if (ext_map & LPFC_EXT_ACC_ALLOC)
3312 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3313 if (ext_map & LPFC_EXT_ACC_DRIVR)
3314 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3316 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3319 #undef lpfc_debugfs_op_disc_trc
3320 static const struct file_operations lpfc_debugfs_op_disc_trc = {
3321 .owner = THIS_MODULE,
3322 .open = lpfc_debugfs_disc_trc_open,
3323 .llseek = lpfc_debugfs_lseek,
3324 .read = lpfc_debugfs_read,
3325 .release = lpfc_debugfs_release,
3328 #undef lpfc_debugfs_op_nodelist
3329 static const struct file_operations lpfc_debugfs_op_nodelist = {
3330 .owner = THIS_MODULE,
3331 .open = lpfc_debugfs_nodelist_open,
3332 .llseek = lpfc_debugfs_lseek,
3333 .read = lpfc_debugfs_read,
3334 .release = lpfc_debugfs_release,
3337 #undef lpfc_debugfs_op_hbqinfo
3338 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
3339 .owner = THIS_MODULE,
3340 .open = lpfc_debugfs_hbqinfo_open,
3341 .llseek = lpfc_debugfs_lseek,
3342 .read = lpfc_debugfs_read,
3343 .release = lpfc_debugfs_release,
3346 #undef lpfc_debugfs_op_dumpHBASlim
3347 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
3348 .owner = THIS_MODULE,
3349 .open = lpfc_debugfs_dumpHBASlim_open,
3350 .llseek = lpfc_debugfs_lseek,
3351 .read = lpfc_debugfs_read,
3352 .release = lpfc_debugfs_release,
3355 #undef lpfc_debugfs_op_dumpHostSlim
3356 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
3357 .owner = THIS_MODULE,
3358 .open = lpfc_debugfs_dumpHostSlim_open,
3359 .llseek = lpfc_debugfs_lseek,
3360 .read = lpfc_debugfs_read,
3361 .release = lpfc_debugfs_release,
3364 #undef lpfc_debugfs_op_dumpData
3365 static const struct file_operations lpfc_debugfs_op_dumpData = {
3366 .owner = THIS_MODULE,
3367 .open = lpfc_debugfs_dumpData_open,
3368 .llseek = lpfc_debugfs_lseek,
3369 .read = lpfc_debugfs_read,
3370 .write = lpfc_debugfs_dumpDataDif_write,
3371 .release = lpfc_debugfs_dumpDataDif_release,
3374 #undef lpfc_debugfs_op_dumpDif
3375 static const struct file_operations lpfc_debugfs_op_dumpDif = {
3376 .owner = THIS_MODULE,
3377 .open = lpfc_debugfs_dumpDif_open,
3378 .llseek = lpfc_debugfs_lseek,
3379 .read = lpfc_debugfs_read,
3380 .write = lpfc_debugfs_dumpDataDif_write,
3381 .release = lpfc_debugfs_dumpDataDif_release,
3384 #undef lpfc_debugfs_op_slow_ring_trc
3385 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
3386 .owner = THIS_MODULE,
3387 .open = lpfc_debugfs_slow_ring_trc_open,
3388 .llseek = lpfc_debugfs_lseek,
3389 .read = lpfc_debugfs_read,
3390 .release = lpfc_debugfs_release,
3393 static struct dentry *lpfc_debugfs_root = NULL;
3394 static atomic_t lpfc_debugfs_hba_count;
3397 * File operations for the iDiag debugfs
3399 #undef lpfc_idiag_op_pciCfg
3400 static const struct file_operations lpfc_idiag_op_pciCfg = {
3401 .owner = THIS_MODULE,
3402 .open = lpfc_idiag_open,
3403 .llseek = lpfc_debugfs_lseek,
3404 .read = lpfc_idiag_pcicfg_read,
3405 .write = lpfc_idiag_pcicfg_write,
3406 .release = lpfc_idiag_cmd_release,
3409 #undef lpfc_idiag_op_barAcc
3410 static const struct file_operations lpfc_idiag_op_barAcc = {
3411 .owner = THIS_MODULE,
3412 .open = lpfc_idiag_open,
3413 .llseek = lpfc_debugfs_lseek,
3414 .read = lpfc_idiag_baracc_read,
3415 .write = lpfc_idiag_baracc_write,
3416 .release = lpfc_idiag_cmd_release,
3419 #undef lpfc_idiag_op_queInfo
3420 static const struct file_operations lpfc_idiag_op_queInfo = {
3421 .owner = THIS_MODULE,
3422 .open = lpfc_idiag_open,
3423 .read = lpfc_idiag_queinfo_read,
3424 .release = lpfc_idiag_release,
3427 #undef lpfc_idiag_op_queAcc
3428 static const struct file_operations lpfc_idiag_op_queAcc = {
3429 .owner = THIS_MODULE,
3430 .open = lpfc_idiag_open,
3431 .llseek = lpfc_debugfs_lseek,
3432 .read = lpfc_idiag_queacc_read,
3433 .write = lpfc_idiag_queacc_write,
3434 .release = lpfc_idiag_cmd_release,
3437 #undef lpfc_idiag_op_drbAcc
3438 static const struct file_operations lpfc_idiag_op_drbAcc = {
3439 .owner = THIS_MODULE,
3440 .open = lpfc_idiag_open,
3441 .llseek = lpfc_debugfs_lseek,
3442 .read = lpfc_idiag_drbacc_read,
3443 .write = lpfc_idiag_drbacc_write,
3444 .release = lpfc_idiag_cmd_release,
3447 #undef lpfc_idiag_op_ctlAcc
3448 static const struct file_operations lpfc_idiag_op_ctlAcc = {
3449 .owner = THIS_MODULE,
3450 .open = lpfc_idiag_open,
3451 .llseek = lpfc_debugfs_lseek,
3452 .read = lpfc_idiag_ctlacc_read,
3453 .write = lpfc_idiag_ctlacc_write,
3454 .release = lpfc_idiag_cmd_release,
3457 #undef lpfc_idiag_op_mbxAcc
3458 static const struct file_operations lpfc_idiag_op_mbxAcc = {
3459 .owner = THIS_MODULE,
3460 .open = lpfc_idiag_open,
3461 .llseek = lpfc_debugfs_lseek,
3462 .read = lpfc_idiag_mbxacc_read,
3463 .write = lpfc_idiag_mbxacc_write,
3464 .release = lpfc_idiag_cmd_release,
3467 #undef lpfc_idiag_op_extAcc
3468 static const struct file_operations lpfc_idiag_op_extAcc = {
3469 .owner = THIS_MODULE,
3470 .open = lpfc_idiag_open,
3471 .llseek = lpfc_debugfs_lseek,
3472 .read = lpfc_idiag_extacc_read,
3473 .write = lpfc_idiag_extacc_write,
3474 .release = lpfc_idiag_cmd_release,
3477 #endif
3479 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3480 * @phba: Pointer to HBA context object.
3481 * @dmabuf: Pointer to a DMA buffer descriptor.
3483 * Description:
3484 * This routine dump a bsg pass-through non-embedded mailbox command with
3485 * external buffer.
3487 void
3488 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3489 enum mbox_type mbox_tp, enum dma_type dma_tp,
3490 enum sta_type sta_tp,
3491 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3493 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3494 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3495 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3496 int len = 0;
3497 uint32_t do_dump = 0;
3498 uint32_t *pword;
3499 uint32_t i;
3501 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3502 return;
3504 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3505 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3506 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3507 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3509 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3510 (*mbx_dump_cnt == 0) ||
3511 (*mbx_word_cnt == 0))
3512 return;
3514 if (*mbx_mbox_cmd != 0x9B)
3515 return;
3517 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3518 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3519 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
3520 printk(KERN_ERR "\nRead mbox command (x%x), "
3521 "nemb:0x%x, extbuf_cnt:%d:\n",
3522 sta_tp, nemb_tp, ext_buf);
3525 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3526 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3527 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
3528 printk(KERN_ERR "\nRead mbox buffer (x%x), "
3529 "nemb:0x%x, extbuf_seq:%d:\n",
3530 sta_tp, nemb_tp, ext_buf);
3533 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3534 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3535 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
3536 printk(KERN_ERR "\nWrite mbox command (x%x), "
3537 "nemb:0x%x, extbuf_cnt:%d:\n",
3538 sta_tp, nemb_tp, ext_buf);
3541 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3542 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3543 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
3544 printk(KERN_ERR "\nWrite mbox buffer (x%x), "
3545 "nemb:0x%x, extbuf_seq:%d:\n",
3546 sta_tp, nemb_tp, ext_buf);
3550 /* dump buffer content */
3551 if (do_dump) {
3552 pword = (uint32_t *)dmabuf->virt;
3553 for (i = 0; i < *mbx_word_cnt; i++) {
3554 if (!(i % 8)) {
3555 if (i != 0)
3556 printk(KERN_ERR "%s\n", line_buf);
3557 len = 0;
3558 len += snprintf(line_buf+len,
3559 LPFC_MBX_ACC_LBUF_SZ-len,
3560 "%03d: ", i);
3562 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3563 "%08x ", (uint32_t)*pword);
3564 pword++;
3566 if ((i - 1) % 8)
3567 printk(KERN_ERR "%s\n", line_buf);
3568 (*mbx_dump_cnt)--;
3571 /* Clean out command structure on reaching dump count */
3572 if (*mbx_dump_cnt == 0)
3573 memset(&idiag, 0, sizeof(idiag));
3574 return;
3575 #endif
3578 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3579 * @phba: Pointer to HBA context object.
3580 * @dmabuf: Pointer to a DMA buffer descriptor.
3582 * Description:
3583 * This routine dump a pass-through non-embedded mailbox command from issue
3584 * mailbox command.
3586 void
3587 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3589 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3590 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3591 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3592 int len = 0;
3593 uint32_t *pword;
3594 uint8_t *pbyte;
3595 uint32_t i, j;
3597 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3598 return;
3600 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3601 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3602 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3603 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3605 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3606 (*mbx_dump_cnt == 0) ||
3607 (*mbx_word_cnt == 0))
3608 return;
3610 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3611 (*mbx_mbox_cmd != pmbox->mbxCommand))
3612 return;
3614 /* dump buffer content */
3615 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
3616 printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
3617 pmbox->mbxCommand);
3618 pword = (uint32_t *)pmbox;
3619 for (i = 0; i < *mbx_word_cnt; i++) {
3620 if (!(i % 8)) {
3621 if (i != 0)
3622 printk(KERN_ERR "%s\n", line_buf);
3623 len = 0;
3624 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3625 len += snprintf(line_buf+len,
3626 LPFC_MBX_ACC_LBUF_SZ-len,
3627 "%03d: ", i);
3629 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3630 "%08x ",
3631 ((uint32_t)*pword) & 0xffffffff);
3632 pword++;
3634 if ((i - 1) % 8)
3635 printk(KERN_ERR "%s\n", line_buf);
3636 printk(KERN_ERR "\n");
3638 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
3639 printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
3640 pmbox->mbxCommand);
3641 pbyte = (uint8_t *)pmbox;
3642 for (i = 0; i < *mbx_word_cnt; i++) {
3643 if (!(i % 8)) {
3644 if (i != 0)
3645 printk(KERN_ERR "%s\n", line_buf);
3646 len = 0;
3647 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3648 len += snprintf(line_buf+len,
3649 LPFC_MBX_ACC_LBUF_SZ-len,
3650 "%03d: ", i);
3652 for (j = 0; j < 4; j++) {
3653 len += snprintf(line_buf+len,
3654 LPFC_MBX_ACC_LBUF_SZ-len,
3655 "%02x",
3656 ((uint8_t)*pbyte) & 0xff);
3657 pbyte++;
3659 len += snprintf(line_buf+len,
3660 LPFC_MBX_ACC_LBUF_SZ-len, " ");
3662 if ((i - 1) % 8)
3663 printk(KERN_ERR "%s\n", line_buf);
3664 printk(KERN_ERR "\n");
3666 (*mbx_dump_cnt)--;
3668 /* Clean out command structure on reaching dump count */
3669 if (*mbx_dump_cnt == 0)
3670 memset(&idiag, 0, sizeof(idiag));
3671 return;
3672 #endif
3676 * lpfc_debugfs_initialize - Initialize debugfs for a vport
3677 * @vport: The vport pointer to initialize.
3679 * Description:
3680 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3681 * If not already created, this routine will create the lpfc directory, and
3682 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3683 * also create each file used to access lpfc specific debugfs information.
3685 inline void
3686 lpfc_debugfs_initialize(struct lpfc_vport *vport)
3688 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3689 struct lpfc_hba *phba = vport->phba;
3690 char name[64];
3691 uint32_t num, i;
3693 if (!lpfc_debugfs_enable)
3694 return;
3696 /* Setup lpfc root directory */
3697 if (!lpfc_debugfs_root) {
3698 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
3699 atomic_set(&lpfc_debugfs_hba_count, 0);
3700 if (!lpfc_debugfs_root) {
3701 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3702 "0408 Cannot create debugfs root\n");
3703 goto debug_failed;
3706 if (!lpfc_debugfs_start_time)
3707 lpfc_debugfs_start_time = jiffies;
3709 /* Setup funcX directory for specific HBA PCI function */
3710 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
3711 if (!phba->hba_debugfs_root) {
3712 phba->hba_debugfs_root =
3713 debugfs_create_dir(name, lpfc_debugfs_root);
3714 if (!phba->hba_debugfs_root) {
3715 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3716 "0412 Cannot create debugfs hba\n");
3717 goto debug_failed;
3719 atomic_inc(&lpfc_debugfs_hba_count);
3720 atomic_set(&phba->debugfs_vport_count, 0);
3722 /* Setup hbqinfo */
3723 snprintf(name, sizeof(name), "hbqinfo");
3724 phba->debug_hbqinfo =
3725 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3726 phba->hba_debugfs_root,
3727 phba, &lpfc_debugfs_op_hbqinfo);
3728 if (!phba->debug_hbqinfo) {
3729 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3730 "0411 Cannot create debugfs hbqinfo\n");
3731 goto debug_failed;
3734 /* Setup dumpHBASlim */
3735 if (phba->sli_rev < LPFC_SLI_REV4) {
3736 snprintf(name, sizeof(name), "dumpHBASlim");
3737 phba->debug_dumpHBASlim =
3738 debugfs_create_file(name,
3739 S_IFREG|S_IRUGO|S_IWUSR,
3740 phba->hba_debugfs_root,
3741 phba, &lpfc_debugfs_op_dumpHBASlim);
3742 if (!phba->debug_dumpHBASlim) {
3743 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3744 "0413 Cannot create debugfs "
3745 "dumpHBASlim\n");
3746 goto debug_failed;
3748 } else
3749 phba->debug_dumpHBASlim = NULL;
3751 /* Setup dumpHostSlim */
3752 if (phba->sli_rev < LPFC_SLI_REV4) {
3753 snprintf(name, sizeof(name), "dumpHostSlim");
3754 phba->debug_dumpHostSlim =
3755 debugfs_create_file(name,
3756 S_IFREG|S_IRUGO|S_IWUSR,
3757 phba->hba_debugfs_root,
3758 phba, &lpfc_debugfs_op_dumpHostSlim);
3759 if (!phba->debug_dumpHostSlim) {
3760 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3761 "0414 Cannot create debugfs "
3762 "dumpHostSlim\n");
3763 goto debug_failed;
3765 } else
3766 phba->debug_dumpHBASlim = NULL;
3768 /* Setup dumpData */
3769 snprintf(name, sizeof(name), "dumpData");
3770 phba->debug_dumpData =
3771 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3772 phba->hba_debugfs_root,
3773 phba, &lpfc_debugfs_op_dumpData);
3774 if (!phba->debug_dumpData) {
3775 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3776 "0800 Cannot create debugfs dumpData\n");
3777 goto debug_failed;
3780 /* Setup dumpDif */
3781 snprintf(name, sizeof(name), "dumpDif");
3782 phba->debug_dumpDif =
3783 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3784 phba->hba_debugfs_root,
3785 phba, &lpfc_debugfs_op_dumpDif);
3786 if (!phba->debug_dumpDif) {
3787 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3788 "0801 Cannot create debugfs dumpDif\n");
3789 goto debug_failed;
3792 /* Setup slow ring trace */
3793 if (lpfc_debugfs_max_slow_ring_trc) {
3794 num = lpfc_debugfs_max_slow_ring_trc - 1;
3795 if (num & lpfc_debugfs_max_slow_ring_trc) {
3796 /* Change to be a power of 2 */
3797 num = lpfc_debugfs_max_slow_ring_trc;
3798 i = 0;
3799 while (num > 1) {
3800 num = num >> 1;
3801 i++;
3803 lpfc_debugfs_max_slow_ring_trc = (1 << i);
3804 printk(KERN_ERR
3805 "lpfc_debugfs_max_disc_trc changed to "
3806 "%d\n", lpfc_debugfs_max_disc_trc);
3810 snprintf(name, sizeof(name), "slow_ring_trace");
3811 phba->debug_slow_ring_trc =
3812 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3813 phba->hba_debugfs_root,
3814 phba, &lpfc_debugfs_op_slow_ring_trc);
3815 if (!phba->debug_slow_ring_trc) {
3816 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3817 "0415 Cannot create debugfs "
3818 "slow_ring_trace\n");
3819 goto debug_failed;
3821 if (!phba->slow_ring_trc) {
3822 phba->slow_ring_trc = kmalloc(
3823 (sizeof(struct lpfc_debugfs_trc) *
3824 lpfc_debugfs_max_slow_ring_trc),
3825 GFP_KERNEL);
3826 if (!phba->slow_ring_trc) {
3827 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3828 "0416 Cannot create debugfs "
3829 "slow_ring buffer\n");
3830 goto debug_failed;
3832 atomic_set(&phba->slow_ring_trc_cnt, 0);
3833 memset(phba->slow_ring_trc, 0,
3834 (sizeof(struct lpfc_debugfs_trc) *
3835 lpfc_debugfs_max_slow_ring_trc));
3839 snprintf(name, sizeof(name), "vport%d", vport->vpi);
3840 if (!vport->vport_debugfs_root) {
3841 vport->vport_debugfs_root =
3842 debugfs_create_dir(name, phba->hba_debugfs_root);
3843 if (!vport->vport_debugfs_root) {
3844 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3845 "0417 Can't create debugfs\n");
3846 goto debug_failed;
3848 atomic_inc(&phba->debugfs_vport_count);
3851 if (lpfc_debugfs_max_disc_trc) {
3852 num = lpfc_debugfs_max_disc_trc - 1;
3853 if (num & lpfc_debugfs_max_disc_trc) {
3854 /* Change to be a power of 2 */
3855 num = lpfc_debugfs_max_disc_trc;
3856 i = 0;
3857 while (num > 1) {
3858 num = num >> 1;
3859 i++;
3861 lpfc_debugfs_max_disc_trc = (1 << i);
3862 printk(KERN_ERR
3863 "lpfc_debugfs_max_disc_trc changed to %d\n",
3864 lpfc_debugfs_max_disc_trc);
3868 vport->disc_trc = kzalloc(
3869 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
3870 GFP_KERNEL);
3872 if (!vport->disc_trc) {
3873 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3874 "0418 Cannot create debugfs disc trace "
3875 "buffer\n");
3876 goto debug_failed;
3878 atomic_set(&vport->disc_trc_cnt, 0);
3880 snprintf(name, sizeof(name), "discovery_trace");
3881 vport->debug_disc_trc =
3882 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3883 vport->vport_debugfs_root,
3884 vport, &lpfc_debugfs_op_disc_trc);
3885 if (!vport->debug_disc_trc) {
3886 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3887 "0419 Cannot create debugfs "
3888 "discovery_trace\n");
3889 goto debug_failed;
3891 snprintf(name, sizeof(name), "nodelist");
3892 vport->debug_nodelist =
3893 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3894 vport->vport_debugfs_root,
3895 vport, &lpfc_debugfs_op_nodelist);
3896 if (!vport->debug_nodelist) {
3897 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3898 "2985 Can't create debugfs nodelist\n");
3899 goto debug_failed;
3903 * iDiag debugfs root entry points for SLI4 device only
3905 if (phba->sli_rev < LPFC_SLI_REV4)
3906 goto debug_failed;
3908 snprintf(name, sizeof(name), "iDiag");
3909 if (!phba->idiag_root) {
3910 phba->idiag_root =
3911 debugfs_create_dir(name, phba->hba_debugfs_root);
3912 if (!phba->idiag_root) {
3913 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3914 "2922 Can't create idiag debugfs\n");
3915 goto debug_failed;
3917 /* Initialize iDiag data structure */
3918 memset(&idiag, 0, sizeof(idiag));
3921 /* iDiag read PCI config space */
3922 snprintf(name, sizeof(name), "pciCfg");
3923 if (!phba->idiag_pci_cfg) {
3924 phba->idiag_pci_cfg =
3925 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3926 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
3927 if (!phba->idiag_pci_cfg) {
3928 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3929 "2923 Can't create idiag debugfs\n");
3930 goto debug_failed;
3932 idiag.offset.last_rd = 0;
3935 /* iDiag PCI BAR access */
3936 snprintf(name, sizeof(name), "barAcc");
3937 if (!phba->idiag_bar_acc) {
3938 phba->idiag_bar_acc =
3939 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3940 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
3941 if (!phba->idiag_bar_acc) {
3942 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3943 "3056 Can't create idiag debugfs\n");
3944 goto debug_failed;
3946 idiag.offset.last_rd = 0;
3949 /* iDiag get PCI function queue information */
3950 snprintf(name, sizeof(name), "queInfo");
3951 if (!phba->idiag_que_info) {
3952 phba->idiag_que_info =
3953 debugfs_create_file(name, S_IFREG|S_IRUGO,
3954 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
3955 if (!phba->idiag_que_info) {
3956 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3957 "2924 Can't create idiag debugfs\n");
3958 goto debug_failed;
3962 /* iDiag access PCI function queue */
3963 snprintf(name, sizeof(name), "queAcc");
3964 if (!phba->idiag_que_acc) {
3965 phba->idiag_que_acc =
3966 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3967 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
3968 if (!phba->idiag_que_acc) {
3969 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3970 "2926 Can't create idiag debugfs\n");
3971 goto debug_failed;
3975 /* iDiag access PCI function doorbell registers */
3976 snprintf(name, sizeof(name), "drbAcc");
3977 if (!phba->idiag_drb_acc) {
3978 phba->idiag_drb_acc =
3979 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3980 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
3981 if (!phba->idiag_drb_acc) {
3982 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3983 "2927 Can't create idiag debugfs\n");
3984 goto debug_failed;
3988 /* iDiag access PCI function control registers */
3989 snprintf(name, sizeof(name), "ctlAcc");
3990 if (!phba->idiag_ctl_acc) {
3991 phba->idiag_ctl_acc =
3992 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3993 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
3994 if (!phba->idiag_ctl_acc) {
3995 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3996 "2981 Can't create idiag debugfs\n");
3997 goto debug_failed;
4001 /* iDiag access mbox commands */
4002 snprintf(name, sizeof(name), "mbxAcc");
4003 if (!phba->idiag_mbx_acc) {
4004 phba->idiag_mbx_acc =
4005 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4006 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
4007 if (!phba->idiag_mbx_acc) {
4008 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4009 "2980 Can't create idiag debugfs\n");
4010 goto debug_failed;
4014 /* iDiag extents access commands */
4015 if (phba->sli4_hba.extents_in_use) {
4016 snprintf(name, sizeof(name), "extAcc");
4017 if (!phba->idiag_ext_acc) {
4018 phba->idiag_ext_acc =
4019 debugfs_create_file(name,
4020 S_IFREG|S_IRUGO|S_IWUSR,
4021 phba->idiag_root, phba,
4022 &lpfc_idiag_op_extAcc);
4023 if (!phba->idiag_ext_acc) {
4024 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4025 "2986 Cant create "
4026 "idiag debugfs\n");
4027 goto debug_failed;
4032 debug_failed:
4033 return;
4034 #endif
4038 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
4039 * @vport: The vport pointer to remove from debugfs.
4041 * Description:
4042 * When Debugfs is configured this routine removes debugfs file system elements
4043 * that are specific to this vport. It also checks to see if there are any
4044 * users left for the debugfs directories associated with the HBA and driver. If
4045 * this is the last user of the HBA directory or driver directory then it will
4046 * remove those from the debugfs infrastructure as well.
4048 inline void
4049 lpfc_debugfs_terminate(struct lpfc_vport *vport)
4051 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4052 struct lpfc_hba *phba = vport->phba;
4054 if (vport->disc_trc) {
4055 kfree(vport->disc_trc);
4056 vport->disc_trc = NULL;
4058 if (vport->debug_disc_trc) {
4059 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
4060 vport->debug_disc_trc = NULL;
4062 if (vport->debug_nodelist) {
4063 debugfs_remove(vport->debug_nodelist); /* nodelist */
4064 vport->debug_nodelist = NULL;
4066 if (vport->vport_debugfs_root) {
4067 debugfs_remove(vport->vport_debugfs_root); /* vportX */
4068 vport->vport_debugfs_root = NULL;
4069 atomic_dec(&phba->debugfs_vport_count);
4071 if (atomic_read(&phba->debugfs_vport_count) == 0) {
4073 if (phba->debug_hbqinfo) {
4074 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
4075 phba->debug_hbqinfo = NULL;
4077 if (phba->debug_dumpHBASlim) {
4078 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
4079 phba->debug_dumpHBASlim = NULL;
4081 if (phba->debug_dumpHostSlim) {
4082 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
4083 phba->debug_dumpHostSlim = NULL;
4085 if (phba->debug_dumpData) {
4086 debugfs_remove(phba->debug_dumpData); /* dumpData */
4087 phba->debug_dumpData = NULL;
4090 if (phba->debug_dumpDif) {
4091 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
4092 phba->debug_dumpDif = NULL;
4095 if (phba->slow_ring_trc) {
4096 kfree(phba->slow_ring_trc);
4097 phba->slow_ring_trc = NULL;
4099 if (phba->debug_slow_ring_trc) {
4100 /* slow_ring_trace */
4101 debugfs_remove(phba->debug_slow_ring_trc);
4102 phba->debug_slow_ring_trc = NULL;
4106 * iDiag release
4108 if (phba->sli_rev == LPFC_SLI_REV4) {
4109 if (phba->idiag_ext_acc) {
4110 /* iDiag extAcc */
4111 debugfs_remove(phba->idiag_ext_acc);
4112 phba->idiag_ext_acc = NULL;
4114 if (phba->idiag_mbx_acc) {
4115 /* iDiag mbxAcc */
4116 debugfs_remove(phba->idiag_mbx_acc);
4117 phba->idiag_mbx_acc = NULL;
4119 if (phba->idiag_ctl_acc) {
4120 /* iDiag ctlAcc */
4121 debugfs_remove(phba->idiag_ctl_acc);
4122 phba->idiag_ctl_acc = NULL;
4124 if (phba->idiag_drb_acc) {
4125 /* iDiag drbAcc */
4126 debugfs_remove(phba->idiag_drb_acc);
4127 phba->idiag_drb_acc = NULL;
4129 if (phba->idiag_que_acc) {
4130 /* iDiag queAcc */
4131 debugfs_remove(phba->idiag_que_acc);
4132 phba->idiag_que_acc = NULL;
4134 if (phba->idiag_que_info) {
4135 /* iDiag queInfo */
4136 debugfs_remove(phba->idiag_que_info);
4137 phba->idiag_que_info = NULL;
4139 if (phba->idiag_bar_acc) {
4140 /* iDiag barAcc */
4141 debugfs_remove(phba->idiag_bar_acc);
4142 phba->idiag_bar_acc = NULL;
4144 if (phba->idiag_pci_cfg) {
4145 /* iDiag pciCfg */
4146 debugfs_remove(phba->idiag_pci_cfg);
4147 phba->idiag_pci_cfg = NULL;
4150 /* Finally remove the iDiag debugfs root */
4151 if (phba->idiag_root) {
4152 /* iDiag root */
4153 debugfs_remove(phba->idiag_root);
4154 phba->idiag_root = NULL;
4158 if (phba->hba_debugfs_root) {
4159 debugfs_remove(phba->hba_debugfs_root); /* fnX */
4160 phba->hba_debugfs_root = NULL;
4161 atomic_dec(&lpfc_debugfs_hba_count);
4164 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
4165 debugfs_remove(lpfc_debugfs_root); /* lpfc */
4166 lpfc_debugfs_root = NULL;
4169 #endif
4170 return;