blob: 5dd66925f4cae2d24af0c104963cdc1286fb3331 [file] [log] [blame]
James Smart858c9f62007-06-17 19:56:39 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
James Smarte59058c2008-08-24 21:49:00 -04004 * Copyright (C) 2007-2008 Emulex. All rights reserved. *
James Smart858c9f62007-06-17 19:56:39 -05005 * 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/pci.h>
28#include <linux/spinlock.h>
29#include <linux/ctype.h>
James Smart858c9f62007-06-17 19:56:39 -050030
31#include <scsi/scsi.h>
32#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
34#include <scsi/scsi_transport_fc.h>
35
36#include "lpfc_hw.h"
37#include "lpfc_sli.h"
James Smartea2151b2008-09-07 11:52:10 -040038#include "lpfc_nl.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_disc.h"
40#include "lpfc_scsi.h"
41#include "lpfc.h"
42#include "lpfc_logmsg.h"
43#include "lpfc_crtn.h"
44#include "lpfc_vport.h"
45#include "lpfc_version.h"
James Smartc95d6c62008-01-11 01:53:23 -050046#include "lpfc_compat.h"
James Smart858c9f62007-06-17 19:56:39 -050047#include "lpfc_debugfs.h"
48
James Smart923e4b62008-12-04 22:40:07 -050049#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart3621a712009-04-06 18:47:14 -040050/*
James Smarte59058c2008-08-24 21:49:00 -040051 * debugfs interface
James Smart858c9f62007-06-17 19:56:39 -050052 *
53 * To access this interface the user should:
54 * # mkdir /debug
55 * # mount -t debugfs none /debug
56 *
James Smarte59058c2008-08-24 21:49:00 -040057 * The lpfc debugfs directory hierarchy is:
James Smart858c9f62007-06-17 19:56:39 -050058 * lpfc/lpfcX/vportY
59 * where X is the lpfc hba unique_id
60 * where Y is the vport VPI on that hba
61 *
62 * Debugging services available per vport:
63 * discovery_trace
64 * This is an ACSII readable file that contains a trace of the last
65 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
James Smarte59058c2008-08-24 21:49:00 -040066 * See lpfc_debugfs.h for different categories of discovery events.
67 * To enable the discovery trace, the following module parameters must be set:
James Smart858c9f62007-06-17 19:56:39 -050068 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
69 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
70 * EACH vport. X MUST also be a power of 2.
71 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
72 * lpfc_debugfs.h .
James Smarte59058c2008-08-24 21:49:00 -040073 *
74 * slow_ring_trace
75 * This is an ACSII readable file that contains a trace of the last
76 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
77 * To enable the slow ring trace, the following module parameters must be set:
78 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
79 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
80 * the HBA. X MUST also be a power of 2.
James Smart858c9f62007-06-17 19:56:39 -050081 */
James Smart51ef4c22007-08-02 11:10:31 -040082static int lpfc_debugfs_enable = 1;
James Smart858c9f62007-06-17 19:56:39 -050083module_param(lpfc_debugfs_enable, int, 0);
84MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
85
James Smarta58cbd52007-08-02 11:09:43 -040086/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050087static int lpfc_debugfs_max_disc_trc;
James Smart858c9f62007-06-17 19:56:39 -050088module_param(lpfc_debugfs_max_disc_trc, int, 0);
89MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
90 "Set debugfs discovery trace depth");
91
James Smarta58cbd52007-08-02 11:09:43 -040092/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050093static int lpfc_debugfs_max_slow_ring_trc;
James Smarta58cbd52007-08-02 11:09:43 -040094module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
95MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
96 "Set debugfs slow ring trace depth");
97
James Smarta257bf92009-04-06 18:48:10 -040098static int lpfc_debugfs_mask_disc_trc;
James Smart858c9f62007-06-17 19:56:39 -050099module_param(lpfc_debugfs_mask_disc_trc, int, 0);
100MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
101 "Set debugfs discovery trace mask");
102
103#include <linux/debugfs.h>
104
James Smarta58cbd52007-08-02 11:09:43 -0400105/* size of output line, for discovery_trace and slow_ring_trace */
106#define LPFC_DEBUG_TRC_ENTRY_SIZE 100
James Smart858c9f62007-06-17 19:56:39 -0500107
108/* nodelist output buffer size */
109#define LPFC_NODELIST_SIZE 8192
110#define LPFC_NODELIST_ENTRY_SIZE 120
111
James Smartc95d6c62008-01-11 01:53:23 -0500112/* dumpHBASlim output buffer size */
113#define LPFC_DUMPHBASLIM_SIZE 4096
114
115/* dumpHostSlim output buffer size */
116#define LPFC_DUMPHOSTSLIM_SIZE 4096
James Smarta58cbd52007-08-02 11:09:43 -0400117
James Smart78b2d852007-08-02 11:10:21 -0400118/* hbqinfo output buffer size */
119#define LPFC_HBQINFO_SIZE 8192
120
James Smart858c9f62007-06-17 19:56:39 -0500121struct lpfc_debug {
122 char *buffer;
123 int len;
124};
125
James Smart311464e2007-08-02 11:10:37 -0400126static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
127static unsigned long lpfc_debugfs_start_time = 0L;
James Smart858c9f62007-06-17 19:56:39 -0500128
James Smarte59058c2008-08-24 21:49:00 -0400129/**
James Smart3621a712009-04-06 18:47:14 -0400130 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400131 * @vport: The vport to gather the log info from.
132 * @buf: The buffer to dump log into.
133 * @size: The maximum amount of data to process.
134 *
135 * Description:
136 * This routine gathers the lpfc discovery debugfs data from the @vport and
137 * dumps it to @buf up to @size number of bytes. It will start at the next entry
138 * in the log and process the log until the end of the buffer. Then it will
139 * gather from the beginning of the log and process until the current entry.
140 *
141 * Notes:
142 * Discovery logging will be disabled while while this routine dumps the log.
143 *
144 * Return Value:
145 * This routine returns the amount of bytes that were dumped into @buf and will
146 * not exceed @size.
147 **/
James Smart858c9f62007-06-17 19:56:39 -0500148static int
149lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
150{
151 int i, index, len, enable;
152 uint32_t ms;
James Smarta58cbd52007-08-02 11:09:43 -0400153 struct lpfc_debugfs_trc *dtp;
154 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
James Smart858c9f62007-06-17 19:56:39 -0500155
James Smart858c9f62007-06-17 19:56:39 -0500156 enable = lpfc_debugfs_enable;
157 lpfc_debugfs_enable = 0;
158
159 len = 0;
160 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
161 (lpfc_debugfs_max_disc_trc - 1);
162 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
163 dtp = vport->disc_trc + i;
164 if (!dtp->fmt)
165 continue;
166 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400167 snprintf(buffer,
168 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500169 dtp->seq_cnt, ms, dtp->fmt);
170 len += snprintf(buf+len, size-len, buffer,
171 dtp->data1, dtp->data2, dtp->data3);
172 }
173 for (i = 0; i < index; i++) {
174 dtp = vport->disc_trc + i;
175 if (!dtp->fmt)
176 continue;
177 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400178 snprintf(buffer,
179 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500180 dtp->seq_cnt, ms, dtp->fmt);
181 len += snprintf(buf+len, size-len, buffer,
182 dtp->data1, dtp->data2, dtp->data3);
183 }
184
185 lpfc_debugfs_enable = enable;
186 return len;
187}
188
James Smarte59058c2008-08-24 21:49:00 -0400189/**
James Smart3621a712009-04-06 18:47:14 -0400190 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400191 * @phba: The HBA to gather the log info from.
192 * @buf: The buffer to dump log into.
193 * @size: The maximum amount of data to process.
194 *
195 * Description:
196 * This routine gathers the lpfc slow ring debugfs data from the @phba and
197 * dumps it to @buf up to @size number of bytes. It will start at the next entry
198 * in the log and process the log until the end of the buffer. Then it will
199 * gather from the beginning of the log and process until the current entry.
200 *
201 * Notes:
202 * Slow ring logging will be disabled while while this routine dumps the log.
203 *
204 * Return Value:
205 * This routine returns the amount of bytes that were dumped into @buf and will
206 * not exceed @size.
207 **/
James Smart858c9f62007-06-17 19:56:39 -0500208static int
James Smarta58cbd52007-08-02 11:09:43 -0400209lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
210{
211 int i, index, len, enable;
212 uint32_t ms;
213 struct lpfc_debugfs_trc *dtp;
214 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
215
216
217 enable = lpfc_debugfs_enable;
218 lpfc_debugfs_enable = 0;
219
220 len = 0;
221 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
222 (lpfc_debugfs_max_slow_ring_trc - 1);
223 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
224 dtp = phba->slow_ring_trc + i;
225 if (!dtp->fmt)
226 continue;
227 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
228 snprintf(buffer,
229 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
230 dtp->seq_cnt, ms, dtp->fmt);
231 len += snprintf(buf+len, size-len, buffer,
232 dtp->data1, dtp->data2, dtp->data3);
233 }
234 for (i = 0; i < index; i++) {
235 dtp = phba->slow_ring_trc + i;
236 if (!dtp->fmt)
237 continue;
238 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
239 snprintf(buffer,
240 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
241 dtp->seq_cnt, ms, dtp->fmt);
242 len += snprintf(buf+len, size-len, buffer,
243 dtp->data1, dtp->data2, dtp->data3);
244 }
245
246 lpfc_debugfs_enable = enable;
247 return len;
248}
249
James Smart311464e2007-08-02 11:10:37 -0400250static int lpfc_debugfs_last_hbq = -1;
James Smart78b2d852007-08-02 11:10:21 -0400251
James Smarte59058c2008-08-24 21:49:00 -0400252/**
James Smart3621a712009-04-06 18:47:14 -0400253 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400254 * @phba: The HBA to gather host buffer info from.
255 * @buf: The buffer to dump log into.
256 * @size: The maximum amount of data to process.
257 *
258 * Description:
259 * This routine dumps the host buffer queue info from the @phba to @buf up to
260 * @size number of bytes. A header that describes the current hbq state will be
261 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
262 * until @size bytes have been dumped or all the hbq info has been dumped.
263 *
264 * Notes:
265 * This routine will rotate through each configured HBQ each time called.
266 *
267 * Return Value:
268 * This routine returns the amount of bytes that were dumped into @buf and will
269 * not exceed @size.
270 **/
James Smart78b2d852007-08-02 11:10:21 -0400271static int
272lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
273{
274 int len = 0;
275 int cnt, i, j, found, posted, low;
276 uint32_t phys, raw_index, getidx;
277 struct lpfc_hbq_init *hip;
278 struct hbq_s *hbqs;
279 struct lpfc_hbq_entry *hbqe;
280 struct lpfc_dmabuf *d_buf;
281 struct hbq_dmabuf *hbq_buf;
282
James Smart3772a992009-05-22 14:50:54 -0400283 if (phba->sli_rev != 3)
284 return 0;
James Smart78b2d852007-08-02 11:10:21 -0400285 cnt = LPFC_HBQINFO_SIZE;
286 spin_lock_irq(&phba->hbalock);
287
288 /* toggle between multiple hbqs, if any */
289 i = lpfc_sli_hbq_count();
290 if (i > 1) {
291 lpfc_debugfs_last_hbq++;
292 if (lpfc_debugfs_last_hbq >= i)
293 lpfc_debugfs_last_hbq = 0;
294 }
295 else
296 lpfc_debugfs_last_hbq = 0;
297
298 i = lpfc_debugfs_last_hbq;
299
300 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
301
James Smart51ef4c22007-08-02 11:10:31 -0400302 hbqs = &phba->hbqs[i];
James Smart78b2d852007-08-02 11:10:21 -0400303 posted = 0;
James Smart51ef4c22007-08-02 11:10:31 -0400304 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
James Smart78b2d852007-08-02 11:10:21 -0400305 posted++;
306
307 hip = lpfc_hbq_defs[i];
308 len += snprintf(buf+len, size-len,
309 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
310 hip->hbq_index, hip->profile, hip->rn,
311 hip->buffer_count, hip->init_count, hip->add_count, posted);
312
James Smart78b2d852007-08-02 11:10:21 -0400313 raw_index = phba->hbq_get[i];
314 getidx = le32_to_cpu(raw_index);
315 len += snprintf(buf+len, size-len,
James Smarta8adb832007-10-27 13:37:53 -0400316 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
317 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
318 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
James Smart78b2d852007-08-02 11:10:21 -0400319
James Smart51ef4c22007-08-02 11:10:31 -0400320 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
James Smart78b2d852007-08-02 11:10:21 -0400321 for (j=0; j<hbqs->entry_count; j++) {
322 len += snprintf(buf+len, size-len,
323 "%03d: %08x %04x %05x ", j,
James Smarta8adb832007-10-27 13:37:53 -0400324 le32_to_cpu(hbqe->bde.addrLow),
325 le32_to_cpu(hbqe->bde.tus.w),
326 le32_to_cpu(hbqe->buffer_tag));
James Smart78b2d852007-08-02 11:10:21 -0400327 i = 0;
328 found = 0;
329
330 /* First calculate if slot has an associated posted buffer */
331 low = hbqs->hbqPutIdx - posted;
332 if (low >= 0) {
333 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
334 len += snprintf(buf+len, size-len, "Unused\n");
335 goto skipit;
336 }
337 }
338 else {
339 if ((j >= hbqs->hbqPutIdx) &&
340 (j < (hbqs->entry_count+low))) {
341 len += snprintf(buf+len, size-len, "Unused\n");
342 goto skipit;
343 }
344 }
345
346 /* Get the Buffer info for the posted buffer */
James Smart51ef4c22007-08-02 11:10:31 -0400347 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
James Smart78b2d852007-08-02 11:10:21 -0400348 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
349 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
James Smarta8adb832007-10-27 13:37:53 -0400350 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
James Smart78b2d852007-08-02 11:10:21 -0400351 len += snprintf(buf+len, size-len,
352 "Buf%d: %p %06x\n", i,
353 hbq_buf->dbuf.virt, hbq_buf->tag);
354 found = 1;
355 break;
356 }
357 i++;
358 }
359 if (!found) {
360 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
361 }
362skipit:
363 hbqe++;
364 if (len > LPFC_HBQINFO_SIZE - 54)
365 break;
366 }
367 spin_unlock_irq(&phba->hbalock);
368 return len;
369}
370
James Smartc95d6c62008-01-11 01:53:23 -0500371static int lpfc_debugfs_last_hba_slim_off;
372
James Smarte59058c2008-08-24 21:49:00 -0400373/**
James Smart3621a712009-04-06 18:47:14 -0400374 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400375 * @phba: The HBA to gather SLIM info from.
376 * @buf: The buffer to dump log into.
377 * @size: The maximum amount of data to process.
378 *
379 * Description:
380 * This routine dumps the current contents of HBA SLIM for the HBA associated
381 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
382 *
383 * Notes:
384 * This routine will only dump up to 1024 bytes of data each time called and
385 * should be called multiple times to dump the entire HBA SLIM.
386 *
387 * Return Value:
388 * This routine returns the amount of bytes that were dumped into @buf and will
389 * not exceed @size.
390 **/
James Smarta58cbd52007-08-02 11:09:43 -0400391static int
James Smartc95d6c62008-01-11 01:53:23 -0500392lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
James Smarta58cbd52007-08-02 11:09:43 -0400393{
394 int len = 0;
James Smartc95d6c62008-01-11 01:53:23 -0500395 int i, off;
396 uint32_t *ptr;
397 char buffer[1024];
398
399 off = 0;
400 spin_lock_irq(&phba->hbalock);
401
402 len += snprintf(buf+len, size-len, "HBA SLIM\n");
403 lpfc_memcpy_from_slim(buffer,
James Smarta257bf92009-04-06 18:48:10 -0400404 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
James Smartc95d6c62008-01-11 01:53:23 -0500405
406 ptr = (uint32_t *)&buffer[0];
407 off = lpfc_debugfs_last_hba_slim_off;
408
409 /* Set it up for the next time */
410 lpfc_debugfs_last_hba_slim_off += 1024;
411 if (lpfc_debugfs_last_hba_slim_off >= 4096)
412 lpfc_debugfs_last_hba_slim_off = 0;
413
414 i = 1024;
415 while (i > 0) {
416 len += snprintf(buf+len, size-len,
417 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
418 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
419 *(ptr+5), *(ptr+6), *(ptr+7));
420 ptr += 8;
421 i -= (8 * sizeof(uint32_t));
422 off += (8 * sizeof(uint32_t));
423 }
424
425 spin_unlock_irq(&phba->hbalock);
426 return len;
427}
428
James Smarte59058c2008-08-24 21:49:00 -0400429/**
James Smart3621a712009-04-06 18:47:14 -0400430 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400431 * @phba: The HBA to gather Host SLIM info from.
432 * @buf: The buffer to dump log into.
433 * @size: The maximum amount of data to process.
434 *
435 * Description:
436 * This routine dumps the current contents of host SLIM for the host associated
437 * with @phba to @buf up to @size bytes of data. The dump will contain the
438 * Mailbox, PCB, Rings, and Registers that are located in host memory.
439 *
440 * Return Value:
441 * This routine returns the amount of bytes that were dumped into @buf and will
442 * not exceed @size.
443 **/
James Smartc95d6c62008-01-11 01:53:23 -0500444static int
445lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
446{
447 int len = 0;
448 int i, off;
James Smarta58cbd52007-08-02 11:09:43 -0400449 uint32_t word0, word1, word2, word3;
450 uint32_t *ptr;
451 struct lpfc_pgp *pgpp;
452 struct lpfc_sli *psli = &phba->sli;
453 struct lpfc_sli_ring *pring;
454
James Smarta58cbd52007-08-02 11:09:43 -0400455 off = 0;
456 spin_lock_irq(&phba->hbalock);
457
458 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
James Smart34b02dc2008-08-24 21:49:55 -0400459 ptr = (uint32_t *)phba->slim2p.virt;
James Smarta58cbd52007-08-02 11:09:43 -0400460 i = sizeof(MAILBOX_t);
461 while (i > 0) {
462 len += snprintf(buf+len, size-len,
463 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
464 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
465 *(ptr+5), *(ptr+6), *(ptr+7));
466 ptr += 8;
467 i -= (8 * sizeof(uint32_t));
468 off += (8 * sizeof(uint32_t));
469 }
470
471 len += snprintf(buf+len, size-len, "SLIM PCB\n");
James Smart34b02dc2008-08-24 21:49:55 -0400472 ptr = (uint32_t *)phba->pcb;
James Smarta58cbd52007-08-02 11:09:43 -0400473 i = sizeof(PCB_t);
474 while (i > 0) {
475 len += snprintf(buf+len, size-len,
476 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
477 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
478 *(ptr+5), *(ptr+6), *(ptr+7));
479 ptr += 8;
480 i -= (8 * sizeof(uint32_t));
481 off += (8 * sizeof(uint32_t));
482 }
483
James Smart34b02dc2008-08-24 21:49:55 -0400484 for (i = 0; i < 4; i++) {
485 pgpp = &phba->port_gp[i];
486 pring = &psli->ring[i];
487 len += snprintf(buf+len, size-len,
488 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
489 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
490 i, pgpp->cmdGetInx, pring->numCiocb,
491 pring->next_cmdidx, pring->local_getidx,
492 pring->flag, pgpp->rspPutInx, pring->numRiocb);
493 }
James Smart3772a992009-05-22 14:50:54 -0400494
495 if (phba->sli_rev <= LPFC_SLI_REV3) {
496 word0 = readl(phba->HAregaddr);
497 word1 = readl(phba->CAregaddr);
498 word2 = readl(phba->HSregaddr);
499 word3 = readl(phba->HCregaddr);
500 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
501 "HC:%08x\n", word0, word1, word2, word3);
502 }
James Smarta58cbd52007-08-02 11:09:43 -0400503 spin_unlock_irq(&phba->hbalock);
504 return len;
505}
506
James Smarte59058c2008-08-24 21:49:00 -0400507/**
James Smart3621a712009-04-06 18:47:14 -0400508 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400509 * @vport: The vport to gather target node info from.
510 * @buf: The buffer to dump log into.
511 * @size: The maximum amount of data to process.
512 *
513 * Description:
514 * This routine dumps the current target node list associated with @vport to
515 * @buf up to @size bytes of data. Each node entry in the dump will contain a
516 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
517 *
518 * Return Value:
519 * This routine returns the amount of bytes that were dumped into @buf and will
520 * not exceed @size.
521 **/
James Smarta58cbd52007-08-02 11:09:43 -0400522static int
James Smart858c9f62007-06-17 19:56:39 -0500523lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
524{
525 int len = 0;
526 int cnt;
527 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
528 struct lpfc_nodelist *ndlp;
529 unsigned char *statep, *name;
530
531 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
532
533 spin_lock_irq(shost->host_lock);
534 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
535 if (!cnt) {
536 len += snprintf(buf+len, size-len,
537 "Missing Nodelist Entries\n");
538 break;
539 }
540 cnt--;
541 switch (ndlp->nlp_state) {
542 case NLP_STE_UNUSED_NODE:
543 statep = "UNUSED";
544 break;
545 case NLP_STE_PLOGI_ISSUE:
546 statep = "PLOGI ";
547 break;
548 case NLP_STE_ADISC_ISSUE:
549 statep = "ADISC ";
550 break;
551 case NLP_STE_REG_LOGIN_ISSUE:
552 statep = "REGLOG";
553 break;
554 case NLP_STE_PRLI_ISSUE:
555 statep = "PRLI ";
556 break;
557 case NLP_STE_UNMAPPED_NODE:
558 statep = "UNMAP ";
559 break;
560 case NLP_STE_MAPPED_NODE:
561 statep = "MAPPED";
562 break;
563 case NLP_STE_NPR_NODE:
564 statep = "NPR ";
565 break;
566 default:
567 statep = "UNKNOWN";
568 }
569 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
570 statep, ndlp->nlp_DID);
571 name = (unsigned char *)&ndlp->nlp_portname;
572 len += snprintf(buf+len, size-len,
573 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
574 *name, *(name+1), *(name+2), *(name+3),
575 *(name+4), *(name+5), *(name+6), *(name+7));
576 name = (unsigned char *)&ndlp->nlp_nodename;
577 len += snprintf(buf+len, size-len,
578 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
579 *name, *(name+1), *(name+2), *(name+3),
580 *(name+4), *(name+5), *(name+6), *(name+7));
581 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
582 ndlp->nlp_rpi, ndlp->nlp_flag);
583 if (!ndlp->nlp_type)
James Smarta58cbd52007-08-02 11:09:43 -0400584 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500585 if (ndlp->nlp_type & NLP_FC_NODE)
586 len += snprintf(buf+len, size-len, "FC_NODE ");
587 if (ndlp->nlp_type & NLP_FABRIC)
588 len += snprintf(buf+len, size-len, "FABRIC ");
589 if (ndlp->nlp_type & NLP_FCP_TARGET)
590 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
591 ndlp->nlp_sid);
592 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
James Smarta58cbd52007-08-02 11:09:43 -0400593 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart58da1ff2008-04-07 10:15:56 -0400594 len += snprintf(buf+len, size-len, "usgmap:%x ",
595 ndlp->nlp_usg_map);
James Smarta58cbd52007-08-02 11:09:43 -0400596 len += snprintf(buf+len, size-len, "refcnt:%x",
597 atomic_read(&ndlp->kref.refcount));
James Smart858c9f62007-06-17 19:56:39 -0500598 len += snprintf(buf+len, size-len, "\n");
599 }
600 spin_unlock_irq(shost->host_lock);
601 return len;
602}
603#endif
604
James Smarte59058c2008-08-24 21:49:00 -0400605/**
James Smart3621a712009-04-06 18:47:14 -0400606 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400607 * @vport: The vport to associate this trace string with for retrieval.
608 * @mask: Log entry classification.
609 * @fmt: Format string to be displayed when dumping the log.
610 * @data1: 1st data parameter to be applied to @fmt.
611 * @data2: 2nd data parameter to be applied to @fmt.
612 * @data3: 3rd data parameter to be applied to @fmt.
613 *
614 * Description:
615 * This routine is used by the driver code to add a debugfs log entry to the
616 * discovery trace buffer associated with @vport. Only entries with a @mask that
617 * match the current debugfs discovery mask will be saved. Entries that do not
618 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
619 * printf when displaying the log.
620 **/
James Smart858c9f62007-06-17 19:56:39 -0500621inline void
622lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
623 uint32_t data1, uint32_t data2, uint32_t data3)
624{
James Smart923e4b62008-12-04 22:40:07 -0500625#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400626 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -0500627 int index;
628
629 if (!(lpfc_debugfs_mask_disc_trc & mask))
630 return;
631
632 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
633 !vport || !vport->disc_trc)
634 return;
635
636 index = atomic_inc_return(&vport->disc_trc_cnt) &
637 (lpfc_debugfs_max_disc_trc - 1);
638 dtp = vport->disc_trc + index;
639 dtp->fmt = fmt;
640 dtp->data1 = data1;
641 dtp->data2 = data2;
642 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -0400643 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
644 dtp->jif = jiffies;
645#endif
646 return;
647}
648
James Smarte59058c2008-08-24 21:49:00 -0400649/**
James Smart3621a712009-04-06 18:47:14 -0400650 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400651 * @phba: The phba to associate this trace string with for retrieval.
652 * @fmt: Format string to be displayed when dumping the log.
653 * @data1: 1st data parameter to be applied to @fmt.
654 * @data2: 2nd data parameter to be applied to @fmt.
655 * @data3: 3rd data parameter to be applied to @fmt.
656 *
657 * Description:
658 * This routine is used by the driver code to add a debugfs log entry to the
659 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
660 * @data3 are used like printf when displaying the log.
661 **/
James Smarta58cbd52007-08-02 11:09:43 -0400662inline void
663lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
664 uint32_t data1, uint32_t data2, uint32_t data3)
665{
James Smart923e4b62008-12-04 22:40:07 -0500666#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400667 struct lpfc_debugfs_trc *dtp;
668 int index;
669
670 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
671 !phba || !phba->slow_ring_trc)
672 return;
673
674 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
675 (lpfc_debugfs_max_slow_ring_trc - 1);
676 dtp = phba->slow_ring_trc + index;
677 dtp->fmt = fmt;
678 dtp->data1 = data1;
679 dtp->data2 = data2;
680 dtp->data3 = data3;
681 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500682 dtp->jif = jiffies;
683#endif
684 return;
685}
686
James Smart923e4b62008-12-04 22:40:07 -0500687#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -0400688/**
James Smart3621a712009-04-06 18:47:14 -0400689 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400690 * @inode: The inode pointer that contains a vport pointer.
691 * @file: The file pointer to attach the log output.
692 *
693 * Description:
694 * This routine is the entry point for the debugfs open file operation. It gets
695 * the vport from the i_private field in @inode, allocates the necessary buffer
696 * for the log, fills the buffer from the in-memory log for this vport, and then
697 * returns a pointer to that log in the private_data field in @file.
698 *
699 * Returns:
700 * This function returns zero if successful. On error it will return an negative
701 * error value.
702 **/
James Smart858c9f62007-06-17 19:56:39 -0500703static int
704lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
705{
706 struct lpfc_vport *vport = inode->i_private;
707 struct lpfc_debug *debug;
708 int size;
709 int rc = -ENOMEM;
710
711 if (!lpfc_debugfs_max_disc_trc) {
712 rc = -ENOSPC;
713 goto out;
714 }
715
716 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
717 if (!debug)
718 goto out;
719
James Smarte59058c2008-08-24 21:49:00 -0400720 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400721 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -0500722 size = PAGE_ALIGN(size);
723
724 debug->buffer = kmalloc(size, GFP_KERNEL);
725 if (!debug->buffer) {
726 kfree(debug);
727 goto out;
728 }
729
730 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
731 file->private_data = debug;
732
733 rc = 0;
734out:
735 return rc;
736}
737
James Smarte59058c2008-08-24 21:49:00 -0400738/**
James Smart3621a712009-04-06 18:47:14 -0400739 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400740 * @inode: The inode pointer that contains a vport pointer.
741 * @file: The file pointer to attach the log output.
742 *
743 * Description:
744 * This routine is the entry point for the debugfs open file operation. It gets
745 * the vport from the i_private field in @inode, allocates the necessary buffer
746 * for the log, fills the buffer from the in-memory log for this vport, and then
747 * returns a pointer to that log in the private_data field in @file.
748 *
749 * Returns:
750 * This function returns zero if successful. On error it will return an negative
751 * error value.
752 **/
James Smart858c9f62007-06-17 19:56:39 -0500753static int
James Smarta58cbd52007-08-02 11:09:43 -0400754lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
755{
756 struct lpfc_hba *phba = inode->i_private;
757 struct lpfc_debug *debug;
758 int size;
759 int rc = -ENOMEM;
760
761 if (!lpfc_debugfs_max_slow_ring_trc) {
762 rc = -ENOSPC;
763 goto out;
764 }
765
766 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
767 if (!debug)
768 goto out;
769
James Smarte59058c2008-08-24 21:49:00 -0400770 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400771 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
772 size = PAGE_ALIGN(size);
773
774 debug->buffer = kmalloc(size, GFP_KERNEL);
775 if (!debug->buffer) {
776 kfree(debug);
777 goto out;
778 }
779
780 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
781 file->private_data = debug;
782
783 rc = 0;
784out:
785 return rc;
786}
787
James Smarte59058c2008-08-24 21:49:00 -0400788/**
James Smart3621a712009-04-06 18:47:14 -0400789 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400790 * @inode: The inode pointer that contains a vport pointer.
791 * @file: The file pointer to attach the log output.
792 *
793 * Description:
794 * This routine is the entry point for the debugfs open file operation. It gets
795 * the vport from the i_private field in @inode, allocates the necessary buffer
796 * for the log, fills the buffer from the in-memory log for this vport, and then
797 * returns a pointer to that log in the private_data field in @file.
798 *
799 * Returns:
800 * This function returns zero if successful. On error it will return an negative
801 * error value.
802 **/
James Smarta58cbd52007-08-02 11:09:43 -0400803static int
James Smart78b2d852007-08-02 11:10:21 -0400804lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
805{
806 struct lpfc_hba *phba = inode->i_private;
807 struct lpfc_debug *debug;
808 int rc = -ENOMEM;
809
810 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
811 if (!debug)
812 goto out;
813
James Smarte59058c2008-08-24 21:49:00 -0400814 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -0400815 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
816 if (!debug->buffer) {
817 kfree(debug);
818 goto out;
819 }
820
821 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
822 LPFC_HBQINFO_SIZE);
823 file->private_data = debug;
824
825 rc = 0;
826out:
827 return rc;
828}
829
James Smarte59058c2008-08-24 21:49:00 -0400830/**
James Smart3621a712009-04-06 18:47:14 -0400831 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400832 * @inode: The inode pointer that contains a vport pointer.
833 * @file: The file pointer to attach the log output.
834 *
835 * Description:
836 * This routine is the entry point for the debugfs open file operation. It gets
837 * the vport from the i_private field in @inode, allocates the necessary buffer
838 * for the log, fills the buffer from the in-memory log for this vport, and then
839 * returns a pointer to that log in the private_data field in @file.
840 *
841 * Returns:
842 * This function returns zero if successful. On error it will return an negative
843 * error value.
844 **/
James Smart78b2d852007-08-02 11:10:21 -0400845static int
James Smartc95d6c62008-01-11 01:53:23 -0500846lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -0400847{
848 struct lpfc_hba *phba = inode->i_private;
849 struct lpfc_debug *debug;
850 int rc = -ENOMEM;
851
852 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
853 if (!debug)
854 goto out;
855
James Smarte59058c2008-08-24 21:49:00 -0400856 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500857 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -0400858 if (!debug->buffer) {
859 kfree(debug);
860 goto out;
861 }
862
James Smartc95d6c62008-01-11 01:53:23 -0500863 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
864 LPFC_DUMPHBASLIM_SIZE);
865 file->private_data = debug;
866
867 rc = 0;
868out:
869 return rc;
870}
871
James Smarte59058c2008-08-24 21:49:00 -0400872/**
James Smart3621a712009-04-06 18:47:14 -0400873 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400874 * @inode: The inode pointer that contains a vport pointer.
875 * @file: The file pointer to attach the log output.
876 *
877 * Description:
878 * This routine is the entry point for the debugfs open file operation. It gets
879 * the vport from the i_private field in @inode, allocates the necessary buffer
880 * for the log, fills the buffer from the in-memory log for this vport, and then
881 * returns a pointer to that log in the private_data field in @file.
882 *
883 * Returns:
884 * This function returns zero if successful. On error it will return an negative
885 * error value.
886 **/
James Smartc95d6c62008-01-11 01:53:23 -0500887static int
888lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
889{
890 struct lpfc_hba *phba = inode->i_private;
891 struct lpfc_debug *debug;
892 int rc = -ENOMEM;
893
894 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
895 if (!debug)
896 goto out;
897
James Smarte59058c2008-08-24 21:49:00 -0400898 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500899 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
900 if (!debug->buffer) {
901 kfree(debug);
902 goto out;
903 }
904
905 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
906 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -0400907 file->private_data = debug;
908
909 rc = 0;
910out:
911 return rc;
912}
913
James Smarte2a0a9d2008-12-04 22:40:02 -0500914static int
915lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
916{
917 struct lpfc_debug *debug;
918 int rc = -ENOMEM;
919
920 if (!_dump_buf_data)
921 return -EBUSY;
922
923 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
924 if (!debug)
925 goto out;
926
927 /* Round to page boundry */
928 printk(KERN_ERR "BLKGRD %s: _dump_buf_data=0x%p\n",
929 __func__, _dump_buf_data);
930 debug->buffer = _dump_buf_data;
931 if (!debug->buffer) {
932 kfree(debug);
933 goto out;
934 }
935
936 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
937 file->private_data = debug;
938
939 rc = 0;
940out:
941 return rc;
942}
943
944static int
945lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
946{
947 struct lpfc_debug *debug;
948 int rc = -ENOMEM;
949
950 if (!_dump_buf_dif)
951 return -EBUSY;
952
953 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
954 if (!debug)
955 goto out;
956
957 /* Round to page boundry */
958 printk(KERN_ERR "BLKGRD %s: _dump_buf_dif=0x%p file=%s\n", __func__,
959 _dump_buf_dif, file->f_dentry->d_name.name);
960 debug->buffer = _dump_buf_dif;
961 if (!debug->buffer) {
962 kfree(debug);
963 goto out;
964 }
965
966 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
967 file->private_data = debug;
968
969 rc = 0;
970out:
971 return rc;
972}
973
974static ssize_t
975lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
976 size_t nbytes, loff_t *ppos)
977{
978 /*
979 * The Data/DIF buffers only save one failing IO
980 * The write op is used as a reset mechanism after an IO has
981 * already been saved to the next one can be saved
982 */
983 spin_lock(&_dump_buf_lock);
984
985 memset((void *)_dump_buf_data, 0,
986 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
987 memset((void *)_dump_buf_dif, 0,
988 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
989
990 _dump_buf_done = 0;
991
992 spin_unlock(&_dump_buf_lock);
993
994 return nbytes;
995}
996
997
998
James Smarte59058c2008-08-24 21:49:00 -0400999/**
James Smart3621a712009-04-06 18:47:14 -04001000 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001001 * @inode: The inode pointer that contains a vport pointer.
1002 * @file: The file pointer to attach the log output.
1003 *
1004 * Description:
1005 * This routine is the entry point for the debugfs open file operation. It gets
1006 * the vport from the i_private field in @inode, allocates the necessary buffer
1007 * for the log, fills the buffer from the in-memory log for this vport, and then
1008 * returns a pointer to that log in the private_data field in @file.
1009 *
1010 * Returns:
1011 * This function returns zero if successful. On error it will return an negative
1012 * error value.
1013 **/
James Smarta58cbd52007-08-02 11:09:43 -04001014static int
James Smart858c9f62007-06-17 19:56:39 -05001015lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1016{
1017 struct lpfc_vport *vport = inode->i_private;
1018 struct lpfc_debug *debug;
1019 int rc = -ENOMEM;
1020
1021 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1022 if (!debug)
1023 goto out;
1024
James Smarte59058c2008-08-24 21:49:00 -04001025 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05001026 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1027 if (!debug->buffer) {
1028 kfree(debug);
1029 goto out;
1030 }
1031
1032 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1033 LPFC_NODELIST_SIZE);
1034 file->private_data = debug;
1035
1036 rc = 0;
1037out:
1038 return rc;
1039}
1040
James Smarte59058c2008-08-24 21:49:00 -04001041/**
James Smart3621a712009-04-06 18:47:14 -04001042 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001043 * @file: The file pointer to seek through.
1044 * @off: The offset to seek to or the amount to seek by.
1045 * @whence: Indicates how to seek.
1046 *
1047 * Description:
1048 * This routine is the entry point for the debugfs lseek file operation. The
1049 * @whence parameter indicates whether @off is the offset to directly seek to,
1050 * or if it is a value to seek forward or reverse by. This function figures out
1051 * what the new offset of the debugfs file will be and assigns that value to the
1052 * f_pos field of @file.
1053 *
1054 * Returns:
1055 * This function returns the new offset if successful and returns a negative
1056 * error if unable to process the seek.
1057 **/
James Smart858c9f62007-06-17 19:56:39 -05001058static loff_t
1059lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1060{
1061 struct lpfc_debug *debug;
1062 loff_t pos = -1;
1063
1064 debug = file->private_data;
1065
1066 switch (whence) {
1067 case 0:
1068 pos = off;
1069 break;
1070 case 1:
1071 pos = file->f_pos + off;
1072 break;
1073 case 2:
1074 pos = debug->len - off;
1075 }
1076 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1077}
1078
James Smarte59058c2008-08-24 21:49:00 -04001079/**
James Smart3621a712009-04-06 18:47:14 -04001080 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001081 * @file: The file pointer to read from.
1082 * @buf: The buffer to copy the data to.
1083 * @nbytes: The number of bytes to read.
1084 * @ppos: The position in the file to start reading from.
1085 *
1086 * Description:
1087 * This routine reads data from from the buffer indicated in the private_data
1088 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1089 * data to @buf.
1090 *
1091 * Returns:
1092 * This function returns the amount of data that was read (this could be less
1093 * than @nbytes if the end of the file was reached) or a negative error value.
1094 **/
James Smart858c9f62007-06-17 19:56:39 -05001095static ssize_t
1096lpfc_debugfs_read(struct file *file, char __user *buf,
1097 size_t nbytes, loff_t *ppos)
1098{
1099 struct lpfc_debug *debug = file->private_data;
1100 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1101 debug->len);
1102}
1103
James Smarte59058c2008-08-24 21:49:00 -04001104/**
James Smart3621a712009-04-06 18:47:14 -04001105 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04001106 * @inode: The inode pointer that contains a vport pointer. (unused)
1107 * @file: The file pointer that contains the buffer to release.
1108 *
1109 * Description:
1110 * This routine frees the buffer that was allocated when the debugfs file was
1111 * opened.
1112 *
1113 * Returns:
1114 * This function returns zero.
1115 **/
James Smart858c9f62007-06-17 19:56:39 -05001116static int
1117lpfc_debugfs_release(struct inode *inode, struct file *file)
1118{
1119 struct lpfc_debug *debug = file->private_data;
1120
1121 kfree(debug->buffer);
1122 kfree(debug);
1123
1124 return 0;
1125}
1126
James Smarte2a0a9d2008-12-04 22:40:02 -05001127static int
1128lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1129{
1130 struct lpfc_debug *debug = file->private_data;
1131
1132 debug->buffer = NULL;
1133 kfree(debug);
1134
1135 return 0;
1136}
1137
James Smart858c9f62007-06-17 19:56:39 -05001138#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001139static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05001140 .owner = THIS_MODULE,
1141 .open = lpfc_debugfs_disc_trc_open,
1142 .llseek = lpfc_debugfs_lseek,
1143 .read = lpfc_debugfs_read,
1144 .release = lpfc_debugfs_release,
1145};
1146
1147#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001148static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05001149 .owner = THIS_MODULE,
1150 .open = lpfc_debugfs_nodelist_open,
1151 .llseek = lpfc_debugfs_lseek,
1152 .read = lpfc_debugfs_read,
1153 .release = lpfc_debugfs_release,
1154};
1155
James Smart78b2d852007-08-02 11:10:21 -04001156#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001157static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04001158 .owner = THIS_MODULE,
1159 .open = lpfc_debugfs_hbqinfo_open,
1160 .llseek = lpfc_debugfs_lseek,
1161 .read = lpfc_debugfs_read,
1162 .release = lpfc_debugfs_release,
1163};
1164
James Smartc95d6c62008-01-11 01:53:23 -05001165#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001166static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04001167 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05001168 .open = lpfc_debugfs_dumpHBASlim_open,
1169 .llseek = lpfc_debugfs_lseek,
1170 .read = lpfc_debugfs_read,
1171 .release = lpfc_debugfs_release,
1172};
1173
1174#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001175static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05001176 .owner = THIS_MODULE,
1177 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04001178 .llseek = lpfc_debugfs_lseek,
1179 .read = lpfc_debugfs_read,
1180 .release = lpfc_debugfs_release,
1181};
1182
James Smarte2a0a9d2008-12-04 22:40:02 -05001183#undef lpfc_debugfs_op_dumpData
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001184static const struct file_operations lpfc_debugfs_op_dumpData = {
James Smarte2a0a9d2008-12-04 22:40:02 -05001185 .owner = THIS_MODULE,
1186 .open = lpfc_debugfs_dumpData_open,
1187 .llseek = lpfc_debugfs_lseek,
1188 .read = lpfc_debugfs_read,
1189 .write = lpfc_debugfs_dumpDataDif_write,
1190 .release = lpfc_debugfs_dumpDataDif_release,
1191};
1192
1193#undef lpfc_debugfs_op_dumpDif
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001194static const struct file_operations lpfc_debugfs_op_dumpDif = {
James Smarte2a0a9d2008-12-04 22:40:02 -05001195 .owner = THIS_MODULE,
1196 .open = lpfc_debugfs_dumpDif_open,
1197 .llseek = lpfc_debugfs_lseek,
1198 .read = lpfc_debugfs_read,
1199 .write = lpfc_debugfs_dumpDataDif_write,
1200 .release = lpfc_debugfs_dumpDataDif_release,
1201};
1202
James Smarta58cbd52007-08-02 11:09:43 -04001203#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001204static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04001205 .owner = THIS_MODULE,
1206 .open = lpfc_debugfs_slow_ring_trc_open,
1207 .llseek = lpfc_debugfs_lseek,
1208 .read = lpfc_debugfs_read,
1209 .release = lpfc_debugfs_release,
1210};
1211
James Smart858c9f62007-06-17 19:56:39 -05001212static struct dentry *lpfc_debugfs_root = NULL;
1213static atomic_t lpfc_debugfs_hba_count;
1214#endif
1215
James Smarte59058c2008-08-24 21:49:00 -04001216/**
James Smart3621a712009-04-06 18:47:14 -04001217 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04001218 * @vport: The vport pointer to initialize.
1219 *
1220 * Description:
1221 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
1222 * If not already created, this routine will create the lpfc directory, and
1223 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
1224 * also create each file used to access lpfc specific debugfs information.
1225 **/
James Smart858c9f62007-06-17 19:56:39 -05001226inline void
1227lpfc_debugfs_initialize(struct lpfc_vport *vport)
1228{
James Smart923e4b62008-12-04 22:40:07 -05001229#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05001230 struct lpfc_hba *phba = vport->phba;
1231 char name[64];
1232 uint32_t num, i;
1233
1234 if (!lpfc_debugfs_enable)
1235 return;
1236
James Smarta58cbd52007-08-02 11:09:43 -04001237 /* Setup lpfc root directory */
1238 if (!lpfc_debugfs_root) {
1239 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
1240 atomic_set(&lpfc_debugfs_hba_count, 0);
1241 if (!lpfc_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04001242 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001243 "0408 Cannot create debugfs root\n");
James Smarta58cbd52007-08-02 11:09:43 -04001244 goto debug_failed;
1245 }
1246 }
James Smarta58cbd52007-08-02 11:09:43 -04001247 if (!lpfc_debugfs_start_time)
1248 lpfc_debugfs_start_time = jiffies;
1249
1250 /* Setup lpfcX directory for specific HBA */
1251 snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
1252 if (!phba->hba_debugfs_root) {
1253 phba->hba_debugfs_root =
1254 debugfs_create_dir(name, lpfc_debugfs_root);
1255 if (!phba->hba_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04001256 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001257 "0412 Cannot create debugfs hba\n");
James Smarta58cbd52007-08-02 11:09:43 -04001258 goto debug_failed;
1259 }
1260 atomic_inc(&lpfc_debugfs_hba_count);
1261 atomic_set(&phba->debugfs_vport_count, 0);
1262
James Smart78b2d852007-08-02 11:10:21 -04001263 /* Setup hbqinfo */
1264 snprintf(name, sizeof(name), "hbqinfo");
1265 phba->debug_hbqinfo =
1266 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1267 phba->hba_debugfs_root,
1268 phba, &lpfc_debugfs_op_hbqinfo);
1269 if (!phba->debug_hbqinfo) {
1270 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001271 "0411 Cannot create debugfs hbqinfo\n");
James Smart78b2d852007-08-02 11:10:21 -04001272 goto debug_failed;
1273 }
1274
James Smartc95d6c62008-01-11 01:53:23 -05001275 /* Setup dumpHBASlim */
1276 snprintf(name, sizeof(name), "dumpHBASlim");
1277 phba->debug_dumpHBASlim =
James Smarta58cbd52007-08-02 11:09:43 -04001278 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1279 phba->hba_debugfs_root,
James Smartc95d6c62008-01-11 01:53:23 -05001280 phba, &lpfc_debugfs_op_dumpHBASlim);
1281 if (!phba->debug_dumpHBASlim) {
James Smarte8b62012007-08-02 11:10:09 -04001282 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001283 "0413 Cannot create debugfs dumpHBASlim\n");
James Smartc95d6c62008-01-11 01:53:23 -05001284 goto debug_failed;
1285 }
1286
1287 /* Setup dumpHostSlim */
1288 snprintf(name, sizeof(name), "dumpHostSlim");
1289 phba->debug_dumpHostSlim =
1290 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1291 phba->hba_debugfs_root,
1292 phba, &lpfc_debugfs_op_dumpHostSlim);
1293 if (!phba->debug_dumpHostSlim) {
1294 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001295 "0414 Cannot create debugfs dumpHostSlim\n");
James Smarta58cbd52007-08-02 11:09:43 -04001296 goto debug_failed;
1297 }
1298
James Smarte2a0a9d2008-12-04 22:40:02 -05001299 /* Setup dumpData */
1300 snprintf(name, sizeof(name), "dumpData");
1301 phba->debug_dumpData =
1302 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1303 phba->hba_debugfs_root,
1304 phba, &lpfc_debugfs_op_dumpData);
1305 if (!phba->debug_dumpData) {
1306 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1307 "0800 Cannot create debugfs dumpData\n");
1308 goto debug_failed;
1309 }
1310
1311 /* Setup dumpDif */
1312 snprintf(name, sizeof(name), "dumpDif");
1313 phba->debug_dumpDif =
1314 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1315 phba->hba_debugfs_root,
1316 phba, &lpfc_debugfs_op_dumpDif);
1317 if (!phba->debug_dumpDif) {
1318 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1319 "0801 Cannot create debugfs dumpDif\n");
1320 goto debug_failed;
1321 }
1322
1323
1324
James Smarta58cbd52007-08-02 11:09:43 -04001325 /* Setup slow ring trace */
1326 if (lpfc_debugfs_max_slow_ring_trc) {
1327 num = lpfc_debugfs_max_slow_ring_trc - 1;
1328 if (num & lpfc_debugfs_max_slow_ring_trc) {
1329 /* Change to be a power of 2 */
1330 num = lpfc_debugfs_max_slow_ring_trc;
1331 i = 0;
1332 while (num > 1) {
1333 num = num >> 1;
1334 i++;
1335 }
1336 lpfc_debugfs_max_slow_ring_trc = (1 << i);
1337 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04001338 "lpfc_debugfs_max_disc_trc changed to "
1339 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04001340 }
1341 }
1342
1343
1344 snprintf(name, sizeof(name), "slow_ring_trace");
1345 phba->debug_slow_ring_trc =
1346 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1347 phba->hba_debugfs_root,
1348 phba, &lpfc_debugfs_op_slow_ring_trc);
1349 if (!phba->debug_slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001350 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001351 "0415 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04001352 "slow_ring_trace\n");
James Smarta58cbd52007-08-02 11:09:43 -04001353 goto debug_failed;
1354 }
1355 if (!phba->slow_ring_trc) {
1356 phba->slow_ring_trc = kmalloc(
1357 (sizeof(struct lpfc_debugfs_trc) *
1358 lpfc_debugfs_max_slow_ring_trc),
1359 GFP_KERNEL);
1360 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001361 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001362 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04001363 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04001364 goto debug_failed;
1365 }
1366 atomic_set(&phba->slow_ring_trc_cnt, 0);
1367 memset(phba->slow_ring_trc, 0,
1368 (sizeof(struct lpfc_debugfs_trc) *
1369 lpfc_debugfs_max_slow_ring_trc));
1370 }
1371 }
1372
1373 snprintf(name, sizeof(name), "vport%d", vport->vpi);
1374 if (!vport->vport_debugfs_root) {
1375 vport->vport_debugfs_root =
1376 debugfs_create_dir(name, phba->hba_debugfs_root);
1377 if (!vport->vport_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04001378 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001379 "0417 Cant create debugfs");
James Smarta58cbd52007-08-02 11:09:43 -04001380 goto debug_failed;
1381 }
1382 atomic_inc(&phba->debugfs_vport_count);
1383 }
1384
James Smart858c9f62007-06-17 19:56:39 -05001385 if (lpfc_debugfs_max_disc_trc) {
1386 num = lpfc_debugfs_max_disc_trc - 1;
1387 if (num & lpfc_debugfs_max_disc_trc) {
1388 /* Change to be a power of 2 */
1389 num = lpfc_debugfs_max_disc_trc;
1390 i = 0;
1391 while (num > 1) {
1392 num = num >> 1;
1393 i++;
1394 }
1395 lpfc_debugfs_max_disc_trc = (1 << i);
1396 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04001397 "lpfc_debugfs_max_disc_trc changed to %d\n",
1398 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05001399 }
1400 }
1401
Adrian Bunkff86ba52007-10-18 12:52:37 +02001402 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04001403 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05001404 GFP_KERNEL);
1405
James Smarta58cbd52007-08-02 11:09:43 -04001406 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001407 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001408 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04001409 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05001410 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04001411 }
1412 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05001413
1414 snprintf(name, sizeof(name), "discovery_trace");
1415 vport->debug_disc_trc =
1416 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1417 vport->vport_debugfs_root,
1418 vport, &lpfc_debugfs_op_disc_trc);
1419 if (!vport->debug_disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001420 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001421 "0419 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04001422 "discovery_trace\n");
James Smart858c9f62007-06-17 19:56:39 -05001423 goto debug_failed;
1424 }
1425 snprintf(name, sizeof(name), "nodelist");
1426 vport->debug_nodelist =
1427 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1428 vport->vport_debugfs_root,
1429 vport, &lpfc_debugfs_op_nodelist);
1430 if (!vport->debug_nodelist) {
James Smarte8b62012007-08-02 11:10:09 -04001431 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1432 "0409 Cant create debugfs nodelist");
James Smart858c9f62007-06-17 19:56:39 -05001433 goto debug_failed;
1434 }
1435debug_failed:
1436 return;
1437#endif
1438}
1439
James Smarte59058c2008-08-24 21:49:00 -04001440/**
James Smart3621a712009-04-06 18:47:14 -04001441 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04001442 * @vport: The vport pointer to remove from debugfs.
1443 *
1444 * Description:
1445 * When Debugfs is configured this routine removes debugfs file system elements
1446 * that are specific to this vport. It also checks to see if there are any
1447 * users left for the debugfs directories associated with the HBA and driver. If
1448 * this is the last user of the HBA directory or driver directory then it will
1449 * remove those from the debugfs infrastructure as well.
1450 **/
James Smart858c9f62007-06-17 19:56:39 -05001451inline void
1452lpfc_debugfs_terminate(struct lpfc_vport *vport)
1453{
James Smart923e4b62008-12-04 22:40:07 -05001454#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05001455 struct lpfc_hba *phba = vport->phba;
1456
1457 if (vport->disc_trc) {
1458 kfree(vport->disc_trc);
1459 vport->disc_trc = NULL;
1460 }
1461 if (vport->debug_disc_trc) {
1462 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
1463 vport->debug_disc_trc = NULL;
1464 }
1465 if (vport->debug_nodelist) {
1466 debugfs_remove(vport->debug_nodelist); /* nodelist */
1467 vport->debug_nodelist = NULL;
1468 }
James Smarta58cbd52007-08-02 11:09:43 -04001469
James Smart858c9f62007-06-17 19:56:39 -05001470 if (vport->vport_debugfs_root) {
1471 debugfs_remove(vport->vport_debugfs_root); /* vportX */
1472 vport->vport_debugfs_root = NULL;
1473 atomic_dec(&phba->debugfs_vport_count);
1474 }
1475 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04001476
James Smart78b2d852007-08-02 11:10:21 -04001477 if (phba->debug_hbqinfo) {
1478 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
1479 phba->debug_hbqinfo = NULL;
1480 }
James Smartc95d6c62008-01-11 01:53:23 -05001481 if (phba->debug_dumpHBASlim) {
1482 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
1483 phba->debug_dumpHBASlim = NULL;
1484 }
1485 if (phba->debug_dumpHostSlim) {
1486 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
1487 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04001488 }
James Smarte2a0a9d2008-12-04 22:40:02 -05001489 if (phba->debug_dumpData) {
1490 debugfs_remove(phba->debug_dumpData); /* dumpData */
1491 phba->debug_dumpData = NULL;
1492 }
1493
1494 if (phba->debug_dumpDif) {
1495 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
1496 phba->debug_dumpDif = NULL;
1497 }
1498
James Smarta58cbd52007-08-02 11:09:43 -04001499 if (phba->slow_ring_trc) {
1500 kfree(phba->slow_ring_trc);
1501 phba->slow_ring_trc = NULL;
1502 }
1503 if (phba->debug_slow_ring_trc) {
1504 /* slow_ring_trace */
1505 debugfs_remove(phba->debug_slow_ring_trc);
1506 phba->debug_slow_ring_trc = NULL;
1507 }
1508
1509 if (phba->hba_debugfs_root) {
1510 debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
1511 phba->hba_debugfs_root = NULL;
1512 atomic_dec(&lpfc_debugfs_hba_count);
1513 }
1514
James Smart858c9f62007-06-17 19:56:39 -05001515 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
1516 debugfs_remove(lpfc_debugfs_root); /* lpfc */
1517 lpfc_debugfs_root = NULL;
1518 }
1519 }
1520#endif
James Smarta58cbd52007-08-02 11:09:43 -04001521 return;
James Smart858c9f62007-06-17 19:56:39 -05001522}