blob: 5eac0942f13dcd196dee09a1429556d7ea7cb94e [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",
James Smart7e56aa22012-08-03 12:35:34 -0400493 i, pgpp->cmdGetInx, pring->sli.sli3.numCiocb,
494 pring->sli.sli3.next_cmdidx,
495 pring->sli.sli3.local_getidx,
496 pring->flag, pgpp->rspPutInx,
497 pring->sli.sli3.numRiocb);
James Smart34b02dc2008-08-24 21:49:55 -0400498 }
James Smart3772a992009-05-22 14:50:54 -0400499
500 if (phba->sli_rev <= LPFC_SLI_REV3) {
501 word0 = readl(phba->HAregaddr);
502 word1 = readl(phba->CAregaddr);
503 word2 = readl(phba->HSregaddr);
504 word3 = readl(phba->HCregaddr);
505 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
506 "HC:%08x\n", word0, word1, word2, word3);
507 }
James Smarta58cbd52007-08-02 11:09:43 -0400508 spin_unlock_irq(&phba->hbalock);
509 return len;
510}
511
James Smarte59058c2008-08-24 21:49:00 -0400512/**
James Smart3621a712009-04-06 18:47:14 -0400513 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400514 * @vport: The vport to gather target node info from.
515 * @buf: The buffer to dump log into.
516 * @size: The maximum amount of data to process.
517 *
518 * Description:
519 * This routine dumps the current target node list associated with @vport to
520 * @buf up to @size bytes of data. Each node entry in the dump will contain a
521 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
522 *
523 * Return Value:
524 * This routine returns the amount of bytes that were dumped into @buf and will
525 * not exceed @size.
526 **/
James Smarta58cbd52007-08-02 11:09:43 -0400527static int
James Smart858c9f62007-06-17 19:56:39 -0500528lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
529{
530 int len = 0;
531 int cnt;
532 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
533 struct lpfc_nodelist *ndlp;
534 unsigned char *statep, *name;
535
536 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
537
538 spin_lock_irq(shost->host_lock);
539 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
540 if (!cnt) {
541 len += snprintf(buf+len, size-len,
542 "Missing Nodelist Entries\n");
543 break;
544 }
545 cnt--;
546 switch (ndlp->nlp_state) {
547 case NLP_STE_UNUSED_NODE:
548 statep = "UNUSED";
549 break;
550 case NLP_STE_PLOGI_ISSUE:
551 statep = "PLOGI ";
552 break;
553 case NLP_STE_ADISC_ISSUE:
554 statep = "ADISC ";
555 break;
556 case NLP_STE_REG_LOGIN_ISSUE:
557 statep = "REGLOG";
558 break;
559 case NLP_STE_PRLI_ISSUE:
560 statep = "PRLI ";
561 break;
562 case NLP_STE_UNMAPPED_NODE:
563 statep = "UNMAP ";
564 break;
565 case NLP_STE_MAPPED_NODE:
566 statep = "MAPPED";
567 break;
568 case NLP_STE_NPR_NODE:
569 statep = "NPR ";
570 break;
571 default:
572 statep = "UNKNOWN";
573 }
574 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
575 statep, ndlp->nlp_DID);
576 name = (unsigned char *)&ndlp->nlp_portname;
577 len += snprintf(buf+len, size-len,
578 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
579 *name, *(name+1), *(name+2), *(name+3),
580 *(name+4), *(name+5), *(name+6), *(name+7));
581 name = (unsigned char *)&ndlp->nlp_nodename;
582 len += snprintf(buf+len, size-len,
583 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
584 *name, *(name+1), *(name+2), *(name+3),
585 *(name+4), *(name+5), *(name+6), *(name+7));
586 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
587 ndlp->nlp_rpi, ndlp->nlp_flag);
588 if (!ndlp->nlp_type)
James Smarta58cbd52007-08-02 11:09:43 -0400589 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500590 if (ndlp->nlp_type & NLP_FC_NODE)
591 len += snprintf(buf+len, size-len, "FC_NODE ");
592 if (ndlp->nlp_type & NLP_FABRIC)
593 len += snprintf(buf+len, size-len, "FABRIC ");
594 if (ndlp->nlp_type & NLP_FCP_TARGET)
595 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
596 ndlp->nlp_sid);
597 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
James Smarta58cbd52007-08-02 11:09:43 -0400598 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart58da1ff2008-04-07 10:15:56 -0400599 len += snprintf(buf+len, size-len, "usgmap:%x ",
600 ndlp->nlp_usg_map);
James Smarta58cbd52007-08-02 11:09:43 -0400601 len += snprintf(buf+len, size-len, "refcnt:%x",
602 atomic_read(&ndlp->kref.refcount));
James Smart858c9f62007-06-17 19:56:39 -0500603 len += snprintf(buf+len, size-len, "\n");
604 }
605 spin_unlock_irq(shost->host_lock);
606 return len;
607}
608#endif
609
James Smarte59058c2008-08-24 21:49:00 -0400610/**
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400612 * @vport: The vport to associate this trace string with for retrieval.
613 * @mask: Log entry classification.
614 * @fmt: Format string to be displayed when dumping the log.
615 * @data1: 1st data parameter to be applied to @fmt.
616 * @data2: 2nd data parameter to be applied to @fmt.
617 * @data3: 3rd data parameter to be applied to @fmt.
618 *
619 * Description:
620 * This routine is used by the driver code to add a debugfs log entry to the
621 * discovery trace buffer associated with @vport. Only entries with a @mask that
622 * match the current debugfs discovery mask will be saved. Entries that do not
623 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
624 * printf when displaying the log.
625 **/
James Smart858c9f62007-06-17 19:56:39 -0500626inline void
627lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
628 uint32_t data1, uint32_t data2, uint32_t data3)
629{
James Smart923e4b62008-12-04 22:40:07 -0500630#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400631 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -0500632 int index;
633
634 if (!(lpfc_debugfs_mask_disc_trc & mask))
635 return;
636
637 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
638 !vport || !vport->disc_trc)
639 return;
640
641 index = atomic_inc_return(&vport->disc_trc_cnt) &
642 (lpfc_debugfs_max_disc_trc - 1);
643 dtp = vport->disc_trc + index;
644 dtp->fmt = fmt;
645 dtp->data1 = data1;
646 dtp->data2 = data2;
647 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -0400648 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
649 dtp->jif = jiffies;
650#endif
651 return;
652}
653
James Smarte59058c2008-08-24 21:49:00 -0400654/**
James Smart3621a712009-04-06 18:47:14 -0400655 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400656 * @phba: The phba to associate this trace string with for retrieval.
657 * @fmt: Format string to be displayed when dumping the log.
658 * @data1: 1st data parameter to be applied to @fmt.
659 * @data2: 2nd data parameter to be applied to @fmt.
660 * @data3: 3rd data parameter to be applied to @fmt.
661 *
662 * Description:
663 * This routine is used by the driver code to add a debugfs log entry to the
664 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
665 * @data3 are used like printf when displaying the log.
666 **/
James Smarta58cbd52007-08-02 11:09:43 -0400667inline void
668lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
669 uint32_t data1, uint32_t data2, uint32_t data3)
670{
James Smart923e4b62008-12-04 22:40:07 -0500671#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400672 struct lpfc_debugfs_trc *dtp;
673 int index;
674
675 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
676 !phba || !phba->slow_ring_trc)
677 return;
678
679 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
680 (lpfc_debugfs_max_slow_ring_trc - 1);
681 dtp = phba->slow_ring_trc + index;
682 dtp->fmt = fmt;
683 dtp->data1 = data1;
684 dtp->data2 = data2;
685 dtp->data3 = data3;
686 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500687 dtp->jif = jiffies;
688#endif
689 return;
690}
691
James Smart923e4b62008-12-04 22:40:07 -0500692#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -0400693/**
James Smart3621a712009-04-06 18:47:14 -0400694 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400695 * @inode: The inode pointer that contains a vport pointer.
696 * @file: The file pointer to attach the log output.
697 *
698 * Description:
699 * This routine is the entry point for the debugfs open file operation. It gets
700 * the vport from the i_private field in @inode, allocates the necessary buffer
701 * for the log, fills the buffer from the in-memory log for this vport, and then
702 * returns a pointer to that log in the private_data field in @file.
703 *
704 * Returns:
705 * This function returns zero if successful. On error it will return an negative
706 * error value.
707 **/
James Smart858c9f62007-06-17 19:56:39 -0500708static int
709lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
710{
711 struct lpfc_vport *vport = inode->i_private;
712 struct lpfc_debug *debug;
713 int size;
714 int rc = -ENOMEM;
715
716 if (!lpfc_debugfs_max_disc_trc) {
717 rc = -ENOSPC;
718 goto out;
719 }
720
721 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
722 if (!debug)
723 goto out;
724
James Smarte59058c2008-08-24 21:49:00 -0400725 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400726 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -0500727 size = PAGE_ALIGN(size);
728
729 debug->buffer = kmalloc(size, GFP_KERNEL);
730 if (!debug->buffer) {
731 kfree(debug);
732 goto out;
733 }
734
735 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
736 file->private_data = debug;
737
738 rc = 0;
739out:
740 return rc;
741}
742
James Smarte59058c2008-08-24 21:49:00 -0400743/**
James Smart3621a712009-04-06 18:47:14 -0400744 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400745 * @inode: The inode pointer that contains a vport pointer.
746 * @file: The file pointer to attach the log output.
747 *
748 * Description:
749 * This routine is the entry point for the debugfs open file operation. It gets
750 * the vport from the i_private field in @inode, allocates the necessary buffer
751 * for the log, fills the buffer from the in-memory log for this vport, and then
752 * returns a pointer to that log in the private_data field in @file.
753 *
754 * Returns:
755 * This function returns zero if successful. On error it will return an negative
756 * error value.
757 **/
James Smart858c9f62007-06-17 19:56:39 -0500758static int
James Smarta58cbd52007-08-02 11:09:43 -0400759lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
760{
761 struct lpfc_hba *phba = inode->i_private;
762 struct lpfc_debug *debug;
763 int size;
764 int rc = -ENOMEM;
765
766 if (!lpfc_debugfs_max_slow_ring_trc) {
767 rc = -ENOSPC;
768 goto out;
769 }
770
771 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
772 if (!debug)
773 goto out;
774
James Smarte59058c2008-08-24 21:49:00 -0400775 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400776 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
777 size = PAGE_ALIGN(size);
778
779 debug->buffer = kmalloc(size, GFP_KERNEL);
780 if (!debug->buffer) {
781 kfree(debug);
782 goto out;
783 }
784
785 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
786 file->private_data = debug;
787
788 rc = 0;
789out:
790 return rc;
791}
792
James Smarte59058c2008-08-24 21:49:00 -0400793/**
James Smart3621a712009-04-06 18:47:14 -0400794 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400795 * @inode: The inode pointer that contains a vport pointer.
796 * @file: The file pointer to attach the log output.
797 *
798 * Description:
799 * This routine is the entry point for the debugfs open file operation. It gets
800 * the vport from the i_private field in @inode, allocates the necessary buffer
801 * for the log, fills the buffer from the in-memory log for this vport, and then
802 * returns a pointer to that log in the private_data field in @file.
803 *
804 * Returns:
805 * This function returns zero if successful. On error it will return an negative
806 * error value.
807 **/
James Smarta58cbd52007-08-02 11:09:43 -0400808static int
James Smart78b2d852007-08-02 11:10:21 -0400809lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
810{
811 struct lpfc_hba *phba = inode->i_private;
812 struct lpfc_debug *debug;
813 int rc = -ENOMEM;
814
815 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
816 if (!debug)
817 goto out;
818
James Smarte59058c2008-08-24 21:49:00 -0400819 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -0400820 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
821 if (!debug->buffer) {
822 kfree(debug);
823 goto out;
824 }
825
826 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
827 LPFC_HBQINFO_SIZE);
828 file->private_data = debug;
829
830 rc = 0;
831out:
832 return rc;
833}
834
James Smarte59058c2008-08-24 21:49:00 -0400835/**
James Smart3621a712009-04-06 18:47:14 -0400836 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400837 * @inode: The inode pointer that contains a vport pointer.
838 * @file: The file pointer to attach the log output.
839 *
840 * Description:
841 * This routine is the entry point for the debugfs open file operation. It gets
842 * the vport from the i_private field in @inode, allocates the necessary buffer
843 * for the log, fills the buffer from the in-memory log for this vport, and then
844 * returns a pointer to that log in the private_data field in @file.
845 *
846 * Returns:
847 * This function returns zero if successful. On error it will return an negative
848 * error value.
849 **/
James Smart78b2d852007-08-02 11:10:21 -0400850static int
James Smartc95d6c62008-01-11 01:53:23 -0500851lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -0400852{
853 struct lpfc_hba *phba = inode->i_private;
854 struct lpfc_debug *debug;
855 int rc = -ENOMEM;
856
857 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
858 if (!debug)
859 goto out;
860
James Smarte59058c2008-08-24 21:49:00 -0400861 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500862 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -0400863 if (!debug->buffer) {
864 kfree(debug);
865 goto out;
866 }
867
James Smartc95d6c62008-01-11 01:53:23 -0500868 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
869 LPFC_DUMPHBASLIM_SIZE);
870 file->private_data = debug;
871
872 rc = 0;
873out:
874 return rc;
875}
876
James Smarte59058c2008-08-24 21:49:00 -0400877/**
James Smart3621a712009-04-06 18:47:14 -0400878 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400879 * @inode: The inode pointer that contains a vport pointer.
880 * @file: The file pointer to attach the log output.
881 *
882 * Description:
883 * This routine is the entry point for the debugfs open file operation. It gets
884 * the vport from the i_private field in @inode, allocates the necessary buffer
885 * for the log, fills the buffer from the in-memory log for this vport, and then
886 * returns a pointer to that log in the private_data field in @file.
887 *
888 * Returns:
889 * This function returns zero if successful. On error it will return an negative
890 * error value.
891 **/
James Smartc95d6c62008-01-11 01:53:23 -0500892static int
893lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
894{
895 struct lpfc_hba *phba = inode->i_private;
896 struct lpfc_debug *debug;
897 int rc = -ENOMEM;
898
899 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
900 if (!debug)
901 goto out;
902
James Smarte59058c2008-08-24 21:49:00 -0400903 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500904 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
905 if (!debug->buffer) {
906 kfree(debug);
907 goto out;
908 }
909
910 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
911 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -0400912 file->private_data = debug;
913
914 rc = 0;
915out:
916 return rc;
917}
918
James Smarte2a0a9d2008-12-04 22:40:02 -0500919static int
920lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
921{
922 struct lpfc_debug *debug;
923 int rc = -ENOMEM;
924
925 if (!_dump_buf_data)
926 return -EBUSY;
927
928 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
929 if (!debug)
930 goto out;
931
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300932 /* Round to page boundary */
James Smart6a9c52c2009-10-02 15:16:51 -0400933 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
James Smarte2a0a9d2008-12-04 22:40:02 -0500934 __func__, _dump_buf_data);
935 debug->buffer = _dump_buf_data;
936 if (!debug->buffer) {
937 kfree(debug);
938 goto out;
939 }
940
941 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
942 file->private_data = debug;
943
944 rc = 0;
945out:
946 return rc;
947}
948
949static int
950lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
951{
952 struct lpfc_debug *debug;
953 int rc = -ENOMEM;
954
955 if (!_dump_buf_dif)
956 return -EBUSY;
957
958 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
959 if (!debug)
960 goto out;
961
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300962 /* Round to page boundary */
James Smart6a9c52c2009-10-02 15:16:51 -0400963 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
964 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
James Smarte2a0a9d2008-12-04 22:40:02 -0500965 debug->buffer = _dump_buf_dif;
966 if (!debug->buffer) {
967 kfree(debug);
968 goto out;
969 }
970
971 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
972 file->private_data = debug;
973
974 rc = 0;
975out:
976 return rc;
977}
978
979static ssize_t
980lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
981 size_t nbytes, loff_t *ppos)
982{
983 /*
984 * The Data/DIF buffers only save one failing IO
985 * The write op is used as a reset mechanism after an IO has
986 * already been saved to the next one can be saved
987 */
988 spin_lock(&_dump_buf_lock);
989
990 memset((void *)_dump_buf_data, 0,
991 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
992 memset((void *)_dump_buf_dif, 0,
993 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
994
995 _dump_buf_done = 0;
996
997 spin_unlock(&_dump_buf_lock);
998
999 return nbytes;
1000}
1001
James Smartf9bb2da2011-10-10 21:34:11 -04001002static ssize_t
1003lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1004 size_t nbytes, loff_t *ppos)
1005{
1006 struct dentry *dent = file->f_dentry;
1007 struct lpfc_hba *phba = file->private_data;
James Smart9a6b09c2012-03-01 22:37:42 -05001008 char cbuf[32];
James Smart4ac9b222012-03-01 22:38:29 -05001009 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04001010 int cnt = 0;
1011
1012 if (dent == phba->debug_writeGuard)
James Smart9a6b09c2012-03-01 22:37:42 -05001013 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001014 else if (dent == phba->debug_writeApp)
James Smart9a6b09c2012-03-01 22:37:42 -05001015 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001016 else if (dent == phba->debug_writeRef)
James Smart9a6b09c2012-03-01 22:37:42 -05001017 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
James Smartacd68592012-01-18 16:25:09 -05001018 else if (dent == phba->debug_readGuard)
James Smart9a6b09c2012-03-01 22:37:42 -05001019 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001020 else if (dent == phba->debug_readApp)
James Smart9a6b09c2012-03-01 22:37:42 -05001021 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001022 else if (dent == phba->debug_readRef)
James Smart9a6b09c2012-03-01 22:37:42 -05001023 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
James Smart4ac9b222012-03-01 22:38:29 -05001024 else if (dent == phba->debug_InjErrNPortID)
1025 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1026 else if (dent == phba->debug_InjErrWWPN) {
1027 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1028 tmp = cpu_to_be64(tmp);
1029 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1030 } else if (dent == phba->debug_InjErrLBA) {
1031 if (phba->lpfc_injerr_lba == (sector_t)(-1))
James Smart9a6b09c2012-03-01 22:37:42 -05001032 cnt = snprintf(cbuf, 32, "off\n");
1033 else
James Smart4ac9b222012-03-01 22:38:29 -05001034 cnt = snprintf(cbuf, 32, "0x%llx\n",
1035 (uint64_t) phba->lpfc_injerr_lba);
James Smart9a6b09c2012-03-01 22:37:42 -05001036 } else
James Smartf9bb2da2011-10-10 21:34:11 -04001037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1038 "0547 Unknown debugfs error injection entry\n");
1039
1040 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1041}
1042
1043static ssize_t
1044lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1045 size_t nbytes, loff_t *ppos)
1046{
1047 struct dentry *dent = file->f_dentry;
1048 struct lpfc_hba *phba = file->private_data;
1049 char dstbuf[32];
James Smart4ac9b222012-03-01 22:38:29 -05001050 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04001051 int size;
1052
1053 memset(dstbuf, 0, 32);
1054 size = (nbytes < 32) ? nbytes : 32;
1055 if (copy_from_user(dstbuf, buf, size))
1056 return 0;
1057
James Smart9a6b09c2012-03-01 22:37:42 -05001058 if (dent == phba->debug_InjErrLBA) {
1059 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
James Smart4ac9b222012-03-01 22:38:29 -05001060 tmp = (uint64_t)(-1);
James Smart9a6b09c2012-03-01 22:37:42 -05001061 }
1062
James Smart4ac9b222012-03-01 22:38:29 -05001063 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
James Smartf9bb2da2011-10-10 21:34:11 -04001064 return 0;
1065
1066 if (dent == phba->debug_writeGuard)
1067 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1068 else if (dent == phba->debug_writeApp)
1069 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1070 else if (dent == phba->debug_writeRef)
1071 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
James Smartacd68592012-01-18 16:25:09 -05001072 else if (dent == phba->debug_readGuard)
1073 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
James Smartf9bb2da2011-10-10 21:34:11 -04001074 else if (dent == phba->debug_readApp)
1075 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1076 else if (dent == phba->debug_readRef)
1077 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1078 else if (dent == phba->debug_InjErrLBA)
1079 phba->lpfc_injerr_lba = (sector_t)tmp;
James Smart4ac9b222012-03-01 22:38:29 -05001080 else if (dent == phba->debug_InjErrNPortID)
1081 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1082 else if (dent == phba->debug_InjErrWWPN) {
1083 tmp = cpu_to_be64(tmp);
1084 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1085 } else
James Smartf9bb2da2011-10-10 21:34:11 -04001086 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1087 "0548 Unknown debugfs error injection entry\n");
1088
1089 return nbytes;
1090}
1091
1092static int
1093lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1094{
1095 return 0;
1096}
1097
James Smarte59058c2008-08-24 21:49:00 -04001098/**
James Smart3621a712009-04-06 18:47:14 -04001099 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001100 * @inode: The inode pointer that contains a vport pointer.
1101 * @file: The file pointer to attach the log output.
1102 *
1103 * Description:
1104 * This routine is the entry point for the debugfs open file operation. It gets
1105 * the vport from the i_private field in @inode, allocates the necessary buffer
1106 * for the log, fills the buffer from the in-memory log for this vport, and then
1107 * returns a pointer to that log in the private_data field in @file.
1108 *
1109 * Returns:
1110 * This function returns zero if successful. On error it will return an negative
1111 * error value.
1112 **/
James Smarta58cbd52007-08-02 11:09:43 -04001113static int
James Smart858c9f62007-06-17 19:56:39 -05001114lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1115{
1116 struct lpfc_vport *vport = inode->i_private;
1117 struct lpfc_debug *debug;
1118 int rc = -ENOMEM;
1119
1120 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1121 if (!debug)
1122 goto out;
1123
James Smarte59058c2008-08-24 21:49:00 -04001124 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05001125 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1126 if (!debug->buffer) {
1127 kfree(debug);
1128 goto out;
1129 }
1130
1131 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1132 LPFC_NODELIST_SIZE);
1133 file->private_data = debug;
1134
1135 rc = 0;
1136out:
1137 return rc;
1138}
1139
James Smarte59058c2008-08-24 21:49:00 -04001140/**
James Smart3621a712009-04-06 18:47:14 -04001141 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001142 * @file: The file pointer to seek through.
1143 * @off: The offset to seek to or the amount to seek by.
1144 * @whence: Indicates how to seek.
1145 *
1146 * Description:
1147 * This routine is the entry point for the debugfs lseek file operation. The
1148 * @whence parameter indicates whether @off is the offset to directly seek to,
1149 * or if it is a value to seek forward or reverse by. This function figures out
1150 * what the new offset of the debugfs file will be and assigns that value to the
1151 * f_pos field of @file.
1152 *
1153 * Returns:
1154 * This function returns the new offset if successful and returns a negative
1155 * error if unable to process the seek.
1156 **/
James Smart858c9f62007-06-17 19:56:39 -05001157static loff_t
1158lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1159{
1160 struct lpfc_debug *debug;
1161 loff_t pos = -1;
1162
1163 debug = file->private_data;
1164
1165 switch (whence) {
1166 case 0:
1167 pos = off;
1168 break;
1169 case 1:
1170 pos = file->f_pos + off;
1171 break;
1172 case 2:
1173 pos = debug->len - off;
1174 }
1175 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1176}
1177
James Smarte59058c2008-08-24 21:49:00 -04001178/**
James Smart3621a712009-04-06 18:47:14 -04001179 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001180 * @file: The file pointer to read from.
1181 * @buf: The buffer to copy the data to.
1182 * @nbytes: The number of bytes to read.
1183 * @ppos: The position in the file to start reading from.
1184 *
1185 * Description:
1186 * This routine reads data from from the buffer indicated in the private_data
1187 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1188 * data to @buf.
1189 *
1190 * Returns:
1191 * This function returns the amount of data that was read (this could be less
1192 * than @nbytes if the end of the file was reached) or a negative error value.
1193 **/
James Smart858c9f62007-06-17 19:56:39 -05001194static ssize_t
1195lpfc_debugfs_read(struct file *file, char __user *buf,
1196 size_t nbytes, loff_t *ppos)
1197{
1198 struct lpfc_debug *debug = file->private_data;
James Smart2a622bf2011-02-16 12:40:06 -05001199
James Smart858c9f62007-06-17 19:56:39 -05001200 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1201 debug->len);
1202}
1203
James Smarte59058c2008-08-24 21:49:00 -04001204/**
James Smart3621a712009-04-06 18:47:14 -04001205 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04001206 * @inode: The inode pointer that contains a vport pointer. (unused)
1207 * @file: The file pointer that contains the buffer to release.
1208 *
1209 * Description:
1210 * This routine frees the buffer that was allocated when the debugfs file was
1211 * opened.
1212 *
1213 * Returns:
1214 * This function returns zero.
1215 **/
James Smart858c9f62007-06-17 19:56:39 -05001216static int
1217lpfc_debugfs_release(struct inode *inode, struct file *file)
1218{
1219 struct lpfc_debug *debug = file->private_data;
1220
1221 kfree(debug->buffer);
1222 kfree(debug);
1223
1224 return 0;
1225}
1226
James Smarte2a0a9d2008-12-04 22:40:02 -05001227static int
1228lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1229{
1230 struct lpfc_debug *debug = file->private_data;
1231
1232 debug->buffer = NULL;
1233 kfree(debug);
1234
1235 return 0;
1236}
1237
James Smart2a622bf2011-02-16 12:40:06 -05001238/*
James Smart86a80842011-04-16 11:03:04 -04001239 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001240 * iDiag debugfs file access methods
James Smart86a80842011-04-16 11:03:04 -04001241 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001242 *
James Smart86a80842011-04-16 11:03:04 -04001243 * All access methods are through the proper SLI4 PCI function's debugfs
1244 * iDiag directory:
James Smart2a622bf2011-02-16 12:40:06 -05001245 *
James Smart86a80842011-04-16 11:03:04 -04001246 * /sys/kernel/debug/lpfc/fn<#>/iDiag
James Smart2a622bf2011-02-16 12:40:06 -05001247 */
1248
1249/**
1250 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1251 * @buf: The pointer to the user space buffer.
1252 * @nbytes: The number of bytes in the user space buffer.
1253 * @idiag_cmd: pointer to the idiag command struct.
1254 *
1255 * This routine reads data from debugfs user space buffer and parses the
1256 * buffer for getting the idiag command and arguments. The while space in
1257 * between the set of data is used as the parsing separator.
1258 *
1259 * This routine returns 0 when successful, it returns proper error code
1260 * back to the user space in error conditions.
1261 */
1262static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1263 struct lpfc_idiag_cmd *idiag_cmd)
1264{
1265 char mybuf[64];
1266 char *pbuf, *step_str;
Stephen Boydb11d48e2011-05-12 16:50:06 -07001267 int i;
1268 size_t bsize;
James Smart2a622bf2011-02-16 12:40:06 -05001269
1270 /* Protect copy from user */
1271 if (!access_ok(VERIFY_READ, buf, nbytes))
1272 return -EFAULT;
1273
1274 memset(mybuf, 0, sizeof(mybuf));
1275 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1276 bsize = min(nbytes, (sizeof(mybuf)-1));
1277
1278 if (copy_from_user(mybuf, buf, bsize))
1279 return -EFAULT;
1280 pbuf = &mybuf[0];
1281 step_str = strsep(&pbuf, "\t ");
1282
1283 /* The opcode must present */
1284 if (!step_str)
1285 return -EINVAL;
1286
1287 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1288 if (idiag_cmd->opcode == 0)
1289 return -EINVAL;
1290
1291 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1292 step_str = strsep(&pbuf, "\t ");
1293 if (!step_str)
James Smart86a80842011-04-16 11:03:04 -04001294 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001295 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1296 }
James Smart86a80842011-04-16 11:03:04 -04001297 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001298}
1299
1300/**
1301 * lpfc_idiag_open - idiag open debugfs
1302 * @inode: The inode pointer that contains a pointer to phba.
1303 * @file: The file pointer to attach the file operation.
1304 *
1305 * Description:
1306 * This routine is the entry point for the debugfs open file operation. It
1307 * gets the reference to phba from the i_private field in @inode, it then
1308 * allocates buffer for the file operation, performs the necessary PCI config
1309 * space read into the allocated buffer according to the idiag user command
1310 * setup, and then returns a pointer to buffer in the private_data field in
1311 * @file.
1312 *
1313 * Returns:
1314 * This function returns zero if successful. On error it will return an
1315 * negative error value.
1316 **/
1317static int
1318lpfc_idiag_open(struct inode *inode, struct file *file)
1319{
1320 struct lpfc_debug *debug;
1321
1322 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1323 if (!debug)
1324 return -ENOMEM;
1325
1326 debug->i_private = inode->i_private;
1327 debug->buffer = NULL;
1328 file->private_data = debug;
1329
1330 return 0;
1331}
1332
1333/**
1334 * lpfc_idiag_release - Release idiag access file operation
1335 * @inode: The inode pointer that contains a vport pointer. (unused)
1336 * @file: The file pointer that contains the buffer to release.
1337 *
1338 * Description:
1339 * This routine is the generic release routine for the idiag access file
1340 * operation, it frees the buffer that was allocated when the debugfs file
1341 * was opened.
1342 *
1343 * Returns:
1344 * This function returns zero.
1345 **/
1346static int
1347lpfc_idiag_release(struct inode *inode, struct file *file)
1348{
1349 struct lpfc_debug *debug = file->private_data;
1350
1351 /* Free the buffers to the file operation */
1352 kfree(debug->buffer);
1353 kfree(debug);
1354
1355 return 0;
1356}
1357
1358/**
1359 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1360 * @inode: The inode pointer that contains a vport pointer. (unused)
1361 * @file: The file pointer that contains the buffer to release.
1362 *
1363 * Description:
1364 * This routine frees the buffer that was allocated when the debugfs file
1365 * was opened. It also reset the fields in the idiag command struct in the
James Smart86a80842011-04-16 11:03:04 -04001366 * case of command for write operation.
James Smart2a622bf2011-02-16 12:40:06 -05001367 *
1368 * Returns:
1369 * This function returns zero.
1370 **/
1371static int
1372lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1373{
1374 struct lpfc_debug *debug = file->private_data;
1375
James Smart86a80842011-04-16 11:03:04 -04001376 if (debug->op == LPFC_IDIAG_OP_WR) {
1377 switch (idiag.cmd.opcode) {
1378 case LPFC_IDIAG_CMD_PCICFG_WR:
1379 case LPFC_IDIAG_CMD_PCICFG_ST:
1380 case LPFC_IDIAG_CMD_PCICFG_CL:
1381 case LPFC_IDIAG_CMD_QUEACC_WR:
1382 case LPFC_IDIAG_CMD_QUEACC_ST:
1383 case LPFC_IDIAG_CMD_QUEACC_CL:
James Smart2a622bf2011-02-16 12:40:06 -05001384 memset(&idiag, 0, sizeof(idiag));
James Smart86a80842011-04-16 11:03:04 -04001385 break;
1386 default:
1387 break;
1388 }
1389 }
James Smart2a622bf2011-02-16 12:40:06 -05001390
1391 /* Free the buffers to the file operation */
1392 kfree(debug->buffer);
1393 kfree(debug);
1394
1395 return 0;
1396}
1397
1398/**
1399 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1400 * @file: The file pointer to read from.
1401 * @buf: The buffer to copy the data to.
1402 * @nbytes: The number of bytes to read.
1403 * @ppos: The position in the file to start reading from.
1404 *
1405 * Description:
1406 * This routine reads data from the @phba pci config space according to the
1407 * idiag command, and copies to user @buf. Depending on the PCI config space
1408 * read command setup, it does either a single register read of a byte
1409 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1410 * registers from the 4K extended PCI config space.
1411 *
1412 * Returns:
1413 * This function returns the amount of data that was read (this could be less
1414 * than @nbytes if the end of the file was reached) or a negative error value.
1415 **/
1416static ssize_t
1417lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1418 loff_t *ppos)
1419{
1420 struct lpfc_debug *debug = file->private_data;
1421 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1422 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1423 int where, count;
1424 char *pbuffer;
1425 struct pci_dev *pdev;
1426 uint32_t u32val;
1427 uint16_t u16val;
1428 uint8_t u8val;
1429
1430 pdev = phba->pcidev;
1431 if (!pdev)
1432 return 0;
1433
1434 /* This is a user read operation */
1435 debug->op = LPFC_IDIAG_OP_RD;
1436
1437 if (!debug->buffer)
1438 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1439 if (!debug->buffer)
1440 return 0;
1441 pbuffer = debug->buffer;
1442
1443 if (*ppos)
1444 return 0;
1445
1446 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04001447 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1448 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05001449 } else
1450 return 0;
1451
1452 /* Read single PCI config space register */
1453 switch (count) {
1454 case SIZE_U8: /* byte (8 bits) */
1455 pci_read_config_byte(pdev, where, &u8val);
1456 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1457 "%03x: %02x\n", where, u8val);
1458 break;
1459 case SIZE_U16: /* word (16 bits) */
1460 pci_read_config_word(pdev, where, &u16val);
1461 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1462 "%03x: %04x\n", where, u16val);
1463 break;
1464 case SIZE_U32: /* double word (32 bits) */
1465 pci_read_config_dword(pdev, where, &u32val);
1466 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1467 "%03x: %08x\n", where, u32val);
1468 break;
James Smart86a80842011-04-16 11:03:04 -04001469 case LPFC_PCI_CFG_BROWSE: /* browse all */
James Smart2a622bf2011-02-16 12:40:06 -05001470 goto pcicfg_browse;
1471 break;
1472 default:
1473 /* illegal count */
1474 len = 0;
1475 break;
1476 }
1477 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1478
1479pcicfg_browse:
1480
1481 /* Browse all PCI config space registers */
1482 offset_label = idiag.offset.last_rd;
1483 offset = offset_label;
1484
1485 /* Read PCI config space */
1486 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1487 "%03x: ", offset_label);
1488 while (index > 0) {
1489 pci_read_config_dword(pdev, offset, &u32val);
1490 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1491 "%08x ", u32val);
1492 offset += sizeof(uint32_t);
James Smartb76f2dc2011-07-22 18:37:42 -04001493 if (offset >= LPFC_PCI_CFG_SIZE) {
1494 len += snprintf(pbuffer+len,
1495 LPFC_PCI_CFG_SIZE-len, "\n");
1496 break;
1497 }
James Smart2a622bf2011-02-16 12:40:06 -05001498 index -= sizeof(uint32_t);
1499 if (!index)
1500 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1501 "\n");
1502 else if (!(index % (8 * sizeof(uint32_t)))) {
1503 offset_label += (8 * sizeof(uint32_t));
1504 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1505 "\n%03x: ", offset_label);
1506 }
1507 }
1508
1509 /* Set up the offset for next portion of pci cfg read */
James Smartb76f2dc2011-07-22 18:37:42 -04001510 if (index == 0) {
1511 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1512 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1513 idiag.offset.last_rd = 0;
1514 } else
James Smart2a622bf2011-02-16 12:40:06 -05001515 idiag.offset.last_rd = 0;
1516
1517 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1518}
1519
1520/**
1521 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1522 * @file: The file pointer to read from.
1523 * @buf: The buffer to copy the user data from.
1524 * @nbytes: The number of bytes to get.
1525 * @ppos: The position in the file to start reading from.
1526 *
1527 * This routine get the debugfs idiag command struct from user space and
1528 * then perform the syntax check for PCI config space read or write command
1529 * accordingly. In the case of PCI config space read command, it sets up
1530 * the command in the idiag command struct for the debugfs read operation.
1531 * In the case of PCI config space write operation, it executes the write
1532 * operation into the PCI config space accordingly.
1533 *
1534 * It returns the @nbytges passing in from debugfs user space when successful.
1535 * In case of error conditions, it returns proper error code back to the user
1536 * space.
1537 */
1538static ssize_t
1539lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1540 size_t nbytes, loff_t *ppos)
1541{
1542 struct lpfc_debug *debug = file->private_data;
1543 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1544 uint32_t where, value, count;
1545 uint32_t u32val;
1546 uint16_t u16val;
1547 uint8_t u8val;
1548 struct pci_dev *pdev;
1549 int rc;
1550
1551 pdev = phba->pcidev;
1552 if (!pdev)
1553 return -EFAULT;
1554
1555 /* This is a user write operation */
1556 debug->op = LPFC_IDIAG_OP_WR;
1557
1558 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
James Smart86a80842011-04-16 11:03:04 -04001559 if (rc < 0)
James Smart2a622bf2011-02-16 12:40:06 -05001560 return rc;
1561
1562 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smart86a80842011-04-16 11:03:04 -04001563 /* Sanity check on PCI config read command line arguments */
1564 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1565 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001566 /* Read command from PCI config space, set up command fields */
James Smartb76f2dc2011-07-22 18:37:42 -04001567 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1568 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04001569 if (count == LPFC_PCI_CFG_BROWSE) {
1570 if (where % sizeof(uint32_t))
James Smart2a622bf2011-02-16 12:40:06 -05001571 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04001572 /* Starting offset to browse */
1573 idiag.offset.last_rd = where;
James Smart2a622bf2011-02-16 12:40:06 -05001574 } else if ((count != sizeof(uint8_t)) &&
1575 (count != sizeof(uint16_t)) &&
1576 (count != sizeof(uint32_t)))
1577 goto error_out;
1578 if (count == sizeof(uint8_t)) {
1579 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1580 goto error_out;
1581 if (where % sizeof(uint8_t))
1582 goto error_out;
1583 }
1584 if (count == sizeof(uint16_t)) {
1585 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1586 goto error_out;
1587 if (where % sizeof(uint16_t))
1588 goto error_out;
1589 }
1590 if (count == sizeof(uint32_t)) {
1591 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1592 goto error_out;
1593 if (where % sizeof(uint32_t))
1594 goto error_out;
1595 }
1596 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1597 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1598 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
James Smart86a80842011-04-16 11:03:04 -04001599 /* Sanity check on PCI config write command line arguments */
1600 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1601 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001602 /* Write command to PCI config space, read-modify-write */
James Smartb76f2dc2011-07-22 18:37:42 -04001603 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1604 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1605 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05001606 /* Sanity checks */
1607 if ((count != sizeof(uint8_t)) &&
1608 (count != sizeof(uint16_t)) &&
1609 (count != sizeof(uint32_t)))
1610 goto error_out;
1611 if (count == sizeof(uint8_t)) {
1612 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1613 goto error_out;
1614 if (where % sizeof(uint8_t))
1615 goto error_out;
1616 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1617 pci_write_config_byte(pdev, where,
1618 (uint8_t)value);
1619 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1620 rc = pci_read_config_byte(pdev, where, &u8val);
1621 if (!rc) {
1622 u8val |= (uint8_t)value;
1623 pci_write_config_byte(pdev, where,
1624 u8val);
1625 }
1626 }
1627 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1628 rc = pci_read_config_byte(pdev, where, &u8val);
1629 if (!rc) {
1630 u8val &= (uint8_t)(~value);
1631 pci_write_config_byte(pdev, where,
1632 u8val);
1633 }
1634 }
1635 }
1636 if (count == sizeof(uint16_t)) {
1637 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1638 goto error_out;
1639 if (where % sizeof(uint16_t))
1640 goto error_out;
1641 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1642 pci_write_config_word(pdev, where,
1643 (uint16_t)value);
1644 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1645 rc = pci_read_config_word(pdev, where, &u16val);
1646 if (!rc) {
1647 u16val |= (uint16_t)value;
1648 pci_write_config_word(pdev, where,
1649 u16val);
1650 }
1651 }
1652 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1653 rc = pci_read_config_word(pdev, where, &u16val);
1654 if (!rc) {
1655 u16val &= (uint16_t)(~value);
1656 pci_write_config_word(pdev, where,
1657 u16val);
1658 }
1659 }
1660 }
1661 if (count == sizeof(uint32_t)) {
1662 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1663 goto error_out;
1664 if (where % sizeof(uint32_t))
1665 goto error_out;
1666 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1667 pci_write_config_dword(pdev, where, value);
1668 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1669 rc = pci_read_config_dword(pdev, where,
1670 &u32val);
1671 if (!rc) {
1672 u32val |= value;
1673 pci_write_config_dword(pdev, where,
1674 u32val);
1675 }
1676 }
1677 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1678 rc = pci_read_config_dword(pdev, where,
1679 &u32val);
1680 if (!rc) {
1681 u32val &= ~value;
1682 pci_write_config_dword(pdev, where,
1683 u32val);
1684 }
1685 }
1686 }
1687 } else
1688 /* All other opecodes are illegal for now */
1689 goto error_out;
1690
1691 return nbytes;
1692error_out:
1693 memset(&idiag, 0, sizeof(idiag));
1694 return -EINVAL;
1695}
1696
1697/**
James Smartb76f2dc2011-07-22 18:37:42 -04001698 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1699 * @file: The file pointer to read from.
1700 * @buf: The buffer to copy the data to.
1701 * @nbytes: The number of bytes to read.
1702 * @ppos: The position in the file to start reading from.
1703 *
1704 * Description:
1705 * This routine reads data from the @phba pci bar memory mapped space
1706 * according to the idiag command, and copies to user @buf.
1707 *
1708 * Returns:
1709 * This function returns the amount of data that was read (this could be less
1710 * than @nbytes if the end of the file was reached) or a negative error value.
1711 **/
1712static ssize_t
1713lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1714 loff_t *ppos)
1715{
1716 struct lpfc_debug *debug = file->private_data;
1717 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1718 int offset_label, offset, offset_run, len = 0, index;
1719 int bar_num, acc_range, bar_size;
1720 char *pbuffer;
1721 void __iomem *mem_mapped_bar;
1722 uint32_t if_type;
1723 struct pci_dev *pdev;
1724 uint32_t u32val;
1725
1726 pdev = phba->pcidev;
1727 if (!pdev)
1728 return 0;
1729
1730 /* This is a user read operation */
1731 debug->op = LPFC_IDIAG_OP_RD;
1732
1733 if (!debug->buffer)
1734 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1735 if (!debug->buffer)
1736 return 0;
1737 pbuffer = debug->buffer;
1738
1739 if (*ppos)
1740 return 0;
1741
1742 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1743 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1744 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1745 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1746 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1747 } else
1748 return 0;
1749
1750 if (acc_range == 0)
1751 return 0;
1752
1753 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1754 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1755 if (bar_num == IDIAG_BARACC_BAR_0)
1756 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1757 else if (bar_num == IDIAG_BARACC_BAR_1)
1758 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1759 else if (bar_num == IDIAG_BARACC_BAR_2)
1760 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1761 else
1762 return 0;
1763 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1764 if (bar_num == IDIAG_BARACC_BAR_0)
1765 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1766 else
1767 return 0;
1768 } else
1769 return 0;
1770
1771 /* Read single PCI bar space register */
1772 if (acc_range == SINGLE_WORD) {
1773 offset_run = offset;
1774 u32val = readl(mem_mapped_bar + offset_run);
1775 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1776 "%05x: %08x\n", offset_run, u32val);
1777 } else
1778 goto baracc_browse;
1779
1780 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1781
1782baracc_browse:
1783
1784 /* Browse all PCI bar space registers */
1785 offset_label = idiag.offset.last_rd;
1786 offset_run = offset_label;
1787
1788 /* Read PCI bar memory mapped space */
1789 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1790 "%05x: ", offset_label);
1791 index = LPFC_PCI_BAR_RD_SIZE;
1792 while (index > 0) {
1793 u32val = readl(mem_mapped_bar + offset_run);
1794 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1795 "%08x ", u32val);
1796 offset_run += sizeof(uint32_t);
1797 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1798 if (offset_run >= bar_size) {
1799 len += snprintf(pbuffer+len,
1800 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1801 break;
1802 }
1803 } else {
1804 if (offset_run >= offset +
1805 (acc_range * sizeof(uint32_t))) {
1806 len += snprintf(pbuffer+len,
1807 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1808 break;
1809 }
1810 }
1811 index -= sizeof(uint32_t);
1812 if (!index)
1813 len += snprintf(pbuffer+len,
1814 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1815 else if (!(index % (8 * sizeof(uint32_t)))) {
1816 offset_label += (8 * sizeof(uint32_t));
1817 len += snprintf(pbuffer+len,
1818 LPFC_PCI_BAR_RD_BUF_SIZE-len,
1819 "\n%05x: ", offset_label);
1820 }
1821 }
1822
1823 /* Set up the offset for next portion of pci bar read */
1824 if (index == 0) {
1825 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1826 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1827 if (idiag.offset.last_rd >= bar_size)
1828 idiag.offset.last_rd = 0;
1829 } else {
1830 if (offset_run >= offset +
1831 (acc_range * sizeof(uint32_t)))
1832 idiag.offset.last_rd = offset;
1833 }
1834 } else {
1835 if (acc_range == LPFC_PCI_BAR_BROWSE)
1836 idiag.offset.last_rd = 0;
1837 else
1838 idiag.offset.last_rd = offset;
1839 }
1840
1841 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1842}
1843
1844/**
1845 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1846 * @file: The file pointer to read from.
1847 * @buf: The buffer to copy the user data from.
1848 * @nbytes: The number of bytes to get.
1849 * @ppos: The position in the file to start reading from.
1850 *
1851 * This routine get the debugfs idiag command struct from user space and
1852 * then perform the syntax check for PCI bar memory mapped space read or
1853 * write command accordingly. In the case of PCI bar memory mapped space
1854 * read command, it sets up the command in the idiag command struct for
1855 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1856 * write operation, it executes the write operation into the PCI bar memory
1857 * mapped space accordingly.
1858 *
1859 * It returns the @nbytges passing in from debugfs user space when successful.
1860 * In case of error conditions, it returns proper error code back to the user
1861 * space.
1862 */
1863static ssize_t
1864lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1865 size_t nbytes, loff_t *ppos)
1866{
1867 struct lpfc_debug *debug = file->private_data;
1868 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1869 uint32_t bar_num, bar_size, offset, value, acc_range;
1870 struct pci_dev *pdev;
1871 void __iomem *mem_mapped_bar;
1872 uint32_t if_type;
1873 uint32_t u32val;
1874 int rc;
1875
1876 pdev = phba->pcidev;
1877 if (!pdev)
1878 return -EFAULT;
1879
1880 /* This is a user write operation */
1881 debug->op = LPFC_IDIAG_OP_WR;
1882
1883 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1884 if (rc < 0)
1885 return rc;
1886
1887 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1888 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1889
1890 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1891 if ((bar_num != IDIAG_BARACC_BAR_0) &&
1892 (bar_num != IDIAG_BARACC_BAR_1) &&
1893 (bar_num != IDIAG_BARACC_BAR_2))
1894 goto error_out;
1895 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1896 if (bar_num != IDIAG_BARACC_BAR_0)
1897 goto error_out;
1898 } else
1899 goto error_out;
1900
1901 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1902 if (bar_num == IDIAG_BARACC_BAR_0) {
1903 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1904 LPFC_PCI_IF0_BAR0_SIZE;
1905 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1906 } else if (bar_num == IDIAG_BARACC_BAR_1) {
1907 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1908 LPFC_PCI_IF0_BAR1_SIZE;
1909 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1910 } else if (bar_num == IDIAG_BARACC_BAR_2) {
1911 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1912 LPFC_PCI_IF0_BAR2_SIZE;
1913 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1914 } else
1915 goto error_out;
1916 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1917 if (bar_num == IDIAG_BARACC_BAR_0) {
1918 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1919 LPFC_PCI_IF2_BAR0_SIZE;
1920 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1921 } else
1922 goto error_out;
1923 } else
1924 goto error_out;
1925
1926 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1927 if (offset % sizeof(uint32_t))
1928 goto error_out;
1929
1930 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1931 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1932 /* Sanity check on PCI config read command line arguments */
1933 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1934 goto error_out;
1935 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1936 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1937 if (offset > bar_size - sizeof(uint32_t))
1938 goto error_out;
1939 /* Starting offset to browse */
1940 idiag.offset.last_rd = offset;
1941 } else if (acc_range > SINGLE_WORD) {
1942 if (offset + acc_range * sizeof(uint32_t) > bar_size)
1943 goto error_out;
1944 /* Starting offset to browse */
1945 idiag.offset.last_rd = offset;
1946 } else if (acc_range != SINGLE_WORD)
1947 goto error_out;
1948 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1949 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1950 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1951 /* Sanity check on PCI bar write command line arguments */
1952 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1953 goto error_out;
1954 /* Write command to PCI bar space, read-modify-write */
1955 acc_range = SINGLE_WORD;
1956 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1957 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1958 writel(value, mem_mapped_bar + offset);
1959 readl(mem_mapped_bar + offset);
1960 }
1961 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1962 u32val = readl(mem_mapped_bar + offset);
1963 u32val |= value;
1964 writel(u32val, mem_mapped_bar + offset);
1965 readl(mem_mapped_bar + offset);
1966 }
1967 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1968 u32val = readl(mem_mapped_bar + offset);
1969 u32val &= ~value;
1970 writel(u32val, mem_mapped_bar + offset);
1971 readl(mem_mapped_bar + offset);
1972 }
1973 } else
1974 /* All other opecodes are illegal for now */
1975 goto error_out;
1976
1977 return nbytes;
1978error_out:
1979 memset(&idiag, 0, sizeof(idiag));
1980 return -EINVAL;
1981}
1982
1983/**
James Smart2a622bf2011-02-16 12:40:06 -05001984 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1985 * @file: The file pointer to read from.
1986 * @buf: The buffer to copy the data to.
1987 * @nbytes: The number of bytes to read.
1988 * @ppos: The position in the file to start reading from.
1989 *
1990 * Description:
1991 * This routine reads data from the @phba SLI4 PCI function queue information,
1992 * and copies to user @buf.
1993 *
1994 * Returns:
1995 * This function returns the amount of data that was read (this could be less
1996 * than @nbytes if the end of the file was reached) or a negative error value.
1997 **/
1998static ssize_t
1999lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
2000 loff_t *ppos)
2001{
2002 struct lpfc_debug *debug = file->private_data;
2003 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2004 int len = 0, fcp_qidx;
2005 char *pbuffer;
2006
2007 if (!debug->buffer)
2008 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
2009 if (!debug->buffer)
2010 return 0;
2011 pbuffer = debug->buffer;
2012
2013 if (*ppos)
2014 return 0;
2015
2016 /* Get slow-path event queue information */
2017 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2018 "Slow-path EQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002019 if (phba->sli4_hba.sp_eq) {
2020 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002021 "\tEQID[%02d], "
2022 "QE-COUNT[%04d], QE-SIZE[%04d], "
2023 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002024 phba->sli4_hba.sp_eq->queue_id,
2025 phba->sli4_hba.sp_eq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002026 phba->sli4_hba.sp_eq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002027 phba->sli4_hba.sp_eq->host_index,
2028 phba->sli4_hba.sp_eq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002029 }
James Smart2a622bf2011-02-16 12:40:06 -05002030
2031 /* Get fast-path event queue information */
2032 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2033 "Fast-path EQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002034 if (phba->sli4_hba.fp_eq) {
2035 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count;
2036 fcp_qidx++) {
2037 if (phba->sli4_hba.fp_eq[fcp_qidx]) {
2038 len += snprintf(pbuffer+len,
2039 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002040 "\tEQID[%02d], "
2041 "QE-COUNT[%04d], QE-SIZE[%04d], "
2042 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002043 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
2044 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002045 phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002046 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
2047 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002048 }
2049 }
James Smart2a622bf2011-02-16 12:40:06 -05002050 }
2051 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2052
2053 /* Get mailbox complete queue information */
2054 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002055 "Slow-path MBX CQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002056 if (phba->sli4_hba.mbx_cq) {
2057 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002058 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002059 phba->sli4_hba.mbx_cq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002060 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002061 "\tCQID[%02d], "
2062 "QE-COUNT[%04d], QE-SIZE[%04d], "
2063 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002064 phba->sli4_hba.mbx_cq->queue_id,
2065 phba->sli4_hba.mbx_cq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002066 phba->sli4_hba.mbx_cq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002067 phba->sli4_hba.mbx_cq->host_index,
2068 phba->sli4_hba.mbx_cq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002069 }
James Smart2a622bf2011-02-16 12:40:06 -05002070
2071 /* Get slow-path complete queue information */
2072 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002073 "Slow-path ELS CQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002074 if (phba->sli4_hba.els_cq) {
2075 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002076 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002077 phba->sli4_hba.els_cq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002078 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002079 "\tCQID [%02d], "
2080 "QE-COUNT[%04d], QE-SIZE[%04d], "
2081 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002082 phba->sli4_hba.els_cq->queue_id,
2083 phba->sli4_hba.els_cq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002084 phba->sli4_hba.els_cq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002085 phba->sli4_hba.els_cq->host_index,
2086 phba->sli4_hba.els_cq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002087 }
James Smart2a622bf2011-02-16 12:40:06 -05002088
2089 /* Get fast-path complete queue information */
2090 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002091 "Fast-path FCP CQ information:\n");
James Smart05580562011-05-24 11:40:48 -04002092 fcp_qidx = 0;
James Smart2e90f4b2011-12-13 13:22:37 -05002093 if (phba->sli4_hba.fcp_cq) {
2094 do {
2095 if (phba->sli4_hba.fcp_cq[fcp_qidx]) {
2096 len += snprintf(pbuffer+len,
2097 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002098 "Associated EQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002099 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002100 len += snprintf(pbuffer+len,
2101 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002102 "\tCQID[%02d], "
2103 "QE-COUNT[%04d], QE-SIZE[%04d], "
2104 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2105 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
2106 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
2107 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
2108 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
2109 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002110 }
2111 } while (++fcp_qidx < phba->cfg_fcp_eq_count);
2112 len += snprintf(pbuffer+len,
2113 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2114 }
James Smart2a622bf2011-02-16 12:40:06 -05002115
2116 /* Get mailbox queue information */
2117 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002118 "Slow-path MBX MQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002119 if (phba->sli4_hba.mbx_wq) {
2120 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002121 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002122 phba->sli4_hba.mbx_wq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002123 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002124 "\tWQID[%02d], "
2125 "QE-COUNT[%04d], QE-SIZE[%04d], "
2126 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002127 phba->sli4_hba.mbx_wq->queue_id,
2128 phba->sli4_hba.mbx_wq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002129 phba->sli4_hba.mbx_wq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002130 phba->sli4_hba.mbx_wq->host_index,
2131 phba->sli4_hba.mbx_wq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002132 }
James Smart2a622bf2011-02-16 12:40:06 -05002133
2134 /* Get slow-path work queue information */
2135 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002136 "Slow-path ELS WQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002137 if (phba->sli4_hba.els_wq) {
2138 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002139 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002140 phba->sli4_hba.els_wq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002141 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002142 "\tWQID[%02d], "
2143 "QE-COUNT[%04d], QE-SIZE[%04d], "
2144 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
James Smart2a622bf2011-02-16 12:40:06 -05002145 phba->sli4_hba.els_wq->queue_id,
2146 phba->sli4_hba.els_wq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002147 phba->sli4_hba.els_wq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002148 phba->sli4_hba.els_wq->host_index,
2149 phba->sli4_hba.els_wq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002150 }
James Smart2a622bf2011-02-16 12:40:06 -05002151
2152 /* Get fast-path work queue information */
2153 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002154 "Fast-path FCP WQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002155 if (phba->sli4_hba.fcp_wq) {
2156 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count;
2157 fcp_qidx++) {
2158 if (!phba->sli4_hba.fcp_wq[fcp_qidx])
2159 continue;
2160 len += snprintf(pbuffer+len,
2161 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002162 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002163 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002164 len += snprintf(pbuffer+len,
2165 LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002166 "\tWQID[%02d], "
2167 "QE-COUNT[%04d], WQE-SIZE[%04d], "
2168 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002169 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
2170 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002171 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002172 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
2173 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002174 }
2175 len += snprintf(pbuffer+len,
2176 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
James Smart2a622bf2011-02-16 12:40:06 -05002177 }
James Smart2a622bf2011-02-16 12:40:06 -05002178
2179 /* Get receive queue information */
2180 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2181 "Slow-path RQ information:\n");
James Smart2e90f4b2011-12-13 13:22:37 -05002182 if (phba->sli4_hba.hdr_rq && phba->sli4_hba.dat_rq) {
2183 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002184 "Associated CQID[%02d]:\n",
James Smart2a622bf2011-02-16 12:40:06 -05002185 phba->sli4_hba.hdr_rq->assoc_qid);
James Smart2e90f4b2011-12-13 13:22:37 -05002186 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002187 "\tHQID[%02d], "
2188 "QE-COUNT[%04d], QE-SIZE[%04d], "
2189 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002190 phba->sli4_hba.hdr_rq->queue_id,
2191 phba->sli4_hba.hdr_rq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002192 phba->sli4_hba.hdr_rq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002193 phba->sli4_hba.hdr_rq->host_index,
2194 phba->sli4_hba.hdr_rq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002195 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04002196 "\tDQID[%02d], "
2197 "QE-COUNT[%04d], QE-SIZE[%04d], "
2198 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
James Smart2a622bf2011-02-16 12:40:06 -05002199 phba->sli4_hba.dat_rq->queue_id,
2200 phba->sli4_hba.dat_rq->entry_count,
James Smart86a80842011-04-16 11:03:04 -04002201 phba->sli4_hba.dat_rq->entry_size,
James Smart2a622bf2011-02-16 12:40:06 -05002202 phba->sli4_hba.dat_rq->host_index,
2203 phba->sli4_hba.dat_rq->hba_index);
James Smart2e90f4b2011-12-13 13:22:37 -05002204 }
James Smart2a622bf2011-02-16 12:40:06 -05002205 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2206}
2207
James Smart86a80842011-04-16 11:03:04 -04002208/**
2209 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2210 * @q: The pointer to queue structure.
2211 * @index: The index into a queue entry.
2212 * @count: The number of queue entries to access.
2213 *
2214 * Description:
2215 * The routine performs sanity check on device queue access method commands.
2216 *
2217 * Returns:
2218 * This function returns -EINVAL when fails the sanity check, otherwise, it
2219 * returns 0.
2220 **/
2221static int
2222lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
2223{
2224 /* Only support single entry read or browsing */
2225 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
2226 return -EINVAL;
2227 if (index > q->entry_count - 1)
2228 return -EINVAL;
2229 return 0;
2230}
2231
2232/**
2233 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2234 * @pbuffer: The pointer to buffer to copy the read data into.
2235 * @pque: The pointer to the queue to be read.
2236 * @index: The index into the queue entry.
2237 *
2238 * Description:
2239 * This routine reads out a single entry from the given queue's index location
2240 * and copies it into the buffer provided.
2241 *
2242 * Returns:
2243 * This function returns 0 when it fails, otherwise, it returns the length of
2244 * the data read into the buffer provided.
2245 **/
2246static int
2247lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
2248 uint32_t index)
2249{
2250 int offset, esize;
2251 uint32_t *pentry;
2252
2253 if (!pbuffer || !pque)
2254 return 0;
2255
2256 esize = pque->entry_size;
2257 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2258 "QE-INDEX[%04d]:\n", index);
2259
2260 offset = 0;
2261 pentry = pque->qe[index].address;
2262 while (esize > 0) {
2263 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2264 "%08x ", *pentry);
2265 pentry++;
2266 offset += sizeof(uint32_t);
2267 esize -= sizeof(uint32_t);
2268 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
2269 len += snprintf(pbuffer+len,
2270 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2271 }
2272 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2273
2274 return len;
2275}
2276
2277/**
2278 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2279 * @file: The file pointer to read from.
2280 * @buf: The buffer to copy the data to.
2281 * @nbytes: The number of bytes to read.
2282 * @ppos: The position in the file to start reading from.
2283 *
2284 * Description:
2285 * This routine reads data from the @phba device queue memory according to the
2286 * idiag command, and copies to user @buf. Depending on the queue dump read
2287 * command setup, it does either a single queue entry read or browing through
2288 * all entries of the queue.
2289 *
2290 * Returns:
2291 * This function returns the amount of data that was read (this could be less
2292 * than @nbytes if the end of the file was reached) or a negative error value.
2293 **/
2294static ssize_t
2295lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
2296 loff_t *ppos)
2297{
2298 struct lpfc_debug *debug = file->private_data;
2299 uint32_t last_index, index, count;
2300 struct lpfc_queue *pque = NULL;
2301 char *pbuffer;
2302 int len = 0;
2303
2304 /* This is a user read operation */
2305 debug->op = LPFC_IDIAG_OP_RD;
2306
2307 if (!debug->buffer)
2308 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
2309 if (!debug->buffer)
2310 return 0;
2311 pbuffer = debug->buffer;
2312
2313 if (*ppos)
2314 return 0;
2315
2316 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04002317 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2318 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04002319 pque = (struct lpfc_queue *)idiag.ptr_private;
2320 } else
2321 return 0;
2322
2323 /* Browse the queue starting from index */
2324 if (count == LPFC_QUE_ACC_BROWSE)
2325 goto que_browse;
2326
2327 /* Read a single entry from the queue */
2328 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2329
2330 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2331
2332que_browse:
2333
2334 /* Browse all entries from the queue */
2335 last_index = idiag.offset.last_rd;
2336 index = last_index;
2337
2338 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
2339 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2340 index++;
2341 if (index > pque->entry_count - 1)
2342 break;
2343 }
2344
2345 /* Set up the offset for next portion of pci cfg read */
2346 if (index > pque->entry_count - 1)
2347 index = 0;
2348 idiag.offset.last_rd = index;
2349
2350 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2351}
2352
2353/**
2354 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2355 * @file: The file pointer to read from.
2356 * @buf: The buffer to copy the user data from.
2357 * @nbytes: The number of bytes to get.
2358 * @ppos: The position in the file to start reading from.
2359 *
2360 * This routine get the debugfs idiag command struct from user space and then
2361 * perform the syntax check for port queue read (dump) or write (set) command
2362 * accordingly. In the case of port queue read command, it sets up the command
2363 * in the idiag command struct for the following debugfs read operation. In
2364 * the case of port queue write operation, it executes the write operation
2365 * into the port queue entry accordingly.
2366 *
2367 * It returns the @nbytges passing in from debugfs user space when successful.
2368 * In case of error conditions, it returns proper error code back to the user
2369 * space.
2370 **/
2371static ssize_t
2372lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
2373 size_t nbytes, loff_t *ppos)
2374{
2375 struct lpfc_debug *debug = file->private_data;
2376 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2377 uint32_t qidx, quetp, queid, index, count, offset, value;
2378 uint32_t *pentry;
2379 struct lpfc_queue *pque;
2380 int rc;
2381
2382 /* This is a user write operation */
2383 debug->op = LPFC_IDIAG_OP_WR;
2384
2385 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2386 if (rc < 0)
2387 return rc;
2388
2389 /* Get and sanity check on command feilds */
James Smartb76f2dc2011-07-22 18:37:42 -04002390 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
2391 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
2392 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2393 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2394 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
2395 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04002396
2397 /* Sanity check on command line arguments */
2398 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2399 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2400 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2401 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
2402 goto error_out;
2403 if (count != 1)
2404 goto error_out;
2405 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2406 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
2407 goto error_out;
2408 } else
2409 goto error_out;
2410
2411 switch (quetp) {
2412 case LPFC_IDIAG_EQ:
2413 /* Slow-path event queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002414 if (phba->sli4_hba.sp_eq &&
2415 phba->sli4_hba.sp_eq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002416 /* Sanity check */
2417 rc = lpfc_idiag_que_param_check(
2418 phba->sli4_hba.sp_eq, index, count);
2419 if (rc)
2420 goto error_out;
2421 idiag.ptr_private = phba->sli4_hba.sp_eq;
2422 goto pass_check;
2423 }
2424 /* Fast-path event queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002425 if (phba->sli4_hba.fp_eq) {
2426 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
2427 if (phba->sli4_hba.fp_eq[qidx] &&
2428 phba->sli4_hba.fp_eq[qidx]->queue_id ==
2429 queid) {
2430 /* Sanity check */
2431 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002432 phba->sli4_hba.fp_eq[qidx],
2433 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002434 if (rc)
2435 goto error_out;
2436 idiag.ptr_private =
2437 phba->sli4_hba.fp_eq[qidx];
2438 goto pass_check;
2439 }
James Smart86a80842011-04-16 11:03:04 -04002440 }
2441 }
2442 goto error_out;
2443 break;
2444 case LPFC_IDIAG_CQ:
2445 /* MBX complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002446 if (phba->sli4_hba.mbx_cq &&
2447 phba->sli4_hba.mbx_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002448 /* Sanity check */
2449 rc = lpfc_idiag_que_param_check(
2450 phba->sli4_hba.mbx_cq, index, count);
2451 if (rc)
2452 goto error_out;
2453 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2454 goto pass_check;
2455 }
2456 /* ELS complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002457 if (phba->sli4_hba.els_cq &&
2458 phba->sli4_hba.els_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002459 /* Sanity check */
2460 rc = lpfc_idiag_que_param_check(
2461 phba->sli4_hba.els_cq, index, count);
2462 if (rc)
2463 goto error_out;
2464 idiag.ptr_private = phba->sli4_hba.els_cq;
2465 goto pass_check;
2466 }
2467 /* FCP complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002468 if (phba->sli4_hba.fcp_cq) {
2469 qidx = 0;
2470 do {
2471 if (phba->sli4_hba.fcp_cq[qidx] &&
2472 phba->sli4_hba.fcp_cq[qidx]->queue_id ==
2473 queid) {
2474 /* Sanity check */
2475 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002476 phba->sli4_hba.fcp_cq[qidx],
2477 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002478 if (rc)
2479 goto error_out;
2480 idiag.ptr_private =
James Smart86a80842011-04-16 11:03:04 -04002481 phba->sli4_hba.fcp_cq[qidx];
James Smart2e90f4b2011-12-13 13:22:37 -05002482 goto pass_check;
2483 }
2484 } while (++qidx < phba->cfg_fcp_eq_count);
2485 }
James Smart86a80842011-04-16 11:03:04 -04002486 goto error_out;
2487 break;
2488 case LPFC_IDIAG_MQ:
2489 /* MBX work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002490 if (phba->sli4_hba.mbx_wq &&
2491 phba->sli4_hba.mbx_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002492 /* Sanity check */
2493 rc = lpfc_idiag_que_param_check(
2494 phba->sli4_hba.mbx_wq, index, count);
2495 if (rc)
2496 goto error_out;
2497 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2498 goto pass_check;
2499 }
James Smart2e90f4b2011-12-13 13:22:37 -05002500 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04002501 break;
2502 case LPFC_IDIAG_WQ:
2503 /* ELS work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002504 if (phba->sli4_hba.els_wq &&
2505 phba->sli4_hba.els_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002506 /* Sanity check */
2507 rc = lpfc_idiag_que_param_check(
2508 phba->sli4_hba.els_wq, index, count);
2509 if (rc)
2510 goto error_out;
2511 idiag.ptr_private = phba->sli4_hba.els_wq;
2512 goto pass_check;
2513 }
2514 /* FCP work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002515 if (phba->sli4_hba.fcp_wq) {
2516 for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
2517 if (!phba->sli4_hba.fcp_wq[qidx])
2518 continue;
2519 if (phba->sli4_hba.fcp_wq[qidx]->queue_id ==
2520 queid) {
2521 /* Sanity check */
2522 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002523 phba->sli4_hba.fcp_wq[qidx],
2524 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002525 if (rc)
2526 goto error_out;
2527 idiag.ptr_private =
2528 phba->sli4_hba.fcp_wq[qidx];
2529 goto pass_check;
2530 }
James Smart86a80842011-04-16 11:03:04 -04002531 }
2532 }
2533 goto error_out;
2534 break;
2535 case LPFC_IDIAG_RQ:
2536 /* HDR queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002537 if (phba->sli4_hba.hdr_rq &&
2538 phba->sli4_hba.hdr_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002539 /* Sanity check */
2540 rc = lpfc_idiag_que_param_check(
2541 phba->sli4_hba.hdr_rq, index, count);
2542 if (rc)
2543 goto error_out;
2544 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2545 goto pass_check;
2546 }
2547 /* DAT queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002548 if (phba->sli4_hba.dat_rq &&
2549 phba->sli4_hba.dat_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002550 /* Sanity check */
2551 rc = lpfc_idiag_que_param_check(
2552 phba->sli4_hba.dat_rq, index, count);
2553 if (rc)
2554 goto error_out;
2555 idiag.ptr_private = phba->sli4_hba.dat_rq;
2556 goto pass_check;
2557 }
2558 goto error_out;
2559 break;
2560 default:
2561 goto error_out;
2562 break;
2563 }
2564
2565pass_check:
2566
2567 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2568 if (count == LPFC_QUE_ACC_BROWSE)
2569 idiag.offset.last_rd = index;
2570 }
2571
2572 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2573 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2574 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2575 /* Additional sanity checks on write operation */
2576 pque = (struct lpfc_queue *)idiag.ptr_private;
2577 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2578 goto error_out;
2579 pentry = pque->qe[index].address;
2580 pentry += offset;
2581 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2582 *pentry = value;
2583 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2584 *pentry |= value;
2585 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2586 *pentry &= ~value;
2587 }
2588 return nbytes;
2589
2590error_out:
2591 /* Clean out command structure on command error out */
2592 memset(&idiag, 0, sizeof(idiag));
2593 return -EINVAL;
2594}
2595
2596/**
2597 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2598 * @phba: The pointer to hba structure.
2599 * @pbuffer: The pointer to the buffer to copy the data to.
2600 * @len: The lenght of bytes to copied.
2601 * @drbregid: The id to doorbell registers.
2602 *
2603 * Description:
2604 * This routine reads a doorbell register and copies its content to the
2605 * user buffer pointed to by @pbuffer.
2606 *
2607 * Returns:
2608 * This function returns the amount of data that was copied into @pbuffer.
2609 **/
2610static int
2611lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2612 int len, uint32_t drbregid)
2613{
2614
2615 if (!pbuffer)
2616 return 0;
2617
2618 switch (drbregid) {
2619 case LPFC_DRB_EQCQ:
2620 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2621 "EQCQ-DRB-REG: 0x%08x\n",
2622 readl(phba->sli4_hba.EQCQDBregaddr));
2623 break;
2624 case LPFC_DRB_MQ:
2625 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2626 "MQ-DRB-REG: 0x%08x\n",
2627 readl(phba->sli4_hba.MQDBregaddr));
2628 break;
2629 case LPFC_DRB_WQ:
2630 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2631 "WQ-DRB-REG: 0x%08x\n",
2632 readl(phba->sli4_hba.WQDBregaddr));
2633 break;
2634 case LPFC_DRB_RQ:
2635 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2636 "RQ-DRB-REG: 0x%08x\n",
2637 readl(phba->sli4_hba.RQDBregaddr));
2638 break;
2639 default:
2640 break;
2641 }
2642
2643 return len;
2644}
2645
2646/**
2647 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2648 * @file: The file pointer to read from.
2649 * @buf: The buffer to copy the data to.
2650 * @nbytes: The number of bytes to read.
2651 * @ppos: The position in the file to start reading from.
2652 *
2653 * Description:
2654 * This routine reads data from the @phba device doorbell register according
2655 * to the idiag command, and copies to user @buf. Depending on the doorbell
2656 * register read command setup, it does either a single doorbell register
2657 * read or dump all doorbell registers.
2658 *
2659 * Returns:
2660 * This function returns the amount of data that was read (this could be less
2661 * than @nbytes if the end of the file was reached) or a negative error value.
2662 **/
2663static ssize_t
2664lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2665 loff_t *ppos)
2666{
2667 struct lpfc_debug *debug = file->private_data;
2668 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2669 uint32_t drb_reg_id, i;
2670 char *pbuffer;
2671 int len = 0;
2672
2673 /* This is a user read operation */
2674 debug->op = LPFC_IDIAG_OP_RD;
2675
2676 if (!debug->buffer)
2677 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2678 if (!debug->buffer)
2679 return 0;
2680 pbuffer = debug->buffer;
2681
2682 if (*ppos)
2683 return 0;
2684
2685 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
James Smartb76f2dc2011-07-22 18:37:42 -04002686 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
James Smart86a80842011-04-16 11:03:04 -04002687 else
2688 return 0;
2689
2690 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2691 for (i = 1; i <= LPFC_DRB_MAX; i++)
2692 len = lpfc_idiag_drbacc_read_reg(phba,
2693 pbuffer, len, i);
2694 else
2695 len = lpfc_idiag_drbacc_read_reg(phba,
2696 pbuffer, len, drb_reg_id);
2697
2698 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2699}
2700
2701/**
2702 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2703 * @file: The file pointer to read from.
2704 * @buf: The buffer to copy the user data from.
2705 * @nbytes: The number of bytes to get.
2706 * @ppos: The position in the file to start reading from.
2707 *
2708 * This routine get the debugfs idiag command struct from user space and then
2709 * perform the syntax check for port doorbell register read (dump) or write
2710 * (set) command accordingly. In the case of port queue read command, it sets
2711 * up the command in the idiag command struct for the following debugfs read
2712 * operation. In the case of port doorbell register write operation, it
2713 * executes the write operation into the port doorbell register accordingly.
2714 *
2715 * It returns the @nbytges passing in from debugfs user space when successful.
2716 * In case of error conditions, it returns proper error code back to the user
2717 * space.
2718 **/
2719static ssize_t
2720lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2721 size_t nbytes, loff_t *ppos)
2722{
2723 struct lpfc_debug *debug = file->private_data;
2724 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
James Smartb76f2dc2011-07-22 18:37:42 -04002725 uint32_t drb_reg_id, value, reg_val = 0;
James Smart86a80842011-04-16 11:03:04 -04002726 void __iomem *drb_reg;
2727 int rc;
2728
2729 /* This is a user write operation */
2730 debug->op = LPFC_IDIAG_OP_WR;
2731
2732 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2733 if (rc < 0)
2734 return rc;
2735
2736 /* Sanity check on command line arguments */
James Smartb76f2dc2011-07-22 18:37:42 -04002737 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2738 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04002739
2740 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2741 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2742 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2743 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2744 goto error_out;
2745 if (drb_reg_id > LPFC_DRB_MAX)
2746 goto error_out;
2747 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2748 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2749 goto error_out;
2750 if ((drb_reg_id > LPFC_DRB_MAX) &&
2751 (drb_reg_id != LPFC_DRB_ACC_ALL))
2752 goto error_out;
2753 } else
2754 goto error_out;
2755
2756 /* Perform the write access operation */
2757 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2758 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2759 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2760 switch (drb_reg_id) {
2761 case LPFC_DRB_EQCQ:
2762 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2763 break;
2764 case LPFC_DRB_MQ:
2765 drb_reg = phba->sli4_hba.MQDBregaddr;
2766 break;
2767 case LPFC_DRB_WQ:
2768 drb_reg = phba->sli4_hba.WQDBregaddr;
2769 break;
2770 case LPFC_DRB_RQ:
2771 drb_reg = phba->sli4_hba.RQDBregaddr;
2772 break;
2773 default:
2774 goto error_out;
2775 }
2776
2777 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2778 reg_val = value;
2779 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2780 reg_val = readl(drb_reg);
2781 reg_val |= value;
2782 }
2783 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2784 reg_val = readl(drb_reg);
2785 reg_val &= ~value;
2786 }
2787 writel(reg_val, drb_reg);
2788 readl(drb_reg); /* flush */
2789 }
2790 return nbytes;
2791
2792error_out:
2793 /* Clean out command structure on command error out */
2794 memset(&idiag, 0, sizeof(idiag));
2795 return -EINVAL;
2796}
2797
James Smartb76f2dc2011-07-22 18:37:42 -04002798/**
2799 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2800 * @phba: The pointer to hba structure.
2801 * @pbuffer: The pointer to the buffer to copy the data to.
2802 * @len: The lenght of bytes to copied.
2803 * @drbregid: The id to doorbell registers.
2804 *
2805 * Description:
2806 * This routine reads a control register and copies its content to the
2807 * user buffer pointed to by @pbuffer.
2808 *
2809 * Returns:
2810 * This function returns the amount of data that was copied into @pbuffer.
2811 **/
2812static int
2813lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2814 int len, uint32_t ctlregid)
2815{
2816
2817 if (!pbuffer)
2818 return 0;
2819
2820 switch (ctlregid) {
2821 case LPFC_CTL_PORT_SEM:
2822 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2823 "Port SemReg: 0x%08x\n",
2824 readl(phba->sli4_hba.conf_regs_memmap_p +
2825 LPFC_CTL_PORT_SEM_OFFSET));
2826 break;
2827 case LPFC_CTL_PORT_STA:
2828 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2829 "Port StaReg: 0x%08x\n",
2830 readl(phba->sli4_hba.conf_regs_memmap_p +
2831 LPFC_CTL_PORT_STA_OFFSET));
2832 break;
2833 case LPFC_CTL_PORT_CTL:
2834 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2835 "Port CtlReg: 0x%08x\n",
2836 readl(phba->sli4_hba.conf_regs_memmap_p +
2837 LPFC_CTL_PORT_CTL_OFFSET));
2838 break;
2839 case LPFC_CTL_PORT_ER1:
2840 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2841 "Port Er1Reg: 0x%08x\n",
2842 readl(phba->sli4_hba.conf_regs_memmap_p +
2843 LPFC_CTL_PORT_ER1_OFFSET));
2844 break;
2845 case LPFC_CTL_PORT_ER2:
2846 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2847 "Port Er2Reg: 0x%08x\n",
2848 readl(phba->sli4_hba.conf_regs_memmap_p +
2849 LPFC_CTL_PORT_ER2_OFFSET));
2850 break;
2851 case LPFC_CTL_PDEV_CTL:
2852 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2853 "PDev CtlReg: 0x%08x\n",
2854 readl(phba->sli4_hba.conf_regs_memmap_p +
2855 LPFC_CTL_PDEV_CTL_OFFSET));
2856 break;
2857 default:
2858 break;
2859 }
2860 return len;
2861}
2862
2863/**
2864 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2865 * @file: The file pointer to read from.
2866 * @buf: The buffer to copy the data to.
2867 * @nbytes: The number of bytes to read.
2868 * @ppos: The position in the file to start reading from.
2869 *
2870 * Description:
2871 * This routine reads data from the @phba port and device registers according
2872 * to the idiag command, and copies to user @buf.
2873 *
2874 * Returns:
2875 * This function returns the amount of data that was read (this could be less
2876 * than @nbytes if the end of the file was reached) or a negative error value.
2877 **/
2878static ssize_t
2879lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2880 loff_t *ppos)
2881{
2882 struct lpfc_debug *debug = file->private_data;
2883 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2884 uint32_t ctl_reg_id, i;
2885 char *pbuffer;
2886 int len = 0;
2887
2888 /* This is a user read operation */
2889 debug->op = LPFC_IDIAG_OP_RD;
2890
2891 if (!debug->buffer)
2892 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2893 if (!debug->buffer)
2894 return 0;
2895 pbuffer = debug->buffer;
2896
2897 if (*ppos)
2898 return 0;
2899
2900 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2901 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2902 else
2903 return 0;
2904
2905 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2906 for (i = 1; i <= LPFC_CTL_MAX; i++)
2907 len = lpfc_idiag_ctlacc_read_reg(phba,
2908 pbuffer, len, i);
2909 else
2910 len = lpfc_idiag_ctlacc_read_reg(phba,
2911 pbuffer, len, ctl_reg_id);
2912
2913 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2914}
2915
2916/**
2917 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2918 * @file: The file pointer to read from.
2919 * @buf: The buffer to copy the user data from.
2920 * @nbytes: The number of bytes to get.
2921 * @ppos: The position in the file to start reading from.
2922 *
2923 * This routine get the debugfs idiag command struct from user space and then
2924 * perform the syntax check for port and device control register read (dump)
2925 * or write (set) command accordingly.
2926 *
2927 * It returns the @nbytges passing in from debugfs user space when successful.
2928 * In case of error conditions, it returns proper error code back to the user
2929 * space.
2930 **/
2931static ssize_t
2932lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
2933 size_t nbytes, loff_t *ppos)
2934{
2935 struct lpfc_debug *debug = file->private_data;
2936 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2937 uint32_t ctl_reg_id, value, reg_val = 0;
2938 void __iomem *ctl_reg;
2939 int rc;
2940
2941 /* This is a user write operation */
2942 debug->op = LPFC_IDIAG_OP_WR;
2943
2944 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2945 if (rc < 0)
2946 return rc;
2947
2948 /* Sanity check on command line arguments */
2949 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2950 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
2951
2952 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2953 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2954 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2955 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
2956 goto error_out;
2957 if (ctl_reg_id > LPFC_CTL_MAX)
2958 goto error_out;
2959 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
2960 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
2961 goto error_out;
2962 if ((ctl_reg_id > LPFC_CTL_MAX) &&
2963 (ctl_reg_id != LPFC_CTL_ACC_ALL))
2964 goto error_out;
2965 } else
2966 goto error_out;
2967
2968 /* Perform the write access operation */
2969 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2970 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2971 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2972 switch (ctl_reg_id) {
2973 case LPFC_CTL_PORT_SEM:
2974 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2975 LPFC_CTL_PORT_SEM_OFFSET;
2976 break;
2977 case LPFC_CTL_PORT_STA:
2978 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2979 LPFC_CTL_PORT_STA_OFFSET;
2980 break;
2981 case LPFC_CTL_PORT_CTL:
2982 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2983 LPFC_CTL_PORT_CTL_OFFSET;
2984 break;
2985 case LPFC_CTL_PORT_ER1:
2986 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2987 LPFC_CTL_PORT_ER1_OFFSET;
2988 break;
2989 case LPFC_CTL_PORT_ER2:
2990 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2991 LPFC_CTL_PORT_ER2_OFFSET;
2992 break;
2993 case LPFC_CTL_PDEV_CTL:
2994 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2995 LPFC_CTL_PDEV_CTL_OFFSET;
2996 break;
2997 default:
2998 goto error_out;
2999 }
3000
3001 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
3002 reg_val = value;
3003 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
3004 reg_val = readl(ctl_reg);
3005 reg_val |= value;
3006 }
3007 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3008 reg_val = readl(ctl_reg);
3009 reg_val &= ~value;
3010 }
3011 writel(reg_val, ctl_reg);
3012 readl(ctl_reg); /* flush */
3013 }
3014 return nbytes;
3015
3016error_out:
3017 /* Clean out command structure on command error out */
3018 memset(&idiag, 0, sizeof(idiag));
3019 return -EINVAL;
3020}
3021
3022/**
3023 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
3024 * @phba: Pointer to HBA context object.
3025 * @pbuffer: Pointer to data buffer.
3026 *
3027 * Description:
3028 * This routine gets the driver mailbox access debugfs setup information.
3029 *
3030 * Returns:
3031 * This function returns the amount of data that was read (this could be less
3032 * than @nbytes if the end of the file was reached) or a negative error value.
3033 **/
3034static int
3035lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
3036{
3037 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3038 int len = 0;
3039
3040 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3041 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3042 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3043 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3044
3045 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3046 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
3047 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3048 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
3049 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3050 "mbx_word_cnt: %04d\n", mbx_word_cnt);
3051 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3052 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
3053
3054 return len;
3055}
3056
3057/**
3058 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
3059 * @file: The file pointer to read from.
3060 * @buf: The buffer to copy the data to.
3061 * @nbytes: The number of bytes to read.
3062 * @ppos: The position in the file to start reading from.
3063 *
3064 * Description:
3065 * This routine reads data from the @phba driver mailbox access debugfs setup
3066 * information.
3067 *
3068 * Returns:
3069 * This function returns the amount of data that was read (this could be less
3070 * than @nbytes if the end of the file was reached) or a negative error value.
3071 **/
3072static ssize_t
3073lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
3074 loff_t *ppos)
3075{
3076 struct lpfc_debug *debug = file->private_data;
3077 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3078 char *pbuffer;
3079 int len = 0;
3080
3081 /* This is a user read operation */
3082 debug->op = LPFC_IDIAG_OP_RD;
3083
3084 if (!debug->buffer)
3085 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
3086 if (!debug->buffer)
3087 return 0;
3088 pbuffer = debug->buffer;
3089
3090 if (*ppos)
3091 return 0;
3092
3093 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
3094 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
3095 return 0;
3096
3097 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
3098
3099 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3100}
3101
3102/**
3103 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
3104 * @file: The file pointer to read from.
3105 * @buf: The buffer to copy the user data from.
3106 * @nbytes: The number of bytes to get.
3107 * @ppos: The position in the file to start reading from.
3108 *
3109 * This routine get the debugfs idiag command struct from user space and then
3110 * perform the syntax check for driver mailbox command (dump) and sets up the
3111 * necessary states in the idiag command struct accordingly.
3112 *
3113 * It returns the @nbytges passing in from debugfs user space when successful.
3114 * In case of error conditions, it returns proper error code back to the user
3115 * space.
3116 **/
3117static ssize_t
3118lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
3119 size_t nbytes, loff_t *ppos)
3120{
3121 struct lpfc_debug *debug = file->private_data;
3122 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3123 int rc;
3124
3125 /* This is a user write operation */
3126 debug->op = LPFC_IDIAG_OP_WR;
3127
3128 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3129 if (rc < 0)
3130 return rc;
3131
3132 /* Sanity check on command line arguments */
3133 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3134 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3135 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3136 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3137
3138 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
3139 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
3140 goto error_out;
3141 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
3142 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3143 goto error_out;
3144 if (mbx_word_cnt > sizeof(MAILBOX_t))
3145 goto error_out;
3146 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
3147 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
3148 goto error_out;
3149 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
3150 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3151 goto error_out;
3152 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3153 goto error_out;
3154 if (mbx_mbox_cmd != 0x9b)
3155 goto error_out;
3156 } else
3157 goto error_out;
3158
3159 if (mbx_word_cnt == 0)
3160 goto error_out;
3161 if (rc != LPFC_MBX_DMP_ARG)
3162 goto error_out;
3163 if (mbx_mbox_cmd & ~0xff)
3164 goto error_out;
3165
3166 /* condition for stop mailbox dump */
3167 if (mbx_dump_cnt == 0)
3168 goto reset_out;
3169
3170 return nbytes;
3171
3172reset_out:
3173 /* Clean out command structure on command error out */
3174 memset(&idiag, 0, sizeof(idiag));
3175 return nbytes;
3176
3177error_out:
3178 /* Clean out command structure on command error out */
3179 memset(&idiag, 0, sizeof(idiag));
3180 return -EINVAL;
3181}
3182
3183/**
3184 * lpfc_idiag_extacc_avail_get - get the available extents information
3185 * @phba: pointer to lpfc hba data structure.
3186 * @pbuffer: pointer to internal buffer.
3187 * @len: length into the internal buffer data has been copied.
3188 *
3189 * Description:
3190 * This routine is to get the available extent information.
3191 *
3192 * Returns:
3193 * overall lenth of the data read into the internal buffer.
3194 **/
3195static int
3196lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3197{
3198 uint16_t ext_cnt, ext_size;
3199
3200 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3201 "\nAvailable Extents Information:\n");
3202
3203 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3204 "\tPort Available VPI extents: ");
3205 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3206 &ext_cnt, &ext_size);
3207 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3208 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3209
3210 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3211 "\tPort Available VFI extents: ");
3212 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3213 &ext_cnt, &ext_size);
3214 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3215 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3216
3217 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3218 "\tPort Available RPI extents: ");
3219 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3220 &ext_cnt, &ext_size);
3221 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3222 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3223
3224 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3225 "\tPort Available XRI extents: ");
3226 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3227 &ext_cnt, &ext_size);
3228 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3229 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3230
3231 return len;
3232}
3233
3234/**
3235 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3236 * @phba: pointer to lpfc hba data structure.
3237 * @pbuffer: pointer to internal buffer.
3238 * @len: length into the internal buffer data has been copied.
3239 *
3240 * Description:
3241 * This routine is to get the allocated extent information.
3242 *
3243 * Returns:
3244 * overall lenth of the data read into the internal buffer.
3245 **/
3246static int
3247lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3248{
3249 uint16_t ext_cnt, ext_size;
3250 int rc;
3251
3252 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3253 "\nAllocated Extents Information:\n");
3254
3255 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3256 "\tHost Allocated VPI extents: ");
3257 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
3258 &ext_cnt, &ext_size);
3259 if (!rc)
3260 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3261 "Port %d Extent %3d, Size %3d\n",
3262 phba->brd_no, ext_cnt, ext_size);
3263 else
3264 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3265 "N/A\n");
3266
3267 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3268 "\tHost Allocated VFI extents: ");
3269 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
3270 &ext_cnt, &ext_size);
3271 if (!rc)
3272 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3273 "Port %d Extent %3d, Size %3d\n",
3274 phba->brd_no, ext_cnt, ext_size);
3275 else
3276 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3277 "N/A\n");
3278
3279 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3280 "\tHost Allocated RPI extents: ");
3281 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
3282 &ext_cnt, &ext_size);
3283 if (!rc)
3284 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3285 "Port %d Extent %3d, Size %3d\n",
3286 phba->brd_no, ext_cnt, ext_size);
3287 else
3288 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3289 "N/A\n");
3290
3291 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3292 "\tHost Allocated XRI extents: ");
3293 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
3294 &ext_cnt, &ext_size);
3295 if (!rc)
3296 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3297 "Port %d Extent %3d, Size %3d\n",
3298 phba->brd_no, ext_cnt, ext_size);
3299 else
3300 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3301 "N/A\n");
3302
3303 return len;
3304}
3305
3306/**
3307 * lpfc_idiag_extacc_drivr_get - get driver extent information
3308 * @phba: pointer to lpfc hba data structure.
3309 * @pbuffer: pointer to internal buffer.
3310 * @len: length into the internal buffer data has been copied.
3311 *
3312 * Description:
3313 * This routine is to get the driver extent information.
3314 *
3315 * Returns:
3316 * overall lenth of the data read into the internal buffer.
3317 **/
3318static int
3319lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3320{
3321 struct lpfc_rsrc_blks *rsrc_blks;
3322 int index;
3323
3324 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3325 "\nDriver Extents Information:\n");
3326
3327 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3328 "\tVPI extents:\n");
3329 index = 0;
3330 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3331 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3332 "\t\tBlock %3d: Start %4d, Count %4d\n",
3333 index, rsrc_blks->rsrc_start,
3334 rsrc_blks->rsrc_size);
3335 index++;
3336 }
3337 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3338 "\tVFI extents:\n");
3339 index = 0;
3340 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
3341 list) {
3342 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3343 "\t\tBlock %3d: Start %4d, Count %4d\n",
3344 index, rsrc_blks->rsrc_start,
3345 rsrc_blks->rsrc_size);
3346 index++;
3347 }
3348
3349 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3350 "\tRPI extents:\n");
3351 index = 0;
3352 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
3353 list) {
3354 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3355 "\t\tBlock %3d: Start %4d, Count %4d\n",
3356 index, rsrc_blks->rsrc_start,
3357 rsrc_blks->rsrc_size);
3358 index++;
3359 }
3360
3361 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3362 "\tXRI extents:\n");
3363 index = 0;
3364 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
3365 list) {
3366 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3367 "\t\tBlock %3d: Start %4d, Count %4d\n",
3368 index, rsrc_blks->rsrc_start,
3369 rsrc_blks->rsrc_size);
3370 index++;
3371 }
3372
3373 return len;
3374}
3375
3376/**
3377 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3378 * @file: The file pointer to read from.
3379 * @buf: The buffer to copy the user data from.
3380 * @nbytes: The number of bytes to get.
3381 * @ppos: The position in the file to start reading from.
3382 *
3383 * This routine get the debugfs idiag command struct from user space and then
3384 * perform the syntax check for extent information access commands and sets
3385 * up the necessary states in the idiag command struct accordingly.
3386 *
3387 * It returns the @nbytges passing in from debugfs user space when successful.
3388 * In case of error conditions, it returns proper error code back to the user
3389 * space.
3390 **/
3391static ssize_t
3392lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3393 size_t nbytes, loff_t *ppos)
3394{
3395 struct lpfc_debug *debug = file->private_data;
3396 uint32_t ext_map;
3397 int rc;
3398
3399 /* This is a user write operation */
3400 debug->op = LPFC_IDIAG_OP_WR;
3401
3402 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3403 if (rc < 0)
3404 return rc;
3405
3406 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3407
3408 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3409 goto error_out;
3410 if (rc != LPFC_EXT_ACC_CMD_ARG)
3411 goto error_out;
3412 if (!(ext_map & LPFC_EXT_ACC_ALL))
3413 goto error_out;
3414
3415 return nbytes;
3416error_out:
3417 /* Clean out command structure on command error out */
3418 memset(&idiag, 0, sizeof(idiag));
3419 return -EINVAL;
3420}
3421
3422/**
3423 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3424 * @file: The file pointer to read from.
3425 * @buf: The buffer to copy the data to.
3426 * @nbytes: The number of bytes to read.
3427 * @ppos: The position in the file to start reading from.
3428 *
3429 * Description:
3430 * This routine reads data from the proper extent information according to
3431 * the idiag command, and copies to user @buf.
3432 *
3433 * Returns:
3434 * This function returns the amount of data that was read (this could be less
3435 * than @nbytes if the end of the file was reached) or a negative error value.
3436 **/
3437static ssize_t
3438lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3439 loff_t *ppos)
3440{
3441 struct lpfc_debug *debug = file->private_data;
3442 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3443 char *pbuffer;
3444 uint32_t ext_map;
3445 int len = 0;
3446
3447 /* This is a user read operation */
3448 debug->op = LPFC_IDIAG_OP_RD;
3449
3450 if (!debug->buffer)
3451 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3452 if (!debug->buffer)
3453 return 0;
3454 pbuffer = debug->buffer;
3455 if (*ppos)
3456 return 0;
3457 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3458 return 0;
3459
3460 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3461 if (ext_map & LPFC_EXT_ACC_AVAIL)
3462 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3463 if (ext_map & LPFC_EXT_ACC_ALLOC)
3464 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3465 if (ext_map & LPFC_EXT_ACC_DRIVR)
3466 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3467
3468 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3469}
3470
James Smart858c9f62007-06-17 19:56:39 -05003471#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003472static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05003473 .owner = THIS_MODULE,
3474 .open = lpfc_debugfs_disc_trc_open,
3475 .llseek = lpfc_debugfs_lseek,
3476 .read = lpfc_debugfs_read,
3477 .release = lpfc_debugfs_release,
3478};
3479
3480#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003481static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05003482 .owner = THIS_MODULE,
3483 .open = lpfc_debugfs_nodelist_open,
3484 .llseek = lpfc_debugfs_lseek,
3485 .read = lpfc_debugfs_read,
3486 .release = lpfc_debugfs_release,
3487};
3488
James Smart78b2d852007-08-02 11:10:21 -04003489#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003490static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04003491 .owner = THIS_MODULE,
3492 .open = lpfc_debugfs_hbqinfo_open,
3493 .llseek = lpfc_debugfs_lseek,
3494 .read = lpfc_debugfs_read,
3495 .release = lpfc_debugfs_release,
3496};
3497
James Smartc95d6c62008-01-11 01:53:23 -05003498#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003499static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04003500 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05003501 .open = lpfc_debugfs_dumpHBASlim_open,
3502 .llseek = lpfc_debugfs_lseek,
3503 .read = lpfc_debugfs_read,
3504 .release = lpfc_debugfs_release,
3505};
3506
3507#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003508static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05003509 .owner = THIS_MODULE,
3510 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04003511 .llseek = lpfc_debugfs_lseek,
3512 .read = lpfc_debugfs_read,
3513 .release = lpfc_debugfs_release,
3514};
3515
James Smarte2a0a9d2008-12-04 22:40:02 -05003516#undef lpfc_debugfs_op_dumpData
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003517static const struct file_operations lpfc_debugfs_op_dumpData = {
James Smarte2a0a9d2008-12-04 22:40:02 -05003518 .owner = THIS_MODULE,
3519 .open = lpfc_debugfs_dumpData_open,
3520 .llseek = lpfc_debugfs_lseek,
3521 .read = lpfc_debugfs_read,
3522 .write = lpfc_debugfs_dumpDataDif_write,
3523 .release = lpfc_debugfs_dumpDataDif_release,
3524};
3525
3526#undef lpfc_debugfs_op_dumpDif
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003527static const struct file_operations lpfc_debugfs_op_dumpDif = {
James Smarte2a0a9d2008-12-04 22:40:02 -05003528 .owner = THIS_MODULE,
3529 .open = lpfc_debugfs_dumpDif_open,
3530 .llseek = lpfc_debugfs_lseek,
3531 .read = lpfc_debugfs_read,
3532 .write = lpfc_debugfs_dumpDataDif_write,
3533 .release = lpfc_debugfs_dumpDataDif_release,
3534};
3535
James Smartf9bb2da2011-10-10 21:34:11 -04003536#undef lpfc_debugfs_op_dif_err
3537static const struct file_operations lpfc_debugfs_op_dif_err = {
3538 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07003539 .open = simple_open,
James Smartf9bb2da2011-10-10 21:34:11 -04003540 .llseek = lpfc_debugfs_lseek,
3541 .read = lpfc_debugfs_dif_err_read,
3542 .write = lpfc_debugfs_dif_err_write,
3543 .release = lpfc_debugfs_dif_err_release,
3544};
3545
James Smarta58cbd52007-08-02 11:09:43 -04003546#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003547static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04003548 .owner = THIS_MODULE,
3549 .open = lpfc_debugfs_slow_ring_trc_open,
3550 .llseek = lpfc_debugfs_lseek,
3551 .read = lpfc_debugfs_read,
3552 .release = lpfc_debugfs_release,
3553};
3554
James Smart858c9f62007-06-17 19:56:39 -05003555static struct dentry *lpfc_debugfs_root = NULL;
3556static atomic_t lpfc_debugfs_hba_count;
James Smart2a622bf2011-02-16 12:40:06 -05003557
3558/*
3559 * File operations for the iDiag debugfs
3560 */
3561#undef lpfc_idiag_op_pciCfg
3562static const struct file_operations lpfc_idiag_op_pciCfg = {
3563 .owner = THIS_MODULE,
3564 .open = lpfc_idiag_open,
3565 .llseek = lpfc_debugfs_lseek,
3566 .read = lpfc_idiag_pcicfg_read,
3567 .write = lpfc_idiag_pcicfg_write,
3568 .release = lpfc_idiag_cmd_release,
3569};
3570
James Smartb76f2dc2011-07-22 18:37:42 -04003571#undef lpfc_idiag_op_barAcc
3572static const struct file_operations lpfc_idiag_op_barAcc = {
3573 .owner = THIS_MODULE,
3574 .open = lpfc_idiag_open,
3575 .llseek = lpfc_debugfs_lseek,
3576 .read = lpfc_idiag_baracc_read,
3577 .write = lpfc_idiag_baracc_write,
3578 .release = lpfc_idiag_cmd_release,
3579};
3580
James Smart2a622bf2011-02-16 12:40:06 -05003581#undef lpfc_idiag_op_queInfo
3582static const struct file_operations lpfc_idiag_op_queInfo = {
3583 .owner = THIS_MODULE,
3584 .open = lpfc_idiag_open,
3585 .read = lpfc_idiag_queinfo_read,
3586 .release = lpfc_idiag_release,
3587};
3588
James Smartb76f2dc2011-07-22 18:37:42 -04003589#undef lpfc_idiag_op_queAcc
James Smart86a80842011-04-16 11:03:04 -04003590static const struct file_operations lpfc_idiag_op_queAcc = {
3591 .owner = THIS_MODULE,
3592 .open = lpfc_idiag_open,
3593 .llseek = lpfc_debugfs_lseek,
3594 .read = lpfc_idiag_queacc_read,
3595 .write = lpfc_idiag_queacc_write,
3596 .release = lpfc_idiag_cmd_release,
3597};
3598
James Smartb76f2dc2011-07-22 18:37:42 -04003599#undef lpfc_idiag_op_drbAcc
James Smart86a80842011-04-16 11:03:04 -04003600static const struct file_operations lpfc_idiag_op_drbAcc = {
3601 .owner = THIS_MODULE,
3602 .open = lpfc_idiag_open,
3603 .llseek = lpfc_debugfs_lseek,
3604 .read = lpfc_idiag_drbacc_read,
3605 .write = lpfc_idiag_drbacc_write,
3606 .release = lpfc_idiag_cmd_release,
3607};
3608
James Smartb76f2dc2011-07-22 18:37:42 -04003609#undef lpfc_idiag_op_ctlAcc
3610static const struct file_operations lpfc_idiag_op_ctlAcc = {
3611 .owner = THIS_MODULE,
3612 .open = lpfc_idiag_open,
3613 .llseek = lpfc_debugfs_lseek,
3614 .read = lpfc_idiag_ctlacc_read,
3615 .write = lpfc_idiag_ctlacc_write,
3616 .release = lpfc_idiag_cmd_release,
3617};
3618
3619#undef lpfc_idiag_op_mbxAcc
3620static const struct file_operations lpfc_idiag_op_mbxAcc = {
3621 .owner = THIS_MODULE,
3622 .open = lpfc_idiag_open,
3623 .llseek = lpfc_debugfs_lseek,
3624 .read = lpfc_idiag_mbxacc_read,
3625 .write = lpfc_idiag_mbxacc_write,
3626 .release = lpfc_idiag_cmd_release,
3627};
3628
3629#undef lpfc_idiag_op_extAcc
3630static const struct file_operations lpfc_idiag_op_extAcc = {
3631 .owner = THIS_MODULE,
3632 .open = lpfc_idiag_open,
3633 .llseek = lpfc_debugfs_lseek,
3634 .read = lpfc_idiag_extacc_read,
3635 .write = lpfc_idiag_extacc_write,
3636 .release = lpfc_idiag_cmd_release,
3637};
3638
James Smart858c9f62007-06-17 19:56:39 -05003639#endif
3640
James Smartb76f2dc2011-07-22 18:37:42 -04003641/* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3642 * @phba: Pointer to HBA context object.
3643 * @dmabuf: Pointer to a DMA buffer descriptor.
3644 *
3645 * Description:
3646 * This routine dump a bsg pass-through non-embedded mailbox command with
3647 * external buffer.
3648 **/
3649void
3650lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3651 enum mbox_type mbox_tp, enum dma_type dma_tp,
3652 enum sta_type sta_tp,
3653 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3654{
3655#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3656 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3657 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3658 int len = 0;
3659 uint32_t do_dump = 0;
3660 uint32_t *pword;
3661 uint32_t i;
3662
3663 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3664 return;
3665
3666 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3667 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3668 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3669 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3670
3671 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3672 (*mbx_dump_cnt == 0) ||
3673 (*mbx_word_cnt == 0))
3674 return;
3675
3676 if (*mbx_mbox_cmd != 0x9B)
3677 return;
3678
3679 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3680 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3681 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
3682 printk(KERN_ERR "\nRead mbox command (x%x), "
3683 "nemb:0x%x, extbuf_cnt:%d:\n",
3684 sta_tp, nemb_tp, ext_buf);
3685 }
3686 }
3687 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3688 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3689 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
3690 printk(KERN_ERR "\nRead mbox buffer (x%x), "
3691 "nemb:0x%x, extbuf_seq:%d:\n",
3692 sta_tp, nemb_tp, ext_buf);
3693 }
3694 }
3695 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3696 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3697 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
3698 printk(KERN_ERR "\nWrite mbox command (x%x), "
3699 "nemb:0x%x, extbuf_cnt:%d:\n",
3700 sta_tp, nemb_tp, ext_buf);
3701 }
3702 }
3703 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3704 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3705 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
3706 printk(KERN_ERR "\nWrite mbox buffer (x%x), "
3707 "nemb:0x%x, extbuf_seq:%d:\n",
3708 sta_tp, nemb_tp, ext_buf);
3709 }
3710 }
3711
3712 /* dump buffer content */
3713 if (do_dump) {
3714 pword = (uint32_t *)dmabuf->virt;
3715 for (i = 0; i < *mbx_word_cnt; i++) {
3716 if (!(i % 8)) {
3717 if (i != 0)
3718 printk(KERN_ERR "%s\n", line_buf);
3719 len = 0;
3720 len += snprintf(line_buf+len,
3721 LPFC_MBX_ACC_LBUF_SZ-len,
3722 "%03d: ", i);
3723 }
3724 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3725 "%08x ", (uint32_t)*pword);
3726 pword++;
3727 }
3728 if ((i - 1) % 8)
3729 printk(KERN_ERR "%s\n", line_buf);
3730 (*mbx_dump_cnt)--;
3731 }
3732
3733 /* Clean out command structure on reaching dump count */
3734 if (*mbx_dump_cnt == 0)
3735 memset(&idiag, 0, sizeof(idiag));
3736 return;
3737#endif
3738}
3739
3740/* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3741 * @phba: Pointer to HBA context object.
3742 * @dmabuf: Pointer to a DMA buffer descriptor.
3743 *
3744 * Description:
3745 * This routine dump a pass-through non-embedded mailbox command from issue
3746 * mailbox command.
3747 **/
3748void
3749lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3750{
3751#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3752 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3753 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3754 int len = 0;
3755 uint32_t *pword;
3756 uint8_t *pbyte;
3757 uint32_t i, j;
3758
3759 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3760 return;
3761
3762 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3763 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3764 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3765 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3766
3767 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3768 (*mbx_dump_cnt == 0) ||
3769 (*mbx_word_cnt == 0))
3770 return;
3771
3772 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3773 (*mbx_mbox_cmd != pmbox->mbxCommand))
3774 return;
3775
3776 /* dump buffer content */
3777 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
3778 printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
3779 pmbox->mbxCommand);
3780 pword = (uint32_t *)pmbox;
3781 for (i = 0; i < *mbx_word_cnt; i++) {
3782 if (!(i % 8)) {
3783 if (i != 0)
3784 printk(KERN_ERR "%s\n", line_buf);
3785 len = 0;
3786 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3787 len += snprintf(line_buf+len,
3788 LPFC_MBX_ACC_LBUF_SZ-len,
3789 "%03d: ", i);
3790 }
3791 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3792 "%08x ",
3793 ((uint32_t)*pword) & 0xffffffff);
3794 pword++;
3795 }
3796 if ((i - 1) % 8)
3797 printk(KERN_ERR "%s\n", line_buf);
3798 printk(KERN_ERR "\n");
3799 }
3800 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
3801 printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
3802 pmbox->mbxCommand);
3803 pbyte = (uint8_t *)pmbox;
3804 for (i = 0; i < *mbx_word_cnt; i++) {
3805 if (!(i % 8)) {
3806 if (i != 0)
3807 printk(KERN_ERR "%s\n", line_buf);
3808 len = 0;
3809 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3810 len += snprintf(line_buf+len,
3811 LPFC_MBX_ACC_LBUF_SZ-len,
3812 "%03d: ", i);
3813 }
3814 for (j = 0; j < 4; j++) {
3815 len += snprintf(line_buf+len,
3816 LPFC_MBX_ACC_LBUF_SZ-len,
3817 "%02x",
3818 ((uint8_t)*pbyte) & 0xff);
3819 pbyte++;
3820 }
3821 len += snprintf(line_buf+len,
3822 LPFC_MBX_ACC_LBUF_SZ-len, " ");
3823 }
3824 if ((i - 1) % 8)
3825 printk(KERN_ERR "%s\n", line_buf);
3826 printk(KERN_ERR "\n");
3827 }
3828 (*mbx_dump_cnt)--;
3829
3830 /* Clean out command structure on reaching dump count */
3831 if (*mbx_dump_cnt == 0)
3832 memset(&idiag, 0, sizeof(idiag));
3833 return;
3834#endif
3835}
3836
James Smarte59058c2008-08-24 21:49:00 -04003837/**
James Smart3621a712009-04-06 18:47:14 -04003838 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04003839 * @vport: The vport pointer to initialize.
3840 *
3841 * Description:
3842 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3843 * If not already created, this routine will create the lpfc directory, and
3844 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3845 * also create each file used to access lpfc specific debugfs information.
3846 **/
James Smart858c9f62007-06-17 19:56:39 -05003847inline void
3848lpfc_debugfs_initialize(struct lpfc_vport *vport)
3849{
James Smart923e4b62008-12-04 22:40:07 -05003850#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05003851 struct lpfc_hba *phba = vport->phba;
3852 char name[64];
3853 uint32_t num, i;
3854
3855 if (!lpfc_debugfs_enable)
3856 return;
3857
James Smarta58cbd52007-08-02 11:09:43 -04003858 /* Setup lpfc root directory */
3859 if (!lpfc_debugfs_root) {
3860 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
3861 atomic_set(&lpfc_debugfs_hba_count, 0);
3862 if (!lpfc_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04003863 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003864 "0408 Cannot create debugfs root\n");
James Smarta58cbd52007-08-02 11:09:43 -04003865 goto debug_failed;
3866 }
3867 }
James Smarta58cbd52007-08-02 11:09:43 -04003868 if (!lpfc_debugfs_start_time)
3869 lpfc_debugfs_start_time = jiffies;
3870
James Smart2a622bf2011-02-16 12:40:06 -05003871 /* Setup funcX directory for specific HBA PCI function */
3872 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
James Smarta58cbd52007-08-02 11:09:43 -04003873 if (!phba->hba_debugfs_root) {
3874 phba->hba_debugfs_root =
3875 debugfs_create_dir(name, lpfc_debugfs_root);
3876 if (!phba->hba_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04003877 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003878 "0412 Cannot create debugfs hba\n");
James Smarta58cbd52007-08-02 11:09:43 -04003879 goto debug_failed;
3880 }
3881 atomic_inc(&lpfc_debugfs_hba_count);
3882 atomic_set(&phba->debugfs_vport_count, 0);
3883
James Smart78b2d852007-08-02 11:10:21 -04003884 /* Setup hbqinfo */
3885 snprintf(name, sizeof(name), "hbqinfo");
3886 phba->debug_hbqinfo =
3887 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3888 phba->hba_debugfs_root,
3889 phba, &lpfc_debugfs_op_hbqinfo);
3890 if (!phba->debug_hbqinfo) {
3891 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003892 "0411 Cannot create debugfs hbqinfo\n");
James Smart78b2d852007-08-02 11:10:21 -04003893 goto debug_failed;
3894 }
3895
James Smartc95d6c62008-01-11 01:53:23 -05003896 /* Setup dumpHBASlim */
James Smart2a622bf2011-02-16 12:40:06 -05003897 if (phba->sli_rev < LPFC_SLI_REV4) {
3898 snprintf(name, sizeof(name), "dumpHBASlim");
3899 phba->debug_dumpHBASlim =
3900 debugfs_create_file(name,
3901 S_IFREG|S_IRUGO|S_IWUSR,
3902 phba->hba_debugfs_root,
3903 phba, &lpfc_debugfs_op_dumpHBASlim);
3904 if (!phba->debug_dumpHBASlim) {
3905 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3906 "0413 Cannot create debugfs "
3907 "dumpHBASlim\n");
3908 goto debug_failed;
3909 }
3910 } else
3911 phba->debug_dumpHBASlim = NULL;
James Smartc95d6c62008-01-11 01:53:23 -05003912
3913 /* Setup dumpHostSlim */
James Smart2a622bf2011-02-16 12:40:06 -05003914 if (phba->sli_rev < LPFC_SLI_REV4) {
3915 snprintf(name, sizeof(name), "dumpHostSlim");
3916 phba->debug_dumpHostSlim =
3917 debugfs_create_file(name,
3918 S_IFREG|S_IRUGO|S_IWUSR,
3919 phba->hba_debugfs_root,
3920 phba, &lpfc_debugfs_op_dumpHostSlim);
3921 if (!phba->debug_dumpHostSlim) {
3922 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3923 "0414 Cannot create debugfs "
3924 "dumpHostSlim\n");
3925 goto debug_failed;
3926 }
3927 } else
3928 phba->debug_dumpHBASlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04003929
James Smarte2a0a9d2008-12-04 22:40:02 -05003930 /* Setup dumpData */
3931 snprintf(name, sizeof(name), "dumpData");
3932 phba->debug_dumpData =
3933 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3934 phba->hba_debugfs_root,
3935 phba, &lpfc_debugfs_op_dumpData);
3936 if (!phba->debug_dumpData) {
3937 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3938 "0800 Cannot create debugfs dumpData\n");
3939 goto debug_failed;
3940 }
3941
3942 /* Setup dumpDif */
3943 snprintf(name, sizeof(name), "dumpDif");
3944 phba->debug_dumpDif =
3945 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3946 phba->hba_debugfs_root,
3947 phba, &lpfc_debugfs_op_dumpDif);
3948 if (!phba->debug_dumpDif) {
3949 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3950 "0801 Cannot create debugfs dumpDif\n");
3951 goto debug_failed;
3952 }
3953
James Smartf9bb2da2011-10-10 21:34:11 -04003954 /* Setup DIF Error Injections */
3955 snprintf(name, sizeof(name), "InjErrLBA");
3956 phba->debug_InjErrLBA =
3957 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3958 phba->hba_debugfs_root,
3959 phba, &lpfc_debugfs_op_dif_err);
3960 if (!phba->debug_InjErrLBA) {
3961 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3962 "0807 Cannot create debugfs InjErrLBA\n");
3963 goto debug_failed;
3964 }
3965 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
3966
James Smart4ac9b222012-03-01 22:38:29 -05003967 snprintf(name, sizeof(name), "InjErrNPortID");
3968 phba->debug_InjErrNPortID =
3969 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3970 phba->hba_debugfs_root,
3971 phba, &lpfc_debugfs_op_dif_err);
3972 if (!phba->debug_InjErrNPortID) {
3973 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3974 "0809 Cannot create debugfs InjErrNPortID\n");
3975 goto debug_failed;
3976 }
3977
3978 snprintf(name, sizeof(name), "InjErrWWPN");
3979 phba->debug_InjErrWWPN =
3980 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3981 phba->hba_debugfs_root,
3982 phba, &lpfc_debugfs_op_dif_err);
3983 if (!phba->debug_InjErrWWPN) {
3984 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3985 "0810 Cannot create debugfs InjErrWWPN\n");
3986 goto debug_failed;
3987 }
3988
James Smartf9bb2da2011-10-10 21:34:11 -04003989 snprintf(name, sizeof(name), "writeGuardInjErr");
3990 phba->debug_writeGuard =
3991 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3992 phba->hba_debugfs_root,
3993 phba, &lpfc_debugfs_op_dif_err);
3994 if (!phba->debug_writeGuard) {
3995 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3996 "0802 Cannot create debugfs writeGuard\n");
3997 goto debug_failed;
3998 }
3999
4000 snprintf(name, sizeof(name), "writeAppInjErr");
4001 phba->debug_writeApp =
4002 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4003 phba->hba_debugfs_root,
4004 phba, &lpfc_debugfs_op_dif_err);
4005 if (!phba->debug_writeApp) {
4006 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4007 "0803 Cannot create debugfs writeApp\n");
4008 goto debug_failed;
4009 }
4010
4011 snprintf(name, sizeof(name), "writeRefInjErr");
4012 phba->debug_writeRef =
4013 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4014 phba->hba_debugfs_root,
4015 phba, &lpfc_debugfs_op_dif_err);
4016 if (!phba->debug_writeRef) {
4017 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4018 "0804 Cannot create debugfs writeRef\n");
4019 goto debug_failed;
4020 }
4021
James Smartacd68592012-01-18 16:25:09 -05004022 snprintf(name, sizeof(name), "readGuardInjErr");
4023 phba->debug_readGuard =
4024 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4025 phba->hba_debugfs_root,
4026 phba, &lpfc_debugfs_op_dif_err);
4027 if (!phba->debug_readGuard) {
4028 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4029 "0808 Cannot create debugfs readGuard\n");
4030 goto debug_failed;
4031 }
4032
James Smartf9bb2da2011-10-10 21:34:11 -04004033 snprintf(name, sizeof(name), "readAppInjErr");
4034 phba->debug_readApp =
4035 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4036 phba->hba_debugfs_root,
4037 phba, &lpfc_debugfs_op_dif_err);
4038 if (!phba->debug_readApp) {
4039 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4040 "0805 Cannot create debugfs readApp\n");
4041 goto debug_failed;
4042 }
4043
4044 snprintf(name, sizeof(name), "readRefInjErr");
4045 phba->debug_readRef =
4046 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4047 phba->hba_debugfs_root,
4048 phba, &lpfc_debugfs_op_dif_err);
4049 if (!phba->debug_readRef) {
4050 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4051 "0806 Cannot create debugfs readApp\n");
4052 goto debug_failed;
4053 }
4054
James Smarta58cbd52007-08-02 11:09:43 -04004055 /* Setup slow ring trace */
4056 if (lpfc_debugfs_max_slow_ring_trc) {
4057 num = lpfc_debugfs_max_slow_ring_trc - 1;
4058 if (num & lpfc_debugfs_max_slow_ring_trc) {
4059 /* Change to be a power of 2 */
4060 num = lpfc_debugfs_max_slow_ring_trc;
4061 i = 0;
4062 while (num > 1) {
4063 num = num >> 1;
4064 i++;
4065 }
4066 lpfc_debugfs_max_slow_ring_trc = (1 << i);
4067 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04004068 "lpfc_debugfs_max_disc_trc changed to "
4069 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04004070 }
4071 }
4072
James Smarta58cbd52007-08-02 11:09:43 -04004073 snprintf(name, sizeof(name), "slow_ring_trace");
4074 phba->debug_slow_ring_trc =
4075 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4076 phba->hba_debugfs_root,
4077 phba, &lpfc_debugfs_op_slow_ring_trc);
4078 if (!phba->debug_slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004079 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004080 "0415 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004081 "slow_ring_trace\n");
James Smarta58cbd52007-08-02 11:09:43 -04004082 goto debug_failed;
4083 }
4084 if (!phba->slow_ring_trc) {
4085 phba->slow_ring_trc = kmalloc(
4086 (sizeof(struct lpfc_debugfs_trc) *
4087 lpfc_debugfs_max_slow_ring_trc),
4088 GFP_KERNEL);
4089 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004090 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004091 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004092 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04004093 goto debug_failed;
4094 }
4095 atomic_set(&phba->slow_ring_trc_cnt, 0);
4096 memset(phba->slow_ring_trc, 0,
4097 (sizeof(struct lpfc_debugfs_trc) *
4098 lpfc_debugfs_max_slow_ring_trc));
4099 }
4100 }
4101
4102 snprintf(name, sizeof(name), "vport%d", vport->vpi);
4103 if (!vport->vport_debugfs_root) {
4104 vport->vport_debugfs_root =
4105 debugfs_create_dir(name, phba->hba_debugfs_root);
4106 if (!vport->vport_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04004107 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004108 "0417 Can't create debugfs\n");
James Smarta58cbd52007-08-02 11:09:43 -04004109 goto debug_failed;
4110 }
4111 atomic_inc(&phba->debugfs_vport_count);
4112 }
4113
James Smart858c9f62007-06-17 19:56:39 -05004114 if (lpfc_debugfs_max_disc_trc) {
4115 num = lpfc_debugfs_max_disc_trc - 1;
4116 if (num & lpfc_debugfs_max_disc_trc) {
4117 /* Change to be a power of 2 */
4118 num = lpfc_debugfs_max_disc_trc;
4119 i = 0;
4120 while (num > 1) {
4121 num = num >> 1;
4122 i++;
4123 }
4124 lpfc_debugfs_max_disc_trc = (1 << i);
4125 printk(KERN_ERR
James Smarte8b62012007-08-02 11:10:09 -04004126 "lpfc_debugfs_max_disc_trc changed to %d\n",
4127 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05004128 }
4129 }
4130
Adrian Bunkff86ba52007-10-18 12:52:37 +02004131 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04004132 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05004133 GFP_KERNEL);
4134
James Smarta58cbd52007-08-02 11:09:43 -04004135 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004136 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004137 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04004138 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05004139 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04004140 }
4141 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05004142
4143 snprintf(name, sizeof(name), "discovery_trace");
4144 vport->debug_disc_trc =
4145 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4146 vport->vport_debugfs_root,
4147 vport, &lpfc_debugfs_op_disc_trc);
4148 if (!vport->debug_disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004149 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004150 "0419 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004151 "discovery_trace\n");
James Smart858c9f62007-06-17 19:56:39 -05004152 goto debug_failed;
4153 }
4154 snprintf(name, sizeof(name), "nodelist");
4155 vport->debug_nodelist =
4156 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4157 vport->vport_debugfs_root,
4158 vport, &lpfc_debugfs_op_nodelist);
4159 if (!vport->debug_nodelist) {
James Smarte8b62012007-08-02 11:10:09 -04004160 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartb76f2dc2011-07-22 18:37:42 -04004161 "2985 Can't create debugfs nodelist\n");
James Smart858c9f62007-06-17 19:56:39 -05004162 goto debug_failed;
4163 }
James Smart2a622bf2011-02-16 12:40:06 -05004164
4165 /*
4166 * iDiag debugfs root entry points for SLI4 device only
4167 */
4168 if (phba->sli_rev < LPFC_SLI_REV4)
4169 goto debug_failed;
4170
4171 snprintf(name, sizeof(name), "iDiag");
4172 if (!phba->idiag_root) {
4173 phba->idiag_root =
4174 debugfs_create_dir(name, phba->hba_debugfs_root);
4175 if (!phba->idiag_root) {
4176 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4177 "2922 Can't create idiag debugfs\n");
4178 goto debug_failed;
4179 }
4180 /* Initialize iDiag data structure */
4181 memset(&idiag, 0, sizeof(idiag));
4182 }
4183
4184 /* iDiag read PCI config space */
4185 snprintf(name, sizeof(name), "pciCfg");
4186 if (!phba->idiag_pci_cfg) {
4187 phba->idiag_pci_cfg =
4188 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4189 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
4190 if (!phba->idiag_pci_cfg) {
4191 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4192 "2923 Can't create idiag debugfs\n");
4193 goto debug_failed;
4194 }
4195 idiag.offset.last_rd = 0;
4196 }
4197
James Smartb76f2dc2011-07-22 18:37:42 -04004198 /* iDiag PCI BAR access */
4199 snprintf(name, sizeof(name), "barAcc");
4200 if (!phba->idiag_bar_acc) {
4201 phba->idiag_bar_acc =
4202 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4203 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
4204 if (!phba->idiag_bar_acc) {
4205 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4206 "3056 Can't create idiag debugfs\n");
4207 goto debug_failed;
4208 }
4209 idiag.offset.last_rd = 0;
4210 }
4211
James Smart2a622bf2011-02-16 12:40:06 -05004212 /* iDiag get PCI function queue information */
4213 snprintf(name, sizeof(name), "queInfo");
4214 if (!phba->idiag_que_info) {
4215 phba->idiag_que_info =
4216 debugfs_create_file(name, S_IFREG|S_IRUGO,
4217 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
4218 if (!phba->idiag_que_info) {
4219 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4220 "2924 Can't create idiag debugfs\n");
4221 goto debug_failed;
4222 }
4223 }
4224
James Smart86a80842011-04-16 11:03:04 -04004225 /* iDiag access PCI function queue */
4226 snprintf(name, sizeof(name), "queAcc");
4227 if (!phba->idiag_que_acc) {
4228 phba->idiag_que_acc =
4229 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4230 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
4231 if (!phba->idiag_que_acc) {
4232 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4233 "2926 Can't create idiag debugfs\n");
4234 goto debug_failed;
4235 }
4236 }
4237
4238 /* iDiag access PCI function doorbell registers */
4239 snprintf(name, sizeof(name), "drbAcc");
4240 if (!phba->idiag_drb_acc) {
4241 phba->idiag_drb_acc =
4242 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4243 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
4244 if (!phba->idiag_drb_acc) {
4245 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4246 "2927 Can't create idiag debugfs\n");
4247 goto debug_failed;
4248 }
4249 }
4250
James Smartb76f2dc2011-07-22 18:37:42 -04004251 /* iDiag access PCI function control registers */
4252 snprintf(name, sizeof(name), "ctlAcc");
4253 if (!phba->idiag_ctl_acc) {
4254 phba->idiag_ctl_acc =
4255 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4256 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
4257 if (!phba->idiag_ctl_acc) {
4258 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4259 "2981 Can't create idiag debugfs\n");
4260 goto debug_failed;
4261 }
4262 }
4263
4264 /* iDiag access mbox commands */
4265 snprintf(name, sizeof(name), "mbxAcc");
4266 if (!phba->idiag_mbx_acc) {
4267 phba->idiag_mbx_acc =
4268 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4269 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
4270 if (!phba->idiag_mbx_acc) {
4271 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4272 "2980 Can't create idiag debugfs\n");
4273 goto debug_failed;
4274 }
4275 }
4276
4277 /* iDiag extents access commands */
4278 if (phba->sli4_hba.extents_in_use) {
4279 snprintf(name, sizeof(name), "extAcc");
4280 if (!phba->idiag_ext_acc) {
4281 phba->idiag_ext_acc =
4282 debugfs_create_file(name,
4283 S_IFREG|S_IRUGO|S_IWUSR,
4284 phba->idiag_root, phba,
4285 &lpfc_idiag_op_extAcc);
4286 if (!phba->idiag_ext_acc) {
4287 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4288 "2986 Cant create "
4289 "idiag debugfs\n");
4290 goto debug_failed;
4291 }
4292 }
4293 }
4294
James Smart858c9f62007-06-17 19:56:39 -05004295debug_failed:
4296 return;
4297#endif
4298}
4299
James Smarte59058c2008-08-24 21:49:00 -04004300/**
James Smart3621a712009-04-06 18:47:14 -04004301 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04004302 * @vport: The vport pointer to remove from debugfs.
4303 *
4304 * Description:
4305 * When Debugfs is configured this routine removes debugfs file system elements
4306 * that are specific to this vport. It also checks to see if there are any
4307 * users left for the debugfs directories associated with the HBA and driver. If
4308 * this is the last user of the HBA directory or driver directory then it will
4309 * remove those from the debugfs infrastructure as well.
4310 **/
James Smart858c9f62007-06-17 19:56:39 -05004311inline void
4312lpfc_debugfs_terminate(struct lpfc_vport *vport)
4313{
James Smart923e4b62008-12-04 22:40:07 -05004314#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05004315 struct lpfc_hba *phba = vport->phba;
4316
4317 if (vport->disc_trc) {
4318 kfree(vport->disc_trc);
4319 vport->disc_trc = NULL;
4320 }
4321 if (vport->debug_disc_trc) {
4322 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
4323 vport->debug_disc_trc = NULL;
4324 }
4325 if (vport->debug_nodelist) {
4326 debugfs_remove(vport->debug_nodelist); /* nodelist */
4327 vport->debug_nodelist = NULL;
4328 }
4329 if (vport->vport_debugfs_root) {
4330 debugfs_remove(vport->vport_debugfs_root); /* vportX */
4331 vport->vport_debugfs_root = NULL;
4332 atomic_dec(&phba->debugfs_vport_count);
4333 }
4334 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04004335
James Smart78b2d852007-08-02 11:10:21 -04004336 if (phba->debug_hbqinfo) {
4337 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
4338 phba->debug_hbqinfo = NULL;
4339 }
James Smartc95d6c62008-01-11 01:53:23 -05004340 if (phba->debug_dumpHBASlim) {
4341 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
4342 phba->debug_dumpHBASlim = NULL;
4343 }
4344 if (phba->debug_dumpHostSlim) {
4345 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
4346 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04004347 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004348 if (phba->debug_dumpData) {
4349 debugfs_remove(phba->debug_dumpData); /* dumpData */
4350 phba->debug_dumpData = NULL;
4351 }
4352
4353 if (phba->debug_dumpDif) {
4354 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
4355 phba->debug_dumpDif = NULL;
4356 }
James Smartf9bb2da2011-10-10 21:34:11 -04004357 if (phba->debug_InjErrLBA) {
4358 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
4359 phba->debug_InjErrLBA = NULL;
4360 }
James Smart4ac9b222012-03-01 22:38:29 -05004361 if (phba->debug_InjErrNPortID) { /* InjErrNPortID */
4362 debugfs_remove(phba->debug_InjErrNPortID);
4363 phba->debug_InjErrNPortID = NULL;
4364 }
4365 if (phba->debug_InjErrWWPN) {
4366 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
4367 phba->debug_InjErrWWPN = NULL;
4368 }
James Smartf9bb2da2011-10-10 21:34:11 -04004369 if (phba->debug_writeGuard) {
4370 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
4371 phba->debug_writeGuard = NULL;
4372 }
4373 if (phba->debug_writeApp) {
4374 debugfs_remove(phba->debug_writeApp); /* writeApp */
4375 phba->debug_writeApp = NULL;
4376 }
4377 if (phba->debug_writeRef) {
4378 debugfs_remove(phba->debug_writeRef); /* writeRef */
4379 phba->debug_writeRef = NULL;
4380 }
James Smartacd68592012-01-18 16:25:09 -05004381 if (phba->debug_readGuard) {
4382 debugfs_remove(phba->debug_readGuard); /* readGuard */
4383 phba->debug_readGuard = NULL;
4384 }
James Smartf9bb2da2011-10-10 21:34:11 -04004385 if (phba->debug_readApp) {
4386 debugfs_remove(phba->debug_readApp); /* readApp */
4387 phba->debug_readApp = NULL;
4388 }
4389 if (phba->debug_readRef) {
4390 debugfs_remove(phba->debug_readRef); /* readRef */
4391 phba->debug_readRef = NULL;
4392 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004393
James Smarta58cbd52007-08-02 11:09:43 -04004394 if (phba->slow_ring_trc) {
4395 kfree(phba->slow_ring_trc);
4396 phba->slow_ring_trc = NULL;
4397 }
4398 if (phba->debug_slow_ring_trc) {
4399 /* slow_ring_trace */
4400 debugfs_remove(phba->debug_slow_ring_trc);
4401 phba->debug_slow_ring_trc = NULL;
4402 }
4403
James Smart2a622bf2011-02-16 12:40:06 -05004404 /*
4405 * iDiag release
4406 */
4407 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartb76f2dc2011-07-22 18:37:42 -04004408 if (phba->idiag_ext_acc) {
4409 /* iDiag extAcc */
4410 debugfs_remove(phba->idiag_ext_acc);
4411 phba->idiag_ext_acc = NULL;
4412 }
4413 if (phba->idiag_mbx_acc) {
4414 /* iDiag mbxAcc */
4415 debugfs_remove(phba->idiag_mbx_acc);
4416 phba->idiag_mbx_acc = NULL;
4417 }
4418 if (phba->idiag_ctl_acc) {
4419 /* iDiag ctlAcc */
4420 debugfs_remove(phba->idiag_ctl_acc);
4421 phba->idiag_ctl_acc = NULL;
4422 }
James Smart86a80842011-04-16 11:03:04 -04004423 if (phba->idiag_drb_acc) {
4424 /* iDiag drbAcc */
4425 debugfs_remove(phba->idiag_drb_acc);
4426 phba->idiag_drb_acc = NULL;
4427 }
4428 if (phba->idiag_que_acc) {
4429 /* iDiag queAcc */
4430 debugfs_remove(phba->idiag_que_acc);
4431 phba->idiag_que_acc = NULL;
4432 }
James Smart2a622bf2011-02-16 12:40:06 -05004433 if (phba->idiag_que_info) {
4434 /* iDiag queInfo */
4435 debugfs_remove(phba->idiag_que_info);
4436 phba->idiag_que_info = NULL;
4437 }
James Smartb76f2dc2011-07-22 18:37:42 -04004438 if (phba->idiag_bar_acc) {
4439 /* iDiag barAcc */
4440 debugfs_remove(phba->idiag_bar_acc);
4441 phba->idiag_bar_acc = NULL;
4442 }
James Smart2a622bf2011-02-16 12:40:06 -05004443 if (phba->idiag_pci_cfg) {
4444 /* iDiag pciCfg */
4445 debugfs_remove(phba->idiag_pci_cfg);
4446 phba->idiag_pci_cfg = NULL;
4447 }
4448
4449 /* Finally remove the iDiag debugfs root */
4450 if (phba->idiag_root) {
4451 /* iDiag root */
4452 debugfs_remove(phba->idiag_root);
4453 phba->idiag_root = NULL;
4454 }
4455 }
4456
James Smarta58cbd52007-08-02 11:09:43 -04004457 if (phba->hba_debugfs_root) {
James Smart2a622bf2011-02-16 12:40:06 -05004458 debugfs_remove(phba->hba_debugfs_root); /* fnX */
James Smarta58cbd52007-08-02 11:09:43 -04004459 phba->hba_debugfs_root = NULL;
4460 atomic_dec(&lpfc_debugfs_hba_count);
4461 }
4462
James Smart858c9f62007-06-17 19:56:39 -05004463 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
4464 debugfs_remove(lpfc_debugfs_root); /* lpfc */
4465 lpfc_debugfs_root = NULL;
4466 }
4467 }
4468#endif
James Smarta58cbd52007-08-02 11:09:43 -04004469 return;
James Smart858c9f62007-06-17 19:56:39 -05004470}
James Smart809c7532012-05-09 21:19:25 -04004471
4472/*
4473 * Driver debug utility routines outside of debugfs. The debug utility
4474 * routines implemented here is intended to be used in the instrumented
4475 * debug driver for debugging host or port issues.
4476 */
4477
4478/**
4479 * lpfc_debug_dump_all_queues - dump all the queues with a hba
4480 * @phba: Pointer to HBA context object.
4481 *
4482 * This function dumps entries of all the queues asociated with the @phba.
4483 **/
4484void
4485lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
4486{
4487 int fcp_wqidx;
4488
4489 /*
4490 * Dump Work Queues (WQs)
4491 */
4492 lpfc_debug_dump_mbx_wq(phba);
4493 lpfc_debug_dump_els_wq(phba);
4494
4495 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++)
4496 lpfc_debug_dump_fcp_wq(phba, fcp_wqidx);
4497
4498 lpfc_debug_dump_hdr_rq(phba);
4499 lpfc_debug_dump_dat_rq(phba);
4500 /*
4501 * Dump Complete Queues (CQs)
4502 */
4503 lpfc_debug_dump_mbx_cq(phba);
4504 lpfc_debug_dump_els_cq(phba);
4505
4506 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++)
4507 lpfc_debug_dump_fcp_cq(phba, fcp_wqidx);
4508
4509 /*
4510 * Dump Event Queues (EQs)
4511 */
4512 lpfc_debug_dump_sp_eq(phba);
4513
4514 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++)
4515 lpfc_debug_dump_fcp_eq(phba, fcp_wqidx);
4516}