]> Git Repo - linux.git/blob - drivers/scsi/lpfc/lpfc_debugfs.c
memsw: remove noswapaccount kernel parameter
[linux.git] / drivers / scsi / lpfc / lpfc_debugfs.c
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  *******************************************************************/
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/slab.h>
28 #include <linux/pci.h>
29 #include <linux/spinlock.h>
30 #include <linux/ctype.h>
31
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
36
37 #include "lpfc_hw4.h"
38 #include "lpfc_hw.h"
39 #include "lpfc_sli.h"
40 #include "lpfc_sli4.h"
41 #include "lpfc_nl.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
44 #include "lpfc.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
48 #include "lpfc_version.h"
49 #include "lpfc_compat.h"
50 #include "lpfc_debugfs.h"
51
52 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
53 /*
54  * debugfs interface
55  *
56  * To access this interface the user should:
57  * # mount -t debugfs none /sys/kernel/debug
58  *
59  * The lpfc debugfs directory hierarchy is:
60  * /sys/kernel/debug/lpfc/fnX/vportY
61  * where X is the lpfc hba function unique_id
62  * where Y is the vport VPI on that hba
63  *
64  * Debugging services available per vport:
65  * discovery_trace
66  * This is an ACSII readable file that contains a trace of the last
67  * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
68  * See lpfc_debugfs.h for different categories of  discovery events.
69  * To enable the discovery trace, the following module parameters must be set:
70  * lpfc_debugfs_enable=1         Turns on lpfc debugfs filesystem support
71  * lpfc_debugfs_max_disc_trc=X   Where X is the event trace depth for
72  *                               EACH vport. X MUST also be a power of 2.
73  * lpfc_debugfs_mask_disc_trc=Y  Where Y is an event mask as defined in
74  *                               lpfc_debugfs.h .
75  *
76  * slow_ring_trace
77  * This is an ACSII readable file that contains a trace of the last
78  * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
79  * To enable the slow ring trace, the following module parameters must be set:
80  * lpfc_debugfs_enable=1         Turns on lpfc debugfs filesystem support
81  * lpfc_debugfs_max_slow_ring_trc=X   Where X is the event trace depth for
82  *                               the HBA. X MUST also be a power of 2.
83  */
84 static int lpfc_debugfs_enable = 1;
85 module_param(lpfc_debugfs_enable, int, S_IRUGO);
86 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
87
88 /* This MUST be a power of 2 */
89 static int lpfc_debugfs_max_disc_trc;
90 module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
91 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
92         "Set debugfs discovery trace depth");
93
94 /* This MUST be a power of 2 */
95 static int lpfc_debugfs_max_slow_ring_trc;
96 module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
97 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
98         "Set debugfs slow ring trace depth");
99
100 static int lpfc_debugfs_mask_disc_trc;
101 module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
102 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
103         "Set debugfs discovery trace mask");
104
105 #include <linux/debugfs.h>
106
107 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
108 static unsigned long lpfc_debugfs_start_time = 0L;
109
110 /* iDiag */
111 static struct lpfc_idiag idiag;
112
113 /**
114  * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
115  * @vport: The vport to gather the log info from.
116  * @buf: The buffer to dump log into.
117  * @size: The maximum amount of data to process.
118  *
119  * Description:
120  * This routine gathers the lpfc discovery debugfs data from the @vport and
121  * dumps it to @buf up to @size number of bytes. It will start at the next entry
122  * in the log and process the log until the end of the buffer. Then it will
123  * gather from the beginning of the log and process until the current entry.
124  *
125  * Notes:
126  * Discovery logging will be disabled while while this routine dumps the log.
127  *
128  * Return Value:
129  * This routine returns the amount of bytes that were dumped into @buf and will
130  * not exceed @size.
131  **/
132 static int
133 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
134 {
135         int i, index, len, enable;
136         uint32_t ms;
137         struct lpfc_debugfs_trc *dtp;
138         char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
139
140         enable = lpfc_debugfs_enable;
141         lpfc_debugfs_enable = 0;
142
143         len = 0;
144         index = (atomic_read(&vport->disc_trc_cnt) + 1) &
145                 (lpfc_debugfs_max_disc_trc - 1);
146         for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
147                 dtp = vport->disc_trc + i;
148                 if (!dtp->fmt)
149                         continue;
150                 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
151                 snprintf(buffer,
152                         LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
153                         dtp->seq_cnt, ms, dtp->fmt);
154                 len +=  snprintf(buf+len, size-len, buffer,
155                         dtp->data1, dtp->data2, dtp->data3);
156         }
157         for (i = 0; i < index; i++) {
158                 dtp = vport->disc_trc + i;
159                 if (!dtp->fmt)
160                         continue;
161                 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
162                 snprintf(buffer,
163                         LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
164                         dtp->seq_cnt, ms, dtp->fmt);
165                 len +=  snprintf(buf+len, size-len, buffer,
166                         dtp->data1, dtp->data2, dtp->data3);
167         }
168
169         lpfc_debugfs_enable = enable;
170         return len;
171 }
172
173 /**
174  * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
175  * @phba: The HBA to gather the log info from.
176  * @buf: The buffer to dump log into.
177  * @size: The maximum amount of data to process.
178  *
179  * Description:
180  * This routine gathers the lpfc slow ring debugfs data from the @phba and
181  * dumps it to @buf up to @size number of bytes. It will start at the next entry
182  * in the log and process the log until the end of the buffer. Then it will
183  * gather from the beginning of the log and process until the current entry.
184  *
185  * Notes:
186  * Slow ring logging will be disabled while while this routine dumps the log.
187  *
188  * Return Value:
189  * This routine returns the amount of bytes that were dumped into @buf and will
190  * not exceed @size.
191  **/
192 static int
193 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
194 {
195         int i, index, len, enable;
196         uint32_t ms;
197         struct lpfc_debugfs_trc *dtp;
198         char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
199
200
201         enable = lpfc_debugfs_enable;
202         lpfc_debugfs_enable = 0;
203
204         len = 0;
205         index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
206                 (lpfc_debugfs_max_slow_ring_trc - 1);
207         for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
208                 dtp = phba->slow_ring_trc + i;
209                 if (!dtp->fmt)
210                         continue;
211                 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
212                 snprintf(buffer,
213                         LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
214                         dtp->seq_cnt, ms, dtp->fmt);
215                 len +=  snprintf(buf+len, size-len, buffer,
216                         dtp->data1, dtp->data2, dtp->data3);
217         }
218         for (i = 0; i < index; 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);
228         }
229
230         lpfc_debugfs_enable = enable;
231         return len;
232 }
233
234 static int lpfc_debugfs_last_hbq = -1;
235
236 /**
237  * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
238  * @phba: The HBA to gather host buffer info from.
239  * @buf: The buffer to dump log into.
240  * @size: The maximum amount of data to process.
241  *
242  * Description:
243  * This routine dumps the host buffer queue info from the @phba to @buf up to
244  * @size number of bytes. A header that describes the current hbq state will be
245  * dumped to @buf first and then info on each hbq entry will be dumped to @buf
246  * until @size bytes have been dumped or all the hbq info has been dumped.
247  *
248  * Notes:
249  * This routine will rotate through each configured HBQ each time called.
250  *
251  * Return Value:
252  * This routine returns the amount of bytes that were dumped into @buf and will
253  * not exceed @size.
254  **/
255 static int
256 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
257 {
258         int len = 0;
259         int cnt, i, j, found, posted, low;
260         uint32_t phys, raw_index, getidx;
261         struct lpfc_hbq_init *hip;
262         struct hbq_s *hbqs;
263         struct lpfc_hbq_entry *hbqe;
264         struct lpfc_dmabuf *d_buf;
265         struct hbq_dmabuf *hbq_buf;
266
267         if (phba->sli_rev != 3)
268                 return 0;
269         cnt = LPFC_HBQINFO_SIZE;
270         spin_lock_irq(&phba->hbalock);
271
272         /* toggle between multiple hbqs, if any */
273         i = lpfc_sli_hbq_count();
274         if (i > 1) {
275                  lpfc_debugfs_last_hbq++;
276                  if (lpfc_debugfs_last_hbq >= i)
277                         lpfc_debugfs_last_hbq = 0;
278         }
279         else
280                 lpfc_debugfs_last_hbq = 0;
281
282         i = lpfc_debugfs_last_hbq;
283
284         len +=  snprintf(buf+len, size-len, "HBQ %d Info\n", i);
285
286         hbqs =  &phba->hbqs[i];
287         posted = 0;
288         list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
289                 posted++;
290
291         hip =  lpfc_hbq_defs[i];
292         len +=  snprintf(buf+len, size-len,
293                 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
294                 hip->hbq_index, hip->profile, hip->rn,
295                 hip->buffer_count, hip->init_count, hip->add_count, posted);
296
297         raw_index = phba->hbq_get[i];
298         getidx = le32_to_cpu(raw_index);
299         len +=  snprintf(buf+len, size-len,
300                 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
301                 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
302                 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
303
304         hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
305         for (j=0; j<hbqs->entry_count; j++) {
306                 len +=  snprintf(buf+len, size-len,
307                         "%03d: %08x %04x %05x ", j,
308                         le32_to_cpu(hbqe->bde.addrLow),
309                         le32_to_cpu(hbqe->bde.tus.w),
310                         le32_to_cpu(hbqe->buffer_tag));
311                 i = 0;
312                 found = 0;
313
314                 /* First calculate if slot has an associated posted buffer */
315                 low = hbqs->hbqPutIdx - posted;
316                 if (low >= 0) {
317                         if ((j >= hbqs->hbqPutIdx) || (j < low)) {
318                                 len +=  snprintf(buf+len, size-len, "Unused\n");
319                                 goto skipit;
320                         }
321                 }
322                 else {
323                         if ((j >= hbqs->hbqPutIdx) &&
324                                 (j < (hbqs->entry_count+low))) {
325                                 len +=  snprintf(buf+len, size-len, "Unused\n");
326                                 goto skipit;
327                         }
328                 }
329
330                 /* Get the Buffer info for the posted buffer */
331                 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
332                         hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
333                         phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
334                         if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
335                                 len +=  snprintf(buf+len, size-len,
336                                         "Buf%d: %p %06x\n", i,
337                                         hbq_buf->dbuf.virt, hbq_buf->tag);
338                                 found = 1;
339                                 break;
340                         }
341                         i++;
342                 }
343                 if (!found) {
344                         len +=  snprintf(buf+len, size-len, "No DMAinfo?\n");
345                 }
346 skipit:
347                 hbqe++;
348                 if (len > LPFC_HBQINFO_SIZE - 54)
349                         break;
350         }
351         spin_unlock_irq(&phba->hbalock);
352         return len;
353 }
354
355 static int lpfc_debugfs_last_hba_slim_off;
356
357 /**
358  * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
359  * @phba: The HBA to gather SLIM info from.
360  * @buf: The buffer to dump log into.
361  * @size: The maximum amount of data to process.
362  *
363  * Description:
364  * This routine dumps the current contents of HBA SLIM for the HBA associated
365  * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
366  *
367  * Notes:
368  * This routine will only dump up to 1024 bytes of data each time called and
369  * should be called multiple times to dump the entire HBA SLIM.
370  *
371  * Return Value:
372  * This routine returns the amount of bytes that were dumped into @buf and will
373  * not exceed @size.
374  **/
375 static int
376 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
377 {
378         int len = 0;
379         int i, off;
380         uint32_t *ptr;
381         char buffer[1024];
382
383         off = 0;
384         spin_lock_irq(&phba->hbalock);
385
386         len +=  snprintf(buf+len, size-len, "HBA SLIM\n");
387         lpfc_memcpy_from_slim(buffer,
388                 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
389
390         ptr = (uint32_t *)&buffer[0];
391         off = lpfc_debugfs_last_hba_slim_off;
392
393         /* Set it up for the next time */
394         lpfc_debugfs_last_hba_slim_off += 1024;
395         if (lpfc_debugfs_last_hba_slim_off >= 4096)
396                 lpfc_debugfs_last_hba_slim_off = 0;
397
398         i = 1024;
399         while (i > 0) {
400                 len +=  snprintf(buf+len, size-len,
401                 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
402                 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
403                 *(ptr+5), *(ptr+6), *(ptr+7));
404                 ptr += 8;
405                 i -= (8 * sizeof(uint32_t));
406                 off += (8 * sizeof(uint32_t));
407         }
408
409         spin_unlock_irq(&phba->hbalock);
410         return len;
411 }
412
413 /**
414  * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
415  * @phba: The HBA to gather Host SLIM info from.
416  * @buf: The buffer to dump log into.
417  * @size: The maximum amount of data to process.
418  *
419  * Description:
420  * This routine dumps the current contents of host SLIM for the host associated
421  * with @phba to @buf up to @size bytes of data. The dump will contain the
422  * Mailbox, PCB, Rings, and Registers that are located in host memory.
423  *
424  * Return Value:
425  * This routine returns the amount of bytes that were dumped into @buf and will
426  * not exceed @size.
427  **/
428 static int
429 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
430 {
431         int len = 0;
432         int i, off;
433         uint32_t word0, word1, word2, word3;
434         uint32_t *ptr;
435         struct lpfc_pgp *pgpp;
436         struct lpfc_sli *psli = &phba->sli;
437         struct lpfc_sli_ring *pring;
438
439         off = 0;
440         spin_lock_irq(&phba->hbalock);
441
442         len +=  snprintf(buf+len, size-len, "SLIM Mailbox\n");
443         ptr = (uint32_t *)phba->slim2p.virt;
444         i = sizeof(MAILBOX_t);
445         while (i > 0) {
446                 len +=  snprintf(buf+len, size-len,
447                 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
448                 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
449                 *(ptr+5), *(ptr+6), *(ptr+7));
450                 ptr += 8;
451                 i -= (8 * sizeof(uint32_t));
452                 off += (8 * sizeof(uint32_t));
453         }
454
455         len +=  snprintf(buf+len, size-len, "SLIM PCB\n");
456         ptr = (uint32_t *)phba->pcb;
457         i = sizeof(PCB_t);
458         while (i > 0) {
459                 len +=  snprintf(buf+len, size-len,
460                 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
461                 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
462                 *(ptr+5), *(ptr+6), *(ptr+7));
463                 ptr += 8;
464                 i -= (8 * sizeof(uint32_t));
465                 off += (8 * sizeof(uint32_t));
466         }
467
468         for (i = 0; i < 4; i++) {
469                 pgpp = &phba->port_gp[i];
470                 pring = &psli->ring[i];
471                 len +=  snprintf(buf+len, size-len,
472                                  "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
473                                  "Local:%d flg:x%x)  RSP PutInx:%d Max:%d\n",
474                                  i, pgpp->cmdGetInx, pring->numCiocb,
475                                  pring->next_cmdidx, pring->local_getidx,
476                                  pring->flag, pgpp->rspPutInx, pring->numRiocb);
477         }
478
479         if (phba->sli_rev <= LPFC_SLI_REV3) {
480                 word0 = readl(phba->HAregaddr);
481                 word1 = readl(phba->CAregaddr);
482                 word2 = readl(phba->HSregaddr);
483                 word3 = readl(phba->HCregaddr);
484                 len +=  snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
485                                  "HC:%08x\n", word0, word1, word2, word3);
486         }
487         spin_unlock_irq(&phba->hbalock);
488         return len;
489 }
490
491 /**
492  * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
493  * @vport: The vport to gather target node info from.
494  * @buf: The buffer to dump log into.
495  * @size: The maximum amount of data to process.
496  *
497  * Description:
498  * This routine dumps the current target node list associated with @vport to
499  * @buf up to @size bytes of data. Each node entry in the dump will contain a
500  * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
501  *
502  * Return Value:
503  * This routine returns the amount of bytes that were dumped into @buf and will
504  * not exceed @size.
505  **/
506 static int
507 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
508 {
509         int len = 0;
510         int cnt;
511         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
512         struct lpfc_nodelist *ndlp;
513         unsigned char *statep, *name;
514
515         cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
516
517         spin_lock_irq(shost->host_lock);
518         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
519                 if (!cnt) {
520                         len +=  snprintf(buf+len, size-len,
521                                 "Missing Nodelist Entries\n");
522                         break;
523                 }
524                 cnt--;
525                 switch (ndlp->nlp_state) {
526                 case NLP_STE_UNUSED_NODE:
527                         statep = "UNUSED";
528                         break;
529                 case NLP_STE_PLOGI_ISSUE:
530                         statep = "PLOGI ";
531                         break;
532                 case NLP_STE_ADISC_ISSUE:
533                         statep = "ADISC ";
534                         break;
535                 case NLP_STE_REG_LOGIN_ISSUE:
536                         statep = "REGLOG";
537                         break;
538                 case NLP_STE_PRLI_ISSUE:
539                         statep = "PRLI  ";
540                         break;
541                 case NLP_STE_UNMAPPED_NODE:
542                         statep = "UNMAP ";
543                         break;
544                 case NLP_STE_MAPPED_NODE:
545                         statep = "MAPPED";
546                         break;
547                 case NLP_STE_NPR_NODE:
548                         statep = "NPR   ";
549                         break;
550                 default:
551                         statep = "UNKNOWN";
552                 }
553                 len +=  snprintf(buf+len, size-len, "%s DID:x%06x ",
554                         statep, ndlp->nlp_DID);
555                 name = (unsigned char *)&ndlp->nlp_portname;
556                 len +=  snprintf(buf+len, size-len,
557                         "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
558                         *name, *(name+1), *(name+2), *(name+3),
559                         *(name+4), *(name+5), *(name+6), *(name+7));
560                 name = (unsigned char *)&ndlp->nlp_nodename;
561                 len +=  snprintf(buf+len, size-len,
562                         "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
563                         *name, *(name+1), *(name+2), *(name+3),
564                         *(name+4), *(name+5), *(name+6), *(name+7));
565                 len +=  snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
566                         ndlp->nlp_rpi, ndlp->nlp_flag);
567                 if (!ndlp->nlp_type)
568                         len +=  snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
569                 if (ndlp->nlp_type & NLP_FC_NODE)
570                         len +=  snprintf(buf+len, size-len, "FC_NODE ");
571                 if (ndlp->nlp_type & NLP_FABRIC)
572                         len +=  snprintf(buf+len, size-len, "FABRIC ");
573                 if (ndlp->nlp_type & NLP_FCP_TARGET)
574                         len +=  snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
575                                 ndlp->nlp_sid);
576                 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
577                         len +=  snprintf(buf+len, size-len, "FCP_INITIATOR ");
578                 len += snprintf(buf+len, size-len, "usgmap:%x ",
579                         ndlp->nlp_usg_map);
580                 len += snprintf(buf+len, size-len, "refcnt:%x",
581                         atomic_read(&ndlp->kref.refcount));
582                 len +=  snprintf(buf+len, size-len, "\n");
583         }
584         spin_unlock_irq(shost->host_lock);
585         return len;
586 }
587 #endif
588
589 /**
590  * lpfc_debugfs_disc_trc - Store discovery trace log
591  * @vport: The vport to associate this trace string with for retrieval.
592  * @mask: Log entry classification.
593  * @fmt: Format string to be displayed when dumping the log.
594  * @data1: 1st data parameter to be applied to @fmt.
595  * @data2: 2nd data parameter to be applied to @fmt.
596  * @data3: 3rd data parameter to be applied to @fmt.
597  *
598  * Description:
599  * This routine is used by the driver code to add a debugfs log entry to the
600  * discovery trace buffer associated with @vport. Only entries with a @mask that
601  * match the current debugfs discovery mask will be saved. Entries that do not
602  * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
603  * printf when displaying the log.
604  **/
605 inline void
606 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
607         uint32_t data1, uint32_t data2, uint32_t data3)
608 {
609 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
610         struct lpfc_debugfs_trc *dtp;
611         int index;
612
613         if (!(lpfc_debugfs_mask_disc_trc & mask))
614                 return;
615
616         if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
617                 !vport || !vport->disc_trc)
618                 return;
619
620         index = atomic_inc_return(&vport->disc_trc_cnt) &
621                 (lpfc_debugfs_max_disc_trc - 1);
622         dtp = vport->disc_trc + index;
623         dtp->fmt = fmt;
624         dtp->data1 = data1;
625         dtp->data2 = data2;
626         dtp->data3 = data3;
627         dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
628         dtp->jif = jiffies;
629 #endif
630         return;
631 }
632
633 /**
634  * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
635  * @phba: The phba to associate this trace string with for retrieval.
636  * @fmt: Format string to be displayed when dumping the log.
637  * @data1: 1st data parameter to be applied to @fmt.
638  * @data2: 2nd data parameter to be applied to @fmt.
639  * @data3: 3rd data parameter to be applied to @fmt.
640  *
641  * Description:
642  * This routine is used by the driver code to add a debugfs log entry to the
643  * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
644  * @data3 are used like printf when displaying the log.
645  **/
646 inline void
647 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
648         uint32_t data1, uint32_t data2, uint32_t data3)
649 {
650 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
651         struct lpfc_debugfs_trc *dtp;
652         int index;
653
654         if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
655                 !phba || !phba->slow_ring_trc)
656                 return;
657
658         index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
659                 (lpfc_debugfs_max_slow_ring_trc - 1);
660         dtp = phba->slow_ring_trc + index;
661         dtp->fmt = fmt;
662         dtp->data1 = data1;
663         dtp->data2 = data2;
664         dtp->data3 = data3;
665         dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
666         dtp->jif = jiffies;
667 #endif
668         return;
669 }
670
671 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
672 /**
673  * lpfc_debugfs_disc_trc_open - Open the discovery trace log
674  * @inode: The inode pointer that contains a vport pointer.
675  * @file: The file pointer to attach the log output.
676  *
677  * Description:
678  * This routine is the entry point for the debugfs open file operation. It gets
679  * the vport from the i_private field in @inode, allocates the necessary buffer
680  * for the log, fills the buffer from the in-memory log for this vport, and then
681  * returns a pointer to that log in the private_data field in @file.
682  *
683  * Returns:
684  * This function returns zero if successful. On error it will return an negative
685  * error value.
686  **/
687 static int
688 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
689 {
690         struct lpfc_vport *vport = inode->i_private;
691         struct lpfc_debug *debug;
692         int size;
693         int rc = -ENOMEM;
694
695         if (!lpfc_debugfs_max_disc_trc) {
696                  rc = -ENOSPC;
697                 goto out;
698         }
699
700         debug = kmalloc(sizeof(*debug), GFP_KERNEL);
701         if (!debug)
702                 goto out;
703
704         /* Round to page boundary */
705         size =  (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
706         size = PAGE_ALIGN(size);
707
708         debug->buffer = kmalloc(size, GFP_KERNEL);
709         if (!debug->buffer) {
710                 kfree(debug);
711                 goto out;
712         }
713
714         debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
715         file->private_data = debug;
716
717         rc = 0;
718 out:
719         return rc;
720 }
721
722 /**
723  * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
724  * @inode: The inode pointer that contains a vport pointer.
725  * @file: The file pointer to attach the log output.
726  *
727  * Description:
728  * This routine is the entry point for the debugfs open file operation. It gets
729  * the vport from the i_private field in @inode, allocates the necessary buffer
730  * for the log, fills the buffer from the in-memory log for this vport, and then
731  * returns a pointer to that log in the private_data field in @file.
732  *
733  * Returns:
734  * This function returns zero if successful. On error it will return an negative
735  * error value.
736  **/
737 static int
738 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
739 {
740         struct lpfc_hba *phba = inode->i_private;
741         struct lpfc_debug *debug;
742         int size;
743         int rc = -ENOMEM;
744
745         if (!lpfc_debugfs_max_slow_ring_trc) {
746                  rc = -ENOSPC;
747                 goto out;
748         }
749
750         debug = kmalloc(sizeof(*debug), GFP_KERNEL);
751         if (!debug)
752                 goto out;
753
754         /* Round to page boundary */
755         size =  (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
756         size = PAGE_ALIGN(size);
757
758         debug->buffer = kmalloc(size, GFP_KERNEL);
759         if (!debug->buffer) {
760                 kfree(debug);
761                 goto out;
762         }
763
764         debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
765         file->private_data = debug;
766
767         rc = 0;
768 out:
769         return rc;
770 }
771
772 /**
773  * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
774  * @inode: The inode pointer that contains a vport pointer.
775  * @file: The file pointer to attach the log output.
776  *
777  * Description:
778  * This routine is the entry point for the debugfs open file operation. It gets
779  * the vport from the i_private field in @inode, allocates the necessary buffer
780  * for the log, fills the buffer from the in-memory log for this vport, and then
781  * returns a pointer to that log in the private_data field in @file.
782  *
783  * Returns:
784  * This function returns zero if successful. On error it will return an negative
785  * error value.
786  **/
787 static int
788 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
789 {
790         struct lpfc_hba *phba = inode->i_private;
791         struct lpfc_debug *debug;
792         int rc = -ENOMEM;
793
794         debug = kmalloc(sizeof(*debug), GFP_KERNEL);
795         if (!debug)
796                 goto out;
797
798         /* Round to page boundary */
799         debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
800         if (!debug->buffer) {
801                 kfree(debug);
802                 goto out;
803         }
804
805         debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
806                 LPFC_HBQINFO_SIZE);
807         file->private_data = debug;
808
809         rc = 0;
810 out:
811         return rc;
812 }
813
814 /**
815  * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
816  * @inode: The inode pointer that contains a vport pointer.
817  * @file: The file pointer to attach the log output.
818  *
819  * Description:
820  * This routine is the entry point for the debugfs open file operation. It gets
821  * the vport from the i_private field in @inode, allocates the necessary buffer
822  * for the log, fills the buffer from the in-memory log for this vport, and then
823  * returns a pointer to that log in the private_data field in @file.
824  *
825  * Returns:
826  * This function returns zero if successful. On error it will return an negative
827  * error value.
828  **/
829 static int
830 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
831 {
832         struct lpfc_hba *phba = inode->i_private;
833         struct lpfc_debug *debug;
834         int rc = -ENOMEM;
835
836         debug = kmalloc(sizeof(*debug), GFP_KERNEL);
837         if (!debug)
838                 goto out;
839
840         /* Round to page boundary */
841         debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
842         if (!debug->buffer) {
843                 kfree(debug);
844                 goto out;
845         }
846
847         debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
848                 LPFC_DUMPHBASLIM_SIZE);
849         file->private_data = debug;
850
851         rc = 0;
852 out:
853         return rc;
854 }
855
856 /**
857  * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
858  * @inode: The inode pointer that contains a vport pointer.
859  * @file: The file pointer to attach the log output.
860  *
861  * Description:
862  * This routine is the entry point for the debugfs open file operation. It gets
863  * the vport from the i_private field in @inode, allocates the necessary buffer
864  * for the log, fills the buffer from the in-memory log for this vport, and then
865  * returns a pointer to that log in the private_data field in @file.
866  *
867  * Returns:
868  * This function returns zero if successful. On error it will return an negative
869  * error value.
870  **/
871 static int
872 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
873 {
874         struct lpfc_hba *phba = inode->i_private;
875         struct lpfc_debug *debug;
876         int rc = -ENOMEM;
877
878         debug = kmalloc(sizeof(*debug), GFP_KERNEL);
879         if (!debug)
880                 goto out;
881
882         /* Round to page boundary */
883         debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
884         if (!debug->buffer) {
885                 kfree(debug);
886                 goto out;
887         }
888
889         debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
890                 LPFC_DUMPHOSTSLIM_SIZE);
891         file->private_data = debug;
892
893         rc = 0;
894 out:
895         return rc;
896 }
897
898 static int
899 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
900 {
901         struct lpfc_debug *debug;
902         int rc = -ENOMEM;
903
904         if (!_dump_buf_data)
905                 return -EBUSY;
906
907         debug = kmalloc(sizeof(*debug), GFP_KERNEL);
908         if (!debug)
909                 goto out;
910
911         /* Round to page boundary */
912         printk(KERN_ERR "9059 BLKGRD:  %s: _dump_buf_data=0x%p\n",
913                         __func__, _dump_buf_data);
914         debug->buffer = _dump_buf_data;
915         if (!debug->buffer) {
916                 kfree(debug);
917                 goto out;
918         }
919
920         debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
921         file->private_data = debug;
922
923         rc = 0;
924 out:
925         return rc;
926 }
927
928 static int
929 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
930 {
931         struct lpfc_debug *debug;
932         int rc = -ENOMEM;
933
934         if (!_dump_buf_dif)
935                 return -EBUSY;
936
937         debug = kmalloc(sizeof(*debug), GFP_KERNEL);
938         if (!debug)
939                 goto out;
940
941         /* Round to page boundary */
942         printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
943                 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
944         debug->buffer = _dump_buf_dif;
945         if (!debug->buffer) {
946                 kfree(debug);
947                 goto out;
948         }
949
950         debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
951         file->private_data = debug;
952
953         rc = 0;
954 out:
955         return rc;
956 }
957
958 static ssize_t
959 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
960                   size_t nbytes, loff_t *ppos)
961 {
962         /*
963          * The Data/DIF buffers only save one failing IO
964          * The write op is used as a reset mechanism after an IO has
965          * already been saved to the next one can be saved
966          */
967         spin_lock(&_dump_buf_lock);
968
969         memset((void *)_dump_buf_data, 0,
970                         ((1 << PAGE_SHIFT) << _dump_buf_data_order));
971         memset((void *)_dump_buf_dif, 0,
972                         ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
973
974         _dump_buf_done = 0;
975
976         spin_unlock(&_dump_buf_lock);
977
978         return nbytes;
979 }
980
981 /**
982  * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
983  * @inode: The inode pointer that contains a vport pointer.
984  * @file: The file pointer to attach the log output.
985  *
986  * Description:
987  * This routine is the entry point for the debugfs open file operation. It gets
988  * the vport from the i_private field in @inode, allocates the necessary buffer
989  * for the log, fills the buffer from the in-memory log for this vport, and then
990  * returns a pointer to that log in the private_data field in @file.
991  *
992  * Returns:
993  * This function returns zero if successful. On error it will return an negative
994  * error value.
995  **/
996 static int
997 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
998 {
999         struct lpfc_vport *vport = inode->i_private;
1000         struct lpfc_debug *debug;
1001         int rc = -ENOMEM;
1002
1003         debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1004         if (!debug)
1005                 goto out;
1006
1007         /* Round to page boundary */
1008         debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1009         if (!debug->buffer) {
1010                 kfree(debug);
1011                 goto out;
1012         }
1013
1014         debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1015                 LPFC_NODELIST_SIZE);
1016         file->private_data = debug;
1017
1018         rc = 0;
1019 out:
1020         return rc;
1021 }
1022
1023 /**
1024  * lpfc_debugfs_lseek - Seek through a debugfs file
1025  * @file: The file pointer to seek through.
1026  * @off: The offset to seek to or the amount to seek by.
1027  * @whence: Indicates how to seek.
1028  *
1029  * Description:
1030  * This routine is the entry point for the debugfs lseek file operation. The
1031  * @whence parameter indicates whether @off is the offset to directly seek to,
1032  * or if it is a value to seek forward or reverse by. This function figures out
1033  * what the new offset of the debugfs file will be and assigns that value to the
1034  * f_pos field of @file.
1035  *
1036  * Returns:
1037  * This function returns the new offset if successful and returns a negative
1038  * error if unable to process the seek.
1039  **/
1040 static loff_t
1041 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1042 {
1043         struct lpfc_debug *debug;
1044         loff_t pos = -1;
1045
1046         debug = file->private_data;
1047
1048         switch (whence) {
1049         case 0:
1050                 pos = off;
1051                 break;
1052         case 1:
1053                 pos = file->f_pos + off;
1054                 break;
1055         case 2:
1056                 pos = debug->len - off;
1057         }
1058         return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1059 }
1060
1061 /**
1062  * lpfc_debugfs_read - Read a debugfs file
1063  * @file: The file pointer to read from.
1064  * @buf: The buffer to copy the data to.
1065  * @nbytes: The number of bytes to read.
1066  * @ppos: The position in the file to start reading from.
1067  *
1068  * Description:
1069  * This routine reads data from from the buffer indicated in the private_data
1070  * field of @file. It will start reading at @ppos and copy up to @nbytes of
1071  * data to @buf.
1072  *
1073  * Returns:
1074  * This function returns the amount of data that was read (this could be less
1075  * than @nbytes if the end of the file was reached) or a negative error value.
1076  **/
1077 static ssize_t
1078 lpfc_debugfs_read(struct file *file, char __user *buf,
1079                   size_t nbytes, loff_t *ppos)
1080 {
1081         struct lpfc_debug *debug = file->private_data;
1082
1083         return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1084                                        debug->len);
1085 }
1086
1087 /**
1088  * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1089  * @inode: The inode pointer that contains a vport pointer. (unused)
1090  * @file: The file pointer that contains the buffer to release.
1091  *
1092  * Description:
1093  * This routine frees the buffer that was allocated when the debugfs file was
1094  * opened.
1095  *
1096  * Returns:
1097  * This function returns zero.
1098  **/
1099 static int
1100 lpfc_debugfs_release(struct inode *inode, struct file *file)
1101 {
1102         struct lpfc_debug *debug = file->private_data;
1103
1104         kfree(debug->buffer);
1105         kfree(debug);
1106
1107         return 0;
1108 }
1109
1110 static int
1111 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1112 {
1113         struct lpfc_debug *debug = file->private_data;
1114
1115         debug->buffer = NULL;
1116         kfree(debug);
1117
1118         return 0;
1119 }
1120
1121 /*
1122  * ---------------------------------
1123  * iDiag debugfs file access methods
1124  * ---------------------------------
1125  *
1126  * All access methods are through the proper SLI4 PCI function's debugfs
1127  * iDiag directory:
1128  *
1129  *     /sys/kernel/debug/lpfc/fn<#>/iDiag
1130  */
1131
1132 /**
1133  * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1134  * @buf: The pointer to the user space buffer.
1135  * @nbytes: The number of bytes in the user space buffer.
1136  * @idiag_cmd: pointer to the idiag command struct.
1137  *
1138  * This routine reads data from debugfs user space buffer and parses the
1139  * buffer for getting the idiag command and arguments. The while space in
1140  * between the set of data is used as the parsing separator.
1141  *
1142  * This routine returns 0 when successful, it returns proper error code
1143  * back to the user space in error conditions.
1144  */
1145 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1146                               struct lpfc_idiag_cmd *idiag_cmd)
1147 {
1148         char mybuf[64];
1149         char *pbuf, *step_str;
1150         int bsize, i;
1151
1152         /* Protect copy from user */
1153         if (!access_ok(VERIFY_READ, buf, nbytes))
1154                 return -EFAULT;
1155
1156         memset(mybuf, 0, sizeof(mybuf));
1157         memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1158         bsize = min(nbytes, (sizeof(mybuf)-1));
1159
1160         if (copy_from_user(mybuf, buf, bsize))
1161                 return -EFAULT;
1162         pbuf = &mybuf[0];
1163         step_str = strsep(&pbuf, "\t ");
1164
1165         /* The opcode must present */
1166         if (!step_str)
1167                 return -EINVAL;
1168
1169         idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1170         if (idiag_cmd->opcode == 0)
1171                 return -EINVAL;
1172
1173         for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1174                 step_str = strsep(&pbuf, "\t ");
1175                 if (!step_str)
1176                         return i;
1177                 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1178         }
1179         return i;
1180 }
1181
1182 /**
1183  * lpfc_idiag_open - idiag open debugfs
1184  * @inode: The inode pointer that contains a pointer to phba.
1185  * @file: The file pointer to attach the file operation.
1186  *
1187  * Description:
1188  * This routine is the entry point for the debugfs open file operation. It
1189  * gets the reference to phba from the i_private field in @inode, it then
1190  * allocates buffer for the file operation, performs the necessary PCI config
1191  * space read into the allocated buffer according to the idiag user command
1192  * setup, and then returns a pointer to buffer in the private_data field in
1193  * @file.
1194  *
1195  * Returns:
1196  * This function returns zero if successful. On error it will return an
1197  * negative error value.
1198  **/
1199 static int
1200 lpfc_idiag_open(struct inode *inode, struct file *file)
1201 {
1202         struct lpfc_debug *debug;
1203
1204         debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1205         if (!debug)
1206                 return -ENOMEM;
1207
1208         debug->i_private = inode->i_private;
1209         debug->buffer = NULL;
1210         file->private_data = debug;
1211
1212         return 0;
1213 }
1214
1215 /**
1216  * lpfc_idiag_release - Release idiag access file operation
1217  * @inode: The inode pointer that contains a vport pointer. (unused)
1218  * @file: The file pointer that contains the buffer to release.
1219  *
1220  * Description:
1221  * This routine is the generic release routine for the idiag access file
1222  * operation, it frees the buffer that was allocated when the debugfs file
1223  * was opened.
1224  *
1225  * Returns:
1226  * This function returns zero.
1227  **/
1228 static int
1229 lpfc_idiag_release(struct inode *inode, struct file *file)
1230 {
1231         struct lpfc_debug *debug = file->private_data;
1232
1233         /* Free the buffers to the file operation */
1234         kfree(debug->buffer);
1235         kfree(debug);
1236
1237         return 0;
1238 }
1239
1240 /**
1241  * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1242  * @inode: The inode pointer that contains a vport pointer. (unused)
1243  * @file: The file pointer that contains the buffer to release.
1244  *
1245  * Description:
1246  * This routine frees the buffer that was allocated when the debugfs file
1247  * was opened. It also reset the fields in the idiag command struct in the
1248  * case of command for write operation.
1249  *
1250  * Returns:
1251  * This function returns zero.
1252  **/
1253 static int
1254 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1255 {
1256         struct lpfc_debug *debug = file->private_data;
1257
1258         if (debug->op == LPFC_IDIAG_OP_WR) {
1259                 switch (idiag.cmd.opcode) {
1260                 case LPFC_IDIAG_CMD_PCICFG_WR:
1261                 case LPFC_IDIAG_CMD_PCICFG_ST:
1262                 case LPFC_IDIAG_CMD_PCICFG_CL:
1263                 case LPFC_IDIAG_CMD_QUEACC_WR:
1264                 case LPFC_IDIAG_CMD_QUEACC_ST:
1265                 case LPFC_IDIAG_CMD_QUEACC_CL:
1266                         memset(&idiag, 0, sizeof(idiag));
1267                         break;
1268                 default:
1269                         break;
1270                 }
1271         }
1272
1273         /* Free the buffers to the file operation */
1274         kfree(debug->buffer);
1275         kfree(debug);
1276
1277         return 0;
1278 }
1279
1280 /**
1281  * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1282  * @file: The file pointer to read from.
1283  * @buf: The buffer to copy the data to.
1284  * @nbytes: The number of bytes to read.
1285  * @ppos: The position in the file to start reading from.
1286  *
1287  * Description:
1288  * This routine reads data from the @phba pci config space according to the
1289  * idiag command, and copies to user @buf. Depending on the PCI config space
1290  * read command setup, it does either a single register read of a byte
1291  * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1292  * registers from the 4K extended PCI config space.
1293  *
1294  * Returns:
1295  * This function returns the amount of data that was read (this could be less
1296  * than @nbytes if the end of the file was reached) or a negative error value.
1297  **/
1298 static ssize_t
1299 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1300                        loff_t *ppos)
1301 {
1302         struct lpfc_debug *debug = file->private_data;
1303         struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1304         int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1305         int where, count;
1306         char *pbuffer;
1307         struct pci_dev *pdev;
1308         uint32_t u32val;
1309         uint16_t u16val;
1310         uint8_t u8val;
1311
1312         pdev = phba->pcidev;
1313         if (!pdev)
1314                 return 0;
1315
1316         /* This is a user read operation */
1317         debug->op = LPFC_IDIAG_OP_RD;
1318
1319         if (!debug->buffer)
1320                 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1321         if (!debug->buffer)
1322                 return 0;
1323         pbuffer = debug->buffer;
1324
1325         if (*ppos)
1326                 return 0;
1327
1328         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1329                 where = idiag.cmd.data[0];
1330                 count = idiag.cmd.data[1];
1331         } else
1332                 return 0;
1333
1334         /* Read single PCI config space register */
1335         switch (count) {
1336         case SIZE_U8: /* byte (8 bits) */
1337                 pci_read_config_byte(pdev, where, &u8val);
1338                 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1339                                 "%03x: %02x\n", where, u8val);
1340                 break;
1341         case SIZE_U16: /* word (16 bits) */
1342                 pci_read_config_word(pdev, where, &u16val);
1343                 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1344                                 "%03x: %04x\n", where, u16val);
1345                 break;
1346         case SIZE_U32: /* double word (32 bits) */
1347                 pci_read_config_dword(pdev, where, &u32val);
1348                 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1349                                 "%03x: %08x\n", where, u32val);
1350                 break;
1351         case LPFC_PCI_CFG_BROWSE: /* browse all */
1352                 goto pcicfg_browse;
1353                 break;
1354         default:
1355                 /* illegal count */
1356                 len = 0;
1357                 break;
1358         }
1359         return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1360
1361 pcicfg_browse:
1362
1363         /* Browse all PCI config space registers */
1364         offset_label = idiag.offset.last_rd;
1365         offset = offset_label;
1366
1367         /* Read PCI config space */
1368         len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1369                         "%03x: ", offset_label);
1370         while (index > 0) {
1371                 pci_read_config_dword(pdev, offset, &u32val);
1372                 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1373                                 "%08x ", u32val);
1374                 offset += sizeof(uint32_t);
1375                 index -= sizeof(uint32_t);
1376                 if (!index)
1377                         len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1378                                         "\n");
1379                 else if (!(index % (8 * sizeof(uint32_t)))) {
1380                         offset_label += (8 * sizeof(uint32_t));
1381                         len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1382                                         "\n%03x: ", offset_label);
1383                 }
1384         }
1385
1386         /* Set up the offset for next portion of pci cfg read */
1387         idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1388         if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1389                 idiag.offset.last_rd = 0;
1390
1391         return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1392 }
1393
1394 /**
1395  * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1396  * @file: The file pointer to read from.
1397  * @buf: The buffer to copy the user data from.
1398  * @nbytes: The number of bytes to get.
1399  * @ppos: The position in the file to start reading from.
1400  *
1401  * This routine get the debugfs idiag command struct from user space and
1402  * then perform the syntax check for PCI config space read or write command
1403  * accordingly. In the case of PCI config space read command, it sets up
1404  * the command in the idiag command struct for the debugfs read operation.
1405  * In the case of PCI config space write operation, it executes the write
1406  * operation into the PCI config space accordingly.
1407  *
1408  * It returns the @nbytges passing in from debugfs user space when successful.
1409  * In case of error conditions, it returns proper error code back to the user
1410  * space.
1411  */
1412 static ssize_t
1413 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1414                         size_t nbytes, loff_t *ppos)
1415 {
1416         struct lpfc_debug *debug = file->private_data;
1417         struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1418         uint32_t where, value, count;
1419         uint32_t u32val;
1420         uint16_t u16val;
1421         uint8_t u8val;
1422         struct pci_dev *pdev;
1423         int rc;
1424
1425         pdev = phba->pcidev;
1426         if (!pdev)
1427                 return -EFAULT;
1428
1429         /* This is a user write operation */
1430         debug->op = LPFC_IDIAG_OP_WR;
1431
1432         rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1433         if (rc < 0)
1434                 return rc;
1435
1436         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1437                 /* Sanity check on PCI config read command line arguments */
1438                 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1439                         goto error_out;
1440                 /* Read command from PCI config space, set up command fields */
1441                 where = idiag.cmd.data[0];
1442                 count = idiag.cmd.data[1];
1443                 if (count == LPFC_PCI_CFG_BROWSE) {
1444                         if (where % sizeof(uint32_t))
1445                                 goto error_out;
1446                         /* Starting offset to browse */
1447                         idiag.offset.last_rd = where;
1448                 } else if ((count != sizeof(uint8_t)) &&
1449                            (count != sizeof(uint16_t)) &&
1450                            (count != sizeof(uint32_t)))
1451                         goto error_out;
1452                 if (count == sizeof(uint8_t)) {
1453                         if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1454                                 goto error_out;
1455                         if (where % sizeof(uint8_t))
1456                                 goto error_out;
1457                 }
1458                 if (count == sizeof(uint16_t)) {
1459                         if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1460                                 goto error_out;
1461                         if (where % sizeof(uint16_t))
1462                                 goto error_out;
1463                 }
1464                 if (count == sizeof(uint32_t)) {
1465                         if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1466                                 goto error_out;
1467                         if (where % sizeof(uint32_t))
1468                                 goto error_out;
1469                 }
1470         } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1471                    idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1472                    idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1473                 /* Sanity check on PCI config write command line arguments */
1474                 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1475                         goto error_out;
1476                 /* Write command to PCI config space, read-modify-write */
1477                 where = idiag.cmd.data[0];
1478                 count = idiag.cmd.data[1];
1479                 value = idiag.cmd.data[2];
1480                 /* Sanity checks */
1481                 if ((count != sizeof(uint8_t)) &&
1482                     (count != sizeof(uint16_t)) &&
1483                     (count != sizeof(uint32_t)))
1484                         goto error_out;
1485                 if (count == sizeof(uint8_t)) {
1486                         if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1487                                 goto error_out;
1488                         if (where % sizeof(uint8_t))
1489                                 goto error_out;
1490                         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1491                                 pci_write_config_byte(pdev, where,
1492                                                       (uint8_t)value);
1493                         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1494                                 rc = pci_read_config_byte(pdev, where, &u8val);
1495                                 if (!rc) {
1496                                         u8val |= (uint8_t)value;
1497                                         pci_write_config_byte(pdev, where,
1498                                                               u8val);
1499                                 }
1500                         }
1501                         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1502                                 rc = pci_read_config_byte(pdev, where, &u8val);
1503                                 if (!rc) {
1504                                         u8val &= (uint8_t)(~value);
1505                                         pci_write_config_byte(pdev, where,
1506                                                               u8val);
1507                                 }
1508                         }
1509                 }
1510                 if (count == sizeof(uint16_t)) {
1511                         if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1512                                 goto error_out;
1513                         if (where % sizeof(uint16_t))
1514                                 goto error_out;
1515                         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1516                                 pci_write_config_word(pdev, where,
1517                                                       (uint16_t)value);
1518                         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1519                                 rc = pci_read_config_word(pdev, where, &u16val);
1520                                 if (!rc) {
1521                                         u16val |= (uint16_t)value;
1522                                         pci_write_config_word(pdev, where,
1523                                                               u16val);
1524                                 }
1525                         }
1526                         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1527                                 rc = pci_read_config_word(pdev, where, &u16val);
1528                                 if (!rc) {
1529                                         u16val &= (uint16_t)(~value);
1530                                         pci_write_config_word(pdev, where,
1531                                                               u16val);
1532                                 }
1533                         }
1534                 }
1535                 if (count == sizeof(uint32_t)) {
1536                         if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1537                                 goto error_out;
1538                         if (where % sizeof(uint32_t))
1539                                 goto error_out;
1540                         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1541                                 pci_write_config_dword(pdev, where, value);
1542                         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1543                                 rc = pci_read_config_dword(pdev, where,
1544                                                            &u32val);
1545                                 if (!rc) {
1546                                         u32val |= value;
1547                                         pci_write_config_dword(pdev, where,
1548                                                                u32val);
1549                                 }
1550                         }
1551                         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1552                                 rc = pci_read_config_dword(pdev, where,
1553                                                            &u32val);
1554                                 if (!rc) {
1555                                         u32val &= ~value;
1556                                         pci_write_config_dword(pdev, where,
1557                                                                u32val);
1558                                 }
1559                         }
1560                 }
1561         } else
1562                 /* All other opecodes are illegal for now */
1563                 goto error_out;
1564
1565         return nbytes;
1566 error_out:
1567         memset(&idiag, 0, sizeof(idiag));
1568         return -EINVAL;
1569 }
1570
1571 /**
1572  * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1573  * @file: The file pointer to read from.
1574  * @buf: The buffer to copy the data to.
1575  * @nbytes: The number of bytes to read.
1576  * @ppos: The position in the file to start reading from.
1577  *
1578  * Description:
1579  * This routine reads data from the @phba SLI4 PCI function queue information,
1580  * and copies to user @buf.
1581  *
1582  * Returns:
1583  * This function returns the amount of data that was read (this could be less
1584  * than @nbytes if the end of the file was reached) or a negative error value.
1585  **/
1586 static ssize_t
1587 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
1588                         loff_t *ppos)
1589 {
1590         struct lpfc_debug *debug = file->private_data;
1591         struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1592         int len = 0, fcp_qidx;
1593         char *pbuffer;
1594
1595         if (!debug->buffer)
1596                 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
1597         if (!debug->buffer)
1598                 return 0;
1599         pbuffer = debug->buffer;
1600
1601         if (*ppos)
1602                 return 0;
1603
1604         /* Get slow-path event queue information */
1605         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1606                         "Slow-path EQ information:\n");
1607         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1608                         "\tEQID[%02d], "
1609                         "QE-COUNT[%04d], QE-SIZE[%04d], "
1610                         "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1611                         phba->sli4_hba.sp_eq->queue_id,
1612                         phba->sli4_hba.sp_eq->entry_count,
1613                         phba->sli4_hba.sp_eq->entry_size,
1614                         phba->sli4_hba.sp_eq->host_index,
1615                         phba->sli4_hba.sp_eq->hba_index);
1616
1617         /* Get fast-path event queue information */
1618         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1619                         "Fast-path EQ information:\n");
1620         for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
1621                 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1622                                 "\tEQID[%02d], "
1623                                 "QE-COUNT[%04d], QE-SIZE[%04d], "
1624                                 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1625                                 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
1626                                 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
1627                                 phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
1628                                 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
1629                                 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
1630         }
1631         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1632
1633         /* Get mailbox complete queue information */
1634         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1635                         "Slow-path MBX CQ information:\n");
1636         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1637                         "Associated EQID[%02d]:\n",
1638                         phba->sli4_hba.mbx_cq->assoc_qid);
1639         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1640                         "\tCQID[%02d], "
1641                         "QE-COUNT[%04d], QE-SIZE[%04d], "
1642                         "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1643                         phba->sli4_hba.mbx_cq->queue_id,
1644                         phba->sli4_hba.mbx_cq->entry_count,
1645                         phba->sli4_hba.mbx_cq->entry_size,
1646                         phba->sli4_hba.mbx_cq->host_index,
1647                         phba->sli4_hba.mbx_cq->hba_index);
1648
1649         /* Get slow-path complete queue information */
1650         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1651                         "Slow-path ELS CQ information:\n");
1652         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1653                         "Associated EQID[%02d]:\n",
1654                         phba->sli4_hba.els_cq->assoc_qid);
1655         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1656                         "\tCQID [%02d], "
1657                         "QE-COUNT[%04d], QE-SIZE[%04d], "
1658                         "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1659                         phba->sli4_hba.els_cq->queue_id,
1660                         phba->sli4_hba.els_cq->entry_count,
1661                         phba->sli4_hba.els_cq->entry_size,
1662                         phba->sli4_hba.els_cq->host_index,
1663                         phba->sli4_hba.els_cq->hba_index);
1664
1665         /* Get fast-path complete queue information */
1666         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1667                         "Fast-path FCP CQ information:\n");
1668         for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
1669                 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1670                                 "Associated EQID[%02d]:\n",
1671                                 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
1672                 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1673                                 "\tCQID[%02d], "
1674                                 "QE-COUNT[%04d], QE-SIZE[%04d], "
1675                                 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1676                                 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
1677                                 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
1678                                 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
1679                                 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
1680                                 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
1681         }
1682         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1683
1684         /* Get mailbox queue information */
1685         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1686                         "Slow-path MBX MQ information:\n");
1687         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1688                         "Associated CQID[%02d]:\n",
1689                         phba->sli4_hba.mbx_wq->assoc_qid);
1690         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1691                         "\tWQID[%02d], "
1692                         "QE-COUNT[%04d], QE-SIZE[%04d], "
1693                         "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1694                         phba->sli4_hba.mbx_wq->queue_id,
1695                         phba->sli4_hba.mbx_wq->entry_count,
1696                         phba->sli4_hba.mbx_wq->entry_size,
1697                         phba->sli4_hba.mbx_wq->host_index,
1698                         phba->sli4_hba.mbx_wq->hba_index);
1699
1700         /* Get slow-path work queue information */
1701         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1702                         "Slow-path ELS WQ information:\n");
1703         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1704                         "Associated CQID[%02d]:\n",
1705                         phba->sli4_hba.els_wq->assoc_qid);
1706         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1707                         "\tWQID[%02d], "
1708                         "QE-COUNT[%04d], QE-SIZE[%04d], "
1709                         "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
1710                         phba->sli4_hba.els_wq->queue_id,
1711                         phba->sli4_hba.els_wq->entry_count,
1712                         phba->sli4_hba.els_wq->entry_size,
1713                         phba->sli4_hba.els_wq->host_index,
1714                         phba->sli4_hba.els_wq->hba_index);
1715
1716         /* Get fast-path work queue information */
1717         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1718                         "Fast-path FCP WQ information:\n");
1719         for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
1720                 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1721                                 "Associated CQID[%02d]:\n",
1722                                 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
1723                 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1724                                 "\tWQID[%02d], "
1725                                 "QE-COUNT[%04d], WQE-SIZE[%04d], "
1726                                 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1727                                 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
1728                                 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
1729                                 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
1730                                 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
1731                                 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
1732         }
1733         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1734
1735         /* Get receive queue information */
1736         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1737                         "Slow-path RQ information:\n");
1738         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1739                         "Associated CQID[%02d]:\n",
1740                         phba->sli4_hba.hdr_rq->assoc_qid);
1741         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1742                         "\tHQID[%02d], "
1743                         "QE-COUNT[%04d], QE-SIZE[%04d], "
1744                         "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1745                         phba->sli4_hba.hdr_rq->queue_id,
1746                         phba->sli4_hba.hdr_rq->entry_count,
1747                         phba->sli4_hba.hdr_rq->entry_size,
1748                         phba->sli4_hba.hdr_rq->host_index,
1749                         phba->sli4_hba.hdr_rq->hba_index);
1750         len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1751                         "\tDQID[%02d], "
1752                         "QE-COUNT[%04d], QE-SIZE[%04d], "
1753                         "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1754                         phba->sli4_hba.dat_rq->queue_id,
1755                         phba->sli4_hba.dat_rq->entry_count,
1756                         phba->sli4_hba.dat_rq->entry_size,
1757                         phba->sli4_hba.dat_rq->host_index,
1758                         phba->sli4_hba.dat_rq->hba_index);
1759
1760         return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1761 }
1762
1763 /**
1764  * lpfc_idiag_que_param_check - queue access command parameter sanity check
1765  * @q: The pointer to queue structure.
1766  * @index: The index into a queue entry.
1767  * @count: The number of queue entries to access.
1768  *
1769  * Description:
1770  * The routine performs sanity check on device queue access method commands.
1771  *
1772  * Returns:
1773  * This function returns -EINVAL when fails the sanity check, otherwise, it
1774  * returns 0.
1775  **/
1776 static int
1777 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
1778 {
1779         /* Only support single entry read or browsing */
1780         if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
1781                 return -EINVAL;
1782         if (index > q->entry_count - 1)
1783                 return -EINVAL;
1784         return 0;
1785 }
1786
1787 /**
1788  * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
1789  * @pbuffer: The pointer to buffer to copy the read data into.
1790  * @pque: The pointer to the queue to be read.
1791  * @index: The index into the queue entry.
1792  *
1793  * Description:
1794  * This routine reads out a single entry from the given queue's index location
1795  * and copies it into the buffer provided.
1796  *
1797  * Returns:
1798  * This function returns 0 when it fails, otherwise, it returns the length of
1799  * the data read into the buffer provided.
1800  **/
1801 static int
1802 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
1803                           uint32_t index)
1804 {
1805         int offset, esize;
1806         uint32_t *pentry;
1807
1808         if (!pbuffer || !pque)
1809                 return 0;
1810
1811         esize = pque->entry_size;
1812         len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
1813                         "QE-INDEX[%04d]:\n", index);
1814
1815         offset = 0;
1816         pentry = pque->qe[index].address;
1817         while (esize > 0) {
1818                 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
1819                                 "%08x ", *pentry);
1820                 pentry++;
1821                 offset += sizeof(uint32_t);
1822                 esize -= sizeof(uint32_t);
1823                 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
1824                         len += snprintf(pbuffer+len,
1825                                         LPFC_QUE_ACC_BUF_SIZE-len, "\n");
1826         }
1827         len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
1828
1829         return len;
1830 }
1831
1832 /**
1833  * lpfc_idiag_queacc_read - idiag debugfs read port queue
1834  * @file: The file pointer to read from.
1835  * @buf: The buffer to copy the data to.
1836  * @nbytes: The number of bytes to read.
1837  * @ppos: The position in the file to start reading from.
1838  *
1839  * Description:
1840  * This routine reads data from the @phba device queue memory according to the
1841  * idiag command, and copies to user @buf. Depending on the queue dump read
1842  * command setup, it does either a single queue entry read or browing through
1843  * all entries of the queue.
1844  *
1845  * Returns:
1846  * This function returns the amount of data that was read (this could be less
1847  * than @nbytes if the end of the file was reached) or a negative error value.
1848  **/
1849 static ssize_t
1850 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
1851                        loff_t *ppos)
1852 {
1853         struct lpfc_debug *debug = file->private_data;
1854         uint32_t last_index, index, count;
1855         struct lpfc_queue *pque = NULL;
1856         char *pbuffer;
1857         int len = 0;
1858
1859         /* This is a user read operation */
1860         debug->op = LPFC_IDIAG_OP_RD;
1861
1862         if (!debug->buffer)
1863                 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
1864         if (!debug->buffer)
1865                 return 0;
1866         pbuffer = debug->buffer;
1867
1868         if (*ppos)
1869                 return 0;
1870
1871         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
1872                 index = idiag.cmd.data[2];
1873                 count = idiag.cmd.data[3];
1874                 pque = (struct lpfc_queue *)idiag.ptr_private;
1875         } else
1876                 return 0;
1877
1878         /* Browse the queue starting from index */
1879         if (count == LPFC_QUE_ACC_BROWSE)
1880                 goto que_browse;
1881
1882         /* Read a single entry from the queue */
1883         len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
1884
1885         return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1886
1887 que_browse:
1888
1889         /* Browse all entries from the queue */
1890         last_index = idiag.offset.last_rd;
1891         index = last_index;
1892
1893         while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
1894                 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
1895                 index++;
1896                 if (index > pque->entry_count - 1)
1897                         break;
1898         }
1899
1900         /* Set up the offset for next portion of pci cfg read */
1901         if (index > pque->entry_count - 1)
1902                 index = 0;
1903         idiag.offset.last_rd = index;
1904
1905         return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1906 }
1907
1908 /**
1909  * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
1910  * @file: The file pointer to read from.
1911  * @buf: The buffer to copy the user data from.
1912  * @nbytes: The number of bytes to get.
1913  * @ppos: The position in the file to start reading from.
1914  *
1915  * This routine get the debugfs idiag command struct from user space and then
1916  * perform the syntax check for port queue read (dump) or write (set) command
1917  * accordingly. In the case of port queue read command, it sets up the command
1918  * in the idiag command struct for the following debugfs read operation. In
1919  * the case of port queue write operation, it executes the write operation
1920  * into the port queue entry accordingly.
1921  *
1922  * It returns the @nbytges passing in from debugfs user space when successful.
1923  * In case of error conditions, it returns proper error code back to the user
1924  * space.
1925  **/
1926 static ssize_t
1927 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
1928                         size_t nbytes, loff_t *ppos)
1929 {
1930         struct lpfc_debug *debug = file->private_data;
1931         struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1932         uint32_t qidx, quetp, queid, index, count, offset, value;
1933         uint32_t *pentry;
1934         struct lpfc_queue *pque;
1935         int rc;
1936
1937         /* This is a user write operation */
1938         debug->op = LPFC_IDIAG_OP_WR;
1939
1940         rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1941         if (rc < 0)
1942                 return rc;
1943
1944         /* Get and sanity check on command feilds */
1945         quetp  = idiag.cmd.data[0];
1946         queid  = idiag.cmd.data[1];
1947         index  = idiag.cmd.data[2];
1948         count  = idiag.cmd.data[3];
1949         offset = idiag.cmd.data[4];
1950         value  = idiag.cmd.data[5];
1951
1952         /* Sanity check on command line arguments */
1953         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
1954             idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
1955             idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
1956                 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
1957                         goto error_out;
1958                 if (count != 1)
1959                         goto error_out;
1960         } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
1961                 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
1962                         goto error_out;
1963         } else
1964                 goto error_out;
1965
1966         switch (quetp) {
1967         case LPFC_IDIAG_EQ:
1968                 /* Slow-path event queue */
1969                 if (phba->sli4_hba.sp_eq->queue_id == queid) {
1970                         /* Sanity check */
1971                         rc = lpfc_idiag_que_param_check(
1972                                         phba->sli4_hba.sp_eq, index, count);
1973                         if (rc)
1974                                 goto error_out;
1975                         idiag.ptr_private = phba->sli4_hba.sp_eq;
1976                         goto pass_check;
1977                 }
1978                 /* Fast-path event queue */
1979                 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
1980                         if (phba->sli4_hba.fp_eq[qidx]->queue_id == queid) {
1981                                 /* Sanity check */
1982                                 rc = lpfc_idiag_que_param_check(
1983                                                 phba->sli4_hba.fp_eq[qidx],
1984                                                 index, count);
1985                                 if (rc)
1986                                         goto error_out;
1987                                 idiag.ptr_private = phba->sli4_hba.fp_eq[qidx];
1988                                 goto pass_check;
1989                         }
1990                 }
1991                 goto error_out;
1992                 break;
1993         case LPFC_IDIAG_CQ:
1994                 /* MBX complete queue */
1995                 if (phba->sli4_hba.mbx_cq->queue_id == queid) {
1996                         /* Sanity check */
1997                         rc = lpfc_idiag_que_param_check(
1998                                         phba->sli4_hba.mbx_cq, index, count);
1999                         if (rc)
2000                                 goto error_out;
2001                         idiag.ptr_private = phba->sli4_hba.mbx_cq;
2002                         goto pass_check;
2003                 }
2004                 /* ELS complete queue */
2005                 if (phba->sli4_hba.els_cq->queue_id == queid) {
2006                         /* Sanity check */
2007                         rc = lpfc_idiag_que_param_check(
2008                                         phba->sli4_hba.els_cq, index, count);
2009                         if (rc)
2010                                 goto error_out;
2011                         idiag.ptr_private = phba->sli4_hba.els_cq;
2012                         goto pass_check;
2013                 }
2014                 /* FCP complete queue */
2015                 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
2016                         if (phba->sli4_hba.fcp_cq[qidx]->queue_id == queid) {
2017                                 /* Sanity check */
2018                                 rc = lpfc_idiag_que_param_check(
2019                                                 phba->sli4_hba.fcp_cq[qidx],
2020                                                 index, count);
2021                                 if (rc)
2022                                         goto error_out;
2023                                 idiag.ptr_private =
2024                                                 phba->sli4_hba.fcp_cq[qidx];
2025                                 goto pass_check;
2026                         }
2027                 }
2028                 goto error_out;
2029                 break;
2030         case LPFC_IDIAG_MQ:
2031                 /* MBX work queue */
2032                 if (phba->sli4_hba.mbx_wq->queue_id == queid) {
2033                         /* Sanity check */
2034                         rc = lpfc_idiag_que_param_check(
2035                                         phba->sli4_hba.mbx_wq, index, count);
2036                         if (rc)
2037                                 goto error_out;
2038                         idiag.ptr_private = phba->sli4_hba.mbx_wq;
2039                         goto pass_check;
2040                 }
2041                 break;
2042         case LPFC_IDIAG_WQ:
2043                 /* ELS work queue */
2044                 if (phba->sli4_hba.els_wq->queue_id == queid) {
2045                         /* Sanity check */
2046                         rc = lpfc_idiag_que_param_check(
2047                                         phba->sli4_hba.els_wq, index, count);
2048                         if (rc)
2049                                 goto error_out;
2050                         idiag.ptr_private = phba->sli4_hba.els_wq;
2051                         goto pass_check;
2052                 }
2053                 /* FCP work queue */
2054                 for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
2055                         if (phba->sli4_hba.fcp_wq[qidx]->queue_id == queid) {
2056                                 /* Sanity check */
2057                                 rc = lpfc_idiag_que_param_check(
2058                                                 phba->sli4_hba.fcp_wq[qidx],
2059                                                 index, count);
2060                                 if (rc)
2061                                         goto error_out;
2062                                 idiag.ptr_private =
2063                                         phba->sli4_hba.fcp_wq[qidx];
2064                                 goto pass_check;
2065                         }
2066                 }
2067                 goto error_out;
2068                 break;
2069         case LPFC_IDIAG_RQ:
2070                 /* HDR queue */
2071                 if (phba->sli4_hba.hdr_rq->queue_id == queid) {
2072                         /* Sanity check */
2073                         rc = lpfc_idiag_que_param_check(
2074                                         phba->sli4_hba.hdr_rq, index, count);
2075                         if (rc)
2076                                 goto error_out;
2077                         idiag.ptr_private = phba->sli4_hba.hdr_rq;
2078                         goto pass_check;
2079                 }
2080                 /* DAT queue */
2081                 if (phba->sli4_hba.dat_rq->queue_id == queid) {
2082                         /* Sanity check */
2083                         rc = lpfc_idiag_que_param_check(
2084                                         phba->sli4_hba.dat_rq, index, count);
2085                         if (rc)
2086                                 goto error_out;
2087                         idiag.ptr_private = phba->sli4_hba.dat_rq;
2088                         goto pass_check;
2089                 }
2090                 goto error_out;
2091                 break;
2092         default:
2093                 goto error_out;
2094                 break;
2095         }
2096
2097 pass_check:
2098
2099         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2100                 if (count == LPFC_QUE_ACC_BROWSE)
2101                         idiag.offset.last_rd = index;
2102         }
2103
2104         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2105             idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2106             idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2107                 /* Additional sanity checks on write operation */
2108                 pque = (struct lpfc_queue *)idiag.ptr_private;
2109                 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2110                         goto error_out;
2111                 pentry = pque->qe[index].address;
2112                 pentry += offset;
2113                 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2114                         *pentry = value;
2115                 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2116                         *pentry |= value;
2117                 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2118                         *pentry &= ~value;
2119         }
2120         return nbytes;
2121
2122 error_out:
2123         /* Clean out command structure on command error out */
2124         memset(&idiag, 0, sizeof(idiag));
2125         return -EINVAL;
2126 }
2127
2128 /**
2129  * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2130  * @phba: The pointer to hba structure.
2131  * @pbuffer: The pointer to the buffer to copy the data to.
2132  * @len: The lenght of bytes to copied.
2133  * @drbregid: The id to doorbell registers.
2134  *
2135  * Description:
2136  * This routine reads a doorbell register and copies its content to the
2137  * user buffer pointed to by @pbuffer.
2138  *
2139  * Returns:
2140  * This function returns the amount of data that was copied into @pbuffer.
2141  **/
2142 static int
2143 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2144                            int len, uint32_t drbregid)
2145 {
2146
2147         if (!pbuffer)
2148                 return 0;
2149
2150         switch (drbregid) {
2151         case LPFC_DRB_EQCQ:
2152                 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2153                                 "EQCQ-DRB-REG: 0x%08x\n",
2154                                 readl(phba->sli4_hba.EQCQDBregaddr));
2155                 break;
2156         case LPFC_DRB_MQ:
2157                 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2158                                 "MQ-DRB-REG:   0x%08x\n",
2159                                 readl(phba->sli4_hba.MQDBregaddr));
2160                 break;
2161         case LPFC_DRB_WQ:
2162                 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2163                                 "WQ-DRB-REG:   0x%08x\n",
2164                                 readl(phba->sli4_hba.WQDBregaddr));
2165                 break;
2166         case LPFC_DRB_RQ:
2167                 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2168                                 "RQ-DRB-REG:   0x%08x\n",
2169                                 readl(phba->sli4_hba.RQDBregaddr));
2170                 break;
2171         default:
2172                 break;
2173         }
2174
2175         return len;
2176 }
2177
2178 /**
2179  * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2180  * @file: The file pointer to read from.
2181  * @buf: The buffer to copy the data to.
2182  * @nbytes: The number of bytes to read.
2183  * @ppos: The position in the file to start reading from.
2184  *
2185  * Description:
2186  * This routine reads data from the @phba device doorbell register according
2187  * to the idiag command, and copies to user @buf. Depending on the doorbell
2188  * register read command setup, it does either a single doorbell register
2189  * read or dump all doorbell registers.
2190  *
2191  * Returns:
2192  * This function returns the amount of data that was read (this could be less
2193  * than @nbytes if the end of the file was reached) or a negative error value.
2194  **/
2195 static ssize_t
2196 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2197                        loff_t *ppos)
2198 {
2199         struct lpfc_debug *debug = file->private_data;
2200         struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2201         uint32_t drb_reg_id, i;
2202         char *pbuffer;
2203         int len = 0;
2204
2205         /* This is a user read operation */
2206         debug->op = LPFC_IDIAG_OP_RD;
2207
2208         if (!debug->buffer)
2209                 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2210         if (!debug->buffer)
2211                 return 0;
2212         pbuffer = debug->buffer;
2213
2214         if (*ppos)
2215                 return 0;
2216
2217         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
2218                 drb_reg_id = idiag.cmd.data[0];
2219         else
2220                 return 0;
2221
2222         if (drb_reg_id == LPFC_DRB_ACC_ALL)
2223                 for (i = 1; i <= LPFC_DRB_MAX; i++)
2224                         len = lpfc_idiag_drbacc_read_reg(phba,
2225                                                          pbuffer, len, i);
2226         else
2227                 len = lpfc_idiag_drbacc_read_reg(phba,
2228                                                  pbuffer, len, drb_reg_id);
2229
2230         return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2231 }
2232
2233 /**
2234  * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2235  * @file: The file pointer to read from.
2236  * @buf: The buffer to copy the user data from.
2237  * @nbytes: The number of bytes to get.
2238  * @ppos: The position in the file to start reading from.
2239  *
2240  * This routine get the debugfs idiag command struct from user space and then
2241  * perform the syntax check for port doorbell register read (dump) or write
2242  * (set) command accordingly. In the case of port queue read command, it sets
2243  * up the command in the idiag command struct for the following debugfs read
2244  * operation. In the case of port doorbell register write operation, it
2245  * executes the write operation into the port doorbell register accordingly.
2246  *
2247  * It returns the @nbytges passing in from debugfs user space when successful.
2248  * In case of error conditions, it returns proper error code back to the user
2249  * space.
2250  **/
2251 static ssize_t
2252 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2253                         size_t nbytes, loff_t *ppos)
2254 {
2255         struct lpfc_debug *debug = file->private_data;
2256         struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2257         uint32_t drb_reg_id, value, reg_val;
2258         void __iomem *drb_reg;
2259         int rc;
2260
2261         /* This is a user write operation */
2262         debug->op = LPFC_IDIAG_OP_WR;
2263
2264         rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2265         if (rc < 0)
2266                 return rc;
2267
2268         /* Sanity check on command line arguments */
2269         drb_reg_id = idiag.cmd.data[0];
2270         value = idiag.cmd.data[1];
2271
2272         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2273             idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2274             idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2275                 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2276                         goto error_out;
2277                 if (drb_reg_id > LPFC_DRB_MAX)
2278                         goto error_out;
2279         } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2280                 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2281                         goto error_out;
2282                 if ((drb_reg_id > LPFC_DRB_MAX) &&
2283                     (drb_reg_id != LPFC_DRB_ACC_ALL))
2284                         goto error_out;
2285         } else
2286                 goto error_out;
2287
2288         /* Perform the write access operation */
2289         if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2290             idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2291             idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2292                 switch (drb_reg_id) {
2293                 case LPFC_DRB_EQCQ:
2294                         drb_reg = phba->sli4_hba.EQCQDBregaddr;
2295                         break;
2296                 case LPFC_DRB_MQ:
2297                         drb_reg = phba->sli4_hba.MQDBregaddr;
2298                         break;
2299                 case LPFC_DRB_WQ:
2300                         drb_reg = phba->sli4_hba.WQDBregaddr;
2301                         break;
2302                 case LPFC_DRB_RQ:
2303                         drb_reg = phba->sli4_hba.RQDBregaddr;
2304                         break;
2305                 default:
2306                         goto error_out;
2307                 }
2308
2309                 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2310                         reg_val = value;
2311                 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2312                         reg_val = readl(drb_reg);
2313                         reg_val |= value;
2314                 }
2315                 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2316                         reg_val = readl(drb_reg);
2317                         reg_val &= ~value;
2318                 }
2319                 writel(reg_val, drb_reg);
2320                 readl(drb_reg); /* flush */
2321         }
2322         return nbytes;
2323
2324 error_out:
2325         /* Clean out command structure on command error out */
2326         memset(&idiag, 0, sizeof(idiag));
2327         return -EINVAL;
2328 }
2329
2330 #undef lpfc_debugfs_op_disc_trc
2331 static const struct file_operations lpfc_debugfs_op_disc_trc = {
2332         .owner =        THIS_MODULE,
2333         .open =         lpfc_debugfs_disc_trc_open,
2334         .llseek =       lpfc_debugfs_lseek,
2335         .read =         lpfc_debugfs_read,
2336         .release =      lpfc_debugfs_release,
2337 };
2338
2339 #undef lpfc_debugfs_op_nodelist
2340 static const struct file_operations lpfc_debugfs_op_nodelist = {
2341         .owner =        THIS_MODULE,
2342         .open =         lpfc_debugfs_nodelist_open,
2343         .llseek =       lpfc_debugfs_lseek,
2344         .read =         lpfc_debugfs_read,
2345         .release =      lpfc_debugfs_release,
2346 };
2347
2348 #undef lpfc_debugfs_op_hbqinfo
2349 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
2350         .owner =        THIS_MODULE,
2351         .open =         lpfc_debugfs_hbqinfo_open,
2352         .llseek =       lpfc_debugfs_lseek,
2353         .read =         lpfc_debugfs_read,
2354         .release =      lpfc_debugfs_release,
2355 };
2356
2357 #undef lpfc_debugfs_op_dumpHBASlim
2358 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
2359         .owner =        THIS_MODULE,
2360         .open =         lpfc_debugfs_dumpHBASlim_open,
2361         .llseek =       lpfc_debugfs_lseek,
2362         .read =         lpfc_debugfs_read,
2363         .release =      lpfc_debugfs_release,
2364 };
2365
2366 #undef lpfc_debugfs_op_dumpHostSlim
2367 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
2368         .owner =        THIS_MODULE,
2369         .open =         lpfc_debugfs_dumpHostSlim_open,
2370         .llseek =       lpfc_debugfs_lseek,
2371         .read =         lpfc_debugfs_read,
2372         .release =      lpfc_debugfs_release,
2373 };
2374
2375 #undef lpfc_debugfs_op_dumpData
2376 static const struct file_operations lpfc_debugfs_op_dumpData = {
2377         .owner =        THIS_MODULE,
2378         .open =         lpfc_debugfs_dumpData_open,
2379         .llseek =       lpfc_debugfs_lseek,
2380         .read =         lpfc_debugfs_read,
2381         .write =        lpfc_debugfs_dumpDataDif_write,
2382         .release =      lpfc_debugfs_dumpDataDif_release,
2383 };
2384
2385 #undef lpfc_debugfs_op_dumpDif
2386 static const struct file_operations lpfc_debugfs_op_dumpDif = {
2387         .owner =        THIS_MODULE,
2388         .open =         lpfc_debugfs_dumpDif_open,
2389         .llseek =       lpfc_debugfs_lseek,
2390         .read =         lpfc_debugfs_read,
2391         .write =        lpfc_debugfs_dumpDataDif_write,
2392         .release =      lpfc_debugfs_dumpDataDif_release,
2393 };
2394
2395 #undef lpfc_debugfs_op_slow_ring_trc
2396 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
2397         .owner =        THIS_MODULE,
2398         .open =         lpfc_debugfs_slow_ring_trc_open,
2399         .llseek =       lpfc_debugfs_lseek,
2400         .read =         lpfc_debugfs_read,
2401         .release =      lpfc_debugfs_release,
2402 };
2403
2404 static struct dentry *lpfc_debugfs_root = NULL;
2405 static atomic_t lpfc_debugfs_hba_count;
2406
2407 /*
2408  * File operations for the iDiag debugfs
2409  */
2410 #undef lpfc_idiag_op_pciCfg
2411 static const struct file_operations lpfc_idiag_op_pciCfg = {
2412         .owner =        THIS_MODULE,
2413         .open =         lpfc_idiag_open,
2414         .llseek =       lpfc_debugfs_lseek,
2415         .read =         lpfc_idiag_pcicfg_read,
2416         .write =        lpfc_idiag_pcicfg_write,
2417         .release =      lpfc_idiag_cmd_release,
2418 };
2419
2420 #undef lpfc_idiag_op_queInfo
2421 static const struct file_operations lpfc_idiag_op_queInfo = {
2422         .owner =        THIS_MODULE,
2423         .open =         lpfc_idiag_open,
2424         .read =         lpfc_idiag_queinfo_read,
2425         .release =      lpfc_idiag_release,
2426 };
2427
2428 #undef lpfc_idiag_op_queacc
2429 static const struct file_operations lpfc_idiag_op_queAcc = {
2430         .owner =        THIS_MODULE,
2431         .open =         lpfc_idiag_open,
2432         .llseek =       lpfc_debugfs_lseek,
2433         .read =         lpfc_idiag_queacc_read,
2434         .write =        lpfc_idiag_queacc_write,
2435         .release =      lpfc_idiag_cmd_release,
2436 };
2437
2438 #undef lpfc_idiag_op_drbacc
2439 static const struct file_operations lpfc_idiag_op_drbAcc = {
2440         .owner =        THIS_MODULE,
2441         .open =         lpfc_idiag_open,
2442         .llseek =       lpfc_debugfs_lseek,
2443         .read =         lpfc_idiag_drbacc_read,
2444         .write =        lpfc_idiag_drbacc_write,
2445         .release =      lpfc_idiag_cmd_release,
2446 };
2447
2448 #endif
2449
2450 /**
2451  * lpfc_debugfs_initialize - Initialize debugfs for a vport
2452  * @vport: The vport pointer to initialize.
2453  *
2454  * Description:
2455  * When Debugfs is configured this routine sets up the lpfc debugfs file system.
2456  * If not already created, this routine will create the lpfc directory, and
2457  * lpfcX directory (for this HBA), and vportX directory for this vport. It will
2458  * also create each file used to access lpfc specific debugfs information.
2459  **/
2460 inline void
2461 lpfc_debugfs_initialize(struct lpfc_vport *vport)
2462 {
2463 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2464         struct lpfc_hba   *phba = vport->phba;
2465         char name[64];
2466         uint32_t num, i;
2467
2468         if (!lpfc_debugfs_enable)
2469                 return;
2470
2471         /* Setup lpfc root directory */
2472         if (!lpfc_debugfs_root) {
2473                 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
2474                 atomic_set(&lpfc_debugfs_hba_count, 0);
2475                 if (!lpfc_debugfs_root) {
2476                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2477                                          "0408 Cannot create debugfs root\n");
2478                         goto debug_failed;
2479                 }
2480         }
2481         if (!lpfc_debugfs_start_time)
2482                 lpfc_debugfs_start_time = jiffies;
2483
2484         /* Setup funcX directory for specific HBA PCI function */
2485         snprintf(name, sizeof(name), "fn%d", phba->brd_no);
2486         if (!phba->hba_debugfs_root) {
2487                 phba->hba_debugfs_root =
2488                         debugfs_create_dir(name, lpfc_debugfs_root);
2489                 if (!phba->hba_debugfs_root) {
2490                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2491                                          "0412 Cannot create debugfs hba\n");
2492                         goto debug_failed;
2493                 }
2494                 atomic_inc(&lpfc_debugfs_hba_count);
2495                 atomic_set(&phba->debugfs_vport_count, 0);
2496
2497                 /* Setup hbqinfo */
2498                 snprintf(name, sizeof(name), "hbqinfo");
2499                 phba->debug_hbqinfo =
2500                         debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2501                                  phba->hba_debugfs_root,
2502                                  phba, &lpfc_debugfs_op_hbqinfo);
2503                 if (!phba->debug_hbqinfo) {
2504                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2505                                 "0411 Cannot create debugfs hbqinfo\n");
2506                         goto debug_failed;
2507                 }
2508
2509                 /* Setup dumpHBASlim */
2510                 if (phba->sli_rev < LPFC_SLI_REV4) {
2511                         snprintf(name, sizeof(name), "dumpHBASlim");
2512                         phba->debug_dumpHBASlim =
2513                                 debugfs_create_file(name,
2514                                         S_IFREG|S_IRUGO|S_IWUSR,
2515                                         phba->hba_debugfs_root,
2516                                         phba, &lpfc_debugfs_op_dumpHBASlim);
2517                         if (!phba->debug_dumpHBASlim) {
2518                                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2519                                                  "0413 Cannot create debugfs "
2520                                                 "dumpHBASlim\n");
2521                                 goto debug_failed;
2522                         }
2523                 } else
2524                         phba->debug_dumpHBASlim = NULL;
2525
2526                 /* Setup dumpHostSlim */
2527                 if (phba->sli_rev < LPFC_SLI_REV4) {
2528                         snprintf(name, sizeof(name), "dumpHostSlim");
2529                         phba->debug_dumpHostSlim =
2530                                 debugfs_create_file(name,
2531                                         S_IFREG|S_IRUGO|S_IWUSR,
2532                                         phba->hba_debugfs_root,
2533                                         phba, &lpfc_debugfs_op_dumpHostSlim);
2534                         if (!phba->debug_dumpHostSlim) {
2535                                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2536                                                  "0414 Cannot create debugfs "
2537                                                  "dumpHostSlim\n");
2538                                 goto debug_failed;
2539                         }
2540                 } else
2541                         phba->debug_dumpHBASlim = NULL;
2542
2543                 /* Setup dumpData */
2544                 snprintf(name, sizeof(name), "dumpData");
2545                 phba->debug_dumpData =
2546                         debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2547                                  phba->hba_debugfs_root,
2548                                  phba, &lpfc_debugfs_op_dumpData);
2549                 if (!phba->debug_dumpData) {
2550                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2551                                 "0800 Cannot create debugfs dumpData\n");
2552                         goto debug_failed;
2553                 }
2554
2555                 /* Setup dumpDif */
2556                 snprintf(name, sizeof(name), "dumpDif");
2557                 phba->debug_dumpDif =
2558                         debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2559                                  phba->hba_debugfs_root,
2560                                  phba, &lpfc_debugfs_op_dumpDif);
2561                 if (!phba->debug_dumpDif) {
2562                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2563                                 "0801 Cannot create debugfs dumpDif\n");
2564                         goto debug_failed;
2565                 }
2566
2567                 /* Setup slow ring trace */
2568                 if (lpfc_debugfs_max_slow_ring_trc) {
2569                         num = lpfc_debugfs_max_slow_ring_trc - 1;
2570                         if (num & lpfc_debugfs_max_slow_ring_trc) {
2571                                 /* Change to be a power of 2 */
2572                                 num = lpfc_debugfs_max_slow_ring_trc;
2573                                 i = 0;
2574                                 while (num > 1) {
2575                                         num = num >> 1;
2576                                         i++;
2577                                 }
2578                                 lpfc_debugfs_max_slow_ring_trc = (1 << i);
2579                                 printk(KERN_ERR
2580                                        "lpfc_debugfs_max_disc_trc changed to "
2581                                        "%d\n", lpfc_debugfs_max_disc_trc);
2582                         }
2583                 }
2584
2585                 snprintf(name, sizeof(name), "slow_ring_trace");
2586                 phba->debug_slow_ring_trc =
2587                         debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2588                                  phba->hba_debugfs_root,
2589                                  phba, &lpfc_debugfs_op_slow_ring_trc);
2590                 if (!phba->debug_slow_ring_trc) {
2591                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2592                                          "0415 Cannot create debugfs "
2593                                          "slow_ring_trace\n");
2594                         goto debug_failed;
2595                 }
2596                 if (!phba->slow_ring_trc) {
2597                         phba->slow_ring_trc = kmalloc(
2598                                 (sizeof(struct lpfc_debugfs_trc) *
2599                                 lpfc_debugfs_max_slow_ring_trc),
2600                                 GFP_KERNEL);
2601                         if (!phba->slow_ring_trc) {
2602                                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2603                                                  "0416 Cannot create debugfs "
2604                                                  "slow_ring buffer\n");
2605                                 goto debug_failed;
2606                         }
2607                         atomic_set(&phba->slow_ring_trc_cnt, 0);
2608                         memset(phba->slow_ring_trc, 0,
2609                                 (sizeof(struct lpfc_debugfs_trc) *
2610                                 lpfc_debugfs_max_slow_ring_trc));
2611                 }
2612         }
2613
2614         snprintf(name, sizeof(name), "vport%d", vport->vpi);
2615         if (!vport->vport_debugfs_root) {
2616                 vport->vport_debugfs_root =
2617                         debugfs_create_dir(name, phba->hba_debugfs_root);
2618                 if (!vport->vport_debugfs_root) {
2619                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2620                                          "0417 Can't create debugfs\n");
2621                         goto debug_failed;
2622                 }
2623                 atomic_inc(&phba->debugfs_vport_count);
2624         }
2625
2626         if (lpfc_debugfs_max_disc_trc) {
2627                 num = lpfc_debugfs_max_disc_trc - 1;
2628                 if (num & lpfc_debugfs_max_disc_trc) {
2629                         /* Change to be a power of 2 */
2630                         num = lpfc_debugfs_max_disc_trc;
2631                         i = 0;
2632                         while (num > 1) {
2633                                 num = num >> 1;
2634                                 i++;
2635                         }
2636                         lpfc_debugfs_max_disc_trc = (1 << i);
2637                         printk(KERN_ERR
2638                                "lpfc_debugfs_max_disc_trc changed to %d\n",
2639                                lpfc_debugfs_max_disc_trc);
2640                 }
2641         }
2642
2643         vport->disc_trc = kzalloc(
2644                 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
2645                 GFP_KERNEL);
2646
2647         if (!vport->disc_trc) {
2648                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2649                                  "0418 Cannot create debugfs disc trace "
2650                                  "buffer\n");
2651                 goto debug_failed;
2652         }
2653         atomic_set(&vport->disc_trc_cnt, 0);
2654
2655         snprintf(name, sizeof(name), "discovery_trace");
2656         vport->debug_disc_trc =
2657                 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2658                                  vport->vport_debugfs_root,
2659                                  vport, &lpfc_debugfs_op_disc_trc);
2660         if (!vport->debug_disc_trc) {
2661                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2662                                  "0419 Cannot create debugfs "
2663                                  "discovery_trace\n");
2664                 goto debug_failed;
2665         }
2666         snprintf(name, sizeof(name), "nodelist");
2667         vport->debug_nodelist =
2668                 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2669                                  vport->vport_debugfs_root,
2670                                  vport, &lpfc_debugfs_op_nodelist);
2671         if (!vport->debug_nodelist) {
2672                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2673                                  "0409 Can't create debugfs nodelist\n");
2674                 goto debug_failed;
2675         }
2676
2677         /*
2678          * iDiag debugfs root entry points for SLI4 device only
2679          */
2680         if (phba->sli_rev < LPFC_SLI_REV4)
2681                 goto debug_failed;
2682
2683         snprintf(name, sizeof(name), "iDiag");
2684         if (!phba->idiag_root) {
2685                 phba->idiag_root =
2686                         debugfs_create_dir(name, phba->hba_debugfs_root);
2687                 if (!phba->idiag_root) {
2688                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2689                                          "2922 Can't create idiag debugfs\n");
2690                         goto debug_failed;
2691                 }
2692                 /* Initialize iDiag data structure */
2693                 memset(&idiag, 0, sizeof(idiag));
2694         }
2695
2696         /* iDiag read PCI config space */
2697         snprintf(name, sizeof(name), "pciCfg");
2698         if (!phba->idiag_pci_cfg) {
2699                 phba->idiag_pci_cfg =
2700                         debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2701                                 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
2702                 if (!phba->idiag_pci_cfg) {
2703                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2704                                          "2923 Can't create idiag debugfs\n");
2705                         goto debug_failed;
2706                 }
2707                 idiag.offset.last_rd = 0;
2708         }
2709
2710         /* iDiag get PCI function queue information */
2711         snprintf(name, sizeof(name), "queInfo");
2712         if (!phba->idiag_que_info) {
2713                 phba->idiag_que_info =
2714                         debugfs_create_file(name, S_IFREG|S_IRUGO,
2715                         phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
2716                 if (!phba->idiag_que_info) {
2717                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2718                                          "2924 Can't create idiag debugfs\n");
2719                         goto debug_failed;
2720                 }
2721         }
2722
2723         /* iDiag access PCI function queue */
2724         snprintf(name, sizeof(name), "queAcc");
2725         if (!phba->idiag_que_acc) {
2726                 phba->idiag_que_acc =
2727                         debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2728                                 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
2729                 if (!phba->idiag_que_acc) {
2730                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2731                                          "2926 Can't create idiag debugfs\n");
2732                         goto debug_failed;
2733                 }
2734         }
2735
2736         /* iDiag access PCI function doorbell registers */
2737         snprintf(name, sizeof(name), "drbAcc");
2738         if (!phba->idiag_drb_acc) {
2739                 phba->idiag_drb_acc =
2740                         debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2741                                 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
2742                 if (!phba->idiag_drb_acc) {
2743                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2744                                          "2927 Can't create idiag debugfs\n");
2745                         goto debug_failed;
2746                 }
2747         }
2748
2749 debug_failed:
2750         return;
2751 #endif
2752 }
2753
2754 /**
2755  * lpfc_debugfs_terminate -  Tear down debugfs infrastructure for this vport
2756  * @vport: The vport pointer to remove from debugfs.
2757  *
2758  * Description:
2759  * When Debugfs is configured this routine removes debugfs file system elements
2760  * that are specific to this vport. It also checks to see if there are any
2761  * users left for the debugfs directories associated with the HBA and driver. If
2762  * this is the last user of the HBA directory or driver directory then it will
2763  * remove those from the debugfs infrastructure as well.
2764  **/
2765 inline void
2766 lpfc_debugfs_terminate(struct lpfc_vport *vport)
2767 {
2768 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
2769         struct lpfc_hba   *phba = vport->phba;
2770
2771         if (vport->disc_trc) {
2772                 kfree(vport->disc_trc);
2773                 vport->disc_trc = NULL;
2774         }
2775         if (vport->debug_disc_trc) {
2776                 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
2777                 vport->debug_disc_trc = NULL;
2778         }
2779         if (vport->debug_nodelist) {
2780                 debugfs_remove(vport->debug_nodelist); /* nodelist */
2781                 vport->debug_nodelist = NULL;
2782         }
2783
2784         if (vport->vport_debugfs_root) {
2785                 debugfs_remove(vport->vport_debugfs_root); /* vportX */
2786                 vport->vport_debugfs_root = NULL;
2787                 atomic_dec(&phba->debugfs_vport_count);
2788         }
2789         if (atomic_read(&phba->debugfs_vport_count) == 0) {
2790
2791                 if (phba->debug_hbqinfo) {
2792                         debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
2793                         phba->debug_hbqinfo = NULL;
2794                 }
2795                 if (phba->debug_dumpHBASlim) {
2796                         debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
2797                         phba->debug_dumpHBASlim = NULL;
2798                 }
2799                 if (phba->debug_dumpHostSlim) {
2800                         debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
2801                         phba->debug_dumpHostSlim = NULL;
2802                 }
2803                 if (phba->debug_dumpData) {
2804                         debugfs_remove(phba->debug_dumpData); /* dumpData */
2805                         phba->debug_dumpData = NULL;
2806                 }
2807
2808                 if (phba->debug_dumpDif) {
2809                         debugfs_remove(phba->debug_dumpDif); /* dumpDif */
2810                         phba->debug_dumpDif = NULL;
2811                 }
2812
2813                 if (phba->slow_ring_trc) {
2814                         kfree(phba->slow_ring_trc);
2815                         phba->slow_ring_trc = NULL;
2816                 }
2817                 if (phba->debug_slow_ring_trc) {
2818                         /* slow_ring_trace */
2819                         debugfs_remove(phba->debug_slow_ring_trc);
2820                         phba->debug_slow_ring_trc = NULL;
2821                 }
2822
2823                 /*
2824                  * iDiag release
2825                  */
2826                 if (phba->sli_rev == LPFC_SLI_REV4) {
2827                         if (phba->idiag_drb_acc) {
2828                                 /* iDiag drbAcc */
2829                                 debugfs_remove(phba->idiag_drb_acc);
2830                                 phba->idiag_drb_acc = NULL;
2831                         }
2832                         if (phba->idiag_que_acc) {
2833                                 /* iDiag queAcc */
2834                                 debugfs_remove(phba->idiag_que_acc);
2835                                 phba->idiag_que_acc = NULL;
2836                         }
2837                         if (phba->idiag_que_info) {
2838                                 /* iDiag queInfo */
2839                                 debugfs_remove(phba->idiag_que_info);
2840                                 phba->idiag_que_info = NULL;
2841                         }
2842                         if (phba->idiag_pci_cfg) {
2843                                 /* iDiag pciCfg */
2844                                 debugfs_remove(phba->idiag_pci_cfg);
2845                                 phba->idiag_pci_cfg = NULL;
2846                         }
2847
2848                         /* Finally remove the iDiag debugfs root */
2849                         if (phba->idiag_root) {
2850                                 /* iDiag root */
2851                                 debugfs_remove(phba->idiag_root);
2852                                 phba->idiag_root = NULL;
2853                         }
2854                 }
2855
2856                 if (phba->hba_debugfs_root) {
2857                         debugfs_remove(phba->hba_debugfs_root); /* fnX */
2858                         phba->hba_debugfs_root = NULL;
2859                         atomic_dec(&lpfc_debugfs_hba_count);
2860                 }
2861
2862                 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
2863                         debugfs_remove(lpfc_debugfs_root); /* lpfc */
2864                         lpfc_debugfs_root = NULL;
2865                 }
2866         }
2867 #endif
2868         return;
2869 }
This page took 0.209782 seconds and 4 git commands to generate.