blob: 391584183d81fc7102453bd73a5f7faf1a5e1798 [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2007-2009 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
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_hw4.h"
James Smart858c9f62007-06-17 19:56:39 -050037#include "lpfc_hw.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040040#include "lpfc_nl.h"
James Smart858c9f62007-06-17 19:56:39 -050041#include "lpfc_disc.h"
42#include "lpfc_scsi.h"
43#include "lpfc.h"
44#include "lpfc_logmsg.h"
45#include "lpfc_crtn.h"
46#include "lpfc_vport.h"
47#include "lpfc_version.h"
James Smartc95d6c62008-01-11 01:53:23 -050048#include "lpfc_compat.h"
James Smart858c9f62007-06-17 19:56:39 -050049#include "lpfc_debugfs.h"
50
James Smart923e4b62008-12-04 22:40:07 -050051#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart3621a712009-04-06 18:47:14 -040052/*
James Smarte59058c2008-08-24 21:49:00 -040053 * debugfs interface
James Smart858c9f62007-06-17 19:56:39 -050054 *
55 * To access this interface the user should:
GeunSik Lim156f5a72009-06-02 15:01:37 +090056 * # mount -t debugfs none /sys/kernel/debug
James Smart858c9f62007-06-17 19:56:39 -050057 *
James Smarte59058c2008-08-24 21:49:00 -040058 * The lpfc debugfs directory hierarchy is:
James Smart858c9f62007-06-17 19:56:39 -050059 * lpfc/lpfcX/vportY
60 * where X is the lpfc hba unique_id
61 * where Y is the vport VPI on that hba
62 *
63 * Debugging services available per vport:
64 * discovery_trace
65 * This is an ACSII readable file that contains a trace of the last
66 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
James Smarte59058c2008-08-24 21:49:00 -040067 * See lpfc_debugfs.h for different categories of discovery events.
68 * To enable the discovery trace, the following module parameters must be set:
James Smart858c9f62007-06-17 19:56:39 -050069 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
70 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
71 * EACH vport. X MUST also be a power of 2.
72 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
73 * lpfc_debugfs.h .
James Smarte59058c2008-08-24 21:49:00 -040074 *
75 * slow_ring_trace
76 * This is an ACSII readable file that contains a trace of the last
77 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
78 * To enable the slow ring trace, the following module parameters must be set:
79 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
80 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
81 * the HBA. X MUST also be a power of 2.
James Smart858c9f62007-06-17 19:56:39 -050082 */
James Smart51ef4c22007-08-02 11:10:31 -040083static int lpfc_debugfs_enable = 1;
James Smart858c9f62007-06-17 19:56:39 -050084module_param(lpfc_debugfs_enable, int, 0);
85MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
86
James Smarta58cbd52007-08-02 11:09:43 -040087/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050088static int lpfc_debugfs_max_disc_trc;
James Smart858c9f62007-06-17 19:56:39 -050089module_param(lpfc_debugfs_max_disc_trc, int, 0);
90MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
91 "Set debugfs discovery trace depth");
92
James Smarta58cbd52007-08-02 11:09:43 -040093/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050094static int lpfc_debugfs_max_slow_ring_trc;
James Smarta58cbd52007-08-02 11:09:43 -040095module_param(lpfc_debugfs_max_slow_ring_trc, int, 0);
96MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
97 "Set debugfs slow ring trace depth");
98
James Smarta257bf92009-04-06 18:48:10 -040099static int lpfc_debugfs_mask_disc_trc;
James Smart858c9f62007-06-17 19:56:39 -0500100module_param(lpfc_debugfs_mask_disc_trc, int, 0);
101MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
102 "Set debugfs discovery trace mask");
103
104#include <linux/debugfs.h>
105
James Smarta58cbd52007-08-02 11:09:43 -0400106/* size of output line, for discovery_trace and slow_ring_trace */
107#define LPFC_DEBUG_TRC_ENTRY_SIZE 100
James Smart858c9f62007-06-17 19:56:39 -0500108
109/* nodelist output buffer size */
110#define LPFC_NODELIST_SIZE 8192
111#define LPFC_NODELIST_ENTRY_SIZE 120
112
James Smartc95d6c62008-01-11 01:53:23 -0500113/* dumpHBASlim output buffer size */
114#define LPFC_DUMPHBASLIM_SIZE 4096
115
116/* dumpHostSlim output buffer size */
117#define LPFC_DUMPHOSTSLIM_SIZE 4096
James Smarta58cbd52007-08-02 11:09:43 -0400118
James Smart78b2d852007-08-02 11:10:21 -0400119/* hbqinfo output buffer size */
120#define LPFC_HBQINFO_SIZE 8192
121
James Smart858c9f62007-06-17 19:56:39 -0500122struct lpfc_debug {
123 char *buffer;
124 int len;
125};
126
James Smart311464e2007-08-02 11:10:37 -0400127static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
128static unsigned long lpfc_debugfs_start_time = 0L;
James Smart858c9f62007-06-17 19:56:39 -0500129
James Smarte59058c2008-08-24 21:49:00 -0400130/**
James Smart3621a712009-04-06 18:47:14 -0400131 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400132 * @vport: The vport to gather the log info from.
133 * @buf: The buffer to dump log into.
134 * @size: The maximum amount of data to process.
135 *
136 * Description:
137 * This routine gathers the lpfc discovery debugfs data from the @vport and
138 * dumps it to @buf up to @size number of bytes. It will start at the next entry
139 * in the log and process the log until the end of the buffer. Then it will
140 * gather from the beginning of the log and process until the current entry.
141 *
142 * Notes:
143 * Discovery logging will be disabled while while this routine dumps the log.
144 *
145 * Return Value:
146 * This routine returns the amount of bytes that were dumped into @buf and will
147 * not exceed @size.
148 **/
James Smart858c9f62007-06-17 19:56:39 -0500149static int
150lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
151{
152 int i, index, len, enable;
153 uint32_t ms;
James Smarta58cbd52007-08-02 11:09:43 -0400154 struct lpfc_debugfs_trc *dtp;
155 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
James Smart858c9f62007-06-17 19:56:39 -0500156
James Smart858c9f62007-06-17 19:56:39 -0500157 enable = lpfc_debugfs_enable;
158 lpfc_debugfs_enable = 0;
159
160 len = 0;
161 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
162 (lpfc_debugfs_max_disc_trc - 1);
163 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
164 dtp = vport->disc_trc + i;
165 if (!dtp->fmt)
166 continue;
167 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400168 snprintf(buffer,
169 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500170 dtp->seq_cnt, ms, dtp->fmt);
171 len += snprintf(buf+len, size-len, buffer,
172 dtp->data1, dtp->data2, dtp->data3);
173 }
174 for (i = 0; i < index; i++) {
175 dtp = vport->disc_trc + i;
176 if (!dtp->fmt)
177 continue;
178 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400179 snprintf(buffer,
180 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500181 dtp->seq_cnt, ms, dtp->fmt);
182 len += snprintf(buf+len, size-len, buffer,
183 dtp->data1, dtp->data2, dtp->data3);
184 }
185
186 lpfc_debugfs_enable = enable;
187 return len;
188}
189
James Smarte59058c2008-08-24 21:49:00 -0400190/**
James Smart3621a712009-04-06 18:47:14 -0400191 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400192 * @phba: The HBA to gather the log info from.
193 * @buf: The buffer to dump log into.
194 * @size: The maximum amount of data to process.
195 *
196 * Description:
197 * This routine gathers the lpfc slow ring debugfs data from the @phba and
198 * dumps it to @buf up to @size number of bytes. It will start at the next entry
199 * in the log and process the log until the end of the buffer. Then it will
200 * gather from the beginning of the log and process until the current entry.
201 *
202 * Notes:
203 * Slow ring logging will be disabled while while this routine dumps the log.
204 *
205 * Return Value:
206 * This routine returns the amount of bytes that were dumped into @buf and will
207 * not exceed @size.
208 **/
James Smart858c9f62007-06-17 19:56:39 -0500209static int
James Smarta58cbd52007-08-02 11:09:43 -0400210lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
211{
212 int i, index, len, enable;
213 uint32_t ms;
214 struct lpfc_debugfs_trc *dtp;
215 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
216
217
218 enable = lpfc_debugfs_enable;
219 lpfc_debugfs_enable = 0;
220
221 len = 0;
222 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
223 (lpfc_debugfs_max_slow_ring_trc - 1);
224 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
225 dtp = phba->slow_ring_trc + i;
226 if (!dtp->fmt)
227 continue;
228 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
229 snprintf(buffer,
230 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
231 dtp->seq_cnt, ms, dtp->fmt);
232 len += snprintf(buf+len, size-len, buffer,
233 dtp->data1, dtp->data2, dtp->data3);
234 }
235 for (i = 0; i < index; i++) {
236 dtp = phba->slow_ring_trc + i;
237 if (!dtp->fmt)
238 continue;
239 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
240 snprintf(buffer,
241 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
242 dtp->seq_cnt, ms, dtp->fmt);
243 len += snprintf(buf+len, size-len, buffer,
244 dtp->data1, dtp->data2, dtp->data3);
245 }
246
247 lpfc_debugfs_enable = enable;
248 return len;
249}
250
James Smart311464e2007-08-02 11:10:37 -0400251static int lpfc_debugfs_last_hbq = -1;
James Smart78b2d852007-08-02 11:10:21 -0400252
James Smarte59058c2008-08-24 21:49:00 -0400253/**
James Smart3621a712009-04-06 18:47:14 -0400254 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400255 * @phba: The HBA to gather host buffer info from.
256 * @buf: The buffer to dump log into.
257 * @size: The maximum amount of data to process.
258 *
259 * Description:
260 * This routine dumps the host buffer queue info from the @phba to @buf up to
261 * @size number of bytes. A header that describes the current hbq state will be
262 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
263 * until @size bytes have been dumped or all the hbq info has been dumped.
264 *
265 * Notes:
266 * This routine will rotate through each configured HBQ each time called.
267 *
268 * Return Value:
269 * This routine returns the amount of bytes that were dumped into @buf and will
270 * not exceed @size.
271 **/
James Smart78b2d852007-08-02 11:10:21 -0400272static int
273lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
274{
275 int len = 0;
276 int cnt, i, j, found, posted, low;
277 uint32_t phys, raw_index, getidx;
278 struct lpfc_hbq_init *hip;
279 struct hbq_s *hbqs;
280 struct lpfc_hbq_entry *hbqe;
281 struct lpfc_dmabuf *d_buf;
282 struct hbq_dmabuf *hbq_buf;
283
James Smart3772a992009-05-22 14:50:54 -0400284 if (phba->sli_rev != 3)
285 return 0;
James Smart78b2d852007-08-02 11:10:21 -0400286 cnt = LPFC_HBQINFO_SIZE;
287 spin_lock_irq(&phba->hbalock);
288
289 /* toggle between multiple hbqs, if any */
290 i = lpfc_sli_hbq_count();
291 if (i > 1) {
292 lpfc_debugfs_last_hbq++;
293 if (lpfc_debugfs_last_hbq >= i)
294 lpfc_debugfs_last_hbq = 0;
295 }
296 else
297 lpfc_debugfs_last_hbq = 0;
298
299 i = lpfc_debugfs_last_hbq;
300
301 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
302
James Smart51ef4c22007-08-02 11:10:31 -0400303 hbqs = &phba->hbqs[i];
James Smart78b2d852007-08-02 11:10:21 -0400304 posted = 0;
James Smart51ef4c22007-08-02 11:10:31 -0400305 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
James Smart78b2d852007-08-02 11:10:21 -0400306 posted++;
307
308 hip = lpfc_hbq_defs[i];
309 len += snprintf(buf+len, size-len,
310 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
311 hip->hbq_index, hip->profile, hip->rn,
312 hip->buffer_count, hip->init_count, hip->add_count, posted);
313
James Smart78b2d852007-08-02 11:10:21 -0400314 raw_index = phba->hbq_get[i];
315 getidx = le32_to_cpu(raw_index);
316 len += snprintf(buf+len, size-len,
James Smarta8adb832007-10-27 13:37:53 -0400317 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
318 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
319 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
James Smart78b2d852007-08-02 11:10:21 -0400320
James Smart51ef4c22007-08-02 11:10:31 -0400321 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
James Smart78b2d852007-08-02 11:10:21 -0400322 for (j=0; j<hbqs->entry_count; j++) {
323 len += snprintf(buf+len, size-len,
324 "%03d: %08x %04x %05x ", j,
James Smarta8adb832007-10-27 13:37:53 -0400325 le32_to_cpu(hbqe->bde.addrLow),
326 le32_to_cpu(hbqe->bde.tus.w),
327 le32_to_cpu(hbqe->buffer_tag));
James Smart78b2d852007-08-02 11:10:21 -0400328 i = 0;
329 found = 0;
330
331 /* First calculate if slot has an associated posted buffer */
332 low = hbqs->hbqPutIdx - posted;
333 if (low >= 0) {
334 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
335 len += snprintf(buf+len, size-len, "Unused\n");
336 goto skipit;
337 }
338 }
339 else {
340 if ((j >= hbqs->hbqPutIdx) &&
341 (j < (hbqs->entry_count+low))) {
342 len += snprintf(buf+len, size-len, "Unused\n");
343 goto skipit;
344 }
345 }
346
347 /* Get the Buffer info for the posted buffer */
James Smart51ef4c22007-08-02 11:10:31 -0400348 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
James Smart78b2d852007-08-02 11:10:21 -0400349 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
350 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
James Smarta8adb832007-10-27 13:37:53 -0400351 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
James Smart78b2d852007-08-02 11:10:21 -0400352 len += snprintf(buf+len, size-len,
353 "Buf%d: %p %06x\n", i,
354 hbq_buf->dbuf.virt, hbq_buf->tag);
355 found = 1;
356 break;
357 }
358 i++;
359 }
360 if (!found) {
361 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
362 }
363skipit:
364 hbqe++;
365 if (len > LPFC_HBQINFO_SIZE - 54)
366 break;
367 }
368 spin_unlock_irq(&phba->hbalock);
369 return len;
370}
371
James Smartc95d6c62008-01-11 01:53:23 -0500372static int lpfc_debugfs_last_hba_slim_off;
373
James Smarte59058c2008-08-24 21:49:00 -0400374/**
James Smart3621a712009-04-06 18:47:14 -0400375 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400376 * @phba: The HBA to gather SLIM info from.
377 * @buf: The buffer to dump log into.
378 * @size: The maximum amount of data to process.
379 *
380 * Description:
381 * This routine dumps the current contents of HBA SLIM for the HBA associated
382 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
383 *
384 * Notes:
385 * This routine will only dump up to 1024 bytes of data each time called and
386 * should be called multiple times to dump the entire HBA SLIM.
387 *
388 * Return Value:
389 * This routine returns the amount of bytes that were dumped into @buf and will
390 * not exceed @size.
391 **/
James Smarta58cbd52007-08-02 11:09:43 -0400392static int
James Smartc95d6c62008-01-11 01:53:23 -0500393lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
James Smarta58cbd52007-08-02 11:09:43 -0400394{
395 int len = 0;
James Smartc95d6c62008-01-11 01:53:23 -0500396 int i, off;
397 uint32_t *ptr;
398 char buffer[1024];
399
400 off = 0;
401 spin_lock_irq(&phba->hbalock);
402
403 len += snprintf(buf+len, size-len, "HBA SLIM\n");
404 lpfc_memcpy_from_slim(buffer,
James Smarta257bf92009-04-06 18:48:10 -0400405 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
James Smartc95d6c62008-01-11 01:53:23 -0500406
407 ptr = (uint32_t *)&buffer[0];
408 off = lpfc_debugfs_last_hba_slim_off;
409
410 /* Set it up for the next time */
411 lpfc_debugfs_last_hba_slim_off += 1024;
412 if (lpfc_debugfs_last_hba_slim_off >= 4096)
413 lpfc_debugfs_last_hba_slim_off = 0;
414
415 i = 1024;
416 while (i > 0) {
417 len += snprintf(buf+len, size-len,
418 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
419 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
420 *(ptr+5), *(ptr+6), *(ptr+7));
421 ptr += 8;
422 i -= (8 * sizeof(uint32_t));
423 off += (8 * sizeof(uint32_t));
424 }
425
426 spin_unlock_irq(&phba->hbalock);
427 return len;
428}
429
James Smarte59058c2008-08-24 21:49:00 -0400430/**
James Smart3621a712009-04-06 18:47:14 -0400431 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400432 * @phba: The HBA to gather Host SLIM info from.
433 * @buf: The buffer to dump log into.
434 * @size: The maximum amount of data to process.
435 *
436 * Description:
437 * This routine dumps the current contents of host SLIM for the host associated
438 * with @phba to @buf up to @size bytes of data. The dump will contain the
439 * Mailbox, PCB, Rings, and Registers that are located in host memory.
440 *
441 * Return Value:
442 * This routine returns the amount of bytes that were dumped into @buf and will
443 * not exceed @size.
444 **/
James Smartc95d6c62008-01-11 01:53:23 -0500445static int
446lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
447{
448 int len = 0;
449 int i, off;
James Smarta58cbd52007-08-02 11:09:43 -0400450 uint32_t word0, word1, word2, word3;
451 uint32_t *ptr;
452 struct lpfc_pgp *pgpp;
453 struct lpfc_sli *psli = &phba->sli;
454 struct lpfc_sli_ring *pring;
455
James Smarta58cbd52007-08-02 11:09:43 -0400456 off = 0;
457 spin_lock_irq(&phba->hbalock);
458
459 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
James Smart34b02dc2008-08-24 21:49:55 -0400460 ptr = (uint32_t *)phba->slim2p.virt;
James Smarta58cbd52007-08-02 11:09:43 -0400461 i = sizeof(MAILBOX_t);
462 while (i > 0) {
463 len += snprintf(buf+len, size-len,
464 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
465 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
466 *(ptr+5), *(ptr+6), *(ptr+7));
467 ptr += 8;
468 i -= (8 * sizeof(uint32_t));
469 off += (8 * sizeof(uint32_t));
470 }
471
472 len += snprintf(buf+len, size-len, "SLIM PCB\n");
James Smart34b02dc2008-08-24 21:49:55 -0400473 ptr = (uint32_t *)phba->pcb;
James Smarta58cbd52007-08-02 11:09:43 -0400474 i = sizeof(PCB_t);
475 while (i > 0) {
476 len += snprintf(buf+len, size-len,
477 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
478 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
479 *(ptr+5), *(ptr+6), *(ptr+7));
480 ptr += 8;
481 i -= (8 * sizeof(uint32_t));
482 off += (8 * sizeof(uint32_t));
483 }
484
James Smart34b02dc2008-08-24 21:49:55 -0400485 for (i = 0; i < 4; i++) {
486 pgpp = &phba->port_gp[i];
487 pring = &psli->ring[i];
488 len += snprintf(buf+len, size-len,
489 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
490 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
491 i, pgpp->cmdGetInx, pring->numCiocb,
492 pring->next_cmdidx, pring->local_getidx,
493 pring->flag, pgpp->rspPutInx, pring->numRiocb);
494 }
James Smart3772a992009-05-22 14:50:54 -0400495
496 if (phba->sli_rev <= LPFC_SLI_REV3) {
497 word0 = readl(phba->HAregaddr);
498 word1 = readl(phba->CAregaddr);
499 word2 = readl(phba->HSregaddr);
500 word3 = readl(phba->HCregaddr);
501 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
502 "HC:%08x\n", word0, word1, word2, word3);
503 }
James Smarta58cbd52007-08-02 11:09:43 -0400504 spin_unlock_irq(&phba->hbalock);
505 return len;
506}
507
James Smarte59058c2008-08-24 21:49:00 -0400508/**
James Smart3621a712009-04-06 18:47:14 -0400509 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400510 * @vport: The vport to gather target node info from.
511 * @buf: The buffer to dump log into.
512 * @size: The maximum amount of data to process.
513 *
514 * Description:
515 * This routine dumps the current target node list associated with @vport to
516 * @buf up to @size bytes of data. Each node entry in the dump will contain a
517 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
518 *
519 * Return Value:
520 * This routine returns the amount of bytes that were dumped into @buf and will
521 * not exceed @size.
522 **/
James Smarta58cbd52007-08-02 11:09:43 -0400523static int
James Smart858c9f62007-06-17 19:56:39 -0500524lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
525{
526 int len = 0;
527 int cnt;
528 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
529 struct lpfc_nodelist *ndlp;
530 unsigned char *statep, *name;
531
532 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
533
534 spin_lock_irq(shost->host_lock);
535 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
536 if (!cnt) {
537 len += snprintf(buf+len, size-len,
538 "Missing Nodelist Entries\n");
539 break;
540 }
541 cnt--;
542 switch (ndlp->nlp_state) {
543 case NLP_STE_UNUSED_NODE:
544 statep = "UNUSED";
545 break;
546 case NLP_STE_PLOGI_ISSUE:
547 statep = "PLOGI ";
548 break;
549 case NLP_STE_ADISC_ISSUE:
550 statep = "ADISC ";
551 break;
552 case NLP_STE_REG_LOGIN_ISSUE:
553 statep = "REGLOG";
554 break;
555 case NLP_STE_PRLI_ISSUE:
556 statep = "PRLI ";
557 break;
558 case NLP_STE_UNMAPPED_NODE:
559 statep = "UNMAP ";
560 break;
561 case NLP_STE_MAPPED_NODE:
562 statep = "MAPPED";
563 break;
564 case NLP_STE_NPR_NODE:
565 statep = "NPR ";
566 break;
567 default:
568 statep = "UNKNOWN";
569 }
570 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
571 statep, ndlp->nlp_DID);
572 name = (unsigned char *)&ndlp->nlp_portname;
573 len += snprintf(buf+len, size-len,
574 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
575 *name, *(name+1), *(name+2), *(name+3),
576 *(name+4), *(name+5), *(name+6), *(name+7));
577 name = (unsigned char *)&ndlp->nlp_nodename;
578 len += snprintf(buf+len, size-len,
579 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
580 *name, *(name+1), *(name+2), *(name+3),
581 *(name+4), *(name+5), *(name+6), *(name+7));
582 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
583 ndlp->nlp_rpi, ndlp->nlp_flag);
584 if (!ndlp->nlp_type)
James Smarta58cbd52007-08-02 11:09:43 -0400585 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500586 if (ndlp->nlp_type & NLP_FC_NODE)
587 len += snprintf(buf+len, size-len, "FC_NODE ");
588 if (ndlp->nlp_type & NLP_FABRIC)
589 len += snprintf(buf+len, size-len, "FABRIC ");
590 if (ndlp->nlp_type & NLP_FCP_TARGET)
591 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
592 ndlp->nlp_sid);
593 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
James Smarta58cbd52007-08-02 11:09:43 -0400594 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart58da1ff2008-04-07 10:15:56 -0400595 len += snprintf(buf+len, size-len, "usgmap:%x ",
596 ndlp->nlp_usg_map);
James Smarta58cbd52007-08-02 11:09:43 -0400597 len += snprintf(buf+len, size-len, "refcnt:%x",
598 atomic_read(&ndlp->kref.refcount));
James Smart858c9f62007-06-17 19:56:39 -0500599 len += snprintf(buf+len, size-len, "\n");
600 }
601 spin_unlock_irq(shost->host_lock);
602 return len;
603}
604#endif
605
James Smarte59058c2008-08-24 21:49:00 -0400606/**
James Smart3621a712009-04-06 18:47:14 -0400607 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400608 * @vport: The vport to associate this trace string with for retrieval.
609 * @mask: Log entry classification.
610 * @fmt: Format string to be displayed when dumping the log.
611 * @data1: 1st data parameter to be applied to @fmt.
612 * @data2: 2nd data parameter to be applied to @fmt.
613 * @data3: 3rd data parameter to be applied to @fmt.
614 *
615 * Description:
616 * This routine is used by the driver code to add a debugfs log entry to the
617 * discovery trace buffer associated with @vport. Only entries with a @mask that
618 * match the current debugfs discovery mask will be saved. Entries that do not
619 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
620 * printf when displaying the log.
621 **/
James Smart858c9f62007-06-17 19:56:39 -0500622inline void
623lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
624 uint32_t data1, uint32_t data2, uint32_t data3)
625{
James Smart923e4b62008-12-04 22:40:07 -0500626#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400627 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -0500628 int index;
629
630 if (!(lpfc_debugfs_mask_disc_trc & mask))
631 return;
632
633 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
634 !vport || !vport->disc_trc)
635 return;
636
637 index = atomic_inc_return(&vport->disc_trc_cnt) &
638 (lpfc_debugfs_max_disc_trc - 1);
639 dtp = vport->disc_trc + index;
640 dtp->fmt = fmt;
641 dtp->data1 = data1;
642 dtp->data2 = data2;
643 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -0400644 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
645 dtp->jif = jiffies;
646#endif
647 return;
648}
649
James Smarte59058c2008-08-24 21:49:00 -0400650/**
James Smart3621a712009-04-06 18:47:14 -0400651 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400652 * @phba: The phba to associate this trace string with for retrieval.
653 * @fmt: Format string to be displayed when dumping the log.
654 * @data1: 1st data parameter to be applied to @fmt.
655 * @data2: 2nd data parameter to be applied to @fmt.
656 * @data3: 3rd data parameter to be applied to @fmt.
657 *
658 * Description:
659 * This routine is used by the driver code to add a debugfs log entry to the
660 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
661 * @data3 are used like printf when displaying the log.
662 **/
James Smarta58cbd52007-08-02 11:09:43 -0400663inline void
664lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
665 uint32_t data1, uint32_t data2, uint32_t data3)
666{
James Smart923e4b62008-12-04 22:40:07 -0500667#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400668 struct lpfc_debugfs_trc *dtp;
669 int index;
670
671 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
672 !phba || !phba->slow_ring_trc)
673 return;
674
675 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
676 (lpfc_debugfs_max_slow_ring_trc - 1);
677 dtp = phba->slow_ring_trc + index;
678 dtp->fmt = fmt;
679 dtp->data1 = data1;
680 dtp->data2 = data2;
681 dtp->data3 = data3;
682 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500683 dtp->jif = jiffies;
684#endif
685 return;
686}
687
James Smart923e4b62008-12-04 22:40:07 -0500688#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -0400689/**
James Smart3621a712009-04-06 18:47:14 -0400690 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400691 * @inode: The inode pointer that contains a vport pointer.
692 * @file: The file pointer to attach the log output.
693 *
694 * Description:
695 * This routine is the entry point for the debugfs open file operation. It gets
696 * the vport from the i_private field in @inode, allocates the necessary buffer
697 * for the log, fills the buffer from the in-memory log for this vport, and then
698 * returns a pointer to that log in the private_data field in @file.
699 *
700 * Returns:
701 * This function returns zero if successful. On error it will return an negative
702 * error value.
703 **/
James Smart858c9f62007-06-17 19:56:39 -0500704static int
705lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
706{
707 struct lpfc_vport *vport = inode->i_private;
708 struct lpfc_debug *debug;
709 int size;
710 int rc = -ENOMEM;
711
712 if (!lpfc_debugfs_max_disc_trc) {
713 rc = -ENOSPC;
714 goto out;
715 }
716
717 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
718 if (!debug)
719 goto out;
720
James Smarte59058c2008-08-24 21:49:00 -0400721 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400722 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -0500723 size = PAGE_ALIGN(size);
724
725 debug->buffer = kmalloc(size, GFP_KERNEL);
726 if (!debug->buffer) {
727 kfree(debug);
728 goto out;
729 }
730
731 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
732 file->private_data = debug;
733
734 rc = 0;
735out:
736 return rc;
737}
738
James Smarte59058c2008-08-24 21:49:00 -0400739/**
James Smart3621a712009-04-06 18:47:14 -0400740 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400741 * @inode: The inode pointer that contains a vport pointer.
742 * @file: The file pointer to attach the log output.
743 *
744 * Description:
745 * This routine is the entry point for the debugfs open file operation. It gets
746 * the vport from the i_private field in @inode, allocates the necessary buffer
747 * for the log, fills the buffer from the in-memory log for this vport, and then
748 * returns a pointer to that log in the private_data field in @file.
749 *
750 * Returns:
751 * This function returns zero if successful. On error it will return an negative
752 * error value.
753 **/
James Smart858c9f62007-06-17 19:56:39 -0500754static int
James Smarta58cbd52007-08-02 11:09:43 -0400755lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
756{
757 struct lpfc_hba *phba = inode->i_private;
758 struct lpfc_debug *debug;
759 int size;
760 int rc = -ENOMEM;
761
762 if (!lpfc_debugfs_max_slow_ring_trc) {
763 rc = -ENOSPC;
764 goto out;
765 }
766
767 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
768 if (!debug)
769 goto out;
770
James Smarte59058c2008-08-24 21:49:00 -0400771 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400772 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
773 size = PAGE_ALIGN(size);
774
775 debug->buffer = kmalloc(size, GFP_KERNEL);
776 if (!debug->buffer) {
777 kfree(debug);
778 goto out;
779 }
780
781 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
782 file->private_data = debug;
783
784 rc = 0;
785out:
786 return rc;
787}
788
James Smarte59058c2008-08-24 21:49:00 -0400789/**
James Smart3621a712009-04-06 18:47:14 -0400790 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400791 * @inode: The inode pointer that contains a vport pointer.
792 * @file: The file pointer to attach the log output.
793 *
794 * Description:
795 * This routine is the entry point for the debugfs open file operation. It gets
796 * the vport from the i_private field in @inode, allocates the necessary buffer
797 * for the log, fills the buffer from the in-memory log for this vport, and then
798 * returns a pointer to that log in the private_data field in @file.
799 *
800 * Returns:
801 * This function returns zero if successful. On error it will return an negative
802 * error value.
803 **/
James Smarta58cbd52007-08-02 11:09:43 -0400804static int
James Smart78b2d852007-08-02 11:10:21 -0400805lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
806{
807 struct lpfc_hba *phba = inode->i_private;
808 struct lpfc_debug *debug;
809 int rc = -ENOMEM;
810
811 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
812 if (!debug)
813 goto out;
814
James Smarte59058c2008-08-24 21:49:00 -0400815 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -0400816 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
817 if (!debug->buffer) {
818 kfree(debug);
819 goto out;
820 }
821
822 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
823 LPFC_HBQINFO_SIZE);
824 file->private_data = debug;
825
826 rc = 0;
827out:
828 return rc;
829}
830
James Smarte59058c2008-08-24 21:49:00 -0400831/**
James Smart3621a712009-04-06 18:47:14 -0400832 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400833 * @inode: The inode pointer that contains a vport pointer.
834 * @file: The file pointer to attach the log output.
835 *
836 * Description:
837 * This routine is the entry point for the debugfs open file operation. It gets
838 * the vport from the i_private field in @inode, allocates the necessary buffer
839 * for the log, fills the buffer from the in-memory log for this vport, and then
840 * returns a pointer to that log in the private_data field in @file.
841 *
842 * Returns:
843 * This function returns zero if successful. On error it will return an negative
844 * error value.
845 **/
James Smart78b2d852007-08-02 11:10:21 -0400846static int
James Smartc95d6c62008-01-11 01:53:23 -0500847lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -0400848{
849 struct lpfc_hba *phba = inode->i_private;
850 struct lpfc_debug *debug;
851 int rc = -ENOMEM;
852
853 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
854 if (!debug)
855 goto out;
856
James Smarte59058c2008-08-24 21:49:00 -0400857 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500858 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -0400859 if (!debug->buffer) {
860 kfree(debug);
861 goto out;
862 }
863
James Smartc95d6c62008-01-11 01:53:23 -0500864 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
865 LPFC_DUMPHBASLIM_SIZE);
866 file->private_data = debug;
867
868 rc = 0;
869out:
870 return rc;
871}
872
James Smarte59058c2008-08-24 21:49:00 -0400873/**
James Smart3621a712009-04-06 18:47:14 -0400874 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400875 * @inode: The inode pointer that contains a vport pointer.
876 * @file: The file pointer to attach the log output.
877 *
878 * Description:
879 * This routine is the entry point for the debugfs open file operation. It gets
880 * the vport from the i_private field in @inode, allocates the necessary buffer
881 * for the log, fills the buffer from the in-memory log for this vport, and then
882 * returns a pointer to that log in the private_data field in @file.
883 *
884 * Returns:
885 * This function returns zero if successful. On error it will return an negative
886 * error value.
887 **/
James Smartc95d6c62008-01-11 01:53:23 -0500888static int
889lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
890{
891 struct lpfc_hba *phba = inode->i_private;
892 struct lpfc_debug *debug;
893 int rc = -ENOMEM;
894
895 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
896 if (!debug)
897 goto out;
898
James Smarte59058c2008-08-24 21:49:00 -0400899 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500900 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
901 if (!debug->buffer) {
902 kfree(debug);
903 goto out;
904 }
905
906 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
907 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -0400908 file->private_data = debug;
909
910 rc = 0;
911out:
912 return rc;
913}
914
James Smarte2a0a9d2008-12-04 22:40:02 -0500915static int
916lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
917{
918 struct lpfc_debug *debug;
919 int rc = -ENOMEM;
920
921 if (!_dump_buf_data)
922 return -EBUSY;
923
924 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
925 if (!debug)
926 goto out;
927
928 /* Round to page boundry */
James Smart6a9c52c2009-10-02 15:16:51 -0400929 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
James Smarte2a0a9d2008-12-04 22:40:02 -0500930 __func__, _dump_buf_data);
931 debug->buffer = _dump_buf_data;
932 if (!debug->buffer) {
933 kfree(debug);
934 goto out;
935 }
936
937 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
938 file->private_data = debug;
939
940 rc = 0;
941out:
942 return rc;
943}
944
945static int
946lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
947{
948 struct lpfc_debug *debug;
949 int rc = -ENOMEM;
950
951 if (!_dump_buf_dif)
952 return -EBUSY;
953
954 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
955 if (!debug)
956 goto out;
957
958 /* Round to page boundry */
James Smart6a9c52c2009-10-02 15:16:51 -0400959 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
960 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
James Smarte2a0a9d2008-12-04 22:40:02 -0500961 debug->buffer = _dump_buf_dif;
962 if (!debug->buffer) {
963 kfree(debug);
964 goto out;
965 }
966
967 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
968 file->private_data = debug;
969
970 rc = 0;
971out:
972 return rc;
973}
974
975static ssize_t
976lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
977 size_t nbytes, loff_t *ppos)
978{
979 /*
980 * The Data/DIF buffers only save one failing IO
981 * The write op is used as a reset mechanism after an IO has
982 * already been saved to the next one can be saved
983 */
984 spin_lock(&_dump_buf_lock);
985
986 memset((void *)_dump_buf_data, 0,
987 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
988 memset((void *)_dump_buf_dif, 0,
989 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
990
991 _dump_buf_done = 0;
992
993 spin_unlock(&_dump_buf_lock);
994
995 return nbytes;
996}
997
998
999
James Smarte59058c2008-08-24 21:49:00 -04001000/**
James Smart3621a712009-04-06 18:47:14 -04001001 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001002 * @inode: The inode pointer that contains a vport pointer.
1003 * @file: The file pointer to attach the log output.
1004 *
1005 * Description:
1006 * This routine is the entry point for the debugfs open file operation. It gets
1007 * the vport from the i_private field in @inode, allocates the necessary buffer
1008 * for the log, fills the buffer from the in-memory log for this vport, and then
1009 * returns a pointer to that log in the private_data field in @file.
1010 *
1011 * Returns:
1012 * This function returns zero if successful. On error it will return an negative
1013 * error value.
1014 **/
James Smarta58cbd52007-08-02 11:09:43 -04001015static int
James Smart858c9f62007-06-17 19:56:39 -05001016lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1017{
1018 struct lpfc_vport *vport = inode->i_private;
1019 struct lpfc_debug *debug;
1020 int rc = -ENOMEM;
1021
1022 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1023 if (!debug)
1024 goto out;
1025
James Smarte59058c2008-08-24 21:49:00 -04001026 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05001027 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1028 if (!debug->buffer) {
1029 kfree(debug);
1030 goto out;
1031 }
1032
1033 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1034 LPFC_NODELIST_SIZE);
1035 file->private_data = debug;
1036
1037 rc = 0;
1038out:
1039 return rc;
1040}
1041
James Smarte59058c2008-08-24 21:49:00 -04001042/**
James Smart3621a712009-04-06 18:47:14 -04001043 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001044 * @file: The file pointer to seek through.
1045 * @off: The offset to seek to or the amount to seek by.
1046 * @whence: Indicates how to seek.
1047 *
1048 * Description:
1049 * This routine is the entry point for the debugfs lseek file operation. The
1050 * @whence parameter indicates whether @off is the offset to directly seek to,
1051 * or if it is a value to seek forward or reverse by. This function figures out
1052 * what the new offset of the debugfs file will be and assigns that value to the
1053 * f_pos field of @file.
1054 *
1055 * Returns:
1056 * This function returns the new offset if successful and returns a negative
1057 * error if unable to process the seek.
1058 **/
James Smart858c9f62007-06-17 19:56:39 -05001059static loff_t
1060lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1061{
1062 struct lpfc_debug *debug;
1063 loff_t pos = -1;
1064
1065 debug = file->private_data;
1066
1067 switch (whence) {
1068 case 0:
1069 pos = off;
1070 break;
1071 case 1:
1072 pos = file->f_pos + off;
1073 break;
1074 case 2:
1075 pos = debug->len - off;
1076 }
1077 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1078}
1079
James Smarte59058c2008-08-24 21:49:00 -04001080/**
James Smart3621a712009-04-06 18:47:14 -04001081 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001082 * @file: The file pointer to read from.
1083 * @buf: The buffer to copy the data to.
1084 * @nbytes: The number of bytes to read.
1085 * @ppos: The position in the file to start reading from.
1086 *
1087 * Description:
1088 * This routine reads data from from the buffer indicated in the private_data
1089 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1090 * data to @buf.
1091 *
1092 * Returns:
1093 * This function returns the amount of data that was read (this could be less
1094 * than @nbytes if the end of the file was reached) or a negative error value.
1095 **/
James Smart858c9f62007-06-17 19:56:39 -05001096static ssize_t
1097lpfc_debugfs_read(struct file *file, char __user *buf,
1098 size_t nbytes, loff_t *ppos)
1099{
1100 struct lpfc_debug *debug = file->private_data;
1101 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1102 debug->len);
1103}
1104
James Smarte59058c2008-08-24 21:49:00 -04001105/**
James Smart3621a712009-04-06 18:47:14 -04001106 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04001107 * @inode: The inode pointer that contains a vport pointer. (unused)
1108 * @file: The file pointer that contains the buffer to release.
1109 *
1110 * Description:
1111 * This routine frees the buffer that was allocated when the debugfs file was
1112 * opened.
1113 *
1114 * Returns:
1115 * This function returns zero.
1116 **/
James Smart858c9f62007-06-17 19:56:39 -05001117static int
1118lpfc_debugfs_release(struct inode *inode, struct file *file)
1119{
1120 struct lpfc_debug *debug = file->private_data;
1121
1122 kfree(debug->buffer);
1123 kfree(debug);
1124
1125 return 0;
1126}
1127
James Smarte2a0a9d2008-12-04 22:40:02 -05001128static int
1129lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1130{
1131 struct lpfc_debug *debug = file->private_data;
1132
1133 debug->buffer = NULL;
1134 kfree(debug);
1135
1136 return 0;
1137}
1138
James Smart858c9f62007-06-17 19:56:39 -05001139#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001140static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05001141 .owner = THIS_MODULE,
1142 .open = lpfc_debugfs_disc_trc_open,
1143 .llseek = lpfc_debugfs_lseek,
1144 .read = lpfc_debugfs_read,
1145 .release = lpfc_debugfs_release,
1146};
1147
1148#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001149static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05001150 .owner = THIS_MODULE,
1151 .open = lpfc_debugfs_nodelist_open,
1152 .llseek = lpfc_debugfs_lseek,
1153 .read = lpfc_debugfs_read,
1154 .release = lpfc_debugfs_release,
1155};
1156
James Smart78b2d852007-08-02 11:10:21 -04001157#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001158static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04001159 .owner = THIS_MODULE,
1160 .open = lpfc_debugfs_hbqinfo_open,
1161 .llseek = lpfc_debugfs_lseek,
1162 .read = lpfc_debugfs_read,
1163 .release = lpfc_debugfs_release,
1164};
1165
James Smartc95d6c62008-01-11 01:53:23 -05001166#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001167static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04001168 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05001169 .open = lpfc_debugfs_dumpHBASlim_open,
1170 .llseek = lpfc_debugfs_lseek,
1171 .read = lpfc_debugfs_read,
1172 .release = lpfc_debugfs_release,
1173};
1174
1175#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001176static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05001177 .owner = THIS_MODULE,
1178 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04001179 .llseek = lpfc_debugfs_lseek,
1180 .read = lpfc_debugfs_read,
1181 .release = lpfc_debugfs_release,
1182};
1183
James Smarte2a0a9d2008-12-04 22:40:02 -05001184#undef lpfc_debugfs_op_dumpData
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001185static const struct file_operations lpfc_debugfs_op_dumpData = {
James Smarte2a0a9d2008-12-04 22:40:02 -05001186 .owner = THIS_MODULE,
1187 .open = lpfc_debugfs_dumpData_open,
1188 .llseek = lpfc_debugfs_lseek,
1189 .read = lpfc_debugfs_read,
1190 .write = lpfc_debugfs_dumpDataDif_write,
1191 .release = lpfc_debugfs_dumpDataDif_release,
1192};
1193
1194#undef lpfc_debugfs_op_dumpDif
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001195static const struct file_operations lpfc_debugfs_op_dumpDif = {
James Smarte2a0a9d2008-12-04 22:40:02 -05001196 .owner = THIS_MODULE,
1197 .open = lpfc_debugfs_dumpDif_open,
1198 .llseek = lpfc_debugfs_lseek,
1199 .read = lpfc_debugfs_read,
1200 .write = lpfc_debugfs_dumpDataDif_write,
1201 .release = lpfc_debugfs_dumpDataDif_release,
1202};
1203
James Smarta58cbd52007-08-02 11:09:43 -04001204#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001205static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04001206 .owner = THIS_MODULE,
1207 .open = lpfc_debugfs_slow_ring_trc_open,
1208 .llseek = lpfc_debugfs_lseek,
1209 .read = lpfc_debugfs_read,
1210 .release = lpfc_debugfs_release,
1211};
1212
James Smart858c9f62007-06-17 19:56:39 -05001213static struct dentry *lpfc_debugfs_root = NULL;
1214static atomic_t lpfc_debugfs_hba_count;
1215#endif
1216
James Smarte59058c2008-08-24 21:49:00 -04001217/**
James Smart3621a712009-04-06 18:47:14 -04001218 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04001219 * @vport: The vport pointer to initialize.
1220 *
1221 * Description:
1222 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
1223 * If not already created, this routine will create the lpfc directory, and
1224 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
1225 * also create each file used to access lpfc specific debugfs information.
1226 **/
James Smart858c9f62007-06-17 19:56:39 -05001227inline void
1228lpfc_debugfs_initialize(struct lpfc_vport *vport)
1229{
James Smart923e4b62008-12-04 22:40:07 -05001230#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05001231 struct lpfc_hba *phba = vport->phba;
1232 char name[64];
1233 uint32_t num, i;
1234
1235 if (!lpfc_debugfs_enable)
1236 return;
1237
James Smarta58cbd52007-08-02 11:09:43 -04001238 /* Setup lpfc root directory */
1239 if (!lpfc_debugfs_root) {
1240 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
1241 atomic_set(&lpfc_debugfs_hba_count, 0);
1242 if (!lpfc_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04001243 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001244 "0408 Cannot create debugfs root\n");
James Smarta58cbd52007-08-02 11:09:43 -04001245 goto debug_failed;
1246 }
1247 }
James Smarta58cbd52007-08-02 11:09:43 -04001248 if (!lpfc_debugfs_start_time)
1249 lpfc_debugfs_start_time = jiffies;
1250
1251 /* Setup lpfcX directory for specific HBA */
1252 snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
1253 if (!phba->hba_debugfs_root) {
1254 phba->hba_debugfs_root =
1255 debugfs_create_dir(name, lpfc_debugfs_root);
1256 if (!phba->hba_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04001257 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001258 "0412 Cannot create debugfs hba\n");
James Smarta58cbd52007-08-02 11:09:43 -04001259 goto debug_failed;
1260 }
1261 atomic_inc(&lpfc_debugfs_hba_count);
1262 atomic_set(&phba->debugfs_vport_count, 0);
1263
James Smart78b2d852007-08-02 11:10:21 -04001264 /* Setup hbqinfo */
1265 snprintf(name, sizeof(name), "hbqinfo");
1266 phba->debug_hbqinfo =
1267 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1268 phba->hba_debugfs_root,
1269 phba, &lpfc_debugfs_op_hbqinfo);
1270 if (!phba->debug_hbqinfo) {
1271 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001272 "0411 Cannot create debugfs hbqinfo\n");
James Smart78b2d852007-08-02 11:10:21 -04001273 goto debug_failed;
1274 }
1275
James Smartc95d6c62008-01-11 01:53:23 -05001276 /* Setup dumpHBASlim */
1277 snprintf(name, sizeof(name), "dumpHBASlim");
1278 phba->debug_dumpHBASlim =
James Smarta58cbd52007-08-02 11:09:43 -04001279 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1280 phba->hba_debugfs_root,
James Smartc95d6c62008-01-11 01:53:23 -05001281 phba, &lpfc_debugfs_op_dumpHBASlim);
1282 if (!phba->debug_dumpHBASlim) {
James Smarte8b62012007-08-02 11:10:09 -04001283 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001284 "0413 Cannot create debugfs dumpHBASlim\n");
James Smartc95d6c62008-01-11 01:53:23 -05001285 goto debug_failed;
1286 }
1287
1288 /* Setup dumpHostSlim */
1289 snprintf(name, sizeof(name), "dumpHostSlim");
1290 phba->debug_dumpHostSlim =
1291 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1292 phba->hba_debugfs_root,
1293 phba, &lpfc_debugfs_op_dumpHostSlim);
1294 if (!phba->debug_dumpHostSlim) {
1295 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001296 "0414 Cannot create debugfs dumpHostSlim\n");
James Smarta58cbd52007-08-02 11:09:43 -04001297 goto debug_failed;
1298 }
1299
James Smarte2a0a9d2008-12-04 22:40:02 -05001300 /* Setup dumpData */
1301 snprintf(name, sizeof(name), "dumpData");
1302 phba->debug_dumpData =
1303 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1304 phba->hba_debugfs_root,
1305 phba, &lpfc_debugfs_op_dumpData);
1306 if (!phba->debug_dumpData) {
1307 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1308 "0800 Cannot create debugfs dumpData\n");
1309 goto debug_failed;
1310 }
1311
1312 /* Setup dumpDif */
1313 snprintf(name, sizeof(name), "dumpDif");
1314 phba->debug_dumpDif =
1315 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1316 phba->hba_debugfs_root,
1317 phba, &lpfc_debugfs_op_dumpDif);
1318 if (!phba->debug_dumpDif) {
1319 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1320 "0801 Cannot create debugfs dumpDif\n");
1321 goto debug_failed;
1322 }
1323
1324
1325
James Smarta58cbd52007-08-02 11:09:43 -04001326 /* Setup slow ring trace */
1327 if (lpfc_debugfs_max_slow_ring_trc) {
1328 num = lpfc_debugfs_max_slow_ring_trc - 1;
1329 if (num & lpfc_debugfs_max_slow_ring_trc) {
1330 /* Change to be a power of 2 */
1331 num = lpfc_debugfs_max_slow_ring_trc;
1332 i = 0;
1333 while (num > 1) {
1334 num = num >> 1;
1335 i++;
1336 }
1337 lpfc_debugfs_max_slow_ring_trc = (1 << i);
1338 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04001339 "lpfc_debugfs_max_disc_trc changed to "
1340 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04001341 }
1342 }
1343
1344
1345 snprintf(name, sizeof(name), "slow_ring_trace");
1346 phba->debug_slow_ring_trc =
1347 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1348 phba->hba_debugfs_root,
1349 phba, &lpfc_debugfs_op_slow_ring_trc);
1350 if (!phba->debug_slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001351 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001352 "0415 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04001353 "slow_ring_trace\n");
James Smarta58cbd52007-08-02 11:09:43 -04001354 goto debug_failed;
1355 }
1356 if (!phba->slow_ring_trc) {
1357 phba->slow_ring_trc = kmalloc(
1358 (sizeof(struct lpfc_debugfs_trc) *
1359 lpfc_debugfs_max_slow_ring_trc),
1360 GFP_KERNEL);
1361 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001362 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001363 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04001364 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04001365 goto debug_failed;
1366 }
1367 atomic_set(&phba->slow_ring_trc_cnt, 0);
1368 memset(phba->slow_ring_trc, 0,
1369 (sizeof(struct lpfc_debugfs_trc) *
1370 lpfc_debugfs_max_slow_ring_trc));
1371 }
1372 }
1373
1374 snprintf(name, sizeof(name), "vport%d", vport->vpi);
1375 if (!vport->vport_debugfs_root) {
1376 vport->vport_debugfs_root =
1377 debugfs_create_dir(name, phba->hba_debugfs_root);
1378 if (!vport->vport_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04001379 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6a9c52c2009-10-02 15:16:51 -04001380 "0417 Cant create debugfs\n");
James Smarta58cbd52007-08-02 11:09:43 -04001381 goto debug_failed;
1382 }
1383 atomic_inc(&phba->debugfs_vport_count);
1384 }
1385
James Smart858c9f62007-06-17 19:56:39 -05001386 if (lpfc_debugfs_max_disc_trc) {
1387 num = lpfc_debugfs_max_disc_trc - 1;
1388 if (num & lpfc_debugfs_max_disc_trc) {
1389 /* Change to be a power of 2 */
1390 num = lpfc_debugfs_max_disc_trc;
1391 i = 0;
1392 while (num > 1) {
1393 num = num >> 1;
1394 i++;
1395 }
1396 lpfc_debugfs_max_disc_trc = (1 << i);
1397 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04001398 "lpfc_debugfs_max_disc_trc changed to %d\n",
1399 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05001400 }
1401 }
1402
Adrian Bunkff86ba52007-10-18 12:52:37 +02001403 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04001404 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05001405 GFP_KERNEL);
1406
James Smarta58cbd52007-08-02 11:09:43 -04001407 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001408 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001409 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04001410 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05001411 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04001412 }
1413 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05001414
1415 snprintf(name, sizeof(name), "discovery_trace");
1416 vport->debug_disc_trc =
1417 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1418 vport->vport_debugfs_root,
1419 vport, &lpfc_debugfs_op_disc_trc);
1420 if (!vport->debug_disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001421 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001422 "0419 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04001423 "discovery_trace\n");
James Smart858c9f62007-06-17 19:56:39 -05001424 goto debug_failed;
1425 }
1426 snprintf(name, sizeof(name), "nodelist");
1427 vport->debug_nodelist =
1428 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1429 vport->vport_debugfs_root,
1430 vport, &lpfc_debugfs_op_nodelist);
1431 if (!vport->debug_nodelist) {
James Smarte8b62012007-08-02 11:10:09 -04001432 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6a9c52c2009-10-02 15:16:51 -04001433 "0409 Cant create debugfs nodelist\n");
James Smart858c9f62007-06-17 19:56:39 -05001434 goto debug_failed;
1435 }
1436debug_failed:
1437 return;
1438#endif
1439}
1440
James Smarte59058c2008-08-24 21:49:00 -04001441/**
James Smart3621a712009-04-06 18:47:14 -04001442 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04001443 * @vport: The vport pointer to remove from debugfs.
1444 *
1445 * Description:
1446 * When Debugfs is configured this routine removes debugfs file system elements
1447 * that are specific to this vport. It also checks to see if there are any
1448 * users left for the debugfs directories associated with the HBA and driver. If
1449 * this is the last user of the HBA directory or driver directory then it will
1450 * remove those from the debugfs infrastructure as well.
1451 **/
James Smart858c9f62007-06-17 19:56:39 -05001452inline void
1453lpfc_debugfs_terminate(struct lpfc_vport *vport)
1454{
James Smart923e4b62008-12-04 22:40:07 -05001455#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05001456 struct lpfc_hba *phba = vport->phba;
1457
1458 if (vport->disc_trc) {
1459 kfree(vport->disc_trc);
1460 vport->disc_trc = NULL;
1461 }
1462 if (vport->debug_disc_trc) {
1463 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
1464 vport->debug_disc_trc = NULL;
1465 }
1466 if (vport->debug_nodelist) {
1467 debugfs_remove(vport->debug_nodelist); /* nodelist */
1468 vport->debug_nodelist = NULL;
1469 }
James Smarta58cbd52007-08-02 11:09:43 -04001470
James Smart858c9f62007-06-17 19:56:39 -05001471 if (vport->vport_debugfs_root) {
1472 debugfs_remove(vport->vport_debugfs_root); /* vportX */
1473 vport->vport_debugfs_root = NULL;
1474 atomic_dec(&phba->debugfs_vport_count);
1475 }
1476 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04001477
James Smart78b2d852007-08-02 11:10:21 -04001478 if (phba->debug_hbqinfo) {
1479 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
1480 phba->debug_hbqinfo = NULL;
1481 }
James Smartc95d6c62008-01-11 01:53:23 -05001482 if (phba->debug_dumpHBASlim) {
1483 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
1484 phba->debug_dumpHBASlim = NULL;
1485 }
1486 if (phba->debug_dumpHostSlim) {
1487 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
1488 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04001489 }
James Smarte2a0a9d2008-12-04 22:40:02 -05001490 if (phba->debug_dumpData) {
1491 debugfs_remove(phba->debug_dumpData); /* dumpData */
1492 phba->debug_dumpData = NULL;
1493 }
1494
1495 if (phba->debug_dumpDif) {
1496 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
1497 phba->debug_dumpDif = NULL;
1498 }
1499
James Smarta58cbd52007-08-02 11:09:43 -04001500 if (phba->slow_ring_trc) {
1501 kfree(phba->slow_ring_trc);
1502 phba->slow_ring_trc = NULL;
1503 }
1504 if (phba->debug_slow_ring_trc) {
1505 /* slow_ring_trace */
1506 debugfs_remove(phba->debug_slow_ring_trc);
1507 phba->debug_slow_ring_trc = NULL;
1508 }
1509
1510 if (phba->hba_debugfs_root) {
1511 debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
1512 phba->hba_debugfs_root = NULL;
1513 atomic_dec(&lpfc_debugfs_hba_count);
1514 }
1515
James Smart858c9f62007-06-17 19:56:39 -05001516 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
1517 debugfs_remove(lpfc_debugfs_root); /* lpfc */
1518 lpfc_debugfs_root = NULL;
1519 }
1520 }
1521#endif
James Smarta58cbd52007-08-02 11:09:43 -04001522 return;
James Smart858c9f62007-06-17 19:56:39 -05001523}