blob: c9a327b13e5cf44bd28bf04f10557eb4840cba3c [file] [log] [blame]
James Smart858c9f62007-06-17 19:56:39 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
James Smart0d041212019-01-28 11:14:41 -08004 * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
James Smart3e21d1c2018-05-04 20:37:59 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smartf25e8e72015-04-07 15:07:28 -04006 * Copyright (C) 2007-2015 Emulex. All rights reserved. *
James Smart858c9f62007-06-17 19:56:39 -05007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James Smart858c9f62007-06-17 19:56:39 -05009 * *
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>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040025#include <linux/module.h>
James Smart858c9f62007-06-17 19:56:39 -050026#include <linux/dma-mapping.h>
27#include <linux/idr.h>
28#include <linux/interrupt.h>
29#include <linux/kthread.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
James Smart858c9f62007-06-17 19:56:39 -050031#include <linux/pci.h>
32#include <linux/spinlock.h>
33#include <linux/ctype.h>
James Smart9e2edb42019-10-25 11:25:30 -070034#include <linux/vmalloc.h>
James Smart858c9f62007-06-17 19:56:39 -050035
36#include <scsi/scsi.h>
37#include <scsi/scsi_device.h>
38#include <scsi/scsi_host.h>
39#include <scsi/scsi_transport_fc.h>
James Smartbd2cdd52017-02-12 13:52:33 -080040#include <scsi/fc/fc_fs.h>
41
James Smartda0436e2009-05-22 14:51:39 -040042#include "lpfc_hw4.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_hw.h"
44#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040045#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040046#include "lpfc_nl.h"
James Smart858c9f62007-06-17 19:56:39 -050047#include "lpfc_disc.h"
James Smart858c9f62007-06-17 19:56:39 -050048#include "lpfc.h"
James Smartbd2cdd52017-02-12 13:52:33 -080049#include "lpfc_scsi.h"
50#include "lpfc_nvme.h"
James Smart858c9f62007-06-17 19:56:39 -050051#include "lpfc_logmsg.h"
52#include "lpfc_crtn.h"
53#include "lpfc_vport.h"
54#include "lpfc_version.h"
James Smartc95d6c62008-01-11 01:53:23 -050055#include "lpfc_compat.h"
James Smart858c9f62007-06-17 19:56:39 -050056#include "lpfc_debugfs.h"
James Smartb76f2dc2011-07-22 18:37:42 -040057#include "lpfc_bsg.h"
James Smart858c9f62007-06-17 19:56:39 -050058
James Smart923e4b62008-12-04 22:40:07 -050059#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart3621a712009-04-06 18:47:14 -040060/*
James Smarte59058c2008-08-24 21:49:00 -040061 * debugfs interface
James Smart858c9f62007-06-17 19:56:39 -050062 *
63 * To access this interface the user should:
GeunSik Lim156f5a72009-06-02 15:01:37 +090064 * # mount -t debugfs none /sys/kernel/debug
James Smart858c9f62007-06-17 19:56:39 -050065 *
James Smarte59058c2008-08-24 21:49:00 -040066 * The lpfc debugfs directory hierarchy is:
James Smart2a622bf2011-02-16 12:40:06 -050067 * /sys/kernel/debug/lpfc/fnX/vportY
68 * where X is the lpfc hba function unique_id
James Smart858c9f62007-06-17 19:56:39 -050069 * where Y is the vport VPI on that hba
70 *
71 * Debugging services available per vport:
72 * discovery_trace
73 * This is an ACSII readable file that contains a trace of the last
74 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
James Smarte59058c2008-08-24 21:49:00 -040075 * See lpfc_debugfs.h for different categories of discovery events.
76 * To enable the discovery trace, the following module parameters must be set:
James Smart858c9f62007-06-17 19:56:39 -050077 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
78 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
79 * EACH vport. X MUST also be a power of 2.
80 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
81 * lpfc_debugfs.h .
James Smarte59058c2008-08-24 21:49:00 -040082 *
83 * slow_ring_trace
84 * This is an ACSII readable file that contains a trace of the last
85 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
86 * To enable the slow ring trace, the following module parameters must be set:
87 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
88 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
89 * the HBA. X MUST also be a power of 2.
James Smart858c9f62007-06-17 19:56:39 -050090 */
James Smart51ef4c22007-08-02 11:10:31 -040091static int lpfc_debugfs_enable = 1;
James Smartab56dc22011-02-16 12:39:57 -050092module_param(lpfc_debugfs_enable, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050093MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
94
James Smarta58cbd52007-08-02 11:09:43 -040095/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -050096static int lpfc_debugfs_max_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -050097module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -050098MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
99 "Set debugfs discovery trace depth");
100
James Smarta58cbd52007-08-02 11:09:43 -0400101/* This MUST be a power of 2 */
James Smartc95d6c62008-01-11 01:53:23 -0500102static int lpfc_debugfs_max_slow_ring_trc;
James Smartab56dc22011-02-16 12:39:57 -0500103module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
James Smarta58cbd52007-08-02 11:09:43 -0400104MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
105 "Set debugfs slow ring trace depth");
106
James Smartbd2cdd52017-02-12 13:52:33 -0800107/* This MUST be a power of 2 */
108static int lpfc_debugfs_max_nvmeio_trc;
109module_param(lpfc_debugfs_max_nvmeio_trc, int, 0444);
110MODULE_PARM_DESC(lpfc_debugfs_max_nvmeio_trc,
111 "Set debugfs NVME IO trace depth");
112
James Smarta257bf92009-04-06 18:48:10 -0400113static int lpfc_debugfs_mask_disc_trc;
James Smartab56dc22011-02-16 12:39:57 -0500114module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
James Smart858c9f62007-06-17 19:56:39 -0500115MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
116 "Set debugfs discovery trace mask");
117
118#include <linux/debugfs.h>
119
James Smart311464e2007-08-02 11:10:37 -0400120static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
121static unsigned long lpfc_debugfs_start_time = 0L;
James Smart858c9f62007-06-17 19:56:39 -0500122
James Smart2a622bf2011-02-16 12:40:06 -0500123/* iDiag */
124static struct lpfc_idiag idiag;
125
James Smarte59058c2008-08-24 21:49:00 -0400126/**
James Smart3621a712009-04-06 18:47:14 -0400127 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400128 * @vport: The vport to gather the log info from.
129 * @buf: The buffer to dump log into.
130 * @size: The maximum amount of data to process.
131 *
132 * Description:
133 * This routine gathers the lpfc discovery debugfs data from the @vport and
134 * dumps it to @buf up to @size number of bytes. It will start at the next entry
135 * in the log and process the log until the end of the buffer. Then it will
136 * gather from the beginning of the log and process until the current entry.
137 *
138 * Notes:
139 * Discovery logging will be disabled while while this routine dumps the log.
140 *
141 * Return Value:
142 * This routine returns the amount of bytes that were dumped into @buf and will
143 * not exceed @size.
144 **/
James Smart858c9f62007-06-17 19:56:39 -0500145static int
146lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
147{
148 int i, index, len, enable;
149 uint32_t ms;
James Smarta58cbd52007-08-02 11:09:43 -0400150 struct lpfc_debugfs_trc *dtp;
James Smartb76f2dc2011-07-22 18:37:42 -0400151 char *buffer;
152
153 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
154 if (!buffer)
155 return 0;
James Smart858c9f62007-06-17 19:56:39 -0500156
James Smart858c9f62007-06-17 19:56:39 -0500157 enable = lpfc_debugfs_enable;
158 lpfc_debugfs_enable = 0;
159
160 len = 0;
161 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
162 (lpfc_debugfs_max_disc_trc - 1);
163 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
164 dtp = vport->disc_trc + i;
165 if (!dtp->fmt)
166 continue;
167 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400168 snprintf(buffer,
169 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500170 dtp->seq_cnt, ms, dtp->fmt);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700171 len += scnprintf(buf+len, size-len, buffer,
James Smart858c9f62007-06-17 19:56:39 -0500172 dtp->data1, dtp->data2, dtp->data3);
173 }
174 for (i = 0; i < index; i++) {
175 dtp = vport->disc_trc + i;
176 if (!dtp->fmt)
177 continue;
178 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
James Smarta58cbd52007-08-02 11:09:43 -0400179 snprintf(buffer,
180 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
James Smart858c9f62007-06-17 19:56:39 -0500181 dtp->seq_cnt, ms, dtp->fmt);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700182 len += scnprintf(buf+len, size-len, buffer,
James Smart858c9f62007-06-17 19:56:39 -0500183 dtp->data1, dtp->data2, dtp->data3);
184 }
185
186 lpfc_debugfs_enable = enable;
James Smartb76f2dc2011-07-22 18:37:42 -0400187 kfree(buffer);
188
James Smart858c9f62007-06-17 19:56:39 -0500189 return len;
190}
191
James Smarte59058c2008-08-24 21:49:00 -0400192/**
James Smart3621a712009-04-06 18:47:14 -0400193 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400194 * @phba: The HBA to gather the log info from.
195 * @buf: The buffer to dump log into.
196 * @size: The maximum amount of data to process.
197 *
198 * Description:
199 * This routine gathers the lpfc slow ring debugfs data from the @phba and
200 * dumps it to @buf up to @size number of bytes. It will start at the next entry
201 * in the log and process the log until the end of the buffer. Then it will
202 * gather from the beginning of the log and process until the current entry.
203 *
204 * Notes:
205 * Slow ring logging will be disabled while while this routine dumps the log.
206 *
207 * Return Value:
208 * This routine returns the amount of bytes that were dumped into @buf and will
209 * not exceed @size.
210 **/
James Smart858c9f62007-06-17 19:56:39 -0500211static int
James Smarta58cbd52007-08-02 11:09:43 -0400212lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
213{
214 int i, index, len, enable;
215 uint32_t ms;
216 struct lpfc_debugfs_trc *dtp;
James Smartb76f2dc2011-07-22 18:37:42 -0400217 char *buffer;
James Smarta58cbd52007-08-02 11:09:43 -0400218
James Smartb76f2dc2011-07-22 18:37:42 -0400219 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
220 if (!buffer)
221 return 0;
James Smarta58cbd52007-08-02 11:09:43 -0400222
223 enable = lpfc_debugfs_enable;
224 lpfc_debugfs_enable = 0;
225
226 len = 0;
227 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
228 (lpfc_debugfs_max_slow_ring_trc - 1);
229 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
230 dtp = phba->slow_ring_trc + i;
231 if (!dtp->fmt)
232 continue;
233 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
234 snprintf(buffer,
235 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
236 dtp->seq_cnt, ms, dtp->fmt);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700237 len += scnprintf(buf+len, size-len, buffer,
James Smarta58cbd52007-08-02 11:09:43 -0400238 dtp->data1, dtp->data2, dtp->data3);
239 }
240 for (i = 0; i < index; i++) {
241 dtp = phba->slow_ring_trc + i;
242 if (!dtp->fmt)
243 continue;
244 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
245 snprintf(buffer,
246 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
247 dtp->seq_cnt, ms, dtp->fmt);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700248 len += scnprintf(buf+len, size-len, buffer,
James Smarta58cbd52007-08-02 11:09:43 -0400249 dtp->data1, dtp->data2, dtp->data3);
250 }
251
252 lpfc_debugfs_enable = enable;
James Smartb76f2dc2011-07-22 18:37:42 -0400253 kfree(buffer);
254
James Smarta58cbd52007-08-02 11:09:43 -0400255 return len;
256}
257
James Smart311464e2007-08-02 11:10:37 -0400258static int lpfc_debugfs_last_hbq = -1;
James Smart78b2d852007-08-02 11:10:21 -0400259
James Smarte59058c2008-08-24 21:49:00 -0400260/**
James Smart3621a712009-04-06 18:47:14 -0400261 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400262 * @phba: The HBA to gather host buffer info from.
263 * @buf: The buffer to dump log into.
264 * @size: The maximum amount of data to process.
265 *
266 * Description:
267 * This routine dumps the host buffer queue info from the @phba to @buf up to
268 * @size number of bytes. A header that describes the current hbq state will be
269 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
270 * until @size bytes have been dumped or all the hbq info has been dumped.
271 *
272 * Notes:
273 * This routine will rotate through each configured HBQ each time called.
274 *
275 * Return Value:
276 * This routine returns the amount of bytes that were dumped into @buf and will
277 * not exceed @size.
278 **/
James Smart78b2d852007-08-02 11:10:21 -0400279static int
280lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
281{
282 int len = 0;
James Smarteb016562014-09-03 12:58:06 -0400283 int i, j, found, posted, low;
James Smart78b2d852007-08-02 11:10:21 -0400284 uint32_t phys, raw_index, getidx;
285 struct lpfc_hbq_init *hip;
286 struct hbq_s *hbqs;
287 struct lpfc_hbq_entry *hbqe;
288 struct lpfc_dmabuf *d_buf;
289 struct hbq_dmabuf *hbq_buf;
290
James Smart3772a992009-05-22 14:50:54 -0400291 if (phba->sli_rev != 3)
292 return 0;
James Smarteb016562014-09-03 12:58:06 -0400293
James Smart78b2d852007-08-02 11:10:21 -0400294 spin_lock_irq(&phba->hbalock);
295
296 /* toggle between multiple hbqs, if any */
297 i = lpfc_sli_hbq_count();
298 if (i > 1) {
299 lpfc_debugfs_last_hbq++;
300 if (lpfc_debugfs_last_hbq >= i)
301 lpfc_debugfs_last_hbq = 0;
302 }
303 else
304 lpfc_debugfs_last_hbq = 0;
305
306 i = lpfc_debugfs_last_hbq;
307
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700308 len += scnprintf(buf+len, size-len, "HBQ %d Info\n", i);
James Smart78b2d852007-08-02 11:10:21 -0400309
James Smart51ef4c22007-08-02 11:10:31 -0400310 hbqs = &phba->hbqs[i];
James Smart78b2d852007-08-02 11:10:21 -0400311 posted = 0;
James Smart51ef4c22007-08-02 11:10:31 -0400312 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
James Smart78b2d852007-08-02 11:10:21 -0400313 posted++;
314
315 hip = lpfc_hbq_defs[i];
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700316 len += scnprintf(buf+len, size-len,
James Smart78b2d852007-08-02 11:10:21 -0400317 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
318 hip->hbq_index, hip->profile, hip->rn,
319 hip->buffer_count, hip->init_count, hip->add_count, posted);
320
James Smart78b2d852007-08-02 11:10:21 -0400321 raw_index = phba->hbq_get[i];
322 getidx = le32_to_cpu(raw_index);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700323 len += scnprintf(buf+len, size-len,
Colin Ian King1ab62072017-05-26 11:11:37 +0100324 "entries:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
James Smarta8adb832007-10-27 13:37:53 -0400325 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
326 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
James Smart78b2d852007-08-02 11:10:21 -0400327
James Smart51ef4c22007-08-02 11:10:31 -0400328 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
James Smart78b2d852007-08-02 11:10:21 -0400329 for (j=0; j<hbqs->entry_count; j++) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700330 len += scnprintf(buf+len, size-len,
James Smart78b2d852007-08-02 11:10:21 -0400331 "%03d: %08x %04x %05x ", j,
James Smarta8adb832007-10-27 13:37:53 -0400332 le32_to_cpu(hbqe->bde.addrLow),
333 le32_to_cpu(hbqe->bde.tus.w),
334 le32_to_cpu(hbqe->buffer_tag));
James Smart78b2d852007-08-02 11:10:21 -0400335 i = 0;
336 found = 0;
337
338 /* First calculate if slot has an associated posted buffer */
339 low = hbqs->hbqPutIdx - posted;
340 if (low >= 0) {
341 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700342 len += scnprintf(buf + len, size - len,
343 "Unused\n");
James Smart78b2d852007-08-02 11:10:21 -0400344 goto skipit;
345 }
346 }
347 else {
348 if ((j >= hbqs->hbqPutIdx) &&
349 (j < (hbqs->entry_count+low))) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700350 len += scnprintf(buf + len, size - len,
351 "Unused\n");
James Smart78b2d852007-08-02 11:10:21 -0400352 goto skipit;
353 }
354 }
355
356 /* Get the Buffer info for the posted buffer */
James Smart51ef4c22007-08-02 11:10:31 -0400357 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
James Smart78b2d852007-08-02 11:10:21 -0400358 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
359 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
James Smarta8adb832007-10-27 13:37:53 -0400360 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700361 len += scnprintf(buf+len, size-len,
James Smart32350662019-08-14 16:57:06 -0700362 "Buf%d: x%px %06x\n", i,
James Smart78b2d852007-08-02 11:10:21 -0400363 hbq_buf->dbuf.virt, hbq_buf->tag);
364 found = 1;
365 break;
366 }
367 i++;
368 }
369 if (!found) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700370 len += scnprintf(buf+len, size-len, "No DMAinfo?\n");
James Smart78b2d852007-08-02 11:10:21 -0400371 }
372skipit:
373 hbqe++;
374 if (len > LPFC_HBQINFO_SIZE - 54)
375 break;
376 }
377 spin_unlock_irq(&phba->hbalock);
378 return len;
379}
380
James Smart6a828b02019-01-28 11:14:31 -0800381static int lpfc_debugfs_last_xripool;
382
383/**
384 * lpfc_debugfs_common_xri_data - Dump Hardware Queue info to a buffer
385 * @phba: The HBA to gather host buffer 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 Hardware Queue info from the @phba to @buf up to
391 * @size number of bytes. A header that describes the current hdwq state will be
392 * dumped to @buf first and then info on each hdwq entry will be dumped to @buf
393 * until @size bytes have been dumped or all the hdwq info has been dumped.
394 *
395 * Notes:
396 * This routine will rotate through each configured Hardware Queue each
397 * time called.
398 *
399 * Return Value:
400 * This routine returns the amount of bytes that were dumped into @buf and will
401 * not exceed @size.
402 **/
403static int
404lpfc_debugfs_commonxripools_data(struct lpfc_hba *phba, char *buf, int size)
405{
406 struct lpfc_sli4_hdw_queue *qp;
407 int len = 0;
408 int i, out;
409 unsigned long iflag;
410
411 for (i = 0; i < phba->cfg_hdw_queue; i++) {
412 if (len > (LPFC_DUMP_MULTIXRIPOOL_SIZE - 80))
413 break;
414 qp = &phba->sli4_hba.hdwq[lpfc_debugfs_last_xripool];
415
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700416 len += scnprintf(buf + len, size - len, "HdwQ %d Info ", i);
James Smartc00f62e2019-08-14 16:57:11 -0700417 spin_lock_irqsave(&qp->abts_io_buf_list_lock, iflag);
James Smart6a828b02019-01-28 11:14:31 -0800418 spin_lock(&qp->io_buf_list_get_lock);
419 spin_lock(&qp->io_buf_list_put_lock);
420 out = qp->total_io_bufs - (qp->get_io_bufs + qp->put_io_bufs +
421 qp->abts_scsi_io_bufs + qp->abts_nvme_io_bufs);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700422 len += scnprintf(buf + len, size - len,
James Smart6a828b02019-01-28 11:14:31 -0800423 "tot:%d get:%d put:%d mt:%d "
424 "ABTS scsi:%d nvme:%d Out:%d\n",
425 qp->total_io_bufs, qp->get_io_bufs, qp->put_io_bufs,
426 qp->empty_io_bufs, qp->abts_scsi_io_bufs,
427 qp->abts_nvme_io_bufs, out);
428 spin_unlock(&qp->io_buf_list_put_lock);
429 spin_unlock(&qp->io_buf_list_get_lock);
James Smartc00f62e2019-08-14 16:57:11 -0700430 spin_unlock_irqrestore(&qp->abts_io_buf_list_lock, iflag);
James Smart6a828b02019-01-28 11:14:31 -0800431
432 lpfc_debugfs_last_xripool++;
433 if (lpfc_debugfs_last_xripool >= phba->cfg_hdw_queue)
434 lpfc_debugfs_last_xripool = 0;
435 }
436
437 return len;
438}
439
James Smartc4908502019-01-28 11:14:28 -0800440/**
441 * lpfc_debugfs_multixripools_data - Display multi-XRI pools information
442 * @phba: The HBA to gather host buffer info from.
443 * @buf: The buffer to dump log into.
444 * @size: The maximum amount of data to process.
445 *
446 * Description:
447 * This routine displays current multi-XRI pools information including XRI
448 * count in public, private and txcmplq. It also displays current high and
449 * low watermark.
450 *
451 * Return Value:
452 * This routine returns the amount of bytes that were dumped into @buf and will
453 * not exceed @size.
454 **/
455static int
456lpfc_debugfs_multixripools_data(struct lpfc_hba *phba, char *buf, int size)
457{
458 u32 i;
459 u32 hwq_count;
460 struct lpfc_sli4_hdw_queue *qp;
461 struct lpfc_multixri_pool *multixri_pool;
462 struct lpfc_pvt_pool *pvt_pool;
463 struct lpfc_pbl_pool *pbl_pool;
464 u32 txcmplq_cnt;
465 char tmp[LPFC_DEBUG_OUT_LINE_SZ] = {0};
466
James Smart6a828b02019-01-28 11:14:31 -0800467 if (phba->sli_rev != LPFC_SLI_REV4)
468 return 0;
469
470 if (!phba->sli4_hba.hdwq)
471 return 0;
472
473 if (!phba->cfg_xri_rebalancing) {
474 i = lpfc_debugfs_commonxripools_data(phba, buf, size);
475 return i;
476 }
477
James Smartc4908502019-01-28 11:14:28 -0800478 /*
479 * Pbl: Current number of free XRIs in public pool
480 * Pvt: Current number of free XRIs in private pool
481 * Busy: Current number of outstanding XRIs
482 * HWM: Current high watermark
483 * pvt_empty: Incremented by 1 when IO submission fails (no xri)
484 * pbl_empty: Incremented by 1 when all pbl_pool are empty during
485 * IO submission
486 */
487 scnprintf(tmp, sizeof(tmp),
488 "HWQ: Pbl Pvt Busy HWM | pvt_empty pbl_empty ");
489 if (strlcat(buf, tmp, size) >= size)
490 return strnlen(buf, size);
491
492#ifdef LPFC_MXP_STAT
493 /*
494 * MAXH: Max high watermark seen so far
495 * above_lmt: Incremented by 1 if xri_owned > xri_limit during
496 * IO submission
497 * below_lmt: Incremented by 1 if xri_owned <= xri_limit during
498 * IO submission
499 * locPbl_hit: Incremented by 1 if successfully get a batch of XRI from
500 * local pbl_pool
501 * othPbl_hit: Incremented by 1 if successfully get a batch of XRI from
502 * other pbl_pool
503 */
504 scnprintf(tmp, sizeof(tmp),
505 "MAXH above_lmt below_lmt locPbl_hit othPbl_hit");
506 if (strlcat(buf, tmp, size) >= size)
507 return strnlen(buf, size);
508
509 /*
510 * sPbl: snapshot of Pbl 15 sec after stat gets cleared
511 * sPvt: snapshot of Pvt 15 sec after stat gets cleared
512 * sBusy: snapshot of Busy 15 sec after stat gets cleared
513 */
514 scnprintf(tmp, sizeof(tmp),
515 " | sPbl sPvt sBusy");
516 if (strlcat(buf, tmp, size) >= size)
517 return strnlen(buf, size);
518#endif
519
520 scnprintf(tmp, sizeof(tmp), "\n");
521 if (strlcat(buf, tmp, size) >= size)
522 return strnlen(buf, size);
523
524 hwq_count = phba->cfg_hdw_queue;
525 for (i = 0; i < hwq_count; i++) {
526 qp = &phba->sli4_hba.hdwq[i];
527 multixri_pool = qp->p_multixri_pool;
528 if (!multixri_pool)
529 continue;
530 pbl_pool = &multixri_pool->pbl_pool;
531 pvt_pool = &multixri_pool->pvt_pool;
James Smartc00f62e2019-08-14 16:57:11 -0700532 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
James Smartc4908502019-01-28 11:14:28 -0800533
534 scnprintf(tmp, sizeof(tmp),
535 "%03d: %4d %4d %4d %4d | %10d %10d ",
536 i, pbl_pool->count, pvt_pool->count,
537 txcmplq_cnt, pvt_pool->high_watermark,
538 qp->empty_io_bufs, multixri_pool->pbl_empty_count);
539 if (strlcat(buf, tmp, size) >= size)
540 break;
541
542#ifdef LPFC_MXP_STAT
543 scnprintf(tmp, sizeof(tmp),
544 "%4d %10d %10d %10d %10d",
545 multixri_pool->stat_max_hwm,
546 multixri_pool->above_limit_count,
547 multixri_pool->below_limit_count,
548 multixri_pool->local_pbl_hit_count,
549 multixri_pool->other_pbl_hit_count);
550 if (strlcat(buf, tmp, size) >= size)
551 break;
552
553 scnprintf(tmp, sizeof(tmp),
554 " | %4d %4d %5d",
555 multixri_pool->stat_pbl_count,
556 multixri_pool->stat_pvt_count,
557 multixri_pool->stat_busy_count);
558 if (strlcat(buf, tmp, size) >= size)
559 break;
560#endif
561
562 scnprintf(tmp, sizeof(tmp), "\n");
563 if (strlcat(buf, tmp, size) >= size)
564 break;
565 }
566 return strnlen(buf, size);
567}
568
James Smart6a828b02019-01-28 11:14:31 -0800569
570#ifdef LPFC_HDWQ_LOCK_STAT
571static int lpfc_debugfs_last_lock;
James Smart5e5b5112019-01-28 11:14:22 -0800572
573/**
James Smart6a828b02019-01-28 11:14:31 -0800574 * lpfc_debugfs_lockstat_data - Dump Hardware Queue info to a buffer
James Smart5e5b5112019-01-28 11:14:22 -0800575 * @phba: The HBA to gather host buffer info from.
576 * @buf: The buffer to dump log into.
577 * @size: The maximum amount of data to process.
578 *
579 * Description:
580 * This routine dumps the Hardware Queue info from the @phba to @buf up to
581 * @size number of bytes. A header that describes the current hdwq state will be
582 * dumped to @buf first and then info on each hdwq entry will be dumped to @buf
583 * until @size bytes have been dumped or all the hdwq info has been dumped.
584 *
585 * Notes:
586 * This routine will rotate through each configured Hardware Queue each
587 * time called.
588 *
589 * Return Value:
590 * This routine returns the amount of bytes that were dumped into @buf and will
591 * not exceed @size.
592 **/
593static int
James Smart6a828b02019-01-28 11:14:31 -0800594lpfc_debugfs_lockstat_data(struct lpfc_hba *phba, char *buf, int size)
James Smart5e5b5112019-01-28 11:14:22 -0800595{
596 struct lpfc_sli4_hdw_queue *qp;
597 int len = 0;
James Smart6a828b02019-01-28 11:14:31 -0800598 int i;
James Smart5e5b5112019-01-28 11:14:22 -0800599
600 if (phba->sli_rev != LPFC_SLI_REV4)
601 return 0;
602
603 if (!phba->sli4_hba.hdwq)
604 return 0;
605
606 for (i = 0; i < phba->cfg_hdw_queue; i++) {
James Smart6a828b02019-01-28 11:14:31 -0800607 if (len > (LPFC_HDWQINFO_SIZE - 100))
James Smart5e5b5112019-01-28 11:14:22 -0800608 break;
James Smart6a828b02019-01-28 11:14:31 -0800609 qp = &phba->sli4_hba.hdwq[lpfc_debugfs_last_lock];
James Smart5e5b5112019-01-28 11:14:22 -0800610
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700611 len += scnprintf(buf + len, size - len, "HdwQ %03d Lock ", i);
James Smart6a828b02019-01-28 11:14:31 -0800612 if (phba->cfg_xri_rebalancing) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700613 len += scnprintf(buf + len, size - len,
James Smart6a828b02019-01-28 11:14:31 -0800614 "get_pvt:%d mv_pvt:%d "
615 "mv2pub:%d mv2pvt:%d "
616 "put_pvt:%d put_pub:%d wq:%d\n",
617 qp->lock_conflict.alloc_pvt_pool,
618 qp->lock_conflict.mv_from_pvt_pool,
619 qp->lock_conflict.mv_to_pub_pool,
620 qp->lock_conflict.mv_to_pvt_pool,
621 qp->lock_conflict.free_pvt_pool,
622 qp->lock_conflict.free_pub_pool,
623 qp->lock_conflict.wq_access);
624 } else {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700625 len += scnprintf(buf + len, size - len,
James Smart6a828b02019-01-28 11:14:31 -0800626 "get:%d put:%d free:%d wq:%d\n",
627 qp->lock_conflict.alloc_xri_get,
628 qp->lock_conflict.alloc_xri_put,
629 qp->lock_conflict.free_xri,
630 qp->lock_conflict.wq_access);
631 }
James Smart5e5b5112019-01-28 11:14:22 -0800632
James Smart6a828b02019-01-28 11:14:31 -0800633 lpfc_debugfs_last_lock++;
634 if (lpfc_debugfs_last_lock >= phba->cfg_hdw_queue)
635 lpfc_debugfs_last_lock = 0;
James Smart5e5b5112019-01-28 11:14:22 -0800636 }
637
638 return len;
639}
James Smart6a828b02019-01-28 11:14:31 -0800640#endif
James Smart5e5b5112019-01-28 11:14:22 -0800641
James Smartc95d6c62008-01-11 01:53:23 -0500642static int lpfc_debugfs_last_hba_slim_off;
643
James Smarte59058c2008-08-24 21:49:00 -0400644/**
James Smart3621a712009-04-06 18:47:14 -0400645 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400646 * @phba: The HBA to gather SLIM info from.
647 * @buf: The buffer to dump log into.
648 * @size: The maximum amount of data to process.
649 *
650 * Description:
651 * This routine dumps the current contents of HBA SLIM for the HBA associated
652 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
653 *
654 * Notes:
655 * This routine will only dump up to 1024 bytes of data each time called and
656 * should be called multiple times to dump the entire HBA SLIM.
657 *
658 * Return Value:
659 * This routine returns the amount of bytes that were dumped into @buf and will
660 * not exceed @size.
661 **/
James Smarta58cbd52007-08-02 11:09:43 -0400662static int
James Smartc95d6c62008-01-11 01:53:23 -0500663lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
James Smarta58cbd52007-08-02 11:09:43 -0400664{
665 int len = 0;
James Smartc95d6c62008-01-11 01:53:23 -0500666 int i, off;
667 uint32_t *ptr;
James Smartb76f2dc2011-07-22 18:37:42 -0400668 char *buffer;
669
670 buffer = kmalloc(1024, GFP_KERNEL);
671 if (!buffer)
672 return 0;
James Smartc95d6c62008-01-11 01:53:23 -0500673
674 off = 0;
675 spin_lock_irq(&phba->hbalock);
676
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700677 len += scnprintf(buf+len, size-len, "HBA SLIM\n");
James Smartc95d6c62008-01-11 01:53:23 -0500678 lpfc_memcpy_from_slim(buffer,
James Smarta257bf92009-04-06 18:48:10 -0400679 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
James Smartc95d6c62008-01-11 01:53:23 -0500680
681 ptr = (uint32_t *)&buffer[0];
682 off = lpfc_debugfs_last_hba_slim_off;
683
684 /* Set it up for the next time */
685 lpfc_debugfs_last_hba_slim_off += 1024;
686 if (lpfc_debugfs_last_hba_slim_off >= 4096)
687 lpfc_debugfs_last_hba_slim_off = 0;
688
689 i = 1024;
690 while (i > 0) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700691 len += scnprintf(buf+len, size-len,
James Smartc95d6c62008-01-11 01:53:23 -0500692 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
693 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
694 *(ptr+5), *(ptr+6), *(ptr+7));
695 ptr += 8;
696 i -= (8 * sizeof(uint32_t));
697 off += (8 * sizeof(uint32_t));
698 }
699
700 spin_unlock_irq(&phba->hbalock);
James Smartb76f2dc2011-07-22 18:37:42 -0400701 kfree(buffer);
702
James Smartc95d6c62008-01-11 01:53:23 -0500703 return len;
704}
705
James Smarte59058c2008-08-24 21:49:00 -0400706/**
James Smart3621a712009-04-06 18:47:14 -0400707 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400708 * @phba: The HBA to gather Host SLIM info from.
709 * @buf: The buffer to dump log into.
710 * @size: The maximum amount of data to process.
711 *
712 * Description:
713 * This routine dumps the current contents of host SLIM for the host associated
714 * with @phba to @buf up to @size bytes of data. The dump will contain the
715 * Mailbox, PCB, Rings, and Registers that are located in host memory.
716 *
717 * Return Value:
718 * This routine returns the amount of bytes that were dumped into @buf and will
719 * not exceed @size.
720 **/
James Smartc95d6c62008-01-11 01:53:23 -0500721static int
722lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
723{
724 int len = 0;
725 int i, off;
James Smarta58cbd52007-08-02 11:09:43 -0400726 uint32_t word0, word1, word2, word3;
727 uint32_t *ptr;
728 struct lpfc_pgp *pgpp;
729 struct lpfc_sli *psli = &phba->sli;
730 struct lpfc_sli_ring *pring;
731
James Smarta58cbd52007-08-02 11:09:43 -0400732 off = 0;
733 spin_lock_irq(&phba->hbalock);
734
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700735 len += scnprintf(buf+len, size-len, "SLIM Mailbox\n");
James Smart34b02dc2008-08-24 21:49:55 -0400736 ptr = (uint32_t *)phba->slim2p.virt;
James Smarta58cbd52007-08-02 11:09:43 -0400737 i = sizeof(MAILBOX_t);
738 while (i > 0) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700739 len += scnprintf(buf+len, size-len,
James Smarta58cbd52007-08-02 11:09:43 -0400740 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
741 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
742 *(ptr+5), *(ptr+6), *(ptr+7));
743 ptr += 8;
744 i -= (8 * sizeof(uint32_t));
745 off += (8 * sizeof(uint32_t));
746 }
747
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700748 len += scnprintf(buf+len, size-len, "SLIM PCB\n");
James Smart34b02dc2008-08-24 21:49:55 -0400749 ptr = (uint32_t *)phba->pcb;
James Smarta58cbd52007-08-02 11:09:43 -0400750 i = sizeof(PCB_t);
751 while (i > 0) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700752 len += scnprintf(buf+len, size-len,
James Smarta58cbd52007-08-02 11:09:43 -0400753 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
754 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
755 *(ptr+5), *(ptr+6), *(ptr+7));
756 ptr += 8;
757 i -= (8 * sizeof(uint32_t));
758 off += (8 * sizeof(uint32_t));
759 }
760
James Smart3772a992009-05-22 14:50:54 -0400761 if (phba->sli_rev <= LPFC_SLI_REV3) {
James Smart895427b2017-02-12 13:52:30 -0800762 for (i = 0; i < 4; i++) {
763 pgpp = &phba->port_gp[i];
764 pring = &psli->sli3_ring[i];
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700765 len += scnprintf(buf+len, size-len,
James Smart895427b2017-02-12 13:52:30 -0800766 "Ring %d: CMD GetInx:%d "
767 "(Max:%d Next:%d "
768 "Local:%d flg:x%x) "
769 "RSP PutInx:%d Max:%d\n",
770 i, pgpp->cmdGetInx,
771 pring->sli.sli3.numCiocb,
772 pring->sli.sli3.next_cmdidx,
773 pring->sli.sli3.local_getidx,
774 pring->flag, pgpp->rspPutInx,
775 pring->sli.sli3.numRiocb);
776 }
777
James Smart3772a992009-05-22 14:50:54 -0400778 word0 = readl(phba->HAregaddr);
779 word1 = readl(phba->CAregaddr);
780 word2 = readl(phba->HSregaddr);
781 word3 = readl(phba->HCregaddr);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700782 len += scnprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
James Smart3772a992009-05-22 14:50:54 -0400783 "HC:%08x\n", word0, word1, word2, word3);
784 }
James Smarta58cbd52007-08-02 11:09:43 -0400785 spin_unlock_irq(&phba->hbalock);
786 return len;
787}
788
James Smarte59058c2008-08-24 21:49:00 -0400789/**
James Smart3621a712009-04-06 18:47:14 -0400790 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
James Smarte59058c2008-08-24 21:49:00 -0400791 * @vport: The vport to gather target node info from.
792 * @buf: The buffer to dump log into.
793 * @size: The maximum amount of data to process.
794 *
795 * Description:
796 * This routine dumps the current target node list associated with @vport to
797 * @buf up to @size bytes of data. Each node entry in the dump will contain a
798 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
799 *
800 * Return Value:
801 * This routine returns the amount of bytes that were dumped into @buf and will
802 * not exceed @size.
803 **/
James Smarta58cbd52007-08-02 11:09:43 -0400804static int
James Smart858c9f62007-06-17 19:56:39 -0500805lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
806{
807 int len = 0;
James Smartf91bc592018-04-09 14:24:22 -0700808 int i, iocnt, outio, cnt;
James Smart858c9f62007-06-17 19:56:39 -0500809 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2b65e182017-02-12 13:52:38 -0800810 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -0500811 struct lpfc_nodelist *ndlp;
James Smart2ea259e2017-02-12 13:52:27 -0800812 unsigned char *statep;
James Smartbd2cdd52017-02-12 13:52:33 -0800813 struct nvme_fc_local_port *localport;
James Smart9e210172018-09-13 15:41:10 -0700814 struct nvme_fc_remote_port *nrport = NULL;
James Smart01466022018-04-09 14:24:27 -0700815 struct lpfc_nvme_rport *rport;
James Smart858c9f62007-06-17 19:56:39 -0500816
817 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
James Smartf91bc592018-04-09 14:24:22 -0700818 outio = 0;
James Smart858c9f62007-06-17 19:56:39 -0500819
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700820 len += scnprintf(buf+len, size-len, "\nFCP Nodelist Entries ...\n");
James Smart858c9f62007-06-17 19:56:39 -0500821 spin_lock_irq(shost->host_lock);
822 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smartf91bc592018-04-09 14:24:22 -0700823 iocnt = 0;
James Smart858c9f62007-06-17 19:56:39 -0500824 if (!cnt) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700825 len += scnprintf(buf+len, size-len,
James Smart858c9f62007-06-17 19:56:39 -0500826 "Missing Nodelist Entries\n");
827 break;
828 }
829 cnt--;
830 switch (ndlp->nlp_state) {
831 case NLP_STE_UNUSED_NODE:
832 statep = "UNUSED";
833 break;
834 case NLP_STE_PLOGI_ISSUE:
835 statep = "PLOGI ";
836 break;
837 case NLP_STE_ADISC_ISSUE:
838 statep = "ADISC ";
839 break;
840 case NLP_STE_REG_LOGIN_ISSUE:
841 statep = "REGLOG";
842 break;
843 case NLP_STE_PRLI_ISSUE:
844 statep = "PRLI ";
845 break;
James Smart086a3452012-08-14 14:25:21 -0400846 case NLP_STE_LOGO_ISSUE:
847 statep = "LOGO ";
848 break;
James Smart858c9f62007-06-17 19:56:39 -0500849 case NLP_STE_UNMAPPED_NODE:
850 statep = "UNMAP ";
James Smartf91bc592018-04-09 14:24:22 -0700851 iocnt = 1;
James Smart858c9f62007-06-17 19:56:39 -0500852 break;
853 case NLP_STE_MAPPED_NODE:
854 statep = "MAPPED";
James Smartf91bc592018-04-09 14:24:22 -0700855 iocnt = 1;
James Smart858c9f62007-06-17 19:56:39 -0500856 break;
857 case NLP_STE_NPR_NODE:
858 statep = "NPR ";
859 break;
860 default:
861 statep = "UNKNOWN";
862 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700863 len += scnprintf(buf+len, size-len, "%s DID:x%06x ",
James Smart2ea259e2017-02-12 13:52:27 -0800864 statep, ndlp->nlp_DID);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700865 len += scnprintf(buf+len, size-len,
James Smart2ea259e2017-02-12 13:52:27 -0800866 "WWPN x%llx ",
867 wwn_to_u64(ndlp->nlp_portname.u.wwn));
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700868 len += scnprintf(buf+len, size-len,
James Smart2ea259e2017-02-12 13:52:27 -0800869 "WWNN x%llx ",
870 wwn_to_u64(ndlp->nlp_nodename.u.wwn));
James Smart086a3452012-08-14 14:25:21 -0400871 if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700872 len += scnprintf(buf+len, size-len, "RPI:%03d ",
James Smart2ea259e2017-02-12 13:52:27 -0800873 ndlp->nlp_rpi);
James Smart086a3452012-08-14 14:25:21 -0400874 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700875 len += scnprintf(buf+len, size-len, "RPI:none ");
876 len += scnprintf(buf+len, size-len, "flag:x%08x ",
James Smart086a3452012-08-14 14:25:21 -0400877 ndlp->nlp_flag);
James Smart858c9f62007-06-17 19:56:39 -0500878 if (!ndlp->nlp_type)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700879 len += scnprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500880 if (ndlp->nlp_type & NLP_FC_NODE)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700881 len += scnprintf(buf+len, size-len, "FC_NODE ");
James Smartf91bc592018-04-09 14:24:22 -0700882 if (ndlp->nlp_type & NLP_FABRIC) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700883 len += scnprintf(buf+len, size-len, "FABRIC ");
James Smartf91bc592018-04-09 14:24:22 -0700884 iocnt = 0;
885 }
James Smart858c9f62007-06-17 19:56:39 -0500886 if (ndlp->nlp_type & NLP_FCP_TARGET)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700887 len += scnprintf(buf+len, size-len, "FCP_TGT sid:%d ",
James Smart858c9f62007-06-17 19:56:39 -0500888 ndlp->nlp_sid);
889 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700890 len += scnprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart7d790f02017-06-01 21:06:57 -0700891 if (ndlp->nlp_type & NLP_NVME_TARGET)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700892 len += scnprintf(buf + len,
James Smart7d790f02017-06-01 21:06:57 -0700893 size - len, "NVME_TGT sid:%d ",
894 NLP_NO_SID);
895 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700896 len += scnprintf(buf + len,
James Smart7d790f02017-06-01 21:06:57 -0700897 size - len, "NVME_INITIATOR ");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700898 len += scnprintf(buf+len, size-len, "usgmap:%x ",
James Smart58da1ff2008-04-07 10:15:56 -0400899 ndlp->nlp_usg_map);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700900 len += scnprintf(buf+len, size-len, "refcnt:%x",
Peter Zijlstra2c935bc2016-11-14 17:29:48 +0100901 kref_read(&ndlp->kref));
James Smartf91bc592018-04-09 14:24:22 -0700902 if (iocnt) {
903 i = atomic_read(&ndlp->cmd_pending);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700904 len += scnprintf(buf + len, size - len,
James Smartf91bc592018-04-09 14:24:22 -0700905 " OutIO:x%x Qdepth x%x",
906 i, ndlp->cmd_qdepth);
907 outio += i;
908 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700909 len += scnprintf(buf + len, size - len, "defer:%x ",
James Smartdea16bd2018-11-29 16:09:30 -0800910 ndlp->nlp_defer_did);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700911 len += scnprintf(buf+len, size-len, "\n");
James Smart858c9f62007-06-17 19:56:39 -0500912 }
913 spin_unlock_irq(shost->host_lock);
James Smart2ea259e2017-02-12 13:52:27 -0800914
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700915 len += scnprintf(buf + len, size - len,
James Smartf91bc592018-04-09 14:24:22 -0700916 "\nOutstanding IO x%x\n", outio);
917
James Smart2b65e182017-02-12 13:52:38 -0800918 if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700919 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -0800920 "\nNVME Targetport Entry ...\n");
921
922 /* Port state is only one of two values for now. */
923 if (phba->targetport->port_id)
924 statep = "REGISTERED";
925 else
926 statep = "INIT";
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700927 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -0800928 "TGT WWNN x%llx WWPN x%llx State %s\n",
929 wwn_to_u64(vport->fc_nodename.u.wwn),
930 wwn_to_u64(vport->fc_portname.u.wwn),
931 statep);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700932 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -0800933 " Targetport DID x%06x\n",
934 phba->targetport->port_id);
935 goto out_exit;
936 }
937
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700938 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -0800939 "\nNVME Lport/Rport Entries ...\n");
940
941 localport = vport->localport;
942 if (!localport)
943 goto out_exit;
944
945 spin_lock_irq(shost->host_lock);
James Smartbd2cdd52017-02-12 13:52:33 -0800946
947 /* Port state is only one of two values for now. */
948 if (localport->port_id)
949 statep = "ONLINE";
950 else
951 statep = "UNKNOWN ";
952
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700953 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -0800954 "Lport DID x%06x PortState %s\n",
955 localport->port_id, statep);
956
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700957 len += scnprintf(buf + len, size - len, "\tRport List:\n");
James Smart80cc0042017-06-01 21:06:56 -0700958 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smartbd2cdd52017-02-12 13:52:33 -0800959 /* local short-hand pointer. */
James Smart9e210172018-09-13 15:41:10 -0700960 spin_lock(&phba->hbalock);
James Smart01466022018-04-09 14:24:27 -0700961 rport = lpfc_ndlp_get_nrport(ndlp);
James Smart9e210172018-09-13 15:41:10 -0700962 if (rport)
963 nrport = rport->remoteport;
Arnd Bergmannf8d29432018-11-02 16:35:48 +0100964 else
965 nrport = NULL;
James Smart9e210172018-09-13 15:41:10 -0700966 spin_unlock(&phba->hbalock);
James Smart01466022018-04-09 14:24:27 -0700967 if (!nrport)
968 continue;
James Smartbd2cdd52017-02-12 13:52:33 -0800969
970 /* Port state is only one of two values for now. */
971 switch (nrport->port_state) {
972 case FC_OBJSTATE_ONLINE:
973 statep = "ONLINE";
974 break;
975 case FC_OBJSTATE_UNKNOWN:
976 statep = "UNKNOWN ";
977 break;
978 default:
979 statep = "UNSUPPORTED";
980 break;
981 }
982
983 /* Tab in to show lport ownership. */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700984 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -0800985 "\t%s Port ID:x%06x ",
986 statep, nrport->port_id);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700987 len += scnprintf(buf + len, size - len, "WWPN x%llx ",
James Smartbd2cdd52017-02-12 13:52:33 -0800988 nrport->port_name);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700989 len += scnprintf(buf + len, size - len, "WWNN x%llx ",
James Smartbd2cdd52017-02-12 13:52:33 -0800990 nrport->node_name);
James Smart7d790f02017-06-01 21:06:57 -0700991
992 /* An NVME rport can have multiple roles. */
993 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700994 len += scnprintf(buf + len, size - len,
James Smart7d790f02017-06-01 21:06:57 -0700995 "INITIATOR ");
996 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700997 len += scnprintf(buf + len, size - len,
James Smart7d790f02017-06-01 21:06:57 -0700998 "TARGET ");
999 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001000 len += scnprintf(buf + len, size - len,
James Smart7d790f02017-06-01 21:06:57 -07001001 "DISCSRVC ");
1002 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
1003 FC_PORT_ROLE_NVME_TARGET |
1004 FC_PORT_ROLE_NVME_DISCOVERY))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001005 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001006 "UNKNOWN ROLE x%x",
1007 nrport->port_role);
James Smartbd2cdd52017-02-12 13:52:33 -08001008 /* Terminate the string. */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001009 len += scnprintf(buf + len, size - len, "\n");
James Smartbd2cdd52017-02-12 13:52:33 -08001010 }
1011
1012 spin_unlock_irq(shost->host_lock);
1013 out_exit:
1014 return len;
1015}
1016
1017/**
1018 * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
1019 * @vport: The vport to gather target node info from.
1020 * @buf: The buffer to dump log into.
1021 * @size: The maximum amount of data to process.
1022 *
1023 * Description:
1024 * This routine dumps the NVME statistics associated with @vport
1025 *
1026 * Return Value:
1027 * This routine returns the amount of bytes that were dumped into @buf and will
1028 * not exceed @size.
1029 **/
1030static int
1031lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
1032{
1033 struct lpfc_hba *phba = vport->phba;
James Smart2b65e182017-02-12 13:52:38 -08001034 struct lpfc_nvmet_tgtport *tgtp;
James Smart7cacae22020-03-31 09:50:03 -07001035 struct lpfc_async_xchg_ctx *ctxp, *next_ctxp;
James Smart4b056682017-12-08 17:18:10 -08001036 struct nvme_fc_local_port *localport;
James Smart4c47efc2019-01-28 11:14:25 -08001037 struct lpfc_fc4_ctrl_stat *cstat;
James Smart4b056682017-12-08 17:18:10 -08001038 struct lpfc_nvme_lport *lport;
James Smart66a210f2018-04-09 14:24:23 -07001039 uint64_t data1, data2, data3;
1040 uint64_t tot, totin, totout;
James Smart6a828b02019-01-28 11:14:31 -08001041 int cnt, i;
James Smartbd2cdd52017-02-12 13:52:33 -08001042 int len = 0;
1043
James Smart2b65e182017-02-12 13:52:38 -08001044 if (phba->nvmet_support) {
1045 if (!phba->targetport)
1046 return len;
1047 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001048 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001049 "\nNVME Targetport Statistics\n");
1050
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001051 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001052 "LS: Rcv %08x Drop %08x Abort %08x\n",
1053 atomic_read(&tgtp->rcv_ls_req_in),
1054 atomic_read(&tgtp->rcv_ls_req_drop),
1055 atomic_read(&tgtp->xmt_ls_abort));
1056 if (atomic_read(&tgtp->rcv_ls_req_in) !=
1057 atomic_read(&tgtp->rcv_ls_req_out)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001058 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001059 "Rcv LS: in %08x != out %08x\n",
1060 atomic_read(&tgtp->rcv_ls_req_in),
1061 atomic_read(&tgtp->rcv_ls_req_out));
1062 }
1063
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001064 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001065 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
James Smart2b65e182017-02-12 13:52:38 -08001066 atomic_read(&tgtp->xmt_ls_rsp),
1067 atomic_read(&tgtp->xmt_ls_drop),
James Smart4b056682017-12-08 17:18:10 -08001068 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
1069
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001070 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001071 "LS: RSP Abort %08x xb %08x Err %08x\n",
1072 atomic_read(&tgtp->xmt_ls_rsp_aborted),
1073 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
James Smart2b65e182017-02-12 13:52:38 -08001074 atomic_read(&tgtp->xmt_ls_rsp_error));
1075
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001076 len += scnprintf(buf + len, size - len,
James Smart50738422017-08-01 15:12:40 -07001077 "FCP: Rcv %08x Defer %08x Release %08x "
1078 "Drop %08x\n",
James Smart2b65e182017-02-12 13:52:38 -08001079 atomic_read(&tgtp->rcv_fcp_cmd_in),
James Smart50738422017-08-01 15:12:40 -07001080 atomic_read(&tgtp->rcv_fcp_cmd_defer),
1081 atomic_read(&tgtp->xmt_fcp_release),
James Smart2b65e182017-02-12 13:52:38 -08001082 atomic_read(&tgtp->rcv_fcp_cmd_drop));
1083
1084 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
1085 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001086 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001087 "Rcv FCP: in %08x != out %08x\n",
1088 atomic_read(&tgtp->rcv_fcp_cmd_in),
1089 atomic_read(&tgtp->rcv_fcp_cmd_out));
1090 }
1091
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001092 len += scnprintf(buf + len, size - len,
James Smart86c67372017-04-21 16:05:04 -07001093 "FCP Rsp: read %08x readrsp %08x "
1094 "write %08x rsp %08x\n",
James Smart2b65e182017-02-12 13:52:38 -08001095 atomic_read(&tgtp->xmt_fcp_read),
1096 atomic_read(&tgtp->xmt_fcp_read_rsp),
1097 atomic_read(&tgtp->xmt_fcp_write),
1098 atomic_read(&tgtp->xmt_fcp_rsp));
1099
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001100 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001101 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
1102 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
1103 atomic_read(&tgtp->xmt_fcp_rsp_error),
1104 atomic_read(&tgtp->xmt_fcp_rsp_drop));
1105
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001106 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001107 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
1108 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
1109 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
1110 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
1111
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001112 len += scnprintf(buf + len, size - len,
James Smart547077a2017-05-15 15:20:40 -07001113 "ABORT: Xmt %08x Cmpl %08x\n",
1114 atomic_read(&tgtp->xmt_fcp_abort),
1115 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
1116
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001117 len += scnprintf(buf + len, size - len,
James Smart547077a2017-05-15 15:20:40 -07001118 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
1119 atomic_read(&tgtp->xmt_abort_sol),
1120 atomic_read(&tgtp->xmt_abort_unsol),
James Smart2b65e182017-02-12 13:52:38 -08001121 atomic_read(&tgtp->xmt_abort_rsp),
James Smart547077a2017-05-15 15:20:40 -07001122 atomic_read(&tgtp->xmt_abort_rsp_error));
James Smart2b65e182017-02-12 13:52:38 -08001123
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001124 len += scnprintf(buf + len, size - len, "\n");
James Smart86c67372017-04-21 16:05:04 -07001125
1126 cnt = 0;
James Smart5e5b5112019-01-28 11:14:22 -08001127 spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001128 list_for_each_entry_safe(ctxp, next_ctxp,
1129 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1130 list) {
1131 cnt++;
1132 }
James Smart5e5b5112019-01-28 11:14:22 -08001133 spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001134 if (cnt) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001135 len += scnprintf(buf + len, size - len,
James Smart86c67372017-04-21 16:05:04 -07001136 "ABORT: %d ctx entries\n", cnt);
James Smart5e5b5112019-01-28 11:14:22 -08001137 spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001138 list_for_each_entry_safe(ctxp, next_ctxp,
1139 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1140 list) {
1141 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
1142 break;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001143 len += scnprintf(buf + len, size - len,
James Smart86c67372017-04-21 16:05:04 -07001144 "Entry: oxid %x state %x "
1145 "flag %x\n",
1146 ctxp->oxid, ctxp->state,
1147 ctxp->flag);
1148 }
James Smart5e5b5112019-01-28 11:14:22 -08001149 spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001150 }
James Smarta8cf5df2017-05-15 15:20:46 -07001151
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001152 /* Calculate outstanding IOs */
1153 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1154 tot += atomic_read(&tgtp->xmt_fcp_release);
1155 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart2cee7802017-06-01 21:07:02 -07001156
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001157 len += scnprintf(buf + len, size - len,
James Smart2cee7802017-06-01 21:07:02 -07001158 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
1159 "CTX Outstanding %08llx\n",
James Smart966bb5b2017-06-15 22:56:45 -07001160 phba->sli4_hba.nvmet_xri_cnt,
James Smarta8cf5df2017-05-15 15:20:46 -07001161 phba->sli4_hba.nvmet_io_wait_cnt,
James Smart2cee7802017-06-01 21:07:02 -07001162 phba->sli4_hba.nvmet_io_wait_total,
1163 tot);
James Smart2b65e182017-02-12 13:52:38 -08001164 } else {
James Smartf6e84792019-01-28 11:14:38 -08001165 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
James Smartbd2cdd52017-02-12 13:52:33 -08001166 return len;
1167
James Smart4b056682017-12-08 17:18:10 -08001168 localport = vport->localport;
1169 if (!localport)
1170 return len;
1171 lport = (struct lpfc_nvme_lport *)localport->private;
1172 if (!lport)
1173 return len;
1174
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001175 len += scnprintf(buf + len, size - len,
James Smart4c47efc2019-01-28 11:14:25 -08001176 "\nNVME HDWQ Statistics\n");
James Smart66a210f2018-04-09 14:24:23 -07001177
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001178 len += scnprintf(buf + len, size - len,
James Smart66a210f2018-04-09 14:24:23 -07001179 "LS: Xmt %016x Cmpl %016x\n",
1180 atomic_read(&lport->fc4NvmeLsRequests),
1181 atomic_read(&lport->fc4NvmeLsCmpls));
1182
James Smart66a210f2018-04-09 14:24:23 -07001183 totin = 0;
1184 totout = 0;
James Smartcdb42be2019-01-28 11:14:21 -08001185 for (i = 0; i < phba->cfg_hdw_queue; i++) {
James Smart4c47efc2019-01-28 11:14:25 -08001186 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
1187 tot = cstat->io_cmpls;
James Smart66a210f2018-04-09 14:24:23 -07001188 totin += tot;
James Smart4c47efc2019-01-28 11:14:25 -08001189 data1 = cstat->input_requests;
1190 data2 = cstat->output_requests;
1191 data3 = cstat->control_requests;
James Smart66a210f2018-04-09 14:24:23 -07001192 totout += (data1 + data2 + data3);
1193
1194 /* Limit to 32, debugfs display buffer limitation */
1195 if (i >= 32)
1196 continue;
1197
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001198 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart4c47efc2019-01-28 11:14:25 -08001199 "HDWQ (%d): Rd %016llx Wr %016llx "
James Smart66a210f2018-04-09 14:24:23 -07001200 "IO %016llx ",
1201 i, data1, data2, data3);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001202 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart66a210f2018-04-09 14:24:23 -07001203 "Cmpl %016llx OutIO %016llx\n",
1204 tot, ((data1 + data2 + data3) - tot));
1205 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001206 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart66a210f2018-04-09 14:24:23 -07001207 "Total FCP Cmpl %016llx Issue %016llx "
1208 "OutIO %016llx\n",
1209 totin, totout, totout - totin);
1210
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001211 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001212 "LS Xmt Err: Abrt %08x Err %08x "
1213 "Cmpl Err: xb %08x Err %08x\n",
1214 atomic_read(&lport->xmt_ls_abort),
1215 atomic_read(&lport->xmt_ls_err),
1216 atomic_read(&lport->cmpl_ls_xb),
1217 atomic_read(&lport->cmpl_ls_err));
1218
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001219 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001220 "FCP Xmt Err: noxri %06x nondlp %06x "
James Smart44c27572018-05-04 20:37:56 -07001221 "qdepth %06x wqerr %06x err %06x Abrt %06x\n",
James Smart4b056682017-12-08 17:18:10 -08001222 atomic_read(&lport->xmt_fcp_noxri),
1223 atomic_read(&lport->xmt_fcp_bad_ndlp),
1224 atomic_read(&lport->xmt_fcp_qdepth),
1225 atomic_read(&lport->xmt_fcp_wqerr),
James Smart44c27572018-05-04 20:37:56 -07001226 atomic_read(&lport->xmt_fcp_err),
James Smart4b056682017-12-08 17:18:10 -08001227 atomic_read(&lport->xmt_fcp_abort));
1228
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001229 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001230 "FCP Cmpl Err: xb %08x Err %08x\n",
1231 atomic_read(&lport->cmpl_fcp_xb),
1232 atomic_read(&lport->cmpl_fcp_err));
1233
James Smartbd2cdd52017-02-12 13:52:33 -08001234 }
1235
1236 return len;
1237}
1238
James Smart4c47efc2019-01-28 11:14:25 -08001239/**
1240 * lpfc_debugfs_scsistat_data - Dump target node list to a buffer
1241 * @vport: The vport to gather target node info from.
1242 * @buf: The buffer to dump log into.
1243 * @size: The maximum amount of data to process.
1244 *
1245 * Description:
1246 * This routine dumps the SCSI statistics associated with @vport
1247 *
1248 * Return Value:
1249 * This routine returns the amount of bytes that were dumped into @buf and will
1250 * not exceed @size.
1251 **/
1252static int
1253lpfc_debugfs_scsistat_data(struct lpfc_vport *vport, char *buf, int size)
1254{
1255 int len;
1256 struct lpfc_hba *phba = vport->phba;
1257 struct lpfc_fc4_ctrl_stat *cstat;
1258 u64 data1, data2, data3;
1259 u64 tot, totin, totout;
1260 int i;
1261 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
1262
James Smartf6e84792019-01-28 11:14:38 -08001263 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
James Smart4c47efc2019-01-28 11:14:25 -08001264 (phba->sli_rev != LPFC_SLI_REV4))
1265 return 0;
1266
1267 scnprintf(buf, size, "SCSI HDWQ Statistics\n");
1268
1269 totin = 0;
1270 totout = 0;
1271 for (i = 0; i < phba->cfg_hdw_queue; i++) {
1272 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
1273 tot = cstat->io_cmpls;
1274 totin += tot;
1275 data1 = cstat->input_requests;
1276 data2 = cstat->output_requests;
1277 data3 = cstat->control_requests;
1278 totout += (data1 + data2 + data3);
1279
1280 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
1281 "IO %016llx ", i, data1, data2, data3);
1282 if (strlcat(buf, tmp, size) >= size)
1283 goto buffer_done;
1284
1285 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
1286 tot, ((data1 + data2 + data3) - tot));
1287 if (strlcat(buf, tmp, size) >= size)
1288 goto buffer_done;
1289 }
1290 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
1291 "OutIO %016llx\n", totin, totout, totout - totin);
1292 strlcat(buf, tmp, size);
1293
1294buffer_done:
1295 len = strnlen(buf, size);
1296
1297 return len;
1298}
James Smartbd2cdd52017-02-12 13:52:33 -08001299
James Smart2fcbc562020-03-22 11:13:02 -07001300void
1301lpfc_io_ktime(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
1302{
1303 uint64_t seg1, seg2, seg3, seg4;
1304 uint64_t segsum;
1305
1306 if (!lpfc_cmd->ts_last_cmd ||
1307 !lpfc_cmd->ts_cmd_start ||
1308 !lpfc_cmd->ts_cmd_wqput ||
1309 !lpfc_cmd->ts_isr_cmpl ||
1310 !lpfc_cmd->ts_data_io)
1311 return;
1312
1313 if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_cmd_start)
1314 return;
1315 if (lpfc_cmd->ts_cmd_start < lpfc_cmd->ts_last_cmd)
1316 return;
1317 if (lpfc_cmd->ts_cmd_wqput < lpfc_cmd->ts_cmd_start)
1318 return;
1319 if (lpfc_cmd->ts_isr_cmpl < lpfc_cmd->ts_cmd_wqput)
1320 return;
1321 if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_isr_cmpl)
1322 return;
1323 /*
1324 * Segment 1 - Time from Last FCP command cmpl is handed
1325 * off to NVME Layer to start of next command.
1326 * Segment 2 - Time from Driver receives a IO cmd start
1327 * from NVME Layer to WQ put is done on IO cmd.
1328 * Segment 3 - Time from Driver WQ put is done on IO cmd
1329 * to MSI-X ISR for IO cmpl.
1330 * Segment 4 - Time from MSI-X ISR for IO cmpl to when
1331 * cmpl is handled off to the NVME Layer.
1332 */
1333 seg1 = lpfc_cmd->ts_cmd_start - lpfc_cmd->ts_last_cmd;
1334 if (seg1 > 5000000) /* 5 ms - for sequential IOs only */
1335 seg1 = 0;
1336
1337 /* Calculate times relative to start of IO */
1338 seg2 = (lpfc_cmd->ts_cmd_wqput - lpfc_cmd->ts_cmd_start);
1339 segsum = seg2;
1340 seg3 = lpfc_cmd->ts_isr_cmpl - lpfc_cmd->ts_cmd_start;
1341 if (segsum > seg3)
1342 return;
1343 seg3 -= segsum;
1344 segsum += seg3;
1345
1346 seg4 = lpfc_cmd->ts_data_io - lpfc_cmd->ts_cmd_start;
1347 if (segsum > seg4)
1348 return;
1349 seg4 -= segsum;
1350
1351 phba->ktime_data_samples++;
1352 phba->ktime_seg1_total += seg1;
1353 if (seg1 < phba->ktime_seg1_min)
1354 phba->ktime_seg1_min = seg1;
1355 else if (seg1 > phba->ktime_seg1_max)
1356 phba->ktime_seg1_max = seg1;
1357 phba->ktime_seg2_total += seg2;
1358 if (seg2 < phba->ktime_seg2_min)
1359 phba->ktime_seg2_min = seg2;
1360 else if (seg2 > phba->ktime_seg2_max)
1361 phba->ktime_seg2_max = seg2;
1362 phba->ktime_seg3_total += seg3;
1363 if (seg3 < phba->ktime_seg3_min)
1364 phba->ktime_seg3_min = seg3;
1365 else if (seg3 > phba->ktime_seg3_max)
1366 phba->ktime_seg3_max = seg3;
1367 phba->ktime_seg4_total += seg4;
1368 if (seg4 < phba->ktime_seg4_min)
1369 phba->ktime_seg4_min = seg4;
1370 else if (seg4 > phba->ktime_seg4_max)
1371 phba->ktime_seg4_max = seg4;
1372
1373 lpfc_cmd->ts_last_cmd = 0;
1374 lpfc_cmd->ts_cmd_start = 0;
1375 lpfc_cmd->ts_cmd_wqput = 0;
1376 lpfc_cmd->ts_isr_cmpl = 0;
1377 lpfc_cmd->ts_data_io = 0;
1378}
1379
James Smartbd2cdd52017-02-12 13:52:33 -08001380/**
James Smart2fcbc562020-03-22 11:13:02 -07001381 * lpfc_debugfs_ioktime_data - Dump target node list to a buffer
James Smartbd2cdd52017-02-12 13:52:33 -08001382 * @vport: The vport to gather target node info from.
1383 * @buf: The buffer to dump log into.
1384 * @size: The maximum amount of data to process.
1385 *
1386 * Description:
1387 * This routine dumps the NVME statistics associated with @vport
1388 *
1389 * Return Value:
1390 * This routine returns the amount of bytes that were dumped into @buf and will
1391 * not exceed @size.
1392 **/
1393static int
James Smart2fcbc562020-03-22 11:13:02 -07001394lpfc_debugfs_ioktime_data(struct lpfc_vport *vport, char *buf, int size)
James Smartbd2cdd52017-02-12 13:52:33 -08001395{
1396 struct lpfc_hba *phba = vport->phba;
1397 int len = 0;
1398
1399 if (phba->nvmet_support == 0) {
James Smart2fcbc562020-03-22 11:13:02 -07001400 /* Initiator */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001401 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001402 "ktime %s: Total Samples: %lld\n",
1403 (phba->ktime_on ? "Enabled" : "Disabled"),
1404 phba->ktime_data_samples);
1405 if (phba->ktime_data_samples == 0)
1406 return len;
1407
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001408 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001409 buf + len, PAGE_SIZE - len,
James Smart2fcbc562020-03-22 11:13:02 -07001410 "Segment 1: Last Cmd cmpl "
1411 "done -to- Start of next Cmd (in driver)\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001412 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001413 buf + len, PAGE_SIZE - len,
1414 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001415 div_u64(phba->ktime_seg1_total,
1416 phba->ktime_data_samples),
James Smartbd2cdd52017-02-12 13:52:33 -08001417 phba->ktime_seg1_min,
1418 phba->ktime_seg1_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001419 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001420 buf + len, PAGE_SIZE - len,
James Smart2fcbc562020-03-22 11:13:02 -07001421 "Segment 2: Driver start of Cmd "
James Smartbd2cdd52017-02-12 13:52:33 -08001422 "-to- Firmware WQ doorbell\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001423 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001424 buf + len, PAGE_SIZE - len,
1425 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001426 div_u64(phba->ktime_seg2_total,
1427 phba->ktime_data_samples),
James Smartbd2cdd52017-02-12 13:52:33 -08001428 phba->ktime_seg2_min,
1429 phba->ktime_seg2_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001430 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001431 buf + len, PAGE_SIZE - len,
1432 "Segment 3: Firmware WQ doorbell -to- "
1433 "MSI-X ISR cmpl\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001434 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001435 buf + len, PAGE_SIZE - len,
1436 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001437 div_u64(phba->ktime_seg3_total,
1438 phba->ktime_data_samples),
James Smartbd2cdd52017-02-12 13:52:33 -08001439 phba->ktime_seg3_min,
1440 phba->ktime_seg3_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001441 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001442 buf + len, PAGE_SIZE - len,
1443 "Segment 4: MSI-X ISR cmpl -to- "
James Smart2fcbc562020-03-22 11:13:02 -07001444 "Cmd cmpl done\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001445 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001446 buf + len, PAGE_SIZE - len,
1447 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001448 div_u64(phba->ktime_seg4_total,
1449 phba->ktime_data_samples),
James Smartbd2cdd52017-02-12 13:52:33 -08001450 phba->ktime_seg4_min,
1451 phba->ktime_seg4_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001452 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001453 buf + len, PAGE_SIZE - len,
1454 "Total IO avg time: %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001455 div_u64(phba->ktime_seg1_total +
James Smartbd2cdd52017-02-12 13:52:33 -08001456 phba->ktime_seg2_total +
1457 phba->ktime_seg3_total +
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001458 phba->ktime_seg4_total,
James Smartbd2cdd52017-02-12 13:52:33 -08001459 phba->ktime_data_samples));
1460 return len;
1461 }
James Smart2b65e182017-02-12 13:52:38 -08001462
1463 /* NVME Target */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001464 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001465 "ktime %s: Total Samples: %lld %lld\n",
1466 (phba->ktime_on ? "Enabled" : "Disabled"),
1467 phba->ktime_data_samples,
1468 phba->ktime_status_samples);
1469 if (phba->ktime_data_samples == 0)
1470 return len;
1471
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001472 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001473 "Segment 1: MSI-X ISR Rcv cmd -to- "
1474 "cmd pass to NVME Layer\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001475 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001476 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001477 div_u64(phba->ktime_seg1_total,
1478 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001479 phba->ktime_seg1_min,
1480 phba->ktime_seg1_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001481 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001482 "Segment 2: cmd pass to NVME Layer- "
1483 "-to- Driver rcv cmd OP (action)\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001484 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001485 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001486 div_u64(phba->ktime_seg2_total,
1487 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001488 phba->ktime_seg2_min,
1489 phba->ktime_seg2_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001490 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001491 "Segment 3: Driver rcv cmd OP -to- "
1492 "Firmware WQ doorbell: cmd\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001493 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001494 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001495 div_u64(phba->ktime_seg3_total,
1496 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001497 phba->ktime_seg3_min,
1498 phba->ktime_seg3_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001499 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001500 "Segment 4: Firmware WQ doorbell: cmd "
1501 "-to- MSI-X ISR for cmd cmpl\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001502 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001503 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001504 div_u64(phba->ktime_seg4_total,
1505 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001506 phba->ktime_seg4_min,
1507 phba->ktime_seg4_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001508 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001509 "Segment 5: MSI-X ISR for cmd cmpl "
1510 "-to- NVME layer passed cmd done\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001511 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001512 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001513 div_u64(phba->ktime_seg5_total,
1514 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001515 phba->ktime_seg5_min,
1516 phba->ktime_seg5_max);
1517
1518 if (phba->ktime_status_samples == 0) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001519 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001520 "Total: cmd received by MSI-X ISR "
1521 "-to- cmd completed on wire\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001522 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001523 "avg:%08lld min:%08lld "
1524 "max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001525 div_u64(phba->ktime_seg10_total,
1526 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001527 phba->ktime_seg10_min,
1528 phba->ktime_seg10_max);
1529 return len;
1530 }
1531
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001532 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001533 "Segment 6: NVME layer passed cmd done "
1534 "-to- Driver rcv rsp status OP\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001535 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001536 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001537 div_u64(phba->ktime_seg6_total,
1538 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001539 phba->ktime_seg6_min,
1540 phba->ktime_seg6_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001541 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001542 "Segment 7: Driver rcv rsp status OP "
1543 "-to- Firmware WQ doorbell: status\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001544 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001545 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001546 div_u64(phba->ktime_seg7_total,
1547 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001548 phba->ktime_seg7_min,
1549 phba->ktime_seg7_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001550 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001551 "Segment 8: Firmware WQ doorbell: status"
1552 " -to- MSI-X ISR for status cmpl\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001553 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001554 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001555 div_u64(phba->ktime_seg8_total,
1556 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001557 phba->ktime_seg8_min,
1558 phba->ktime_seg8_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001559 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001560 "Segment 9: MSI-X ISR for status cmpl "
1561 "-to- NVME layer passed status done\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001562 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001563 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001564 div_u64(phba->ktime_seg9_total,
1565 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001566 phba->ktime_seg9_min,
1567 phba->ktime_seg9_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001568 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001569 "Total: cmd received by MSI-X ISR -to- "
1570 "cmd completed on wire\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001571 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001572 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001573 div_u64(phba->ktime_seg10_total,
1574 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001575 phba->ktime_seg10_min,
1576 phba->ktime_seg10_max);
James Smartbd2cdd52017-02-12 13:52:33 -08001577 return len;
1578}
1579
1580/**
1581 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1582 * @phba: The phba to gather target node info from.
1583 * @buf: The buffer to dump log into.
1584 * @size: The maximum amount of data to process.
1585 *
1586 * Description:
1587 * This routine dumps the NVME IO trace associated with @phba
1588 *
1589 * Return Value:
1590 * This routine returns the amount of bytes that were dumped into @buf and will
1591 * not exceed @size.
1592 **/
1593static int
1594lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1595{
1596 struct lpfc_debugfs_nvmeio_trc *dtp;
1597 int i, state, index, skip;
1598 int len = 0;
1599
1600 state = phba->nvmeio_trc_on;
1601
1602 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1603 (phba->nvmeio_trc_size - 1);
1604 skip = phba->nvmeio_trc_output_idx;
1605
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001606 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001607 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1608 (phba->nvmet_support ? "NVME" : "NVMET"),
1609 (state ? "Enabled" : "Disabled"),
1610 index, skip, phba->nvmeio_trc_size);
1611
1612 if (!phba->nvmeio_trc || state)
1613 return len;
1614
1615 /* trace MUST bhe off to continue */
1616
1617 for (i = index; i < phba->nvmeio_trc_size; i++) {
1618 if (skip) {
1619 skip--;
1620 continue;
1621 }
1622 dtp = phba->nvmeio_trc + i;
1623 phba->nvmeio_trc_output_idx++;
1624
1625 if (!dtp->fmt)
1626 continue;
1627
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001628 len += scnprintf(buf + len, size - len, dtp->fmt,
James Smartbd2cdd52017-02-12 13:52:33 -08001629 dtp->data1, dtp->data2, dtp->data3);
1630
1631 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1632 phba->nvmeio_trc_output_idx = 0;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001633 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001634 "Trace Complete\n");
1635 goto out;
1636 }
1637
1638 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001639 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001640 "Trace Continue (%d of %d)\n",
1641 phba->nvmeio_trc_output_idx,
1642 phba->nvmeio_trc_size);
1643 goto out;
1644 }
1645 }
1646 for (i = 0; i < index; i++) {
1647 if (skip) {
1648 skip--;
1649 continue;
1650 }
1651 dtp = phba->nvmeio_trc + i;
1652 phba->nvmeio_trc_output_idx++;
1653
1654 if (!dtp->fmt)
1655 continue;
1656
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001657 len += scnprintf(buf + len, size - len, dtp->fmt,
James Smartbd2cdd52017-02-12 13:52:33 -08001658 dtp->data1, dtp->data2, dtp->data3);
1659
1660 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1661 phba->nvmeio_trc_output_idx = 0;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001662 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001663 "Trace Complete\n");
1664 goto out;
1665 }
1666
1667 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001668 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001669 "Trace Continue (%d of %d)\n",
1670 phba->nvmeio_trc_output_idx,
1671 phba->nvmeio_trc_size);
1672 goto out;
1673 }
1674 }
1675
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001676 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001677 "Trace Done\n");
1678out:
1679 return len;
1680}
1681
1682/**
James Smart840eda92020-03-22 11:13:00 -07001683 * lpfc_debugfs_hdwqstat_data - Dump I/O stats to a buffer
James Smartbd2cdd52017-02-12 13:52:33 -08001684 * @vport: The vport to gather target node info from.
1685 * @buf: The buffer to dump log into.
1686 * @size: The maximum amount of data to process.
1687 *
1688 * Description:
James Smart840eda92020-03-22 11:13:00 -07001689 * This routine dumps the NVME + SCSI statistics associated with @vport
James Smartbd2cdd52017-02-12 13:52:33 -08001690 *
1691 * Return Value:
1692 * This routine returns the amount of bytes that were dumped into @buf and will
1693 * not exceed @size.
1694 **/
1695static int
James Smart840eda92020-03-22 11:13:00 -07001696lpfc_debugfs_hdwqstat_data(struct lpfc_vport *vport, char *buf, int size)
James Smartbd2cdd52017-02-12 13:52:33 -08001697{
1698 struct lpfc_hba *phba = vport->phba;
James Smart840eda92020-03-22 11:13:00 -07001699 struct lpfc_hdwq_stat *c_stat;
1700 int i, j, len;
James Smart63df6d62019-01-28 11:14:24 -08001701 uint32_t tot_xmt;
1702 uint32_t tot_rcv;
1703 uint32_t tot_cmpl;
James Smart840eda92020-03-22 11:13:00 -07001704 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
James Smartbd2cdd52017-02-12 13:52:33 -08001705
James Smart840eda92020-03-22 11:13:00 -07001706 scnprintf(tmp, sizeof(tmp), "HDWQ Stats:\n\n");
1707 if (strlcat(buf, tmp, size) >= size)
1708 goto buffer_done;
1709
1710 scnprintf(tmp, sizeof(tmp), "(NVME Accounting: %s) ",
1711 (phba->hdwqstat_on &
1712 (LPFC_CHECK_NVME_IO | LPFC_CHECK_NVMET_IO) ?
1713 "Enabled" : "Disabled"));
1714 if (strlcat(buf, tmp, size) >= size)
1715 goto buffer_done;
1716
1717 scnprintf(tmp, sizeof(tmp), "(SCSI Accounting: %s) ",
1718 (phba->hdwqstat_on & LPFC_CHECK_SCSI_IO ?
1719 "Enabled" : "Disabled"));
1720 if (strlcat(buf, tmp, size) >= size)
1721 goto buffer_done;
1722
1723 scnprintf(tmp, sizeof(tmp), "\n\n");
1724 if (strlcat(buf, tmp, size) >= size)
1725 goto buffer_done;
James Smart63df6d62019-01-28 11:14:24 -08001726
1727 for (i = 0; i < phba->cfg_hdw_queue; i++) {
James Smart63df6d62019-01-28 11:14:24 -08001728 tot_rcv = 0;
1729 tot_xmt = 0;
1730 tot_cmpl = 0;
James Smart840eda92020-03-22 11:13:00 -07001731
1732 for_each_present_cpu(j) {
1733 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, j);
1734
1735 /* Only display for this HDWQ */
1736 if (i != c_stat->hdwq_no)
1737 continue;
1738
1739 /* Only display non-zero counters */
1740 if (!c_stat->xmt_io && !c_stat->cmpl_io &&
1741 !c_stat->rcv_io)
1742 continue;
1743
1744 if (!tot_xmt && !tot_cmpl && !tot_rcv) {
1745 /* Print HDWQ string only the first time */
1746 scnprintf(tmp, sizeof(tmp), "[HDWQ %d]:\t", i);
1747 if (strlcat(buf, tmp, size) >= size)
1748 goto buffer_done;
1749 }
1750
1751 tot_xmt += c_stat->xmt_io;
1752 tot_cmpl += c_stat->cmpl_io;
James Smart63df6d62019-01-28 11:14:24 -08001753 if (phba->nvmet_support)
James Smart840eda92020-03-22 11:13:00 -07001754 tot_rcv += c_stat->rcv_io;
1755
1756 scnprintf(tmp, sizeof(tmp), "| [CPU %d]: ", j);
1757 if (strlcat(buf, tmp, size) >= size)
1758 goto buffer_done;
1759
1760 if (phba->nvmet_support) {
1761 scnprintf(tmp, sizeof(tmp),
1762 "XMT 0x%x CMPL 0x%x RCV 0x%x |",
1763 c_stat->xmt_io, c_stat->cmpl_io,
1764 c_stat->rcv_io);
1765 if (strlcat(buf, tmp, size) >= size)
1766 goto buffer_done;
1767 } else {
1768 scnprintf(tmp, sizeof(tmp),
1769 "XMT 0x%x CMPL 0x%x |",
1770 c_stat->xmt_io, c_stat->cmpl_io);
1771 if (strlcat(buf, tmp, size) >= size)
1772 goto buffer_done;
1773 }
James Smart63df6d62019-01-28 11:14:24 -08001774 }
1775
James Smart840eda92020-03-22 11:13:00 -07001776 /* Check if nothing to display */
James Smart63df6d62019-01-28 11:14:24 -08001777 if (!tot_xmt && !tot_cmpl && !tot_rcv)
1778 continue;
1779
James Smart840eda92020-03-22 11:13:00 -07001780 scnprintf(tmp, sizeof(tmp), "\t->\t[HDWQ Total: ");
1781 if (strlcat(buf, tmp, size) >= size)
1782 goto buffer_done;
1783
1784 if (phba->nvmet_support) {
1785 scnprintf(tmp, sizeof(tmp),
1786 "XMT 0x%x CMPL 0x%x RCV 0x%x]\n\n",
1787 tot_xmt, tot_cmpl, tot_rcv);
1788 if (strlcat(buf, tmp, size) >= size)
1789 goto buffer_done;
1790 } else {
1791 scnprintf(tmp, sizeof(tmp),
1792 "XMT 0x%x CMPL 0x%x]\n\n",
1793 tot_xmt, tot_cmpl);
1794 if (strlcat(buf, tmp, size) >= size)
1795 goto buffer_done;
James Smart6a828b02019-01-28 11:14:31 -08001796 }
James Smart63df6d62019-01-28 11:14:24 -08001797 }
James Smart840eda92020-03-22 11:13:00 -07001798
1799buffer_done:
1800 len = strnlen(buf, size);
James Smart858c9f62007-06-17 19:56:39 -05001801 return len;
1802}
James Smart2ea259e2017-02-12 13:52:27 -08001803
James Smart858c9f62007-06-17 19:56:39 -05001804#endif
1805
James Smarte59058c2008-08-24 21:49:00 -04001806/**
James Smart3621a712009-04-06 18:47:14 -04001807 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -04001808 * @vport: The vport to associate this trace string with for retrieval.
1809 * @mask: Log entry classification.
1810 * @fmt: Format string to be displayed when dumping the log.
1811 * @data1: 1st data parameter to be applied to @fmt.
1812 * @data2: 2nd data parameter to be applied to @fmt.
1813 * @data3: 3rd data parameter to be applied to @fmt.
1814 *
1815 * Description:
1816 * This routine is used by the driver code to add a debugfs log entry to the
1817 * discovery trace buffer associated with @vport. Only entries with a @mask that
1818 * match the current debugfs discovery mask will be saved. Entries that do not
1819 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1820 * printf when displaying the log.
1821 **/
James Smart858c9f62007-06-17 19:56:39 -05001822inline void
1823lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1824 uint32_t data1, uint32_t data2, uint32_t data3)
1825{
James Smart923e4b62008-12-04 22:40:07 -05001826#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -04001827 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -05001828 int index;
1829
1830 if (!(lpfc_debugfs_mask_disc_trc & mask))
1831 return;
1832
1833 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1834 !vport || !vport->disc_trc)
1835 return;
1836
1837 index = atomic_inc_return(&vport->disc_trc_cnt) &
1838 (lpfc_debugfs_max_disc_trc - 1);
1839 dtp = vport->disc_trc + index;
1840 dtp->fmt = fmt;
1841 dtp->data1 = data1;
1842 dtp->data2 = data2;
1843 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -04001844 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1845 dtp->jif = jiffies;
1846#endif
1847 return;
1848}
1849
James Smarte59058c2008-08-24 21:49:00 -04001850/**
James Smart3621a712009-04-06 18:47:14 -04001851 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -04001852 * @phba: The phba to associate this trace string with for retrieval.
1853 * @fmt: Format string to be displayed when dumping the log.
1854 * @data1: 1st data parameter to be applied to @fmt.
1855 * @data2: 2nd data parameter to be applied to @fmt.
1856 * @data3: 3rd data parameter to be applied to @fmt.
1857 *
1858 * Description:
1859 * This routine is used by the driver code to add a debugfs log entry to the
1860 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1861 * @data3 are used like printf when displaying the log.
1862 **/
James Smarta58cbd52007-08-02 11:09:43 -04001863inline void
1864lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1865 uint32_t data1, uint32_t data2, uint32_t data3)
1866{
James Smart923e4b62008-12-04 22:40:07 -05001867#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -04001868 struct lpfc_debugfs_trc *dtp;
1869 int index;
1870
1871 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1872 !phba || !phba->slow_ring_trc)
1873 return;
1874
1875 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1876 (lpfc_debugfs_max_slow_ring_trc - 1);
1877 dtp = phba->slow_ring_trc + index;
1878 dtp->fmt = fmt;
1879 dtp->data1 = data1;
1880 dtp->data2 = data2;
1881 dtp->data3 = data3;
1882 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -05001883 dtp->jif = jiffies;
1884#endif
1885 return;
1886}
1887
James Smartbd2cdd52017-02-12 13:52:33 -08001888/**
1889 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1890 * @phba: The phba to associate this trace string with for retrieval.
1891 * @fmt: Format string to be displayed when dumping the log.
1892 * @data1: 1st data parameter to be applied to @fmt.
1893 * @data2: 2nd data parameter to be applied to @fmt.
1894 * @data3: 3rd data parameter to be applied to @fmt.
1895 *
1896 * Description:
1897 * This routine is used by the driver code to add a debugfs log entry to the
1898 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1899 * @data3 are used like printf when displaying the log.
1900 **/
1901inline void
1902lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1903 uint16_t data1, uint16_t data2, uint32_t data3)
1904{
1905#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1906 struct lpfc_debugfs_nvmeio_trc *dtp;
1907 int index;
1908
1909 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1910 return;
1911
1912 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1913 (phba->nvmeio_trc_size - 1);
1914 dtp = phba->nvmeio_trc + index;
1915 dtp->fmt = fmt;
1916 dtp->data1 = data1;
1917 dtp->data2 = data2;
1918 dtp->data3 = data3;
1919#endif
1920}
1921
James Smart923e4b62008-12-04 22:40:07 -05001922#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -04001923/**
James Smart3621a712009-04-06 18:47:14 -04001924 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -04001925 * @inode: The inode pointer that contains a vport pointer.
1926 * @file: The file pointer to attach the log output.
1927 *
1928 * Description:
1929 * This routine is the entry point for the debugfs open file operation. It gets
1930 * the vport from the i_private field in @inode, allocates the necessary buffer
1931 * for the log, fills the buffer from the in-memory log for this vport, and then
1932 * returns a pointer to that log in the private_data field in @file.
1933 *
1934 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02001935 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04001936 * error value.
1937 **/
James Smart858c9f62007-06-17 19:56:39 -05001938static int
1939lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1940{
1941 struct lpfc_vport *vport = inode->i_private;
1942 struct lpfc_debug *debug;
1943 int size;
1944 int rc = -ENOMEM;
1945
1946 if (!lpfc_debugfs_max_disc_trc) {
Colin Ian King258f84f2019-02-12 15:29:45 +00001947 rc = -ENOSPC;
James Smart858c9f62007-06-17 19:56:39 -05001948 goto out;
1949 }
1950
1951 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1952 if (!debug)
1953 goto out;
1954
James Smarte59058c2008-08-24 21:49:00 -04001955 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -04001956 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -05001957 size = PAGE_ALIGN(size);
1958
1959 debug->buffer = kmalloc(size, GFP_KERNEL);
1960 if (!debug->buffer) {
1961 kfree(debug);
1962 goto out;
1963 }
1964
1965 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1966 file->private_data = debug;
1967
1968 rc = 0;
1969out:
1970 return rc;
1971}
1972
James Smarte59058c2008-08-24 21:49:00 -04001973/**
James Smart3621a712009-04-06 18:47:14 -04001974 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -04001975 * @inode: The inode pointer that contains a vport pointer.
1976 * @file: The file pointer to attach the log output.
1977 *
1978 * Description:
1979 * This routine is the entry point for the debugfs open file operation. It gets
1980 * the vport from the i_private field in @inode, allocates the necessary buffer
1981 * for the log, fills the buffer from the in-memory log for this vport, and then
1982 * returns a pointer to that log in the private_data field in @file.
1983 *
1984 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02001985 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04001986 * error value.
1987 **/
James Smart858c9f62007-06-17 19:56:39 -05001988static int
James Smarta58cbd52007-08-02 11:09:43 -04001989lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1990{
1991 struct lpfc_hba *phba = inode->i_private;
1992 struct lpfc_debug *debug;
1993 int size;
1994 int rc = -ENOMEM;
1995
1996 if (!lpfc_debugfs_max_slow_ring_trc) {
Colin Ian King258f84f2019-02-12 15:29:45 +00001997 rc = -ENOSPC;
James Smarta58cbd52007-08-02 11:09:43 -04001998 goto out;
1999 }
2000
2001 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2002 if (!debug)
2003 goto out;
2004
James Smarte59058c2008-08-24 21:49:00 -04002005 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -04002006 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
2007 size = PAGE_ALIGN(size);
2008
2009 debug->buffer = kmalloc(size, GFP_KERNEL);
2010 if (!debug->buffer) {
2011 kfree(debug);
2012 goto out;
2013 }
2014
2015 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
2016 file->private_data = debug;
2017
2018 rc = 0;
2019out:
2020 return rc;
2021}
2022
James Smarte59058c2008-08-24 21:49:00 -04002023/**
James Smart3621a712009-04-06 18:47:14 -04002024 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -04002025 * @inode: The inode pointer that contains a vport pointer.
2026 * @file: The file pointer to attach the log output.
2027 *
2028 * Description:
2029 * This routine is the entry point for the debugfs open file operation. It gets
2030 * the vport from the i_private field in @inode, allocates the necessary buffer
2031 * for the log, fills the buffer from the in-memory log for this vport, and then
2032 * returns a pointer to that log in the private_data field in @file.
2033 *
2034 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02002035 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04002036 * error value.
2037 **/
James Smarta58cbd52007-08-02 11:09:43 -04002038static int
James Smart78b2d852007-08-02 11:10:21 -04002039lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
2040{
2041 struct lpfc_hba *phba = inode->i_private;
2042 struct lpfc_debug *debug;
2043 int rc = -ENOMEM;
2044
2045 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2046 if (!debug)
2047 goto out;
2048
James Smarte59058c2008-08-24 21:49:00 -04002049 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -04002050 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
2051 if (!debug->buffer) {
2052 kfree(debug);
2053 goto out;
2054 }
2055
2056 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
2057 LPFC_HBQINFO_SIZE);
2058 file->private_data = debug;
2059
2060 rc = 0;
2061out:
2062 return rc;
2063}
2064
James Smarte59058c2008-08-24 21:49:00 -04002065/**
James Smartc4908502019-01-28 11:14:28 -08002066 * lpfc_debugfs_multixripools_open - Open the multixripool debugfs buffer
2067 * @inode: The inode pointer that contains a hba pointer.
2068 * @file: The file pointer to attach the log output.
2069 *
2070 * Description:
2071 * This routine is the entry point for the debugfs open file operation. It gets
2072 * the hba from the i_private field in @inode, allocates the necessary buffer
2073 * for the log, fills the buffer from the in-memory log for this hba, and then
2074 * returns a pointer to that log in the private_data field in @file.
2075 *
2076 * Returns:
2077 * This function returns zero if successful. On error it will return a negative
2078 * error value.
2079 **/
2080static int
2081lpfc_debugfs_multixripools_open(struct inode *inode, struct file *file)
2082{
2083 struct lpfc_hba *phba = inode->i_private;
2084 struct lpfc_debug *debug;
2085 int rc = -ENOMEM;
2086
2087 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2088 if (!debug)
2089 goto out;
2090
2091 /* Round to page boundary */
2092 debug->buffer = kzalloc(LPFC_DUMP_MULTIXRIPOOL_SIZE, GFP_KERNEL);
2093 if (!debug->buffer) {
2094 kfree(debug);
2095 goto out;
2096 }
2097
James Smart6a828b02019-01-28 11:14:31 -08002098 debug->len = lpfc_debugfs_multixripools_data(
2099 phba, debug->buffer, LPFC_DUMP_MULTIXRIPOOL_SIZE);
James Smartc4908502019-01-28 11:14:28 -08002100
2101 debug->i_private = inode->i_private;
2102 file->private_data = debug;
2103
2104 rc = 0;
2105out:
2106 return rc;
2107}
2108
James Smart6a828b02019-01-28 11:14:31 -08002109#ifdef LPFC_HDWQ_LOCK_STAT
James Smartc4908502019-01-28 11:14:28 -08002110/**
James Smart6a828b02019-01-28 11:14:31 -08002111 * lpfc_debugfs_lockstat_open - Open the lockstat debugfs buffer
James Smart5e5b5112019-01-28 11:14:22 -08002112 * @inode: The inode pointer that contains a vport pointer.
2113 * @file: The file pointer to attach the log output.
2114 *
2115 * Description:
2116 * This routine is the entry point for the debugfs open file operation. It gets
2117 * the vport from the i_private field in @inode, allocates the necessary buffer
2118 * for the log, fills the buffer from the in-memory log for this vport, and then
2119 * returns a pointer to that log in the private_data field in @file.
2120 *
2121 * Returns:
2122 * This function returns zero if successful. On error it will return a negative
2123 * error value.
2124 **/
2125static int
James Smart6a828b02019-01-28 11:14:31 -08002126lpfc_debugfs_lockstat_open(struct inode *inode, struct file *file)
James Smart5e5b5112019-01-28 11:14:22 -08002127{
2128 struct lpfc_hba *phba = inode->i_private;
2129 struct lpfc_debug *debug;
2130 int rc = -ENOMEM;
2131
2132 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2133 if (!debug)
2134 goto out;
2135
2136 /* Round to page boundary */
2137 debug->buffer = kmalloc(LPFC_HDWQINFO_SIZE, GFP_KERNEL);
2138 if (!debug->buffer) {
2139 kfree(debug);
2140 goto out;
2141 }
2142
James Smart6a828b02019-01-28 11:14:31 -08002143 debug->len = lpfc_debugfs_lockstat_data(phba, debug->buffer,
James Smart5e5b5112019-01-28 11:14:22 -08002144 LPFC_HBQINFO_SIZE);
2145 file->private_data = debug;
2146
2147 rc = 0;
2148out:
2149 return rc;
2150}
2151
James Smart6a828b02019-01-28 11:14:31 -08002152static ssize_t
2153lpfc_debugfs_lockstat_write(struct file *file, const char __user *buf,
2154 size_t nbytes, loff_t *ppos)
2155{
2156 struct lpfc_debug *debug = file->private_data;
2157 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2158 struct lpfc_sli4_hdw_queue *qp;
2159 char mybuf[64];
2160 char *pbuf;
2161 int i;
2162
James Smart6a828b02019-01-28 11:14:31 -08002163 memset(mybuf, 0, sizeof(mybuf));
2164
2165 if (copy_from_user(mybuf, buf, nbytes))
2166 return -EFAULT;
2167 pbuf = &mybuf[0];
2168
2169 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
2170 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
2171 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2172 qp = &phba->sli4_hba.hdwq[i];
2173 qp->lock_conflict.alloc_xri_get = 0;
2174 qp->lock_conflict.alloc_xri_put = 0;
2175 qp->lock_conflict.free_xri = 0;
2176 qp->lock_conflict.wq_access = 0;
2177 qp->lock_conflict.alloc_pvt_pool = 0;
2178 qp->lock_conflict.mv_from_pvt_pool = 0;
2179 qp->lock_conflict.mv_to_pub_pool = 0;
2180 qp->lock_conflict.mv_to_pvt_pool = 0;
2181 qp->lock_conflict.free_pvt_pool = 0;
2182 qp->lock_conflict.free_pub_pool = 0;
2183 qp->lock_conflict.wq_access = 0;
2184 }
2185 }
2186 return nbytes;
2187}
2188#endif
2189
YueHaibing7b10db52019-10-28 21:25:56 +08002190static int lpfc_debugfs_ras_log_data(struct lpfc_hba *phba,
2191 char *buffer, int size)
James Smart95bfc6d2019-10-18 14:18:27 -07002192{
2193 int copied = 0;
2194 struct lpfc_dmabuf *dmabuf, *next;
2195
James Smart9a20cc12019-12-18 15:58:03 -08002196 memset(buffer, 0, size);
2197
James Smart95bfc6d2019-10-18 14:18:27 -07002198 spin_lock_irq(&phba->hbalock);
2199 if (phba->ras_fwlog.state != ACTIVE) {
2200 spin_unlock_irq(&phba->hbalock);
2201 return -EINVAL;
2202 }
2203 spin_unlock_irq(&phba->hbalock);
2204
2205 list_for_each_entry_safe(dmabuf, next,
2206 &phba->ras_fwlog.fwlog_buff_list, list) {
James Smart9a20cc12019-12-18 15:58:03 -08002207 /* Check if copying will go over size and a '\0' char */
2208 if ((copied + LPFC_RAS_MAX_ENTRY_SIZE) >= (size - 1)) {
2209 memcpy(buffer + copied, dmabuf->virt,
2210 size - copied - 1);
2211 copied += size - copied - 1;
2212 break;
2213 }
James Smart95bfc6d2019-10-18 14:18:27 -07002214 memcpy(buffer + copied, dmabuf->virt, LPFC_RAS_MAX_ENTRY_SIZE);
2215 copied += LPFC_RAS_MAX_ENTRY_SIZE;
James Smart95bfc6d2019-10-18 14:18:27 -07002216 }
2217 return copied;
2218}
2219
2220static int
2221lpfc_debugfs_ras_log_release(struct inode *inode, struct file *file)
2222{
2223 struct lpfc_debug *debug = file->private_data;
2224
2225 vfree(debug->buffer);
2226 kfree(debug);
2227
2228 return 0;
2229}
2230
2231/**
2232 * lpfc_debugfs_ras_log_open - Open the RAS log debugfs buffer
2233 * @inode: The inode pointer that contains a vport pointer.
2234 * @file: The file pointer to attach the log output.
2235 *
2236 * Description:
2237 * This routine is the entry point for the debugfs open file operation. It gets
2238 * the vport from the i_private field in @inode, allocates the necessary buffer
2239 * for the log, fills the buffer from the in-memory log for this vport, and then
2240 * returns a pointer to that log in the private_data field in @file.
2241 *
2242 * Returns:
2243 * This function returns zero if successful. On error it will return a negative
2244 * error value.
2245 **/
2246static int
2247lpfc_debugfs_ras_log_open(struct inode *inode, struct file *file)
2248{
2249 struct lpfc_hba *phba = inode->i_private;
2250 struct lpfc_debug *debug;
2251 int size;
2252 int rc = -ENOMEM;
2253
2254 spin_lock_irq(&phba->hbalock);
2255 if (phba->ras_fwlog.state != ACTIVE) {
2256 spin_unlock_irq(&phba->hbalock);
2257 rc = -EINVAL;
2258 goto out;
2259 }
2260 spin_unlock_irq(&phba->hbalock);
2261 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2262 if (!debug)
2263 goto out;
2264
2265 size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;
2266 debug->buffer = vmalloc(size);
2267 if (!debug->buffer)
2268 goto free_debug;
2269
2270 debug->len = lpfc_debugfs_ras_log_data(phba, debug->buffer, size);
2271 if (debug->len < 0) {
2272 rc = -EINVAL;
2273 goto free_buffer;
2274 }
2275 file->private_data = debug;
2276
2277 return 0;
2278
2279free_buffer:
2280 vfree(debug->buffer);
2281free_debug:
2282 kfree(debug);
2283out:
2284 return rc;
2285}
2286
James Smart5e5b5112019-01-28 11:14:22 -08002287/**
James Smart3621a712009-04-06 18:47:14 -04002288 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -04002289 * @inode: The inode pointer that contains a vport pointer.
2290 * @file: The file pointer to attach the log output.
2291 *
2292 * Description:
2293 * This routine is the entry point for the debugfs open file operation. It gets
2294 * the vport from the i_private field in @inode, allocates the necessary buffer
2295 * for the log, fills the buffer from the in-memory log for this vport, and then
2296 * returns a pointer to that log in the private_data field in @file.
2297 *
2298 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02002299 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04002300 * error value.
2301 **/
James Smart78b2d852007-08-02 11:10:21 -04002302static int
James Smartc95d6c62008-01-11 01:53:23 -05002303lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -04002304{
2305 struct lpfc_hba *phba = inode->i_private;
2306 struct lpfc_debug *debug;
2307 int rc = -ENOMEM;
2308
2309 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2310 if (!debug)
2311 goto out;
2312
James Smarte59058c2008-08-24 21:49:00 -04002313 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -05002314 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -04002315 if (!debug->buffer) {
2316 kfree(debug);
2317 goto out;
2318 }
2319
James Smartc95d6c62008-01-11 01:53:23 -05002320 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
2321 LPFC_DUMPHBASLIM_SIZE);
2322 file->private_data = debug;
2323
2324 rc = 0;
2325out:
2326 return rc;
2327}
2328
James Smarte59058c2008-08-24 21:49:00 -04002329/**
James Smart3621a712009-04-06 18:47:14 -04002330 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -04002331 * @inode: The inode pointer that contains a vport pointer.
2332 * @file: The file pointer to attach the log output.
2333 *
2334 * Description:
2335 * This routine is the entry point for the debugfs open file operation. It gets
2336 * the vport from the i_private field in @inode, allocates the necessary buffer
2337 * for the log, fills the buffer from the in-memory log for this vport, and then
2338 * returns a pointer to that log in the private_data field in @file.
2339 *
2340 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02002341 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04002342 * error value.
2343 **/
James Smartc95d6c62008-01-11 01:53:23 -05002344static int
2345lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
2346{
2347 struct lpfc_hba *phba = inode->i_private;
2348 struct lpfc_debug *debug;
2349 int rc = -ENOMEM;
2350
2351 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2352 if (!debug)
2353 goto out;
2354
James Smarte59058c2008-08-24 21:49:00 -04002355 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -05002356 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
2357 if (!debug->buffer) {
2358 kfree(debug);
2359 goto out;
2360 }
2361
2362 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
2363 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -04002364 file->private_data = debug;
2365
2366 rc = 0;
2367out:
2368 return rc;
2369}
2370
James Smartf9bb2da2011-10-10 21:34:11 -04002371static ssize_t
2372lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
2373 size_t nbytes, loff_t *ppos)
2374{
Al Virob5830432014-10-31 01:22:04 -04002375 struct dentry *dent = file->f_path.dentry;
James Smartf9bb2da2011-10-10 21:34:11 -04002376 struct lpfc_hba *phba = file->private_data;
James Smart9a6b09c2012-03-01 22:37:42 -05002377 char cbuf[32];
James Smart4ac9b222012-03-01 22:38:29 -05002378 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04002379 int cnt = 0;
2380
2381 if (dent == phba->debug_writeGuard)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002382 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04002383 else if (dent == phba->debug_writeApp)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002384 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04002385 else if (dent == phba->debug_writeRef)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002386 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
James Smartacd68592012-01-18 16:25:09 -05002387 else if (dent == phba->debug_readGuard)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002388 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04002389 else if (dent == phba->debug_readApp)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002390 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04002391 else if (dent == phba->debug_readRef)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002392 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
James Smart4ac9b222012-03-01 22:38:29 -05002393 else if (dent == phba->debug_InjErrNPortID)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002394 cnt = scnprintf(cbuf, 32, "0x%06x\n",
2395 phba->lpfc_injerr_nportid);
James Smart4ac9b222012-03-01 22:38:29 -05002396 else if (dent == phba->debug_InjErrWWPN) {
2397 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
2398 tmp = cpu_to_be64(tmp);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002399 cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
James Smart4ac9b222012-03-01 22:38:29 -05002400 } else if (dent == phba->debug_InjErrLBA) {
2401 if (phba->lpfc_injerr_lba == (sector_t)(-1))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002402 cnt = scnprintf(cbuf, 32, "off\n");
James Smart9a6b09c2012-03-01 22:37:42 -05002403 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002404 cnt = scnprintf(cbuf, 32, "0x%llx\n",
James Smart4ac9b222012-03-01 22:38:29 -05002405 (uint64_t) phba->lpfc_injerr_lba);
James Smart9a6b09c2012-03-01 22:37:42 -05002406 } else
James Smartf9bb2da2011-10-10 21:34:11 -04002407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2408 "0547 Unknown debugfs error injection entry\n");
2409
2410 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
2411}
2412
2413static ssize_t
2414lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
2415 size_t nbytes, loff_t *ppos)
2416{
Al Virob5830432014-10-31 01:22:04 -04002417 struct dentry *dent = file->f_path.dentry;
James Smartf9bb2da2011-10-10 21:34:11 -04002418 struct lpfc_hba *phba = file->private_data;
Alan0872774d2016-02-15 19:11:56 +00002419 char dstbuf[33];
James Smart4ac9b222012-03-01 22:38:29 -05002420 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04002421 int size;
2422
Alan0872774d2016-02-15 19:11:56 +00002423 memset(dstbuf, 0, 33);
James Smartf9bb2da2011-10-10 21:34:11 -04002424 size = (nbytes < 32) ? nbytes : 32;
2425 if (copy_from_user(dstbuf, buf, size))
2426 return 0;
2427
James Smart9a6b09c2012-03-01 22:37:42 -05002428 if (dent == phba->debug_InjErrLBA) {
Dick Kennedya7fc0712020-05-01 14:43:08 -07002429 if ((dstbuf[0] == 'o') && (dstbuf[1] == 'f') &&
2430 (dstbuf[2] == 'f'))
James Smart4ac9b222012-03-01 22:38:29 -05002431 tmp = (uint64_t)(-1);
James Smart9a6b09c2012-03-01 22:37:42 -05002432 }
2433
James Smart4ac9b222012-03-01 22:38:29 -05002434 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
James Smartf9bb2da2011-10-10 21:34:11 -04002435 return 0;
2436
2437 if (dent == phba->debug_writeGuard)
2438 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
2439 else if (dent == phba->debug_writeApp)
2440 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
2441 else if (dent == phba->debug_writeRef)
2442 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
James Smartacd68592012-01-18 16:25:09 -05002443 else if (dent == phba->debug_readGuard)
2444 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
James Smartf9bb2da2011-10-10 21:34:11 -04002445 else if (dent == phba->debug_readApp)
2446 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
2447 else if (dent == phba->debug_readRef)
2448 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
2449 else if (dent == phba->debug_InjErrLBA)
2450 phba->lpfc_injerr_lba = (sector_t)tmp;
James Smart4ac9b222012-03-01 22:38:29 -05002451 else if (dent == phba->debug_InjErrNPortID)
2452 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
2453 else if (dent == phba->debug_InjErrWWPN) {
2454 tmp = cpu_to_be64(tmp);
2455 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
2456 } else
James Smartf9bb2da2011-10-10 21:34:11 -04002457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2458 "0548 Unknown debugfs error injection entry\n");
2459
2460 return nbytes;
2461}
2462
2463static int
2464lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
2465{
2466 return 0;
2467}
2468
James Smarte59058c2008-08-24 21:49:00 -04002469/**
James Smart3621a712009-04-06 18:47:14 -04002470 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -04002471 * @inode: The inode pointer that contains a vport pointer.
2472 * @file: The file pointer to attach the log output.
2473 *
2474 * Description:
2475 * This routine is the entry point for the debugfs open file operation. It gets
2476 * the vport from the i_private field in @inode, allocates the necessary buffer
2477 * for the log, fills the buffer from the in-memory log for this vport, and then
2478 * returns a pointer to that log in the private_data field in @file.
2479 *
2480 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02002481 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04002482 * error value.
2483 **/
James Smarta58cbd52007-08-02 11:09:43 -04002484static int
James Smart858c9f62007-06-17 19:56:39 -05002485lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
2486{
2487 struct lpfc_vport *vport = inode->i_private;
2488 struct lpfc_debug *debug;
2489 int rc = -ENOMEM;
2490
2491 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2492 if (!debug)
2493 goto out;
2494
James Smarte59058c2008-08-24 21:49:00 -04002495 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05002496 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
2497 if (!debug->buffer) {
2498 kfree(debug);
2499 goto out;
2500 }
2501
2502 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
2503 LPFC_NODELIST_SIZE);
2504 file->private_data = debug;
2505
2506 rc = 0;
2507out:
2508 return rc;
2509}
2510
James Smarte59058c2008-08-24 21:49:00 -04002511/**
James Smart3621a712009-04-06 18:47:14 -04002512 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04002513 * @file: The file pointer to seek through.
2514 * @off: The offset to seek to or the amount to seek by.
2515 * @whence: Indicates how to seek.
2516 *
2517 * Description:
2518 * This routine is the entry point for the debugfs lseek file operation. The
2519 * @whence parameter indicates whether @off is the offset to directly seek to,
2520 * or if it is a value to seek forward or reverse by. This function figures out
2521 * what the new offset of the debugfs file will be and assigns that value to the
2522 * f_pos field of @file.
2523 *
2524 * Returns:
2525 * This function returns the new offset if successful and returns a negative
2526 * error if unable to process the seek.
2527 **/
James Smart858c9f62007-06-17 19:56:39 -05002528static loff_t
2529lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
2530{
Al Viro7233c772013-06-23 12:08:05 +04002531 struct lpfc_debug *debug = file->private_data;
2532 return fixed_size_llseek(file, off, whence, debug->len);
James Smart858c9f62007-06-17 19:56:39 -05002533}
2534
James Smarte59058c2008-08-24 21:49:00 -04002535/**
James Smart3621a712009-04-06 18:47:14 -04002536 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04002537 * @file: The file pointer to read from.
2538 * @buf: The buffer to copy the data to.
2539 * @nbytes: The number of bytes to read.
2540 * @ppos: The position in the file to start reading from.
2541 *
2542 * Description:
2543 * This routine reads data from from the buffer indicated in the private_data
2544 * field of @file. It will start reading at @ppos and copy up to @nbytes of
2545 * data to @buf.
2546 *
2547 * Returns:
2548 * This function returns the amount of data that was read (this could be less
2549 * than @nbytes if the end of the file was reached) or a negative error value.
2550 **/
James Smart858c9f62007-06-17 19:56:39 -05002551static ssize_t
2552lpfc_debugfs_read(struct file *file, char __user *buf,
2553 size_t nbytes, loff_t *ppos)
2554{
2555 struct lpfc_debug *debug = file->private_data;
James Smart2a622bf2011-02-16 12:40:06 -05002556
James Smart858c9f62007-06-17 19:56:39 -05002557 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
2558 debug->len);
2559}
2560
James Smarte59058c2008-08-24 21:49:00 -04002561/**
James Smart3621a712009-04-06 18:47:14 -04002562 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04002563 * @inode: The inode pointer that contains a vport pointer. (unused)
2564 * @file: The file pointer that contains the buffer to release.
2565 *
2566 * Description:
2567 * This routine frees the buffer that was allocated when the debugfs file was
2568 * opened.
2569 *
2570 * Returns:
2571 * This function returns zero.
2572 **/
James Smart858c9f62007-06-17 19:56:39 -05002573static int
2574lpfc_debugfs_release(struct inode *inode, struct file *file)
2575{
2576 struct lpfc_debug *debug = file->private_data;
2577
2578 kfree(debug->buffer);
2579 kfree(debug);
2580
2581 return 0;
2582}
2583
James Smartc4908502019-01-28 11:14:28 -08002584/**
2585 * lpfc_debugfs_multixripools_write - Clear multi-XRI pools statistics
2586 * @file: The file pointer to read from.
2587 * @buf: The buffer to copy the user data from.
2588 * @nbytes: The number of bytes to get.
2589 * @ppos: The position in the file to start reading from.
2590 *
2591 * Description:
2592 * This routine clears multi-XRI pools statistics when buf contains "clear".
2593 *
2594 * Return Value:
2595 * It returns the @nbytges passing in from debugfs user space when successful.
2596 * In case of error conditions, it returns proper error code back to the user
2597 * space.
2598 **/
2599static ssize_t
2600lpfc_debugfs_multixripools_write(struct file *file, const char __user *buf,
2601 size_t nbytes, loff_t *ppos)
2602{
2603 struct lpfc_debug *debug = file->private_data;
2604 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2605 char mybuf[64];
2606 char *pbuf;
2607 u32 i;
2608 u32 hwq_count;
2609 struct lpfc_sli4_hdw_queue *qp;
2610 struct lpfc_multixri_pool *multixri_pool;
2611
2612 if (nbytes > 64)
2613 nbytes = 64;
2614
James Smartc4908502019-01-28 11:14:28 -08002615 memset(mybuf, 0, sizeof(mybuf));
2616
2617 if (copy_from_user(mybuf, buf, nbytes))
2618 return -EFAULT;
2619 pbuf = &mybuf[0];
2620
2621 if ((strncmp(pbuf, "clear", strlen("clear"))) == 0) {
2622 hwq_count = phba->cfg_hdw_queue;
2623 for (i = 0; i < hwq_count; i++) {
2624 qp = &phba->sli4_hba.hdwq[i];
2625 multixri_pool = qp->p_multixri_pool;
2626 if (!multixri_pool)
2627 continue;
2628
2629 qp->empty_io_bufs = 0;
2630 multixri_pool->pbl_empty_count = 0;
2631#ifdef LPFC_MXP_STAT
2632 multixri_pool->above_limit_count = 0;
2633 multixri_pool->below_limit_count = 0;
2634 multixri_pool->stat_max_hwm = 0;
2635 multixri_pool->local_pbl_hit_count = 0;
2636 multixri_pool->other_pbl_hit_count = 0;
2637
2638 multixri_pool->stat_pbl_count = 0;
2639 multixri_pool->stat_pvt_count = 0;
2640 multixri_pool->stat_busy_count = 0;
2641 multixri_pool->stat_snapshot_taken = 0;
2642#endif
2643 }
2644 return strlen(pbuf);
2645 }
2646
2647 return -EINVAL;
2648}
James Smartbd2cdd52017-02-12 13:52:33 -08002649
2650static int
2651lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
2652{
2653 struct lpfc_vport *vport = inode->i_private;
2654 struct lpfc_debug *debug;
2655 int rc = -ENOMEM;
2656
2657 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2658 if (!debug)
2659 goto out;
2660
2661 /* Round to page boundary */
2662 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
2663 if (!debug->buffer) {
2664 kfree(debug);
2665 goto out;
2666 }
2667
2668 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
2669 LPFC_NVMESTAT_SIZE);
2670
2671 debug->i_private = inode->i_private;
2672 file->private_data = debug;
2673
2674 rc = 0;
2675out:
2676 return rc;
2677}
2678
James Smart2b65e182017-02-12 13:52:38 -08002679static ssize_t
2680lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
2681 size_t nbytes, loff_t *ppos)
2682{
2683 struct lpfc_debug *debug = file->private_data;
2684 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2685 struct lpfc_hba *phba = vport->phba;
2686 struct lpfc_nvmet_tgtport *tgtp;
2687 char mybuf[64];
2688 char *pbuf;
2689
2690 if (!phba->targetport)
2691 return -ENXIO;
2692
2693 if (nbytes > 64)
2694 nbytes = 64;
2695
James Smart2b65e182017-02-12 13:52:38 -08002696 memset(mybuf, 0, sizeof(mybuf));
2697
2698 if (copy_from_user(mybuf, buf, nbytes))
2699 return -EFAULT;
2700 pbuf = &mybuf[0];
2701
2702 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2703 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
2704 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
2705 atomic_set(&tgtp->rcv_ls_req_in, 0);
2706 atomic_set(&tgtp->rcv_ls_req_out, 0);
2707 atomic_set(&tgtp->rcv_ls_req_drop, 0);
2708 atomic_set(&tgtp->xmt_ls_abort, 0);
James Smart547077a2017-05-15 15:20:40 -07002709 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
James Smart2b65e182017-02-12 13:52:38 -08002710 atomic_set(&tgtp->xmt_ls_rsp, 0);
2711 atomic_set(&tgtp->xmt_ls_drop, 0);
2712 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
2713 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
2714
2715 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
2716 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
2717 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
James Smart2b65e182017-02-12 13:52:38 -08002718 atomic_set(&tgtp->xmt_fcp_drop, 0);
2719 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
2720 atomic_set(&tgtp->xmt_fcp_read, 0);
2721 atomic_set(&tgtp->xmt_fcp_write, 0);
2722 atomic_set(&tgtp->xmt_fcp_rsp, 0);
James Smart547077a2017-05-15 15:20:40 -07002723 atomic_set(&tgtp->xmt_fcp_release, 0);
James Smart2b65e182017-02-12 13:52:38 -08002724 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
2725 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
2726 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
2727
James Smart547077a2017-05-15 15:20:40 -07002728 atomic_set(&tgtp->xmt_fcp_abort, 0);
2729 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
2730 atomic_set(&tgtp->xmt_abort_sol, 0);
2731 atomic_set(&tgtp->xmt_abort_unsol, 0);
James Smart2b65e182017-02-12 13:52:38 -08002732 atomic_set(&tgtp->xmt_abort_rsp, 0);
2733 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
James Smart2b65e182017-02-12 13:52:38 -08002734 }
2735 return nbytes;
2736}
2737
James Smartbd2cdd52017-02-12 13:52:33 -08002738static int
James Smart4c47efc2019-01-28 11:14:25 -08002739lpfc_debugfs_scsistat_open(struct inode *inode, struct file *file)
2740{
2741 struct lpfc_vport *vport = inode->i_private;
2742 struct lpfc_debug *debug;
2743 int rc = -ENOMEM;
2744
2745 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2746 if (!debug)
2747 goto out;
2748
2749 /* Round to page boundary */
2750 debug->buffer = kzalloc(LPFC_SCSISTAT_SIZE, GFP_KERNEL);
2751 if (!debug->buffer) {
2752 kfree(debug);
2753 goto out;
2754 }
2755
2756 debug->len = lpfc_debugfs_scsistat_data(vport, debug->buffer,
2757 LPFC_SCSISTAT_SIZE);
2758
2759 debug->i_private = inode->i_private;
2760 file->private_data = debug;
2761
2762 rc = 0;
2763out:
2764 return rc;
2765}
2766
2767static ssize_t
2768lpfc_debugfs_scsistat_write(struct file *file, const char __user *buf,
2769 size_t nbytes, loff_t *ppos)
2770{
2771 struct lpfc_debug *debug = file->private_data;
2772 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2773 struct lpfc_hba *phba = vport->phba;
2774 char mybuf[6] = {0};
2775 int i;
2776
James Smart4c47efc2019-01-28 11:14:25 -08002777 if (copy_from_user(mybuf, buf, (nbytes >= sizeof(mybuf)) ?
2778 (sizeof(mybuf) - 1) : nbytes))
2779 return -EFAULT;
2780
2781 if ((strncmp(&mybuf[0], "reset", strlen("reset")) == 0) ||
2782 (strncmp(&mybuf[0], "zero", strlen("zero")) == 0)) {
2783 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2784 memset(&phba->sli4_hba.hdwq[i].scsi_cstat, 0,
2785 sizeof(phba->sli4_hba.hdwq[i].scsi_cstat));
2786 }
2787 }
2788
2789 return nbytes;
2790}
2791
2792static int
James Smart2fcbc562020-03-22 11:13:02 -07002793lpfc_debugfs_ioktime_open(struct inode *inode, struct file *file)
James Smartbd2cdd52017-02-12 13:52:33 -08002794{
2795 struct lpfc_vport *vport = inode->i_private;
2796 struct lpfc_debug *debug;
2797 int rc = -ENOMEM;
2798
2799 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2800 if (!debug)
2801 goto out;
2802
2803 /* Round to page boundary */
James Smart2fcbc562020-03-22 11:13:02 -07002804 debug->buffer = kmalloc(LPFC_IOKTIME_SIZE, GFP_KERNEL);
James Smartbd2cdd52017-02-12 13:52:33 -08002805 if (!debug->buffer) {
2806 kfree(debug);
2807 goto out;
2808 }
2809
James Smart2fcbc562020-03-22 11:13:02 -07002810 debug->len = lpfc_debugfs_ioktime_data(vport, debug->buffer,
2811 LPFC_IOKTIME_SIZE);
James Smartbd2cdd52017-02-12 13:52:33 -08002812
2813 debug->i_private = inode->i_private;
2814 file->private_data = debug;
2815
2816 rc = 0;
2817out:
2818 return rc;
2819}
2820
2821static ssize_t
James Smart2fcbc562020-03-22 11:13:02 -07002822lpfc_debugfs_ioktime_write(struct file *file, const char __user *buf,
2823 size_t nbytes, loff_t *ppos)
James Smartbd2cdd52017-02-12 13:52:33 -08002824{
2825 struct lpfc_debug *debug = file->private_data;
2826 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2827 struct lpfc_hba *phba = vport->phba;
2828 char mybuf[64];
2829 char *pbuf;
2830
2831 if (nbytes > 64)
2832 nbytes = 64;
2833
James Smartbd2cdd52017-02-12 13:52:33 -08002834 memset(mybuf, 0, sizeof(mybuf));
2835
2836 if (copy_from_user(mybuf, buf, nbytes))
2837 return -EFAULT;
2838 pbuf = &mybuf[0];
2839
2840 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2841 phba->ktime_data_samples = 0;
2842 phba->ktime_status_samples = 0;
2843 phba->ktime_seg1_total = 0;
2844 phba->ktime_seg1_max = 0;
2845 phba->ktime_seg1_min = 0xffffffff;
2846 phba->ktime_seg2_total = 0;
2847 phba->ktime_seg2_max = 0;
2848 phba->ktime_seg2_min = 0xffffffff;
2849 phba->ktime_seg3_total = 0;
2850 phba->ktime_seg3_max = 0;
2851 phba->ktime_seg3_min = 0xffffffff;
2852 phba->ktime_seg4_total = 0;
2853 phba->ktime_seg4_max = 0;
2854 phba->ktime_seg4_min = 0xffffffff;
2855 phba->ktime_seg5_total = 0;
2856 phba->ktime_seg5_max = 0;
2857 phba->ktime_seg5_min = 0xffffffff;
2858 phba->ktime_seg6_total = 0;
2859 phba->ktime_seg6_max = 0;
2860 phba->ktime_seg6_min = 0xffffffff;
2861 phba->ktime_seg7_total = 0;
2862 phba->ktime_seg7_max = 0;
2863 phba->ktime_seg7_min = 0xffffffff;
2864 phba->ktime_seg8_total = 0;
2865 phba->ktime_seg8_max = 0;
2866 phba->ktime_seg8_min = 0xffffffff;
2867 phba->ktime_seg9_total = 0;
2868 phba->ktime_seg9_max = 0;
2869 phba->ktime_seg9_min = 0xffffffff;
2870 phba->ktime_seg10_total = 0;
2871 phba->ktime_seg10_max = 0;
2872 phba->ktime_seg10_min = 0xffffffff;
2873
2874 phba->ktime_on = 1;
2875 return strlen(pbuf);
2876 } else if ((strncmp(pbuf, "off",
2877 sizeof("off") - 1) == 0)) {
2878 phba->ktime_on = 0;
2879 return strlen(pbuf);
2880 } else if ((strncmp(pbuf, "zero",
2881 sizeof("zero") - 1) == 0)) {
2882 phba->ktime_data_samples = 0;
2883 phba->ktime_status_samples = 0;
2884 phba->ktime_seg1_total = 0;
2885 phba->ktime_seg1_max = 0;
2886 phba->ktime_seg1_min = 0xffffffff;
2887 phba->ktime_seg2_total = 0;
2888 phba->ktime_seg2_max = 0;
2889 phba->ktime_seg2_min = 0xffffffff;
2890 phba->ktime_seg3_total = 0;
2891 phba->ktime_seg3_max = 0;
2892 phba->ktime_seg3_min = 0xffffffff;
2893 phba->ktime_seg4_total = 0;
2894 phba->ktime_seg4_max = 0;
2895 phba->ktime_seg4_min = 0xffffffff;
2896 phba->ktime_seg5_total = 0;
2897 phba->ktime_seg5_max = 0;
2898 phba->ktime_seg5_min = 0xffffffff;
2899 phba->ktime_seg6_total = 0;
2900 phba->ktime_seg6_max = 0;
2901 phba->ktime_seg6_min = 0xffffffff;
2902 phba->ktime_seg7_total = 0;
2903 phba->ktime_seg7_max = 0;
2904 phba->ktime_seg7_min = 0xffffffff;
2905 phba->ktime_seg8_total = 0;
2906 phba->ktime_seg8_max = 0;
2907 phba->ktime_seg8_min = 0xffffffff;
2908 phba->ktime_seg9_total = 0;
2909 phba->ktime_seg9_max = 0;
2910 phba->ktime_seg9_min = 0xffffffff;
2911 phba->ktime_seg10_total = 0;
2912 phba->ktime_seg10_max = 0;
2913 phba->ktime_seg10_min = 0xffffffff;
2914 return strlen(pbuf);
2915 }
2916 return -EINVAL;
2917}
2918
2919static int
2920lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2921{
2922 struct lpfc_hba *phba = inode->i_private;
2923 struct lpfc_debug *debug;
2924 int rc = -ENOMEM;
2925
2926 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2927 if (!debug)
2928 goto out;
2929
2930 /* Round to page boundary */
2931 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2932 if (!debug->buffer) {
2933 kfree(debug);
2934 goto out;
2935 }
2936
2937 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2938 LPFC_NVMEIO_TRC_SIZE);
2939
2940 debug->i_private = inode->i_private;
2941 file->private_data = debug;
2942
2943 rc = 0;
2944out:
2945 return rc;
2946}
2947
2948static ssize_t
2949lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2950 size_t nbytes, loff_t *ppos)
2951{
2952 struct lpfc_debug *debug = file->private_data;
2953 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2954 int i;
2955 unsigned long sz;
2956 char mybuf[64];
2957 char *pbuf;
2958
2959 if (nbytes > 64)
2960 nbytes = 64;
2961
James Smartbd2cdd52017-02-12 13:52:33 -08002962 memset(mybuf, 0, sizeof(mybuf));
2963
2964 if (copy_from_user(mybuf, buf, nbytes))
2965 return -EFAULT;
2966 pbuf = &mybuf[0];
2967
2968 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2969 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2970 "0570 nvmeio_trc_off\n");
2971 phba->nvmeio_trc_output_idx = 0;
2972 phba->nvmeio_trc_on = 0;
2973 return strlen(pbuf);
2974 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2975 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2976 "0571 nvmeio_trc_on\n");
2977 phba->nvmeio_trc_output_idx = 0;
2978 phba->nvmeio_trc_on = 1;
2979 return strlen(pbuf);
2980 }
2981
2982 /* We must be off to allocate the trace buffer */
2983 if (phba->nvmeio_trc_on != 0)
2984 return -EINVAL;
2985
2986 /* If not on or off, the parameter is the trace buffer size */
2987 i = kstrtoul(pbuf, 0, &sz);
2988 if (i)
2989 return -EINVAL;
2990 phba->nvmeio_trc_size = (uint32_t)sz;
2991
2992 /* It must be a power of 2 - round down */
2993 i = 0;
2994 while (sz > 1) {
2995 sz = sz >> 1;
2996 i++;
2997 }
2998 sz = (1 << i);
2999 if (phba->nvmeio_trc_size != sz)
3000 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3001 "0572 nvmeio_trc_size changed to %ld\n",
3002 sz);
3003 phba->nvmeio_trc_size = (uint32_t)sz;
3004
3005 /* If one previously exists, free it */
3006 kfree(phba->nvmeio_trc);
3007
3008 /* Allocate new trace buffer and initialize */
Vasyl Gomonovych1c356ec2017-10-11 21:42:41 +02003009 phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
James Smartbd2cdd52017-02-12 13:52:33 -08003010 sz), GFP_KERNEL);
3011 if (!phba->nvmeio_trc) {
3012 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3013 "0573 Cannot create debugfs "
3014 "nvmeio_trc buffer\n");
3015 return -ENOMEM;
3016 }
James Smartbd2cdd52017-02-12 13:52:33 -08003017 atomic_set(&phba->nvmeio_trc_cnt, 0);
3018 phba->nvmeio_trc_on = 0;
3019 phba->nvmeio_trc_output_idx = 0;
3020
3021 return strlen(pbuf);
3022}
3023
3024static int
James Smart840eda92020-03-22 11:13:00 -07003025lpfc_debugfs_hdwqstat_open(struct inode *inode, struct file *file)
James Smartbd2cdd52017-02-12 13:52:33 -08003026{
3027 struct lpfc_vport *vport = inode->i_private;
3028 struct lpfc_debug *debug;
3029 int rc = -ENOMEM;
3030
3031 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
3032 if (!debug)
3033 goto out;
3034
3035 /* Round to page boundary */
James Smart840eda92020-03-22 11:13:00 -07003036 debug->buffer = kcalloc(1, LPFC_SCSISTAT_SIZE, GFP_KERNEL);
James Smartbd2cdd52017-02-12 13:52:33 -08003037 if (!debug->buffer) {
3038 kfree(debug);
3039 goto out;
3040 }
3041
James Smart840eda92020-03-22 11:13:00 -07003042 debug->len = lpfc_debugfs_hdwqstat_data(vport, debug->buffer,
3043 LPFC_SCSISTAT_SIZE);
James Smartbd2cdd52017-02-12 13:52:33 -08003044
3045 debug->i_private = inode->i_private;
3046 file->private_data = debug;
3047
3048 rc = 0;
3049out:
3050 return rc;
3051}
3052
3053static ssize_t
James Smart840eda92020-03-22 11:13:00 -07003054lpfc_debugfs_hdwqstat_write(struct file *file, const char __user *buf,
James Smartbd2cdd52017-02-12 13:52:33 -08003055 size_t nbytes, loff_t *ppos)
3056{
3057 struct lpfc_debug *debug = file->private_data;
3058 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
3059 struct lpfc_hba *phba = vport->phba;
James Smart840eda92020-03-22 11:13:00 -07003060 struct lpfc_hdwq_stat *c_stat;
James Smartbd2cdd52017-02-12 13:52:33 -08003061 char mybuf[64];
3062 char *pbuf;
James Smart840eda92020-03-22 11:13:00 -07003063 int i;
James Smartbd2cdd52017-02-12 13:52:33 -08003064
3065 if (nbytes > 64)
3066 nbytes = 64;
3067
James Smartbd2cdd52017-02-12 13:52:33 -08003068 memset(mybuf, 0, sizeof(mybuf));
3069
3070 if (copy_from_user(mybuf, buf, nbytes))
3071 return -EFAULT;
3072 pbuf = &mybuf[0];
3073
3074 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
James Smart2b65e182017-02-12 13:52:38 -08003075 if (phba->nvmet_support)
James Smart840eda92020-03-22 11:13:00 -07003076 phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
James Smart2b65e182017-02-12 13:52:38 -08003077 else
James Smart840eda92020-03-22 11:13:00 -07003078 phba->hdwqstat_on |= (LPFC_CHECK_NVME_IO |
James Smart6a828b02019-01-28 11:14:31 -08003079 LPFC_CHECK_SCSI_IO);
3080 return strlen(pbuf);
3081 } else if ((strncmp(pbuf, "nvme_on", sizeof("nvme_on") - 1) == 0)) {
3082 if (phba->nvmet_support)
James Smart840eda92020-03-22 11:13:00 -07003083 phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
James Smart6a828b02019-01-28 11:14:31 -08003084 else
James Smart840eda92020-03-22 11:13:00 -07003085 phba->hdwqstat_on |= LPFC_CHECK_NVME_IO;
James Smartbd2cdd52017-02-12 13:52:33 -08003086 return strlen(pbuf);
James Smart6a828b02019-01-28 11:14:31 -08003087 } else if ((strncmp(pbuf, "scsi_on", sizeof("scsi_on") - 1) == 0)) {
James Smart840eda92020-03-22 11:13:00 -07003088 if (!phba->nvmet_support)
3089 phba->hdwqstat_on |= LPFC_CHECK_SCSI_IO;
James Smart6a828b02019-01-28 11:14:31 -08003090 return strlen(pbuf);
James Smart840eda92020-03-22 11:13:00 -07003091 } else if ((strncmp(pbuf, "nvme_off", sizeof("nvme_off") - 1) == 0)) {
3092 phba->hdwqstat_on &= ~(LPFC_CHECK_NVME_IO |
3093 LPFC_CHECK_NVMET_IO);
3094 return strlen(pbuf);
3095 } else if ((strncmp(pbuf, "scsi_off", sizeof("scsi_off") - 1) == 0)) {
3096 phba->hdwqstat_on &= ~LPFC_CHECK_SCSI_IO;
James Smartf358dd02017-02-12 13:52:34 -08003097 return strlen(pbuf);
James Smartbd2cdd52017-02-12 13:52:33 -08003098 } else if ((strncmp(pbuf, "off",
3099 sizeof("off") - 1) == 0)) {
James Smart840eda92020-03-22 11:13:00 -07003100 phba->hdwqstat_on = LPFC_CHECK_OFF;
James Smartbd2cdd52017-02-12 13:52:33 -08003101 return strlen(pbuf);
3102 } else if ((strncmp(pbuf, "zero",
3103 sizeof("zero") - 1) == 0)) {
James Smart840eda92020-03-22 11:13:00 -07003104 for_each_present_cpu(i) {
3105 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, i);
3106 c_stat->xmt_io = 0;
3107 c_stat->cmpl_io = 0;
3108 c_stat->rcv_io = 0;
James Smartbd2cdd52017-02-12 13:52:33 -08003109 }
3110 return strlen(pbuf);
3111 }
3112 return -EINVAL;
3113}
3114
James Smart2a622bf2011-02-16 12:40:06 -05003115/*
James Smart86a80842011-04-16 11:03:04 -04003116 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05003117 * iDiag debugfs file access methods
James Smart86a80842011-04-16 11:03:04 -04003118 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05003119 *
James Smart86a80842011-04-16 11:03:04 -04003120 * All access methods are through the proper SLI4 PCI function's debugfs
3121 * iDiag directory:
James Smart2a622bf2011-02-16 12:40:06 -05003122 *
James Smart86a80842011-04-16 11:03:04 -04003123 * /sys/kernel/debug/lpfc/fn<#>/iDiag
James Smart2a622bf2011-02-16 12:40:06 -05003124 */
3125
3126/**
3127 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
3128 * @buf: The pointer to the user space buffer.
3129 * @nbytes: The number of bytes in the user space buffer.
3130 * @idiag_cmd: pointer to the idiag command struct.
3131 *
3132 * This routine reads data from debugfs user space buffer and parses the
3133 * buffer for getting the idiag command and arguments. The while space in
3134 * between the set of data is used as the parsing separator.
3135 *
3136 * This routine returns 0 when successful, it returns proper error code
3137 * back to the user space in error conditions.
3138 */
3139static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
3140 struct lpfc_idiag_cmd *idiag_cmd)
3141{
3142 char mybuf[64];
3143 char *pbuf, *step_str;
Stephen Boydb11d48e2011-05-12 16:50:06 -07003144 int i;
3145 size_t bsize;
James Smart2a622bf2011-02-16 12:40:06 -05003146
James Smart2a622bf2011-02-16 12:40:06 -05003147 memset(mybuf, 0, sizeof(mybuf));
3148 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
3149 bsize = min(nbytes, (sizeof(mybuf)-1));
3150
3151 if (copy_from_user(mybuf, buf, bsize))
3152 return -EFAULT;
3153 pbuf = &mybuf[0];
3154 step_str = strsep(&pbuf, "\t ");
3155
3156 /* The opcode must present */
3157 if (!step_str)
3158 return -EINVAL;
3159
3160 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
3161 if (idiag_cmd->opcode == 0)
3162 return -EINVAL;
3163
3164 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
3165 step_str = strsep(&pbuf, "\t ");
3166 if (!step_str)
James Smart86a80842011-04-16 11:03:04 -04003167 return i;
James Smart2a622bf2011-02-16 12:40:06 -05003168 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
3169 }
James Smart86a80842011-04-16 11:03:04 -04003170 return i;
James Smart2a622bf2011-02-16 12:40:06 -05003171}
3172
3173/**
3174 * lpfc_idiag_open - idiag open debugfs
3175 * @inode: The inode pointer that contains a pointer to phba.
3176 * @file: The file pointer to attach the file operation.
3177 *
3178 * Description:
3179 * This routine is the entry point for the debugfs open file operation. It
3180 * gets the reference to phba from the i_private field in @inode, it then
3181 * allocates buffer for the file operation, performs the necessary PCI config
3182 * space read into the allocated buffer according to the idiag user command
3183 * setup, and then returns a pointer to buffer in the private_data field in
3184 * @file.
3185 *
3186 * Returns:
3187 * This function returns zero if successful. On error it will return an
3188 * negative error value.
3189 **/
3190static int
3191lpfc_idiag_open(struct inode *inode, struct file *file)
3192{
3193 struct lpfc_debug *debug;
3194
3195 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
3196 if (!debug)
3197 return -ENOMEM;
3198
3199 debug->i_private = inode->i_private;
3200 debug->buffer = NULL;
3201 file->private_data = debug;
3202
3203 return 0;
3204}
3205
3206/**
3207 * lpfc_idiag_release - Release idiag access file operation
3208 * @inode: The inode pointer that contains a vport pointer. (unused)
3209 * @file: The file pointer that contains the buffer to release.
3210 *
3211 * Description:
3212 * This routine is the generic release routine for the idiag access file
3213 * operation, it frees the buffer that was allocated when the debugfs file
3214 * was opened.
3215 *
3216 * Returns:
3217 * This function returns zero.
3218 **/
3219static int
3220lpfc_idiag_release(struct inode *inode, struct file *file)
3221{
3222 struct lpfc_debug *debug = file->private_data;
3223
3224 /* Free the buffers to the file operation */
3225 kfree(debug->buffer);
3226 kfree(debug);
3227
3228 return 0;
3229}
3230
3231/**
3232 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
3233 * @inode: The inode pointer that contains a vport pointer. (unused)
3234 * @file: The file pointer that contains the buffer to release.
3235 *
3236 * Description:
3237 * This routine frees the buffer that was allocated when the debugfs file
3238 * was opened. It also reset the fields in the idiag command struct in the
James Smart86a80842011-04-16 11:03:04 -04003239 * case of command for write operation.
James Smart2a622bf2011-02-16 12:40:06 -05003240 *
3241 * Returns:
3242 * This function returns zero.
3243 **/
3244static int
3245lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
3246{
3247 struct lpfc_debug *debug = file->private_data;
3248
James Smart86a80842011-04-16 11:03:04 -04003249 if (debug->op == LPFC_IDIAG_OP_WR) {
3250 switch (idiag.cmd.opcode) {
3251 case LPFC_IDIAG_CMD_PCICFG_WR:
3252 case LPFC_IDIAG_CMD_PCICFG_ST:
3253 case LPFC_IDIAG_CMD_PCICFG_CL:
3254 case LPFC_IDIAG_CMD_QUEACC_WR:
3255 case LPFC_IDIAG_CMD_QUEACC_ST:
3256 case LPFC_IDIAG_CMD_QUEACC_CL:
James Smart2a622bf2011-02-16 12:40:06 -05003257 memset(&idiag, 0, sizeof(idiag));
James Smart86a80842011-04-16 11:03:04 -04003258 break;
3259 default:
3260 break;
3261 }
3262 }
James Smart2a622bf2011-02-16 12:40:06 -05003263
3264 /* Free the buffers to the file operation */
3265 kfree(debug->buffer);
3266 kfree(debug);
3267
3268 return 0;
3269}
3270
3271/**
3272 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
3273 * @file: The file pointer to read from.
3274 * @buf: The buffer to copy the data to.
3275 * @nbytes: The number of bytes to read.
3276 * @ppos: The position in the file to start reading from.
3277 *
3278 * Description:
3279 * This routine reads data from the @phba pci config space according to the
3280 * idiag command, and copies to user @buf. Depending on the PCI config space
3281 * read command setup, it does either a single register read of a byte
3282 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
3283 * registers from the 4K extended PCI config space.
3284 *
3285 * Returns:
3286 * This function returns the amount of data that was read (this could be less
3287 * than @nbytes if the end of the file was reached) or a negative error value.
3288 **/
3289static ssize_t
3290lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
3291 loff_t *ppos)
3292{
3293 struct lpfc_debug *debug = file->private_data;
3294 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3295 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
3296 int where, count;
3297 char *pbuffer;
3298 struct pci_dev *pdev;
3299 uint32_t u32val;
3300 uint16_t u16val;
3301 uint8_t u8val;
3302
3303 pdev = phba->pcidev;
3304 if (!pdev)
3305 return 0;
3306
3307 /* This is a user read operation */
3308 debug->op = LPFC_IDIAG_OP_RD;
3309
3310 if (!debug->buffer)
3311 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
3312 if (!debug->buffer)
3313 return 0;
3314 pbuffer = debug->buffer;
3315
3316 if (*ppos)
3317 return 0;
3318
3319 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04003320 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3321 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05003322 } else
3323 return 0;
3324
3325 /* Read single PCI config space register */
3326 switch (count) {
3327 case SIZE_U8: /* byte (8 bits) */
3328 pci_read_config_byte(pdev, where, &u8val);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003329 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003330 "%03x: %02x\n", where, u8val);
3331 break;
3332 case SIZE_U16: /* word (16 bits) */
3333 pci_read_config_word(pdev, where, &u16val);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003334 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003335 "%03x: %04x\n", where, u16val);
3336 break;
3337 case SIZE_U32: /* double word (32 bits) */
3338 pci_read_config_dword(pdev, where, &u32val);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003339 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003340 "%03x: %08x\n", where, u32val);
3341 break;
James Smart86a80842011-04-16 11:03:04 -04003342 case LPFC_PCI_CFG_BROWSE: /* browse all */
James Smart2a622bf2011-02-16 12:40:06 -05003343 goto pcicfg_browse;
3344 break;
3345 default:
3346 /* illegal count */
3347 len = 0;
3348 break;
3349 }
3350 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3351
3352pcicfg_browse:
3353
3354 /* Browse all PCI config space registers */
3355 offset_label = idiag.offset.last_rd;
3356 offset = offset_label;
3357
3358 /* Read PCI config space */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003359 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003360 "%03x: ", offset_label);
3361 while (index > 0) {
3362 pci_read_config_dword(pdev, offset, &u32val);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003363 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003364 "%08x ", u32val);
3365 offset += sizeof(uint32_t);
James Smartb76f2dc2011-07-22 18:37:42 -04003366 if (offset >= LPFC_PCI_CFG_SIZE) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003367 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003368 LPFC_PCI_CFG_SIZE-len, "\n");
3369 break;
3370 }
James Smart2a622bf2011-02-16 12:40:06 -05003371 index -= sizeof(uint32_t);
3372 if (!index)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003373 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003374 "\n");
3375 else if (!(index % (8 * sizeof(uint32_t)))) {
3376 offset_label += (8 * sizeof(uint32_t));
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003377 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003378 "\n%03x: ", offset_label);
3379 }
3380 }
3381
3382 /* Set up the offset for next portion of pci cfg read */
James Smartb76f2dc2011-07-22 18:37:42 -04003383 if (index == 0) {
3384 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
3385 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
3386 idiag.offset.last_rd = 0;
3387 } else
James Smart2a622bf2011-02-16 12:40:06 -05003388 idiag.offset.last_rd = 0;
3389
3390 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3391}
3392
3393/**
3394 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
3395 * @file: The file pointer to read from.
3396 * @buf: The buffer to copy the user data from.
3397 * @nbytes: The number of bytes to get.
3398 * @ppos: The position in the file to start reading from.
3399 *
3400 * This routine get the debugfs idiag command struct from user space and
3401 * then perform the syntax check for PCI config space read or write command
3402 * accordingly. In the case of PCI config space read command, it sets up
3403 * the command in the idiag command struct for the debugfs read operation.
3404 * In the case of PCI config space write operation, it executes the write
3405 * operation into the PCI config space accordingly.
3406 *
3407 * It returns the @nbytges passing in from debugfs user space when successful.
3408 * In case of error conditions, it returns proper error code back to the user
3409 * space.
3410 */
3411static ssize_t
3412lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
3413 size_t nbytes, loff_t *ppos)
3414{
3415 struct lpfc_debug *debug = file->private_data;
3416 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3417 uint32_t where, value, count;
3418 uint32_t u32val;
3419 uint16_t u16val;
3420 uint8_t u8val;
3421 struct pci_dev *pdev;
3422 int rc;
3423
3424 pdev = phba->pcidev;
3425 if (!pdev)
3426 return -EFAULT;
3427
3428 /* This is a user write operation */
3429 debug->op = LPFC_IDIAG_OP_WR;
3430
3431 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
James Smart86a80842011-04-16 11:03:04 -04003432 if (rc < 0)
James Smart2a622bf2011-02-16 12:40:06 -05003433 return rc;
3434
3435 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smart86a80842011-04-16 11:03:04 -04003436 /* Sanity check on PCI config read command line arguments */
3437 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
3438 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05003439 /* Read command from PCI config space, set up command fields */
James Smartb76f2dc2011-07-22 18:37:42 -04003440 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3441 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04003442 if (count == LPFC_PCI_CFG_BROWSE) {
3443 if (where % sizeof(uint32_t))
James Smart2a622bf2011-02-16 12:40:06 -05003444 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04003445 /* Starting offset to browse */
3446 idiag.offset.last_rd = where;
James Smart2a622bf2011-02-16 12:40:06 -05003447 } else if ((count != sizeof(uint8_t)) &&
3448 (count != sizeof(uint16_t)) &&
3449 (count != sizeof(uint32_t)))
3450 goto error_out;
3451 if (count == sizeof(uint8_t)) {
3452 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
3453 goto error_out;
3454 if (where % sizeof(uint8_t))
3455 goto error_out;
3456 }
3457 if (count == sizeof(uint16_t)) {
3458 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
3459 goto error_out;
3460 if (where % sizeof(uint16_t))
3461 goto error_out;
3462 }
3463 if (count == sizeof(uint32_t)) {
3464 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
3465 goto error_out;
3466 if (where % sizeof(uint32_t))
3467 goto error_out;
3468 }
3469 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
3470 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
3471 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
James Smart86a80842011-04-16 11:03:04 -04003472 /* Sanity check on PCI config write command line arguments */
3473 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
3474 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05003475 /* Write command to PCI config space, read-modify-write */
James Smartb76f2dc2011-07-22 18:37:42 -04003476 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3477 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
3478 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05003479 /* Sanity checks */
3480 if ((count != sizeof(uint8_t)) &&
3481 (count != sizeof(uint16_t)) &&
3482 (count != sizeof(uint32_t)))
3483 goto error_out;
3484 if (count == sizeof(uint8_t)) {
3485 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
3486 goto error_out;
3487 if (where % sizeof(uint8_t))
3488 goto error_out;
3489 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3490 pci_write_config_byte(pdev, where,
3491 (uint8_t)value);
3492 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3493 rc = pci_read_config_byte(pdev, where, &u8val);
3494 if (!rc) {
3495 u8val |= (uint8_t)value;
3496 pci_write_config_byte(pdev, where,
3497 u8val);
3498 }
3499 }
3500 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3501 rc = pci_read_config_byte(pdev, where, &u8val);
3502 if (!rc) {
3503 u8val &= (uint8_t)(~value);
3504 pci_write_config_byte(pdev, where,
3505 u8val);
3506 }
3507 }
3508 }
3509 if (count == sizeof(uint16_t)) {
3510 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
3511 goto error_out;
3512 if (where % sizeof(uint16_t))
3513 goto error_out;
3514 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3515 pci_write_config_word(pdev, where,
3516 (uint16_t)value);
3517 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3518 rc = pci_read_config_word(pdev, where, &u16val);
3519 if (!rc) {
3520 u16val |= (uint16_t)value;
3521 pci_write_config_word(pdev, where,
3522 u16val);
3523 }
3524 }
3525 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3526 rc = pci_read_config_word(pdev, where, &u16val);
3527 if (!rc) {
3528 u16val &= (uint16_t)(~value);
3529 pci_write_config_word(pdev, where,
3530 u16val);
3531 }
3532 }
3533 }
3534 if (count == sizeof(uint32_t)) {
3535 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
3536 goto error_out;
3537 if (where % sizeof(uint32_t))
3538 goto error_out;
3539 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3540 pci_write_config_dword(pdev, where, value);
3541 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3542 rc = pci_read_config_dword(pdev, where,
3543 &u32val);
3544 if (!rc) {
3545 u32val |= value;
3546 pci_write_config_dword(pdev, where,
3547 u32val);
3548 }
3549 }
3550 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3551 rc = pci_read_config_dword(pdev, where,
3552 &u32val);
3553 if (!rc) {
3554 u32val &= ~value;
3555 pci_write_config_dword(pdev, where,
3556 u32val);
3557 }
3558 }
3559 }
3560 } else
3561 /* All other opecodes are illegal for now */
3562 goto error_out;
3563
3564 return nbytes;
3565error_out:
3566 memset(&idiag, 0, sizeof(idiag));
3567 return -EINVAL;
3568}
3569
3570/**
James Smartb76f2dc2011-07-22 18:37:42 -04003571 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
3572 * @file: The file pointer to read from.
3573 * @buf: The buffer to copy the data to.
3574 * @nbytes: The number of bytes to read.
3575 * @ppos: The position in the file to start reading from.
3576 *
3577 * Description:
3578 * This routine reads data from the @phba pci bar memory mapped space
3579 * according to the idiag command, and copies to user @buf.
3580 *
3581 * Returns:
3582 * This function returns the amount of data that was read (this could be less
3583 * than @nbytes if the end of the file was reached) or a negative error value.
3584 **/
3585static ssize_t
3586lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
3587 loff_t *ppos)
3588{
3589 struct lpfc_debug *debug = file->private_data;
3590 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3591 int offset_label, offset, offset_run, len = 0, index;
3592 int bar_num, acc_range, bar_size;
3593 char *pbuffer;
3594 void __iomem *mem_mapped_bar;
3595 uint32_t if_type;
3596 struct pci_dev *pdev;
3597 uint32_t u32val;
3598
3599 pdev = phba->pcidev;
3600 if (!pdev)
3601 return 0;
3602
3603 /* This is a user read operation */
3604 debug->op = LPFC_IDIAG_OP_RD;
3605
3606 if (!debug->buffer)
3607 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
3608 if (!debug->buffer)
3609 return 0;
3610 pbuffer = debug->buffer;
3611
3612 if (*ppos)
3613 return 0;
3614
3615 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3616 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
3617 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3618 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3619 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3620 } else
3621 return 0;
3622
3623 if (acc_range == 0)
3624 return 0;
3625
3626 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3627 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3628 if (bar_num == IDIAG_BARACC_BAR_0)
3629 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3630 else if (bar_num == IDIAG_BARACC_BAR_1)
3631 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
3632 else if (bar_num == IDIAG_BARACC_BAR_2)
3633 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3634 else
3635 return 0;
3636 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3637 if (bar_num == IDIAG_BARACC_BAR_0)
3638 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3639 else
3640 return 0;
3641 } else
3642 return 0;
3643
3644 /* Read single PCI bar space register */
3645 if (acc_range == SINGLE_WORD) {
3646 offset_run = offset;
3647 u32val = readl(mem_mapped_bar + offset_run);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003648 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04003649 "%05x: %08x\n", offset_run, u32val);
3650 } else
3651 goto baracc_browse;
3652
3653 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3654
3655baracc_browse:
3656
3657 /* Browse all PCI bar space registers */
3658 offset_label = idiag.offset.last_rd;
3659 offset_run = offset_label;
3660
3661 /* Read PCI bar memory mapped space */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003662 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04003663 "%05x: ", offset_label);
3664 index = LPFC_PCI_BAR_RD_SIZE;
3665 while (index > 0) {
3666 u32val = readl(mem_mapped_bar + offset_run);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003667 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04003668 "%08x ", u32val);
3669 offset_run += sizeof(uint32_t);
3670 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3671 if (offset_run >= bar_size) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003672 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003673 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3674 break;
3675 }
3676 } else {
3677 if (offset_run >= offset +
3678 (acc_range * sizeof(uint32_t))) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003679 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003680 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3681 break;
3682 }
3683 }
3684 index -= sizeof(uint32_t);
3685 if (!index)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003686 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003687 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3688 else if (!(index % (8 * sizeof(uint32_t)))) {
3689 offset_label += (8 * sizeof(uint32_t));
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003690 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003691 LPFC_PCI_BAR_RD_BUF_SIZE-len,
3692 "\n%05x: ", offset_label);
3693 }
3694 }
3695
3696 /* Set up the offset for next portion of pci bar read */
3697 if (index == 0) {
3698 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
3699 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3700 if (idiag.offset.last_rd >= bar_size)
3701 idiag.offset.last_rd = 0;
3702 } else {
3703 if (offset_run >= offset +
3704 (acc_range * sizeof(uint32_t)))
3705 idiag.offset.last_rd = offset;
3706 }
3707 } else {
3708 if (acc_range == LPFC_PCI_BAR_BROWSE)
3709 idiag.offset.last_rd = 0;
3710 else
3711 idiag.offset.last_rd = offset;
3712 }
3713
3714 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3715}
3716
3717/**
3718 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
3719 * @file: The file pointer to read from.
3720 * @buf: The buffer to copy the user data from.
3721 * @nbytes: The number of bytes to get.
3722 * @ppos: The position in the file to start reading from.
3723 *
3724 * This routine get the debugfs idiag command struct from user space and
3725 * then perform the syntax check for PCI bar memory mapped space read or
3726 * write command accordingly. In the case of PCI bar memory mapped space
3727 * read command, it sets up the command in the idiag command struct for
3728 * the debugfs read operation. In the case of PCI bar memorpy mapped space
3729 * write operation, it executes the write operation into the PCI bar memory
3730 * mapped space accordingly.
3731 *
3732 * It returns the @nbytges passing in from debugfs user space when successful.
3733 * In case of error conditions, it returns proper error code back to the user
3734 * space.
3735 */
3736static ssize_t
3737lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
3738 size_t nbytes, loff_t *ppos)
3739{
3740 struct lpfc_debug *debug = file->private_data;
3741 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3742 uint32_t bar_num, bar_size, offset, value, acc_range;
3743 struct pci_dev *pdev;
3744 void __iomem *mem_mapped_bar;
3745 uint32_t if_type;
3746 uint32_t u32val;
3747 int rc;
3748
3749 pdev = phba->pcidev;
3750 if (!pdev)
3751 return -EFAULT;
3752
3753 /* This is a user write operation */
3754 debug->op = LPFC_IDIAG_OP_WR;
3755
3756 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3757 if (rc < 0)
3758 return rc;
3759
3760 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3761 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
3762
3763 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3764 if ((bar_num != IDIAG_BARACC_BAR_0) &&
3765 (bar_num != IDIAG_BARACC_BAR_1) &&
3766 (bar_num != IDIAG_BARACC_BAR_2))
3767 goto error_out;
3768 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3769 if (bar_num != IDIAG_BARACC_BAR_0)
3770 goto error_out;
3771 } else
3772 goto error_out;
3773
3774 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3775 if (bar_num == IDIAG_BARACC_BAR_0) {
3776 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3777 LPFC_PCI_IF0_BAR0_SIZE;
3778 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3779 } else if (bar_num == IDIAG_BARACC_BAR_1) {
3780 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3781 LPFC_PCI_IF0_BAR1_SIZE;
3782 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
3783 } else if (bar_num == IDIAG_BARACC_BAR_2) {
3784 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3785 LPFC_PCI_IF0_BAR2_SIZE;
3786 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3787 } else
3788 goto error_out;
3789 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3790 if (bar_num == IDIAG_BARACC_BAR_0) {
3791 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3792 LPFC_PCI_IF2_BAR0_SIZE;
3793 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3794 } else
3795 goto error_out;
3796 } else
3797 goto error_out;
3798
3799 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3800 if (offset % sizeof(uint32_t))
3801 goto error_out;
3802
3803 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3804 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3805 /* Sanity check on PCI config read command line arguments */
3806 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3807 goto error_out;
3808 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3809 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3810 if (offset > bar_size - sizeof(uint32_t))
3811 goto error_out;
3812 /* Starting offset to browse */
3813 idiag.offset.last_rd = offset;
3814 } else if (acc_range > SINGLE_WORD) {
3815 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3816 goto error_out;
3817 /* Starting offset to browse */
3818 idiag.offset.last_rd = offset;
3819 } else if (acc_range != SINGLE_WORD)
3820 goto error_out;
3821 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3822 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3823 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3824 /* Sanity check on PCI bar write command line arguments */
3825 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3826 goto error_out;
3827 /* Write command to PCI bar space, read-modify-write */
3828 acc_range = SINGLE_WORD;
3829 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3830 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3831 writel(value, mem_mapped_bar + offset);
3832 readl(mem_mapped_bar + offset);
3833 }
3834 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3835 u32val = readl(mem_mapped_bar + offset);
3836 u32val |= value;
3837 writel(u32val, mem_mapped_bar + offset);
3838 readl(mem_mapped_bar + offset);
3839 }
3840 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3841 u32val = readl(mem_mapped_bar + offset);
3842 u32val &= ~value;
3843 writel(u32val, mem_mapped_bar + offset);
3844 readl(mem_mapped_bar + offset);
3845 }
3846 } else
3847 /* All other opecodes are illegal for now */
3848 goto error_out;
3849
3850 return nbytes;
3851error_out:
3852 memset(&idiag, 0, sizeof(idiag));
3853 return -EINVAL;
3854}
3855
James Smart07bcd982017-02-12 13:52:28 -08003856static int
3857__lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3858 char *pbuffer, int len)
3859{
3860 if (!qp)
3861 return len;
3862
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003863 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003864 "\t\t%s WQ info: ", wqtype);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003865 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003866 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3867 qp->assoc_qid, qp->q_cnt_1,
3868 (unsigned long long)qp->q_cnt_4);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003869 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07003870 "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08003871 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]",
James Smart07bcd982017-02-12 13:52:28 -08003872 qp->queue_id, qp->entry_count,
3873 qp->entry_size, qp->host_index,
James Smart32517fc2019-01-28 11:14:33 -08003874 qp->hba_index, qp->notify_interval);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003875 len += scnprintf(pbuffer + len,
James Smart07bcd982017-02-12 13:52:28 -08003876 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3877 return len;
3878}
3879
3880static int
3881lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3882 int *len, int max_cnt, int cq_id)
3883{
3884 struct lpfc_queue *qp;
3885 int qidx;
3886
James Smartcdb42be2019-01-28 11:14:21 -08003887 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smartc00f62e2019-08-14 16:57:11 -07003888 qp = phba->sli4_hba.hdwq[qidx].io_wq;
James Smart07bcd982017-02-12 13:52:28 -08003889 if (qp->assoc_qid != cq_id)
3890 continue;
3891 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3892 if (*len >= max_cnt)
3893 return 1;
3894 }
3895 return 0;
3896}
3897
3898static int
3899__lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3900 char *pbuffer, int len)
3901{
3902 if (!qp)
3903 return len;
3904
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003905 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003906 "\t%s CQ info: ", cqtype);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003907 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003908 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3909 "xabt:x%x wq:x%llx]\n",
3910 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3911 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003912 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07003913 "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08003914 "HST-IDX[%04d], NTFI[%03d], PLMT[%03d]",
James Smart07bcd982017-02-12 13:52:28 -08003915 qp->queue_id, qp->entry_count,
3916 qp->entry_size, qp->host_index,
James Smart32517fc2019-01-28 11:14:33 -08003917 qp->notify_interval, qp->max_proc_limit);
James Smart07bcd982017-02-12 13:52:28 -08003918
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003919 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3920 "\n");
James Smart07bcd982017-02-12 13:52:28 -08003921
3922 return len;
3923}
3924
3925static int
3926__lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3927 char *rqtype, char *pbuffer, int len)
3928{
3929 if (!qp || !datqp)
3930 return len;
3931
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003932 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003933 "\t\t%s RQ info: ", rqtype);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003934 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003935 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
James Smart547077a2017-05-15 15:20:40 -07003936 "posted:x%x rcv:x%llx]\n",
James Smart07bcd982017-02-12 13:52:28 -08003937 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3938 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003939 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07003940 "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08003941 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
James Smart07bcd982017-02-12 13:52:28 -08003942 qp->queue_id, qp->entry_count, qp->entry_size,
James Smart32517fc2019-01-28 11:14:33 -08003943 qp->host_index, qp->hba_index, qp->notify_interval);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003944 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07003945 "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08003946 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
James Smart07bcd982017-02-12 13:52:28 -08003947 datqp->queue_id, datqp->entry_count,
3948 datqp->entry_size, datqp->host_index,
James Smart32517fc2019-01-28 11:14:33 -08003949 datqp->hba_index, datqp->notify_interval);
James Smart07bcd982017-02-12 13:52:28 -08003950 return len;
3951}
3952
3953static int
3954lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
James Smart2d7dbc42017-02-12 13:52:35 -08003955 int *len, int max_cnt, int eqidx, int eq_id)
James Smart07bcd982017-02-12 13:52:28 -08003956{
3957 struct lpfc_queue *qp;
James Smart6a828b02019-01-28 11:14:31 -08003958 int rc;
James Smart07bcd982017-02-12 13:52:28 -08003959
James Smartc00f62e2019-08-14 16:57:11 -07003960 qp = phba->sli4_hba.hdwq[eqidx].io_cq;
James Smart07bcd982017-02-12 13:52:28 -08003961
James Smartc00f62e2019-08-14 16:57:11 -07003962 *len = __lpfc_idiag_print_cq(qp, "IO", pbuffer, *len);
James Smart6a828b02019-01-28 11:14:31 -08003963
3964 /* Reset max counter */
3965 qp->CQ_max_cqe = 0;
3966
3967 if (*len >= max_cnt)
3968 return 1;
3969
James Smartc00f62e2019-08-14 16:57:11 -07003970 rc = lpfc_idiag_wqs_for_cq(phba, "IO", pbuffer, len,
James Smart6a828b02019-01-28 11:14:31 -08003971 max_cnt, qp->queue_id);
3972 if (rc)
3973 return 1;
3974
James Smartbcb24f62017-11-20 16:00:36 -08003975 if ((eqidx < phba->cfg_nvmet_mrq) && phba->nvmet_support) {
James Smart2d7dbc42017-02-12 13:52:35 -08003976 /* NVMET CQset */
3977 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3978 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3979
3980 /* Reset max counter */
3981 qp->CQ_max_cqe = 0;
3982
3983 if (*len >= max_cnt)
3984 return 1;
3985
3986 /* RQ header */
3987 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3988 *len = __lpfc_idiag_print_rqpair(qp,
3989 phba->sli4_hba.nvmet_mrq_data[eqidx],
3990 "NVMET MRQ", pbuffer, *len);
3991
3992 if (*len >= max_cnt)
3993 return 1;
3994 }
3995
James Smart07bcd982017-02-12 13:52:28 -08003996 return 0;
3997}
3998
3999static int
4000__lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
4001 char *pbuffer, int len)
4002{
4003 if (!qp)
4004 return len;
4005
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004006 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08004007 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
James Smart07d494f2017-11-20 16:00:35 -08004008 "cqe_proc:x%x eqe_proc:x%llx eqd %d]\n",
James Smart07bcd982017-02-12 13:52:28 -08004009 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
James Smart0cf07f842017-06-01 21:07:10 -07004010 (unsigned long long)qp->q_cnt_4, qp->q_mode);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004011 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07004012 "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08004013 "HST-IDX[%04d], NTFI[%03d], PLMT[%03d], AFFIN[%03d]",
James Smart07bcd982017-02-12 13:52:28 -08004014 qp->queue_id, qp->entry_count, qp->entry_size,
James Smart32517fc2019-01-28 11:14:33 -08004015 qp->host_index, qp->notify_interval,
4016 qp->max_proc_limit, qp->chann);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004017 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
4018 "\n");
James Smart07bcd982017-02-12 13:52:28 -08004019
4020 return len;
4021}
4022
James Smartb76f2dc2011-07-22 18:37:42 -04004023/**
James Smart2a622bf2011-02-16 12:40:06 -05004024 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
4025 * @file: The file pointer to read from.
4026 * @buf: The buffer to copy the data to.
4027 * @nbytes: The number of bytes to read.
4028 * @ppos: The position in the file to start reading from.
4029 *
4030 * Description:
4031 * This routine reads data from the @phba SLI4 PCI function queue information,
4032 * and copies to user @buf.
James Smart07bcd982017-02-12 13:52:28 -08004033 * This routine only returns 1 EQs worth of information. It remembers the last
4034 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
4035 * retrieve all EQs allocated for the phba.
James Smart2a622bf2011-02-16 12:40:06 -05004036 *
4037 * Returns:
4038 * This function returns the amount of data that was read (this could be less
4039 * than @nbytes if the end of the file was reached) or a negative error value.
4040 **/
4041static ssize_t
4042lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
4043 loff_t *ppos)
4044{
4045 struct lpfc_debug *debug = file->private_data;
4046 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
James Smart2a622bf2011-02-16 12:40:06 -05004047 char *pbuffer;
James Smart07bcd982017-02-12 13:52:28 -08004048 int max_cnt, rc, x, len = 0;
James Smartc85a65a2012-08-03 12:37:00 -04004049 struct lpfc_queue *qp = NULL;
4050
James Smart2a622bf2011-02-16 12:40:06 -05004051 if (!debug->buffer)
4052 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
4053 if (!debug->buffer)
4054 return 0;
4055 pbuffer = debug->buffer;
James Smart07bcd982017-02-12 13:52:28 -08004056 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
James Smart2a622bf2011-02-16 12:40:06 -05004057
4058 if (*ppos)
4059 return 0;
4060
James Smartc85a65a2012-08-03 12:37:00 -04004061 spin_lock_irq(&phba->hbalock);
James Smart2a622bf2011-02-16 12:40:06 -05004062
James Smartc85a65a2012-08-03 12:37:00 -04004063 /* Fast-path event queue */
James Smartcdb42be2019-01-28 11:14:21 -08004064 if (phba->sli4_hba.hdwq && phba->cfg_hdw_queue) {
James Smart2a622bf2011-02-16 12:40:06 -05004065
James Smart07bcd982017-02-12 13:52:28 -08004066 x = phba->lpfc_idiag_last_eq;
James Smart07bcd982017-02-12 13:52:28 -08004067 phba->lpfc_idiag_last_eq++;
James Smartcdb42be2019-01-28 11:14:21 -08004068 if (phba->lpfc_idiag_last_eq >= phba->cfg_hdw_queue)
James Smart7370d102019-01-28 11:14:20 -08004069 phba->lpfc_idiag_last_eq = 0;
James Smart2a622bf2011-02-16 12:40:06 -05004070
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004071 len += scnprintf(pbuffer + len,
4072 LPFC_QUE_INFO_GET_BUF_SIZE - len,
4073 "HDWQ %d out of %d HBA HDWQs\n",
4074 x, phba->cfg_hdw_queue);
James Smart07bcd982017-02-12 13:52:28 -08004075
4076 /* Fast-path EQ */
James Smartcdb42be2019-01-28 11:14:21 -08004077 qp = phba->sli4_hba.hdwq[x].hba_eq;
James Smart1ba981f2014-02-20 09:56:45 -05004078 if (!qp)
4079 goto out;
4080
James Smart07bcd982017-02-12 13:52:28 -08004081 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
James Smart1ba981f2014-02-20 09:56:45 -05004082
4083 /* Reset max counter */
4084 qp->EQ_max_eqe = 0;
4085
James Smart07bcd982017-02-12 13:52:28 -08004086 if (len >= max_cnt)
4087 goto too_big;
4088
James Smart895427b2017-02-12 13:52:30 -08004089 /* will dump both fcp and nvme cqs/wqs for the eq */
James Smart07bcd982017-02-12 13:52:28 -08004090 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
James Smart2d7dbc42017-02-12 13:52:35 -08004091 max_cnt, x, qp->queue_id);
James Smart07bcd982017-02-12 13:52:28 -08004092 if (rc)
4093 goto too_big;
4094
4095 /* Only EQ 0 has slow path CQs configured */
4096 if (x)
4097 goto out;
4098
4099 /* Slow-path mailbox CQ */
4100 qp = phba->sli4_hba.mbx_cq;
4101 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
4102 if (len >= max_cnt)
4103 goto too_big;
4104
4105 /* Slow-path MBOX MQ */
4106 qp = phba->sli4_hba.mbx_wq;
4107 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
4108 if (len >= max_cnt)
4109 goto too_big;
4110
4111 /* Slow-path ELS response CQ */
4112 qp = phba->sli4_hba.els_cq;
4113 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
4114 /* Reset max counter */
4115 if (qp)
4116 qp->CQ_max_cqe = 0;
4117 if (len >= max_cnt)
4118 goto too_big;
4119
4120 /* Slow-path ELS WQ */
4121 qp = phba->sli4_hba.els_wq;
4122 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
4123 if (len >= max_cnt)
4124 goto too_big;
4125
James Smart07d494f2017-11-20 16:00:35 -08004126 qp = phba->sli4_hba.hdr_rq;
4127 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
4128 "ELS RQpair", pbuffer, len);
4129 if (len >= max_cnt)
4130 goto too_big;
4131
James Smart895427b2017-02-12 13:52:30 -08004132 /* Slow-path NVME LS response CQ */
4133 qp = phba->sli4_hba.nvmels_cq;
4134 len = __lpfc_idiag_print_cq(qp, "NVME LS",
4135 pbuffer, len);
4136 /* Reset max counter */
4137 if (qp)
4138 qp->CQ_max_cqe = 0;
4139 if (len >= max_cnt)
4140 goto too_big;
4141
4142 /* Slow-path NVME LS WQ */
4143 qp = phba->sli4_hba.nvmels_wq;
4144 len = __lpfc_idiag_print_wq(qp, "NVME LS",
4145 pbuffer, len);
4146 if (len >= max_cnt)
4147 goto too_big;
4148
James Smart07bcd982017-02-12 13:52:28 -08004149 goto out;
4150 }
4151
James Smartc85a65a2012-08-03 12:37:00 -04004152 spin_unlock_irq(&phba->hbalock);
4153 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4154
4155too_big:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004156 len += scnprintf(pbuffer + len,
James Smart07bcd982017-02-12 13:52:28 -08004157 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
4158out:
James Smartc85a65a2012-08-03 12:37:00 -04004159 spin_unlock_irq(&phba->hbalock);
James Smart2a622bf2011-02-16 12:40:06 -05004160 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4161}
4162
James Smart86a80842011-04-16 11:03:04 -04004163/**
4164 * lpfc_idiag_que_param_check - queue access command parameter sanity check
4165 * @q: The pointer to queue structure.
4166 * @index: The index into a queue entry.
4167 * @count: The number of queue entries to access.
4168 *
4169 * Description:
4170 * The routine performs sanity check on device queue access method commands.
4171 *
4172 * Returns:
4173 * This function returns -EINVAL when fails the sanity check, otherwise, it
4174 * returns 0.
4175 **/
4176static int
4177lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
4178{
4179 /* Only support single entry read or browsing */
4180 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
4181 return -EINVAL;
4182 if (index > q->entry_count - 1)
4183 return -EINVAL;
4184 return 0;
4185}
4186
4187/**
4188 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
4189 * @pbuffer: The pointer to buffer to copy the read data into.
4190 * @pque: The pointer to the queue to be read.
4191 * @index: The index into the queue entry.
4192 *
4193 * Description:
4194 * This routine reads out a single entry from the given queue's index location
4195 * and copies it into the buffer provided.
4196 *
4197 * Returns:
4198 * This function returns 0 when it fails, otherwise, it returns the length of
4199 * the data read into the buffer provided.
4200 **/
4201static int
4202lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
4203 uint32_t index)
4204{
4205 int offset, esize;
4206 uint32_t *pentry;
4207
4208 if (!pbuffer || !pque)
4209 return 0;
4210
4211 esize = pque->entry_size;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004212 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04004213 "QE-INDEX[%04d]:\n", index);
4214
4215 offset = 0;
James Smart9afbee32019-03-12 16:30:28 -07004216 pentry = lpfc_sli4_qe(pque, index);
James Smart86a80842011-04-16 11:03:04 -04004217 while (esize > 0) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004218 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04004219 "%08x ", *pentry);
4220 pentry++;
4221 offset += sizeof(uint32_t);
4222 esize -= sizeof(uint32_t);
4223 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004224 len += scnprintf(pbuffer+len,
James Smart86a80842011-04-16 11:03:04 -04004225 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
4226 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004227 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
James Smart86a80842011-04-16 11:03:04 -04004228
4229 return len;
4230}
4231
4232/**
4233 * lpfc_idiag_queacc_read - idiag debugfs read port queue
4234 * @file: The file pointer to read from.
4235 * @buf: The buffer to copy the data to.
4236 * @nbytes: The number of bytes to read.
4237 * @ppos: The position in the file to start reading from.
4238 *
4239 * Description:
4240 * This routine reads data from the @phba device queue memory according to the
4241 * idiag command, and copies to user @buf. Depending on the queue dump read
4242 * command setup, it does either a single queue entry read or browing through
4243 * all entries of the queue.
4244 *
4245 * Returns:
4246 * This function returns the amount of data that was read (this could be less
4247 * than @nbytes if the end of the file was reached) or a negative error value.
4248 **/
4249static ssize_t
4250lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
4251 loff_t *ppos)
4252{
4253 struct lpfc_debug *debug = file->private_data;
4254 uint32_t last_index, index, count;
4255 struct lpfc_queue *pque = NULL;
4256 char *pbuffer;
4257 int len = 0;
4258
4259 /* This is a user read operation */
4260 debug->op = LPFC_IDIAG_OP_RD;
4261
4262 if (!debug->buffer)
4263 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
4264 if (!debug->buffer)
4265 return 0;
4266 pbuffer = debug->buffer;
4267
4268 if (*ppos)
4269 return 0;
4270
4271 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04004272 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
4273 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04004274 pque = (struct lpfc_queue *)idiag.ptr_private;
4275 } else
4276 return 0;
4277
4278 /* Browse the queue starting from index */
4279 if (count == LPFC_QUE_ACC_BROWSE)
4280 goto que_browse;
4281
4282 /* Read a single entry from the queue */
4283 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
4284
4285 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4286
4287que_browse:
4288
4289 /* Browse all entries from the queue */
4290 last_index = idiag.offset.last_rd;
4291 index = last_index;
4292
4293 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
4294 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
4295 index++;
4296 if (index > pque->entry_count - 1)
4297 break;
4298 }
4299
4300 /* Set up the offset for next portion of pci cfg read */
4301 if (index > pque->entry_count - 1)
4302 index = 0;
4303 idiag.offset.last_rd = index;
4304
4305 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4306}
4307
4308/**
4309 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
4310 * @file: The file pointer to read from.
4311 * @buf: The buffer to copy the user data from.
4312 * @nbytes: The number of bytes to get.
4313 * @ppos: The position in the file to start reading from.
4314 *
4315 * This routine get the debugfs idiag command struct from user space and then
4316 * perform the syntax check for port queue read (dump) or write (set) command
4317 * accordingly. In the case of port queue read command, it sets up the command
4318 * in the idiag command struct for the following debugfs read operation. In
4319 * the case of port queue write operation, it executes the write operation
4320 * into the port queue entry accordingly.
4321 *
4322 * It returns the @nbytges passing in from debugfs user space when successful.
4323 * In case of error conditions, it returns proper error code back to the user
4324 * space.
4325 **/
4326static ssize_t
4327lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
4328 size_t nbytes, loff_t *ppos)
4329{
4330 struct lpfc_debug *debug = file->private_data;
4331 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4332 uint32_t qidx, quetp, queid, index, count, offset, value;
4333 uint32_t *pentry;
James Smart895427b2017-02-12 13:52:30 -08004334 struct lpfc_queue *pque, *qp;
James Smart86a80842011-04-16 11:03:04 -04004335 int rc;
4336
4337 /* This is a user write operation */
4338 debug->op = LPFC_IDIAG_OP_WR;
4339
4340 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4341 if (rc < 0)
4342 return rc;
4343
4344 /* Get and sanity check on command feilds */
James Smartb76f2dc2011-07-22 18:37:42 -04004345 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
4346 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
4347 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
4348 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
4349 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
4350 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04004351
4352 /* Sanity check on command line arguments */
4353 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
4354 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
4355 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
4356 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
4357 goto error_out;
4358 if (count != 1)
4359 goto error_out;
4360 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4361 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
4362 goto error_out;
4363 } else
4364 goto error_out;
4365
4366 switch (quetp) {
4367 case LPFC_IDIAG_EQ:
James Smart67d12732012-08-03 12:36:13 -04004368 /* HBA event queue */
James Smartcdb42be2019-01-28 11:14:21 -08004369 if (phba->sli4_hba.hdwq) {
4370 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
4371 qp = phba->sli4_hba.hdwq[qidx].hba_eq;
James Smart895427b2017-02-12 13:52:30 -08004372 if (qp && qp->queue_id == queid) {
James Smart2e90f4b2011-12-13 13:22:37 -05004373 /* Sanity check */
James Smart895427b2017-02-12 13:52:30 -08004374 rc = lpfc_idiag_que_param_check(qp,
James Smart86a80842011-04-16 11:03:04 -04004375 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05004376 if (rc)
4377 goto error_out;
James Smart895427b2017-02-12 13:52:30 -08004378 idiag.ptr_private = qp;
James Smart2e90f4b2011-12-13 13:22:37 -05004379 goto pass_check;
4380 }
James Smart86a80842011-04-16 11:03:04 -04004381 }
4382 }
4383 goto error_out;
4384 break;
4385 case LPFC_IDIAG_CQ:
4386 /* MBX complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004387 if (phba->sli4_hba.mbx_cq &&
4388 phba->sli4_hba.mbx_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004389 /* Sanity check */
4390 rc = lpfc_idiag_que_param_check(
4391 phba->sli4_hba.mbx_cq, index, count);
4392 if (rc)
4393 goto error_out;
4394 idiag.ptr_private = phba->sli4_hba.mbx_cq;
4395 goto pass_check;
4396 }
4397 /* ELS complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004398 if (phba->sli4_hba.els_cq &&
4399 phba->sli4_hba.els_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004400 /* Sanity check */
4401 rc = lpfc_idiag_que_param_check(
4402 phba->sli4_hba.els_cq, index, count);
4403 if (rc)
4404 goto error_out;
4405 idiag.ptr_private = phba->sli4_hba.els_cq;
4406 goto pass_check;
4407 }
James Smart895427b2017-02-12 13:52:30 -08004408 /* NVME LS complete queue */
4409 if (phba->sli4_hba.nvmels_cq &&
4410 phba->sli4_hba.nvmels_cq->queue_id == queid) {
4411 /* Sanity check */
4412 rc = lpfc_idiag_que_param_check(
4413 phba->sli4_hba.nvmels_cq, index, count);
4414 if (rc)
4415 goto error_out;
4416 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
4417 goto pass_check;
4418 }
James Smart86a80842011-04-16 11:03:04 -04004419 /* FCP complete queue */
James Smartcdb42be2019-01-28 11:14:21 -08004420 if (phba->sli4_hba.hdwq) {
4421 for (qidx = 0; qidx < phba->cfg_hdw_queue;
James Smart895427b2017-02-12 13:52:30 -08004422 qidx++) {
James Smartc00f62e2019-08-14 16:57:11 -07004423 qp = phba->sli4_hba.hdwq[qidx].io_cq;
James Smart895427b2017-02-12 13:52:30 -08004424 if (qp && qp->queue_id == queid) {
James Smart2e90f4b2011-12-13 13:22:37 -05004425 /* Sanity check */
4426 rc = lpfc_idiag_que_param_check(
James Smart895427b2017-02-12 13:52:30 -08004427 qp, index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05004428 if (rc)
4429 goto error_out;
James Smart895427b2017-02-12 13:52:30 -08004430 idiag.ptr_private = qp;
James Smart2e90f4b2011-12-13 13:22:37 -05004431 goto pass_check;
4432 }
James Smart895427b2017-02-12 13:52:30 -08004433 }
James Smart2e90f4b2011-12-13 13:22:37 -05004434 }
James Smart86a80842011-04-16 11:03:04 -04004435 goto error_out;
4436 break;
4437 case LPFC_IDIAG_MQ:
4438 /* MBX work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004439 if (phba->sli4_hba.mbx_wq &&
4440 phba->sli4_hba.mbx_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004441 /* Sanity check */
4442 rc = lpfc_idiag_que_param_check(
4443 phba->sli4_hba.mbx_wq, index, count);
4444 if (rc)
4445 goto error_out;
4446 idiag.ptr_private = phba->sli4_hba.mbx_wq;
4447 goto pass_check;
4448 }
James Smart2e90f4b2011-12-13 13:22:37 -05004449 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04004450 break;
4451 case LPFC_IDIAG_WQ:
4452 /* ELS work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004453 if (phba->sli4_hba.els_wq &&
4454 phba->sli4_hba.els_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004455 /* Sanity check */
4456 rc = lpfc_idiag_que_param_check(
4457 phba->sli4_hba.els_wq, index, count);
4458 if (rc)
4459 goto error_out;
4460 idiag.ptr_private = phba->sli4_hba.els_wq;
4461 goto pass_check;
4462 }
James Smart895427b2017-02-12 13:52:30 -08004463 /* NVME LS work queue */
4464 if (phba->sli4_hba.nvmels_wq &&
4465 phba->sli4_hba.nvmels_wq->queue_id == queid) {
4466 /* Sanity check */
4467 rc = lpfc_idiag_que_param_check(
4468 phba->sli4_hba.nvmels_wq, index, count);
4469 if (rc)
4470 goto error_out;
4471 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
4472 goto pass_check;
4473 }
James Smartcdb42be2019-01-28 11:14:21 -08004474
4475 if (phba->sli4_hba.hdwq) {
4476 /* FCP/SCSI work queue */
4477 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smartc00f62e2019-08-14 16:57:11 -07004478 qp = phba->sli4_hba.hdwq[qidx].io_wq;
James Smart895427b2017-02-12 13:52:30 -08004479 if (qp && qp->queue_id == queid) {
4480 /* Sanity check */
4481 rc = lpfc_idiag_que_param_check(
4482 qp, index, count);
4483 if (rc)
4484 goto error_out;
4485 idiag.ptr_private = qp;
James Smart2e90f4b2011-12-13 13:22:37 -05004486 goto pass_check;
4487 }
James Smart86a80842011-04-16 11:03:04 -04004488 }
4489 }
James Smartbd2cdd52017-02-12 13:52:33 -08004490
James Smart86a80842011-04-16 11:03:04 -04004491 goto error_out;
4492 break;
4493 case LPFC_IDIAG_RQ:
4494 /* HDR queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004495 if (phba->sli4_hba.hdr_rq &&
4496 phba->sli4_hba.hdr_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004497 /* Sanity check */
4498 rc = lpfc_idiag_que_param_check(
4499 phba->sli4_hba.hdr_rq, index, count);
4500 if (rc)
4501 goto error_out;
4502 idiag.ptr_private = phba->sli4_hba.hdr_rq;
4503 goto pass_check;
4504 }
4505 /* DAT queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004506 if (phba->sli4_hba.dat_rq &&
4507 phba->sli4_hba.dat_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004508 /* Sanity check */
4509 rc = lpfc_idiag_que_param_check(
4510 phba->sli4_hba.dat_rq, index, count);
4511 if (rc)
4512 goto error_out;
4513 idiag.ptr_private = phba->sli4_hba.dat_rq;
4514 goto pass_check;
4515 }
4516 goto error_out;
4517 break;
4518 default:
4519 goto error_out;
4520 break;
4521 }
4522
4523pass_check:
4524
4525 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4526 if (count == LPFC_QUE_ACC_BROWSE)
4527 idiag.offset.last_rd = index;
4528 }
4529
4530 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
4531 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
4532 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
4533 /* Additional sanity checks on write operation */
4534 pque = (struct lpfc_queue *)idiag.ptr_private;
4535 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
4536 goto error_out;
James Smart9afbee32019-03-12 16:30:28 -07004537 pentry = lpfc_sli4_qe(pque, index);
James Smart86a80842011-04-16 11:03:04 -04004538 pentry += offset;
4539 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
4540 *pentry = value;
4541 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
4542 *pentry |= value;
4543 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
4544 *pentry &= ~value;
4545 }
4546 return nbytes;
4547
4548error_out:
4549 /* Clean out command structure on command error out */
4550 memset(&idiag, 0, sizeof(idiag));
4551 return -EINVAL;
4552}
4553
4554/**
4555 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
4556 * @phba: The pointer to hba structure.
4557 * @pbuffer: The pointer to the buffer to copy the data to.
Matteo Croce92684bf2019-01-04 22:38:54 +01004558 * @len: The length of bytes to copied.
James Smart86a80842011-04-16 11:03:04 -04004559 * @drbregid: The id to doorbell registers.
4560 *
4561 * Description:
4562 * This routine reads a doorbell register and copies its content to the
4563 * user buffer pointed to by @pbuffer.
4564 *
4565 * Returns:
4566 * This function returns the amount of data that was copied into @pbuffer.
4567 **/
4568static int
4569lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4570 int len, uint32_t drbregid)
4571{
4572
4573 if (!pbuffer)
4574 return 0;
4575
4576 switch (drbregid) {
James Smart9dd35422018-02-22 08:18:41 -08004577 case LPFC_DRB_EQ:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004578 len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE-len,
James Smart9dd35422018-02-22 08:18:41 -08004579 "EQ-DRB-REG: 0x%08x\n",
4580 readl(phba->sli4_hba.EQDBregaddr));
4581 break;
4582 case LPFC_DRB_CQ:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004583 len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE - len,
James Smart9dd35422018-02-22 08:18:41 -08004584 "CQ-DRB-REG: 0x%08x\n",
4585 readl(phba->sli4_hba.CQDBregaddr));
James Smart86a80842011-04-16 11:03:04 -04004586 break;
4587 case LPFC_DRB_MQ:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004588 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04004589 "MQ-DRB-REG: 0x%08x\n",
4590 readl(phba->sli4_hba.MQDBregaddr));
4591 break;
4592 case LPFC_DRB_WQ:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004593 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04004594 "WQ-DRB-REG: 0x%08x\n",
4595 readl(phba->sli4_hba.WQDBregaddr));
4596 break;
4597 case LPFC_DRB_RQ:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004598 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04004599 "RQ-DRB-REG: 0x%08x\n",
4600 readl(phba->sli4_hba.RQDBregaddr));
4601 break;
4602 default:
4603 break;
4604 }
4605
4606 return len;
4607}
4608
4609/**
4610 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
4611 * @file: The file pointer to read from.
4612 * @buf: The buffer to copy the data to.
4613 * @nbytes: The number of bytes to read.
4614 * @ppos: The position in the file to start reading from.
4615 *
4616 * Description:
4617 * This routine reads data from the @phba device doorbell register according
4618 * to the idiag command, and copies to user @buf. Depending on the doorbell
4619 * register read command setup, it does either a single doorbell register
4620 * read or dump all doorbell registers.
4621 *
4622 * Returns:
4623 * This function returns the amount of data that was read (this could be less
4624 * than @nbytes if the end of the file was reached) or a negative error value.
4625 **/
4626static ssize_t
4627lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
4628 loff_t *ppos)
4629{
4630 struct lpfc_debug *debug = file->private_data;
4631 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4632 uint32_t drb_reg_id, i;
4633 char *pbuffer;
4634 int len = 0;
4635
4636 /* This is a user read operation */
4637 debug->op = LPFC_IDIAG_OP_RD;
4638
4639 if (!debug->buffer)
4640 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
4641 if (!debug->buffer)
4642 return 0;
4643 pbuffer = debug->buffer;
4644
4645 if (*ppos)
4646 return 0;
4647
4648 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
James Smartb76f2dc2011-07-22 18:37:42 -04004649 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
James Smart86a80842011-04-16 11:03:04 -04004650 else
4651 return 0;
4652
4653 if (drb_reg_id == LPFC_DRB_ACC_ALL)
4654 for (i = 1; i <= LPFC_DRB_MAX; i++)
4655 len = lpfc_idiag_drbacc_read_reg(phba,
4656 pbuffer, len, i);
4657 else
4658 len = lpfc_idiag_drbacc_read_reg(phba,
4659 pbuffer, len, drb_reg_id);
4660
4661 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4662}
4663
4664/**
4665 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc 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 port doorbell register read (dump) or write
4673 * (set) command accordingly. In the case of port queue read command, it sets
4674 * up the command in the idiag command struct for the following debugfs read
4675 * operation. In the case of port doorbell register write operation, it
4676 * executes the write operation into the port doorbell register accordingly.
4677 *
4678 * It returns the @nbytges passing in from debugfs user space when successful.
4679 * In case of error conditions, it returns proper error code back to the user
4680 * space.
4681 **/
4682static ssize_t
4683lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4684 size_t nbytes, loff_t *ppos)
4685{
4686 struct lpfc_debug *debug = file->private_data;
4687 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
James Smartb76f2dc2011-07-22 18:37:42 -04004688 uint32_t drb_reg_id, value, reg_val = 0;
James Smart86a80842011-04-16 11:03:04 -04004689 void __iomem *drb_reg;
4690 int rc;
4691
4692 /* This is a user write operation */
4693 debug->op = LPFC_IDIAG_OP_WR;
4694
4695 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4696 if (rc < 0)
4697 return rc;
4698
4699 /* Sanity check on command line arguments */
James Smartb76f2dc2011-07-22 18:37:42 -04004700 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4701 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04004702
4703 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4704 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4705 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4706 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4707 goto error_out;
4708 if (drb_reg_id > LPFC_DRB_MAX)
4709 goto error_out;
4710 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4711 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4712 goto error_out;
4713 if ((drb_reg_id > LPFC_DRB_MAX) &&
4714 (drb_reg_id != LPFC_DRB_ACC_ALL))
4715 goto error_out;
4716 } else
4717 goto error_out;
4718
4719 /* Perform the write access operation */
4720 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4721 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4722 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4723 switch (drb_reg_id) {
James Smart9dd35422018-02-22 08:18:41 -08004724 case LPFC_DRB_EQ:
4725 drb_reg = phba->sli4_hba.EQDBregaddr;
4726 break;
4727 case LPFC_DRB_CQ:
4728 drb_reg = phba->sli4_hba.CQDBregaddr;
James Smart86a80842011-04-16 11:03:04 -04004729 break;
4730 case LPFC_DRB_MQ:
4731 drb_reg = phba->sli4_hba.MQDBregaddr;
4732 break;
4733 case LPFC_DRB_WQ:
4734 drb_reg = phba->sli4_hba.WQDBregaddr;
4735 break;
4736 case LPFC_DRB_RQ:
4737 drb_reg = phba->sli4_hba.RQDBregaddr;
4738 break;
4739 default:
4740 goto error_out;
4741 }
4742
4743 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4744 reg_val = value;
4745 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4746 reg_val = readl(drb_reg);
4747 reg_val |= value;
4748 }
4749 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4750 reg_val = readl(drb_reg);
4751 reg_val &= ~value;
4752 }
4753 writel(reg_val, drb_reg);
4754 readl(drb_reg); /* flush */
4755 }
4756 return nbytes;
4757
4758error_out:
4759 /* Clean out command structure on command error out */
4760 memset(&idiag, 0, sizeof(idiag));
4761 return -EINVAL;
4762}
4763
James Smartb76f2dc2011-07-22 18:37:42 -04004764/**
4765 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4766 * @phba: The pointer to hba structure.
4767 * @pbuffer: The pointer to the buffer to copy the data to.
Matteo Croce92684bf2019-01-04 22:38:54 +01004768 * @len: The length of bytes to copied.
James Smartb76f2dc2011-07-22 18:37:42 -04004769 * @drbregid: The id to doorbell registers.
4770 *
4771 * Description:
4772 * This routine reads a control register and copies its content to the
4773 * user buffer pointed to by @pbuffer.
4774 *
4775 * Returns:
4776 * This function returns the amount of data that was copied into @pbuffer.
4777 **/
4778static int
4779lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4780 int len, uint32_t ctlregid)
4781{
4782
4783 if (!pbuffer)
4784 return 0;
4785
4786 switch (ctlregid) {
4787 case LPFC_CTL_PORT_SEM:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004788 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004789 "Port SemReg: 0x%08x\n",
4790 readl(phba->sli4_hba.conf_regs_memmap_p +
4791 LPFC_CTL_PORT_SEM_OFFSET));
4792 break;
4793 case LPFC_CTL_PORT_STA:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004794 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004795 "Port StaReg: 0x%08x\n",
4796 readl(phba->sli4_hba.conf_regs_memmap_p +
4797 LPFC_CTL_PORT_STA_OFFSET));
4798 break;
4799 case LPFC_CTL_PORT_CTL:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004800 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004801 "Port CtlReg: 0x%08x\n",
4802 readl(phba->sli4_hba.conf_regs_memmap_p +
4803 LPFC_CTL_PORT_CTL_OFFSET));
4804 break;
4805 case LPFC_CTL_PORT_ER1:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004806 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004807 "Port Er1Reg: 0x%08x\n",
4808 readl(phba->sli4_hba.conf_regs_memmap_p +
4809 LPFC_CTL_PORT_ER1_OFFSET));
4810 break;
4811 case LPFC_CTL_PORT_ER2:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004812 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004813 "Port Er2Reg: 0x%08x\n",
4814 readl(phba->sli4_hba.conf_regs_memmap_p +
4815 LPFC_CTL_PORT_ER2_OFFSET));
4816 break;
4817 case LPFC_CTL_PDEV_CTL:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004818 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004819 "PDev CtlReg: 0x%08x\n",
4820 readl(phba->sli4_hba.conf_regs_memmap_p +
4821 LPFC_CTL_PDEV_CTL_OFFSET));
4822 break;
4823 default:
4824 break;
4825 }
4826 return len;
4827}
4828
4829/**
4830 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4831 * @file: The file pointer to read from.
4832 * @buf: The buffer to copy the data to.
4833 * @nbytes: The number of bytes to read.
4834 * @ppos: The position in the file to start reading from.
4835 *
4836 * Description:
4837 * This routine reads data from the @phba port and device registers according
4838 * to the idiag command, and copies to user @buf.
4839 *
4840 * Returns:
4841 * This function returns the amount of data that was read (this could be less
4842 * than @nbytes if the end of the file was reached) or a negative error value.
4843 **/
4844static ssize_t
4845lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4846 loff_t *ppos)
4847{
4848 struct lpfc_debug *debug = file->private_data;
4849 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4850 uint32_t ctl_reg_id, i;
4851 char *pbuffer;
4852 int len = 0;
4853
4854 /* This is a user read operation */
4855 debug->op = LPFC_IDIAG_OP_RD;
4856
4857 if (!debug->buffer)
4858 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4859 if (!debug->buffer)
4860 return 0;
4861 pbuffer = debug->buffer;
4862
4863 if (*ppos)
4864 return 0;
4865
4866 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4867 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4868 else
4869 return 0;
4870
4871 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4872 for (i = 1; i <= LPFC_CTL_MAX; i++)
4873 len = lpfc_idiag_ctlacc_read_reg(phba,
4874 pbuffer, len, i);
4875 else
4876 len = lpfc_idiag_ctlacc_read_reg(phba,
4877 pbuffer, len, ctl_reg_id);
4878
4879 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4880}
4881
4882/**
4883 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4884 * @file: The file pointer to read from.
4885 * @buf: The buffer to copy the user data from.
4886 * @nbytes: The number of bytes to get.
4887 * @ppos: The position in the file to start reading from.
4888 *
4889 * This routine get the debugfs idiag command struct from user space and then
4890 * perform the syntax check for port and device control register read (dump)
4891 * or write (set) command accordingly.
4892 *
4893 * It returns the @nbytges passing in from debugfs user space when successful.
4894 * In case of error conditions, it returns proper error code back to the user
4895 * space.
4896 **/
4897static ssize_t
4898lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4899 size_t nbytes, loff_t *ppos)
4900{
4901 struct lpfc_debug *debug = file->private_data;
4902 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4903 uint32_t ctl_reg_id, value, reg_val = 0;
4904 void __iomem *ctl_reg;
4905 int rc;
4906
4907 /* This is a user write operation */
4908 debug->op = LPFC_IDIAG_OP_WR;
4909
4910 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4911 if (rc < 0)
4912 return rc;
4913
4914 /* Sanity check on command line arguments */
4915 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4916 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4917
4918 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4919 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4920 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4921 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4922 goto error_out;
4923 if (ctl_reg_id > LPFC_CTL_MAX)
4924 goto error_out;
4925 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4926 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4927 goto error_out;
4928 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4929 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4930 goto error_out;
4931 } else
4932 goto error_out;
4933
4934 /* Perform the write access operation */
4935 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4936 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4937 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4938 switch (ctl_reg_id) {
4939 case LPFC_CTL_PORT_SEM:
4940 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4941 LPFC_CTL_PORT_SEM_OFFSET;
4942 break;
4943 case LPFC_CTL_PORT_STA:
4944 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4945 LPFC_CTL_PORT_STA_OFFSET;
4946 break;
4947 case LPFC_CTL_PORT_CTL:
4948 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4949 LPFC_CTL_PORT_CTL_OFFSET;
4950 break;
4951 case LPFC_CTL_PORT_ER1:
4952 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4953 LPFC_CTL_PORT_ER1_OFFSET;
4954 break;
4955 case LPFC_CTL_PORT_ER2:
4956 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4957 LPFC_CTL_PORT_ER2_OFFSET;
4958 break;
4959 case LPFC_CTL_PDEV_CTL:
4960 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4961 LPFC_CTL_PDEV_CTL_OFFSET;
4962 break;
4963 default:
4964 goto error_out;
4965 }
4966
4967 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4968 reg_val = value;
4969 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4970 reg_val = readl(ctl_reg);
4971 reg_val |= value;
4972 }
4973 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4974 reg_val = readl(ctl_reg);
4975 reg_val &= ~value;
4976 }
4977 writel(reg_val, ctl_reg);
4978 readl(ctl_reg); /* flush */
4979 }
4980 return nbytes;
4981
4982error_out:
4983 /* Clean out command structure on command error out */
4984 memset(&idiag, 0, sizeof(idiag));
4985 return -EINVAL;
4986}
4987
4988/**
4989 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4990 * @phba: Pointer to HBA context object.
4991 * @pbuffer: Pointer to data buffer.
4992 *
4993 * Description:
4994 * This routine gets the driver mailbox access debugfs setup information.
4995 *
4996 * Returns:
4997 * This function returns the amount of data that was read (this could be less
4998 * than @nbytes if the end of the file was reached) or a negative error value.
4999 **/
5000static int
5001lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
5002{
5003 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
5004 int len = 0;
5005
5006 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5007 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5008 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5009 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5010
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005011 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005012 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005013 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005014 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005015 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005016 "mbx_word_cnt: %04d\n", mbx_word_cnt);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005017 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005018 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
5019
5020 return len;
5021}
5022
5023/**
5024 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
5025 * @file: The file pointer to read from.
5026 * @buf: The buffer to copy the data to.
5027 * @nbytes: The number of bytes to read.
5028 * @ppos: The position in the file to start reading from.
5029 *
5030 * Description:
5031 * This routine reads data from the @phba driver mailbox access debugfs setup
5032 * information.
5033 *
5034 * Returns:
5035 * This function returns the amount of data that was read (this could be less
5036 * than @nbytes if the end of the file was reached) or a negative error value.
5037 **/
5038static ssize_t
5039lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
5040 loff_t *ppos)
5041{
5042 struct lpfc_debug *debug = file->private_data;
5043 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5044 char *pbuffer;
5045 int len = 0;
5046
5047 /* This is a user read operation */
5048 debug->op = LPFC_IDIAG_OP_RD;
5049
5050 if (!debug->buffer)
5051 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
5052 if (!debug->buffer)
5053 return 0;
5054 pbuffer = debug->buffer;
5055
5056 if (*ppos)
5057 return 0;
5058
5059 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
5060 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
5061 return 0;
5062
5063 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
5064
5065 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
5066}
5067
5068/**
5069 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
5070 * @file: The file pointer to read from.
5071 * @buf: The buffer to copy the user data from.
5072 * @nbytes: The number of bytes to get.
5073 * @ppos: The position in the file to start reading from.
5074 *
5075 * This routine get the debugfs idiag command struct from user space and then
5076 * perform the syntax check for driver mailbox command (dump) and sets up the
5077 * necessary states in the idiag command struct accordingly.
5078 *
5079 * It returns the @nbytges passing in from debugfs user space when successful.
5080 * In case of error conditions, it returns proper error code back to the user
5081 * space.
5082 **/
5083static ssize_t
5084lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
5085 size_t nbytes, loff_t *ppos)
5086{
5087 struct lpfc_debug *debug = file->private_data;
5088 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
5089 int rc;
5090
5091 /* This is a user write operation */
5092 debug->op = LPFC_IDIAG_OP_WR;
5093
5094 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
5095 if (rc < 0)
5096 return rc;
5097
5098 /* Sanity check on command line arguments */
5099 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5100 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5101 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5102 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5103
5104 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
5105 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
5106 goto error_out;
5107 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
5108 (mbx_dump_map != LPFC_MBX_DMP_ALL))
5109 goto error_out;
5110 if (mbx_word_cnt > sizeof(MAILBOX_t))
5111 goto error_out;
5112 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
5113 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
5114 goto error_out;
5115 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
5116 (mbx_dump_map != LPFC_MBX_DMP_ALL))
5117 goto error_out;
5118 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
5119 goto error_out;
5120 if (mbx_mbox_cmd != 0x9b)
5121 goto error_out;
5122 } else
5123 goto error_out;
5124
5125 if (mbx_word_cnt == 0)
5126 goto error_out;
5127 if (rc != LPFC_MBX_DMP_ARG)
5128 goto error_out;
5129 if (mbx_mbox_cmd & ~0xff)
5130 goto error_out;
5131
5132 /* condition for stop mailbox dump */
5133 if (mbx_dump_cnt == 0)
5134 goto reset_out;
5135
5136 return nbytes;
5137
5138reset_out:
5139 /* Clean out command structure on command error out */
5140 memset(&idiag, 0, sizeof(idiag));
5141 return nbytes;
5142
5143error_out:
5144 /* Clean out command structure on command error out */
5145 memset(&idiag, 0, sizeof(idiag));
5146 return -EINVAL;
5147}
5148
5149/**
5150 * lpfc_idiag_extacc_avail_get - get the available extents information
5151 * @phba: pointer to lpfc hba data structure.
5152 * @pbuffer: pointer to internal buffer.
5153 * @len: length into the internal buffer data has been copied.
5154 *
5155 * Description:
5156 * This routine is to get the available extent information.
5157 *
5158 * Returns:
5159 * overall lenth of the data read into the internal buffer.
5160 **/
5161static int
5162lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
5163{
5164 uint16_t ext_cnt, ext_size;
5165
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005166 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005167 "\nAvailable Extents Information:\n");
5168
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005169 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005170 "\tPort Available VPI extents: ");
5171 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
5172 &ext_cnt, &ext_size);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005173 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005174 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5175
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005176 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005177 "\tPort Available VFI extents: ");
5178 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
5179 &ext_cnt, &ext_size);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005180 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005181 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5182
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005183 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005184 "\tPort Available RPI extents: ");
5185 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
5186 &ext_cnt, &ext_size);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005187 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005188 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5189
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005190 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005191 "\tPort Available XRI extents: ");
5192 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
5193 &ext_cnt, &ext_size);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005194 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005195 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5196
5197 return len;
5198}
5199
5200/**
5201 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
5202 * @phba: pointer to lpfc hba data structure.
5203 * @pbuffer: pointer to internal buffer.
5204 * @len: length into the internal buffer data has been copied.
5205 *
5206 * Description:
5207 * This routine is to get the allocated extent information.
5208 *
5209 * Returns:
5210 * overall lenth of the data read into the internal buffer.
5211 **/
5212static int
5213lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
5214{
5215 uint16_t ext_cnt, ext_size;
5216 int rc;
5217
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005218 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005219 "\nAllocated Extents Information:\n");
5220
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005221 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005222 "\tHost Allocated VPI extents: ");
5223 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
5224 &ext_cnt, &ext_size);
5225 if (!rc)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005226 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005227 "Port %d Extent %3d, Size %3d\n",
5228 phba->brd_no, ext_cnt, ext_size);
5229 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005230 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005231 "N/A\n");
5232
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005233 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005234 "\tHost Allocated VFI extents: ");
5235 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
5236 &ext_cnt, &ext_size);
5237 if (!rc)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005238 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005239 "Port %d Extent %3d, Size %3d\n",
5240 phba->brd_no, ext_cnt, ext_size);
5241 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005242 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005243 "N/A\n");
5244
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005245 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005246 "\tHost Allocated RPI extents: ");
5247 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
5248 &ext_cnt, &ext_size);
5249 if (!rc)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005250 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005251 "Port %d Extent %3d, Size %3d\n",
5252 phba->brd_no, ext_cnt, ext_size);
5253 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005254 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005255 "N/A\n");
5256
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005257 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005258 "\tHost Allocated XRI extents: ");
5259 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
5260 &ext_cnt, &ext_size);
5261 if (!rc)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005262 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005263 "Port %d Extent %3d, Size %3d\n",
5264 phba->brd_no, ext_cnt, ext_size);
5265 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005266 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005267 "N/A\n");
5268
5269 return len;
5270}
5271
5272/**
5273 * lpfc_idiag_extacc_drivr_get - get driver extent information
5274 * @phba: pointer to lpfc hba data structure.
5275 * @pbuffer: pointer to internal buffer.
5276 * @len: length into the internal buffer data has been copied.
5277 *
5278 * Description:
5279 * This routine is to get the driver extent information.
5280 *
5281 * Returns:
5282 * overall lenth of the data read into the internal buffer.
5283 **/
5284static int
5285lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
5286{
5287 struct lpfc_rsrc_blks *rsrc_blks;
5288 int index;
5289
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005290 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005291 "\nDriver Extents Information:\n");
5292
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005293 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005294 "\tVPI extents:\n");
5295 index = 0;
5296 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005297 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005298 "\t\tBlock %3d: Start %4d, Count %4d\n",
5299 index, rsrc_blks->rsrc_start,
5300 rsrc_blks->rsrc_size);
5301 index++;
5302 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005303 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005304 "\tVFI extents:\n");
5305 index = 0;
5306 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
5307 list) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005308 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005309 "\t\tBlock %3d: Start %4d, Count %4d\n",
5310 index, rsrc_blks->rsrc_start,
5311 rsrc_blks->rsrc_size);
5312 index++;
5313 }
5314
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005315 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005316 "\tRPI extents:\n");
5317 index = 0;
5318 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
5319 list) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005320 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005321 "\t\tBlock %3d: Start %4d, Count %4d\n",
5322 index, rsrc_blks->rsrc_start,
5323 rsrc_blks->rsrc_size);
5324 index++;
5325 }
5326
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005327 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005328 "\tXRI extents:\n");
5329 index = 0;
5330 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
5331 list) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005332 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005333 "\t\tBlock %3d: Start %4d, Count %4d\n",
5334 index, rsrc_blks->rsrc_start,
5335 rsrc_blks->rsrc_size);
5336 index++;
5337 }
5338
5339 return len;
5340}
5341
5342/**
5343 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
5344 * @file: The file pointer to read from.
5345 * @buf: The buffer to copy the user data from.
5346 * @nbytes: The number of bytes to get.
5347 * @ppos: The position in the file to start reading from.
5348 *
5349 * This routine get the debugfs idiag command struct from user space and then
5350 * perform the syntax check for extent information access commands and sets
5351 * up the necessary states in the idiag command struct accordingly.
5352 *
5353 * It returns the @nbytges passing in from debugfs user space when successful.
5354 * In case of error conditions, it returns proper error code back to the user
5355 * space.
5356 **/
5357static ssize_t
5358lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
5359 size_t nbytes, loff_t *ppos)
5360{
5361 struct lpfc_debug *debug = file->private_data;
5362 uint32_t ext_map;
5363 int rc;
5364
5365 /* This is a user write operation */
5366 debug->op = LPFC_IDIAG_OP_WR;
5367
5368 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
5369 if (rc < 0)
5370 return rc;
5371
5372 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
5373
5374 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
5375 goto error_out;
5376 if (rc != LPFC_EXT_ACC_CMD_ARG)
5377 goto error_out;
5378 if (!(ext_map & LPFC_EXT_ACC_ALL))
5379 goto error_out;
5380
5381 return nbytes;
5382error_out:
5383 /* Clean out command structure on command error out */
5384 memset(&idiag, 0, sizeof(idiag));
5385 return -EINVAL;
5386}
5387
5388/**
5389 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
5390 * @file: The file pointer to read from.
5391 * @buf: The buffer to copy the data to.
5392 * @nbytes: The number of bytes to read.
5393 * @ppos: The position in the file to start reading from.
5394 *
5395 * Description:
5396 * This routine reads data from the proper extent information according to
5397 * the idiag command, and copies to user @buf.
5398 *
5399 * Returns:
5400 * This function returns the amount of data that was read (this could be less
5401 * than @nbytes if the end of the file was reached) or a negative error value.
5402 **/
5403static ssize_t
5404lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
5405 loff_t *ppos)
5406{
5407 struct lpfc_debug *debug = file->private_data;
5408 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5409 char *pbuffer;
5410 uint32_t ext_map;
5411 int len = 0;
5412
5413 /* This is a user read operation */
5414 debug->op = LPFC_IDIAG_OP_RD;
5415
5416 if (!debug->buffer)
5417 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
5418 if (!debug->buffer)
5419 return 0;
5420 pbuffer = debug->buffer;
5421 if (*ppos)
5422 return 0;
5423 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
5424 return 0;
5425
5426 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
5427 if (ext_map & LPFC_EXT_ACC_AVAIL)
5428 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
5429 if (ext_map & LPFC_EXT_ACC_ALLOC)
5430 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
5431 if (ext_map & LPFC_EXT_ACC_DRIVR)
5432 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
5433
5434 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
5435}
5436
James Smart858c9f62007-06-17 19:56:39 -05005437#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005438static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05005439 .owner = THIS_MODULE,
5440 .open = lpfc_debugfs_disc_trc_open,
5441 .llseek = lpfc_debugfs_lseek,
5442 .read = lpfc_debugfs_read,
5443 .release = lpfc_debugfs_release,
5444};
5445
5446#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005447static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05005448 .owner = THIS_MODULE,
5449 .open = lpfc_debugfs_nodelist_open,
5450 .llseek = lpfc_debugfs_lseek,
5451 .read = lpfc_debugfs_read,
5452 .release = lpfc_debugfs_release,
5453};
5454
James Smartc4908502019-01-28 11:14:28 -08005455#undef lpfc_debugfs_op_multixripools
5456static const struct file_operations lpfc_debugfs_op_multixripools = {
5457 .owner = THIS_MODULE,
5458 .open = lpfc_debugfs_multixripools_open,
5459 .llseek = lpfc_debugfs_lseek,
5460 .read = lpfc_debugfs_read,
5461 .write = lpfc_debugfs_multixripools_write,
5462 .release = lpfc_debugfs_release,
5463};
5464
James Smart78b2d852007-08-02 11:10:21 -04005465#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005466static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04005467 .owner = THIS_MODULE,
5468 .open = lpfc_debugfs_hbqinfo_open,
5469 .llseek = lpfc_debugfs_lseek,
5470 .read = lpfc_debugfs_read,
5471 .release = lpfc_debugfs_release,
5472};
5473
James Smart6a828b02019-01-28 11:14:31 -08005474#ifdef LPFC_HDWQ_LOCK_STAT
5475#undef lpfc_debugfs_op_lockstat
5476static const struct file_operations lpfc_debugfs_op_lockstat = {
James Smart5e5b5112019-01-28 11:14:22 -08005477 .owner = THIS_MODULE,
James Smart6a828b02019-01-28 11:14:31 -08005478 .open = lpfc_debugfs_lockstat_open,
James Smart5e5b5112019-01-28 11:14:22 -08005479 .llseek = lpfc_debugfs_lseek,
5480 .read = lpfc_debugfs_read,
James Smart6a828b02019-01-28 11:14:31 -08005481 .write = lpfc_debugfs_lockstat_write,
James Smart5e5b5112019-01-28 11:14:22 -08005482 .release = lpfc_debugfs_release,
5483};
James Smart6a828b02019-01-28 11:14:31 -08005484#endif
James Smart5e5b5112019-01-28 11:14:22 -08005485
James Smart95bfc6d2019-10-18 14:18:27 -07005486#undef lpfc_debugfs_ras_log
5487static const struct file_operations lpfc_debugfs_ras_log = {
5488 .owner = THIS_MODULE,
5489 .open = lpfc_debugfs_ras_log_open,
5490 .llseek = lpfc_debugfs_lseek,
5491 .read = lpfc_debugfs_read,
5492 .release = lpfc_debugfs_ras_log_release,
5493};
James Smart95bfc6d2019-10-18 14:18:27 -07005494
James Smartc95d6c62008-01-11 01:53:23 -05005495#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005496static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04005497 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05005498 .open = lpfc_debugfs_dumpHBASlim_open,
5499 .llseek = lpfc_debugfs_lseek,
5500 .read = lpfc_debugfs_read,
5501 .release = lpfc_debugfs_release,
5502};
5503
5504#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005505static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05005506 .owner = THIS_MODULE,
5507 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04005508 .llseek = lpfc_debugfs_lseek,
5509 .read = lpfc_debugfs_read,
5510 .release = lpfc_debugfs_release,
5511};
5512
James Smartbd2cdd52017-02-12 13:52:33 -08005513#undef lpfc_debugfs_op_nvmestat
5514static const struct file_operations lpfc_debugfs_op_nvmestat = {
5515 .owner = THIS_MODULE,
5516 .open = lpfc_debugfs_nvmestat_open,
5517 .llseek = lpfc_debugfs_lseek,
5518 .read = lpfc_debugfs_read,
James Smart2b65e182017-02-12 13:52:38 -08005519 .write = lpfc_debugfs_nvmestat_write,
James Smartbd2cdd52017-02-12 13:52:33 -08005520 .release = lpfc_debugfs_release,
5521};
5522
James Smart4c47efc2019-01-28 11:14:25 -08005523#undef lpfc_debugfs_op_scsistat
5524static const struct file_operations lpfc_debugfs_op_scsistat = {
5525 .owner = THIS_MODULE,
5526 .open = lpfc_debugfs_scsistat_open,
5527 .llseek = lpfc_debugfs_lseek,
5528 .read = lpfc_debugfs_read,
5529 .write = lpfc_debugfs_scsistat_write,
5530 .release = lpfc_debugfs_release,
5531};
5532
James Smart2fcbc562020-03-22 11:13:02 -07005533#undef lpfc_debugfs_op_ioktime
5534static const struct file_operations lpfc_debugfs_op_ioktime = {
James Smartbd2cdd52017-02-12 13:52:33 -08005535 .owner = THIS_MODULE,
James Smart2fcbc562020-03-22 11:13:02 -07005536 .open = lpfc_debugfs_ioktime_open,
James Smartbd2cdd52017-02-12 13:52:33 -08005537 .llseek = lpfc_debugfs_lseek,
5538 .read = lpfc_debugfs_read,
James Smart2fcbc562020-03-22 11:13:02 -07005539 .write = lpfc_debugfs_ioktime_write,
James Smartbd2cdd52017-02-12 13:52:33 -08005540 .release = lpfc_debugfs_release,
5541};
5542
5543#undef lpfc_debugfs_op_nvmeio_trc
5544static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
5545 .owner = THIS_MODULE,
5546 .open = lpfc_debugfs_nvmeio_trc_open,
5547 .llseek = lpfc_debugfs_lseek,
5548 .read = lpfc_debugfs_read,
5549 .write = lpfc_debugfs_nvmeio_trc_write,
5550 .release = lpfc_debugfs_release,
5551};
5552
James Smart840eda92020-03-22 11:13:00 -07005553#undef lpfc_debugfs_op_hdwqstat
5554static const struct file_operations lpfc_debugfs_op_hdwqstat = {
James Smartbd2cdd52017-02-12 13:52:33 -08005555 .owner = THIS_MODULE,
James Smart840eda92020-03-22 11:13:00 -07005556 .open = lpfc_debugfs_hdwqstat_open,
James Smartbd2cdd52017-02-12 13:52:33 -08005557 .llseek = lpfc_debugfs_lseek,
5558 .read = lpfc_debugfs_read,
James Smart840eda92020-03-22 11:13:00 -07005559 .write = lpfc_debugfs_hdwqstat_write,
James Smartbd2cdd52017-02-12 13:52:33 -08005560 .release = lpfc_debugfs_release,
5561};
5562
James Smartf9bb2da2011-10-10 21:34:11 -04005563#undef lpfc_debugfs_op_dif_err
5564static const struct file_operations lpfc_debugfs_op_dif_err = {
5565 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07005566 .open = simple_open,
James Smartf9bb2da2011-10-10 21:34:11 -04005567 .llseek = lpfc_debugfs_lseek,
5568 .read = lpfc_debugfs_dif_err_read,
5569 .write = lpfc_debugfs_dif_err_write,
5570 .release = lpfc_debugfs_dif_err_release,
5571};
5572
James Smarta58cbd52007-08-02 11:09:43 -04005573#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005574static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04005575 .owner = THIS_MODULE,
5576 .open = lpfc_debugfs_slow_ring_trc_open,
5577 .llseek = lpfc_debugfs_lseek,
5578 .read = lpfc_debugfs_read,
5579 .release = lpfc_debugfs_release,
5580};
5581
James Smart858c9f62007-06-17 19:56:39 -05005582static struct dentry *lpfc_debugfs_root = NULL;
5583static atomic_t lpfc_debugfs_hba_count;
James Smart2a622bf2011-02-16 12:40:06 -05005584
5585/*
5586 * File operations for the iDiag debugfs
5587 */
5588#undef lpfc_idiag_op_pciCfg
5589static const struct file_operations lpfc_idiag_op_pciCfg = {
5590 .owner = THIS_MODULE,
5591 .open = lpfc_idiag_open,
5592 .llseek = lpfc_debugfs_lseek,
5593 .read = lpfc_idiag_pcicfg_read,
5594 .write = lpfc_idiag_pcicfg_write,
5595 .release = lpfc_idiag_cmd_release,
5596};
5597
James Smartb76f2dc2011-07-22 18:37:42 -04005598#undef lpfc_idiag_op_barAcc
5599static const struct file_operations lpfc_idiag_op_barAcc = {
5600 .owner = THIS_MODULE,
5601 .open = lpfc_idiag_open,
5602 .llseek = lpfc_debugfs_lseek,
5603 .read = lpfc_idiag_baracc_read,
5604 .write = lpfc_idiag_baracc_write,
5605 .release = lpfc_idiag_cmd_release,
5606};
5607
James Smart2a622bf2011-02-16 12:40:06 -05005608#undef lpfc_idiag_op_queInfo
5609static const struct file_operations lpfc_idiag_op_queInfo = {
5610 .owner = THIS_MODULE,
5611 .open = lpfc_idiag_open,
5612 .read = lpfc_idiag_queinfo_read,
5613 .release = lpfc_idiag_release,
5614};
5615
James Smartb76f2dc2011-07-22 18:37:42 -04005616#undef lpfc_idiag_op_queAcc
James Smart86a80842011-04-16 11:03:04 -04005617static const struct file_operations lpfc_idiag_op_queAcc = {
5618 .owner = THIS_MODULE,
5619 .open = lpfc_idiag_open,
5620 .llseek = lpfc_debugfs_lseek,
5621 .read = lpfc_idiag_queacc_read,
5622 .write = lpfc_idiag_queacc_write,
5623 .release = lpfc_idiag_cmd_release,
5624};
5625
James Smartb76f2dc2011-07-22 18:37:42 -04005626#undef lpfc_idiag_op_drbAcc
James Smart86a80842011-04-16 11:03:04 -04005627static const struct file_operations lpfc_idiag_op_drbAcc = {
5628 .owner = THIS_MODULE,
5629 .open = lpfc_idiag_open,
5630 .llseek = lpfc_debugfs_lseek,
5631 .read = lpfc_idiag_drbacc_read,
5632 .write = lpfc_idiag_drbacc_write,
5633 .release = lpfc_idiag_cmd_release,
5634};
5635
James Smartb76f2dc2011-07-22 18:37:42 -04005636#undef lpfc_idiag_op_ctlAcc
5637static const struct file_operations lpfc_idiag_op_ctlAcc = {
5638 .owner = THIS_MODULE,
5639 .open = lpfc_idiag_open,
5640 .llseek = lpfc_debugfs_lseek,
5641 .read = lpfc_idiag_ctlacc_read,
5642 .write = lpfc_idiag_ctlacc_write,
5643 .release = lpfc_idiag_cmd_release,
5644};
5645
5646#undef lpfc_idiag_op_mbxAcc
5647static const struct file_operations lpfc_idiag_op_mbxAcc = {
5648 .owner = THIS_MODULE,
5649 .open = lpfc_idiag_open,
5650 .llseek = lpfc_debugfs_lseek,
5651 .read = lpfc_idiag_mbxacc_read,
5652 .write = lpfc_idiag_mbxacc_write,
5653 .release = lpfc_idiag_cmd_release,
5654};
5655
5656#undef lpfc_idiag_op_extAcc
5657static const struct file_operations lpfc_idiag_op_extAcc = {
5658 .owner = THIS_MODULE,
5659 .open = lpfc_idiag_open,
5660 .llseek = lpfc_debugfs_lseek,
5661 .read = lpfc_idiag_extacc_read,
5662 .write = lpfc_idiag_extacc_write,
5663 .release = lpfc_idiag_cmd_release,
5664};
Arnd Bergmann201743b2019-12-16 14:16:49 +01005665#endif
James Smart858c9f62007-06-17 19:56:39 -05005666
James Smartb76f2dc2011-07-22 18:37:42 -04005667/* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
5668 * @phba: Pointer to HBA context object.
5669 * @dmabuf: Pointer to a DMA buffer descriptor.
5670 *
5671 * Description:
5672 * This routine dump a bsg pass-through non-embedded mailbox command with
5673 * external buffer.
5674 **/
5675void
5676lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
5677 enum mbox_type mbox_tp, enum dma_type dma_tp,
5678 enum sta_type sta_tp,
5679 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
5680{
5681#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5682 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
5683 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5684 int len = 0;
5685 uint32_t do_dump = 0;
5686 uint32_t *pword;
5687 uint32_t i;
5688
5689 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
5690 return;
5691
5692 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5693 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5694 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5695 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5696
5697 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
5698 (*mbx_dump_cnt == 0) ||
5699 (*mbx_word_cnt == 0))
5700 return;
5701
5702 if (*mbx_mbox_cmd != 0x9B)
5703 return;
5704
5705 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5706 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5707 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
James Smart2ea259e2017-02-12 13:52:27 -08005708 pr_err("\nRead mbox command (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04005709 "nemb:0x%x, extbuf_cnt:%d:\n",
5710 sta_tp, nemb_tp, ext_buf);
5711 }
5712 }
5713 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5714 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5715 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
James Smart2ea259e2017-02-12 13:52:27 -08005716 pr_err("\nRead mbox buffer (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04005717 "nemb:0x%x, extbuf_seq:%d:\n",
5718 sta_tp, nemb_tp, ext_buf);
5719 }
5720 }
5721 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5722 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5723 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
James Smart2ea259e2017-02-12 13:52:27 -08005724 pr_err("\nWrite mbox command (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04005725 "nemb:0x%x, extbuf_cnt:%d:\n",
5726 sta_tp, nemb_tp, ext_buf);
5727 }
5728 }
5729 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5730 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5731 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
James Smart2ea259e2017-02-12 13:52:27 -08005732 pr_err("\nWrite mbox buffer (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04005733 "nemb:0x%x, extbuf_seq:%d:\n",
5734 sta_tp, nemb_tp, ext_buf);
5735 }
5736 }
5737
5738 /* dump buffer content */
5739 if (do_dump) {
5740 pword = (uint32_t *)dmabuf->virt;
5741 for (i = 0; i < *mbx_word_cnt; i++) {
5742 if (!(i % 8)) {
5743 if (i != 0)
James Smart2ea259e2017-02-12 13:52:27 -08005744 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04005745 len = 0;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005746 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04005747 LPFC_MBX_ACC_LBUF_SZ-len,
5748 "%03d: ", i);
5749 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005750 len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005751 "%08x ", (uint32_t)*pword);
5752 pword++;
5753 }
5754 if ((i - 1) % 8)
James Smart2ea259e2017-02-12 13:52:27 -08005755 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04005756 (*mbx_dump_cnt)--;
5757 }
5758
5759 /* Clean out command structure on reaching dump count */
5760 if (*mbx_dump_cnt == 0)
5761 memset(&idiag, 0, sizeof(idiag));
5762 return;
5763#endif
5764}
5765
5766/* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5767 * @phba: Pointer to HBA context object.
5768 * @dmabuf: Pointer to a DMA buffer descriptor.
5769 *
5770 * Description:
5771 * This routine dump a pass-through non-embedded mailbox command from issue
5772 * mailbox command.
5773 **/
5774void
5775lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5776{
5777#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5778 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5779 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5780 int len = 0;
5781 uint32_t *pword;
5782 uint8_t *pbyte;
5783 uint32_t i, j;
5784
5785 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5786 return;
5787
5788 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5789 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5790 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5791 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5792
5793 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5794 (*mbx_dump_cnt == 0) ||
5795 (*mbx_word_cnt == 0))
5796 return;
5797
5798 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5799 (*mbx_mbox_cmd != pmbox->mbxCommand))
5800 return;
5801
5802 /* dump buffer content */
5803 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
James Smart2ea259e2017-02-12 13:52:27 -08005804 pr_err("Mailbox command:0x%x dump by word:\n",
James Smartb76f2dc2011-07-22 18:37:42 -04005805 pmbox->mbxCommand);
5806 pword = (uint32_t *)pmbox;
5807 for (i = 0; i < *mbx_word_cnt; i++) {
5808 if (!(i % 8)) {
5809 if (i != 0)
James Smart2ea259e2017-02-12 13:52:27 -08005810 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04005811 len = 0;
5812 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005813 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04005814 LPFC_MBX_ACC_LBUF_SZ-len,
5815 "%03d: ", i);
5816 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005817 len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005818 "%08x ",
5819 ((uint32_t)*pword) & 0xffffffff);
5820 pword++;
5821 }
5822 if ((i - 1) % 8)
James Smart2ea259e2017-02-12 13:52:27 -08005823 pr_err("%s\n", line_buf);
5824 pr_err("\n");
James Smartb76f2dc2011-07-22 18:37:42 -04005825 }
5826 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
James Smart2ea259e2017-02-12 13:52:27 -08005827 pr_err("Mailbox command:0x%x dump by byte:\n",
James Smartb76f2dc2011-07-22 18:37:42 -04005828 pmbox->mbxCommand);
5829 pbyte = (uint8_t *)pmbox;
5830 for (i = 0; i < *mbx_word_cnt; i++) {
5831 if (!(i % 8)) {
5832 if (i != 0)
James Smart2ea259e2017-02-12 13:52:27 -08005833 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04005834 len = 0;
5835 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005836 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04005837 LPFC_MBX_ACC_LBUF_SZ-len,
5838 "%03d: ", i);
5839 }
5840 for (j = 0; j < 4; j++) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005841 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04005842 LPFC_MBX_ACC_LBUF_SZ-len,
5843 "%02x",
5844 ((uint8_t)*pbyte) & 0xff);
5845 pbyte++;
5846 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005847 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04005848 LPFC_MBX_ACC_LBUF_SZ-len, " ");
5849 }
5850 if ((i - 1) % 8)
James Smart2ea259e2017-02-12 13:52:27 -08005851 pr_err("%s\n", line_buf);
5852 pr_err("\n");
James Smartb76f2dc2011-07-22 18:37:42 -04005853 }
5854 (*mbx_dump_cnt)--;
5855
5856 /* Clean out command structure on reaching dump count */
5857 if (*mbx_dump_cnt == 0)
5858 memset(&idiag, 0, sizeof(idiag));
5859 return;
5860#endif
5861}
5862
James Smarte59058c2008-08-24 21:49:00 -04005863/**
James Smart3621a712009-04-06 18:47:14 -04005864 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04005865 * @vport: The vport pointer to initialize.
5866 *
5867 * Description:
5868 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
5869 * If not already created, this routine will create the lpfc directory, and
5870 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
5871 * also create each file used to access lpfc specific debugfs information.
5872 **/
James Smart858c9f62007-06-17 19:56:39 -05005873inline void
5874lpfc_debugfs_initialize(struct lpfc_vport *vport)
5875{
James Smart923e4b62008-12-04 22:40:07 -05005876#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05005877 struct lpfc_hba *phba = vport->phba;
5878 char name[64];
5879 uint32_t num, i;
James Smartf6c3bdf2013-12-17 20:29:59 -05005880 bool pport_setup = false;
James Smart858c9f62007-06-17 19:56:39 -05005881
5882 if (!lpfc_debugfs_enable)
5883 return;
5884
James Smarta58cbd52007-08-02 11:09:43 -04005885 /* Setup lpfc root directory */
5886 if (!lpfc_debugfs_root) {
5887 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
5888 atomic_set(&lpfc_debugfs_hba_count, 0);
James Smarta58cbd52007-08-02 11:09:43 -04005889 }
James Smarta58cbd52007-08-02 11:09:43 -04005890 if (!lpfc_debugfs_start_time)
5891 lpfc_debugfs_start_time = jiffies;
5892
James Smart2a622bf2011-02-16 12:40:06 -05005893 /* Setup funcX directory for specific HBA PCI function */
5894 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
James Smarta58cbd52007-08-02 11:09:43 -04005895 if (!phba->hba_debugfs_root) {
James Smartf6c3bdf2013-12-17 20:29:59 -05005896 pport_setup = true;
James Smarta58cbd52007-08-02 11:09:43 -04005897 phba->hba_debugfs_root =
5898 debugfs_create_dir(name, lpfc_debugfs_root);
James Smarta58cbd52007-08-02 11:09:43 -04005899 atomic_inc(&lpfc_debugfs_hba_count);
5900 atomic_set(&phba->debugfs_vport_count, 0);
5901
James Smartc4908502019-01-28 11:14:28 -08005902 /* Multi-XRI pools */
5903 snprintf(name, sizeof(name), "multixripools");
5904 phba->debug_multixri_pools =
5905 debugfs_create_file(name, S_IFREG | 0644,
5906 phba->hba_debugfs_root,
5907 phba,
5908 &lpfc_debugfs_op_multixripools);
5909 if (!phba->debug_multixri_pools) {
5910 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5911 "0527 Cannot create debugfs multixripools\n");
5912 goto debug_failed;
5913 }
5914
James Smart95bfc6d2019-10-18 14:18:27 -07005915 /* RAS log */
5916 snprintf(name, sizeof(name), "ras_log");
5917 phba->debug_ras_log =
5918 debugfs_create_file(name, 0644,
5919 phba->hba_debugfs_root,
5920 phba, &lpfc_debugfs_ras_log);
5921 if (!phba->debug_ras_log) {
5922 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
5923 "6148 Cannot create debugfs"
5924 " ras_log\n");
5925 goto debug_failed;
5926 }
5927
James Smart78b2d852007-08-02 11:10:21 -04005928 /* Setup hbqinfo */
5929 snprintf(name, sizeof(name), "hbqinfo");
5930 phba->debug_hbqinfo =
James Smart63df6d62019-01-28 11:14:24 -08005931 debugfs_create_file(name, S_IFREG | 0644,
5932 phba->hba_debugfs_root,
5933 phba, &lpfc_debugfs_op_hbqinfo);
James Smart78b2d852007-08-02 11:10:21 -04005934
James Smart6a828b02019-01-28 11:14:31 -08005935#ifdef LPFC_HDWQ_LOCK_STAT
5936 /* Setup lockstat */
5937 snprintf(name, sizeof(name), "lockstat");
5938 phba->debug_lockstat =
James Smart5e5b5112019-01-28 11:14:22 -08005939 debugfs_create_file(name, S_IFREG | 0644,
5940 phba->hba_debugfs_root,
James Smart6a828b02019-01-28 11:14:31 -08005941 phba, &lpfc_debugfs_op_lockstat);
5942 if (!phba->debug_lockstat) {
James Smart5e5b5112019-01-28 11:14:22 -08005943 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
Colin Ian Kinga9b83982020-08-10 11:12:38 +01005944 "4610 Can't create debugfs lockstat\n");
James Smart5e5b5112019-01-28 11:14:22 -08005945 goto debug_failed;
5946 }
James Smart6a828b02019-01-28 11:14:31 -08005947#endif
James Smart5e5b5112019-01-28 11:14:22 -08005948
James Smartc95d6c62008-01-11 01:53:23 -05005949 /* Setup dumpHBASlim */
James Smart2a622bf2011-02-16 12:40:06 -05005950 if (phba->sli_rev < LPFC_SLI_REV4) {
5951 snprintf(name, sizeof(name), "dumpHBASlim");
5952 phba->debug_dumpHBASlim =
5953 debugfs_create_file(name,
5954 S_IFREG|S_IRUGO|S_IWUSR,
5955 phba->hba_debugfs_root,
5956 phba, &lpfc_debugfs_op_dumpHBASlim);
James Smart2a622bf2011-02-16 12:40:06 -05005957 } else
5958 phba->debug_dumpHBASlim = NULL;
James Smartc95d6c62008-01-11 01:53:23 -05005959
5960 /* Setup dumpHostSlim */
James Smart2a622bf2011-02-16 12:40:06 -05005961 if (phba->sli_rev < LPFC_SLI_REV4) {
5962 snprintf(name, sizeof(name), "dumpHostSlim");
5963 phba->debug_dumpHostSlim =
5964 debugfs_create_file(name,
5965 S_IFREG|S_IRUGO|S_IWUSR,
5966 phba->hba_debugfs_root,
5967 phba, &lpfc_debugfs_op_dumpHostSlim);
James Smart2a622bf2011-02-16 12:40:06 -05005968 } else
Felipe Penab28d1082013-10-18 20:15:37 -03005969 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04005970
James Smartf9bb2da2011-10-10 21:34:11 -04005971 /* Setup DIF Error Injections */
5972 snprintf(name, sizeof(name), "InjErrLBA");
5973 phba->debug_InjErrLBA =
5974 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5975 phba->hba_debugfs_root,
5976 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04005977 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
5978
James Smart4ac9b222012-03-01 22:38:29 -05005979 snprintf(name, sizeof(name), "InjErrNPortID");
5980 phba->debug_InjErrNPortID =
5981 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5982 phba->hba_debugfs_root,
5983 phba, &lpfc_debugfs_op_dif_err);
James Smart4ac9b222012-03-01 22:38:29 -05005984
5985 snprintf(name, sizeof(name), "InjErrWWPN");
5986 phba->debug_InjErrWWPN =
5987 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5988 phba->hba_debugfs_root,
5989 phba, &lpfc_debugfs_op_dif_err);
James Smart4ac9b222012-03-01 22:38:29 -05005990
James Smartf9bb2da2011-10-10 21:34:11 -04005991 snprintf(name, sizeof(name), "writeGuardInjErr");
5992 phba->debug_writeGuard =
5993 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
5994 phba->hba_debugfs_root,
5995 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04005996
5997 snprintf(name, sizeof(name), "writeAppInjErr");
5998 phba->debug_writeApp =
5999 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6000 phba->hba_debugfs_root,
6001 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006002
6003 snprintf(name, sizeof(name), "writeRefInjErr");
6004 phba->debug_writeRef =
6005 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6006 phba->hba_debugfs_root,
6007 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006008
James Smartacd68592012-01-18 16:25:09 -05006009 snprintf(name, sizeof(name), "readGuardInjErr");
6010 phba->debug_readGuard =
6011 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6012 phba->hba_debugfs_root,
6013 phba, &lpfc_debugfs_op_dif_err);
James Smartacd68592012-01-18 16:25:09 -05006014
James Smartf9bb2da2011-10-10 21:34:11 -04006015 snprintf(name, sizeof(name), "readAppInjErr");
6016 phba->debug_readApp =
6017 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6018 phba->hba_debugfs_root,
6019 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006020
6021 snprintf(name, sizeof(name), "readRefInjErr");
6022 phba->debug_readRef =
6023 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6024 phba->hba_debugfs_root,
6025 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006026
James Smarta58cbd52007-08-02 11:09:43 -04006027 /* Setup slow ring trace */
6028 if (lpfc_debugfs_max_slow_ring_trc) {
6029 num = lpfc_debugfs_max_slow_ring_trc - 1;
6030 if (num & lpfc_debugfs_max_slow_ring_trc) {
6031 /* Change to be a power of 2 */
6032 num = lpfc_debugfs_max_slow_ring_trc;
6033 i = 0;
6034 while (num > 1) {
6035 num = num >> 1;
6036 i++;
6037 }
6038 lpfc_debugfs_max_slow_ring_trc = (1 << i);
James Smart2ea259e2017-02-12 13:52:27 -08006039 pr_err("lpfc_debugfs_max_disc_trc changed to "
James Smarte8b62012007-08-02 11:10:09 -04006040 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04006041 }
6042 }
6043
James Smarta58cbd52007-08-02 11:09:43 -04006044 snprintf(name, sizeof(name), "slow_ring_trace");
6045 phba->debug_slow_ring_trc =
6046 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6047 phba->hba_debugfs_root,
6048 phba, &lpfc_debugfs_op_slow_ring_trc);
James Smarta58cbd52007-08-02 11:09:43 -04006049 if (!phba->slow_ring_trc) {
6050 phba->slow_ring_trc = kmalloc(
6051 (sizeof(struct lpfc_debugfs_trc) *
6052 lpfc_debugfs_max_slow_ring_trc),
6053 GFP_KERNEL);
6054 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04006055 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04006056 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04006057 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04006058 goto debug_failed;
6059 }
6060 atomic_set(&phba->slow_ring_trc_cnt, 0);
6061 memset(phba->slow_ring_trc, 0,
6062 (sizeof(struct lpfc_debugfs_trc) *
6063 lpfc_debugfs_max_slow_ring_trc));
6064 }
James Smart2ea259e2017-02-12 13:52:27 -08006065
James Smartbd2cdd52017-02-12 13:52:33 -08006066 snprintf(name, sizeof(name), "nvmeio_trc");
6067 phba->debug_nvmeio_trc =
6068 debugfs_create_file(name, 0644,
6069 phba->hba_debugfs_root,
6070 phba, &lpfc_debugfs_op_nvmeio_trc);
James Smartbd2cdd52017-02-12 13:52:33 -08006071
6072 atomic_set(&phba->nvmeio_trc_cnt, 0);
6073 if (lpfc_debugfs_max_nvmeio_trc) {
6074 num = lpfc_debugfs_max_nvmeio_trc - 1;
6075 if (num & lpfc_debugfs_max_disc_trc) {
6076 /* Change to be a power of 2 */
6077 num = lpfc_debugfs_max_nvmeio_trc;
6078 i = 0;
6079 while (num > 1) {
6080 num = num >> 1;
6081 i++;
6082 }
6083 lpfc_debugfs_max_nvmeio_trc = (1 << i);
6084 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6085 "0575 lpfc_debugfs_max_nvmeio_trc "
6086 "changed to %d\n",
6087 lpfc_debugfs_max_nvmeio_trc);
6088 }
6089 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
6090
6091 /* Allocate trace buffer and initialize */
Vasyl Gomonovych1c356ec2017-10-11 21:42:41 +02006092 phba->nvmeio_trc = kzalloc(
James Smartbd2cdd52017-02-12 13:52:33 -08006093 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
6094 phba->nvmeio_trc_size), GFP_KERNEL);
6095
6096 if (!phba->nvmeio_trc) {
6097 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6098 "0576 Cannot create debugfs "
6099 "nvmeio_trc buffer\n");
6100 goto nvmeio_off;
6101 }
James Smartbd2cdd52017-02-12 13:52:33 -08006102 phba->nvmeio_trc_on = 1;
6103 phba->nvmeio_trc_output_idx = 0;
6104 phba->nvmeio_trc = NULL;
6105 } else {
6106nvmeio_off:
6107 phba->nvmeio_trc_size = 0;
6108 phba->nvmeio_trc_on = 0;
6109 phba->nvmeio_trc_output_idx = 0;
6110 phba->nvmeio_trc = NULL;
6111 }
James Smarta58cbd52007-08-02 11:09:43 -04006112 }
6113
6114 snprintf(name, sizeof(name), "vport%d", vport->vpi);
6115 if (!vport->vport_debugfs_root) {
6116 vport->vport_debugfs_root =
6117 debugfs_create_dir(name, phba->hba_debugfs_root);
James Smarta58cbd52007-08-02 11:09:43 -04006118 atomic_inc(&phba->debugfs_vport_count);
6119 }
6120
James Smart858c9f62007-06-17 19:56:39 -05006121 if (lpfc_debugfs_max_disc_trc) {
6122 num = lpfc_debugfs_max_disc_trc - 1;
6123 if (num & lpfc_debugfs_max_disc_trc) {
6124 /* Change to be a power of 2 */
6125 num = lpfc_debugfs_max_disc_trc;
6126 i = 0;
6127 while (num > 1) {
6128 num = num >> 1;
6129 i++;
6130 }
6131 lpfc_debugfs_max_disc_trc = (1 << i);
James Smart2ea259e2017-02-12 13:52:27 -08006132 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
James Smarte8b62012007-08-02 11:10:09 -04006133 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05006134 }
6135 }
6136
Adrian Bunkff86ba52007-10-18 12:52:37 +02006137 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04006138 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05006139 GFP_KERNEL);
6140
James Smarta58cbd52007-08-02 11:09:43 -04006141 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04006142 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04006143 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04006144 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05006145 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04006146 }
6147 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05006148
6149 snprintf(name, sizeof(name), "discovery_trace");
6150 vport->debug_disc_trc =
6151 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6152 vport->vport_debugfs_root,
6153 vport, &lpfc_debugfs_op_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05006154 snprintf(name, sizeof(name), "nodelist");
6155 vport->debug_nodelist =
6156 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6157 vport->vport_debugfs_root,
6158 vport, &lpfc_debugfs_op_nodelist);
James Smart2a622bf2011-02-16 12:40:06 -05006159
James Smartbd2cdd52017-02-12 13:52:33 -08006160 snprintf(name, sizeof(name), "nvmestat");
6161 vport->debug_nvmestat =
6162 debugfs_create_file(name, 0644,
6163 vport->vport_debugfs_root,
6164 vport, &lpfc_debugfs_op_nvmestat);
James Smartbd2cdd52017-02-12 13:52:33 -08006165
James Smart4c47efc2019-01-28 11:14:25 -08006166 snprintf(name, sizeof(name), "scsistat");
6167 vport->debug_scsistat =
6168 debugfs_create_file(name, 0644,
6169 vport->vport_debugfs_root,
6170 vport, &lpfc_debugfs_op_scsistat);
6171 if (!vport->debug_scsistat) {
6172 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartc835c082019-03-12 16:30:30 -07006173 "4611 Cannot create debugfs scsistat\n");
James Smart4c47efc2019-01-28 11:14:25 -08006174 goto debug_failed;
6175 }
6176
James Smart2fcbc562020-03-22 11:13:02 -07006177 snprintf(name, sizeof(name), "ioktime");
6178 vport->debug_ioktime =
James Smartbd2cdd52017-02-12 13:52:33 -08006179 debugfs_create_file(name, 0644,
6180 vport->vport_debugfs_root,
James Smart2fcbc562020-03-22 11:13:02 -07006181 vport, &lpfc_debugfs_op_ioktime);
6182 if (!vport->debug_ioktime) {
6183 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6184 "0815 Cannot create debugfs ioktime\n");
6185 goto debug_failed;
6186 }
James Smartbd2cdd52017-02-12 13:52:33 -08006187
James Smart840eda92020-03-22 11:13:00 -07006188 snprintf(name, sizeof(name), "hdwqstat");
6189 vport->debug_hdwqstat =
James Smartbd2cdd52017-02-12 13:52:33 -08006190 debugfs_create_file(name, 0644,
6191 vport->vport_debugfs_root,
James Smart840eda92020-03-22 11:13:00 -07006192 vport, &lpfc_debugfs_op_hdwqstat);
James Smartbd2cdd52017-02-12 13:52:33 -08006193
James Smart2a622bf2011-02-16 12:40:06 -05006194 /*
James Smartf6c3bdf2013-12-17 20:29:59 -05006195 * The following section is for additional directories/files for the
6196 * physical port.
6197 */
6198
6199 if (!pport_setup)
6200 goto debug_failed;
6201
6202 /*
James Smart2a622bf2011-02-16 12:40:06 -05006203 * iDiag debugfs root entry points for SLI4 device only
6204 */
6205 if (phba->sli_rev < LPFC_SLI_REV4)
6206 goto debug_failed;
6207
6208 snprintf(name, sizeof(name), "iDiag");
6209 if (!phba->idiag_root) {
6210 phba->idiag_root =
6211 debugfs_create_dir(name, phba->hba_debugfs_root);
James Smart2a622bf2011-02-16 12:40:06 -05006212 /* Initialize iDiag data structure */
6213 memset(&idiag, 0, sizeof(idiag));
6214 }
6215
6216 /* iDiag read PCI config space */
6217 snprintf(name, sizeof(name), "pciCfg");
6218 if (!phba->idiag_pci_cfg) {
6219 phba->idiag_pci_cfg =
6220 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6221 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
James Smart2a622bf2011-02-16 12:40:06 -05006222 idiag.offset.last_rd = 0;
6223 }
6224
James Smartb76f2dc2011-07-22 18:37:42 -04006225 /* iDiag PCI BAR access */
6226 snprintf(name, sizeof(name), "barAcc");
6227 if (!phba->idiag_bar_acc) {
6228 phba->idiag_bar_acc =
6229 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6230 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
James Smartb76f2dc2011-07-22 18:37:42 -04006231 idiag.offset.last_rd = 0;
6232 }
6233
James Smart2a622bf2011-02-16 12:40:06 -05006234 /* iDiag get PCI function queue information */
6235 snprintf(name, sizeof(name), "queInfo");
6236 if (!phba->idiag_que_info) {
6237 phba->idiag_que_info =
6238 debugfs_create_file(name, S_IFREG|S_IRUGO,
6239 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
James Smart2a622bf2011-02-16 12:40:06 -05006240 }
6241
James Smart86a80842011-04-16 11:03:04 -04006242 /* iDiag access PCI function queue */
6243 snprintf(name, sizeof(name), "queAcc");
6244 if (!phba->idiag_que_acc) {
6245 phba->idiag_que_acc =
6246 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6247 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
James Smart86a80842011-04-16 11:03:04 -04006248 }
6249
6250 /* iDiag access PCI function doorbell registers */
6251 snprintf(name, sizeof(name), "drbAcc");
6252 if (!phba->idiag_drb_acc) {
6253 phba->idiag_drb_acc =
6254 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6255 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
James Smart86a80842011-04-16 11:03:04 -04006256 }
6257
James Smartb76f2dc2011-07-22 18:37:42 -04006258 /* iDiag access PCI function control registers */
6259 snprintf(name, sizeof(name), "ctlAcc");
6260 if (!phba->idiag_ctl_acc) {
6261 phba->idiag_ctl_acc =
6262 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6263 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
James Smartb76f2dc2011-07-22 18:37:42 -04006264 }
6265
6266 /* iDiag access mbox commands */
6267 snprintf(name, sizeof(name), "mbxAcc");
6268 if (!phba->idiag_mbx_acc) {
6269 phba->idiag_mbx_acc =
6270 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6271 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
James Smartb76f2dc2011-07-22 18:37:42 -04006272 }
6273
6274 /* iDiag extents access commands */
6275 if (phba->sli4_hba.extents_in_use) {
6276 snprintf(name, sizeof(name), "extAcc");
6277 if (!phba->idiag_ext_acc) {
6278 phba->idiag_ext_acc =
6279 debugfs_create_file(name,
6280 S_IFREG|S_IRUGO|S_IWUSR,
6281 phba->idiag_root, phba,
6282 &lpfc_idiag_op_extAcc);
James Smartb76f2dc2011-07-22 18:37:42 -04006283 }
6284 }
6285
James Smart858c9f62007-06-17 19:56:39 -05006286debug_failed:
6287 return;
6288#endif
6289}
6290
James Smarte59058c2008-08-24 21:49:00 -04006291/**
James Smart3621a712009-04-06 18:47:14 -04006292 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04006293 * @vport: The vport pointer to remove from debugfs.
6294 *
6295 * Description:
6296 * When Debugfs is configured this routine removes debugfs file system elements
6297 * that are specific to this vport. It also checks to see if there are any
6298 * users left for the debugfs directories associated with the HBA and driver. If
6299 * this is the last user of the HBA directory or driver directory then it will
6300 * remove those from the debugfs infrastructure as well.
6301 **/
James Smart858c9f62007-06-17 19:56:39 -05006302inline void
6303lpfc_debugfs_terminate(struct lpfc_vport *vport)
6304{
James Smart923e4b62008-12-04 22:40:07 -05006305#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05006306 struct lpfc_hba *phba = vport->phba;
6307
James Smarteafe89f2017-04-21 16:04:52 -07006308 kfree(vport->disc_trc);
6309 vport->disc_trc = NULL;
James Smartbd2cdd52017-02-12 13:52:33 -08006310
6311 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
6312 vport->debug_disc_trc = NULL;
6313
6314 debugfs_remove(vport->debug_nodelist); /* nodelist */
6315 vport->debug_nodelist = NULL;
6316
6317 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
6318 vport->debug_nvmestat = NULL;
6319
James Smart4c47efc2019-01-28 11:14:25 -08006320 debugfs_remove(vport->debug_scsistat); /* scsistat */
6321 vport->debug_scsistat = NULL;
6322
James Smart2fcbc562020-03-22 11:13:02 -07006323 debugfs_remove(vport->debug_ioktime); /* ioktime */
6324 vport->debug_ioktime = NULL;
James Smartbd2cdd52017-02-12 13:52:33 -08006325
James Smart840eda92020-03-22 11:13:00 -07006326 debugfs_remove(vport->debug_hdwqstat); /* hdwqstat */
6327 vport->debug_hdwqstat = NULL;
James Smartbd2cdd52017-02-12 13:52:33 -08006328
James Smart858c9f62007-06-17 19:56:39 -05006329 if (vport->vport_debugfs_root) {
6330 debugfs_remove(vport->vport_debugfs_root); /* vportX */
6331 vport->vport_debugfs_root = NULL;
6332 atomic_dec(&phba->debugfs_vport_count);
6333 }
James Smartbd2cdd52017-02-12 13:52:33 -08006334
James Smart858c9f62007-06-17 19:56:39 -05006335 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04006336
James Smartc4908502019-01-28 11:14:28 -08006337 debugfs_remove(phba->debug_multixri_pools); /* multixripools*/
6338 phba->debug_multixri_pools = NULL;
6339
James Smartbd2cdd52017-02-12 13:52:33 -08006340 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
6341 phba->debug_hbqinfo = NULL;
James Smarte2a0a9d2008-12-04 22:40:02 -05006342
James Smart95bfc6d2019-10-18 14:18:27 -07006343 debugfs_remove(phba->debug_ras_log);
6344 phba->debug_ras_log = NULL;
6345
James Smart6a828b02019-01-28 11:14:31 -08006346#ifdef LPFC_HDWQ_LOCK_STAT
6347 debugfs_remove(phba->debug_lockstat); /* lockstat */
6348 phba->debug_lockstat = NULL;
6349#endif
James Smartbd2cdd52017-02-12 13:52:33 -08006350 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
6351 phba->debug_dumpHBASlim = NULL;
6352
6353 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
6354 phba->debug_dumpHostSlim = NULL;
6355
James Smartbd2cdd52017-02-12 13:52:33 -08006356 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
6357 phba->debug_InjErrLBA = NULL;
6358
6359 debugfs_remove(phba->debug_InjErrNPortID);
6360 phba->debug_InjErrNPortID = NULL;
6361
6362 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
6363 phba->debug_InjErrWWPN = NULL;
6364
6365 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
6366 phba->debug_writeGuard = NULL;
6367
6368 debugfs_remove(phba->debug_writeApp); /* writeApp */
6369 phba->debug_writeApp = NULL;
6370
6371 debugfs_remove(phba->debug_writeRef); /* writeRef */
6372 phba->debug_writeRef = NULL;
6373
6374 debugfs_remove(phba->debug_readGuard); /* readGuard */
6375 phba->debug_readGuard = NULL;
6376
6377 debugfs_remove(phba->debug_readApp); /* readApp */
6378 phba->debug_readApp = NULL;
6379
6380 debugfs_remove(phba->debug_readRef); /* readRef */
6381 phba->debug_readRef = NULL;
James Smarte2a0a9d2008-12-04 22:40:02 -05006382
James Smarteafe89f2017-04-21 16:04:52 -07006383 kfree(phba->slow_ring_trc);
6384 phba->slow_ring_trc = NULL;
James Smartbd2cdd52017-02-12 13:52:33 -08006385
6386 /* slow_ring_trace */
6387 debugfs_remove(phba->debug_slow_ring_trc);
6388 phba->debug_slow_ring_trc = NULL;
6389
6390 debugfs_remove(phba->debug_nvmeio_trc);
6391 phba->debug_nvmeio_trc = NULL;
6392
6393 kfree(phba->nvmeio_trc);
6394 phba->nvmeio_trc = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04006395
James Smart2a622bf2011-02-16 12:40:06 -05006396 /*
6397 * iDiag release
6398 */
6399 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartbd2cdd52017-02-12 13:52:33 -08006400 /* iDiag extAcc */
6401 debugfs_remove(phba->idiag_ext_acc);
6402 phba->idiag_ext_acc = NULL;
6403
6404 /* iDiag mbxAcc */
6405 debugfs_remove(phba->idiag_mbx_acc);
6406 phba->idiag_mbx_acc = NULL;
6407
6408 /* iDiag ctlAcc */
6409 debugfs_remove(phba->idiag_ctl_acc);
6410 phba->idiag_ctl_acc = NULL;
6411
6412 /* iDiag drbAcc */
6413 debugfs_remove(phba->idiag_drb_acc);
6414 phba->idiag_drb_acc = NULL;
6415
6416 /* iDiag queAcc */
6417 debugfs_remove(phba->idiag_que_acc);
6418 phba->idiag_que_acc = NULL;
6419
6420 /* iDiag queInfo */
6421 debugfs_remove(phba->idiag_que_info);
6422 phba->idiag_que_info = NULL;
6423
6424 /* iDiag barAcc */
6425 debugfs_remove(phba->idiag_bar_acc);
6426 phba->idiag_bar_acc = NULL;
6427
6428 /* iDiag pciCfg */
6429 debugfs_remove(phba->idiag_pci_cfg);
6430 phba->idiag_pci_cfg = NULL;
James Smart2a622bf2011-02-16 12:40:06 -05006431
6432 /* Finally remove the iDiag debugfs root */
James Smartbd2cdd52017-02-12 13:52:33 -08006433 debugfs_remove(phba->idiag_root);
6434 phba->idiag_root = NULL;
James Smart2a622bf2011-02-16 12:40:06 -05006435 }
6436
James Smarta58cbd52007-08-02 11:09:43 -04006437 if (phba->hba_debugfs_root) {
James Smart2a622bf2011-02-16 12:40:06 -05006438 debugfs_remove(phba->hba_debugfs_root); /* fnX */
James Smarta58cbd52007-08-02 11:09:43 -04006439 phba->hba_debugfs_root = NULL;
6440 atomic_dec(&lpfc_debugfs_hba_count);
6441 }
6442
James Smart667a7662017-05-15 15:20:48 -07006443 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
6444 debugfs_remove(lpfc_debugfs_root); /* lpfc */
6445 lpfc_debugfs_root = NULL;
6446 }
James Smart858c9f62007-06-17 19:56:39 -05006447 }
6448#endif
James Smarta58cbd52007-08-02 11:09:43 -04006449 return;
James Smart858c9f62007-06-17 19:56:39 -05006450}
James Smart809c7532012-05-09 21:19:25 -04006451
6452/*
6453 * Driver debug utility routines outside of debugfs. The debug utility
6454 * routines implemented here is intended to be used in the instrumented
6455 * debug driver for debugging host or port issues.
6456 */
6457
6458/**
6459 * lpfc_debug_dump_all_queues - dump all the queues with a hba
6460 * @phba: Pointer to HBA context object.
6461 *
6462 * This function dumps entries of all the queues asociated with the @phba.
6463 **/
6464void
6465lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
6466{
James Smart1d9d5a92017-02-12 13:52:29 -08006467 int idx;
James Smart809c7532012-05-09 21:19:25 -04006468
6469 /*
6470 * Dump Work Queues (WQs)
6471 */
James Smart1d9d5a92017-02-12 13:52:29 -08006472 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
6473 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
James Smart895427b2017-02-12 13:52:30 -08006474 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
James Smart809c7532012-05-09 21:19:25 -04006475
James Smartcdb42be2019-01-28 11:14:21 -08006476 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
James Smartc00f62e2019-08-14 16:57:11 -07006477 lpfc_debug_dump_wq(phba, DUMP_IO, idx);
James Smart895427b2017-02-12 13:52:30 -08006478
James Smart809c7532012-05-09 21:19:25 -04006479 lpfc_debug_dump_hdr_rq(phba);
6480 lpfc_debug_dump_dat_rq(phba);
6481 /*
6482 * Dump Complete Queues (CQs)
6483 */
James Smart1d9d5a92017-02-12 13:52:29 -08006484 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
6485 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
James Smart895427b2017-02-12 13:52:30 -08006486 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
James Smart809c7532012-05-09 21:19:25 -04006487
James Smartcdb42be2019-01-28 11:14:21 -08006488 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
James Smartc00f62e2019-08-14 16:57:11 -07006489 lpfc_debug_dump_cq(phba, DUMP_IO, idx);
James Smart895427b2017-02-12 13:52:30 -08006490
James Smart809c7532012-05-09 21:19:25 -04006491 /*
6492 * Dump Event Queues (EQs)
6493 */
James Smartcdb42be2019-01-28 11:14:21 -08006494 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
James Smart1d9d5a92017-02-12 13:52:29 -08006495 lpfc_debug_dump_hba_eq(phba, idx);
James Smart809c7532012-05-09 21:19:25 -04006496}