blob: 3c8c91a7609c6657c0c9ba592ab86a449eee9c96 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
James Smart858c9f62007-06-17 19:56:39 -050028#include <linux/pci.h>
29#include <linux/spinlock.h>
30#include <linux/ctype.h>
James Smart858c9f62007-06-17 19:56:39 -050031
32#include <scsi/scsi.h>
33#include <scsi/scsi_device.h>
34#include <scsi/scsi_host.h>
35#include <scsi/scsi_transport_fc.h>
36
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
James Smart858c9f62007-06-17 19:56:39 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
James Smart858c9f62007-06-17 19:56:39 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_crtn.h"
47#include "lpfc_vport.h"
48#include "lpfc_version.h"
James Smartc95d6c62008-01-11 01:53:23 -050049#include "lpfc_compat.h"
James Smart858c9f62007-06-17 19:56:39 -050050#include "lpfc_debugfs.h"
51
James Smart923e4b62008-12-04 22:40:07 -050052#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart3621a712009-04-06 18:47:14 -040053/*
James Smarte59058c2008-08-24 21:49:00 -040054 * debugfs interface
James Smart858c9f62007-06-17 19:56:39 -050055 *
56 * To access this interface the user should:
GeunSik Lim156f5a72009-06-02 15:01:37 +090057 * # mount -t debugfs none /sys/kernel/debug
James Smart858c9f62007-06-17 19:56:39 -050058 *
James Smarte59058c2008-08-24 21:49:00 -040059 * The lpfc debugfs directory hierarchy is:
James Smart858c9f62007-06-17 19:56:39 -050060 * lpfc/lpfcX/vportY
61 * where X is the lpfc hba unique_id
62 * where Y is the vport VPI on that hba
63 *
64 * Debugging services available per vport:
65 * discovery_trace
66 * This is an ACSII readable file that contains a trace of the last
67 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
James Smarte59058c2008-08-24 21:49:00 -040068 * See lpfc_debugfs.h for different categories of discovery events.
69 * To enable the discovery trace, the following module parameters must be set:
James Smart858c9f62007-06-17 19:56:39 -050070 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
71 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
72 * EACH vport. X MUST also be a power of 2.
73 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
74 * lpfc_debugfs.h .
James Smarte59058c2008-08-24 21:49:00 -040075 *
76 * slow_ring_trace
77 * This is an ACSII readable file that contains a trace of the last
78 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
79 * To enable the slow ring trace, the following module parameters must be set:
80 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
81 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
82 * the HBA. X MUST also be a power of 2.
James Smart858c9f62007-06-17 19:56:39 -050083 */
James Smart51ef4c22007-08-02 11:10:31 -040084static int lpfc_debugfs_enable = 1;
James Smartab56dc22011-02-16 12:39:57 -050085module_param(lpfc_debugfs_enable, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050086MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
87
James Smarta58cbd52007-08-02 11:09:43 -040088/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050089static int lpfc_debugfs_max_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -050090module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050091MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
92 "Set debugfs discovery trace depth");
93
James Smarta58cbd52007-08-02 11:09:43 -040094/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050095static int lpfc_debugfs_max_slow_ring_trc;
James Smartab56dc22011-02-16 12:39:57 -050096module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
James Smarta58cbd52007-08-02 11:09:43 -040097MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
98 "Set debugfs slow ring trace depth");
99
James Smarta257bf92009-04-06 18:48:10 -0400100static int lpfc_debugfs_mask_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -0500101module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -0500102MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
103 "Set debugfs discovery trace mask");
104
105#include <linux/debugfs.h>
106
James Smarta58cbd52007-08-02 11:09:43 -0400107/* size of output line, for discovery_trace and slow_ring_trace */
108#define LPFC_DEBUG_TRC_ENTRY_SIZE 100
James Smart858c9f62007-06-17 19:56:39 -0500109
110/* nodelist output buffer size */
111#define LPFC_NODELIST_SIZE 8192
112#define LPFC_NODELIST_ENTRY_SIZE 120
113
James Smartc95d6c62008-01-11 01:53:23 -0500114/* dumpHBASlim output buffer size */
115#define LPFC_DUMPHBASLIM_SIZE 4096
116
117/* dumpHostSlim output buffer size */
118#define LPFC_DUMPHOSTSLIM_SIZE 4096
James Smarta58cbd52007-08-02 11:09:43 -0400119
James Smart78b2d852007-08-02 11:10:21 -0400120/* hbqinfo output buffer size */
121#define LPFC_HBQINFO_SIZE 8192
122
James Smart858c9f62007-06-17 19:56:39 -0500123struct lpfc_debug {
124 char *buffer;
125 int len;
126};
127
James Smart311464e2007-08-02 11:10:37 -0400128static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
129static unsigned long lpfc_debugfs_start_time = 0L;
James Smart858c9f62007-06-17 19:56:39 -0500130
James Smarte59058c2008-08-24 21:49:00 -0400131/**
James Smart3621a712009-04-06 18:47:14 -0400132 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400133 * @vport: The vport to gather the log info from.
134 * @buf: The buffer to dump log into.
135 * @size: The maximum amount of data to process.
136 *
137 * Description:
138 * This routine gathers the lpfc discovery debugfs data from the @vport and
139 * dumps it to @buf up to @size number of bytes. It will start at the next entry
140 * in the log and process the log until the end of the buffer. Then it will
141 * gather from the beginning of the log and process until the current entry.
142 *
143 * Notes:
144 * Discovery logging will be disabled while while this routine dumps the log.
145 *
146 * Return Value:
147 * This routine returns the amount of bytes that were dumped into @buf and will
148 * not exceed @size.
149 **/
James Smart858c9f62007-06-17 19:56:39 -0500150static int
151lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
152{
153 int i, index, len, enable;
154 uint32_t ms;
James Smarta58cbd52007-08-02 11:09:43 -0400155 struct lpfc_debugfs_trc *dtp;
156 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
James Smart858c9f62007-06-17 19:56:39 -0500157
James Smart858c9f62007-06-17 19:56:39 -0500158 enable = lpfc_debugfs_enable;
159 lpfc_debugfs_enable = 0;
160
161 len = 0;
162 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
163 (lpfc_debugfs_max_disc_trc - 1);
164 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
165 dtp = vport->disc_trc + i;
166 if (!dtp->fmt)
167 continue;
168 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400169 snprintf(buffer,
170 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500171 dtp->seq_cnt, ms, dtp->fmt);
172 len += snprintf(buf+len, size-len, buffer,
173 dtp->data1, dtp->data2, dtp->data3);
174 }
175 for (i = 0; i < index; i++) {
176 dtp = vport->disc_trc + i;
177 if (!dtp->fmt)
178 continue;
179 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400180 snprintf(buffer,
181 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500182 dtp->seq_cnt, ms, dtp->fmt);
183 len += snprintf(buf+len, size-len, buffer,
184 dtp->data1, dtp->data2, dtp->data3);
185 }
186
187 lpfc_debugfs_enable = enable;
188 return len;
189}
190
James Smarte59058c2008-08-24 21:49:00 -0400191/**
James Smart3621a712009-04-06 18:47:14 -0400192 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400193 * @phba: The HBA to gather the log info from.
194 * @buf: The buffer to dump log into.
195 * @size: The maximum amount of data to process.
196 *
197 * Description:
198 * This routine gathers the lpfc slow ring debugfs data from the @phba and
199 * dumps it to @buf up to @size number of bytes. It will start at the next entry
200 * in the log and process the log until the end of the buffer. Then it will
201 * gather from the beginning of the log and process until the current entry.
202 *
203 * Notes:
204 * Slow ring logging will be disabled while while this routine dumps the log.
205 *
206 * Return Value:
207 * This routine returns the amount of bytes that were dumped into @buf and will
208 * not exceed @size.
209 **/
James Smart858c9f62007-06-17 19:56:39 -0500210static int
James Smarta58cbd52007-08-02 11:09:43 -0400211lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
212{
213 int i, index, len, enable;
214 uint32_t ms;
215 struct lpfc_debugfs_trc *dtp;
216 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
217
218
219 enable = lpfc_debugfs_enable;
220 lpfc_debugfs_enable = 0;
221
222 len = 0;
223 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
224 (lpfc_debugfs_max_slow_ring_trc - 1);
225 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
226 dtp = phba->slow_ring_trc + i;
227 if (!dtp->fmt)
228 continue;
229 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
230 snprintf(buffer,
231 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
232 dtp->seq_cnt, ms, dtp->fmt);
233 len += snprintf(buf+len, size-len, buffer,
234 dtp->data1, dtp->data2, dtp->data3);
235 }
236 for (i = 0; i < index; i++) {
237 dtp = phba->slow_ring_trc + i;
238 if (!dtp->fmt)
239 continue;
240 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
241 snprintf(buffer,
242 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
243 dtp->seq_cnt, ms, dtp->fmt);
244 len += snprintf(buf+len, size-len, buffer,
245 dtp->data1, dtp->data2, dtp->data3);
246 }
247
248 lpfc_debugfs_enable = enable;
249 return len;
250}
251
James Smart311464e2007-08-02 11:10:37 -0400252static int lpfc_debugfs_last_hbq = -1;
James Smart78b2d852007-08-02 11:10:21 -0400253
James Smarte59058c2008-08-24 21:49:00 -0400254/**
James Smart3621a712009-04-06 18:47:14 -0400255 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400256 * @phba: The HBA to gather host buffer info from.
257 * @buf: The buffer to dump log into.
258 * @size: The maximum amount of data to process.
259 *
260 * Description:
261 * This routine dumps the host buffer queue info from the @phba to @buf up to
262 * @size number of bytes. A header that describes the current hbq state will be
263 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
264 * until @size bytes have been dumped or all the hbq info has been dumped.
265 *
266 * Notes:
267 * This routine will rotate through each configured HBQ each time called.
268 *
269 * Return Value:
270 * This routine returns the amount of bytes that were dumped into @buf and will
271 * not exceed @size.
272 **/
James Smart78b2d852007-08-02 11:10:21 -0400273static int
274lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
275{
276 int len = 0;
277 int cnt, i, j, found, posted, low;
278 uint32_t phys, raw_index, getidx;
279 struct lpfc_hbq_init *hip;
280 struct hbq_s *hbqs;
281 struct lpfc_hbq_entry *hbqe;
282 struct lpfc_dmabuf *d_buf;
283 struct hbq_dmabuf *hbq_buf;
284
James Smart3772a992009-05-22 14:50:54 -0400285 if (phba->sli_rev != 3)
286 return 0;
James Smart78b2d852007-08-02 11:10:21 -0400287 cnt = LPFC_HBQINFO_SIZE;
288 spin_lock_irq(&phba->hbalock);
289
290 /* toggle between multiple hbqs, if any */
291 i = lpfc_sli_hbq_count();
292 if (i > 1) {
293 lpfc_debugfs_last_hbq++;
294 if (lpfc_debugfs_last_hbq >= i)
295 lpfc_debugfs_last_hbq = 0;
296 }
297 else
298 lpfc_debugfs_last_hbq = 0;
299
300 i = lpfc_debugfs_last_hbq;
301
302 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
303
James Smart51ef4c22007-08-02 11:10:31 -0400304 hbqs = &phba->hbqs[i];
James Smart78b2d852007-08-02 11:10:21 -0400305 posted = 0;
James Smart51ef4c22007-08-02 11:10:31 -0400306 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
James Smart78b2d852007-08-02 11:10:21 -0400307 posted++;
308
309 hip = lpfc_hbq_defs[i];
310 len += snprintf(buf+len, size-len,
311 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
312 hip->hbq_index, hip->profile, hip->rn,
313 hip->buffer_count, hip->init_count, hip->add_count, posted);
314
James Smart78b2d852007-08-02 11:10:21 -0400315 raw_index = phba->hbq_get[i];
316 getidx = le32_to_cpu(raw_index);
317 len += snprintf(buf+len, size-len,
James Smarta8adb832007-10-27 13:37:53 -0400318 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
319 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
320 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
James Smart78b2d852007-08-02 11:10:21 -0400321
James Smart51ef4c22007-08-02 11:10:31 -0400322 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
James Smart78b2d852007-08-02 11:10:21 -0400323 for (j=0; j<hbqs->entry_count; j++) {
324 len += snprintf(buf+len, size-len,
325 "%03d: %08x %04x %05x ", j,
James Smarta8adb832007-10-27 13:37:53 -0400326 le32_to_cpu(hbqe->bde.addrLow),
327 le32_to_cpu(hbqe->bde.tus.w),
328 le32_to_cpu(hbqe->buffer_tag));
James Smart78b2d852007-08-02 11:10:21 -0400329 i = 0;
330 found = 0;
331
332 /* First calculate if slot has an associated posted buffer */
333 low = hbqs->hbqPutIdx - posted;
334 if (low >= 0) {
335 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
336 len += snprintf(buf+len, size-len, "Unused\n");
337 goto skipit;
338 }
339 }
340 else {
341 if ((j >= hbqs->hbqPutIdx) &&
342 (j < (hbqs->entry_count+low))) {
343 len += snprintf(buf+len, size-len, "Unused\n");
344 goto skipit;
345 }
346 }
347
348 /* Get the Buffer info for the posted buffer */
James Smart51ef4c22007-08-02 11:10:31 -0400349 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
James Smart78b2d852007-08-02 11:10:21 -0400350 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
351 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
James Smarta8adb832007-10-27 13:37:53 -0400352 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
James Smart78b2d852007-08-02 11:10:21 -0400353 len += snprintf(buf+len, size-len,
354 "Buf%d: %p %06x\n", i,
355 hbq_buf->dbuf.virt, hbq_buf->tag);
356 found = 1;
357 break;
358 }
359 i++;
360 }
361 if (!found) {
362 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
363 }
364skipit:
365 hbqe++;
366 if (len > LPFC_HBQINFO_SIZE - 54)
367 break;
368 }
369 spin_unlock_irq(&phba->hbalock);
370 return len;
371}
372
James Smartc95d6c62008-01-11 01:53:23 -0500373static int lpfc_debugfs_last_hba_slim_off;
374
James Smarte59058c2008-08-24 21:49:00 -0400375/**
James Smart3621a712009-04-06 18:47:14 -0400376 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400377 * @phba: The HBA to gather SLIM info from.
378 * @buf: The buffer to dump log into.
379 * @size: The maximum amount of data to process.
380 *
381 * Description:
382 * This routine dumps the current contents of HBA SLIM for the HBA associated
383 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
384 *
385 * Notes:
386 * This routine will only dump up to 1024 bytes of data each time called and
387 * should be called multiple times to dump the entire HBA SLIM.
388 *
389 * Return Value:
390 * This routine returns the amount of bytes that were dumped into @buf and will
391 * not exceed @size.
392 **/
James Smarta58cbd52007-08-02 11:09:43 -0400393static int
James Smartc95d6c62008-01-11 01:53:23 -0500394lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
James Smarta58cbd52007-08-02 11:09:43 -0400395{
396 int len = 0;
James Smartc95d6c62008-01-11 01:53:23 -0500397 int i, off;
398 uint32_t *ptr;
399 char buffer[1024];
400
401 off = 0;
402 spin_lock_irq(&phba->hbalock);
403
404 len += snprintf(buf+len, size-len, "HBA SLIM\n");
405 lpfc_memcpy_from_slim(buffer,
James Smarta257bf92009-04-06 18:48:10 -0400406 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
James Smartc95d6c62008-01-11 01:53:23 -0500407
408 ptr = (uint32_t *)&buffer[0];
409 off = lpfc_debugfs_last_hba_slim_off;
410
411 /* Set it up for the next time */
412 lpfc_debugfs_last_hba_slim_off += 1024;
413 if (lpfc_debugfs_last_hba_slim_off >= 4096)
414 lpfc_debugfs_last_hba_slim_off = 0;
415
416 i = 1024;
417 while (i > 0) {
418 len += snprintf(buf+len, size-len,
419 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
420 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
421 *(ptr+5), *(ptr+6), *(ptr+7));
422 ptr += 8;
423 i -= (8 * sizeof(uint32_t));
424 off += (8 * sizeof(uint32_t));
425 }
426
427 spin_unlock_irq(&phba->hbalock);
428 return len;
429}
430
James Smarte59058c2008-08-24 21:49:00 -0400431/**
James Smart3621a712009-04-06 18:47:14 -0400432 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400433 * @phba: The HBA to gather Host SLIM info from.
434 * @buf: The buffer to dump log into.
435 * @size: The maximum amount of data to process.
436 *
437 * Description:
438 * This routine dumps the current contents of host SLIM for the host associated
439 * with @phba to @buf up to @size bytes of data. The dump will contain the
440 * Mailbox, PCB, Rings, and Registers that are located in host memory.
441 *
442 * Return Value:
443 * This routine returns the amount of bytes that were dumped into @buf and will
444 * not exceed @size.
445 **/
James Smartc95d6c62008-01-11 01:53:23 -0500446static int
447lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
448{
449 int len = 0;
450 int i, off;
James Smarta58cbd52007-08-02 11:09:43 -0400451 uint32_t word0, word1, word2, word3;
452 uint32_t *ptr;
453 struct lpfc_pgp *pgpp;
454 struct lpfc_sli *psli = &phba->sli;
455 struct lpfc_sli_ring *pring;
456
James Smarta58cbd52007-08-02 11:09:43 -0400457 off = 0;
458 spin_lock_irq(&phba->hbalock);
459
460 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
James Smart34b02dc2008-08-24 21:49:55 -0400461 ptr = (uint32_t *)phba->slim2p.virt;
James Smarta58cbd52007-08-02 11:09:43 -0400462 i = sizeof(MAILBOX_t);
463 while (i > 0) {
464 len += snprintf(buf+len, size-len,
465 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
466 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
467 *(ptr+5), *(ptr+6), *(ptr+7));
468 ptr += 8;
469 i -= (8 * sizeof(uint32_t));
470 off += (8 * sizeof(uint32_t));
471 }
472
473 len += snprintf(buf+len, size-len, "SLIM PCB\n");
James Smart34b02dc2008-08-24 21:49:55 -0400474 ptr = (uint32_t *)phba->pcb;
James Smarta58cbd52007-08-02 11:09:43 -0400475 i = sizeof(PCB_t);
476 while (i > 0) {
477 len += snprintf(buf+len, size-len,
478 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
479 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
480 *(ptr+5), *(ptr+6), *(ptr+7));
481 ptr += 8;
482 i -= (8 * sizeof(uint32_t));
483 off += (8 * sizeof(uint32_t));
484 }
485
James Smart34b02dc2008-08-24 21:49:55 -0400486 for (i = 0; i < 4; i++) {
487 pgpp = &phba->port_gp[i];
488 pring = &psli->ring[i];
489 len += snprintf(buf+len, size-len,
490 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
491 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
492 i, pgpp->cmdGetInx, pring->numCiocb,
493 pring->next_cmdidx, pring->local_getidx,
494 pring->flag, pgpp->rspPutInx, pring->numRiocb);
495 }
James Smart3772a992009-05-22 14:50:54 -0400496
497 if (phba->sli_rev <= LPFC_SLI_REV3) {
498 word0 = readl(phba->HAregaddr);
499 word1 = readl(phba->CAregaddr);
500 word2 = readl(phba->HSregaddr);
501 word3 = readl(phba->HCregaddr);
502 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
503 "HC:%08x\n", word0, word1, word2, word3);
504 }
James Smarta58cbd52007-08-02 11:09:43 -0400505 spin_unlock_irq(&phba->hbalock);
506 return len;
507}
508
James Smarte59058c2008-08-24 21:49:00 -0400509/**
James Smart3621a712009-04-06 18:47:14 -0400510 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400511 * @vport: The vport to gather target node info from.
512 * @buf: The buffer to dump log into.
513 * @size: The maximum amount of data to process.
514 *
515 * Description:
516 * This routine dumps the current target node list associated with @vport to
517 * @buf up to @size bytes of data. Each node entry in the dump will contain a
518 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
519 *
520 * Return Value:
521 * This routine returns the amount of bytes that were dumped into @buf and will
522 * not exceed @size.
523 **/
James Smarta58cbd52007-08-02 11:09:43 -0400524static int
James Smart858c9f62007-06-17 19:56:39 -0500525lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
526{
527 int len = 0;
528 int cnt;
529 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
530 struct lpfc_nodelist *ndlp;
531 unsigned char *statep, *name;
532
533 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
534
535 spin_lock_irq(shost->host_lock);
536 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
537 if (!cnt) {
538 len += snprintf(buf+len, size-len,
539 "Missing Nodelist Entries\n");
540 break;
541 }
542 cnt--;
543 switch (ndlp->nlp_state) {
544 case NLP_STE_UNUSED_NODE:
545 statep = "UNUSED";
546 break;
547 case NLP_STE_PLOGI_ISSUE:
548 statep = "PLOGI ";
549 break;
550 case NLP_STE_ADISC_ISSUE:
551 statep = "ADISC ";
552 break;
553 case NLP_STE_REG_LOGIN_ISSUE:
554 statep = "REGLOG";
555 break;
556 case NLP_STE_PRLI_ISSUE:
557 statep = "PRLI ";
558 break;
559 case NLP_STE_UNMAPPED_NODE:
560 statep = "UNMAP ";
561 break;
562 case NLP_STE_MAPPED_NODE:
563 statep = "MAPPED";
564 break;
565 case NLP_STE_NPR_NODE:
566 statep = "NPR ";
567 break;
568 default:
569 statep = "UNKNOWN";
570 }
571 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
572 statep, ndlp->nlp_DID);
573 name = (unsigned char *)&ndlp->nlp_portname;
574 len += snprintf(buf+len, size-len,
575 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
576 *name, *(name+1), *(name+2), *(name+3),
577 *(name+4), *(name+5), *(name+6), *(name+7));
578 name = (unsigned char *)&ndlp->nlp_nodename;
579 len += snprintf(buf+len, size-len,
580 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
581 *name, *(name+1), *(name+2), *(name+3),
582 *(name+4), *(name+5), *(name+6), *(name+7));
583 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
584 ndlp->nlp_rpi, ndlp->nlp_flag);
585 if (!ndlp->nlp_type)
James Smarta58cbd52007-08-02 11:09:43 -0400586 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500587 if (ndlp->nlp_type & NLP_FC_NODE)
588 len += snprintf(buf+len, size-len, "FC_NODE ");
589 if (ndlp->nlp_type & NLP_FABRIC)
590 len += snprintf(buf+len, size-len, "FABRIC ");
591 if (ndlp->nlp_type & NLP_FCP_TARGET)
592 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
593 ndlp->nlp_sid);
594 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
James Smarta58cbd52007-08-02 11:09:43 -0400595 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart58da1ff2008-04-07 10:15:56 -0400596 len += snprintf(buf+len, size-len, "usgmap:%x ",
597 ndlp->nlp_usg_map);
James Smarta58cbd52007-08-02 11:09:43 -0400598 len += snprintf(buf+len, size-len, "refcnt:%x",
599 atomic_read(&ndlp->kref.refcount));
James Smart858c9f62007-06-17 19:56:39 -0500600 len += snprintf(buf+len, size-len, "\n");
601 }
602 spin_unlock_irq(shost->host_lock);
603 return len;
604}
605#endif
606
James Smarte59058c2008-08-24 21:49:00 -0400607/**
James Smart3621a712009-04-06 18:47:14 -0400608 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400609 * @vport: The vport to associate this trace string with for retrieval.
610 * @mask: Log entry classification.
611 * @fmt: Format string to be displayed when dumping the log.
612 * @data1: 1st data parameter to be applied to @fmt.
613 * @data2: 2nd data parameter to be applied to @fmt.
614 * @data3: 3rd data parameter to be applied to @fmt.
615 *
616 * Description:
617 * This routine is used by the driver code to add a debugfs log entry to the
618 * discovery trace buffer associated with @vport. Only entries with a @mask that
619 * match the current debugfs discovery mask will be saved. Entries that do not
620 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
621 * printf when displaying the log.
622 **/
James Smart858c9f62007-06-17 19:56:39 -0500623inline void
624lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
625 uint32_t data1, uint32_t data2, uint32_t data3)
626{
James Smart923e4b62008-12-04 22:40:07 -0500627#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400628 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -0500629 int index;
630
631 if (!(lpfc_debugfs_mask_disc_trc & mask))
632 return;
633
634 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
635 !vport || !vport->disc_trc)
636 return;
637
638 index = atomic_inc_return(&vport->disc_trc_cnt) &
639 (lpfc_debugfs_max_disc_trc - 1);
640 dtp = vport->disc_trc + index;
641 dtp->fmt = fmt;
642 dtp->data1 = data1;
643 dtp->data2 = data2;
644 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -0400645 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
646 dtp->jif = jiffies;
647#endif
648 return;
649}
650
James Smarte59058c2008-08-24 21:49:00 -0400651/**
James Smart3621a712009-04-06 18:47:14 -0400652 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400653 * @phba: The phba to associate this trace string with for retrieval.
654 * @fmt: Format string to be displayed when dumping the log.
655 * @data1: 1st data parameter to be applied to @fmt.
656 * @data2: 2nd data parameter to be applied to @fmt.
657 * @data3: 3rd data parameter to be applied to @fmt.
658 *
659 * Description:
660 * This routine is used by the driver code to add a debugfs log entry to the
661 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
662 * @data3 are used like printf when displaying the log.
663 **/
James Smarta58cbd52007-08-02 11:09:43 -0400664inline void
665lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
666 uint32_t data1, uint32_t data2, uint32_t data3)
667{
James Smart923e4b62008-12-04 22:40:07 -0500668#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400669 struct lpfc_debugfs_trc *dtp;
670 int index;
671
672 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
673 !phba || !phba->slow_ring_trc)
674 return;
675
676 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
677 (lpfc_debugfs_max_slow_ring_trc - 1);
678 dtp = phba->slow_ring_trc + index;
679 dtp->fmt = fmt;
680 dtp->data1 = data1;
681 dtp->data2 = data2;
682 dtp->data3 = data3;
683 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500684 dtp->jif = jiffies;
685#endif
686 return;
687}
688
James Smart923e4b62008-12-04 22:40:07 -0500689#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -0400690/**
James Smart3621a712009-04-06 18:47:14 -0400691 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400692 * @inode: The inode pointer that contains a vport pointer.
693 * @file: The file pointer to attach the log output.
694 *
695 * Description:
696 * This routine is the entry point for the debugfs open file operation. It gets
697 * the vport from the i_private field in @inode, allocates the necessary buffer
698 * for the log, fills the buffer from the in-memory log for this vport, and then
699 * returns a pointer to that log in the private_data field in @file.
700 *
701 * Returns:
702 * This function returns zero if successful. On error it will return an negative
703 * error value.
704 **/
James Smart858c9f62007-06-17 19:56:39 -0500705static int
706lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
707{
708 struct lpfc_vport *vport = inode->i_private;
709 struct lpfc_debug *debug;
710 int size;
711 int rc = -ENOMEM;
712
713 if (!lpfc_debugfs_max_disc_trc) {
714 rc = -ENOSPC;
715 goto out;
716 }
717
718 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
719 if (!debug)
720 goto out;
721
James Smarte59058c2008-08-24 21:49:00 -0400722 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400723 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -0500724 size = PAGE_ALIGN(size);
725
726 debug->buffer = kmalloc(size, GFP_KERNEL);
727 if (!debug->buffer) {
728 kfree(debug);
729 goto out;
730 }
731
732 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
733 file->private_data = debug;
734
735 rc = 0;
736out:
737 return rc;
738}
739
James Smarte59058c2008-08-24 21:49:00 -0400740/**
James Smart3621a712009-04-06 18:47:14 -0400741 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400742 * @inode: The inode pointer that contains a vport pointer.
743 * @file: The file pointer to attach the log output.
744 *
745 * Description:
746 * This routine is the entry point for the debugfs open file operation. It gets
747 * the vport from the i_private field in @inode, allocates the necessary buffer
748 * for the log, fills the buffer from the in-memory log for this vport, and then
749 * returns a pointer to that log in the private_data field in @file.
750 *
751 * Returns:
752 * This function returns zero if successful. On error it will return an negative
753 * error value.
754 **/
James Smart858c9f62007-06-17 19:56:39 -0500755static int
James Smarta58cbd52007-08-02 11:09:43 -0400756lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
757{
758 struct lpfc_hba *phba = inode->i_private;
759 struct lpfc_debug *debug;
760 int size;
761 int rc = -ENOMEM;
762
763 if (!lpfc_debugfs_max_slow_ring_trc) {
764 rc = -ENOSPC;
765 goto out;
766 }
767
768 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
769 if (!debug)
770 goto out;
771
James Smarte59058c2008-08-24 21:49:00 -0400772 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400773 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
774 size = PAGE_ALIGN(size);
775
776 debug->buffer = kmalloc(size, GFP_KERNEL);
777 if (!debug->buffer) {
778 kfree(debug);
779 goto out;
780 }
781
782 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
783 file->private_data = debug;
784
785 rc = 0;
786out:
787 return rc;
788}
789
James Smarte59058c2008-08-24 21:49:00 -0400790/**
James Smart3621a712009-04-06 18:47:14 -0400791 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400792 * @inode: The inode pointer that contains a vport pointer.
793 * @file: The file pointer to attach the log output.
794 *
795 * Description:
796 * This routine is the entry point for the debugfs open file operation. It gets
797 * the vport from the i_private field in @inode, allocates the necessary buffer
798 * for the log, fills the buffer from the in-memory log for this vport, and then
799 * returns a pointer to that log in the private_data field in @file.
800 *
801 * Returns:
802 * This function returns zero if successful. On error it will return an negative
803 * error value.
804 **/
James Smarta58cbd52007-08-02 11:09:43 -0400805static int
James Smart78b2d852007-08-02 11:10:21 -0400806lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
807{
808 struct lpfc_hba *phba = inode->i_private;
809 struct lpfc_debug *debug;
810 int rc = -ENOMEM;
811
812 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
813 if (!debug)
814 goto out;
815
James Smarte59058c2008-08-24 21:49:00 -0400816 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -0400817 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
818 if (!debug->buffer) {
819 kfree(debug);
820 goto out;
821 }
822
823 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
824 LPFC_HBQINFO_SIZE);
825 file->private_data = debug;
826
827 rc = 0;
828out:
829 return rc;
830}
831
James Smarte59058c2008-08-24 21:49:00 -0400832/**
James Smart3621a712009-04-06 18:47:14 -0400833 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400834 * @inode: The inode pointer that contains a vport pointer.
835 * @file: The file pointer to attach the log output.
836 *
837 * Description:
838 * This routine is the entry point for the debugfs open file operation. It gets
839 * the vport from the i_private field in @inode, allocates the necessary buffer
840 * for the log, fills the buffer from the in-memory log for this vport, and then
841 * returns a pointer to that log in the private_data field in @file.
842 *
843 * Returns:
844 * This function returns zero if successful. On error it will return an negative
845 * error value.
846 **/
James Smart78b2d852007-08-02 11:10:21 -0400847static int
James Smartc95d6c62008-01-11 01:53:23 -0500848lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -0400849{
850 struct lpfc_hba *phba = inode->i_private;
851 struct lpfc_debug *debug;
852 int rc = -ENOMEM;
853
854 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
855 if (!debug)
856 goto out;
857
James Smarte59058c2008-08-24 21:49:00 -0400858 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500859 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -0400860 if (!debug->buffer) {
861 kfree(debug);
862 goto out;
863 }
864
James Smartc95d6c62008-01-11 01:53:23 -0500865 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
866 LPFC_DUMPHBASLIM_SIZE);
867 file->private_data = debug;
868
869 rc = 0;
870out:
871 return rc;
872}
873
James Smarte59058c2008-08-24 21:49:00 -0400874/**
James Smart3621a712009-04-06 18:47:14 -0400875 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400876 * @inode: The inode pointer that contains a vport pointer.
877 * @file: The file pointer to attach the log output.
878 *
879 * Description:
880 * This routine is the entry point for the debugfs open file operation. It gets
881 * the vport from the i_private field in @inode, allocates the necessary buffer
882 * for the log, fills the buffer from the in-memory log for this vport, and then
883 * returns a pointer to that log in the private_data field in @file.
884 *
885 * Returns:
886 * This function returns zero if successful. On error it will return an negative
887 * error value.
888 **/
James Smartc95d6c62008-01-11 01:53:23 -0500889static int
890lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
891{
892 struct lpfc_hba *phba = inode->i_private;
893 struct lpfc_debug *debug;
894 int rc = -ENOMEM;
895
896 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
897 if (!debug)
898 goto out;
899
James Smarte59058c2008-08-24 21:49:00 -0400900 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500901 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
902 if (!debug->buffer) {
903 kfree(debug);
904 goto out;
905 }
906
907 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
908 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -0400909 file->private_data = debug;
910
911 rc = 0;
912out:
913 return rc;
914}
915
James Smarte2a0a9d2008-12-04 22:40:02 -0500916static int
917lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
918{
919 struct lpfc_debug *debug;
920 int rc = -ENOMEM;
921
922 if (!_dump_buf_data)
923 return -EBUSY;
924
925 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
926 if (!debug)
927 goto out;
928
929 /* Round to page boundry */
James Smart6a9c52c2009-10-02 15:16:51 -0400930 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
James Smarte2a0a9d2008-12-04 22:40:02 -0500931 __func__, _dump_buf_data);
932 debug->buffer = _dump_buf_data;
933 if (!debug->buffer) {
934 kfree(debug);
935 goto out;
936 }
937
938 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
939 file->private_data = debug;
940
941 rc = 0;
942out:
943 return rc;
944}
945
946static int
947lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
948{
949 struct lpfc_debug *debug;
950 int rc = -ENOMEM;
951
952 if (!_dump_buf_dif)
953 return -EBUSY;
954
955 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
956 if (!debug)
957 goto out;
958
959 /* Round to page boundry */
James Smart6a9c52c2009-10-02 15:16:51 -0400960 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
961 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
James Smarte2a0a9d2008-12-04 22:40:02 -0500962 debug->buffer = _dump_buf_dif;
963 if (!debug->buffer) {
964 kfree(debug);
965 goto out;
966 }
967
968 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
969 file->private_data = debug;
970
971 rc = 0;
972out:
973 return rc;
974}
975
976static ssize_t
977lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
978 size_t nbytes, loff_t *ppos)
979{
980 /*
981 * The Data/DIF buffers only save one failing IO
982 * The write op is used as a reset mechanism after an IO has
983 * already been saved to the next one can be saved
984 */
985 spin_lock(&_dump_buf_lock);
986
987 memset((void *)_dump_buf_data, 0,
988 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
989 memset((void *)_dump_buf_dif, 0,
990 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
991
992 _dump_buf_done = 0;
993
994 spin_unlock(&_dump_buf_lock);
995
996 return nbytes;
997}
998
999
1000
James Smarte59058c2008-08-24 21:49:00 -04001001/**
James Smart3621a712009-04-06 18:47:14 -04001002 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001003 * @inode: The inode pointer that contains a vport pointer.
1004 * @file: The file pointer to attach the log output.
1005 *
1006 * Description:
1007 * This routine is the entry point for the debugfs open file operation. It gets
1008 * the vport from the i_private field in @inode, allocates the necessary buffer
1009 * for the log, fills the buffer from the in-memory log for this vport, and then
1010 * returns a pointer to that log in the private_data field in @file.
1011 *
1012 * Returns:
1013 * This function returns zero if successful. On error it will return an negative
1014 * error value.
1015 **/
James Smarta58cbd52007-08-02 11:09:43 -04001016static int
James Smart858c9f62007-06-17 19:56:39 -05001017lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1018{
1019 struct lpfc_vport *vport = inode->i_private;
1020 struct lpfc_debug *debug;
1021 int rc = -ENOMEM;
1022
1023 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1024 if (!debug)
1025 goto out;
1026
James Smarte59058c2008-08-24 21:49:00 -04001027 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05001028 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1029 if (!debug->buffer) {
1030 kfree(debug);
1031 goto out;
1032 }
1033
1034 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1035 LPFC_NODELIST_SIZE);
1036 file->private_data = debug;
1037
1038 rc = 0;
1039out:
1040 return rc;
1041}
1042
James Smarte59058c2008-08-24 21:49:00 -04001043/**
James Smart3621a712009-04-06 18:47:14 -04001044 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001045 * @file: The file pointer to seek through.
1046 * @off: The offset to seek to or the amount to seek by.
1047 * @whence: Indicates how to seek.
1048 *
1049 * Description:
1050 * This routine is the entry point for the debugfs lseek file operation. The
1051 * @whence parameter indicates whether @off is the offset to directly seek to,
1052 * or if it is a value to seek forward or reverse by. This function figures out
1053 * what the new offset of the debugfs file will be and assigns that value to the
1054 * f_pos field of @file.
1055 *
1056 * Returns:
1057 * This function returns the new offset if successful and returns a negative
1058 * error if unable to process the seek.
1059 **/
James Smart858c9f62007-06-17 19:56:39 -05001060static loff_t
1061lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1062{
1063 struct lpfc_debug *debug;
1064 loff_t pos = -1;
1065
1066 debug = file->private_data;
1067
1068 switch (whence) {
1069 case 0:
1070 pos = off;
1071 break;
1072 case 1:
1073 pos = file->f_pos + off;
1074 break;
1075 case 2:
1076 pos = debug->len - off;
1077 }
1078 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1079}
1080
James Smarte59058c2008-08-24 21:49:00 -04001081/**
James Smart3621a712009-04-06 18:47:14 -04001082 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001083 * @file: The file pointer to read from.
1084 * @buf: The buffer to copy the data to.
1085 * @nbytes: The number of bytes to read.
1086 * @ppos: The position in the file to start reading from.
1087 *
1088 * Description:
1089 * This routine reads data from from the buffer indicated in the private_data
1090 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1091 * data to @buf.
1092 *
1093 * Returns:
1094 * This function returns the amount of data that was read (this could be less
1095 * than @nbytes if the end of the file was reached) or a negative error value.
1096 **/
James Smart858c9f62007-06-17 19:56:39 -05001097static ssize_t
1098lpfc_debugfs_read(struct file *file, char __user *buf,
1099 size_t nbytes, loff_t *ppos)
1100{
1101 struct lpfc_debug *debug = file->private_data;
1102 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1103 debug->len);
1104}
1105
James Smarte59058c2008-08-24 21:49:00 -04001106/**
James Smart3621a712009-04-06 18:47:14 -04001107 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04001108 * @inode: The inode pointer that contains a vport pointer. (unused)
1109 * @file: The file pointer that contains the buffer to release.
1110 *
1111 * Description:
1112 * This routine frees the buffer that was allocated when the debugfs file was
1113 * opened.
1114 *
1115 * Returns:
1116 * This function returns zero.
1117 **/
James Smart858c9f62007-06-17 19:56:39 -05001118static int
1119lpfc_debugfs_release(struct inode *inode, struct file *file)
1120{
1121 struct lpfc_debug *debug = file->private_data;
1122
1123 kfree(debug->buffer);
1124 kfree(debug);
1125
1126 return 0;
1127}
1128
James Smarte2a0a9d2008-12-04 22:40:02 -05001129static int
1130lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1131{
1132 struct lpfc_debug *debug = file->private_data;
1133
1134 debug->buffer = NULL;
1135 kfree(debug);
1136
1137 return 0;
1138}
1139
James Smart858c9f62007-06-17 19:56:39 -05001140#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001141static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05001142 .owner = THIS_MODULE,
1143 .open = lpfc_debugfs_disc_trc_open,
1144 .llseek = lpfc_debugfs_lseek,
1145 .read = lpfc_debugfs_read,
1146 .release = lpfc_debugfs_release,
1147};
1148
1149#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001150static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05001151 .owner = THIS_MODULE,
1152 .open = lpfc_debugfs_nodelist_open,
1153 .llseek = lpfc_debugfs_lseek,
1154 .read = lpfc_debugfs_read,
1155 .release = lpfc_debugfs_release,
1156};
1157
James Smart78b2d852007-08-02 11:10:21 -04001158#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001159static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04001160 .owner = THIS_MODULE,
1161 .open = lpfc_debugfs_hbqinfo_open,
1162 .llseek = lpfc_debugfs_lseek,
1163 .read = lpfc_debugfs_read,
1164 .release = lpfc_debugfs_release,
1165};
1166
James Smartc95d6c62008-01-11 01:53:23 -05001167#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001168static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04001169 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05001170 .open = lpfc_debugfs_dumpHBASlim_open,
1171 .llseek = lpfc_debugfs_lseek,
1172 .read = lpfc_debugfs_read,
1173 .release = lpfc_debugfs_release,
1174};
1175
1176#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001177static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05001178 .owner = THIS_MODULE,
1179 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04001180 .llseek = lpfc_debugfs_lseek,
1181 .read = lpfc_debugfs_read,
1182 .release = lpfc_debugfs_release,
1183};
1184
James Smarte2a0a9d2008-12-04 22:40:02 -05001185#undef lpfc_debugfs_op_dumpData
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001186static const struct file_operations lpfc_debugfs_op_dumpData = {
James Smarte2a0a9d2008-12-04 22:40:02 -05001187 .owner = THIS_MODULE,
1188 .open = lpfc_debugfs_dumpData_open,
1189 .llseek = lpfc_debugfs_lseek,
1190 .read = lpfc_debugfs_read,
1191 .write = lpfc_debugfs_dumpDataDif_write,
1192 .release = lpfc_debugfs_dumpDataDif_release,
1193};
1194
1195#undef lpfc_debugfs_op_dumpDif
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001196static const struct file_operations lpfc_debugfs_op_dumpDif = {
James Smarte2a0a9d2008-12-04 22:40:02 -05001197 .owner = THIS_MODULE,
1198 .open = lpfc_debugfs_dumpDif_open,
1199 .llseek = lpfc_debugfs_lseek,
1200 .read = lpfc_debugfs_read,
1201 .write = lpfc_debugfs_dumpDataDif_write,
1202 .release = lpfc_debugfs_dumpDataDif_release,
1203};
1204
James Smarta58cbd52007-08-02 11:09:43 -04001205#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01001206static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04001207 .owner = THIS_MODULE,
1208 .open = lpfc_debugfs_slow_ring_trc_open,
1209 .llseek = lpfc_debugfs_lseek,
1210 .read = lpfc_debugfs_read,
1211 .release = lpfc_debugfs_release,
1212};
1213
James Smart858c9f62007-06-17 19:56:39 -05001214static struct dentry *lpfc_debugfs_root = NULL;
1215static atomic_t lpfc_debugfs_hba_count;
1216#endif
1217
James Smarte59058c2008-08-24 21:49:00 -04001218/**
James Smart3621a712009-04-06 18:47:14 -04001219 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04001220 * @vport: The vport pointer to initialize.
1221 *
1222 * Description:
1223 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
1224 * If not already created, this routine will create the lpfc directory, and
1225 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
1226 * also create each file used to access lpfc specific debugfs information.
1227 **/
James Smart858c9f62007-06-17 19:56:39 -05001228inline void
1229lpfc_debugfs_initialize(struct lpfc_vport *vport)
1230{
James Smart923e4b62008-12-04 22:40:07 -05001231#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05001232 struct lpfc_hba *phba = vport->phba;
1233 char name[64];
1234 uint32_t num, i;
1235
1236 if (!lpfc_debugfs_enable)
1237 return;
1238
James Smarta58cbd52007-08-02 11:09:43 -04001239 /* Setup lpfc root directory */
1240 if (!lpfc_debugfs_root) {
1241 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
1242 atomic_set(&lpfc_debugfs_hba_count, 0);
1243 if (!lpfc_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04001244 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001245 "0408 Cannot create debugfs root\n");
James Smarta58cbd52007-08-02 11:09:43 -04001246 goto debug_failed;
1247 }
1248 }
James Smarta58cbd52007-08-02 11:09:43 -04001249 if (!lpfc_debugfs_start_time)
1250 lpfc_debugfs_start_time = jiffies;
1251
1252 /* Setup lpfcX directory for specific HBA */
1253 snprintf(name, sizeof(name), "lpfc%d", phba->brd_no);
1254 if (!phba->hba_debugfs_root) {
1255 phba->hba_debugfs_root =
1256 debugfs_create_dir(name, lpfc_debugfs_root);
1257 if (!phba->hba_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04001258 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001259 "0412 Cannot create debugfs hba\n");
James Smarta58cbd52007-08-02 11:09:43 -04001260 goto debug_failed;
1261 }
1262 atomic_inc(&lpfc_debugfs_hba_count);
1263 atomic_set(&phba->debugfs_vport_count, 0);
1264
James Smart78b2d852007-08-02 11:10:21 -04001265 /* Setup hbqinfo */
1266 snprintf(name, sizeof(name), "hbqinfo");
1267 phba->debug_hbqinfo =
1268 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1269 phba->hba_debugfs_root,
1270 phba, &lpfc_debugfs_op_hbqinfo);
1271 if (!phba->debug_hbqinfo) {
1272 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001273 "0411 Cannot create debugfs hbqinfo\n");
James Smart78b2d852007-08-02 11:10:21 -04001274 goto debug_failed;
1275 }
1276
James Smartc95d6c62008-01-11 01:53:23 -05001277 /* Setup dumpHBASlim */
1278 snprintf(name, sizeof(name), "dumpHBASlim");
1279 phba->debug_dumpHBASlim =
James Smarta58cbd52007-08-02 11:09:43 -04001280 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1281 phba->hba_debugfs_root,
James Smartc95d6c62008-01-11 01:53:23 -05001282 phba, &lpfc_debugfs_op_dumpHBASlim);
1283 if (!phba->debug_dumpHBASlim) {
James Smarte8b62012007-08-02 11:10:09 -04001284 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001285 "0413 Cannot create debugfs dumpHBASlim\n");
James Smartc95d6c62008-01-11 01:53:23 -05001286 goto debug_failed;
1287 }
1288
1289 /* Setup dumpHostSlim */
1290 snprintf(name, sizeof(name), "dumpHostSlim");
1291 phba->debug_dumpHostSlim =
1292 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1293 phba->hba_debugfs_root,
1294 phba, &lpfc_debugfs_op_dumpHostSlim);
1295 if (!phba->debug_dumpHostSlim) {
1296 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001297 "0414 Cannot create debugfs dumpHostSlim\n");
James Smarta58cbd52007-08-02 11:09:43 -04001298 goto debug_failed;
1299 }
1300
James Smarte2a0a9d2008-12-04 22:40:02 -05001301 /* Setup dumpData */
1302 snprintf(name, sizeof(name), "dumpData");
1303 phba->debug_dumpData =
1304 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1305 phba->hba_debugfs_root,
1306 phba, &lpfc_debugfs_op_dumpData);
1307 if (!phba->debug_dumpData) {
1308 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1309 "0800 Cannot create debugfs dumpData\n");
1310 goto debug_failed;
1311 }
1312
1313 /* Setup dumpDif */
1314 snprintf(name, sizeof(name), "dumpDif");
1315 phba->debug_dumpDif =
1316 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1317 phba->hba_debugfs_root,
1318 phba, &lpfc_debugfs_op_dumpDif);
1319 if (!phba->debug_dumpDif) {
1320 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1321 "0801 Cannot create debugfs dumpDif\n");
1322 goto debug_failed;
1323 }
1324
1325
1326
James Smarta58cbd52007-08-02 11:09:43 -04001327 /* Setup slow ring trace */
1328 if (lpfc_debugfs_max_slow_ring_trc) {
1329 num = lpfc_debugfs_max_slow_ring_trc - 1;
1330 if (num & lpfc_debugfs_max_slow_ring_trc) {
1331 /* Change to be a power of 2 */
1332 num = lpfc_debugfs_max_slow_ring_trc;
1333 i = 0;
1334 while (num > 1) {
1335 num = num >> 1;
1336 i++;
1337 }
1338 lpfc_debugfs_max_slow_ring_trc = (1 << i);
1339 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04001340 "lpfc_debugfs_max_disc_trc changed to "
1341 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04001342 }
1343 }
1344
1345
1346 snprintf(name, sizeof(name), "slow_ring_trace");
1347 phba->debug_slow_ring_trc =
1348 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1349 phba->hba_debugfs_root,
1350 phba, &lpfc_debugfs_op_slow_ring_trc);
1351 if (!phba->debug_slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001352 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001353 "0415 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04001354 "slow_ring_trace\n");
James Smarta58cbd52007-08-02 11:09:43 -04001355 goto debug_failed;
1356 }
1357 if (!phba->slow_ring_trc) {
1358 phba->slow_ring_trc = kmalloc(
1359 (sizeof(struct lpfc_debugfs_trc) *
1360 lpfc_debugfs_max_slow_ring_trc),
1361 GFP_KERNEL);
1362 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001363 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001364 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04001365 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04001366 goto debug_failed;
1367 }
1368 atomic_set(&phba->slow_ring_trc_cnt, 0);
1369 memset(phba->slow_ring_trc, 0,
1370 (sizeof(struct lpfc_debugfs_trc) *
1371 lpfc_debugfs_max_slow_ring_trc));
1372 }
1373 }
1374
1375 snprintf(name, sizeof(name), "vport%d", vport->vpi);
1376 if (!vport->vport_debugfs_root) {
1377 vport->vport_debugfs_root =
1378 debugfs_create_dir(name, phba->hba_debugfs_root);
1379 if (!vport->vport_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04001380 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6a9c52c2009-10-02 15:16:51 -04001381 "0417 Cant create debugfs\n");
James Smarta58cbd52007-08-02 11:09:43 -04001382 goto debug_failed;
1383 }
1384 atomic_inc(&phba->debugfs_vport_count);
1385 }
1386
James Smart858c9f62007-06-17 19:56:39 -05001387 if (lpfc_debugfs_max_disc_trc) {
1388 num = lpfc_debugfs_max_disc_trc - 1;
1389 if (num & lpfc_debugfs_max_disc_trc) {
1390 /* Change to be a power of 2 */
1391 num = lpfc_debugfs_max_disc_trc;
1392 i = 0;
1393 while (num > 1) {
1394 num = num >> 1;
1395 i++;
1396 }
1397 lpfc_debugfs_max_disc_trc = (1 << i);
1398 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04001399 "lpfc_debugfs_max_disc_trc changed to %d\n",
1400 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05001401 }
1402 }
1403
Adrian Bunkff86ba52007-10-18 12:52:37 +02001404 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04001405 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05001406 GFP_KERNEL);
1407
James Smarta58cbd52007-08-02 11:09:43 -04001408 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001409 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001410 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04001411 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05001412 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04001413 }
1414 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05001415
1416 snprintf(name, sizeof(name), "discovery_trace");
1417 vport->debug_disc_trc =
1418 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1419 vport->vport_debugfs_root,
1420 vport, &lpfc_debugfs_op_disc_trc);
1421 if (!vport->debug_disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04001422 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001423 "0419 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04001424 "discovery_trace\n");
James Smart858c9f62007-06-17 19:56:39 -05001425 goto debug_failed;
1426 }
1427 snprintf(name, sizeof(name), "nodelist");
1428 vport->debug_nodelist =
1429 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
1430 vport->vport_debugfs_root,
1431 vport, &lpfc_debugfs_op_nodelist);
1432 if (!vport->debug_nodelist) {
James Smarte8b62012007-08-02 11:10:09 -04001433 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6a9c52c2009-10-02 15:16:51 -04001434 "0409 Cant create debugfs nodelist\n");
James Smart858c9f62007-06-17 19:56:39 -05001435 goto debug_failed;
1436 }
1437debug_failed:
1438 return;
1439#endif
1440}
1441
James Smarte59058c2008-08-24 21:49:00 -04001442/**
James Smart3621a712009-04-06 18:47:14 -04001443 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04001444 * @vport: The vport pointer to remove from debugfs.
1445 *
1446 * Description:
1447 * When Debugfs is configured this routine removes debugfs file system elements
1448 * that are specific to this vport. It also checks to see if there are any
1449 * users left for the debugfs directories associated with the HBA and driver. If
1450 * this is the last user of the HBA directory or driver directory then it will
1451 * remove those from the debugfs infrastructure as well.
1452 **/
James Smart858c9f62007-06-17 19:56:39 -05001453inline void
1454lpfc_debugfs_terminate(struct lpfc_vport *vport)
1455{
James Smart923e4b62008-12-04 22:40:07 -05001456#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05001457 struct lpfc_hba *phba = vport->phba;
1458
1459 if (vport->disc_trc) {
1460 kfree(vport->disc_trc);
1461 vport->disc_trc = NULL;
1462 }
1463 if (vport->debug_disc_trc) {
1464 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
1465 vport->debug_disc_trc = NULL;
1466 }
1467 if (vport->debug_nodelist) {
1468 debugfs_remove(vport->debug_nodelist); /* nodelist */
1469 vport->debug_nodelist = NULL;
1470 }
James Smarta58cbd52007-08-02 11:09:43 -04001471
James Smart858c9f62007-06-17 19:56:39 -05001472 if (vport->vport_debugfs_root) {
1473 debugfs_remove(vport->vport_debugfs_root); /* vportX */
1474 vport->vport_debugfs_root = NULL;
1475 atomic_dec(&phba->debugfs_vport_count);
1476 }
1477 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04001478
James Smart78b2d852007-08-02 11:10:21 -04001479 if (phba->debug_hbqinfo) {
1480 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
1481 phba->debug_hbqinfo = NULL;
1482 }
James Smartc95d6c62008-01-11 01:53:23 -05001483 if (phba->debug_dumpHBASlim) {
1484 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
1485 phba->debug_dumpHBASlim = NULL;
1486 }
1487 if (phba->debug_dumpHostSlim) {
1488 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
1489 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04001490 }
James Smarte2a0a9d2008-12-04 22:40:02 -05001491 if (phba->debug_dumpData) {
1492 debugfs_remove(phba->debug_dumpData); /* dumpData */
1493 phba->debug_dumpData = NULL;
1494 }
1495
1496 if (phba->debug_dumpDif) {
1497 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
1498 phba->debug_dumpDif = NULL;
1499 }
1500
James Smarta58cbd52007-08-02 11:09:43 -04001501 if (phba->slow_ring_trc) {
1502 kfree(phba->slow_ring_trc);
1503 phba->slow_ring_trc = NULL;
1504 }
1505 if (phba->debug_slow_ring_trc) {
1506 /* slow_ring_trace */
1507 debugfs_remove(phba->debug_slow_ring_trc);
1508 phba->debug_slow_ring_trc = NULL;
1509 }
1510
1511 if (phba->hba_debugfs_root) {
1512 debugfs_remove(phba->hba_debugfs_root); /* lpfcX */
1513 phba->hba_debugfs_root = NULL;
1514 atomic_dec(&lpfc_debugfs_hba_count);
1515 }
1516
James Smart858c9f62007-06-17 19:56:39 -05001517 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
1518 debugfs_remove(lpfc_debugfs_root); /* lpfc */
1519 lpfc_debugfs_root = NULL;
1520 }
1521 }
1522#endif
James Smarta58cbd52007-08-02 11:09:43 -04001523 return;
James Smart858c9f62007-06-17 19:56:39 -05001524}