]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/scsi/lpfc/lpfc_debugfs.c
Merge remote-tracking branch 'regulator/fix/max77802' into regulator-linus
[mirror_ubuntu-artful-kernel.git] / drivers / scsi / lpfc / lpfc_debugfs.c
CommitLineData
858c9f6c
JS
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
d080abe0
JS
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
f25e8e79 6 * Copyright (C) 2007-2015 Emulex. All rights reserved. *
858c9f6c 7 * EMULEX and SLI are trademarks of Emulex. *
d080abe0 8 * www.broadcom.com *
858c9f6c
JS
9 * *
10 * This program is free software; you can redistribute it and/or *
11 * modify it under the terms of version 2 of the GNU General *
12 * Public License as published by the Free Software Foundation. *
13 * This program is distributed in the hope that it will be useful. *
14 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
15 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
17 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18 * TO BE LEGALLY INVALID. See the GNU General Public License for *
19 * more details, a copy of which can be found in the file COPYING *
20 * included with this package. *
21 *******************************************************************/
22
23#include <linux/blkdev.h>
24#include <linux/delay.h>
acf3368f 25#include <linux/module.h>
858c9f6c
JS
26#include <linux/dma-mapping.h>
27#include <linux/idr.h>
28#include <linux/interrupt.h>
29#include <linux/kthread.h>
5a0e3ad6 30#include <linux/slab.h>
858c9f6c
JS
31#include <linux/pci.h>
32#include <linux/spinlock.h>
33#include <linux/ctype.h>
858c9f6c
JS
34
35#include <scsi/scsi.h>
36#include <scsi/scsi_device.h>
37#include <scsi/scsi_host.h>
38#include <scsi/scsi_transport_fc.h>
bd2cdd5e
JS
39#include <scsi/fc/fc_fs.h>
40
41#include <linux/nvme-fc-driver.h>
858c9f6c 42
da0436e9 43#include "lpfc_hw4.h"
858c9f6c
JS
44#include "lpfc_hw.h"
45#include "lpfc_sli.h"
da0436e9 46#include "lpfc_sli4.h"
ea2151b4 47#include "lpfc_nl.h"
858c9f6c 48#include "lpfc_disc.h"
858c9f6c 49#include "lpfc.h"
bd2cdd5e
JS
50#include "lpfc_scsi.h"
51#include "lpfc_nvme.h"
2b65e182 52#include "lpfc_nvmet.h"
858c9f6c
JS
53#include "lpfc_logmsg.h"
54#include "lpfc_crtn.h"
55#include "lpfc_vport.h"
56#include "lpfc_version.h"
c95d6c6c 57#include "lpfc_compat.h"
858c9f6c 58#include "lpfc_debugfs.h"
b76f2dc9 59#include "lpfc_bsg.h"
858c9f6c 60
923e4b6a 61#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3621a710 62/*
e59058c4 63 * debugfs interface
858c9f6c
JS
64 *
65 * To access this interface the user should:
156f5a78 66 * # mount -t debugfs none /sys/kernel/debug
858c9f6c 67 *
e59058c4 68 * The lpfc debugfs directory hierarchy is:
2a622bfb
JS
69 * /sys/kernel/debug/lpfc/fnX/vportY
70 * where X is the lpfc hba function unique_id
858c9f6c
JS
71 * where Y is the vport VPI on that hba
72 *
73 * Debugging services available per vport:
74 * discovery_trace
75 * This is an ACSII readable file that contains a trace of the last
76 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
e59058c4
JS
77 * See lpfc_debugfs.h for different categories of discovery events.
78 * To enable the discovery trace, the following module parameters must be set:
858c9f6c
JS
79 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
80 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
81 * EACH vport. X MUST also be a power of 2.
82 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
83 * lpfc_debugfs.h .
e59058c4
JS
84 *
85 * slow_ring_trace
86 * This is an ACSII readable file that contains a trace of the last
87 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
88 * To enable the slow ring trace, the following module parameters must be set:
89 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
90 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
91 * the HBA. X MUST also be a power of 2.
858c9f6c 92 */
51ef4c26 93static int lpfc_debugfs_enable = 1;
ab56dc2e 94module_param(lpfc_debugfs_enable, int, S_IRUGO);
858c9f6c
JS
95MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
96
a58cbd52 97/* This MUST be a power of 2 */
c95d6c6c 98static int lpfc_debugfs_max_disc_trc;
ab56dc2e 99module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
858c9f6c
JS
100MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
101 "Set debugfs discovery trace depth");
102
a58cbd52 103/* This MUST be a power of 2 */
c95d6c6c 104static int lpfc_debugfs_max_slow_ring_trc;
ab56dc2e 105module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
a58cbd52
JS
106MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
107 "Set debugfs slow ring trace depth");
108
bd2cdd5e
JS
109/* This MUST be a power of 2 */
110static int lpfc_debugfs_max_nvmeio_trc;
111module_param(lpfc_debugfs_max_nvmeio_trc, int, 0444);
112MODULE_PARM_DESC(lpfc_debugfs_max_nvmeio_trc,
113 "Set debugfs NVME IO trace depth");
114
a257bf90 115static int lpfc_debugfs_mask_disc_trc;
ab56dc2e 116module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
858c9f6c
JS
117MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
118 "Set debugfs discovery trace mask");
119
120#include <linux/debugfs.h>
121
311464ec
JS
122static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
123static unsigned long lpfc_debugfs_start_time = 0L;
858c9f6c 124
2a622bfb
JS
125/* iDiag */
126static struct lpfc_idiag idiag;
127
e59058c4 128/**
3621a710 129 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
e59058c4
JS
130 * @vport: The vport to gather the log info from.
131 * @buf: The buffer to dump log into.
132 * @size: The maximum amount of data to process.
133 *
134 * Description:
135 * This routine gathers the lpfc discovery debugfs data from the @vport and
136 * dumps it to @buf up to @size number of bytes. It will start at the next entry
137 * in the log and process the log until the end of the buffer. Then it will
138 * gather from the beginning of the log and process until the current entry.
139 *
140 * Notes:
141 * Discovery logging will be disabled while while this routine dumps the log.
142 *
143 * Return Value:
144 * This routine returns the amount of bytes that were dumped into @buf and will
145 * not exceed @size.
146 **/
858c9f6c
JS
147static int
148lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
149{
150 int i, index, len, enable;
151 uint32_t ms;
a58cbd52 152 struct lpfc_debugfs_trc *dtp;
b76f2dc9
JS
153 char *buffer;
154
155 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
156 if (!buffer)
157 return 0;
858c9f6c 158
858c9f6c
JS
159 enable = lpfc_debugfs_enable;
160 lpfc_debugfs_enable = 0;
161
162 len = 0;
163 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
164 (lpfc_debugfs_max_disc_trc - 1);
165 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
166 dtp = vport->disc_trc + i;
167 if (!dtp->fmt)
168 continue;
169 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
a58cbd52
JS
170 snprintf(buffer,
171 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
858c9f6c
JS
172 dtp->seq_cnt, ms, dtp->fmt);
173 len += snprintf(buf+len, size-len, buffer,
174 dtp->data1, dtp->data2, dtp->data3);
175 }
176 for (i = 0; i < index; i++) {
177 dtp = vport->disc_trc + i;
178 if (!dtp->fmt)
179 continue;
180 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
a58cbd52
JS
181 snprintf(buffer,
182 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
183 dtp->seq_cnt, ms, dtp->fmt);
184 len += snprintf(buf+len, size-len, buffer,
185 dtp->data1, dtp->data2, dtp->data3);
186 }
187
188 lpfc_debugfs_enable = enable;
b76f2dc9
JS
189 kfree(buffer);
190
a58cbd52
JS
191 return len;
192}
193
e59058c4 194/**
3621a710 195 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
e59058c4
JS
196 * @phba: The HBA to gather the log info from.
197 * @buf: The buffer to dump log into.
198 * @size: The maximum amount of data to process.
199 *
200 * Description:
201 * This routine gathers the lpfc slow ring debugfs data from the @phba and
202 * dumps it to @buf up to @size number of bytes. It will start at the next entry
203 * in the log and process the log until the end of the buffer. Then it will
204 * gather from the beginning of the log and process until the current entry.
205 *
206 * Notes:
207 * Slow ring logging will be disabled while while this routine dumps the log.
208 *
209 * Return Value:
210 * This routine returns the amount of bytes that were dumped into @buf and will
211 * not exceed @size.
212 **/
a58cbd52
JS
213static int
214lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
215{
216 int i, index, len, enable;
217 uint32_t ms;
218 struct lpfc_debugfs_trc *dtp;
b76f2dc9 219 char *buffer;
a58cbd52 220
b76f2dc9
JS
221 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
222 if (!buffer)
223 return 0;
a58cbd52
JS
224
225 enable = lpfc_debugfs_enable;
226 lpfc_debugfs_enable = 0;
227
228 len = 0;
229 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
230 (lpfc_debugfs_max_slow_ring_trc - 1);
231 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
232 dtp = phba->slow_ring_trc + i;
233 if (!dtp->fmt)
234 continue;
235 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
236 snprintf(buffer,
237 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
238 dtp->seq_cnt, ms, dtp->fmt);
239 len += snprintf(buf+len, size-len, buffer,
240 dtp->data1, dtp->data2, dtp->data3);
241 }
242 for (i = 0; i < index; i++) {
243 dtp = phba->slow_ring_trc + i;
244 if (!dtp->fmt)
245 continue;
246 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
247 snprintf(buffer,
248 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
858c9f6c
JS
249 dtp->seq_cnt, ms, dtp->fmt);
250 len += snprintf(buf+len, size-len, buffer,
251 dtp->data1, dtp->data2, dtp->data3);
252 }
253
254 lpfc_debugfs_enable = enable;
b76f2dc9
JS
255 kfree(buffer);
256
858c9f6c
JS
257 return len;
258}
259
311464ec 260static int lpfc_debugfs_last_hbq = -1;
78b2d852 261
e59058c4 262/**
3621a710 263 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
e59058c4
JS
264 * @phba: The HBA to gather host buffer info from.
265 * @buf: The buffer to dump log into.
266 * @size: The maximum amount of data to process.
267 *
268 * Description:
269 * This routine dumps the host buffer queue info from the @phba to @buf up to
270 * @size number of bytes. A header that describes the current hbq state will be
271 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
272 * until @size bytes have been dumped or all the hbq info has been dumped.
273 *
274 * Notes:
275 * This routine will rotate through each configured HBQ each time called.
276 *
277 * Return Value:
278 * This routine returns the amount of bytes that were dumped into @buf and will
279 * not exceed @size.
280 **/
78b2d852
JS
281static int
282lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
283{
284 int len = 0;
eb016566 285 int i, j, found, posted, low;
78b2d852
JS
286 uint32_t phys, raw_index, getidx;
287 struct lpfc_hbq_init *hip;
288 struct hbq_s *hbqs;
289 struct lpfc_hbq_entry *hbqe;
290 struct lpfc_dmabuf *d_buf;
291 struct hbq_dmabuf *hbq_buf;
292
3772a991
JS
293 if (phba->sli_rev != 3)
294 return 0;
eb016566 295
78b2d852
JS
296 spin_lock_irq(&phba->hbalock);
297
298 /* toggle between multiple hbqs, if any */
299 i = lpfc_sli_hbq_count();
300 if (i > 1) {
301 lpfc_debugfs_last_hbq++;
302 if (lpfc_debugfs_last_hbq >= i)
303 lpfc_debugfs_last_hbq = 0;
304 }
305 else
306 lpfc_debugfs_last_hbq = 0;
307
308 i = lpfc_debugfs_last_hbq;
309
310 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
311
51ef4c26 312 hbqs = &phba->hbqs[i];
78b2d852 313 posted = 0;
51ef4c26 314 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
78b2d852
JS
315 posted++;
316
317 hip = lpfc_hbq_defs[i];
318 len += snprintf(buf+len, size-len,
319 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
320 hip->hbq_index, hip->profile, hip->rn,
321 hip->buffer_count, hip->init_count, hip->add_count, posted);
322
78b2d852
JS
323 raw_index = phba->hbq_get[i];
324 getidx = le32_to_cpu(raw_index);
325 len += snprintf(buf+len, size-len,
a8adb832
JS
326 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
327 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
328 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
78b2d852 329
51ef4c26 330 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
78b2d852
JS
331 for (j=0; j<hbqs->entry_count; j++) {
332 len += snprintf(buf+len, size-len,
333 "%03d: %08x %04x %05x ", j,
a8adb832
JS
334 le32_to_cpu(hbqe->bde.addrLow),
335 le32_to_cpu(hbqe->bde.tus.w),
336 le32_to_cpu(hbqe->buffer_tag));
78b2d852
JS
337 i = 0;
338 found = 0;
339
340 /* First calculate if slot has an associated posted buffer */
341 low = hbqs->hbqPutIdx - posted;
342 if (low >= 0) {
343 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
344 len += snprintf(buf+len, size-len, "Unused\n");
345 goto skipit;
346 }
347 }
348 else {
349 if ((j >= hbqs->hbqPutIdx) &&
350 (j < (hbqs->entry_count+low))) {
351 len += snprintf(buf+len, size-len, "Unused\n");
352 goto skipit;
353 }
354 }
355
356 /* Get the Buffer info for the posted buffer */
51ef4c26 357 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
78b2d852
JS
358 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
359 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
a8adb832 360 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
78b2d852
JS
361 len += snprintf(buf+len, size-len,
362 "Buf%d: %p %06x\n", i,
363 hbq_buf->dbuf.virt, hbq_buf->tag);
364 found = 1;
365 break;
366 }
367 i++;
368 }
369 if (!found) {
370 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
371 }
372skipit:
373 hbqe++;
374 if (len > LPFC_HBQINFO_SIZE - 54)
375 break;
376 }
377 spin_unlock_irq(&phba->hbalock);
378 return len;
379}
380
c95d6c6c
JS
381static int lpfc_debugfs_last_hba_slim_off;
382
e59058c4 383/**
3621a710 384 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
e59058c4
JS
385 * @phba: The HBA to gather SLIM info from.
386 * @buf: The buffer to dump log into.
387 * @size: The maximum amount of data to process.
388 *
389 * Description:
390 * This routine dumps the current contents of HBA SLIM for the HBA associated
391 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
392 *
393 * Notes:
394 * This routine will only dump up to 1024 bytes of data each time called and
395 * should be called multiple times to dump the entire HBA SLIM.
396 *
397 * Return Value:
398 * This routine returns the amount of bytes that were dumped into @buf and will
399 * not exceed @size.
400 **/
c95d6c6c
JS
401static int
402lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
403{
404 int len = 0;
405 int i, off;
406 uint32_t *ptr;
b76f2dc9
JS
407 char *buffer;
408
409 buffer = kmalloc(1024, GFP_KERNEL);
410 if (!buffer)
411 return 0;
c95d6c6c
JS
412
413 off = 0;
414 spin_lock_irq(&phba->hbalock);
415
416 len += snprintf(buf+len, size-len, "HBA SLIM\n");
417 lpfc_memcpy_from_slim(buffer,
a257bf90 418 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
c95d6c6c
JS
419
420 ptr = (uint32_t *)&buffer[0];
421 off = lpfc_debugfs_last_hba_slim_off;
422
423 /* Set it up for the next time */
424 lpfc_debugfs_last_hba_slim_off += 1024;
425 if (lpfc_debugfs_last_hba_slim_off >= 4096)
426 lpfc_debugfs_last_hba_slim_off = 0;
427
428 i = 1024;
429 while (i > 0) {
430 len += snprintf(buf+len, size-len,
431 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
432 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
433 *(ptr+5), *(ptr+6), *(ptr+7));
434 ptr += 8;
435 i -= (8 * sizeof(uint32_t));
436 off += (8 * sizeof(uint32_t));
437 }
438
439 spin_unlock_irq(&phba->hbalock);
b76f2dc9
JS
440 kfree(buffer);
441
c95d6c6c
JS
442 return len;
443}
444
e59058c4 445/**
3621a710 446 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
e59058c4
JS
447 * @phba: The HBA to gather Host SLIM info from.
448 * @buf: The buffer to dump log into.
449 * @size: The maximum amount of data to process.
450 *
451 * Description:
452 * This routine dumps the current contents of host SLIM for the host associated
453 * with @phba to @buf up to @size bytes of data. The dump will contain the
454 * Mailbox, PCB, Rings, and Registers that are located in host memory.
455 *
456 * Return Value:
457 * This routine returns the amount of bytes that were dumped into @buf and will
458 * not exceed @size.
459 **/
a58cbd52 460static int
c95d6c6c 461lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
a58cbd52
JS
462{
463 int len = 0;
c95d6c6c 464 int i, off;
a58cbd52
JS
465 uint32_t word0, word1, word2, word3;
466 uint32_t *ptr;
467 struct lpfc_pgp *pgpp;
468 struct lpfc_sli *psli = &phba->sli;
469 struct lpfc_sli_ring *pring;
470
a58cbd52
JS
471 off = 0;
472 spin_lock_irq(&phba->hbalock);
473
474 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
34b02dcd 475 ptr = (uint32_t *)phba->slim2p.virt;
a58cbd52
JS
476 i = sizeof(MAILBOX_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
487 len += snprintf(buf+len, size-len, "SLIM PCB\n");
34b02dcd 488 ptr = (uint32_t *)phba->pcb;
a58cbd52
JS
489 i = sizeof(PCB_t);
490 while (i > 0) {
491 len += snprintf(buf+len, size-len,
492 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
493 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
494 *(ptr+5), *(ptr+6), *(ptr+7));
495 ptr += 8;
496 i -= (8 * sizeof(uint32_t));
497 off += (8 * sizeof(uint32_t));
498 }
499
3772a991 500 if (phba->sli_rev <= LPFC_SLI_REV3) {
895427bd
JS
501 for (i = 0; i < 4; i++) {
502 pgpp = &phba->port_gp[i];
503 pring = &psli->sli3_ring[i];
504 len += snprintf(buf+len, size-len,
505 "Ring %d: CMD GetInx:%d "
506 "(Max:%d Next:%d "
507 "Local:%d flg:x%x) "
508 "RSP PutInx:%d Max:%d\n",
509 i, pgpp->cmdGetInx,
510 pring->sli.sli3.numCiocb,
511 pring->sli.sli3.next_cmdidx,
512 pring->sli.sli3.local_getidx,
513 pring->flag, pgpp->rspPutInx,
514 pring->sli.sli3.numRiocb);
515 }
516
3772a991
JS
517 word0 = readl(phba->HAregaddr);
518 word1 = readl(phba->CAregaddr);
519 word2 = readl(phba->HSregaddr);
520 word3 = readl(phba->HCregaddr);
521 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
522 "HC:%08x\n", word0, word1, word2, word3);
523 }
a58cbd52
JS
524 spin_unlock_irq(&phba->hbalock);
525 return len;
526}
527
e59058c4 528/**
3621a710 529 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
e59058c4
JS
530 * @vport: The vport to gather target node info from.
531 * @buf: The buffer to dump log into.
532 * @size: The maximum amount of data to process.
533 *
534 * Description:
535 * This routine dumps the current target node list associated with @vport to
536 * @buf up to @size bytes of data. Each node entry in the dump will contain a
537 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
538 *
539 * Return Value:
540 * This routine returns the amount of bytes that were dumped into @buf and will
541 * not exceed @size.
542 **/
858c9f6c
JS
543static int
544lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
545{
546 int len = 0;
547 int cnt;
548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2b65e182 549 struct lpfc_hba *phba = vport->phba;
858c9f6c 550 struct lpfc_nodelist *ndlp;
2ea259ee 551 unsigned char *statep;
bd2cdd5e
JS
552 struct nvme_fc_local_port *localport;
553 struct lpfc_nvme_lport *lport;
554 struct lpfc_nvme_rport *rport;
2b65e182 555 struct lpfc_nvmet_tgtport *tgtp;
bd2cdd5e 556 struct nvme_fc_remote_port *nrport;
858c9f6c
JS
557
558 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
559
895427bd 560 len += snprintf(buf+len, size-len, "\nFCP Nodelist Entries ...\n");
858c9f6c
JS
561 spin_lock_irq(shost->host_lock);
562 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
563 if (!cnt) {
564 len += snprintf(buf+len, size-len,
565 "Missing Nodelist Entries\n");
566 break;
567 }
568 cnt--;
569 switch (ndlp->nlp_state) {
570 case NLP_STE_UNUSED_NODE:
571 statep = "UNUSED";
572 break;
573 case NLP_STE_PLOGI_ISSUE:
574 statep = "PLOGI ";
575 break;
576 case NLP_STE_ADISC_ISSUE:
577 statep = "ADISC ";
578 break;
579 case NLP_STE_REG_LOGIN_ISSUE:
580 statep = "REGLOG";
581 break;
582 case NLP_STE_PRLI_ISSUE:
583 statep = "PRLI ";
584 break;
086a345f
JS
585 case NLP_STE_LOGO_ISSUE:
586 statep = "LOGO ";
587 break;
858c9f6c
JS
588 case NLP_STE_UNMAPPED_NODE:
589 statep = "UNMAP ";
590 break;
591 case NLP_STE_MAPPED_NODE:
592 statep = "MAPPED";
593 break;
594 case NLP_STE_NPR_NODE:
595 statep = "NPR ";
596 break;
597 default:
598 statep = "UNKNOWN";
599 }
2ea259ee
JS
600 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
601 statep, ndlp->nlp_DID);
602 len += snprintf(buf+len, size-len,
603 "WWPN x%llx ",
604 wwn_to_u64(ndlp->nlp_portname.u.wwn));
605 len += snprintf(buf+len, size-len,
606 "WWNN x%llx ",
607 wwn_to_u64(ndlp->nlp_nodename.u.wwn));
086a345f 608 if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
2ea259ee
JS
609 len += snprintf(buf+len, size-len, "RPI:%03d ",
610 ndlp->nlp_rpi);
086a345f 611 else
2ea259ee 612 len += snprintf(buf+len, size-len, "RPI:none ");
086a345f
JS
613 len += snprintf(buf+len, size-len, "flag:x%08x ",
614 ndlp->nlp_flag);
858c9f6c 615 if (!ndlp->nlp_type)
2ea259ee 616 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
858c9f6c 617 if (ndlp->nlp_type & NLP_FC_NODE)
2ea259ee 618 len += snprintf(buf+len, size-len, "FC_NODE ");
858c9f6c 619 if (ndlp->nlp_type & NLP_FABRIC)
2ea259ee 620 len += snprintf(buf+len, size-len, "FABRIC ");
858c9f6c 621 if (ndlp->nlp_type & NLP_FCP_TARGET)
2ea259ee 622 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
858c9f6c
JS
623 ndlp->nlp_sid);
624 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
2ea259ee 625 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
58da1ffb
JS
626 len += snprintf(buf+len, size-len, "usgmap:%x ",
627 ndlp->nlp_usg_map);
a58cbd52 628 len += snprintf(buf+len, size-len, "refcnt:%x",
2c935bc5 629 kref_read(&ndlp->kref));
858c9f6c
JS
630 len += snprintf(buf+len, size-len, "\n");
631 }
632 spin_unlock_irq(shost->host_lock);
2ea259ee 633
2b65e182
JS
634 if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
635 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
636 len += snprintf(buf + len, size - len,
637 "\nNVME Targetport Entry ...\n");
638
639 /* Port state is only one of two values for now. */
640 if (phba->targetport->port_id)
641 statep = "REGISTERED";
642 else
643 statep = "INIT";
644 len += snprintf(buf + len, size - len,
645 "TGT WWNN x%llx WWPN x%llx State %s\n",
646 wwn_to_u64(vport->fc_nodename.u.wwn),
647 wwn_to_u64(vport->fc_portname.u.wwn),
648 statep);
649 len += snprintf(buf + len, size - len,
650 " Targetport DID x%06x\n",
651 phba->targetport->port_id);
652 goto out_exit;
653 }
654
bd2cdd5e
JS
655 len += snprintf(buf + len, size - len,
656 "\nNVME Lport/Rport Entries ...\n");
657
658 localport = vport->localport;
659 if (!localport)
660 goto out_exit;
661
662 spin_lock_irq(shost->host_lock);
663 lport = (struct lpfc_nvme_lport *)localport->private;
664
665 /* Port state is only one of two values for now. */
666 if (localport->port_id)
667 statep = "ONLINE";
668 else
669 statep = "UNKNOWN ";
670
671 len += snprintf(buf + len, size - len,
672 "Lport DID x%06x PortState %s\n",
673 localport->port_id, statep);
674
675 len += snprintf(buf + len, size - len, "\tRport List:\n");
676 list_for_each_entry(rport, &lport->rport_list, list) {
677 /* local short-hand pointer. */
678 nrport = rport->remoteport;
679
680 /* Port state is only one of two values for now. */
681 switch (nrport->port_state) {
682 case FC_OBJSTATE_ONLINE:
683 statep = "ONLINE";
684 break;
685 case FC_OBJSTATE_UNKNOWN:
686 statep = "UNKNOWN ";
687 break;
688 default:
689 statep = "UNSUPPORTED";
690 break;
691 }
692
693 /* Tab in to show lport ownership. */
694 len += snprintf(buf + len, size - len,
695 "\t%s Port ID:x%06x ",
696 statep, nrport->port_id);
697 len += snprintf(buf + len, size - len, "WWPN x%llx ",
698 nrport->port_name);
699 len += snprintf(buf + len, size - len, "WWNN x%llx ",
700 nrport->node_name);
701 switch (nrport->port_role) {
702 case FC_PORT_ROLE_NVME_INITIATOR:
703 len += snprintf(buf + len, size - len,
704 "NVME INITIATOR ");
705 break;
706 case FC_PORT_ROLE_NVME_TARGET:
707 len += snprintf(buf + len, size - len,
708 "NVME TARGET ");
709 break;
710 case FC_PORT_ROLE_NVME_DISCOVERY:
711 len += snprintf(buf + len, size - len,
712 "NVME DISCOVERY ");
713 break;
714 default:
715 len += snprintf(buf + len, size - len,
716 "UNKNOWN ROLE x%x",
717 nrport->port_role);
718 break;
719 }
720
721 /* Terminate the string. */
722 len += snprintf(buf + len, size - len, "\n");
723 }
724
725 spin_unlock_irq(shost->host_lock);
726 out_exit:
727 return len;
728}
729
730/**
731 * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
732 * @vport: The vport to gather target node info from.
733 * @buf: The buffer to dump log into.
734 * @size: The maximum amount of data to process.
735 *
736 * Description:
737 * This routine dumps the NVME statistics associated with @vport
738 *
739 * Return Value:
740 * This routine returns the amount of bytes that were dumped into @buf and will
741 * not exceed @size.
742 **/
743static int
744lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
745{
746 struct lpfc_hba *phba = vport->phba;
2b65e182 747 struct lpfc_nvmet_tgtport *tgtp;
86c67379 748 struct lpfc_nvmet_rcv_ctx *ctxp, *next_ctxp;
bd2cdd5e 749 int len = 0;
86c67379 750 int cnt;
bd2cdd5e 751
2b65e182
JS
752 if (phba->nvmet_support) {
753 if (!phba->targetport)
754 return len;
755 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
86c67379 756 len += snprintf(buf + len, size - len,
2b65e182
JS
757 "\nNVME Targetport Statistics\n");
758
86c67379 759 len += snprintf(buf + len, size - len,
2b65e182
JS
760 "LS: Rcv %08x Drop %08x Abort %08x\n",
761 atomic_read(&tgtp->rcv_ls_req_in),
762 atomic_read(&tgtp->rcv_ls_req_drop),
763 atomic_read(&tgtp->xmt_ls_abort));
764 if (atomic_read(&tgtp->rcv_ls_req_in) !=
765 atomic_read(&tgtp->rcv_ls_req_out)) {
86c67379 766 len += snprintf(buf + len, size - len,
2b65e182
JS
767 "Rcv LS: in %08x != out %08x\n",
768 atomic_read(&tgtp->rcv_ls_req_in),
769 atomic_read(&tgtp->rcv_ls_req_out));
770 }
771
86c67379 772 len += snprintf(buf + len, size - len,
2b65e182
JS
773 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
774 atomic_read(&tgtp->xmt_ls_rsp),
775 atomic_read(&tgtp->xmt_ls_drop),
776 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
777 atomic_read(&tgtp->xmt_ls_rsp_error));
778
86c67379 779 len += snprintf(buf + len, size - len,
2b65e182
JS
780 "FCP: Rcv %08x Drop %08x\n",
781 atomic_read(&tgtp->rcv_fcp_cmd_in),
782 atomic_read(&tgtp->rcv_fcp_cmd_drop));
783
784 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
785 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
86c67379 786 len += snprintf(buf + len, size - len,
2b65e182
JS
787 "Rcv FCP: in %08x != out %08x\n",
788 atomic_read(&tgtp->rcv_fcp_cmd_in),
789 atomic_read(&tgtp->rcv_fcp_cmd_out));
790 }
791
86c67379
JS
792 len += snprintf(buf + len, size - len,
793 "FCP Rsp: read %08x readrsp %08x "
794 "write %08x rsp %08x\n",
2b65e182
JS
795 atomic_read(&tgtp->xmt_fcp_read),
796 atomic_read(&tgtp->xmt_fcp_read_rsp),
797 atomic_read(&tgtp->xmt_fcp_write),
798 atomic_read(&tgtp->xmt_fcp_rsp));
799
86c67379 800 len += snprintf(buf + len, size - len,
2b65e182
JS
801 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
802 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
803 atomic_read(&tgtp->xmt_fcp_rsp_error),
804 atomic_read(&tgtp->xmt_fcp_rsp_drop));
805
86c67379 806 len += snprintf(buf + len, size - len,
547077a4
JS
807 "ABORT: Xmt %08x Cmpl %08x\n",
808 atomic_read(&tgtp->xmt_fcp_abort),
809 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
810
811 len += snprintf(buf + len, size - len,
812 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
813 atomic_read(&tgtp->xmt_abort_sol),
814 atomic_read(&tgtp->xmt_abort_unsol),
2b65e182 815 atomic_read(&tgtp->xmt_abort_rsp),
547077a4 816 atomic_read(&tgtp->xmt_abort_rsp_error));
2b65e182 817
86c67379
JS
818 len += snprintf(buf + len, size - len, "\n");
819
820 cnt = 0;
821 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
822 list_for_each_entry_safe(ctxp, next_ctxp,
823 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
824 list) {
825 cnt++;
826 }
827 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
828 if (cnt) {
829 len += snprintf(buf + len, size - len,
830 "ABORT: %d ctx entries\n", cnt);
831 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
832 list_for_each_entry_safe(ctxp, next_ctxp,
833 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
834 list) {
835 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
836 break;
837 len += snprintf(buf + len, size - len,
838 "Entry: oxid %x state %x "
839 "flag %x\n",
840 ctxp->oxid, ctxp->state,
841 ctxp->flag);
842 }
843 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
844 }
a8cf5dfe
JS
845
846 len += snprintf(buf + len, size - len,
847 "IO_CTX: %08x outstanding %08x total %08x\n",
848 phba->sli4_hba.nvmet_ctx_cnt,
849 phba->sli4_hba.nvmet_io_wait_cnt,
850 phba->sli4_hba.nvmet_io_wait_total);
2b65e182 851 } else {
bd2cdd5e
JS
852 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
853 return len;
854
855 len += snprintf(buf + len, size - len,
856 "\nNVME Lport Statistics\n");
857
858 len += snprintf(buf + len, size - len,
859 "LS: Xmt %016llx Cmpl %016llx\n",
860 phba->fc4NvmeLsRequests,
861 phba->fc4NvmeLsCmpls);
862
863 len += snprintf(buf + len, size - len,
864 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
865 phba->fc4NvmeInputRequests,
866 phba->fc4NvmeOutputRequests,
867 phba->fc4NvmeControlRequests);
868
869 len += snprintf(buf + len, size - len,
870 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
871 }
872
873 return len;
874}
875
876
877/**
878 * lpfc_debugfs_nvmektime_data - Dump target node list to a buffer
879 * @vport: The vport to gather target node info from.
880 * @buf: The buffer to dump log into.
881 * @size: The maximum amount of data to process.
882 *
883 * Description:
884 * This routine dumps the NVME statistics associated with @vport
885 *
886 * Return Value:
887 * This routine returns the amount of bytes that were dumped into @buf and will
888 * not exceed @size.
889 **/
890static int
891lpfc_debugfs_nvmektime_data(struct lpfc_vport *vport, char *buf, int size)
892{
893 struct lpfc_hba *phba = vport->phba;
894 int len = 0;
895
896 if (phba->nvmet_support == 0) {
897 /* NVME Initiator */
898 len += snprintf(buf + len, PAGE_SIZE - len,
899 "ktime %s: Total Samples: %lld\n",
900 (phba->ktime_on ? "Enabled" : "Disabled"),
901 phba->ktime_data_samples);
902 if (phba->ktime_data_samples == 0)
903 return len;
904
905 len += snprintf(
906 buf + len, PAGE_SIZE - len,
907 "Segment 1: Last NVME Cmd cmpl "
908 "done -to- Start of next NVME cnd (in driver)\n");
909 len += snprintf(
910 buf + len, PAGE_SIZE - len,
911 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
912 div_u64(phba->ktime_seg1_total,
913 phba->ktime_data_samples),
bd2cdd5e
JS
914 phba->ktime_seg1_min,
915 phba->ktime_seg1_max);
916 len += snprintf(
917 buf + len, PAGE_SIZE - len,
918 "Segment 2: Driver start of NVME cmd "
919 "-to- Firmware WQ doorbell\n");
920 len += snprintf(
921 buf + len, PAGE_SIZE - len,
922 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
923 div_u64(phba->ktime_seg2_total,
924 phba->ktime_data_samples),
bd2cdd5e
JS
925 phba->ktime_seg2_min,
926 phba->ktime_seg2_max);
927 len += snprintf(
928 buf + len, PAGE_SIZE - len,
929 "Segment 3: Firmware WQ doorbell -to- "
930 "MSI-X ISR cmpl\n");
931 len += snprintf(
932 buf + len, PAGE_SIZE - len,
933 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
934 div_u64(phba->ktime_seg3_total,
935 phba->ktime_data_samples),
bd2cdd5e
JS
936 phba->ktime_seg3_min,
937 phba->ktime_seg3_max);
938 len += snprintf(
939 buf + len, PAGE_SIZE - len,
940 "Segment 4: MSI-X ISR cmpl -to- "
941 "NVME cmpl done\n");
942 len += snprintf(
943 buf + len, PAGE_SIZE - len,
944 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
945 div_u64(phba->ktime_seg4_total,
946 phba->ktime_data_samples),
bd2cdd5e
JS
947 phba->ktime_seg4_min,
948 phba->ktime_seg4_max);
949 len += snprintf(
950 buf + len, PAGE_SIZE - len,
951 "Total IO avg time: %08lld\n",
90ec7c9d 952 div_u64(phba->ktime_seg1_total +
bd2cdd5e
JS
953 phba->ktime_seg2_total +
954 phba->ktime_seg3_total +
90ec7c9d 955 phba->ktime_seg4_total,
bd2cdd5e
JS
956 phba->ktime_data_samples));
957 return len;
958 }
2b65e182
JS
959
960 /* NVME Target */
961 len += snprintf(buf + len, PAGE_SIZE-len,
962 "ktime %s: Total Samples: %lld %lld\n",
963 (phba->ktime_on ? "Enabled" : "Disabled"),
964 phba->ktime_data_samples,
965 phba->ktime_status_samples);
966 if (phba->ktime_data_samples == 0)
967 return len;
968
969 len += snprintf(buf + len, PAGE_SIZE-len,
970 "Segment 1: MSI-X ISR Rcv cmd -to- "
971 "cmd pass to NVME Layer\n");
972 len += snprintf(buf + len, PAGE_SIZE-len,
973 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
974 div_u64(phba->ktime_seg1_total,
975 phba->ktime_data_samples),
2b65e182
JS
976 phba->ktime_seg1_min,
977 phba->ktime_seg1_max);
978 len += snprintf(buf + len, PAGE_SIZE-len,
979 "Segment 2: cmd pass to NVME Layer- "
980 "-to- Driver rcv cmd OP (action)\n");
981 len += snprintf(buf + len, PAGE_SIZE-len,
982 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
983 div_u64(phba->ktime_seg2_total,
984 phba->ktime_data_samples),
2b65e182
JS
985 phba->ktime_seg2_min,
986 phba->ktime_seg2_max);
987 len += snprintf(buf + len, PAGE_SIZE-len,
988 "Segment 3: Driver rcv cmd OP -to- "
989 "Firmware WQ doorbell: cmd\n");
990 len += snprintf(buf + len, PAGE_SIZE-len,
991 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
992 div_u64(phba->ktime_seg3_total,
993 phba->ktime_data_samples),
2b65e182
JS
994 phba->ktime_seg3_min,
995 phba->ktime_seg3_max);
996 len += snprintf(buf + len, PAGE_SIZE-len,
997 "Segment 4: Firmware WQ doorbell: cmd "
998 "-to- MSI-X ISR for cmd cmpl\n");
999 len += snprintf(buf + len, PAGE_SIZE-len,
1000 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
1001 div_u64(phba->ktime_seg4_total,
1002 phba->ktime_data_samples),
2b65e182
JS
1003 phba->ktime_seg4_min,
1004 phba->ktime_seg4_max);
1005 len += snprintf(buf + len, PAGE_SIZE-len,
1006 "Segment 5: MSI-X ISR for cmd cmpl "
1007 "-to- NVME layer passed cmd done\n");
1008 len += snprintf(buf + len, PAGE_SIZE-len,
1009 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
1010 div_u64(phba->ktime_seg5_total,
1011 phba->ktime_data_samples),
2b65e182
JS
1012 phba->ktime_seg5_min,
1013 phba->ktime_seg5_max);
1014
1015 if (phba->ktime_status_samples == 0) {
1016 len += snprintf(buf + len, PAGE_SIZE-len,
1017 "Total: cmd received by MSI-X ISR "
1018 "-to- cmd completed on wire\n");
1019 len += snprintf(buf + len, PAGE_SIZE-len,
1020 "avg:%08lld min:%08lld "
1021 "max %08lld\n",
90ec7c9d
AB
1022 div_u64(phba->ktime_seg10_total,
1023 phba->ktime_data_samples),
2b65e182
JS
1024 phba->ktime_seg10_min,
1025 phba->ktime_seg10_max);
1026 return len;
1027 }
1028
1029 len += snprintf(buf + len, PAGE_SIZE-len,
1030 "Segment 6: NVME layer passed cmd done "
1031 "-to- Driver rcv rsp status OP\n");
1032 len += snprintf(buf + len, PAGE_SIZE-len,
1033 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
1034 div_u64(phba->ktime_seg6_total,
1035 phba->ktime_status_samples),
2b65e182
JS
1036 phba->ktime_seg6_min,
1037 phba->ktime_seg6_max);
1038 len += snprintf(buf + len, PAGE_SIZE-len,
1039 "Segment 7: Driver rcv rsp status OP "
1040 "-to- Firmware WQ doorbell: status\n");
1041 len += snprintf(buf + len, PAGE_SIZE-len,
1042 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
1043 div_u64(phba->ktime_seg7_total,
1044 phba->ktime_status_samples),
2b65e182
JS
1045 phba->ktime_seg7_min,
1046 phba->ktime_seg7_max);
1047 len += snprintf(buf + len, PAGE_SIZE-len,
1048 "Segment 8: Firmware WQ doorbell: status"
1049 " -to- MSI-X ISR for status cmpl\n");
1050 len += snprintf(buf + len, PAGE_SIZE-len,
1051 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
1052 div_u64(phba->ktime_seg8_total,
1053 phba->ktime_status_samples),
2b65e182
JS
1054 phba->ktime_seg8_min,
1055 phba->ktime_seg8_max);
1056 len += snprintf(buf + len, PAGE_SIZE-len,
1057 "Segment 9: MSI-X ISR for status cmpl "
1058 "-to- NVME layer passed status done\n");
1059 len += snprintf(buf + len, PAGE_SIZE-len,
1060 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
1061 div_u64(phba->ktime_seg9_total,
1062 phba->ktime_status_samples),
2b65e182
JS
1063 phba->ktime_seg9_min,
1064 phba->ktime_seg9_max);
1065 len += snprintf(buf + len, PAGE_SIZE-len,
1066 "Total: cmd received by MSI-X ISR -to- "
1067 "cmd completed on wire\n");
1068 len += snprintf(buf + len, PAGE_SIZE-len,
1069 "avg:%08lld min:%08lld max %08lld\n",
90ec7c9d
AB
1070 div_u64(phba->ktime_seg10_total,
1071 phba->ktime_status_samples),
2b65e182
JS
1072 phba->ktime_seg10_min,
1073 phba->ktime_seg10_max);
bd2cdd5e
JS
1074 return len;
1075}
1076
1077/**
1078 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1079 * @phba: The phba to gather target node info from.
1080 * @buf: The buffer to dump log into.
1081 * @size: The maximum amount of data to process.
1082 *
1083 * Description:
1084 * This routine dumps the NVME IO trace associated with @phba
1085 *
1086 * Return Value:
1087 * This routine returns the amount of bytes that were dumped into @buf and will
1088 * not exceed @size.
1089 **/
1090static int
1091lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1092{
1093 struct lpfc_debugfs_nvmeio_trc *dtp;
1094 int i, state, index, skip;
1095 int len = 0;
1096
1097 state = phba->nvmeio_trc_on;
1098
1099 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1100 (phba->nvmeio_trc_size - 1);
1101 skip = phba->nvmeio_trc_output_idx;
1102
1103 len += snprintf(buf + len, size - len,
1104 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1105 (phba->nvmet_support ? "NVME" : "NVMET"),
1106 (state ? "Enabled" : "Disabled"),
1107 index, skip, phba->nvmeio_trc_size);
1108
1109 if (!phba->nvmeio_trc || state)
1110 return len;
1111
1112 /* trace MUST bhe off to continue */
1113
1114 for (i = index; i < phba->nvmeio_trc_size; i++) {
1115 if (skip) {
1116 skip--;
1117 continue;
1118 }
1119 dtp = phba->nvmeio_trc + i;
1120 phba->nvmeio_trc_output_idx++;
1121
1122 if (!dtp->fmt)
1123 continue;
1124
1125 len += snprintf(buf + len, size - len, dtp->fmt,
1126 dtp->data1, dtp->data2, dtp->data3);
1127
1128 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1129 phba->nvmeio_trc_output_idx = 0;
1130 len += snprintf(buf + len, size - len,
1131 "Trace Complete\n");
1132 goto out;
1133 }
1134
1135 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1136 len += snprintf(buf + len, size - len,
1137 "Trace Continue (%d of %d)\n",
1138 phba->nvmeio_trc_output_idx,
1139 phba->nvmeio_trc_size);
1140 goto out;
1141 }
1142 }
1143 for (i = 0; i < index; i++) {
1144 if (skip) {
1145 skip--;
1146 continue;
1147 }
1148 dtp = phba->nvmeio_trc + i;
1149 phba->nvmeio_trc_output_idx++;
1150
1151 if (!dtp->fmt)
1152 continue;
1153
1154 len += snprintf(buf + len, size - len, dtp->fmt,
1155 dtp->data1, dtp->data2, dtp->data3);
1156
1157 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1158 phba->nvmeio_trc_output_idx = 0;
1159 len += snprintf(buf + len, size - len,
1160 "Trace Complete\n");
1161 goto out;
1162 }
1163
1164 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
1165 len += snprintf(buf + len, size - len,
1166 "Trace Continue (%d of %d)\n",
1167 phba->nvmeio_trc_output_idx,
1168 phba->nvmeio_trc_size);
1169 goto out;
1170 }
1171 }
1172
1173 len += snprintf(buf + len, size - len,
1174 "Trace Done\n");
1175out:
1176 return len;
1177}
1178
1179/**
1180 * lpfc_debugfs_cpucheck_data - Dump target node list to a buffer
1181 * @vport: The vport to gather target node info from.
1182 * @buf: The buffer to dump log into.
1183 * @size: The maximum amount of data to process.
1184 *
1185 * Description:
1186 * This routine dumps the NVME statistics associated with @vport
1187 *
1188 * Return Value:
1189 * This routine returns the amount of bytes that were dumped into @buf and will
1190 * not exceed @size.
1191 **/
1192static int
1193lpfc_debugfs_cpucheck_data(struct lpfc_vport *vport, char *buf, int size)
1194{
1195 struct lpfc_hba *phba = vport->phba;
1196 int i;
1197 int len = 0;
1198 uint32_t tot_xmt = 0;
2b65e182 1199 uint32_t tot_rcv = 0;
bd2cdd5e 1200 uint32_t tot_cmpl = 0;
2b65e182 1201 uint32_t tot_ccmpl = 0;
bd2cdd5e
JS
1202
1203 if (phba->nvmet_support == 0) {
1204 /* NVME Initiator */
1205 len += snprintf(buf + len, PAGE_SIZE - len,
1206 "CPUcheck %s\n",
1207 (phba->cpucheck_on & LPFC_CHECK_NVME_IO ?
1208 "Enabled" : "Disabled"));
1209 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1210 if (i >= LPFC_CHECK_CPU_CNT)
1211 break;
1212 len += snprintf(buf + len, PAGE_SIZE - len,
1213 "%02d: xmit x%08x cmpl x%08x\n",
1214 i, phba->cpucheck_xmt_io[i],
1215 phba->cpucheck_cmpl_io[i]);
1216 tot_xmt += phba->cpucheck_xmt_io[i];
1217 tot_cmpl += phba->cpucheck_cmpl_io[i];
1218 }
1219 len += snprintf(buf + len, PAGE_SIZE - len,
1220 "tot:xmit x%08x cmpl x%08x\n",
1221 tot_xmt, tot_cmpl);
1222 return len;
1223 }
1224
2b65e182
JS
1225 /* NVME Target */
1226 len += snprintf(buf + len, PAGE_SIZE - len,
1227 "CPUcheck %s ",
1228 (phba->cpucheck_on & LPFC_CHECK_NVMET_IO ?
1229 "IO Enabled - " : "IO Disabled - "));
1230 len += snprintf(buf + len, PAGE_SIZE - len,
1231 "%s\n",
1232 (phba->cpucheck_on & LPFC_CHECK_NVMET_RCV ?
1233 "Rcv Enabled\n" : "Rcv Disabled\n"));
1234 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
1235 if (i >= LPFC_CHECK_CPU_CNT)
1236 break;
1237 len += snprintf(buf + len, PAGE_SIZE - len,
1238 "%02d: xmit x%08x ccmpl x%08x "
1239 "cmpl x%08x rcv x%08x\n",
1240 i, phba->cpucheck_xmt_io[i],
1241 phba->cpucheck_ccmpl_io[i],
1242 phba->cpucheck_cmpl_io[i],
1243 phba->cpucheck_rcv_io[i]);
1244 tot_xmt += phba->cpucheck_xmt_io[i];
1245 tot_rcv += phba->cpucheck_rcv_io[i];
1246 tot_cmpl += phba->cpucheck_cmpl_io[i];
1247 tot_ccmpl += phba->cpucheck_ccmpl_io[i];
1248 }
1249 len += snprintf(buf + len, PAGE_SIZE - len,
1250 "tot:xmit x%08x ccmpl x%08x cmpl x%08x rcv x%08x\n",
1251 tot_xmt, tot_ccmpl, tot_cmpl, tot_rcv);
858c9f6c
JS
1252 return len;
1253}
2ea259ee 1254
858c9f6c
JS
1255#endif
1256
e59058c4 1257/**
3621a710 1258 * lpfc_debugfs_disc_trc - Store discovery trace log
e59058c4
JS
1259 * @vport: The vport to associate this trace string with for retrieval.
1260 * @mask: Log entry classification.
1261 * @fmt: Format string to be displayed when dumping the log.
1262 * @data1: 1st data parameter to be applied to @fmt.
1263 * @data2: 2nd data parameter to be applied to @fmt.
1264 * @data3: 3rd data parameter to be applied to @fmt.
1265 *
1266 * Description:
1267 * This routine is used by the driver code to add a debugfs log entry to the
1268 * discovery trace buffer associated with @vport. Only entries with a @mask that
1269 * match the current debugfs discovery mask will be saved. Entries that do not
1270 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1271 * printf when displaying the log.
1272 **/
858c9f6c
JS
1273inline void
1274lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1275 uint32_t data1, uint32_t data2, uint32_t data3)
1276{
923e4b6a 1277#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
a58cbd52 1278 struct lpfc_debugfs_trc *dtp;
858c9f6c
JS
1279 int index;
1280
1281 if (!(lpfc_debugfs_mask_disc_trc & mask))
1282 return;
1283
1284 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1285 !vport || !vport->disc_trc)
1286 return;
1287
1288 index = atomic_inc_return(&vport->disc_trc_cnt) &
1289 (lpfc_debugfs_max_disc_trc - 1);
1290 dtp = vport->disc_trc + index;
1291 dtp->fmt = fmt;
1292 dtp->data1 = data1;
1293 dtp->data2 = data2;
1294 dtp->data3 = data3;
a58cbd52
JS
1295 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1296 dtp->jif = jiffies;
1297#endif
1298 return;
1299}
1300
e59058c4 1301/**
3621a710 1302 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
e59058c4
JS
1303 * @phba: The phba to associate this trace string with for retrieval.
1304 * @fmt: Format string to be displayed when dumping the log.
1305 * @data1: 1st data parameter to be applied to @fmt.
1306 * @data2: 2nd data parameter to be applied to @fmt.
1307 * @data3: 3rd data parameter to be applied to @fmt.
1308 *
1309 * Description:
1310 * This routine is used by the driver code to add a debugfs log entry to the
1311 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1312 * @data3 are used like printf when displaying the log.
1313 **/
a58cbd52
JS
1314inline void
1315lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1316 uint32_t data1, uint32_t data2, uint32_t data3)
1317{
923e4b6a 1318#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
a58cbd52
JS
1319 struct lpfc_debugfs_trc *dtp;
1320 int index;
1321
1322 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1323 !phba || !phba->slow_ring_trc)
1324 return;
1325
1326 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1327 (lpfc_debugfs_max_slow_ring_trc - 1);
1328 dtp = phba->slow_ring_trc + index;
1329 dtp->fmt = fmt;
1330 dtp->data1 = data1;
1331 dtp->data2 = data2;
1332 dtp->data3 = data3;
1333 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
858c9f6c
JS
1334 dtp->jif = jiffies;
1335#endif
1336 return;
1337}
1338
bd2cdd5e
JS
1339/**
1340 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1341 * @phba: The phba to associate this trace string with for retrieval.
1342 * @fmt: Format string to be displayed when dumping the log.
1343 * @data1: 1st data parameter to be applied to @fmt.
1344 * @data2: 2nd data parameter to be applied to @fmt.
1345 * @data3: 3rd data parameter to be applied to @fmt.
1346 *
1347 * Description:
1348 * This routine is used by the driver code to add a debugfs log entry to the
1349 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1350 * @data3 are used like printf when displaying the log.
1351 **/
1352inline void
1353lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1354 uint16_t data1, uint16_t data2, uint32_t data3)
1355{
1356#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1357 struct lpfc_debugfs_nvmeio_trc *dtp;
1358 int index;
1359
1360 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1361 return;
1362
1363 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1364 (phba->nvmeio_trc_size - 1);
1365 dtp = phba->nvmeio_trc + index;
1366 dtp->fmt = fmt;
1367 dtp->data1 = data1;
1368 dtp->data2 = data2;
1369 dtp->data3 = data3;
1370#endif
1371}
1372
923e4b6a 1373#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
e59058c4 1374/**
3621a710 1375 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
e59058c4
JS
1376 * @inode: The inode pointer that contains a vport pointer.
1377 * @file: The file pointer to attach the log output.
1378 *
1379 * Description:
1380 * This routine is the entry point for the debugfs open file operation. It gets
1381 * the vport from the i_private field in @inode, allocates the necessary buffer
1382 * for the log, fills the buffer from the in-memory log for this vport, and then
1383 * returns a pointer to that log in the private_data field in @file.
1384 *
1385 * Returns:
79ce48df 1386 * This function returns zero if successful. On error it will return a negative
e59058c4
JS
1387 * error value.
1388 **/
858c9f6c
JS
1389static int
1390lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1391{
1392 struct lpfc_vport *vport = inode->i_private;
1393 struct lpfc_debug *debug;
1394 int size;
1395 int rc = -ENOMEM;
1396
1397 if (!lpfc_debugfs_max_disc_trc) {
1398 rc = -ENOSPC;
1399 goto out;
1400 }
1401
1402 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1403 if (!debug)
1404 goto out;
1405
e59058c4 1406 /* Round to page boundary */
a58cbd52 1407 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
858c9f6c
JS
1408 size = PAGE_ALIGN(size);
1409
1410 debug->buffer = kmalloc(size, GFP_KERNEL);
1411 if (!debug->buffer) {
1412 kfree(debug);
1413 goto out;
1414 }
1415
1416 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1417 file->private_data = debug;
1418
1419 rc = 0;
1420out:
1421 return rc;
1422}
1423
e59058c4 1424/**
3621a710 1425 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
e59058c4
JS
1426 * @inode: The inode pointer that contains a vport pointer.
1427 * @file: The file pointer to attach the log output.
1428 *
1429 * Description:
1430 * This routine is the entry point for the debugfs open file operation. It gets
1431 * the vport from the i_private field in @inode, allocates the necessary buffer
1432 * for the log, fills the buffer from the in-memory log for this vport, and then
1433 * returns a pointer to that log in the private_data field in @file.
1434 *
1435 * Returns:
79ce48df 1436 * This function returns zero if successful. On error it will return a negative
e59058c4
JS
1437 * error value.
1438 **/
a58cbd52
JS
1439static int
1440lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1441{
1442 struct lpfc_hba *phba = inode->i_private;
1443 struct lpfc_debug *debug;
1444 int size;
1445 int rc = -ENOMEM;
1446
1447 if (!lpfc_debugfs_max_slow_ring_trc) {
1448 rc = -ENOSPC;
1449 goto out;
1450 }
1451
1452 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1453 if (!debug)
1454 goto out;
1455
e59058c4 1456 /* Round to page boundary */
a58cbd52
JS
1457 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
1458 size = PAGE_ALIGN(size);
1459
1460 debug->buffer = kmalloc(size, GFP_KERNEL);
1461 if (!debug->buffer) {
1462 kfree(debug);
1463 goto out;
1464 }
1465
1466 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
1467 file->private_data = debug;
1468
1469 rc = 0;
1470out:
1471 return rc;
1472}
1473
e59058c4 1474/**
3621a710 1475 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
e59058c4
JS
1476 * @inode: The inode pointer that contains a vport pointer.
1477 * @file: The file pointer to attach the log output.
1478 *
1479 * Description:
1480 * This routine is the entry point for the debugfs open file operation. It gets
1481 * the vport from the i_private field in @inode, allocates the necessary buffer
1482 * for the log, fills the buffer from the in-memory log for this vport, and then
1483 * returns a pointer to that log in the private_data field in @file.
1484 *
1485 * Returns:
79ce48df 1486 * This function returns zero if successful. On error it will return a negative
e59058c4
JS
1487 * error value.
1488 **/
78b2d852
JS
1489static int
1490lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
1491{
1492 struct lpfc_hba *phba = inode->i_private;
1493 struct lpfc_debug *debug;
1494 int rc = -ENOMEM;
1495
1496 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1497 if (!debug)
1498 goto out;
1499
e59058c4 1500 /* Round to page boundary */
78b2d852
JS
1501 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
1502 if (!debug->buffer) {
1503 kfree(debug);
1504 goto out;
1505 }
1506
1507 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
1508 LPFC_HBQINFO_SIZE);
1509 file->private_data = debug;
1510
1511 rc = 0;
1512out:
1513 return rc;
1514}
1515
e59058c4 1516/**
3621a710 1517 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
e59058c4
JS
1518 * @inode: The inode pointer that contains a vport pointer.
1519 * @file: The file pointer to attach the log output.
1520 *
1521 * Description:
1522 * This routine is the entry point for the debugfs open file operation. It gets
1523 * the vport from the i_private field in @inode, allocates the necessary buffer
1524 * for the log, fills the buffer from the in-memory log for this vport, and then
1525 * returns a pointer to that log in the private_data field in @file.
1526 *
1527 * Returns:
79ce48df 1528 * This function returns zero if successful. On error it will return a negative
e59058c4
JS
1529 * error value.
1530 **/
a58cbd52 1531static int
c95d6c6c 1532lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
a58cbd52
JS
1533{
1534 struct lpfc_hba *phba = inode->i_private;
1535 struct lpfc_debug *debug;
1536 int rc = -ENOMEM;
1537
1538 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1539 if (!debug)
1540 goto out;
1541
e59058c4 1542 /* Round to page boundary */
c95d6c6c 1543 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
a58cbd52
JS
1544 if (!debug->buffer) {
1545 kfree(debug);
1546 goto out;
1547 }
1548
c95d6c6c
JS
1549 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
1550 LPFC_DUMPHBASLIM_SIZE);
1551 file->private_data = debug;
1552
1553 rc = 0;
1554out:
1555 return rc;
1556}
1557
e59058c4 1558/**
3621a710 1559 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
e59058c4
JS
1560 * @inode: The inode pointer that contains a vport pointer.
1561 * @file: The file pointer to attach the log output.
1562 *
1563 * Description:
1564 * This routine is the entry point for the debugfs open file operation. It gets
1565 * the vport from the i_private field in @inode, allocates the necessary buffer
1566 * for the log, fills the buffer from the in-memory log for this vport, and then
1567 * returns a pointer to that log in the private_data field in @file.
1568 *
1569 * Returns:
79ce48df 1570 * This function returns zero if successful. On error it will return a negative
e59058c4
JS
1571 * error value.
1572 **/
c95d6c6c
JS
1573static int
1574lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
1575{
1576 struct lpfc_hba *phba = inode->i_private;
1577 struct lpfc_debug *debug;
1578 int rc = -ENOMEM;
1579
1580 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1581 if (!debug)
1582 goto out;
1583
e59058c4 1584 /* Round to page boundary */
c95d6c6c
JS
1585 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
1586 if (!debug->buffer) {
1587 kfree(debug);
1588 goto out;
1589 }
1590
1591 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
1592 LPFC_DUMPHOSTSLIM_SIZE);
a58cbd52
JS
1593 file->private_data = debug;
1594
1595 rc = 0;
1596out:
1597 return rc;
1598}
1599
e2a0a9d6
JS
1600static int
1601lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
1602{
1603 struct lpfc_debug *debug;
1604 int rc = -ENOMEM;
1605
1606 if (!_dump_buf_data)
1607 return -EBUSY;
1608
1609 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1610 if (!debug)
1611 goto out;
1612
25985edc 1613 /* Round to page boundary */
2ea259ee 1614 pr_err("9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
e2a0a9d6
JS
1615 __func__, _dump_buf_data);
1616 debug->buffer = _dump_buf_data;
1617 if (!debug->buffer) {
1618 kfree(debug);
1619 goto out;
1620 }
1621
1622 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
1623 file->private_data = debug;
1624
1625 rc = 0;
1626out:
1627 return rc;
1628}
1629
1630static int
1631lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
1632{
1633 struct lpfc_debug *debug;
1634 int rc = -ENOMEM;
1635
1636 if (!_dump_buf_dif)
1637 return -EBUSY;
1638
1639 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1640 if (!debug)
1641 goto out;
1642
25985edc 1643 /* Round to page boundary */
2ea259ee
JS
1644 pr_err("9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%pD\n",
1645 __func__, _dump_buf_dif, file);
e2a0a9d6
JS
1646 debug->buffer = _dump_buf_dif;
1647 if (!debug->buffer) {
1648 kfree(debug);
1649 goto out;
1650 }
1651
1652 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
1653 file->private_data = debug;
1654
1655 rc = 0;
1656out:
1657 return rc;
1658}
1659
1660static ssize_t
1661lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
1662 size_t nbytes, loff_t *ppos)
1663{
1664 /*
1665 * The Data/DIF buffers only save one failing IO
1666 * The write op is used as a reset mechanism after an IO has
1667 * already been saved to the next one can be saved
1668 */
1669 spin_lock(&_dump_buf_lock);
1670
1671 memset((void *)_dump_buf_data, 0,
1672 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
1673 memset((void *)_dump_buf_dif, 0,
1674 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
1675
1676 _dump_buf_done = 0;
1677
1678 spin_unlock(&_dump_buf_lock);
1679
1680 return nbytes;
1681}
1682
f9bb2da1
JS
1683static ssize_t
1684lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1685 size_t nbytes, loff_t *ppos)
1686{
b583043e 1687 struct dentry *dent = file->f_path.dentry;
f9bb2da1 1688 struct lpfc_hba *phba = file->private_data;
9a6b09c0 1689 char cbuf[32];
4ac9b226 1690 uint64_t tmp = 0;
f9bb2da1
JS
1691 int cnt = 0;
1692
1693 if (dent == phba->debug_writeGuard)
9a6b09c0 1694 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
f9bb2da1 1695 else if (dent == phba->debug_writeApp)
9a6b09c0 1696 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
f9bb2da1 1697 else if (dent == phba->debug_writeRef)
9a6b09c0 1698 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
acd6859b 1699 else if (dent == phba->debug_readGuard)
9a6b09c0 1700 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
f9bb2da1 1701 else if (dent == phba->debug_readApp)
9a6b09c0 1702 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
f9bb2da1 1703 else if (dent == phba->debug_readRef)
9a6b09c0 1704 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
4ac9b226
JS
1705 else if (dent == phba->debug_InjErrNPortID)
1706 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1707 else if (dent == phba->debug_InjErrWWPN) {
1708 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1709 tmp = cpu_to_be64(tmp);
1710 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1711 } else if (dent == phba->debug_InjErrLBA) {
1712 if (phba->lpfc_injerr_lba == (sector_t)(-1))
9a6b09c0
JS
1713 cnt = snprintf(cbuf, 32, "off\n");
1714 else
4ac9b226
JS
1715 cnt = snprintf(cbuf, 32, "0x%llx\n",
1716 (uint64_t) phba->lpfc_injerr_lba);
9a6b09c0 1717 } else
f9bb2da1
JS
1718 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1719 "0547 Unknown debugfs error injection entry\n");
1720
1721 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1722}
1723
1724static ssize_t
1725lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1726 size_t nbytes, loff_t *ppos)
1727{
b583043e 1728 struct dentry *dent = file->f_path.dentry;
f9bb2da1 1729 struct lpfc_hba *phba = file->private_data;
0872774d 1730 char dstbuf[33];
4ac9b226 1731 uint64_t tmp = 0;
f9bb2da1
JS
1732 int size;
1733
0872774d 1734 memset(dstbuf, 0, 33);
f9bb2da1
JS
1735 size = (nbytes < 32) ? nbytes : 32;
1736 if (copy_from_user(dstbuf, buf, size))
1737 return 0;
1738
9a6b09c0
JS
1739 if (dent == phba->debug_InjErrLBA) {
1740 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
4ac9b226 1741 tmp = (uint64_t)(-1);
9a6b09c0
JS
1742 }
1743
4ac9b226 1744 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
f9bb2da1
JS
1745 return 0;
1746
1747 if (dent == phba->debug_writeGuard)
1748 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1749 else if (dent == phba->debug_writeApp)
1750 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1751 else if (dent == phba->debug_writeRef)
1752 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
acd6859b
JS
1753 else if (dent == phba->debug_readGuard)
1754 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
f9bb2da1
JS
1755 else if (dent == phba->debug_readApp)
1756 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1757 else if (dent == phba->debug_readRef)
1758 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1759 else if (dent == phba->debug_InjErrLBA)
1760 phba->lpfc_injerr_lba = (sector_t)tmp;
4ac9b226
JS
1761 else if (dent == phba->debug_InjErrNPortID)
1762 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1763 else if (dent == phba->debug_InjErrWWPN) {
1764 tmp = cpu_to_be64(tmp);
1765 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1766 } else
f9bb2da1
JS
1767 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1768 "0548 Unknown debugfs error injection entry\n");
1769
1770 return nbytes;
1771}
1772
1773static int
1774lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1775{
1776 return 0;
1777}
1778
e59058c4 1779/**
3621a710 1780 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
e59058c4
JS
1781 * @inode: The inode pointer that contains a vport pointer.
1782 * @file: The file pointer to attach the log output.
1783 *
1784 * Description:
1785 * This routine is the entry point for the debugfs open file operation. It gets
1786 * the vport from the i_private field in @inode, allocates the necessary buffer
1787 * for the log, fills the buffer from the in-memory log for this vport, and then
1788 * returns a pointer to that log in the private_data field in @file.
1789 *
1790 * Returns:
79ce48df 1791 * This function returns zero if successful. On error it will return a negative
e59058c4
JS
1792 * error value.
1793 **/
858c9f6c
JS
1794static int
1795lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1796{
1797 struct lpfc_vport *vport = inode->i_private;
1798 struct lpfc_debug *debug;
1799 int rc = -ENOMEM;
1800
1801 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1802 if (!debug)
1803 goto out;
1804
e59058c4 1805 /* Round to page boundary */
858c9f6c
JS
1806 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1807 if (!debug->buffer) {
1808 kfree(debug);
1809 goto out;
1810 }
1811
1812 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1813 LPFC_NODELIST_SIZE);
1814 file->private_data = debug;
1815
1816 rc = 0;
1817out:
1818 return rc;
1819}
1820
e59058c4 1821/**
3621a710 1822 * lpfc_debugfs_lseek - Seek through a debugfs file
e59058c4
JS
1823 * @file: The file pointer to seek through.
1824 * @off: The offset to seek to or the amount to seek by.
1825 * @whence: Indicates how to seek.
1826 *
1827 * Description:
1828 * This routine is the entry point for the debugfs lseek file operation. The
1829 * @whence parameter indicates whether @off is the offset to directly seek to,
1830 * or if it is a value to seek forward or reverse by. This function figures out
1831 * what the new offset of the debugfs file will be and assigns that value to the
1832 * f_pos field of @file.
1833 *
1834 * Returns:
1835 * This function returns the new offset if successful and returns a negative
1836 * error if unable to process the seek.
1837 **/
858c9f6c
JS
1838static loff_t
1839lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1840{
7233c774
AV
1841 struct lpfc_debug *debug = file->private_data;
1842 return fixed_size_llseek(file, off, whence, debug->len);
858c9f6c
JS
1843}
1844
e59058c4 1845/**
3621a710 1846 * lpfc_debugfs_read - Read a debugfs file
e59058c4
JS
1847 * @file: The file pointer to read from.
1848 * @buf: The buffer to copy the data to.
1849 * @nbytes: The number of bytes to read.
1850 * @ppos: The position in the file to start reading from.
1851 *
1852 * Description:
1853 * This routine reads data from from the buffer indicated in the private_data
1854 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1855 * data to @buf.
1856 *
1857 * Returns:
1858 * This function returns the amount of data that was read (this could be less
1859 * than @nbytes if the end of the file was reached) or a negative error value.
1860 **/
858c9f6c
JS
1861static ssize_t
1862lpfc_debugfs_read(struct file *file, char __user *buf,
1863 size_t nbytes, loff_t *ppos)
1864{
1865 struct lpfc_debug *debug = file->private_data;
2a622bfb 1866
858c9f6c
JS
1867 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1868 debug->len);
1869}
1870
e59058c4 1871/**
3621a710 1872 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
e59058c4
JS
1873 * @inode: The inode pointer that contains a vport pointer. (unused)
1874 * @file: The file pointer that contains the buffer to release.
1875 *
1876 * Description:
1877 * This routine frees the buffer that was allocated when the debugfs file was
1878 * opened.
1879 *
1880 * Returns:
1881 * This function returns zero.
1882 **/
858c9f6c
JS
1883static int
1884lpfc_debugfs_release(struct inode *inode, struct file *file)
1885{
1886 struct lpfc_debug *debug = file->private_data;
1887
1888 kfree(debug->buffer);
1889 kfree(debug);
1890
1891 return 0;
1892}
1893
e2a0a9d6
JS
1894static int
1895lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1896{
1897 struct lpfc_debug *debug = file->private_data;
1898
1899 debug->buffer = NULL;
1900 kfree(debug);
1901
1902 return 0;
1903}
1904
bd2cdd5e
JS
1905
1906static int
1907lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
1908{
1909 struct lpfc_vport *vport = inode->i_private;
1910 struct lpfc_debug *debug;
1911 int rc = -ENOMEM;
1912
1913 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1914 if (!debug)
1915 goto out;
1916
1917 /* Round to page boundary */
1918 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
1919 if (!debug->buffer) {
1920 kfree(debug);
1921 goto out;
1922 }
1923
1924 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
1925 LPFC_NVMESTAT_SIZE);
1926
1927 debug->i_private = inode->i_private;
1928 file->private_data = debug;
1929
1930 rc = 0;
1931out:
1932 return rc;
1933}
1934
2b65e182
JS
1935static ssize_t
1936lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
1937 size_t nbytes, loff_t *ppos)
1938{
1939 struct lpfc_debug *debug = file->private_data;
1940 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
1941 struct lpfc_hba *phba = vport->phba;
1942 struct lpfc_nvmet_tgtport *tgtp;
1943 char mybuf[64];
1944 char *pbuf;
1945
1946 if (!phba->targetport)
1947 return -ENXIO;
1948
1949 if (nbytes > 64)
1950 nbytes = 64;
1951
1952 /* Protect copy from user */
1953 if (!access_ok(VERIFY_READ, buf, nbytes))
1954 return -EFAULT;
1955
1956 memset(mybuf, 0, sizeof(mybuf));
1957
1958 if (copy_from_user(mybuf, buf, nbytes))
1959 return -EFAULT;
1960 pbuf = &mybuf[0];
1961
1962 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1963 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
1964 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
1965 atomic_set(&tgtp->rcv_ls_req_in, 0);
1966 atomic_set(&tgtp->rcv_ls_req_out, 0);
1967 atomic_set(&tgtp->rcv_ls_req_drop, 0);
1968 atomic_set(&tgtp->xmt_ls_abort, 0);
547077a4 1969 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
2b65e182
JS
1970 atomic_set(&tgtp->xmt_ls_rsp, 0);
1971 atomic_set(&tgtp->xmt_ls_drop, 0);
1972 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
1973 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
1974
1975 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
1976 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
1977 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
2b65e182
JS
1978 atomic_set(&tgtp->xmt_fcp_drop, 0);
1979 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
1980 atomic_set(&tgtp->xmt_fcp_read, 0);
1981 atomic_set(&tgtp->xmt_fcp_write, 0);
1982 atomic_set(&tgtp->xmt_fcp_rsp, 0);
547077a4 1983 atomic_set(&tgtp->xmt_fcp_release, 0);
2b65e182
JS
1984 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
1985 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
1986 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
1987
547077a4
JS
1988 atomic_set(&tgtp->xmt_fcp_abort, 0);
1989 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
1990 atomic_set(&tgtp->xmt_abort_sol, 0);
1991 atomic_set(&tgtp->xmt_abort_unsol, 0);
2b65e182
JS
1992 atomic_set(&tgtp->xmt_abort_rsp, 0);
1993 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
2b65e182
JS
1994 }
1995 return nbytes;
1996}
1997
bd2cdd5e
JS
1998static int
1999lpfc_debugfs_nvmektime_open(struct inode *inode, struct file *file)
2000{
2001 struct lpfc_vport *vport = inode->i_private;
2002 struct lpfc_debug *debug;
2003 int rc = -ENOMEM;
2004
2005 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2006 if (!debug)
2007 goto out;
2008
2009 /* Round to page boundary */
2010 debug->buffer = kmalloc(LPFC_NVMEKTIME_SIZE, GFP_KERNEL);
2011 if (!debug->buffer) {
2012 kfree(debug);
2013 goto out;
2014 }
2015
2016 debug->len = lpfc_debugfs_nvmektime_data(vport, debug->buffer,
2017 LPFC_NVMEKTIME_SIZE);
2018
2019 debug->i_private = inode->i_private;
2020 file->private_data = debug;
2021
2022 rc = 0;
2023out:
2024 return rc;
2025}
2026
2027static ssize_t
2028lpfc_debugfs_nvmektime_write(struct file *file, const char __user *buf,
2029 size_t nbytes, loff_t *ppos)
2030{
2031 struct lpfc_debug *debug = file->private_data;
2032 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2033 struct lpfc_hba *phba = vport->phba;
2034 char mybuf[64];
2035 char *pbuf;
2036
2037 if (nbytes > 64)
2038 nbytes = 64;
2039
2040 /* Protect copy from user */
2041 if (!access_ok(VERIFY_READ, buf, nbytes))
2042 return -EFAULT;
2043
2044 memset(mybuf, 0, sizeof(mybuf));
2045
2046 if (copy_from_user(mybuf, buf, nbytes))
2047 return -EFAULT;
2048 pbuf = &mybuf[0];
2049
2050 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2051 phba->ktime_data_samples = 0;
2052 phba->ktime_status_samples = 0;
2053 phba->ktime_seg1_total = 0;
2054 phba->ktime_seg1_max = 0;
2055 phba->ktime_seg1_min = 0xffffffff;
2056 phba->ktime_seg2_total = 0;
2057 phba->ktime_seg2_max = 0;
2058 phba->ktime_seg2_min = 0xffffffff;
2059 phba->ktime_seg3_total = 0;
2060 phba->ktime_seg3_max = 0;
2061 phba->ktime_seg3_min = 0xffffffff;
2062 phba->ktime_seg4_total = 0;
2063 phba->ktime_seg4_max = 0;
2064 phba->ktime_seg4_min = 0xffffffff;
2065 phba->ktime_seg5_total = 0;
2066 phba->ktime_seg5_max = 0;
2067 phba->ktime_seg5_min = 0xffffffff;
2068 phba->ktime_seg6_total = 0;
2069 phba->ktime_seg6_max = 0;
2070 phba->ktime_seg6_min = 0xffffffff;
2071 phba->ktime_seg7_total = 0;
2072 phba->ktime_seg7_max = 0;
2073 phba->ktime_seg7_min = 0xffffffff;
2074 phba->ktime_seg8_total = 0;
2075 phba->ktime_seg8_max = 0;
2076 phba->ktime_seg8_min = 0xffffffff;
2077 phba->ktime_seg9_total = 0;
2078 phba->ktime_seg9_max = 0;
2079 phba->ktime_seg9_min = 0xffffffff;
2080 phba->ktime_seg10_total = 0;
2081 phba->ktime_seg10_max = 0;
2082 phba->ktime_seg10_min = 0xffffffff;
2083
2084 phba->ktime_on = 1;
2085 return strlen(pbuf);
2086 } else if ((strncmp(pbuf, "off",
2087 sizeof("off") - 1) == 0)) {
2088 phba->ktime_on = 0;
2089 return strlen(pbuf);
2090 } else if ((strncmp(pbuf, "zero",
2091 sizeof("zero") - 1) == 0)) {
2092 phba->ktime_data_samples = 0;
2093 phba->ktime_status_samples = 0;
2094 phba->ktime_seg1_total = 0;
2095 phba->ktime_seg1_max = 0;
2096 phba->ktime_seg1_min = 0xffffffff;
2097 phba->ktime_seg2_total = 0;
2098 phba->ktime_seg2_max = 0;
2099 phba->ktime_seg2_min = 0xffffffff;
2100 phba->ktime_seg3_total = 0;
2101 phba->ktime_seg3_max = 0;
2102 phba->ktime_seg3_min = 0xffffffff;
2103 phba->ktime_seg4_total = 0;
2104 phba->ktime_seg4_max = 0;
2105 phba->ktime_seg4_min = 0xffffffff;
2106 phba->ktime_seg5_total = 0;
2107 phba->ktime_seg5_max = 0;
2108 phba->ktime_seg5_min = 0xffffffff;
2109 phba->ktime_seg6_total = 0;
2110 phba->ktime_seg6_max = 0;
2111 phba->ktime_seg6_min = 0xffffffff;
2112 phba->ktime_seg7_total = 0;
2113 phba->ktime_seg7_max = 0;
2114 phba->ktime_seg7_min = 0xffffffff;
2115 phba->ktime_seg8_total = 0;
2116 phba->ktime_seg8_max = 0;
2117 phba->ktime_seg8_min = 0xffffffff;
2118 phba->ktime_seg9_total = 0;
2119 phba->ktime_seg9_max = 0;
2120 phba->ktime_seg9_min = 0xffffffff;
2121 phba->ktime_seg10_total = 0;
2122 phba->ktime_seg10_max = 0;
2123 phba->ktime_seg10_min = 0xffffffff;
2124 return strlen(pbuf);
2125 }
2126 return -EINVAL;
2127}
2128
2129static int
2130lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2131{
2132 struct lpfc_hba *phba = inode->i_private;
2133 struct lpfc_debug *debug;
2134 int rc = -ENOMEM;
2135
2136 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2137 if (!debug)
2138 goto out;
2139
2140 /* Round to page boundary */
2141 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2142 if (!debug->buffer) {
2143 kfree(debug);
2144 goto out;
2145 }
2146
2147 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2148 LPFC_NVMEIO_TRC_SIZE);
2149
2150 debug->i_private = inode->i_private;
2151 file->private_data = debug;
2152
2153 rc = 0;
2154out:
2155 return rc;
2156}
2157
2158static ssize_t
2159lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2160 size_t nbytes, loff_t *ppos)
2161{
2162 struct lpfc_debug *debug = file->private_data;
2163 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2164 int i;
2165 unsigned long sz;
2166 char mybuf[64];
2167 char *pbuf;
2168
2169 if (nbytes > 64)
2170 nbytes = 64;
2171
2172 /* Protect copy from user */
2173 if (!access_ok(VERIFY_READ, buf, nbytes))
2174 return -EFAULT;
2175
2176 memset(mybuf, 0, sizeof(mybuf));
2177
2178 if (copy_from_user(mybuf, buf, nbytes))
2179 return -EFAULT;
2180 pbuf = &mybuf[0];
2181
2182 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2184 "0570 nvmeio_trc_off\n");
2185 phba->nvmeio_trc_output_idx = 0;
2186 phba->nvmeio_trc_on = 0;
2187 return strlen(pbuf);
2188 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2189 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2190 "0571 nvmeio_trc_on\n");
2191 phba->nvmeio_trc_output_idx = 0;
2192 phba->nvmeio_trc_on = 1;
2193 return strlen(pbuf);
2194 }
2195
2196 /* We must be off to allocate the trace buffer */
2197 if (phba->nvmeio_trc_on != 0)
2198 return -EINVAL;
2199
2200 /* If not on or off, the parameter is the trace buffer size */
2201 i = kstrtoul(pbuf, 0, &sz);
2202 if (i)
2203 return -EINVAL;
2204 phba->nvmeio_trc_size = (uint32_t)sz;
2205
2206 /* It must be a power of 2 - round down */
2207 i = 0;
2208 while (sz > 1) {
2209 sz = sz >> 1;
2210 i++;
2211 }
2212 sz = (1 << i);
2213 if (phba->nvmeio_trc_size != sz)
2214 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2215 "0572 nvmeio_trc_size changed to %ld\n",
2216 sz);
2217 phba->nvmeio_trc_size = (uint32_t)sz;
2218
2219 /* If one previously exists, free it */
2220 kfree(phba->nvmeio_trc);
2221
2222 /* Allocate new trace buffer and initialize */
2223 phba->nvmeio_trc = kmalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
2224 sz), GFP_KERNEL);
2225 if (!phba->nvmeio_trc) {
2226 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2227 "0573 Cannot create debugfs "
2228 "nvmeio_trc buffer\n");
2229 return -ENOMEM;
2230 }
2231 memset(phba->nvmeio_trc, 0,
2232 (sizeof(struct lpfc_debugfs_nvmeio_trc) * sz));
2233 atomic_set(&phba->nvmeio_trc_cnt, 0);
2234 phba->nvmeio_trc_on = 0;
2235 phba->nvmeio_trc_output_idx = 0;
2236
2237 return strlen(pbuf);
2238}
2239
2240static int
2241lpfc_debugfs_cpucheck_open(struct inode *inode, struct file *file)
2242{
2243 struct lpfc_vport *vport = inode->i_private;
2244 struct lpfc_debug *debug;
2245 int rc = -ENOMEM;
2246
2247 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2248 if (!debug)
2249 goto out;
2250
2251 /* Round to page boundary */
2252 debug->buffer = kmalloc(LPFC_CPUCHECK_SIZE, GFP_KERNEL);
2253 if (!debug->buffer) {
2254 kfree(debug);
2255 goto out;
2256 }
2257
2258 debug->len = lpfc_debugfs_cpucheck_data(vport, debug->buffer,
2259 LPFC_NVMEKTIME_SIZE);
2260
2261 debug->i_private = inode->i_private;
2262 file->private_data = debug;
2263
2264 rc = 0;
2265out:
2266 return rc;
2267}
2268
2269static ssize_t
2270lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf,
2271 size_t nbytes, loff_t *ppos)
2272{
2273 struct lpfc_debug *debug = file->private_data;
2274 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2275 struct lpfc_hba *phba = vport->phba;
2276 char mybuf[64];
2277 char *pbuf;
2278 int i;
2279
2280 if (nbytes > 64)
2281 nbytes = 64;
2282
2283 /* Protect copy from user */
2284 if (!access_ok(VERIFY_READ, buf, nbytes))
2285 return -EFAULT;
2286
2287 memset(mybuf, 0, sizeof(mybuf));
2288
2289 if (copy_from_user(mybuf, buf, nbytes))
2290 return -EFAULT;
2291 pbuf = &mybuf[0];
2292
2293 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2b65e182
JS
2294 if (phba->nvmet_support)
2295 phba->cpucheck_on |= LPFC_CHECK_NVMET_IO;
2296 else
2297 phba->cpucheck_on |= LPFC_CHECK_NVME_IO;
bd2cdd5e
JS
2298 return strlen(pbuf);
2299 } else if ((strncmp(pbuf, "rcv",
2300 sizeof("rcv") - 1) == 0)) {
f358dd0c
JS
2301 if (phba->nvmet_support)
2302 phba->cpucheck_on |= LPFC_CHECK_NVMET_RCV;
2303 else
2304 return -EINVAL;
2305 return strlen(pbuf);
bd2cdd5e
JS
2306 } else if ((strncmp(pbuf, "off",
2307 sizeof("off") - 1) == 0)) {
2308 phba->cpucheck_on = LPFC_CHECK_OFF;
2309 return strlen(pbuf);
2310 } else if ((strncmp(pbuf, "zero",
2311 sizeof("zero") - 1) == 0)) {
2312 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
2313 if (i >= LPFC_CHECK_CPU_CNT)
2314 break;
2315 phba->cpucheck_rcv_io[i] = 0;
2316 phba->cpucheck_xmt_io[i] = 0;
2317 phba->cpucheck_cmpl_io[i] = 0;
2318 phba->cpucheck_ccmpl_io[i] = 0;
2319 }
2320 return strlen(pbuf);
2321 }
2322 return -EINVAL;
2323}
2324
2a622bfb 2325/*
86a80846 2326 * ---------------------------------
2a622bfb 2327 * iDiag debugfs file access methods
86a80846 2328 * ---------------------------------
2a622bfb 2329 *
86a80846
JS
2330 * All access methods are through the proper SLI4 PCI function's debugfs
2331 * iDiag directory:
2a622bfb 2332 *
86a80846 2333 * /sys/kernel/debug/lpfc/fn<#>/iDiag
2a622bfb
JS
2334 */
2335
2336/**
2337 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
2338 * @buf: The pointer to the user space buffer.
2339 * @nbytes: The number of bytes in the user space buffer.
2340 * @idiag_cmd: pointer to the idiag command struct.
2341 *
2342 * This routine reads data from debugfs user space buffer and parses the
2343 * buffer for getting the idiag command and arguments. The while space in
2344 * between the set of data is used as the parsing separator.
2345 *
2346 * This routine returns 0 when successful, it returns proper error code
2347 * back to the user space in error conditions.
2348 */
2349static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
2350 struct lpfc_idiag_cmd *idiag_cmd)
2351{
2352 char mybuf[64];
2353 char *pbuf, *step_str;
b11d48e8
SB
2354 int i;
2355 size_t bsize;
2a622bfb
JS
2356
2357 /* Protect copy from user */
2358 if (!access_ok(VERIFY_READ, buf, nbytes))
2359 return -EFAULT;
2360
2361 memset(mybuf, 0, sizeof(mybuf));
2362 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
2363 bsize = min(nbytes, (sizeof(mybuf)-1));
2364
2365 if (copy_from_user(mybuf, buf, bsize))
2366 return -EFAULT;
2367 pbuf = &mybuf[0];
2368 step_str = strsep(&pbuf, "\t ");
2369
2370 /* The opcode must present */
2371 if (!step_str)
2372 return -EINVAL;
2373
2374 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
2375 if (idiag_cmd->opcode == 0)
2376 return -EINVAL;
2377
2378 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
2379 step_str = strsep(&pbuf, "\t ");
2380 if (!step_str)
86a80846 2381 return i;
2a622bfb
JS
2382 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
2383 }
86a80846 2384 return i;
2a622bfb
JS
2385}
2386
2387/**
2388 * lpfc_idiag_open - idiag open debugfs
2389 * @inode: The inode pointer that contains a pointer to phba.
2390 * @file: The file pointer to attach the file operation.
2391 *
2392 * Description:
2393 * This routine is the entry point for the debugfs open file operation. It
2394 * gets the reference to phba from the i_private field in @inode, it then
2395 * allocates buffer for the file operation, performs the necessary PCI config
2396 * space read into the allocated buffer according to the idiag user command
2397 * setup, and then returns a pointer to buffer in the private_data field in
2398 * @file.
2399 *
2400 * Returns:
2401 * This function returns zero if successful. On error it will return an
2402 * negative error value.
2403 **/
2404static int
2405lpfc_idiag_open(struct inode *inode, struct file *file)
2406{
2407 struct lpfc_debug *debug;
2408
2409 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2410 if (!debug)
2411 return -ENOMEM;
2412
2413 debug->i_private = inode->i_private;
2414 debug->buffer = NULL;
2415 file->private_data = debug;
2416
2417 return 0;
2418}
2419
2420/**
2421 * lpfc_idiag_release - Release idiag access file operation
2422 * @inode: The inode pointer that contains a vport pointer. (unused)
2423 * @file: The file pointer that contains the buffer to release.
2424 *
2425 * Description:
2426 * This routine is the generic release routine for the idiag access file
2427 * operation, it frees the buffer that was allocated when the debugfs file
2428 * was opened.
2429 *
2430 * Returns:
2431 * This function returns zero.
2432 **/
2433static int
2434lpfc_idiag_release(struct inode *inode, struct file *file)
2435{
2436 struct lpfc_debug *debug = file->private_data;
2437
2438 /* Free the buffers to the file operation */
2439 kfree(debug->buffer);
2440 kfree(debug);
2441
2442 return 0;
2443}
2444
2445/**
2446 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
2447 * @inode: The inode pointer that contains a vport pointer. (unused)
2448 * @file: The file pointer that contains the buffer to release.
2449 *
2450 * Description:
2451 * This routine frees the buffer that was allocated when the debugfs file
2452 * was opened. It also reset the fields in the idiag command struct in the
86a80846 2453 * case of command for write operation.
2a622bfb
JS
2454 *
2455 * Returns:
2456 * This function returns zero.
2457 **/
2458static int
2459lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
2460{
2461 struct lpfc_debug *debug = file->private_data;
2462
86a80846
JS
2463 if (debug->op == LPFC_IDIAG_OP_WR) {
2464 switch (idiag.cmd.opcode) {
2465 case LPFC_IDIAG_CMD_PCICFG_WR:
2466 case LPFC_IDIAG_CMD_PCICFG_ST:
2467 case LPFC_IDIAG_CMD_PCICFG_CL:
2468 case LPFC_IDIAG_CMD_QUEACC_WR:
2469 case LPFC_IDIAG_CMD_QUEACC_ST:
2470 case LPFC_IDIAG_CMD_QUEACC_CL:
2a622bfb 2471 memset(&idiag, 0, sizeof(idiag));
86a80846
JS
2472 break;
2473 default:
2474 break;
2475 }
2476 }
2a622bfb
JS
2477
2478 /* Free the buffers to the file operation */
2479 kfree(debug->buffer);
2480 kfree(debug);
2481
2482 return 0;
2483}
2484
2485/**
2486 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
2487 * @file: The file pointer to read from.
2488 * @buf: The buffer to copy the data to.
2489 * @nbytes: The number of bytes to read.
2490 * @ppos: The position in the file to start reading from.
2491 *
2492 * Description:
2493 * This routine reads data from the @phba pci config space according to the
2494 * idiag command, and copies to user @buf. Depending on the PCI config space
2495 * read command setup, it does either a single register read of a byte
2496 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
2497 * registers from the 4K extended PCI config space.
2498 *
2499 * Returns:
2500 * This function returns the amount of data that was read (this could be less
2501 * than @nbytes if the end of the file was reached) or a negative error value.
2502 **/
2503static ssize_t
2504lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
2505 loff_t *ppos)
2506{
2507 struct lpfc_debug *debug = file->private_data;
2508 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2509 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
2510 int where, count;
2511 char *pbuffer;
2512 struct pci_dev *pdev;
2513 uint32_t u32val;
2514 uint16_t u16val;
2515 uint8_t u8val;
2516
2517 pdev = phba->pcidev;
2518 if (!pdev)
2519 return 0;
2520
2521 /* This is a user read operation */
2522 debug->op = LPFC_IDIAG_OP_RD;
2523
2524 if (!debug->buffer)
2525 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
2526 if (!debug->buffer)
2527 return 0;
2528 pbuffer = debug->buffer;
2529
2530 if (*ppos)
2531 return 0;
2532
2533 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
b76f2dc9
JS
2534 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2535 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2a622bfb
JS
2536 } else
2537 return 0;
2538
2539 /* Read single PCI config space register */
2540 switch (count) {
2541 case SIZE_U8: /* byte (8 bits) */
2542 pci_read_config_byte(pdev, where, &u8val);
2543 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2544 "%03x: %02x\n", where, u8val);
2545 break;
2546 case SIZE_U16: /* word (16 bits) */
2547 pci_read_config_word(pdev, where, &u16val);
2548 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2549 "%03x: %04x\n", where, u16val);
2550 break;
2551 case SIZE_U32: /* double word (32 bits) */
2552 pci_read_config_dword(pdev, where, &u32val);
2553 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2554 "%03x: %08x\n", where, u32val);
2555 break;
86a80846 2556 case LPFC_PCI_CFG_BROWSE: /* browse all */
2a622bfb
JS
2557 goto pcicfg_browse;
2558 break;
2559 default:
2560 /* illegal count */
2561 len = 0;
2562 break;
2563 }
2564 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2565
2566pcicfg_browse:
2567
2568 /* Browse all PCI config space registers */
2569 offset_label = idiag.offset.last_rd;
2570 offset = offset_label;
2571
2572 /* Read PCI config space */
2573 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2574 "%03x: ", offset_label);
2575 while (index > 0) {
2576 pci_read_config_dword(pdev, offset, &u32val);
2577 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2578 "%08x ", u32val);
2579 offset += sizeof(uint32_t);
b76f2dc9
JS
2580 if (offset >= LPFC_PCI_CFG_SIZE) {
2581 len += snprintf(pbuffer+len,
2582 LPFC_PCI_CFG_SIZE-len, "\n");
2583 break;
2584 }
2a622bfb
JS
2585 index -= sizeof(uint32_t);
2586 if (!index)
2587 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2588 "\n");
2589 else if (!(index % (8 * sizeof(uint32_t)))) {
2590 offset_label += (8 * sizeof(uint32_t));
2591 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
2592 "\n%03x: ", offset_label);
2593 }
2594 }
2595
2596 /* Set up the offset for next portion of pci cfg read */
b76f2dc9
JS
2597 if (index == 0) {
2598 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
2599 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
2600 idiag.offset.last_rd = 0;
2601 } else
2a622bfb
JS
2602 idiag.offset.last_rd = 0;
2603
2604 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2605}
2606
2607/**
2608 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
2609 * @file: The file pointer to read from.
2610 * @buf: The buffer to copy the user data from.
2611 * @nbytes: The number of bytes to get.
2612 * @ppos: The position in the file to start reading from.
2613 *
2614 * This routine get the debugfs idiag command struct from user space and
2615 * then perform the syntax check for PCI config space read or write command
2616 * accordingly. In the case of PCI config space read command, it sets up
2617 * the command in the idiag command struct for the debugfs read operation.
2618 * In the case of PCI config space write operation, it executes the write
2619 * operation into the PCI config space accordingly.
2620 *
2621 * It returns the @nbytges passing in from debugfs user space when successful.
2622 * In case of error conditions, it returns proper error code back to the user
2623 * space.
2624 */
2625static ssize_t
2626lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
2627 size_t nbytes, loff_t *ppos)
2628{
2629 struct lpfc_debug *debug = file->private_data;
2630 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2631 uint32_t where, value, count;
2632 uint32_t u32val;
2633 uint16_t u16val;
2634 uint8_t u8val;
2635 struct pci_dev *pdev;
2636 int rc;
2637
2638 pdev = phba->pcidev;
2639 if (!pdev)
2640 return -EFAULT;
2641
2642 /* This is a user write operation */
2643 debug->op = LPFC_IDIAG_OP_WR;
2644
2645 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
86a80846 2646 if (rc < 0)
2a622bfb
JS
2647 return rc;
2648
2649 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
86a80846
JS
2650 /* Sanity check on PCI config read command line arguments */
2651 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
2652 goto error_out;
2a622bfb 2653 /* Read command from PCI config space, set up command fields */
b76f2dc9
JS
2654 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2655 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
86a80846
JS
2656 if (count == LPFC_PCI_CFG_BROWSE) {
2657 if (where % sizeof(uint32_t))
2a622bfb 2658 goto error_out;
86a80846
JS
2659 /* Starting offset to browse */
2660 idiag.offset.last_rd = where;
2a622bfb
JS
2661 } else if ((count != sizeof(uint8_t)) &&
2662 (count != sizeof(uint16_t)) &&
2663 (count != sizeof(uint32_t)))
2664 goto error_out;
2665 if (count == sizeof(uint8_t)) {
2666 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2667 goto error_out;
2668 if (where % sizeof(uint8_t))
2669 goto error_out;
2670 }
2671 if (count == sizeof(uint16_t)) {
2672 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2673 goto error_out;
2674 if (where % sizeof(uint16_t))
2675 goto error_out;
2676 }
2677 if (count == sizeof(uint32_t)) {
2678 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2679 goto error_out;
2680 if (where % sizeof(uint32_t))
2681 goto error_out;
2682 }
2683 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
2684 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
2685 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
86a80846
JS
2686 /* Sanity check on PCI config write command line arguments */
2687 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
2688 goto error_out;
2a622bfb 2689 /* Write command to PCI config space, read-modify-write */
b76f2dc9
JS
2690 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
2691 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
2692 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
2a622bfb
JS
2693 /* Sanity checks */
2694 if ((count != sizeof(uint8_t)) &&
2695 (count != sizeof(uint16_t)) &&
2696 (count != sizeof(uint32_t)))
2697 goto error_out;
2698 if (count == sizeof(uint8_t)) {
2699 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
2700 goto error_out;
2701 if (where % sizeof(uint8_t))
2702 goto error_out;
2703 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2704 pci_write_config_byte(pdev, where,
2705 (uint8_t)value);
2706 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2707 rc = pci_read_config_byte(pdev, where, &u8val);
2708 if (!rc) {
2709 u8val |= (uint8_t)value;
2710 pci_write_config_byte(pdev, where,
2711 u8val);
2712 }
2713 }
2714 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2715 rc = pci_read_config_byte(pdev, where, &u8val);
2716 if (!rc) {
2717 u8val &= (uint8_t)(~value);
2718 pci_write_config_byte(pdev, where,
2719 u8val);
2720 }
2721 }
2722 }
2723 if (count == sizeof(uint16_t)) {
2724 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
2725 goto error_out;
2726 if (where % sizeof(uint16_t))
2727 goto error_out;
2728 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2729 pci_write_config_word(pdev, where,
2730 (uint16_t)value);
2731 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2732 rc = pci_read_config_word(pdev, where, &u16val);
2733 if (!rc) {
2734 u16val |= (uint16_t)value;
2735 pci_write_config_word(pdev, where,
2736 u16val);
2737 }
2738 }
2739 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2740 rc = pci_read_config_word(pdev, where, &u16val);
2741 if (!rc) {
2742 u16val &= (uint16_t)(~value);
2743 pci_write_config_word(pdev, where,
2744 u16val);
2745 }
2746 }
2747 }
2748 if (count == sizeof(uint32_t)) {
2749 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
2750 goto error_out;
2751 if (where % sizeof(uint32_t))
2752 goto error_out;
2753 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
2754 pci_write_config_dword(pdev, where, value);
2755 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
2756 rc = pci_read_config_dword(pdev, where,
2757 &u32val);
2758 if (!rc) {
2759 u32val |= value;
2760 pci_write_config_dword(pdev, where,
2761 u32val);
2762 }
2763 }
2764 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
2765 rc = pci_read_config_dword(pdev, where,
2766 &u32val);
2767 if (!rc) {
2768 u32val &= ~value;
2769 pci_write_config_dword(pdev, where,
2770 u32val);
2771 }
2772 }
2773 }
2774 } else
2775 /* All other opecodes are illegal for now */
2776 goto error_out;
2777
2778 return nbytes;
2779error_out:
2780 memset(&idiag, 0, sizeof(idiag));
2781 return -EINVAL;
2782}
2783
b76f2dc9
JS
2784/**
2785 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
2786 * @file: The file pointer to read from.
2787 * @buf: The buffer to copy the data to.
2788 * @nbytes: The number of bytes to read.
2789 * @ppos: The position in the file to start reading from.
2790 *
2791 * Description:
2792 * This routine reads data from the @phba pci bar memory mapped space
2793 * according to the idiag command, and copies to user @buf.
2794 *
2795 * Returns:
2796 * This function returns the amount of data that was read (this could be less
2797 * than @nbytes if the end of the file was reached) or a negative error value.
2798 **/
2799static ssize_t
2800lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
2801 loff_t *ppos)
2802{
2803 struct lpfc_debug *debug = file->private_data;
2804 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2805 int offset_label, offset, offset_run, len = 0, index;
2806 int bar_num, acc_range, bar_size;
2807 char *pbuffer;
2808 void __iomem *mem_mapped_bar;
2809 uint32_t if_type;
2810 struct pci_dev *pdev;
2811 uint32_t u32val;
2812
2813 pdev = phba->pcidev;
2814 if (!pdev)
2815 return 0;
2816
2817 /* This is a user read operation */
2818 debug->op = LPFC_IDIAG_OP_RD;
2819
2820 if (!debug->buffer)
2821 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
2822 if (!debug->buffer)
2823 return 0;
2824 pbuffer = debug->buffer;
2825
2826 if (*ppos)
2827 return 0;
2828
2829 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
2830 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2831 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
2832 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
2833 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
2834 } else
2835 return 0;
2836
2837 if (acc_range == 0)
2838 return 0;
2839
2840 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2841 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2842 if (bar_num == IDIAG_BARACC_BAR_0)
2843 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2844 else if (bar_num == IDIAG_BARACC_BAR_1)
2845 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2846 else if (bar_num == IDIAG_BARACC_BAR_2)
2847 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
2848 else
2849 return 0;
2850 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2851 if (bar_num == IDIAG_BARACC_BAR_0)
2852 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2853 else
2854 return 0;
2855 } else
2856 return 0;
2857
2858 /* Read single PCI bar space register */
2859 if (acc_range == SINGLE_WORD) {
2860 offset_run = offset;
2861 u32val = readl(mem_mapped_bar + offset_run);
2862 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2863 "%05x: %08x\n", offset_run, u32val);
2864 } else
2865 goto baracc_browse;
2866
2867 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2868
2869baracc_browse:
2870
2871 /* Browse all PCI bar space registers */
2872 offset_label = idiag.offset.last_rd;
2873 offset_run = offset_label;
2874
2875 /* Read PCI bar memory mapped space */
2876 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2877 "%05x: ", offset_label);
2878 index = LPFC_PCI_BAR_RD_SIZE;
2879 while (index > 0) {
2880 u32val = readl(mem_mapped_bar + offset_run);
2881 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
2882 "%08x ", u32val);
2883 offset_run += sizeof(uint32_t);
2884 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2885 if (offset_run >= bar_size) {
2886 len += snprintf(pbuffer+len,
2887 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2888 break;
2889 }
2890 } else {
2891 if (offset_run >= offset +
2892 (acc_range * sizeof(uint32_t))) {
2893 len += snprintf(pbuffer+len,
2894 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2895 break;
2896 }
2897 }
2898 index -= sizeof(uint32_t);
2899 if (!index)
2900 len += snprintf(pbuffer+len,
2901 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
2902 else if (!(index % (8 * sizeof(uint32_t)))) {
2903 offset_label += (8 * sizeof(uint32_t));
2904 len += snprintf(pbuffer+len,
2905 LPFC_PCI_BAR_RD_BUF_SIZE-len,
2906 "\n%05x: ", offset_label);
2907 }
2908 }
2909
2910 /* Set up the offset for next portion of pci bar read */
2911 if (index == 0) {
2912 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
2913 if (acc_range == LPFC_PCI_BAR_BROWSE) {
2914 if (idiag.offset.last_rd >= bar_size)
2915 idiag.offset.last_rd = 0;
2916 } else {
2917 if (offset_run >= offset +
2918 (acc_range * sizeof(uint32_t)))
2919 idiag.offset.last_rd = offset;
2920 }
2921 } else {
2922 if (acc_range == LPFC_PCI_BAR_BROWSE)
2923 idiag.offset.last_rd = 0;
2924 else
2925 idiag.offset.last_rd = offset;
2926 }
2927
2928 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2929}
2930
2931/**
2932 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
2933 * @file: The file pointer to read from.
2934 * @buf: The buffer to copy the user data from.
2935 * @nbytes: The number of bytes to get.
2936 * @ppos: The position in the file to start reading from.
2937 *
2938 * This routine get the debugfs idiag command struct from user space and
2939 * then perform the syntax check for PCI bar memory mapped space read or
2940 * write command accordingly. In the case of PCI bar memory mapped space
2941 * read command, it sets up the command in the idiag command struct for
2942 * the debugfs read operation. In the case of PCI bar memorpy mapped space
2943 * write operation, it executes the write operation into the PCI bar memory
2944 * mapped space accordingly.
2945 *
2946 * It returns the @nbytges passing in from debugfs user space when successful.
2947 * In case of error conditions, it returns proper error code back to the user
2948 * space.
2949 */
2950static ssize_t
2951lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
2952 size_t nbytes, loff_t *ppos)
2953{
2954 struct lpfc_debug *debug = file->private_data;
2955 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2956 uint32_t bar_num, bar_size, offset, value, acc_range;
2957 struct pci_dev *pdev;
2958 void __iomem *mem_mapped_bar;
2959 uint32_t if_type;
2960 uint32_t u32val;
2961 int rc;
2962
2963 pdev = phba->pcidev;
2964 if (!pdev)
2965 return -EFAULT;
2966
2967 /* This is a user write operation */
2968 debug->op = LPFC_IDIAG_OP_WR;
2969
2970 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2971 if (rc < 0)
2972 return rc;
2973
2974 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2975 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
2976
2977 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2978 if ((bar_num != IDIAG_BARACC_BAR_0) &&
2979 (bar_num != IDIAG_BARACC_BAR_1) &&
2980 (bar_num != IDIAG_BARACC_BAR_2))
2981 goto error_out;
2982 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
2983 if (bar_num != IDIAG_BARACC_BAR_0)
2984 goto error_out;
2985 } else
2986 goto error_out;
2987
2988 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
2989 if (bar_num == IDIAG_BARACC_BAR_0) {
2990 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2991 LPFC_PCI_IF0_BAR0_SIZE;
2992 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
2993 } else if (bar_num == IDIAG_BARACC_BAR_1) {
2994 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2995 LPFC_PCI_IF0_BAR1_SIZE;
2996 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
2997 } else if (bar_num == IDIAG_BARACC_BAR_2) {
2998 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
2999 LPFC_PCI_IF0_BAR2_SIZE;
3000 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3001 } else
3002 goto error_out;
3003 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3004 if (bar_num == IDIAG_BARACC_BAR_0) {
3005 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3006 LPFC_PCI_IF2_BAR0_SIZE;
3007 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3008 } else
3009 goto error_out;
3010 } else
3011 goto error_out;
3012
3013 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3014 if (offset % sizeof(uint32_t))
3015 goto error_out;
3016
3017 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3018 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3019 /* Sanity check on PCI config read command line arguments */
3020 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3021 goto error_out;
3022 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3023 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3024 if (offset > bar_size - sizeof(uint32_t))
3025 goto error_out;
3026 /* Starting offset to browse */
3027 idiag.offset.last_rd = offset;
3028 } else if (acc_range > SINGLE_WORD) {
3029 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3030 goto error_out;
3031 /* Starting offset to browse */
3032 idiag.offset.last_rd = offset;
3033 } else if (acc_range != SINGLE_WORD)
3034 goto error_out;
3035 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3036 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3037 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3038 /* Sanity check on PCI bar write command line arguments */
3039 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3040 goto error_out;
3041 /* Write command to PCI bar space, read-modify-write */
3042 acc_range = SINGLE_WORD;
3043 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3044 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3045 writel(value, mem_mapped_bar + offset);
3046 readl(mem_mapped_bar + offset);
3047 }
3048 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3049 u32val = readl(mem_mapped_bar + offset);
3050 u32val |= value;
3051 writel(u32val, mem_mapped_bar + offset);
3052 readl(mem_mapped_bar + offset);
3053 }
3054 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3055 u32val = readl(mem_mapped_bar + offset);
3056 u32val &= ~value;
3057 writel(u32val, mem_mapped_bar + offset);
3058 readl(mem_mapped_bar + offset);
3059 }
3060 } else
3061 /* All other opecodes are illegal for now */
3062 goto error_out;
3063
3064 return nbytes;
3065error_out:
3066 memset(&idiag, 0, sizeof(idiag));
3067 return -EINVAL;
3068}
3069
07bcd98e
JS
3070static int
3071__lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3072 char *pbuffer, int len)
3073{
3074 if (!qp)
3075 return len;
3076
3077 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3078 "\t\t%s WQ info: ", wqtype);
3079 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3080 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3081 qp->assoc_qid, qp->q_cnt_1,
3082 (unsigned long long)qp->q_cnt_4);
3083 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
7869da18
JS
3084 "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3085 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
07bcd98e
JS
3086 qp->queue_id, qp->entry_count,
3087 qp->entry_size, qp->host_index,
7869da18 3088 qp->hba_index, qp->entry_repost);
07bcd98e
JS
3089 len += snprintf(pbuffer + len,
3090 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3091 return len;
3092}
3093
3094static int
3095lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3096 int *len, int max_cnt, int cq_id)
3097{
3098 struct lpfc_queue *qp;
3099 int qidx;
3100
3101 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3102 qp = phba->sli4_hba.fcp_wq[qidx];
3103 if (qp->assoc_qid != cq_id)
3104 continue;
3105 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3106 if (*len >= max_cnt)
3107 return 1;
3108 }
895427bd
JS
3109 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3110 qp = phba->sli4_hba.nvme_wq[qidx];
3111 if (qp->assoc_qid != cq_id)
3112 continue;
3113 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3114 if (*len >= max_cnt)
3115 return 1;
3116 }
07bcd98e
JS
3117 return 0;
3118}
3119
3120static int
3121__lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3122 char *pbuffer, int len)
3123{
3124 if (!qp)
3125 return len;
3126
3127 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3128 "\t%s CQ info: ", cqtype);
3129 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3130 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3131 "xabt:x%x wq:x%llx]\n",
3132 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3133 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3134 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
7869da18
JS
3135 "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3136 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
07bcd98e
JS
3137 qp->queue_id, qp->entry_count,
3138 qp->entry_size, qp->host_index,
7869da18 3139 qp->hba_index, qp->entry_repost);
07bcd98e
JS
3140
3141 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3142
3143 return len;
3144}
3145
3146static int
3147__lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3148 char *rqtype, char *pbuffer, int len)
3149{
3150 if (!qp || !datqp)
3151 return len;
3152
3153 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3154 "\t\t%s RQ info: ", rqtype);
3155 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3156 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
547077a4 3157 "posted:x%x rcv:x%llx]\n",
07bcd98e
JS
3158 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3159 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
3160 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
7869da18
JS
3161 "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3162 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
07bcd98e 3163 qp->queue_id, qp->entry_count, qp->entry_size,
7869da18 3164 qp->host_index, qp->hba_index, qp->entry_repost);
07bcd98e 3165 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
7869da18
JS
3166 "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3167 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]\n",
07bcd98e
JS
3168 datqp->queue_id, datqp->entry_count,
3169 datqp->entry_size, datqp->host_index,
7869da18 3170 datqp->hba_index, datqp->entry_repost);
07bcd98e
JS
3171 return len;
3172}
3173
3174static int
3175lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
2d7dbc4c 3176 int *len, int max_cnt, int eqidx, int eq_id)
07bcd98e
JS
3177{
3178 struct lpfc_queue *qp;
3179 int qidx, rc;
3180
3181 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
3182 qp = phba->sli4_hba.fcp_cq[qidx];
3183 if (qp->assoc_qid != eq_id)
3184 continue;
3185
3186 *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len);
3187
3188 /* Reset max counter */
3189 qp->CQ_max_cqe = 0;
3190
3191 if (*len >= max_cnt)
3192 return 1;
3193
3194 rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len,
3195 max_cnt, qp->queue_id);
3196 if (rc)
3197 return 1;
3198 }
3199
895427bd
JS
3200 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
3201 qp = phba->sli4_hba.nvme_cq[qidx];
3202 if (qp->assoc_qid != eq_id)
3203 continue;
3204
3205 *len = __lpfc_idiag_print_cq(qp, "NVME", pbuffer, *len);
3206
3207 /* Reset max counter */
3208 qp->CQ_max_cqe = 0;
3209
3210 if (*len >= max_cnt)
3211 return 1;
3212
3213 rc = lpfc_idiag_wqs_for_cq(phba, "NVME", pbuffer, len,
3214 max_cnt, qp->queue_id);
3215 if (rc)
3216 return 1;
3217 }
3218
2b65e182 3219 if (eqidx < phba->cfg_nvmet_mrq) {
2d7dbc4c
JS
3220 /* NVMET CQset */
3221 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3222 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3223
3224 /* Reset max counter */
3225 qp->CQ_max_cqe = 0;
3226
3227 if (*len >= max_cnt)
3228 return 1;
3229
3230 /* RQ header */
3231 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3232 *len = __lpfc_idiag_print_rqpair(qp,
3233 phba->sli4_hba.nvmet_mrq_data[eqidx],
3234 "NVMET MRQ", pbuffer, *len);
3235
3236 if (*len >= max_cnt)
3237 return 1;
3238 }
3239
07bcd98e
JS
3240 return 0;
3241}
3242
3243static int
3244__lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
3245 char *pbuffer, int len)
3246{
3247 if (!qp)
3248 return len;
3249
3250 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3251 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
3252 "bs:x%x proc:x%llx]\n",
3253 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
3254 (unsigned long long)qp->q_cnt_4);
3255 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
7869da18
JS
3256 "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
3257 "HST-IDX[%04d], PRT-IDX[%04d], PST[%03d]",
07bcd98e 3258 qp->queue_id, qp->entry_count, qp->entry_size,
7869da18 3259 qp->host_index, qp->hba_index, qp->entry_repost);
07bcd98e
JS
3260 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3261
3262 return len;
3263}
3264
2a622bfb
JS
3265/**
3266 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
3267 * @file: The file pointer to read from.
3268 * @buf: The buffer to copy the data to.
3269 * @nbytes: The number of bytes to read.
3270 * @ppos: The position in the file to start reading from.
3271 *
3272 * Description:
3273 * This routine reads data from the @phba SLI4 PCI function queue information,
3274 * and copies to user @buf.
07bcd98e
JS
3275 * This routine only returns 1 EQs worth of information. It remembers the last
3276 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
3277 * retrieve all EQs allocated for the phba.
2a622bfb
JS
3278 *
3279 * Returns:
3280 * This function returns the amount of data that was read (this could be less
3281 * than @nbytes if the end of the file was reached) or a negative error value.
3282 **/
3283static ssize_t
3284lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
3285 loff_t *ppos)
3286{
3287 struct lpfc_debug *debug = file->private_data;
3288 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2a622bfb 3289 char *pbuffer;
07bcd98e 3290 int max_cnt, rc, x, len = 0;
c85a65ac
JS
3291 struct lpfc_queue *qp = NULL;
3292
2a622bfb
JS
3293 if (!debug->buffer)
3294 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
3295 if (!debug->buffer)
3296 return 0;
3297 pbuffer = debug->buffer;
07bcd98e 3298 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
2a622bfb
JS
3299
3300 if (*ppos)
3301 return 0;
3302
c85a65ac
JS
3303 spin_lock_irq(&phba->hbalock);
3304
3305 /* Fast-path event queue */
895427bd 3306 if (phba->sli4_hba.hba_eq && phba->io_channel_irqs) {
c85a65ac 3307
07bcd98e 3308 x = phba->lpfc_idiag_last_eq;
895427bd 3309 if (phba->cfg_fof && (x >= phba->io_channel_irqs)) {
07bcd98e
JS
3310 phba->lpfc_idiag_last_eq = 0;
3311 goto fof;
3312 }
3313 phba->lpfc_idiag_last_eq++;
895427bd 3314 if (phba->lpfc_idiag_last_eq >= phba->io_channel_irqs)
07bcd98e
JS
3315 if (phba->cfg_fof == 0)
3316 phba->lpfc_idiag_last_eq = 0;
c85a65ac 3317
07bcd98e
JS
3318 len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3319 "EQ %d out of %d HBA EQs\n",
895427bd 3320 x, phba->io_channel_irqs);
c85a65ac 3321
07bcd98e
JS
3322 /* Fast-path EQ */
3323 qp = phba->sli4_hba.hba_eq[x];
3324 if (!qp)
3325 goto out;
c85a65ac 3326
07bcd98e 3327 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
c85a65ac 3328
07bcd98e
JS
3329 /* Reset max counter */
3330 qp->EQ_max_eqe = 0;
c85a65ac 3331
07bcd98e
JS
3332 if (len >= max_cnt)
3333 goto too_big;
c85a65ac 3334
895427bd 3335 /* will dump both fcp and nvme cqs/wqs for the eq */
07bcd98e 3336 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
2d7dbc4c 3337 max_cnt, x, qp->queue_id);
07bcd98e
JS
3338 if (rc)
3339 goto too_big;
c85a65ac 3340
07bcd98e
JS
3341 /* Only EQ 0 has slow path CQs configured */
3342 if (x)
3343 goto out;
c85a65ac 3344
07bcd98e
JS
3345 /* Slow-path mailbox CQ */
3346 qp = phba->sli4_hba.mbx_cq;
3347 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
3348 if (len >= max_cnt)
3349 goto too_big;
2a622bfb 3350
07bcd98e
JS
3351 /* Slow-path MBOX MQ */
3352 qp = phba->sli4_hba.mbx_wq;
3353 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
3354 if (len >= max_cnt)
3355 goto too_big;
2a622bfb 3356
07bcd98e
JS
3357 /* Slow-path ELS response CQ */
3358 qp = phba->sli4_hba.els_cq;
3359 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
3360 /* Reset max counter */
3361 if (qp)
3362 qp->CQ_max_cqe = 0;
3363 if (len >= max_cnt)
3364 goto too_big;
2a622bfb 3365
07bcd98e
JS
3366 /* Slow-path ELS WQ */
3367 qp = phba->sli4_hba.els_wq;
3368 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
3369 if (len >= max_cnt)
3370 goto too_big;
2a622bfb 3371
895427bd
JS
3372 /* Slow-path NVME LS response CQ */
3373 qp = phba->sli4_hba.nvmels_cq;
3374 len = __lpfc_idiag_print_cq(qp, "NVME LS",
3375 pbuffer, len);
3376 /* Reset max counter */
3377 if (qp)
3378 qp->CQ_max_cqe = 0;
3379 if (len >= max_cnt)
3380 goto too_big;
3381
3382 /* Slow-path NVME LS WQ */
3383 qp = phba->sli4_hba.nvmels_wq;
3384 len = __lpfc_idiag_print_wq(qp, "NVME LS",
3385 pbuffer, len);
3386 if (len >= max_cnt)
3387 goto too_big;
3388
07bcd98e
JS
3389 qp = phba->sli4_hba.hdr_rq;
3390 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
3391 "RQpair", pbuffer, len);
3392 if (len >= max_cnt)
3393 goto too_big;
2a622bfb 3394
07bcd98e 3395 goto out;
2a622bfb 3396 }
2a622bfb 3397
07bcd98e 3398fof:
1ba981fd
JS
3399 if (phba->cfg_fof) {
3400 /* FOF EQ */
3401 qp = phba->sli4_hba.fof_eq;
07bcd98e 3402 len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len);
1ba981fd
JS
3403
3404 /* Reset max counter */
07bcd98e
JS
3405 if (qp)
3406 qp->EQ_max_eqe = 0;
1ba981fd 3407
1ba981fd
JS
3408 if (len >= max_cnt)
3409 goto too_big;
1ba981fd
JS
3410
3411 /* OAS CQ */
3412 qp = phba->sli4_hba.oas_cq;
07bcd98e
JS
3413 len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len);
3414 /* Reset max counter */
3415 if (qp)
1ba981fd 3416 qp->CQ_max_cqe = 0;
07bcd98e
JS
3417 if (len >= max_cnt)
3418 goto too_big;
1ba981fd
JS
3419
3420 /* OAS WQ */
3421 qp = phba->sli4_hba.oas_wq;
07bcd98e
JS
3422 len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len);
3423 if (len >= max_cnt)
3424 goto too_big;
1ba981fd 3425 }
07bcd98e 3426
c85a65ac
JS
3427 spin_unlock_irq(&phba->hbalock);
3428 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3429
3430too_big:
07bcd98e
JS
3431 len += snprintf(pbuffer + len,
3432 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
3433out:
c85a65ac 3434 spin_unlock_irq(&phba->hbalock);
2a622bfb
JS
3435 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3436}
3437
86a80846
JS
3438/**
3439 * lpfc_idiag_que_param_check - queue access command parameter sanity check
3440 * @q: The pointer to queue structure.
3441 * @index: The index into a queue entry.
3442 * @count: The number of queue entries to access.
3443 *
3444 * Description:
3445 * The routine performs sanity check on device queue access method commands.
3446 *
3447 * Returns:
3448 * This function returns -EINVAL when fails the sanity check, otherwise, it
3449 * returns 0.
3450 **/
3451static int
3452lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
3453{
3454 /* Only support single entry read or browsing */
3455 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
3456 return -EINVAL;
3457 if (index > q->entry_count - 1)
3458 return -EINVAL;
3459 return 0;
3460}
3461
3462/**
3463 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
3464 * @pbuffer: The pointer to buffer to copy the read data into.
3465 * @pque: The pointer to the queue to be read.
3466 * @index: The index into the queue entry.
3467 *
3468 * Description:
3469 * This routine reads out a single entry from the given queue's index location
3470 * and copies it into the buffer provided.
3471 *
3472 * Returns:
3473 * This function returns 0 when it fails, otherwise, it returns the length of
3474 * the data read into the buffer provided.
3475 **/
3476static int
3477lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
3478 uint32_t index)
3479{
3480 int offset, esize;
3481 uint32_t *pentry;
3482
3483 if (!pbuffer || !pque)
3484 return 0;
3485
3486 esize = pque->entry_size;
3487 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3488 "QE-INDEX[%04d]:\n", index);
3489
3490 offset = 0;
3491 pentry = pque->qe[index].address;
3492 while (esize > 0) {
3493 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
3494 "%08x ", *pentry);
3495 pentry++;
3496 offset += sizeof(uint32_t);
3497 esize -= sizeof(uint32_t);
3498 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
3499 len += snprintf(pbuffer+len,
3500 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3501 }
3502 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
3503
3504 return len;
3505}
3506
3507/**
3508 * lpfc_idiag_queacc_read - idiag debugfs read port queue
3509 * @file: The file pointer to read from.
3510 * @buf: The buffer to copy the data to.
3511 * @nbytes: The number of bytes to read.
3512 * @ppos: The position in the file to start reading from.
3513 *
3514 * Description:
3515 * This routine reads data from the @phba device queue memory according to the
3516 * idiag command, and copies to user @buf. Depending on the queue dump read
3517 * command setup, it does either a single queue entry read or browing through
3518 * all entries of the queue.
3519 *
3520 * Returns:
3521 * This function returns the amount of data that was read (this could be less
3522 * than @nbytes if the end of the file was reached) or a negative error value.
3523 **/
3524static ssize_t
3525lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
3526 loff_t *ppos)
3527{
3528 struct lpfc_debug *debug = file->private_data;
3529 uint32_t last_index, index, count;
3530 struct lpfc_queue *pque = NULL;
3531 char *pbuffer;
3532 int len = 0;
3533
3534 /* This is a user read operation */
3535 debug->op = LPFC_IDIAG_OP_RD;
3536
3537 if (!debug->buffer)
3538 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
3539 if (!debug->buffer)
3540 return 0;
3541 pbuffer = debug->buffer;
3542
3543 if (*ppos)
3544 return 0;
3545
3546 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
b76f2dc9
JS
3547 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3548 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
86a80846
JS
3549 pque = (struct lpfc_queue *)idiag.ptr_private;
3550 } else
3551 return 0;
3552
3553 /* Browse the queue starting from index */
3554 if (count == LPFC_QUE_ACC_BROWSE)
3555 goto que_browse;
3556
3557 /* Read a single entry from the queue */
3558 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3559
3560 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3561
3562que_browse:
3563
3564 /* Browse all entries from the queue */
3565 last_index = idiag.offset.last_rd;
3566 index = last_index;
3567
3568 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
3569 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
3570 index++;
3571 if (index > pque->entry_count - 1)
3572 break;
3573 }
3574
3575 /* Set up the offset for next portion of pci cfg read */
3576 if (index > pque->entry_count - 1)
3577 index = 0;
3578 idiag.offset.last_rd = index;
3579
3580 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3581}
3582
3583/**
3584 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
3585 * @file: The file pointer to read from.
3586 * @buf: The buffer to copy the user data from.
3587 * @nbytes: The number of bytes to get.
3588 * @ppos: The position in the file to start reading from.
3589 *
3590 * This routine get the debugfs idiag command struct from user space and then
3591 * perform the syntax check for port queue read (dump) or write (set) command
3592 * accordingly. In the case of port queue read command, it sets up the command
3593 * in the idiag command struct for the following debugfs read operation. In
3594 * the case of port queue write operation, it executes the write operation
3595 * into the port queue entry accordingly.
3596 *
3597 * It returns the @nbytges passing in from debugfs user space when successful.
3598 * In case of error conditions, it returns proper error code back to the user
3599 * space.
3600 **/
3601static ssize_t
3602lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
3603 size_t nbytes, loff_t *ppos)
3604{
3605 struct lpfc_debug *debug = file->private_data;
3606 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3607 uint32_t qidx, quetp, queid, index, count, offset, value;
3608 uint32_t *pentry;
895427bd 3609 struct lpfc_queue *pque, *qp;
86a80846
JS
3610 int rc;
3611
3612 /* This is a user write operation */
3613 debug->op = LPFC_IDIAG_OP_WR;
3614
3615 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3616 if (rc < 0)
3617 return rc;
3618
3619 /* Get and sanity check on command feilds */
b76f2dc9
JS
3620 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
3621 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
3622 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
3623 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
3624 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
3625 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
86a80846
JS
3626
3627 /* Sanity check on command line arguments */
3628 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3629 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3630 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3631 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
3632 goto error_out;
3633 if (count != 1)
3634 goto error_out;
3635 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3636 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
3637 goto error_out;
3638 } else
3639 goto error_out;
3640
3641 switch (quetp) {
3642 case LPFC_IDIAG_EQ:
67d12733
JS
3643 /* HBA event queue */
3644 if (phba->sli4_hba.hba_eq) {
895427bd
JS
3645 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) {
3646 qp = phba->sli4_hba.hba_eq[qidx];
3647 if (qp && qp->queue_id == queid) {
2e90f4b5 3648 /* Sanity check */
895427bd 3649 rc = lpfc_idiag_que_param_check(qp,
86a80846 3650 index, count);
2e90f4b5
JS
3651 if (rc)
3652 goto error_out;
895427bd 3653 idiag.ptr_private = qp;
2e90f4b5
JS
3654 goto pass_check;
3655 }
86a80846
JS
3656 }
3657 }
3658 goto error_out;
3659 break;
3660 case LPFC_IDIAG_CQ:
3661 /* MBX complete queue */
2e90f4b5
JS
3662 if (phba->sli4_hba.mbx_cq &&
3663 phba->sli4_hba.mbx_cq->queue_id == queid) {
86a80846
JS
3664 /* Sanity check */
3665 rc = lpfc_idiag_que_param_check(
3666 phba->sli4_hba.mbx_cq, index, count);
3667 if (rc)
3668 goto error_out;
3669 idiag.ptr_private = phba->sli4_hba.mbx_cq;
3670 goto pass_check;
3671 }
3672 /* ELS complete queue */
2e90f4b5
JS
3673 if (phba->sli4_hba.els_cq &&
3674 phba->sli4_hba.els_cq->queue_id == queid) {
86a80846
JS
3675 /* Sanity check */
3676 rc = lpfc_idiag_que_param_check(
3677 phba->sli4_hba.els_cq, index, count);
3678 if (rc)
3679 goto error_out;
3680 idiag.ptr_private = phba->sli4_hba.els_cq;
3681 goto pass_check;
3682 }
895427bd
JS
3683 /* NVME LS complete queue */
3684 if (phba->sli4_hba.nvmels_cq &&
3685 phba->sli4_hba.nvmels_cq->queue_id == queid) {
3686 /* Sanity check */
3687 rc = lpfc_idiag_que_param_check(
3688 phba->sli4_hba.nvmels_cq, index, count);
3689 if (rc)
3690 goto error_out;
3691 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
3692 goto pass_check;
3693 }
86a80846 3694 /* FCP complete queue */
2e90f4b5 3695 if (phba->sli4_hba.fcp_cq) {
895427bd
JS
3696 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
3697 qidx++) {
3698 qp = phba->sli4_hba.fcp_cq[qidx];
3699 if (qp && qp->queue_id == queid) {
2e90f4b5
JS
3700 /* Sanity check */
3701 rc = lpfc_idiag_que_param_check(
895427bd 3702 qp, index, count);
2e90f4b5
JS
3703 if (rc)
3704 goto error_out;
895427bd 3705 idiag.ptr_private = qp;
2e90f4b5
JS
3706 goto pass_check;
3707 }
895427bd 3708 }
2e90f4b5 3709 }
bd2cdd5e
JS
3710 /* NVME complete queue */
3711 if (phba->sli4_hba.nvme_cq) {
3712 qidx = 0;
3713 do {
3714 if (phba->sli4_hba.nvme_cq[qidx] &&
3715 phba->sli4_hba.nvme_cq[qidx]->queue_id ==
3716 queid) {
3717 /* Sanity check */
3718 rc = lpfc_idiag_que_param_check(
3719 phba->sli4_hba.nvme_cq[qidx],
3720 index, count);
3721 if (rc)
3722 goto error_out;
3723 idiag.ptr_private =
3724 phba->sli4_hba.nvme_cq[qidx];
3725 goto pass_check;
3726 }
3727 } while (++qidx < phba->cfg_nvme_io_channel);
3728 }
86a80846
JS
3729 goto error_out;
3730 break;
3731 case LPFC_IDIAG_MQ:
3732 /* MBX work queue */
2e90f4b5
JS
3733 if (phba->sli4_hba.mbx_wq &&
3734 phba->sli4_hba.mbx_wq->queue_id == queid) {
86a80846
JS
3735 /* Sanity check */
3736 rc = lpfc_idiag_que_param_check(
3737 phba->sli4_hba.mbx_wq, index, count);
3738 if (rc)
3739 goto error_out;
3740 idiag.ptr_private = phba->sli4_hba.mbx_wq;
3741 goto pass_check;
3742 }
2e90f4b5 3743 goto error_out;
86a80846
JS
3744 break;
3745 case LPFC_IDIAG_WQ:
3746 /* ELS work queue */
2e90f4b5
JS
3747 if (phba->sli4_hba.els_wq &&
3748 phba->sli4_hba.els_wq->queue_id == queid) {
86a80846
JS
3749 /* Sanity check */
3750 rc = lpfc_idiag_que_param_check(
3751 phba->sli4_hba.els_wq, index, count);
3752 if (rc)
3753 goto error_out;
3754 idiag.ptr_private = phba->sli4_hba.els_wq;
3755 goto pass_check;
3756 }
895427bd
JS
3757 /* NVME LS work queue */
3758 if (phba->sli4_hba.nvmels_wq &&
3759 phba->sli4_hba.nvmels_wq->queue_id == queid) {
3760 /* Sanity check */
3761 rc = lpfc_idiag_que_param_check(
3762 phba->sli4_hba.nvmels_wq, index, count);
3763 if (rc)
3764 goto error_out;
3765 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
3766 goto pass_check;
3767 }
86a80846 3768 /* FCP work queue */
2e90f4b5 3769 if (phba->sli4_hba.fcp_wq) {
67d12733 3770 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
895427bd
JS
3771 qidx++) {
3772 qp = phba->sli4_hba.fcp_wq[qidx];
3773 if (qp && qp->queue_id == queid) {
2e90f4b5
JS
3774 /* Sanity check */
3775 rc = lpfc_idiag_que_param_check(
895427bd
JS
3776 qp, index, count);
3777 if (rc)
3778 goto error_out;
3779 idiag.ptr_private = qp;
3780 goto pass_check;
3781 }
3782 }
3783 }
3784 /* NVME work queue */
3785 if (phba->sli4_hba.nvme_wq) {
3786 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3787 qidx++) {
3788 qp = phba->sli4_hba.nvme_wq[qidx];
3789 if (qp && qp->queue_id == queid) {
3790 /* Sanity check */
3791 rc = lpfc_idiag_que_param_check(
3792 qp, index, count);
2e90f4b5
JS
3793 if (rc)
3794 goto error_out;
895427bd 3795 idiag.ptr_private = qp;
2e90f4b5
JS
3796 goto pass_check;
3797 }
86a80846
JS
3798 }
3799 }
bd2cdd5e
JS
3800
3801 /* NVME work queues */
3802 if (phba->sli4_hba.nvme_wq) {
3803 for (qidx = 0; qidx < phba->cfg_nvme_io_channel;
3804 qidx++) {
3805 if (!phba->sli4_hba.nvme_wq[qidx])
3806 continue;
3807 if (phba->sli4_hba.nvme_wq[qidx]->queue_id ==
3808 queid) {
3809 /* Sanity check */
3810 rc = lpfc_idiag_que_param_check(
3811 phba->sli4_hba.nvme_wq[qidx],
3812 index, count);
3813 if (rc)
3814 goto error_out;
3815 idiag.ptr_private =
3816 phba->sli4_hba.nvme_wq[qidx];
3817 goto pass_check;
3818 }
3819 }
3820 }
86a80846
JS
3821 goto error_out;
3822 break;
3823 case LPFC_IDIAG_RQ:
3824 /* HDR queue */
2e90f4b5
JS
3825 if (phba->sli4_hba.hdr_rq &&
3826 phba->sli4_hba.hdr_rq->queue_id == queid) {
86a80846
JS
3827 /* Sanity check */
3828 rc = lpfc_idiag_que_param_check(
3829 phba->sli4_hba.hdr_rq, index, count);
3830 if (rc)
3831 goto error_out;
3832 idiag.ptr_private = phba->sli4_hba.hdr_rq;
3833 goto pass_check;
3834 }
3835 /* DAT queue */
2e90f4b5
JS
3836 if (phba->sli4_hba.dat_rq &&
3837 phba->sli4_hba.dat_rq->queue_id == queid) {
86a80846
JS
3838 /* Sanity check */
3839 rc = lpfc_idiag_que_param_check(
3840 phba->sli4_hba.dat_rq, index, count);
3841 if (rc)
3842 goto error_out;
3843 idiag.ptr_private = phba->sli4_hba.dat_rq;
3844 goto pass_check;
3845 }
3846 goto error_out;
3847 break;
3848 default:
3849 goto error_out;
3850 break;
3851 }
3852
3853pass_check:
3854
3855 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
3856 if (count == LPFC_QUE_ACC_BROWSE)
3857 idiag.offset.last_rd = index;
3858 }
3859
3860 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
3861 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
3862 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
3863 /* Additional sanity checks on write operation */
3864 pque = (struct lpfc_queue *)idiag.ptr_private;
3865 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
3866 goto error_out;
3867 pentry = pque->qe[index].address;
3868 pentry += offset;
3869 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
3870 *pentry = value;
3871 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
3872 *pentry |= value;
3873 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
3874 *pentry &= ~value;
3875 }
3876 return nbytes;
3877
3878error_out:
3879 /* Clean out command structure on command error out */
3880 memset(&idiag, 0, sizeof(idiag));
3881 return -EINVAL;
3882}
3883
3884/**
3885 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
3886 * @phba: The pointer to hba structure.
3887 * @pbuffer: The pointer to the buffer to copy the data to.
3888 * @len: The lenght of bytes to copied.
3889 * @drbregid: The id to doorbell registers.
3890 *
3891 * Description:
3892 * This routine reads a doorbell register and copies its content to the
3893 * user buffer pointed to by @pbuffer.
3894 *
3895 * Returns:
3896 * This function returns the amount of data that was copied into @pbuffer.
3897 **/
3898static int
3899lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
3900 int len, uint32_t drbregid)
3901{
3902
3903 if (!pbuffer)
3904 return 0;
3905
3906 switch (drbregid) {
3907 case LPFC_DRB_EQCQ:
3908 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3909 "EQCQ-DRB-REG: 0x%08x\n",
3910 readl(phba->sli4_hba.EQCQDBregaddr));
3911 break;
3912 case LPFC_DRB_MQ:
3913 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3914 "MQ-DRB-REG: 0x%08x\n",
3915 readl(phba->sli4_hba.MQDBregaddr));
3916 break;
3917 case LPFC_DRB_WQ:
3918 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3919 "WQ-DRB-REG: 0x%08x\n",
3920 readl(phba->sli4_hba.WQDBregaddr));
3921 break;
3922 case LPFC_DRB_RQ:
3923 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
3924 "RQ-DRB-REG: 0x%08x\n",
3925 readl(phba->sli4_hba.RQDBregaddr));
3926 break;
3927 default:
3928 break;
3929 }
3930
3931 return len;
3932}
3933
3934/**
3935 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
3936 * @file: The file pointer to read from.
3937 * @buf: The buffer to copy the data to.
3938 * @nbytes: The number of bytes to read.
3939 * @ppos: The position in the file to start reading from.
3940 *
3941 * Description:
3942 * This routine reads data from the @phba device doorbell register according
3943 * to the idiag command, and copies to user @buf. Depending on the doorbell
3944 * register read command setup, it does either a single doorbell register
3945 * read or dump all doorbell registers.
3946 *
3947 * Returns:
3948 * This function returns the amount of data that was read (this could be less
3949 * than @nbytes if the end of the file was reached) or a negative error value.
3950 **/
3951static ssize_t
3952lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
3953 loff_t *ppos)
3954{
3955 struct lpfc_debug *debug = file->private_data;
3956 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3957 uint32_t drb_reg_id, i;
3958 char *pbuffer;
3959 int len = 0;
3960
3961 /* This is a user read operation */
3962 debug->op = LPFC_IDIAG_OP_RD;
3963
3964 if (!debug->buffer)
3965 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
3966 if (!debug->buffer)
3967 return 0;
3968 pbuffer = debug->buffer;
3969
3970 if (*ppos)
3971 return 0;
3972
3973 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
b76f2dc9 3974 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
86a80846
JS
3975 else
3976 return 0;
3977
3978 if (drb_reg_id == LPFC_DRB_ACC_ALL)
3979 for (i = 1; i <= LPFC_DRB_MAX; i++)
3980 len = lpfc_idiag_drbacc_read_reg(phba,
3981 pbuffer, len, i);
3982 else
3983 len = lpfc_idiag_drbacc_read_reg(phba,
3984 pbuffer, len, drb_reg_id);
3985
3986 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3987}
3988
3989/**
3990 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
3991 * @file: The file pointer to read from.
3992 * @buf: The buffer to copy the user data from.
3993 * @nbytes: The number of bytes to get.
3994 * @ppos: The position in the file to start reading from.
3995 *
3996 * This routine get the debugfs idiag command struct from user space and then
3997 * perform the syntax check for port doorbell register read (dump) or write
3998 * (set) command accordingly. In the case of port queue read command, it sets
3999 * up the command in the idiag command struct for the following debugfs read
4000 * operation. In the case of port doorbell register write operation, it
4001 * executes the write operation into the port doorbell register accordingly.
4002 *
4003 * It returns the @nbytges passing in from debugfs user space when successful.
4004 * In case of error conditions, it returns proper error code back to the user
4005 * space.
4006 **/
4007static ssize_t
4008lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4009 size_t nbytes, loff_t *ppos)
4010{
4011 struct lpfc_debug *debug = file->private_data;
4012 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
b76f2dc9 4013 uint32_t drb_reg_id, value, reg_val = 0;
86a80846
JS
4014 void __iomem *drb_reg;
4015 int rc;
4016
4017 /* This is a user write operation */
4018 debug->op = LPFC_IDIAG_OP_WR;
4019
4020 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4021 if (rc < 0)
4022 return rc;
4023
4024 /* Sanity check on command line arguments */
b76f2dc9
JS
4025 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4026 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
86a80846
JS
4027
4028 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4029 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4030 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4031 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4032 goto error_out;
4033 if (drb_reg_id > LPFC_DRB_MAX)
4034 goto error_out;
4035 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4036 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4037 goto error_out;
4038 if ((drb_reg_id > LPFC_DRB_MAX) &&
4039 (drb_reg_id != LPFC_DRB_ACC_ALL))
4040 goto error_out;
4041 } else
4042 goto error_out;
4043
4044 /* Perform the write access operation */
4045 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4046 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4047 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4048 switch (drb_reg_id) {
4049 case LPFC_DRB_EQCQ:
4050 drb_reg = phba->sli4_hba.EQCQDBregaddr;
4051 break;
4052 case LPFC_DRB_MQ:
4053 drb_reg = phba->sli4_hba.MQDBregaddr;
4054 break;
4055 case LPFC_DRB_WQ:
4056 drb_reg = phba->sli4_hba.WQDBregaddr;
4057 break;
4058 case LPFC_DRB_RQ:
4059 drb_reg = phba->sli4_hba.RQDBregaddr;
4060 break;
4061 default:
4062 goto error_out;
4063 }
4064
4065 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4066 reg_val = value;
4067 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4068 reg_val = readl(drb_reg);
4069 reg_val |= value;
4070 }
4071 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4072 reg_val = readl(drb_reg);
4073 reg_val &= ~value;
4074 }
4075 writel(reg_val, drb_reg);
4076 readl(drb_reg); /* flush */
4077 }
4078 return nbytes;
4079
4080error_out:
4081 /* Clean out command structure on command error out */
4082 memset(&idiag, 0, sizeof(idiag));
4083 return -EINVAL;
4084}
4085
b76f2dc9
JS
4086/**
4087 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4088 * @phba: The pointer to hba structure.
4089 * @pbuffer: The pointer to the buffer to copy the data to.
4090 * @len: The lenght of bytes to copied.
4091 * @drbregid: The id to doorbell registers.
4092 *
4093 * Description:
4094 * This routine reads a control register and copies its content to the
4095 * user buffer pointed to by @pbuffer.
4096 *
4097 * Returns:
4098 * This function returns the amount of data that was copied into @pbuffer.
4099 **/
4100static int
4101lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4102 int len, uint32_t ctlregid)
4103{
858c9f6c 4104
b76f2dc9
JS
4105 if (!pbuffer)
4106 return 0;
858c9f6c 4107
b76f2dc9
JS
4108 switch (ctlregid) {
4109 case LPFC_CTL_PORT_SEM:
4110 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4111 "Port SemReg: 0x%08x\n",
4112 readl(phba->sli4_hba.conf_regs_memmap_p +
4113 LPFC_CTL_PORT_SEM_OFFSET));
4114 break;
4115 case LPFC_CTL_PORT_STA:
4116 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4117 "Port StaReg: 0x%08x\n",
4118 readl(phba->sli4_hba.conf_regs_memmap_p +
4119 LPFC_CTL_PORT_STA_OFFSET));
4120 break;
4121 case LPFC_CTL_PORT_CTL:
4122 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4123 "Port CtlReg: 0x%08x\n",
4124 readl(phba->sli4_hba.conf_regs_memmap_p +
4125 LPFC_CTL_PORT_CTL_OFFSET));
4126 break;
4127 case LPFC_CTL_PORT_ER1:
4128 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4129 "Port Er1Reg: 0x%08x\n",
4130 readl(phba->sli4_hba.conf_regs_memmap_p +
4131 LPFC_CTL_PORT_ER1_OFFSET));
4132 break;
4133 case LPFC_CTL_PORT_ER2:
4134 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4135 "Port Er2Reg: 0x%08x\n",
4136 readl(phba->sli4_hba.conf_regs_memmap_p +
4137 LPFC_CTL_PORT_ER2_OFFSET));
4138 break;
4139 case LPFC_CTL_PDEV_CTL:
4140 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
4141 "PDev CtlReg: 0x%08x\n",
4142 readl(phba->sli4_hba.conf_regs_memmap_p +
4143 LPFC_CTL_PDEV_CTL_OFFSET));
4144 break;
4145 default:
4146 break;
4147 }
4148 return len;
4149}
78b2d852 4150
b76f2dc9
JS
4151/**
4152 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4153 * @file: The file pointer to read from.
4154 * @buf: The buffer to copy the data to.
4155 * @nbytes: The number of bytes to read.
4156 * @ppos: The position in the file to start reading from.
4157 *
4158 * Description:
4159 * This routine reads data from the @phba port and device registers according
4160 * to the idiag command, and copies to user @buf.
4161 *
4162 * Returns:
4163 * This function returns the amount of data that was read (this could be less
4164 * than @nbytes if the end of the file was reached) or a negative error value.
4165 **/
4166static ssize_t
4167lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4168 loff_t *ppos)
4169{
4170 struct lpfc_debug *debug = file->private_data;
4171 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4172 uint32_t ctl_reg_id, i;
4173 char *pbuffer;
4174 int len = 0;
c95d6c6c 4175
b76f2dc9
JS
4176 /* This is a user read operation */
4177 debug->op = LPFC_IDIAG_OP_RD;
a58cbd52 4178
b76f2dc9
JS
4179 if (!debug->buffer)
4180 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4181 if (!debug->buffer)
4182 return 0;
4183 pbuffer = debug->buffer;
e2a0a9d6 4184
b76f2dc9
JS
4185 if (*ppos)
4186 return 0;
4187
4188 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4189 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4190 else
4191 return 0;
4192
4193 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4194 for (i = 1; i <= LPFC_CTL_MAX; i++)
4195 len = lpfc_idiag_ctlacc_read_reg(phba,
4196 pbuffer, len, i);
4197 else
4198 len = lpfc_idiag_ctlacc_read_reg(phba,
4199 pbuffer, len, ctl_reg_id);
4200
4201 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4202}
4203
4204/**
4205 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4206 * @file: The file pointer to read from.
4207 * @buf: The buffer to copy the user data from.
4208 * @nbytes: The number of bytes to get.
4209 * @ppos: The position in the file to start reading from.
4210 *
4211 * This routine get the debugfs idiag command struct from user space and then
4212 * perform the syntax check for port and device control register read (dump)
4213 * or write (set) command accordingly.
4214 *
4215 * It returns the @nbytges passing in from debugfs user space when successful.
4216 * In case of error conditions, it returns proper error code back to the user
4217 * space.
4218 **/
4219static ssize_t
4220lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4221 size_t nbytes, loff_t *ppos)
4222{
4223 struct lpfc_debug *debug = file->private_data;
4224 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4225 uint32_t ctl_reg_id, value, reg_val = 0;
4226 void __iomem *ctl_reg;
4227 int rc;
4228
4229 /* This is a user write operation */
4230 debug->op = LPFC_IDIAG_OP_WR;
4231
4232 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4233 if (rc < 0)
4234 return rc;
4235
4236 /* Sanity check on command line arguments */
4237 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4238 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4239
4240 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4241 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4242 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4243 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4244 goto error_out;
4245 if (ctl_reg_id > LPFC_CTL_MAX)
4246 goto error_out;
4247 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4248 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4249 goto error_out;
4250 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4251 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4252 goto error_out;
4253 } else
4254 goto error_out;
4255
4256 /* Perform the write access operation */
4257 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4258 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4259 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4260 switch (ctl_reg_id) {
4261 case LPFC_CTL_PORT_SEM:
4262 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4263 LPFC_CTL_PORT_SEM_OFFSET;
4264 break;
4265 case LPFC_CTL_PORT_STA:
4266 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4267 LPFC_CTL_PORT_STA_OFFSET;
4268 break;
4269 case LPFC_CTL_PORT_CTL:
4270 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4271 LPFC_CTL_PORT_CTL_OFFSET;
4272 break;
4273 case LPFC_CTL_PORT_ER1:
4274 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4275 LPFC_CTL_PORT_ER1_OFFSET;
4276 break;
4277 case LPFC_CTL_PORT_ER2:
4278 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4279 LPFC_CTL_PORT_ER2_OFFSET;
4280 break;
4281 case LPFC_CTL_PDEV_CTL:
4282 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4283 LPFC_CTL_PDEV_CTL_OFFSET;
4284 break;
4285 default:
4286 goto error_out;
4287 }
4288
4289 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4290 reg_val = value;
4291 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4292 reg_val = readl(ctl_reg);
4293 reg_val |= value;
4294 }
4295 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4296 reg_val = readl(ctl_reg);
4297 reg_val &= ~value;
4298 }
4299 writel(reg_val, ctl_reg);
4300 readl(ctl_reg); /* flush */
4301 }
4302 return nbytes;
4303
4304error_out:
4305 /* Clean out command structure on command error out */
4306 memset(&idiag, 0, sizeof(idiag));
4307 return -EINVAL;
4308}
4309
4310/**
4311 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4312 * @phba: Pointer to HBA context object.
4313 * @pbuffer: Pointer to data buffer.
4314 *
4315 * Description:
4316 * This routine gets the driver mailbox access debugfs setup information.
4317 *
4318 * Returns:
4319 * This function returns the amount of data that was read (this could be less
4320 * than @nbytes if the end of the file was reached) or a negative error value.
4321 **/
4322static int
4323lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
4324{
4325 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4326 int len = 0;
4327
4328 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4329 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4330 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4331 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4332
4333 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4334 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
4335 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4336 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
4337 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4338 "mbx_word_cnt: %04d\n", mbx_word_cnt);
4339 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
4340 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
4341
4342 return len;
4343}
4344
4345/**
4346 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
4347 * @file: The file pointer to read from.
4348 * @buf: The buffer to copy the data to.
4349 * @nbytes: The number of bytes to read.
4350 * @ppos: The position in the file to start reading from.
4351 *
4352 * Description:
4353 * This routine reads data from the @phba driver mailbox access debugfs setup
4354 * information.
4355 *
4356 * Returns:
4357 * This function returns the amount of data that was read (this could be less
4358 * than @nbytes if the end of the file was reached) or a negative error value.
4359 **/
4360static ssize_t
4361lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
4362 loff_t *ppos)
4363{
4364 struct lpfc_debug *debug = file->private_data;
4365 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4366 char *pbuffer;
4367 int len = 0;
4368
4369 /* This is a user read operation */
4370 debug->op = LPFC_IDIAG_OP_RD;
4371
4372 if (!debug->buffer)
4373 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
4374 if (!debug->buffer)
4375 return 0;
4376 pbuffer = debug->buffer;
4377
4378 if (*ppos)
4379 return 0;
4380
4381 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
4382 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
4383 return 0;
4384
4385 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
4386
4387 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4388}
4389
4390/**
4391 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
4392 * @file: The file pointer to read from.
4393 * @buf: The buffer to copy the user data from.
4394 * @nbytes: The number of bytes to get.
4395 * @ppos: The position in the file to start reading from.
4396 *
4397 * This routine get the debugfs idiag command struct from user space and then
4398 * perform the syntax check for driver mailbox command (dump) and sets up the
4399 * necessary states in the idiag command struct accordingly.
4400 *
4401 * It returns the @nbytges passing in from debugfs user space when successful.
4402 * In case of error conditions, it returns proper error code back to the user
4403 * space.
4404 **/
4405static ssize_t
4406lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
4407 size_t nbytes, loff_t *ppos)
4408{
4409 struct lpfc_debug *debug = file->private_data;
4410 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4411 int rc;
4412
4413 /* This is a user write operation */
4414 debug->op = LPFC_IDIAG_OP_WR;
4415
4416 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4417 if (rc < 0)
4418 return rc;
4419
4420 /* Sanity check on command line arguments */
4421 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4422 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4423 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4424 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4425
4426 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
4427 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
4428 goto error_out;
4429 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
4430 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4431 goto error_out;
4432 if (mbx_word_cnt > sizeof(MAILBOX_t))
4433 goto error_out;
4434 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
4435 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
4436 goto error_out;
4437 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
4438 (mbx_dump_map != LPFC_MBX_DMP_ALL))
4439 goto error_out;
4440 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
4441 goto error_out;
4442 if (mbx_mbox_cmd != 0x9b)
4443 goto error_out;
4444 } else
4445 goto error_out;
4446
4447 if (mbx_word_cnt == 0)
4448 goto error_out;
4449 if (rc != LPFC_MBX_DMP_ARG)
4450 goto error_out;
4451 if (mbx_mbox_cmd & ~0xff)
4452 goto error_out;
4453
4454 /* condition for stop mailbox dump */
4455 if (mbx_dump_cnt == 0)
4456 goto reset_out;
4457
4458 return nbytes;
4459
4460reset_out:
4461 /* Clean out command structure on command error out */
4462 memset(&idiag, 0, sizeof(idiag));
4463 return nbytes;
4464
4465error_out:
4466 /* Clean out command structure on command error out */
4467 memset(&idiag, 0, sizeof(idiag));
4468 return -EINVAL;
4469}
4470
4471/**
4472 * lpfc_idiag_extacc_avail_get - get the available extents information
4473 * @phba: pointer to lpfc hba data structure.
4474 * @pbuffer: pointer to internal buffer.
4475 * @len: length into the internal buffer data has been copied.
4476 *
4477 * Description:
4478 * This routine is to get the available extent information.
4479 *
4480 * Returns:
4481 * overall lenth of the data read into the internal buffer.
4482 **/
4483static int
4484lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
4485{
4486 uint16_t ext_cnt, ext_size;
4487
4488 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4489 "\nAvailable Extents Information:\n");
4490
4491 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4492 "\tPort Available VPI extents: ");
4493 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
4494 &ext_cnt, &ext_size);
4495 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4496 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4497
4498 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4499 "\tPort Available VFI extents: ");
4500 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
4501 &ext_cnt, &ext_size);
4502 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4503 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4504
4505 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4506 "\tPort Available RPI extents: ");
4507 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
4508 &ext_cnt, &ext_size);
4509 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4510 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4511
4512 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4513 "\tPort Available XRI extents: ");
4514 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
4515 &ext_cnt, &ext_size);
4516 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4517 "Count %3d, Size %3d\n", ext_cnt, ext_size);
4518
4519 return len;
4520}
4521
4522/**
4523 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
4524 * @phba: pointer to lpfc hba data structure.
4525 * @pbuffer: pointer to internal buffer.
4526 * @len: length into the internal buffer data has been copied.
4527 *
4528 * Description:
4529 * This routine is to get the allocated extent information.
4530 *
4531 * Returns:
4532 * overall lenth of the data read into the internal buffer.
4533 **/
4534static int
4535lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
4536{
4537 uint16_t ext_cnt, ext_size;
4538 int rc;
4539
4540 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4541 "\nAllocated Extents Information:\n");
4542
4543 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4544 "\tHost Allocated VPI extents: ");
4545 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
4546 &ext_cnt, &ext_size);
4547 if (!rc)
4548 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4549 "Port %d Extent %3d, Size %3d\n",
4550 phba->brd_no, ext_cnt, ext_size);
4551 else
4552 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4553 "N/A\n");
4554
4555 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4556 "\tHost Allocated VFI extents: ");
4557 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
4558 &ext_cnt, &ext_size);
4559 if (!rc)
4560 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4561 "Port %d Extent %3d, Size %3d\n",
4562 phba->brd_no, ext_cnt, ext_size);
4563 else
4564 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4565 "N/A\n");
4566
4567 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4568 "\tHost Allocated RPI extents: ");
4569 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
4570 &ext_cnt, &ext_size);
4571 if (!rc)
4572 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4573 "Port %d Extent %3d, Size %3d\n",
4574 phba->brd_no, ext_cnt, ext_size);
4575 else
4576 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4577 "N/A\n");
4578
4579 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4580 "\tHost Allocated XRI extents: ");
4581 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
4582 &ext_cnt, &ext_size);
4583 if (!rc)
4584 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4585 "Port %d Extent %3d, Size %3d\n",
4586 phba->brd_no, ext_cnt, ext_size);
4587 else
4588 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4589 "N/A\n");
4590
4591 return len;
4592}
4593
4594/**
4595 * lpfc_idiag_extacc_drivr_get - get driver extent information
4596 * @phba: pointer to lpfc hba data structure.
4597 * @pbuffer: pointer to internal buffer.
4598 * @len: length into the internal buffer data has been copied.
4599 *
4600 * Description:
4601 * This routine is to get the driver extent information.
4602 *
4603 * Returns:
4604 * overall lenth of the data read into the internal buffer.
4605 **/
4606static int
4607lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
4608{
4609 struct lpfc_rsrc_blks *rsrc_blks;
4610 int index;
4611
4612 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4613 "\nDriver Extents Information:\n");
4614
4615 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4616 "\tVPI extents:\n");
4617 index = 0;
4618 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
4619 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4620 "\t\tBlock %3d: Start %4d, Count %4d\n",
4621 index, rsrc_blks->rsrc_start,
4622 rsrc_blks->rsrc_size);
4623 index++;
4624 }
4625 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4626 "\tVFI extents:\n");
4627 index = 0;
4628 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
4629 list) {
4630 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4631 "\t\tBlock %3d: Start %4d, Count %4d\n",
4632 index, rsrc_blks->rsrc_start,
4633 rsrc_blks->rsrc_size);
4634 index++;
4635 }
4636
4637 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4638 "\tRPI extents:\n");
4639 index = 0;
4640 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
4641 list) {
4642 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4643 "\t\tBlock %3d: Start %4d, Count %4d\n",
4644 index, rsrc_blks->rsrc_start,
4645 rsrc_blks->rsrc_size);
4646 index++;
4647 }
4648
4649 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4650 "\tXRI extents:\n");
4651 index = 0;
4652 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
4653 list) {
4654 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
4655 "\t\tBlock %3d: Start %4d, Count %4d\n",
4656 index, rsrc_blks->rsrc_start,
4657 rsrc_blks->rsrc_size);
4658 index++;
4659 }
4660
4661 return len;
4662}
4663
4664/**
4665 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
4666 * @file: The file pointer to read from.
4667 * @buf: The buffer to copy the user data from.
4668 * @nbytes: The number of bytes to get.
4669 * @ppos: The position in the file to start reading from.
4670 *
4671 * This routine get the debugfs idiag command struct from user space and then
4672 * perform the syntax check for extent information access commands and sets
4673 * up the necessary states in the idiag command struct accordingly.
4674 *
4675 * It returns the @nbytges passing in from debugfs user space when successful.
4676 * In case of error conditions, it returns proper error code back to the user
4677 * space.
4678 **/
4679static ssize_t
4680lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
4681 size_t nbytes, loff_t *ppos)
4682{
4683 struct lpfc_debug *debug = file->private_data;
4684 uint32_t ext_map;
4685 int rc;
4686
4687 /* This is a user write operation */
4688 debug->op = LPFC_IDIAG_OP_WR;
4689
4690 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4691 if (rc < 0)
4692 return rc;
4693
4694 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4695
4696 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4697 goto error_out;
4698 if (rc != LPFC_EXT_ACC_CMD_ARG)
4699 goto error_out;
4700 if (!(ext_map & LPFC_EXT_ACC_ALL))
4701 goto error_out;
4702
4703 return nbytes;
4704error_out:
4705 /* Clean out command structure on command error out */
4706 memset(&idiag, 0, sizeof(idiag));
4707 return -EINVAL;
4708}
4709
4710/**
4711 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
4712 * @file: The file pointer to read from.
4713 * @buf: The buffer to copy the data to.
4714 * @nbytes: The number of bytes to read.
4715 * @ppos: The position in the file to start reading from.
4716 *
4717 * Description:
4718 * This routine reads data from the proper extent information according to
4719 * the idiag command, and copies to user @buf.
4720 *
4721 * Returns:
4722 * This function returns the amount of data that was read (this could be less
4723 * than @nbytes if the end of the file was reached) or a negative error value.
4724 **/
4725static ssize_t
4726lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
4727 loff_t *ppos)
4728{
4729 struct lpfc_debug *debug = file->private_data;
4730 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4731 char *pbuffer;
4732 uint32_t ext_map;
4733 int len = 0;
4734
4735 /* This is a user read operation */
4736 debug->op = LPFC_IDIAG_OP_RD;
4737
4738 if (!debug->buffer)
4739 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
4740 if (!debug->buffer)
4741 return 0;
4742 pbuffer = debug->buffer;
4743 if (*ppos)
4744 return 0;
4745 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
4746 return 0;
4747
4748 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
4749 if (ext_map & LPFC_EXT_ACC_AVAIL)
4750 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
4751 if (ext_map & LPFC_EXT_ACC_ALLOC)
4752 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
4753 if (ext_map & LPFC_EXT_ACC_DRIVR)
4754 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
4755
4756 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4757}
4758
4759#undef lpfc_debugfs_op_disc_trc
4760static const struct file_operations lpfc_debugfs_op_disc_trc = {
4761 .owner = THIS_MODULE,
4762 .open = lpfc_debugfs_disc_trc_open,
4763 .llseek = lpfc_debugfs_lseek,
4764 .read = lpfc_debugfs_read,
4765 .release = lpfc_debugfs_release,
4766};
4767
4768#undef lpfc_debugfs_op_nodelist
4769static const struct file_operations lpfc_debugfs_op_nodelist = {
4770 .owner = THIS_MODULE,
4771 .open = lpfc_debugfs_nodelist_open,
4772 .llseek = lpfc_debugfs_lseek,
4773 .read = lpfc_debugfs_read,
4774 .release = lpfc_debugfs_release,
4775};
4776
4777#undef lpfc_debugfs_op_hbqinfo
4778static const struct file_operations lpfc_debugfs_op_hbqinfo = {
4779 .owner = THIS_MODULE,
4780 .open = lpfc_debugfs_hbqinfo_open,
4781 .llseek = lpfc_debugfs_lseek,
4782 .read = lpfc_debugfs_read,
4783 .release = lpfc_debugfs_release,
4784};
4785
4786#undef lpfc_debugfs_op_dumpHBASlim
4787static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
4788 .owner = THIS_MODULE,
4789 .open = lpfc_debugfs_dumpHBASlim_open,
4790 .llseek = lpfc_debugfs_lseek,
4791 .read = lpfc_debugfs_read,
4792 .release = lpfc_debugfs_release,
4793};
4794
4795#undef lpfc_debugfs_op_dumpHostSlim
4796static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
4797 .owner = THIS_MODULE,
4798 .open = lpfc_debugfs_dumpHostSlim_open,
4799 .llseek = lpfc_debugfs_lseek,
4800 .read = lpfc_debugfs_read,
4801 .release = lpfc_debugfs_release,
4802};
4803
bd2cdd5e
JS
4804#undef lpfc_debugfs_op_nvmestat
4805static const struct file_operations lpfc_debugfs_op_nvmestat = {
4806 .owner = THIS_MODULE,
4807 .open = lpfc_debugfs_nvmestat_open,
4808 .llseek = lpfc_debugfs_lseek,
4809 .read = lpfc_debugfs_read,
2b65e182 4810 .write = lpfc_debugfs_nvmestat_write,
bd2cdd5e
JS
4811 .release = lpfc_debugfs_release,
4812};
4813
4814#undef lpfc_debugfs_op_nvmektime
4815static const struct file_operations lpfc_debugfs_op_nvmektime = {
4816 .owner = THIS_MODULE,
4817 .open = lpfc_debugfs_nvmektime_open,
4818 .llseek = lpfc_debugfs_lseek,
4819 .read = lpfc_debugfs_read,
4820 .write = lpfc_debugfs_nvmektime_write,
4821 .release = lpfc_debugfs_release,
4822};
4823
4824#undef lpfc_debugfs_op_nvmeio_trc
4825static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
4826 .owner = THIS_MODULE,
4827 .open = lpfc_debugfs_nvmeio_trc_open,
4828 .llseek = lpfc_debugfs_lseek,
4829 .read = lpfc_debugfs_read,
4830 .write = lpfc_debugfs_nvmeio_trc_write,
4831 .release = lpfc_debugfs_release,
4832};
4833
4834#undef lpfc_debugfs_op_cpucheck
4835static const struct file_operations lpfc_debugfs_op_cpucheck = {
4836 .owner = THIS_MODULE,
4837 .open = lpfc_debugfs_cpucheck_open,
4838 .llseek = lpfc_debugfs_lseek,
4839 .read = lpfc_debugfs_read,
4840 .write = lpfc_debugfs_cpucheck_write,
4841 .release = lpfc_debugfs_release,
4842};
4843
b76f2dc9
JS
4844#undef lpfc_debugfs_op_dumpData
4845static const struct file_operations lpfc_debugfs_op_dumpData = {
4846 .owner = THIS_MODULE,
4847 .open = lpfc_debugfs_dumpData_open,
4848 .llseek = lpfc_debugfs_lseek,
4849 .read = lpfc_debugfs_read,
4850 .write = lpfc_debugfs_dumpDataDif_write,
4851 .release = lpfc_debugfs_dumpDataDif_release,
4852};
4853
4854#undef lpfc_debugfs_op_dumpDif
4855static const struct file_operations lpfc_debugfs_op_dumpDif = {
e2a0a9d6
JS
4856 .owner = THIS_MODULE,
4857 .open = lpfc_debugfs_dumpDif_open,
4858 .llseek = lpfc_debugfs_lseek,
4859 .read = lpfc_debugfs_read,
4860 .write = lpfc_debugfs_dumpDataDif_write,
4861 .release = lpfc_debugfs_dumpDataDif_release,
4862};
4863
f9bb2da1
JS
4864#undef lpfc_debugfs_op_dif_err
4865static const struct file_operations lpfc_debugfs_op_dif_err = {
4866 .owner = THIS_MODULE,
234e3405 4867 .open = simple_open,
f9bb2da1
JS
4868 .llseek = lpfc_debugfs_lseek,
4869 .read = lpfc_debugfs_dif_err_read,
4870 .write = lpfc_debugfs_dif_err_write,
4871 .release = lpfc_debugfs_dif_err_release,
4872};
4873
a58cbd52 4874#undef lpfc_debugfs_op_slow_ring_trc
71fa7421 4875static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
a58cbd52
JS
4876 .owner = THIS_MODULE,
4877 .open = lpfc_debugfs_slow_ring_trc_open,
4878 .llseek = lpfc_debugfs_lseek,
4879 .read = lpfc_debugfs_read,
4880 .release = lpfc_debugfs_release,
4881};
4882
858c9f6c
JS
4883static struct dentry *lpfc_debugfs_root = NULL;
4884static atomic_t lpfc_debugfs_hba_count;
2a622bfb
JS
4885
4886/*
4887 * File operations for the iDiag debugfs
4888 */
4889#undef lpfc_idiag_op_pciCfg
4890static const struct file_operations lpfc_idiag_op_pciCfg = {
4891 .owner = THIS_MODULE,
4892 .open = lpfc_idiag_open,
4893 .llseek = lpfc_debugfs_lseek,
4894 .read = lpfc_idiag_pcicfg_read,
4895 .write = lpfc_idiag_pcicfg_write,
4896 .release = lpfc_idiag_cmd_release,
4897};
4898
b76f2dc9
JS
4899#undef lpfc_idiag_op_barAcc
4900static const struct file_operations lpfc_idiag_op_barAcc = {
4901 .owner = THIS_MODULE,
4902 .open = lpfc_idiag_open,
4903 .llseek = lpfc_debugfs_lseek,
4904 .read = lpfc_idiag_baracc_read,
4905 .write = lpfc_idiag_baracc_write,
4906 .release = lpfc_idiag_cmd_release,
4907};
4908
2a622bfb
JS
4909#undef lpfc_idiag_op_queInfo
4910static const struct file_operations lpfc_idiag_op_queInfo = {
4911 .owner = THIS_MODULE,
4912 .open = lpfc_idiag_open,
4913 .read = lpfc_idiag_queinfo_read,
4914 .release = lpfc_idiag_release,
4915};
4916
b76f2dc9 4917#undef lpfc_idiag_op_queAcc
86a80846
JS
4918static const struct file_operations lpfc_idiag_op_queAcc = {
4919 .owner = THIS_MODULE,
4920 .open = lpfc_idiag_open,
4921 .llseek = lpfc_debugfs_lseek,
4922 .read = lpfc_idiag_queacc_read,
4923 .write = lpfc_idiag_queacc_write,
4924 .release = lpfc_idiag_cmd_release,
4925};
4926
b76f2dc9 4927#undef lpfc_idiag_op_drbAcc
86a80846
JS
4928static const struct file_operations lpfc_idiag_op_drbAcc = {
4929 .owner = THIS_MODULE,
4930 .open = lpfc_idiag_open,
4931 .llseek = lpfc_debugfs_lseek,
4932 .read = lpfc_idiag_drbacc_read,
4933 .write = lpfc_idiag_drbacc_write,
4934 .release = lpfc_idiag_cmd_release,
4935};
4936
b76f2dc9
JS
4937#undef lpfc_idiag_op_ctlAcc
4938static const struct file_operations lpfc_idiag_op_ctlAcc = {
4939 .owner = THIS_MODULE,
4940 .open = lpfc_idiag_open,
4941 .llseek = lpfc_debugfs_lseek,
4942 .read = lpfc_idiag_ctlacc_read,
4943 .write = lpfc_idiag_ctlacc_write,
4944 .release = lpfc_idiag_cmd_release,
4945};
4946
4947#undef lpfc_idiag_op_mbxAcc
4948static const struct file_operations lpfc_idiag_op_mbxAcc = {
4949 .owner = THIS_MODULE,
4950 .open = lpfc_idiag_open,
4951 .llseek = lpfc_debugfs_lseek,
4952 .read = lpfc_idiag_mbxacc_read,
4953 .write = lpfc_idiag_mbxacc_write,
4954 .release = lpfc_idiag_cmd_release,
4955};
4956
4957#undef lpfc_idiag_op_extAcc
4958static const struct file_operations lpfc_idiag_op_extAcc = {
4959 .owner = THIS_MODULE,
4960 .open = lpfc_idiag_open,
4961 .llseek = lpfc_debugfs_lseek,
4962 .read = lpfc_idiag_extacc_read,
4963 .write = lpfc_idiag_extacc_write,
4964 .release = lpfc_idiag_cmd_release,
4965};
4966
858c9f6c
JS
4967#endif
4968
b76f2dc9
JS
4969/* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
4970 * @phba: Pointer to HBA context object.
4971 * @dmabuf: Pointer to a DMA buffer descriptor.
4972 *
4973 * Description:
4974 * This routine dump a bsg pass-through non-embedded mailbox command with
4975 * external buffer.
4976 **/
4977void
4978lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
4979 enum mbox_type mbox_tp, enum dma_type dma_tp,
4980 enum sta_type sta_tp,
4981 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
4982{
4983#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4984 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
4985 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
4986 int len = 0;
4987 uint32_t do_dump = 0;
4988 uint32_t *pword;
4989 uint32_t i;
4990
4991 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
4992 return;
4993
4994 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
4995 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
4996 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
4997 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
4998
4999 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
5000 (*mbx_dump_cnt == 0) ||
5001 (*mbx_word_cnt == 0))
5002 return;
5003
5004 if (*mbx_mbox_cmd != 0x9B)
5005 return;
5006
5007 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5008 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5009 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
2ea259ee 5010 pr_err("\nRead mbox command (x%x), "
b76f2dc9
JS
5011 "nemb:0x%x, extbuf_cnt:%d:\n",
5012 sta_tp, nemb_tp, ext_buf);
5013 }
5014 }
5015 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5016 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5017 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
2ea259ee 5018 pr_err("\nRead mbox buffer (x%x), "
b76f2dc9
JS
5019 "nemb:0x%x, extbuf_seq:%d:\n",
5020 sta_tp, nemb_tp, ext_buf);
5021 }
5022 }
5023 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5024 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5025 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
2ea259ee 5026 pr_err("\nWrite mbox command (x%x), "
b76f2dc9
JS
5027 "nemb:0x%x, extbuf_cnt:%d:\n",
5028 sta_tp, nemb_tp, ext_buf);
5029 }
5030 }
5031 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5032 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5033 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
2ea259ee 5034 pr_err("\nWrite mbox buffer (x%x), "
b76f2dc9
JS
5035 "nemb:0x%x, extbuf_seq:%d:\n",
5036 sta_tp, nemb_tp, ext_buf);
5037 }
5038 }
5039
5040 /* dump buffer content */
5041 if (do_dump) {
5042 pword = (uint32_t *)dmabuf->virt;
5043 for (i = 0; i < *mbx_word_cnt; i++) {
5044 if (!(i % 8)) {
5045 if (i != 0)
2ea259ee 5046 pr_err("%s\n", line_buf);
b76f2dc9
JS
5047 len = 0;
5048 len += snprintf(line_buf+len,
5049 LPFC_MBX_ACC_LBUF_SZ-len,
5050 "%03d: ", i);
5051 }
5052 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5053 "%08x ", (uint32_t)*pword);
5054 pword++;
5055 }
5056 if ((i - 1) % 8)
2ea259ee 5057 pr_err("%s\n", line_buf);
b76f2dc9
JS
5058 (*mbx_dump_cnt)--;
5059 }
5060
5061 /* Clean out command structure on reaching dump count */
5062 if (*mbx_dump_cnt == 0)
5063 memset(&idiag, 0, sizeof(idiag));
5064 return;
5065#endif
5066}
5067
5068/* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5069 * @phba: Pointer to HBA context object.
5070 * @dmabuf: Pointer to a DMA buffer descriptor.
5071 *
5072 * Description:
5073 * This routine dump a pass-through non-embedded mailbox command from issue
5074 * mailbox command.
5075 **/
5076void
5077lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5078{
5079#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5080 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5081 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5082 int len = 0;
5083 uint32_t *pword;
5084 uint8_t *pbyte;
5085 uint32_t i, j;
5086
5087 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5088 return;
5089
5090 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5091 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5092 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5093 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5094
5095 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5096 (*mbx_dump_cnt == 0) ||
5097 (*mbx_word_cnt == 0))
5098 return;
5099
5100 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5101 (*mbx_mbox_cmd != pmbox->mbxCommand))
5102 return;
5103
5104 /* dump buffer content */
5105 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
2ea259ee 5106 pr_err("Mailbox command:0x%x dump by word:\n",
b76f2dc9
JS
5107 pmbox->mbxCommand);
5108 pword = (uint32_t *)pmbox;
5109 for (i = 0; i < *mbx_word_cnt; i++) {
5110 if (!(i % 8)) {
5111 if (i != 0)
2ea259ee 5112 pr_err("%s\n", line_buf);
b76f2dc9
JS
5113 len = 0;
5114 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5115 len += snprintf(line_buf+len,
5116 LPFC_MBX_ACC_LBUF_SZ-len,
5117 "%03d: ", i);
5118 }
5119 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
5120 "%08x ",
5121 ((uint32_t)*pword) & 0xffffffff);
5122 pword++;
5123 }
5124 if ((i - 1) % 8)
2ea259ee
JS
5125 pr_err("%s\n", line_buf);
5126 pr_err("\n");
b76f2dc9
JS
5127 }
5128 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
2ea259ee 5129 pr_err("Mailbox command:0x%x dump by byte:\n",
b76f2dc9
JS
5130 pmbox->mbxCommand);
5131 pbyte = (uint8_t *)pmbox;
5132 for (i = 0; i < *mbx_word_cnt; i++) {
5133 if (!(i % 8)) {
5134 if (i != 0)
2ea259ee 5135 pr_err("%s\n", line_buf);
b76f2dc9
JS
5136 len = 0;
5137 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
5138 len += snprintf(line_buf+len,
5139 LPFC_MBX_ACC_LBUF_SZ-len,
5140 "%03d: ", i);
5141 }
5142 for (j = 0; j < 4; j++) {
5143 len += snprintf(line_buf+len,
5144 LPFC_MBX_ACC_LBUF_SZ-len,
5145 "%02x",
5146 ((uint8_t)*pbyte) & 0xff);
5147 pbyte++;
5148 }
5149 len += snprintf(line_buf+len,
5150 LPFC_MBX_ACC_LBUF_SZ-len, " ");
5151 }
5152 if ((i - 1) % 8)
2ea259ee
JS
5153 pr_err("%s\n", line_buf);
5154 pr_err("\n");
b76f2dc9
JS
5155 }
5156 (*mbx_dump_cnt)--;
5157
5158 /* Clean out command structure on reaching dump count */
5159 if (*mbx_dump_cnt == 0)
5160 memset(&idiag, 0, sizeof(idiag));
5161 return;
5162#endif
5163}
5164
e59058c4 5165/**
3621a710 5166 * lpfc_debugfs_initialize - Initialize debugfs for a vport
e59058c4
JS
5167 * @vport: The vport pointer to initialize.
5168 *
5169 * Description:
5170 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
5171 * If not already created, this routine will create the lpfc directory, and
5172 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
5173 * also create each file used to access lpfc specific debugfs information.
5174 **/
858c9f6c
JS
5175inline void
5176lpfc_debugfs_initialize(struct lpfc_vport *vport)
5177{
923e4b6a 5178#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
858c9f6c
JS
5179 struct lpfc_hba *phba = vport->phba;
5180 char name[64];
5181 uint32_t num, i;
f6c3bdfb 5182 bool pport_setup = false;
858c9f6c
JS
5183
5184 if (!lpfc_debugfs_enable)
5185 return;
5186
a58cbd52 5187 /* Setup lpfc root directory */
858c9f6c
JS
5188 if (!lpfc_debugfs_root) {
5189 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
5190 atomic_set(&lpfc_debugfs_hba_count, 0);
a58cbd52 5191 if (!lpfc_debugfs_root) {
e8b62011 5192 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 5193 "0408 Cannot create debugfs root\n");
858c9f6c 5194 goto debug_failed;
a58cbd52 5195 }
858c9f6c 5196 }
a58cbd52
JS
5197 if (!lpfc_debugfs_start_time)
5198 lpfc_debugfs_start_time = jiffies;
5199
2a622bfb
JS
5200 /* Setup funcX directory for specific HBA PCI function */
5201 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
858c9f6c 5202 if (!phba->hba_debugfs_root) {
f6c3bdfb 5203 pport_setup = true;
858c9f6c
JS
5204 phba->hba_debugfs_root =
5205 debugfs_create_dir(name, lpfc_debugfs_root);
a58cbd52 5206 if (!phba->hba_debugfs_root) {
e8b62011 5207 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 5208 "0412 Cannot create debugfs hba\n");
858c9f6c 5209 goto debug_failed;
a58cbd52 5210 }
858c9f6c
JS
5211 atomic_inc(&lpfc_debugfs_hba_count);
5212 atomic_set(&phba->debugfs_vport_count, 0);
a58cbd52 5213
78b2d852
JS
5214 /* Setup hbqinfo */
5215 snprintf(name, sizeof(name), "hbqinfo");
5216 phba->debug_hbqinfo =
5217 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5218 phba->hba_debugfs_root,
5219 phba, &lpfc_debugfs_op_hbqinfo);
5220 if (!phba->debug_hbqinfo) {
5221 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 5222 "0411 Cannot create debugfs hbqinfo\n");
78b2d852
JS
5223 goto debug_failed;
5224 }
5225
c95d6c6c 5226 /* Setup dumpHBASlim */
2a622bfb
JS
5227 if (phba->sli_rev < LPFC_SLI_REV4) {
5228 snprintf(name, sizeof(name), "dumpHBASlim");
5229 phba->debug_dumpHBASlim =
5230 debugfs_create_file(name,
5231 S_IFREG|S_IRUGO|S_IWUSR,
5232 phba->hba_debugfs_root,
5233 phba, &lpfc_debugfs_op_dumpHBASlim);
5234 if (!phba->debug_dumpHBASlim) {
5235 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5236 "0413 Cannot create debugfs "
5237 "dumpHBASlim\n");
5238 goto debug_failed;
5239 }
5240 } else
5241 phba->debug_dumpHBASlim = NULL;
c95d6c6c
JS
5242
5243 /* Setup dumpHostSlim */
2a622bfb
JS
5244 if (phba->sli_rev < LPFC_SLI_REV4) {
5245 snprintf(name, sizeof(name), "dumpHostSlim");
5246 phba->debug_dumpHostSlim =
5247 debugfs_create_file(name,
5248 S_IFREG|S_IRUGO|S_IWUSR,
5249 phba->hba_debugfs_root,
5250 phba, &lpfc_debugfs_op_dumpHostSlim);
5251 if (!phba->debug_dumpHostSlim) {
5252 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5253 "0414 Cannot create debugfs "
5254 "dumpHostSlim\n");
5255 goto debug_failed;
5256 }
5257 } else
b28d108b 5258 phba->debug_dumpHostSlim = NULL;
a58cbd52 5259
e2a0a9d6
JS
5260 /* Setup dumpData */
5261 snprintf(name, sizeof(name), "dumpData");
5262 phba->debug_dumpData =
5263 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5264 phba->hba_debugfs_root,
5265 phba, &lpfc_debugfs_op_dumpData);
5266 if (!phba->debug_dumpData) {
5267 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5268 "0800 Cannot create debugfs dumpData\n");
5269 goto debug_failed;
5270 }
5271
5272 /* Setup dumpDif */
5273 snprintf(name, sizeof(name), "dumpDif");
5274 phba->debug_dumpDif =
5275 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5276 phba->hba_debugfs_root,
5277 phba, &lpfc_debugfs_op_dumpDif);
5278 if (!phba->debug_dumpDif) {
5279 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5280 "0801 Cannot create debugfs dumpDif\n");
5281 goto debug_failed;
5282 }
5283
f9bb2da1
JS
5284 /* Setup DIF Error Injections */
5285 snprintf(name, sizeof(name), "InjErrLBA");
5286 phba->debug_InjErrLBA =
5287 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5288 phba->hba_debugfs_root,
5289 phba, &lpfc_debugfs_op_dif_err);
5290 if (!phba->debug_InjErrLBA) {
5291 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5292 "0807 Cannot create debugfs InjErrLBA\n");
5293 goto debug_failed;
5294 }
5295 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
5296
4ac9b226
JS
5297 snprintf(name, sizeof(name), "InjErrNPortID");
5298 phba->debug_InjErrNPortID =
5299 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5300 phba->hba_debugfs_root,
5301 phba, &lpfc_debugfs_op_dif_err);
5302 if (!phba->debug_InjErrNPortID) {
5303 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5304 "0809 Cannot create debugfs InjErrNPortID\n");
5305 goto debug_failed;
5306 }
5307
5308 snprintf(name, sizeof(name), "InjErrWWPN");
5309 phba->debug_InjErrWWPN =
5310 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5311 phba->hba_debugfs_root,
5312 phba, &lpfc_debugfs_op_dif_err);
5313 if (!phba->debug_InjErrWWPN) {
5314 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5315 "0810 Cannot create debugfs InjErrWWPN\n");
5316 goto debug_failed;
5317 }
5318
f9bb2da1
JS
5319 snprintf(name, sizeof(name), "writeGuardInjErr");
5320 phba->debug_writeGuard =
5321 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5322 phba->hba_debugfs_root,
5323 phba, &lpfc_debugfs_op_dif_err);
5324 if (!phba->debug_writeGuard) {
5325 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5326 "0802 Cannot create debugfs writeGuard\n");
5327 goto debug_failed;
5328 }
5329
5330 snprintf(name, sizeof(name), "writeAppInjErr");
5331 phba->debug_writeApp =
5332 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5333 phba->hba_debugfs_root,
5334 phba, &lpfc_debugfs_op_dif_err);
5335 if (!phba->debug_writeApp) {
5336 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5337 "0803 Cannot create debugfs writeApp\n");
5338 goto debug_failed;
5339 }
5340
5341 snprintf(name, sizeof(name), "writeRefInjErr");
5342 phba->debug_writeRef =
5343 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5344 phba->hba_debugfs_root,
5345 phba, &lpfc_debugfs_op_dif_err);
5346 if (!phba->debug_writeRef) {
5347 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5348 "0804 Cannot create debugfs writeRef\n");
5349 goto debug_failed;
5350 }
5351
acd6859b
JS
5352 snprintf(name, sizeof(name), "readGuardInjErr");
5353 phba->debug_readGuard =
5354 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5355 phba->hba_debugfs_root,
5356 phba, &lpfc_debugfs_op_dif_err);
5357 if (!phba->debug_readGuard) {
5358 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5359 "0808 Cannot create debugfs readGuard\n");
5360 goto debug_failed;
5361 }
5362
f9bb2da1
JS
5363 snprintf(name, sizeof(name), "readAppInjErr");
5364 phba->debug_readApp =
5365 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5366 phba->hba_debugfs_root,
5367 phba, &lpfc_debugfs_op_dif_err);
5368 if (!phba->debug_readApp) {
5369 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5370 "0805 Cannot create debugfs readApp\n");
5371 goto debug_failed;
5372 }
5373
5374 snprintf(name, sizeof(name), "readRefInjErr");
5375 phba->debug_readRef =
5376 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5377 phba->hba_debugfs_root,
5378 phba, &lpfc_debugfs_op_dif_err);
5379 if (!phba->debug_readRef) {
5380 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5381 "0806 Cannot create debugfs readApp\n");
5382 goto debug_failed;
5383 }
5384
a58cbd52
JS
5385 /* Setup slow ring trace */
5386 if (lpfc_debugfs_max_slow_ring_trc) {
5387 num = lpfc_debugfs_max_slow_ring_trc - 1;
5388 if (num & lpfc_debugfs_max_slow_ring_trc) {
5389 /* Change to be a power of 2 */
5390 num = lpfc_debugfs_max_slow_ring_trc;
5391 i = 0;
5392 while (num > 1) {
5393 num = num >> 1;
5394 i++;
5395 }
5396 lpfc_debugfs_max_slow_ring_trc = (1 << i);
2ea259ee 5397 pr_err("lpfc_debugfs_max_disc_trc changed to "
e8b62011 5398 "%d\n", lpfc_debugfs_max_disc_trc);
a58cbd52
JS
5399 }
5400 }
5401
a58cbd52
JS
5402 snprintf(name, sizeof(name), "slow_ring_trace");
5403 phba->debug_slow_ring_trc =
5404 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5405 phba->hba_debugfs_root,
5406 phba, &lpfc_debugfs_op_slow_ring_trc);
5407 if (!phba->debug_slow_ring_trc) {
e8b62011 5408 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 5409 "0415 Cannot create debugfs "
e8b62011 5410 "slow_ring_trace\n");
a58cbd52
JS
5411 goto debug_failed;
5412 }
5413 if (!phba->slow_ring_trc) {
5414 phba->slow_ring_trc = kmalloc(
5415 (sizeof(struct lpfc_debugfs_trc) *
5416 lpfc_debugfs_max_slow_ring_trc),
5417 GFP_KERNEL);
5418 if (!phba->slow_ring_trc) {
e8b62011 5419 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 5420 "0416 Cannot create debugfs "
e8b62011 5421 "slow_ring buffer\n");
a58cbd52
JS
5422 goto debug_failed;
5423 }
5424 atomic_set(&phba->slow_ring_trc_cnt, 0);
5425 memset(phba->slow_ring_trc, 0,
5426 (sizeof(struct lpfc_debugfs_trc) *
5427 lpfc_debugfs_max_slow_ring_trc));
5428 }
2ea259ee 5429
bd2cdd5e
JS
5430 snprintf(name, sizeof(name), "nvmeio_trc");
5431 phba->debug_nvmeio_trc =
5432 debugfs_create_file(name, 0644,
5433 phba->hba_debugfs_root,
5434 phba, &lpfc_debugfs_op_nvmeio_trc);
5435 if (!phba->debug_nvmeio_trc) {
5436 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5437 "0574 No create debugfs nvmeio_trc\n");
5438 goto debug_failed;
5439 }
5440
5441 atomic_set(&phba->nvmeio_trc_cnt, 0);
5442 if (lpfc_debugfs_max_nvmeio_trc) {
5443 num = lpfc_debugfs_max_nvmeio_trc - 1;
5444 if (num & lpfc_debugfs_max_disc_trc) {
5445 /* Change to be a power of 2 */
5446 num = lpfc_debugfs_max_nvmeio_trc;
5447 i = 0;
5448 while (num > 1) {
5449 num = num >> 1;
5450 i++;
5451 }
5452 lpfc_debugfs_max_nvmeio_trc = (1 << i);
5453 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5454 "0575 lpfc_debugfs_max_nvmeio_trc "
5455 "changed to %d\n",
5456 lpfc_debugfs_max_nvmeio_trc);
5457 }
5458 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
5459
5460 /* Allocate trace buffer and initialize */
5461 phba->nvmeio_trc = kmalloc(
5462 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5463 phba->nvmeio_trc_size), GFP_KERNEL);
5464
5465 if (!phba->nvmeio_trc) {
5466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5467 "0576 Cannot create debugfs "
5468 "nvmeio_trc buffer\n");
5469 goto nvmeio_off;
5470 }
5471 memset(phba->nvmeio_trc, 0,
5472 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
5473 phba->nvmeio_trc_size));
5474 phba->nvmeio_trc_on = 1;
5475 phba->nvmeio_trc_output_idx = 0;
5476 phba->nvmeio_trc = NULL;
5477 } else {
5478nvmeio_off:
5479 phba->nvmeio_trc_size = 0;
5480 phba->nvmeio_trc_on = 0;
5481 phba->nvmeio_trc_output_idx = 0;
5482 phba->nvmeio_trc = NULL;
5483 }
858c9f6c
JS
5484 }
5485
5486 snprintf(name, sizeof(name), "vport%d", vport->vpi);
5487 if (!vport->vport_debugfs_root) {
5488 vport->vport_debugfs_root =
5489 debugfs_create_dir(name, phba->hba_debugfs_root);
a58cbd52 5490 if (!vport->vport_debugfs_root) {
e8b62011 5491 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
25985edc 5492 "0417 Can't create debugfs\n");
858c9f6c 5493 goto debug_failed;
a58cbd52 5494 }
858c9f6c
JS
5495 atomic_inc(&phba->debugfs_vport_count);
5496 }
5497
a58cbd52
JS
5498 if (lpfc_debugfs_max_disc_trc) {
5499 num = lpfc_debugfs_max_disc_trc - 1;
5500 if (num & lpfc_debugfs_max_disc_trc) {
5501 /* Change to be a power of 2 */
5502 num = lpfc_debugfs_max_disc_trc;
5503 i = 0;
5504 while (num > 1) {
5505 num = num >> 1;
5506 i++;
5507 }
5508 lpfc_debugfs_max_disc_trc = (1 << i);
2ea259ee 5509 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
e8b62011 5510 lpfc_debugfs_max_disc_trc);
a58cbd52
JS
5511 }
5512 }
858c9f6c 5513
ff86ba59 5514 vport->disc_trc = kzalloc(
a58cbd52 5515 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
858c9f6c
JS
5516 GFP_KERNEL);
5517
a58cbd52 5518 if (!vport->disc_trc) {
e8b62011 5519 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 5520 "0418 Cannot create debugfs disc trace "
e8b62011 5521 "buffer\n");
858c9f6c 5522 goto debug_failed;
a58cbd52
JS
5523 }
5524 atomic_set(&vport->disc_trc_cnt, 0);
858c9f6c
JS
5525
5526 snprintf(name, sizeof(name), "discovery_trace");
5527 vport->debug_disc_trc =
5528 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5529 vport->vport_debugfs_root,
5530 vport, &lpfc_debugfs_op_disc_trc);
5531 if (!vport->debug_disc_trc) {
e8b62011 5532 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
d7c255b2 5533 "0419 Cannot create debugfs "
e8b62011 5534 "discovery_trace\n");
858c9f6c
JS
5535 goto debug_failed;
5536 }
5537 snprintf(name, sizeof(name), "nodelist");
5538 vport->debug_nodelist =
5539 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5540 vport->vport_debugfs_root,
5541 vport, &lpfc_debugfs_op_nodelist);
5542 if (!vport->debug_nodelist) {
e8b62011 5543 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
b76f2dc9 5544 "2985 Can't create debugfs nodelist\n");
858c9f6c
JS
5545 goto debug_failed;
5546 }
2a622bfb 5547
bd2cdd5e
JS
5548 snprintf(name, sizeof(name), "nvmestat");
5549 vport->debug_nvmestat =
5550 debugfs_create_file(name, 0644,
5551 vport->vport_debugfs_root,
5552 vport, &lpfc_debugfs_op_nvmestat);
5553 if (!vport->debug_nvmestat) {
5554 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5555 "0811 Cannot create debugfs nvmestat\n");
5556 goto debug_failed;
5557 }
5558
5559 snprintf(name, sizeof(name), "nvmektime");
5560 vport->debug_nvmektime =
5561 debugfs_create_file(name, 0644,
5562 vport->vport_debugfs_root,
5563 vport, &lpfc_debugfs_op_nvmektime);
5564 if (!vport->debug_nvmektime) {
5565 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5566 "0815 Cannot create debugfs nvmektime\n");
5567 goto debug_failed;
5568 }
5569
5570 snprintf(name, sizeof(name), "cpucheck");
5571 vport->debug_cpucheck =
5572 debugfs_create_file(name, 0644,
5573 vport->vport_debugfs_root,
5574 vport, &lpfc_debugfs_op_cpucheck);
5575 if (!vport->debug_cpucheck) {
5576 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5577 "0819 Cannot create debugfs cpucheck\n");
5578 goto debug_failed;
5579 }
5580
f6c3bdfb
JS
5581 /*
5582 * The following section is for additional directories/files for the
5583 * physical port.
5584 */
5585
5586 if (!pport_setup)
5587 goto debug_failed;
5588
2a622bfb
JS
5589 /*
5590 * iDiag debugfs root entry points for SLI4 device only
5591 */
5592 if (phba->sli_rev < LPFC_SLI_REV4)
5593 goto debug_failed;
5594
5595 snprintf(name, sizeof(name), "iDiag");
5596 if (!phba->idiag_root) {
5597 phba->idiag_root =
5598 debugfs_create_dir(name, phba->hba_debugfs_root);
5599 if (!phba->idiag_root) {
5600 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5601 "2922 Can't create idiag debugfs\n");
5602 goto debug_failed;
5603 }
5604 /* Initialize iDiag data structure */
5605 memset(&idiag, 0, sizeof(idiag));
5606 }
5607
5608 /* iDiag read PCI config space */
5609 snprintf(name, sizeof(name), "pciCfg");
5610 if (!phba->idiag_pci_cfg) {
5611 phba->idiag_pci_cfg =
5612 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5613 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
5614 if (!phba->idiag_pci_cfg) {
5615 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5616 "2923 Can't create idiag debugfs\n");
5617 goto debug_failed;
5618 }
5619 idiag.offset.last_rd = 0;
5620 }
5621
b76f2dc9
JS
5622 /* iDiag PCI BAR access */
5623 snprintf(name, sizeof(name), "barAcc");
5624 if (!phba->idiag_bar_acc) {
5625 phba->idiag_bar_acc =
5626 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5627 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
5628 if (!phba->idiag_bar_acc) {
5629 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5630 "3056 Can't create idiag debugfs\n");
5631 goto debug_failed;
5632 }
5633 idiag.offset.last_rd = 0;
5634 }
5635
2a622bfb
JS
5636 /* iDiag get PCI function queue information */
5637 snprintf(name, sizeof(name), "queInfo");
5638 if (!phba->idiag_que_info) {
5639 phba->idiag_que_info =
5640 debugfs_create_file(name, S_IFREG|S_IRUGO,
5641 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
5642 if (!phba->idiag_que_info) {
5643 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5644 "2924 Can't create idiag debugfs\n");
5645 goto debug_failed;
5646 }
5647 }
5648
86a80846
JS
5649 /* iDiag access PCI function queue */
5650 snprintf(name, sizeof(name), "queAcc");
5651 if (!phba->idiag_que_acc) {
5652 phba->idiag_que_acc =
5653 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5654 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
5655 if (!phba->idiag_que_acc) {
5656 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5657 "2926 Can't create idiag debugfs\n");
5658 goto debug_failed;
5659 }
5660 }
5661
5662 /* iDiag access PCI function doorbell registers */
5663 snprintf(name, sizeof(name), "drbAcc");
5664 if (!phba->idiag_drb_acc) {
5665 phba->idiag_drb_acc =
5666 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5667 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
5668 if (!phba->idiag_drb_acc) {
5669 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5670 "2927 Can't create idiag debugfs\n");
5671 goto debug_failed;
5672 }
5673 }
5674
b76f2dc9
JS
5675 /* iDiag access PCI function control registers */
5676 snprintf(name, sizeof(name), "ctlAcc");
5677 if (!phba->idiag_ctl_acc) {
5678 phba->idiag_ctl_acc =
5679 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5680 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
5681 if (!phba->idiag_ctl_acc) {
5682 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5683 "2981 Can't create idiag debugfs\n");
5684 goto debug_failed;
5685 }
5686 }
5687
5688 /* iDiag access mbox commands */
5689 snprintf(name, sizeof(name), "mbxAcc");
5690 if (!phba->idiag_mbx_acc) {
5691 phba->idiag_mbx_acc =
5692 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5693 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
5694 if (!phba->idiag_mbx_acc) {
5695 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5696 "2980 Can't create idiag debugfs\n");
5697 goto debug_failed;
5698 }
5699 }
5700
5701 /* iDiag extents access commands */
5702 if (phba->sli4_hba.extents_in_use) {
5703 snprintf(name, sizeof(name), "extAcc");
5704 if (!phba->idiag_ext_acc) {
5705 phba->idiag_ext_acc =
5706 debugfs_create_file(name,
5707 S_IFREG|S_IRUGO|S_IWUSR,
5708 phba->idiag_root, phba,
5709 &lpfc_idiag_op_extAcc);
5710 if (!phba->idiag_ext_acc) {
5711 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5712 "2986 Cant create "
5713 "idiag debugfs\n");
5714 goto debug_failed;
5715 }
5716 }
5717 }
5718
858c9f6c
JS
5719debug_failed:
5720 return;
5721#endif
5722}
5723
e59058c4 5724/**
3621a710 5725 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
e59058c4
JS
5726 * @vport: The vport pointer to remove from debugfs.
5727 *
5728 * Description:
5729 * When Debugfs is configured this routine removes debugfs file system elements
5730 * that are specific to this vport. It also checks to see if there are any
5731 * users left for the debugfs directories associated with the HBA and driver. If
5732 * this is the last user of the HBA directory or driver directory then it will
5733 * remove those from the debugfs infrastructure as well.
5734 **/
858c9f6c
JS
5735inline void
5736lpfc_debugfs_terminate(struct lpfc_vport *vport)
5737{
923e4b6a 5738#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
858c9f6c
JS
5739 struct lpfc_hba *phba = vport->phba;
5740
eafe89f5
JS
5741 kfree(vport->disc_trc);
5742 vport->disc_trc = NULL;
bd2cdd5e
JS
5743
5744 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
5745 vport->debug_disc_trc = NULL;
5746
5747 debugfs_remove(vport->debug_nodelist); /* nodelist */
5748 vport->debug_nodelist = NULL;
5749
5750 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
5751 vport->debug_nvmestat = NULL;
5752
5753 debugfs_remove(vport->debug_nvmektime); /* nvmektime */
5754 vport->debug_nvmektime = NULL;
5755
5756 debugfs_remove(vport->debug_cpucheck); /* cpucheck */
5757 vport->debug_cpucheck = NULL;
5758
858c9f6c
JS
5759 if (vport->vport_debugfs_root) {
5760 debugfs_remove(vport->vport_debugfs_root); /* vportX */
5761 vport->vport_debugfs_root = NULL;
5762 atomic_dec(&phba->debugfs_vport_count);
5763 }
bd2cdd5e 5764
858c9f6c 5765 if (atomic_read(&phba->debugfs_vport_count) == 0) {
a58cbd52 5766
bd2cdd5e
JS
5767 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
5768 phba->debug_hbqinfo = NULL;
e2a0a9d6 5769
bd2cdd5e
JS
5770 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
5771 phba->debug_dumpHBASlim = NULL;
5772
5773 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
5774 phba->debug_dumpHostSlim = NULL;
5775
5776 debugfs_remove(phba->debug_dumpData); /* dumpData */
5777 phba->debug_dumpData = NULL;
5778
5779 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
5780 phba->debug_dumpDif = NULL;
5781
5782 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
5783 phba->debug_InjErrLBA = NULL;
5784
5785 debugfs_remove(phba->debug_InjErrNPortID);
5786 phba->debug_InjErrNPortID = NULL;
5787
5788 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
5789 phba->debug_InjErrWWPN = NULL;
5790
5791 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
5792 phba->debug_writeGuard = NULL;
5793
5794 debugfs_remove(phba->debug_writeApp); /* writeApp */
5795 phba->debug_writeApp = NULL;
5796
5797 debugfs_remove(phba->debug_writeRef); /* writeRef */
5798 phba->debug_writeRef = NULL;
5799
5800 debugfs_remove(phba->debug_readGuard); /* readGuard */
5801 phba->debug_readGuard = NULL;
5802
5803 debugfs_remove(phba->debug_readApp); /* readApp */
5804 phba->debug_readApp = NULL;
5805
5806 debugfs_remove(phba->debug_readRef); /* readRef */
5807 phba->debug_readRef = NULL;
e2a0a9d6 5808
eafe89f5
JS
5809 kfree(phba->slow_ring_trc);
5810 phba->slow_ring_trc = NULL;
bd2cdd5e
JS
5811
5812 /* slow_ring_trace */
5813 debugfs_remove(phba->debug_slow_ring_trc);
5814 phba->debug_slow_ring_trc = NULL;
5815
5816 debugfs_remove(phba->debug_nvmeio_trc);
5817 phba->debug_nvmeio_trc = NULL;
5818
5819 kfree(phba->nvmeio_trc);
5820 phba->nvmeio_trc = NULL;
a58cbd52 5821
2a622bfb
JS
5822 /*
5823 * iDiag release
5824 */
5825 if (phba->sli_rev == LPFC_SLI_REV4) {
bd2cdd5e
JS
5826 /* iDiag extAcc */
5827 debugfs_remove(phba->idiag_ext_acc);
5828 phba->idiag_ext_acc = NULL;
5829
5830 /* iDiag mbxAcc */
5831 debugfs_remove(phba->idiag_mbx_acc);
5832 phba->idiag_mbx_acc = NULL;
5833
5834 /* iDiag ctlAcc */
5835 debugfs_remove(phba->idiag_ctl_acc);
5836 phba->idiag_ctl_acc = NULL;
5837
5838 /* iDiag drbAcc */
5839 debugfs_remove(phba->idiag_drb_acc);
5840 phba->idiag_drb_acc = NULL;
5841
5842 /* iDiag queAcc */
5843 debugfs_remove(phba->idiag_que_acc);
5844 phba->idiag_que_acc = NULL;
5845
5846 /* iDiag queInfo */
5847 debugfs_remove(phba->idiag_que_info);
5848 phba->idiag_que_info = NULL;
5849
5850 /* iDiag barAcc */
5851 debugfs_remove(phba->idiag_bar_acc);
5852 phba->idiag_bar_acc = NULL;
5853
5854 /* iDiag pciCfg */
5855 debugfs_remove(phba->idiag_pci_cfg);
5856 phba->idiag_pci_cfg = NULL;
2a622bfb
JS
5857
5858 /* Finally remove the iDiag debugfs root */
bd2cdd5e
JS
5859 debugfs_remove(phba->idiag_root);
5860 phba->idiag_root = NULL;
2a622bfb
JS
5861 }
5862
a58cbd52 5863 if (phba->hba_debugfs_root) {
2a622bfb 5864 debugfs_remove(phba->hba_debugfs_root); /* fnX */
a58cbd52
JS
5865 phba->hba_debugfs_root = NULL;
5866 atomic_dec(&lpfc_debugfs_hba_count);
5867 }
5868
667a7662
JS
5869 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
5870 debugfs_remove(lpfc_debugfs_root); /* lpfc */
5871 lpfc_debugfs_root = NULL;
5872 }
858c9f6c
JS
5873 }
5874#endif
a58cbd52 5875 return;
858c9f6c 5876}
809c7536
JS
5877
5878/*
5879 * Driver debug utility routines outside of debugfs. The debug utility
5880 * routines implemented here is intended to be used in the instrumented
5881 * debug driver for debugging host or port issues.
5882 */
5883
5884/**
5885 * lpfc_debug_dump_all_queues - dump all the queues with a hba
5886 * @phba: Pointer to HBA context object.
5887 *
5888 * This function dumps entries of all the queues asociated with the @phba.
5889 **/
5890void
5891lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
5892{
1d9d5a98 5893 int idx;
809c7536
JS
5894
5895 /*
5896 * Dump Work Queues (WQs)
5897 */
1d9d5a98
JS
5898 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
5899 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
895427bd 5900 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
809c7536 5901
1d9d5a98
JS
5902 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5903 lpfc_debug_dump_wq(phba, DUMP_FCP, idx);
809c7536 5904
895427bd
JS
5905 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5906 lpfc_debug_dump_wq(phba, DUMP_NVME, idx);
5907
809c7536
JS
5908 lpfc_debug_dump_hdr_rq(phba);
5909 lpfc_debug_dump_dat_rq(phba);
5910 /*
5911 * Dump Complete Queues (CQs)
5912 */
1d9d5a98
JS
5913 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
5914 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
895427bd 5915 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
809c7536 5916
1d9d5a98
JS
5917 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
5918 lpfc_debug_dump_cq(phba, DUMP_FCP, idx);
809c7536 5919
895427bd
JS
5920 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
5921 lpfc_debug_dump_cq(phba, DUMP_NVME, idx);
5922
809c7536
JS
5923 /*
5924 * Dump Event Queues (EQs)
5925 */
895427bd 5926 for (idx = 0; idx < phba->io_channel_irqs; idx++)
1d9d5a98 5927 lpfc_debug_dump_hba_eq(phba, idx);
809c7536 5928}