1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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>
30
31#include <scsi/scsi.h>
32#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
34#include <scsi/scsi_transport_fc.h>
35
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"
50
51#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83static int lpfc_debugfs_enable = 1;
84module_param(lpfc_debugfs_enable, int, 0);
85MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
86
87
88static int lpfc_debugfs_max_disc_trc;
89module_param(lpfc_debugfs_max_disc_trc, int, 0);
90MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
91 "Set debugfs discovery trace depth");
92
93
94static int lpfc_debugfs_max_slow_ring_trc;
95module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
96MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
97 "Set debugfs slow ring trace depth");
98
99static int lpfc_debugfs_mask_disc_trc;
100module_param(lpfc_debugfs_mask_disc_trc, int, 0);
101MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
102 "Set debugfs discovery trace mask");
103
104#include <linux/debugfs.h>
105
106
107#define LPFC_DEBUG_TRC_ENTRY_SIZE 100
108
109
110#define LPFC_NODELIST_SIZE 8192
111#define LPFC_NODELIST_ENTRY_SIZE 120
112
113
114#define LPFC_DUMPHBASLIM_SIZE 4096
115
116
117#define LPFC_DUMPHOSTSLIM_SIZE 4096
118
119
120#define LPFC_HBQINFO_SIZE 8192
121
122struct lpfc_debug {
123 char *buffer;
124 int len;
125};
126
127static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
128static unsigned long lpfc_debugfs_start_time = 0L;
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149static int
150lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
151{
152 int i, index, len, enable;
153 uint32_t ms;
154 struct lpfc_debugfs_trc *dtp;
155 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
156
157 enable = lpfc_debugfs_enable;
158 lpfc_debugfs_enable = 0;
159
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);
173 }
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);
184 }
185
186 lpfc_debugfs_enable = enable;
187 return len;
188}
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209static int
210lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
211{
212 int i, index, len, enable;
213 uint32_t ms;
214 struct lpfc_debugfs_trc *dtp;
215 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
216
217
218 enable = lpfc_debugfs_enable;
219 lpfc_debugfs_enable = 0;
220
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);
234 }
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);
245 }
246
247 lpfc_debugfs_enable = enable;
248 return len;
249}
250
251static int lpfc_debugfs_last_hbq = -1;
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272static int
273lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
274{
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;
283
284 if (phba->sli_rev != 3)
285 return 0;
286 cnt = LPFC_HBQINFO_SIZE;
287 spin_lock_irq(&phba->hbalock);
288
289
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;
295 }
296 else
297 lpfc_debugfs_last_hbq = 0;
298
299 i = lpfc_debugfs_last_hbq;
300
301 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
302
303 hbqs = &phba->hbqs[i];
304 posted = 0;
305 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
306 posted++;
307
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);
313
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);
320
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;
330
331
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;
337 }
338 }
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;
344 }
345 }
346
347
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;
357 }
358 i++;
359 }
360 if (!found) {
361 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
362 }
363skipit:
364 hbqe++;
365 if (len > LPFC_HBQINFO_SIZE - 54)
366 break;
367 }
368 spin_unlock_irq(&phba->hbalock);
369 return len;
370}
371
372static int lpfc_debugfs_last_hba_slim_off;
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392static int
393lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
394{
395 int len = 0;
396 int i, off;
397 uint32_t *ptr;
398 char buffer[1024];
399
400 off = 0;
401 spin_lock_irq(&phba->hbalock);
402
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);
406
407 ptr = (uint32_t *)&buffer[0];
408 off = lpfc_debugfs_last_hba_slim_off;
409
410
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;
414
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));
424 }
425
426 spin_unlock_irq(&phba->hbalock);
427 return len;
428}
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445static int
446lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
447{
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;
455
456 off = 0;
457 spin_lock_irq(&phba->hbalock);
458
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));
470 }
471
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));
483 }
484
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);
494 }
495
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);
503 }
504 spin_unlock_irq(&phba->hbalock);
505 return len;
506}
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523static int
524lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
525{
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;
531
532 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
533
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;
540 }
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";
569 }
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");
600 }
601 spin_unlock_irq(shost->host_lock);
602 return len;
603}
604#endif
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622inline void
623lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
624 uint32_t data1, uint32_t data2, uint32_t data3)
625{
626#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
627 struct lpfc_debugfs_trc *dtp;
628 int index;
629
630 if (!(lpfc_debugfs_mask_disc_trc & mask))
631 return;
632
633 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
634 !vport || !vport->disc_trc)
635 return;
636
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;
648}
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663inline void
664lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
665 uint32_t data1, uint32_t data2, uint32_t data3)
666{
667#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
668 struct lpfc_debugfs_trc *dtp;
669 int index;
670
671 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
672 !phba || !phba->slow_ring_trc)
673 return;
674
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;
686}
687
688#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704static int
705lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
706{
707 struct lpfc_vport *vport = inode->i_private;
708 struct lpfc_debug *debug;
709 int size;
710 int rc = -ENOMEM;
711
712 if (!lpfc_debugfs_max_disc_trc) {
713 rc = -ENOSPC;
714 goto out;
715 }
716
717 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
718 if (!debug)
719 goto out;
720
721
722 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
723 size = PAGE_ALIGN(size);
724
725 debug->buffer = kmalloc(size, GFP_KERNEL);
726 if (!debug->buffer) {
727 kfree(debug);
728 goto out;
729 }
730
731 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
732 file->private_data = debug;
733
734 rc = 0;
735out:
736 return rc;
737}
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754static int
755lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
756{
757 struct lpfc_hba *phba = inode->i_private;
758 struct lpfc_debug *debug;
759 int size;
760 int rc = -ENOMEM;
761
762 if (!lpfc_debugfs_max_slow_ring_trc) {
763 rc = -ENOSPC;
764 goto out;
765 }
766
767 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
768 if (!debug)
769 goto out;
770
771
772 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
773 size = PAGE_ALIGN(size);
774
775 debug->buffer = kmalloc(size, GFP_KERNEL);
776 if (!debug->buffer) {
777 kfree(debug);
778 goto out;
779 }
780
781 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
782 file->private_data = debug;
783
784 rc = 0;
785out:
786 return rc;
787}
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804static int
805lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
806{
807 struct lpfc_hba *phba = inode->i_private;
808 struct lpfc_debug *debug;
809 int rc = -ENOMEM;
810
811 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
812 if (!debug)
813 goto out;
814
815
816 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
817 if (!debug->buffer) {
818 kfree(debug);
819 goto out;
820 }
821
822 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
823 LPFC_HBQINFO_SIZE);
824 file->private_data = debug;
825
826 rc = 0;
827out:
828 return rc;
829}
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846static int
847lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
848{
849 struct lpfc_hba *phba = inode->i_private;
850 struct lpfc_debug *debug;
851 int rc = -ENOMEM;
852
853 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
854 if (!debug)
855 goto out;
856
857
858 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
859 if (!debug->buffer) {
860 kfree(debug);
861 goto out;
862 }
863
864 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
865 LPFC_DUMPHBASLIM_SIZE);
866 file->private_data = debug;
867
868 rc = 0;
869out:
870 return rc;
871}
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888static int
889lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
890{
891 struct lpfc_hba *phba = inode->i_private;
892 struct lpfc_debug *debug;
893 int rc = -ENOMEM;
894
895 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
896 if (!debug)
897 goto out;
898
899
900 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
901 if (!debug->buffer) {
902 kfree(debug);
903 goto out;
904 }
905
906 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
907 LPFC_DUMPHOSTSLIM_SIZE);
908 file->private_data = debug;
909
910 rc = 0;
911out:
912 return rc;
913}
914
915static int
916lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
917{
918 struct lpfc_debug *debug;
919 int rc = -ENOMEM;
920
921 if (!_dump_buf_data)
922 return -EBUSY;
923
924 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
925 if (!debug)
926 goto out;
927
928
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;
935 }
936
937 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
938 file->private_data = debug;
939
940 rc = 0;
941out:
942 return rc;
943}
944
945static int
946lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
947{
948 struct lpfc_debug *debug;
949 int rc = -ENOMEM;
950
951 if (!_dump_buf_dif)
952 return -EBUSY;
953
954 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
955 if (!debug)
956 goto out;
957
958
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;
965 }
966
967 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
968 file->private_data = debug;
969
970 rc = 0;
971out:
972 return rc;
973}
974
975static ssize_t
976lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
977 size_t nbytes, loff_t *ppos)
978{
979
980
981
982
983
984 spin_lock(&_dump_buf_lock);
985
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));
990
991 _dump_buf_done = 0;
992
993 spin_unlock(&_dump_buf_lock);
994
995 return nbytes;
996}
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015static int
1016lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1017{
1018 struct lpfc_vport *vport = inode->i_private;
1019 struct lpfc_debug *debug;
1020 int rc = -ENOMEM;
1021
1022 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1023 if (!debug)
1024 goto out;
1025
1026
1027 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1028 if (!debug->buffer) {
1029 kfree(debug);
1030 goto out;
1031 }
1032
1033 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1034 LPFC_NODELIST_SIZE);
1035 file->private_data = debug;
1036
1037 rc = 0;
1038out:
1039 return rc;
1040}
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059static loff_t
1060lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1061{
1062 struct lpfc_debug *debug;
1063 loff_t pos = -1;
1064
1065 debug = file->private_data;
1066
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;
1076 }
1077 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1078}
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096static ssize_t
1097lpfc_debugfs_read(struct file *file, char __user *buf,
1098 size_t nbytes, loff_t *ppos)
1099{
1100 struct lpfc_debug *debug = file->private_data;
1101 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1102 debug->len);
1103}
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117static int
1118lpfc_debugfs_release(struct inode *inode, struct file *file)
1119{
1120 struct lpfc_debug *debug = file->private_data;
1121
1122 kfree(debug->buffer);
1123 kfree(debug);
1124
1125 return 0;
1126}
1127
1128static int
1129lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1130{
1131 struct lpfc_debug *debug = file->private_data;
1132
1133 debug->buffer = NULL;
1134 kfree(debug);
1135
1136 return 0;
1137}
1138
1139#undef lpfc_debugfs_op_disc_trc
1140static 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,
1146};
1147
1148#undef lpfc_debugfs_op_nodelist
1149static 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,
1155};
1156
1157#undef lpfc_debugfs_op_hbqinfo
1158static 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,
1164};
1165
1166#undef lpfc_debugfs_op_dumpHBASlim
1167static 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,
1173};
1174
1175#undef lpfc_debugfs_op_dumpHostSlim
1176static 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,
1182};
1183
1184#undef lpfc_debugfs_op_dumpData
1185static 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,
1192};
1193
1194#undef lpfc_debugfs_op_dumpDif
1195static 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,
1202};
1203
1204#undef lpfc_debugfs_op_slow_ring_trc
1205static 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,
1211};
1212
1213static struct dentry *lpfc_debugfs_root = NULL;
1214static atomic_t lpfc_debugfs_hba_count;
1215#endif
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227inline void
1228lpfc_debugfs_initialize(struct lpfc_vport *vport)
1229{
1230#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1231 struct lpfc_hba *phba = vport->phba;
1232 char name[64];
1233 uint32_t num, i;
1234
1235 if (!lpfc_debugfs_enable)
1236 return;
1237
1238
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;
1246 }
1247 }
1248 if (!lpfc_debugfs_start_time)
1249 lpfc_debugfs_start_time = jiffies;
1250
1251
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;
1260 }
1261 atomic_inc(&lpfc_debugfs_hba_count);
1262 atomic_set(&phba->debugfs_vport_count, 0);
1263
1264
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;
1274 }
1275
1276
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;
1286 }
1287
1288
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;
1298 }
1299
1300
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;
1310 }
1311
1312
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;
1322 }
1323
1324
1325
1326
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
1331 num = lpfc_debugfs_max_slow_ring_trc;
1332 i = 0;
1333 while (num > 1) {
1334 num = num >> 1;
1335 i++;
1336 }
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);
1341 }
1342 }
1343
1344
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;
1355 }
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;
1366 }
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));
1371 }
1372 }
1373
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;
1382 }
1383 atomic_inc(&phba->debugfs_vport_count);
1384 }
1385
1386 if (lpfc_debugfs_max_disc_trc) {
1387 num = lpfc_debugfs_max_disc_trc - 1;
1388 if (num & lpfc_debugfs_max_disc_trc) {
1389
1390 num = lpfc_debugfs_max_disc_trc;
1391 i = 0;
1392 while (num > 1) {
1393 num = num >> 1;
1394 i++;
1395 }
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);
1400 }
1401 }
1402
1403 vport->disc_trc = kzalloc(
1404 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
1405 GFP_KERNEL);
1406
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;
1412 }
1413 atomic_set(&vport->disc_trc_cnt, 0);
1414
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;
1425 }
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;
1435 }
1436debug_failed:
1437 return;
1438#endif
1439}
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452inline void
1453lpfc_debugfs_terminate(struct lpfc_vport *vport)
1454{
1455#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1456 struct lpfc_hba *phba = vport->phba;
1457
1458 if (vport->disc_trc) {
1459 kfree(vport->disc_trc);
1460 vport->disc_trc = NULL;
1461 }
1462 if (vport->debug_disc_trc) {
1463 debugfs_remove(vport->debug_disc_trc);
1464 vport->debug_disc_trc = NULL;
1465 }
1466 if (vport->debug_nodelist) {
1467 debugfs_remove(vport->debug_nodelist);
1468 vport->debug_nodelist = NULL;
1469 }
1470
1471 if (vport->vport_debugfs_root) {
1472 debugfs_remove(vport->vport_debugfs_root);
1473 vport->vport_debugfs_root = NULL;
1474 atomic_dec(&phba->debugfs_vport_count);
1475 }
1476 if (atomic_read(&phba->debugfs_vport_count) == 0) {
1477
1478 if (phba->debug_hbqinfo) {
1479 debugfs_remove(phba->debug_hbqinfo);
1480 phba->debug_hbqinfo = NULL;
1481 }
1482 if (phba->debug_dumpHBASlim) {
1483 debugfs_remove(phba->debug_dumpHBASlim);
1484 phba->debug_dumpHBASlim = NULL;
1485 }
1486 if (phba->debug_dumpHostSlim) {
1487 debugfs_remove(phba->debug_dumpHostSlim);
1488 phba->debug_dumpHostSlim = NULL;
1489 }
1490 if (phba->debug_dumpData) {
1491 debugfs_remove(phba->debug_dumpData);
1492 phba->debug_dumpData = NULL;
1493 }
1494
1495 if (phba->debug_dumpDif) {
1496 debugfs_remove(phba->debug_dumpDif);
1497 phba->debug_dumpDif = NULL;
1498 }
1499
1500 if (phba->slow_ring_trc) {
1501 kfree(phba->slow_ring_trc);
1502 phba->slow_ring_trc = NULL;
1503 }
1504 if (phba->debug_slow_ring_trc) {
1505
1506 debugfs_remove(phba->debug_slow_ring_trc);
1507 phba->debug_slow_ring_trc = NULL;
1508 }
1509
1510 if (phba->hba_debugfs_root) {
1511 debugfs_remove(phba->hba_debugfs_root);
1512 phba->hba_debugfs_root = NULL;
1513 atomic_dec(&lpfc_debugfs_hba_count);
1514 }
1515
1516 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
1517 debugfs_remove(lpfc_debugfs_root);
1518 lpfc_debugfs_root = NULL;
1519 }
1520 }
1521#endif
1522 return;
1523}
1524