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