blob: 34f7cf76bf4f609c7b0154626870506438bf353d [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 Smart2a622bf2011-02-16 12:40:06 -05004 * Copyright (C) 2007-2011 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>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040023#include <linux/module.h>
James Smart858c9f62007-06-17 19:56:39 -050024#include <linux/dma-mapping.h>
25#include <linux/idr.h>
26#include <linux/interrupt.h>
27#include <linux/kthread.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
James Smart858c9f62007-06-17 19:56:39 -050029#include <linux/pci.h>
30#include <linux/spinlock.h>
31#include <linux/ctype.h>
James Smart858c9f62007-06-17 19:56:39 -050032
33#include <scsi/scsi.h>
34#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_transport_fc.h>
37
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_hw4.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_hw.h"
40#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040041#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040042#include "lpfc_nl.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_disc.h"
44#include "lpfc_scsi.h"
45#include "lpfc.h"
46#include "lpfc_logmsg.h"
47#include "lpfc_crtn.h"
48#include "lpfc_vport.h"
49#include "lpfc_version.h"
James Smartc95d6c62008-01-11 01:53:23 -050050#include "lpfc_compat.h"
James Smart858c9f62007-06-17 19:56:39 -050051#include "lpfc_debugfs.h"
James Smartb76f2dc2011-07-22 18:37:42 -040052#include "lpfc_bsg.h"
James Smart858c9f62007-06-17 19:56:39 -050053
James Smart923e4b62008-12-04 22:40:07 -050054#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart3621a712009-04-06 18:47:14 -040055/*
James Smarte59058c2008-08-24 21:49:00 -040056 * debugfs interface
James Smart858c9f62007-06-17 19:56:39 -050057 *
58 * To access this interface the user should:
GeunSik Lim156f5a72009-06-02 15:01:37 +090059 * # mount -t debugfs none /sys/kernel/debug
James Smart858c9f62007-06-17 19:56:39 -050060 *
James Smarte59058c2008-08-24 21:49:00 -040061 * The lpfc debugfs directory hierarchy is:
James Smart2a622bf2011-02-16 12:40:06 -050062 * /sys/kernel/debug/lpfc/fnX/vportY
63 * where X is the lpfc hba function unique_id
James Smart858c9f62007-06-17 19:56:39 -050064 * where Y is the vport VPI on that hba
65 *
66 * Debugging services available per vport:
67 * discovery_trace
68 * This is an ACSII readable file that contains a trace of the last
69 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
James Smarte59058c2008-08-24 21:49:00 -040070 * See lpfc_debugfs.h for different categories of discovery events.
71 * To enable the discovery trace, the following module parameters must be set:
James Smart858c9f62007-06-17 19:56:39 -050072 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
73 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
74 * EACH vport. X MUST also be a power of 2.
75 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
76 * lpfc_debugfs.h .
James Smarte59058c2008-08-24 21:49:00 -040077 *
78 * slow_ring_trace
79 * This is an ACSII readable file that contains a trace of the last
80 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
81 * To enable the slow ring trace, the following module parameters must be set:
82 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
83 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
84 * the HBA. X MUST also be a power of 2.
James Smart858c9f62007-06-17 19:56:39 -050085 */
James Smart51ef4c22007-08-02 11:10:31 -040086static int lpfc_debugfs_enable = 1;
James Smartab56dc22011-02-16 12:39:57 -050087module_param(lpfc_debugfs_enable, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050088MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
89
James Smarta58cbd52007-08-02 11:09:43 -040090/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050091static int lpfc_debugfs_max_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -050092module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050093MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
94 "Set debugfs discovery trace depth");
95
James Smarta58cbd52007-08-02 11:09:43 -040096/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050097static int lpfc_debugfs_max_slow_ring_trc;
James Smartab56dc22011-02-16 12:39:57 -050098module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
James Smarta58cbd52007-08-02 11:09:43 -040099MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
100 "Set debugfs slow ring trace depth");
101
James Smarta257bf92009-04-06 18:48:10 -0400102static int lpfc_debugfs_mask_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -0500103module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -0500104MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
105 "Set debugfs discovery trace mask");
106
107#include <linux/debugfs.h>
108
James Smart311464e2007-08-02 11:10:37 -0400109static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
110static unsigned long lpfc_debugfs_start_time = 0L;
James Smart858c9f62007-06-17 19:56:39 -0500111
James Smart2a622bf2011-02-16 12:40:06 -0500112/* iDiag */
113static struct lpfc_idiag idiag;
114
James Smarte59058c2008-08-24 21:49:00 -0400115/**
James Smart3621a712009-04-06 18:47:14 -0400116 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400117 * @vport: The vport to gather the log info from.
118 * @buf: The buffer to dump log into.
119 * @size: The maximum amount of data to process.
120 *
121 * Description:
122 * This routine gathers the lpfc discovery debugfs data from the @vport and
123 * dumps it to @buf up to @size number of bytes. It will start at the next entry
124 * in the log and process the log until the end of the buffer. Then it will
125 * gather from the beginning of the log and process until the current entry.
126 *
127 * Notes:
128 * Discovery logging will be disabled while while this routine dumps the log.
129 *
130 * Return Value:
131 * This routine returns the amount of bytes that were dumped into @buf and will
132 * not exceed @size.
133 **/
James Smart858c9f62007-06-17 19:56:39 -0500134static int
135lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
136{
137 int i, index, len, enable;
138 uint32_t ms;
James Smarta58cbd52007-08-02 11:09:43 -0400139 struct lpfc_debugfs_trc *dtp;
James Smartb76f2dc2011-07-22 18:37:42 -0400140 char *buffer;
141
142 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
143 if (!buffer)
144 return 0;
James Smart858c9f62007-06-17 19:56:39 -0500145
James Smart858c9f62007-06-17 19:56:39 -0500146 enable = lpfc_debugfs_enable;
147 lpfc_debugfs_enable = 0;
148
149 len = 0;
150 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
151 (lpfc_debugfs_max_disc_trc - 1);
152 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
153 dtp = vport->disc_trc + i;
154 if (!dtp->fmt)
155 continue;
156 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400157 snprintf(buffer,
158 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500159 dtp->seq_cnt, ms, dtp->fmt);
160 len += snprintf(buf+len, size-len, buffer,
161 dtp->data1, dtp->data2, dtp->data3);
162 }
163 for (i = 0; i < index; 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
175 lpfc_debugfs_enable = enable;
James Smartb76f2dc2011-07-22 18:37:42 -0400176 kfree(buffer);
177
James Smart858c9f62007-06-17 19:56:39 -0500178 return len;
179}
180
James Smarte59058c2008-08-24 21:49:00 -0400181/**
James Smart3621a712009-04-06 18:47:14 -0400182 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400183 * @phba: The HBA to gather the log info from.
184 * @buf: The buffer to dump log into.
185 * @size: The maximum amount of data to process.
186 *
187 * Description:
188 * This routine gathers the lpfc slow ring debugfs data from the @phba and
189 * dumps it to @buf up to @size number of bytes. It will start at the next entry
190 * in the log and process the log until the end of the buffer. Then it will
191 * gather from the beginning of the log and process until the current entry.
192 *
193 * Notes:
194 * Slow ring logging will be disabled while while this routine dumps the log.
195 *
196 * Return Value:
197 * This routine returns the amount of bytes that were dumped into @buf and will
198 * not exceed @size.
199 **/
James Smart858c9f62007-06-17 19:56:39 -0500200static int
James Smarta58cbd52007-08-02 11:09:43 -0400201lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
202{
203 int i, index, len, enable;
204 uint32_t ms;
205 struct lpfc_debugfs_trc *dtp;
James Smartb76f2dc2011-07-22 18:37:42 -0400206 char *buffer;
James Smarta58cbd52007-08-02 11:09:43 -0400207
James Smartb76f2dc2011-07-22 18:37:42 -0400208 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
209 if (!buffer)
210 return 0;
James Smarta58cbd52007-08-02 11:09:43 -0400211
212 enable = lpfc_debugfs_enable;
213 lpfc_debugfs_enable = 0;
214
215 len = 0;
216 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
217 (lpfc_debugfs_max_slow_ring_trc - 1);
218 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
219 dtp = phba->slow_ring_trc + i;
220 if (!dtp->fmt)
221 continue;
222 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
223 snprintf(buffer,
224 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
225 dtp->seq_cnt, ms, dtp->fmt);
226 len += snprintf(buf+len, size-len, buffer,
227 dtp->data1, dtp->data2, dtp->data3);
228 }
229 for (i = 0; i < index; i++) {
230 dtp = phba->slow_ring_trc + i;
231 if (!dtp->fmt)
232 continue;
233 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
234 snprintf(buffer,
235 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
236 dtp->seq_cnt, ms, dtp->fmt);
237 len += snprintf(buf+len, size-len, buffer,
238 dtp->data1, dtp->data2, dtp->data3);
239 }
240
241 lpfc_debugfs_enable = enable;
James Smartb76f2dc2011-07-22 18:37:42 -0400242 kfree(buffer);
243
James Smarta58cbd52007-08-02 11:09:43 -0400244 return len;
245}
246
James Smart311464e2007-08-02 11:10:37 -0400247static int lpfc_debugfs_last_hbq = -1;
James Smart78b2d852007-08-02 11:10:21 -0400248
James Smarte59058c2008-08-24 21:49:00 -0400249/**
James Smart3621a712009-04-06 18:47:14 -0400250 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400251 * @phba: The HBA to gather host buffer info from.
252 * @buf: The buffer to dump log into.
253 * @size: The maximum amount of data to process.
254 *
255 * Description:
256 * This routine dumps the host buffer queue info from the @phba to @buf up to
257 * @size number of bytes. A header that describes the current hbq state will be
258 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
259 * until @size bytes have been dumped or all the hbq info has been dumped.
260 *
261 * Notes:
262 * This routine will rotate through each configured HBQ each time called.
263 *
264 * Return Value:
265 * This routine returns the amount of bytes that were dumped into @buf and will
266 * not exceed @size.
267 **/
James Smart78b2d852007-08-02 11:10:21 -0400268static int
269lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
270{
271 int len = 0;
272 int cnt, i, j, found, posted, low;
273 uint32_t phys, raw_index, getidx;
274 struct lpfc_hbq_init *hip;
275 struct hbq_s *hbqs;
276 struct lpfc_hbq_entry *hbqe;
277 struct lpfc_dmabuf *d_buf;
278 struct hbq_dmabuf *hbq_buf;
279
James Smart3772a992009-05-22 14:50:54 -0400280 if (phba->sli_rev != 3)
281 return 0;
James Smart78b2d852007-08-02 11:10:21 -0400282 cnt = LPFC_HBQINFO_SIZE;
283 spin_lock_irq(&phba->hbalock);
284
285 /* toggle between multiple hbqs, if any */
286 i = lpfc_sli_hbq_count();
287 if (i > 1) {
288 lpfc_debugfs_last_hbq++;
289 if (lpfc_debugfs_last_hbq >= i)
290 lpfc_debugfs_last_hbq = 0;
291 }
292 else
293 lpfc_debugfs_last_hbq = 0;
294
295 i = lpfc_debugfs_last_hbq;
296
297 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
298
James Smart51ef4c22007-08-02 11:10:31 -0400299 hbqs = &phba->hbqs[i];
James Smart78b2d852007-08-02 11:10:21 -0400300 posted = 0;
James Smart51ef4c22007-08-02 11:10:31 -0400301 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
James Smart78b2d852007-08-02 11:10:21 -0400302 posted++;
303
304 hip = lpfc_hbq_defs[i];
305 len += snprintf(buf+len, size-len,
306 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
307 hip->hbq_index, hip->profile, hip->rn,
308 hip->buffer_count, hip->init_count, hip->add_count, posted);
309
James Smart78b2d852007-08-02 11:10:21 -0400310 raw_index = phba->hbq_get[i];
311 getidx = le32_to_cpu(raw_index);
312 len += snprintf(buf+len, size-len,
James Smarta8adb832007-10-27 13:37:53 -0400313 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
314 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
315 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
James Smart78b2d852007-08-02 11:10:21 -0400316
James Smart51ef4c22007-08-02 11:10:31 -0400317 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
James Smart78b2d852007-08-02 11:10:21 -0400318 for (j=0; j<hbqs->entry_count; j++) {
319 len += snprintf(buf+len, size-len,
320 "%03d: %08x %04x %05x ", j,
James Smarta8adb832007-10-27 13:37:53 -0400321 le32_to_cpu(hbqe->bde.addrLow),
322 le32_to_cpu(hbqe->bde.tus.w),
323 le32_to_cpu(hbqe->buffer_tag));
James Smart78b2d852007-08-02 11:10:21 -0400324 i = 0;
325 found = 0;
326
327 /* First calculate if slot has an associated posted buffer */
328 low = hbqs->hbqPutIdx - posted;
329 if (low >= 0) {
330 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
331 len += snprintf(buf+len, size-len, "Unused\n");
332 goto skipit;
333 }
334 }
335 else {
336 if ((j >= hbqs->hbqPutIdx) &&
337 (j < (hbqs->entry_count+low))) {
338 len += snprintf(buf+len, size-len, "Unused\n");
339 goto skipit;
340 }
341 }
342
343 /* Get the Buffer info for the posted buffer */
James Smart51ef4c22007-08-02 11:10:31 -0400344 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
James Smart78b2d852007-08-02 11:10:21 -0400345 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
346 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
James Smarta8adb832007-10-27 13:37:53 -0400347 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
James Smart78b2d852007-08-02 11:10:21 -0400348 len += snprintf(buf+len, size-len,
349 "Buf%d: %p %06x\n", i,
350 hbq_buf->dbuf.virt, hbq_buf->tag);
351 found = 1;
352 break;
353 }
354 i++;
355 }
356 if (!found) {
357 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
358 }
359skipit:
360 hbqe++;
361 if (len > LPFC_HBQINFO_SIZE - 54)
362 break;
363 }
364 spin_unlock_irq(&phba->hbalock);
365 return len;
366}
367
James Smartc95d6c62008-01-11 01:53:23 -0500368static int lpfc_debugfs_last_hba_slim_off;
369
James Smarte59058c2008-08-24 21:49:00 -0400370/**
James Smart3621a712009-04-06 18:47:14 -0400371 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400372 * @phba: The HBA to gather SLIM info from.
373 * @buf: The buffer to dump log into.
374 * @size: The maximum amount of data to process.
375 *
376 * Description:
377 * This routine dumps the current contents of HBA SLIM for the HBA associated
378 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
379 *
380 * Notes:
381 * This routine will only dump up to 1024 bytes of data each time called and
382 * should be called multiple times to dump the entire HBA SLIM.
383 *
384 * Return Value:
385 * This routine returns the amount of bytes that were dumped into @buf and will
386 * not exceed @size.
387 **/
James Smarta58cbd52007-08-02 11:09:43 -0400388static int
James Smartc95d6c62008-01-11 01:53:23 -0500389lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
James Smarta58cbd52007-08-02 11:09:43 -0400390{
391 int len = 0;
James Smartc95d6c62008-01-11 01:53:23 -0500392 int i, off;
393 uint32_t *ptr;
James Smartb76f2dc2011-07-22 18:37:42 -0400394 char *buffer;
395
396 buffer = kmalloc(1024, GFP_KERNEL);
397 if (!buffer)
398 return 0;
James Smartc95d6c62008-01-11 01:53:23 -0500399
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);
James Smartb76f2dc2011-07-22 18:37:42 -0400427 kfree(buffer);
428
James Smartc95d6c62008-01-11 01:53:23 -0500429 return len;
430}
431
James Smarte59058c2008-08-24 21:49:00 -0400432/**
James Smart3621a712009-04-06 18:47:14 -0400433 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400434 * @phba: The HBA to gather Host SLIM info from.
435 * @buf: The buffer to dump log into.
436 * @size: The maximum amount of data to process.
437 *
438 * Description:
439 * This routine dumps the current contents of host SLIM for the host associated
440 * with @phba to @buf up to @size bytes of data. The dump will contain the
441 * Mailbox, PCB, Rings, and Registers that are located in host memory.
442 *
443 * Return Value:
444 * This routine returns the amount of bytes that were dumped into @buf and will
445 * not exceed @size.
446 **/
James Smartc95d6c62008-01-11 01:53:23 -0500447static int
448lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
449{
450 int len = 0;
451 int i, off;
James Smarta58cbd52007-08-02 11:09:43 -0400452 uint32_t word0, word1, word2, word3;
453 uint32_t *ptr;
454 struct lpfc_pgp *pgpp;
455 struct lpfc_sli *psli = &phba->sli;
456 struct lpfc_sli_ring *pring;
457
James Smarta58cbd52007-08-02 11:09:43 -0400458 off = 0;
459 spin_lock_irq(&phba->hbalock);
460
461 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
James Smart34b02dc2008-08-24 21:49:55 -0400462 ptr = (uint32_t *)phba->slim2p.virt;
James Smarta58cbd52007-08-02 11:09:43 -0400463 i = sizeof(MAILBOX_t);
464 while (i > 0) {
465 len += snprintf(buf+len, size-len,
466 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
467 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
468 *(ptr+5), *(ptr+6), *(ptr+7));
469 ptr += 8;
470 i -= (8 * sizeof(uint32_t));
471 off += (8 * sizeof(uint32_t));
472 }
473
474 len += snprintf(buf+len, size-len, "SLIM PCB\n");
James Smart34b02dc2008-08-24 21:49:55 -0400475 ptr = (uint32_t *)phba->pcb;
James Smarta58cbd52007-08-02 11:09:43 -0400476 i = sizeof(PCB_t);
477 while (i > 0) {
478 len += snprintf(buf+len, size-len,
479 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
480 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
481 *(ptr+5), *(ptr+6), *(ptr+7));
482 ptr += 8;
483 i -= (8 * sizeof(uint32_t));
484 off += (8 * sizeof(uint32_t));
485 }
486
James Smart34b02dc2008-08-24 21:49:55 -0400487 for (i = 0; i < 4; i++) {
488 pgpp = &phba->port_gp[i];
489 pring = &psli->ring[i];
490 len += snprintf(buf+len, size-len,
491 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
492 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
493 i, pgpp->cmdGetInx, pring->numCiocb,
494 pring->next_cmdidx, pring->local_getidx,
495 pring->flag, pgpp->rspPutInx, pring->numRiocb);
496 }
James Smart3772a992009-05-22 14:50:54 -0400497
498 if (phba->sli_rev <= LPFC_SLI_REV3) {
499 word0 = readl(phba->HAregaddr);
500 word1 = readl(phba->CAregaddr);
501 word2 = readl(phba->HSregaddr);
502 word3 = readl(phba->HCregaddr);
503 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
504 "HC:%08x\n", word0, word1, word2, word3);
505 }
James Smarta58cbd52007-08-02 11:09:43 -0400506 spin_unlock_irq(&phba->hbalock);
507 return len;
508}
509
James Smarte59058c2008-08-24 21:49:00 -0400510/**
James Smart3621a712009-04-06 18:47:14 -0400511 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400512 * @vport: The vport to gather target node info from.
513 * @buf: The buffer to dump log into.
514 * @size: The maximum amount of data to process.
515 *
516 * Description:
517 * This routine dumps the current target node list associated with @vport to
518 * @buf up to @size bytes of data. Each node entry in the dump will contain a
519 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
520 *
521 * Return Value:
522 * This routine returns the amount of bytes that were dumped into @buf and will
523 * not exceed @size.
524 **/
James Smarta58cbd52007-08-02 11:09:43 -0400525static int
James Smart858c9f62007-06-17 19:56:39 -0500526lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
527{
528 int len = 0;
529 int cnt;
530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
531 struct lpfc_nodelist *ndlp;
532 unsigned char *statep, *name;
533
534 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
535
536 spin_lock_irq(shost->host_lock);
537 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
538 if (!cnt) {
539 len += snprintf(buf+len, size-len,
540 "Missing Nodelist Entries\n");
541 break;
542 }
543 cnt--;
544 switch (ndlp->nlp_state) {
545 case NLP_STE_UNUSED_NODE:
546 statep = "UNUSED";
547 break;
548 case NLP_STE_PLOGI_ISSUE:
549 statep = "PLOGI ";
550 break;
551 case NLP_STE_ADISC_ISSUE:
552 statep = "ADISC ";
553 break;
554 case NLP_STE_REG_LOGIN_ISSUE:
555 statep = "REGLOG";
556 break;
557 case NLP_STE_PRLI_ISSUE:
558 statep = "PRLI ";
559 break;
560 case NLP_STE_UNMAPPED_NODE:
561 statep = "UNMAP ";
562 break;
563 case NLP_STE_MAPPED_NODE:
564 statep = "MAPPED";
565 break;
566 case NLP_STE_NPR_NODE:
567 statep = "NPR ";
568 break;
569 default:
570 statep = "UNKNOWN";
571 }
572 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
573 statep, ndlp->nlp_DID);
574 name = (unsigned char *)&ndlp->nlp_portname;
575 len += snprintf(buf+len, size-len,
576 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
577 *name, *(name+1), *(name+2), *(name+3),
578 *(name+4), *(name+5), *(name+6), *(name+7));
579 name = (unsigned char *)&ndlp->nlp_nodename;
580 len += snprintf(buf+len, size-len,
581 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
582 *name, *(name+1), *(name+2), *(name+3),
583 *(name+4), *(name+5), *(name+6), *(name+7));
584 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
585 ndlp->nlp_rpi, ndlp->nlp_flag);
586 if (!ndlp->nlp_type)
James Smarta58cbd52007-08-02 11:09:43 -0400587 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500588 if (ndlp->nlp_type & NLP_FC_NODE)
589 len += snprintf(buf+len, size-len, "FC_NODE ");
590 if (ndlp->nlp_type & NLP_FABRIC)
591 len += snprintf(buf+len, size-len, "FABRIC ");
592 if (ndlp->nlp_type & NLP_FCP_TARGET)
593 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
594 ndlp->nlp_sid);
595 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
James Smarta58cbd52007-08-02 11:09:43 -0400596 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart58da1ff2008-04-07 10:15:56 -0400597 len += snprintf(buf+len, size-len, "usgmap:%x ",
598 ndlp->nlp_usg_map);
James Smarta58cbd52007-08-02 11:09:43 -0400599 len += snprintf(buf+len, size-len, "refcnt:%x",
600 atomic_read(&ndlp->kref.refcount));
James Smart858c9f62007-06-17 19:56:39 -0500601 len += snprintf(buf+len, size-len, "\n");
602 }
603 spin_unlock_irq(shost->host_lock);
604 return len;
605}
606#endif
607
James Smarte59058c2008-08-24 21:49:00 -0400608/**
James Smart3621a712009-04-06 18:47:14 -0400609 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400610 * @vport: The vport to associate this trace string with for retrieval.
611 * @mask: Log entry classification.
612 * @fmt: Format string to be displayed when dumping the log.
613 * @data1: 1st data parameter to be applied to @fmt.
614 * @data2: 2nd data parameter to be applied to @fmt.
615 * @data3: 3rd data parameter to be applied to @fmt.
616 *
617 * Description:
618 * This routine is used by the driver code to add a debugfs log entry to the
619 * discovery trace buffer associated with @vport. Only entries with a @mask that
620 * match the current debugfs discovery mask will be saved. Entries that do not
621 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
622 * printf when displaying the log.
623 **/
James Smart858c9f62007-06-17 19:56:39 -0500624inline void
625lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
626 uint32_t data1, uint32_t data2, uint32_t data3)
627{
James Smart923e4b62008-12-04 22:40:07 -0500628#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400629 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -0500630 int index;
631
632 if (!(lpfc_debugfs_mask_disc_trc & mask))
633 return;
634
635 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
636 !vport || !vport->disc_trc)
637 return;
638
639 index = atomic_inc_return(&vport->disc_trc_cnt) &
640 (lpfc_debugfs_max_disc_trc - 1);
641 dtp = vport->disc_trc + index;
642 dtp->fmt = fmt;
643 dtp->data1 = data1;
644 dtp->data2 = data2;
645 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -0400646 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
647 dtp->jif = jiffies;
648#endif
649 return;
650}
651
James Smarte59058c2008-08-24 21:49:00 -0400652/**
James Smart3621a712009-04-06 18:47:14 -0400653 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400654 * @phba: The phba to associate this trace string with for retrieval.
655 * @fmt: Format string to be displayed when dumping the log.
656 * @data1: 1st data parameter to be applied to @fmt.
657 * @data2: 2nd data parameter to be applied to @fmt.
658 * @data3: 3rd data parameter to be applied to @fmt.
659 *
660 * Description:
661 * This routine is used by the driver code to add a debugfs log entry to the
662 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
663 * @data3 are used like printf when displaying the log.
664 **/
James Smarta58cbd52007-08-02 11:09:43 -0400665inline void
666lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
667 uint32_t data1, uint32_t data2, uint32_t data3)
668{
James Smart923e4b62008-12-04 22:40:07 -0500669#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400670 struct lpfc_debugfs_trc *dtp;
671 int index;
672
673 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
674 !phba || !phba->slow_ring_trc)
675 return;
676
677 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
678 (lpfc_debugfs_max_slow_ring_trc - 1);
679 dtp = phba->slow_ring_trc + index;
680 dtp->fmt = fmt;
681 dtp->data1 = data1;
682 dtp->data2 = data2;
683 dtp->data3 = data3;
684 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500685 dtp->jif = jiffies;
686#endif
687 return;
688}
689
James Smart923e4b62008-12-04 22:40:07 -0500690#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -0400691/**
James Smart3621a712009-04-06 18:47:14 -0400692 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400693 * @inode: The inode pointer that contains a vport pointer.
694 * @file: The file pointer to attach the log output.
695 *
696 * Description:
697 * This routine is the entry point for the debugfs open file operation. It gets
698 * the vport from the i_private field in @inode, allocates the necessary buffer
699 * for the log, fills the buffer from the in-memory log for this vport, and then
700 * returns a pointer to that log in the private_data field in @file.
701 *
702 * Returns:
703 * This function returns zero if successful. On error it will return an negative
704 * error value.
705 **/
James Smart858c9f62007-06-17 19:56:39 -0500706static int
707lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
708{
709 struct lpfc_vport *vport = inode->i_private;
710 struct lpfc_debug *debug;
711 int size;
712 int rc = -ENOMEM;
713
714 if (!lpfc_debugfs_max_disc_trc) {
715 rc = -ENOSPC;
716 goto out;
717 }
718
719 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
720 if (!debug)
721 goto out;
722
James Smarte59058c2008-08-24 21:49:00 -0400723 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400724 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -0500725 size = PAGE_ALIGN(size);
726
727 debug->buffer = kmalloc(size, GFP_KERNEL);
728 if (!debug->buffer) {
729 kfree(debug);
730 goto out;
731 }
732
733 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
734 file->private_data = debug;
735
736 rc = 0;
737out:
738 return rc;
739}
740
James Smarte59058c2008-08-24 21:49:00 -0400741/**
James Smart3621a712009-04-06 18:47:14 -0400742 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400743 * @inode: The inode pointer that contains a vport pointer.
744 * @file: The file pointer to attach the log output.
745 *
746 * Description:
747 * This routine is the entry point for the debugfs open file operation. It gets
748 * the vport from the i_private field in @inode, allocates the necessary buffer
749 * for the log, fills the buffer from the in-memory log for this vport, and then
750 * returns a pointer to that log in the private_data field in @file.
751 *
752 * Returns:
753 * This function returns zero if successful. On error it will return an negative
754 * error value.
755 **/
James Smart858c9f62007-06-17 19:56:39 -0500756static int
James Smarta58cbd52007-08-02 11:09:43 -0400757lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
758{
759 struct lpfc_hba *phba = inode->i_private;
760 struct lpfc_debug *debug;
761 int size;
762 int rc = -ENOMEM;
763
764 if (!lpfc_debugfs_max_slow_ring_trc) {
765 rc = -ENOSPC;
766 goto out;
767 }
768
769 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
770 if (!debug)
771 goto out;
772
James Smarte59058c2008-08-24 21:49:00 -0400773 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400774 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
775 size = PAGE_ALIGN(size);
776
777 debug->buffer = kmalloc(size, GFP_KERNEL);
778 if (!debug->buffer) {
779 kfree(debug);
780 goto out;
781 }
782
783 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
784 file->private_data = debug;
785
786 rc = 0;
787out:
788 return rc;
789}
790
James Smarte59058c2008-08-24 21:49:00 -0400791/**
James Smart3621a712009-04-06 18:47:14 -0400792 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400793 * @inode: The inode pointer that contains a vport pointer.
794 * @file: The file pointer to attach the log output.
795 *
796 * Description:
797 * This routine is the entry point for the debugfs open file operation. It gets
798 * the vport from the i_private field in @inode, allocates the necessary buffer
799 * for the log, fills the buffer from the in-memory log for this vport, and then
800 * returns a pointer to that log in the private_data field in @file.
801 *
802 * Returns:
803 * This function returns zero if successful. On error it will return an negative
804 * error value.
805 **/
James Smarta58cbd52007-08-02 11:09:43 -0400806static int
James Smart78b2d852007-08-02 11:10:21 -0400807lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
808{
809 struct lpfc_hba *phba = inode->i_private;
810 struct lpfc_debug *debug;
811 int rc = -ENOMEM;
812
813 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
814 if (!debug)
815 goto out;
816
James Smarte59058c2008-08-24 21:49:00 -0400817 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -0400818 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
819 if (!debug->buffer) {
820 kfree(debug);
821 goto out;
822 }
823
824 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
825 LPFC_HBQINFO_SIZE);
826 file->private_data = debug;
827
828 rc = 0;
829out:
830 return rc;
831}
832
James Smarte59058c2008-08-24 21:49:00 -0400833/**
James Smart3621a712009-04-06 18:47:14 -0400834 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400835 * @inode: The inode pointer that contains a vport pointer.
836 * @file: The file pointer to attach the log output.
837 *
838 * Description:
839 * This routine is the entry point for the debugfs open file operation. It gets
840 * the vport from the i_private field in @inode, allocates the necessary buffer
841 * for the log, fills the buffer from the in-memory log for this vport, and then
842 * returns a pointer to that log in the private_data field in @file.
843 *
844 * Returns:
845 * This function returns zero if successful. On error it will return an negative
846 * error value.
847 **/
James Smart78b2d852007-08-02 11:10:21 -0400848static int
James Smartc95d6c62008-01-11 01:53:23 -0500849lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -0400850{
851 struct lpfc_hba *phba = inode->i_private;
852 struct lpfc_debug *debug;
853 int rc = -ENOMEM;
854
855 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
856 if (!debug)
857 goto out;
858
James Smarte59058c2008-08-24 21:49:00 -0400859 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500860 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -0400861 if (!debug->buffer) {
862 kfree(debug);
863 goto out;
864 }
865
James Smartc95d6c62008-01-11 01:53:23 -0500866 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
867 LPFC_DUMPHBASLIM_SIZE);
868 file->private_data = debug;
869
870 rc = 0;
871out:
872 return rc;
873}
874
James Smarte59058c2008-08-24 21:49:00 -0400875/**
James Smart3621a712009-04-06 18:47:14 -0400876 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400877 * @inode: The inode pointer that contains a vport pointer.
878 * @file: The file pointer to attach the log output.
879 *
880 * Description:
881 * This routine is the entry point for the debugfs open file operation. It gets
882 * the vport from the i_private field in @inode, allocates the necessary buffer
883 * for the log, fills the buffer from the in-memory log for this vport, and then
884 * returns a pointer to that log in the private_data field in @file.
885 *
886 * Returns:
887 * This function returns zero if successful. On error it will return an negative
888 * error value.
889 **/
James Smartc95d6c62008-01-11 01:53:23 -0500890static int
891lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
892{
893 struct lpfc_hba *phba = inode->i_private;
894 struct lpfc_debug *debug;
895 int rc = -ENOMEM;
896
897 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
898 if (!debug)
899 goto out;
900
James Smarte59058c2008-08-24 21:49:00 -0400901 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500902 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
903 if (!debug->buffer) {
904 kfree(debug);
905 goto out;
906 }
907
908 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
909 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -0400910 file->private_data = debug;
911
912 rc = 0;
913out:
914 return rc;
915}
916
James Smarte2a0a9d2008-12-04 22:40:02 -0500917static int
918lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
919{
920 struct lpfc_debug *debug;
921 int rc = -ENOMEM;
922
923 if (!_dump_buf_data)
924 return -EBUSY;
925
926 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
927 if (!debug)
928 goto out;
929
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300930 /* Round to page boundary */
James Smart6a9c52c2009-10-02 15:16:51 -0400931 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
James Smarte2a0a9d2008-12-04 22:40:02 -0500932 __func__, _dump_buf_data);
933 debug->buffer = _dump_buf_data;
934 if (!debug->buffer) {
935 kfree(debug);
936 goto out;
937 }
938
939 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
940 file->private_data = debug;
941
942 rc = 0;
943out:
944 return rc;
945}
946
947static int
948lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
949{
950 struct lpfc_debug *debug;
951 int rc = -ENOMEM;
952
953 if (!_dump_buf_dif)
954 return -EBUSY;
955
956 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
957 if (!debug)
958 goto out;
959
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300960 /* Round to page boundary */
James Smart6a9c52c2009-10-02 15:16:51 -0400961 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
962 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
James Smarte2a0a9d2008-12-04 22:40:02 -0500963 debug->buffer = _dump_buf_dif;
964 if (!debug->buffer) {
965 kfree(debug);
966 goto out;
967 }
968
969 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
970 file->private_data = debug;
971
972 rc = 0;
973out:
974 return rc;
975}
976
977static ssize_t
978lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
979 size_t nbytes, loff_t *ppos)
980{
981 /*
982 * The Data/DIF buffers only save one failing IO
983 * The write op is used as a reset mechanism after an IO has
984 * already been saved to the next one can be saved
985 */
986 spin_lock(&_dump_buf_lock);
987
988 memset((void *)_dump_buf_data, 0,
989 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
990 memset((void *)_dump_buf_dif, 0,
991 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
992
993 _dump_buf_done = 0;
994
995 spin_unlock(&_dump_buf_lock);
996
997 return nbytes;
998}
999
James Smartf9bb2da2011-10-10 21:34:11 -04001000static ssize_t
1001lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1002 size_t nbytes, loff_t *ppos)
1003{
1004 struct dentry *dent = file->f_dentry;
1005 struct lpfc_hba *phba = file->private_data;
1006 char cbuf[16];
1007 int cnt = 0;
1008
1009 if (dent == phba->debug_writeGuard)
1010 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1011 else if (dent == phba->debug_writeApp)
1012 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wapp_cnt);
1013 else if (dent == phba->debug_writeRef)
1014 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wref_cnt);
James Smartacd68592012-01-18 16:25:09 -05001015 else if (dent == phba->debug_readGuard)
1016 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001017 else if (dent == phba->debug_readApp)
1018 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rapp_cnt);
1019 else if (dent == phba->debug_readRef)
1020 cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rref_cnt);
1021 else if (dent == phba->debug_InjErrLBA)
1022 cnt = snprintf(cbuf, 16, "0x%lx\n",
1023 (unsigned long) phba->lpfc_injerr_lba);
1024 else
1025 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1026 "0547 Unknown debugfs error injection entry\n");
1027
1028 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1029}
1030
1031static ssize_t
1032lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1033 size_t nbytes, loff_t *ppos)
1034{
1035 struct dentry *dent = file->f_dentry;
1036 struct lpfc_hba *phba = file->private_data;
1037 char dstbuf[32];
1038 unsigned long tmp;
1039 int size;
1040
1041 memset(dstbuf, 0, 32);
1042 size = (nbytes < 32) ? nbytes : 32;
1043 if (copy_from_user(dstbuf, buf, size))
1044 return 0;
1045
1046 if (strict_strtoul(dstbuf, 0, &tmp))
1047 return 0;
1048
1049 if (dent == phba->debug_writeGuard)
1050 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1051 else if (dent == phba->debug_writeApp)
1052 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1053 else if (dent == phba->debug_writeRef)
1054 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
James Smartacd68592012-01-18 16:25:09 -05001055 else if (dent == phba->debug_readGuard)
1056 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
James Smartf9bb2da2011-10-10 21:34:11 -04001057 else if (dent == phba->debug_readApp)
1058 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1059 else if (dent == phba->debug_readRef)
1060 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1061 else if (dent == phba->debug_InjErrLBA)
1062 phba->lpfc_injerr_lba = (sector_t)tmp;
1063 else
1064 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1065 "0548 Unknown debugfs error injection entry\n");
1066
1067 return nbytes;
1068}
1069
1070static int
1071lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1072{
1073 return 0;
1074}
1075
James Smarte59058c2008-08-24 21:49:00 -04001076/**
James Smart3621a712009-04-06 18:47:14 -04001077 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001078 * @inode: The inode pointer that contains a vport pointer.
1079 * @file: The file pointer to attach the log output.
1080 *
1081 * Description:
1082 * This routine is the entry point for the debugfs open file operation. It gets
1083 * the vport from the i_private field in @inode, allocates the necessary buffer
1084 * for the log, fills the buffer from the in-memory log for this vport, and then
1085 * returns a pointer to that log in the private_data field in @file.
1086 *
1087 * Returns:
1088 * This function returns zero if successful. On error it will return an negative
1089 * error value.
1090 **/
James Smarta58cbd52007-08-02 11:09:43 -04001091static int
James Smart858c9f62007-06-17 19:56:39 -05001092lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1093{
1094 struct lpfc_vport *vport = inode->i_private;
1095 struct lpfc_debug *debug;
1096 int rc = -ENOMEM;
1097
1098 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1099 if (!debug)
1100 goto out;
1101
James Smarte59058c2008-08-24 21:49:00 -04001102 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05001103 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1104 if (!debug->buffer) {
1105 kfree(debug);
1106 goto out;
1107 }
1108
1109 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1110 LPFC_NODELIST_SIZE);
1111 file->private_data = debug;
1112
1113 rc = 0;
1114out:
1115 return rc;
1116}
1117
James Smarte59058c2008-08-24 21:49:00 -04001118/**
James Smart3621a712009-04-06 18:47:14 -04001119 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001120 * @file: The file pointer to seek through.
1121 * @off: The offset to seek to or the amount to seek by.
1122 * @whence: Indicates how to seek.
1123 *
1124 * Description:
1125 * This routine is the entry point for the debugfs lseek file operation. The
1126 * @whence parameter indicates whether @off is the offset to directly seek to,
1127 * or if it is a value to seek forward or reverse by. This function figures out
1128 * what the new offset of the debugfs file will be and assigns that value to the
1129 * f_pos field of @file.
1130 *
1131 * Returns:
1132 * This function returns the new offset if successful and returns a negative
1133 * error if unable to process the seek.
1134 **/
James Smart858c9f62007-06-17 19:56:39 -05001135static loff_t
1136lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1137{
1138 struct lpfc_debug *debug;
1139 loff_t pos = -1;
1140
1141 debug = file->private_data;
1142
1143 switch (whence) {
1144 case 0:
1145 pos = off;
1146 break;
1147 case 1:
1148 pos = file->f_pos + off;
1149 break;
1150 case 2:
1151 pos = debug->len - off;
1152 }
1153 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1154}
1155
James Smarte59058c2008-08-24 21:49:00 -04001156/**
James Smart3621a712009-04-06 18:47:14 -04001157 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001158 * @file: The file pointer to read from.
1159 * @buf: The buffer to copy the data to.
1160 * @nbytes: The number of bytes to read.
1161 * @ppos: The position in the file to start reading from.
1162 *
1163 * Description:
1164 * This routine reads data from from the buffer indicated in the private_data
1165 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1166 * data to @buf.
1167 *
1168 * Returns:
1169 * This function returns the amount of data that was read (this could be less
1170 * than @nbytes if the end of the file was reached) or a negative error value.
1171 **/
James Smart858c9f62007-06-17 19:56:39 -05001172static ssize_t
1173lpfc_debugfs_read(struct file *file, char __user *buf,
1174 size_t nbytes, loff_t *ppos)
1175{
1176 struct lpfc_debug *debug = file->private_data;
James Smart2a622bf2011-02-16 12:40:06 -05001177
James Smart858c9f62007-06-17 19:56:39 -05001178 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1179 debug->len);
1180}
1181
James Smarte59058c2008-08-24 21:49:00 -04001182/**
James Smart3621a712009-04-06 18:47:14 -04001183 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04001184 * @inode: The inode pointer that contains a vport pointer. (unused)
1185 * @file: The file pointer that contains the buffer to release.
1186 *
1187 * Description:
1188 * This routine frees the buffer that was allocated when the debugfs file was
1189 * opened.
1190 *
1191 * Returns:
1192 * This function returns zero.
1193 **/
James Smart858c9f62007-06-17 19:56:39 -05001194static int
1195lpfc_debugfs_release(struct inode *inode, struct file *file)
1196{
1197 struct lpfc_debug *debug = file->private_data;
1198
1199 kfree(debug->buffer);
1200 kfree(debug);
1201
1202 return 0;
1203}
1204
James Smarte2a0a9d2008-12-04 22:40:02 -05001205static int
1206lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1207{
1208 struct lpfc_debug *debug = file->private_data;
1209
1210 debug->buffer = NULL;
1211 kfree(debug);
1212
1213 return 0;
1214}
1215
James Smart2a622bf2011-02-16 12:40:06 -05001216/*
James Smart86a80842011-04-16 11:03:04 -04001217 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001218 * iDiag debugfs file access methods
James Smart86a80842011-04-16 11:03:04 -04001219 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001220 *
James Smart86a80842011-04-16 11:03:04 -04001221 * All access methods are through the proper SLI4 PCI function's debugfs
1222 * iDiag directory:
James Smart2a622bf2011-02-16 12:40:06 -05001223 *
James Smart86a80842011-04-16 11:03:04 -04001224 * /sys/kernel/debug/lpfc/fn<#>/iDiag
James Smart2a622bf2011-02-16 12:40:06 -05001225 */
1226
1227/**
1228 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1229 * @buf: The pointer to the user space buffer.
1230 * @nbytes: The number of bytes in the user space buffer.
1231 * @idiag_cmd: pointer to the idiag command struct.
1232 *
1233 * This routine reads data from debugfs user space buffer and parses the
1234 * buffer for getting the idiag command and arguments. The while space in
1235 * between the set of data is used as the parsing separator.
1236 *
1237 * This routine returns 0 when successful, it returns proper error code
1238 * back to the user space in error conditions.
1239 */
1240static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1241 struct lpfc_idiag_cmd *idiag_cmd)
1242{
1243 char mybuf[64];
1244 char *pbuf, *step_str;
Stephen Boydb11d48e2011-05-12 16:50:06 -07001245 int i;
1246 size_t bsize;
James Smart2a622bf2011-02-16 12:40:06 -05001247
1248 /* Protect copy from user */
1249 if (!access_ok(VERIFY_READ, buf, nbytes))
1250 return -EFAULT;
1251
1252 memset(mybuf, 0, sizeof(mybuf));
1253 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1254 bsize = min(nbytes, (sizeof(mybuf)-1));
1255
1256 if (copy_from_user(mybuf, buf, bsize))
1257 return -EFAULT;
1258 pbuf = &mybuf[0];
1259 step_str = strsep(&pbuf, "\t ");
1260
1261 /* The opcode must present */
1262 if (!step_str)
1263 return -EINVAL;
1264
1265 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1266 if (idiag_cmd->opcode == 0)
1267 return -EINVAL;
1268
1269 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1270 step_str = strsep(&pbuf, "\t ");
1271 if (!step_str)
James Smart86a80842011-04-16 11:03:04 -04001272 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001273 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1274 }
James Smart86a80842011-04-16 11:03:04 -04001275 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001276}
1277
1278/**
1279 * lpfc_idiag_open - idiag open debugfs
1280 * @inode: The inode pointer that contains a pointer to phba.
1281 * @file: The file pointer to attach the file operation.
1282 *
1283 * Description:
1284 * This routine is the entry point for the debugfs open file operation. It
1285 * gets the reference to phba from the i_private field in @inode, it then
1286 * allocates buffer for the file operation, performs the necessary PCI config
1287 * space read into the allocated buffer according to the idiag user command
1288 * setup, and then returns a pointer to buffer in the private_data field in
1289 * @file.
1290 *
1291 * Returns:
1292 * This function returns zero if successful. On error it will return an
1293 * negative error value.
1294 **/
1295static int
1296lpfc_idiag_open(struct inode *inode, struct file *file)
1297{
1298 struct lpfc_debug *debug;
1299
1300 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1301 if (!debug)
1302 return -ENOMEM;
1303
1304 debug->i_private = inode->i_private;
1305 debug->buffer = NULL;
1306 file->private_data = debug;
1307
1308 return 0;
1309}
1310
1311/**
1312 * lpfc_idiag_release - Release idiag access file operation
1313 * @inode: The inode pointer that contains a vport pointer. (unused)
1314 * @file: The file pointer that contains the buffer to release.
1315 *
1316 * Description:
1317 * This routine is the generic release routine for the idiag access file
1318 * operation, it frees the buffer that was allocated when the debugfs file
1319 * was opened.
1320 *
1321 * Returns:
1322 * This function returns zero.
1323 **/
1324static int
1325lpfc_idiag_release(struct inode *inode, struct file *file)
1326{
1327 struct lpfc_debug *debug = file->private_data;
1328
1329 /* Free the buffers to the file operation */
1330 kfree(debug->buffer);
1331 kfree(debug);
1332
1333 return 0;
1334}
1335
1336/**
1337 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1338 * @inode: The inode pointer that contains a vport pointer. (unused)
1339 * @file: The file pointer that contains the buffer to release.
1340 *
1341 * Description:
1342 * This routine frees the buffer that was allocated when the debugfs file
1343 * was opened. It also reset the fields in the idiag command struct in the
James Smart86a80842011-04-16 11:03:04 -04001344 * case of command for write operation.
James Smart2a622bf2011-02-16 12:40:06 -05001345 *
1346 * Returns:
1347 * This function returns zero.
1348 **/
1349static int
1350lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1351{
1352 struct lpfc_debug *debug = file->private_data;
1353
James Smart86a80842011-04-16 11:03:04 -04001354 if (debug->op == LPFC_IDIAG_OP_WR) {
1355 switch (idiag.cmd.opcode) {
1356 case LPFC_IDIAG_CMD_PCICFG_WR:
1357 case LPFC_IDIAG_CMD_PCICFG_ST:
1358 case LPFC_IDIAG_CMD_PCICFG_CL:
1359 case LPFC_IDIAG_CMD_QUEACC_WR:
1360 case LPFC_IDIAG_CMD_QUEACC_ST:
1361 case LPFC_IDIAG_CMD_QUEACC_CL:
James Smart2a622bf2011-02-16 12:40:06 -05001362 memset(&idiag, 0, sizeof(idiag));
James Smart86a80842011-04-16 11:03:04 -04001363 break;
1364 default:
1365 break;
1366 }
1367 }
James Smart2a622bf2011-02-16 12:40:06 -05001368
1369 /* Free the buffers to the file operation */
1370 kfree(debug->buffer);
1371 kfree(debug);
1372
1373 return 0;
1374}
1375
1376/**
1377 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1378 * @file: The file pointer to read from.
1379 * @buf: The buffer to copy the data to.
1380 * @nbytes: The number of bytes to read.
1381 * @ppos: The position in the file to start reading from.
1382 *
1383 * Description:
1384 * This routine reads data from the @phba pci config space according to the
1385 * idiag command, and copies to user @buf. Depending on the PCI config space
1386 * read command setup, it does either a single register read of a byte
1387 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1388 * registers from the 4K extended PCI config space.
1389 *
1390 * Returns:
1391 * This function returns the amount of data that was read (this could be less
1392 * than @nbytes if the end of the file was reached) or a negative error value.
1393 **/
1394static ssize_t
1395lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1396 loff_t *ppos)
1397{
1398 struct lpfc_debug *debug = file->private_data;
1399 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1400 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1401 int where, count;
1402 char *pbuffer;
1403 struct pci_dev *pdev;
1404 uint32_t u32val;
1405 uint16_t u16val;
1406 uint8_t u8val;
1407
1408 pdev = phba->pcidev;
1409 if (!pdev)
1410 return 0;
1411
1412 /* This is a user read operation */
1413 debug->op = LPFC_IDIAG_OP_RD;
1414
1415 if (!debug->buffer)
1416 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1417 if (!debug->buffer)
1418 return 0;
1419 pbuffer = debug->buffer;
1420
1421 if (*ppos)
1422 return 0;
1423
1424 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04001425 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1426 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05001427 } else
1428 return 0;
1429
1430 /* Read single PCI config space register */
1431 switch (count) {
1432 case SIZE_U8: /* byte (8 bits) */
1433 pci_read_config_byte(pdev, where, &u8val);
1434 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1435 "%03x: %02x\n", where, u8val);
1436 break;
1437 case SIZE_U16: /* word (16 bits) */
1438 pci_read_config_word(pdev, where, &u16val);
1439 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1440 "%03x: %04x\n", where, u16val);
1441 break;
1442 case SIZE_U32: /* double word (32 bits) */
1443 pci_read_config_dword(pdev, where, &u32val);
1444 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1445 "%03x: %08x\n", where, u32val);
1446 break;
James Smart86a80842011-04-16 11:03:04 -04001447 case LPFC_PCI_CFG_BROWSE: /* browse all */
James Smart2a622bf2011-02-16 12:40:06 -05001448 goto pcicfg_browse;
1449 break;
1450 default:
1451 /* illegal count */
1452 len = 0;
1453 break;
1454 }
1455 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1456
1457pcicfg_browse:
1458
1459 /* Browse all PCI config space registers */
1460 offset_label = idiag.offset.last_rd;
1461 offset = offset_label;
1462
1463 /* Read PCI config space */
1464 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1465 "%03x: ", offset_label);
1466 while (index > 0) {
1467 pci_read_config_dword(pdev, offset, &u32val);
1468 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1469 "%08x ", u32val);
1470 offset += sizeof(uint32_t);
James Smartb76f2dc2011-07-22 18:37:42 -04001471 if (offset >= LPFC_PCI_CFG_SIZE) {
1472 len += snprintf(pbuffer+len,
1473 LPFC_PCI_CFG_SIZE-len, "\n");
1474 break;
1475 }
James Smart2a622bf2011-02-16 12:40:06 -05001476 index -= sizeof(uint32_t);
1477 if (!index)
1478 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1479 "\n");
1480 else if (!(index % (8 * sizeof(uint32_t)))) {
1481 offset_label += (8 * sizeof(uint32_t));
1482 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1483 "\n%03x: ", offset_label);
1484 }
1485 }
1486
1487 /* Set up the offset for next portion of pci cfg read */
James Smartb76f2dc2011-07-22 18:37:42 -04001488 if (index == 0) {
1489 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1490 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1491 idiag.offset.last_rd = 0;
1492 } else
James Smart2a622bf2011-02-16 12:40:06 -05001493 idiag.offset.last_rd = 0;
1494
1495 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1496}
1497
1498/**
1499 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1500 * @file: The file pointer to read from.
1501 * @buf: The buffer to copy the user data from.
1502 * @nbytes: The number of bytes to get.
1503 * @ppos: The position in the file to start reading from.
1504 *
1505 * This routine get the debugfs idiag command struct from user space and
1506 * then perform the syntax check for PCI config space read or write command
1507 * accordingly. In the case of PCI config space read command, it sets up
1508 * the command in the idiag command struct for the debugfs read operation.
1509 * In the case of PCI config space write operation, it executes the write
1510 * operation into the PCI config space accordingly.
1511 *
1512 * It returns the @nbytges passing in from debugfs user space when successful.
1513 * In case of error conditions, it returns proper error code back to the user
1514 * space.
1515 */
1516static ssize_t
1517lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1518 size_t nbytes, loff_t *ppos)
1519{
1520 struct lpfc_debug *debug = file->private_data;
1521 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1522 uint32_t where, value, count;
1523 uint32_t u32val;
1524 uint16_t u16val;
1525 uint8_t u8val;
1526 struct pci_dev *pdev;
1527 int rc;
1528
1529 pdev = phba->pcidev;
1530 if (!pdev)
1531 return -EFAULT;
1532
1533 /* This is a user write operation */
1534 debug->op = LPFC_IDIAG_OP_WR;
1535
1536 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
James Smart86a80842011-04-16 11:03:04 -04001537 if (rc < 0)
James Smart2a622bf2011-02-16 12:40:06 -05001538 return rc;
1539
1540 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smart86a80842011-04-16 11:03:04 -04001541 /* Sanity check on PCI config read command line arguments */
1542 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1543 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001544 /* Read command from PCI config space, set up command fields */
James Smartb76f2dc2011-07-22 18:37:42 -04001545 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1546 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04001547 if (count == LPFC_PCI_CFG_BROWSE) {
1548 if (where % sizeof(uint32_t))
James Smart2a622bf2011-02-16 12:40:06 -05001549 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04001550 /* Starting offset to browse */
1551 idiag.offset.last_rd = where;
James Smart2a622bf2011-02-16 12:40:06 -05001552 } else if ((count != sizeof(uint8_t)) &&
1553 (count != sizeof(uint16_t)) &&
1554 (count != sizeof(uint32_t)))
1555 goto error_out;
1556 if (count == sizeof(uint8_t)) {
1557 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1558 goto error_out;
1559 if (where % sizeof(uint8_t))
1560 goto error_out;
1561 }
1562 if (count == sizeof(uint16_t)) {
1563 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1564 goto error_out;
1565 if (where % sizeof(uint16_t))
1566 goto error_out;
1567 }
1568 if (count == sizeof(uint32_t)) {
1569 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1570 goto error_out;
1571 if (where % sizeof(uint32_t))
1572 goto error_out;
1573 }
1574 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1575 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1576 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
James Smart86a80842011-04-16 11:03:04 -04001577 /* Sanity check on PCI config write command line arguments */
1578 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1579 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001580 /* Write command to PCI config space, read-modify-write */
James Smartb76f2dc2011-07-22 18:37:42 -04001581 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1582 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1583 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05001584 /* Sanity checks */
1585 if ((count != sizeof(uint8_t)) &&
1586 (count != sizeof(uint16_t)) &&
1587 (count != sizeof(uint32_t)))
1588 goto error_out;
1589 if (count == sizeof(uint8_t)) {
1590 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1591 goto error_out;
1592 if (where % sizeof(uint8_t))
1593 goto error_out;
1594 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1595 pci_write_config_byte(pdev, where,
1596 (uint8_t)value);
1597 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1598 rc = pci_read_config_byte(pdev, where, &u8val);
1599 if (!rc) {
1600 u8val |= (uint8_t)value;
1601 pci_write_config_byte(pdev, where,
1602 u8val);
1603 }
1604 }
1605 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1606 rc = pci_read_config_byte(pdev, where, &u8val);
1607 if (!rc) {
1608 u8val &= (uint8_t)(~value);
1609 pci_write_config_byte(pdev, where,
1610 u8val);
1611 }
1612 }
1613 }
1614 if (count == sizeof(uint16_t)) {
1615 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1616 goto error_out;
1617 if (where % sizeof(uint16_t))
1618 goto error_out;
1619 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1620 pci_write_config_word(pdev, where,
1621 (uint16_t)value);
1622 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1623 rc = pci_read_config_word(pdev, where, &u16val);
1624 if (!rc) {
1625 u16val |= (uint16_t)value;
1626 pci_write_config_word(pdev, where,
1627 u16val);
1628 }
1629 }
1630 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1631 rc = pci_read_config_word(pdev, where, &u16val);
1632 if (!rc) {
1633 u16val &= (uint16_t)(~value);
1634 pci_write_config_word(pdev, where,
1635 u16val);
1636 }
1637 }
1638 }
1639 if (count == sizeof(uint32_t)) {
1640 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1641 goto error_out;
1642 if (where % sizeof(uint32_t))
1643 goto error_out;
1644 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1645 pci_write_config_dword(pdev, where, value);
1646 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1647 rc = pci_read_config_dword(pdev, where,
1648 &u32val);
1649 if (!rc) {
1650 u32val |= value;
1651 pci_write_config_dword(pdev, where,
1652 u32val);
1653 }
1654 }
1655 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1656 rc = pci_read_config_dword(pdev, where,
1657 &u32val);
1658 if (!rc) {
1659 u32val &= ~value;
1660 pci_write_config_dword(pdev, where,
1661 u32val);
1662 }
1663 }
1664 }
1665 } else
1666 /* All other opecodes are illegal for now */
1667 goto error_out;
1668
1669 return nbytes;
1670error_out:
1671 memset(&idiag, 0, sizeof(idiag));
1672 return -EINVAL;
1673}
1674
1675/**
James Smartb76f2dc2011-07-22 18:37:42 -04001676 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1677 * @file: The file pointer to read from.
1678 * @buf: The buffer to copy the data to.
1679 * @nbytes: The number of bytes to read.
1680 * @ppos: The position in the file to start reading from.
1681 *
1682 * Description:
1683 * This routine reads data from the @phba pci bar memory mapped space
1684 * according to the idiag command, and copies to user @buf.
1685 *
1686 * Returns:
1687 * This function returns the amount of data that was read (this could be less
1688 * than @nbytes if the end of the file was reached) or a negative error value.
1689 **/
1690static ssize_t
1691lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1692 loff_t *ppos)
1693{
1694 struct lpfc_debug *debug = file->private_data;
1695 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1696 int offset_label, offset, offset_run, len = 0, index;
1697 int bar_num, acc_range, bar_size;
1698 char *pbuffer;
1699 void __iomem *mem_mapped_bar;
1700 uint32_t if_type;
1701 struct pci_dev *pdev;
1702 uint32_t u32val;
1703
1704 pdev = phba->pcidev;
1705 if (!pdev)
1706 return 0;
1707
1708 /* This is a user read operation */
1709 debug->op = LPFC_IDIAG_OP_RD;
1710
1711 if (!debug->buffer)
1712 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1713 if (!debug->buffer)
1714 return 0;
1715 pbuffer = debug->buffer;
1716
1717 if (*ppos)
1718 return 0;
1719
1720 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1721 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1722 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1723 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1724 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1725 } else
1726 return 0;
1727
1728 if (acc_range == 0)
1729 return 0;
1730
1731 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1732 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1733 if (bar_num == IDIAG_BARACC_BAR_0)
1734 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1735 else if (bar_num == IDIAG_BARACC_BAR_1)
1736 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1737 else if (bar_num == IDIAG_BARACC_BAR_2)
1738 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1739 else
1740 return 0;
1741 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1742 if (bar_num == IDIAG_BARACC_BAR_0)
1743 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1744 else
1745 return 0;
1746 } else
1747 return 0;
1748
1749 /* Read single PCI bar space register */
1750 if (acc_range == SINGLE_WORD) {
1751 offset_run = offset;
1752 u32val = readl(mem_mapped_bar + offset_run);
1753 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1754 "%05x: %08x\n", offset_run, u32val);
1755 } else
1756 goto baracc_browse;
1757
1758 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1759
1760baracc_browse:
1761
1762 /* Browse all PCI bar space registers */
1763 offset_label = idiag.offset.last_rd;
1764 offset_run = offset_label;
1765
1766 /* Read PCI bar memory mapped space */
1767 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1768 "%05x: ", offset_label);
1769 index = LPFC_PCI_BAR_RD_SIZE;
1770 while (index > 0) {
1771 u32val = readl(mem_mapped_bar + offset_run);
1772 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1773 "%08x ", u32val);
1774 offset_run += sizeof(uint32_t);
1775 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1776 if (offset_run >= bar_size) {
1777 len += snprintf(pbuffer+len,
1778 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1779 break;
1780 }
1781 } else {
1782 if (offset_run >= offset +
1783 (acc_range * sizeof(uint32_t))) {
1784 len += snprintf(pbuffer+len,
1785 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1786 break;
1787 }
1788 }
1789 index -= sizeof(uint32_t);
1790 if (!index)
1791 len += snprintf(pbuffer+len,
1792 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1793 else if (!(index % (8 * sizeof(uint32_t)))) {
1794 offset_label += (8 * sizeof(uint32_t));
1795 len += snprintf(pbuffer+len,
1796 LPFC_PCI_BAR_RD_BUF_SIZE-len,
1797 "\n%05x: ", offset_label);
1798 }
1799 }
1800
1801 /* Set up the offset for next portion of pci bar read */
1802 if (index == 0) {
1803 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1804 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1805 if (idiag.offset.last_rd >= bar_size)
1806 idiag.offset.last_rd = 0;
1807 } else {
1808 if (offset_run >= offset +
1809 (acc_range * sizeof(uint32_t)))
1810 idiag.offset.last_rd = offset;
1811 }
1812 } else {
1813 if (acc_range == LPFC_PCI_BAR_BROWSE)
1814 idiag.offset.last_rd = 0;
1815 else
1816 idiag.offset.last_rd = offset;
1817 }
1818
1819 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1820}
1821
1822/**
1823 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1824 * @file: The file pointer to read from.
1825 * @buf: The buffer to copy the user data from.
1826 * @nbytes: The number of bytes to get.
1827 * @ppos: The position in the file to start reading from.
1828 *
1829 * This routine get the debugfs idiag command struct from user space and
1830 * then perform the syntax check for PCI bar memory mapped space read or
1831 * write command accordingly. In the case of PCI bar memory mapped space
1832 * read command, it sets up the command in the idiag command struct for
1833 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1834 * write operation, it executes the write operation into the PCI bar memory
1835 * mapped space accordingly.
1836 *
1837 * It returns the @nbytges passing in from debugfs user space when successful.
1838 * In case of error conditions, it returns proper error code back to the user
1839 * space.
1840 */
1841static ssize_t
1842lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1843 size_t nbytes, loff_t *ppos)
1844{
1845 struct lpfc_debug *debug = file->private_data;
1846 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1847 uint32_t bar_num, bar_size, offset, value, acc_range;
1848 struct pci_dev *pdev;
1849 void __iomem *mem_mapped_bar;
1850 uint32_t if_type;
1851 uint32_t u32val;
1852 int rc;
1853
1854 pdev = phba->pcidev;
1855 if (!pdev)
1856 return -EFAULT;
1857
1858 /* This is a user write operation */
1859 debug->op = LPFC_IDIAG_OP_WR;
1860
1861 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1862 if (rc < 0)
1863 return rc;
1864
1865 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1866 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1867
1868 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1869 if ((bar_num != IDIAG_BARACC_BAR_0) &&
1870 (bar_num != IDIAG_BARACC_BAR_1) &&
1871 (bar_num != IDIAG_BARACC_BAR_2))
1872 goto error_out;
1873 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1874 if (bar_num != IDIAG_BARACC_BAR_0)
1875 goto error_out;
1876 } else
1877 goto error_out;
1878
1879 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1880 if (bar_num == IDIAG_BARACC_BAR_0) {
1881 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1882 LPFC_PCI_IF0_BAR0_SIZE;
1883 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1884 } else if (bar_num == IDIAG_BARACC_BAR_1) {
1885 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1886 LPFC_PCI_IF0_BAR1_SIZE;
1887 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1888 } else if (bar_num == IDIAG_BARACC_BAR_2) {
1889 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1890 LPFC_PCI_IF0_BAR2_SIZE;
1891 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1892 } else
1893 goto error_out;
1894 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1895 if (bar_num == IDIAG_BARACC_BAR_0) {
1896 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1897 LPFC_PCI_IF2_BAR0_SIZE;
1898 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1899 } else
1900 goto error_out;
1901 } else
1902 goto error_out;
1903
1904 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1905 if (offset % sizeof(uint32_t))
1906 goto error_out;
1907
1908 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1909 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1910 /* Sanity check on PCI config read command line arguments */
1911 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1912 goto error_out;
1913 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1914 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1915 if (offset > bar_size - sizeof(uint32_t))
1916 goto error_out;
1917 /* Starting offset to browse */
1918 idiag.offset.last_rd = offset;
1919 } else if (acc_range > SINGLE_WORD) {
1920 if (offset + acc_range * sizeof(uint32_t) > bar_size)
1921 goto error_out;
1922 /* Starting offset to browse */
1923 idiag.offset.last_rd = offset;
1924 } else if (acc_range != SINGLE_WORD)
1925 goto error_out;
1926 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1927 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1928 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1929 /* Sanity check on PCI bar write command line arguments */
1930 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1931 goto error_out;
1932 /* Write command to PCI bar space, read-modify-write */
1933 acc_range = SINGLE_WORD;
1934 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1935 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1936 writel(value, mem_mapped_bar + offset);
1937 readl(mem_mapped_bar + offset);
1938 }
1939 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1940 u32val = readl(mem_mapped_bar + offset);
1941 u32val |= value;
1942 writel(u32val, mem_mapped_bar + offset);
1943 readl(mem_mapped_bar + offset);
1944 }
1945 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1946 u32val = readl(mem_mapped_bar + offset);
1947 u32val &= ~value;
1948 writel(u32val, mem_mapped_bar + offset);
1949 readl(mem_mapped_bar + offset);
1950 }
1951 } else
1952 /* All other opecodes are illegal for now */
1953 goto error_out;
1954
1955 return nbytes;
1956error_out:
1957 memset(&idiag, 0, sizeof(idiag));
1958 return -EINVAL;
1959}
1960
1961/**
James Smart2a622bf2011-02-16 12:40:06 -05001962 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1963 * @file: The file pointer to read from.
1964 * @buf: The buffer to copy the data to.
1965 * @nbytes: The number of bytes to read.
1966 * @ppos: The position in the file to start reading from.
1967 *
1968 * Description:
1969 * This routine reads data from the @phba SLI4 PCI function queue information,
1970 * and copies to user @buf.
1971 *
1972 * Returns:
1973 * This function returns the amount of data that was read (this could be less
1974 * than @nbytes if the end of the file was reached) or a negative error value.
1975 **/
1976static ssize_t
1977lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
1978 loff_t *ppos)
1979{
1980 struct lpfc_debug *debug = file->private_data;
1981 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1982 int len = 0, fcp_qidx;
1983 char *pbuffer;
1984
1985 if (!debug->buffer)
1986 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
1987 if (!debug->buffer)
1988 return 0;
1989 pbuffer = debug->buffer;
1990
1991 if (*ppos)
1992 return 0;
1993
1994 /* Get slow-path event queue information */
1995 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1996 "Slow-path EQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05001997 if (phba->sli4_hba.sp_eq) {
1998 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001999 "\tEQID[%02d], "
2000 "QE-COUNT[%04d], QE-SIZE[%04d], "
2001 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002002 phba->sli4_hba.sp_eq->queue_id,
2003 phba->sli4_hba.sp_eq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002004 phba->sli4_hba.sp_eq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002005 phba->sli4_hba.sp_eq->host_index,
2006 phba->sli4_hba.sp_eq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002007 }
James Smart2a622bf2011-02-16 12:40:06 -05002008
2009 /* Get fast-path event queue information */
2010 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2011 "Fast-path EQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002012 if (phba->sli4_hba.fp_eq) {
2013 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count;
2014 fcp_qidx++) {
2015 if (phba->sli4_hba.fp_eq[fcp_qidx]) {
2016 len += snprintf(pbuffer+len,
2017 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002018 "\tEQID[%02d], "
2019 "QE-COUNT[%04d], QE-SIZE[%04d], "
2020 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002021 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
2022 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002023 phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002024 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
2025 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002026 }
2027 }
James Smart2a622bf2011-02-16 12:40:06 -05002028 }
2029 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2030
2031 /* Get mailbox complete queue information */
2032 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002033 "Slow-path MBX CQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002034 if (phba->sli4_hba.mbx_cq) {
2035 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002036 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002037 phba->sli4_hba.mbx_cq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002038 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002039 "\tCQID[%02d], "
2040 "QE-COUNT[%04d], QE-SIZE[%04d], "
2041 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002042 phba->sli4_hba.mbx_cq->queue_id,
2043 phba->sli4_hba.mbx_cq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002044 phba->sli4_hba.mbx_cq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002045 phba->sli4_hba.mbx_cq->host_index,
2046 phba->sli4_hba.mbx_cq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002047 }
James Smart2a622bf2011-02-16 12:40:06 -05002048
2049 /* Get slow-path complete queue information */
2050 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002051 "Slow-path ELS CQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002052 if (phba->sli4_hba.els_cq) {
2053 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002054 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002055 phba->sli4_hba.els_cq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002056 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002057 "\tCQID [%02d], "
2058 "QE-COUNT[%04d], QE-SIZE[%04d], "
2059 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002060 phba->sli4_hba.els_cq->queue_id,
2061 phba->sli4_hba.els_cq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002062 phba->sli4_hba.els_cq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002063 phba->sli4_hba.els_cq->host_index,
2064 phba->sli4_hba.els_cq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002065 }
James Smart2a622bf2011-02-16 12:40:06 -05002066
2067 /* Get fast-path complete queue information */
2068 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002069 "Fast-path FCP CQ information:\n");
James Smart05580562011-05-24 11:40:48 -04002070 fcp_qidx = 0;
James Smart2e90f4b2011-12-13 13:22:37 -05002071 if (phba->sli4_hba.fcp_cq) {
2072 do {
2073 if (phba->sli4_hba.fcp_cq[fcp_qidx]) {
2074 len += snprintf(pbuffer+len,
2075 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002076 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002077 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002078 len += snprintf(pbuffer+len,
2079 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002080 "\tCQID[%02d], "
2081 "QE-COUNT[%04d], QE-SIZE[%04d], "
2082 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2083 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
2084 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
2085 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
2086 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
2087 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002088 }
2089 } while (++fcp_qidx < phba->cfg_fcp_eq_count);
2090 len += snprintf(pbuffer+len,
2091 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2092 }
James Smart2a622bf2011-02-16 12:40:06 -05002093
2094 /* Get mailbox queue information */
2095 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002096 "Slow-path MBX MQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002097 if (phba->sli4_hba.mbx_wq) {
2098 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002099 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002100 phba->sli4_hba.mbx_wq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002101 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002102 "\tWQID[%02d], "
2103 "QE-COUNT[%04d], QE-SIZE[%04d], "
2104 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002105 phba->sli4_hba.mbx_wq->queue_id,
2106 phba->sli4_hba.mbx_wq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002107 phba->sli4_hba.mbx_wq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002108 phba->sli4_hba.mbx_wq->host_index,
2109 phba->sli4_hba.mbx_wq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002110 }
James Smart2a622bf2011-02-16 12:40:06 -05002111
2112 /* Get slow-path work queue information */
2113 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002114 "Slow-path ELS WQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002115 if (phba->sli4_hba.els_wq) {
2116 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002117 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002118 phba->sli4_hba.els_wq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002119 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002120 "\tWQID[%02d], "
2121 "QE-COUNT[%04d], QE-SIZE[%04d], "
2122 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002123 phba->sli4_hba.els_wq->queue_id,
2124 phba->sli4_hba.els_wq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002125 phba->sli4_hba.els_wq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002126 phba->sli4_hba.els_wq->host_index,
2127 phba->sli4_hba.els_wq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002128 }
James Smart2a622bf2011-02-16 12:40:06 -05002129
2130 /* Get fast-path work queue information */
2131 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002132 "Fast-path FCP WQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002133 if (phba->sli4_hba.fcp_wq) {
2134 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count;
2135 fcp_qidx++) {
2136 if (!phba->sli4_hba.fcp_wq[fcp_qidx])
2137 continue;
2138 len += snprintf(pbuffer+len,
2139 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002140 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002141 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002142 len += snprintf(pbuffer+len,
2143 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002144 "\tWQID[%02d], "
2145 "QE-COUNT[%04d], WQE-SIZE[%04d], "
2146 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002147 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
2148 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002149 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002150 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
2151 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002152 }
2153 len += snprintf(pbuffer+len,
2154 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
James Smart2a622bf2011-02-16 12:40:06 -05002155 }
James Smart2a622bf2011-02-16 12:40:06 -05002156
2157 /* Get receive queue information */
2158 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2159 "Slow-path RQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002160 if (phba->sli4_hba.hdr_rq && phba->sli4_hba.dat_rq) {
2161 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002162 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002163 phba->sli4_hba.hdr_rq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002164 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002165 "\tHQID[%02d], "
2166 "QE-COUNT[%04d], QE-SIZE[%04d], "
2167 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002168 phba->sli4_hba.hdr_rq->queue_id,
2169 phba->sli4_hba.hdr_rq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002170 phba->sli4_hba.hdr_rq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002171 phba->sli4_hba.hdr_rq->host_index,
2172 phba->sli4_hba.hdr_rq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002173 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002174 "\tDQID[%02d], "
2175 "QE-COUNT[%04d], QE-SIZE[%04d], "
2176 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002177 phba->sli4_hba.dat_rq->queue_id,
2178 phba->sli4_hba.dat_rq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002179 phba->sli4_hba.dat_rq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002180 phba->sli4_hba.dat_rq->host_index,
2181 phba->sli4_hba.dat_rq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002182 }
James Smart2a622bf2011-02-16 12:40:06 -05002183 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2184}
2185
James Smart86a80842011-04-16 11:03:04 -04002186/**
2187 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2188 * @q: The pointer to queue structure.
2189 * @index: The index into a queue entry.
2190 * @count: The number of queue entries to access.
2191 *
2192 * Description:
2193 * The routine performs sanity check on device queue access method commands.
2194 *
2195 * Returns:
2196 * This function returns -EINVAL when fails the sanity check, otherwise, it
2197 * returns 0.
2198 **/
2199static int
2200lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
2201{
2202 /* Only support single entry read or browsing */
2203 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
2204 return -EINVAL;
2205 if (index > q->entry_count - 1)
2206 return -EINVAL;
2207 return 0;
2208}
2209
2210/**
2211 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2212 * @pbuffer: The pointer to buffer to copy the read data into.
2213 * @pque: The pointer to the queue to be read.
2214 * @index: The index into the queue entry.
2215 *
2216 * Description:
2217 * This routine reads out a single entry from the given queue's index location
2218 * and copies it into the buffer provided.
2219 *
2220 * Returns:
2221 * This function returns 0 when it fails, otherwise, it returns the length of
2222 * the data read into the buffer provided.
2223 **/
2224static int
2225lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
2226 uint32_t index)
2227{
2228 int offset, esize;
2229 uint32_t *pentry;
2230
2231 if (!pbuffer || !pque)
2232 return 0;
2233
2234 esize = pque->entry_size;
2235 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2236 "QE-INDEX[%04d]:\n", index);
2237
2238 offset = 0;
2239 pentry = pque->qe[index].address;
2240 while (esize > 0) {
2241 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2242 "%08x ", *pentry);
2243 pentry++;
2244 offset += sizeof(uint32_t);
2245 esize -= sizeof(uint32_t);
2246 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
2247 len += snprintf(pbuffer+len,
2248 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2249 }
2250 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2251
2252 return len;
2253}
2254
2255/**
2256 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2257 * @file: The file pointer to read from.
2258 * @buf: The buffer to copy the data to.
2259 * @nbytes: The number of bytes to read.
2260 * @ppos: The position in the file to start reading from.
2261 *
2262 * Description:
2263 * This routine reads data from the @phba device queue memory according to the
2264 * idiag command, and copies to user @buf. Depending on the queue dump read
2265 * command setup, it does either a single queue entry read or browing through
2266 * all entries of the queue.
2267 *
2268 * Returns:
2269 * This function returns the amount of data that was read (this could be less
2270 * than @nbytes if the end of the file was reached) or a negative error value.
2271 **/
2272static ssize_t
2273lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
2274 loff_t *ppos)
2275{
2276 struct lpfc_debug *debug = file->private_data;
2277 uint32_t last_index, index, count;
2278 struct lpfc_queue *pque = NULL;
2279 char *pbuffer;
2280 int len = 0;
2281
2282 /* This is a user read operation */
2283 debug->op = LPFC_IDIAG_OP_RD;
2284
2285 if (!debug->buffer)
2286 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
2287 if (!debug->buffer)
2288 return 0;
2289 pbuffer = debug->buffer;
2290
2291 if (*ppos)
2292 return 0;
2293
2294 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04002295 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2296 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04002297 pque = (struct lpfc_queue *)idiag.ptr_private;
2298 } else
2299 return 0;
2300
2301 /* Browse the queue starting from index */
2302 if (count == LPFC_QUE_ACC_BROWSE)
2303 goto que_browse;
2304
2305 /* Read a single entry from the queue */
2306 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2307
2308 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2309
2310que_browse:
2311
2312 /* Browse all entries from the queue */
2313 last_index = idiag.offset.last_rd;
2314 index = last_index;
2315
2316 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
2317 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2318 index++;
2319 if (index > pque->entry_count - 1)
2320 break;
2321 }
2322
2323 /* Set up the offset for next portion of pci cfg read */
2324 if (index > pque->entry_count - 1)
2325 index = 0;
2326 idiag.offset.last_rd = index;
2327
2328 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2329}
2330
2331/**
2332 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2333 * @file: The file pointer to read from.
2334 * @buf: The buffer to copy the user data from.
2335 * @nbytes: The number of bytes to get.
2336 * @ppos: The position in the file to start reading from.
2337 *
2338 * This routine get the debugfs idiag command struct from user space and then
2339 * perform the syntax check for port queue read (dump) or write (set) command
2340 * accordingly. In the case of port queue read command, it sets up the command
2341 * in the idiag command struct for the following debugfs read operation. In
2342 * the case of port queue write operation, it executes the write operation
2343 * into the port queue entry accordingly.
2344 *
2345 * It returns the @nbytges passing in from debugfs user space when successful.
2346 * In case of error conditions, it returns proper error code back to the user
2347 * space.
2348 **/
2349static ssize_t
2350lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
2351 size_t nbytes, loff_t *ppos)
2352{
2353 struct lpfc_debug *debug = file->private_data;
2354 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2355 uint32_t qidx, quetp, queid, index, count, offset, value;
2356 uint32_t *pentry;
2357 struct lpfc_queue *pque;
2358 int rc;
2359
2360 /* This is a user write operation */
2361 debug->op = LPFC_IDIAG_OP_WR;
2362
2363 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2364 if (rc < 0)
2365 return rc;
2366
2367 /* Get and sanity check on command feilds */
James Smartb76f2dc2011-07-22 18:37:42 -04002368 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
2369 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
2370 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2371 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2372 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
2373 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04002374
2375 /* Sanity check on command line arguments */
2376 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2377 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2378 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2379 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
2380 goto error_out;
2381 if (count != 1)
2382 goto error_out;
2383 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2384 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
2385 goto error_out;
2386 } else
2387 goto error_out;
2388
2389 switch (quetp) {
2390 case LPFC_IDIAG_EQ:
2391 /* Slow-path event queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002392 if (phba->sli4_hba.sp_eq &&
2393 phba->sli4_hba.sp_eq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002394 /* Sanity check */
2395 rc = lpfc_idiag_que_param_check(
2396 phba->sli4_hba.sp_eq, index, count);
2397 if (rc)
2398 goto error_out;
2399 idiag.ptr_private = phba->sli4_hba.sp_eq;
2400 goto pass_check;
2401 }
2402 /* Fast-path event queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002403 if (phba->sli4_hba.fp_eq) {
2404 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
2405 if (phba->sli4_hba.fp_eq[qidx] &&
2406 phba->sli4_hba.fp_eq[qidx]->queue_id ==
2407 queid) {
2408 /* Sanity check */
2409 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002410 phba->sli4_hba.fp_eq[qidx],
2411 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002412 if (rc)
2413 goto error_out;
2414 idiag.ptr_private =
2415 phba->sli4_hba.fp_eq[qidx];
2416 goto pass_check;
2417 }
James Smart86a80842011-04-16 11:03:04 -04002418 }
2419 }
2420 goto error_out;
2421 break;
2422 case LPFC_IDIAG_CQ:
2423 /* MBX complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002424 if (phba->sli4_hba.mbx_cq &&
2425 phba->sli4_hba.mbx_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002426 /* Sanity check */
2427 rc = lpfc_idiag_que_param_check(
2428 phba->sli4_hba.mbx_cq, index, count);
2429 if (rc)
2430 goto error_out;
2431 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2432 goto pass_check;
2433 }
2434 /* ELS complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002435 if (phba->sli4_hba.els_cq &&
2436 phba->sli4_hba.els_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002437 /* Sanity check */
2438 rc = lpfc_idiag_que_param_check(
2439 phba->sli4_hba.els_cq, index, count);
2440 if (rc)
2441 goto error_out;
2442 idiag.ptr_private = phba->sli4_hba.els_cq;
2443 goto pass_check;
2444 }
2445 /* FCP complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002446 if (phba->sli4_hba.fcp_cq) {
2447 qidx = 0;
2448 do {
2449 if (phba->sli4_hba.fcp_cq[qidx] &&
2450 phba->sli4_hba.fcp_cq[qidx]->queue_id ==
2451 queid) {
2452 /* Sanity check */
2453 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002454 phba->sli4_hba.fcp_cq[qidx],
2455 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002456 if (rc)
2457 goto error_out;
2458 idiag.ptr_private =
James Smart86a80842011-04-16 11:03:04 -04002459 phba->sli4_hba.fcp_cq[qidx];
James Smart2e90f4b2011-12-13 13:22:37 -05002460 goto pass_check;
2461 }
2462 } while (++qidx < phba->cfg_fcp_eq_count);
2463 }
James Smart86a80842011-04-16 11:03:04 -04002464 goto error_out;
2465 break;
2466 case LPFC_IDIAG_MQ:
2467 /* MBX work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002468 if (phba->sli4_hba.mbx_wq &&
2469 phba->sli4_hba.mbx_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002470 /* Sanity check */
2471 rc = lpfc_idiag_que_param_check(
2472 phba->sli4_hba.mbx_wq, index, count);
2473 if (rc)
2474 goto error_out;
2475 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2476 goto pass_check;
2477 }
James Smart2e90f4b2011-12-13 13:22:37 -05002478 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04002479 break;
2480 case LPFC_IDIAG_WQ:
2481 /* ELS work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002482 if (phba->sli4_hba.els_wq &&
2483 phba->sli4_hba.els_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002484 /* Sanity check */
2485 rc = lpfc_idiag_que_param_check(
2486 phba->sli4_hba.els_wq, index, count);
2487 if (rc)
2488 goto error_out;
2489 idiag.ptr_private = phba->sli4_hba.els_wq;
2490 goto pass_check;
2491 }
2492 /* FCP work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002493 if (phba->sli4_hba.fcp_wq) {
2494 for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
2495 if (!phba->sli4_hba.fcp_wq[qidx])
2496 continue;
2497 if (phba->sli4_hba.fcp_wq[qidx]->queue_id ==
2498 queid) {
2499 /* Sanity check */
2500 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002501 phba->sli4_hba.fcp_wq[qidx],
2502 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002503 if (rc)
2504 goto error_out;
2505 idiag.ptr_private =
2506 phba->sli4_hba.fcp_wq[qidx];
2507 goto pass_check;
2508 }
James Smart86a80842011-04-16 11:03:04 -04002509 }
2510 }
2511 goto error_out;
2512 break;
2513 case LPFC_IDIAG_RQ:
2514 /* HDR queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002515 if (phba->sli4_hba.hdr_rq &&
2516 phba->sli4_hba.hdr_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002517 /* Sanity check */
2518 rc = lpfc_idiag_que_param_check(
2519 phba->sli4_hba.hdr_rq, index, count);
2520 if (rc)
2521 goto error_out;
2522 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2523 goto pass_check;
2524 }
2525 /* DAT queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002526 if (phba->sli4_hba.dat_rq &&
2527 phba->sli4_hba.dat_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002528 /* Sanity check */
2529 rc = lpfc_idiag_que_param_check(
2530 phba->sli4_hba.dat_rq, index, count);
2531 if (rc)
2532 goto error_out;
2533 idiag.ptr_private = phba->sli4_hba.dat_rq;
2534 goto pass_check;
2535 }
2536 goto error_out;
2537 break;
2538 default:
2539 goto error_out;
2540 break;
2541 }
2542
2543pass_check:
2544
2545 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2546 if (count == LPFC_QUE_ACC_BROWSE)
2547 idiag.offset.last_rd = index;
2548 }
2549
2550 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2551 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2552 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2553 /* Additional sanity checks on write operation */
2554 pque = (struct lpfc_queue *)idiag.ptr_private;
2555 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2556 goto error_out;
2557 pentry = pque->qe[index].address;
2558 pentry += offset;
2559 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2560 *pentry = value;
2561 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2562 *pentry |= value;
2563 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2564 *pentry &= ~value;
2565 }
2566 return nbytes;
2567
2568error_out:
2569 /* Clean out command structure on command error out */
2570 memset(&idiag, 0, sizeof(idiag));
2571 return -EINVAL;
2572}
2573
2574/**
2575 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2576 * @phba: The pointer to hba structure.
2577 * @pbuffer: The pointer to the buffer to copy the data to.
2578 * @len: The lenght of bytes to copied.
2579 * @drbregid: The id to doorbell registers.
2580 *
2581 * Description:
2582 * This routine reads a doorbell register and copies its content to the
2583 * user buffer pointed to by @pbuffer.
2584 *
2585 * Returns:
2586 * This function returns the amount of data that was copied into @pbuffer.
2587 **/
2588static int
2589lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2590 int len, uint32_t drbregid)
2591{
2592
2593 if (!pbuffer)
2594 return 0;
2595
2596 switch (drbregid) {
2597 case LPFC_DRB_EQCQ:
2598 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2599 "EQCQ-DRB-REG: 0x%08x\n",
2600 readl(phba->sli4_hba.EQCQDBregaddr));
2601 break;
2602 case LPFC_DRB_MQ:
2603 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2604 "MQ-DRB-REG: 0x%08x\n",
2605 readl(phba->sli4_hba.MQDBregaddr));
2606 break;
2607 case LPFC_DRB_WQ:
2608 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2609 "WQ-DRB-REG: 0x%08x\n",
2610 readl(phba->sli4_hba.WQDBregaddr));
2611 break;
2612 case LPFC_DRB_RQ:
2613 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2614 "RQ-DRB-REG: 0x%08x\n",
2615 readl(phba->sli4_hba.RQDBregaddr));
2616 break;
2617 default:
2618 break;
2619 }
2620
2621 return len;
2622}
2623
2624/**
2625 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2626 * @file: The file pointer to read from.
2627 * @buf: The buffer to copy the data to.
2628 * @nbytes: The number of bytes to read.
2629 * @ppos: The position in the file to start reading from.
2630 *
2631 * Description:
2632 * This routine reads data from the @phba device doorbell register according
2633 * to the idiag command, and copies to user @buf. Depending on the doorbell
2634 * register read command setup, it does either a single doorbell register
2635 * read or dump all doorbell registers.
2636 *
2637 * Returns:
2638 * This function returns the amount of data that was read (this could be less
2639 * than @nbytes if the end of the file was reached) or a negative error value.
2640 **/
2641static ssize_t
2642lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2643 loff_t *ppos)
2644{
2645 struct lpfc_debug *debug = file->private_data;
2646 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2647 uint32_t drb_reg_id, i;
2648 char *pbuffer;
2649 int len = 0;
2650
2651 /* This is a user read operation */
2652 debug->op = LPFC_IDIAG_OP_RD;
2653
2654 if (!debug->buffer)
2655 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2656 if (!debug->buffer)
2657 return 0;
2658 pbuffer = debug->buffer;
2659
2660 if (*ppos)
2661 return 0;
2662
2663 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
James Smartb76f2dc2011-07-22 18:37:42 -04002664 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
James Smart86a80842011-04-16 11:03:04 -04002665 else
2666 return 0;
2667
2668 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2669 for (i = 1; i <= LPFC_DRB_MAX; i++)
2670 len = lpfc_idiag_drbacc_read_reg(phba,
2671 pbuffer, len, i);
2672 else
2673 len = lpfc_idiag_drbacc_read_reg(phba,
2674 pbuffer, len, drb_reg_id);
2675
2676 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2677}
2678
2679/**
2680 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2681 * @file: The file pointer to read from.
2682 * @buf: The buffer to copy the user data from.
2683 * @nbytes: The number of bytes to get.
2684 * @ppos: The position in the file to start reading from.
2685 *
2686 * This routine get the debugfs idiag command struct from user space and then
2687 * perform the syntax check for port doorbell register read (dump) or write
2688 * (set) command accordingly. In the case of port queue read command, it sets
2689 * up the command in the idiag command struct for the following debugfs read
2690 * operation. In the case of port doorbell register write operation, it
2691 * executes the write operation into the port doorbell register accordingly.
2692 *
2693 * It returns the @nbytges passing in from debugfs user space when successful.
2694 * In case of error conditions, it returns proper error code back to the user
2695 * space.
2696 **/
2697static ssize_t
2698lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2699 size_t nbytes, loff_t *ppos)
2700{
2701 struct lpfc_debug *debug = file->private_data;
2702 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
James Smartb76f2dc2011-07-22 18:37:42 -04002703 uint32_t drb_reg_id, value, reg_val = 0;
James Smart86a80842011-04-16 11:03:04 -04002704 void __iomem *drb_reg;
2705 int rc;
2706
2707 /* This is a user write operation */
2708 debug->op = LPFC_IDIAG_OP_WR;
2709
2710 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2711 if (rc < 0)
2712 return rc;
2713
2714 /* Sanity check on command line arguments */
James Smartb76f2dc2011-07-22 18:37:42 -04002715 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2716 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04002717
2718 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2719 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2720 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2721 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2722 goto error_out;
2723 if (drb_reg_id > LPFC_DRB_MAX)
2724 goto error_out;
2725 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2726 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2727 goto error_out;
2728 if ((drb_reg_id > LPFC_DRB_MAX) &&
2729 (drb_reg_id != LPFC_DRB_ACC_ALL))
2730 goto error_out;
2731 } else
2732 goto error_out;
2733
2734 /* Perform the write access operation */
2735 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2736 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2737 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2738 switch (drb_reg_id) {
2739 case LPFC_DRB_EQCQ:
2740 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2741 break;
2742 case LPFC_DRB_MQ:
2743 drb_reg = phba->sli4_hba.MQDBregaddr;
2744 break;
2745 case LPFC_DRB_WQ:
2746 drb_reg = phba->sli4_hba.WQDBregaddr;
2747 break;
2748 case LPFC_DRB_RQ:
2749 drb_reg = phba->sli4_hba.RQDBregaddr;
2750 break;
2751 default:
2752 goto error_out;
2753 }
2754
2755 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2756 reg_val = value;
2757 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2758 reg_val = readl(drb_reg);
2759 reg_val |= value;
2760 }
2761 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2762 reg_val = readl(drb_reg);
2763 reg_val &= ~value;
2764 }
2765 writel(reg_val, drb_reg);
2766 readl(drb_reg); /* flush */
2767 }
2768 return nbytes;
2769
2770error_out:
2771 /* Clean out command structure on command error out */
2772 memset(&idiag, 0, sizeof(idiag));
2773 return -EINVAL;
2774}
2775
James Smartb76f2dc2011-07-22 18:37:42 -04002776/**
2777 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2778 * @phba: The pointer to hba structure.
2779 * @pbuffer: The pointer to the buffer to copy the data to.
2780 * @len: The lenght of bytes to copied.
2781 * @drbregid: The id to doorbell registers.
2782 *
2783 * Description:
2784 * This routine reads a control register and copies its content to the
2785 * user buffer pointed to by @pbuffer.
2786 *
2787 * Returns:
2788 * This function returns the amount of data that was copied into @pbuffer.
2789 **/
2790static int
2791lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2792 int len, uint32_t ctlregid)
2793{
2794
2795 if (!pbuffer)
2796 return 0;
2797
2798 switch (ctlregid) {
2799 case LPFC_CTL_PORT_SEM:
2800 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2801 "Port SemReg: 0x%08x\n",
2802 readl(phba->sli4_hba.conf_regs_memmap_p +
2803 LPFC_CTL_PORT_SEM_OFFSET));
2804 break;
2805 case LPFC_CTL_PORT_STA:
2806 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2807 "Port StaReg: 0x%08x\n",
2808 readl(phba->sli4_hba.conf_regs_memmap_p +
2809 LPFC_CTL_PORT_STA_OFFSET));
2810 break;
2811 case LPFC_CTL_PORT_CTL:
2812 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2813 "Port CtlReg: 0x%08x\n",
2814 readl(phba->sli4_hba.conf_regs_memmap_p +
2815 LPFC_CTL_PORT_CTL_OFFSET));
2816 break;
2817 case LPFC_CTL_PORT_ER1:
2818 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2819 "Port Er1Reg: 0x%08x\n",
2820 readl(phba->sli4_hba.conf_regs_memmap_p +
2821 LPFC_CTL_PORT_ER1_OFFSET));
2822 break;
2823 case LPFC_CTL_PORT_ER2:
2824 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2825 "Port Er2Reg: 0x%08x\n",
2826 readl(phba->sli4_hba.conf_regs_memmap_p +
2827 LPFC_CTL_PORT_ER2_OFFSET));
2828 break;
2829 case LPFC_CTL_PDEV_CTL:
2830 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2831 "PDev CtlReg: 0x%08x\n",
2832 readl(phba->sli4_hba.conf_regs_memmap_p +
2833 LPFC_CTL_PDEV_CTL_OFFSET));
2834 break;
2835 default:
2836 break;
2837 }
2838 return len;
2839}
2840
2841/**
2842 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2843 * @file: The file pointer to read from.
2844 * @buf: The buffer to copy the data to.
2845 * @nbytes: The number of bytes to read.
2846 * @ppos: The position in the file to start reading from.
2847 *
2848 * Description:
2849 * This routine reads data from the @phba port and device registers according
2850 * to the idiag command, and copies to user @buf.
2851 *
2852 * Returns:
2853 * This function returns the amount of data that was read (this could be less
2854 * than @nbytes if the end of the file was reached) or a negative error value.
2855 **/
2856static ssize_t
2857lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2858 loff_t *ppos)
2859{
2860 struct lpfc_debug *debug = file->private_data;
2861 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2862 uint32_t ctl_reg_id, i;
2863 char *pbuffer;
2864 int len = 0;
2865
2866 /* This is a user read operation */
2867 debug->op = LPFC_IDIAG_OP_RD;
2868
2869 if (!debug->buffer)
2870 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2871 if (!debug->buffer)
2872 return 0;
2873 pbuffer = debug->buffer;
2874
2875 if (*ppos)
2876 return 0;
2877
2878 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2879 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2880 else
2881 return 0;
2882
2883 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2884 for (i = 1; i <= LPFC_CTL_MAX; i++)
2885 len = lpfc_idiag_ctlacc_read_reg(phba,
2886 pbuffer, len, i);
2887 else
2888 len = lpfc_idiag_ctlacc_read_reg(phba,
2889 pbuffer, len, ctl_reg_id);
2890
2891 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2892}
2893
2894/**
2895 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2896 * @file: The file pointer to read from.
2897 * @buf: The buffer to copy the user data from.
2898 * @nbytes: The number of bytes to get.
2899 * @ppos: The position in the file to start reading from.
2900 *
2901 * This routine get the debugfs idiag command struct from user space and then
2902 * perform the syntax check for port and device control register read (dump)
2903 * or write (set) command accordingly.
2904 *
2905 * It returns the @nbytges passing in from debugfs user space when successful.
2906 * In case of error conditions, it returns proper error code back to the user
2907 * space.
2908 **/
2909static ssize_t
2910lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
2911 size_t nbytes, loff_t *ppos)
2912{
2913 struct lpfc_debug *debug = file->private_data;
2914 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2915 uint32_t ctl_reg_id, value, reg_val = 0;
2916 void __iomem *ctl_reg;
2917 int rc;
2918
2919 /* This is a user write operation */
2920 debug->op = LPFC_IDIAG_OP_WR;
2921
2922 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2923 if (rc < 0)
2924 return rc;
2925
2926 /* Sanity check on command line arguments */
2927 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2928 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
2929
2930 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2931 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2932 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2933 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
2934 goto error_out;
2935 if (ctl_reg_id > LPFC_CTL_MAX)
2936 goto error_out;
2937 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
2938 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
2939 goto error_out;
2940 if ((ctl_reg_id > LPFC_CTL_MAX) &&
2941 (ctl_reg_id != LPFC_CTL_ACC_ALL))
2942 goto error_out;
2943 } else
2944 goto error_out;
2945
2946 /* Perform the write access operation */
2947 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2948 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2949 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2950 switch (ctl_reg_id) {
2951 case LPFC_CTL_PORT_SEM:
2952 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2953 LPFC_CTL_PORT_SEM_OFFSET;
2954 break;
2955 case LPFC_CTL_PORT_STA:
2956 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2957 LPFC_CTL_PORT_STA_OFFSET;
2958 break;
2959 case LPFC_CTL_PORT_CTL:
2960 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2961 LPFC_CTL_PORT_CTL_OFFSET;
2962 break;
2963 case LPFC_CTL_PORT_ER1:
2964 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2965 LPFC_CTL_PORT_ER1_OFFSET;
2966 break;
2967 case LPFC_CTL_PORT_ER2:
2968 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2969 LPFC_CTL_PORT_ER2_OFFSET;
2970 break;
2971 case LPFC_CTL_PDEV_CTL:
2972 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2973 LPFC_CTL_PDEV_CTL_OFFSET;
2974 break;
2975 default:
2976 goto error_out;
2977 }
2978
2979 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
2980 reg_val = value;
2981 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
2982 reg_val = readl(ctl_reg);
2983 reg_val |= value;
2984 }
2985 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2986 reg_val = readl(ctl_reg);
2987 reg_val &= ~value;
2988 }
2989 writel(reg_val, ctl_reg);
2990 readl(ctl_reg); /* flush */
2991 }
2992 return nbytes;
2993
2994error_out:
2995 /* Clean out command structure on command error out */
2996 memset(&idiag, 0, sizeof(idiag));
2997 return -EINVAL;
2998}
2999
3000/**
3001 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
3002 * @phba: Pointer to HBA context object.
3003 * @pbuffer: Pointer to data buffer.
3004 *
3005 * Description:
3006 * This routine gets the driver mailbox access debugfs setup information.
3007 *
3008 * Returns:
3009 * This function returns the amount of data that was read (this could be less
3010 * than @nbytes if the end of the file was reached) or a negative error value.
3011 **/
3012static int
3013lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
3014{
3015 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3016 int len = 0;
3017
3018 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3019 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3020 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3021 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3022
3023 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3024 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
3025 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3026 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
3027 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3028 "mbx_word_cnt: %04d\n", mbx_word_cnt);
3029 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3030 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
3031
3032 return len;
3033}
3034
3035/**
3036 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
3037 * @file: The file pointer to read from.
3038 * @buf: The buffer to copy the data to.
3039 * @nbytes: The number of bytes to read.
3040 * @ppos: The position in the file to start reading from.
3041 *
3042 * Description:
3043 * This routine reads data from the @phba driver mailbox access debugfs setup
3044 * information.
3045 *
3046 * Returns:
3047 * This function returns the amount of data that was read (this could be less
3048 * than @nbytes if the end of the file was reached) or a negative error value.
3049 **/
3050static ssize_t
3051lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
3052 loff_t *ppos)
3053{
3054 struct lpfc_debug *debug = file->private_data;
3055 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3056 char *pbuffer;
3057 int len = 0;
3058
3059 /* This is a user read operation */
3060 debug->op = LPFC_IDIAG_OP_RD;
3061
3062 if (!debug->buffer)
3063 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
3064 if (!debug->buffer)
3065 return 0;
3066 pbuffer = debug->buffer;
3067
3068 if (*ppos)
3069 return 0;
3070
3071 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
3072 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
3073 return 0;
3074
3075 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
3076
3077 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3078}
3079
3080/**
3081 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
3082 * @file: The file pointer to read from.
3083 * @buf: The buffer to copy the user data from.
3084 * @nbytes: The number of bytes to get.
3085 * @ppos: The position in the file to start reading from.
3086 *
3087 * This routine get the debugfs idiag command struct from user space and then
3088 * perform the syntax check for driver mailbox command (dump) and sets up the
3089 * necessary states in the idiag command struct accordingly.
3090 *
3091 * It returns the @nbytges passing in from debugfs user space when successful.
3092 * In case of error conditions, it returns proper error code back to the user
3093 * space.
3094 **/
3095static ssize_t
3096lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
3097 size_t nbytes, loff_t *ppos)
3098{
3099 struct lpfc_debug *debug = file->private_data;
3100 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3101 int rc;
3102
3103 /* This is a user write operation */
3104 debug->op = LPFC_IDIAG_OP_WR;
3105
3106 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3107 if (rc < 0)
3108 return rc;
3109
3110 /* Sanity check on command line arguments */
3111 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3112 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3113 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3114 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3115
3116 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
3117 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
3118 goto error_out;
3119 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
3120 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3121 goto error_out;
3122 if (mbx_word_cnt > sizeof(MAILBOX_t))
3123 goto error_out;
3124 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
3125 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
3126 goto error_out;
3127 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
3128 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3129 goto error_out;
3130 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3131 goto error_out;
3132 if (mbx_mbox_cmd != 0x9b)
3133 goto error_out;
3134 } else
3135 goto error_out;
3136
3137 if (mbx_word_cnt == 0)
3138 goto error_out;
3139 if (rc != LPFC_MBX_DMP_ARG)
3140 goto error_out;
3141 if (mbx_mbox_cmd & ~0xff)
3142 goto error_out;
3143
3144 /* condition for stop mailbox dump */
3145 if (mbx_dump_cnt == 0)
3146 goto reset_out;
3147
3148 return nbytes;
3149
3150reset_out:
3151 /* Clean out command structure on command error out */
3152 memset(&idiag, 0, sizeof(idiag));
3153 return nbytes;
3154
3155error_out:
3156 /* Clean out command structure on command error out */
3157 memset(&idiag, 0, sizeof(idiag));
3158 return -EINVAL;
3159}
3160
3161/**
3162 * lpfc_idiag_extacc_avail_get - get the available extents information
3163 * @phba: pointer to lpfc hba data structure.
3164 * @pbuffer: pointer to internal buffer.
3165 * @len: length into the internal buffer data has been copied.
3166 *
3167 * Description:
3168 * This routine is to get the available extent information.
3169 *
3170 * Returns:
3171 * overall lenth of the data read into the internal buffer.
3172 **/
3173static int
3174lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3175{
3176 uint16_t ext_cnt, ext_size;
3177
3178 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3179 "\nAvailable Extents Information:\n");
3180
3181 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3182 "\tPort Available VPI extents: ");
3183 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3184 &ext_cnt, &ext_size);
3185 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3186 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3187
3188 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3189 "\tPort Available VFI extents: ");
3190 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3191 &ext_cnt, &ext_size);
3192 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3193 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3194
3195 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3196 "\tPort Available RPI extents: ");
3197 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3198 &ext_cnt, &ext_size);
3199 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3200 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3201
3202 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3203 "\tPort Available XRI extents: ");
3204 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3205 &ext_cnt, &ext_size);
3206 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3207 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3208
3209 return len;
3210}
3211
3212/**
3213 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3214 * @phba: pointer to lpfc hba data structure.
3215 * @pbuffer: pointer to internal buffer.
3216 * @len: length into the internal buffer data has been copied.
3217 *
3218 * Description:
3219 * This routine is to get the allocated extent information.
3220 *
3221 * Returns:
3222 * overall lenth of the data read into the internal buffer.
3223 **/
3224static int
3225lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3226{
3227 uint16_t ext_cnt, ext_size;
3228 int rc;
3229
3230 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3231 "\nAllocated Extents Information:\n");
3232
3233 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3234 "\tHost Allocated VPI extents: ");
3235 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
3236 &ext_cnt, &ext_size);
3237 if (!rc)
3238 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3239 "Port %d Extent %3d, Size %3d\n",
3240 phba->brd_no, ext_cnt, ext_size);
3241 else
3242 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3243 "N/A\n");
3244
3245 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3246 "\tHost Allocated VFI extents: ");
3247 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
3248 &ext_cnt, &ext_size);
3249 if (!rc)
3250 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3251 "Port %d Extent %3d, Size %3d\n",
3252 phba->brd_no, ext_cnt, ext_size);
3253 else
3254 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3255 "N/A\n");
3256
3257 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3258 "\tHost Allocated RPI extents: ");
3259 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
3260 &ext_cnt, &ext_size);
3261 if (!rc)
3262 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3263 "Port %d Extent %3d, Size %3d\n",
3264 phba->brd_no, ext_cnt, ext_size);
3265 else
3266 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3267 "N/A\n");
3268
3269 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3270 "\tHost Allocated XRI extents: ");
3271 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
3272 &ext_cnt, &ext_size);
3273 if (!rc)
3274 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3275 "Port %d Extent %3d, Size %3d\n",
3276 phba->brd_no, ext_cnt, ext_size);
3277 else
3278 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3279 "N/A\n");
3280
3281 return len;
3282}
3283
3284/**
3285 * lpfc_idiag_extacc_drivr_get - get driver extent information
3286 * @phba: pointer to lpfc hba data structure.
3287 * @pbuffer: pointer to internal buffer.
3288 * @len: length into the internal buffer data has been copied.
3289 *
3290 * Description:
3291 * This routine is to get the driver extent information.
3292 *
3293 * Returns:
3294 * overall lenth of the data read into the internal buffer.
3295 **/
3296static int
3297lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3298{
3299 struct lpfc_rsrc_blks *rsrc_blks;
3300 int index;
3301
3302 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3303 "\nDriver Extents Information:\n");
3304
3305 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3306 "\tVPI extents:\n");
3307 index = 0;
3308 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3309 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3310 "\t\tBlock %3d: Start %4d, Count %4d\n",
3311 index, rsrc_blks->rsrc_start,
3312 rsrc_blks->rsrc_size);
3313 index++;
3314 }
3315 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3316 "\tVFI extents:\n");
3317 index = 0;
3318 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
3319 list) {
3320 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3321 "\t\tBlock %3d: Start %4d, Count %4d\n",
3322 index, rsrc_blks->rsrc_start,
3323 rsrc_blks->rsrc_size);
3324 index++;
3325 }
3326
3327 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3328 "\tRPI extents:\n");
3329 index = 0;
3330 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
3331 list) {
3332 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3333 "\t\tBlock %3d: Start %4d, Count %4d\n",
3334 index, rsrc_blks->rsrc_start,
3335 rsrc_blks->rsrc_size);
3336 index++;
3337 }
3338
3339 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3340 "\tXRI extents:\n");
3341 index = 0;
3342 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
3343 list) {
3344 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3345 "\t\tBlock %3d: Start %4d, Count %4d\n",
3346 index, rsrc_blks->rsrc_start,
3347 rsrc_blks->rsrc_size);
3348 index++;
3349 }
3350
3351 return len;
3352}
3353
3354/**
3355 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3356 * @file: The file pointer to read from.
3357 * @buf: The buffer to copy the user data from.
3358 * @nbytes: The number of bytes to get.
3359 * @ppos: The position in the file to start reading from.
3360 *
3361 * This routine get the debugfs idiag command struct from user space and then
3362 * perform the syntax check for extent information access commands and sets
3363 * up the necessary states in the idiag command struct accordingly.
3364 *
3365 * It returns the @nbytges passing in from debugfs user space when successful.
3366 * In case of error conditions, it returns proper error code back to the user
3367 * space.
3368 **/
3369static ssize_t
3370lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3371 size_t nbytes, loff_t *ppos)
3372{
3373 struct lpfc_debug *debug = file->private_data;
3374 uint32_t ext_map;
3375 int rc;
3376
3377 /* This is a user write operation */
3378 debug->op = LPFC_IDIAG_OP_WR;
3379
3380 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3381 if (rc < 0)
3382 return rc;
3383
3384 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3385
3386 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3387 goto error_out;
3388 if (rc != LPFC_EXT_ACC_CMD_ARG)
3389 goto error_out;
3390 if (!(ext_map & LPFC_EXT_ACC_ALL))
3391 goto error_out;
3392
3393 return nbytes;
3394error_out:
3395 /* Clean out command structure on command error out */
3396 memset(&idiag, 0, sizeof(idiag));
3397 return -EINVAL;
3398}
3399
3400/**
3401 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3402 * @file: The file pointer to read from.
3403 * @buf: The buffer to copy the data to.
3404 * @nbytes: The number of bytes to read.
3405 * @ppos: The position in the file to start reading from.
3406 *
3407 * Description:
3408 * This routine reads data from the proper extent information according to
3409 * the idiag command, and copies to user @buf.
3410 *
3411 * Returns:
3412 * This function returns the amount of data that was read (this could be less
3413 * than @nbytes if the end of the file was reached) or a negative error value.
3414 **/
3415static ssize_t
3416lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3417 loff_t *ppos)
3418{
3419 struct lpfc_debug *debug = file->private_data;
3420 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3421 char *pbuffer;
3422 uint32_t ext_map;
3423 int len = 0;
3424
3425 /* This is a user read operation */
3426 debug->op = LPFC_IDIAG_OP_RD;
3427
3428 if (!debug->buffer)
3429 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3430 if (!debug->buffer)
3431 return 0;
3432 pbuffer = debug->buffer;
3433 if (*ppos)
3434 return 0;
3435 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3436 return 0;
3437
3438 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3439 if (ext_map & LPFC_EXT_ACC_AVAIL)
3440 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3441 if (ext_map & LPFC_EXT_ACC_ALLOC)
3442 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3443 if (ext_map & LPFC_EXT_ACC_DRIVR)
3444 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3445
3446 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3447}
3448
James Smart858c9f62007-06-17 19:56:39 -05003449#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003450static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05003451 .owner = THIS_MODULE,
3452 .open = lpfc_debugfs_disc_trc_open,
3453 .llseek = lpfc_debugfs_lseek,
3454 .read = lpfc_debugfs_read,
3455 .release = lpfc_debugfs_release,
3456};
3457
3458#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003459static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05003460 .owner = THIS_MODULE,
3461 .open = lpfc_debugfs_nodelist_open,
3462 .llseek = lpfc_debugfs_lseek,
3463 .read = lpfc_debugfs_read,
3464 .release = lpfc_debugfs_release,
3465};
3466
James Smart78b2d852007-08-02 11:10:21 -04003467#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003468static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04003469 .owner = THIS_MODULE,
3470 .open = lpfc_debugfs_hbqinfo_open,
3471 .llseek = lpfc_debugfs_lseek,
3472 .read = lpfc_debugfs_read,
3473 .release = lpfc_debugfs_release,
3474};
3475
James Smartc95d6c62008-01-11 01:53:23 -05003476#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003477static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04003478 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05003479 .open = lpfc_debugfs_dumpHBASlim_open,
3480 .llseek = lpfc_debugfs_lseek,
3481 .read = lpfc_debugfs_read,
3482 .release = lpfc_debugfs_release,
3483};
3484
3485#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003486static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05003487 .owner = THIS_MODULE,
3488 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04003489 .llseek = lpfc_debugfs_lseek,
3490 .read = lpfc_debugfs_read,
3491 .release = lpfc_debugfs_release,
3492};
3493
James Smarte2a0a9d2008-12-04 22:40:02 -05003494#undef lpfc_debugfs_op_dumpData
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003495static const struct file_operations lpfc_debugfs_op_dumpData = {
James Smarte2a0a9d2008-12-04 22:40:02 -05003496 .owner = THIS_MODULE,
3497 .open = lpfc_debugfs_dumpData_open,
3498 .llseek = lpfc_debugfs_lseek,
3499 .read = lpfc_debugfs_read,
3500 .write = lpfc_debugfs_dumpDataDif_write,
3501 .release = lpfc_debugfs_dumpDataDif_release,
3502};
3503
3504#undef lpfc_debugfs_op_dumpDif
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003505static const struct file_operations lpfc_debugfs_op_dumpDif = {
James Smarte2a0a9d2008-12-04 22:40:02 -05003506 .owner = THIS_MODULE,
3507 .open = lpfc_debugfs_dumpDif_open,
3508 .llseek = lpfc_debugfs_lseek,
3509 .read = lpfc_debugfs_read,
3510 .write = lpfc_debugfs_dumpDataDif_write,
3511 .release = lpfc_debugfs_dumpDataDif_release,
3512};
3513
James Smartf9bb2da2011-10-10 21:34:11 -04003514#undef lpfc_debugfs_op_dif_err
3515static const struct file_operations lpfc_debugfs_op_dif_err = {
3516 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07003517 .open = simple_open,
James Smartf9bb2da2011-10-10 21:34:11 -04003518 .llseek = lpfc_debugfs_lseek,
3519 .read = lpfc_debugfs_dif_err_read,
3520 .write = lpfc_debugfs_dif_err_write,
3521 .release = lpfc_debugfs_dif_err_release,
3522};
3523
James Smarta58cbd52007-08-02 11:09:43 -04003524#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003525static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04003526 .owner = THIS_MODULE,
3527 .open = lpfc_debugfs_slow_ring_trc_open,
3528 .llseek = lpfc_debugfs_lseek,
3529 .read = lpfc_debugfs_read,
3530 .release = lpfc_debugfs_release,
3531};
3532
James Smart858c9f62007-06-17 19:56:39 -05003533static struct dentry *lpfc_debugfs_root = NULL;
3534static atomic_t lpfc_debugfs_hba_count;
James Smart2a622bf2011-02-16 12:40:06 -05003535
3536/*
3537 * File operations for the iDiag debugfs
3538 */
3539#undef lpfc_idiag_op_pciCfg
3540static const struct file_operations lpfc_idiag_op_pciCfg = {
3541 .owner = THIS_MODULE,
3542 .open = lpfc_idiag_open,
3543 .llseek = lpfc_debugfs_lseek,
3544 .read = lpfc_idiag_pcicfg_read,
3545 .write = lpfc_idiag_pcicfg_write,
3546 .release = lpfc_idiag_cmd_release,
3547};
3548
James Smartb76f2dc2011-07-22 18:37:42 -04003549#undef lpfc_idiag_op_barAcc
3550static const struct file_operations lpfc_idiag_op_barAcc = {
3551 .owner = THIS_MODULE,
3552 .open = lpfc_idiag_open,
3553 .llseek = lpfc_debugfs_lseek,
3554 .read = lpfc_idiag_baracc_read,
3555 .write = lpfc_idiag_baracc_write,
3556 .release = lpfc_idiag_cmd_release,
3557};
3558
James Smart2a622bf2011-02-16 12:40:06 -05003559#undef lpfc_idiag_op_queInfo
3560static const struct file_operations lpfc_idiag_op_queInfo = {
3561 .owner = THIS_MODULE,
3562 .open = lpfc_idiag_open,
3563 .read = lpfc_idiag_queinfo_read,
3564 .release = lpfc_idiag_release,
3565};
3566
James Smartb76f2dc2011-07-22 18:37:42 -04003567#undef lpfc_idiag_op_queAcc
James Smart86a80842011-04-16 11:03:04 -04003568static const struct file_operations lpfc_idiag_op_queAcc = {
3569 .owner = THIS_MODULE,
3570 .open = lpfc_idiag_open,
3571 .llseek = lpfc_debugfs_lseek,
3572 .read = lpfc_idiag_queacc_read,
3573 .write = lpfc_idiag_queacc_write,
3574 .release = lpfc_idiag_cmd_release,
3575};
3576
James Smartb76f2dc2011-07-22 18:37:42 -04003577#undef lpfc_idiag_op_drbAcc
James Smart86a80842011-04-16 11:03:04 -04003578static const struct file_operations lpfc_idiag_op_drbAcc = {
3579 .owner = THIS_MODULE,
3580 .open = lpfc_idiag_open,
3581 .llseek = lpfc_debugfs_lseek,
3582 .read = lpfc_idiag_drbacc_read,
3583 .write = lpfc_idiag_drbacc_write,
3584 .release = lpfc_idiag_cmd_release,
3585};
3586
James Smartb76f2dc2011-07-22 18:37:42 -04003587#undef lpfc_idiag_op_ctlAcc
3588static const struct file_operations lpfc_idiag_op_ctlAcc = {
3589 .owner = THIS_MODULE,
3590 .open = lpfc_idiag_open,
3591 .llseek = lpfc_debugfs_lseek,
3592 .read = lpfc_idiag_ctlacc_read,
3593 .write = lpfc_idiag_ctlacc_write,
3594 .release = lpfc_idiag_cmd_release,
3595};
3596
3597#undef lpfc_idiag_op_mbxAcc
3598static const struct file_operations lpfc_idiag_op_mbxAcc = {
3599 .owner = THIS_MODULE,
3600 .open = lpfc_idiag_open,
3601 .llseek = lpfc_debugfs_lseek,
3602 .read = lpfc_idiag_mbxacc_read,
3603 .write = lpfc_idiag_mbxacc_write,
3604 .release = lpfc_idiag_cmd_release,
3605};
3606
3607#undef lpfc_idiag_op_extAcc
3608static const struct file_operations lpfc_idiag_op_extAcc = {
3609 .owner = THIS_MODULE,
3610 .open = lpfc_idiag_open,
3611 .llseek = lpfc_debugfs_lseek,
3612 .read = lpfc_idiag_extacc_read,
3613 .write = lpfc_idiag_extacc_write,
3614 .release = lpfc_idiag_cmd_release,
3615};
3616
James Smart858c9f62007-06-17 19:56:39 -05003617#endif
3618
James Smartb76f2dc2011-07-22 18:37:42 -04003619/* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3620 * @phba: Pointer to HBA context object.
3621 * @dmabuf: Pointer to a DMA buffer descriptor.
3622 *
3623 * Description:
3624 * This routine dump a bsg pass-through non-embedded mailbox command with
3625 * external buffer.
3626 **/
3627void
3628lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3629 enum mbox_type mbox_tp, enum dma_type dma_tp,
3630 enum sta_type sta_tp,
3631 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3632{
3633#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3634 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3635 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3636 int len = 0;
3637 uint32_t do_dump = 0;
3638 uint32_t *pword;
3639 uint32_t i;
3640
3641 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3642 return;
3643
3644 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3645 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3646 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3647 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3648
3649 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3650 (*mbx_dump_cnt == 0) ||
3651 (*mbx_word_cnt == 0))
3652 return;
3653
3654 if (*mbx_mbox_cmd != 0x9B)
3655 return;
3656
3657 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3658 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3659 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
3660 printk(KERN_ERR "\nRead mbox command (x%x), "
3661 "nemb:0x%x, extbuf_cnt:%d:\n",
3662 sta_tp, nemb_tp, ext_buf);
3663 }
3664 }
3665 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3666 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3667 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
3668 printk(KERN_ERR "\nRead mbox buffer (x%x), "
3669 "nemb:0x%x, extbuf_seq:%d:\n",
3670 sta_tp, nemb_tp, ext_buf);
3671 }
3672 }
3673 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3674 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3675 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
3676 printk(KERN_ERR "\nWrite mbox command (x%x), "
3677 "nemb:0x%x, extbuf_cnt:%d:\n",
3678 sta_tp, nemb_tp, ext_buf);
3679 }
3680 }
3681 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3682 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3683 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
3684 printk(KERN_ERR "\nWrite mbox buffer (x%x), "
3685 "nemb:0x%x, extbuf_seq:%d:\n",
3686 sta_tp, nemb_tp, ext_buf);
3687 }
3688 }
3689
3690 /* dump buffer content */
3691 if (do_dump) {
3692 pword = (uint32_t *)dmabuf->virt;
3693 for (i = 0; i < *mbx_word_cnt; i++) {
3694 if (!(i % 8)) {
3695 if (i != 0)
3696 printk(KERN_ERR "%s\n", line_buf);
3697 len = 0;
3698 len += snprintf(line_buf+len,
3699 LPFC_MBX_ACC_LBUF_SZ-len,
3700 "%03d: ", i);
3701 }
3702 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3703 "%08x ", (uint32_t)*pword);
3704 pword++;
3705 }
3706 if ((i - 1) % 8)
3707 printk(KERN_ERR "%s\n", line_buf);
3708 (*mbx_dump_cnt)--;
3709 }
3710
3711 /* Clean out command structure on reaching dump count */
3712 if (*mbx_dump_cnt == 0)
3713 memset(&idiag, 0, sizeof(idiag));
3714 return;
3715#endif
3716}
3717
3718/* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3719 * @phba: Pointer to HBA context object.
3720 * @dmabuf: Pointer to a DMA buffer descriptor.
3721 *
3722 * Description:
3723 * This routine dump a pass-through non-embedded mailbox command from issue
3724 * mailbox command.
3725 **/
3726void
3727lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3728{
3729#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3730 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3731 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3732 int len = 0;
3733 uint32_t *pword;
3734 uint8_t *pbyte;
3735 uint32_t i, j;
3736
3737 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3738 return;
3739
3740 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3741 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3742 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3743 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3744
3745 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3746 (*mbx_dump_cnt == 0) ||
3747 (*mbx_word_cnt == 0))
3748 return;
3749
3750 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3751 (*mbx_mbox_cmd != pmbox->mbxCommand))
3752 return;
3753
3754 /* dump buffer content */
3755 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
3756 printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
3757 pmbox->mbxCommand);
3758 pword = (uint32_t *)pmbox;
3759 for (i = 0; i < *mbx_word_cnt; i++) {
3760 if (!(i % 8)) {
3761 if (i != 0)
3762 printk(KERN_ERR "%s\n", line_buf);
3763 len = 0;
3764 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3765 len += snprintf(line_buf+len,
3766 LPFC_MBX_ACC_LBUF_SZ-len,
3767 "%03d: ", i);
3768 }
3769 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3770 "%08x ",
3771 ((uint32_t)*pword) & 0xffffffff);
3772 pword++;
3773 }
3774 if ((i - 1) % 8)
3775 printk(KERN_ERR "%s\n", line_buf);
3776 printk(KERN_ERR "\n");
3777 }
3778 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
3779 printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
3780 pmbox->mbxCommand);
3781 pbyte = (uint8_t *)pmbox;
3782 for (i = 0; i < *mbx_word_cnt; i++) {
3783 if (!(i % 8)) {
3784 if (i != 0)
3785 printk(KERN_ERR "%s\n", line_buf);
3786 len = 0;
3787 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3788 len += snprintf(line_buf+len,
3789 LPFC_MBX_ACC_LBUF_SZ-len,
3790 "%03d: ", i);
3791 }
3792 for (j = 0; j < 4; j++) {
3793 len += snprintf(line_buf+len,
3794 LPFC_MBX_ACC_LBUF_SZ-len,
3795 "%02x",
3796 ((uint8_t)*pbyte) & 0xff);
3797 pbyte++;
3798 }
3799 len += snprintf(line_buf+len,
3800 LPFC_MBX_ACC_LBUF_SZ-len, " ");
3801 }
3802 if ((i - 1) % 8)
3803 printk(KERN_ERR "%s\n", line_buf);
3804 printk(KERN_ERR "\n");
3805 }
3806 (*mbx_dump_cnt)--;
3807
3808 /* Clean out command structure on reaching dump count */
3809 if (*mbx_dump_cnt == 0)
3810 memset(&idiag, 0, sizeof(idiag));
3811 return;
3812#endif
3813}
3814
James Smarte59058c2008-08-24 21:49:00 -04003815/**
James Smart3621a712009-04-06 18:47:14 -04003816 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04003817 * @vport: The vport pointer to initialize.
3818 *
3819 * Description:
3820 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3821 * If not already created, this routine will create the lpfc directory, and
3822 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3823 * also create each file used to access lpfc specific debugfs information.
3824 **/
James Smart858c9f62007-06-17 19:56:39 -05003825inline void
3826lpfc_debugfs_initialize(struct lpfc_vport *vport)
3827{
James Smart923e4b62008-12-04 22:40:07 -05003828#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05003829 struct lpfc_hba *phba = vport->phba;
3830 char name[64];
3831 uint32_t num, i;
3832
3833 if (!lpfc_debugfs_enable)
3834 return;
3835
James Smarta58cbd52007-08-02 11:09:43 -04003836 /* Setup lpfc root directory */
3837 if (!lpfc_debugfs_root) {
3838 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
3839 atomic_set(&lpfc_debugfs_hba_count, 0);
3840 if (!lpfc_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04003841 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003842 "0408 Cannot create debugfs root\n");
James Smarta58cbd52007-08-02 11:09:43 -04003843 goto debug_failed;
3844 }
3845 }
James Smarta58cbd52007-08-02 11:09:43 -04003846 if (!lpfc_debugfs_start_time)
3847 lpfc_debugfs_start_time = jiffies;
3848
James Smart2a622bf2011-02-16 12:40:06 -05003849 /* Setup funcX directory for specific HBA PCI function */
3850 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
James Smarta58cbd52007-08-02 11:09:43 -04003851 if (!phba->hba_debugfs_root) {
3852 phba->hba_debugfs_root =
3853 debugfs_create_dir(name, lpfc_debugfs_root);
3854 if (!phba->hba_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04003855 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003856 "0412 Cannot create debugfs hba\n");
James Smarta58cbd52007-08-02 11:09:43 -04003857 goto debug_failed;
3858 }
3859 atomic_inc(&lpfc_debugfs_hba_count);
3860 atomic_set(&phba->debugfs_vport_count, 0);
3861
James Smart78b2d852007-08-02 11:10:21 -04003862 /* Setup hbqinfo */
3863 snprintf(name, sizeof(name), "hbqinfo");
3864 phba->debug_hbqinfo =
3865 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3866 phba->hba_debugfs_root,
3867 phba, &lpfc_debugfs_op_hbqinfo);
3868 if (!phba->debug_hbqinfo) {
3869 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003870 "0411 Cannot create debugfs hbqinfo\n");
James Smart78b2d852007-08-02 11:10:21 -04003871 goto debug_failed;
3872 }
3873
James Smartc95d6c62008-01-11 01:53:23 -05003874 /* Setup dumpHBASlim */
James Smart2a622bf2011-02-16 12:40:06 -05003875 if (phba->sli_rev < LPFC_SLI_REV4) {
3876 snprintf(name, sizeof(name), "dumpHBASlim");
3877 phba->debug_dumpHBASlim =
3878 debugfs_create_file(name,
3879 S_IFREG|S_IRUGO|S_IWUSR,
3880 phba->hba_debugfs_root,
3881 phba, &lpfc_debugfs_op_dumpHBASlim);
3882 if (!phba->debug_dumpHBASlim) {
3883 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3884 "0413 Cannot create debugfs "
3885 "dumpHBASlim\n");
3886 goto debug_failed;
3887 }
3888 } else
3889 phba->debug_dumpHBASlim = NULL;
James Smartc95d6c62008-01-11 01:53:23 -05003890
3891 /* Setup dumpHostSlim */
James Smart2a622bf2011-02-16 12:40:06 -05003892 if (phba->sli_rev < LPFC_SLI_REV4) {
3893 snprintf(name, sizeof(name), "dumpHostSlim");
3894 phba->debug_dumpHostSlim =
3895 debugfs_create_file(name,
3896 S_IFREG|S_IRUGO|S_IWUSR,
3897 phba->hba_debugfs_root,
3898 phba, &lpfc_debugfs_op_dumpHostSlim);
3899 if (!phba->debug_dumpHostSlim) {
3900 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3901 "0414 Cannot create debugfs "
3902 "dumpHostSlim\n");
3903 goto debug_failed;
3904 }
3905 } else
3906 phba->debug_dumpHBASlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04003907
James Smarte2a0a9d2008-12-04 22:40:02 -05003908 /* Setup dumpData */
3909 snprintf(name, sizeof(name), "dumpData");
3910 phba->debug_dumpData =
3911 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3912 phba->hba_debugfs_root,
3913 phba, &lpfc_debugfs_op_dumpData);
3914 if (!phba->debug_dumpData) {
3915 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3916 "0800 Cannot create debugfs dumpData\n");
3917 goto debug_failed;
3918 }
3919
3920 /* Setup dumpDif */
3921 snprintf(name, sizeof(name), "dumpDif");
3922 phba->debug_dumpDif =
3923 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3924 phba->hba_debugfs_root,
3925 phba, &lpfc_debugfs_op_dumpDif);
3926 if (!phba->debug_dumpDif) {
3927 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3928 "0801 Cannot create debugfs dumpDif\n");
3929 goto debug_failed;
3930 }
3931
James Smartf9bb2da2011-10-10 21:34:11 -04003932 /* Setup DIF Error Injections */
3933 snprintf(name, sizeof(name), "InjErrLBA");
3934 phba->debug_InjErrLBA =
3935 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3936 phba->hba_debugfs_root,
3937 phba, &lpfc_debugfs_op_dif_err);
3938 if (!phba->debug_InjErrLBA) {
3939 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3940 "0807 Cannot create debugfs InjErrLBA\n");
3941 goto debug_failed;
3942 }
3943 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
3944
3945 snprintf(name, sizeof(name), "writeGuardInjErr");
3946 phba->debug_writeGuard =
3947 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3948 phba->hba_debugfs_root,
3949 phba, &lpfc_debugfs_op_dif_err);
3950 if (!phba->debug_writeGuard) {
3951 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3952 "0802 Cannot create debugfs writeGuard\n");
3953 goto debug_failed;
3954 }
3955
3956 snprintf(name, sizeof(name), "writeAppInjErr");
3957 phba->debug_writeApp =
3958 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3959 phba->hba_debugfs_root,
3960 phba, &lpfc_debugfs_op_dif_err);
3961 if (!phba->debug_writeApp) {
3962 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3963 "0803 Cannot create debugfs writeApp\n");
3964 goto debug_failed;
3965 }
3966
3967 snprintf(name, sizeof(name), "writeRefInjErr");
3968 phba->debug_writeRef =
3969 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3970 phba->hba_debugfs_root,
3971 phba, &lpfc_debugfs_op_dif_err);
3972 if (!phba->debug_writeRef) {
3973 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3974 "0804 Cannot create debugfs writeRef\n");
3975 goto debug_failed;
3976 }
3977
James Smartacd68592012-01-18 16:25:09 -05003978 snprintf(name, sizeof(name), "readGuardInjErr");
3979 phba->debug_readGuard =
3980 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3981 phba->hba_debugfs_root,
3982 phba, &lpfc_debugfs_op_dif_err);
3983 if (!phba->debug_readGuard) {
3984 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3985 "0808 Cannot create debugfs readGuard\n");
3986 goto debug_failed;
3987 }
3988
James Smartf9bb2da2011-10-10 21:34:11 -04003989 snprintf(name, sizeof(name), "readAppInjErr");
3990 phba->debug_readApp =
3991 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3992 phba->hba_debugfs_root,
3993 phba, &lpfc_debugfs_op_dif_err);
3994 if (!phba->debug_readApp) {
3995 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3996 "0805 Cannot create debugfs readApp\n");
3997 goto debug_failed;
3998 }
3999
4000 snprintf(name, sizeof(name), "readRefInjErr");
4001 phba->debug_readRef =
4002 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4003 phba->hba_debugfs_root,
4004 phba, &lpfc_debugfs_op_dif_err);
4005 if (!phba->debug_readRef) {
4006 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4007 "0806 Cannot create debugfs readApp\n");
4008 goto debug_failed;
4009 }
4010
James Smarta58cbd52007-08-02 11:09:43 -04004011 /* Setup slow ring trace */
4012 if (lpfc_debugfs_max_slow_ring_trc) {
4013 num = lpfc_debugfs_max_slow_ring_trc - 1;
4014 if (num & lpfc_debugfs_max_slow_ring_trc) {
4015 /* Change to be a power of 2 */
4016 num = lpfc_debugfs_max_slow_ring_trc;
4017 i = 0;
4018 while (num > 1) {
4019 num = num >> 1;
4020 i++;
4021 }
4022 lpfc_debugfs_max_slow_ring_trc = (1 << i);
4023 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04004024 "lpfc_debugfs_max_disc_trc changed to "
4025 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04004026 }
4027 }
4028
James Smarta58cbd52007-08-02 11:09:43 -04004029 snprintf(name, sizeof(name), "slow_ring_trace");
4030 phba->debug_slow_ring_trc =
4031 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4032 phba->hba_debugfs_root,
4033 phba, &lpfc_debugfs_op_slow_ring_trc);
4034 if (!phba->debug_slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004035 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004036 "0415 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004037 "slow_ring_trace\n");
James Smarta58cbd52007-08-02 11:09:43 -04004038 goto debug_failed;
4039 }
4040 if (!phba->slow_ring_trc) {
4041 phba->slow_ring_trc = kmalloc(
4042 (sizeof(struct lpfc_debugfs_trc) *
4043 lpfc_debugfs_max_slow_ring_trc),
4044 GFP_KERNEL);
4045 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004046 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004047 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004048 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04004049 goto debug_failed;
4050 }
4051 atomic_set(&phba->slow_ring_trc_cnt, 0);
4052 memset(phba->slow_ring_trc, 0,
4053 (sizeof(struct lpfc_debugfs_trc) *
4054 lpfc_debugfs_max_slow_ring_trc));
4055 }
4056 }
4057
4058 snprintf(name, sizeof(name), "vport%d", vport->vpi);
4059 if (!vport->vport_debugfs_root) {
4060 vport->vport_debugfs_root =
4061 debugfs_create_dir(name, phba->hba_debugfs_root);
4062 if (!vport->vport_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04004063 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004064 "0417 Can't create debugfs\n");
James Smarta58cbd52007-08-02 11:09:43 -04004065 goto debug_failed;
4066 }
4067 atomic_inc(&phba->debugfs_vport_count);
4068 }
4069
James Smart858c9f62007-06-17 19:56:39 -05004070 if (lpfc_debugfs_max_disc_trc) {
4071 num = lpfc_debugfs_max_disc_trc - 1;
4072 if (num & lpfc_debugfs_max_disc_trc) {
4073 /* Change to be a power of 2 */
4074 num = lpfc_debugfs_max_disc_trc;
4075 i = 0;
4076 while (num > 1) {
4077 num = num >> 1;
4078 i++;
4079 }
4080 lpfc_debugfs_max_disc_trc = (1 << i);
4081 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04004082 "lpfc_debugfs_max_disc_trc changed to %d\n",
4083 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05004084 }
4085 }
4086
Adrian Bunkff86ba52007-10-18 12:52:37 +02004087 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04004088 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05004089 GFP_KERNEL);
4090
James Smarta58cbd52007-08-02 11:09:43 -04004091 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004092 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004093 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04004094 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05004095 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04004096 }
4097 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05004098
4099 snprintf(name, sizeof(name), "discovery_trace");
4100 vport->debug_disc_trc =
4101 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4102 vport->vport_debugfs_root,
4103 vport, &lpfc_debugfs_op_disc_trc);
4104 if (!vport->debug_disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004105 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004106 "0419 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004107 "discovery_trace\n");
James Smart858c9f62007-06-17 19:56:39 -05004108 goto debug_failed;
4109 }
4110 snprintf(name, sizeof(name), "nodelist");
4111 vport->debug_nodelist =
4112 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4113 vport->vport_debugfs_root,
4114 vport, &lpfc_debugfs_op_nodelist);
4115 if (!vport->debug_nodelist) {
James Smarte8b62012007-08-02 11:10:09 -04004116 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartb76f2dc2011-07-22 18:37:42 -04004117 "2985 Can't create debugfs nodelist\n");
James Smart858c9f62007-06-17 19:56:39 -05004118 goto debug_failed;
4119 }
James Smart2a622bf2011-02-16 12:40:06 -05004120
4121 /*
4122 * iDiag debugfs root entry points for SLI4 device only
4123 */
4124 if (phba->sli_rev < LPFC_SLI_REV4)
4125 goto debug_failed;
4126
4127 snprintf(name, sizeof(name), "iDiag");
4128 if (!phba->idiag_root) {
4129 phba->idiag_root =
4130 debugfs_create_dir(name, phba->hba_debugfs_root);
4131 if (!phba->idiag_root) {
4132 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4133 "2922 Can't create idiag debugfs\n");
4134 goto debug_failed;
4135 }
4136 /* Initialize iDiag data structure */
4137 memset(&idiag, 0, sizeof(idiag));
4138 }
4139
4140 /* iDiag read PCI config space */
4141 snprintf(name, sizeof(name), "pciCfg");
4142 if (!phba->idiag_pci_cfg) {
4143 phba->idiag_pci_cfg =
4144 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4145 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
4146 if (!phba->idiag_pci_cfg) {
4147 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4148 "2923 Can't create idiag debugfs\n");
4149 goto debug_failed;
4150 }
4151 idiag.offset.last_rd = 0;
4152 }
4153
James Smartb76f2dc2011-07-22 18:37:42 -04004154 /* iDiag PCI BAR access */
4155 snprintf(name, sizeof(name), "barAcc");
4156 if (!phba->idiag_bar_acc) {
4157 phba->idiag_bar_acc =
4158 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4159 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
4160 if (!phba->idiag_bar_acc) {
4161 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4162 "3056 Can't create idiag debugfs\n");
4163 goto debug_failed;
4164 }
4165 idiag.offset.last_rd = 0;
4166 }
4167
James Smart2a622bf2011-02-16 12:40:06 -05004168 /* iDiag get PCI function queue information */
4169 snprintf(name, sizeof(name), "queInfo");
4170 if (!phba->idiag_que_info) {
4171 phba->idiag_que_info =
4172 debugfs_create_file(name, S_IFREG|S_IRUGO,
4173 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
4174 if (!phba->idiag_que_info) {
4175 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4176 "2924 Can't create idiag debugfs\n");
4177 goto debug_failed;
4178 }
4179 }
4180
James Smart86a80842011-04-16 11:03:04 -04004181 /* iDiag access PCI function queue */
4182 snprintf(name, sizeof(name), "queAcc");
4183 if (!phba->idiag_que_acc) {
4184 phba->idiag_que_acc =
4185 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4186 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
4187 if (!phba->idiag_que_acc) {
4188 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4189 "2926 Can't create idiag debugfs\n");
4190 goto debug_failed;
4191 }
4192 }
4193
4194 /* iDiag access PCI function doorbell registers */
4195 snprintf(name, sizeof(name), "drbAcc");
4196 if (!phba->idiag_drb_acc) {
4197 phba->idiag_drb_acc =
4198 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4199 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
4200 if (!phba->idiag_drb_acc) {
4201 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4202 "2927 Can't create idiag debugfs\n");
4203 goto debug_failed;
4204 }
4205 }
4206
James Smartb76f2dc2011-07-22 18:37:42 -04004207 /* iDiag access PCI function control registers */
4208 snprintf(name, sizeof(name), "ctlAcc");
4209 if (!phba->idiag_ctl_acc) {
4210 phba->idiag_ctl_acc =
4211 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4212 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
4213 if (!phba->idiag_ctl_acc) {
4214 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4215 "2981 Can't create idiag debugfs\n");
4216 goto debug_failed;
4217 }
4218 }
4219
4220 /* iDiag access mbox commands */
4221 snprintf(name, sizeof(name), "mbxAcc");
4222 if (!phba->idiag_mbx_acc) {
4223 phba->idiag_mbx_acc =
4224 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4225 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
4226 if (!phba->idiag_mbx_acc) {
4227 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4228 "2980 Can't create idiag debugfs\n");
4229 goto debug_failed;
4230 }
4231 }
4232
4233 /* iDiag extents access commands */
4234 if (phba->sli4_hba.extents_in_use) {
4235 snprintf(name, sizeof(name), "extAcc");
4236 if (!phba->idiag_ext_acc) {
4237 phba->idiag_ext_acc =
4238 debugfs_create_file(name,
4239 S_IFREG|S_IRUGO|S_IWUSR,
4240 phba->idiag_root, phba,
4241 &lpfc_idiag_op_extAcc);
4242 if (!phba->idiag_ext_acc) {
4243 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4244 "2986 Cant create "
4245 "idiag debugfs\n");
4246 goto debug_failed;
4247 }
4248 }
4249 }
4250
James Smart858c9f62007-06-17 19:56:39 -05004251debug_failed:
4252 return;
4253#endif
4254}
4255
James Smarte59058c2008-08-24 21:49:00 -04004256/**
James Smart3621a712009-04-06 18:47:14 -04004257 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04004258 * @vport: The vport pointer to remove from debugfs.
4259 *
4260 * Description:
4261 * When Debugfs is configured this routine removes debugfs file system elements
4262 * that are specific to this vport. It also checks to see if there are any
4263 * users left for the debugfs directories associated with the HBA and driver. If
4264 * this is the last user of the HBA directory or driver directory then it will
4265 * remove those from the debugfs infrastructure as well.
4266 **/
James Smart858c9f62007-06-17 19:56:39 -05004267inline void
4268lpfc_debugfs_terminate(struct lpfc_vport *vport)
4269{
James Smart923e4b62008-12-04 22:40:07 -05004270#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05004271 struct lpfc_hba *phba = vport->phba;
4272
4273 if (vport->disc_trc) {
4274 kfree(vport->disc_trc);
4275 vport->disc_trc = NULL;
4276 }
4277 if (vport->debug_disc_trc) {
4278 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
4279 vport->debug_disc_trc = NULL;
4280 }
4281 if (vport->debug_nodelist) {
4282 debugfs_remove(vport->debug_nodelist); /* nodelist */
4283 vport->debug_nodelist = NULL;
4284 }
4285 if (vport->vport_debugfs_root) {
4286 debugfs_remove(vport->vport_debugfs_root); /* vportX */
4287 vport->vport_debugfs_root = NULL;
4288 atomic_dec(&phba->debugfs_vport_count);
4289 }
4290 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04004291
James Smart78b2d852007-08-02 11:10:21 -04004292 if (phba->debug_hbqinfo) {
4293 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
4294 phba->debug_hbqinfo = NULL;
4295 }
James Smartc95d6c62008-01-11 01:53:23 -05004296 if (phba->debug_dumpHBASlim) {
4297 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
4298 phba->debug_dumpHBASlim = NULL;
4299 }
4300 if (phba->debug_dumpHostSlim) {
4301 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
4302 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04004303 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004304 if (phba->debug_dumpData) {
4305 debugfs_remove(phba->debug_dumpData); /* dumpData */
4306 phba->debug_dumpData = NULL;
4307 }
4308
4309 if (phba->debug_dumpDif) {
4310 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
4311 phba->debug_dumpDif = NULL;
4312 }
James Smartf9bb2da2011-10-10 21:34:11 -04004313 if (phba->debug_InjErrLBA) {
4314 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
4315 phba->debug_InjErrLBA = NULL;
4316 }
4317 if (phba->debug_writeGuard) {
4318 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
4319 phba->debug_writeGuard = NULL;
4320 }
4321 if (phba->debug_writeApp) {
4322 debugfs_remove(phba->debug_writeApp); /* writeApp */
4323 phba->debug_writeApp = NULL;
4324 }
4325 if (phba->debug_writeRef) {
4326 debugfs_remove(phba->debug_writeRef); /* writeRef */
4327 phba->debug_writeRef = NULL;
4328 }
James Smartacd68592012-01-18 16:25:09 -05004329 if (phba->debug_readGuard) {
4330 debugfs_remove(phba->debug_readGuard); /* readGuard */
4331 phba->debug_readGuard = NULL;
4332 }
James Smartf9bb2da2011-10-10 21:34:11 -04004333 if (phba->debug_readApp) {
4334 debugfs_remove(phba->debug_readApp); /* readApp */
4335 phba->debug_readApp = NULL;
4336 }
4337 if (phba->debug_readRef) {
4338 debugfs_remove(phba->debug_readRef); /* readRef */
4339 phba->debug_readRef = NULL;
4340 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004341
James Smarta58cbd52007-08-02 11:09:43 -04004342 if (phba->slow_ring_trc) {
4343 kfree(phba->slow_ring_trc);
4344 phba->slow_ring_trc = NULL;
4345 }
4346 if (phba->debug_slow_ring_trc) {
4347 /* slow_ring_trace */
4348 debugfs_remove(phba->debug_slow_ring_trc);
4349 phba->debug_slow_ring_trc = NULL;
4350 }
4351
James Smart2a622bf2011-02-16 12:40:06 -05004352 /*
4353 * iDiag release
4354 */
4355 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartb76f2dc2011-07-22 18:37:42 -04004356 if (phba->idiag_ext_acc) {
4357 /* iDiag extAcc */
4358 debugfs_remove(phba->idiag_ext_acc);
4359 phba->idiag_ext_acc = NULL;
4360 }
4361 if (phba->idiag_mbx_acc) {
4362 /* iDiag mbxAcc */
4363 debugfs_remove(phba->idiag_mbx_acc);
4364 phba->idiag_mbx_acc = NULL;
4365 }
4366 if (phba->idiag_ctl_acc) {
4367 /* iDiag ctlAcc */
4368 debugfs_remove(phba->idiag_ctl_acc);
4369 phba->idiag_ctl_acc = NULL;
4370 }
James Smart86a80842011-04-16 11:03:04 -04004371 if (phba->idiag_drb_acc) {
4372 /* iDiag drbAcc */
4373 debugfs_remove(phba->idiag_drb_acc);
4374 phba->idiag_drb_acc = NULL;
4375 }
4376 if (phba->idiag_que_acc) {
4377 /* iDiag queAcc */
4378 debugfs_remove(phba->idiag_que_acc);
4379 phba->idiag_que_acc = NULL;
4380 }
James Smart2a622bf2011-02-16 12:40:06 -05004381 if (phba->idiag_que_info) {
4382 /* iDiag queInfo */
4383 debugfs_remove(phba->idiag_que_info);
4384 phba->idiag_que_info = NULL;
4385 }
James Smartb76f2dc2011-07-22 18:37:42 -04004386 if (phba->idiag_bar_acc) {
4387 /* iDiag barAcc */
4388 debugfs_remove(phba->idiag_bar_acc);
4389 phba->idiag_bar_acc = NULL;
4390 }
James Smart2a622bf2011-02-16 12:40:06 -05004391 if (phba->idiag_pci_cfg) {
4392 /* iDiag pciCfg */
4393 debugfs_remove(phba->idiag_pci_cfg);
4394 phba->idiag_pci_cfg = NULL;
4395 }
4396
4397 /* Finally remove the iDiag debugfs root */
4398 if (phba->idiag_root) {
4399 /* iDiag root */
4400 debugfs_remove(phba->idiag_root);
4401 phba->idiag_root = NULL;
4402 }
4403 }
4404
James Smarta58cbd52007-08-02 11:09:43 -04004405 if (phba->hba_debugfs_root) {
James Smart2a622bf2011-02-16 12:40:06 -05004406 debugfs_remove(phba->hba_debugfs_root); /* fnX */
James Smarta58cbd52007-08-02 11:09:43 -04004407 phba->hba_debugfs_root = NULL;
4408 atomic_dec(&lpfc_debugfs_hba_count);
4409 }
4410
James Smart858c9f62007-06-17 19:56:39 -05004411 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
4412 debugfs_remove(lpfc_debugfs_root); /* lpfc */
4413 lpfc_debugfs_root = NULL;
4414 }
4415 }
4416#endif
James Smarta58cbd52007-08-02 11:09:43 -04004417 return;
James Smart858c9f62007-06-17 19:56:39 -05004418}