Merge branch 'mini2440-dev-unlikely' into mini2440-dev
[linux-2.6/mini2440.git] / drivers / scsi / lpfc / lpfc_debugfs.c
blob8d0f0de76b6336098e3c76411002d1f8529244ae
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2007-2009 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/dma-mapping.h>
24 #include <linux/idr.h>
25 #include <linux/interrupt.h>
26 #include <linux/kthread.h>
27 #include <linux/pci.h>
28 #include <linux/spinlock.h>
29 #include <linux/ctype.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_transport_fc.h>
36 #include "lpfc_hw4.h"
37 #include "lpfc_hw.h"
38 #include "lpfc_sli.h"
39 #include "lpfc_sli4.h"
40 #include "lpfc_nl.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
43 #include "lpfc.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_version.h"
48 #include "lpfc_compat.h"
49 #include "lpfc_debugfs.h"
51 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
53 * debugfs interface
55 * To access this interface the user should:
56 * # mount -t debugfs none /sys/kernel/debug
58 * The lpfc debugfs directory hierarchy is:
59 * lpfc/lpfcX/vportY
60 * where X is the lpfc hba unique_id
61 * where Y is the vport VPI on that hba
63 * Debugging services available per vport:
64 * discovery_trace
65 * This is an ACSII readable file that contains a trace of the last
66 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
67 * See lpfc_debugfs.h for different categories of discovery events.
68 * To enable the discovery trace, the following module parameters must be set:
69 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
70 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
71 * EACH vport. X MUST also be a power of 2.
72 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
73 * lpfc_debugfs.h .
75 * slow_ring_trace
76 * This is an ACSII readable file that contains a trace of the last
77 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
78 * To enable the slow ring trace, the following module parameters must be set:
79 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
80 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
81 * the HBA. X MUST also be a power of 2.
83 static int lpfc_debugfs_enable = 1;
84 module_param(lpfc_debugfs_enable, int, 0);
85 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
87 /* This MUST be a power of 2 */
88 static int lpfc_debugfs_max_disc_trc;
89 module_param(lpfc_debugfs_max_disc_trc, int, 0);
90 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
91 "Set debugfs discovery trace depth");
93 /* This MUST be a power of 2 */
94 static int lpfc_debugfs_max_slow_ring_trc;
95 module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
96 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
97 "Set debugfs slow ring trace depth");
99 static int lpfc_debugfs_mask_disc_trc;
100 module_param(lpfc_debugfs_mask_disc_trc, int, 0);
101 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
102 "Set debugfs discovery trace mask");
104 #include <linux/debugfs.h>
106 /* size of output line, for discovery_trace and slow_ring_trace */
107 #define LPFC_DEBUG_TRC_ENTRY_SIZE 100
109 /* nodelist output buffer size */
110 #define LPFC_NODELIST_SIZE 8192
111 #define LPFC_NODELIST_ENTRY_SIZE 120
113 /* dumpHBASlim output buffer size */
114 #define LPFC_DUMPHBASLIM_SIZE 4096
116 /* dumpHostSlim output buffer size */
117 #define LPFC_DUMPHOSTSLIM_SIZE 4096
119 /* hbqinfo output buffer size */
120 #define LPFC_HBQINFO_SIZE 8192
122 struct lpfc_debug {
123 char *buffer;
124 int len;
127 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
128 static unsigned long lpfc_debugfs_start_time = 0L;
131 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
132 * @vport: The vport to gather the log info from.
133 * @buf: The buffer to dump log into.
134 * @size: The maximum amount of data to process.
136 * Description:
137 * This routine gathers the lpfc discovery debugfs data from the @vport and
138 * dumps it to @buf up to @size number of bytes. It will start at the next entry
139 * in the log and process the log until the end of the buffer. Then it will
140 * gather from the beginning of the log and process until the current entry.
142 * Notes:
143 * Discovery logging will be disabled while while this routine dumps the log.
145 * Return Value:
146 * This routine returns the amount of bytes that were dumped into @buf and will
147 * not exceed @size.
149 static int
150 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
152 int i, index, len, enable;
153 uint32_t ms;
154 struct lpfc_debugfs_trc *dtp;
155 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
157 enable = lpfc_debugfs_enable;
158 lpfc_debugfs_enable = 0;
160 len = 0;
161 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
162 (lpfc_debugfs_max_disc_trc - 1);
163 for (i = index; i < lpfc_debugfs_max_disc_trc; 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);
174 for (i = 0; i < index; i++) {
175 dtp = vport->disc_trc + i;
176 if (!dtp->fmt)
177 continue;
178 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
179 snprintf(buffer,
180 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
181 dtp->seq_cnt, ms, dtp->fmt);
182 len += snprintf(buf+len, size-len, buffer,
183 dtp->data1, dtp->data2, dtp->data3);
186 lpfc_debugfs_enable = enable;
187 return len;
191 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
192 * @phba: The HBA to gather the log info from.
193 * @buf: The buffer to dump log into.
194 * @size: The maximum amount of data to process.
196 * Description:
197 * This routine gathers the lpfc slow ring debugfs data from the @phba and
198 * dumps it to @buf up to @size number of bytes. It will start at the next entry
199 * in the log and process the log until the end of the buffer. Then it will
200 * gather from the beginning of the log and process until the current entry.
202 * Notes:
203 * Slow ring logging will be disabled while while this routine dumps the log.
205 * Return Value:
206 * This routine returns the amount of bytes that were dumped into @buf and will
207 * not exceed @size.
209 static int
210 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
212 int i, index, len, enable;
213 uint32_t ms;
214 struct lpfc_debugfs_trc *dtp;
215 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
218 enable = lpfc_debugfs_enable;
219 lpfc_debugfs_enable = 0;
221 len = 0;
222 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
223 (lpfc_debugfs_max_slow_ring_trc - 1);
224 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
225 dtp = phba->slow_ring_trc + i;
226 if (!dtp->fmt)
227 continue;
228 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
229 snprintf(buffer,
230 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
231 dtp->seq_cnt, ms, dtp->fmt);
232 len += snprintf(buf+len, size-len, buffer,
233 dtp->data1, dtp->data2, dtp->data3);
235 for (i = 0; i < index; i++) {
236 dtp = phba->slow_ring_trc + i;
237 if (!dtp->fmt)
238 continue;
239 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
240 snprintf(buffer,
241 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
242 dtp->seq_cnt, ms, dtp->fmt);
243 len += snprintf(buf+len, size-len, buffer,
244 dtp->data1, dtp->data2, dtp->data3);
247 lpfc_debugfs_enable = enable;
248 return len;
251 static int lpfc_debugfs_last_hbq = -1;
254 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
255 * @phba: The HBA to gather host buffer info from.
256 * @buf: The buffer to dump log into.
257 * @size: The maximum amount of data to process.
259 * Description:
260 * This routine dumps the host buffer queue info from the @phba to @buf up to
261 * @size number of bytes. A header that describes the current hbq state will be
262 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
263 * until @size bytes have been dumped or all the hbq info has been dumped.
265 * Notes:
266 * This routine will rotate through each configured HBQ each time called.
268 * Return Value:
269 * This routine returns the amount of bytes that were dumped into @buf and will
270 * not exceed @size.
272 static int
273 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
275 int len = 0;
276 int cnt, i, j, found, posted, low;
277 uint32_t phys, raw_index, getidx;
278 struct lpfc_hbq_init *hip;
279 struct hbq_s *hbqs;
280 struct lpfc_hbq_entry *hbqe;
281 struct lpfc_dmabuf *d_buf;
282 struct hbq_dmabuf *hbq_buf;
284 if (phba->sli_rev != 3)
285 return 0;
286 cnt = LPFC_HBQINFO_SIZE;
287 spin_lock_irq(&phba->hbalock);
289 /* toggle between multiple hbqs, if any */
290 i = lpfc_sli_hbq_count();
291 if (i > 1) {
292 lpfc_debugfs_last_hbq++;
293 if (lpfc_debugfs_last_hbq >= i)
294 lpfc_debugfs_last_hbq = 0;
296 else
297 lpfc_debugfs_last_hbq = 0;
299 i = lpfc_debugfs_last_hbq;
301 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
303 hbqs = &phba->hbqs[i];
304 posted = 0;
305 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
306 posted++;
308 hip = lpfc_hbq_defs[i];
309 len += snprintf(buf+len, size-len,
310 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
311 hip->hbq_index, hip->profile, hip->rn,
312 hip->buffer_count, hip->init_count, hip->add_count, posted);
314 raw_index = phba->hbq_get[i];
315 getidx = le32_to_cpu(raw_index);
316 len += snprintf(buf+len, size-len,
317 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
318 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
319 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
321 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
322 for (j=0; j<hbqs->entry_count; j++) {
323 len += snprintf(buf+len, size-len,
324 "%03d: %08x %04x %05x ", j,
325 le32_to_cpu(hbqe->bde.addrLow),
326 le32_to_cpu(hbqe->bde.tus.w),
327 le32_to_cpu(hbqe->buffer_tag));
328 i = 0;
329 found = 0;
331 /* First calculate if slot has an associated posted buffer */
332 low = hbqs->hbqPutIdx - posted;
333 if (low >= 0) {
334 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
335 len += snprintf(buf+len, size-len, "Unused\n");
336 goto skipit;
339 else {
340 if ((j >= hbqs->hbqPutIdx) &&
341 (j < (hbqs->entry_count+low))) {
342 len += snprintf(buf+len, size-len, "Unused\n");
343 goto skipit;
347 /* Get the Buffer info for the posted buffer */
348 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
349 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
350 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
351 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
352 len += snprintf(buf+len, size-len,
353 "Buf%d: %p %06x\n", i,
354 hbq_buf->dbuf.virt, hbq_buf->tag);
355 found = 1;
356 break;
358 i++;
360 if (!found) {
361 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
363 skipit:
364 hbqe++;
365 if (len > LPFC_HBQINFO_SIZE - 54)
366 break;
368 spin_unlock_irq(&phba->hbalock);
369 return len;
372 static int lpfc_debugfs_last_hba_slim_off;
375 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
376 * @phba: The HBA to gather SLIM info from.
377 * @buf: The buffer to dump log into.
378 * @size: The maximum amount of data to process.
380 * Description:
381 * This routine dumps the current contents of HBA SLIM for the HBA associated
382 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
384 * Notes:
385 * This routine will only dump up to 1024 bytes of data each time called and
386 * should be called multiple times to dump the entire HBA SLIM.
388 * Return Value:
389 * This routine returns the amount of bytes that were dumped into @buf and will
390 * not exceed @size.
392 static int
393 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
395 int len = 0;
396 int i, off;
397 uint32_t *ptr;
398 char buffer[1024];
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 return len;
431 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
432 * @phba: The HBA to gather Host SLIM info from.
433 * @buf: The buffer to dump log into.
434 * @size: The maximum amount of data to process.
436 * Description:
437 * This routine dumps the current contents of host SLIM for the host associated
438 * with @phba to @buf up to @size bytes of data. The dump will contain the
439 * Mailbox, PCB, Rings, and Registers that are located in host memory.
441 * Return Value:
442 * This routine returns the amount of bytes that were dumped into @buf and will
443 * not exceed @size.
445 static int
446 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
448 int len = 0;
449 int i, off;
450 uint32_t word0, word1, word2, word3;
451 uint32_t *ptr;
452 struct lpfc_pgp *pgpp;
453 struct lpfc_sli *psli = &phba->sli;
454 struct lpfc_sli_ring *pring;
456 off = 0;
457 spin_lock_irq(&phba->hbalock);
459 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
460 ptr = (uint32_t *)phba->slim2p.virt;
461 i = sizeof(MAILBOX_t);
462 while (i > 0) {
463 len += snprintf(buf+len, size-len,
464 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
465 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
466 *(ptr+5), *(ptr+6), *(ptr+7));
467 ptr += 8;
468 i -= (8 * sizeof(uint32_t));
469 off += (8 * sizeof(uint32_t));
472 len += snprintf(buf+len, size-len, "SLIM PCB\n");
473 ptr = (uint32_t *)phba->pcb;
474 i = sizeof(PCB_t);
475 while (i > 0) {
476 len += snprintf(buf+len, size-len,
477 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
478 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
479 *(ptr+5), *(ptr+6), *(ptr+7));
480 ptr += 8;
481 i -= (8 * sizeof(uint32_t));
482 off += (8 * sizeof(uint32_t));
485 for (i = 0; i < 4; i++) {
486 pgpp = &phba->port_gp[i];
487 pring = &psli->ring[i];
488 len += snprintf(buf+len, size-len,
489 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
490 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
491 i, pgpp->cmdGetInx, pring->numCiocb,
492 pring->next_cmdidx, pring->local_getidx,
493 pring->flag, pgpp->rspPutInx, pring->numRiocb);
496 if (phba->sli_rev <= LPFC_SLI_REV3) {
497 word0 = readl(phba->HAregaddr);
498 word1 = readl(phba->CAregaddr);
499 word2 = readl(phba->HSregaddr);
500 word3 = readl(phba->HCregaddr);
501 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
502 "HC:%08x\n", word0, word1, word2, word3);
504 spin_unlock_irq(&phba->hbalock);
505 return len;
509 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
510 * @vport: The vport to gather target node info from.
511 * @buf: The buffer to dump log into.
512 * @size: The maximum amount of data to process.
514 * Description:
515 * This routine dumps the current target node list associated with @vport to
516 * @buf up to @size bytes of data. Each node entry in the dump will contain a
517 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
519 * Return Value:
520 * This routine returns the amount of bytes that were dumped into @buf and will
521 * not exceed @size.
523 static int
524 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
526 int len = 0;
527 int cnt;
528 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
529 struct lpfc_nodelist *ndlp;
530 unsigned char *statep, *name;
532 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
534 spin_lock_irq(shost->host_lock);
535 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
536 if (!cnt) {
537 len += snprintf(buf+len, size-len,
538 "Missing Nodelist Entries\n");
539 break;
541 cnt--;
542 switch (ndlp->nlp_state) {
543 case NLP_STE_UNUSED_NODE:
544 statep = "UNUSED";
545 break;
546 case NLP_STE_PLOGI_ISSUE:
547 statep = "PLOGI ";
548 break;
549 case NLP_STE_ADISC_ISSUE:
550 statep = "ADISC ";
551 break;
552 case NLP_STE_REG_LOGIN_ISSUE:
553 statep = "REGLOG";
554 break;
555 case NLP_STE_PRLI_ISSUE:
556 statep = "PRLI ";
557 break;
558 case NLP_STE_UNMAPPED_NODE:
559 statep = "UNMAP ";
560 break;
561 case NLP_STE_MAPPED_NODE:
562 statep = "MAPPED";
563 break;
564 case NLP_STE_NPR_NODE:
565 statep = "NPR ";
566 break;
567 default:
568 statep = "UNKNOWN";
570 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
571 statep, ndlp->nlp_DID);
572 name = (unsigned char *)&ndlp->nlp_portname;
573 len += snprintf(buf+len, size-len,
574 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
575 *name, *(name+1), *(name+2), *(name+3),
576 *(name+4), *(name+5), *(name+6), *(name+7));
577 name = (unsigned char *)&ndlp->nlp_nodename;
578 len += snprintf(buf+len, size-len,
579 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
580 *name, *(name+1), *(name+2), *(name+3),
581 *(name+4), *(name+5), *(name+6), *(name+7));
582 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
583 ndlp->nlp_rpi, ndlp->nlp_flag);
584 if (!ndlp->nlp_type)
585 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
586 if (ndlp->nlp_type & NLP_FC_NODE)
587 len += snprintf(buf+len, size-len, "FC_NODE ");
588 if (ndlp->nlp_type & NLP_FABRIC)
589 len += snprintf(buf+len, size-len, "FABRIC ");
590 if (ndlp->nlp_type & NLP_FCP_TARGET)
591 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
592 ndlp->nlp_sid);
593 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
594 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
595 len += snprintf(buf+len, size-len, "usgmap:%x ",
596 ndlp->nlp_usg_map);
597 len += snprintf(buf+len, size-len, "refcnt:%x",
598 atomic_read(&ndlp->kref.refcount));
599 len += snprintf(buf+len, size-len, "\n");
601 spin_unlock_irq(shost->host_lock);
602 return len;
604 #endif
607 * lpfc_debugfs_disc_trc - Store discovery trace log
608 * @vport: The vport to associate this trace string with for retrieval.
609 * @mask: Log entry classification.
610 * @fmt: Format string to be displayed when dumping the log.
611 * @data1: 1st data parameter to be applied to @fmt.
612 * @data2: 2nd data parameter to be applied to @fmt.
613 * @data3: 3rd data parameter to be applied to @fmt.
615 * Description:
616 * This routine is used by the driver code to add a debugfs log entry to the
617 * discovery trace buffer associated with @vport. Only entries with a @mask that
618 * match the current debugfs discovery mask will be saved. Entries that do not
619 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
620 * printf when displaying the log.
622 inline void
623 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
624 uint32_t data1, uint32_t data2, uint32_t data3)
626 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
627 struct lpfc_debugfs_trc *dtp;
628 int index;
630 if (!(lpfc_debugfs_mask_disc_trc & mask))
631 return;
633 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
634 !vport || !vport->disc_trc)
635 return;
637 index = atomic_inc_return(&vport->disc_trc_cnt) &
638 (lpfc_debugfs_max_disc_trc - 1);
639 dtp = vport->disc_trc + index;
640 dtp->fmt = fmt;
641 dtp->data1 = data1;
642 dtp->data2 = data2;
643 dtp->data3 = data3;
644 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
645 dtp->jif = jiffies;
646 #endif
647 return;
651 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
652 * @phba: The phba to associate this trace string with for retrieval.
653 * @fmt: Format string to be displayed when dumping the log.
654 * @data1: 1st data parameter to be applied to @fmt.
655 * @data2: 2nd data parameter to be applied to @fmt.
656 * @data3: 3rd data parameter to be applied to @fmt.
658 * Description:
659 * This routine is used by the driver code to add a debugfs log entry to the
660 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
661 * @data3 are used like printf when displaying the log.
663 inline void
664 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
665 uint32_t data1, uint32_t data2, uint32_t data3)
667 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
668 struct lpfc_debugfs_trc *dtp;
669 int index;
671 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
672 !phba || !phba->slow_ring_trc)
673 return;
675 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
676 (lpfc_debugfs_max_slow_ring_trc - 1);
677 dtp = phba->slow_ring_trc + index;
678 dtp->fmt = fmt;
679 dtp->data1 = data1;
680 dtp->data2 = data2;
681 dtp->data3 = data3;
682 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
683 dtp->jif = jiffies;
684 #endif
685 return;
688 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
690 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
691 * @inode: The inode pointer that contains a vport pointer.
692 * @file: The file pointer to attach the log output.
694 * Description:
695 * This routine is the entry point for the debugfs open file operation. It gets
696 * the vport from the i_private field in @inode, allocates the necessary buffer
697 * for the log, fills the buffer from the in-memory log for this vport, and then
698 * returns a pointer to that log in the private_data field in @file.
700 * Returns:
701 * This function returns zero if successful. On error it will return an negative
702 * error value.
704 static int
705 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
707 struct lpfc_vport *vport = inode->i_private;
708 struct lpfc_debug *debug;
709 int size;
710 int rc = -ENOMEM;
712 if (!lpfc_debugfs_max_disc_trc) {
713 rc = -ENOSPC;
714 goto out;
717 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
718 if (!debug)
719 goto out;
721 /* Round to page boundary */
722 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
723 size = PAGE_ALIGN(size);
725 debug->buffer = kmalloc(size, GFP_KERNEL);
726 if (!debug->buffer) {
727 kfree(debug);
728 goto out;
731 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
732 file->private_data = debug;
734 rc = 0;
735 out:
736 return rc;
740 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
741 * @inode: The inode pointer that contains a vport pointer.
742 * @file: The file pointer to attach the log output.
744 * Description:
745 * This routine is the entry point for the debugfs open file operation. It gets
746 * the vport from the i_private field in @inode, allocates the necessary buffer
747 * for the log, fills the buffer from the in-memory log for this vport, and then
748 * returns a pointer to that log in the private_data field in @file.
750 * Returns:
751 * This function returns zero if successful. On error it will return an negative
752 * error value.
754 static int
755 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
757 struct lpfc_hba *phba = inode->i_private;
758 struct lpfc_debug *debug;
759 int size;
760 int rc = -ENOMEM;
762 if (!lpfc_debugfs_max_slow_ring_trc) {
763 rc = -ENOSPC;
764 goto out;
767 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
768 if (!debug)
769 goto out;
771 /* Round to page boundary */
772 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
773 size = PAGE_ALIGN(size);
775 debug->buffer = kmalloc(size, GFP_KERNEL);
776 if (!debug->buffer) {
777 kfree(debug);
778 goto out;
781 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
782 file->private_data = debug;
784 rc = 0;
785 out:
786 return rc;
790 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
791 * @inode: The inode pointer that contains a vport pointer.
792 * @file: The file pointer to attach the log output.
794 * Description:
795 * This routine is the entry point for the debugfs open file operation. It gets
796 * the vport from the i_private field in @inode, allocates the necessary buffer
797 * for the log, fills the buffer from the in-memory log for this vport, and then
798 * returns a pointer to that log in the private_data field in @file.
800 * Returns:
801 * This function returns zero if successful. On error it will return an negative
802 * error value.
804 static int
805 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
807 struct lpfc_hba *phba = inode->i_private;
808 struct lpfc_debug *debug;
809 int rc = -ENOMEM;
811 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
812 if (!debug)
813 goto out;
815 /* Round to page boundary */
816 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
817 if (!debug->buffer) {
818 kfree(debug);
819 goto out;
822 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
823 LPFC_HBQINFO_SIZE);
824 file->private_data = debug;
826 rc = 0;
827 out:
828 return rc;
832 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
833 * @inode: The inode pointer that contains a vport pointer.
834 * @file: The file pointer to attach the log output.
836 * Description:
837 * This routine is the entry point for the debugfs open file operation. It gets
838 * the vport from the i_private field in @inode, allocates the necessary buffer
839 * for the log, fills the buffer from the in-memory log for this vport, and then
840 * returns a pointer to that log in the private_data field in @file.
842 * Returns:
843 * This function returns zero if successful. On error it will return an negative
844 * error value.
846 static int
847 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
849 struct lpfc_hba *phba = inode->i_private;
850 struct lpfc_debug *debug;
851 int rc = -ENOMEM;
853 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
854 if (!debug)
855 goto out;
857 /* Round to page boundary */
858 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
859 if (!debug->buffer) {
860 kfree(debug);
861 goto out;
864 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
865 LPFC_DUMPHBASLIM_SIZE);
866 file->private_data = debug;
868 rc = 0;
869 out:
870 return rc;
874 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
875 * @inode: The inode pointer that contains a vport pointer.
876 * @file: The file pointer to attach the log output.
878 * Description:
879 * This routine is the entry point for the debugfs open file operation. It gets
880 * the vport from the i_private field in @inode, allocates the necessary buffer
881 * for the log, fills the buffer from the in-memory log for this vport, and then
882 * returns a pointer to that log in the private_data field in @file.
884 * Returns:
885 * This function returns zero if successful. On error it will return an negative
886 * error value.
888 static int
889 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
891 struct lpfc_hba *phba = inode->i_private;
892 struct lpfc_debug *debug;
893 int rc = -ENOMEM;
895 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
896 if (!debug)
897 goto out;
899 /* Round to page boundary */
900 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
901 if (!debug->buffer) {
902 kfree(debug);
903 goto out;
906 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
907 LPFC_DUMPHOSTSLIM_SIZE);
908 file->private_data = debug;
910 rc = 0;
911 out:
912 return rc;
915 static int
916 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
918 struct lpfc_debug *debug;
919 int rc = -ENOMEM;
921 if (!_dump_buf_data)
922 return -EBUSY;
924 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
925 if (!debug)
926 goto out;
928 /* Round to page boundry */
929 printk(KERN_ERR "BLKGRD %s: _dump_buf_data=0x%p\n",
930 __func__, _dump_buf_data);
931 debug->buffer = _dump_buf_data;
932 if (!debug->buffer) {
933 kfree(debug);
934 goto out;
937 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
938 file->private_data = debug;
940 rc = 0;
941 out:
942 return rc;
945 static int
946 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
948 struct lpfc_debug *debug;
949 int rc = -ENOMEM;
951 if (!_dump_buf_dif)
952 return -EBUSY;
954 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
955 if (!debug)
956 goto out;
958 /* Round to page boundry */
959 printk(KERN_ERR "BLKGRD %s: _dump_buf_dif=0x%p file=%s\n", __func__,
960 _dump_buf_dif, file->f_dentry->d_name.name);
961 debug->buffer = _dump_buf_dif;
962 if (!debug->buffer) {
963 kfree(debug);
964 goto out;
967 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
968 file->private_data = debug;
970 rc = 0;
971 out:
972 return rc;
975 static ssize_t
976 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
977 size_t nbytes, loff_t *ppos)
980 * The Data/DIF buffers only save one failing IO
981 * The write op is used as a reset mechanism after an IO has
982 * already been saved to the next one can be saved
984 spin_lock(&_dump_buf_lock);
986 memset((void *)_dump_buf_data, 0,
987 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
988 memset((void *)_dump_buf_dif, 0,
989 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
991 _dump_buf_done = 0;
993 spin_unlock(&_dump_buf_lock);
995 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;
1101 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1102 debug->len);
1106 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1107 * @inode: The inode pointer that contains a vport pointer. (unused)
1108 * @file: The file pointer that contains the buffer to release.
1110 * Description:
1111 * This routine frees the buffer that was allocated when the debugfs file was
1112 * opened.
1114 * Returns:
1115 * This function returns zero.
1117 static int
1118 lpfc_debugfs_release(struct inode *inode, struct file *file)
1120 struct lpfc_debug *debug = file->private_data;
1122 kfree(debug->buffer);
1123 kfree(debug);
1125 return 0;
1128 static int
1129 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1131 struct lpfc_debug *debug = file->private_data;
1133 debug->buffer = NULL;
1134 kfree(debug);
1136 return 0;
1139 #undef lpfc_debugfs_op_disc_trc
1140 static const struct file_operations lpfc_debugfs_op_disc_trc = {
1141 .owner = THIS_MODULE,
1142 .open = lpfc_debugfs_disc_trc_open,
1143 .llseek = lpfc_debugfs_lseek,
1144 .read = lpfc_debugfs_read,
1145 .release = lpfc_debugfs_release,
1148 #undef lpfc_debugfs_op_nodelist
1149 static const struct file_operations lpfc_debugfs_op_nodelist = {
1150 .owner = THIS_MODULE,
1151 .open = lpfc_debugfs_nodelist_open,
1152 .llseek = lpfc_debugfs_lseek,
1153 .read = lpfc_debugfs_read,
1154 .release = lpfc_debugfs_release,
1157 #undef lpfc_debugfs_op_hbqinfo
1158 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
1159 .owner = THIS_MODULE,
1160 .open = lpfc_debugfs_hbqinfo_open,
1161 .llseek = lpfc_debugfs_lseek,
1162 .read = lpfc_debugfs_read,
1163 .release = lpfc_debugfs_release,
1166 #undef lpfc_debugfs_op_dumpHBASlim
1167 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
1168 .owner = THIS_MODULE,
1169 .open = lpfc_debugfs_dumpHBASlim_open,
1170 .llseek = lpfc_debugfs_lseek,
1171 .read = lpfc_debugfs_read,
1172 .release = lpfc_debugfs_release,
1175 #undef lpfc_debugfs_op_dumpHostSlim
1176 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
1177 .owner = THIS_MODULE,
1178 .open = lpfc_debugfs_dumpHostSlim_open,
1179 .llseek = lpfc_debugfs_lseek,
1180 .read = lpfc_debugfs_read,
1181 .release = lpfc_debugfs_release,
1184 #undef lpfc_debugfs_op_dumpData
1185 static const struct file_operations lpfc_debugfs_op_dumpData = {
1186 .owner = THIS_MODULE,
1187 .open = lpfc_debugfs_dumpData_open,
1188 .llseek = lpfc_debugfs_lseek,
1189 .read = lpfc_debugfs_read,
1190 .write = lpfc_debugfs_dumpDataDif_write,
1191 .release = lpfc_debugfs_dumpDataDif_release,
1194 #undef lpfc_debugfs_op_dumpDif
1195 static const struct file_operations lpfc_debugfs_op_dumpDif = {
1196 .owner = THIS_MODULE,
1197 .open = lpfc_debugfs_dumpDif_open,
1198 .llseek = lpfc_debugfs_lseek,
1199 .read = lpfc_debugfs_read,
1200 .write = lpfc_debugfs_dumpDataDif_write,
1201 .release = lpfc_debugfs_dumpDataDif_release,
1204 #undef lpfc_debugfs_op_slow_ring_trc
1205 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
1206 .owner = THIS_MODULE,
1207 .open = lpfc_debugfs_slow_ring_trc_open,
1208 .llseek = lpfc_debugfs_lseek,
1209 .read = lpfc_debugfs_read,
1210 .release = lpfc_debugfs_release,
1213 static struct dentry *lpfc_debugfs_root = NULL;
1214 static atomic_t lpfc_debugfs_hba_count;
1215 #endif
1218 * lpfc_debugfs_initialize - Initialize debugfs for a vport
1219 * @vport: The vport pointer to initialize.
1221 * Description:
1222 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
1223 * If not already created, this routine will create the lpfc directory, and
1224 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
1225 * also create each file used to access lpfc specific debugfs information.
1227 inline void
1228 lpfc_debugfs_initialize(struct lpfc_vport *vport)
1230 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1231 struct lpfc_hba *phba = vport->phba;
1232 char name[64];
1233 uint32_t num, i;
1235 if (!lpfc_debugfs_enable)
1236 return;
1238 /* Setup lpfc root directory */
1239 if (!lpfc_debugfs_root) {
1240 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
1241 atomic_set(&lpfc_debugfs_hba_count, 0);
1242 if (!lpfc_debugfs_root) {
1243 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1244 "0408 Cannot create debugfs root\n");
1245 goto debug_failed;
1248 if (!lpfc_debugfs_start_time)
1249 lpfc_debugfs_start_time = jiffies;
1251 /* Setup lpfcX directory for specific HBA */
1252 snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
1253 if (!phba->hba_debugfs_root) {
1254 phba->hba_debugfs_root =
1255 debugfs_create_dir(name, lpfc_debugfs_root);
1256 if (!phba->hba_debugfs_root) {
1257 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1258 "0412 Cannot create debugfs hba\n");
1259 goto debug_failed;
1261 atomic_inc(&lpfc_debugfs_hba_count);
1262 atomic_set(&phba->debugfs_vport_count, 0);
1264 /* Setup hbqinfo */
1265 snprintf(name, sizeof(name), "hbqinfo");
1266 phba->debug_hbqinfo =
1267 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1268 phba->hba_debugfs_root,
1269 phba, &lpfc_debugfs_op_hbqinfo);
1270 if (!phba->debug_hbqinfo) {
1271 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1272 "0411 Cannot create debugfs hbqinfo\n");
1273 goto debug_failed;
1276 /* Setup dumpHBASlim */
1277 snprintf(name, sizeof(name), "dumpHBASlim");
1278 phba->debug_dumpHBASlim =
1279 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1280 phba->hba_debugfs_root,
1281 phba, &lpfc_debugfs_op_dumpHBASlim);
1282 if (!phba->debug_dumpHBASlim) {
1283 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1284 "0413 Cannot create debugfs dumpHBASlim\n");
1285 goto debug_failed;
1288 /* Setup dumpHostSlim */
1289 snprintf(name, sizeof(name), "dumpHostSlim");
1290 phba->debug_dumpHostSlim =
1291 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1292 phba->hba_debugfs_root,
1293 phba, &lpfc_debugfs_op_dumpHostSlim);
1294 if (!phba->debug_dumpHostSlim) {
1295 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1296 "0414 Cannot create debugfs dumpHostSlim\n");
1297 goto debug_failed;
1300 /* Setup dumpData */
1301 snprintf(name, sizeof(name), "dumpData");
1302 phba->debug_dumpData =
1303 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1304 phba->hba_debugfs_root,
1305 phba, &lpfc_debugfs_op_dumpData);
1306 if (!phba->debug_dumpData) {
1307 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1308 "0800 Cannot create debugfs dumpData\n");
1309 goto debug_failed;
1312 /* Setup dumpDif */
1313 snprintf(name, sizeof(name), "dumpDif");
1314 phba->debug_dumpDif =
1315 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1316 phba->hba_debugfs_root,
1317 phba, &lpfc_debugfs_op_dumpDif);
1318 if (!phba->debug_dumpDif) {
1319 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1320 "0801 Cannot create debugfs dumpDif\n");
1321 goto debug_failed;
1326 /* Setup slow ring trace */
1327 if (lpfc_debugfs_max_slow_ring_trc) {
1328 num = lpfc_debugfs_max_slow_ring_trc - 1;
1329 if (num & lpfc_debugfs_max_slow_ring_trc) {
1330 /* Change to be a power of 2 */
1331 num = lpfc_debugfs_max_slow_ring_trc;
1332 i = 0;
1333 while (num > 1) {
1334 num = num >> 1;
1335 i++;
1337 lpfc_debugfs_max_slow_ring_trc = (1 << i);
1338 printk(KERN_ERR
1339 "lpfc_debugfs_max_disc_trc changed to "
1340 "%d\n", lpfc_debugfs_max_disc_trc);
1345 snprintf(name, sizeof(name), "slow_ring_trace");
1346 phba->debug_slow_ring_trc =
1347 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1348 phba->hba_debugfs_root,
1349 phba, &lpfc_debugfs_op_slow_ring_trc);
1350 if (!phba->debug_slow_ring_trc) {
1351 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1352 "0415 Cannot create debugfs "
1353 "slow_ring_trace\n");
1354 goto debug_failed;
1356 if (!phba->slow_ring_trc) {
1357 phba->slow_ring_trc = kmalloc(
1358 (sizeof(struct lpfc_debugfs_trc) *
1359 lpfc_debugfs_max_slow_ring_trc),
1360 GFP_KERNEL);
1361 if (!phba->slow_ring_trc) {
1362 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1363 "0416 Cannot create debugfs "
1364 "slow_ring buffer\n");
1365 goto debug_failed;
1367 atomic_set(&phba->slow_ring_trc_cnt, 0);
1368 memset(phba->slow_ring_trc, 0,
1369 (sizeof(struct lpfc_debugfs_trc) *
1370 lpfc_debugfs_max_slow_ring_trc));
1374 snprintf(name, sizeof(name), "vport%d", vport->vpi);
1375 if (!vport->vport_debugfs_root) {
1376 vport->vport_debugfs_root =
1377 debugfs_create_dir(name, phba->hba_debugfs_root);
1378 if (!vport->vport_debugfs_root) {
1379 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1380 "0417 Cant create debugfs");
1381 goto debug_failed;
1383 atomic_inc(&phba->debugfs_vport_count);
1386 if (lpfc_debugfs_max_disc_trc) {
1387 num = lpfc_debugfs_max_disc_trc - 1;
1388 if (num & lpfc_debugfs_max_disc_trc) {
1389 /* Change to be a power of 2 */
1390 num = lpfc_debugfs_max_disc_trc;
1391 i = 0;
1392 while (num > 1) {
1393 num = num >> 1;
1394 i++;
1396 lpfc_debugfs_max_disc_trc = (1 << i);
1397 printk(KERN_ERR
1398 "lpfc_debugfs_max_disc_trc changed to %d\n",
1399 lpfc_debugfs_max_disc_trc);
1403 vport->disc_trc = kzalloc(
1404 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
1405 GFP_KERNEL);
1407 if (!vport->disc_trc) {
1408 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1409 "0418 Cannot create debugfs disc trace "
1410 "buffer\n");
1411 goto debug_failed;
1413 atomic_set(&vport->disc_trc_cnt, 0);
1415 snprintf(name, sizeof(name), "discovery_trace");
1416 vport->debug_disc_trc =
1417 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1418 vport->vport_debugfs_root,
1419 vport, &lpfc_debugfs_op_disc_trc);
1420 if (!vport->debug_disc_trc) {
1421 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1422 "0419 Cannot create debugfs "
1423 "discovery_trace\n");
1424 goto debug_failed;
1426 snprintf(name, sizeof(name), "nodelist");
1427 vport->debug_nodelist =
1428 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1429 vport->vport_debugfs_root,
1430 vport, &lpfc_debugfs_op_nodelist);
1431 if (!vport->debug_nodelist) {
1432 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1433 "0409 Cant create debugfs nodelist");
1434 goto debug_failed;
1436 debug_failed:
1437 return;
1438 #endif
1442 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
1443 * @vport: The vport pointer to remove from debugfs.
1445 * Description:
1446 * When Debugfs is configured this routine removes debugfs file system elements
1447 * that are specific to this vport. It also checks to see if there are any
1448 * users left for the debugfs directories associated with the HBA and driver. If
1449 * this is the last user of the HBA directory or driver directory then it will
1450 * remove those from the debugfs infrastructure as well.
1452 inline void
1453 lpfc_debugfs_terminate(struct lpfc_vport *vport)
1455 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1456 struct lpfc_hba *phba = vport->phba;
1458 if (vport->disc_trc) {
1459 kfree(vport->disc_trc);
1460 vport->disc_trc = NULL;
1462 if (vport->debug_disc_trc) {
1463 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
1464 vport->debug_disc_trc = NULL;
1466 if (vport->debug_nodelist) {
1467 debugfs_remove(vport->debug_nodelist); /* nodelist */
1468 vport->debug_nodelist = NULL;
1471 if (vport->vport_debugfs_root) {
1472 debugfs_remove(vport->vport_debugfs_root); /* vportX */
1473 vport->vport_debugfs_root = NULL;
1474 atomic_dec(&phba->debugfs_vport_count);
1476 if (atomic_read(&phba->debugfs_vport_count) == 0) {
1478 if (phba->debug_hbqinfo) {
1479 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
1480 phba->debug_hbqinfo = NULL;
1482 if (phba->debug_dumpHBASlim) {
1483 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
1484 phba->debug_dumpHBASlim = NULL;
1486 if (phba->debug_dumpHostSlim) {
1487 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
1488 phba->debug_dumpHostSlim = NULL;
1490 if (phba->debug_dumpData) {
1491 debugfs_remove(phba->debug_dumpData); /* dumpData */
1492 phba->debug_dumpData = NULL;
1495 if (phba->debug_dumpDif) {
1496 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
1497 phba->debug_dumpDif = NULL;
1500 if (phba->slow_ring_trc) {
1501 kfree(phba->slow_ring_trc);
1502 phba->slow_ring_trc = NULL;
1504 if (phba->debug_slow_ring_trc) {
1505 /* slow_ring_trace */
1506 debugfs_remove(phba->debug_slow_ring_trc);
1507 phba->debug_slow_ring_trc = NULL;
1510 if (phba->hba_debugfs_root) {
1511 debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
1512 phba->hba_debugfs_root = NULL;
1513 atomic_dec(&lpfc_debugfs_hba_count);
1516 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
1517 debugfs_remove(lpfc_debugfs_root); /* lpfc */
1518 lpfc_debugfs_root = NULL;
1521 #endif
1522 return;