blob: 5bdf2eecb1782dd4c33f863607d045ed27535fe9 [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 Gortmakeracf3368f2011-05-27 09:47:43 -040023#include <linux/module.h>
James Smart858c9f62007-06-17 19:56:39 -050024#include <linux/dma-mapping.h>
25#include <linux/idr.h>
26#include <linux/interrupt.h>
27#include <linux/kthread.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
James Smart858c9f62007-06-17 19:56:39 -050029#include <linux/pci.h>
30#include <linux/spinlock.h>
31#include <linux/ctype.h>
James Smart858c9f62007-06-17 19:56:39 -050032
33#include <scsi/scsi.h>
34#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_transport_fc.h>
37
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_hw4.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_hw.h"
40#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040041#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040042#include "lpfc_nl.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_disc.h"
44#include "lpfc_scsi.h"
45#include "lpfc.h"
46#include "lpfc_logmsg.h"
47#include "lpfc_crtn.h"
48#include "lpfc_vport.h"
49#include "lpfc_version.h"
James Smartc95d6c62008-01-11 01:53:23 -050050#include "lpfc_compat.h"
James Smart858c9f62007-06-17 19:56:39 -050051#include "lpfc_debugfs.h"
James Smartb76f2dc2011-07-22 18:37:42 -040052#include "lpfc_bsg.h"
James Smart858c9f62007-06-17 19:56:39 -050053
James Smart923e4b62008-12-04 22:40:07 -050054#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart3621a712009-04-06 18:47:14 -040055/*
James Smarte59058c2008-08-24 21:49:00 -040056 * debugfs interface
James Smart858c9f62007-06-17 19:56:39 -050057 *
58 * To access this interface the user should:
GeunSik Lim156f5a72009-06-02 15:01:37 +090059 * # mount -t debugfs none /sys/kernel/debug
James Smart858c9f62007-06-17 19:56:39 -050060 *
James Smarte59058c2008-08-24 21:49:00 -040061 * The lpfc debugfs directory hierarchy is:
James Smart2a622bf2011-02-16 12:40:06 -050062 * /sys/kernel/debug/lpfc/fnX/vportY
63 * where X is the lpfc hba function unique_id
James Smart858c9f62007-06-17 19:56:39 -050064 * where Y is the vport VPI on that hba
65 *
66 * Debugging services available per vport:
67 * discovery_trace
68 * This is an ACSII readable file that contains a trace of the last
69 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
James Smarte59058c2008-08-24 21:49:00 -040070 * See lpfc_debugfs.h for different categories of discovery events.
71 * To enable the discovery trace, the following module parameters must be set:
James Smart858c9f62007-06-17 19:56:39 -050072 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
73 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
74 * EACH vport. X MUST also be a power of 2.
75 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
76 * lpfc_debugfs.h .
James Smarte59058c2008-08-24 21:49:00 -040077 *
78 * slow_ring_trace
79 * This is an ACSII readable file that contains a trace of the last
80 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
81 * To enable the slow ring trace, the following module parameters must be set:
82 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
83 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
84 * the HBA. X MUST also be a power of 2.
James Smart858c9f62007-06-17 19:56:39 -050085 */
James Smart51ef4c22007-08-02 11:10:31 -040086static int lpfc_debugfs_enable = 1;
James Smartab56dc22011-02-16 12:39:57 -050087module_param(lpfc_debugfs_enable, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050088MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
89
James Smarta58cbd52007-08-02 11:09:43 -040090/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050091static int lpfc_debugfs_max_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -050092module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050093MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
94 "Set debugfs discovery trace depth");
95
James Smarta58cbd52007-08-02 11:09:43 -040096/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050097static int lpfc_debugfs_max_slow_ring_trc;
James Smartab56dc22011-02-16 12:39:57 -050098module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
James Smarta58cbd52007-08-02 11:09:43 -040099MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
100 "Set debugfs slow ring trace depth");
101
James Smarta257bf92009-04-06 18:48:10 -0400102static int lpfc_debugfs_mask_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -0500103module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -0500104MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
105 "Set debugfs discovery trace mask");
106
107#include <linux/debugfs.h>
108
James Smart311464e2007-08-02 11:10:37 -0400109static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
110static unsigned long lpfc_debugfs_start_time = 0L;
James Smart858c9f62007-06-17 19:56:39 -0500111
James Smart2a622bf2011-02-16 12:40:06 -0500112/* iDiag */
113static struct lpfc_idiag idiag;
114
James Smarte59058c2008-08-24 21:49:00 -0400115/**
James Smart3621a712009-04-06 18:47:14 -0400116 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400117 * @vport: The vport to gather the log info from.
118 * @buf: The buffer to dump log into.
119 * @size: The maximum amount of data to process.
120 *
121 * Description:
122 * This routine gathers the lpfc discovery debugfs data from the @vport and
123 * dumps it to @buf up to @size number of bytes. It will start at the next entry
124 * in the log and process the log until the end of the buffer. Then it will
125 * gather from the beginning of the log and process until the current entry.
126 *
127 * Notes:
128 * Discovery logging will be disabled while while this routine dumps the log.
129 *
130 * Return Value:
131 * This routine returns the amount of bytes that were dumped into @buf and will
132 * not exceed @size.
133 **/
James Smart858c9f62007-06-17 19:56:39 -0500134static int
135lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
136{
137 int i, index, len, enable;
138 uint32_t ms;
James Smarta58cbd52007-08-02 11:09:43 -0400139 struct lpfc_debugfs_trc *dtp;
James Smartb76f2dc2011-07-22 18:37:42 -0400140 char *buffer;
141
142 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
143 if (!buffer)
144 return 0;
James Smart858c9f62007-06-17 19:56:39 -0500145
James Smart858c9f62007-06-17 19:56:39 -0500146 enable = lpfc_debugfs_enable;
147 lpfc_debugfs_enable = 0;
148
149 len = 0;
150 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
151 (lpfc_debugfs_max_disc_trc - 1);
152 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
153 dtp = vport->disc_trc + i;
154 if (!dtp->fmt)
155 continue;
156 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400157 snprintf(buffer,
158 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500159 dtp->seq_cnt, ms, dtp->fmt);
160 len += snprintf(buf+len, size-len, buffer,
161 dtp->data1, dtp->data2, dtp->data3);
162 }
163 for (i = 0; i < index; i++) {
164 dtp = vport->disc_trc + i;
165 if (!dtp->fmt)
166 continue;
167 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400168 snprintf(buffer,
169 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500170 dtp->seq_cnt, ms, dtp->fmt);
171 len += snprintf(buf+len, size-len, buffer,
172 dtp->data1, dtp->data2, dtp->data3);
173 }
174
175 lpfc_debugfs_enable = enable;
James Smartb76f2dc2011-07-22 18:37:42 -0400176 kfree(buffer);
177
James Smart858c9f62007-06-17 19:56:39 -0500178 return len;
179}
180
James Smarte59058c2008-08-24 21:49:00 -0400181/**
James Smart3621a712009-04-06 18:47:14 -0400182 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400183 * @phba: The HBA to gather the log info from.
184 * @buf: The buffer to dump log into.
185 * @size: The maximum amount of data to process.
186 *
187 * Description:
188 * This routine gathers the lpfc slow ring debugfs data from the @phba and
189 * dumps it to @buf up to @size number of bytes. It will start at the next entry
190 * in the log and process the log until the end of the buffer. Then it will
191 * gather from the beginning of the log and process until the current entry.
192 *
193 * Notes:
194 * Slow ring logging will be disabled while while this routine dumps the log.
195 *
196 * Return Value:
197 * This routine returns the amount of bytes that were dumped into @buf and will
198 * not exceed @size.
199 **/
James Smart858c9f62007-06-17 19:56:39 -0500200static int
James Smarta58cbd52007-08-02 11:09:43 -0400201lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
202{
203 int i, index, len, enable;
204 uint32_t ms;
205 struct lpfc_debugfs_trc *dtp;
James Smartb76f2dc2011-07-22 18:37:42 -0400206 char *buffer;
James Smarta58cbd52007-08-02 11:09:43 -0400207
James Smartb76f2dc2011-07-22 18:37:42 -0400208 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
209 if (!buffer)
210 return 0;
James Smarta58cbd52007-08-02 11:09:43 -0400211
212 enable = lpfc_debugfs_enable;
213 lpfc_debugfs_enable = 0;
214
215 len = 0;
216 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
217 (lpfc_debugfs_max_slow_ring_trc - 1);
218 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
219 dtp = phba->slow_ring_trc + i;
220 if (!dtp->fmt)
221 continue;
222 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
223 snprintf(buffer,
224 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
225 dtp->seq_cnt, ms, dtp->fmt);
226 len += snprintf(buf+len, size-len, buffer,
227 dtp->data1, dtp->data2, dtp->data3);
228 }
229 for (i = 0; i < index; i++) {
230 dtp = phba->slow_ring_trc + i;
231 if (!dtp->fmt)
232 continue;
233 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
234 snprintf(buffer,
235 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
236 dtp->seq_cnt, ms, dtp->fmt);
237 len += snprintf(buf+len, size-len, buffer,
238 dtp->data1, dtp->data2, dtp->data3);
239 }
240
241 lpfc_debugfs_enable = enable;
James Smartb76f2dc2011-07-22 18:37:42 -0400242 kfree(buffer);
243
James Smarta58cbd52007-08-02 11:09:43 -0400244 return len;
245}
246
James Smart311464e2007-08-02 11:10:37 -0400247static int lpfc_debugfs_last_hbq = -1;
James Smart78b2d852007-08-02 11:10:21 -0400248
James Smarte59058c2008-08-24 21:49:00 -0400249/**
James Smart3621a712009-04-06 18:47:14 -0400250 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400251 * @phba: The HBA to gather host buffer info from.
252 * @buf: The buffer to dump log into.
253 * @size: The maximum amount of data to process.
254 *
255 * Description:
256 * This routine dumps the host buffer queue info from the @phba to @buf up to
257 * @size number of bytes. A header that describes the current hbq state will be
258 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
259 * until @size bytes have been dumped or all the hbq info has been dumped.
260 *
261 * Notes:
262 * This routine will rotate through each configured HBQ each time called.
263 *
264 * Return Value:
265 * This routine returns the amount of bytes that were dumped into @buf and will
266 * not exceed @size.
267 **/
James Smart78b2d852007-08-02 11:10:21 -0400268static int
269lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
270{
271 int len = 0;
272 int cnt, i, j, found, posted, low;
273 uint32_t phys, raw_index, getidx;
274 struct lpfc_hbq_init *hip;
275 struct hbq_s *hbqs;
276 struct lpfc_hbq_entry *hbqe;
277 struct lpfc_dmabuf *d_buf;
278 struct hbq_dmabuf *hbq_buf;
279
James Smart3772a992009-05-22 14:50:54 -0400280 if (phba->sli_rev != 3)
281 return 0;
James Smart78b2d852007-08-02 11:10:21 -0400282 cnt = LPFC_HBQINFO_SIZE;
283 spin_lock_irq(&phba->hbalock);
284
285 /* toggle between multiple hbqs, if any */
286 i = lpfc_sli_hbq_count();
287 if (i > 1) {
288 lpfc_debugfs_last_hbq++;
289 if (lpfc_debugfs_last_hbq >= i)
290 lpfc_debugfs_last_hbq = 0;
291 }
292 else
293 lpfc_debugfs_last_hbq = 0;
294
295 i = lpfc_debugfs_last_hbq;
296
297 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
298
James Smart51ef4c22007-08-02 11:10:31 -0400299 hbqs = &phba->hbqs[i];
James Smart78b2d852007-08-02 11:10:21 -0400300 posted = 0;
James Smart51ef4c22007-08-02 11:10:31 -0400301 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
James Smart78b2d852007-08-02 11:10:21 -0400302 posted++;
303
304 hip = lpfc_hbq_defs[i];
305 len += snprintf(buf+len, size-len,
306 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
307 hip->hbq_index, hip->profile, hip->rn,
308 hip->buffer_count, hip->init_count, hip->add_count, posted);
309
James Smart78b2d852007-08-02 11:10:21 -0400310 raw_index = phba->hbq_get[i];
311 getidx = le32_to_cpu(raw_index);
312 len += snprintf(buf+len, size-len,
James Smarta8adb832007-10-27 13:37:53 -0400313 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
314 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
315 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
James Smart78b2d852007-08-02 11:10:21 -0400316
James Smart51ef4c22007-08-02 11:10:31 -0400317 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
James Smart78b2d852007-08-02 11:10:21 -0400318 for (j=0; j<hbqs->entry_count; j++) {
319 len += snprintf(buf+len, size-len,
320 "%03d: %08x %04x %05x ", j,
James Smarta8adb832007-10-27 13:37:53 -0400321 le32_to_cpu(hbqe->bde.addrLow),
322 le32_to_cpu(hbqe->bde.tus.w),
323 le32_to_cpu(hbqe->buffer_tag));
James Smart78b2d852007-08-02 11:10:21 -0400324 i = 0;
325 found = 0;
326
327 /* First calculate if slot has an associated posted buffer */
328 low = hbqs->hbqPutIdx - posted;
329 if (low >= 0) {
330 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
331 len += snprintf(buf+len, size-len, "Unused\n");
332 goto skipit;
333 }
334 }
335 else {
336 if ((j >= hbqs->hbqPutIdx) &&
337 (j < (hbqs->entry_count+low))) {
338 len += snprintf(buf+len, size-len, "Unused\n");
339 goto skipit;
340 }
341 }
342
343 /* Get the Buffer info for the posted buffer */
James Smart51ef4c22007-08-02 11:10:31 -0400344 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
James Smart78b2d852007-08-02 11:10:21 -0400345 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
346 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
James Smarta8adb832007-10-27 13:37:53 -0400347 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
James Smart78b2d852007-08-02 11:10:21 -0400348 len += snprintf(buf+len, size-len,
349 "Buf%d: %p %06x\n", i,
350 hbq_buf->dbuf.virt, hbq_buf->tag);
351 found = 1;
352 break;
353 }
354 i++;
355 }
356 if (!found) {
357 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
358 }
359skipit:
360 hbqe++;
361 if (len > LPFC_HBQINFO_SIZE - 54)
362 break;
363 }
364 spin_unlock_irq(&phba->hbalock);
365 return len;
366}
367
James Smartc95d6c62008-01-11 01:53:23 -0500368static int lpfc_debugfs_last_hba_slim_off;
369
James Smarte59058c2008-08-24 21:49:00 -0400370/**
James Smart3621a712009-04-06 18:47:14 -0400371 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400372 * @phba: The HBA to gather SLIM info from.
373 * @buf: The buffer to dump log into.
374 * @size: The maximum amount of data to process.
375 *
376 * Description:
377 * This routine dumps the current contents of HBA SLIM for the HBA associated
378 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
379 *
380 * Notes:
381 * This routine will only dump up to 1024 bytes of data each time called and
382 * should be called multiple times to dump the entire HBA SLIM.
383 *
384 * Return Value:
385 * This routine returns the amount of bytes that were dumped into @buf and will
386 * not exceed @size.
387 **/
James Smarta58cbd52007-08-02 11:09:43 -0400388static int
James Smartc95d6c62008-01-11 01:53:23 -0500389lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
James Smarta58cbd52007-08-02 11:09:43 -0400390{
391 int len = 0;
James Smartc95d6c62008-01-11 01:53:23 -0500392 int i, off;
393 uint32_t *ptr;
James Smartb76f2dc2011-07-22 18:37:42 -0400394 char *buffer;
395
396 buffer = kmalloc(1024, GFP_KERNEL);
397 if (!buffer)
398 return 0;
James Smartc95d6c62008-01-11 01:53:23 -0500399
400 off = 0;
401 spin_lock_irq(&phba->hbalock);
402
403 len += snprintf(buf+len, size-len, "HBA SLIM\n");
404 lpfc_memcpy_from_slim(buffer,
James Smarta257bf92009-04-06 18:48:10 -0400405 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
James Smartc95d6c62008-01-11 01:53:23 -0500406
407 ptr = (uint32_t *)&buffer[0];
408 off = lpfc_debugfs_last_hba_slim_off;
409
410 /* Set it up for the next time */
411 lpfc_debugfs_last_hba_slim_off += 1024;
412 if (lpfc_debugfs_last_hba_slim_off >= 4096)
413 lpfc_debugfs_last_hba_slim_off = 0;
414
415 i = 1024;
416 while (i > 0) {
417 len += snprintf(buf+len, size-len,
418 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
419 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
420 *(ptr+5), *(ptr+6), *(ptr+7));
421 ptr += 8;
422 i -= (8 * sizeof(uint32_t));
423 off += (8 * sizeof(uint32_t));
424 }
425
426 spin_unlock_irq(&phba->hbalock);
James Smartb76f2dc2011-07-22 18:37:42 -0400427 kfree(buffer);
428
James Smartc95d6c62008-01-11 01:53:23 -0500429 return len;
430}
431
James Smarte59058c2008-08-24 21:49:00 -0400432/**
James Smart3621a712009-04-06 18:47:14 -0400433 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400434 * @phba: The HBA to gather Host SLIM info from.
435 * @buf: The buffer to dump log into.
436 * @size: The maximum amount of data to process.
437 *
438 * Description:
439 * This routine dumps the current contents of host SLIM for the host associated
440 * with @phba to @buf up to @size bytes of data. The dump will contain the
441 * Mailbox, PCB, Rings, and Registers that are located in host memory.
442 *
443 * Return Value:
444 * This routine returns the amount of bytes that were dumped into @buf and will
445 * not exceed @size.
446 **/
James Smartc95d6c62008-01-11 01:53:23 -0500447static int
448lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
449{
450 int len = 0;
451 int i, off;
James Smarta58cbd52007-08-02 11:09:43 -0400452 uint32_t word0, word1, word2, word3;
453 uint32_t *ptr;
454 struct lpfc_pgp *pgpp;
455 struct lpfc_sli *psli = &phba->sli;
456 struct lpfc_sli_ring *pring;
457
James Smarta58cbd52007-08-02 11:09:43 -0400458 off = 0;
459 spin_lock_irq(&phba->hbalock);
460
461 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
James Smart34b02dc2008-08-24 21:49:55 -0400462 ptr = (uint32_t *)phba->slim2p.virt;
James Smarta58cbd52007-08-02 11:09:43 -0400463 i = sizeof(MAILBOX_t);
464 while (i > 0) {
465 len += snprintf(buf+len, size-len,
466 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
467 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
468 *(ptr+5), *(ptr+6), *(ptr+7));
469 ptr += 8;
470 i -= (8 * sizeof(uint32_t));
471 off += (8 * sizeof(uint32_t));
472 }
473
474 len += snprintf(buf+len, size-len, "SLIM PCB\n");
James Smart34b02dc2008-08-24 21:49:55 -0400475 ptr = (uint32_t *)phba->pcb;
James Smarta58cbd52007-08-02 11:09:43 -0400476 i = sizeof(PCB_t);
477 while (i > 0) {
478 len += snprintf(buf+len, size-len,
479 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
480 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
481 *(ptr+5), *(ptr+6), *(ptr+7));
482 ptr += 8;
483 i -= (8 * sizeof(uint32_t));
484 off += (8 * sizeof(uint32_t));
485 }
486
James Smart34b02dc2008-08-24 21:49:55 -0400487 for (i = 0; i < 4; i++) {
488 pgpp = &phba->port_gp[i];
489 pring = &psli->ring[i];
490 len += snprintf(buf+len, size-len,
491 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
492 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
493 i, pgpp->cmdGetInx, pring->numCiocb,
494 pring->next_cmdidx, pring->local_getidx,
495 pring->flag, pgpp->rspPutInx, pring->numRiocb);
496 }
James Smart3772a992009-05-22 14:50:54 -0400497
498 if (phba->sli_rev <= LPFC_SLI_REV3) {
499 word0 = readl(phba->HAregaddr);
500 word1 = readl(phba->CAregaddr);
501 word2 = readl(phba->HSregaddr);
502 word3 = readl(phba->HCregaddr);
503 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
504 "HC:%08x\n", word0, word1, word2, word3);
505 }
James Smarta58cbd52007-08-02 11:09:43 -0400506 spin_unlock_irq(&phba->hbalock);
507 return len;
508}
509
James Smarte59058c2008-08-24 21:49:00 -0400510/**
James Smart3621a712009-04-06 18:47:14 -0400511 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400512 * @vport: The vport to gather target node info from.
513 * @buf: The buffer to dump log into.
514 * @size: The maximum amount of data to process.
515 *
516 * Description:
517 * This routine dumps the current target node list associated with @vport to
518 * @buf up to @size bytes of data. Each node entry in the dump will contain a
519 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
520 *
521 * Return Value:
522 * This routine returns the amount of bytes that were dumped into @buf and will
523 * not exceed @size.
524 **/
James Smarta58cbd52007-08-02 11:09:43 -0400525static int
James Smart858c9f62007-06-17 19:56:39 -0500526lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
527{
528 int len = 0;
529 int cnt;
530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
531 struct lpfc_nodelist *ndlp;
532 unsigned char *statep, *name;
533
534 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
535
536 spin_lock_irq(shost->host_lock);
537 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
538 if (!cnt) {
539 len += snprintf(buf+len, size-len,
540 "Missing Nodelist Entries\n");
541 break;
542 }
543 cnt--;
544 switch (ndlp->nlp_state) {
545 case NLP_STE_UNUSED_NODE:
546 statep = "UNUSED";
547 break;
548 case NLP_STE_PLOGI_ISSUE:
549 statep = "PLOGI ";
550 break;
551 case NLP_STE_ADISC_ISSUE:
552 statep = "ADISC ";
553 break;
554 case NLP_STE_REG_LOGIN_ISSUE:
555 statep = "REGLOG";
556 break;
557 case NLP_STE_PRLI_ISSUE:
558 statep = "PRLI ";
559 break;
560 case NLP_STE_UNMAPPED_NODE:
561 statep = "UNMAP ";
562 break;
563 case NLP_STE_MAPPED_NODE:
564 statep = "MAPPED";
565 break;
566 case NLP_STE_NPR_NODE:
567 statep = "NPR ";
568 break;
569 default:
570 statep = "UNKNOWN";
571 }
572 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
573 statep, ndlp->nlp_DID);
574 name = (unsigned char *)&ndlp->nlp_portname;
575 len += snprintf(buf+len, size-len,
576 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
577 *name, *(name+1), *(name+2), *(name+3),
578 *(name+4), *(name+5), *(name+6), *(name+7));
579 name = (unsigned char *)&ndlp->nlp_nodename;
580 len += snprintf(buf+len, size-len,
581 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
582 *name, *(name+1), *(name+2), *(name+3),
583 *(name+4), *(name+5), *(name+6), *(name+7));
584 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
585 ndlp->nlp_rpi, ndlp->nlp_flag);
586 if (!ndlp->nlp_type)
James Smarta58cbd52007-08-02 11:09:43 -0400587 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500588 if (ndlp->nlp_type & NLP_FC_NODE)
589 len += snprintf(buf+len, size-len, "FC_NODE ");
590 if (ndlp->nlp_type & NLP_FABRIC)
591 len += snprintf(buf+len, size-len, "FABRIC ");
592 if (ndlp->nlp_type & NLP_FCP_TARGET)
593 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
594 ndlp->nlp_sid);
595 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
James Smarta58cbd52007-08-02 11:09:43 -0400596 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart58da1ff2008-04-07 10:15:56 -0400597 len += snprintf(buf+len, size-len, "usgmap:%x ",
598 ndlp->nlp_usg_map);
James Smarta58cbd52007-08-02 11:09:43 -0400599 len += snprintf(buf+len, size-len, "refcnt:%x",
600 atomic_read(&ndlp->kref.refcount));
James Smart858c9f62007-06-17 19:56:39 -0500601 len += snprintf(buf+len, size-len, "\n");
602 }
603 spin_unlock_irq(shost->host_lock);
604 return len;
605}
606#endif
607
James Smarte59058c2008-08-24 21:49:00 -0400608/**
James Smart3621a712009-04-06 18:47:14 -0400609 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400610 * @vport: The vport to associate this trace string with for retrieval.
611 * @mask: Log entry classification.
612 * @fmt: Format string to be displayed when dumping the log.
613 * @data1: 1st data parameter to be applied to @fmt.
614 * @data2: 2nd data parameter to be applied to @fmt.
615 * @data3: 3rd data parameter to be applied to @fmt.
616 *
617 * Description:
618 * This routine is used by the driver code to add a debugfs log entry to the
619 * discovery trace buffer associated with @vport. Only entries with a @mask that
620 * match the current debugfs discovery mask will be saved. Entries that do not
621 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
622 * printf when displaying the log.
623 **/
James Smart858c9f62007-06-17 19:56:39 -0500624inline void
625lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
626 uint32_t data1, uint32_t data2, uint32_t data3)
627{
James Smart923e4b62008-12-04 22:40:07 -0500628#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400629 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -0500630 int index;
631
632 if (!(lpfc_debugfs_mask_disc_trc & mask))
633 return;
634
635 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
636 !vport || !vport->disc_trc)
637 return;
638
639 index = atomic_inc_return(&vport->disc_trc_cnt) &
640 (lpfc_debugfs_max_disc_trc - 1);
641 dtp = vport->disc_trc + index;
642 dtp->fmt = fmt;
643 dtp->data1 = data1;
644 dtp->data2 = data2;
645 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -0400646 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
647 dtp->jif = jiffies;
648#endif
649 return;
650}
651
James Smarte59058c2008-08-24 21:49:00 -0400652/**
James Smart3621a712009-04-06 18:47:14 -0400653 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400654 * @phba: The phba to associate this trace string with for retrieval.
655 * @fmt: Format string to be displayed when dumping the log.
656 * @data1: 1st data parameter to be applied to @fmt.
657 * @data2: 2nd data parameter to be applied to @fmt.
658 * @data3: 3rd data parameter to be applied to @fmt.
659 *
660 * Description:
661 * This routine is used by the driver code to add a debugfs log entry to the
662 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
663 * @data3 are used like printf when displaying the log.
664 **/
James Smarta58cbd52007-08-02 11:09:43 -0400665inline void
666lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
667 uint32_t data1, uint32_t data2, uint32_t data3)
668{
James Smart923e4b62008-12-04 22:40:07 -0500669#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400670 struct lpfc_debugfs_trc *dtp;
671 int index;
672
673 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
674 !phba || !phba->slow_ring_trc)
675 return;
676
677 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
678 (lpfc_debugfs_max_slow_ring_trc - 1);
679 dtp = phba->slow_ring_trc + index;
680 dtp->fmt = fmt;
681 dtp->data1 = data1;
682 dtp->data2 = data2;
683 dtp->data3 = data3;
684 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500685 dtp->jif = jiffies;
686#endif
687 return;
688}
689
James Smart923e4b62008-12-04 22:40:07 -0500690#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -0400691/**
James Smart3621a712009-04-06 18:47:14 -0400692 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400693 * @inode: The inode pointer that contains a vport pointer.
694 * @file: The file pointer to attach the log output.
695 *
696 * Description:
697 * This routine is the entry point for the debugfs open file operation. It gets
698 * the vport from the i_private field in @inode, allocates the necessary buffer
699 * for the log, fills the buffer from the in-memory log for this vport, and then
700 * returns a pointer to that log in the private_data field in @file.
701 *
702 * Returns:
703 * This function returns zero if successful. On error it will return an negative
704 * error value.
705 **/
James Smart858c9f62007-06-17 19:56:39 -0500706static int
707lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
708{
709 struct lpfc_vport *vport = inode->i_private;
710 struct lpfc_debug *debug;
711 int size;
712 int rc = -ENOMEM;
713
714 if (!lpfc_debugfs_max_disc_trc) {
715 rc = -ENOSPC;
716 goto out;
717 }
718
719 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
720 if (!debug)
721 goto out;
722
James Smarte59058c2008-08-24 21:49:00 -0400723 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400724 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -0500725 size = PAGE_ALIGN(size);
726
727 debug->buffer = kmalloc(size, GFP_KERNEL);
728 if (!debug->buffer) {
729 kfree(debug);
730 goto out;
731 }
732
733 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
734 file->private_data = debug;
735
736 rc = 0;
737out:
738 return rc;
739}
740
James Smarte59058c2008-08-24 21:49:00 -0400741/**
James Smart3621a712009-04-06 18:47:14 -0400742 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400743 * @inode: The inode pointer that contains a vport pointer.
744 * @file: The file pointer to attach the log output.
745 *
746 * Description:
747 * This routine is the entry point for the debugfs open file operation. It gets
748 * the vport from the i_private field in @inode, allocates the necessary buffer
749 * for the log, fills the buffer from the in-memory log for this vport, and then
750 * returns a pointer to that log in the private_data field in @file.
751 *
752 * Returns:
753 * This function returns zero if successful. On error it will return an negative
754 * error value.
755 **/
James Smart858c9f62007-06-17 19:56:39 -0500756static int
James Smarta58cbd52007-08-02 11:09:43 -0400757lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
758{
759 struct lpfc_hba *phba = inode->i_private;
760 struct lpfc_debug *debug;
761 int size;
762 int rc = -ENOMEM;
763
764 if (!lpfc_debugfs_max_slow_ring_trc) {
765 rc = -ENOSPC;
766 goto out;
767 }
768
769 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
770 if (!debug)
771 goto out;
772
James Smarte59058c2008-08-24 21:49:00 -0400773 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400774 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
775 size = PAGE_ALIGN(size);
776
777 debug->buffer = kmalloc(size, GFP_KERNEL);
778 if (!debug->buffer) {
779 kfree(debug);
780 goto out;
781 }
782
783 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
784 file->private_data = debug;
785
786 rc = 0;
787out:
788 return rc;
789}
790
James Smarte59058c2008-08-24 21:49:00 -0400791/**
James Smart3621a712009-04-06 18:47:14 -0400792 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400793 * @inode: The inode pointer that contains a vport pointer.
794 * @file: The file pointer to attach the log output.
795 *
796 * Description:
797 * This routine is the entry point for the debugfs open file operation. It gets
798 * the vport from the i_private field in @inode, allocates the necessary buffer
799 * for the log, fills the buffer from the in-memory log for this vport, and then
800 * returns a pointer to that log in the private_data field in @file.
801 *
802 * Returns:
803 * This function returns zero if successful. On error it will return an negative
804 * error value.
805 **/
James Smarta58cbd52007-08-02 11:09:43 -0400806static int
James Smart78b2d852007-08-02 11:10:21 -0400807lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
808{
809 struct lpfc_hba *phba = inode->i_private;
810 struct lpfc_debug *debug;
811 int rc = -ENOMEM;
812
813 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
814 if (!debug)
815 goto out;
816
James Smarte59058c2008-08-24 21:49:00 -0400817 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -0400818 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
819 if (!debug->buffer) {
820 kfree(debug);
821 goto out;
822 }
823
824 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
825 LPFC_HBQINFO_SIZE);
826 file->private_data = debug;
827
828 rc = 0;
829out:
830 return rc;
831}
832
James Smarte59058c2008-08-24 21:49:00 -0400833/**
James Smart3621a712009-04-06 18:47:14 -0400834 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400835 * @inode: The inode pointer that contains a vport pointer.
836 * @file: The file pointer to attach the log output.
837 *
838 * Description:
839 * This routine is the entry point for the debugfs open file operation. It gets
840 * the vport from the i_private field in @inode, allocates the necessary buffer
841 * for the log, fills the buffer from the in-memory log for this vport, and then
842 * returns a pointer to that log in the private_data field in @file.
843 *
844 * Returns:
845 * This function returns zero if successful. On error it will return an negative
846 * error value.
847 **/
James Smart78b2d852007-08-02 11:10:21 -0400848static int
James Smartc95d6c62008-01-11 01:53:23 -0500849lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -0400850{
851 struct lpfc_hba *phba = inode->i_private;
852 struct lpfc_debug *debug;
853 int rc = -ENOMEM;
854
855 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
856 if (!debug)
857 goto out;
858
James Smarte59058c2008-08-24 21:49:00 -0400859 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500860 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -0400861 if (!debug->buffer) {
862 kfree(debug);
863 goto out;
864 }
865
James Smartc95d6c62008-01-11 01:53:23 -0500866 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
867 LPFC_DUMPHBASLIM_SIZE);
868 file->private_data = debug;
869
870 rc = 0;
871out:
872 return rc;
873}
874
James Smarte59058c2008-08-24 21:49:00 -0400875/**
James Smart3621a712009-04-06 18:47:14 -0400876 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400877 * @inode: The inode pointer that contains a vport pointer.
878 * @file: The file pointer to attach the log output.
879 *
880 * Description:
881 * This routine is the entry point for the debugfs open file operation. It gets
882 * the vport from the i_private field in @inode, allocates the necessary buffer
883 * for the log, fills the buffer from the in-memory log for this vport, and then
884 * returns a pointer to that log in the private_data field in @file.
885 *
886 * Returns:
887 * This function returns zero if successful. On error it will return an negative
888 * error value.
889 **/
James Smartc95d6c62008-01-11 01:53:23 -0500890static int
891lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
892{
893 struct lpfc_hba *phba = inode->i_private;
894 struct lpfc_debug *debug;
895 int rc = -ENOMEM;
896
897 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
898 if (!debug)
899 goto out;
900
James Smarte59058c2008-08-24 21:49:00 -0400901 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500902 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
903 if (!debug->buffer) {
904 kfree(debug);
905 goto out;
906 }
907
908 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
909 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -0400910 file->private_data = debug;
911
912 rc = 0;
913out:
914 return rc;
915}
916
James Smarte2a0a9d2008-12-04 22:40:02 -0500917static int
918lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
919{
920 struct lpfc_debug *debug;
921 int rc = -ENOMEM;
922
923 if (!_dump_buf_data)
924 return -EBUSY;
925
926 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
927 if (!debug)
928 goto out;
929
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300930 /* Round to page boundary */
James Smart6a9c52c2009-10-02 15:16:51 -0400931 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
James Smarte2a0a9d2008-12-04 22:40:02 -0500932 __func__, _dump_buf_data);
933 debug->buffer = _dump_buf_data;
934 if (!debug->buffer) {
935 kfree(debug);
936 goto out;
937 }
938
939 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
940 file->private_data = debug;
941
942 rc = 0;
943out:
944 return rc;
945}
946
947static int
948lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
949{
950 struct lpfc_debug *debug;
951 int rc = -ENOMEM;
952
953 if (!_dump_buf_dif)
954 return -EBUSY;
955
956 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
957 if (!debug)
958 goto out;
959
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300960 /* Round to page boundary */
James Smart6a9c52c2009-10-02 15:16:51 -0400961 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
962 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
James Smarte2a0a9d2008-12-04 22:40:02 -0500963 debug->buffer = _dump_buf_dif;
964 if (!debug->buffer) {
965 kfree(debug);
966 goto out;
967 }
968
969 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
970 file->private_data = debug;
971
972 rc = 0;
973out:
974 return rc;
975}
976
977static ssize_t
978lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
979 size_t nbytes, loff_t *ppos)
980{
981 /*
982 * The Data/DIF buffers only save one failing IO
983 * The write op is used as a reset mechanism after an IO has
984 * already been saved to the next one can be saved
985 */
986 spin_lock(&_dump_buf_lock);
987
988 memset((void *)_dump_buf_data, 0,
989 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
990 memset((void *)_dump_buf_dif, 0,
991 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
992
993 _dump_buf_done = 0;
994
995 spin_unlock(&_dump_buf_lock);
996
997 return nbytes;
998}
999
James Smartf9bb2da2011-10-10 21:34:11 -04001000static 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 Smart4ac9b222012-03-01 22:38:29 -05001014 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04001015 int cnt = 0;
1016
1017 if (dent == phba->debug_writeGuard)
James Smart9a6b09c2012-03-01 22:37:42 -05001018 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001019 else if (dent == phba->debug_writeApp)
James Smart9a6b09c2012-03-01 22:37:42 -05001020 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001021 else if (dent == phba->debug_writeRef)
James Smart9a6b09c2012-03-01 22:37:42 -05001022 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
James Smartacd68592012-01-18 16:25:09 -05001023 else if (dent == phba->debug_readGuard)
James Smart9a6b09c2012-03-01 22:37:42 -05001024 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001025 else if (dent == phba->debug_readApp)
James Smart9a6b09c2012-03-01 22:37:42 -05001026 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001027 else if (dent == phba->debug_readRef)
James Smart9a6b09c2012-03-01 22:37:42 -05001028 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
James Smart4ac9b222012-03-01 22:38:29 -05001029 else if (dent == phba->debug_InjErrNPortID)
1030 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1031 else if (dent == phba->debug_InjErrWWPN) {
1032 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1033 tmp = cpu_to_be64(tmp);
1034 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1035 } else if (dent == phba->debug_InjErrLBA) {
1036 if (phba->lpfc_injerr_lba == (sector_t)(-1))
James Smart9a6b09c2012-03-01 22:37:42 -05001037 cnt = snprintf(cbuf, 32, "off\n");
1038 else
James Smart4ac9b222012-03-01 22:38:29 -05001039 cnt = snprintf(cbuf, 32, "0x%llx\n",
1040 (uint64_t) phba->lpfc_injerr_lba);
James Smart9a6b09c2012-03-01 22:37:42 -05001041 } else
James Smartf9bb2da2011-10-10 21:34:11 -04001042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1043 "0547 Unknown debugfs error injection entry\n");
1044
1045 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1046}
1047
1048static ssize_t
1049lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1050 size_t nbytes, loff_t *ppos)
1051{
1052 struct dentry *dent = file->f_dentry;
1053 struct lpfc_hba *phba = file->private_data;
1054 char dstbuf[32];
James Smart4ac9b222012-03-01 22:38:29 -05001055 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04001056 int size;
1057
1058 memset(dstbuf, 0, 32);
1059 size = (nbytes < 32) ? nbytes : 32;
1060 if (copy_from_user(dstbuf, buf, size))
1061 return 0;
1062
James Smart9a6b09c2012-03-01 22:37:42 -05001063 if (dent == phba->debug_InjErrLBA) {
1064 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
James Smart4ac9b222012-03-01 22:38:29 -05001065 tmp = (uint64_t)(-1);
James Smart9a6b09c2012-03-01 22:37:42 -05001066 }
1067
James Smart4ac9b222012-03-01 22:38:29 -05001068 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
James Smartf9bb2da2011-10-10 21:34:11 -04001069 return 0;
1070
1071 if (dent == phba->debug_writeGuard)
1072 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1073 else if (dent == phba->debug_writeApp)
1074 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1075 else if (dent == phba->debug_writeRef)
1076 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
James Smartacd68592012-01-18 16:25:09 -05001077 else if (dent == phba->debug_readGuard)
1078 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
James Smartf9bb2da2011-10-10 21:34:11 -04001079 else if (dent == phba->debug_readApp)
1080 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1081 else if (dent == phba->debug_readRef)
1082 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1083 else if (dent == phba->debug_InjErrLBA)
1084 phba->lpfc_injerr_lba = (sector_t)tmp;
James Smart4ac9b222012-03-01 22:38:29 -05001085 else if (dent == phba->debug_InjErrNPortID)
1086 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1087 else if (dent == phba->debug_InjErrWWPN) {
1088 tmp = cpu_to_be64(tmp);
1089 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1090 } else
James Smartf9bb2da2011-10-10 21:34:11 -04001091 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1092 "0548 Unknown debugfs error injection entry\n");
1093
1094 return nbytes;
1095}
1096
1097static int
1098lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1099{
1100 return 0;
1101}
1102
James Smarte59058c2008-08-24 21:49:00 -04001103/**
James Smart3621a712009-04-06 18:47:14 -04001104 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001105 * @inode: The inode pointer that contains a vport pointer.
1106 * @file: The file pointer to attach the log output.
1107 *
1108 * Description:
1109 * This routine is the entry point for the debugfs open file operation. It gets
1110 * the vport from the i_private field in @inode, allocates the necessary buffer
1111 * for the log, fills the buffer from the in-memory log for this vport, and then
1112 * returns a pointer to that log in the private_data field in @file.
1113 *
1114 * Returns:
1115 * This function returns zero if successful. On error it will return an negative
1116 * error value.
1117 **/
James Smarta58cbd52007-08-02 11:09:43 -04001118static int
James Smart858c9f62007-06-17 19:56:39 -05001119lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1120{
1121 struct lpfc_vport *vport = inode->i_private;
1122 struct lpfc_debug *debug;
1123 int rc = -ENOMEM;
1124
1125 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1126 if (!debug)
1127 goto out;
1128
James Smarte59058c2008-08-24 21:49:00 -04001129 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05001130 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1131 if (!debug->buffer) {
1132 kfree(debug);
1133 goto out;
1134 }
1135
1136 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1137 LPFC_NODELIST_SIZE);
1138 file->private_data = debug;
1139
1140 rc = 0;
1141out:
1142 return rc;
1143}
1144
James Smarte59058c2008-08-24 21:49:00 -04001145/**
James Smart3621a712009-04-06 18:47:14 -04001146 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001147 * @file: The file pointer to seek through.
1148 * @off: The offset to seek to or the amount to seek by.
1149 * @whence: Indicates how to seek.
1150 *
1151 * Description:
1152 * This routine is the entry point for the debugfs lseek file operation. The
1153 * @whence parameter indicates whether @off is the offset to directly seek to,
1154 * or if it is a value to seek forward or reverse by. This function figures out
1155 * what the new offset of the debugfs file will be and assigns that value to the
1156 * f_pos field of @file.
1157 *
1158 * Returns:
1159 * This function returns the new offset if successful and returns a negative
1160 * error if unable to process the seek.
1161 **/
James Smart858c9f62007-06-17 19:56:39 -05001162static loff_t
1163lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1164{
1165 struct lpfc_debug *debug;
1166 loff_t pos = -1;
1167
1168 debug = file->private_data;
1169
1170 switch (whence) {
1171 case 0:
1172 pos = off;
1173 break;
1174 case 1:
1175 pos = file->f_pos + off;
1176 break;
1177 case 2:
1178 pos = debug->len - off;
1179 }
1180 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1181}
1182
James Smarte59058c2008-08-24 21:49:00 -04001183/**
James Smart3621a712009-04-06 18:47:14 -04001184 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001185 * @file: The file pointer to read from.
1186 * @buf: The buffer to copy the data to.
1187 * @nbytes: The number of bytes to read.
1188 * @ppos: The position in the file to start reading from.
1189 *
1190 * Description:
1191 * This routine reads data from from the buffer indicated in the private_data
1192 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1193 * data to @buf.
1194 *
1195 * Returns:
1196 * This function returns the amount of data that was read (this could be less
1197 * than @nbytes if the end of the file was reached) or a negative error value.
1198 **/
James Smart858c9f62007-06-17 19:56:39 -05001199static ssize_t
1200lpfc_debugfs_read(struct file *file, char __user *buf,
1201 size_t nbytes, loff_t *ppos)
1202{
1203 struct lpfc_debug *debug = file->private_data;
James Smart2a622bf2011-02-16 12:40:06 -05001204
James Smart858c9f62007-06-17 19:56:39 -05001205 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1206 debug->len);
1207}
1208
James Smarte59058c2008-08-24 21:49:00 -04001209/**
James Smart3621a712009-04-06 18:47:14 -04001210 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04001211 * @inode: The inode pointer that contains a vport pointer. (unused)
1212 * @file: The file pointer that contains the buffer to release.
1213 *
1214 * Description:
1215 * This routine frees the buffer that was allocated when the debugfs file was
1216 * opened.
1217 *
1218 * Returns:
1219 * This function returns zero.
1220 **/
James Smart858c9f62007-06-17 19:56:39 -05001221static int
1222lpfc_debugfs_release(struct inode *inode, struct file *file)
1223{
1224 struct lpfc_debug *debug = file->private_data;
1225
1226 kfree(debug->buffer);
1227 kfree(debug);
1228
1229 return 0;
1230}
1231
James Smarte2a0a9d2008-12-04 22:40:02 -05001232static int
1233lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1234{
1235 struct lpfc_debug *debug = file->private_data;
1236
1237 debug->buffer = NULL;
1238 kfree(debug);
1239
1240 return 0;
1241}
1242
James Smart2a622bf2011-02-16 12:40:06 -05001243/*
James Smart86a80842011-04-16 11:03:04 -04001244 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001245 * iDiag debugfs file access methods
James Smart86a80842011-04-16 11:03:04 -04001246 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001247 *
James Smart86a80842011-04-16 11:03:04 -04001248 * All access methods are through the proper SLI4 PCI function's debugfs
1249 * iDiag directory:
James Smart2a622bf2011-02-16 12:40:06 -05001250 *
James Smart86a80842011-04-16 11:03:04 -04001251 * /sys/kernel/debug/lpfc/fn<#>/iDiag
James Smart2a622bf2011-02-16 12:40:06 -05001252 */
1253
1254/**
1255 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1256 * @buf: The pointer to the user space buffer.
1257 * @nbytes: The number of bytes in the user space buffer.
1258 * @idiag_cmd: pointer to the idiag command struct.
1259 *
1260 * This routine reads data from debugfs user space buffer and parses the
1261 * buffer for getting the idiag command and arguments. The while space in
1262 * between the set of data is used as the parsing separator.
1263 *
1264 * This routine returns 0 when successful, it returns proper error code
1265 * back to the user space in error conditions.
1266 */
1267static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1268 struct lpfc_idiag_cmd *idiag_cmd)
1269{
1270 char mybuf[64];
1271 char *pbuf, *step_str;
Stephen Boydb11d48e2011-05-12 16:50:06 -07001272 int i;
1273 size_t bsize;
James Smart2a622bf2011-02-16 12:40:06 -05001274
1275 /* Protect copy from user */
1276 if (!access_ok(VERIFY_READ, buf, nbytes))
1277 return -EFAULT;
1278
1279 memset(mybuf, 0, sizeof(mybuf));
1280 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1281 bsize = min(nbytes, (sizeof(mybuf)-1));
1282
1283 if (copy_from_user(mybuf, buf, bsize))
1284 return -EFAULT;
1285 pbuf = &mybuf[0];
1286 step_str = strsep(&pbuf, "\t ");
1287
1288 /* The opcode must present */
1289 if (!step_str)
1290 return -EINVAL;
1291
1292 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1293 if (idiag_cmd->opcode == 0)
1294 return -EINVAL;
1295
1296 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1297 step_str = strsep(&pbuf, "\t ");
1298 if (!step_str)
James Smart86a80842011-04-16 11:03:04 -04001299 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001300 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1301 }
James Smart86a80842011-04-16 11:03:04 -04001302 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001303}
1304
1305/**
1306 * lpfc_idiag_open - idiag open debugfs
1307 * @inode: The inode pointer that contains a pointer to phba.
1308 * @file: The file pointer to attach the file operation.
1309 *
1310 * Description:
1311 * This routine is the entry point for the debugfs open file operation. It
1312 * gets the reference to phba from the i_private field in @inode, it then
1313 * allocates buffer for the file operation, performs the necessary PCI config
1314 * space read into the allocated buffer according to the idiag user command
1315 * setup, and then returns a pointer to buffer in the private_data field in
1316 * @file.
1317 *
1318 * Returns:
1319 * This function returns zero if successful. On error it will return an
1320 * negative error value.
1321 **/
1322static int
1323lpfc_idiag_open(struct inode *inode, struct file *file)
1324{
1325 struct lpfc_debug *debug;
1326
1327 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1328 if (!debug)
1329 return -ENOMEM;
1330
1331 debug->i_private = inode->i_private;
1332 debug->buffer = NULL;
1333 file->private_data = debug;
1334
1335 return 0;
1336}
1337
1338/**
1339 * lpfc_idiag_release - Release idiag access file operation
1340 * @inode: The inode pointer that contains a vport pointer. (unused)
1341 * @file: The file pointer that contains the buffer to release.
1342 *
1343 * Description:
1344 * This routine is the generic release routine for the idiag access file
1345 * operation, it frees the buffer that was allocated when the debugfs file
1346 * was opened.
1347 *
1348 * Returns:
1349 * This function returns zero.
1350 **/
1351static int
1352lpfc_idiag_release(struct inode *inode, struct file *file)
1353{
1354 struct lpfc_debug *debug = file->private_data;
1355
1356 /* Free the buffers to the file operation */
1357 kfree(debug->buffer);
1358 kfree(debug);
1359
1360 return 0;
1361}
1362
1363/**
1364 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1365 * @inode: The inode pointer that contains a vport pointer. (unused)
1366 * @file: The file pointer that contains the buffer to release.
1367 *
1368 * Description:
1369 * This routine frees the buffer that was allocated when the debugfs file
1370 * was opened. It also reset the fields in the idiag command struct in the
James Smart86a80842011-04-16 11:03:04 -04001371 * case of command for write operation.
James Smart2a622bf2011-02-16 12:40:06 -05001372 *
1373 * Returns:
1374 * This function returns zero.
1375 **/
1376static int
1377lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1378{
1379 struct lpfc_debug *debug = file->private_data;
1380
James Smart86a80842011-04-16 11:03:04 -04001381 if (debug->op == LPFC_IDIAG_OP_WR) {
1382 switch (idiag.cmd.opcode) {
1383 case LPFC_IDIAG_CMD_PCICFG_WR:
1384 case LPFC_IDIAG_CMD_PCICFG_ST:
1385 case LPFC_IDIAG_CMD_PCICFG_CL:
1386 case LPFC_IDIAG_CMD_QUEACC_WR:
1387 case LPFC_IDIAG_CMD_QUEACC_ST:
1388 case LPFC_IDIAG_CMD_QUEACC_CL:
James Smart2a622bf2011-02-16 12:40:06 -05001389 memset(&idiag, 0, sizeof(idiag));
James Smart86a80842011-04-16 11:03:04 -04001390 break;
1391 default:
1392 break;
1393 }
1394 }
James Smart2a622bf2011-02-16 12:40:06 -05001395
1396 /* Free the buffers to the file operation */
1397 kfree(debug->buffer);
1398 kfree(debug);
1399
1400 return 0;
1401}
1402
1403/**
1404 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1405 * @file: The file pointer to read from.
1406 * @buf: The buffer to copy the data to.
1407 * @nbytes: The number of bytes to read.
1408 * @ppos: The position in the file to start reading from.
1409 *
1410 * Description:
1411 * This routine reads data from the @phba pci config space according to the
1412 * idiag command, and copies to user @buf. Depending on the PCI config space
1413 * read command setup, it does either a single register read of a byte
1414 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1415 * registers from the 4K extended PCI config space.
1416 *
1417 * Returns:
1418 * This function returns the amount of data that was read (this could be less
1419 * than @nbytes if the end of the file was reached) or a negative error value.
1420 **/
1421static ssize_t
1422lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1423 loff_t *ppos)
1424{
1425 struct lpfc_debug *debug = file->private_data;
1426 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1427 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1428 int where, count;
1429 char *pbuffer;
1430 struct pci_dev *pdev;
1431 uint32_t u32val;
1432 uint16_t u16val;
1433 uint8_t u8val;
1434
1435 pdev = phba->pcidev;
1436 if (!pdev)
1437 return 0;
1438
1439 /* This is a user read operation */
1440 debug->op = LPFC_IDIAG_OP_RD;
1441
1442 if (!debug->buffer)
1443 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1444 if (!debug->buffer)
1445 return 0;
1446 pbuffer = debug->buffer;
1447
1448 if (*ppos)
1449 return 0;
1450
1451 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04001452 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1453 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05001454 } else
1455 return 0;
1456
1457 /* Read single PCI config space register */
1458 switch (count) {
1459 case SIZE_U8: /* byte (8 bits) */
1460 pci_read_config_byte(pdev, where, &u8val);
1461 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1462 "%03x: %02x\n", where, u8val);
1463 break;
1464 case SIZE_U16: /* word (16 bits) */
1465 pci_read_config_word(pdev, where, &u16val);
1466 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1467 "%03x: %04x\n", where, u16val);
1468 break;
1469 case SIZE_U32: /* double word (32 bits) */
1470 pci_read_config_dword(pdev, where, &u32val);
1471 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1472 "%03x: %08x\n", where, u32val);
1473 break;
James Smart86a80842011-04-16 11:03:04 -04001474 case LPFC_PCI_CFG_BROWSE: /* browse all */
James Smart2a622bf2011-02-16 12:40:06 -05001475 goto pcicfg_browse;
1476 break;
1477 default:
1478 /* illegal count */
1479 len = 0;
1480 break;
1481 }
1482 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1483
1484pcicfg_browse:
1485
1486 /* Browse all PCI config space registers */
1487 offset_label = idiag.offset.last_rd;
1488 offset = offset_label;
1489
1490 /* Read PCI config space */
1491 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1492 "%03x: ", offset_label);
1493 while (index > 0) {
1494 pci_read_config_dword(pdev, offset, &u32val);
1495 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1496 "%08x ", u32val);
1497 offset += sizeof(uint32_t);
James Smartb76f2dc2011-07-22 18:37:42 -04001498 if (offset >= LPFC_PCI_CFG_SIZE) {
1499 len += snprintf(pbuffer+len,
1500 LPFC_PCI_CFG_SIZE-len, "\n");
1501 break;
1502 }
James Smart2a622bf2011-02-16 12:40:06 -05001503 index -= sizeof(uint32_t);
1504 if (!index)
1505 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1506 "\n");
1507 else if (!(index % (8 * sizeof(uint32_t)))) {
1508 offset_label += (8 * sizeof(uint32_t));
1509 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1510 "\n%03x: ", offset_label);
1511 }
1512 }
1513
1514 /* Set up the offset for next portion of pci cfg read */
James Smartb76f2dc2011-07-22 18:37:42 -04001515 if (index == 0) {
1516 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1517 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1518 idiag.offset.last_rd = 0;
1519 } else
James Smart2a622bf2011-02-16 12:40:06 -05001520 idiag.offset.last_rd = 0;
1521
1522 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1523}
1524
1525/**
1526 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1527 * @file: The file pointer to read from.
1528 * @buf: The buffer to copy the user data from.
1529 * @nbytes: The number of bytes to get.
1530 * @ppos: The position in the file to start reading from.
1531 *
1532 * This routine get the debugfs idiag command struct from user space and
1533 * then perform the syntax check for PCI config space read or write command
1534 * accordingly. In the case of PCI config space read command, it sets up
1535 * the command in the idiag command struct for the debugfs read operation.
1536 * In the case of PCI config space write operation, it executes the write
1537 * operation into the PCI config space accordingly.
1538 *
1539 * It returns the @nbytges passing in from debugfs user space when successful.
1540 * In case of error conditions, it returns proper error code back to the user
1541 * space.
1542 */
1543static ssize_t
1544lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1545 size_t nbytes, loff_t *ppos)
1546{
1547 struct lpfc_debug *debug = file->private_data;
1548 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1549 uint32_t where, value, count;
1550 uint32_t u32val;
1551 uint16_t u16val;
1552 uint8_t u8val;
1553 struct pci_dev *pdev;
1554 int rc;
1555
1556 pdev = phba->pcidev;
1557 if (!pdev)
1558 return -EFAULT;
1559
1560 /* This is a user write operation */
1561 debug->op = LPFC_IDIAG_OP_WR;
1562
1563 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
James Smart86a80842011-04-16 11:03:04 -04001564 if (rc < 0)
James Smart2a622bf2011-02-16 12:40:06 -05001565 return rc;
1566
1567 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smart86a80842011-04-16 11:03:04 -04001568 /* Sanity check on PCI config read command line arguments */
1569 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1570 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001571 /* Read command from PCI config space, set up command fields */
James Smartb76f2dc2011-07-22 18:37:42 -04001572 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1573 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04001574 if (count == LPFC_PCI_CFG_BROWSE) {
1575 if (where % sizeof(uint32_t))
James Smart2a622bf2011-02-16 12:40:06 -05001576 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04001577 /* Starting offset to browse */
1578 idiag.offset.last_rd = where;
James Smart2a622bf2011-02-16 12:40:06 -05001579 } else if ((count != sizeof(uint8_t)) &&
1580 (count != sizeof(uint16_t)) &&
1581 (count != sizeof(uint32_t)))
1582 goto error_out;
1583 if (count == sizeof(uint8_t)) {
1584 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1585 goto error_out;
1586 if (where % sizeof(uint8_t))
1587 goto error_out;
1588 }
1589 if (count == sizeof(uint16_t)) {
1590 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1591 goto error_out;
1592 if (where % sizeof(uint16_t))
1593 goto error_out;
1594 }
1595 if (count == sizeof(uint32_t)) {
1596 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1597 goto error_out;
1598 if (where % sizeof(uint32_t))
1599 goto error_out;
1600 }
1601 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1602 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1603 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
James Smart86a80842011-04-16 11:03:04 -04001604 /* Sanity check on PCI config write command line arguments */
1605 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1606 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001607 /* Write command to PCI config space, read-modify-write */
James Smartb76f2dc2011-07-22 18:37:42 -04001608 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1609 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1610 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05001611 /* Sanity checks */
1612 if ((count != sizeof(uint8_t)) &&
1613 (count != sizeof(uint16_t)) &&
1614 (count != sizeof(uint32_t)))
1615 goto error_out;
1616 if (count == sizeof(uint8_t)) {
1617 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1618 goto error_out;
1619 if (where % sizeof(uint8_t))
1620 goto error_out;
1621 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1622 pci_write_config_byte(pdev, where,
1623 (uint8_t)value);
1624 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1625 rc = pci_read_config_byte(pdev, where, &u8val);
1626 if (!rc) {
1627 u8val |= (uint8_t)value;
1628 pci_write_config_byte(pdev, where,
1629 u8val);
1630 }
1631 }
1632 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1633 rc = pci_read_config_byte(pdev, where, &u8val);
1634 if (!rc) {
1635 u8val &= (uint8_t)(~value);
1636 pci_write_config_byte(pdev, where,
1637 u8val);
1638 }
1639 }
1640 }
1641 if (count == sizeof(uint16_t)) {
1642 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1643 goto error_out;
1644 if (where % sizeof(uint16_t))
1645 goto error_out;
1646 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1647 pci_write_config_word(pdev, where,
1648 (uint16_t)value);
1649 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1650 rc = pci_read_config_word(pdev, where, &u16val);
1651 if (!rc) {
1652 u16val |= (uint16_t)value;
1653 pci_write_config_word(pdev, where,
1654 u16val);
1655 }
1656 }
1657 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1658 rc = pci_read_config_word(pdev, where, &u16val);
1659 if (!rc) {
1660 u16val &= (uint16_t)(~value);
1661 pci_write_config_word(pdev, where,
1662 u16val);
1663 }
1664 }
1665 }
1666 if (count == sizeof(uint32_t)) {
1667 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1668 goto error_out;
1669 if (where % sizeof(uint32_t))
1670 goto error_out;
1671 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1672 pci_write_config_dword(pdev, where, value);
1673 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1674 rc = pci_read_config_dword(pdev, where,
1675 &u32val);
1676 if (!rc) {
1677 u32val |= value;
1678 pci_write_config_dword(pdev, where,
1679 u32val);
1680 }
1681 }
1682 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1683 rc = pci_read_config_dword(pdev, where,
1684 &u32val);
1685 if (!rc) {
1686 u32val &= ~value;
1687 pci_write_config_dword(pdev, where,
1688 u32val);
1689 }
1690 }
1691 }
1692 } else
1693 /* All other opecodes are illegal for now */
1694 goto error_out;
1695
1696 return nbytes;
1697error_out:
1698 memset(&idiag, 0, sizeof(idiag));
1699 return -EINVAL;
1700}
1701
1702/**
James Smartb76f2dc2011-07-22 18:37:42 -04001703 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1704 * @file: The file pointer to read from.
1705 * @buf: The buffer to copy the data to.
1706 * @nbytes: The number of bytes to read.
1707 * @ppos: The position in the file to start reading from.
1708 *
1709 * Description:
1710 * This routine reads data from the @phba pci bar memory mapped space
1711 * according to the idiag command, and copies to user @buf.
1712 *
1713 * Returns:
1714 * This function returns the amount of data that was read (this could be less
1715 * than @nbytes if the end of the file was reached) or a negative error value.
1716 **/
1717static ssize_t
1718lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1719 loff_t *ppos)
1720{
1721 struct lpfc_debug *debug = file->private_data;
1722 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1723 int offset_label, offset, offset_run, len = 0, index;
1724 int bar_num, acc_range, bar_size;
1725 char *pbuffer;
1726 void __iomem *mem_mapped_bar;
1727 uint32_t if_type;
1728 struct pci_dev *pdev;
1729 uint32_t u32val;
1730
1731 pdev = phba->pcidev;
1732 if (!pdev)
1733 return 0;
1734
1735 /* This is a user read operation */
1736 debug->op = LPFC_IDIAG_OP_RD;
1737
1738 if (!debug->buffer)
1739 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1740 if (!debug->buffer)
1741 return 0;
1742 pbuffer = debug->buffer;
1743
1744 if (*ppos)
1745 return 0;
1746
1747 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1748 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1749 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1750 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1751 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1752 } else
1753 return 0;
1754
1755 if (acc_range == 0)
1756 return 0;
1757
1758 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1759 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1760 if (bar_num == IDIAG_BARACC_BAR_0)
1761 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1762 else if (bar_num == IDIAG_BARACC_BAR_1)
1763 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1764 else if (bar_num == IDIAG_BARACC_BAR_2)
1765 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1766 else
1767 return 0;
1768 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1769 if (bar_num == IDIAG_BARACC_BAR_0)
1770 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1771 else
1772 return 0;
1773 } else
1774 return 0;
1775
1776 /* Read single PCI bar space register */
1777 if (acc_range == SINGLE_WORD) {
1778 offset_run = offset;
1779 u32val = readl(mem_mapped_bar + offset_run);
1780 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1781 "%05x: %08x\n", offset_run, u32val);
1782 } else
1783 goto baracc_browse;
1784
1785 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1786
1787baracc_browse:
1788
1789 /* Browse all PCI bar space registers */
1790 offset_label = idiag.offset.last_rd;
1791 offset_run = offset_label;
1792
1793 /* Read PCI bar memory mapped space */
1794 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1795 "%05x: ", offset_label);
1796 index = LPFC_PCI_BAR_RD_SIZE;
1797 while (index > 0) {
1798 u32val = readl(mem_mapped_bar + offset_run);
1799 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1800 "%08x ", u32val);
1801 offset_run += sizeof(uint32_t);
1802 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1803 if (offset_run >= bar_size) {
1804 len += snprintf(pbuffer+len,
1805 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1806 break;
1807 }
1808 } else {
1809 if (offset_run >= offset +
1810 (acc_range * sizeof(uint32_t))) {
1811 len += snprintf(pbuffer+len,
1812 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1813 break;
1814 }
1815 }
1816 index -= sizeof(uint32_t);
1817 if (!index)
1818 len += snprintf(pbuffer+len,
1819 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1820 else if (!(index % (8 * sizeof(uint32_t)))) {
1821 offset_label += (8 * sizeof(uint32_t));
1822 len += snprintf(pbuffer+len,
1823 LPFC_PCI_BAR_RD_BUF_SIZE-len,
1824 "\n%05x: ", offset_label);
1825 }
1826 }
1827
1828 /* Set up the offset for next portion of pci bar read */
1829 if (index == 0) {
1830 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1831 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1832 if (idiag.offset.last_rd >= bar_size)
1833 idiag.offset.last_rd = 0;
1834 } else {
1835 if (offset_run >= offset +
1836 (acc_range * sizeof(uint32_t)))
1837 idiag.offset.last_rd = offset;
1838 }
1839 } else {
1840 if (acc_range == LPFC_PCI_BAR_BROWSE)
1841 idiag.offset.last_rd = 0;
1842 else
1843 idiag.offset.last_rd = offset;
1844 }
1845
1846 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1847}
1848
1849/**
1850 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1851 * @file: The file pointer to read from.
1852 * @buf: The buffer to copy the user data from.
1853 * @nbytes: The number of bytes to get.
1854 * @ppos: The position in the file to start reading from.
1855 *
1856 * This routine get the debugfs idiag command struct from user space and
1857 * then perform the syntax check for PCI bar memory mapped space read or
1858 * write command accordingly. In the case of PCI bar memory mapped space
1859 * read command, it sets up the command in the idiag command struct for
1860 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1861 * write operation, it executes the write operation into the PCI bar memory
1862 * mapped space accordingly.
1863 *
1864 * It returns the @nbytges passing in from debugfs user space when successful.
1865 * In case of error conditions, it returns proper error code back to the user
1866 * space.
1867 */
1868static ssize_t
1869lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1870 size_t nbytes, loff_t *ppos)
1871{
1872 struct lpfc_debug *debug = file->private_data;
1873 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1874 uint32_t bar_num, bar_size, offset, value, acc_range;
1875 struct pci_dev *pdev;
1876 void __iomem *mem_mapped_bar;
1877 uint32_t if_type;
1878 uint32_t u32val;
1879 int rc;
1880
1881 pdev = phba->pcidev;
1882 if (!pdev)
1883 return -EFAULT;
1884
1885 /* This is a user write operation */
1886 debug->op = LPFC_IDIAG_OP_WR;
1887
1888 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1889 if (rc < 0)
1890 return rc;
1891
1892 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1893 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1894
1895 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1896 if ((bar_num != IDIAG_BARACC_BAR_0) &&
1897 (bar_num != IDIAG_BARACC_BAR_1) &&
1898 (bar_num != IDIAG_BARACC_BAR_2))
1899 goto error_out;
1900 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1901 if (bar_num != IDIAG_BARACC_BAR_0)
1902 goto error_out;
1903 } else
1904 goto error_out;
1905
1906 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1907 if (bar_num == IDIAG_BARACC_BAR_0) {
1908 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1909 LPFC_PCI_IF0_BAR0_SIZE;
1910 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1911 } else if (bar_num == IDIAG_BARACC_BAR_1) {
1912 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1913 LPFC_PCI_IF0_BAR1_SIZE;
1914 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1915 } else if (bar_num == IDIAG_BARACC_BAR_2) {
1916 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1917 LPFC_PCI_IF0_BAR2_SIZE;
1918 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1919 } else
1920 goto error_out;
1921 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1922 if (bar_num == IDIAG_BARACC_BAR_0) {
1923 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1924 LPFC_PCI_IF2_BAR0_SIZE;
1925 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1926 } else
1927 goto error_out;
1928 } else
1929 goto error_out;
1930
1931 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1932 if (offset % sizeof(uint32_t))
1933 goto error_out;
1934
1935 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1936 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1937 /* Sanity check on PCI config read command line arguments */
1938 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1939 goto error_out;
1940 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1941 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1942 if (offset > bar_size - sizeof(uint32_t))
1943 goto error_out;
1944 /* Starting offset to browse */
1945 idiag.offset.last_rd = offset;
1946 } else if (acc_range > SINGLE_WORD) {
1947 if (offset + acc_range * sizeof(uint32_t) > bar_size)
1948 goto error_out;
1949 /* Starting offset to browse */
1950 idiag.offset.last_rd = offset;
1951 } else if (acc_range != SINGLE_WORD)
1952 goto error_out;
1953 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1954 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1955 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1956 /* Sanity check on PCI bar write command line arguments */
1957 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1958 goto error_out;
1959 /* Write command to PCI bar space, read-modify-write */
1960 acc_range = SINGLE_WORD;
1961 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1962 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1963 writel(value, mem_mapped_bar + offset);
1964 readl(mem_mapped_bar + offset);
1965 }
1966 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1967 u32val = readl(mem_mapped_bar + offset);
1968 u32val |= value;
1969 writel(u32val, mem_mapped_bar + offset);
1970 readl(mem_mapped_bar + offset);
1971 }
1972 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1973 u32val = readl(mem_mapped_bar + offset);
1974 u32val &= ~value;
1975 writel(u32val, mem_mapped_bar + offset);
1976 readl(mem_mapped_bar + offset);
1977 }
1978 } else
1979 /* All other opecodes are illegal for now */
1980 goto error_out;
1981
1982 return nbytes;
1983error_out:
1984 memset(&idiag, 0, sizeof(idiag));
1985 return -EINVAL;
1986}
1987
1988/**
James Smart2a622bf2011-02-16 12:40:06 -05001989 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1990 * @file: The file pointer to read from.
1991 * @buf: The buffer to copy the data to.
1992 * @nbytes: The number of bytes to read.
1993 * @ppos: The position in the file to start reading from.
1994 *
1995 * Description:
1996 * This routine reads data from the @phba SLI4 PCI function queue information,
1997 * and copies to user @buf.
1998 *
1999 * Returns:
2000 * This function returns the amount of data that was read (this could be less
2001 * than @nbytes if the end of the file was reached) or a negative error value.
2002 **/
2003static ssize_t
2004lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
2005 loff_t *ppos)
2006{
2007 struct lpfc_debug *debug = file->private_data;
2008 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2009 int len = 0, fcp_qidx;
2010 char *pbuffer;
2011
2012 if (!debug->buffer)
2013 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
2014 if (!debug->buffer)
2015 return 0;
2016 pbuffer = debug->buffer;
2017
2018 if (*ppos)
2019 return 0;
2020
2021 /* Get slow-path event queue information */
2022 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2023 "Slow-path EQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002024 if (phba->sli4_hba.sp_eq) {
2025 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002026 "\tEQID[%02d], "
2027 "QE-COUNT[%04d], QE-SIZE[%04d], "
2028 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002029 phba->sli4_hba.sp_eq->queue_id,
2030 phba->sli4_hba.sp_eq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002031 phba->sli4_hba.sp_eq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002032 phba->sli4_hba.sp_eq->host_index,
2033 phba->sli4_hba.sp_eq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002034 }
James Smart2a622bf2011-02-16 12:40:06 -05002035
2036 /* Get fast-path event queue information */
2037 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2038 "Fast-path EQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002039 if (phba->sli4_hba.fp_eq) {
2040 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count;
2041 fcp_qidx++) {
2042 if (phba->sli4_hba.fp_eq[fcp_qidx]) {
2043 len += snprintf(pbuffer+len,
2044 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002045 "\tEQID[%02d], "
2046 "QE-COUNT[%04d], QE-SIZE[%04d], "
2047 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002048 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
2049 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002050 phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002051 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
2052 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002053 }
2054 }
James Smart2a622bf2011-02-16 12:40:06 -05002055 }
2056 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2057
2058 /* Get mailbox complete queue information */
2059 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002060 "Slow-path MBX CQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002061 if (phba->sli4_hba.mbx_cq) {
2062 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002063 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002064 phba->sli4_hba.mbx_cq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002065 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002066 "\tCQID[%02d], "
2067 "QE-COUNT[%04d], QE-SIZE[%04d], "
2068 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002069 phba->sli4_hba.mbx_cq->queue_id,
2070 phba->sli4_hba.mbx_cq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002071 phba->sli4_hba.mbx_cq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002072 phba->sli4_hba.mbx_cq->host_index,
2073 phba->sli4_hba.mbx_cq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002074 }
James Smart2a622bf2011-02-16 12:40:06 -05002075
2076 /* Get slow-path complete queue information */
2077 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002078 "Slow-path ELS CQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002079 if (phba->sli4_hba.els_cq) {
2080 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002081 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002082 phba->sli4_hba.els_cq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002083 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002084 "\tCQID [%02d], "
2085 "QE-COUNT[%04d], QE-SIZE[%04d], "
2086 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002087 phba->sli4_hba.els_cq->queue_id,
2088 phba->sli4_hba.els_cq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002089 phba->sli4_hba.els_cq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002090 phba->sli4_hba.els_cq->host_index,
2091 phba->sli4_hba.els_cq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002092 }
James Smart2a622bf2011-02-16 12:40:06 -05002093
2094 /* Get fast-path complete queue information */
2095 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002096 "Fast-path FCP CQ information:\n");
James Smart05580562011-05-24 11:40:48 -04002097 fcp_qidx = 0;
James Smart2e90f4b2011-12-13 13:22:37 -05002098 if (phba->sli4_hba.fcp_cq) {
2099 do {
2100 if (phba->sli4_hba.fcp_cq[fcp_qidx]) {
2101 len += snprintf(pbuffer+len,
2102 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002103 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002104 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002105 len += snprintf(pbuffer+len,
2106 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002107 "\tCQID[%02d], "
2108 "QE-COUNT[%04d], QE-SIZE[%04d], "
2109 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2110 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
2111 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
2112 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
2113 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
2114 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002115 }
2116 } while (++fcp_qidx < phba->cfg_fcp_eq_count);
2117 len += snprintf(pbuffer+len,
2118 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2119 }
James Smart2a622bf2011-02-16 12:40:06 -05002120
2121 /* Get mailbox queue information */
2122 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002123 "Slow-path MBX MQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002124 if (phba->sli4_hba.mbx_wq) {
2125 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002126 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002127 phba->sli4_hba.mbx_wq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002128 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002129 "\tWQID[%02d], "
2130 "QE-COUNT[%04d], QE-SIZE[%04d], "
2131 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002132 phba->sli4_hba.mbx_wq->queue_id,
2133 phba->sli4_hba.mbx_wq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002134 phba->sli4_hba.mbx_wq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002135 phba->sli4_hba.mbx_wq->host_index,
2136 phba->sli4_hba.mbx_wq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002137 }
James Smart2a622bf2011-02-16 12:40:06 -05002138
2139 /* Get slow-path work queue information */
2140 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002141 "Slow-path ELS WQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002142 if (phba->sli4_hba.els_wq) {
2143 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002144 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002145 phba->sli4_hba.els_wq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002146 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002147 "\tWQID[%02d], "
2148 "QE-COUNT[%04d], QE-SIZE[%04d], "
2149 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002150 phba->sli4_hba.els_wq->queue_id,
2151 phba->sli4_hba.els_wq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002152 phba->sli4_hba.els_wq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002153 phba->sli4_hba.els_wq->host_index,
2154 phba->sli4_hba.els_wq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002155 }
James Smart2a622bf2011-02-16 12:40:06 -05002156
2157 /* Get fast-path work queue information */
2158 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002159 "Fast-path FCP WQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002160 if (phba->sli4_hba.fcp_wq) {
2161 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count;
2162 fcp_qidx++) {
2163 if (!phba->sli4_hba.fcp_wq[fcp_qidx])
2164 continue;
2165 len += snprintf(pbuffer+len,
2166 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002167 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002168 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002169 len += snprintf(pbuffer+len,
2170 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002171 "\tWQID[%02d], "
2172 "QE-COUNT[%04d], WQE-SIZE[%04d], "
2173 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002174 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
2175 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002176 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002177 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
2178 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002179 }
2180 len += snprintf(pbuffer+len,
2181 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
James Smart2a622bf2011-02-16 12:40:06 -05002182 }
James Smart2a622bf2011-02-16 12:40:06 -05002183
2184 /* Get receive queue information */
2185 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2186 "Slow-path RQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002187 if (phba->sli4_hba.hdr_rq && phba->sli4_hba.dat_rq) {
2188 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002189 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002190 phba->sli4_hba.hdr_rq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002191 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002192 "\tHQID[%02d], "
2193 "QE-COUNT[%04d], QE-SIZE[%04d], "
2194 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002195 phba->sli4_hba.hdr_rq->queue_id,
2196 phba->sli4_hba.hdr_rq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002197 phba->sli4_hba.hdr_rq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002198 phba->sli4_hba.hdr_rq->host_index,
2199 phba->sli4_hba.hdr_rq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002200 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002201 "\tDQID[%02d], "
2202 "QE-COUNT[%04d], QE-SIZE[%04d], "
2203 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002204 phba->sli4_hba.dat_rq->queue_id,
2205 phba->sli4_hba.dat_rq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002206 phba->sli4_hba.dat_rq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002207 phba->sli4_hba.dat_rq->host_index,
2208 phba->sli4_hba.dat_rq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002209 }
James Smart2a622bf2011-02-16 12:40:06 -05002210 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2211}
2212
James Smart86a80842011-04-16 11:03:04 -04002213/**
2214 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2215 * @q: The pointer to queue structure.
2216 * @index: The index into a queue entry.
2217 * @count: The number of queue entries to access.
2218 *
2219 * Description:
2220 * The routine performs sanity check on device queue access method commands.
2221 *
2222 * Returns:
2223 * This function returns -EINVAL when fails the sanity check, otherwise, it
2224 * returns 0.
2225 **/
2226static int
2227lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
2228{
2229 /* Only support single entry read or browsing */
2230 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
2231 return -EINVAL;
2232 if (index > q->entry_count - 1)
2233 return -EINVAL;
2234 return 0;
2235}
2236
2237/**
2238 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2239 * @pbuffer: The pointer to buffer to copy the read data into.
2240 * @pque: The pointer to the queue to be read.
2241 * @index: The index into the queue entry.
2242 *
2243 * Description:
2244 * This routine reads out a single entry from the given queue's index location
2245 * and copies it into the buffer provided.
2246 *
2247 * Returns:
2248 * This function returns 0 when it fails, otherwise, it returns the length of
2249 * the data read into the buffer provided.
2250 **/
2251static int
2252lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
2253 uint32_t index)
2254{
2255 int offset, esize;
2256 uint32_t *pentry;
2257
2258 if (!pbuffer || !pque)
2259 return 0;
2260
2261 esize = pque->entry_size;
2262 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2263 "QE-INDEX[%04d]:\n", index);
2264
2265 offset = 0;
2266 pentry = pque->qe[index].address;
2267 while (esize > 0) {
2268 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2269 "%08x ", *pentry);
2270 pentry++;
2271 offset += sizeof(uint32_t);
2272 esize -= sizeof(uint32_t);
2273 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
2274 len += snprintf(pbuffer+len,
2275 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2276 }
2277 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2278
2279 return len;
2280}
2281
2282/**
2283 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2284 * @file: The file pointer to read from.
2285 * @buf: The buffer to copy the data to.
2286 * @nbytes: The number of bytes to read.
2287 * @ppos: The position in the file to start reading from.
2288 *
2289 * Description:
2290 * This routine reads data from the @phba device queue memory according to the
2291 * idiag command, and copies to user @buf. Depending on the queue dump read
2292 * command setup, it does either a single queue entry read or browing through
2293 * all entries of the queue.
2294 *
2295 * Returns:
2296 * This function returns the amount of data that was read (this could be less
2297 * than @nbytes if the end of the file was reached) or a negative error value.
2298 **/
2299static ssize_t
2300lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
2301 loff_t *ppos)
2302{
2303 struct lpfc_debug *debug = file->private_data;
2304 uint32_t last_index, index, count;
2305 struct lpfc_queue *pque = NULL;
2306 char *pbuffer;
2307 int len = 0;
2308
2309 /* This is a user read operation */
2310 debug->op = LPFC_IDIAG_OP_RD;
2311
2312 if (!debug->buffer)
2313 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
2314 if (!debug->buffer)
2315 return 0;
2316 pbuffer = debug->buffer;
2317
2318 if (*ppos)
2319 return 0;
2320
2321 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04002322 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2323 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04002324 pque = (struct lpfc_queue *)idiag.ptr_private;
2325 } else
2326 return 0;
2327
2328 /* Browse the queue starting from index */
2329 if (count == LPFC_QUE_ACC_BROWSE)
2330 goto que_browse;
2331
2332 /* Read a single entry from the queue */
2333 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2334
2335 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2336
2337que_browse:
2338
2339 /* Browse all entries from the queue */
2340 last_index = idiag.offset.last_rd;
2341 index = last_index;
2342
2343 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
2344 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2345 index++;
2346 if (index > pque->entry_count - 1)
2347 break;
2348 }
2349
2350 /* Set up the offset for next portion of pci cfg read */
2351 if (index > pque->entry_count - 1)
2352 index = 0;
2353 idiag.offset.last_rd = index;
2354
2355 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2356}
2357
2358/**
2359 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2360 * @file: The file pointer to read from.
2361 * @buf: The buffer to copy the user data from.
2362 * @nbytes: The number of bytes to get.
2363 * @ppos: The position in the file to start reading from.
2364 *
2365 * This routine get the debugfs idiag command struct from user space and then
2366 * perform the syntax check for port queue read (dump) or write (set) command
2367 * accordingly. In the case of port queue read command, it sets up the command
2368 * in the idiag command struct for the following debugfs read operation. In
2369 * the case of port queue write operation, it executes the write operation
2370 * into the port queue entry accordingly.
2371 *
2372 * It returns the @nbytges passing in from debugfs user space when successful.
2373 * In case of error conditions, it returns proper error code back to the user
2374 * space.
2375 **/
2376static ssize_t
2377lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
2378 size_t nbytes, loff_t *ppos)
2379{
2380 struct lpfc_debug *debug = file->private_data;
2381 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2382 uint32_t qidx, quetp, queid, index, count, offset, value;
2383 uint32_t *pentry;
2384 struct lpfc_queue *pque;
2385 int rc;
2386
2387 /* This is a user write operation */
2388 debug->op = LPFC_IDIAG_OP_WR;
2389
2390 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2391 if (rc < 0)
2392 return rc;
2393
2394 /* Get and sanity check on command feilds */
James Smartb76f2dc2011-07-22 18:37:42 -04002395 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
2396 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
2397 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2398 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2399 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
2400 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04002401
2402 /* Sanity check on command line arguments */
2403 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2404 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2405 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2406 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
2407 goto error_out;
2408 if (count != 1)
2409 goto error_out;
2410 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2411 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
2412 goto error_out;
2413 } else
2414 goto error_out;
2415
2416 switch (quetp) {
2417 case LPFC_IDIAG_EQ:
2418 /* Slow-path event queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002419 if (phba->sli4_hba.sp_eq &&
2420 phba->sli4_hba.sp_eq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002421 /* Sanity check */
2422 rc = lpfc_idiag_que_param_check(
2423 phba->sli4_hba.sp_eq, index, count);
2424 if (rc)
2425 goto error_out;
2426 idiag.ptr_private = phba->sli4_hba.sp_eq;
2427 goto pass_check;
2428 }
2429 /* Fast-path event queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002430 if (phba->sli4_hba.fp_eq) {
2431 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
2432 if (phba->sli4_hba.fp_eq[qidx] &&
2433 phba->sli4_hba.fp_eq[qidx]->queue_id ==
2434 queid) {
2435 /* Sanity check */
2436 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002437 phba->sli4_hba.fp_eq[qidx],
2438 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002439 if (rc)
2440 goto error_out;
2441 idiag.ptr_private =
2442 phba->sli4_hba.fp_eq[qidx];
2443 goto pass_check;
2444 }
James Smart86a80842011-04-16 11:03:04 -04002445 }
2446 }
2447 goto error_out;
2448 break;
2449 case LPFC_IDIAG_CQ:
2450 /* MBX complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002451 if (phba->sli4_hba.mbx_cq &&
2452 phba->sli4_hba.mbx_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002453 /* Sanity check */
2454 rc = lpfc_idiag_que_param_check(
2455 phba->sli4_hba.mbx_cq, index, count);
2456 if (rc)
2457 goto error_out;
2458 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2459 goto pass_check;
2460 }
2461 /* ELS complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002462 if (phba->sli4_hba.els_cq &&
2463 phba->sli4_hba.els_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002464 /* Sanity check */
2465 rc = lpfc_idiag_que_param_check(
2466 phba->sli4_hba.els_cq, index, count);
2467 if (rc)
2468 goto error_out;
2469 idiag.ptr_private = phba->sli4_hba.els_cq;
2470 goto pass_check;
2471 }
2472 /* FCP complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002473 if (phba->sli4_hba.fcp_cq) {
2474 qidx = 0;
2475 do {
2476 if (phba->sli4_hba.fcp_cq[qidx] &&
2477 phba->sli4_hba.fcp_cq[qidx]->queue_id ==
2478 queid) {
2479 /* Sanity check */
2480 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002481 phba->sli4_hba.fcp_cq[qidx],
2482 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002483 if (rc)
2484 goto error_out;
2485 idiag.ptr_private =
James Smart86a80842011-04-16 11:03:04 -04002486 phba->sli4_hba.fcp_cq[qidx];
James Smart2e90f4b2011-12-13 13:22:37 -05002487 goto pass_check;
2488 }
2489 } while (++qidx < phba->cfg_fcp_eq_count);
2490 }
James Smart86a80842011-04-16 11:03:04 -04002491 goto error_out;
2492 break;
2493 case LPFC_IDIAG_MQ:
2494 /* MBX work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002495 if (phba->sli4_hba.mbx_wq &&
2496 phba->sli4_hba.mbx_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002497 /* Sanity check */
2498 rc = lpfc_idiag_que_param_check(
2499 phba->sli4_hba.mbx_wq, index, count);
2500 if (rc)
2501 goto error_out;
2502 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2503 goto pass_check;
2504 }
James Smart2e90f4b2011-12-13 13:22:37 -05002505 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04002506 break;
2507 case LPFC_IDIAG_WQ:
2508 /* ELS work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002509 if (phba->sli4_hba.els_wq &&
2510 phba->sli4_hba.els_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002511 /* Sanity check */
2512 rc = lpfc_idiag_que_param_check(
2513 phba->sli4_hba.els_wq, index, count);
2514 if (rc)
2515 goto error_out;
2516 idiag.ptr_private = phba->sli4_hba.els_wq;
2517 goto pass_check;
2518 }
2519 /* FCP work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002520 if (phba->sli4_hba.fcp_wq) {
2521 for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
2522 if (!phba->sli4_hba.fcp_wq[qidx])
2523 continue;
2524 if (phba->sli4_hba.fcp_wq[qidx]->queue_id ==
2525 queid) {
2526 /* Sanity check */
2527 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002528 phba->sli4_hba.fcp_wq[qidx],
2529 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002530 if (rc)
2531 goto error_out;
2532 idiag.ptr_private =
2533 phba->sli4_hba.fcp_wq[qidx];
2534 goto pass_check;
2535 }
James Smart86a80842011-04-16 11:03:04 -04002536 }
2537 }
2538 goto error_out;
2539 break;
2540 case LPFC_IDIAG_RQ:
2541 /* HDR queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002542 if (phba->sli4_hba.hdr_rq &&
2543 phba->sli4_hba.hdr_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002544 /* Sanity check */
2545 rc = lpfc_idiag_que_param_check(
2546 phba->sli4_hba.hdr_rq, index, count);
2547 if (rc)
2548 goto error_out;
2549 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2550 goto pass_check;
2551 }
2552 /* DAT queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002553 if (phba->sli4_hba.dat_rq &&
2554 phba->sli4_hba.dat_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002555 /* Sanity check */
2556 rc = lpfc_idiag_que_param_check(
2557 phba->sli4_hba.dat_rq, index, count);
2558 if (rc)
2559 goto error_out;
2560 idiag.ptr_private = phba->sli4_hba.dat_rq;
2561 goto pass_check;
2562 }
2563 goto error_out;
2564 break;
2565 default:
2566 goto error_out;
2567 break;
2568 }
2569
2570pass_check:
2571
2572 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2573 if (count == LPFC_QUE_ACC_BROWSE)
2574 idiag.offset.last_rd = index;
2575 }
2576
2577 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2578 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2579 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2580 /* Additional sanity checks on write operation */
2581 pque = (struct lpfc_queue *)idiag.ptr_private;
2582 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2583 goto error_out;
2584 pentry = pque->qe[index].address;
2585 pentry += offset;
2586 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2587 *pentry = value;
2588 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2589 *pentry |= value;
2590 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2591 *pentry &= ~value;
2592 }
2593 return nbytes;
2594
2595error_out:
2596 /* Clean out command structure on command error out */
2597 memset(&idiag, 0, sizeof(idiag));
2598 return -EINVAL;
2599}
2600
2601/**
2602 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2603 * @phba: The pointer to hba structure.
2604 * @pbuffer: The pointer to the buffer to copy the data to.
2605 * @len: The lenght of bytes to copied.
2606 * @drbregid: The id to doorbell registers.
2607 *
2608 * Description:
2609 * This routine reads a doorbell register and copies its content to the
2610 * user buffer pointed to by @pbuffer.
2611 *
2612 * Returns:
2613 * This function returns the amount of data that was copied into @pbuffer.
2614 **/
2615static int
2616lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2617 int len, uint32_t drbregid)
2618{
2619
2620 if (!pbuffer)
2621 return 0;
2622
2623 switch (drbregid) {
2624 case LPFC_DRB_EQCQ:
2625 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2626 "EQCQ-DRB-REG: 0x%08x\n",
2627 readl(phba->sli4_hba.EQCQDBregaddr));
2628 break;
2629 case LPFC_DRB_MQ:
2630 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2631 "MQ-DRB-REG: 0x%08x\n",
2632 readl(phba->sli4_hba.MQDBregaddr));
2633 break;
2634 case LPFC_DRB_WQ:
2635 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2636 "WQ-DRB-REG: 0x%08x\n",
2637 readl(phba->sli4_hba.WQDBregaddr));
2638 break;
2639 case LPFC_DRB_RQ:
2640 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2641 "RQ-DRB-REG: 0x%08x\n",
2642 readl(phba->sli4_hba.RQDBregaddr));
2643 break;
2644 default:
2645 break;
2646 }
2647
2648 return len;
2649}
2650
2651/**
2652 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2653 * @file: The file pointer to read from.
2654 * @buf: The buffer to copy the data to.
2655 * @nbytes: The number of bytes to read.
2656 * @ppos: The position in the file to start reading from.
2657 *
2658 * Description:
2659 * This routine reads data from the @phba device doorbell register according
2660 * to the idiag command, and copies to user @buf. Depending on the doorbell
2661 * register read command setup, it does either a single doorbell register
2662 * read or dump all doorbell registers.
2663 *
2664 * Returns:
2665 * This function returns the amount of data that was read (this could be less
2666 * than @nbytes if the end of the file was reached) or a negative error value.
2667 **/
2668static ssize_t
2669lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2670 loff_t *ppos)
2671{
2672 struct lpfc_debug *debug = file->private_data;
2673 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2674 uint32_t drb_reg_id, i;
2675 char *pbuffer;
2676 int len = 0;
2677
2678 /* This is a user read operation */
2679 debug->op = LPFC_IDIAG_OP_RD;
2680
2681 if (!debug->buffer)
2682 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2683 if (!debug->buffer)
2684 return 0;
2685 pbuffer = debug->buffer;
2686
2687 if (*ppos)
2688 return 0;
2689
2690 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
James Smartb76f2dc2011-07-22 18:37:42 -04002691 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
James Smart86a80842011-04-16 11:03:04 -04002692 else
2693 return 0;
2694
2695 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2696 for (i = 1; i <= LPFC_DRB_MAX; i++)
2697 len = lpfc_idiag_drbacc_read_reg(phba,
2698 pbuffer, len, i);
2699 else
2700 len = lpfc_idiag_drbacc_read_reg(phba,
2701 pbuffer, len, drb_reg_id);
2702
2703 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2704}
2705
2706/**
2707 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2708 * @file: The file pointer to read from.
2709 * @buf: The buffer to copy the user data from.
2710 * @nbytes: The number of bytes to get.
2711 * @ppos: The position in the file to start reading from.
2712 *
2713 * This routine get the debugfs idiag command struct from user space and then
2714 * perform the syntax check for port doorbell register read (dump) or write
2715 * (set) command accordingly. In the case of port queue read command, it sets
2716 * up the command in the idiag command struct for the following debugfs read
2717 * operation. In the case of port doorbell register write operation, it
2718 * executes the write operation into the port doorbell register accordingly.
2719 *
2720 * It returns the @nbytges passing in from debugfs user space when successful.
2721 * In case of error conditions, it returns proper error code back to the user
2722 * space.
2723 **/
2724static ssize_t
2725lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2726 size_t nbytes, loff_t *ppos)
2727{
2728 struct lpfc_debug *debug = file->private_data;
2729 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
James Smartb76f2dc2011-07-22 18:37:42 -04002730 uint32_t drb_reg_id, value, reg_val = 0;
James Smart86a80842011-04-16 11:03:04 -04002731 void __iomem *drb_reg;
2732 int rc;
2733
2734 /* This is a user write operation */
2735 debug->op = LPFC_IDIAG_OP_WR;
2736
2737 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2738 if (rc < 0)
2739 return rc;
2740
2741 /* Sanity check on command line arguments */
James Smartb76f2dc2011-07-22 18:37:42 -04002742 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2743 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04002744
2745 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2746 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2747 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2748 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2749 goto error_out;
2750 if (drb_reg_id > LPFC_DRB_MAX)
2751 goto error_out;
2752 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2753 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2754 goto error_out;
2755 if ((drb_reg_id > LPFC_DRB_MAX) &&
2756 (drb_reg_id != LPFC_DRB_ACC_ALL))
2757 goto error_out;
2758 } else
2759 goto error_out;
2760
2761 /* Perform the write access operation */
2762 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2763 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2764 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2765 switch (drb_reg_id) {
2766 case LPFC_DRB_EQCQ:
2767 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2768 break;
2769 case LPFC_DRB_MQ:
2770 drb_reg = phba->sli4_hba.MQDBregaddr;
2771 break;
2772 case LPFC_DRB_WQ:
2773 drb_reg = phba->sli4_hba.WQDBregaddr;
2774 break;
2775 case LPFC_DRB_RQ:
2776 drb_reg = phba->sli4_hba.RQDBregaddr;
2777 break;
2778 default:
2779 goto error_out;
2780 }
2781
2782 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2783 reg_val = value;
2784 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2785 reg_val = readl(drb_reg);
2786 reg_val |= value;
2787 }
2788 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2789 reg_val = readl(drb_reg);
2790 reg_val &= ~value;
2791 }
2792 writel(reg_val, drb_reg);
2793 readl(drb_reg); /* flush */
2794 }
2795 return nbytes;
2796
2797error_out:
2798 /* Clean out command structure on command error out */
2799 memset(&idiag, 0, sizeof(idiag));
2800 return -EINVAL;
2801}
2802
James Smartb76f2dc2011-07-22 18:37:42 -04002803/**
2804 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2805 * @phba: The pointer to hba structure.
2806 * @pbuffer: The pointer to the buffer to copy the data to.
2807 * @len: The lenght of bytes to copied.
2808 * @drbregid: The id to doorbell registers.
2809 *
2810 * Description:
2811 * This routine reads a control register and copies its content to the
2812 * user buffer pointed to by @pbuffer.
2813 *
2814 * Returns:
2815 * This function returns the amount of data that was copied into @pbuffer.
2816 **/
2817static int
2818lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2819 int len, uint32_t ctlregid)
2820{
2821
2822 if (!pbuffer)
2823 return 0;
2824
2825 switch (ctlregid) {
2826 case LPFC_CTL_PORT_SEM:
2827 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2828 "Port SemReg: 0x%08x\n",
2829 readl(phba->sli4_hba.conf_regs_memmap_p +
2830 LPFC_CTL_PORT_SEM_OFFSET));
2831 break;
2832 case LPFC_CTL_PORT_STA:
2833 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2834 "Port StaReg: 0x%08x\n",
2835 readl(phba->sli4_hba.conf_regs_memmap_p +
2836 LPFC_CTL_PORT_STA_OFFSET));
2837 break;
2838 case LPFC_CTL_PORT_CTL:
2839 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2840 "Port CtlReg: 0x%08x\n",
2841 readl(phba->sli4_hba.conf_regs_memmap_p +
2842 LPFC_CTL_PORT_CTL_OFFSET));
2843 break;
2844 case LPFC_CTL_PORT_ER1:
2845 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2846 "Port Er1Reg: 0x%08x\n",
2847 readl(phba->sli4_hba.conf_regs_memmap_p +
2848 LPFC_CTL_PORT_ER1_OFFSET));
2849 break;
2850 case LPFC_CTL_PORT_ER2:
2851 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2852 "Port Er2Reg: 0x%08x\n",
2853 readl(phba->sli4_hba.conf_regs_memmap_p +
2854 LPFC_CTL_PORT_ER2_OFFSET));
2855 break;
2856 case LPFC_CTL_PDEV_CTL:
2857 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2858 "PDev CtlReg: 0x%08x\n",
2859 readl(phba->sli4_hba.conf_regs_memmap_p +
2860 LPFC_CTL_PDEV_CTL_OFFSET));
2861 break;
2862 default:
2863 break;
2864 }
2865 return len;
2866}
2867
2868/**
2869 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2870 * @file: The file pointer to read from.
2871 * @buf: The buffer to copy the data to.
2872 * @nbytes: The number of bytes to read.
2873 * @ppos: The position in the file to start reading from.
2874 *
2875 * Description:
2876 * This routine reads data from the @phba port and device registers according
2877 * to the idiag command, and copies to user @buf.
2878 *
2879 * Returns:
2880 * This function returns the amount of data that was read (this could be less
2881 * than @nbytes if the end of the file was reached) or a negative error value.
2882 **/
2883static ssize_t
2884lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2885 loff_t *ppos)
2886{
2887 struct lpfc_debug *debug = file->private_data;
2888 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2889 uint32_t ctl_reg_id, i;
2890 char *pbuffer;
2891 int len = 0;
2892
2893 /* This is a user read operation */
2894 debug->op = LPFC_IDIAG_OP_RD;
2895
2896 if (!debug->buffer)
2897 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2898 if (!debug->buffer)
2899 return 0;
2900 pbuffer = debug->buffer;
2901
2902 if (*ppos)
2903 return 0;
2904
2905 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2906 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2907 else
2908 return 0;
2909
2910 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2911 for (i = 1; i <= LPFC_CTL_MAX; i++)
2912 len = lpfc_idiag_ctlacc_read_reg(phba,
2913 pbuffer, len, i);
2914 else
2915 len = lpfc_idiag_ctlacc_read_reg(phba,
2916 pbuffer, len, ctl_reg_id);
2917
2918 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2919}
2920
2921/**
2922 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2923 * @file: The file pointer to read from.
2924 * @buf: The buffer to copy the user data from.
2925 * @nbytes: The number of bytes to get.
2926 * @ppos: The position in the file to start reading from.
2927 *
2928 * This routine get the debugfs idiag command struct from user space and then
2929 * perform the syntax check for port and device control register read (dump)
2930 * or write (set) command accordingly.
2931 *
2932 * It returns the @nbytges passing in from debugfs user space when successful.
2933 * In case of error conditions, it returns proper error code back to the user
2934 * space.
2935 **/
2936static ssize_t
2937lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
2938 size_t nbytes, loff_t *ppos)
2939{
2940 struct lpfc_debug *debug = file->private_data;
2941 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2942 uint32_t ctl_reg_id, value, reg_val = 0;
2943 void __iomem *ctl_reg;
2944 int rc;
2945
2946 /* This is a user write operation */
2947 debug->op = LPFC_IDIAG_OP_WR;
2948
2949 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2950 if (rc < 0)
2951 return rc;
2952
2953 /* Sanity check on command line arguments */
2954 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2955 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
2956
2957 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2958 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2959 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2960 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
2961 goto error_out;
2962 if (ctl_reg_id > LPFC_CTL_MAX)
2963 goto error_out;
2964 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
2965 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
2966 goto error_out;
2967 if ((ctl_reg_id > LPFC_CTL_MAX) &&
2968 (ctl_reg_id != LPFC_CTL_ACC_ALL))
2969 goto error_out;
2970 } else
2971 goto error_out;
2972
2973 /* Perform the write access operation */
2974 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2975 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2976 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2977 switch (ctl_reg_id) {
2978 case LPFC_CTL_PORT_SEM:
2979 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2980 LPFC_CTL_PORT_SEM_OFFSET;
2981 break;
2982 case LPFC_CTL_PORT_STA:
2983 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2984 LPFC_CTL_PORT_STA_OFFSET;
2985 break;
2986 case LPFC_CTL_PORT_CTL:
2987 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2988 LPFC_CTL_PORT_CTL_OFFSET;
2989 break;
2990 case LPFC_CTL_PORT_ER1:
2991 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2992 LPFC_CTL_PORT_ER1_OFFSET;
2993 break;
2994 case LPFC_CTL_PORT_ER2:
2995 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2996 LPFC_CTL_PORT_ER2_OFFSET;
2997 break;
2998 case LPFC_CTL_PDEV_CTL:
2999 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3000 LPFC_CTL_PDEV_CTL_OFFSET;
3001 break;
3002 default:
3003 goto error_out;
3004 }
3005
3006 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
3007 reg_val = value;
3008 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
3009 reg_val = readl(ctl_reg);
3010 reg_val |= value;
3011 }
3012 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3013 reg_val = readl(ctl_reg);
3014 reg_val &= ~value;
3015 }
3016 writel(reg_val, ctl_reg);
3017 readl(ctl_reg); /* flush */
3018 }
3019 return nbytes;
3020
3021error_out:
3022 /* Clean out command structure on command error out */
3023 memset(&idiag, 0, sizeof(idiag));
3024 return -EINVAL;
3025}
3026
3027/**
3028 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
3029 * @phba: Pointer to HBA context object.
3030 * @pbuffer: Pointer to data buffer.
3031 *
3032 * Description:
3033 * This routine gets the driver mailbox access debugfs setup information.
3034 *
3035 * Returns:
3036 * This function returns the amount of data that was read (this could be less
3037 * than @nbytes if the end of the file was reached) or a negative error value.
3038 **/
3039static int
3040lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
3041{
3042 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3043 int len = 0;
3044
3045 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3046 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3047 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3048 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3049
3050 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3051 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
3052 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3053 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
3054 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3055 "mbx_word_cnt: %04d\n", mbx_word_cnt);
3056 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3057 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
3058
3059 return len;
3060}
3061
3062/**
3063 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
3064 * @file: The file pointer to read from.
3065 * @buf: The buffer to copy the data to.
3066 * @nbytes: The number of bytes to read.
3067 * @ppos: The position in the file to start reading from.
3068 *
3069 * Description:
3070 * This routine reads data from the @phba driver mailbox access debugfs setup
3071 * information.
3072 *
3073 * Returns:
3074 * This function returns the amount of data that was read (this could be less
3075 * than @nbytes if the end of the file was reached) or a negative error value.
3076 **/
3077static ssize_t
3078lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
3079 loff_t *ppos)
3080{
3081 struct lpfc_debug *debug = file->private_data;
3082 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3083 char *pbuffer;
3084 int len = 0;
3085
3086 /* This is a user read operation */
3087 debug->op = LPFC_IDIAG_OP_RD;
3088
3089 if (!debug->buffer)
3090 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
3091 if (!debug->buffer)
3092 return 0;
3093 pbuffer = debug->buffer;
3094
3095 if (*ppos)
3096 return 0;
3097
3098 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
3099 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
3100 return 0;
3101
3102 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
3103
3104 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3105}
3106
3107/**
3108 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
3109 * @file: The file pointer to read from.
3110 * @buf: The buffer to copy the user data from.
3111 * @nbytes: The number of bytes to get.
3112 * @ppos: The position in the file to start reading from.
3113 *
3114 * This routine get the debugfs idiag command struct from user space and then
3115 * perform the syntax check for driver mailbox command (dump) and sets up the
3116 * necessary states in the idiag command struct accordingly.
3117 *
3118 * It returns the @nbytges passing in from debugfs user space when successful.
3119 * In case of error conditions, it returns proper error code back to the user
3120 * space.
3121 **/
3122static ssize_t
3123lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
3124 size_t nbytes, loff_t *ppos)
3125{
3126 struct lpfc_debug *debug = file->private_data;
3127 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3128 int rc;
3129
3130 /* This is a user write operation */
3131 debug->op = LPFC_IDIAG_OP_WR;
3132
3133 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3134 if (rc < 0)
3135 return rc;
3136
3137 /* Sanity check on command line arguments */
3138 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3139 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3140 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3141 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3142
3143 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
3144 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
3145 goto error_out;
3146 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
3147 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3148 goto error_out;
3149 if (mbx_word_cnt > sizeof(MAILBOX_t))
3150 goto error_out;
3151 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
3152 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
3153 goto error_out;
3154 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
3155 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3156 goto error_out;
3157 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3158 goto error_out;
3159 if (mbx_mbox_cmd != 0x9b)
3160 goto error_out;
3161 } else
3162 goto error_out;
3163
3164 if (mbx_word_cnt == 0)
3165 goto error_out;
3166 if (rc != LPFC_MBX_DMP_ARG)
3167 goto error_out;
3168 if (mbx_mbox_cmd & ~0xff)
3169 goto error_out;
3170
3171 /* condition for stop mailbox dump */
3172 if (mbx_dump_cnt == 0)
3173 goto reset_out;
3174
3175 return nbytes;
3176
3177reset_out:
3178 /* Clean out command structure on command error out */
3179 memset(&idiag, 0, sizeof(idiag));
3180 return nbytes;
3181
3182error_out:
3183 /* Clean out command structure on command error out */
3184 memset(&idiag, 0, sizeof(idiag));
3185 return -EINVAL;
3186}
3187
3188/**
3189 * lpfc_idiag_extacc_avail_get - get the available extents information
3190 * @phba: pointer to lpfc hba data structure.
3191 * @pbuffer: pointer to internal buffer.
3192 * @len: length into the internal buffer data has been copied.
3193 *
3194 * Description:
3195 * This routine is to get the available extent information.
3196 *
3197 * Returns:
3198 * overall lenth of the data read into the internal buffer.
3199 **/
3200static int
3201lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3202{
3203 uint16_t ext_cnt, ext_size;
3204
3205 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3206 "\nAvailable Extents Information:\n");
3207
3208 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3209 "\tPort Available VPI extents: ");
3210 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3211 &ext_cnt, &ext_size);
3212 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3213 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3214
3215 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3216 "\tPort Available VFI extents: ");
3217 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3218 &ext_cnt, &ext_size);
3219 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3220 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3221
3222 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3223 "\tPort Available RPI extents: ");
3224 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3225 &ext_cnt, &ext_size);
3226 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3227 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3228
3229 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3230 "\tPort Available XRI extents: ");
3231 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3232 &ext_cnt, &ext_size);
3233 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3234 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3235
3236 return len;
3237}
3238
3239/**
3240 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3241 * @phba: pointer to lpfc hba data structure.
3242 * @pbuffer: pointer to internal buffer.
3243 * @len: length into the internal buffer data has been copied.
3244 *
3245 * Description:
3246 * This routine is to get the allocated extent information.
3247 *
3248 * Returns:
3249 * overall lenth of the data read into the internal buffer.
3250 **/
3251static int
3252lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3253{
3254 uint16_t ext_cnt, ext_size;
3255 int rc;
3256
3257 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3258 "\nAllocated Extents Information:\n");
3259
3260 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3261 "\tHost Allocated VPI extents: ");
3262 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
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 VFI extents: ");
3274 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
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 RPI extents: ");
3286 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
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 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3297 "\tHost Allocated XRI extents: ");
3298 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
3299 &ext_cnt, &ext_size);
3300 if (!rc)
3301 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3302 "Port %d Extent %3d, Size %3d\n",
3303 phba->brd_no, ext_cnt, ext_size);
3304 else
3305 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3306 "N/A\n");
3307
3308 return len;
3309}
3310
3311/**
3312 * lpfc_idiag_extacc_drivr_get - get driver extent information
3313 * @phba: pointer to lpfc hba data structure.
3314 * @pbuffer: pointer to internal buffer.
3315 * @len: length into the internal buffer data has been copied.
3316 *
3317 * Description:
3318 * This routine is to get the driver extent information.
3319 *
3320 * Returns:
3321 * overall lenth of the data read into the internal buffer.
3322 **/
3323static int
3324lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3325{
3326 struct lpfc_rsrc_blks *rsrc_blks;
3327 int index;
3328
3329 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3330 "\nDriver Extents Information:\n");
3331
3332 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3333 "\tVPI extents:\n");
3334 index = 0;
3335 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3336 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3337 "\t\tBlock %3d: Start %4d, Count %4d\n",
3338 index, rsrc_blks->rsrc_start,
3339 rsrc_blks->rsrc_size);
3340 index++;
3341 }
3342 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3343 "\tVFI extents:\n");
3344 index = 0;
3345 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_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 "\tRPI extents:\n");
3356 index = 0;
3357 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_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 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3367 "\tXRI extents:\n");
3368 index = 0;
3369 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
3370 list) {
3371 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3372 "\t\tBlock %3d: Start %4d, Count %4d\n",
3373 index, rsrc_blks->rsrc_start,
3374 rsrc_blks->rsrc_size);
3375 index++;
3376 }
3377
3378 return len;
3379}
3380
3381/**
3382 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3383 * @file: The file pointer to read from.
3384 * @buf: The buffer to copy the user data from.
3385 * @nbytes: The number of bytes to get.
3386 * @ppos: The position in the file to start reading from.
3387 *
3388 * This routine get the debugfs idiag command struct from user space and then
3389 * perform the syntax check for extent information access commands and sets
3390 * up the necessary states in the idiag command struct accordingly.
3391 *
3392 * It returns the @nbytges passing in from debugfs user space when successful.
3393 * In case of error conditions, it returns proper error code back to the user
3394 * space.
3395 **/
3396static ssize_t
3397lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3398 size_t nbytes, loff_t *ppos)
3399{
3400 struct lpfc_debug *debug = file->private_data;
3401 uint32_t ext_map;
3402 int rc;
3403
3404 /* This is a user write operation */
3405 debug->op = LPFC_IDIAG_OP_WR;
3406
3407 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3408 if (rc < 0)
3409 return rc;
3410
3411 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3412
3413 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3414 goto error_out;
3415 if (rc != LPFC_EXT_ACC_CMD_ARG)
3416 goto error_out;
3417 if (!(ext_map & LPFC_EXT_ACC_ALL))
3418 goto error_out;
3419
3420 return nbytes;
3421error_out:
3422 /* Clean out command structure on command error out */
3423 memset(&idiag, 0, sizeof(idiag));
3424 return -EINVAL;
3425}
3426
3427/**
3428 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3429 * @file: The file pointer to read from.
3430 * @buf: The buffer to copy the data to.
3431 * @nbytes: The number of bytes to read.
3432 * @ppos: The position in the file to start reading from.
3433 *
3434 * Description:
3435 * This routine reads data from the proper extent information according to
3436 * the idiag command, and copies to user @buf.
3437 *
3438 * Returns:
3439 * This function returns the amount of data that was read (this could be less
3440 * than @nbytes if the end of the file was reached) or a negative error value.
3441 **/
3442static ssize_t
3443lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3444 loff_t *ppos)
3445{
3446 struct lpfc_debug *debug = file->private_data;
3447 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3448 char *pbuffer;
3449 uint32_t ext_map;
3450 int len = 0;
3451
3452 /* This is a user read operation */
3453 debug->op = LPFC_IDIAG_OP_RD;
3454
3455 if (!debug->buffer)
3456 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3457 if (!debug->buffer)
3458 return 0;
3459 pbuffer = debug->buffer;
3460 if (*ppos)
3461 return 0;
3462 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3463 return 0;
3464
3465 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3466 if (ext_map & LPFC_EXT_ACC_AVAIL)
3467 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3468 if (ext_map & LPFC_EXT_ACC_ALLOC)
3469 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3470 if (ext_map & LPFC_EXT_ACC_DRIVR)
3471 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3472
3473 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3474}
3475
James Smart858c9f62007-06-17 19:56:39 -05003476#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003477static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05003478 .owner = THIS_MODULE,
3479 .open = lpfc_debugfs_disc_trc_open,
3480 .llseek = lpfc_debugfs_lseek,
3481 .read = lpfc_debugfs_read,
3482 .release = lpfc_debugfs_release,
3483};
3484
3485#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003486static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05003487 .owner = THIS_MODULE,
3488 .open = lpfc_debugfs_nodelist_open,
3489 .llseek = lpfc_debugfs_lseek,
3490 .read = lpfc_debugfs_read,
3491 .release = lpfc_debugfs_release,
3492};
3493
James Smart78b2d852007-08-02 11:10:21 -04003494#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003495static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04003496 .owner = THIS_MODULE,
3497 .open = lpfc_debugfs_hbqinfo_open,
3498 .llseek = lpfc_debugfs_lseek,
3499 .read = lpfc_debugfs_read,
3500 .release = lpfc_debugfs_release,
3501};
3502
James Smartc95d6c62008-01-11 01:53:23 -05003503#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003504static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04003505 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05003506 .open = lpfc_debugfs_dumpHBASlim_open,
3507 .llseek = lpfc_debugfs_lseek,
3508 .read = lpfc_debugfs_read,
3509 .release = lpfc_debugfs_release,
3510};
3511
3512#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003513static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05003514 .owner = THIS_MODULE,
3515 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04003516 .llseek = lpfc_debugfs_lseek,
3517 .read = lpfc_debugfs_read,
3518 .release = lpfc_debugfs_release,
3519};
3520
James Smarte2a0a9d2008-12-04 22:40:02 -05003521#undef lpfc_debugfs_op_dumpData
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003522static const struct file_operations lpfc_debugfs_op_dumpData = {
James Smarte2a0a9d2008-12-04 22:40:02 -05003523 .owner = THIS_MODULE,
3524 .open = lpfc_debugfs_dumpData_open,
3525 .llseek = lpfc_debugfs_lseek,
3526 .read = lpfc_debugfs_read,
3527 .write = lpfc_debugfs_dumpDataDif_write,
3528 .release = lpfc_debugfs_dumpDataDif_release,
3529};
3530
3531#undef lpfc_debugfs_op_dumpDif
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003532static const struct file_operations lpfc_debugfs_op_dumpDif = {
James Smarte2a0a9d2008-12-04 22:40:02 -05003533 .owner = THIS_MODULE,
3534 .open = lpfc_debugfs_dumpDif_open,
3535 .llseek = lpfc_debugfs_lseek,
3536 .read = lpfc_debugfs_read,
3537 .write = lpfc_debugfs_dumpDataDif_write,
3538 .release = lpfc_debugfs_dumpDataDif_release,
3539};
3540
James Smartf9bb2da2011-10-10 21:34:11 -04003541#undef lpfc_debugfs_op_dif_err
3542static const struct file_operations lpfc_debugfs_op_dif_err = {
3543 .owner = THIS_MODULE,
3544 .open = lpfc_debugfs_dif_err_open,
3545 .llseek = lpfc_debugfs_lseek,
3546 .read = lpfc_debugfs_dif_err_read,
3547 .write = lpfc_debugfs_dif_err_write,
3548 .release = lpfc_debugfs_dif_err_release,
3549};
3550
James Smarta58cbd52007-08-02 11:09:43 -04003551#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003552static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04003553 .owner = THIS_MODULE,
3554 .open = lpfc_debugfs_slow_ring_trc_open,
3555 .llseek = lpfc_debugfs_lseek,
3556 .read = lpfc_debugfs_read,
3557 .release = lpfc_debugfs_release,
3558};
3559
James Smart858c9f62007-06-17 19:56:39 -05003560static struct dentry *lpfc_debugfs_root = NULL;
3561static atomic_t lpfc_debugfs_hba_count;
James Smart2a622bf2011-02-16 12:40:06 -05003562
3563/*
3564 * File operations for the iDiag debugfs
3565 */
3566#undef lpfc_idiag_op_pciCfg
3567static const struct file_operations lpfc_idiag_op_pciCfg = {
3568 .owner = THIS_MODULE,
3569 .open = lpfc_idiag_open,
3570 .llseek = lpfc_debugfs_lseek,
3571 .read = lpfc_idiag_pcicfg_read,
3572 .write = lpfc_idiag_pcicfg_write,
3573 .release = lpfc_idiag_cmd_release,
3574};
3575
James Smartb76f2dc2011-07-22 18:37:42 -04003576#undef lpfc_idiag_op_barAcc
3577static const struct file_operations lpfc_idiag_op_barAcc = {
3578 .owner = THIS_MODULE,
3579 .open = lpfc_idiag_open,
3580 .llseek = lpfc_debugfs_lseek,
3581 .read = lpfc_idiag_baracc_read,
3582 .write = lpfc_idiag_baracc_write,
3583 .release = lpfc_idiag_cmd_release,
3584};
3585
James Smart2a622bf2011-02-16 12:40:06 -05003586#undef lpfc_idiag_op_queInfo
3587static const struct file_operations lpfc_idiag_op_queInfo = {
3588 .owner = THIS_MODULE,
3589 .open = lpfc_idiag_open,
3590 .read = lpfc_idiag_queinfo_read,
3591 .release = lpfc_idiag_release,
3592};
3593
James Smartb76f2dc2011-07-22 18:37:42 -04003594#undef lpfc_idiag_op_queAcc
James Smart86a80842011-04-16 11:03:04 -04003595static const struct file_operations lpfc_idiag_op_queAcc = {
3596 .owner = THIS_MODULE,
3597 .open = lpfc_idiag_open,
3598 .llseek = lpfc_debugfs_lseek,
3599 .read = lpfc_idiag_queacc_read,
3600 .write = lpfc_idiag_queacc_write,
3601 .release = lpfc_idiag_cmd_release,
3602};
3603
James Smartb76f2dc2011-07-22 18:37:42 -04003604#undef lpfc_idiag_op_drbAcc
James Smart86a80842011-04-16 11:03:04 -04003605static const struct file_operations lpfc_idiag_op_drbAcc = {
3606 .owner = THIS_MODULE,
3607 .open = lpfc_idiag_open,
3608 .llseek = lpfc_debugfs_lseek,
3609 .read = lpfc_idiag_drbacc_read,
3610 .write = lpfc_idiag_drbacc_write,
3611 .release = lpfc_idiag_cmd_release,
3612};
3613
James Smartb76f2dc2011-07-22 18:37:42 -04003614#undef lpfc_idiag_op_ctlAcc
3615static const struct file_operations lpfc_idiag_op_ctlAcc = {
3616 .owner = THIS_MODULE,
3617 .open = lpfc_idiag_open,
3618 .llseek = lpfc_debugfs_lseek,
3619 .read = lpfc_idiag_ctlacc_read,
3620 .write = lpfc_idiag_ctlacc_write,
3621 .release = lpfc_idiag_cmd_release,
3622};
3623
3624#undef lpfc_idiag_op_mbxAcc
3625static const struct file_operations lpfc_idiag_op_mbxAcc = {
3626 .owner = THIS_MODULE,
3627 .open = lpfc_idiag_open,
3628 .llseek = lpfc_debugfs_lseek,
3629 .read = lpfc_idiag_mbxacc_read,
3630 .write = lpfc_idiag_mbxacc_write,
3631 .release = lpfc_idiag_cmd_release,
3632};
3633
3634#undef lpfc_idiag_op_extAcc
3635static const struct file_operations lpfc_idiag_op_extAcc = {
3636 .owner = THIS_MODULE,
3637 .open = lpfc_idiag_open,
3638 .llseek = lpfc_debugfs_lseek,
3639 .read = lpfc_idiag_extacc_read,
3640 .write = lpfc_idiag_extacc_write,
3641 .release = lpfc_idiag_cmd_release,
3642};
3643
James Smart858c9f62007-06-17 19:56:39 -05003644#endif
3645
James Smartb76f2dc2011-07-22 18:37:42 -04003646/* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3647 * @phba: Pointer to HBA context object.
3648 * @dmabuf: Pointer to a DMA buffer descriptor.
3649 *
3650 * Description:
3651 * This routine dump a bsg pass-through non-embedded mailbox command with
3652 * external buffer.
3653 **/
3654void
3655lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3656 enum mbox_type mbox_tp, enum dma_type dma_tp,
3657 enum sta_type sta_tp,
3658 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3659{
3660#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3661 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3662 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3663 int len = 0;
3664 uint32_t do_dump = 0;
3665 uint32_t *pword;
3666 uint32_t i;
3667
3668 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3669 return;
3670
3671 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3672 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3673 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3674 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3675
3676 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3677 (*mbx_dump_cnt == 0) ||
3678 (*mbx_word_cnt == 0))
3679 return;
3680
3681 if (*mbx_mbox_cmd != 0x9B)
3682 return;
3683
3684 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3685 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3686 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
3687 printk(KERN_ERR "\nRead mbox command (x%x), "
3688 "nemb:0x%x, extbuf_cnt:%d:\n",
3689 sta_tp, nemb_tp, ext_buf);
3690 }
3691 }
3692 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3693 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3694 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
3695 printk(KERN_ERR "\nRead mbox buffer (x%x), "
3696 "nemb:0x%x, extbuf_seq:%d:\n",
3697 sta_tp, nemb_tp, ext_buf);
3698 }
3699 }
3700 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3701 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3702 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
3703 printk(KERN_ERR "\nWrite mbox command (x%x), "
3704 "nemb:0x%x, extbuf_cnt:%d:\n",
3705 sta_tp, nemb_tp, ext_buf);
3706 }
3707 }
3708 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3709 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3710 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
3711 printk(KERN_ERR "\nWrite mbox buffer (x%x), "
3712 "nemb:0x%x, extbuf_seq:%d:\n",
3713 sta_tp, nemb_tp, ext_buf);
3714 }
3715 }
3716
3717 /* dump buffer content */
3718 if (do_dump) {
3719 pword = (uint32_t *)dmabuf->virt;
3720 for (i = 0; i < *mbx_word_cnt; i++) {
3721 if (!(i % 8)) {
3722 if (i != 0)
3723 printk(KERN_ERR "%s\n", line_buf);
3724 len = 0;
3725 len += snprintf(line_buf+len,
3726 LPFC_MBX_ACC_LBUF_SZ-len,
3727 "%03d: ", i);
3728 }
3729 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3730 "%08x ", (uint32_t)*pword);
3731 pword++;
3732 }
3733 if ((i - 1) % 8)
3734 printk(KERN_ERR "%s\n", line_buf);
3735 (*mbx_dump_cnt)--;
3736 }
3737
3738 /* Clean out command structure on reaching dump count */
3739 if (*mbx_dump_cnt == 0)
3740 memset(&idiag, 0, sizeof(idiag));
3741 return;
3742#endif
3743}
3744
3745/* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3746 * @phba: Pointer to HBA context object.
3747 * @dmabuf: Pointer to a DMA buffer descriptor.
3748 *
3749 * Description:
3750 * This routine dump a pass-through non-embedded mailbox command from issue
3751 * mailbox command.
3752 **/
3753void
3754lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3755{
3756#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3757 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3758 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3759 int len = 0;
3760 uint32_t *pword;
3761 uint8_t *pbyte;
3762 uint32_t i, j;
3763
3764 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3765 return;
3766
3767 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3768 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3769 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3770 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3771
3772 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3773 (*mbx_dump_cnt == 0) ||
3774 (*mbx_word_cnt == 0))
3775 return;
3776
3777 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3778 (*mbx_mbox_cmd != pmbox->mbxCommand))
3779 return;
3780
3781 /* dump buffer content */
3782 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
3783 printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
3784 pmbox->mbxCommand);
3785 pword = (uint32_t *)pmbox;
3786 for (i = 0; i < *mbx_word_cnt; i++) {
3787 if (!(i % 8)) {
3788 if (i != 0)
3789 printk(KERN_ERR "%s\n", line_buf);
3790 len = 0;
3791 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3792 len += snprintf(line_buf+len,
3793 LPFC_MBX_ACC_LBUF_SZ-len,
3794 "%03d: ", i);
3795 }
3796 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3797 "%08x ",
3798 ((uint32_t)*pword) & 0xffffffff);
3799 pword++;
3800 }
3801 if ((i - 1) % 8)
3802 printk(KERN_ERR "%s\n", line_buf);
3803 printk(KERN_ERR "\n");
3804 }
3805 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
3806 printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
3807 pmbox->mbxCommand);
3808 pbyte = (uint8_t *)pmbox;
3809 for (i = 0; i < *mbx_word_cnt; i++) {
3810 if (!(i % 8)) {
3811 if (i != 0)
3812 printk(KERN_ERR "%s\n", line_buf);
3813 len = 0;
3814 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3815 len += snprintf(line_buf+len,
3816 LPFC_MBX_ACC_LBUF_SZ-len,
3817 "%03d: ", i);
3818 }
3819 for (j = 0; j < 4; j++) {
3820 len += snprintf(line_buf+len,
3821 LPFC_MBX_ACC_LBUF_SZ-len,
3822 "%02x",
3823 ((uint8_t)*pbyte) & 0xff);
3824 pbyte++;
3825 }
3826 len += snprintf(line_buf+len,
3827 LPFC_MBX_ACC_LBUF_SZ-len, " ");
3828 }
3829 if ((i - 1) % 8)
3830 printk(KERN_ERR "%s\n", line_buf);
3831 printk(KERN_ERR "\n");
3832 }
3833 (*mbx_dump_cnt)--;
3834
3835 /* Clean out command structure on reaching dump count */
3836 if (*mbx_dump_cnt == 0)
3837 memset(&idiag, 0, sizeof(idiag));
3838 return;
3839#endif
3840}
3841
James Smarte59058c2008-08-24 21:49:00 -04003842/**
James Smart3621a712009-04-06 18:47:14 -04003843 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04003844 * @vport: The vport pointer to initialize.
3845 *
3846 * Description:
3847 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3848 * If not already created, this routine will create the lpfc directory, and
3849 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3850 * also create each file used to access lpfc specific debugfs information.
3851 **/
James Smart858c9f62007-06-17 19:56:39 -05003852inline void
3853lpfc_debugfs_initialize(struct lpfc_vport *vport)
3854{
James Smart923e4b62008-12-04 22:40:07 -05003855#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05003856 struct lpfc_hba *phba = vport->phba;
3857 char name[64];
3858 uint32_t num, i;
3859
3860 if (!lpfc_debugfs_enable)
3861 return;
3862
James Smarta58cbd52007-08-02 11:09:43 -04003863 /* Setup lpfc root directory */
3864 if (!lpfc_debugfs_root) {
3865 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
3866 atomic_set(&lpfc_debugfs_hba_count, 0);
3867 if (!lpfc_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04003868 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003869 "0408 Cannot create debugfs root\n");
James Smarta58cbd52007-08-02 11:09:43 -04003870 goto debug_failed;
3871 }
3872 }
James Smarta58cbd52007-08-02 11:09:43 -04003873 if (!lpfc_debugfs_start_time)
3874 lpfc_debugfs_start_time = jiffies;
3875
James Smart2a622bf2011-02-16 12:40:06 -05003876 /* Setup funcX directory for specific HBA PCI function */
3877 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
James Smarta58cbd52007-08-02 11:09:43 -04003878 if (!phba->hba_debugfs_root) {
3879 phba->hba_debugfs_root =
3880 debugfs_create_dir(name, lpfc_debugfs_root);
3881 if (!phba->hba_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04003882 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003883 "0412 Cannot create debugfs hba\n");
James Smarta58cbd52007-08-02 11:09:43 -04003884 goto debug_failed;
3885 }
3886 atomic_inc(&lpfc_debugfs_hba_count);
3887 atomic_set(&phba->debugfs_vport_count, 0);
3888
James Smart78b2d852007-08-02 11:10:21 -04003889 /* Setup hbqinfo */
3890 snprintf(name, sizeof(name), "hbqinfo");
3891 phba->debug_hbqinfo =
3892 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3893 phba->hba_debugfs_root,
3894 phba, &lpfc_debugfs_op_hbqinfo);
3895 if (!phba->debug_hbqinfo) {
3896 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003897 "0411 Cannot create debugfs hbqinfo\n");
James Smart78b2d852007-08-02 11:10:21 -04003898 goto debug_failed;
3899 }
3900
James Smartc95d6c62008-01-11 01:53:23 -05003901 /* Setup dumpHBASlim */
James Smart2a622bf2011-02-16 12:40:06 -05003902 if (phba->sli_rev < LPFC_SLI_REV4) {
3903 snprintf(name, sizeof(name), "dumpHBASlim");
3904 phba->debug_dumpHBASlim =
3905 debugfs_create_file(name,
3906 S_IFREG|S_IRUGO|S_IWUSR,
3907 phba->hba_debugfs_root,
3908 phba, &lpfc_debugfs_op_dumpHBASlim);
3909 if (!phba->debug_dumpHBASlim) {
3910 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3911 "0413 Cannot create debugfs "
3912 "dumpHBASlim\n");
3913 goto debug_failed;
3914 }
3915 } else
3916 phba->debug_dumpHBASlim = NULL;
James Smartc95d6c62008-01-11 01:53:23 -05003917
3918 /* Setup dumpHostSlim */
James Smart2a622bf2011-02-16 12:40:06 -05003919 if (phba->sli_rev < LPFC_SLI_REV4) {
3920 snprintf(name, sizeof(name), "dumpHostSlim");
3921 phba->debug_dumpHostSlim =
3922 debugfs_create_file(name,
3923 S_IFREG|S_IRUGO|S_IWUSR,
3924 phba->hba_debugfs_root,
3925 phba, &lpfc_debugfs_op_dumpHostSlim);
3926 if (!phba->debug_dumpHostSlim) {
3927 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3928 "0414 Cannot create debugfs "
3929 "dumpHostSlim\n");
3930 goto debug_failed;
3931 }
3932 } else
3933 phba->debug_dumpHBASlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04003934
James Smarte2a0a9d2008-12-04 22:40:02 -05003935 /* Setup dumpData */
3936 snprintf(name, sizeof(name), "dumpData");
3937 phba->debug_dumpData =
3938 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3939 phba->hba_debugfs_root,
3940 phba, &lpfc_debugfs_op_dumpData);
3941 if (!phba->debug_dumpData) {
3942 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3943 "0800 Cannot create debugfs dumpData\n");
3944 goto debug_failed;
3945 }
3946
3947 /* Setup dumpDif */
3948 snprintf(name, sizeof(name), "dumpDif");
3949 phba->debug_dumpDif =
3950 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3951 phba->hba_debugfs_root,
3952 phba, &lpfc_debugfs_op_dumpDif);
3953 if (!phba->debug_dumpDif) {
3954 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3955 "0801 Cannot create debugfs dumpDif\n");
3956 goto debug_failed;
3957 }
3958
James Smartf9bb2da2011-10-10 21:34:11 -04003959 /* Setup DIF Error Injections */
3960 snprintf(name, sizeof(name), "InjErrLBA");
3961 phba->debug_InjErrLBA =
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_InjErrLBA) {
3966 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3967 "0807 Cannot create debugfs InjErrLBA\n");
3968 goto debug_failed;
3969 }
3970 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
3971
James Smart4ac9b222012-03-01 22:38:29 -05003972 snprintf(name, sizeof(name), "InjErrNPortID");
3973 phba->debug_InjErrNPortID =
3974 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3975 phba->hba_debugfs_root,
3976 phba, &lpfc_debugfs_op_dif_err);
3977 if (!phba->debug_InjErrNPortID) {
3978 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3979 "0809 Cannot create debugfs InjErrNPortID\n");
3980 goto debug_failed;
3981 }
3982
3983 snprintf(name, sizeof(name), "InjErrWWPN");
3984 phba->debug_InjErrWWPN =
3985 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3986 phba->hba_debugfs_root,
3987 phba, &lpfc_debugfs_op_dif_err);
3988 if (!phba->debug_InjErrWWPN) {
3989 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3990 "0810 Cannot create debugfs InjErrWWPN\n");
3991 goto debug_failed;
3992 }
3993
James Smartf9bb2da2011-10-10 21:34:11 -04003994 snprintf(name, sizeof(name), "writeGuardInjErr");
3995 phba->debug_writeGuard =
3996 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3997 phba->hba_debugfs_root,
3998 phba, &lpfc_debugfs_op_dif_err);
3999 if (!phba->debug_writeGuard) {
4000 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4001 "0802 Cannot create debugfs writeGuard\n");
4002 goto debug_failed;
4003 }
4004
4005 snprintf(name, sizeof(name), "writeAppInjErr");
4006 phba->debug_writeApp =
4007 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4008 phba->hba_debugfs_root,
4009 phba, &lpfc_debugfs_op_dif_err);
4010 if (!phba->debug_writeApp) {
4011 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4012 "0803 Cannot create debugfs writeApp\n");
4013 goto debug_failed;
4014 }
4015
4016 snprintf(name, sizeof(name), "writeRefInjErr");
4017 phba->debug_writeRef =
4018 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4019 phba->hba_debugfs_root,
4020 phba, &lpfc_debugfs_op_dif_err);
4021 if (!phba->debug_writeRef) {
4022 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4023 "0804 Cannot create debugfs writeRef\n");
4024 goto debug_failed;
4025 }
4026
James Smartacd68592012-01-18 16:25:09 -05004027 snprintf(name, sizeof(name), "readGuardInjErr");
4028 phba->debug_readGuard =
4029 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4030 phba->hba_debugfs_root,
4031 phba, &lpfc_debugfs_op_dif_err);
4032 if (!phba->debug_readGuard) {
4033 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4034 "0808 Cannot create debugfs readGuard\n");
4035 goto debug_failed;
4036 }
4037
James Smartf9bb2da2011-10-10 21:34:11 -04004038 snprintf(name, sizeof(name), "readAppInjErr");
4039 phba->debug_readApp =
4040 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4041 phba->hba_debugfs_root,
4042 phba, &lpfc_debugfs_op_dif_err);
4043 if (!phba->debug_readApp) {
4044 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4045 "0805 Cannot create debugfs readApp\n");
4046 goto debug_failed;
4047 }
4048
4049 snprintf(name, sizeof(name), "readRefInjErr");
4050 phba->debug_readRef =
4051 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4052 phba->hba_debugfs_root,
4053 phba, &lpfc_debugfs_op_dif_err);
4054 if (!phba->debug_readRef) {
4055 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4056 "0806 Cannot create debugfs readApp\n");
4057 goto debug_failed;
4058 }
4059
James Smarta58cbd52007-08-02 11:09:43 -04004060 /* Setup slow ring trace */
4061 if (lpfc_debugfs_max_slow_ring_trc) {
4062 num = lpfc_debugfs_max_slow_ring_trc - 1;
4063 if (num & lpfc_debugfs_max_slow_ring_trc) {
4064 /* Change to be a power of 2 */
4065 num = lpfc_debugfs_max_slow_ring_trc;
4066 i = 0;
4067 while (num > 1) {
4068 num = num >> 1;
4069 i++;
4070 }
4071 lpfc_debugfs_max_slow_ring_trc = (1 << i);
4072 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04004073 "lpfc_debugfs_max_disc_trc changed to "
4074 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04004075 }
4076 }
4077
James Smarta58cbd52007-08-02 11:09:43 -04004078 snprintf(name, sizeof(name), "slow_ring_trace");
4079 phba->debug_slow_ring_trc =
4080 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4081 phba->hba_debugfs_root,
4082 phba, &lpfc_debugfs_op_slow_ring_trc);
4083 if (!phba->debug_slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004084 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004085 "0415 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004086 "slow_ring_trace\n");
James Smarta58cbd52007-08-02 11:09:43 -04004087 goto debug_failed;
4088 }
4089 if (!phba->slow_ring_trc) {
4090 phba->slow_ring_trc = kmalloc(
4091 (sizeof(struct lpfc_debugfs_trc) *
4092 lpfc_debugfs_max_slow_ring_trc),
4093 GFP_KERNEL);
4094 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004095 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004096 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004097 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04004098 goto debug_failed;
4099 }
4100 atomic_set(&phba->slow_ring_trc_cnt, 0);
4101 memset(phba->slow_ring_trc, 0,
4102 (sizeof(struct lpfc_debugfs_trc) *
4103 lpfc_debugfs_max_slow_ring_trc));
4104 }
4105 }
4106
4107 snprintf(name, sizeof(name), "vport%d", vport->vpi);
4108 if (!vport->vport_debugfs_root) {
4109 vport->vport_debugfs_root =
4110 debugfs_create_dir(name, phba->hba_debugfs_root);
4111 if (!vport->vport_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04004112 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004113 "0417 Can't create debugfs\n");
James Smarta58cbd52007-08-02 11:09:43 -04004114 goto debug_failed;
4115 }
4116 atomic_inc(&phba->debugfs_vport_count);
4117 }
4118
James Smart858c9f62007-06-17 19:56:39 -05004119 if (lpfc_debugfs_max_disc_trc) {
4120 num = lpfc_debugfs_max_disc_trc - 1;
4121 if (num & lpfc_debugfs_max_disc_trc) {
4122 /* Change to be a power of 2 */
4123 num = lpfc_debugfs_max_disc_trc;
4124 i = 0;
4125 while (num > 1) {
4126 num = num >> 1;
4127 i++;
4128 }
4129 lpfc_debugfs_max_disc_trc = (1 << i);
4130 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04004131 "lpfc_debugfs_max_disc_trc changed to %d\n",
4132 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05004133 }
4134 }
4135
Adrian Bunkff86ba52007-10-18 12:52:37 +02004136 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04004137 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05004138 GFP_KERNEL);
4139
James Smarta58cbd52007-08-02 11:09:43 -04004140 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004141 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004142 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04004143 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05004144 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04004145 }
4146 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05004147
4148 snprintf(name, sizeof(name), "discovery_trace");
4149 vport->debug_disc_trc =
4150 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4151 vport->vport_debugfs_root,
4152 vport, &lpfc_debugfs_op_disc_trc);
4153 if (!vport->debug_disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004154 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004155 "0419 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004156 "discovery_trace\n");
James Smart858c9f62007-06-17 19:56:39 -05004157 goto debug_failed;
4158 }
4159 snprintf(name, sizeof(name), "nodelist");
4160 vport->debug_nodelist =
4161 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4162 vport->vport_debugfs_root,
4163 vport, &lpfc_debugfs_op_nodelist);
4164 if (!vport->debug_nodelist) {
James Smarte8b62012007-08-02 11:10:09 -04004165 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartb76f2dc2011-07-22 18:37:42 -04004166 "2985 Can't create debugfs nodelist\n");
James Smart858c9f62007-06-17 19:56:39 -05004167 goto debug_failed;
4168 }
James Smart2a622bf2011-02-16 12:40:06 -05004169
4170 /*
4171 * iDiag debugfs root entry points for SLI4 device only
4172 */
4173 if (phba->sli_rev < LPFC_SLI_REV4)
4174 goto debug_failed;
4175
4176 snprintf(name, sizeof(name), "iDiag");
4177 if (!phba->idiag_root) {
4178 phba->idiag_root =
4179 debugfs_create_dir(name, phba->hba_debugfs_root);
4180 if (!phba->idiag_root) {
4181 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4182 "2922 Can't create idiag debugfs\n");
4183 goto debug_failed;
4184 }
4185 /* Initialize iDiag data structure */
4186 memset(&idiag, 0, sizeof(idiag));
4187 }
4188
4189 /* iDiag read PCI config space */
4190 snprintf(name, sizeof(name), "pciCfg");
4191 if (!phba->idiag_pci_cfg) {
4192 phba->idiag_pci_cfg =
4193 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4194 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
4195 if (!phba->idiag_pci_cfg) {
4196 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4197 "2923 Can't create idiag debugfs\n");
4198 goto debug_failed;
4199 }
4200 idiag.offset.last_rd = 0;
4201 }
4202
James Smartb76f2dc2011-07-22 18:37:42 -04004203 /* iDiag PCI BAR access */
4204 snprintf(name, sizeof(name), "barAcc");
4205 if (!phba->idiag_bar_acc) {
4206 phba->idiag_bar_acc =
4207 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4208 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
4209 if (!phba->idiag_bar_acc) {
4210 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4211 "3056 Can't create idiag debugfs\n");
4212 goto debug_failed;
4213 }
4214 idiag.offset.last_rd = 0;
4215 }
4216
James Smart2a622bf2011-02-16 12:40:06 -05004217 /* iDiag get PCI function queue information */
4218 snprintf(name, sizeof(name), "queInfo");
4219 if (!phba->idiag_que_info) {
4220 phba->idiag_que_info =
4221 debugfs_create_file(name, S_IFREG|S_IRUGO,
4222 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
4223 if (!phba->idiag_que_info) {
4224 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4225 "2924 Can't create idiag debugfs\n");
4226 goto debug_failed;
4227 }
4228 }
4229
James Smart86a80842011-04-16 11:03:04 -04004230 /* iDiag access PCI function queue */
4231 snprintf(name, sizeof(name), "queAcc");
4232 if (!phba->idiag_que_acc) {
4233 phba->idiag_que_acc =
4234 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4235 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
4236 if (!phba->idiag_que_acc) {
4237 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4238 "2926 Can't create idiag debugfs\n");
4239 goto debug_failed;
4240 }
4241 }
4242
4243 /* iDiag access PCI function doorbell registers */
4244 snprintf(name, sizeof(name), "drbAcc");
4245 if (!phba->idiag_drb_acc) {
4246 phba->idiag_drb_acc =
4247 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4248 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
4249 if (!phba->idiag_drb_acc) {
4250 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4251 "2927 Can't create idiag debugfs\n");
4252 goto debug_failed;
4253 }
4254 }
4255
James Smartb76f2dc2011-07-22 18:37:42 -04004256 /* iDiag access PCI function control registers */
4257 snprintf(name, sizeof(name), "ctlAcc");
4258 if (!phba->idiag_ctl_acc) {
4259 phba->idiag_ctl_acc =
4260 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4261 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
4262 if (!phba->idiag_ctl_acc) {
4263 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4264 "2981 Can't create idiag debugfs\n");
4265 goto debug_failed;
4266 }
4267 }
4268
4269 /* iDiag access mbox commands */
4270 snprintf(name, sizeof(name), "mbxAcc");
4271 if (!phba->idiag_mbx_acc) {
4272 phba->idiag_mbx_acc =
4273 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4274 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
4275 if (!phba->idiag_mbx_acc) {
4276 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4277 "2980 Can't create idiag debugfs\n");
4278 goto debug_failed;
4279 }
4280 }
4281
4282 /* iDiag extents access commands */
4283 if (phba->sli4_hba.extents_in_use) {
4284 snprintf(name, sizeof(name), "extAcc");
4285 if (!phba->idiag_ext_acc) {
4286 phba->idiag_ext_acc =
4287 debugfs_create_file(name,
4288 S_IFREG|S_IRUGO|S_IWUSR,
4289 phba->idiag_root, phba,
4290 &lpfc_idiag_op_extAcc);
4291 if (!phba->idiag_ext_acc) {
4292 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4293 "2986 Cant create "
4294 "idiag debugfs\n");
4295 goto debug_failed;
4296 }
4297 }
4298 }
4299
James Smart858c9f62007-06-17 19:56:39 -05004300debug_failed:
4301 return;
4302#endif
4303}
4304
James Smarte59058c2008-08-24 21:49:00 -04004305/**
James Smart3621a712009-04-06 18:47:14 -04004306 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04004307 * @vport: The vport pointer to remove from debugfs.
4308 *
4309 * Description:
4310 * When Debugfs is configured this routine removes debugfs file system elements
4311 * that are specific to this vport. It also checks to see if there are any
4312 * users left for the debugfs directories associated with the HBA and driver. If
4313 * this is the last user of the HBA directory or driver directory then it will
4314 * remove those from the debugfs infrastructure as well.
4315 **/
James Smart858c9f62007-06-17 19:56:39 -05004316inline void
4317lpfc_debugfs_terminate(struct lpfc_vport *vport)
4318{
James Smart923e4b62008-12-04 22:40:07 -05004319#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05004320 struct lpfc_hba *phba = vport->phba;
4321
4322 if (vport->disc_trc) {
4323 kfree(vport->disc_trc);
4324 vport->disc_trc = NULL;
4325 }
4326 if (vport->debug_disc_trc) {
4327 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
4328 vport->debug_disc_trc = NULL;
4329 }
4330 if (vport->debug_nodelist) {
4331 debugfs_remove(vport->debug_nodelist); /* nodelist */
4332 vport->debug_nodelist = NULL;
4333 }
4334 if (vport->vport_debugfs_root) {
4335 debugfs_remove(vport->vport_debugfs_root); /* vportX */
4336 vport->vport_debugfs_root = NULL;
4337 atomic_dec(&phba->debugfs_vport_count);
4338 }
4339 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04004340
James Smart78b2d852007-08-02 11:10:21 -04004341 if (phba->debug_hbqinfo) {
4342 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
4343 phba->debug_hbqinfo = NULL;
4344 }
James Smartc95d6c62008-01-11 01:53:23 -05004345 if (phba->debug_dumpHBASlim) {
4346 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
4347 phba->debug_dumpHBASlim = NULL;
4348 }
4349 if (phba->debug_dumpHostSlim) {
4350 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
4351 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04004352 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004353 if (phba->debug_dumpData) {
4354 debugfs_remove(phba->debug_dumpData); /* dumpData */
4355 phba->debug_dumpData = NULL;
4356 }
4357
4358 if (phba->debug_dumpDif) {
4359 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
4360 phba->debug_dumpDif = NULL;
4361 }
James Smartf9bb2da2011-10-10 21:34:11 -04004362 if (phba->debug_InjErrLBA) {
4363 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
4364 phba->debug_InjErrLBA = NULL;
4365 }
James Smart4ac9b222012-03-01 22:38:29 -05004366 if (phba->debug_InjErrNPortID) { /* InjErrNPortID */
4367 debugfs_remove(phba->debug_InjErrNPortID);
4368 phba->debug_InjErrNPortID = NULL;
4369 }
4370 if (phba->debug_InjErrWWPN) {
4371 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
4372 phba->debug_InjErrWWPN = NULL;
4373 }
James Smartf9bb2da2011-10-10 21:34:11 -04004374 if (phba->debug_writeGuard) {
4375 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
4376 phba->debug_writeGuard = NULL;
4377 }
4378 if (phba->debug_writeApp) {
4379 debugfs_remove(phba->debug_writeApp); /* writeApp */
4380 phba->debug_writeApp = NULL;
4381 }
4382 if (phba->debug_writeRef) {
4383 debugfs_remove(phba->debug_writeRef); /* writeRef */
4384 phba->debug_writeRef = NULL;
4385 }
James Smartacd68592012-01-18 16:25:09 -05004386 if (phba->debug_readGuard) {
4387 debugfs_remove(phba->debug_readGuard); /* readGuard */
4388 phba->debug_readGuard = NULL;
4389 }
James Smartf9bb2da2011-10-10 21:34:11 -04004390 if (phba->debug_readApp) {
4391 debugfs_remove(phba->debug_readApp); /* readApp */
4392 phba->debug_readApp = NULL;
4393 }
4394 if (phba->debug_readRef) {
4395 debugfs_remove(phba->debug_readRef); /* readRef */
4396 phba->debug_readRef = NULL;
4397 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004398
James Smarta58cbd52007-08-02 11:09:43 -04004399 if (phba->slow_ring_trc) {
4400 kfree(phba->slow_ring_trc);
4401 phba->slow_ring_trc = NULL;
4402 }
4403 if (phba->debug_slow_ring_trc) {
4404 /* slow_ring_trace */
4405 debugfs_remove(phba->debug_slow_ring_trc);
4406 phba->debug_slow_ring_trc = NULL;
4407 }
4408
James Smart2a622bf2011-02-16 12:40:06 -05004409 /*
4410 * iDiag release
4411 */
4412 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartb76f2dc2011-07-22 18:37:42 -04004413 if (phba->idiag_ext_acc) {
4414 /* iDiag extAcc */
4415 debugfs_remove(phba->idiag_ext_acc);
4416 phba->idiag_ext_acc = NULL;
4417 }
4418 if (phba->idiag_mbx_acc) {
4419 /* iDiag mbxAcc */
4420 debugfs_remove(phba->idiag_mbx_acc);
4421 phba->idiag_mbx_acc = NULL;
4422 }
4423 if (phba->idiag_ctl_acc) {
4424 /* iDiag ctlAcc */
4425 debugfs_remove(phba->idiag_ctl_acc);
4426 phba->idiag_ctl_acc = NULL;
4427 }
James Smart86a80842011-04-16 11:03:04 -04004428 if (phba->idiag_drb_acc) {
4429 /* iDiag drbAcc */
4430 debugfs_remove(phba->idiag_drb_acc);
4431 phba->idiag_drb_acc = NULL;
4432 }
4433 if (phba->idiag_que_acc) {
4434 /* iDiag queAcc */
4435 debugfs_remove(phba->idiag_que_acc);
4436 phba->idiag_que_acc = NULL;
4437 }
James Smart2a622bf2011-02-16 12:40:06 -05004438 if (phba->idiag_que_info) {
4439 /* iDiag queInfo */
4440 debugfs_remove(phba->idiag_que_info);
4441 phba->idiag_que_info = NULL;
4442 }
James Smartb76f2dc2011-07-22 18:37:42 -04004443 if (phba->idiag_bar_acc) {
4444 /* iDiag barAcc */
4445 debugfs_remove(phba->idiag_bar_acc);
4446 phba->idiag_bar_acc = NULL;
4447 }
James Smart2a622bf2011-02-16 12:40:06 -05004448 if (phba->idiag_pci_cfg) {
4449 /* iDiag pciCfg */
4450 debugfs_remove(phba->idiag_pci_cfg);
4451 phba->idiag_pci_cfg = NULL;
4452 }
4453
4454 /* Finally remove the iDiag debugfs root */
4455 if (phba->idiag_root) {
4456 /* iDiag root */
4457 debugfs_remove(phba->idiag_root);
4458 phba->idiag_root = NULL;
4459 }
4460 }
4461
James Smarta58cbd52007-08-02 11:09:43 -04004462 if (phba->hba_debugfs_root) {
James Smart2a622bf2011-02-16 12:40:06 -05004463 debugfs_remove(phba->hba_debugfs_root); /* fnX */
James Smarta58cbd52007-08-02 11:09:43 -04004464 phba->hba_debugfs_root = NULL;
4465 atomic_dec(&lpfc_debugfs_hba_count);
4466 }
4467
James Smart858c9f62007-06-17 19:56:39 -05004468 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
4469 debugfs_remove(lpfc_debugfs_root); /* lpfc */
4470 lpfc_debugfs_root = NULL;
4471 }
4472 }
4473#endif
James Smarta58cbd52007-08-02 11:09:43 -04004474 return;
James Smart858c9f62007-06-17 19:56:39 -05004475}