blob: 30b25c5fdd7e2520c719b283af284016bf72b6e9 [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>
23#include <linux/dma-mapping.h>
24#include <linux/idr.h>
25#include <linux/interrupt.h>
26#include <linux/kthread.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
James Smart858c9f62007-06-17 19:56:39 -050028#include <linux/pci.h>
29#include <linux/spinlock.h>
30#include <linux/ctype.h>
James Smart858c9f62007-06-17 19:56:39 -050031
32#include <scsi/scsi.h>
33#include <scsi/scsi_device.h>
34#include <scsi/scsi_host.h>
35#include <scsi/scsi_transport_fc.h>
36
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_hw4.h"
James Smart858c9f62007-06-17 19:56:39 -050038#include "lpfc_hw.h"
39#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
James Smart858c9f62007-06-17 19:56:39 -050042#include "lpfc_disc.h"
43#include "lpfc_scsi.h"
44#include "lpfc.h"
45#include "lpfc_logmsg.h"
46#include "lpfc_crtn.h"
47#include "lpfc_vport.h"
48#include "lpfc_version.h"
James Smartc95d6c62008-01-11 01:53:23 -050049#include "lpfc_compat.h"
James Smart858c9f62007-06-17 19:56:39 -050050#include "lpfc_debugfs.h"
51
James Smart923e4b62008-12-04 22:40:07 -050052#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart3621a712009-04-06 18:47:14 -040053/*
James Smarte59058c2008-08-24 21:49:00 -040054 * debugfs interface
James Smart858c9f62007-06-17 19:56:39 -050055 *
56 * To access this interface the user should:
GeunSik Lim156f5a72009-06-02 15:01:37 +090057 * # mount -t debugfs none /sys/kernel/debug
James Smart858c9f62007-06-17 19:56:39 -050058 *
James Smarte59058c2008-08-24 21:49:00 -040059 * The lpfc debugfs directory hierarchy is:
James Smart2a622bf2011-02-16 12:40:06 -050060 * /sys/kernel/debug/lpfc/fnX/vportY
61 * where X is the lpfc hba function unique_id
James Smart858c9f62007-06-17 19:56:39 -050062 * where Y is the vport VPI on that hba
63 *
64 * Debugging services available per vport:
65 * discovery_trace
66 * This is an ACSII readable file that contains a trace of the last
67 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
James Smarte59058c2008-08-24 21:49:00 -040068 * See lpfc_debugfs.h for different categories of discovery events.
69 * To enable the discovery trace, the following module parameters must be set:
James Smart858c9f62007-06-17 19:56:39 -050070 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
71 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
72 * EACH vport. X MUST also be a power of 2.
73 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
74 * lpfc_debugfs.h .
James Smarte59058c2008-08-24 21:49:00 -040075 *
76 * slow_ring_trace
77 * This is an ACSII readable file that contains a trace of the last
78 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
79 * To enable the slow ring trace, the following module parameters must be set:
80 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
81 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
82 * the HBA. X MUST also be a power of 2.
James Smart858c9f62007-06-17 19:56:39 -050083 */
James Smart51ef4c22007-08-02 11:10:31 -040084static int lpfc_debugfs_enable = 1;
James Smartab56dc22011-02-16 12:39:57 -050085module_param(lpfc_debugfs_enable, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050086MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
87
James Smarta58cbd52007-08-02 11:09:43 -040088/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050089static int lpfc_debugfs_max_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -050090module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050091MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
92 "Set debugfs discovery trace depth");
93
James Smarta58cbd52007-08-02 11:09:43 -040094/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050095static int lpfc_debugfs_max_slow_ring_trc;
James Smartab56dc22011-02-16 12:39:57 -050096module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
James Smarta58cbd52007-08-02 11:09:43 -040097MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
98 "Set debugfs slow ring trace depth");
99
James Smarta257bf92009-04-06 18:48:10 -0400100static int lpfc_debugfs_mask_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -0500101module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -0500102MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
103 "Set debugfs discovery trace mask");
104
105#include <linux/debugfs.h>
106
James Smart311464e2007-08-02 11:10:37 -0400107static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
108static unsigned long lpfc_debugfs_start_time = 0L;
James Smart858c9f62007-06-17 19:56:39 -0500109
James Smart2a622bf2011-02-16 12:40:06 -0500110/* iDiag */
111static struct lpfc_idiag idiag;
112
James Smarte59058c2008-08-24 21:49:00 -0400113/**
James Smart3621a712009-04-06 18:47:14 -0400114 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400115 * @vport: The vport to gather the log info from.
116 * @buf: The buffer to dump log into.
117 * @size: The maximum amount of data to process.
118 *
119 * Description:
120 * This routine gathers the lpfc discovery debugfs data from the @vport and
121 * dumps it to @buf up to @size number of bytes. It will start at the next entry
122 * in the log and process the log until the end of the buffer. Then it will
123 * gather from the beginning of the log and process until the current entry.
124 *
125 * Notes:
126 * Discovery logging will be disabled while while this routine dumps the log.
127 *
128 * Return Value:
129 * This routine returns the amount of bytes that were dumped into @buf and will
130 * not exceed @size.
131 **/
James Smart858c9f62007-06-17 19:56:39 -0500132static int
133lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
134{
135 int i, index, len, enable;
136 uint32_t ms;
James Smarta58cbd52007-08-02 11:09:43 -0400137 struct lpfc_debugfs_trc *dtp;
138 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
James Smart858c9f62007-06-17 19:56:39 -0500139
James Smart858c9f62007-06-17 19:56:39 -0500140 enable = lpfc_debugfs_enable;
141 lpfc_debugfs_enable = 0;
142
143 len = 0;
144 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
145 (lpfc_debugfs_max_disc_trc - 1);
146 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
147 dtp = vport->disc_trc + i;
148 if (!dtp->fmt)
149 continue;
150 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400151 snprintf(buffer,
152 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500153 dtp->seq_cnt, ms, dtp->fmt);
154 len += snprintf(buf+len, size-len, buffer,
155 dtp->data1, dtp->data2, dtp->data3);
156 }
157 for (i = 0; i < index; i++) {
158 dtp = vport->disc_trc + i;
159 if (!dtp->fmt)
160 continue;
161 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400162 snprintf(buffer,
163 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500164 dtp->seq_cnt, ms, dtp->fmt);
165 len += snprintf(buf+len, size-len, buffer,
166 dtp->data1, dtp->data2, dtp->data3);
167 }
168
169 lpfc_debugfs_enable = enable;
170 return len;
171}
172
James Smarte59058c2008-08-24 21:49:00 -0400173/**
James Smart3621a712009-04-06 18:47:14 -0400174 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400175 * @phba: The HBA to gather the log info from.
176 * @buf: The buffer to dump log into.
177 * @size: The maximum amount of data to process.
178 *
179 * Description:
180 * This routine gathers the lpfc slow ring debugfs data from the @phba and
181 * dumps it to @buf up to @size number of bytes. It will start at the next entry
182 * in the log and process the log until the end of the buffer. Then it will
183 * gather from the beginning of the log and process until the current entry.
184 *
185 * Notes:
186 * Slow ring logging will be disabled while while this routine dumps the log.
187 *
188 * Return Value:
189 * This routine returns the amount of bytes that were dumped into @buf and will
190 * not exceed @size.
191 **/
James Smart858c9f62007-06-17 19:56:39 -0500192static int
James Smarta58cbd52007-08-02 11:09:43 -0400193lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
194{
195 int i, index, len, enable;
196 uint32_t ms;
197 struct lpfc_debugfs_trc *dtp;
198 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
199
200
201 enable = lpfc_debugfs_enable;
202 lpfc_debugfs_enable = 0;
203
204 len = 0;
205 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
206 (lpfc_debugfs_max_slow_ring_trc - 1);
207 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
208 dtp = phba->slow_ring_trc + i;
209 if (!dtp->fmt)
210 continue;
211 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
212 snprintf(buffer,
213 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
214 dtp->seq_cnt, ms, dtp->fmt);
215 len += snprintf(buf+len, size-len, buffer,
216 dtp->data1, dtp->data2, dtp->data3);
217 }
218 for (i = 0; i < index; i++) {
219 dtp = phba->slow_ring_trc + i;
220 if (!dtp->fmt)
221 continue;
222 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
223 snprintf(buffer,
224 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
225 dtp->seq_cnt, ms, dtp->fmt);
226 len += snprintf(buf+len, size-len, buffer,
227 dtp->data1, dtp->data2, dtp->data3);
228 }
229
230 lpfc_debugfs_enable = enable;
231 return len;
232}
233
James Smart311464e2007-08-02 11:10:37 -0400234static int lpfc_debugfs_last_hbq = -1;
James Smart78b2d852007-08-02 11:10:21 -0400235
James Smarte59058c2008-08-24 21:49:00 -0400236/**
James Smart3621a712009-04-06 18:47:14 -0400237 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400238 * @phba: The HBA to gather host buffer info from.
239 * @buf: The buffer to dump log into.
240 * @size: The maximum amount of data to process.
241 *
242 * Description:
243 * This routine dumps the host buffer queue info from the @phba to @buf up to
244 * @size number of bytes. A header that describes the current hbq state will be
245 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
246 * until @size bytes have been dumped or all the hbq info has been dumped.
247 *
248 * Notes:
249 * This routine will rotate through each configured HBQ each time called.
250 *
251 * Return Value:
252 * This routine returns the amount of bytes that were dumped into @buf and will
253 * not exceed @size.
254 **/
James Smart78b2d852007-08-02 11:10:21 -0400255static int
256lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
257{
258 int len = 0;
259 int cnt, i, j, found, posted, low;
260 uint32_t phys, raw_index, getidx;
261 struct lpfc_hbq_init *hip;
262 struct hbq_s *hbqs;
263 struct lpfc_hbq_entry *hbqe;
264 struct lpfc_dmabuf *d_buf;
265 struct hbq_dmabuf *hbq_buf;
266
James Smart3772a992009-05-22 14:50:54 -0400267 if (phba->sli_rev != 3)
268 return 0;
James Smart78b2d852007-08-02 11:10:21 -0400269 cnt = LPFC_HBQINFO_SIZE;
270 spin_lock_irq(&phba->hbalock);
271
272 /* toggle between multiple hbqs, if any */
273 i = lpfc_sli_hbq_count();
274 if (i > 1) {
275 lpfc_debugfs_last_hbq++;
276 if (lpfc_debugfs_last_hbq >= i)
277 lpfc_debugfs_last_hbq = 0;
278 }
279 else
280 lpfc_debugfs_last_hbq = 0;
281
282 i = lpfc_debugfs_last_hbq;
283
284 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
285
James Smart51ef4c22007-08-02 11:10:31 -0400286 hbqs = &phba->hbqs[i];
James Smart78b2d852007-08-02 11:10:21 -0400287 posted = 0;
James Smart51ef4c22007-08-02 11:10:31 -0400288 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
James Smart78b2d852007-08-02 11:10:21 -0400289 posted++;
290
291 hip = lpfc_hbq_defs[i];
292 len += snprintf(buf+len, size-len,
293 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
294 hip->hbq_index, hip->profile, hip->rn,
295 hip->buffer_count, hip->init_count, hip->add_count, posted);
296
James Smart78b2d852007-08-02 11:10:21 -0400297 raw_index = phba->hbq_get[i];
298 getidx = le32_to_cpu(raw_index);
299 len += snprintf(buf+len, size-len,
James Smarta8adb832007-10-27 13:37:53 -0400300 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
301 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
302 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
James Smart78b2d852007-08-02 11:10:21 -0400303
James Smart51ef4c22007-08-02 11:10:31 -0400304 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
James Smart78b2d852007-08-02 11:10:21 -0400305 for (j=0; j<hbqs->entry_count; j++) {
306 len += snprintf(buf+len, size-len,
307 "%03d: %08x %04x %05x ", j,
James Smarta8adb832007-10-27 13:37:53 -0400308 le32_to_cpu(hbqe->bde.addrLow),
309 le32_to_cpu(hbqe->bde.tus.w),
310 le32_to_cpu(hbqe->buffer_tag));
James Smart78b2d852007-08-02 11:10:21 -0400311 i = 0;
312 found = 0;
313
314 /* First calculate if slot has an associated posted buffer */
315 low = hbqs->hbqPutIdx - posted;
316 if (low >= 0) {
317 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
318 len += snprintf(buf+len, size-len, "Unused\n");
319 goto skipit;
320 }
321 }
322 else {
323 if ((j >= hbqs->hbqPutIdx) &&
324 (j < (hbqs->entry_count+low))) {
325 len += snprintf(buf+len, size-len, "Unused\n");
326 goto skipit;
327 }
328 }
329
330 /* Get the Buffer info for the posted buffer */
James Smart51ef4c22007-08-02 11:10:31 -0400331 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
James Smart78b2d852007-08-02 11:10:21 -0400332 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
333 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
James Smarta8adb832007-10-27 13:37:53 -0400334 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
James Smart78b2d852007-08-02 11:10:21 -0400335 len += snprintf(buf+len, size-len,
336 "Buf%d: %p %06x\n", i,
337 hbq_buf->dbuf.virt, hbq_buf->tag);
338 found = 1;
339 break;
340 }
341 i++;
342 }
343 if (!found) {
344 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
345 }
346skipit:
347 hbqe++;
348 if (len > LPFC_HBQINFO_SIZE - 54)
349 break;
350 }
351 spin_unlock_irq(&phba->hbalock);
352 return len;
353}
354
James Smartc95d6c62008-01-11 01:53:23 -0500355static int lpfc_debugfs_last_hba_slim_off;
356
James Smarte59058c2008-08-24 21:49:00 -0400357/**
James Smart3621a712009-04-06 18:47:14 -0400358 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400359 * @phba: The HBA to gather SLIM info from.
360 * @buf: The buffer to dump log into.
361 * @size: The maximum amount of data to process.
362 *
363 * Description:
364 * This routine dumps the current contents of HBA SLIM for the HBA associated
365 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
366 *
367 * Notes:
368 * This routine will only dump up to 1024 bytes of data each time called and
369 * should be called multiple times to dump the entire HBA SLIM.
370 *
371 * Return Value:
372 * This routine returns the amount of bytes that were dumped into @buf and will
373 * not exceed @size.
374 **/
James Smarta58cbd52007-08-02 11:09:43 -0400375static int
James Smartc95d6c62008-01-11 01:53:23 -0500376lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
James Smarta58cbd52007-08-02 11:09:43 -0400377{
378 int len = 0;
James Smartc95d6c62008-01-11 01:53:23 -0500379 int i, off;
380 uint32_t *ptr;
381 char buffer[1024];
382
383 off = 0;
384 spin_lock_irq(&phba->hbalock);
385
386 len += snprintf(buf+len, size-len, "HBA SLIM\n");
387 lpfc_memcpy_from_slim(buffer,
James Smarta257bf92009-04-06 18:48:10 -0400388 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
James Smartc95d6c62008-01-11 01:53:23 -0500389
390 ptr = (uint32_t *)&buffer[0];
391 off = lpfc_debugfs_last_hba_slim_off;
392
393 /* Set it up for the next time */
394 lpfc_debugfs_last_hba_slim_off += 1024;
395 if (lpfc_debugfs_last_hba_slim_off >= 4096)
396 lpfc_debugfs_last_hba_slim_off = 0;
397
398 i = 1024;
399 while (i > 0) {
400 len += snprintf(buf+len, size-len,
401 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
402 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
403 *(ptr+5), *(ptr+6), *(ptr+7));
404 ptr += 8;
405 i -= (8 * sizeof(uint32_t));
406 off += (8 * sizeof(uint32_t));
407 }
408
409 spin_unlock_irq(&phba->hbalock);
410 return len;
411}
412
James Smarte59058c2008-08-24 21:49:00 -0400413/**
James Smart3621a712009-04-06 18:47:14 -0400414 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400415 * @phba: The HBA to gather Host SLIM info from.
416 * @buf: The buffer to dump log into.
417 * @size: The maximum amount of data to process.
418 *
419 * Description:
420 * This routine dumps the current contents of host SLIM for the host associated
421 * with @phba to @buf up to @size bytes of data. The dump will contain the
422 * Mailbox, PCB, Rings, and Registers that are located in host memory.
423 *
424 * Return Value:
425 * This routine returns the amount of bytes that were dumped into @buf and will
426 * not exceed @size.
427 **/
James Smartc95d6c62008-01-11 01:53:23 -0500428static int
429lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
430{
431 int len = 0;
432 int i, off;
James Smarta58cbd52007-08-02 11:09:43 -0400433 uint32_t word0, word1, word2, word3;
434 uint32_t *ptr;
435 struct lpfc_pgp *pgpp;
436 struct lpfc_sli *psli = &phba->sli;
437 struct lpfc_sli_ring *pring;
438
James Smarta58cbd52007-08-02 11:09:43 -0400439 off = 0;
440 spin_lock_irq(&phba->hbalock);
441
442 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
James Smart34b02dc2008-08-24 21:49:55 -0400443 ptr = (uint32_t *)phba->slim2p.virt;
James Smarta58cbd52007-08-02 11:09:43 -0400444 i = sizeof(MAILBOX_t);
445 while (i > 0) {
446 len += snprintf(buf+len, size-len,
447 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
448 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
449 *(ptr+5), *(ptr+6), *(ptr+7));
450 ptr += 8;
451 i -= (8 * sizeof(uint32_t));
452 off += (8 * sizeof(uint32_t));
453 }
454
455 len += snprintf(buf+len, size-len, "SLIM PCB\n");
James Smart34b02dc2008-08-24 21:49:55 -0400456 ptr = (uint32_t *)phba->pcb;
James Smarta58cbd52007-08-02 11:09:43 -0400457 i = sizeof(PCB_t);
458 while (i > 0) {
459 len += snprintf(buf+len, size-len,
460 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
461 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
462 *(ptr+5), *(ptr+6), *(ptr+7));
463 ptr += 8;
464 i -= (8 * sizeof(uint32_t));
465 off += (8 * sizeof(uint32_t));
466 }
467
James Smart34b02dc2008-08-24 21:49:55 -0400468 for (i = 0; i < 4; i++) {
469 pgpp = &phba->port_gp[i];
470 pring = &psli->ring[i];
471 len += snprintf(buf+len, size-len,
472 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
473 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
474 i, pgpp->cmdGetInx, pring->numCiocb,
475 pring->next_cmdidx, pring->local_getidx,
476 pring->flag, pgpp->rspPutInx, pring->numRiocb);
477 }
James Smart3772a992009-05-22 14:50:54 -0400478
479 if (phba->sli_rev <= LPFC_SLI_REV3) {
480 word0 = readl(phba->HAregaddr);
481 word1 = readl(phba->CAregaddr);
482 word2 = readl(phba->HSregaddr);
483 word3 = readl(phba->HCregaddr);
484 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
485 "HC:%08x\n", word0, word1, word2, word3);
486 }
James Smarta58cbd52007-08-02 11:09:43 -0400487 spin_unlock_irq(&phba->hbalock);
488 return len;
489}
490
James Smarte59058c2008-08-24 21:49:00 -0400491/**
James Smart3621a712009-04-06 18:47:14 -0400492 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400493 * @vport: The vport to gather target node info from.
494 * @buf: The buffer to dump log into.
495 * @size: The maximum amount of data to process.
496 *
497 * Description:
498 * This routine dumps the current target node list associated with @vport to
499 * @buf up to @size bytes of data. Each node entry in the dump will contain a
500 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
501 *
502 * Return Value:
503 * This routine returns the amount of bytes that were dumped into @buf and will
504 * not exceed @size.
505 **/
James Smarta58cbd52007-08-02 11:09:43 -0400506static int
James Smart858c9f62007-06-17 19:56:39 -0500507lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
508{
509 int len = 0;
510 int cnt;
511 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
512 struct lpfc_nodelist *ndlp;
513 unsigned char *statep, *name;
514
515 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
516
517 spin_lock_irq(shost->host_lock);
518 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
519 if (!cnt) {
520 len += snprintf(buf+len, size-len,
521 "Missing Nodelist Entries\n");
522 break;
523 }
524 cnt--;
525 switch (ndlp->nlp_state) {
526 case NLP_STE_UNUSED_NODE:
527 statep = "UNUSED";
528 break;
529 case NLP_STE_PLOGI_ISSUE:
530 statep = "PLOGI ";
531 break;
532 case NLP_STE_ADISC_ISSUE:
533 statep = "ADISC ";
534 break;
535 case NLP_STE_REG_LOGIN_ISSUE:
536 statep = "REGLOG";
537 break;
538 case NLP_STE_PRLI_ISSUE:
539 statep = "PRLI ";
540 break;
541 case NLP_STE_UNMAPPED_NODE:
542 statep = "UNMAP ";
543 break;
544 case NLP_STE_MAPPED_NODE:
545 statep = "MAPPED";
546 break;
547 case NLP_STE_NPR_NODE:
548 statep = "NPR ";
549 break;
550 default:
551 statep = "UNKNOWN";
552 }
553 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
554 statep, ndlp->nlp_DID);
555 name = (unsigned char *)&ndlp->nlp_portname;
556 len += snprintf(buf+len, size-len,
557 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
558 *name, *(name+1), *(name+2), *(name+3),
559 *(name+4), *(name+5), *(name+6), *(name+7));
560 name = (unsigned char *)&ndlp->nlp_nodename;
561 len += snprintf(buf+len, size-len,
562 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
563 *name, *(name+1), *(name+2), *(name+3),
564 *(name+4), *(name+5), *(name+6), *(name+7));
565 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
566 ndlp->nlp_rpi, ndlp->nlp_flag);
567 if (!ndlp->nlp_type)
James Smarta58cbd52007-08-02 11:09:43 -0400568 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500569 if (ndlp->nlp_type & NLP_FC_NODE)
570 len += snprintf(buf+len, size-len, "FC_NODE ");
571 if (ndlp->nlp_type & NLP_FABRIC)
572 len += snprintf(buf+len, size-len, "FABRIC ");
573 if (ndlp->nlp_type & NLP_FCP_TARGET)
574 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
575 ndlp->nlp_sid);
576 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
James Smarta58cbd52007-08-02 11:09:43 -0400577 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart58da1ff2008-04-07 10:15:56 -0400578 len += snprintf(buf+len, size-len, "usgmap:%x ",
579 ndlp->nlp_usg_map);
James Smarta58cbd52007-08-02 11:09:43 -0400580 len += snprintf(buf+len, size-len, "refcnt:%x",
581 atomic_read(&ndlp->kref.refcount));
James Smart858c9f62007-06-17 19:56:39 -0500582 len += snprintf(buf+len, size-len, "\n");
583 }
584 spin_unlock_irq(shost->host_lock);
585 return len;
586}
587#endif
588
James Smarte59058c2008-08-24 21:49:00 -0400589/**
James Smart3621a712009-04-06 18:47:14 -0400590 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400591 * @vport: The vport to associate this trace string with for retrieval.
592 * @mask: Log entry classification.
593 * @fmt: Format string to be displayed when dumping the log.
594 * @data1: 1st data parameter to be applied to @fmt.
595 * @data2: 2nd data parameter to be applied to @fmt.
596 * @data3: 3rd data parameter to be applied to @fmt.
597 *
598 * Description:
599 * This routine is used by the driver code to add a debugfs log entry to the
600 * discovery trace buffer associated with @vport. Only entries with a @mask that
601 * match the current debugfs discovery mask will be saved. Entries that do not
602 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
603 * printf when displaying the log.
604 **/
James Smart858c9f62007-06-17 19:56:39 -0500605inline void
606lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
607 uint32_t data1, uint32_t data2, uint32_t data3)
608{
James Smart923e4b62008-12-04 22:40:07 -0500609#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400610 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -0500611 int index;
612
613 if (!(lpfc_debugfs_mask_disc_trc & mask))
614 return;
615
616 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
617 !vport || !vport->disc_trc)
618 return;
619
620 index = atomic_inc_return(&vport->disc_trc_cnt) &
621 (lpfc_debugfs_max_disc_trc - 1);
622 dtp = vport->disc_trc + index;
623 dtp->fmt = fmt;
624 dtp->data1 = data1;
625 dtp->data2 = data2;
626 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -0400627 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
628 dtp->jif = jiffies;
629#endif
630 return;
631}
632
James Smarte59058c2008-08-24 21:49:00 -0400633/**
James Smart3621a712009-04-06 18:47:14 -0400634 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400635 * @phba: The phba to associate this trace string with for retrieval.
636 * @fmt: Format string to be displayed when dumping the log.
637 * @data1: 1st data parameter to be applied to @fmt.
638 * @data2: 2nd data parameter to be applied to @fmt.
639 * @data3: 3rd data parameter to be applied to @fmt.
640 *
641 * Description:
642 * This routine is used by the driver code to add a debugfs log entry to the
643 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
644 * @data3 are used like printf when displaying the log.
645 **/
James Smarta58cbd52007-08-02 11:09:43 -0400646inline void
647lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
648 uint32_t data1, uint32_t data2, uint32_t data3)
649{
James Smart923e4b62008-12-04 22:40:07 -0500650#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400651 struct lpfc_debugfs_trc *dtp;
652 int index;
653
654 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
655 !phba || !phba->slow_ring_trc)
656 return;
657
658 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
659 (lpfc_debugfs_max_slow_ring_trc - 1);
660 dtp = phba->slow_ring_trc + index;
661 dtp->fmt = fmt;
662 dtp->data1 = data1;
663 dtp->data2 = data2;
664 dtp->data3 = data3;
665 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500666 dtp->jif = jiffies;
667#endif
668 return;
669}
670
James Smart923e4b62008-12-04 22:40:07 -0500671#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -0400672/**
James Smart3621a712009-04-06 18:47:14 -0400673 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400674 * @inode: The inode pointer that contains a vport pointer.
675 * @file: The file pointer to attach the log output.
676 *
677 * Description:
678 * This routine is the entry point for the debugfs open file operation. It gets
679 * the vport from the i_private field in @inode, allocates the necessary buffer
680 * for the log, fills the buffer from the in-memory log for this vport, and then
681 * returns a pointer to that log in the private_data field in @file.
682 *
683 * Returns:
684 * This function returns zero if successful. On error it will return an negative
685 * error value.
686 **/
James Smart858c9f62007-06-17 19:56:39 -0500687static int
688lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
689{
690 struct lpfc_vport *vport = inode->i_private;
691 struct lpfc_debug *debug;
692 int size;
693 int rc = -ENOMEM;
694
695 if (!lpfc_debugfs_max_disc_trc) {
696 rc = -ENOSPC;
697 goto out;
698 }
699
700 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
701 if (!debug)
702 goto out;
703
James Smarte59058c2008-08-24 21:49:00 -0400704 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400705 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -0500706 size = PAGE_ALIGN(size);
707
708 debug->buffer = kmalloc(size, GFP_KERNEL);
709 if (!debug->buffer) {
710 kfree(debug);
711 goto out;
712 }
713
714 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
715 file->private_data = debug;
716
717 rc = 0;
718out:
719 return rc;
720}
721
James Smarte59058c2008-08-24 21:49:00 -0400722/**
James Smart3621a712009-04-06 18:47:14 -0400723 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400724 * @inode: The inode pointer that contains a vport pointer.
725 * @file: The file pointer to attach the log output.
726 *
727 * Description:
728 * This routine is the entry point for the debugfs open file operation. It gets
729 * the vport from the i_private field in @inode, allocates the necessary buffer
730 * for the log, fills the buffer from the in-memory log for this vport, and then
731 * returns a pointer to that log in the private_data field in @file.
732 *
733 * Returns:
734 * This function returns zero if successful. On error it will return an negative
735 * error value.
736 **/
James Smart858c9f62007-06-17 19:56:39 -0500737static int
James Smarta58cbd52007-08-02 11:09:43 -0400738lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
739{
740 struct lpfc_hba *phba = inode->i_private;
741 struct lpfc_debug *debug;
742 int size;
743 int rc = -ENOMEM;
744
745 if (!lpfc_debugfs_max_slow_ring_trc) {
746 rc = -ENOSPC;
747 goto out;
748 }
749
750 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
751 if (!debug)
752 goto out;
753
James Smarte59058c2008-08-24 21:49:00 -0400754 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400755 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
756 size = PAGE_ALIGN(size);
757
758 debug->buffer = kmalloc(size, GFP_KERNEL);
759 if (!debug->buffer) {
760 kfree(debug);
761 goto out;
762 }
763
764 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
765 file->private_data = debug;
766
767 rc = 0;
768out:
769 return rc;
770}
771
James Smarte59058c2008-08-24 21:49:00 -0400772/**
James Smart3621a712009-04-06 18:47:14 -0400773 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400774 * @inode: The inode pointer that contains a vport pointer.
775 * @file: The file pointer to attach the log output.
776 *
777 * Description:
778 * This routine is the entry point for the debugfs open file operation. It gets
779 * the vport from the i_private field in @inode, allocates the necessary buffer
780 * for the log, fills the buffer from the in-memory log for this vport, and then
781 * returns a pointer to that log in the private_data field in @file.
782 *
783 * Returns:
784 * This function returns zero if successful. On error it will return an negative
785 * error value.
786 **/
James Smarta58cbd52007-08-02 11:09:43 -0400787static int
James Smart78b2d852007-08-02 11:10:21 -0400788lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
789{
790 struct lpfc_hba *phba = inode->i_private;
791 struct lpfc_debug *debug;
792 int rc = -ENOMEM;
793
794 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
795 if (!debug)
796 goto out;
797
James Smarte59058c2008-08-24 21:49:00 -0400798 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -0400799 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
800 if (!debug->buffer) {
801 kfree(debug);
802 goto out;
803 }
804
805 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
806 LPFC_HBQINFO_SIZE);
807 file->private_data = debug;
808
809 rc = 0;
810out:
811 return rc;
812}
813
James Smarte59058c2008-08-24 21:49:00 -0400814/**
James Smart3621a712009-04-06 18:47:14 -0400815 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400816 * @inode: The inode pointer that contains a vport pointer.
817 * @file: The file pointer to attach the log output.
818 *
819 * Description:
820 * This routine is the entry point for the debugfs open file operation. It gets
821 * the vport from the i_private field in @inode, allocates the necessary buffer
822 * for the log, fills the buffer from the in-memory log for this vport, and then
823 * returns a pointer to that log in the private_data field in @file.
824 *
825 * Returns:
826 * This function returns zero if successful. On error it will return an negative
827 * error value.
828 **/
James Smart78b2d852007-08-02 11:10:21 -0400829static int
James Smartc95d6c62008-01-11 01:53:23 -0500830lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -0400831{
832 struct lpfc_hba *phba = inode->i_private;
833 struct lpfc_debug *debug;
834 int rc = -ENOMEM;
835
836 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
837 if (!debug)
838 goto out;
839
James Smarte59058c2008-08-24 21:49:00 -0400840 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500841 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -0400842 if (!debug->buffer) {
843 kfree(debug);
844 goto out;
845 }
846
James Smartc95d6c62008-01-11 01:53:23 -0500847 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
848 LPFC_DUMPHBASLIM_SIZE);
849 file->private_data = debug;
850
851 rc = 0;
852out:
853 return rc;
854}
855
James Smarte59058c2008-08-24 21:49:00 -0400856/**
James Smart3621a712009-04-06 18:47:14 -0400857 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400858 * @inode: The inode pointer that contains a vport pointer.
859 * @file: The file pointer to attach the log output.
860 *
861 * Description:
862 * This routine is the entry point for the debugfs open file operation. It gets
863 * the vport from the i_private field in @inode, allocates the necessary buffer
864 * for the log, fills the buffer from the in-memory log for this vport, and then
865 * returns a pointer to that log in the private_data field in @file.
866 *
867 * Returns:
868 * This function returns zero if successful. On error it will return an negative
869 * error value.
870 **/
James Smartc95d6c62008-01-11 01:53:23 -0500871static int
872lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
873{
874 struct lpfc_hba *phba = inode->i_private;
875 struct lpfc_debug *debug;
876 int rc = -ENOMEM;
877
878 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
879 if (!debug)
880 goto out;
881
James Smarte59058c2008-08-24 21:49:00 -0400882 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500883 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
884 if (!debug->buffer) {
885 kfree(debug);
886 goto out;
887 }
888
889 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
890 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -0400891 file->private_data = debug;
892
893 rc = 0;
894out:
895 return rc;
896}
897
James Smarte2a0a9d2008-12-04 22:40:02 -0500898static int
899lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
900{
901 struct lpfc_debug *debug;
902 int rc = -ENOMEM;
903
904 if (!_dump_buf_data)
905 return -EBUSY;
906
907 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
908 if (!debug)
909 goto out;
910
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300911 /* Round to page boundary */
James Smart6a9c52c2009-10-02 15:16:51 -0400912 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
James Smarte2a0a9d2008-12-04 22:40:02 -0500913 __func__, _dump_buf_data);
914 debug->buffer = _dump_buf_data;
915 if (!debug->buffer) {
916 kfree(debug);
917 goto out;
918 }
919
920 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
921 file->private_data = debug;
922
923 rc = 0;
924out:
925 return rc;
926}
927
928static int
929lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
930{
931 struct lpfc_debug *debug;
932 int rc = -ENOMEM;
933
934 if (!_dump_buf_dif)
935 return -EBUSY;
936
937 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
938 if (!debug)
939 goto out;
940
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300941 /* Round to page boundary */
James Smart6a9c52c2009-10-02 15:16:51 -0400942 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
943 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
James Smarte2a0a9d2008-12-04 22:40:02 -0500944 debug->buffer = _dump_buf_dif;
945 if (!debug->buffer) {
946 kfree(debug);
947 goto out;
948 }
949
950 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
951 file->private_data = debug;
952
953 rc = 0;
954out:
955 return rc;
956}
957
958static ssize_t
959lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
960 size_t nbytes, loff_t *ppos)
961{
962 /*
963 * The Data/DIF buffers only save one failing IO
964 * The write op is used as a reset mechanism after an IO has
965 * already been saved to the next one can be saved
966 */
967 spin_lock(&_dump_buf_lock);
968
969 memset((void *)_dump_buf_data, 0,
970 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
971 memset((void *)_dump_buf_dif, 0,
972 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
973
974 _dump_buf_done = 0;
975
976 spin_unlock(&_dump_buf_lock);
977
978 return nbytes;
979}
980
James Smarte59058c2008-08-24 21:49:00 -0400981/**
James Smart3621a712009-04-06 18:47:14 -0400982 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -0400983 * @inode: The inode pointer that contains a vport pointer.
984 * @file: The file pointer to attach the log output.
985 *
986 * Description:
987 * This routine is the entry point for the debugfs open file operation. It gets
988 * the vport from the i_private field in @inode, allocates the necessary buffer
989 * for the log, fills the buffer from the in-memory log for this vport, and then
990 * returns a pointer to that log in the private_data field in @file.
991 *
992 * Returns:
993 * This function returns zero if successful. On error it will return an negative
994 * error value.
995 **/
James Smarta58cbd52007-08-02 11:09:43 -0400996static int
James Smart858c9f62007-06-17 19:56:39 -0500997lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
998{
999 struct lpfc_vport *vport = inode->i_private;
1000 struct lpfc_debug *debug;
1001 int rc = -ENOMEM;
1002
1003 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1004 if (!debug)
1005 goto out;
1006
James Smarte59058c2008-08-24 21:49:00 -04001007 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05001008 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1009 if (!debug->buffer) {
1010 kfree(debug);
1011 goto out;
1012 }
1013
1014 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1015 LPFC_NODELIST_SIZE);
1016 file->private_data = debug;
1017
1018 rc = 0;
1019out:
1020 return rc;
1021}
1022
James Smarte59058c2008-08-24 21:49:00 -04001023/**
James Smart3621a712009-04-06 18:47:14 -04001024 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001025 * @file: The file pointer to seek through.
1026 * @off: The offset to seek to or the amount to seek by.
1027 * @whence: Indicates how to seek.
1028 *
1029 * Description:
1030 * This routine is the entry point for the debugfs lseek file operation. The
1031 * @whence parameter indicates whether @off is the offset to directly seek to,
1032 * or if it is a value to seek forward or reverse by. This function figures out
1033 * what the new offset of the debugfs file will be and assigns that value to the
1034 * f_pos field of @file.
1035 *
1036 * Returns:
1037 * This function returns the new offset if successful and returns a negative
1038 * error if unable to process the seek.
1039 **/
James Smart858c9f62007-06-17 19:56:39 -05001040static loff_t
1041lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1042{
1043 struct lpfc_debug *debug;
1044 loff_t pos = -1;
1045
1046 debug = file->private_data;
1047
1048 switch (whence) {
1049 case 0:
1050 pos = off;
1051 break;
1052 case 1:
1053 pos = file->f_pos + off;
1054 break;
1055 case 2:
1056 pos = debug->len - off;
1057 }
1058 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1059}
1060
James Smarte59058c2008-08-24 21:49:00 -04001061/**
James Smart3621a712009-04-06 18:47:14 -04001062 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001063 * @file: The file pointer to read from.
1064 * @buf: The buffer to copy the data to.
1065 * @nbytes: The number of bytes to read.
1066 * @ppos: The position in the file to start reading from.
1067 *
1068 * Description:
1069 * This routine reads data from from the buffer indicated in the private_data
1070 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1071 * data to @buf.
1072 *
1073 * Returns:
1074 * This function returns the amount of data that was read (this could be less
1075 * than @nbytes if the end of the file was reached) or a negative error value.
1076 **/
James Smart858c9f62007-06-17 19:56:39 -05001077static ssize_t
1078lpfc_debugfs_read(struct file *file, char __user *buf,
1079 size_t nbytes, loff_t *ppos)
1080{
1081 struct lpfc_debug *debug = file->private_data;
James Smart2a622bf2011-02-16 12:40:06 -05001082
James Smart858c9f62007-06-17 19:56:39 -05001083 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1084 debug->len);
1085}
1086
James Smarte59058c2008-08-24 21:49:00 -04001087/**
James Smart3621a712009-04-06 18:47:14 -04001088 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04001089 * @inode: The inode pointer that contains a vport pointer. (unused)
1090 * @file: The file pointer that contains the buffer to release.
1091 *
1092 * Description:
1093 * This routine frees the buffer that was allocated when the debugfs file was
1094 * opened.
1095 *
1096 * Returns:
1097 * This function returns zero.
1098 **/
James Smart858c9f62007-06-17 19:56:39 -05001099static int
1100lpfc_debugfs_release(struct inode *inode, struct file *file)
1101{
1102 struct lpfc_debug *debug = file->private_data;
1103
1104 kfree(debug->buffer);
1105 kfree(debug);
1106
1107 return 0;
1108}
1109
James Smarte2a0a9d2008-12-04 22:40:02 -05001110static int
1111lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1112{
1113 struct lpfc_debug *debug = file->private_data;
1114
1115 debug->buffer = NULL;
1116 kfree(debug);
1117
1118 return 0;
1119}
1120
James Smart2a622bf2011-02-16 12:40:06 -05001121/*
James Smart86a80842011-04-16 11:03:04 -04001122 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001123 * iDiag debugfs file access methods
James Smart86a80842011-04-16 11:03:04 -04001124 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001125 *
James Smart86a80842011-04-16 11:03:04 -04001126 * All access methods are through the proper SLI4 PCI function's debugfs
1127 * iDiag directory:
James Smart2a622bf2011-02-16 12:40:06 -05001128 *
James Smart86a80842011-04-16 11:03:04 -04001129 * /sys/kernel/debug/lpfc/fn<#>/iDiag
James Smart2a622bf2011-02-16 12:40:06 -05001130 */
1131
1132/**
1133 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1134 * @buf: The pointer to the user space buffer.
1135 * @nbytes: The number of bytes in the user space buffer.
1136 * @idiag_cmd: pointer to the idiag command struct.
1137 *
1138 * This routine reads data from debugfs user space buffer and parses the
1139 * buffer for getting the idiag command and arguments. The while space in
1140 * between the set of data is used as the parsing separator.
1141 *
1142 * This routine returns 0 when successful, it returns proper error code
1143 * back to the user space in error conditions.
1144 */
1145static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1146 struct lpfc_idiag_cmd *idiag_cmd)
1147{
1148 char mybuf[64];
1149 char *pbuf, *step_str;
Stephen Boydb11d48e2011-05-12 16:50:06 -07001150 int i;
1151 size_t bsize;
James Smart2a622bf2011-02-16 12:40:06 -05001152
1153 /* Protect copy from user */
1154 if (!access_ok(VERIFY_READ, buf, nbytes))
1155 return -EFAULT;
1156
1157 memset(mybuf, 0, sizeof(mybuf));
1158 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1159 bsize = min(nbytes, (sizeof(mybuf)-1));
1160
1161 if (copy_from_user(mybuf, buf, bsize))
1162 return -EFAULT;
1163 pbuf = &mybuf[0];
1164 step_str = strsep(&pbuf, "\t ");
1165
1166 /* The opcode must present */
1167 if (!step_str)
1168 return -EINVAL;
1169
1170 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1171 if (idiag_cmd->opcode == 0)
1172 return -EINVAL;
1173
1174 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1175 step_str = strsep(&pbuf, "\t ");
1176 if (!step_str)
James Smart86a80842011-04-16 11:03:04 -04001177 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001178 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1179 }
James Smart86a80842011-04-16 11:03:04 -04001180 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001181}
1182
1183/**
1184 * lpfc_idiag_open - idiag open debugfs
1185 * @inode: The inode pointer that contains a pointer to phba.
1186 * @file: The file pointer to attach the file operation.
1187 *
1188 * Description:
1189 * This routine is the entry point for the debugfs open file operation. It
1190 * gets the reference to phba from the i_private field in @inode, it then
1191 * allocates buffer for the file operation, performs the necessary PCI config
1192 * space read into the allocated buffer according to the idiag user command
1193 * setup, and then returns a pointer to buffer in the private_data field in
1194 * @file.
1195 *
1196 * Returns:
1197 * This function returns zero if successful. On error it will return an
1198 * negative error value.
1199 **/
1200static int
1201lpfc_idiag_open(struct inode *inode, struct file *file)
1202{
1203 struct lpfc_debug *debug;
1204
1205 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1206 if (!debug)
1207 return -ENOMEM;
1208
1209 debug->i_private = inode->i_private;
1210 debug->buffer = NULL;
1211 file->private_data = debug;
1212
1213 return 0;
1214}
1215
1216/**
1217 * lpfc_idiag_release - Release idiag access file operation
1218 * @inode: The inode pointer that contains a vport pointer. (unused)
1219 * @file: The file pointer that contains the buffer to release.
1220 *
1221 * Description:
1222 * This routine is the generic release routine for the idiag access file
1223 * operation, it frees the buffer that was allocated when the debugfs file
1224 * was opened.
1225 *
1226 * Returns:
1227 * This function returns zero.
1228 **/
1229static int
1230lpfc_idiag_release(struct inode *inode, struct file *file)
1231{
1232 struct lpfc_debug *debug = file->private_data;
1233
1234 /* Free the buffers to the file operation */
1235 kfree(debug->buffer);
1236 kfree(debug);
1237
1238 return 0;
1239}
1240
1241/**
1242 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1243 * @inode: The inode pointer that contains a vport pointer. (unused)
1244 * @file: The file pointer that contains the buffer to release.
1245 *
1246 * Description:
1247 * This routine frees the buffer that was allocated when the debugfs file
1248 * was opened. It also reset the fields in the idiag command struct in the
James Smart86a80842011-04-16 11:03:04 -04001249 * case of command for write operation.
James Smart2a622bf2011-02-16 12:40:06 -05001250 *
1251 * Returns:
1252 * This function returns zero.
1253 **/
1254static int
1255lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1256{
1257 struct lpfc_debug *debug = file->private_data;
1258
James Smart86a80842011-04-16 11:03:04 -04001259 if (debug->op == LPFC_IDIAG_OP_WR) {
1260 switch (idiag.cmd.opcode) {
1261 case LPFC_IDIAG_CMD_PCICFG_WR:
1262 case LPFC_IDIAG_CMD_PCICFG_ST:
1263 case LPFC_IDIAG_CMD_PCICFG_CL:
1264 case LPFC_IDIAG_CMD_QUEACC_WR:
1265 case LPFC_IDIAG_CMD_QUEACC_ST:
1266 case LPFC_IDIAG_CMD_QUEACC_CL:
James Smart2a622bf2011-02-16 12:40:06 -05001267 memset(&idiag, 0, sizeof(idiag));
James Smart86a80842011-04-16 11:03:04 -04001268 break;
1269 default:
1270 break;
1271 }
1272 }
James Smart2a622bf2011-02-16 12:40:06 -05001273
1274 /* Free the buffers to the file operation */
1275 kfree(debug->buffer);
1276 kfree(debug);
1277
1278 return 0;
1279}
1280
1281/**
1282 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1283 * @file: The file pointer to read from.
1284 * @buf: The buffer to copy the data to.
1285 * @nbytes: The number of bytes to read.
1286 * @ppos: The position in the file to start reading from.
1287 *
1288 * Description:
1289 * This routine reads data from the @phba pci config space according to the
1290 * idiag command, and copies to user @buf. Depending on the PCI config space
1291 * read command setup, it does either a single register read of a byte
1292 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1293 * registers from the 4K extended PCI config space.
1294 *
1295 * Returns:
1296 * This function returns the amount of data that was read (this could be less
1297 * than @nbytes if the end of the file was reached) or a negative error value.
1298 **/
1299static ssize_t
1300lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1301 loff_t *ppos)
1302{
1303 struct lpfc_debug *debug = file->private_data;
1304 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1305 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1306 int where, count;
1307 char *pbuffer;
1308 struct pci_dev *pdev;
1309 uint32_t u32val;
1310 uint16_t u16val;
1311 uint8_t u8val;
1312
1313 pdev = phba->pcidev;
1314 if (!pdev)
1315 return 0;
1316
1317 /* This is a user read operation */
1318 debug->op = LPFC_IDIAG_OP_RD;
1319
1320 if (!debug->buffer)
1321 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1322 if (!debug->buffer)
1323 return 0;
1324 pbuffer = debug->buffer;
1325
1326 if (*ppos)
1327 return 0;
1328
1329 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1330 where = idiag.cmd.data[0];
1331 count = idiag.cmd.data[1];
1332 } else
1333 return 0;
1334
1335 /* Read single PCI config space register */
1336 switch (count) {
1337 case SIZE_U8: /* byte (8 bits) */
1338 pci_read_config_byte(pdev, where, &u8val);
1339 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1340 "%03x: %02x\n", where, u8val);
1341 break;
1342 case SIZE_U16: /* word (16 bits) */
1343 pci_read_config_word(pdev, where, &u16val);
1344 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1345 "%03x: %04x\n", where, u16val);
1346 break;
1347 case SIZE_U32: /* double word (32 bits) */
1348 pci_read_config_dword(pdev, where, &u32val);
1349 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1350 "%03x: %08x\n", where, u32val);
1351 break;
James Smart86a80842011-04-16 11:03:04 -04001352 case LPFC_PCI_CFG_BROWSE: /* browse all */
James Smart2a622bf2011-02-16 12:40:06 -05001353 goto pcicfg_browse;
1354 break;
1355 default:
1356 /* illegal count */
1357 len = 0;
1358 break;
1359 }
1360 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1361
1362pcicfg_browse:
1363
1364 /* Browse all PCI config space registers */
1365 offset_label = idiag.offset.last_rd;
1366 offset = offset_label;
1367
1368 /* Read PCI config space */
1369 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1370 "%03x: ", offset_label);
1371 while (index > 0) {
1372 pci_read_config_dword(pdev, offset, &u32val);
1373 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1374 "%08x ", u32val);
1375 offset += sizeof(uint32_t);
1376 index -= sizeof(uint32_t);
1377 if (!index)
1378 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1379 "\n");
1380 else if (!(index % (8 * sizeof(uint32_t)))) {
1381 offset_label += (8 * sizeof(uint32_t));
1382 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1383 "\n%03x: ", offset_label);
1384 }
1385 }
1386
1387 /* Set up the offset for next portion of pci cfg read */
1388 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1389 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1390 idiag.offset.last_rd = 0;
1391
1392 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1393}
1394
1395/**
1396 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1397 * @file: The file pointer to read from.
1398 * @buf: The buffer to copy the user data from.
1399 * @nbytes: The number of bytes to get.
1400 * @ppos: The position in the file to start reading from.
1401 *
1402 * This routine get the debugfs idiag command struct from user space and
1403 * then perform the syntax check for PCI config space read or write command
1404 * accordingly. In the case of PCI config space read command, it sets up
1405 * the command in the idiag command struct for the debugfs read operation.
1406 * In the case of PCI config space write operation, it executes the write
1407 * operation into the PCI config space accordingly.
1408 *
1409 * It returns the @nbytges passing in from debugfs user space when successful.
1410 * In case of error conditions, it returns proper error code back to the user
1411 * space.
1412 */
1413static ssize_t
1414lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1415 size_t nbytes, loff_t *ppos)
1416{
1417 struct lpfc_debug *debug = file->private_data;
1418 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1419 uint32_t where, value, count;
1420 uint32_t u32val;
1421 uint16_t u16val;
1422 uint8_t u8val;
1423 struct pci_dev *pdev;
1424 int rc;
1425
1426 pdev = phba->pcidev;
1427 if (!pdev)
1428 return -EFAULT;
1429
1430 /* This is a user write operation */
1431 debug->op = LPFC_IDIAG_OP_WR;
1432
1433 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
James Smart86a80842011-04-16 11:03:04 -04001434 if (rc < 0)
James Smart2a622bf2011-02-16 12:40:06 -05001435 return rc;
1436
1437 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smart86a80842011-04-16 11:03:04 -04001438 /* Sanity check on PCI config read command line arguments */
1439 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1440 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001441 /* Read command from PCI config space, set up command fields */
1442 where = idiag.cmd.data[0];
1443 count = idiag.cmd.data[1];
James Smart86a80842011-04-16 11:03:04 -04001444 if (count == LPFC_PCI_CFG_BROWSE) {
1445 if (where % sizeof(uint32_t))
James Smart2a622bf2011-02-16 12:40:06 -05001446 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04001447 /* Starting offset to browse */
1448 idiag.offset.last_rd = where;
James Smart2a622bf2011-02-16 12:40:06 -05001449 } else if ((count != sizeof(uint8_t)) &&
1450 (count != sizeof(uint16_t)) &&
1451 (count != sizeof(uint32_t)))
1452 goto error_out;
1453 if (count == sizeof(uint8_t)) {
1454 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1455 goto error_out;
1456 if (where % sizeof(uint8_t))
1457 goto error_out;
1458 }
1459 if (count == sizeof(uint16_t)) {
1460 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1461 goto error_out;
1462 if (where % sizeof(uint16_t))
1463 goto error_out;
1464 }
1465 if (count == sizeof(uint32_t)) {
1466 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1467 goto error_out;
1468 if (where % sizeof(uint32_t))
1469 goto error_out;
1470 }
1471 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1472 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1473 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
James Smart86a80842011-04-16 11:03:04 -04001474 /* Sanity check on PCI config write command line arguments */
1475 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1476 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001477 /* Write command to PCI config space, read-modify-write */
1478 where = idiag.cmd.data[0];
1479 count = idiag.cmd.data[1];
1480 value = idiag.cmd.data[2];
1481 /* Sanity checks */
1482 if ((count != sizeof(uint8_t)) &&
1483 (count != sizeof(uint16_t)) &&
1484 (count != sizeof(uint32_t)))
1485 goto error_out;
1486 if (count == sizeof(uint8_t)) {
1487 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1488 goto error_out;
1489 if (where % sizeof(uint8_t))
1490 goto error_out;
1491 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1492 pci_write_config_byte(pdev, where,
1493 (uint8_t)value);
1494 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1495 rc = pci_read_config_byte(pdev, where, &u8val);
1496 if (!rc) {
1497 u8val |= (uint8_t)value;
1498 pci_write_config_byte(pdev, where,
1499 u8val);
1500 }
1501 }
1502 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1503 rc = pci_read_config_byte(pdev, where, &u8val);
1504 if (!rc) {
1505 u8val &= (uint8_t)(~value);
1506 pci_write_config_byte(pdev, where,
1507 u8val);
1508 }
1509 }
1510 }
1511 if (count == sizeof(uint16_t)) {
1512 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1513 goto error_out;
1514 if (where % sizeof(uint16_t))
1515 goto error_out;
1516 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1517 pci_write_config_word(pdev, where,
1518 (uint16_t)value);
1519 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1520 rc = pci_read_config_word(pdev, where, &u16val);
1521 if (!rc) {
1522 u16val |= (uint16_t)value;
1523 pci_write_config_word(pdev, where,
1524 u16val);
1525 }
1526 }
1527 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1528 rc = pci_read_config_word(pdev, where, &u16val);
1529 if (!rc) {
1530 u16val &= (uint16_t)(~value);
1531 pci_write_config_word(pdev, where,
1532 u16val);
1533 }
1534 }
1535 }
1536 if (count == sizeof(uint32_t)) {
1537 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1538 goto error_out;
1539 if (where % sizeof(uint32_t))
1540 goto error_out;
1541 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1542 pci_write_config_dword(pdev, where, value);
1543 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1544 rc = pci_read_config_dword(pdev, where,
1545 &u32val);
1546 if (!rc) {
1547 u32val |= value;
1548 pci_write_config_dword(pdev, where,
1549 u32val);
1550 }
1551 }
1552 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1553 rc = pci_read_config_dword(pdev, where,
1554 &u32val);
1555 if (!rc) {
1556 u32val &= ~value;
1557 pci_write_config_dword(pdev, where,
1558 u32val);
1559 }
1560 }
1561 }
1562 } else
1563 /* All other opecodes are illegal for now */
1564 goto error_out;
1565
1566 return nbytes;
1567error_out:
1568 memset(&idiag, 0, sizeof(idiag));
1569 return -EINVAL;
1570}
1571
1572/**
1573 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1574 * @file: The file pointer to read from.
1575 * @buf: The buffer to copy the data to.
1576 * @nbytes: The number of bytes to read.
1577 * @ppos: The position in the file to start reading from.
1578 *
1579 * Description:
1580 * This routine reads data from the @phba SLI4 PCI function queue information,
1581 * and copies to user @buf.
1582 *
1583 * Returns:
1584 * This function returns the amount of data that was read (this could be less
1585 * than @nbytes if the end of the file was reached) or a negative error value.
1586 **/
1587static ssize_t
1588lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
1589 loff_t *ppos)
1590{
1591 struct lpfc_debug *debug = file->private_data;
1592 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1593 int len = 0, fcp_qidx;
1594 char *pbuffer;
1595
1596 if (!debug->buffer)
1597 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
1598 if (!debug->buffer)
1599 return 0;
1600 pbuffer = debug->buffer;
1601
1602 if (*ppos)
1603 return 0;
1604
1605 /* Get slow-path event queue information */
1606 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1607 "Slow-path EQ information:\n");
1608 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001609 "\tEQID[%02d], "
1610 "QE-COUNT[%04d], QE-SIZE[%04d], "
1611 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05001612 phba->sli4_hba.sp_eq->queue_id,
1613 phba->sli4_hba.sp_eq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04001614 phba->sli4_hba.sp_eq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05001615 phba->sli4_hba.sp_eq->host_index,
1616 phba->sli4_hba.sp_eq->hba_index);
1617
1618 /* Get fast-path event queue information */
1619 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1620 "Fast-path EQ information:\n");
1621 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
1622 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001623 "\tEQID[%02d], "
1624 "QE-COUNT[%04d], QE-SIZE[%04d], "
1625 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05001626 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
1627 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
James Smart86a80842011-04-16 11:03:04 -04001628 phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05001629 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
1630 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
1631 }
1632 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1633
1634 /* Get mailbox complete queue information */
1635 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001636 "Slow-path MBX CQ information:\n");
James Smart2a622bf2011-02-16 12:40:06 -05001637 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001638 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05001639 phba->sli4_hba.mbx_cq->assoc_qid);
1640 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001641 "\tCQID[%02d], "
1642 "QE-COUNT[%04d], QE-SIZE[%04d], "
1643 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05001644 phba->sli4_hba.mbx_cq->queue_id,
1645 phba->sli4_hba.mbx_cq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04001646 phba->sli4_hba.mbx_cq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05001647 phba->sli4_hba.mbx_cq->host_index,
1648 phba->sli4_hba.mbx_cq->hba_index);
1649
1650 /* Get slow-path complete queue information */
1651 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001652 "Slow-path ELS CQ information:\n");
James Smart2a622bf2011-02-16 12:40:06 -05001653 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001654 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05001655 phba->sli4_hba.els_cq->assoc_qid);
1656 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001657 "\tCQID [%02d], "
1658 "QE-COUNT[%04d], QE-SIZE[%04d], "
1659 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05001660 phba->sli4_hba.els_cq->queue_id,
1661 phba->sli4_hba.els_cq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04001662 phba->sli4_hba.els_cq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05001663 phba->sli4_hba.els_cq->host_index,
1664 phba->sli4_hba.els_cq->hba_index);
1665
1666 /* Get fast-path complete queue information */
1667 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001668 "Fast-path FCP CQ information:\n");
James Smart05580562011-05-24 11:40:48 -04001669 fcp_qidx = 0;
1670 do {
James Smart2a622bf2011-02-16 12:40:06 -05001671 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001672 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05001673 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
1674 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001675 "\tCQID[%02d], "
1676 "QE-COUNT[%04d], QE-SIZE[%04d], "
1677 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
1678 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
1679 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
1680 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
1681 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
1682 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
James Smart05580562011-05-24 11:40:48 -04001683 } while (++fcp_qidx < phba->cfg_fcp_eq_count);
James Smart2a622bf2011-02-16 12:40:06 -05001684 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1685
1686 /* Get mailbox queue information */
1687 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001688 "Slow-path MBX MQ information:\n");
James Smart2a622bf2011-02-16 12:40:06 -05001689 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001690 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05001691 phba->sli4_hba.mbx_wq->assoc_qid);
1692 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001693 "\tWQID[%02d], "
1694 "QE-COUNT[%04d], QE-SIZE[%04d], "
1695 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05001696 phba->sli4_hba.mbx_wq->queue_id,
1697 phba->sli4_hba.mbx_wq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04001698 phba->sli4_hba.mbx_wq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05001699 phba->sli4_hba.mbx_wq->host_index,
1700 phba->sli4_hba.mbx_wq->hba_index);
1701
1702 /* Get slow-path work queue information */
1703 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001704 "Slow-path ELS WQ information:\n");
James Smart2a622bf2011-02-16 12:40:06 -05001705 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001706 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05001707 phba->sli4_hba.els_wq->assoc_qid);
1708 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001709 "\tWQID[%02d], "
1710 "QE-COUNT[%04d], QE-SIZE[%04d], "
1711 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05001712 phba->sli4_hba.els_wq->queue_id,
1713 phba->sli4_hba.els_wq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04001714 phba->sli4_hba.els_wq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05001715 phba->sli4_hba.els_wq->host_index,
1716 phba->sli4_hba.els_wq->hba_index);
1717
1718 /* Get fast-path work queue information */
1719 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001720 "Fast-path FCP WQ information:\n");
James Smart2a622bf2011-02-16 12:40:06 -05001721 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
1722 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001723 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05001724 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
1725 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001726 "\tWQID[%02d], "
1727 "QE-COUNT[%04d], WQE-SIZE[%04d], "
1728 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05001729 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
1730 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
James Smart86a80842011-04-16 11:03:04 -04001731 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05001732 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
1733 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
1734 }
1735 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
1736
1737 /* Get receive queue information */
1738 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
1739 "Slow-path RQ information:\n");
1740 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001741 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05001742 phba->sli4_hba.hdr_rq->assoc_qid);
1743 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001744 "\tHQID[%02d], "
1745 "QE-COUNT[%04d], QE-SIZE[%04d], "
1746 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05001747 phba->sli4_hba.hdr_rq->queue_id,
1748 phba->sli4_hba.hdr_rq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04001749 phba->sli4_hba.hdr_rq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05001750 phba->sli4_hba.hdr_rq->host_index,
1751 phba->sli4_hba.hdr_rq->hba_index);
1752 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04001753 "\tDQID[%02d], "
1754 "QE-COUNT[%04d], QE-SIZE[%04d], "
1755 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05001756 phba->sli4_hba.dat_rq->queue_id,
1757 phba->sli4_hba.dat_rq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04001758 phba->sli4_hba.dat_rq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05001759 phba->sli4_hba.dat_rq->host_index,
1760 phba->sli4_hba.dat_rq->hba_index);
1761
1762 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1763}
1764
James Smart86a80842011-04-16 11:03:04 -04001765/**
1766 * lpfc_idiag_que_param_check - queue access command parameter sanity check
1767 * @q: The pointer to queue structure.
1768 * @index: The index into a queue entry.
1769 * @count: The number of queue entries to access.
1770 *
1771 * Description:
1772 * The routine performs sanity check on device queue access method commands.
1773 *
1774 * Returns:
1775 * This function returns -EINVAL when fails the sanity check, otherwise, it
1776 * returns 0.
1777 **/
1778static int
1779lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
1780{
1781 /* Only support single entry read or browsing */
1782 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
1783 return -EINVAL;
1784 if (index > q->entry_count - 1)
1785 return -EINVAL;
1786 return 0;
1787}
1788
1789/**
1790 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
1791 * @pbuffer: The pointer to buffer to copy the read data into.
1792 * @pque: The pointer to the queue to be read.
1793 * @index: The index into the queue entry.
1794 *
1795 * Description:
1796 * This routine reads out a single entry from the given queue's index location
1797 * and copies it into the buffer provided.
1798 *
1799 * Returns:
1800 * This function returns 0 when it fails, otherwise, it returns the length of
1801 * the data read into the buffer provided.
1802 **/
1803static int
1804lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
1805 uint32_t index)
1806{
1807 int offset, esize;
1808 uint32_t *pentry;
1809
1810 if (!pbuffer || !pque)
1811 return 0;
1812
1813 esize = pque->entry_size;
1814 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
1815 "QE-INDEX[%04d]:\n", index);
1816
1817 offset = 0;
1818 pentry = pque->qe[index].address;
1819 while (esize > 0) {
1820 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
1821 "%08x ", *pentry);
1822 pentry++;
1823 offset += sizeof(uint32_t);
1824 esize -= sizeof(uint32_t);
1825 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
1826 len += snprintf(pbuffer+len,
1827 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
1828 }
1829 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
1830
1831 return len;
1832}
1833
1834/**
1835 * lpfc_idiag_queacc_read - idiag debugfs read port queue
1836 * @file: The file pointer to read from.
1837 * @buf: The buffer to copy the data to.
1838 * @nbytes: The number of bytes to read.
1839 * @ppos: The position in the file to start reading from.
1840 *
1841 * Description:
1842 * This routine reads data from the @phba device queue memory according to the
1843 * idiag command, and copies to user @buf. Depending on the queue dump read
1844 * command setup, it does either a single queue entry read or browing through
1845 * all entries of the queue.
1846 *
1847 * Returns:
1848 * This function returns the amount of data that was read (this could be less
1849 * than @nbytes if the end of the file was reached) or a negative error value.
1850 **/
1851static ssize_t
1852lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
1853 loff_t *ppos)
1854{
1855 struct lpfc_debug *debug = file->private_data;
1856 uint32_t last_index, index, count;
1857 struct lpfc_queue *pque = NULL;
1858 char *pbuffer;
1859 int len = 0;
1860
1861 /* This is a user read operation */
1862 debug->op = LPFC_IDIAG_OP_RD;
1863
1864 if (!debug->buffer)
1865 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
1866 if (!debug->buffer)
1867 return 0;
1868 pbuffer = debug->buffer;
1869
1870 if (*ppos)
1871 return 0;
1872
1873 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
1874 index = idiag.cmd.data[2];
1875 count = idiag.cmd.data[3];
1876 pque = (struct lpfc_queue *)idiag.ptr_private;
1877 } else
1878 return 0;
1879
1880 /* Browse the queue starting from index */
1881 if (count == LPFC_QUE_ACC_BROWSE)
1882 goto que_browse;
1883
1884 /* Read a single entry from the queue */
1885 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
1886
1887 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1888
1889que_browse:
1890
1891 /* Browse all entries from the queue */
1892 last_index = idiag.offset.last_rd;
1893 index = last_index;
1894
1895 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
1896 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
1897 index++;
1898 if (index > pque->entry_count - 1)
1899 break;
1900 }
1901
1902 /* Set up the offset for next portion of pci cfg read */
1903 if (index > pque->entry_count - 1)
1904 index = 0;
1905 idiag.offset.last_rd = index;
1906
1907 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1908}
1909
1910/**
1911 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
1912 * @file: The file pointer to read from.
1913 * @buf: The buffer to copy the user data from.
1914 * @nbytes: The number of bytes to get.
1915 * @ppos: The position in the file to start reading from.
1916 *
1917 * This routine get the debugfs idiag command struct from user space and then
1918 * perform the syntax check for port queue read (dump) or write (set) command
1919 * accordingly. In the case of port queue read command, it sets up the command
1920 * in the idiag command struct for the following debugfs read operation. In
1921 * the case of port queue write operation, it executes the write operation
1922 * into the port queue entry accordingly.
1923 *
1924 * It returns the @nbytges passing in from debugfs user space when successful.
1925 * In case of error conditions, it returns proper error code back to the user
1926 * space.
1927 **/
1928static ssize_t
1929lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
1930 size_t nbytes, loff_t *ppos)
1931{
1932 struct lpfc_debug *debug = file->private_data;
1933 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1934 uint32_t qidx, quetp, queid, index, count, offset, value;
1935 uint32_t *pentry;
1936 struct lpfc_queue *pque;
1937 int rc;
1938
1939 /* This is a user write operation */
1940 debug->op = LPFC_IDIAG_OP_WR;
1941
1942 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1943 if (rc < 0)
1944 return rc;
1945
1946 /* Get and sanity check on command feilds */
1947 quetp = idiag.cmd.data[0];
1948 queid = idiag.cmd.data[1];
1949 index = idiag.cmd.data[2];
1950 count = idiag.cmd.data[3];
1951 offset = idiag.cmd.data[4];
1952 value = idiag.cmd.data[5];
1953
1954 /* Sanity check on command line arguments */
1955 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
1956 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
1957 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
1958 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
1959 goto error_out;
1960 if (count != 1)
1961 goto error_out;
1962 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
1963 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
1964 goto error_out;
1965 } else
1966 goto error_out;
1967
1968 switch (quetp) {
1969 case LPFC_IDIAG_EQ:
1970 /* Slow-path event queue */
1971 if (phba->sli4_hba.sp_eq->queue_id == queid) {
1972 /* Sanity check */
1973 rc = lpfc_idiag_que_param_check(
1974 phba->sli4_hba.sp_eq, index, count);
1975 if (rc)
1976 goto error_out;
1977 idiag.ptr_private = phba->sli4_hba.sp_eq;
1978 goto pass_check;
1979 }
1980 /* Fast-path event queue */
1981 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
1982 if (phba->sli4_hba.fp_eq[qidx]->queue_id == queid) {
1983 /* Sanity check */
1984 rc = lpfc_idiag_que_param_check(
1985 phba->sli4_hba.fp_eq[qidx],
1986 index, count);
1987 if (rc)
1988 goto error_out;
1989 idiag.ptr_private = phba->sli4_hba.fp_eq[qidx];
1990 goto pass_check;
1991 }
1992 }
1993 goto error_out;
1994 break;
1995 case LPFC_IDIAG_CQ:
1996 /* MBX complete queue */
1997 if (phba->sli4_hba.mbx_cq->queue_id == queid) {
1998 /* Sanity check */
1999 rc = lpfc_idiag_que_param_check(
2000 phba->sli4_hba.mbx_cq, index, count);
2001 if (rc)
2002 goto error_out;
2003 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2004 goto pass_check;
2005 }
2006 /* ELS complete queue */
2007 if (phba->sli4_hba.els_cq->queue_id == queid) {
2008 /* Sanity check */
2009 rc = lpfc_idiag_que_param_check(
2010 phba->sli4_hba.els_cq, index, count);
2011 if (rc)
2012 goto error_out;
2013 idiag.ptr_private = phba->sli4_hba.els_cq;
2014 goto pass_check;
2015 }
2016 /* FCP complete queue */
James Smart05580562011-05-24 11:40:48 -04002017 qidx = 0;
2018 do {
James Smart86a80842011-04-16 11:03:04 -04002019 if (phba->sli4_hba.fcp_cq[qidx]->queue_id == queid) {
2020 /* Sanity check */
2021 rc = lpfc_idiag_que_param_check(
2022 phba->sli4_hba.fcp_cq[qidx],
2023 index, count);
2024 if (rc)
2025 goto error_out;
2026 idiag.ptr_private =
2027 phba->sli4_hba.fcp_cq[qidx];
2028 goto pass_check;
2029 }
James Smart05580562011-05-24 11:40:48 -04002030 } while (++qidx < phba->cfg_fcp_eq_count);
James Smart86a80842011-04-16 11:03:04 -04002031 goto error_out;
2032 break;
2033 case LPFC_IDIAG_MQ:
2034 /* MBX work queue */
2035 if (phba->sli4_hba.mbx_wq->queue_id == queid) {
2036 /* Sanity check */
2037 rc = lpfc_idiag_que_param_check(
2038 phba->sli4_hba.mbx_wq, index, count);
2039 if (rc)
2040 goto error_out;
2041 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2042 goto pass_check;
2043 }
2044 break;
2045 case LPFC_IDIAG_WQ:
2046 /* ELS work queue */
2047 if (phba->sli4_hba.els_wq->queue_id == queid) {
2048 /* Sanity check */
2049 rc = lpfc_idiag_que_param_check(
2050 phba->sli4_hba.els_wq, index, count);
2051 if (rc)
2052 goto error_out;
2053 idiag.ptr_private = phba->sli4_hba.els_wq;
2054 goto pass_check;
2055 }
2056 /* FCP work queue */
2057 for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
2058 if (phba->sli4_hba.fcp_wq[qidx]->queue_id == queid) {
2059 /* Sanity check */
2060 rc = lpfc_idiag_que_param_check(
2061 phba->sli4_hba.fcp_wq[qidx],
2062 index, count);
2063 if (rc)
2064 goto error_out;
2065 idiag.ptr_private =
2066 phba->sli4_hba.fcp_wq[qidx];
2067 goto pass_check;
2068 }
2069 }
2070 goto error_out;
2071 break;
2072 case LPFC_IDIAG_RQ:
2073 /* HDR queue */
2074 if (phba->sli4_hba.hdr_rq->queue_id == queid) {
2075 /* Sanity check */
2076 rc = lpfc_idiag_que_param_check(
2077 phba->sli4_hba.hdr_rq, index, count);
2078 if (rc)
2079 goto error_out;
2080 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2081 goto pass_check;
2082 }
2083 /* DAT queue */
2084 if (phba->sli4_hba.dat_rq->queue_id == queid) {
2085 /* Sanity check */
2086 rc = lpfc_idiag_que_param_check(
2087 phba->sli4_hba.dat_rq, index, count);
2088 if (rc)
2089 goto error_out;
2090 idiag.ptr_private = phba->sli4_hba.dat_rq;
2091 goto pass_check;
2092 }
2093 goto error_out;
2094 break;
2095 default:
2096 goto error_out;
2097 break;
2098 }
2099
2100pass_check:
2101
2102 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2103 if (count == LPFC_QUE_ACC_BROWSE)
2104 idiag.offset.last_rd = index;
2105 }
2106
2107 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2108 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2109 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2110 /* Additional sanity checks on write operation */
2111 pque = (struct lpfc_queue *)idiag.ptr_private;
2112 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2113 goto error_out;
2114 pentry = pque->qe[index].address;
2115 pentry += offset;
2116 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2117 *pentry = value;
2118 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2119 *pentry |= value;
2120 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2121 *pentry &= ~value;
2122 }
2123 return nbytes;
2124
2125error_out:
2126 /* Clean out command structure on command error out */
2127 memset(&idiag, 0, sizeof(idiag));
2128 return -EINVAL;
2129}
2130
2131/**
2132 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2133 * @phba: The pointer to hba structure.
2134 * @pbuffer: The pointer to the buffer to copy the data to.
2135 * @len: The lenght of bytes to copied.
2136 * @drbregid: The id to doorbell registers.
2137 *
2138 * Description:
2139 * This routine reads a doorbell register and copies its content to the
2140 * user buffer pointed to by @pbuffer.
2141 *
2142 * Returns:
2143 * This function returns the amount of data that was copied into @pbuffer.
2144 **/
2145static int
2146lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2147 int len, uint32_t drbregid)
2148{
2149
2150 if (!pbuffer)
2151 return 0;
2152
2153 switch (drbregid) {
2154 case LPFC_DRB_EQCQ:
2155 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2156 "EQCQ-DRB-REG: 0x%08x\n",
2157 readl(phba->sli4_hba.EQCQDBregaddr));
2158 break;
2159 case LPFC_DRB_MQ:
2160 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2161 "MQ-DRB-REG: 0x%08x\n",
2162 readl(phba->sli4_hba.MQDBregaddr));
2163 break;
2164 case LPFC_DRB_WQ:
2165 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2166 "WQ-DRB-REG: 0x%08x\n",
2167 readl(phba->sli4_hba.WQDBregaddr));
2168 break;
2169 case LPFC_DRB_RQ:
2170 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2171 "RQ-DRB-REG: 0x%08x\n",
2172 readl(phba->sli4_hba.RQDBregaddr));
2173 break;
2174 default:
2175 break;
2176 }
2177
2178 return len;
2179}
2180
2181/**
2182 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2183 * @file: The file pointer to read from.
2184 * @buf: The buffer to copy the data to.
2185 * @nbytes: The number of bytes to read.
2186 * @ppos: The position in the file to start reading from.
2187 *
2188 * Description:
2189 * This routine reads data from the @phba device doorbell register according
2190 * to the idiag command, and copies to user @buf. Depending on the doorbell
2191 * register read command setup, it does either a single doorbell register
2192 * read or dump all doorbell registers.
2193 *
2194 * Returns:
2195 * This function returns the amount of data that was read (this could be less
2196 * than @nbytes if the end of the file was reached) or a negative error value.
2197 **/
2198static ssize_t
2199lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2200 loff_t *ppos)
2201{
2202 struct lpfc_debug *debug = file->private_data;
2203 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2204 uint32_t drb_reg_id, i;
2205 char *pbuffer;
2206 int len = 0;
2207
2208 /* This is a user read operation */
2209 debug->op = LPFC_IDIAG_OP_RD;
2210
2211 if (!debug->buffer)
2212 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2213 if (!debug->buffer)
2214 return 0;
2215 pbuffer = debug->buffer;
2216
2217 if (*ppos)
2218 return 0;
2219
2220 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
2221 drb_reg_id = idiag.cmd.data[0];
2222 else
2223 return 0;
2224
2225 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2226 for (i = 1; i <= LPFC_DRB_MAX; i++)
2227 len = lpfc_idiag_drbacc_read_reg(phba,
2228 pbuffer, len, i);
2229 else
2230 len = lpfc_idiag_drbacc_read_reg(phba,
2231 pbuffer, len, drb_reg_id);
2232
2233 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2234}
2235
2236/**
2237 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2238 * @file: The file pointer to read from.
2239 * @buf: The buffer to copy the user data from.
2240 * @nbytes: The number of bytes to get.
2241 * @ppos: The position in the file to start reading from.
2242 *
2243 * This routine get the debugfs idiag command struct from user space and then
2244 * perform the syntax check for port doorbell register read (dump) or write
2245 * (set) command accordingly. In the case of port queue read command, it sets
2246 * up the command in the idiag command struct for the following debugfs read
2247 * operation. In the case of port doorbell register write operation, it
2248 * executes the write operation into the port doorbell register accordingly.
2249 *
2250 * It returns the @nbytges passing in from debugfs user space when successful.
2251 * In case of error conditions, it returns proper error code back to the user
2252 * space.
2253 **/
2254static ssize_t
2255lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2256 size_t nbytes, loff_t *ppos)
2257{
2258 struct lpfc_debug *debug = file->private_data;
2259 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2260 uint32_t drb_reg_id, value, reg_val;
2261 void __iomem *drb_reg;
2262 int rc;
2263
2264 /* This is a user write operation */
2265 debug->op = LPFC_IDIAG_OP_WR;
2266
2267 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2268 if (rc < 0)
2269 return rc;
2270
2271 /* Sanity check on command line arguments */
2272 drb_reg_id = idiag.cmd.data[0];
2273 value = idiag.cmd.data[1];
2274
2275 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2276 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2277 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2278 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2279 goto error_out;
2280 if (drb_reg_id > LPFC_DRB_MAX)
2281 goto error_out;
2282 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2283 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2284 goto error_out;
2285 if ((drb_reg_id > LPFC_DRB_MAX) &&
2286 (drb_reg_id != LPFC_DRB_ACC_ALL))
2287 goto error_out;
2288 } else
2289 goto error_out;
2290
2291 /* Perform the write access operation */
2292 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2293 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2294 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2295 switch (drb_reg_id) {
2296 case LPFC_DRB_EQCQ:
2297 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2298 break;
2299 case LPFC_DRB_MQ:
2300 drb_reg = phba->sli4_hba.MQDBregaddr;
2301 break;
2302 case LPFC_DRB_WQ:
2303 drb_reg = phba->sli4_hba.WQDBregaddr;
2304 break;
2305 case LPFC_DRB_RQ:
2306 drb_reg = phba->sli4_hba.RQDBregaddr;
2307 break;
2308 default:
2309 goto error_out;
2310 }
2311
2312 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2313 reg_val = value;
2314 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2315 reg_val = readl(drb_reg);
2316 reg_val |= value;
2317 }
2318 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2319 reg_val = readl(drb_reg);
2320 reg_val &= ~value;
2321 }
2322 writel(reg_val, drb_reg);
2323 readl(drb_reg); /* flush */
2324 }
2325 return nbytes;
2326
2327error_out:
2328 /* Clean out command structure on command error out */
2329 memset(&idiag, 0, sizeof(idiag));
2330 return -EINVAL;
2331}
2332
James Smart858c9f62007-06-17 19:56:39 -05002333#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01002334static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05002335 .owner = THIS_MODULE,
2336 .open = lpfc_debugfs_disc_trc_open,
2337 .llseek = lpfc_debugfs_lseek,
2338 .read = lpfc_debugfs_read,
2339 .release = lpfc_debugfs_release,
2340};
2341
2342#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01002343static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05002344 .owner = THIS_MODULE,
2345 .open = lpfc_debugfs_nodelist_open,
2346 .llseek = lpfc_debugfs_lseek,
2347 .read = lpfc_debugfs_read,
2348 .release = lpfc_debugfs_release,
2349};
2350
James Smart78b2d852007-08-02 11:10:21 -04002351#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01002352static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04002353 .owner = THIS_MODULE,
2354 .open = lpfc_debugfs_hbqinfo_open,
2355 .llseek = lpfc_debugfs_lseek,
2356 .read = lpfc_debugfs_read,
2357 .release = lpfc_debugfs_release,
2358};
2359
James Smartc95d6c62008-01-11 01:53:23 -05002360#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01002361static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04002362 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05002363 .open = lpfc_debugfs_dumpHBASlim_open,
2364 .llseek = lpfc_debugfs_lseek,
2365 .read = lpfc_debugfs_read,
2366 .release = lpfc_debugfs_release,
2367};
2368
2369#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01002370static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05002371 .owner = THIS_MODULE,
2372 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04002373 .llseek = lpfc_debugfs_lseek,
2374 .read = lpfc_debugfs_read,
2375 .release = lpfc_debugfs_release,
2376};
2377
James Smarte2a0a9d2008-12-04 22:40:02 -05002378#undef lpfc_debugfs_op_dumpData
Jan Engelhardt71fa7422009-01-11 10:38:59 +01002379static const struct file_operations lpfc_debugfs_op_dumpData = {
James Smarte2a0a9d2008-12-04 22:40:02 -05002380 .owner = THIS_MODULE,
2381 .open = lpfc_debugfs_dumpData_open,
2382 .llseek = lpfc_debugfs_lseek,
2383 .read = lpfc_debugfs_read,
2384 .write = lpfc_debugfs_dumpDataDif_write,
2385 .release = lpfc_debugfs_dumpDataDif_release,
2386};
2387
2388#undef lpfc_debugfs_op_dumpDif
Jan Engelhardt71fa7422009-01-11 10:38:59 +01002389static const struct file_operations lpfc_debugfs_op_dumpDif = {
James Smarte2a0a9d2008-12-04 22:40:02 -05002390 .owner = THIS_MODULE,
2391 .open = lpfc_debugfs_dumpDif_open,
2392 .llseek = lpfc_debugfs_lseek,
2393 .read = lpfc_debugfs_read,
2394 .write = lpfc_debugfs_dumpDataDif_write,
2395 .release = lpfc_debugfs_dumpDataDif_release,
2396};
2397
James Smarta58cbd52007-08-02 11:09:43 -04002398#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01002399static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04002400 .owner = THIS_MODULE,
2401 .open = lpfc_debugfs_slow_ring_trc_open,
2402 .llseek = lpfc_debugfs_lseek,
2403 .read = lpfc_debugfs_read,
2404 .release = lpfc_debugfs_release,
2405};
2406
James Smart858c9f62007-06-17 19:56:39 -05002407static struct dentry *lpfc_debugfs_root = NULL;
2408static atomic_t lpfc_debugfs_hba_count;
James Smart2a622bf2011-02-16 12:40:06 -05002409
2410/*
2411 * File operations for the iDiag debugfs
2412 */
2413#undef lpfc_idiag_op_pciCfg
2414static const struct file_operations lpfc_idiag_op_pciCfg = {
2415 .owner = THIS_MODULE,
2416 .open = lpfc_idiag_open,
2417 .llseek = lpfc_debugfs_lseek,
2418 .read = lpfc_idiag_pcicfg_read,
2419 .write = lpfc_idiag_pcicfg_write,
2420 .release = lpfc_idiag_cmd_release,
2421};
2422
2423#undef lpfc_idiag_op_queInfo
2424static const struct file_operations lpfc_idiag_op_queInfo = {
2425 .owner = THIS_MODULE,
2426 .open = lpfc_idiag_open,
2427 .read = lpfc_idiag_queinfo_read,
2428 .release = lpfc_idiag_release,
2429};
2430
James Smart86a80842011-04-16 11:03:04 -04002431#undef lpfc_idiag_op_queacc
2432static const struct file_operations lpfc_idiag_op_queAcc = {
2433 .owner = THIS_MODULE,
2434 .open = lpfc_idiag_open,
2435 .llseek = lpfc_debugfs_lseek,
2436 .read = lpfc_idiag_queacc_read,
2437 .write = lpfc_idiag_queacc_write,
2438 .release = lpfc_idiag_cmd_release,
2439};
2440
2441#undef lpfc_idiag_op_drbacc
2442static const struct file_operations lpfc_idiag_op_drbAcc = {
2443 .owner = THIS_MODULE,
2444 .open = lpfc_idiag_open,
2445 .llseek = lpfc_debugfs_lseek,
2446 .read = lpfc_idiag_drbacc_read,
2447 .write = lpfc_idiag_drbacc_write,
2448 .release = lpfc_idiag_cmd_release,
2449};
2450
James Smart858c9f62007-06-17 19:56:39 -05002451#endif
2452
James Smarte59058c2008-08-24 21:49:00 -04002453/**
James Smart3621a712009-04-06 18:47:14 -04002454 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04002455 * @vport: The vport pointer to initialize.
2456 *
2457 * Description:
2458 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
2459 * If not already created, this routine will create the lpfc directory, and
2460 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
2461 * also create each file used to access lpfc specific debugfs information.
2462 **/
James Smart858c9f62007-06-17 19:56:39 -05002463inline void
2464lpfc_debugfs_initialize(struct lpfc_vport *vport)
2465{
James Smart923e4b62008-12-04 22:40:07 -05002466#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05002467 struct lpfc_hba *phba = vport->phba;
2468 char name[64];
2469 uint32_t num, i;
2470
2471 if (!lpfc_debugfs_enable)
2472 return;
2473
James Smarta58cbd52007-08-02 11:09:43 -04002474 /* Setup lpfc root directory */
2475 if (!lpfc_debugfs_root) {
2476 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
2477 atomic_set(&lpfc_debugfs_hba_count, 0);
2478 if (!lpfc_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04002479 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002480 "0408 Cannot create debugfs root\n");
James Smarta58cbd52007-08-02 11:09:43 -04002481 goto debug_failed;
2482 }
2483 }
James Smarta58cbd52007-08-02 11:09:43 -04002484 if (!lpfc_debugfs_start_time)
2485 lpfc_debugfs_start_time = jiffies;
2486
James Smart2a622bf2011-02-16 12:40:06 -05002487 /* Setup funcX directory for specific HBA PCI function */
2488 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
James Smarta58cbd52007-08-02 11:09:43 -04002489 if (!phba->hba_debugfs_root) {
2490 phba->hba_debugfs_root =
2491 debugfs_create_dir(name, lpfc_debugfs_root);
2492 if (!phba->hba_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04002493 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002494 "0412 Cannot create debugfs hba\n");
James Smarta58cbd52007-08-02 11:09:43 -04002495 goto debug_failed;
2496 }
2497 atomic_inc(&lpfc_debugfs_hba_count);
2498 atomic_set(&phba->debugfs_vport_count, 0);
2499
James Smart78b2d852007-08-02 11:10:21 -04002500 /* Setup hbqinfo */
2501 snprintf(name, sizeof(name), "hbqinfo");
2502 phba->debug_hbqinfo =
2503 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2504 phba->hba_debugfs_root,
2505 phba, &lpfc_debugfs_op_hbqinfo);
2506 if (!phba->debug_hbqinfo) {
2507 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002508 "0411 Cannot create debugfs hbqinfo\n");
James Smart78b2d852007-08-02 11:10:21 -04002509 goto debug_failed;
2510 }
2511
James Smartc95d6c62008-01-11 01:53:23 -05002512 /* Setup dumpHBASlim */
James Smart2a622bf2011-02-16 12:40:06 -05002513 if (phba->sli_rev < LPFC_SLI_REV4) {
2514 snprintf(name, sizeof(name), "dumpHBASlim");
2515 phba->debug_dumpHBASlim =
2516 debugfs_create_file(name,
2517 S_IFREG|S_IRUGO|S_IWUSR,
2518 phba->hba_debugfs_root,
2519 phba, &lpfc_debugfs_op_dumpHBASlim);
2520 if (!phba->debug_dumpHBASlim) {
2521 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2522 "0413 Cannot create debugfs "
2523 "dumpHBASlim\n");
2524 goto debug_failed;
2525 }
2526 } else
2527 phba->debug_dumpHBASlim = NULL;
James Smartc95d6c62008-01-11 01:53:23 -05002528
2529 /* Setup dumpHostSlim */
James Smart2a622bf2011-02-16 12:40:06 -05002530 if (phba->sli_rev < LPFC_SLI_REV4) {
2531 snprintf(name, sizeof(name), "dumpHostSlim");
2532 phba->debug_dumpHostSlim =
2533 debugfs_create_file(name,
2534 S_IFREG|S_IRUGO|S_IWUSR,
2535 phba->hba_debugfs_root,
2536 phba, &lpfc_debugfs_op_dumpHostSlim);
2537 if (!phba->debug_dumpHostSlim) {
2538 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2539 "0414 Cannot create debugfs "
2540 "dumpHostSlim\n");
2541 goto debug_failed;
2542 }
2543 } else
2544 phba->debug_dumpHBASlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04002545
James Smarte2a0a9d2008-12-04 22:40:02 -05002546 /* Setup dumpData */
2547 snprintf(name, sizeof(name), "dumpData");
2548 phba->debug_dumpData =
2549 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2550 phba->hba_debugfs_root,
2551 phba, &lpfc_debugfs_op_dumpData);
2552 if (!phba->debug_dumpData) {
2553 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2554 "0800 Cannot create debugfs dumpData\n");
2555 goto debug_failed;
2556 }
2557
2558 /* Setup dumpDif */
2559 snprintf(name, sizeof(name), "dumpDif");
2560 phba->debug_dumpDif =
2561 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2562 phba->hba_debugfs_root,
2563 phba, &lpfc_debugfs_op_dumpDif);
2564 if (!phba->debug_dumpDif) {
2565 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2566 "0801 Cannot create debugfs dumpDif\n");
2567 goto debug_failed;
2568 }
2569
James Smarta58cbd52007-08-02 11:09:43 -04002570 /* Setup slow ring trace */
2571 if (lpfc_debugfs_max_slow_ring_trc) {
2572 num = lpfc_debugfs_max_slow_ring_trc - 1;
2573 if (num & lpfc_debugfs_max_slow_ring_trc) {
2574 /* Change to be a power of 2 */
2575 num = lpfc_debugfs_max_slow_ring_trc;
2576 i = 0;
2577 while (num > 1) {
2578 num = num >> 1;
2579 i++;
2580 }
2581 lpfc_debugfs_max_slow_ring_trc = (1 << i);
2582 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04002583 "lpfc_debugfs_max_disc_trc changed to "
2584 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04002585 }
2586 }
2587
James Smarta58cbd52007-08-02 11:09:43 -04002588 snprintf(name, sizeof(name), "slow_ring_trace");
2589 phba->debug_slow_ring_trc =
2590 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2591 phba->hba_debugfs_root,
2592 phba, &lpfc_debugfs_op_slow_ring_trc);
2593 if (!phba->debug_slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04002594 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002595 "0415 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04002596 "slow_ring_trace\n");
James Smarta58cbd52007-08-02 11:09:43 -04002597 goto debug_failed;
2598 }
2599 if (!phba->slow_ring_trc) {
2600 phba->slow_ring_trc = kmalloc(
2601 (sizeof(struct lpfc_debugfs_trc) *
2602 lpfc_debugfs_max_slow_ring_trc),
2603 GFP_KERNEL);
2604 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04002605 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002606 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04002607 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04002608 goto debug_failed;
2609 }
2610 atomic_set(&phba->slow_ring_trc_cnt, 0);
2611 memset(phba->slow_ring_trc, 0,
2612 (sizeof(struct lpfc_debugfs_trc) *
2613 lpfc_debugfs_max_slow_ring_trc));
2614 }
2615 }
2616
2617 snprintf(name, sizeof(name), "vport%d", vport->vpi);
2618 if (!vport->vport_debugfs_root) {
2619 vport->vport_debugfs_root =
2620 debugfs_create_dir(name, phba->hba_debugfs_root);
2621 if (!vport->vport_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04002622 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002623 "0417 Can't create debugfs\n");
James Smarta58cbd52007-08-02 11:09:43 -04002624 goto debug_failed;
2625 }
2626 atomic_inc(&phba->debugfs_vport_count);
2627 }
2628
James Smart858c9f62007-06-17 19:56:39 -05002629 if (lpfc_debugfs_max_disc_trc) {
2630 num = lpfc_debugfs_max_disc_trc - 1;
2631 if (num & lpfc_debugfs_max_disc_trc) {
2632 /* Change to be a power of 2 */
2633 num = lpfc_debugfs_max_disc_trc;
2634 i = 0;
2635 while (num > 1) {
2636 num = num >> 1;
2637 i++;
2638 }
2639 lpfc_debugfs_max_disc_trc = (1 << i);
2640 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04002641 "lpfc_debugfs_max_disc_trc changed to %d\n",
2642 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05002643 }
2644 }
2645
Adrian Bunkff86ba52007-10-18 12:52:37 +02002646 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04002647 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05002648 GFP_KERNEL);
2649
James Smarta58cbd52007-08-02 11:09:43 -04002650 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04002651 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002652 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04002653 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05002654 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04002655 }
2656 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05002657
2658 snprintf(name, sizeof(name), "discovery_trace");
2659 vport->debug_disc_trc =
2660 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2661 vport->vport_debugfs_root,
2662 vport, &lpfc_debugfs_op_disc_trc);
2663 if (!vport->debug_disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04002664 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04002665 "0419 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04002666 "discovery_trace\n");
James Smart858c9f62007-06-17 19:56:39 -05002667 goto debug_failed;
2668 }
2669 snprintf(name, sizeof(name), "nodelist");
2670 vport->debug_nodelist =
2671 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2672 vport->vport_debugfs_root,
2673 vport, &lpfc_debugfs_op_nodelist);
2674 if (!vport->debug_nodelist) {
James Smarte8b62012007-08-02 11:10:09 -04002675 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002676 "0409 Can't create debugfs nodelist\n");
James Smart858c9f62007-06-17 19:56:39 -05002677 goto debug_failed;
2678 }
James Smart2a622bf2011-02-16 12:40:06 -05002679
2680 /*
2681 * iDiag debugfs root entry points for SLI4 device only
2682 */
2683 if (phba->sli_rev < LPFC_SLI_REV4)
2684 goto debug_failed;
2685
2686 snprintf(name, sizeof(name), "iDiag");
2687 if (!phba->idiag_root) {
2688 phba->idiag_root =
2689 debugfs_create_dir(name, phba->hba_debugfs_root);
2690 if (!phba->idiag_root) {
2691 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2692 "2922 Can't create idiag debugfs\n");
2693 goto debug_failed;
2694 }
2695 /* Initialize iDiag data structure */
2696 memset(&idiag, 0, sizeof(idiag));
2697 }
2698
2699 /* iDiag read PCI config space */
2700 snprintf(name, sizeof(name), "pciCfg");
2701 if (!phba->idiag_pci_cfg) {
2702 phba->idiag_pci_cfg =
2703 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2704 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
2705 if (!phba->idiag_pci_cfg) {
2706 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2707 "2923 Can't create idiag debugfs\n");
2708 goto debug_failed;
2709 }
2710 idiag.offset.last_rd = 0;
2711 }
2712
2713 /* iDiag get PCI function queue information */
2714 snprintf(name, sizeof(name), "queInfo");
2715 if (!phba->idiag_que_info) {
2716 phba->idiag_que_info =
2717 debugfs_create_file(name, S_IFREG|S_IRUGO,
2718 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
2719 if (!phba->idiag_que_info) {
2720 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2721 "2924 Can't create idiag debugfs\n");
2722 goto debug_failed;
2723 }
2724 }
2725
James Smart86a80842011-04-16 11:03:04 -04002726 /* iDiag access PCI function queue */
2727 snprintf(name, sizeof(name), "queAcc");
2728 if (!phba->idiag_que_acc) {
2729 phba->idiag_que_acc =
2730 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2731 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
2732 if (!phba->idiag_que_acc) {
2733 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2734 "2926 Can't create idiag debugfs\n");
2735 goto debug_failed;
2736 }
2737 }
2738
2739 /* iDiag access PCI function doorbell registers */
2740 snprintf(name, sizeof(name), "drbAcc");
2741 if (!phba->idiag_drb_acc) {
2742 phba->idiag_drb_acc =
2743 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
2744 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
2745 if (!phba->idiag_drb_acc) {
2746 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2747 "2927 Can't create idiag debugfs\n");
2748 goto debug_failed;
2749 }
2750 }
2751
James Smart858c9f62007-06-17 19:56:39 -05002752debug_failed:
2753 return;
2754#endif
2755}
2756
James Smarte59058c2008-08-24 21:49:00 -04002757/**
James Smart3621a712009-04-06 18:47:14 -04002758 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04002759 * @vport: The vport pointer to remove from debugfs.
2760 *
2761 * Description:
2762 * When Debugfs is configured this routine removes debugfs file system elements
2763 * that are specific to this vport. It also checks to see if there are any
2764 * users left for the debugfs directories associated with the HBA and driver. If
2765 * this is the last user of the HBA directory or driver directory then it will
2766 * remove those from the debugfs infrastructure as well.
2767 **/
James Smart858c9f62007-06-17 19:56:39 -05002768inline void
2769lpfc_debugfs_terminate(struct lpfc_vport *vport)
2770{
James Smart923e4b62008-12-04 22:40:07 -05002771#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05002772 struct lpfc_hba *phba = vport->phba;
2773
2774 if (vport->disc_trc) {
2775 kfree(vport->disc_trc);
2776 vport->disc_trc = NULL;
2777 }
2778 if (vport->debug_disc_trc) {
2779 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
2780 vport->debug_disc_trc = NULL;
2781 }
2782 if (vport->debug_nodelist) {
2783 debugfs_remove(vport->debug_nodelist); /* nodelist */
2784 vport->debug_nodelist = NULL;
2785 }
James Smarta58cbd52007-08-02 11:09:43 -04002786
James Smart858c9f62007-06-17 19:56:39 -05002787 if (vport->vport_debugfs_root) {
2788 debugfs_remove(vport->vport_debugfs_root); /* vportX */
2789 vport->vport_debugfs_root = NULL;
2790 atomic_dec(&phba->debugfs_vport_count);
2791 }
2792 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04002793
James Smart78b2d852007-08-02 11:10:21 -04002794 if (phba->debug_hbqinfo) {
2795 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
2796 phba->debug_hbqinfo = NULL;
2797 }
James Smartc95d6c62008-01-11 01:53:23 -05002798 if (phba->debug_dumpHBASlim) {
2799 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
2800 phba->debug_dumpHBASlim = NULL;
2801 }
2802 if (phba->debug_dumpHostSlim) {
2803 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
2804 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04002805 }
James Smarte2a0a9d2008-12-04 22:40:02 -05002806 if (phba->debug_dumpData) {
2807 debugfs_remove(phba->debug_dumpData); /* dumpData */
2808 phba->debug_dumpData = NULL;
2809 }
2810
2811 if (phba->debug_dumpDif) {
2812 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
2813 phba->debug_dumpDif = NULL;
2814 }
2815
James Smarta58cbd52007-08-02 11:09:43 -04002816 if (phba->slow_ring_trc) {
2817 kfree(phba->slow_ring_trc);
2818 phba->slow_ring_trc = NULL;
2819 }
2820 if (phba->debug_slow_ring_trc) {
2821 /* slow_ring_trace */
2822 debugfs_remove(phba->debug_slow_ring_trc);
2823 phba->debug_slow_ring_trc = NULL;
2824 }
2825
James Smart2a622bf2011-02-16 12:40:06 -05002826 /*
2827 * iDiag release
2828 */
2829 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart86a80842011-04-16 11:03:04 -04002830 if (phba->idiag_drb_acc) {
2831 /* iDiag drbAcc */
2832 debugfs_remove(phba->idiag_drb_acc);
2833 phba->idiag_drb_acc = NULL;
2834 }
2835 if (phba->idiag_que_acc) {
2836 /* iDiag queAcc */
2837 debugfs_remove(phba->idiag_que_acc);
2838 phba->idiag_que_acc = NULL;
2839 }
James Smart2a622bf2011-02-16 12:40:06 -05002840 if (phba->idiag_que_info) {
2841 /* iDiag queInfo */
2842 debugfs_remove(phba->idiag_que_info);
2843 phba->idiag_que_info = NULL;
2844 }
2845 if (phba->idiag_pci_cfg) {
2846 /* iDiag pciCfg */
2847 debugfs_remove(phba->idiag_pci_cfg);
2848 phba->idiag_pci_cfg = NULL;
2849 }
2850
2851 /* Finally remove the iDiag debugfs root */
2852 if (phba->idiag_root) {
2853 /* iDiag root */
2854 debugfs_remove(phba->idiag_root);
2855 phba->idiag_root = NULL;
2856 }
2857 }
2858
James Smarta58cbd52007-08-02 11:09:43 -04002859 if (phba->hba_debugfs_root) {
James Smart2a622bf2011-02-16 12:40:06 -05002860 debugfs_remove(phba->hba_debugfs_root); /* fnX */
James Smarta58cbd52007-08-02 11:09:43 -04002861 phba->hba_debugfs_root = NULL;
2862 atomic_dec(&lpfc_debugfs_hba_count);
2863 }
2864
James Smart858c9f62007-06-17 19:56:39 -05002865 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
2866 debugfs_remove(lpfc_debugfs_root); /* lpfc */
2867 lpfc_debugfs_root = NULL;
2868 }
2869 }
2870#endif
James Smarta58cbd52007-08-02 11:09:43 -04002871 return;
James Smart858c9f62007-06-17 19:56:39 -05002872}