blob: 866361d4d637429f1e689a36d08f65c0e2ebee1a [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 Smartf25e8e72015-04-07 15:07:28 -04004 * Copyright (C) 2007-2015 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;
James Smarteb016562014-09-03 12:58:06 -0400272 int i, j, found, posted, low;
James Smart78b2d852007-08-02 11:10:21 -0400273 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 Smarteb016562014-09-03 12:58:06 -0400282
James Smart78b2d852007-08-02 11:10:21 -0400283 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;
James Smart2ea259e2017-02-12 13:52:27 -0800534 unsigned char *statep;
James Smart858c9f62007-06-17 19:56:39 -0500535
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;
James Smart086a3452012-08-14 14:25:21 -0400562 case NLP_STE_LOGO_ISSUE:
563 statep = "LOGO ";
564 break;
James Smart858c9f62007-06-17 19:56:39 -0500565 case NLP_STE_UNMAPPED_NODE:
566 statep = "UNMAP ";
567 break;
568 case NLP_STE_MAPPED_NODE:
569 statep = "MAPPED";
570 break;
571 case NLP_STE_NPR_NODE:
572 statep = "NPR ";
573 break;
574 default:
575 statep = "UNKNOWN";
576 }
James Smart2ea259e2017-02-12 13:52:27 -0800577 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
578 statep, ndlp->nlp_DID);
579 len += snprintf(buf+len, size-len,
580 "WWPN x%llx ",
581 wwn_to_u64(ndlp->nlp_portname.u.wwn));
582 len += snprintf(buf+len, size-len,
583 "WWNN x%llx ",
584 wwn_to_u64(ndlp->nlp_nodename.u.wwn));
James Smart086a3452012-08-14 14:25:21 -0400585 if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
James Smart2ea259e2017-02-12 13:52:27 -0800586 len += snprintf(buf+len, size-len, "RPI:%03d ",
587 ndlp->nlp_rpi);
James Smart086a3452012-08-14 14:25:21 -0400588 else
James Smart2ea259e2017-02-12 13:52:27 -0800589 len += snprintf(buf+len, size-len, "RPI:none ");
James Smart086a3452012-08-14 14:25:21 -0400590 len += snprintf(buf+len, size-len, "flag:x%08x ",
591 ndlp->nlp_flag);
James Smart858c9f62007-06-17 19:56:39 -0500592 if (!ndlp->nlp_type)
James Smart2ea259e2017-02-12 13:52:27 -0800593 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500594 if (ndlp->nlp_type & NLP_FC_NODE)
James Smart2ea259e2017-02-12 13:52:27 -0800595 len += snprintf(buf+len, size-len, "FC_NODE ");
James Smart858c9f62007-06-17 19:56:39 -0500596 if (ndlp->nlp_type & NLP_FABRIC)
James Smart2ea259e2017-02-12 13:52:27 -0800597 len += snprintf(buf+len, size-len, "FABRIC ");
James Smart858c9f62007-06-17 19:56:39 -0500598 if (ndlp->nlp_type & NLP_FCP_TARGET)
James Smart2ea259e2017-02-12 13:52:27 -0800599 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
James Smart858c9f62007-06-17 19:56:39 -0500600 ndlp->nlp_sid);
601 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
James Smart2ea259e2017-02-12 13:52:27 -0800602 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart58da1ff2008-04-07 10:15:56 -0400603 len += snprintf(buf+len, size-len, "usgmap:%x ",
604 ndlp->nlp_usg_map);
James Smarta58cbd52007-08-02 11:09:43 -0400605 len += snprintf(buf+len, size-len, "refcnt:%x",
Peter Zijlstra2c935bc2016-11-14 17:29:48 +0100606 kref_read(&ndlp->kref));
James Smart858c9f62007-06-17 19:56:39 -0500607 len += snprintf(buf+len, size-len, "\n");
608 }
609 spin_unlock_irq(shost->host_lock);
James Smart2ea259e2017-02-12 13:52:27 -0800610
James Smart858c9f62007-06-17 19:56:39 -0500611 return len;
612}
James Smart2ea259e2017-02-12 13:52:27 -0800613
James Smart858c9f62007-06-17 19:56:39 -0500614#endif
615
James Smarte59058c2008-08-24 21:49:00 -0400616/**
James Smart3621a712009-04-06 18:47:14 -0400617 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400618 * @vport: The vport to associate this trace string with for retrieval.
619 * @mask: Log entry classification.
620 * @fmt: Format string to be displayed when dumping the log.
621 * @data1: 1st data parameter to be applied to @fmt.
622 * @data2: 2nd data parameter to be applied to @fmt.
623 * @data3: 3rd data parameter to be applied to @fmt.
624 *
625 * Description:
626 * This routine is used by the driver code to add a debugfs log entry to the
627 * discovery trace buffer associated with @vport. Only entries with a @mask that
628 * match the current debugfs discovery mask will be saved. Entries that do not
629 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
630 * printf when displaying the log.
631 **/
James Smart858c9f62007-06-17 19:56:39 -0500632inline void
633lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
634 uint32_t data1, uint32_t data2, uint32_t data3)
635{
James Smart923e4b62008-12-04 22:40:07 -0500636#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400637 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -0500638 int index;
639
640 if (!(lpfc_debugfs_mask_disc_trc & mask))
641 return;
642
643 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
644 !vport || !vport->disc_trc)
645 return;
646
647 index = atomic_inc_return(&vport->disc_trc_cnt) &
648 (lpfc_debugfs_max_disc_trc - 1);
649 dtp = vport->disc_trc + index;
650 dtp->fmt = fmt;
651 dtp->data1 = data1;
652 dtp->data2 = data2;
653 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -0400654 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
655 dtp->jif = jiffies;
656#endif
657 return;
658}
659
James Smarte59058c2008-08-24 21:49:00 -0400660/**
James Smart3621a712009-04-06 18:47:14 -0400661 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400662 * @phba: The phba to associate this trace string with for retrieval.
663 * @fmt: Format string to be displayed when dumping the log.
664 * @data1: 1st data parameter to be applied to @fmt.
665 * @data2: 2nd data parameter to be applied to @fmt.
666 * @data3: 3rd data parameter to be applied to @fmt.
667 *
668 * Description:
669 * This routine is used by the driver code to add a debugfs log entry to the
670 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
671 * @data3 are used like printf when displaying the log.
672 **/
James Smarta58cbd52007-08-02 11:09:43 -0400673inline void
674lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
675 uint32_t data1, uint32_t data2, uint32_t data3)
676{
James Smart923e4b62008-12-04 22:40:07 -0500677#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -0400678 struct lpfc_debugfs_trc *dtp;
679 int index;
680
681 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
682 !phba || !phba->slow_ring_trc)
683 return;
684
685 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
686 (lpfc_debugfs_max_slow_ring_trc - 1);
687 dtp = phba->slow_ring_trc + index;
688 dtp->fmt = fmt;
689 dtp->data1 = data1;
690 dtp->data2 = data2;
691 dtp->data3 = data3;
692 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -0500693 dtp->jif = jiffies;
694#endif
695 return;
696}
697
James Smart923e4b62008-12-04 22:40:07 -0500698#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -0400699/**
James Smart3621a712009-04-06 18:47:14 -0400700 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -0400701 * @inode: The inode pointer that contains a vport pointer.
702 * @file: The file pointer to attach the log output.
703 *
704 * Description:
705 * This routine is the entry point for the debugfs open file operation. It gets
706 * the vport from the i_private field in @inode, allocates the necessary buffer
707 * for the log, fills the buffer from the in-memory log for this vport, and then
708 * returns a pointer to that log in the private_data field in @file.
709 *
710 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +0200711 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -0400712 * error value.
713 **/
James Smart858c9f62007-06-17 19:56:39 -0500714static int
715lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
716{
717 struct lpfc_vport *vport = inode->i_private;
718 struct lpfc_debug *debug;
719 int size;
720 int rc = -ENOMEM;
721
722 if (!lpfc_debugfs_max_disc_trc) {
723 rc = -ENOSPC;
724 goto out;
725 }
726
727 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
728 if (!debug)
729 goto out;
730
James Smarte59058c2008-08-24 21:49:00 -0400731 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400732 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -0500733 size = PAGE_ALIGN(size);
734
735 debug->buffer = kmalloc(size, GFP_KERNEL);
736 if (!debug->buffer) {
737 kfree(debug);
738 goto out;
739 }
740
741 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
742 file->private_data = debug;
743
744 rc = 0;
745out:
746 return rc;
747}
748
James Smarte59058c2008-08-24 21:49:00 -0400749/**
James Smart3621a712009-04-06 18:47:14 -0400750 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -0400751 * @inode: The inode pointer that contains a vport pointer.
752 * @file: The file pointer to attach the log output.
753 *
754 * Description:
755 * This routine is the entry point for the debugfs open file operation. It gets
756 * the vport from the i_private field in @inode, allocates the necessary buffer
757 * for the log, fills the buffer from the in-memory log for this vport, and then
758 * returns a pointer to that log in the private_data field in @file.
759 *
760 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +0200761 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -0400762 * error value.
763 **/
James Smart858c9f62007-06-17 19:56:39 -0500764static int
James Smarta58cbd52007-08-02 11:09:43 -0400765lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
766{
767 struct lpfc_hba *phba = inode->i_private;
768 struct lpfc_debug *debug;
769 int size;
770 int rc = -ENOMEM;
771
772 if (!lpfc_debugfs_max_slow_ring_trc) {
773 rc = -ENOSPC;
774 goto out;
775 }
776
777 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
778 if (!debug)
779 goto out;
780
James Smarte59058c2008-08-24 21:49:00 -0400781 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -0400782 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
783 size = PAGE_ALIGN(size);
784
785 debug->buffer = kmalloc(size, GFP_KERNEL);
786 if (!debug->buffer) {
787 kfree(debug);
788 goto out;
789 }
790
791 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
792 file->private_data = debug;
793
794 rc = 0;
795out:
796 return rc;
797}
798
James Smarte59058c2008-08-24 21:49:00 -0400799/**
James Smart3621a712009-04-06 18:47:14 -0400800 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400801 * @inode: The inode pointer that contains a vport pointer.
802 * @file: The file pointer to attach the log output.
803 *
804 * Description:
805 * This routine is the entry point for the debugfs open file operation. It gets
806 * the vport from the i_private field in @inode, allocates the necessary buffer
807 * for the log, fills the buffer from the in-memory log for this vport, and then
808 * returns a pointer to that log in the private_data field in @file.
809 *
810 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +0200811 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -0400812 * error value.
813 **/
James Smarta58cbd52007-08-02 11:09:43 -0400814static int
James Smart78b2d852007-08-02 11:10:21 -0400815lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
816{
817 struct lpfc_hba *phba = inode->i_private;
818 struct lpfc_debug *debug;
819 int rc = -ENOMEM;
820
821 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
822 if (!debug)
823 goto out;
824
James Smarte59058c2008-08-24 21:49:00 -0400825 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -0400826 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
827 if (!debug->buffer) {
828 kfree(debug);
829 goto out;
830 }
831
832 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
833 LPFC_HBQINFO_SIZE);
834 file->private_data = debug;
835
836 rc = 0;
837out:
838 return rc;
839}
840
James Smarte59058c2008-08-24 21:49:00 -0400841/**
James Smart3621a712009-04-06 18:47:14 -0400842 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400843 * @inode: The inode pointer that contains a vport pointer.
844 * @file: The file pointer to attach the log output.
845 *
846 * Description:
847 * This routine is the entry point for the debugfs open file operation. It gets
848 * the vport from the i_private field in @inode, allocates the necessary buffer
849 * for the log, fills the buffer from the in-memory log for this vport, and then
850 * returns a pointer to that log in the private_data field in @file.
851 *
852 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +0200853 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -0400854 * error value.
855 **/
James Smart78b2d852007-08-02 11:10:21 -0400856static int
James Smartc95d6c62008-01-11 01:53:23 -0500857lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -0400858{
859 struct lpfc_hba *phba = inode->i_private;
860 struct lpfc_debug *debug;
861 int rc = -ENOMEM;
862
863 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
864 if (!debug)
865 goto out;
866
James Smarte59058c2008-08-24 21:49:00 -0400867 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500868 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -0400869 if (!debug->buffer) {
870 kfree(debug);
871 goto out;
872 }
873
James Smartc95d6c62008-01-11 01:53:23 -0500874 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
875 LPFC_DUMPHBASLIM_SIZE);
876 file->private_data = debug;
877
878 rc = 0;
879out:
880 return rc;
881}
882
James Smarte59058c2008-08-24 21:49:00 -0400883/**
James Smart3621a712009-04-06 18:47:14 -0400884 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -0400885 * @inode: The inode pointer that contains a vport pointer.
886 * @file: The file pointer to attach the log output.
887 *
888 * Description:
889 * This routine is the entry point for the debugfs open file operation. It gets
890 * the vport from the i_private field in @inode, allocates the necessary buffer
891 * for the log, fills the buffer from the in-memory log for this vport, and then
892 * returns a pointer to that log in the private_data field in @file.
893 *
894 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +0200895 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -0400896 * error value.
897 **/
James Smartc95d6c62008-01-11 01:53:23 -0500898static int
899lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
900{
901 struct lpfc_hba *phba = inode->i_private;
902 struct lpfc_debug *debug;
903 int rc = -ENOMEM;
904
905 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
906 if (!debug)
907 goto out;
908
James Smarte59058c2008-08-24 21:49:00 -0400909 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -0500910 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
911 if (!debug->buffer) {
912 kfree(debug);
913 goto out;
914 }
915
916 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
917 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -0400918 file->private_data = debug;
919
920 rc = 0;
921out:
922 return rc;
923}
924
James Smarte2a0a9d2008-12-04 22:40:02 -0500925static int
926lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
927{
928 struct lpfc_debug *debug;
929 int rc = -ENOMEM;
930
931 if (!_dump_buf_data)
932 return -EBUSY;
933
934 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
935 if (!debug)
936 goto out;
937
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300938 /* Round to page boundary */
James Smart2ea259e2017-02-12 13:52:27 -0800939 pr_err("9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
James Smarte2a0a9d2008-12-04 22:40:02 -0500940 __func__, _dump_buf_data);
941 debug->buffer = _dump_buf_data;
942 if (!debug->buffer) {
943 kfree(debug);
944 goto out;
945 }
946
947 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
948 file->private_data = debug;
949
950 rc = 0;
951out:
952 return rc;
953}
954
955static int
956lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
957{
958 struct lpfc_debug *debug;
959 int rc = -ENOMEM;
960
961 if (!_dump_buf_dif)
962 return -EBUSY;
963
964 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
965 if (!debug)
966 goto out;
967
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300968 /* Round to page boundary */
James Smart2ea259e2017-02-12 13:52:27 -0800969 pr_err("9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%pD\n",
970 __func__, _dump_buf_dif, file);
James Smarte2a0a9d2008-12-04 22:40:02 -0500971 debug->buffer = _dump_buf_dif;
972 if (!debug->buffer) {
973 kfree(debug);
974 goto out;
975 }
976
977 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
978 file->private_data = debug;
979
980 rc = 0;
981out:
982 return rc;
983}
984
985static ssize_t
986lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
987 size_t nbytes, loff_t *ppos)
988{
989 /*
990 * The Data/DIF buffers only save one failing IO
991 * The write op is used as a reset mechanism after an IO has
992 * already been saved to the next one can be saved
993 */
994 spin_lock(&_dump_buf_lock);
995
996 memset((void *)_dump_buf_data, 0,
997 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
998 memset((void *)_dump_buf_dif, 0,
999 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
1000
1001 _dump_buf_done = 0;
1002
1003 spin_unlock(&_dump_buf_lock);
1004
1005 return nbytes;
1006}
1007
James Smartf9bb2da2011-10-10 21:34:11 -04001008static ssize_t
1009lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1010 size_t nbytes, loff_t *ppos)
1011{
Al Virob5830432014-10-31 01:22:04 -04001012 struct dentry *dent = file->f_path.dentry;
James Smartf9bb2da2011-10-10 21:34:11 -04001013 struct lpfc_hba *phba = file->private_data;
James Smart9a6b09c2012-03-01 22:37:42 -05001014 char cbuf[32];
James Smart4ac9b222012-03-01 22:38:29 -05001015 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04001016 int cnt = 0;
1017
1018 if (dent == phba->debug_writeGuard)
James Smart9a6b09c2012-03-01 22:37:42 -05001019 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001020 else if (dent == phba->debug_writeApp)
James Smart9a6b09c2012-03-01 22:37:42 -05001021 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001022 else if (dent == phba->debug_writeRef)
James Smart9a6b09c2012-03-01 22:37:42 -05001023 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
James Smartacd68592012-01-18 16:25:09 -05001024 else if (dent == phba->debug_readGuard)
James Smart9a6b09c2012-03-01 22:37:42 -05001025 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001026 else if (dent == phba->debug_readApp)
James Smart9a6b09c2012-03-01 22:37:42 -05001027 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04001028 else if (dent == phba->debug_readRef)
James Smart9a6b09c2012-03-01 22:37:42 -05001029 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
James Smart4ac9b222012-03-01 22:38:29 -05001030 else if (dent == phba->debug_InjErrNPortID)
1031 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1032 else if (dent == phba->debug_InjErrWWPN) {
1033 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1034 tmp = cpu_to_be64(tmp);
1035 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1036 } else if (dent == phba->debug_InjErrLBA) {
1037 if (phba->lpfc_injerr_lba == (sector_t)(-1))
James Smart9a6b09c2012-03-01 22:37:42 -05001038 cnt = snprintf(cbuf, 32, "off\n");
1039 else
James Smart4ac9b222012-03-01 22:38:29 -05001040 cnt = snprintf(cbuf, 32, "0x%llx\n",
1041 (uint64_t) phba->lpfc_injerr_lba);
James Smart9a6b09c2012-03-01 22:37:42 -05001042 } else
James Smartf9bb2da2011-10-10 21:34:11 -04001043 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1044 "0547 Unknown debugfs error injection entry\n");
1045
1046 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1047}
1048
1049static ssize_t
1050lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1051 size_t nbytes, loff_t *ppos)
1052{
Al Virob5830432014-10-31 01:22:04 -04001053 struct dentry *dent = file->f_path.dentry;
James Smartf9bb2da2011-10-10 21:34:11 -04001054 struct lpfc_hba *phba = file->private_data;
Alan0872774d2016-02-15 19:11:56 +00001055 char dstbuf[33];
James Smart4ac9b222012-03-01 22:38:29 -05001056 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04001057 int size;
1058
Alan0872774d2016-02-15 19:11:56 +00001059 memset(dstbuf, 0, 33);
James Smartf9bb2da2011-10-10 21:34:11 -04001060 size = (nbytes < 32) ? nbytes : 32;
1061 if (copy_from_user(dstbuf, buf, size))
1062 return 0;
1063
James Smart9a6b09c2012-03-01 22:37:42 -05001064 if (dent == phba->debug_InjErrLBA) {
1065 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
James Smart4ac9b222012-03-01 22:38:29 -05001066 tmp = (uint64_t)(-1);
James Smart9a6b09c2012-03-01 22:37:42 -05001067 }
1068
James Smart4ac9b222012-03-01 22:38:29 -05001069 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
James Smartf9bb2da2011-10-10 21:34:11 -04001070 return 0;
1071
1072 if (dent == phba->debug_writeGuard)
1073 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1074 else if (dent == phba->debug_writeApp)
1075 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1076 else if (dent == phba->debug_writeRef)
1077 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
James Smartacd68592012-01-18 16:25:09 -05001078 else if (dent == phba->debug_readGuard)
1079 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
James Smartf9bb2da2011-10-10 21:34:11 -04001080 else if (dent == phba->debug_readApp)
1081 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1082 else if (dent == phba->debug_readRef)
1083 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1084 else if (dent == phba->debug_InjErrLBA)
1085 phba->lpfc_injerr_lba = (sector_t)tmp;
James Smart4ac9b222012-03-01 22:38:29 -05001086 else if (dent == phba->debug_InjErrNPortID)
1087 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1088 else if (dent == phba->debug_InjErrWWPN) {
1089 tmp = cpu_to_be64(tmp);
1090 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1091 } else
James Smartf9bb2da2011-10-10 21:34:11 -04001092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1093 "0548 Unknown debugfs error injection entry\n");
1094
1095 return nbytes;
1096}
1097
1098static int
1099lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1100{
1101 return 0;
1102}
1103
James Smarte59058c2008-08-24 21:49:00 -04001104/**
James Smart3621a712009-04-06 18:47:14 -04001105 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001106 * @inode: The inode pointer that contains a vport pointer.
1107 * @file: The file pointer to attach the log output.
1108 *
1109 * Description:
1110 * This routine is the entry point for the debugfs open file operation. It gets
1111 * the vport from the i_private field in @inode, allocates the necessary buffer
1112 * for the log, fills the buffer from the in-memory log for this vport, and then
1113 * returns a pointer to that log in the private_data field in @file.
1114 *
1115 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02001116 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04001117 * error value.
1118 **/
James Smarta58cbd52007-08-02 11:09:43 -04001119static int
James Smart858c9f62007-06-17 19:56:39 -05001120lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1121{
1122 struct lpfc_vport *vport = inode->i_private;
1123 struct lpfc_debug *debug;
1124 int rc = -ENOMEM;
1125
1126 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1127 if (!debug)
1128 goto out;
1129
James Smarte59058c2008-08-24 21:49:00 -04001130 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05001131 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1132 if (!debug->buffer) {
1133 kfree(debug);
1134 goto out;
1135 }
1136
1137 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1138 LPFC_NODELIST_SIZE);
1139 file->private_data = debug;
1140
1141 rc = 0;
1142out:
1143 return rc;
1144}
1145
James Smarte59058c2008-08-24 21:49:00 -04001146/**
James Smart3621a712009-04-06 18:47:14 -04001147 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001148 * @file: The file pointer to seek through.
1149 * @off: The offset to seek to or the amount to seek by.
1150 * @whence: Indicates how to seek.
1151 *
1152 * Description:
1153 * This routine is the entry point for the debugfs lseek file operation. The
1154 * @whence parameter indicates whether @off is the offset to directly seek to,
1155 * or if it is a value to seek forward or reverse by. This function figures out
1156 * what the new offset of the debugfs file will be and assigns that value to the
1157 * f_pos field of @file.
1158 *
1159 * Returns:
1160 * This function returns the new offset if successful and returns a negative
1161 * error if unable to process the seek.
1162 **/
James Smart858c9f62007-06-17 19:56:39 -05001163static loff_t
1164lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1165{
Al Viro7233c772013-06-23 12:08:05 +04001166 struct lpfc_debug *debug = file->private_data;
1167 return fixed_size_llseek(file, off, whence, debug->len);
James Smart858c9f62007-06-17 19:56:39 -05001168}
1169
James Smarte59058c2008-08-24 21:49:00 -04001170/**
James Smart3621a712009-04-06 18:47:14 -04001171 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04001172 * @file: The file pointer to read from.
1173 * @buf: The buffer to copy the data to.
1174 * @nbytes: The number of bytes to read.
1175 * @ppos: The position in the file to start reading from.
1176 *
1177 * Description:
1178 * This routine reads data from from the buffer indicated in the private_data
1179 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1180 * data to @buf.
1181 *
1182 * Returns:
1183 * This function returns the amount of data that was read (this could be less
1184 * than @nbytes if the end of the file was reached) or a negative error value.
1185 **/
James Smart858c9f62007-06-17 19:56:39 -05001186static ssize_t
1187lpfc_debugfs_read(struct file *file, char __user *buf,
1188 size_t nbytes, loff_t *ppos)
1189{
1190 struct lpfc_debug *debug = file->private_data;
James Smart2a622bf2011-02-16 12:40:06 -05001191
James Smart858c9f62007-06-17 19:56:39 -05001192 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1193 debug->len);
1194}
1195
James Smarte59058c2008-08-24 21:49:00 -04001196/**
James Smart3621a712009-04-06 18:47:14 -04001197 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04001198 * @inode: The inode pointer that contains a vport pointer. (unused)
1199 * @file: The file pointer that contains the buffer to release.
1200 *
1201 * Description:
1202 * This routine frees the buffer that was allocated when the debugfs file was
1203 * opened.
1204 *
1205 * Returns:
1206 * This function returns zero.
1207 **/
James Smart858c9f62007-06-17 19:56:39 -05001208static int
1209lpfc_debugfs_release(struct inode *inode, struct file *file)
1210{
1211 struct lpfc_debug *debug = file->private_data;
1212
1213 kfree(debug->buffer);
1214 kfree(debug);
1215
1216 return 0;
1217}
1218
James Smarte2a0a9d2008-12-04 22:40:02 -05001219static int
1220lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1221{
1222 struct lpfc_debug *debug = file->private_data;
1223
1224 debug->buffer = NULL;
1225 kfree(debug);
1226
1227 return 0;
1228}
1229
James Smart2a622bf2011-02-16 12:40:06 -05001230/*
James Smart86a80842011-04-16 11:03:04 -04001231 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001232 * iDiag debugfs file access methods
James Smart86a80842011-04-16 11:03:04 -04001233 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05001234 *
James Smart86a80842011-04-16 11:03:04 -04001235 * All access methods are through the proper SLI4 PCI function's debugfs
1236 * iDiag directory:
James Smart2a622bf2011-02-16 12:40:06 -05001237 *
James Smart86a80842011-04-16 11:03:04 -04001238 * /sys/kernel/debug/lpfc/fn<#>/iDiag
James Smart2a622bf2011-02-16 12:40:06 -05001239 */
1240
1241/**
1242 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1243 * @buf: The pointer to the user space buffer.
1244 * @nbytes: The number of bytes in the user space buffer.
1245 * @idiag_cmd: pointer to the idiag command struct.
1246 *
1247 * This routine reads data from debugfs user space buffer and parses the
1248 * buffer for getting the idiag command and arguments. The while space in
1249 * between the set of data is used as the parsing separator.
1250 *
1251 * This routine returns 0 when successful, it returns proper error code
1252 * back to the user space in error conditions.
1253 */
1254static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1255 struct lpfc_idiag_cmd *idiag_cmd)
1256{
1257 char mybuf[64];
1258 char *pbuf, *step_str;
Stephen Boydb11d48e2011-05-12 16:50:06 -07001259 int i;
1260 size_t bsize;
James Smart2a622bf2011-02-16 12:40:06 -05001261
1262 /* Protect copy from user */
1263 if (!access_ok(VERIFY_READ, buf, nbytes))
1264 return -EFAULT;
1265
1266 memset(mybuf, 0, sizeof(mybuf));
1267 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1268 bsize = min(nbytes, (sizeof(mybuf)-1));
1269
1270 if (copy_from_user(mybuf, buf, bsize))
1271 return -EFAULT;
1272 pbuf = &mybuf[0];
1273 step_str = strsep(&pbuf, "\t ");
1274
1275 /* The opcode must present */
1276 if (!step_str)
1277 return -EINVAL;
1278
1279 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1280 if (idiag_cmd->opcode == 0)
1281 return -EINVAL;
1282
1283 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1284 step_str = strsep(&pbuf, "\t ");
1285 if (!step_str)
James Smart86a80842011-04-16 11:03:04 -04001286 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001287 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1288 }
James Smart86a80842011-04-16 11:03:04 -04001289 return i;
James Smart2a622bf2011-02-16 12:40:06 -05001290}
1291
1292/**
1293 * lpfc_idiag_open - idiag open debugfs
1294 * @inode: The inode pointer that contains a pointer to phba.
1295 * @file: The file pointer to attach the file operation.
1296 *
1297 * Description:
1298 * This routine is the entry point for the debugfs open file operation. It
1299 * gets the reference to phba from the i_private field in @inode, it then
1300 * allocates buffer for the file operation, performs the necessary PCI config
1301 * space read into the allocated buffer according to the idiag user command
1302 * setup, and then returns a pointer to buffer in the private_data field in
1303 * @file.
1304 *
1305 * Returns:
1306 * This function returns zero if successful. On error it will return an
1307 * negative error value.
1308 **/
1309static int
1310lpfc_idiag_open(struct inode *inode, struct file *file)
1311{
1312 struct lpfc_debug *debug;
1313
1314 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1315 if (!debug)
1316 return -ENOMEM;
1317
1318 debug->i_private = inode->i_private;
1319 debug->buffer = NULL;
1320 file->private_data = debug;
1321
1322 return 0;
1323}
1324
1325/**
1326 * lpfc_idiag_release - Release idiag access file operation
1327 * @inode: The inode pointer that contains a vport pointer. (unused)
1328 * @file: The file pointer that contains the buffer to release.
1329 *
1330 * Description:
1331 * This routine is the generic release routine for the idiag access file
1332 * operation, it frees the buffer that was allocated when the debugfs file
1333 * was opened.
1334 *
1335 * Returns:
1336 * This function returns zero.
1337 **/
1338static int
1339lpfc_idiag_release(struct inode *inode, struct file *file)
1340{
1341 struct lpfc_debug *debug = file->private_data;
1342
1343 /* Free the buffers to the file operation */
1344 kfree(debug->buffer);
1345 kfree(debug);
1346
1347 return 0;
1348}
1349
1350/**
1351 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1352 * @inode: The inode pointer that contains a vport pointer. (unused)
1353 * @file: The file pointer that contains the buffer to release.
1354 *
1355 * Description:
1356 * This routine frees the buffer that was allocated when the debugfs file
1357 * was opened. It also reset the fields in the idiag command struct in the
James Smart86a80842011-04-16 11:03:04 -04001358 * case of command for write operation.
James Smart2a622bf2011-02-16 12:40:06 -05001359 *
1360 * Returns:
1361 * This function returns zero.
1362 **/
1363static int
1364lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1365{
1366 struct lpfc_debug *debug = file->private_data;
1367
James Smart86a80842011-04-16 11:03:04 -04001368 if (debug->op == LPFC_IDIAG_OP_WR) {
1369 switch (idiag.cmd.opcode) {
1370 case LPFC_IDIAG_CMD_PCICFG_WR:
1371 case LPFC_IDIAG_CMD_PCICFG_ST:
1372 case LPFC_IDIAG_CMD_PCICFG_CL:
1373 case LPFC_IDIAG_CMD_QUEACC_WR:
1374 case LPFC_IDIAG_CMD_QUEACC_ST:
1375 case LPFC_IDIAG_CMD_QUEACC_CL:
James Smart2a622bf2011-02-16 12:40:06 -05001376 memset(&idiag, 0, sizeof(idiag));
James Smart86a80842011-04-16 11:03:04 -04001377 break;
1378 default:
1379 break;
1380 }
1381 }
James Smart2a622bf2011-02-16 12:40:06 -05001382
1383 /* Free the buffers to the file operation */
1384 kfree(debug->buffer);
1385 kfree(debug);
1386
1387 return 0;
1388}
1389
1390/**
1391 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1392 * @file: The file pointer to read from.
1393 * @buf: The buffer to copy the data to.
1394 * @nbytes: The number of bytes to read.
1395 * @ppos: The position in the file to start reading from.
1396 *
1397 * Description:
1398 * This routine reads data from the @phba pci config space according to the
1399 * idiag command, and copies to user @buf. Depending on the PCI config space
1400 * read command setup, it does either a single register read of a byte
1401 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1402 * registers from the 4K extended PCI config space.
1403 *
1404 * Returns:
1405 * This function returns the amount of data that was read (this could be less
1406 * than @nbytes if the end of the file was reached) or a negative error value.
1407 **/
1408static ssize_t
1409lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1410 loff_t *ppos)
1411{
1412 struct lpfc_debug *debug = file->private_data;
1413 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1414 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1415 int where, count;
1416 char *pbuffer;
1417 struct pci_dev *pdev;
1418 uint32_t u32val;
1419 uint16_t u16val;
1420 uint8_t u8val;
1421
1422 pdev = phba->pcidev;
1423 if (!pdev)
1424 return 0;
1425
1426 /* This is a user read operation */
1427 debug->op = LPFC_IDIAG_OP_RD;
1428
1429 if (!debug->buffer)
1430 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1431 if (!debug->buffer)
1432 return 0;
1433 pbuffer = debug->buffer;
1434
1435 if (*ppos)
1436 return 0;
1437
1438 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04001439 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1440 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05001441 } else
1442 return 0;
1443
1444 /* Read single PCI config space register */
1445 switch (count) {
1446 case SIZE_U8: /* byte (8 bits) */
1447 pci_read_config_byte(pdev, where, &u8val);
1448 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1449 "%03x: %02x\n", where, u8val);
1450 break;
1451 case SIZE_U16: /* word (16 bits) */
1452 pci_read_config_word(pdev, where, &u16val);
1453 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1454 "%03x: %04x\n", where, u16val);
1455 break;
1456 case SIZE_U32: /* double word (32 bits) */
1457 pci_read_config_dword(pdev, where, &u32val);
1458 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1459 "%03x: %08x\n", where, u32val);
1460 break;
James Smart86a80842011-04-16 11:03:04 -04001461 case LPFC_PCI_CFG_BROWSE: /* browse all */
James Smart2a622bf2011-02-16 12:40:06 -05001462 goto pcicfg_browse;
1463 break;
1464 default:
1465 /* illegal count */
1466 len = 0;
1467 break;
1468 }
1469 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1470
1471pcicfg_browse:
1472
1473 /* Browse all PCI config space registers */
1474 offset_label = idiag.offset.last_rd;
1475 offset = offset_label;
1476
1477 /* Read PCI config space */
1478 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1479 "%03x: ", offset_label);
1480 while (index > 0) {
1481 pci_read_config_dword(pdev, offset, &u32val);
1482 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1483 "%08x ", u32val);
1484 offset += sizeof(uint32_t);
James Smartb76f2dc2011-07-22 18:37:42 -04001485 if (offset >= LPFC_PCI_CFG_SIZE) {
1486 len += snprintf(pbuffer+len,
1487 LPFC_PCI_CFG_SIZE-len, "\n");
1488 break;
1489 }
James Smart2a622bf2011-02-16 12:40:06 -05001490 index -= sizeof(uint32_t);
1491 if (!index)
1492 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1493 "\n");
1494 else if (!(index % (8 * sizeof(uint32_t)))) {
1495 offset_label += (8 * sizeof(uint32_t));
1496 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1497 "\n%03x: ", offset_label);
1498 }
1499 }
1500
1501 /* Set up the offset for next portion of pci cfg read */
James Smartb76f2dc2011-07-22 18:37:42 -04001502 if (index == 0) {
1503 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1504 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1505 idiag.offset.last_rd = 0;
1506 } else
James Smart2a622bf2011-02-16 12:40:06 -05001507 idiag.offset.last_rd = 0;
1508
1509 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1510}
1511
1512/**
1513 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1514 * @file: The file pointer to read from.
1515 * @buf: The buffer to copy the user data from.
1516 * @nbytes: The number of bytes to get.
1517 * @ppos: The position in the file to start reading from.
1518 *
1519 * This routine get the debugfs idiag command struct from user space and
1520 * then perform the syntax check for PCI config space read or write command
1521 * accordingly. In the case of PCI config space read command, it sets up
1522 * the command in the idiag command struct for the debugfs read operation.
1523 * In the case of PCI config space write operation, it executes the write
1524 * operation into the PCI config space accordingly.
1525 *
1526 * It returns the @nbytges passing in from debugfs user space when successful.
1527 * In case of error conditions, it returns proper error code back to the user
1528 * space.
1529 */
1530static ssize_t
1531lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1532 size_t nbytes, loff_t *ppos)
1533{
1534 struct lpfc_debug *debug = file->private_data;
1535 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1536 uint32_t where, value, count;
1537 uint32_t u32val;
1538 uint16_t u16val;
1539 uint8_t u8val;
1540 struct pci_dev *pdev;
1541 int rc;
1542
1543 pdev = phba->pcidev;
1544 if (!pdev)
1545 return -EFAULT;
1546
1547 /* This is a user write operation */
1548 debug->op = LPFC_IDIAG_OP_WR;
1549
1550 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
James Smart86a80842011-04-16 11:03:04 -04001551 if (rc < 0)
James Smart2a622bf2011-02-16 12:40:06 -05001552 return rc;
1553
1554 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smart86a80842011-04-16 11:03:04 -04001555 /* Sanity check on PCI config read command line arguments */
1556 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1557 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001558 /* Read command from PCI config space, set up command fields */
James Smartb76f2dc2011-07-22 18:37:42 -04001559 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1560 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04001561 if (count == LPFC_PCI_CFG_BROWSE) {
1562 if (where % sizeof(uint32_t))
James Smart2a622bf2011-02-16 12:40:06 -05001563 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04001564 /* Starting offset to browse */
1565 idiag.offset.last_rd = where;
James Smart2a622bf2011-02-16 12:40:06 -05001566 } else if ((count != sizeof(uint8_t)) &&
1567 (count != sizeof(uint16_t)) &&
1568 (count != sizeof(uint32_t)))
1569 goto error_out;
1570 if (count == sizeof(uint8_t)) {
1571 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1572 goto error_out;
1573 if (where % sizeof(uint8_t))
1574 goto error_out;
1575 }
1576 if (count == sizeof(uint16_t)) {
1577 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1578 goto error_out;
1579 if (where % sizeof(uint16_t))
1580 goto error_out;
1581 }
1582 if (count == sizeof(uint32_t)) {
1583 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1584 goto error_out;
1585 if (where % sizeof(uint32_t))
1586 goto error_out;
1587 }
1588 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1589 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1590 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
James Smart86a80842011-04-16 11:03:04 -04001591 /* Sanity check on PCI config write command line arguments */
1592 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1593 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05001594 /* Write command to PCI config space, read-modify-write */
James Smartb76f2dc2011-07-22 18:37:42 -04001595 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1596 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1597 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05001598 /* Sanity checks */
1599 if ((count != sizeof(uint8_t)) &&
1600 (count != sizeof(uint16_t)) &&
1601 (count != sizeof(uint32_t)))
1602 goto error_out;
1603 if (count == sizeof(uint8_t)) {
1604 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1605 goto error_out;
1606 if (where % sizeof(uint8_t))
1607 goto error_out;
1608 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1609 pci_write_config_byte(pdev, where,
1610 (uint8_t)value);
1611 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1612 rc = pci_read_config_byte(pdev, where, &u8val);
1613 if (!rc) {
1614 u8val |= (uint8_t)value;
1615 pci_write_config_byte(pdev, where,
1616 u8val);
1617 }
1618 }
1619 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
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 }
1628 if (count == sizeof(uint16_t)) {
1629 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1630 goto error_out;
1631 if (where % sizeof(uint16_t))
1632 goto error_out;
1633 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1634 pci_write_config_word(pdev, where,
1635 (uint16_t)value);
1636 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1637 rc = pci_read_config_word(pdev, where, &u16val);
1638 if (!rc) {
1639 u16val |= (uint16_t)value;
1640 pci_write_config_word(pdev, where,
1641 u16val);
1642 }
1643 }
1644 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
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 }
1653 if (count == sizeof(uint32_t)) {
1654 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1655 goto error_out;
1656 if (where % sizeof(uint32_t))
1657 goto error_out;
1658 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1659 pci_write_config_dword(pdev, where, value);
1660 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1661 rc = pci_read_config_dword(pdev, where,
1662 &u32val);
1663 if (!rc) {
1664 u32val |= value;
1665 pci_write_config_dword(pdev, where,
1666 u32val);
1667 }
1668 }
1669 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1670 rc = pci_read_config_dword(pdev, where,
1671 &u32val);
1672 if (!rc) {
1673 u32val &= ~value;
1674 pci_write_config_dword(pdev, where,
1675 u32val);
1676 }
1677 }
1678 }
1679 } else
1680 /* All other opecodes are illegal for now */
1681 goto error_out;
1682
1683 return nbytes;
1684error_out:
1685 memset(&idiag, 0, sizeof(idiag));
1686 return -EINVAL;
1687}
1688
1689/**
James Smartb76f2dc2011-07-22 18:37:42 -04001690 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1691 * @file: The file pointer to read from.
1692 * @buf: The buffer to copy the data to.
1693 * @nbytes: The number of bytes to read.
1694 * @ppos: The position in the file to start reading from.
1695 *
1696 * Description:
1697 * This routine reads data from the @phba pci bar memory mapped space
1698 * according to the idiag command, and copies to user @buf.
1699 *
1700 * Returns:
1701 * This function returns the amount of data that was read (this could be less
1702 * than @nbytes if the end of the file was reached) or a negative error value.
1703 **/
1704static ssize_t
1705lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1706 loff_t *ppos)
1707{
1708 struct lpfc_debug *debug = file->private_data;
1709 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1710 int offset_label, offset, offset_run, len = 0, index;
1711 int bar_num, acc_range, bar_size;
1712 char *pbuffer;
1713 void __iomem *mem_mapped_bar;
1714 uint32_t if_type;
1715 struct pci_dev *pdev;
1716 uint32_t u32val;
1717
1718 pdev = phba->pcidev;
1719 if (!pdev)
1720 return 0;
1721
1722 /* This is a user read operation */
1723 debug->op = LPFC_IDIAG_OP_RD;
1724
1725 if (!debug->buffer)
1726 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1727 if (!debug->buffer)
1728 return 0;
1729 pbuffer = debug->buffer;
1730
1731 if (*ppos)
1732 return 0;
1733
1734 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1735 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1736 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1737 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1738 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1739 } else
1740 return 0;
1741
1742 if (acc_range == 0)
1743 return 0;
1744
1745 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1746 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1747 if (bar_num == IDIAG_BARACC_BAR_0)
1748 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1749 else if (bar_num == IDIAG_BARACC_BAR_1)
1750 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1751 else if (bar_num == IDIAG_BARACC_BAR_2)
1752 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1753 else
1754 return 0;
1755 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1756 if (bar_num == IDIAG_BARACC_BAR_0)
1757 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1758 else
1759 return 0;
1760 } else
1761 return 0;
1762
1763 /* Read single PCI bar space register */
1764 if (acc_range == SINGLE_WORD) {
1765 offset_run = offset;
1766 u32val = readl(mem_mapped_bar + offset_run);
1767 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1768 "%05x: %08x\n", offset_run, u32val);
1769 } else
1770 goto baracc_browse;
1771
1772 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1773
1774baracc_browse:
1775
1776 /* Browse all PCI bar space registers */
1777 offset_label = idiag.offset.last_rd;
1778 offset_run = offset_label;
1779
1780 /* Read PCI bar memory mapped space */
1781 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1782 "%05x: ", offset_label);
1783 index = LPFC_PCI_BAR_RD_SIZE;
1784 while (index > 0) {
1785 u32val = readl(mem_mapped_bar + offset_run);
1786 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1787 "%08x ", u32val);
1788 offset_run += sizeof(uint32_t);
1789 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1790 if (offset_run >= bar_size) {
1791 len += snprintf(pbuffer+len,
1792 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1793 break;
1794 }
1795 } else {
1796 if (offset_run >= offset +
1797 (acc_range * sizeof(uint32_t))) {
1798 len += snprintf(pbuffer+len,
1799 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1800 break;
1801 }
1802 }
1803 index -= sizeof(uint32_t);
1804 if (!index)
1805 len += snprintf(pbuffer+len,
1806 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1807 else if (!(index % (8 * sizeof(uint32_t)))) {
1808 offset_label += (8 * sizeof(uint32_t));
1809 len += snprintf(pbuffer+len,
1810 LPFC_PCI_BAR_RD_BUF_SIZE-len,
1811 "\n%05x: ", offset_label);
1812 }
1813 }
1814
1815 /* Set up the offset for next portion of pci bar read */
1816 if (index == 0) {
1817 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1818 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1819 if (idiag.offset.last_rd >= bar_size)
1820 idiag.offset.last_rd = 0;
1821 } else {
1822 if (offset_run >= offset +
1823 (acc_range * sizeof(uint32_t)))
1824 idiag.offset.last_rd = offset;
1825 }
1826 } else {
1827 if (acc_range == LPFC_PCI_BAR_BROWSE)
1828 idiag.offset.last_rd = 0;
1829 else
1830 idiag.offset.last_rd = offset;
1831 }
1832
1833 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1834}
1835
1836/**
1837 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1838 * @file: The file pointer to read from.
1839 * @buf: The buffer to copy the user data from.
1840 * @nbytes: The number of bytes to get.
1841 * @ppos: The position in the file to start reading from.
1842 *
1843 * This routine get the debugfs idiag command struct from user space and
1844 * then perform the syntax check for PCI bar memory mapped space read or
1845 * write command accordingly. In the case of PCI bar memory mapped space
1846 * read command, it sets up the command in the idiag command struct for
1847 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1848 * write operation, it executes the write operation into the PCI bar memory
1849 * mapped space accordingly.
1850 *
1851 * It returns the @nbytges passing in from debugfs user space when successful.
1852 * In case of error conditions, it returns proper error code back to the user
1853 * space.
1854 */
1855static ssize_t
1856lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1857 size_t nbytes, loff_t *ppos)
1858{
1859 struct lpfc_debug *debug = file->private_data;
1860 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1861 uint32_t bar_num, bar_size, offset, value, acc_range;
1862 struct pci_dev *pdev;
1863 void __iomem *mem_mapped_bar;
1864 uint32_t if_type;
1865 uint32_t u32val;
1866 int rc;
1867
1868 pdev = phba->pcidev;
1869 if (!pdev)
1870 return -EFAULT;
1871
1872 /* This is a user write operation */
1873 debug->op = LPFC_IDIAG_OP_WR;
1874
1875 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1876 if (rc < 0)
1877 return rc;
1878
1879 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1880 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1881
1882 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1883 if ((bar_num != IDIAG_BARACC_BAR_0) &&
1884 (bar_num != IDIAG_BARACC_BAR_1) &&
1885 (bar_num != IDIAG_BARACC_BAR_2))
1886 goto error_out;
1887 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1888 if (bar_num != IDIAG_BARACC_BAR_0)
1889 goto error_out;
1890 } else
1891 goto error_out;
1892
1893 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1894 if (bar_num == IDIAG_BARACC_BAR_0) {
1895 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1896 LPFC_PCI_IF0_BAR0_SIZE;
1897 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1898 } else if (bar_num == IDIAG_BARACC_BAR_1) {
1899 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1900 LPFC_PCI_IF0_BAR1_SIZE;
1901 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1902 } else if (bar_num == IDIAG_BARACC_BAR_2) {
1903 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1904 LPFC_PCI_IF0_BAR2_SIZE;
1905 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1906 } else
1907 goto error_out;
1908 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1909 if (bar_num == IDIAG_BARACC_BAR_0) {
1910 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1911 LPFC_PCI_IF2_BAR0_SIZE;
1912 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1913 } else
1914 goto error_out;
1915 } else
1916 goto error_out;
1917
1918 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1919 if (offset % sizeof(uint32_t))
1920 goto error_out;
1921
1922 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1923 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1924 /* Sanity check on PCI config read command line arguments */
1925 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1926 goto error_out;
1927 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1928 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1929 if (offset > bar_size - sizeof(uint32_t))
1930 goto error_out;
1931 /* Starting offset to browse */
1932 idiag.offset.last_rd = offset;
1933 } else if (acc_range > SINGLE_WORD) {
1934 if (offset + acc_range * sizeof(uint32_t) > bar_size)
1935 goto error_out;
1936 /* Starting offset to browse */
1937 idiag.offset.last_rd = offset;
1938 } else if (acc_range != SINGLE_WORD)
1939 goto error_out;
1940 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1941 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1942 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1943 /* Sanity check on PCI bar write command line arguments */
1944 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1945 goto error_out;
1946 /* Write command to PCI bar space, read-modify-write */
1947 acc_range = SINGLE_WORD;
1948 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1949 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1950 writel(value, mem_mapped_bar + offset);
1951 readl(mem_mapped_bar + offset);
1952 }
1953 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1954 u32val = readl(mem_mapped_bar + offset);
1955 u32val |= value;
1956 writel(u32val, mem_mapped_bar + offset);
1957 readl(mem_mapped_bar + offset);
1958 }
1959 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1960 u32val = readl(mem_mapped_bar + offset);
1961 u32val &= ~value;
1962 writel(u32val, mem_mapped_bar + offset);
1963 readl(mem_mapped_bar + offset);
1964 }
1965 } else
1966 /* All other opecodes are illegal for now */
1967 goto error_out;
1968
1969 return nbytes;
1970error_out:
1971 memset(&idiag, 0, sizeof(idiag));
1972 return -EINVAL;
1973}
1974
James Smart07bcd982017-02-12 13:52:28 -08001975static int
1976__lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
1977 char *pbuffer, int len)
1978{
1979 if (!qp)
1980 return len;
1981
1982 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
1983 "\t\t%s WQ info: ", wqtype);
1984 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
1985 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
1986 qp->assoc_qid, qp->q_cnt_1,
1987 (unsigned long long)qp->q_cnt_4);
1988 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
1989 "\t\tWQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
1990 "HOST-IDX[%04d], PORT-IDX[%04d]",
1991 qp->queue_id, qp->entry_count,
1992 qp->entry_size, qp->host_index,
1993 qp->hba_index);
1994 len += snprintf(pbuffer + len,
1995 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
1996 return len;
1997}
1998
1999static int
2000lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
2001 int *len, int max_cnt, int cq_id)
2002{
2003 struct lpfc_queue *qp;
2004 int qidx;
2005
2006 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
2007 qp = phba->sli4_hba.fcp_wq[qidx];
2008 if (qp->assoc_qid != cq_id)
2009 continue;
2010 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
2011 if (*len >= max_cnt)
2012 return 1;
2013 }
2014 return 0;
2015}
2016
2017static int
2018__lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
2019 char *pbuffer, int len)
2020{
2021 if (!qp)
2022 return len;
2023
2024 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2025 "\t%s CQ info: ", cqtype);
2026 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2027 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
2028 "xabt:x%x wq:x%llx]\n",
2029 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
2030 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
2031 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2032 "\tCQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
2033 "HOST-IDX[%04d], PORT-IDX[%04d]",
2034 qp->queue_id, qp->entry_count,
2035 qp->entry_size, qp->host_index,
2036 qp->hba_index);
2037
2038 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
2039
2040 return len;
2041}
2042
2043static int
2044__lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
2045 char *rqtype, char *pbuffer, int len)
2046{
2047 if (!qp || !datqp)
2048 return len;
2049
2050 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2051 "\t\t%s RQ info: ", rqtype);
2052 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2053 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
2054 "trunc:x%x rcv:x%llx]\n",
2055 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
2056 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
2057 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2058 "\t\tHQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
2059 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
2060 qp->queue_id, qp->entry_count, qp->entry_size,
2061 qp->host_index, qp->hba_index);
2062 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2063 "\t\tDQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
2064 "HOST-IDX[%04d], PORT-IDX[%04d]\n",
2065 datqp->queue_id, datqp->entry_count,
2066 datqp->entry_size, datqp->host_index,
2067 datqp->hba_index);
2068 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
2069
2070 return len;
2071}
2072
2073static int
2074lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
2075 int *len, int max_cnt, int eq_id)
2076{
2077 struct lpfc_queue *qp;
2078 int qidx, rc;
2079
2080 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
2081 qp = phba->sli4_hba.fcp_cq[qidx];
2082 if (qp->assoc_qid != eq_id)
2083 continue;
2084
2085 *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len);
2086
2087 /* Reset max counter */
2088 qp->CQ_max_cqe = 0;
2089
2090 if (*len >= max_cnt)
2091 return 1;
2092
2093 rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len,
2094 max_cnt, qp->queue_id);
2095 if (rc)
2096 return 1;
2097 }
2098
2099 return 0;
2100}
2101
2102static int
2103__lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
2104 char *pbuffer, int len)
2105{
2106 if (!qp)
2107 return len;
2108
2109 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2110 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
2111 "bs:x%x proc:x%llx]\n",
2112 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
2113 (unsigned long long)qp->q_cnt_4);
2114 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2115 "EQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], "
2116 "HOST-IDX[%04d], PORT-IDX[%04d]",
2117 qp->queue_id, qp->entry_count, qp->entry_size,
2118 qp->host_index, qp->hba_index);
2119 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
2120
2121 return len;
2122}
2123
James Smartb76f2dc2011-07-22 18:37:42 -04002124/**
James Smart2a622bf2011-02-16 12:40:06 -05002125 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
2126 * @file: The file pointer to read from.
2127 * @buf: The buffer to copy the data to.
2128 * @nbytes: The number of bytes to read.
2129 * @ppos: The position in the file to start reading from.
2130 *
2131 * Description:
2132 * This routine reads data from the @phba SLI4 PCI function queue information,
2133 * and copies to user @buf.
James Smart07bcd982017-02-12 13:52:28 -08002134 * This routine only returns 1 EQs worth of information. It remembers the last
2135 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
2136 * retrieve all EQs allocated for the phba.
James Smart2a622bf2011-02-16 12:40:06 -05002137 *
2138 * Returns:
2139 * This function returns the amount of data that was read (this could be less
2140 * than @nbytes if the end of the file was reached) or a negative error value.
2141 **/
2142static ssize_t
2143lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
2144 loff_t *ppos)
2145{
2146 struct lpfc_debug *debug = file->private_data;
2147 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
James Smart2a622bf2011-02-16 12:40:06 -05002148 char *pbuffer;
James Smart07bcd982017-02-12 13:52:28 -08002149 int max_cnt, rc, x, len = 0;
James Smartc85a65a2012-08-03 12:37:00 -04002150 struct lpfc_queue *qp = NULL;
2151
James Smart2a622bf2011-02-16 12:40:06 -05002152 if (!debug->buffer)
2153 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
2154 if (!debug->buffer)
2155 return 0;
2156 pbuffer = debug->buffer;
James Smart07bcd982017-02-12 13:52:28 -08002157 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
James Smart2a622bf2011-02-16 12:40:06 -05002158
2159 if (*ppos)
2160 return 0;
2161
James Smartc85a65a2012-08-03 12:37:00 -04002162 spin_lock_irq(&phba->hbalock);
James Smart2a622bf2011-02-16 12:40:06 -05002163
James Smartc85a65a2012-08-03 12:37:00 -04002164 /* Fast-path event queue */
2165 if (phba->sli4_hba.hba_eq && phba->cfg_fcp_io_channel) {
James Smart2a622bf2011-02-16 12:40:06 -05002166
James Smart07bcd982017-02-12 13:52:28 -08002167 x = phba->lpfc_idiag_last_eq;
2168 if (phba->cfg_fof && (x >= phba->cfg_fcp_io_channel)) {
2169 phba->lpfc_idiag_last_eq = 0;
2170 goto fof;
James Smart2e90f4b2011-12-13 13:22:37 -05002171 }
James Smart07bcd982017-02-12 13:52:28 -08002172 phba->lpfc_idiag_last_eq++;
2173 if (phba->lpfc_idiag_last_eq >= phba->cfg_fcp_io_channel)
2174 if (phba->cfg_fof == 0)
2175 phba->lpfc_idiag_last_eq = 0;
James Smart2a622bf2011-02-16 12:40:06 -05002176
James Smart07bcd982017-02-12 13:52:28 -08002177 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
2178 "EQ %d out of %d HBA EQs\n",
2179 x, phba->cfg_fcp_io_channel);
2180
2181 /* Fast-path EQ */
2182 qp = phba->sli4_hba.hba_eq[x];
James Smart1ba981f2014-02-20 09:56:45 -05002183 if (!qp)
2184 goto out;
2185
James Smart07bcd982017-02-12 13:52:28 -08002186 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
James Smart1ba981f2014-02-20 09:56:45 -05002187
2188 /* Reset max counter */
2189 qp->EQ_max_eqe = 0;
2190
James Smart07bcd982017-02-12 13:52:28 -08002191 if (len >= max_cnt)
2192 goto too_big;
2193
2194 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
2195 max_cnt, qp->queue_id);
2196 if (rc)
2197 goto too_big;
2198
2199 /* Only EQ 0 has slow path CQs configured */
2200 if (x)
2201 goto out;
2202
2203 /* Slow-path mailbox CQ */
2204 qp = phba->sli4_hba.mbx_cq;
2205 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
2206 if (len >= max_cnt)
2207 goto too_big;
2208
2209 /* Slow-path MBOX MQ */
2210 qp = phba->sli4_hba.mbx_wq;
2211 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
2212 if (len >= max_cnt)
2213 goto too_big;
2214
2215 /* Slow-path ELS response CQ */
2216 qp = phba->sli4_hba.els_cq;
2217 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
2218 /* Reset max counter */
2219 if (qp)
2220 qp->CQ_max_cqe = 0;
2221 if (len >= max_cnt)
2222 goto too_big;
2223
2224 /* Slow-path ELS WQ */
2225 qp = phba->sli4_hba.els_wq;
2226 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
2227 if (len >= max_cnt)
2228 goto too_big;
2229
2230 qp = phba->sli4_hba.hdr_rq;
2231 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
2232 "RQpair", pbuffer, len);
2233 if (len >= max_cnt)
2234 goto too_big;
2235
2236 goto out;
2237 }
2238
2239fof:
2240 if (phba->cfg_fof) {
2241 /* FOF EQ */
2242 qp = phba->sli4_hba.fof_eq;
2243 len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len);
2244
2245 /* Reset max counter */
2246 if (qp)
2247 qp->EQ_max_eqe = 0;
2248
2249 if (len >= max_cnt)
2250 goto too_big;
2251
2252 /* OAS CQ */
2253 qp = phba->sli4_hba.oas_cq;
2254 len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len);
2255 /* Reset max counter */
2256 if (qp)
2257 qp->CQ_max_cqe = 0;
2258 if (len >= max_cnt)
2259 goto too_big;
2260
2261 /* OAS WQ */
2262 qp = phba->sli4_hba.oas_wq;
2263 len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len);
James Smart1ba981f2014-02-20 09:56:45 -05002264 if (len >= max_cnt)
2265 goto too_big;
2266 }
2267
James Smartc85a65a2012-08-03 12:37:00 -04002268 spin_unlock_irq(&phba->hbalock);
2269 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2270
2271too_big:
James Smart07bcd982017-02-12 13:52:28 -08002272 len += snprintf(pbuffer + len,
2273 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
2274out:
James Smartc85a65a2012-08-03 12:37:00 -04002275 spin_unlock_irq(&phba->hbalock);
James Smart2a622bf2011-02-16 12:40:06 -05002276 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2277}
2278
James Smart86a80842011-04-16 11:03:04 -04002279/**
2280 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2281 * @q: The pointer to queue structure.
2282 * @index: The index into a queue entry.
2283 * @count: The number of queue entries to access.
2284 *
2285 * Description:
2286 * The routine performs sanity check on device queue access method commands.
2287 *
2288 * Returns:
2289 * This function returns -EINVAL when fails the sanity check, otherwise, it
2290 * returns 0.
2291 **/
2292static int
2293lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
2294{
2295 /* Only support single entry read or browsing */
2296 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
2297 return -EINVAL;
2298 if (index > q->entry_count - 1)
2299 return -EINVAL;
2300 return 0;
2301}
2302
2303/**
2304 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2305 * @pbuffer: The pointer to buffer to copy the read data into.
2306 * @pque: The pointer to the queue to be read.
2307 * @index: The index into the queue entry.
2308 *
2309 * Description:
2310 * This routine reads out a single entry from the given queue's index location
2311 * and copies it into the buffer provided.
2312 *
2313 * Returns:
2314 * This function returns 0 when it fails, otherwise, it returns the length of
2315 * the data read into the buffer provided.
2316 **/
2317static int
2318lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
2319 uint32_t index)
2320{
2321 int offset, esize;
2322 uint32_t *pentry;
2323
2324 if (!pbuffer || !pque)
2325 return 0;
2326
2327 esize = pque->entry_size;
2328 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2329 "QE-INDEX[%04d]:\n", index);
2330
2331 offset = 0;
2332 pentry = pque->qe[index].address;
2333 while (esize > 0) {
2334 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2335 "%08x ", *pentry);
2336 pentry++;
2337 offset += sizeof(uint32_t);
2338 esize -= sizeof(uint32_t);
2339 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
2340 len += snprintf(pbuffer+len,
2341 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2342 }
2343 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2344
2345 return len;
2346}
2347
2348/**
2349 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2350 * @file: The file pointer to read from.
2351 * @buf: The buffer to copy the data to.
2352 * @nbytes: The number of bytes to read.
2353 * @ppos: The position in the file to start reading from.
2354 *
2355 * Description:
2356 * This routine reads data from the @phba device queue memory according to the
2357 * idiag command, and copies to user @buf. Depending on the queue dump read
2358 * command setup, it does either a single queue entry read or browing through
2359 * all entries of the queue.
2360 *
2361 * Returns:
2362 * This function returns the amount of data that was read (this could be less
2363 * than @nbytes if the end of the file was reached) or a negative error value.
2364 **/
2365static ssize_t
2366lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
2367 loff_t *ppos)
2368{
2369 struct lpfc_debug *debug = file->private_data;
2370 uint32_t last_index, index, count;
2371 struct lpfc_queue *pque = NULL;
2372 char *pbuffer;
2373 int len = 0;
2374
2375 /* This is a user read operation */
2376 debug->op = LPFC_IDIAG_OP_RD;
2377
2378 if (!debug->buffer)
2379 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
2380 if (!debug->buffer)
2381 return 0;
2382 pbuffer = debug->buffer;
2383
2384 if (*ppos)
2385 return 0;
2386
2387 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04002388 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2389 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04002390 pque = (struct lpfc_queue *)idiag.ptr_private;
2391 } else
2392 return 0;
2393
2394 /* Browse the queue starting from index */
2395 if (count == LPFC_QUE_ACC_BROWSE)
2396 goto que_browse;
2397
2398 /* Read a single entry from the queue */
2399 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2400
2401 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2402
2403que_browse:
2404
2405 /* Browse all entries from the queue */
2406 last_index = idiag.offset.last_rd;
2407 index = last_index;
2408
2409 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
2410 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2411 index++;
2412 if (index > pque->entry_count - 1)
2413 break;
2414 }
2415
2416 /* Set up the offset for next portion of pci cfg read */
2417 if (index > pque->entry_count - 1)
2418 index = 0;
2419 idiag.offset.last_rd = index;
2420
2421 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2422}
2423
2424/**
2425 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2426 * @file: The file pointer to read from.
2427 * @buf: The buffer to copy the user data from.
2428 * @nbytes: The number of bytes to get.
2429 * @ppos: The position in the file to start reading from.
2430 *
2431 * This routine get the debugfs idiag command struct from user space and then
2432 * perform the syntax check for port queue read (dump) or write (set) command
2433 * accordingly. In the case of port queue read command, it sets up the command
2434 * in the idiag command struct for the following debugfs read operation. In
2435 * the case of port queue write operation, it executes the write operation
2436 * into the port queue entry accordingly.
2437 *
2438 * It returns the @nbytges passing in from debugfs user space when successful.
2439 * In case of error conditions, it returns proper error code back to the user
2440 * space.
2441 **/
2442static ssize_t
2443lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
2444 size_t nbytes, loff_t *ppos)
2445{
2446 struct lpfc_debug *debug = file->private_data;
2447 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2448 uint32_t qidx, quetp, queid, index, count, offset, value;
2449 uint32_t *pentry;
2450 struct lpfc_queue *pque;
2451 int rc;
2452
2453 /* This is a user write operation */
2454 debug->op = LPFC_IDIAG_OP_WR;
2455
2456 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2457 if (rc < 0)
2458 return rc;
2459
2460 /* Get and sanity check on command feilds */
James Smartb76f2dc2011-07-22 18:37:42 -04002461 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
2462 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
2463 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2464 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2465 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
2466 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04002467
2468 /* Sanity check on command line arguments */
2469 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2470 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2471 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2472 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
2473 goto error_out;
2474 if (count != 1)
2475 goto error_out;
2476 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2477 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
2478 goto error_out;
2479 } else
2480 goto error_out;
2481
2482 switch (quetp) {
2483 case LPFC_IDIAG_EQ:
James Smart67d12732012-08-03 12:36:13 -04002484 /* HBA event queue */
2485 if (phba->sli4_hba.hba_eq) {
2486 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
2487 qidx++) {
2488 if (phba->sli4_hba.hba_eq[qidx] &&
2489 phba->sli4_hba.hba_eq[qidx]->queue_id ==
James Smart2e90f4b2011-12-13 13:22:37 -05002490 queid) {
2491 /* Sanity check */
2492 rc = lpfc_idiag_que_param_check(
James Smart67d12732012-08-03 12:36:13 -04002493 phba->sli4_hba.hba_eq[qidx],
James Smart86a80842011-04-16 11:03:04 -04002494 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002495 if (rc)
2496 goto error_out;
2497 idiag.ptr_private =
James Smart67d12732012-08-03 12:36:13 -04002498 phba->sli4_hba.hba_eq[qidx];
James Smart2e90f4b2011-12-13 13:22:37 -05002499 goto pass_check;
2500 }
James Smart86a80842011-04-16 11:03:04 -04002501 }
2502 }
2503 goto error_out;
2504 break;
2505 case LPFC_IDIAG_CQ:
2506 /* MBX complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002507 if (phba->sli4_hba.mbx_cq &&
2508 phba->sli4_hba.mbx_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002509 /* Sanity check */
2510 rc = lpfc_idiag_que_param_check(
2511 phba->sli4_hba.mbx_cq, index, count);
2512 if (rc)
2513 goto error_out;
2514 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2515 goto pass_check;
2516 }
2517 /* ELS complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002518 if (phba->sli4_hba.els_cq &&
2519 phba->sli4_hba.els_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002520 /* Sanity check */
2521 rc = lpfc_idiag_que_param_check(
2522 phba->sli4_hba.els_cq, index, count);
2523 if (rc)
2524 goto error_out;
2525 idiag.ptr_private = phba->sli4_hba.els_cq;
2526 goto pass_check;
2527 }
2528 /* FCP complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002529 if (phba->sli4_hba.fcp_cq) {
2530 qidx = 0;
2531 do {
2532 if (phba->sli4_hba.fcp_cq[qidx] &&
2533 phba->sli4_hba.fcp_cq[qidx]->queue_id ==
2534 queid) {
2535 /* Sanity check */
2536 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002537 phba->sli4_hba.fcp_cq[qidx],
2538 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002539 if (rc)
2540 goto error_out;
2541 idiag.ptr_private =
James Smart86a80842011-04-16 11:03:04 -04002542 phba->sli4_hba.fcp_cq[qidx];
James Smart2e90f4b2011-12-13 13:22:37 -05002543 goto pass_check;
2544 }
James Smart67d12732012-08-03 12:36:13 -04002545 } while (++qidx < phba->cfg_fcp_io_channel);
James Smart2e90f4b2011-12-13 13:22:37 -05002546 }
James Smart86a80842011-04-16 11:03:04 -04002547 goto error_out;
2548 break;
2549 case LPFC_IDIAG_MQ:
2550 /* MBX work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002551 if (phba->sli4_hba.mbx_wq &&
2552 phba->sli4_hba.mbx_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002553 /* Sanity check */
2554 rc = lpfc_idiag_que_param_check(
2555 phba->sli4_hba.mbx_wq, index, count);
2556 if (rc)
2557 goto error_out;
2558 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2559 goto pass_check;
2560 }
James Smart2e90f4b2011-12-13 13:22:37 -05002561 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04002562 break;
2563 case LPFC_IDIAG_WQ:
2564 /* ELS work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002565 if (phba->sli4_hba.els_wq &&
2566 phba->sli4_hba.els_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002567 /* Sanity check */
2568 rc = lpfc_idiag_que_param_check(
2569 phba->sli4_hba.els_wq, index, count);
2570 if (rc)
2571 goto error_out;
2572 idiag.ptr_private = phba->sli4_hba.els_wq;
2573 goto pass_check;
2574 }
2575 /* FCP work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002576 if (phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04002577 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
2578 qidx++) {
James Smart2e90f4b2011-12-13 13:22:37 -05002579 if (!phba->sli4_hba.fcp_wq[qidx])
2580 continue;
2581 if (phba->sli4_hba.fcp_wq[qidx]->queue_id ==
2582 queid) {
2583 /* Sanity check */
2584 rc = lpfc_idiag_que_param_check(
James Smart86a80842011-04-16 11:03:04 -04002585 phba->sli4_hba.fcp_wq[qidx],
2586 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05002587 if (rc)
2588 goto error_out;
2589 idiag.ptr_private =
2590 phba->sli4_hba.fcp_wq[qidx];
2591 goto pass_check;
2592 }
James Smart86a80842011-04-16 11:03:04 -04002593 }
2594 }
2595 goto error_out;
2596 break;
2597 case LPFC_IDIAG_RQ:
2598 /* HDR queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002599 if (phba->sli4_hba.hdr_rq &&
2600 phba->sli4_hba.hdr_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002601 /* Sanity check */
2602 rc = lpfc_idiag_que_param_check(
2603 phba->sli4_hba.hdr_rq, index, count);
2604 if (rc)
2605 goto error_out;
2606 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2607 goto pass_check;
2608 }
2609 /* DAT queue */
James Smart2e90f4b2011-12-13 13:22:37 -05002610 if (phba->sli4_hba.dat_rq &&
2611 phba->sli4_hba.dat_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04002612 /* Sanity check */
2613 rc = lpfc_idiag_que_param_check(
2614 phba->sli4_hba.dat_rq, index, count);
2615 if (rc)
2616 goto error_out;
2617 idiag.ptr_private = phba->sli4_hba.dat_rq;
2618 goto pass_check;
2619 }
2620 goto error_out;
2621 break;
2622 default:
2623 goto error_out;
2624 break;
2625 }
2626
2627pass_check:
2628
2629 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2630 if (count == LPFC_QUE_ACC_BROWSE)
2631 idiag.offset.last_rd = index;
2632 }
2633
2634 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2635 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2636 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2637 /* Additional sanity checks on write operation */
2638 pque = (struct lpfc_queue *)idiag.ptr_private;
2639 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2640 goto error_out;
2641 pentry = pque->qe[index].address;
2642 pentry += offset;
2643 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2644 *pentry = value;
2645 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2646 *pentry |= value;
2647 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2648 *pentry &= ~value;
2649 }
2650 return nbytes;
2651
2652error_out:
2653 /* Clean out command structure on command error out */
2654 memset(&idiag, 0, sizeof(idiag));
2655 return -EINVAL;
2656}
2657
2658/**
2659 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2660 * @phba: The pointer to hba structure.
2661 * @pbuffer: The pointer to the buffer to copy the data to.
2662 * @len: The lenght of bytes to copied.
2663 * @drbregid: The id to doorbell registers.
2664 *
2665 * Description:
2666 * This routine reads a doorbell register and copies its content to the
2667 * user buffer pointed to by @pbuffer.
2668 *
2669 * Returns:
2670 * This function returns the amount of data that was copied into @pbuffer.
2671 **/
2672static int
2673lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2674 int len, uint32_t drbregid)
2675{
2676
2677 if (!pbuffer)
2678 return 0;
2679
2680 switch (drbregid) {
2681 case LPFC_DRB_EQCQ:
2682 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2683 "EQCQ-DRB-REG: 0x%08x\n",
2684 readl(phba->sli4_hba.EQCQDBregaddr));
2685 break;
2686 case LPFC_DRB_MQ:
2687 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2688 "MQ-DRB-REG: 0x%08x\n",
2689 readl(phba->sli4_hba.MQDBregaddr));
2690 break;
2691 case LPFC_DRB_WQ:
2692 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2693 "WQ-DRB-REG: 0x%08x\n",
2694 readl(phba->sli4_hba.WQDBregaddr));
2695 break;
2696 case LPFC_DRB_RQ:
2697 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2698 "RQ-DRB-REG: 0x%08x\n",
2699 readl(phba->sli4_hba.RQDBregaddr));
2700 break;
2701 default:
2702 break;
2703 }
2704
2705 return len;
2706}
2707
2708/**
2709 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2710 * @file: The file pointer to read from.
2711 * @buf: The buffer to copy the data to.
2712 * @nbytes: The number of bytes to read.
2713 * @ppos: The position in the file to start reading from.
2714 *
2715 * Description:
2716 * This routine reads data from the @phba device doorbell register according
2717 * to the idiag command, and copies to user @buf. Depending on the doorbell
2718 * register read command setup, it does either a single doorbell register
2719 * read or dump all doorbell registers.
2720 *
2721 * Returns:
2722 * This function returns the amount of data that was read (this could be less
2723 * than @nbytes if the end of the file was reached) or a negative error value.
2724 **/
2725static ssize_t
2726lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2727 loff_t *ppos)
2728{
2729 struct lpfc_debug *debug = file->private_data;
2730 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2731 uint32_t drb_reg_id, i;
2732 char *pbuffer;
2733 int len = 0;
2734
2735 /* This is a user read operation */
2736 debug->op = LPFC_IDIAG_OP_RD;
2737
2738 if (!debug->buffer)
2739 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2740 if (!debug->buffer)
2741 return 0;
2742 pbuffer = debug->buffer;
2743
2744 if (*ppos)
2745 return 0;
2746
2747 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
James Smartb76f2dc2011-07-22 18:37:42 -04002748 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
James Smart86a80842011-04-16 11:03:04 -04002749 else
2750 return 0;
2751
2752 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2753 for (i = 1; i <= LPFC_DRB_MAX; i++)
2754 len = lpfc_idiag_drbacc_read_reg(phba,
2755 pbuffer, len, i);
2756 else
2757 len = lpfc_idiag_drbacc_read_reg(phba,
2758 pbuffer, len, drb_reg_id);
2759
2760 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2761}
2762
2763/**
2764 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2765 * @file: The file pointer to read from.
2766 * @buf: The buffer to copy the user data from.
2767 * @nbytes: The number of bytes to get.
2768 * @ppos: The position in the file to start reading from.
2769 *
2770 * This routine get the debugfs idiag command struct from user space and then
2771 * perform the syntax check for port doorbell register read (dump) or write
2772 * (set) command accordingly. In the case of port queue read command, it sets
2773 * up the command in the idiag command struct for the following debugfs read
2774 * operation. In the case of port doorbell register write operation, it
2775 * executes the write operation into the port doorbell register accordingly.
2776 *
2777 * It returns the @nbytges passing in from debugfs user space when successful.
2778 * In case of error conditions, it returns proper error code back to the user
2779 * space.
2780 **/
2781static ssize_t
2782lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2783 size_t nbytes, loff_t *ppos)
2784{
2785 struct lpfc_debug *debug = file->private_data;
2786 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
James Smartb76f2dc2011-07-22 18:37:42 -04002787 uint32_t drb_reg_id, value, reg_val = 0;
James Smart86a80842011-04-16 11:03:04 -04002788 void __iomem *drb_reg;
2789 int rc;
2790
2791 /* This is a user write operation */
2792 debug->op = LPFC_IDIAG_OP_WR;
2793
2794 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2795 if (rc < 0)
2796 return rc;
2797
2798 /* Sanity check on command line arguments */
James Smartb76f2dc2011-07-22 18:37:42 -04002799 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2800 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04002801
2802 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2803 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2804 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2805 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2806 goto error_out;
2807 if (drb_reg_id > LPFC_DRB_MAX)
2808 goto error_out;
2809 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2810 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2811 goto error_out;
2812 if ((drb_reg_id > LPFC_DRB_MAX) &&
2813 (drb_reg_id != LPFC_DRB_ACC_ALL))
2814 goto error_out;
2815 } else
2816 goto error_out;
2817
2818 /* Perform the write access operation */
2819 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2820 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2821 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2822 switch (drb_reg_id) {
2823 case LPFC_DRB_EQCQ:
2824 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2825 break;
2826 case LPFC_DRB_MQ:
2827 drb_reg = phba->sli4_hba.MQDBregaddr;
2828 break;
2829 case LPFC_DRB_WQ:
2830 drb_reg = phba->sli4_hba.WQDBregaddr;
2831 break;
2832 case LPFC_DRB_RQ:
2833 drb_reg = phba->sli4_hba.RQDBregaddr;
2834 break;
2835 default:
2836 goto error_out;
2837 }
2838
2839 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2840 reg_val = value;
2841 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2842 reg_val = readl(drb_reg);
2843 reg_val |= value;
2844 }
2845 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2846 reg_val = readl(drb_reg);
2847 reg_val &= ~value;
2848 }
2849 writel(reg_val, drb_reg);
2850 readl(drb_reg); /* flush */
2851 }
2852 return nbytes;
2853
2854error_out:
2855 /* Clean out command structure on command error out */
2856 memset(&idiag, 0, sizeof(idiag));
2857 return -EINVAL;
2858}
2859
James Smartb76f2dc2011-07-22 18:37:42 -04002860/**
2861 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2862 * @phba: The pointer to hba structure.
2863 * @pbuffer: The pointer to the buffer to copy the data to.
2864 * @len: The lenght of bytes to copied.
2865 * @drbregid: The id to doorbell registers.
2866 *
2867 * Description:
2868 * This routine reads a control register and copies its content to the
2869 * user buffer pointed to by @pbuffer.
2870 *
2871 * Returns:
2872 * This function returns the amount of data that was copied into @pbuffer.
2873 **/
2874static int
2875lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2876 int len, uint32_t ctlregid)
2877{
2878
2879 if (!pbuffer)
2880 return 0;
2881
2882 switch (ctlregid) {
2883 case LPFC_CTL_PORT_SEM:
2884 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2885 "Port SemReg: 0x%08x\n",
2886 readl(phba->sli4_hba.conf_regs_memmap_p +
2887 LPFC_CTL_PORT_SEM_OFFSET));
2888 break;
2889 case LPFC_CTL_PORT_STA:
2890 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2891 "Port StaReg: 0x%08x\n",
2892 readl(phba->sli4_hba.conf_regs_memmap_p +
2893 LPFC_CTL_PORT_STA_OFFSET));
2894 break;
2895 case LPFC_CTL_PORT_CTL:
2896 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2897 "Port CtlReg: 0x%08x\n",
2898 readl(phba->sli4_hba.conf_regs_memmap_p +
2899 LPFC_CTL_PORT_CTL_OFFSET));
2900 break;
2901 case LPFC_CTL_PORT_ER1:
2902 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2903 "Port Er1Reg: 0x%08x\n",
2904 readl(phba->sli4_hba.conf_regs_memmap_p +
2905 LPFC_CTL_PORT_ER1_OFFSET));
2906 break;
2907 case LPFC_CTL_PORT_ER2:
2908 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2909 "Port Er2Reg: 0x%08x\n",
2910 readl(phba->sli4_hba.conf_regs_memmap_p +
2911 LPFC_CTL_PORT_ER2_OFFSET));
2912 break;
2913 case LPFC_CTL_PDEV_CTL:
2914 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2915 "PDev CtlReg: 0x%08x\n",
2916 readl(phba->sli4_hba.conf_regs_memmap_p +
2917 LPFC_CTL_PDEV_CTL_OFFSET));
2918 break;
2919 default:
2920 break;
2921 }
2922 return len;
2923}
2924
2925/**
2926 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2927 * @file: The file pointer to read from.
2928 * @buf: The buffer to copy the data to.
2929 * @nbytes: The number of bytes to read.
2930 * @ppos: The position in the file to start reading from.
2931 *
2932 * Description:
2933 * This routine reads data from the @phba port and device registers according
2934 * to the idiag command, and copies to user @buf.
2935 *
2936 * Returns:
2937 * This function returns the amount of data that was read (this could be less
2938 * than @nbytes if the end of the file was reached) or a negative error value.
2939 **/
2940static ssize_t
2941lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2942 loff_t *ppos)
2943{
2944 struct lpfc_debug *debug = file->private_data;
2945 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2946 uint32_t ctl_reg_id, i;
2947 char *pbuffer;
2948 int len = 0;
2949
2950 /* This is a user read operation */
2951 debug->op = LPFC_IDIAG_OP_RD;
2952
2953 if (!debug->buffer)
2954 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2955 if (!debug->buffer)
2956 return 0;
2957 pbuffer = debug->buffer;
2958
2959 if (*ppos)
2960 return 0;
2961
2962 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2963 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2964 else
2965 return 0;
2966
2967 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2968 for (i = 1; i <= LPFC_CTL_MAX; i++)
2969 len = lpfc_idiag_ctlacc_read_reg(phba,
2970 pbuffer, len, i);
2971 else
2972 len = lpfc_idiag_ctlacc_read_reg(phba,
2973 pbuffer, len, ctl_reg_id);
2974
2975 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2976}
2977
2978/**
2979 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2980 * @file: The file pointer to read from.
2981 * @buf: The buffer to copy the user data from.
2982 * @nbytes: The number of bytes to get.
2983 * @ppos: The position in the file to start reading from.
2984 *
2985 * This routine get the debugfs idiag command struct from user space and then
2986 * perform the syntax check for port and device control register read (dump)
2987 * or write (set) command accordingly.
2988 *
2989 * It returns the @nbytges passing in from debugfs user space when successful.
2990 * In case of error conditions, it returns proper error code back to the user
2991 * space.
2992 **/
2993static ssize_t
2994lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
2995 size_t nbytes, loff_t *ppos)
2996{
2997 struct lpfc_debug *debug = file->private_data;
2998 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2999 uint32_t ctl_reg_id, value, reg_val = 0;
3000 void __iomem *ctl_reg;
3001 int rc;
3002
3003 /* This is a user write operation */
3004 debug->op = LPFC_IDIAG_OP_WR;
3005
3006 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3007 if (rc < 0)
3008 return rc;
3009
3010 /* Sanity check on command line arguments */
3011 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
3012 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
3013
3014 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
3015 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
3016 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3017 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
3018 goto error_out;
3019 if (ctl_reg_id > LPFC_CTL_MAX)
3020 goto error_out;
3021 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
3022 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
3023 goto error_out;
3024 if ((ctl_reg_id > LPFC_CTL_MAX) &&
3025 (ctl_reg_id != LPFC_CTL_ACC_ALL))
3026 goto error_out;
3027 } else
3028 goto error_out;
3029
3030 /* Perform the write access operation */
3031 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
3032 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
3033 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3034 switch (ctl_reg_id) {
3035 case LPFC_CTL_PORT_SEM:
3036 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3037 LPFC_CTL_PORT_SEM_OFFSET;
3038 break;
3039 case LPFC_CTL_PORT_STA:
3040 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3041 LPFC_CTL_PORT_STA_OFFSET;
3042 break;
3043 case LPFC_CTL_PORT_CTL:
3044 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3045 LPFC_CTL_PORT_CTL_OFFSET;
3046 break;
3047 case LPFC_CTL_PORT_ER1:
3048 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3049 LPFC_CTL_PORT_ER1_OFFSET;
3050 break;
3051 case LPFC_CTL_PORT_ER2:
3052 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3053 LPFC_CTL_PORT_ER2_OFFSET;
3054 break;
3055 case LPFC_CTL_PDEV_CTL:
3056 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
3057 LPFC_CTL_PDEV_CTL_OFFSET;
3058 break;
3059 default:
3060 goto error_out;
3061 }
3062
3063 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
3064 reg_val = value;
3065 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
3066 reg_val = readl(ctl_reg);
3067 reg_val |= value;
3068 }
3069 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3070 reg_val = readl(ctl_reg);
3071 reg_val &= ~value;
3072 }
3073 writel(reg_val, ctl_reg);
3074 readl(ctl_reg); /* flush */
3075 }
3076 return nbytes;
3077
3078error_out:
3079 /* Clean out command structure on command error out */
3080 memset(&idiag, 0, sizeof(idiag));
3081 return -EINVAL;
3082}
3083
3084/**
3085 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
3086 * @phba: Pointer to HBA context object.
3087 * @pbuffer: Pointer to data buffer.
3088 *
3089 * Description:
3090 * This routine gets the driver mailbox access debugfs setup information.
3091 *
3092 * Returns:
3093 * This function returns the amount of data that was read (this could be less
3094 * than @nbytes if the end of the file was reached) or a negative error value.
3095 **/
3096static int
3097lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
3098{
3099 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3100 int len = 0;
3101
3102 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3103 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3104 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3105 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3106
3107 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3108 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
3109 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3110 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
3111 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3112 "mbx_word_cnt: %04d\n", mbx_word_cnt);
3113 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3114 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
3115
3116 return len;
3117}
3118
3119/**
3120 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
3121 * @file: The file pointer to read from.
3122 * @buf: The buffer to copy the data to.
3123 * @nbytes: The number of bytes to read.
3124 * @ppos: The position in the file to start reading from.
3125 *
3126 * Description:
3127 * This routine reads data from the @phba driver mailbox access debugfs setup
3128 * information.
3129 *
3130 * Returns:
3131 * This function returns the amount of data that was read (this could be less
3132 * than @nbytes if the end of the file was reached) or a negative error value.
3133 **/
3134static ssize_t
3135lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
3136 loff_t *ppos)
3137{
3138 struct lpfc_debug *debug = file->private_data;
3139 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3140 char *pbuffer;
3141 int len = 0;
3142
3143 /* This is a user read operation */
3144 debug->op = LPFC_IDIAG_OP_RD;
3145
3146 if (!debug->buffer)
3147 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
3148 if (!debug->buffer)
3149 return 0;
3150 pbuffer = debug->buffer;
3151
3152 if (*ppos)
3153 return 0;
3154
3155 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
3156 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
3157 return 0;
3158
3159 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
3160
3161 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3162}
3163
3164/**
3165 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
3166 * @file: The file pointer to read from.
3167 * @buf: The buffer to copy the user data from.
3168 * @nbytes: The number of bytes to get.
3169 * @ppos: The position in the file to start reading from.
3170 *
3171 * This routine get the debugfs idiag command struct from user space and then
3172 * perform the syntax check for driver mailbox command (dump) and sets up the
3173 * necessary states in the idiag command struct accordingly.
3174 *
3175 * It returns the @nbytges passing in from debugfs user space when successful.
3176 * In case of error conditions, it returns proper error code back to the user
3177 * space.
3178 **/
3179static ssize_t
3180lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
3181 size_t nbytes, loff_t *ppos)
3182{
3183 struct lpfc_debug *debug = file->private_data;
3184 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3185 int rc;
3186
3187 /* This is a user write operation */
3188 debug->op = LPFC_IDIAG_OP_WR;
3189
3190 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3191 if (rc < 0)
3192 return rc;
3193
3194 /* Sanity check on command line arguments */
3195 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3196 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3197 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3198 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3199
3200 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
3201 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
3202 goto error_out;
3203 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
3204 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3205 goto error_out;
3206 if (mbx_word_cnt > sizeof(MAILBOX_t))
3207 goto error_out;
3208 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
3209 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
3210 goto error_out;
3211 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
3212 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3213 goto error_out;
3214 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3215 goto error_out;
3216 if (mbx_mbox_cmd != 0x9b)
3217 goto error_out;
3218 } else
3219 goto error_out;
3220
3221 if (mbx_word_cnt == 0)
3222 goto error_out;
3223 if (rc != LPFC_MBX_DMP_ARG)
3224 goto error_out;
3225 if (mbx_mbox_cmd & ~0xff)
3226 goto error_out;
3227
3228 /* condition for stop mailbox dump */
3229 if (mbx_dump_cnt == 0)
3230 goto reset_out;
3231
3232 return nbytes;
3233
3234reset_out:
3235 /* Clean out command structure on command error out */
3236 memset(&idiag, 0, sizeof(idiag));
3237 return nbytes;
3238
3239error_out:
3240 /* Clean out command structure on command error out */
3241 memset(&idiag, 0, sizeof(idiag));
3242 return -EINVAL;
3243}
3244
3245/**
3246 * lpfc_idiag_extacc_avail_get - get the available extents information
3247 * @phba: pointer to lpfc hba data structure.
3248 * @pbuffer: pointer to internal buffer.
3249 * @len: length into the internal buffer data has been copied.
3250 *
3251 * Description:
3252 * This routine is to get the available extent information.
3253 *
3254 * Returns:
3255 * overall lenth of the data read into the internal buffer.
3256 **/
3257static int
3258lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3259{
3260 uint16_t ext_cnt, ext_size;
3261
3262 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3263 "\nAvailable Extents Information:\n");
3264
3265 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3266 "\tPort Available VPI extents: ");
3267 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3268 &ext_cnt, &ext_size);
3269 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3270 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3271
3272 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3273 "\tPort Available VFI extents: ");
3274 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3275 &ext_cnt, &ext_size);
3276 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3277 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3278
3279 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3280 "\tPort Available RPI extents: ");
3281 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3282 &ext_cnt, &ext_size);
3283 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3284 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3285
3286 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3287 "\tPort Available XRI extents: ");
3288 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3289 &ext_cnt, &ext_size);
3290 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3291 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3292
3293 return len;
3294}
3295
3296/**
3297 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3298 * @phba: pointer to lpfc hba data structure.
3299 * @pbuffer: pointer to internal buffer.
3300 * @len: length into the internal buffer data has been copied.
3301 *
3302 * Description:
3303 * This routine is to get the allocated extent information.
3304 *
3305 * Returns:
3306 * overall lenth of the data read into the internal buffer.
3307 **/
3308static int
3309lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3310{
3311 uint16_t ext_cnt, ext_size;
3312 int rc;
3313
3314 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3315 "\nAllocated Extents Information:\n");
3316
3317 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3318 "\tHost Allocated VPI extents: ");
3319 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
3320 &ext_cnt, &ext_size);
3321 if (!rc)
3322 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3323 "Port %d Extent %3d, Size %3d\n",
3324 phba->brd_no, ext_cnt, ext_size);
3325 else
3326 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3327 "N/A\n");
3328
3329 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3330 "\tHost Allocated VFI extents: ");
3331 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
3332 &ext_cnt, &ext_size);
3333 if (!rc)
3334 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3335 "Port %d Extent %3d, Size %3d\n",
3336 phba->brd_no, ext_cnt, ext_size);
3337 else
3338 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3339 "N/A\n");
3340
3341 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3342 "\tHost Allocated RPI extents: ");
3343 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
3344 &ext_cnt, &ext_size);
3345 if (!rc)
3346 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3347 "Port %d Extent %3d, Size %3d\n",
3348 phba->brd_no, ext_cnt, ext_size);
3349 else
3350 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3351 "N/A\n");
3352
3353 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3354 "\tHost Allocated XRI extents: ");
3355 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
3356 &ext_cnt, &ext_size);
3357 if (!rc)
3358 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3359 "Port %d Extent %3d, Size %3d\n",
3360 phba->brd_no, ext_cnt, ext_size);
3361 else
3362 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3363 "N/A\n");
3364
3365 return len;
3366}
3367
3368/**
3369 * lpfc_idiag_extacc_drivr_get - get driver extent information
3370 * @phba: pointer to lpfc hba data structure.
3371 * @pbuffer: pointer to internal buffer.
3372 * @len: length into the internal buffer data has been copied.
3373 *
3374 * Description:
3375 * This routine is to get the driver extent information.
3376 *
3377 * Returns:
3378 * overall lenth of the data read into the internal buffer.
3379 **/
3380static int
3381lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3382{
3383 struct lpfc_rsrc_blks *rsrc_blks;
3384 int index;
3385
3386 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3387 "\nDriver Extents Information:\n");
3388
3389 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3390 "\tVPI extents:\n");
3391 index = 0;
3392 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3393 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3394 "\t\tBlock %3d: Start %4d, Count %4d\n",
3395 index, rsrc_blks->rsrc_start,
3396 rsrc_blks->rsrc_size);
3397 index++;
3398 }
3399 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3400 "\tVFI extents:\n");
3401 index = 0;
3402 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
3403 list) {
3404 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3405 "\t\tBlock %3d: Start %4d, Count %4d\n",
3406 index, rsrc_blks->rsrc_start,
3407 rsrc_blks->rsrc_size);
3408 index++;
3409 }
3410
3411 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3412 "\tRPI extents:\n");
3413 index = 0;
3414 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
3415 list) {
3416 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3417 "\t\tBlock %3d: Start %4d, Count %4d\n",
3418 index, rsrc_blks->rsrc_start,
3419 rsrc_blks->rsrc_size);
3420 index++;
3421 }
3422
3423 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3424 "\tXRI extents:\n");
3425 index = 0;
3426 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
3427 list) {
3428 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3429 "\t\tBlock %3d: Start %4d, Count %4d\n",
3430 index, rsrc_blks->rsrc_start,
3431 rsrc_blks->rsrc_size);
3432 index++;
3433 }
3434
3435 return len;
3436}
3437
3438/**
3439 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3440 * @file: The file pointer to read from.
3441 * @buf: The buffer to copy the user data from.
3442 * @nbytes: The number of bytes to get.
3443 * @ppos: The position in the file to start reading from.
3444 *
3445 * This routine get the debugfs idiag command struct from user space and then
3446 * perform the syntax check for extent information access commands and sets
3447 * up the necessary states in the idiag command struct accordingly.
3448 *
3449 * It returns the @nbytges passing in from debugfs user space when successful.
3450 * In case of error conditions, it returns proper error code back to the user
3451 * space.
3452 **/
3453static ssize_t
3454lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3455 size_t nbytes, loff_t *ppos)
3456{
3457 struct lpfc_debug *debug = file->private_data;
3458 uint32_t ext_map;
3459 int rc;
3460
3461 /* This is a user write operation */
3462 debug->op = LPFC_IDIAG_OP_WR;
3463
3464 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3465 if (rc < 0)
3466 return rc;
3467
3468 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3469
3470 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3471 goto error_out;
3472 if (rc != LPFC_EXT_ACC_CMD_ARG)
3473 goto error_out;
3474 if (!(ext_map & LPFC_EXT_ACC_ALL))
3475 goto error_out;
3476
3477 return nbytes;
3478error_out:
3479 /* Clean out command structure on command error out */
3480 memset(&idiag, 0, sizeof(idiag));
3481 return -EINVAL;
3482}
3483
3484/**
3485 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3486 * @file: The file pointer to read from.
3487 * @buf: The buffer to copy the data to.
3488 * @nbytes: The number of bytes to read.
3489 * @ppos: The position in the file to start reading from.
3490 *
3491 * Description:
3492 * This routine reads data from the proper extent information according to
3493 * the idiag command, and copies to user @buf.
3494 *
3495 * Returns:
3496 * This function returns the amount of data that was read (this could be less
3497 * than @nbytes if the end of the file was reached) or a negative error value.
3498 **/
3499static ssize_t
3500lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3501 loff_t *ppos)
3502{
3503 struct lpfc_debug *debug = file->private_data;
3504 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3505 char *pbuffer;
3506 uint32_t ext_map;
3507 int len = 0;
3508
3509 /* This is a user read operation */
3510 debug->op = LPFC_IDIAG_OP_RD;
3511
3512 if (!debug->buffer)
3513 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3514 if (!debug->buffer)
3515 return 0;
3516 pbuffer = debug->buffer;
3517 if (*ppos)
3518 return 0;
3519 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3520 return 0;
3521
3522 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3523 if (ext_map & LPFC_EXT_ACC_AVAIL)
3524 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3525 if (ext_map & LPFC_EXT_ACC_ALLOC)
3526 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3527 if (ext_map & LPFC_EXT_ACC_DRIVR)
3528 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3529
3530 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3531}
3532
James Smart858c9f62007-06-17 19:56:39 -05003533#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003534static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05003535 .owner = THIS_MODULE,
3536 .open = lpfc_debugfs_disc_trc_open,
3537 .llseek = lpfc_debugfs_lseek,
3538 .read = lpfc_debugfs_read,
3539 .release = lpfc_debugfs_release,
3540};
3541
3542#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003543static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05003544 .owner = THIS_MODULE,
3545 .open = lpfc_debugfs_nodelist_open,
3546 .llseek = lpfc_debugfs_lseek,
3547 .read = lpfc_debugfs_read,
3548 .release = lpfc_debugfs_release,
3549};
3550
James Smart78b2d852007-08-02 11:10:21 -04003551#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003552static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04003553 .owner = THIS_MODULE,
3554 .open = lpfc_debugfs_hbqinfo_open,
3555 .llseek = lpfc_debugfs_lseek,
3556 .read = lpfc_debugfs_read,
3557 .release = lpfc_debugfs_release,
3558};
3559
James Smartc95d6c62008-01-11 01:53:23 -05003560#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003561static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04003562 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05003563 .open = lpfc_debugfs_dumpHBASlim_open,
3564 .llseek = lpfc_debugfs_lseek,
3565 .read = lpfc_debugfs_read,
3566 .release = lpfc_debugfs_release,
3567};
3568
3569#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003570static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05003571 .owner = THIS_MODULE,
3572 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04003573 .llseek = lpfc_debugfs_lseek,
3574 .read = lpfc_debugfs_read,
3575 .release = lpfc_debugfs_release,
3576};
3577
James Smarte2a0a9d2008-12-04 22:40:02 -05003578#undef lpfc_debugfs_op_dumpData
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003579static const struct file_operations lpfc_debugfs_op_dumpData = {
James Smarte2a0a9d2008-12-04 22:40:02 -05003580 .owner = THIS_MODULE,
3581 .open = lpfc_debugfs_dumpData_open,
3582 .llseek = lpfc_debugfs_lseek,
3583 .read = lpfc_debugfs_read,
3584 .write = lpfc_debugfs_dumpDataDif_write,
3585 .release = lpfc_debugfs_dumpDataDif_release,
3586};
3587
3588#undef lpfc_debugfs_op_dumpDif
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003589static const struct file_operations lpfc_debugfs_op_dumpDif = {
James Smarte2a0a9d2008-12-04 22:40:02 -05003590 .owner = THIS_MODULE,
3591 .open = lpfc_debugfs_dumpDif_open,
3592 .llseek = lpfc_debugfs_lseek,
3593 .read = lpfc_debugfs_read,
3594 .write = lpfc_debugfs_dumpDataDif_write,
3595 .release = lpfc_debugfs_dumpDataDif_release,
3596};
3597
James Smartf9bb2da2011-10-10 21:34:11 -04003598#undef lpfc_debugfs_op_dif_err
3599static const struct file_operations lpfc_debugfs_op_dif_err = {
3600 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07003601 .open = simple_open,
James Smartf9bb2da2011-10-10 21:34:11 -04003602 .llseek = lpfc_debugfs_lseek,
3603 .read = lpfc_debugfs_dif_err_read,
3604 .write = lpfc_debugfs_dif_err_write,
3605 .release = lpfc_debugfs_dif_err_release,
3606};
3607
James Smarta58cbd52007-08-02 11:09:43 -04003608#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01003609static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04003610 .owner = THIS_MODULE,
3611 .open = lpfc_debugfs_slow_ring_trc_open,
3612 .llseek = lpfc_debugfs_lseek,
3613 .read = lpfc_debugfs_read,
3614 .release = lpfc_debugfs_release,
3615};
3616
James Smart858c9f62007-06-17 19:56:39 -05003617static struct dentry *lpfc_debugfs_root = NULL;
3618static atomic_t lpfc_debugfs_hba_count;
James Smart2a622bf2011-02-16 12:40:06 -05003619
3620/*
3621 * File operations for the iDiag debugfs
3622 */
3623#undef lpfc_idiag_op_pciCfg
3624static const struct file_operations lpfc_idiag_op_pciCfg = {
3625 .owner = THIS_MODULE,
3626 .open = lpfc_idiag_open,
3627 .llseek = lpfc_debugfs_lseek,
3628 .read = lpfc_idiag_pcicfg_read,
3629 .write = lpfc_idiag_pcicfg_write,
3630 .release = lpfc_idiag_cmd_release,
3631};
3632
James Smartb76f2dc2011-07-22 18:37:42 -04003633#undef lpfc_idiag_op_barAcc
3634static const struct file_operations lpfc_idiag_op_barAcc = {
3635 .owner = THIS_MODULE,
3636 .open = lpfc_idiag_open,
3637 .llseek = lpfc_debugfs_lseek,
3638 .read = lpfc_idiag_baracc_read,
3639 .write = lpfc_idiag_baracc_write,
3640 .release = lpfc_idiag_cmd_release,
3641};
3642
James Smart2a622bf2011-02-16 12:40:06 -05003643#undef lpfc_idiag_op_queInfo
3644static const struct file_operations lpfc_idiag_op_queInfo = {
3645 .owner = THIS_MODULE,
3646 .open = lpfc_idiag_open,
3647 .read = lpfc_idiag_queinfo_read,
3648 .release = lpfc_idiag_release,
3649};
3650
James Smartb76f2dc2011-07-22 18:37:42 -04003651#undef lpfc_idiag_op_queAcc
James Smart86a80842011-04-16 11:03:04 -04003652static const struct file_operations lpfc_idiag_op_queAcc = {
3653 .owner = THIS_MODULE,
3654 .open = lpfc_idiag_open,
3655 .llseek = lpfc_debugfs_lseek,
3656 .read = lpfc_idiag_queacc_read,
3657 .write = lpfc_idiag_queacc_write,
3658 .release = lpfc_idiag_cmd_release,
3659};
3660
James Smartb76f2dc2011-07-22 18:37:42 -04003661#undef lpfc_idiag_op_drbAcc
James Smart86a80842011-04-16 11:03:04 -04003662static const struct file_operations lpfc_idiag_op_drbAcc = {
3663 .owner = THIS_MODULE,
3664 .open = lpfc_idiag_open,
3665 .llseek = lpfc_debugfs_lseek,
3666 .read = lpfc_idiag_drbacc_read,
3667 .write = lpfc_idiag_drbacc_write,
3668 .release = lpfc_idiag_cmd_release,
3669};
3670
James Smartb76f2dc2011-07-22 18:37:42 -04003671#undef lpfc_idiag_op_ctlAcc
3672static const struct file_operations lpfc_idiag_op_ctlAcc = {
3673 .owner = THIS_MODULE,
3674 .open = lpfc_idiag_open,
3675 .llseek = lpfc_debugfs_lseek,
3676 .read = lpfc_idiag_ctlacc_read,
3677 .write = lpfc_idiag_ctlacc_write,
3678 .release = lpfc_idiag_cmd_release,
3679};
3680
3681#undef lpfc_idiag_op_mbxAcc
3682static const struct file_operations lpfc_idiag_op_mbxAcc = {
3683 .owner = THIS_MODULE,
3684 .open = lpfc_idiag_open,
3685 .llseek = lpfc_debugfs_lseek,
3686 .read = lpfc_idiag_mbxacc_read,
3687 .write = lpfc_idiag_mbxacc_write,
3688 .release = lpfc_idiag_cmd_release,
3689};
3690
3691#undef lpfc_idiag_op_extAcc
3692static const struct file_operations lpfc_idiag_op_extAcc = {
3693 .owner = THIS_MODULE,
3694 .open = lpfc_idiag_open,
3695 .llseek = lpfc_debugfs_lseek,
3696 .read = lpfc_idiag_extacc_read,
3697 .write = lpfc_idiag_extacc_write,
3698 .release = lpfc_idiag_cmd_release,
3699};
3700
James Smart858c9f62007-06-17 19:56:39 -05003701#endif
3702
James Smartb76f2dc2011-07-22 18:37:42 -04003703/* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3704 * @phba: Pointer to HBA context object.
3705 * @dmabuf: Pointer to a DMA buffer descriptor.
3706 *
3707 * Description:
3708 * This routine dump a bsg pass-through non-embedded mailbox command with
3709 * external buffer.
3710 **/
3711void
3712lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3713 enum mbox_type mbox_tp, enum dma_type dma_tp,
3714 enum sta_type sta_tp,
3715 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3716{
3717#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3718 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3719 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3720 int len = 0;
3721 uint32_t do_dump = 0;
3722 uint32_t *pword;
3723 uint32_t i;
3724
3725 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3726 return;
3727
3728 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3729 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3730 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3731 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3732
3733 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3734 (*mbx_dump_cnt == 0) ||
3735 (*mbx_word_cnt == 0))
3736 return;
3737
3738 if (*mbx_mbox_cmd != 0x9B)
3739 return;
3740
3741 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3742 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3743 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
James Smart2ea259e2017-02-12 13:52:27 -08003744 pr_err("\nRead mbox command (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04003745 "nemb:0x%x, extbuf_cnt:%d:\n",
3746 sta_tp, nemb_tp, ext_buf);
3747 }
3748 }
3749 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3750 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3751 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
James Smart2ea259e2017-02-12 13:52:27 -08003752 pr_err("\nRead mbox buffer (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04003753 "nemb:0x%x, extbuf_seq:%d:\n",
3754 sta_tp, nemb_tp, ext_buf);
3755 }
3756 }
3757 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3758 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3759 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
James Smart2ea259e2017-02-12 13:52:27 -08003760 pr_err("\nWrite mbox command (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04003761 "nemb:0x%x, extbuf_cnt:%d:\n",
3762 sta_tp, nemb_tp, ext_buf);
3763 }
3764 }
3765 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3766 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3767 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
James Smart2ea259e2017-02-12 13:52:27 -08003768 pr_err("\nWrite mbox buffer (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04003769 "nemb:0x%x, extbuf_seq:%d:\n",
3770 sta_tp, nemb_tp, ext_buf);
3771 }
3772 }
3773
3774 /* dump buffer content */
3775 if (do_dump) {
3776 pword = (uint32_t *)dmabuf->virt;
3777 for (i = 0; i < *mbx_word_cnt; i++) {
3778 if (!(i % 8)) {
3779 if (i != 0)
James Smart2ea259e2017-02-12 13:52:27 -08003780 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04003781 len = 0;
3782 len += snprintf(line_buf+len,
3783 LPFC_MBX_ACC_LBUF_SZ-len,
3784 "%03d: ", i);
3785 }
3786 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3787 "%08x ", (uint32_t)*pword);
3788 pword++;
3789 }
3790 if ((i - 1) % 8)
James Smart2ea259e2017-02-12 13:52:27 -08003791 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04003792 (*mbx_dump_cnt)--;
3793 }
3794
3795 /* Clean out command structure on reaching dump count */
3796 if (*mbx_dump_cnt == 0)
3797 memset(&idiag, 0, sizeof(idiag));
3798 return;
3799#endif
3800}
3801
3802/* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3803 * @phba: Pointer to HBA context object.
3804 * @dmabuf: Pointer to a DMA buffer descriptor.
3805 *
3806 * Description:
3807 * This routine dump a pass-through non-embedded mailbox command from issue
3808 * mailbox command.
3809 **/
3810void
3811lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3812{
3813#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3814 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3815 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3816 int len = 0;
3817 uint32_t *pword;
3818 uint8_t *pbyte;
3819 uint32_t i, j;
3820
3821 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3822 return;
3823
3824 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3825 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3826 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3827 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3828
3829 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3830 (*mbx_dump_cnt == 0) ||
3831 (*mbx_word_cnt == 0))
3832 return;
3833
3834 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3835 (*mbx_mbox_cmd != pmbox->mbxCommand))
3836 return;
3837
3838 /* dump buffer content */
3839 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
James Smart2ea259e2017-02-12 13:52:27 -08003840 pr_err("Mailbox command:0x%x dump by word:\n",
James Smartb76f2dc2011-07-22 18:37:42 -04003841 pmbox->mbxCommand);
3842 pword = (uint32_t *)pmbox;
3843 for (i = 0; i < *mbx_word_cnt; i++) {
3844 if (!(i % 8)) {
3845 if (i != 0)
James Smart2ea259e2017-02-12 13:52:27 -08003846 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04003847 len = 0;
3848 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3849 len += snprintf(line_buf+len,
3850 LPFC_MBX_ACC_LBUF_SZ-len,
3851 "%03d: ", i);
3852 }
3853 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3854 "%08x ",
3855 ((uint32_t)*pword) & 0xffffffff);
3856 pword++;
3857 }
3858 if ((i - 1) % 8)
James Smart2ea259e2017-02-12 13:52:27 -08003859 pr_err("%s\n", line_buf);
3860 pr_err("\n");
James Smartb76f2dc2011-07-22 18:37:42 -04003861 }
3862 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
James Smart2ea259e2017-02-12 13:52:27 -08003863 pr_err("Mailbox command:0x%x dump by byte:\n",
James Smartb76f2dc2011-07-22 18:37:42 -04003864 pmbox->mbxCommand);
3865 pbyte = (uint8_t *)pmbox;
3866 for (i = 0; i < *mbx_word_cnt; i++) {
3867 if (!(i % 8)) {
3868 if (i != 0)
James Smart2ea259e2017-02-12 13:52:27 -08003869 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04003870 len = 0;
3871 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3872 len += snprintf(line_buf+len,
3873 LPFC_MBX_ACC_LBUF_SZ-len,
3874 "%03d: ", i);
3875 }
3876 for (j = 0; j < 4; j++) {
3877 len += snprintf(line_buf+len,
3878 LPFC_MBX_ACC_LBUF_SZ-len,
3879 "%02x",
3880 ((uint8_t)*pbyte) & 0xff);
3881 pbyte++;
3882 }
3883 len += snprintf(line_buf+len,
3884 LPFC_MBX_ACC_LBUF_SZ-len, " ");
3885 }
3886 if ((i - 1) % 8)
James Smart2ea259e2017-02-12 13:52:27 -08003887 pr_err("%s\n", line_buf);
3888 pr_err("\n");
James Smartb76f2dc2011-07-22 18:37:42 -04003889 }
3890 (*mbx_dump_cnt)--;
3891
3892 /* Clean out command structure on reaching dump count */
3893 if (*mbx_dump_cnt == 0)
3894 memset(&idiag, 0, sizeof(idiag));
3895 return;
3896#endif
3897}
3898
James Smarte59058c2008-08-24 21:49:00 -04003899/**
James Smart3621a712009-04-06 18:47:14 -04003900 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04003901 * @vport: The vport pointer to initialize.
3902 *
3903 * Description:
3904 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3905 * If not already created, this routine will create the lpfc directory, and
3906 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3907 * also create each file used to access lpfc specific debugfs information.
3908 **/
James Smart858c9f62007-06-17 19:56:39 -05003909inline void
3910lpfc_debugfs_initialize(struct lpfc_vport *vport)
3911{
James Smart923e4b62008-12-04 22:40:07 -05003912#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05003913 struct lpfc_hba *phba = vport->phba;
3914 char name[64];
3915 uint32_t num, i;
James Smartf6c3bdf2013-12-17 20:29:59 -05003916 bool pport_setup = false;
James Smart858c9f62007-06-17 19:56:39 -05003917
3918 if (!lpfc_debugfs_enable)
3919 return;
3920
James Smarta58cbd52007-08-02 11:09:43 -04003921 /* Setup lpfc root directory */
3922 if (!lpfc_debugfs_root) {
3923 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
3924 atomic_set(&lpfc_debugfs_hba_count, 0);
3925 if (!lpfc_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04003926 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003927 "0408 Cannot create debugfs root\n");
James Smarta58cbd52007-08-02 11:09:43 -04003928 goto debug_failed;
3929 }
3930 }
James Smarta58cbd52007-08-02 11:09:43 -04003931 if (!lpfc_debugfs_start_time)
3932 lpfc_debugfs_start_time = jiffies;
3933
James Smart2a622bf2011-02-16 12:40:06 -05003934 /* Setup funcX directory for specific HBA PCI function */
3935 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
James Smarta58cbd52007-08-02 11:09:43 -04003936 if (!phba->hba_debugfs_root) {
James Smartf6c3bdf2013-12-17 20:29:59 -05003937 pport_setup = true;
James Smarta58cbd52007-08-02 11:09:43 -04003938 phba->hba_debugfs_root =
3939 debugfs_create_dir(name, lpfc_debugfs_root);
3940 if (!phba->hba_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04003941 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003942 "0412 Cannot create debugfs hba\n");
James Smarta58cbd52007-08-02 11:09:43 -04003943 goto debug_failed;
3944 }
3945 atomic_inc(&lpfc_debugfs_hba_count);
3946 atomic_set(&phba->debugfs_vport_count, 0);
3947
James Smart78b2d852007-08-02 11:10:21 -04003948 /* Setup hbqinfo */
3949 snprintf(name, sizeof(name), "hbqinfo");
3950 phba->debug_hbqinfo =
3951 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3952 phba->hba_debugfs_root,
3953 phba, &lpfc_debugfs_op_hbqinfo);
3954 if (!phba->debug_hbqinfo) {
3955 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003956 "0411 Cannot create debugfs hbqinfo\n");
James Smart78b2d852007-08-02 11:10:21 -04003957 goto debug_failed;
3958 }
3959
James Smartc95d6c62008-01-11 01:53:23 -05003960 /* Setup dumpHBASlim */
James Smart2a622bf2011-02-16 12:40:06 -05003961 if (phba->sli_rev < LPFC_SLI_REV4) {
3962 snprintf(name, sizeof(name), "dumpHBASlim");
3963 phba->debug_dumpHBASlim =
3964 debugfs_create_file(name,
3965 S_IFREG|S_IRUGO|S_IWUSR,
3966 phba->hba_debugfs_root,
3967 phba, &lpfc_debugfs_op_dumpHBASlim);
3968 if (!phba->debug_dumpHBASlim) {
3969 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3970 "0413 Cannot create debugfs "
3971 "dumpHBASlim\n");
3972 goto debug_failed;
3973 }
3974 } else
3975 phba->debug_dumpHBASlim = NULL;
James Smartc95d6c62008-01-11 01:53:23 -05003976
3977 /* Setup dumpHostSlim */
James Smart2a622bf2011-02-16 12:40:06 -05003978 if (phba->sli_rev < LPFC_SLI_REV4) {
3979 snprintf(name, sizeof(name), "dumpHostSlim");
3980 phba->debug_dumpHostSlim =
3981 debugfs_create_file(name,
3982 S_IFREG|S_IRUGO|S_IWUSR,
3983 phba->hba_debugfs_root,
3984 phba, &lpfc_debugfs_op_dumpHostSlim);
3985 if (!phba->debug_dumpHostSlim) {
3986 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3987 "0414 Cannot create debugfs "
3988 "dumpHostSlim\n");
3989 goto debug_failed;
3990 }
3991 } else
Felipe Penab28d1082013-10-18 20:15:37 -03003992 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04003993
James Smarte2a0a9d2008-12-04 22:40:02 -05003994 /* Setup dumpData */
3995 snprintf(name, sizeof(name), "dumpData");
3996 phba->debug_dumpData =
3997 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3998 phba->hba_debugfs_root,
3999 phba, &lpfc_debugfs_op_dumpData);
4000 if (!phba->debug_dumpData) {
4001 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4002 "0800 Cannot create debugfs dumpData\n");
4003 goto debug_failed;
4004 }
4005
4006 /* Setup dumpDif */
4007 snprintf(name, sizeof(name), "dumpDif");
4008 phba->debug_dumpDif =
4009 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4010 phba->hba_debugfs_root,
4011 phba, &lpfc_debugfs_op_dumpDif);
4012 if (!phba->debug_dumpDif) {
4013 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4014 "0801 Cannot create debugfs dumpDif\n");
4015 goto debug_failed;
4016 }
4017
James Smartf9bb2da2011-10-10 21:34:11 -04004018 /* Setup DIF Error Injections */
4019 snprintf(name, sizeof(name), "InjErrLBA");
4020 phba->debug_InjErrLBA =
4021 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4022 phba->hba_debugfs_root,
4023 phba, &lpfc_debugfs_op_dif_err);
4024 if (!phba->debug_InjErrLBA) {
4025 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4026 "0807 Cannot create debugfs InjErrLBA\n");
4027 goto debug_failed;
4028 }
4029 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
4030
James Smart4ac9b222012-03-01 22:38:29 -05004031 snprintf(name, sizeof(name), "InjErrNPortID");
4032 phba->debug_InjErrNPortID =
4033 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4034 phba->hba_debugfs_root,
4035 phba, &lpfc_debugfs_op_dif_err);
4036 if (!phba->debug_InjErrNPortID) {
4037 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4038 "0809 Cannot create debugfs InjErrNPortID\n");
4039 goto debug_failed;
4040 }
4041
4042 snprintf(name, sizeof(name), "InjErrWWPN");
4043 phba->debug_InjErrWWPN =
4044 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4045 phba->hba_debugfs_root,
4046 phba, &lpfc_debugfs_op_dif_err);
4047 if (!phba->debug_InjErrWWPN) {
4048 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4049 "0810 Cannot create debugfs InjErrWWPN\n");
4050 goto debug_failed;
4051 }
4052
James Smartf9bb2da2011-10-10 21:34:11 -04004053 snprintf(name, sizeof(name), "writeGuardInjErr");
4054 phba->debug_writeGuard =
4055 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4056 phba->hba_debugfs_root,
4057 phba, &lpfc_debugfs_op_dif_err);
4058 if (!phba->debug_writeGuard) {
4059 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4060 "0802 Cannot create debugfs writeGuard\n");
4061 goto debug_failed;
4062 }
4063
4064 snprintf(name, sizeof(name), "writeAppInjErr");
4065 phba->debug_writeApp =
4066 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4067 phba->hba_debugfs_root,
4068 phba, &lpfc_debugfs_op_dif_err);
4069 if (!phba->debug_writeApp) {
4070 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4071 "0803 Cannot create debugfs writeApp\n");
4072 goto debug_failed;
4073 }
4074
4075 snprintf(name, sizeof(name), "writeRefInjErr");
4076 phba->debug_writeRef =
4077 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4078 phba->hba_debugfs_root,
4079 phba, &lpfc_debugfs_op_dif_err);
4080 if (!phba->debug_writeRef) {
4081 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4082 "0804 Cannot create debugfs writeRef\n");
4083 goto debug_failed;
4084 }
4085
James Smartacd68592012-01-18 16:25:09 -05004086 snprintf(name, sizeof(name), "readGuardInjErr");
4087 phba->debug_readGuard =
4088 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4089 phba->hba_debugfs_root,
4090 phba, &lpfc_debugfs_op_dif_err);
4091 if (!phba->debug_readGuard) {
4092 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4093 "0808 Cannot create debugfs readGuard\n");
4094 goto debug_failed;
4095 }
4096
James Smartf9bb2da2011-10-10 21:34:11 -04004097 snprintf(name, sizeof(name), "readAppInjErr");
4098 phba->debug_readApp =
4099 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4100 phba->hba_debugfs_root,
4101 phba, &lpfc_debugfs_op_dif_err);
4102 if (!phba->debug_readApp) {
4103 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4104 "0805 Cannot create debugfs readApp\n");
4105 goto debug_failed;
4106 }
4107
4108 snprintf(name, sizeof(name), "readRefInjErr");
4109 phba->debug_readRef =
4110 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4111 phba->hba_debugfs_root,
4112 phba, &lpfc_debugfs_op_dif_err);
4113 if (!phba->debug_readRef) {
4114 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4115 "0806 Cannot create debugfs readApp\n");
4116 goto debug_failed;
4117 }
4118
James Smarta58cbd52007-08-02 11:09:43 -04004119 /* Setup slow ring trace */
4120 if (lpfc_debugfs_max_slow_ring_trc) {
4121 num = lpfc_debugfs_max_slow_ring_trc - 1;
4122 if (num & lpfc_debugfs_max_slow_ring_trc) {
4123 /* Change to be a power of 2 */
4124 num = lpfc_debugfs_max_slow_ring_trc;
4125 i = 0;
4126 while (num > 1) {
4127 num = num >> 1;
4128 i++;
4129 }
4130 lpfc_debugfs_max_slow_ring_trc = (1 << i);
James Smart2ea259e2017-02-12 13:52:27 -08004131 pr_err("lpfc_debugfs_max_disc_trc changed to "
James Smarte8b62012007-08-02 11:10:09 -04004132 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04004133 }
4134 }
4135
James Smarta58cbd52007-08-02 11:09:43 -04004136 snprintf(name, sizeof(name), "slow_ring_trace");
4137 phba->debug_slow_ring_trc =
4138 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4139 phba->hba_debugfs_root,
4140 phba, &lpfc_debugfs_op_slow_ring_trc);
4141 if (!phba->debug_slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004142 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004143 "0415 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004144 "slow_ring_trace\n");
James Smarta58cbd52007-08-02 11:09:43 -04004145 goto debug_failed;
4146 }
4147 if (!phba->slow_ring_trc) {
4148 phba->slow_ring_trc = kmalloc(
4149 (sizeof(struct lpfc_debugfs_trc) *
4150 lpfc_debugfs_max_slow_ring_trc),
4151 GFP_KERNEL);
4152 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004153 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004154 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004155 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04004156 goto debug_failed;
4157 }
4158 atomic_set(&phba->slow_ring_trc_cnt, 0);
4159 memset(phba->slow_ring_trc, 0,
4160 (sizeof(struct lpfc_debugfs_trc) *
4161 lpfc_debugfs_max_slow_ring_trc));
4162 }
James Smart2ea259e2017-02-12 13:52:27 -08004163
James Smarta58cbd52007-08-02 11:09:43 -04004164 }
4165
4166 snprintf(name, sizeof(name), "vport%d", vport->vpi);
4167 if (!vport->vport_debugfs_root) {
4168 vport->vport_debugfs_root =
4169 debugfs_create_dir(name, phba->hba_debugfs_root);
4170 if (!vport->vport_debugfs_root) {
James Smarte8b62012007-08-02 11:10:09 -04004171 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004172 "0417 Can't create debugfs\n");
James Smarta58cbd52007-08-02 11:09:43 -04004173 goto debug_failed;
4174 }
4175 atomic_inc(&phba->debugfs_vport_count);
4176 }
4177
James Smart858c9f62007-06-17 19:56:39 -05004178 if (lpfc_debugfs_max_disc_trc) {
4179 num = lpfc_debugfs_max_disc_trc - 1;
4180 if (num & lpfc_debugfs_max_disc_trc) {
4181 /* Change to be a power of 2 */
4182 num = lpfc_debugfs_max_disc_trc;
4183 i = 0;
4184 while (num > 1) {
4185 num = num >> 1;
4186 i++;
4187 }
4188 lpfc_debugfs_max_disc_trc = (1 << i);
James Smart2ea259e2017-02-12 13:52:27 -08004189 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
James Smarte8b62012007-08-02 11:10:09 -04004190 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05004191 }
4192 }
4193
Adrian Bunkff86ba52007-10-18 12:52:37 +02004194 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04004195 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05004196 GFP_KERNEL);
4197
James Smarta58cbd52007-08-02 11:09:43 -04004198 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004199 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004200 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04004201 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05004202 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04004203 }
4204 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05004205
4206 snprintf(name, sizeof(name), "discovery_trace");
4207 vport->debug_disc_trc =
4208 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4209 vport->vport_debugfs_root,
4210 vport, &lpfc_debugfs_op_disc_trc);
4211 if (!vport->debug_disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04004212 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004213 "0419 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04004214 "discovery_trace\n");
James Smart858c9f62007-06-17 19:56:39 -05004215 goto debug_failed;
4216 }
4217 snprintf(name, sizeof(name), "nodelist");
4218 vport->debug_nodelist =
4219 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4220 vport->vport_debugfs_root,
4221 vport, &lpfc_debugfs_op_nodelist);
4222 if (!vport->debug_nodelist) {
James Smarte8b62012007-08-02 11:10:09 -04004223 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartb76f2dc2011-07-22 18:37:42 -04004224 "2985 Can't create debugfs nodelist\n");
James Smart858c9f62007-06-17 19:56:39 -05004225 goto debug_failed;
4226 }
James Smart2a622bf2011-02-16 12:40:06 -05004227
4228 /*
James Smartf6c3bdf2013-12-17 20:29:59 -05004229 * The following section is for additional directories/files for the
4230 * physical port.
4231 */
4232
4233 if (!pport_setup)
4234 goto debug_failed;
4235
4236 /*
James Smart2a622bf2011-02-16 12:40:06 -05004237 * iDiag debugfs root entry points for SLI4 device only
4238 */
4239 if (phba->sli_rev < LPFC_SLI_REV4)
4240 goto debug_failed;
4241
4242 snprintf(name, sizeof(name), "iDiag");
4243 if (!phba->idiag_root) {
4244 phba->idiag_root =
4245 debugfs_create_dir(name, phba->hba_debugfs_root);
4246 if (!phba->idiag_root) {
4247 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4248 "2922 Can't create idiag debugfs\n");
4249 goto debug_failed;
4250 }
4251 /* Initialize iDiag data structure */
4252 memset(&idiag, 0, sizeof(idiag));
4253 }
4254
4255 /* iDiag read PCI config space */
4256 snprintf(name, sizeof(name), "pciCfg");
4257 if (!phba->idiag_pci_cfg) {
4258 phba->idiag_pci_cfg =
4259 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4260 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
4261 if (!phba->idiag_pci_cfg) {
4262 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4263 "2923 Can't create idiag debugfs\n");
4264 goto debug_failed;
4265 }
4266 idiag.offset.last_rd = 0;
4267 }
4268
James Smartb76f2dc2011-07-22 18:37:42 -04004269 /* iDiag PCI BAR access */
4270 snprintf(name, sizeof(name), "barAcc");
4271 if (!phba->idiag_bar_acc) {
4272 phba->idiag_bar_acc =
4273 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4274 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
4275 if (!phba->idiag_bar_acc) {
4276 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4277 "3056 Can't create idiag debugfs\n");
4278 goto debug_failed;
4279 }
4280 idiag.offset.last_rd = 0;
4281 }
4282
James Smart2a622bf2011-02-16 12:40:06 -05004283 /* iDiag get PCI function queue information */
4284 snprintf(name, sizeof(name), "queInfo");
4285 if (!phba->idiag_que_info) {
4286 phba->idiag_que_info =
4287 debugfs_create_file(name, S_IFREG|S_IRUGO,
4288 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
4289 if (!phba->idiag_que_info) {
4290 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4291 "2924 Can't create idiag debugfs\n");
4292 goto debug_failed;
4293 }
4294 }
4295
James Smart86a80842011-04-16 11:03:04 -04004296 /* iDiag access PCI function queue */
4297 snprintf(name, sizeof(name), "queAcc");
4298 if (!phba->idiag_que_acc) {
4299 phba->idiag_que_acc =
4300 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4301 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
4302 if (!phba->idiag_que_acc) {
4303 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4304 "2926 Can't create idiag debugfs\n");
4305 goto debug_failed;
4306 }
4307 }
4308
4309 /* iDiag access PCI function doorbell registers */
4310 snprintf(name, sizeof(name), "drbAcc");
4311 if (!phba->idiag_drb_acc) {
4312 phba->idiag_drb_acc =
4313 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4314 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
4315 if (!phba->idiag_drb_acc) {
4316 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4317 "2927 Can't create idiag debugfs\n");
4318 goto debug_failed;
4319 }
4320 }
4321
James Smartb76f2dc2011-07-22 18:37:42 -04004322 /* iDiag access PCI function control registers */
4323 snprintf(name, sizeof(name), "ctlAcc");
4324 if (!phba->idiag_ctl_acc) {
4325 phba->idiag_ctl_acc =
4326 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4327 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
4328 if (!phba->idiag_ctl_acc) {
4329 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4330 "2981 Can't create idiag debugfs\n");
4331 goto debug_failed;
4332 }
4333 }
4334
4335 /* iDiag access mbox commands */
4336 snprintf(name, sizeof(name), "mbxAcc");
4337 if (!phba->idiag_mbx_acc) {
4338 phba->idiag_mbx_acc =
4339 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4340 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
4341 if (!phba->idiag_mbx_acc) {
4342 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4343 "2980 Can't create idiag debugfs\n");
4344 goto debug_failed;
4345 }
4346 }
4347
4348 /* iDiag extents access commands */
4349 if (phba->sli4_hba.extents_in_use) {
4350 snprintf(name, sizeof(name), "extAcc");
4351 if (!phba->idiag_ext_acc) {
4352 phba->idiag_ext_acc =
4353 debugfs_create_file(name,
4354 S_IFREG|S_IRUGO|S_IWUSR,
4355 phba->idiag_root, phba,
4356 &lpfc_idiag_op_extAcc);
4357 if (!phba->idiag_ext_acc) {
4358 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4359 "2986 Cant create "
4360 "idiag debugfs\n");
4361 goto debug_failed;
4362 }
4363 }
4364 }
4365
James Smart858c9f62007-06-17 19:56:39 -05004366debug_failed:
4367 return;
4368#endif
4369}
4370
James Smarte59058c2008-08-24 21:49:00 -04004371/**
James Smart3621a712009-04-06 18:47:14 -04004372 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04004373 * @vport: The vport pointer to remove from debugfs.
4374 *
4375 * Description:
4376 * When Debugfs is configured this routine removes debugfs file system elements
4377 * that are specific to this vport. It also checks to see if there are any
4378 * users left for the debugfs directories associated with the HBA and driver. If
4379 * this is the last user of the HBA directory or driver directory then it will
4380 * remove those from the debugfs infrastructure as well.
4381 **/
James Smart858c9f62007-06-17 19:56:39 -05004382inline void
4383lpfc_debugfs_terminate(struct lpfc_vport *vport)
4384{
James Smart923e4b62008-12-04 22:40:07 -05004385#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05004386 struct lpfc_hba *phba = vport->phba;
4387
4388 if (vport->disc_trc) {
4389 kfree(vport->disc_trc);
4390 vport->disc_trc = NULL;
4391 }
4392 if (vport->debug_disc_trc) {
4393 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
4394 vport->debug_disc_trc = NULL;
4395 }
4396 if (vport->debug_nodelist) {
4397 debugfs_remove(vport->debug_nodelist); /* nodelist */
4398 vport->debug_nodelist = NULL;
4399 }
4400 if (vport->vport_debugfs_root) {
4401 debugfs_remove(vport->vport_debugfs_root); /* vportX */
4402 vport->vport_debugfs_root = NULL;
4403 atomic_dec(&phba->debugfs_vport_count);
4404 }
4405 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04004406
James Smart78b2d852007-08-02 11:10:21 -04004407 if (phba->debug_hbqinfo) {
4408 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
4409 phba->debug_hbqinfo = NULL;
4410 }
James Smartc95d6c62008-01-11 01:53:23 -05004411 if (phba->debug_dumpHBASlim) {
4412 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
4413 phba->debug_dumpHBASlim = NULL;
4414 }
4415 if (phba->debug_dumpHostSlim) {
4416 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
4417 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04004418 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004419 if (phba->debug_dumpData) {
4420 debugfs_remove(phba->debug_dumpData); /* dumpData */
4421 phba->debug_dumpData = NULL;
4422 }
4423
4424 if (phba->debug_dumpDif) {
4425 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
4426 phba->debug_dumpDif = NULL;
4427 }
James Smartf9bb2da2011-10-10 21:34:11 -04004428 if (phba->debug_InjErrLBA) {
4429 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
4430 phba->debug_InjErrLBA = NULL;
4431 }
James Smart4ac9b222012-03-01 22:38:29 -05004432 if (phba->debug_InjErrNPortID) { /* InjErrNPortID */
4433 debugfs_remove(phba->debug_InjErrNPortID);
4434 phba->debug_InjErrNPortID = NULL;
4435 }
4436 if (phba->debug_InjErrWWPN) {
4437 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
4438 phba->debug_InjErrWWPN = NULL;
4439 }
James Smartf9bb2da2011-10-10 21:34:11 -04004440 if (phba->debug_writeGuard) {
4441 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
4442 phba->debug_writeGuard = NULL;
4443 }
4444 if (phba->debug_writeApp) {
4445 debugfs_remove(phba->debug_writeApp); /* writeApp */
4446 phba->debug_writeApp = NULL;
4447 }
4448 if (phba->debug_writeRef) {
4449 debugfs_remove(phba->debug_writeRef); /* writeRef */
4450 phba->debug_writeRef = NULL;
4451 }
James Smartacd68592012-01-18 16:25:09 -05004452 if (phba->debug_readGuard) {
4453 debugfs_remove(phba->debug_readGuard); /* readGuard */
4454 phba->debug_readGuard = NULL;
4455 }
James Smartf9bb2da2011-10-10 21:34:11 -04004456 if (phba->debug_readApp) {
4457 debugfs_remove(phba->debug_readApp); /* readApp */
4458 phba->debug_readApp = NULL;
4459 }
4460 if (phba->debug_readRef) {
4461 debugfs_remove(phba->debug_readRef); /* readRef */
4462 phba->debug_readRef = NULL;
4463 }
James Smarte2a0a9d2008-12-04 22:40:02 -05004464
James Smarta58cbd52007-08-02 11:09:43 -04004465 if (phba->slow_ring_trc) {
4466 kfree(phba->slow_ring_trc);
4467 phba->slow_ring_trc = NULL;
4468 }
4469 if (phba->debug_slow_ring_trc) {
4470 /* slow_ring_trace */
4471 debugfs_remove(phba->debug_slow_ring_trc);
4472 phba->debug_slow_ring_trc = NULL;
4473 }
4474
James Smart2a622bf2011-02-16 12:40:06 -05004475 /*
4476 * iDiag release
4477 */
4478 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartb76f2dc2011-07-22 18:37:42 -04004479 if (phba->idiag_ext_acc) {
4480 /* iDiag extAcc */
4481 debugfs_remove(phba->idiag_ext_acc);
4482 phba->idiag_ext_acc = NULL;
4483 }
4484 if (phba->idiag_mbx_acc) {
4485 /* iDiag mbxAcc */
4486 debugfs_remove(phba->idiag_mbx_acc);
4487 phba->idiag_mbx_acc = NULL;
4488 }
4489 if (phba->idiag_ctl_acc) {
4490 /* iDiag ctlAcc */
4491 debugfs_remove(phba->idiag_ctl_acc);
4492 phba->idiag_ctl_acc = NULL;
4493 }
James Smart86a80842011-04-16 11:03:04 -04004494 if (phba->idiag_drb_acc) {
4495 /* iDiag drbAcc */
4496 debugfs_remove(phba->idiag_drb_acc);
4497 phba->idiag_drb_acc = NULL;
4498 }
4499 if (phba->idiag_que_acc) {
4500 /* iDiag queAcc */
4501 debugfs_remove(phba->idiag_que_acc);
4502 phba->idiag_que_acc = NULL;
4503 }
James Smart2a622bf2011-02-16 12:40:06 -05004504 if (phba->idiag_que_info) {
4505 /* iDiag queInfo */
4506 debugfs_remove(phba->idiag_que_info);
4507 phba->idiag_que_info = NULL;
4508 }
James Smartb76f2dc2011-07-22 18:37:42 -04004509 if (phba->idiag_bar_acc) {
4510 /* iDiag barAcc */
4511 debugfs_remove(phba->idiag_bar_acc);
4512 phba->idiag_bar_acc = NULL;
4513 }
James Smart2a622bf2011-02-16 12:40:06 -05004514 if (phba->idiag_pci_cfg) {
4515 /* iDiag pciCfg */
4516 debugfs_remove(phba->idiag_pci_cfg);
4517 phba->idiag_pci_cfg = NULL;
4518 }
4519
4520 /* Finally remove the iDiag debugfs root */
4521 if (phba->idiag_root) {
4522 /* iDiag root */
4523 debugfs_remove(phba->idiag_root);
4524 phba->idiag_root = NULL;
4525 }
4526 }
4527
James Smarta58cbd52007-08-02 11:09:43 -04004528 if (phba->hba_debugfs_root) {
James Smart2a622bf2011-02-16 12:40:06 -05004529 debugfs_remove(phba->hba_debugfs_root); /* fnX */
James Smarta58cbd52007-08-02 11:09:43 -04004530 phba->hba_debugfs_root = NULL;
4531 atomic_dec(&lpfc_debugfs_hba_count);
4532 }
4533
James Smart858c9f62007-06-17 19:56:39 -05004534 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
4535 debugfs_remove(lpfc_debugfs_root); /* lpfc */
4536 lpfc_debugfs_root = NULL;
4537 }
4538 }
4539#endif
James Smarta58cbd52007-08-02 11:09:43 -04004540 return;
James Smart858c9f62007-06-17 19:56:39 -05004541}
James Smart809c7532012-05-09 21:19:25 -04004542
4543/*
4544 * Driver debug utility routines outside of debugfs. The debug utility
4545 * routines implemented here is intended to be used in the instrumented
4546 * debug driver for debugging host or port issues.
4547 */
4548
4549/**
4550 * lpfc_debug_dump_all_queues - dump all the queues with a hba
4551 * @phba: Pointer to HBA context object.
4552 *
4553 * This function dumps entries of all the queues asociated with the @phba.
4554 **/
4555void
4556lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
4557{
4558 int fcp_wqidx;
4559
4560 /*
4561 * Dump Work Queues (WQs)
4562 */
4563 lpfc_debug_dump_mbx_wq(phba);
4564 lpfc_debug_dump_els_wq(phba);
4565
James Smart67d12732012-08-03 12:36:13 -04004566 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
James Smart809c7532012-05-09 21:19:25 -04004567 lpfc_debug_dump_fcp_wq(phba, fcp_wqidx);
4568
4569 lpfc_debug_dump_hdr_rq(phba);
4570 lpfc_debug_dump_dat_rq(phba);
4571 /*
4572 * Dump Complete Queues (CQs)
4573 */
4574 lpfc_debug_dump_mbx_cq(phba);
4575 lpfc_debug_dump_els_cq(phba);
4576
James Smart67d12732012-08-03 12:36:13 -04004577 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
James Smart809c7532012-05-09 21:19:25 -04004578 lpfc_debug_dump_fcp_cq(phba, fcp_wqidx);
4579
4580 /*
4581 * Dump Event Queues (EQs)
4582 */
James Smart67d12732012-08-03 12:36:13 -04004583 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++)
4584 lpfc_debug_dump_hba_eq(phba, fcp_wqidx);
James Smart809c7532012-05-09 21:19:25 -04004585}