blob: 30fac2f6fb068342781f5c1260fe6bda66288784 [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 Smart67073c62021-03-01 09:18:21 -08004 * Copyright (C) 2017-2021 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/**
Lee Jones2c6400b2021-03-12 09:47:20 +0000384 * lpfc_debugfs_commonxripools_data - Dump Hardware Queue info to a buffer
James Smart6a828b02019-01-28 11:14:31 -0800385 * @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 Smartfe83e3b2021-05-14 12:55:54 -0700866 "WWPN x%016llx ",
James Smart2ea259e2017-02-12 13:52:27 -0800867 wwn_to_u64(ndlp->nlp_portname.u.wwn));
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700868 len += scnprintf(buf+len, size-len,
James Smartfe83e3b2021-05-14 12:55:54 -0700869 "WWNN x%016llx ",
James Smart2ea259e2017-02-12 13:52:27 -0800870 wwn_to_u64(ndlp->nlp_nodename.u.wwn));
James Smart01131e72021-05-14 12:55:49 -0700871 len += scnprintf(buf+len, size-len, "RPI:x%04x ",
872 ndlp->nlp_rpi);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700873 len += scnprintf(buf+len, size-len, "flag:x%08x ",
James Smart086a3452012-08-14 14:25:21 -0400874 ndlp->nlp_flag);
James Smart858c9f62007-06-17 19:56:39 -0500875 if (!ndlp->nlp_type)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700876 len += scnprintf(buf+len, size-len, "UNKNOWN_TYPE ");
James Smart858c9f62007-06-17 19:56:39 -0500877 if (ndlp->nlp_type & NLP_FC_NODE)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700878 len += scnprintf(buf+len, size-len, "FC_NODE ");
James Smartf91bc592018-04-09 14:24:22 -0700879 if (ndlp->nlp_type & NLP_FABRIC) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700880 len += scnprintf(buf+len, size-len, "FABRIC ");
James Smartf91bc592018-04-09 14:24:22 -0700881 iocnt = 0;
882 }
James Smart858c9f62007-06-17 19:56:39 -0500883 if (ndlp->nlp_type & NLP_FCP_TARGET)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700884 len += scnprintf(buf+len, size-len, "FCP_TGT sid:%d ",
James Smart858c9f62007-06-17 19:56:39 -0500885 ndlp->nlp_sid);
886 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700887 len += scnprintf(buf+len, size-len, "FCP_INITIATOR ");
James Smart7d790f02017-06-01 21:06:57 -0700888 if (ndlp->nlp_type & NLP_NVME_TARGET)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700889 len += scnprintf(buf + len,
James Smart7d790f02017-06-01 21:06:57 -0700890 size - len, "NVME_TGT sid:%d ",
891 NLP_NO_SID);
892 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700893 len += scnprintf(buf + len,
James Smart7d790f02017-06-01 21:06:57 -0700894 size - len, "NVME_INITIATOR ");
James Smartbb6fd332021-03-01 09:18:14 -0800895 len += scnprintf(buf+len, size-len, "refcnt:%d",
Peter Zijlstra2c935bc2016-11-14 17:29:48 +0100896 kref_read(&ndlp->kref));
James Smartf91bc592018-04-09 14:24:22 -0700897 if (iocnt) {
898 i = atomic_read(&ndlp->cmd_pending);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700899 len += scnprintf(buf + len, size - len,
James Smartf91bc592018-04-09 14:24:22 -0700900 " OutIO:x%x Qdepth x%x",
901 i, ndlp->cmd_qdepth);
902 outio += i;
903 }
James Smartbb6fd332021-03-01 09:18:14 -0800904 len += scnprintf(buf+len, size-len, " xpt:x%x",
905 ndlp->fc4_xpt_flags);
906 if (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)
907 len += scnprintf(buf+len, size-len, " defer:%x",
908 ndlp->nlp_defer_did);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700909 len += scnprintf(buf+len, size-len, "\n");
James Smart858c9f62007-06-17 19:56:39 -0500910 }
911 spin_unlock_irq(shost->host_lock);
James Smart2ea259e2017-02-12 13:52:27 -0800912
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700913 len += scnprintf(buf + len, size - len,
James Smartf91bc592018-04-09 14:24:22 -0700914 "\nOutstanding IO x%x\n", outio);
915
James Smart2b65e182017-02-12 13:52:38 -0800916 if (phba->nvmet_support && phba->targetport && (vport == phba->pport)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700917 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -0800918 "\nNVME Targetport Entry ...\n");
919
920 /* Port state is only one of two values for now. */
921 if (phba->targetport->port_id)
922 statep = "REGISTERED";
923 else
924 statep = "INIT";
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700925 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -0800926 "TGT WWNN x%llx WWPN x%llx State %s\n",
927 wwn_to_u64(vport->fc_nodename.u.wwn),
928 wwn_to_u64(vport->fc_portname.u.wwn),
929 statep);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700930 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -0800931 " Targetport DID x%06x\n",
932 phba->targetport->port_id);
933 goto out_exit;
934 }
935
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700936 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -0800937 "\nNVME Lport/Rport Entries ...\n");
938
939 localport = vport->localport;
940 if (!localport)
941 goto out_exit;
942
943 spin_lock_irq(shost->host_lock);
James Smartbd2cdd52017-02-12 13:52:33 -0800944
945 /* Port state is only one of two values for now. */
946 if (localport->port_id)
947 statep = "ONLINE";
948 else
949 statep = "UNKNOWN ";
950
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700951 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -0800952 "Lport DID x%06x PortState %s\n",
953 localport->port_id, statep);
954
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700955 len += scnprintf(buf + len, size - len, "\tRport List:\n");
James Smart80cc0042017-06-01 21:06:56 -0700956 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smartbd2cdd52017-02-12 13:52:33 -0800957 /* local short-hand pointer. */
James Smartc6adba12020-11-15 11:26:34 -0800958 spin_lock(&ndlp->lock);
James Smart01466022018-04-09 14:24:27 -0700959 rport = lpfc_ndlp_get_nrport(ndlp);
James Smart9e210172018-09-13 15:41:10 -0700960 if (rport)
961 nrport = rport->remoteport;
Arnd Bergmannf8d29432018-11-02 16:35:48 +0100962 else
963 nrport = NULL;
James Smartc6adba12020-11-15 11:26:34 -0800964 spin_unlock(&ndlp->lock);
James Smart01466022018-04-09 14:24:27 -0700965 if (!nrport)
966 continue;
James Smartbd2cdd52017-02-12 13:52:33 -0800967
968 /* Port state is only one of two values for now. */
969 switch (nrport->port_state) {
970 case FC_OBJSTATE_ONLINE:
971 statep = "ONLINE";
972 break;
973 case FC_OBJSTATE_UNKNOWN:
974 statep = "UNKNOWN ";
975 break;
976 default:
977 statep = "UNSUPPORTED";
978 break;
979 }
980
981 /* Tab in to show lport ownership. */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700982 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -0800983 "\t%s Port ID:x%06x ",
984 statep, nrport->port_id);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700985 len += scnprintf(buf + len, size - len, "WWPN x%llx ",
James Smartbd2cdd52017-02-12 13:52:33 -0800986 nrport->port_name);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700987 len += scnprintf(buf + len, size - len, "WWNN x%llx ",
James Smartbd2cdd52017-02-12 13:52:33 -0800988 nrport->node_name);
James Smart7d790f02017-06-01 21:06:57 -0700989
990 /* An NVME rport can have multiple roles. */
991 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700992 len += scnprintf(buf + len, size - len,
James Smart7d790f02017-06-01 21:06:57 -0700993 "INITIATOR ");
994 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700995 len += scnprintf(buf + len, size - len,
James Smart7d790f02017-06-01 21:06:57 -0700996 "TARGET ");
997 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -0700998 len += scnprintf(buf + len, size - len,
James Smart7d790f02017-06-01 21:06:57 -0700999 "DISCSRVC ");
1000 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
1001 FC_PORT_ROLE_NVME_TARGET |
1002 FC_PORT_ROLE_NVME_DISCOVERY))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001003 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001004 "UNKNOWN ROLE x%x",
1005 nrport->port_role);
James Smartbd2cdd52017-02-12 13:52:33 -08001006 /* Terminate the string. */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001007 len += scnprintf(buf + len, size - len, "\n");
James Smartbd2cdd52017-02-12 13:52:33 -08001008 }
1009
1010 spin_unlock_irq(shost->host_lock);
1011 out_exit:
1012 return len;
1013}
1014
1015/**
1016 * lpfc_debugfs_nvmestat_data - Dump target node list to a buffer
1017 * @vport: The vport to gather target node info from.
1018 * @buf: The buffer to dump log into.
1019 * @size: The maximum amount of data to process.
1020 *
1021 * Description:
1022 * This routine dumps the NVME statistics associated with @vport
1023 *
1024 * Return Value:
1025 * This routine returns the amount of bytes that were dumped into @buf and will
1026 * not exceed @size.
1027 **/
1028static int
1029lpfc_debugfs_nvmestat_data(struct lpfc_vport *vport, char *buf, int size)
1030{
1031 struct lpfc_hba *phba = vport->phba;
James Smart2b65e182017-02-12 13:52:38 -08001032 struct lpfc_nvmet_tgtport *tgtp;
James Smart7cacae22020-03-31 09:50:03 -07001033 struct lpfc_async_xchg_ctx *ctxp, *next_ctxp;
James Smart4b056682017-12-08 17:18:10 -08001034 struct nvme_fc_local_port *localport;
James Smart4c47efc2019-01-28 11:14:25 -08001035 struct lpfc_fc4_ctrl_stat *cstat;
James Smart4b056682017-12-08 17:18:10 -08001036 struct lpfc_nvme_lport *lport;
James Smart66a210f2018-04-09 14:24:23 -07001037 uint64_t data1, data2, data3;
1038 uint64_t tot, totin, totout;
James Smart6a828b02019-01-28 11:14:31 -08001039 int cnt, i;
James Smartbd2cdd52017-02-12 13:52:33 -08001040 int len = 0;
1041
James Smart2b65e182017-02-12 13:52:38 -08001042 if (phba->nvmet_support) {
1043 if (!phba->targetport)
1044 return len;
1045 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001046 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001047 "\nNVME Targetport Statistics\n");
1048
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001049 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001050 "LS: Rcv %08x Drop %08x Abort %08x\n",
1051 atomic_read(&tgtp->rcv_ls_req_in),
1052 atomic_read(&tgtp->rcv_ls_req_drop),
1053 atomic_read(&tgtp->xmt_ls_abort));
1054 if (atomic_read(&tgtp->rcv_ls_req_in) !=
1055 atomic_read(&tgtp->rcv_ls_req_out)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001056 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001057 "Rcv LS: in %08x != out %08x\n",
1058 atomic_read(&tgtp->rcv_ls_req_in),
1059 atomic_read(&tgtp->rcv_ls_req_out));
1060 }
1061
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001062 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001063 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
James Smart2b65e182017-02-12 13:52:38 -08001064 atomic_read(&tgtp->xmt_ls_rsp),
1065 atomic_read(&tgtp->xmt_ls_drop),
James Smart4b056682017-12-08 17:18:10 -08001066 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
1067
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001068 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001069 "LS: RSP Abort %08x xb %08x Err %08x\n",
1070 atomic_read(&tgtp->xmt_ls_rsp_aborted),
1071 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
James Smart2b65e182017-02-12 13:52:38 -08001072 atomic_read(&tgtp->xmt_ls_rsp_error));
1073
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001074 len += scnprintf(buf + len, size - len,
James Smart50738422017-08-01 15:12:40 -07001075 "FCP: Rcv %08x Defer %08x Release %08x "
1076 "Drop %08x\n",
James Smart2b65e182017-02-12 13:52:38 -08001077 atomic_read(&tgtp->rcv_fcp_cmd_in),
James Smart50738422017-08-01 15:12:40 -07001078 atomic_read(&tgtp->rcv_fcp_cmd_defer),
1079 atomic_read(&tgtp->xmt_fcp_release),
James Smart2b65e182017-02-12 13:52:38 -08001080 atomic_read(&tgtp->rcv_fcp_cmd_drop));
1081
1082 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
1083 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001084 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001085 "Rcv FCP: in %08x != out %08x\n",
1086 atomic_read(&tgtp->rcv_fcp_cmd_in),
1087 atomic_read(&tgtp->rcv_fcp_cmd_out));
1088 }
1089
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001090 len += scnprintf(buf + len, size - len,
James Smart86c67372017-04-21 16:05:04 -07001091 "FCP Rsp: read %08x readrsp %08x "
1092 "write %08x rsp %08x\n",
James Smart2b65e182017-02-12 13:52:38 -08001093 atomic_read(&tgtp->xmt_fcp_read),
1094 atomic_read(&tgtp->xmt_fcp_read_rsp),
1095 atomic_read(&tgtp->xmt_fcp_write),
1096 atomic_read(&tgtp->xmt_fcp_rsp));
1097
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001098 len += scnprintf(buf + len, size - len,
James Smart2b65e182017-02-12 13:52:38 -08001099 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
1100 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
1101 atomic_read(&tgtp->xmt_fcp_rsp_error),
1102 atomic_read(&tgtp->xmt_fcp_rsp_drop));
1103
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001104 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001105 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
1106 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
1107 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
1108 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
1109
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001110 len += scnprintf(buf + len, size - len,
James Smart547077a2017-05-15 15:20:40 -07001111 "ABORT: Xmt %08x Cmpl %08x\n",
1112 atomic_read(&tgtp->xmt_fcp_abort),
1113 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
1114
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001115 len += scnprintf(buf + len, size - len,
James Smart547077a2017-05-15 15:20:40 -07001116 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
1117 atomic_read(&tgtp->xmt_abort_sol),
1118 atomic_read(&tgtp->xmt_abort_unsol),
James Smart2b65e182017-02-12 13:52:38 -08001119 atomic_read(&tgtp->xmt_abort_rsp),
James Smart547077a2017-05-15 15:20:40 -07001120 atomic_read(&tgtp->xmt_abort_rsp_error));
James Smart2b65e182017-02-12 13:52:38 -08001121
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001122 len += scnprintf(buf + len, size - len, "\n");
James Smart86c67372017-04-21 16:05:04 -07001123
1124 cnt = 0;
James Smart5e5b5112019-01-28 11:14:22 -08001125 spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001126 list_for_each_entry_safe(ctxp, next_ctxp,
1127 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1128 list) {
1129 cnt++;
1130 }
James Smart5e5b5112019-01-28 11:14:22 -08001131 spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001132 if (cnt) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001133 len += scnprintf(buf + len, size - len,
James Smart86c67372017-04-21 16:05:04 -07001134 "ABORT: %d ctx entries\n", cnt);
James Smart5e5b5112019-01-28 11:14:22 -08001135 spin_lock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001136 list_for_each_entry_safe(ctxp, next_ctxp,
1137 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1138 list) {
1139 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ))
1140 break;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001141 len += scnprintf(buf + len, size - len,
James Smart86c67372017-04-21 16:05:04 -07001142 "Entry: oxid %x state %x "
1143 "flag %x\n",
1144 ctxp->oxid, ctxp->state,
1145 ctxp->flag);
1146 }
James Smart5e5b5112019-01-28 11:14:22 -08001147 spin_unlock(&phba->sli4_hba.abts_nvmet_buf_list_lock);
James Smart86c67372017-04-21 16:05:04 -07001148 }
James Smarta8cf5df2017-05-15 15:20:46 -07001149
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001150 /* Calculate outstanding IOs */
1151 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1152 tot += atomic_read(&tgtp->xmt_fcp_release);
1153 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart2cee7802017-06-01 21:07:02 -07001154
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001155 len += scnprintf(buf + len, size - len,
James Smart2cee7802017-06-01 21:07:02 -07001156 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
1157 "CTX Outstanding %08llx\n",
James Smart966bb5b2017-06-15 22:56:45 -07001158 phba->sli4_hba.nvmet_xri_cnt,
James Smarta8cf5df2017-05-15 15:20:46 -07001159 phba->sli4_hba.nvmet_io_wait_cnt,
James Smart2cee7802017-06-01 21:07:02 -07001160 phba->sli4_hba.nvmet_io_wait_total,
1161 tot);
James Smart2b65e182017-02-12 13:52:38 -08001162 } else {
James Smartf6e84792019-01-28 11:14:38 -08001163 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
James Smartbd2cdd52017-02-12 13:52:33 -08001164 return len;
1165
James Smart4b056682017-12-08 17:18:10 -08001166 localport = vport->localport;
1167 if (!localport)
1168 return len;
1169 lport = (struct lpfc_nvme_lport *)localport->private;
1170 if (!lport)
1171 return len;
1172
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001173 len += scnprintf(buf + len, size - len,
James Smart4c47efc2019-01-28 11:14:25 -08001174 "\nNVME HDWQ Statistics\n");
James Smart66a210f2018-04-09 14:24:23 -07001175
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001176 len += scnprintf(buf + len, size - len,
James Smart66a210f2018-04-09 14:24:23 -07001177 "LS: Xmt %016x Cmpl %016x\n",
1178 atomic_read(&lport->fc4NvmeLsRequests),
1179 atomic_read(&lport->fc4NvmeLsCmpls));
1180
James Smart66a210f2018-04-09 14:24:23 -07001181 totin = 0;
1182 totout = 0;
James Smartcdb42be2019-01-28 11:14:21 -08001183 for (i = 0; i < phba->cfg_hdw_queue; i++) {
James Smart4c47efc2019-01-28 11:14:25 -08001184 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
1185 tot = cstat->io_cmpls;
James Smart66a210f2018-04-09 14:24:23 -07001186 totin += tot;
James Smart4c47efc2019-01-28 11:14:25 -08001187 data1 = cstat->input_requests;
1188 data2 = cstat->output_requests;
1189 data3 = cstat->control_requests;
James Smart66a210f2018-04-09 14:24:23 -07001190 totout += (data1 + data2 + data3);
1191
1192 /* Limit to 32, debugfs display buffer limitation */
1193 if (i >= 32)
1194 continue;
1195
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001196 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart4c47efc2019-01-28 11:14:25 -08001197 "HDWQ (%d): Rd %016llx Wr %016llx "
James Smart66a210f2018-04-09 14:24:23 -07001198 "IO %016llx ",
1199 i, data1, data2, data3);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001200 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart66a210f2018-04-09 14:24:23 -07001201 "Cmpl %016llx OutIO %016llx\n",
1202 tot, ((data1 + data2 + data3) - tot));
1203 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001204 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smart66a210f2018-04-09 14:24:23 -07001205 "Total FCP Cmpl %016llx Issue %016llx "
1206 "OutIO %016llx\n",
1207 totin, totout, totout - totin);
1208
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001209 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001210 "LS Xmt Err: Abrt %08x Err %08x "
1211 "Cmpl Err: xb %08x Err %08x\n",
1212 atomic_read(&lport->xmt_ls_abort),
1213 atomic_read(&lport->xmt_ls_err),
1214 atomic_read(&lport->cmpl_ls_xb),
1215 atomic_read(&lport->cmpl_ls_err));
1216
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001217 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001218 "FCP Xmt Err: noxri %06x nondlp %06x "
James Smart44c27572018-05-04 20:37:56 -07001219 "qdepth %06x wqerr %06x err %06x Abrt %06x\n",
James Smart4b056682017-12-08 17:18:10 -08001220 atomic_read(&lport->xmt_fcp_noxri),
1221 atomic_read(&lport->xmt_fcp_bad_ndlp),
1222 atomic_read(&lport->xmt_fcp_qdepth),
1223 atomic_read(&lport->xmt_fcp_wqerr),
James Smart44c27572018-05-04 20:37:56 -07001224 atomic_read(&lport->xmt_fcp_err),
James Smart4b056682017-12-08 17:18:10 -08001225 atomic_read(&lport->xmt_fcp_abort));
1226
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001227 len += scnprintf(buf + len, size - len,
James Smart4b056682017-12-08 17:18:10 -08001228 "FCP Cmpl Err: xb %08x Err %08x\n",
1229 atomic_read(&lport->cmpl_fcp_xb),
1230 atomic_read(&lport->cmpl_fcp_err));
1231
James Smartbd2cdd52017-02-12 13:52:33 -08001232 }
1233
1234 return len;
1235}
1236
James Smart4c47efc2019-01-28 11:14:25 -08001237/**
1238 * lpfc_debugfs_scsistat_data - Dump target node list to a buffer
1239 * @vport: The vport to gather target node info from.
1240 * @buf: The buffer to dump log into.
1241 * @size: The maximum amount of data to process.
1242 *
1243 * Description:
1244 * This routine dumps the SCSI statistics associated with @vport
1245 *
1246 * Return Value:
1247 * This routine returns the amount of bytes that were dumped into @buf and will
1248 * not exceed @size.
1249 **/
1250static int
1251lpfc_debugfs_scsistat_data(struct lpfc_vport *vport, char *buf, int size)
1252{
1253 int len;
1254 struct lpfc_hba *phba = vport->phba;
1255 struct lpfc_fc4_ctrl_stat *cstat;
1256 u64 data1, data2, data3;
1257 u64 tot, totin, totout;
1258 int i;
1259 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
1260
James Smartf6e84792019-01-28 11:14:38 -08001261 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
James Smart4c47efc2019-01-28 11:14:25 -08001262 (phba->sli_rev != LPFC_SLI_REV4))
1263 return 0;
1264
1265 scnprintf(buf, size, "SCSI HDWQ Statistics\n");
1266
1267 totin = 0;
1268 totout = 0;
1269 for (i = 0; i < phba->cfg_hdw_queue; i++) {
1270 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
1271 tot = cstat->io_cmpls;
1272 totin += tot;
1273 data1 = cstat->input_requests;
1274 data2 = cstat->output_requests;
1275 data3 = cstat->control_requests;
1276 totout += (data1 + data2 + data3);
1277
1278 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
1279 "IO %016llx ", i, data1, data2, data3);
1280 if (strlcat(buf, tmp, size) >= size)
1281 goto buffer_done;
1282
1283 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
1284 tot, ((data1 + data2 + data3) - tot));
1285 if (strlcat(buf, tmp, size) >= size)
1286 goto buffer_done;
1287 }
1288 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
1289 "OutIO %016llx\n", totin, totout, totout - totin);
1290 strlcat(buf, tmp, size);
1291
1292buffer_done:
1293 len = strnlen(buf, size);
1294
1295 return len;
1296}
James Smartbd2cdd52017-02-12 13:52:33 -08001297
James Smart2fcbc562020-03-22 11:13:02 -07001298void
1299lpfc_io_ktime(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
1300{
1301 uint64_t seg1, seg2, seg3, seg4;
1302 uint64_t segsum;
1303
1304 if (!lpfc_cmd->ts_last_cmd ||
1305 !lpfc_cmd->ts_cmd_start ||
1306 !lpfc_cmd->ts_cmd_wqput ||
1307 !lpfc_cmd->ts_isr_cmpl ||
1308 !lpfc_cmd->ts_data_io)
1309 return;
1310
1311 if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_cmd_start)
1312 return;
1313 if (lpfc_cmd->ts_cmd_start < lpfc_cmd->ts_last_cmd)
1314 return;
1315 if (lpfc_cmd->ts_cmd_wqput < lpfc_cmd->ts_cmd_start)
1316 return;
1317 if (lpfc_cmd->ts_isr_cmpl < lpfc_cmd->ts_cmd_wqput)
1318 return;
1319 if (lpfc_cmd->ts_data_io < lpfc_cmd->ts_isr_cmpl)
1320 return;
1321 /*
1322 * Segment 1 - Time from Last FCP command cmpl is handed
1323 * off to NVME Layer to start of next command.
1324 * Segment 2 - Time from Driver receives a IO cmd start
1325 * from NVME Layer to WQ put is done on IO cmd.
1326 * Segment 3 - Time from Driver WQ put is done on IO cmd
1327 * to MSI-X ISR for IO cmpl.
1328 * Segment 4 - Time from MSI-X ISR for IO cmpl to when
1329 * cmpl is handled off to the NVME Layer.
1330 */
1331 seg1 = lpfc_cmd->ts_cmd_start - lpfc_cmd->ts_last_cmd;
1332 if (seg1 > 5000000) /* 5 ms - for sequential IOs only */
1333 seg1 = 0;
1334
1335 /* Calculate times relative to start of IO */
1336 seg2 = (lpfc_cmd->ts_cmd_wqput - lpfc_cmd->ts_cmd_start);
1337 segsum = seg2;
1338 seg3 = lpfc_cmd->ts_isr_cmpl - lpfc_cmd->ts_cmd_start;
1339 if (segsum > seg3)
1340 return;
1341 seg3 -= segsum;
1342 segsum += seg3;
1343
1344 seg4 = lpfc_cmd->ts_data_io - lpfc_cmd->ts_cmd_start;
1345 if (segsum > seg4)
1346 return;
1347 seg4 -= segsum;
1348
1349 phba->ktime_data_samples++;
1350 phba->ktime_seg1_total += seg1;
1351 if (seg1 < phba->ktime_seg1_min)
1352 phba->ktime_seg1_min = seg1;
1353 else if (seg1 > phba->ktime_seg1_max)
1354 phba->ktime_seg1_max = seg1;
1355 phba->ktime_seg2_total += seg2;
1356 if (seg2 < phba->ktime_seg2_min)
1357 phba->ktime_seg2_min = seg2;
1358 else if (seg2 > phba->ktime_seg2_max)
1359 phba->ktime_seg2_max = seg2;
1360 phba->ktime_seg3_total += seg3;
1361 if (seg3 < phba->ktime_seg3_min)
1362 phba->ktime_seg3_min = seg3;
1363 else if (seg3 > phba->ktime_seg3_max)
1364 phba->ktime_seg3_max = seg3;
1365 phba->ktime_seg4_total += seg4;
1366 if (seg4 < phba->ktime_seg4_min)
1367 phba->ktime_seg4_min = seg4;
1368 else if (seg4 > phba->ktime_seg4_max)
1369 phba->ktime_seg4_max = seg4;
1370
1371 lpfc_cmd->ts_last_cmd = 0;
1372 lpfc_cmd->ts_cmd_start = 0;
1373 lpfc_cmd->ts_cmd_wqput = 0;
1374 lpfc_cmd->ts_isr_cmpl = 0;
1375 lpfc_cmd->ts_data_io = 0;
1376}
1377
James Smartbd2cdd52017-02-12 13:52:33 -08001378/**
James Smart2fcbc562020-03-22 11:13:02 -07001379 * lpfc_debugfs_ioktime_data - Dump target node list to a buffer
James Smartbd2cdd52017-02-12 13:52:33 -08001380 * @vport: The vport to gather target node info from.
1381 * @buf: The buffer to dump log into.
1382 * @size: The maximum amount of data to process.
1383 *
1384 * Description:
1385 * This routine dumps the NVME statistics associated with @vport
1386 *
1387 * Return Value:
1388 * This routine returns the amount of bytes that were dumped into @buf and will
1389 * not exceed @size.
1390 **/
1391static int
James Smart2fcbc562020-03-22 11:13:02 -07001392lpfc_debugfs_ioktime_data(struct lpfc_vport *vport, char *buf, int size)
James Smartbd2cdd52017-02-12 13:52:33 -08001393{
1394 struct lpfc_hba *phba = vport->phba;
1395 int len = 0;
1396
1397 if (phba->nvmet_support == 0) {
James Smart2fcbc562020-03-22 11:13:02 -07001398 /* Initiator */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001399 len += scnprintf(buf + len, PAGE_SIZE - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001400 "ktime %s: Total Samples: %lld\n",
1401 (phba->ktime_on ? "Enabled" : "Disabled"),
1402 phba->ktime_data_samples);
1403 if (phba->ktime_data_samples == 0)
1404 return len;
1405
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001406 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001407 buf + len, PAGE_SIZE - len,
James Smart2fcbc562020-03-22 11:13:02 -07001408 "Segment 1: Last Cmd cmpl "
1409 "done -to- Start of next Cmd (in driver)\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001410 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001411 buf + len, PAGE_SIZE - len,
1412 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001413 div_u64(phba->ktime_seg1_total,
1414 phba->ktime_data_samples),
James Smartbd2cdd52017-02-12 13:52:33 -08001415 phba->ktime_seg1_min,
1416 phba->ktime_seg1_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001417 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001418 buf + len, PAGE_SIZE - len,
James Smart2fcbc562020-03-22 11:13:02 -07001419 "Segment 2: Driver start of Cmd "
James Smartbd2cdd52017-02-12 13:52:33 -08001420 "-to- Firmware WQ doorbell\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001421 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001422 buf + len, PAGE_SIZE - len,
1423 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001424 div_u64(phba->ktime_seg2_total,
1425 phba->ktime_data_samples),
James Smartbd2cdd52017-02-12 13:52:33 -08001426 phba->ktime_seg2_min,
1427 phba->ktime_seg2_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001428 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001429 buf + len, PAGE_SIZE - len,
1430 "Segment 3: Firmware WQ doorbell -to- "
1431 "MSI-X ISR cmpl\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001432 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001433 buf + len, PAGE_SIZE - len,
1434 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001435 div_u64(phba->ktime_seg3_total,
1436 phba->ktime_data_samples),
James Smartbd2cdd52017-02-12 13:52:33 -08001437 phba->ktime_seg3_min,
1438 phba->ktime_seg3_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001439 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001440 buf + len, PAGE_SIZE - len,
1441 "Segment 4: MSI-X ISR cmpl -to- "
James Smart2fcbc562020-03-22 11:13:02 -07001442 "Cmd cmpl done\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001443 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001444 buf + len, PAGE_SIZE - len,
1445 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001446 div_u64(phba->ktime_seg4_total,
1447 phba->ktime_data_samples),
James Smartbd2cdd52017-02-12 13:52:33 -08001448 phba->ktime_seg4_min,
1449 phba->ktime_seg4_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001450 len += scnprintf(
James Smartbd2cdd52017-02-12 13:52:33 -08001451 buf + len, PAGE_SIZE - len,
1452 "Total IO avg time: %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001453 div_u64(phba->ktime_seg1_total +
James Smartbd2cdd52017-02-12 13:52:33 -08001454 phba->ktime_seg2_total +
1455 phba->ktime_seg3_total +
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001456 phba->ktime_seg4_total,
James Smartbd2cdd52017-02-12 13:52:33 -08001457 phba->ktime_data_samples));
1458 return len;
1459 }
James Smart2b65e182017-02-12 13:52:38 -08001460
1461 /* NVME Target */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001462 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001463 "ktime %s: Total Samples: %lld %lld\n",
1464 (phba->ktime_on ? "Enabled" : "Disabled"),
1465 phba->ktime_data_samples,
1466 phba->ktime_status_samples);
1467 if (phba->ktime_data_samples == 0)
1468 return len;
1469
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001470 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001471 "Segment 1: MSI-X ISR Rcv cmd -to- "
1472 "cmd pass to NVME Layer\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001473 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001474 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001475 div_u64(phba->ktime_seg1_total,
1476 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001477 phba->ktime_seg1_min,
1478 phba->ktime_seg1_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001479 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001480 "Segment 2: cmd pass to NVME Layer- "
1481 "-to- Driver rcv cmd OP (action)\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001482 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001483 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001484 div_u64(phba->ktime_seg2_total,
1485 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001486 phba->ktime_seg2_min,
1487 phba->ktime_seg2_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001488 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001489 "Segment 3: Driver rcv cmd OP -to- "
1490 "Firmware WQ doorbell: cmd\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001491 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001492 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001493 div_u64(phba->ktime_seg3_total,
1494 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001495 phba->ktime_seg3_min,
1496 phba->ktime_seg3_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001497 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001498 "Segment 4: Firmware WQ doorbell: cmd "
1499 "-to- MSI-X ISR for cmd cmpl\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001500 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001501 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001502 div_u64(phba->ktime_seg4_total,
1503 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001504 phba->ktime_seg4_min,
1505 phba->ktime_seg4_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001506 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001507 "Segment 5: MSI-X ISR for cmd cmpl "
1508 "-to- NVME layer passed cmd done\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001509 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001510 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001511 div_u64(phba->ktime_seg5_total,
1512 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001513 phba->ktime_seg5_min,
1514 phba->ktime_seg5_max);
1515
1516 if (phba->ktime_status_samples == 0) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001517 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001518 "Total: cmd received by MSI-X ISR "
1519 "-to- cmd completed on wire\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001520 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001521 "avg:%08lld min:%08lld "
1522 "max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001523 div_u64(phba->ktime_seg10_total,
1524 phba->ktime_data_samples),
James Smart2b65e182017-02-12 13:52:38 -08001525 phba->ktime_seg10_min,
1526 phba->ktime_seg10_max);
1527 return len;
1528 }
1529
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001530 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001531 "Segment 6: NVME layer passed cmd done "
1532 "-to- Driver rcv rsp status OP\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001533 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001534 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001535 div_u64(phba->ktime_seg6_total,
1536 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001537 phba->ktime_seg6_min,
1538 phba->ktime_seg6_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001539 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001540 "Segment 7: Driver rcv rsp status OP "
1541 "-to- Firmware WQ doorbell: status\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001542 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001543 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001544 div_u64(phba->ktime_seg7_total,
1545 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001546 phba->ktime_seg7_min,
1547 phba->ktime_seg7_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001548 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001549 "Segment 8: Firmware WQ doorbell: status"
1550 " -to- MSI-X ISR for status cmpl\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001551 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001552 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001553 div_u64(phba->ktime_seg8_total,
1554 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001555 phba->ktime_seg8_min,
1556 phba->ktime_seg8_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001557 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001558 "Segment 9: MSI-X ISR for status cmpl "
1559 "-to- NVME layer passed status done\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001560 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001561 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001562 div_u64(phba->ktime_seg9_total,
1563 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001564 phba->ktime_seg9_min,
1565 phba->ktime_seg9_max);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001566 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001567 "Total: cmd received by MSI-X ISR -to- "
1568 "cmd completed on wire\n");
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001569 len += scnprintf(buf + len, PAGE_SIZE-len,
James Smart2b65e182017-02-12 13:52:38 -08001570 "avg:%08lld min:%08lld max %08lld\n",
Arnd Bergmann90ec7c92017-02-27 21:31:43 +01001571 div_u64(phba->ktime_seg10_total,
1572 phba->ktime_status_samples),
James Smart2b65e182017-02-12 13:52:38 -08001573 phba->ktime_seg10_min,
1574 phba->ktime_seg10_max);
James Smartbd2cdd52017-02-12 13:52:33 -08001575 return len;
1576}
1577
1578/**
1579 * lpfc_debugfs_nvmeio_trc_data - Dump NVME IO trace list to a buffer
1580 * @phba: The phba to gather target node info from.
1581 * @buf: The buffer to dump log into.
1582 * @size: The maximum amount of data to process.
1583 *
1584 * Description:
1585 * This routine dumps the NVME IO trace associated with @phba
1586 *
1587 * Return Value:
1588 * This routine returns the amount of bytes that were dumped into @buf and will
1589 * not exceed @size.
1590 **/
1591static int
1592lpfc_debugfs_nvmeio_trc_data(struct lpfc_hba *phba, char *buf, int size)
1593{
1594 struct lpfc_debugfs_nvmeio_trc *dtp;
1595 int i, state, index, skip;
1596 int len = 0;
1597
1598 state = phba->nvmeio_trc_on;
1599
1600 index = (atomic_read(&phba->nvmeio_trc_cnt) + 1) &
1601 (phba->nvmeio_trc_size - 1);
1602 skip = phba->nvmeio_trc_output_idx;
1603
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001604 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001605 "%s IO Trace %s: next_idx %d skip %d size %d\n",
1606 (phba->nvmet_support ? "NVME" : "NVMET"),
1607 (state ? "Enabled" : "Disabled"),
1608 index, skip, phba->nvmeio_trc_size);
1609
1610 if (!phba->nvmeio_trc || state)
1611 return len;
1612
1613 /* trace MUST bhe off to continue */
1614
1615 for (i = index; i < phba->nvmeio_trc_size; i++) {
1616 if (skip) {
1617 skip--;
1618 continue;
1619 }
1620 dtp = phba->nvmeio_trc + i;
1621 phba->nvmeio_trc_output_idx++;
1622
1623 if (!dtp->fmt)
1624 continue;
1625
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001626 len += scnprintf(buf + len, size - len, dtp->fmt,
James Smartbd2cdd52017-02-12 13:52:33 -08001627 dtp->data1, dtp->data2, dtp->data3);
1628
1629 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1630 phba->nvmeio_trc_output_idx = 0;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001631 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001632 "Trace Complete\n");
1633 goto out;
1634 }
1635
1636 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001637 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001638 "Trace Continue (%d of %d)\n",
1639 phba->nvmeio_trc_output_idx,
1640 phba->nvmeio_trc_size);
1641 goto out;
1642 }
1643 }
1644 for (i = 0; i < index; i++) {
1645 if (skip) {
1646 skip--;
1647 continue;
1648 }
1649 dtp = phba->nvmeio_trc + i;
1650 phba->nvmeio_trc_output_idx++;
1651
1652 if (!dtp->fmt)
1653 continue;
1654
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001655 len += scnprintf(buf + len, size - len, dtp->fmt,
James Smartbd2cdd52017-02-12 13:52:33 -08001656 dtp->data1, dtp->data2, dtp->data3);
1657
1658 if (phba->nvmeio_trc_output_idx >= phba->nvmeio_trc_size) {
1659 phba->nvmeio_trc_output_idx = 0;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001660 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001661 "Trace Complete\n");
1662 goto out;
1663 }
1664
1665 if (len >= (size - LPFC_DEBUG_OUT_LINE_SZ)) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001666 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001667 "Trace Continue (%d of %d)\n",
1668 phba->nvmeio_trc_output_idx,
1669 phba->nvmeio_trc_size);
1670 goto out;
1671 }
1672 }
1673
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07001674 len += scnprintf(buf + len, size - len,
James Smartbd2cdd52017-02-12 13:52:33 -08001675 "Trace Done\n");
1676out:
1677 return len;
1678}
1679
1680/**
James Smart840eda92020-03-22 11:13:00 -07001681 * lpfc_debugfs_hdwqstat_data - Dump I/O stats to a buffer
James Smartbd2cdd52017-02-12 13:52:33 -08001682 * @vport: The vport to gather target node info from.
1683 * @buf: The buffer to dump log into.
1684 * @size: The maximum amount of data to process.
1685 *
1686 * Description:
James Smart840eda92020-03-22 11:13:00 -07001687 * This routine dumps the NVME + SCSI statistics associated with @vport
James Smartbd2cdd52017-02-12 13:52:33 -08001688 *
1689 * Return Value:
1690 * This routine returns the amount of bytes that were dumped into @buf and will
1691 * not exceed @size.
1692 **/
1693static int
James Smart840eda92020-03-22 11:13:00 -07001694lpfc_debugfs_hdwqstat_data(struct lpfc_vport *vport, char *buf, int size)
James Smartbd2cdd52017-02-12 13:52:33 -08001695{
1696 struct lpfc_hba *phba = vport->phba;
James Smart840eda92020-03-22 11:13:00 -07001697 struct lpfc_hdwq_stat *c_stat;
1698 int i, j, len;
James Smart63df6d62019-01-28 11:14:24 -08001699 uint32_t tot_xmt;
1700 uint32_t tot_rcv;
1701 uint32_t tot_cmpl;
James Smart840eda92020-03-22 11:13:00 -07001702 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
James Smartbd2cdd52017-02-12 13:52:33 -08001703
James Smart840eda92020-03-22 11:13:00 -07001704 scnprintf(tmp, sizeof(tmp), "HDWQ Stats:\n\n");
1705 if (strlcat(buf, tmp, size) >= size)
1706 goto buffer_done;
1707
1708 scnprintf(tmp, sizeof(tmp), "(NVME Accounting: %s) ",
1709 (phba->hdwqstat_on &
1710 (LPFC_CHECK_NVME_IO | LPFC_CHECK_NVMET_IO) ?
1711 "Enabled" : "Disabled"));
1712 if (strlcat(buf, tmp, size) >= size)
1713 goto buffer_done;
1714
1715 scnprintf(tmp, sizeof(tmp), "(SCSI Accounting: %s) ",
1716 (phba->hdwqstat_on & LPFC_CHECK_SCSI_IO ?
1717 "Enabled" : "Disabled"));
1718 if (strlcat(buf, tmp, size) >= size)
1719 goto buffer_done;
1720
1721 scnprintf(tmp, sizeof(tmp), "\n\n");
1722 if (strlcat(buf, tmp, size) >= size)
1723 goto buffer_done;
James Smart63df6d62019-01-28 11:14:24 -08001724
1725 for (i = 0; i < phba->cfg_hdw_queue; i++) {
James Smart63df6d62019-01-28 11:14:24 -08001726 tot_rcv = 0;
1727 tot_xmt = 0;
1728 tot_cmpl = 0;
James Smart840eda92020-03-22 11:13:00 -07001729
1730 for_each_present_cpu(j) {
1731 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, j);
1732
1733 /* Only display for this HDWQ */
1734 if (i != c_stat->hdwq_no)
1735 continue;
1736
1737 /* Only display non-zero counters */
1738 if (!c_stat->xmt_io && !c_stat->cmpl_io &&
1739 !c_stat->rcv_io)
1740 continue;
1741
1742 if (!tot_xmt && !tot_cmpl && !tot_rcv) {
1743 /* Print HDWQ string only the first time */
1744 scnprintf(tmp, sizeof(tmp), "[HDWQ %d]:\t", i);
1745 if (strlcat(buf, tmp, size) >= size)
1746 goto buffer_done;
1747 }
1748
1749 tot_xmt += c_stat->xmt_io;
1750 tot_cmpl += c_stat->cmpl_io;
James Smart63df6d62019-01-28 11:14:24 -08001751 if (phba->nvmet_support)
James Smart840eda92020-03-22 11:13:00 -07001752 tot_rcv += c_stat->rcv_io;
1753
1754 scnprintf(tmp, sizeof(tmp), "| [CPU %d]: ", j);
1755 if (strlcat(buf, tmp, size) >= size)
1756 goto buffer_done;
1757
1758 if (phba->nvmet_support) {
1759 scnprintf(tmp, sizeof(tmp),
1760 "XMT 0x%x CMPL 0x%x RCV 0x%x |",
1761 c_stat->xmt_io, c_stat->cmpl_io,
1762 c_stat->rcv_io);
1763 if (strlcat(buf, tmp, size) >= size)
1764 goto buffer_done;
1765 } else {
1766 scnprintf(tmp, sizeof(tmp),
1767 "XMT 0x%x CMPL 0x%x |",
1768 c_stat->xmt_io, c_stat->cmpl_io);
1769 if (strlcat(buf, tmp, size) >= size)
1770 goto buffer_done;
1771 }
James Smart63df6d62019-01-28 11:14:24 -08001772 }
1773
James Smart840eda92020-03-22 11:13:00 -07001774 /* Check if nothing to display */
James Smart63df6d62019-01-28 11:14:24 -08001775 if (!tot_xmt && !tot_cmpl && !tot_rcv)
1776 continue;
1777
James Smart840eda92020-03-22 11:13:00 -07001778 scnprintf(tmp, sizeof(tmp), "\t->\t[HDWQ Total: ");
1779 if (strlcat(buf, tmp, size) >= size)
1780 goto buffer_done;
1781
1782 if (phba->nvmet_support) {
1783 scnprintf(tmp, sizeof(tmp),
1784 "XMT 0x%x CMPL 0x%x RCV 0x%x]\n\n",
1785 tot_xmt, tot_cmpl, tot_rcv);
1786 if (strlcat(buf, tmp, size) >= size)
1787 goto buffer_done;
1788 } else {
1789 scnprintf(tmp, sizeof(tmp),
1790 "XMT 0x%x CMPL 0x%x]\n\n",
1791 tot_xmt, tot_cmpl);
1792 if (strlcat(buf, tmp, size) >= size)
1793 goto buffer_done;
James Smart6a828b02019-01-28 11:14:31 -08001794 }
James Smart63df6d62019-01-28 11:14:24 -08001795 }
James Smart840eda92020-03-22 11:13:00 -07001796
1797buffer_done:
1798 len = strnlen(buf, size);
James Smart858c9f62007-06-17 19:56:39 -05001799 return len;
1800}
James Smart2ea259e2017-02-12 13:52:27 -08001801
James Smart858c9f62007-06-17 19:56:39 -05001802#endif
1803
James Smarte59058c2008-08-24 21:49:00 -04001804/**
James Smart3621a712009-04-06 18:47:14 -04001805 * lpfc_debugfs_disc_trc - Store discovery trace log
James Smarte59058c2008-08-24 21:49:00 -04001806 * @vport: The vport to associate this trace string with for retrieval.
1807 * @mask: Log entry classification.
1808 * @fmt: Format string to be displayed when dumping the log.
1809 * @data1: 1st data parameter to be applied to @fmt.
1810 * @data2: 2nd data parameter to be applied to @fmt.
1811 * @data3: 3rd data parameter to be applied to @fmt.
1812 *
1813 * Description:
1814 * This routine is used by the driver code to add a debugfs log entry to the
1815 * discovery trace buffer associated with @vport. Only entries with a @mask that
1816 * match the current debugfs discovery mask will be saved. Entries that do not
1817 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
1818 * printf when displaying the log.
1819 **/
James Smart858c9f62007-06-17 19:56:39 -05001820inline void
1821lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
1822 uint32_t data1, uint32_t data2, uint32_t data3)
1823{
James Smart923e4b62008-12-04 22:40:07 -05001824#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -04001825 struct lpfc_debugfs_trc *dtp;
James Smart858c9f62007-06-17 19:56:39 -05001826 int index;
1827
1828 if (!(lpfc_debugfs_mask_disc_trc & mask))
1829 return;
1830
1831 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
1832 !vport || !vport->disc_trc)
1833 return;
1834
1835 index = atomic_inc_return(&vport->disc_trc_cnt) &
1836 (lpfc_debugfs_max_disc_trc - 1);
1837 dtp = vport->disc_trc + index;
1838 dtp->fmt = fmt;
1839 dtp->data1 = data1;
1840 dtp->data2 = data2;
1841 dtp->data3 = data3;
James Smarta58cbd52007-08-02 11:09:43 -04001842 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
1843 dtp->jif = jiffies;
1844#endif
1845 return;
1846}
1847
James Smarte59058c2008-08-24 21:49:00 -04001848/**
James Smart3621a712009-04-06 18:47:14 -04001849 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
James Smarte59058c2008-08-24 21:49:00 -04001850 * @phba: The phba to associate this trace string with for retrieval.
1851 * @fmt: Format string to be displayed when dumping the log.
1852 * @data1: 1st data parameter to be applied to @fmt.
1853 * @data2: 2nd data parameter to be applied to @fmt.
1854 * @data3: 3rd data parameter to be applied to @fmt.
1855 *
1856 * Description:
1857 * This routine is used by the driver code to add a debugfs log entry to the
1858 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
1859 * @data3 are used like printf when displaying the log.
1860 **/
James Smarta58cbd52007-08-02 11:09:43 -04001861inline void
1862lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
1863 uint32_t data1, uint32_t data2, uint32_t data3)
1864{
James Smart923e4b62008-12-04 22:40:07 -05001865#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarta58cbd52007-08-02 11:09:43 -04001866 struct lpfc_debugfs_trc *dtp;
1867 int index;
1868
1869 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
1870 !phba || !phba->slow_ring_trc)
1871 return;
1872
1873 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
1874 (lpfc_debugfs_max_slow_ring_trc - 1);
1875 dtp = phba->slow_ring_trc + index;
1876 dtp->fmt = fmt;
1877 dtp->data1 = data1;
1878 dtp->data2 = data2;
1879 dtp->data3 = data3;
1880 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
James Smart858c9f62007-06-17 19:56:39 -05001881 dtp->jif = jiffies;
1882#endif
1883 return;
1884}
1885
James Smartbd2cdd52017-02-12 13:52:33 -08001886/**
1887 * lpfc_debugfs_nvme_trc - Store NVME/NVMET trace log
1888 * @phba: The phba to associate this trace string with for retrieval.
1889 * @fmt: Format string to be displayed when dumping the log.
1890 * @data1: 1st data parameter to be applied to @fmt.
1891 * @data2: 2nd data parameter to be applied to @fmt.
1892 * @data3: 3rd data parameter to be applied to @fmt.
1893 *
1894 * Description:
1895 * This routine is used by the driver code to add a debugfs log entry to the
1896 * nvme trace buffer associated with @phba. @fmt, @data1, @data2, and
1897 * @data3 are used like printf when displaying the log.
1898 **/
1899inline void
1900lpfc_debugfs_nvme_trc(struct lpfc_hba *phba, char *fmt,
1901 uint16_t data1, uint16_t data2, uint32_t data3)
1902{
1903#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
1904 struct lpfc_debugfs_nvmeio_trc *dtp;
1905 int index;
1906
1907 if (!phba->nvmeio_trc_on || !phba->nvmeio_trc)
1908 return;
1909
1910 index = atomic_inc_return(&phba->nvmeio_trc_cnt) &
1911 (phba->nvmeio_trc_size - 1);
1912 dtp = phba->nvmeio_trc + index;
1913 dtp->fmt = fmt;
1914 dtp->data1 = data1;
1915 dtp->data2 = data2;
1916 dtp->data3 = data3;
1917#endif
1918}
1919
James Smart923e4b62008-12-04 22:40:07 -05001920#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smarte59058c2008-08-24 21:49:00 -04001921/**
James Smart3621a712009-04-06 18:47:14 -04001922 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
James Smarte59058c2008-08-24 21:49:00 -04001923 * @inode: The inode pointer that contains a vport pointer.
1924 * @file: The file pointer to attach the log output.
1925 *
1926 * Description:
1927 * This routine is the entry point for the debugfs open file operation. It gets
1928 * the vport from the i_private field in @inode, allocates the necessary buffer
1929 * for the log, fills the buffer from the in-memory log for this vport, and then
1930 * returns a pointer to that log in the private_data field in @file.
1931 *
1932 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02001933 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04001934 * error value.
1935 **/
James Smart858c9f62007-06-17 19:56:39 -05001936static int
1937lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
1938{
1939 struct lpfc_vport *vport = inode->i_private;
1940 struct lpfc_debug *debug;
1941 int size;
1942 int rc = -ENOMEM;
1943
1944 if (!lpfc_debugfs_max_disc_trc) {
Colin Ian King258f84f2019-02-12 15:29:45 +00001945 rc = -ENOSPC;
James Smart858c9f62007-06-17 19:56:39 -05001946 goto out;
1947 }
1948
1949 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1950 if (!debug)
1951 goto out;
1952
James Smarte59058c2008-08-24 21:49:00 -04001953 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -04001954 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
James Smart858c9f62007-06-17 19:56:39 -05001955 size = PAGE_ALIGN(size);
1956
1957 debug->buffer = kmalloc(size, GFP_KERNEL);
1958 if (!debug->buffer) {
1959 kfree(debug);
1960 goto out;
1961 }
1962
1963 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
1964 file->private_data = debug;
1965
1966 rc = 0;
1967out:
1968 return rc;
1969}
1970
James Smarte59058c2008-08-24 21:49:00 -04001971/**
James Smart3621a712009-04-06 18:47:14 -04001972 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
James Smarte59058c2008-08-24 21:49:00 -04001973 * @inode: The inode pointer that contains a vport pointer.
1974 * @file: The file pointer to attach the log output.
1975 *
1976 * Description:
1977 * This routine is the entry point for the debugfs open file operation. It gets
1978 * the vport from the i_private field in @inode, allocates the necessary buffer
1979 * for the log, fills the buffer from the in-memory log for this vport, and then
1980 * returns a pointer to that log in the private_data field in @file.
1981 *
1982 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02001983 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04001984 * error value.
1985 **/
James Smart858c9f62007-06-17 19:56:39 -05001986static int
James Smarta58cbd52007-08-02 11:09:43 -04001987lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
1988{
1989 struct lpfc_hba *phba = inode->i_private;
1990 struct lpfc_debug *debug;
1991 int size;
1992 int rc = -ENOMEM;
1993
1994 if (!lpfc_debugfs_max_slow_ring_trc) {
Colin Ian King258f84f2019-02-12 15:29:45 +00001995 rc = -ENOSPC;
James Smarta58cbd52007-08-02 11:09:43 -04001996 goto out;
1997 }
1998
1999 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2000 if (!debug)
2001 goto out;
2002
James Smarte59058c2008-08-24 21:49:00 -04002003 /* Round to page boundary */
James Smarta58cbd52007-08-02 11:09:43 -04002004 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
2005 size = PAGE_ALIGN(size);
2006
2007 debug->buffer = kmalloc(size, GFP_KERNEL);
2008 if (!debug->buffer) {
2009 kfree(debug);
2010 goto out;
2011 }
2012
2013 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
2014 file->private_data = debug;
2015
2016 rc = 0;
2017out:
2018 return rc;
2019}
2020
James Smarte59058c2008-08-24 21:49:00 -04002021/**
James Smart3621a712009-04-06 18:47:14 -04002022 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -04002023 * @inode: The inode pointer that contains a vport pointer.
2024 * @file: The file pointer to attach the log output.
2025 *
2026 * Description:
2027 * This routine is the entry point for the debugfs open file operation. It gets
2028 * the vport from the i_private field in @inode, allocates the necessary buffer
2029 * for the log, fills the buffer from the in-memory log for this vport, and then
2030 * returns a pointer to that log in the private_data field in @file.
2031 *
2032 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02002033 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04002034 * error value.
2035 **/
James Smarta58cbd52007-08-02 11:09:43 -04002036static int
James Smart78b2d852007-08-02 11:10:21 -04002037lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
2038{
2039 struct lpfc_hba *phba = inode->i_private;
2040 struct lpfc_debug *debug;
2041 int rc = -ENOMEM;
2042
2043 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2044 if (!debug)
2045 goto out;
2046
James Smarte59058c2008-08-24 21:49:00 -04002047 /* Round to page boundary */
James Smart78b2d852007-08-02 11:10:21 -04002048 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
2049 if (!debug->buffer) {
2050 kfree(debug);
2051 goto out;
2052 }
2053
2054 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
2055 LPFC_HBQINFO_SIZE);
2056 file->private_data = debug;
2057
2058 rc = 0;
2059out:
2060 return rc;
2061}
2062
James Smarte59058c2008-08-24 21:49:00 -04002063/**
James Smartc4908502019-01-28 11:14:28 -08002064 * lpfc_debugfs_multixripools_open - Open the multixripool debugfs buffer
2065 * @inode: The inode pointer that contains a hba pointer.
2066 * @file: The file pointer to attach the log output.
2067 *
2068 * Description:
2069 * This routine is the entry point for the debugfs open file operation. It gets
2070 * the hba from the i_private field in @inode, allocates the necessary buffer
2071 * for the log, fills the buffer from the in-memory log for this hba, and then
2072 * returns a pointer to that log in the private_data field in @file.
2073 *
2074 * Returns:
2075 * This function returns zero if successful. On error it will return a negative
2076 * error value.
2077 **/
2078static int
2079lpfc_debugfs_multixripools_open(struct inode *inode, struct file *file)
2080{
2081 struct lpfc_hba *phba = inode->i_private;
2082 struct lpfc_debug *debug;
2083 int rc = -ENOMEM;
2084
2085 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2086 if (!debug)
2087 goto out;
2088
2089 /* Round to page boundary */
2090 debug->buffer = kzalloc(LPFC_DUMP_MULTIXRIPOOL_SIZE, GFP_KERNEL);
2091 if (!debug->buffer) {
2092 kfree(debug);
2093 goto out;
2094 }
2095
James Smart6a828b02019-01-28 11:14:31 -08002096 debug->len = lpfc_debugfs_multixripools_data(
2097 phba, debug->buffer, LPFC_DUMP_MULTIXRIPOOL_SIZE);
James Smartc4908502019-01-28 11:14:28 -08002098
2099 debug->i_private = inode->i_private;
2100 file->private_data = debug;
2101
2102 rc = 0;
2103out:
2104 return rc;
2105}
2106
James Smart6a828b02019-01-28 11:14:31 -08002107#ifdef LPFC_HDWQ_LOCK_STAT
James Smartc4908502019-01-28 11:14:28 -08002108/**
James Smart6a828b02019-01-28 11:14:31 -08002109 * lpfc_debugfs_lockstat_open - Open the lockstat debugfs buffer
James Smart5e5b5112019-01-28 11:14:22 -08002110 * @inode: The inode pointer that contains a vport pointer.
2111 * @file: The file pointer to attach the log output.
2112 *
2113 * Description:
2114 * This routine is the entry point for the debugfs open file operation. It gets
2115 * the vport from the i_private field in @inode, allocates the necessary buffer
2116 * for the log, fills the buffer from the in-memory log for this vport, and then
2117 * returns a pointer to that log in the private_data field in @file.
2118 *
2119 * Returns:
2120 * This function returns zero if successful. On error it will return a negative
2121 * error value.
2122 **/
2123static int
James Smart6a828b02019-01-28 11:14:31 -08002124lpfc_debugfs_lockstat_open(struct inode *inode, struct file *file)
James Smart5e5b5112019-01-28 11:14:22 -08002125{
2126 struct lpfc_hba *phba = inode->i_private;
2127 struct lpfc_debug *debug;
2128 int rc = -ENOMEM;
2129
2130 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2131 if (!debug)
2132 goto out;
2133
2134 /* Round to page boundary */
2135 debug->buffer = kmalloc(LPFC_HDWQINFO_SIZE, GFP_KERNEL);
2136 if (!debug->buffer) {
2137 kfree(debug);
2138 goto out;
2139 }
2140
James Smart6a828b02019-01-28 11:14:31 -08002141 debug->len = lpfc_debugfs_lockstat_data(phba, debug->buffer,
James Smart5e5b5112019-01-28 11:14:22 -08002142 LPFC_HBQINFO_SIZE);
2143 file->private_data = debug;
2144
2145 rc = 0;
2146out:
2147 return rc;
2148}
2149
James Smart6a828b02019-01-28 11:14:31 -08002150static ssize_t
2151lpfc_debugfs_lockstat_write(struct file *file, const char __user *buf,
2152 size_t nbytes, loff_t *ppos)
2153{
2154 struct lpfc_debug *debug = file->private_data;
2155 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2156 struct lpfc_sli4_hdw_queue *qp;
2157 char mybuf[64];
2158 char *pbuf;
2159 int i;
2160
James Smart6a828b02019-01-28 11:14:31 -08002161 memset(mybuf, 0, sizeof(mybuf));
2162
2163 if (copy_from_user(mybuf, buf, nbytes))
2164 return -EFAULT;
2165 pbuf = &mybuf[0];
2166
2167 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
2168 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
2169 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2170 qp = &phba->sli4_hba.hdwq[i];
2171 qp->lock_conflict.alloc_xri_get = 0;
2172 qp->lock_conflict.alloc_xri_put = 0;
2173 qp->lock_conflict.free_xri = 0;
2174 qp->lock_conflict.wq_access = 0;
2175 qp->lock_conflict.alloc_pvt_pool = 0;
2176 qp->lock_conflict.mv_from_pvt_pool = 0;
2177 qp->lock_conflict.mv_to_pub_pool = 0;
2178 qp->lock_conflict.mv_to_pvt_pool = 0;
2179 qp->lock_conflict.free_pvt_pool = 0;
2180 qp->lock_conflict.free_pub_pool = 0;
2181 qp->lock_conflict.wq_access = 0;
2182 }
2183 }
2184 return nbytes;
2185}
2186#endif
2187
YueHaibing7b10db52019-10-28 21:25:56 +08002188static int lpfc_debugfs_ras_log_data(struct lpfc_hba *phba,
2189 char *buffer, int size)
James Smart95bfc6d2019-10-18 14:18:27 -07002190{
2191 int copied = 0;
2192 struct lpfc_dmabuf *dmabuf, *next;
2193
James Smart9a20cc12019-12-18 15:58:03 -08002194 memset(buffer, 0, size);
2195
James Smart95bfc6d2019-10-18 14:18:27 -07002196 spin_lock_irq(&phba->hbalock);
2197 if (phba->ras_fwlog.state != ACTIVE) {
2198 spin_unlock_irq(&phba->hbalock);
2199 return -EINVAL;
2200 }
2201 spin_unlock_irq(&phba->hbalock);
2202
2203 list_for_each_entry_safe(dmabuf, next,
2204 &phba->ras_fwlog.fwlog_buff_list, list) {
James Smart9a20cc12019-12-18 15:58:03 -08002205 /* Check if copying will go over size and a '\0' char */
2206 if ((copied + LPFC_RAS_MAX_ENTRY_SIZE) >= (size - 1)) {
2207 memcpy(buffer + copied, dmabuf->virt,
2208 size - copied - 1);
2209 copied += size - copied - 1;
2210 break;
2211 }
James Smart95bfc6d2019-10-18 14:18:27 -07002212 memcpy(buffer + copied, dmabuf->virt, LPFC_RAS_MAX_ENTRY_SIZE);
2213 copied += LPFC_RAS_MAX_ENTRY_SIZE;
James Smart95bfc6d2019-10-18 14:18:27 -07002214 }
2215 return copied;
2216}
2217
2218static int
2219lpfc_debugfs_ras_log_release(struct inode *inode, struct file *file)
2220{
2221 struct lpfc_debug *debug = file->private_data;
2222
2223 vfree(debug->buffer);
2224 kfree(debug);
2225
2226 return 0;
2227}
2228
2229/**
2230 * lpfc_debugfs_ras_log_open - Open the RAS log debugfs buffer
2231 * @inode: The inode pointer that contains a vport pointer.
2232 * @file: The file pointer to attach the log output.
2233 *
2234 * Description:
2235 * This routine is the entry point for the debugfs open file operation. It gets
2236 * the vport from the i_private field in @inode, allocates the necessary buffer
2237 * for the log, fills the buffer from the in-memory log for this vport, and then
2238 * returns a pointer to that log in the private_data field in @file.
2239 *
2240 * Returns:
2241 * This function returns zero if successful. On error it will return a negative
2242 * error value.
2243 **/
2244static int
2245lpfc_debugfs_ras_log_open(struct inode *inode, struct file *file)
2246{
2247 struct lpfc_hba *phba = inode->i_private;
2248 struct lpfc_debug *debug;
2249 int size;
2250 int rc = -ENOMEM;
2251
2252 spin_lock_irq(&phba->hbalock);
2253 if (phba->ras_fwlog.state != ACTIVE) {
2254 spin_unlock_irq(&phba->hbalock);
2255 rc = -EINVAL;
2256 goto out;
2257 }
2258 spin_unlock_irq(&phba->hbalock);
2259 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2260 if (!debug)
2261 goto out;
2262
2263 size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;
2264 debug->buffer = vmalloc(size);
2265 if (!debug->buffer)
2266 goto free_debug;
2267
2268 debug->len = lpfc_debugfs_ras_log_data(phba, debug->buffer, size);
2269 if (debug->len < 0) {
2270 rc = -EINVAL;
2271 goto free_buffer;
2272 }
2273 file->private_data = debug;
2274
2275 return 0;
2276
2277free_buffer:
2278 vfree(debug->buffer);
2279free_debug:
2280 kfree(debug);
2281out:
2282 return rc;
2283}
2284
James Smart5e5b5112019-01-28 11:14:22 -08002285/**
James Smart3621a712009-04-06 18:47:14 -04002286 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -04002287 * @inode: The inode pointer that contains a vport pointer.
2288 * @file: The file pointer to attach the log output.
2289 *
2290 * Description:
2291 * This routine is the entry point for the debugfs open file operation. It gets
2292 * the vport from the i_private field in @inode, allocates the necessary buffer
2293 * for the log, fills the buffer from the in-memory log for this vport, and then
2294 * returns a pointer to that log in the private_data field in @file.
2295 *
2296 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02002297 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04002298 * error value.
2299 **/
James Smart78b2d852007-08-02 11:10:21 -04002300static int
James Smartc95d6c62008-01-11 01:53:23 -05002301lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
James Smarta58cbd52007-08-02 11:09:43 -04002302{
2303 struct lpfc_hba *phba = inode->i_private;
2304 struct lpfc_debug *debug;
2305 int rc = -ENOMEM;
2306
2307 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2308 if (!debug)
2309 goto out;
2310
James Smarte59058c2008-08-24 21:49:00 -04002311 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -05002312 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
James Smarta58cbd52007-08-02 11:09:43 -04002313 if (!debug->buffer) {
2314 kfree(debug);
2315 goto out;
2316 }
2317
James Smartc95d6c62008-01-11 01:53:23 -05002318 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
2319 LPFC_DUMPHBASLIM_SIZE);
2320 file->private_data = debug;
2321
2322 rc = 0;
2323out:
2324 return rc;
2325}
2326
James Smarte59058c2008-08-24 21:49:00 -04002327/**
James Smart3621a712009-04-06 18:47:14 -04002328 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
James Smarte59058c2008-08-24 21:49:00 -04002329 * @inode: The inode pointer that contains a vport pointer.
2330 * @file: The file pointer to attach the log output.
2331 *
2332 * Description:
2333 * This routine is the entry point for the debugfs open file operation. It gets
2334 * the vport from the i_private field in @inode, allocates the necessary buffer
2335 * for the log, fills the buffer from the in-memory log for this vport, and then
2336 * returns a pointer to that log in the private_data field in @file.
2337 *
2338 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02002339 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04002340 * error value.
2341 **/
James Smartc95d6c62008-01-11 01:53:23 -05002342static int
2343lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
2344{
2345 struct lpfc_hba *phba = inode->i_private;
2346 struct lpfc_debug *debug;
2347 int rc = -ENOMEM;
2348
2349 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2350 if (!debug)
2351 goto out;
2352
James Smarte59058c2008-08-24 21:49:00 -04002353 /* Round to page boundary */
James Smartc95d6c62008-01-11 01:53:23 -05002354 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
2355 if (!debug->buffer) {
2356 kfree(debug);
2357 goto out;
2358 }
2359
2360 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
2361 LPFC_DUMPHOSTSLIM_SIZE);
James Smarta58cbd52007-08-02 11:09:43 -04002362 file->private_data = debug;
2363
2364 rc = 0;
2365out:
2366 return rc;
2367}
2368
James Smartf9bb2da2011-10-10 21:34:11 -04002369static ssize_t
2370lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
2371 size_t nbytes, loff_t *ppos)
2372{
Al Virob5830432014-10-31 01:22:04 -04002373 struct dentry *dent = file->f_path.dentry;
James Smartf9bb2da2011-10-10 21:34:11 -04002374 struct lpfc_hba *phba = file->private_data;
James Smart9a6b09c2012-03-01 22:37:42 -05002375 char cbuf[32];
James Smart4ac9b222012-03-01 22:38:29 -05002376 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04002377 int cnt = 0;
2378
2379 if (dent == phba->debug_writeGuard)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002380 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04002381 else if (dent == phba->debug_writeApp)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002382 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04002383 else if (dent == phba->debug_writeRef)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002384 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
James Smartacd68592012-01-18 16:25:09 -05002385 else if (dent == phba->debug_readGuard)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002386 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04002387 else if (dent == phba->debug_readApp)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002388 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
James Smartf9bb2da2011-10-10 21:34:11 -04002389 else if (dent == phba->debug_readRef)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002390 cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
James Smart4ac9b222012-03-01 22:38:29 -05002391 else if (dent == phba->debug_InjErrNPortID)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002392 cnt = scnprintf(cbuf, 32, "0x%06x\n",
2393 phba->lpfc_injerr_nportid);
James Smart4ac9b222012-03-01 22:38:29 -05002394 else if (dent == phba->debug_InjErrWWPN) {
2395 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
2396 tmp = cpu_to_be64(tmp);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002397 cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
James Smart4ac9b222012-03-01 22:38:29 -05002398 } else if (dent == phba->debug_InjErrLBA) {
2399 if (phba->lpfc_injerr_lba == (sector_t)(-1))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002400 cnt = scnprintf(cbuf, 32, "off\n");
James Smart9a6b09c2012-03-01 22:37:42 -05002401 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07002402 cnt = scnprintf(cbuf, 32, "0x%llx\n",
James Smart4ac9b222012-03-01 22:38:29 -05002403 (uint64_t) phba->lpfc_injerr_lba);
James Smart9a6b09c2012-03-01 22:37:42 -05002404 } else
James Smartf9bb2da2011-10-10 21:34:11 -04002405 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2406 "0547 Unknown debugfs error injection entry\n");
2407
2408 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
2409}
2410
2411static ssize_t
2412lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
2413 size_t nbytes, loff_t *ppos)
2414{
Al Virob5830432014-10-31 01:22:04 -04002415 struct dentry *dent = file->f_path.dentry;
James Smartf9bb2da2011-10-10 21:34:11 -04002416 struct lpfc_hba *phba = file->private_data;
Alan0872774d2016-02-15 19:11:56 +00002417 char dstbuf[33];
James Smart4ac9b222012-03-01 22:38:29 -05002418 uint64_t tmp = 0;
James Smartf9bb2da2011-10-10 21:34:11 -04002419 int size;
2420
Alan0872774d2016-02-15 19:11:56 +00002421 memset(dstbuf, 0, 33);
James Smartf9bb2da2011-10-10 21:34:11 -04002422 size = (nbytes < 32) ? nbytes : 32;
2423 if (copy_from_user(dstbuf, buf, size))
Dan Carpenter19f1bc7e2021-03-12 10:42:11 +03002424 return -EFAULT;
James Smartf9bb2da2011-10-10 21:34:11 -04002425
James Smart9a6b09c2012-03-01 22:37:42 -05002426 if (dent == phba->debug_InjErrLBA) {
Dick Kennedya7fc0712020-05-01 14:43:08 -07002427 if ((dstbuf[0] == 'o') && (dstbuf[1] == 'f') &&
2428 (dstbuf[2] == 'f'))
James Smart4ac9b222012-03-01 22:38:29 -05002429 tmp = (uint64_t)(-1);
James Smart9a6b09c2012-03-01 22:37:42 -05002430 }
2431
James Smart4ac9b222012-03-01 22:38:29 -05002432 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
Dan Carpenter19f1bc7e2021-03-12 10:42:11 +03002433 return -EINVAL;
James Smartf9bb2da2011-10-10 21:34:11 -04002434
2435 if (dent == phba->debug_writeGuard)
2436 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
2437 else if (dent == phba->debug_writeApp)
2438 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
2439 else if (dent == phba->debug_writeRef)
2440 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
James Smartacd68592012-01-18 16:25:09 -05002441 else if (dent == phba->debug_readGuard)
2442 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
James Smartf9bb2da2011-10-10 21:34:11 -04002443 else if (dent == phba->debug_readApp)
2444 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
2445 else if (dent == phba->debug_readRef)
2446 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
2447 else if (dent == phba->debug_InjErrLBA)
2448 phba->lpfc_injerr_lba = (sector_t)tmp;
James Smart4ac9b222012-03-01 22:38:29 -05002449 else if (dent == phba->debug_InjErrNPortID)
2450 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
2451 else if (dent == phba->debug_InjErrWWPN) {
2452 tmp = cpu_to_be64(tmp);
2453 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
2454 } else
James Smartf9bb2da2011-10-10 21:34:11 -04002455 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2456 "0548 Unknown debugfs error injection entry\n");
2457
2458 return nbytes;
2459}
2460
2461static int
2462lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
2463{
2464 return 0;
2465}
2466
James Smarte59058c2008-08-24 21:49:00 -04002467/**
James Smart3621a712009-04-06 18:47:14 -04002468 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
James Smarte59058c2008-08-24 21:49:00 -04002469 * @inode: The inode pointer that contains a vport pointer.
2470 * @file: The file pointer to attach the log output.
2471 *
2472 * Description:
2473 * This routine is the entry point for the debugfs open file operation. It gets
2474 * the vport from the i_private field in @inode, allocates the necessary buffer
2475 * for the log, fills the buffer from the in-memory log for this vport, and then
2476 * returns a pointer to that log in the private_data field in @file.
2477 *
2478 * Returns:
Geert Uytterhoeven79ce48d2015-05-21 14:11:33 +02002479 * This function returns zero if successful. On error it will return a negative
James Smarte59058c2008-08-24 21:49:00 -04002480 * error value.
2481 **/
James Smarta58cbd52007-08-02 11:09:43 -04002482static int
James Smart858c9f62007-06-17 19:56:39 -05002483lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
2484{
2485 struct lpfc_vport *vport = inode->i_private;
2486 struct lpfc_debug *debug;
2487 int rc = -ENOMEM;
2488
2489 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2490 if (!debug)
2491 goto out;
2492
James Smarte59058c2008-08-24 21:49:00 -04002493 /* Round to page boundary */
James Smart858c9f62007-06-17 19:56:39 -05002494 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
2495 if (!debug->buffer) {
2496 kfree(debug);
2497 goto out;
2498 }
2499
2500 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
2501 LPFC_NODELIST_SIZE);
2502 file->private_data = debug;
2503
2504 rc = 0;
2505out:
2506 return rc;
2507}
2508
James Smarte59058c2008-08-24 21:49:00 -04002509/**
James Smart3621a712009-04-06 18:47:14 -04002510 * lpfc_debugfs_lseek - Seek through a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04002511 * @file: The file pointer to seek through.
2512 * @off: The offset to seek to or the amount to seek by.
2513 * @whence: Indicates how to seek.
2514 *
2515 * Description:
2516 * This routine is the entry point for the debugfs lseek file operation. The
2517 * @whence parameter indicates whether @off is the offset to directly seek to,
2518 * or if it is a value to seek forward or reverse by. This function figures out
2519 * what the new offset of the debugfs file will be and assigns that value to the
2520 * f_pos field of @file.
2521 *
2522 * Returns:
2523 * This function returns the new offset if successful and returns a negative
2524 * error if unable to process the seek.
2525 **/
James Smart858c9f62007-06-17 19:56:39 -05002526static loff_t
2527lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
2528{
Al Viro7233c772013-06-23 12:08:05 +04002529 struct lpfc_debug *debug = file->private_data;
2530 return fixed_size_llseek(file, off, whence, debug->len);
James Smart858c9f62007-06-17 19:56:39 -05002531}
2532
James Smarte59058c2008-08-24 21:49:00 -04002533/**
James Smart3621a712009-04-06 18:47:14 -04002534 * lpfc_debugfs_read - Read a debugfs file
James Smarte59058c2008-08-24 21:49:00 -04002535 * @file: The file pointer to read from.
2536 * @buf: The buffer to copy the data to.
2537 * @nbytes: The number of bytes to read.
2538 * @ppos: The position in the file to start reading from.
2539 *
2540 * Description:
2541 * This routine reads data from from the buffer indicated in the private_data
2542 * field of @file. It will start reading at @ppos and copy up to @nbytes of
2543 * data to @buf.
2544 *
2545 * Returns:
2546 * This function returns the amount of data that was read (this could be less
2547 * than @nbytes if the end of the file was reached) or a negative error value.
2548 **/
James Smart858c9f62007-06-17 19:56:39 -05002549static ssize_t
2550lpfc_debugfs_read(struct file *file, char __user *buf,
2551 size_t nbytes, loff_t *ppos)
2552{
2553 struct lpfc_debug *debug = file->private_data;
James Smart2a622bf2011-02-16 12:40:06 -05002554
James Smart858c9f62007-06-17 19:56:39 -05002555 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
2556 debug->len);
2557}
2558
James Smarte59058c2008-08-24 21:49:00 -04002559/**
James Smart3621a712009-04-06 18:47:14 -04002560 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
James Smarte59058c2008-08-24 21:49:00 -04002561 * @inode: The inode pointer that contains a vport pointer. (unused)
2562 * @file: The file pointer that contains the buffer to release.
2563 *
2564 * Description:
2565 * This routine frees the buffer that was allocated when the debugfs file was
2566 * opened.
2567 *
2568 * Returns:
2569 * This function returns zero.
2570 **/
James Smart858c9f62007-06-17 19:56:39 -05002571static int
2572lpfc_debugfs_release(struct inode *inode, struct file *file)
2573{
2574 struct lpfc_debug *debug = file->private_data;
2575
2576 kfree(debug->buffer);
2577 kfree(debug);
2578
2579 return 0;
2580}
2581
James Smartc4908502019-01-28 11:14:28 -08002582/**
2583 * lpfc_debugfs_multixripools_write - Clear multi-XRI pools statistics
2584 * @file: The file pointer to read from.
2585 * @buf: The buffer to copy the user data from.
2586 * @nbytes: The number of bytes to get.
2587 * @ppos: The position in the file to start reading from.
2588 *
2589 * Description:
2590 * This routine clears multi-XRI pools statistics when buf contains "clear".
2591 *
2592 * Return Value:
2593 * It returns the @nbytges passing in from debugfs user space when successful.
2594 * In case of error conditions, it returns proper error code back to the user
2595 * space.
2596 **/
2597static ssize_t
2598lpfc_debugfs_multixripools_write(struct file *file, const char __user *buf,
2599 size_t nbytes, loff_t *ppos)
2600{
2601 struct lpfc_debug *debug = file->private_data;
2602 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2603 char mybuf[64];
2604 char *pbuf;
2605 u32 i;
2606 u32 hwq_count;
2607 struct lpfc_sli4_hdw_queue *qp;
2608 struct lpfc_multixri_pool *multixri_pool;
2609
2610 if (nbytes > 64)
2611 nbytes = 64;
2612
James Smartc4908502019-01-28 11:14:28 -08002613 memset(mybuf, 0, sizeof(mybuf));
2614
2615 if (copy_from_user(mybuf, buf, nbytes))
2616 return -EFAULT;
2617 pbuf = &mybuf[0];
2618
2619 if ((strncmp(pbuf, "clear", strlen("clear"))) == 0) {
2620 hwq_count = phba->cfg_hdw_queue;
2621 for (i = 0; i < hwq_count; i++) {
2622 qp = &phba->sli4_hba.hdwq[i];
2623 multixri_pool = qp->p_multixri_pool;
2624 if (!multixri_pool)
2625 continue;
2626
2627 qp->empty_io_bufs = 0;
2628 multixri_pool->pbl_empty_count = 0;
2629#ifdef LPFC_MXP_STAT
2630 multixri_pool->above_limit_count = 0;
2631 multixri_pool->below_limit_count = 0;
2632 multixri_pool->stat_max_hwm = 0;
2633 multixri_pool->local_pbl_hit_count = 0;
2634 multixri_pool->other_pbl_hit_count = 0;
2635
2636 multixri_pool->stat_pbl_count = 0;
2637 multixri_pool->stat_pvt_count = 0;
2638 multixri_pool->stat_busy_count = 0;
2639 multixri_pool->stat_snapshot_taken = 0;
2640#endif
2641 }
2642 return strlen(pbuf);
2643 }
2644
2645 return -EINVAL;
2646}
James Smartbd2cdd52017-02-12 13:52:33 -08002647
2648static int
2649lpfc_debugfs_nvmestat_open(struct inode *inode, struct file *file)
2650{
2651 struct lpfc_vport *vport = inode->i_private;
2652 struct lpfc_debug *debug;
2653 int rc = -ENOMEM;
2654
2655 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2656 if (!debug)
2657 goto out;
2658
2659 /* Round to page boundary */
2660 debug->buffer = kmalloc(LPFC_NVMESTAT_SIZE, GFP_KERNEL);
2661 if (!debug->buffer) {
2662 kfree(debug);
2663 goto out;
2664 }
2665
2666 debug->len = lpfc_debugfs_nvmestat_data(vport, debug->buffer,
2667 LPFC_NVMESTAT_SIZE);
2668
2669 debug->i_private = inode->i_private;
2670 file->private_data = debug;
2671
2672 rc = 0;
2673out:
2674 return rc;
2675}
2676
James Smart2b65e182017-02-12 13:52:38 -08002677static ssize_t
2678lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
2679 size_t nbytes, loff_t *ppos)
2680{
2681 struct lpfc_debug *debug = file->private_data;
2682 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2683 struct lpfc_hba *phba = vport->phba;
2684 struct lpfc_nvmet_tgtport *tgtp;
2685 char mybuf[64];
2686 char *pbuf;
2687
2688 if (!phba->targetport)
2689 return -ENXIO;
2690
2691 if (nbytes > 64)
2692 nbytes = 64;
2693
James Smart2b65e182017-02-12 13:52:38 -08002694 memset(mybuf, 0, sizeof(mybuf));
2695
2696 if (copy_from_user(mybuf, buf, nbytes))
2697 return -EFAULT;
2698 pbuf = &mybuf[0];
2699
2700 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
2701 if ((strncmp(pbuf, "reset", strlen("reset")) == 0) ||
2702 (strncmp(pbuf, "zero", strlen("zero")) == 0)) {
2703 atomic_set(&tgtp->rcv_ls_req_in, 0);
2704 atomic_set(&tgtp->rcv_ls_req_out, 0);
2705 atomic_set(&tgtp->rcv_ls_req_drop, 0);
2706 atomic_set(&tgtp->xmt_ls_abort, 0);
James Smart547077a2017-05-15 15:20:40 -07002707 atomic_set(&tgtp->xmt_ls_abort_cmpl, 0);
James Smart2b65e182017-02-12 13:52:38 -08002708 atomic_set(&tgtp->xmt_ls_rsp, 0);
2709 atomic_set(&tgtp->xmt_ls_drop, 0);
2710 atomic_set(&tgtp->xmt_ls_rsp_error, 0);
2711 atomic_set(&tgtp->xmt_ls_rsp_cmpl, 0);
2712
2713 atomic_set(&tgtp->rcv_fcp_cmd_in, 0);
2714 atomic_set(&tgtp->rcv_fcp_cmd_out, 0);
2715 atomic_set(&tgtp->rcv_fcp_cmd_drop, 0);
James Smart2b65e182017-02-12 13:52:38 -08002716 atomic_set(&tgtp->xmt_fcp_drop, 0);
2717 atomic_set(&tgtp->xmt_fcp_read_rsp, 0);
2718 atomic_set(&tgtp->xmt_fcp_read, 0);
2719 atomic_set(&tgtp->xmt_fcp_write, 0);
2720 atomic_set(&tgtp->xmt_fcp_rsp, 0);
James Smart547077a2017-05-15 15:20:40 -07002721 atomic_set(&tgtp->xmt_fcp_release, 0);
James Smart2b65e182017-02-12 13:52:38 -08002722 atomic_set(&tgtp->xmt_fcp_rsp_cmpl, 0);
2723 atomic_set(&tgtp->xmt_fcp_rsp_error, 0);
2724 atomic_set(&tgtp->xmt_fcp_rsp_drop, 0);
2725
James Smart547077a2017-05-15 15:20:40 -07002726 atomic_set(&tgtp->xmt_fcp_abort, 0);
2727 atomic_set(&tgtp->xmt_fcp_abort_cmpl, 0);
2728 atomic_set(&tgtp->xmt_abort_sol, 0);
2729 atomic_set(&tgtp->xmt_abort_unsol, 0);
James Smart2b65e182017-02-12 13:52:38 -08002730 atomic_set(&tgtp->xmt_abort_rsp, 0);
2731 atomic_set(&tgtp->xmt_abort_rsp_error, 0);
James Smart2b65e182017-02-12 13:52:38 -08002732 }
2733 return nbytes;
2734}
2735
James Smartbd2cdd52017-02-12 13:52:33 -08002736static int
James Smart4c47efc2019-01-28 11:14:25 -08002737lpfc_debugfs_scsistat_open(struct inode *inode, struct file *file)
2738{
2739 struct lpfc_vport *vport = inode->i_private;
2740 struct lpfc_debug *debug;
2741 int rc = -ENOMEM;
2742
2743 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2744 if (!debug)
2745 goto out;
2746
2747 /* Round to page boundary */
2748 debug->buffer = kzalloc(LPFC_SCSISTAT_SIZE, GFP_KERNEL);
2749 if (!debug->buffer) {
2750 kfree(debug);
2751 goto out;
2752 }
2753
2754 debug->len = lpfc_debugfs_scsistat_data(vport, debug->buffer,
2755 LPFC_SCSISTAT_SIZE);
2756
2757 debug->i_private = inode->i_private;
2758 file->private_data = debug;
2759
2760 rc = 0;
2761out:
2762 return rc;
2763}
2764
2765static ssize_t
2766lpfc_debugfs_scsistat_write(struct file *file, const char __user *buf,
2767 size_t nbytes, loff_t *ppos)
2768{
2769 struct lpfc_debug *debug = file->private_data;
2770 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2771 struct lpfc_hba *phba = vport->phba;
2772 char mybuf[6] = {0};
2773 int i;
2774
James Smart4c47efc2019-01-28 11:14:25 -08002775 if (copy_from_user(mybuf, buf, (nbytes >= sizeof(mybuf)) ?
2776 (sizeof(mybuf) - 1) : nbytes))
2777 return -EFAULT;
2778
2779 if ((strncmp(&mybuf[0], "reset", strlen("reset")) == 0) ||
2780 (strncmp(&mybuf[0], "zero", strlen("zero")) == 0)) {
2781 for (i = 0; i < phba->cfg_hdw_queue; i++) {
2782 memset(&phba->sli4_hba.hdwq[i].scsi_cstat, 0,
2783 sizeof(phba->sli4_hba.hdwq[i].scsi_cstat));
2784 }
2785 }
2786
2787 return nbytes;
2788}
2789
2790static int
James Smart2fcbc562020-03-22 11:13:02 -07002791lpfc_debugfs_ioktime_open(struct inode *inode, struct file *file)
James Smartbd2cdd52017-02-12 13:52:33 -08002792{
2793 struct lpfc_vport *vport = inode->i_private;
2794 struct lpfc_debug *debug;
2795 int rc = -ENOMEM;
2796
2797 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2798 if (!debug)
2799 goto out;
2800
2801 /* Round to page boundary */
James Smart2fcbc562020-03-22 11:13:02 -07002802 debug->buffer = kmalloc(LPFC_IOKTIME_SIZE, GFP_KERNEL);
James Smartbd2cdd52017-02-12 13:52:33 -08002803 if (!debug->buffer) {
2804 kfree(debug);
2805 goto out;
2806 }
2807
James Smart2fcbc562020-03-22 11:13:02 -07002808 debug->len = lpfc_debugfs_ioktime_data(vport, debug->buffer,
2809 LPFC_IOKTIME_SIZE);
James Smartbd2cdd52017-02-12 13:52:33 -08002810
2811 debug->i_private = inode->i_private;
2812 file->private_data = debug;
2813
2814 rc = 0;
2815out:
2816 return rc;
2817}
2818
2819static ssize_t
James Smart2fcbc562020-03-22 11:13:02 -07002820lpfc_debugfs_ioktime_write(struct file *file, const char __user *buf,
2821 size_t nbytes, loff_t *ppos)
James Smartbd2cdd52017-02-12 13:52:33 -08002822{
2823 struct lpfc_debug *debug = file->private_data;
2824 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
2825 struct lpfc_hba *phba = vport->phba;
2826 char mybuf[64];
2827 char *pbuf;
2828
2829 if (nbytes > 64)
2830 nbytes = 64;
2831
James Smartbd2cdd52017-02-12 13:52:33 -08002832 memset(mybuf, 0, sizeof(mybuf));
2833
2834 if (copy_from_user(mybuf, buf, nbytes))
2835 return -EFAULT;
2836 pbuf = &mybuf[0];
2837
2838 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2839 phba->ktime_data_samples = 0;
2840 phba->ktime_status_samples = 0;
2841 phba->ktime_seg1_total = 0;
2842 phba->ktime_seg1_max = 0;
2843 phba->ktime_seg1_min = 0xffffffff;
2844 phba->ktime_seg2_total = 0;
2845 phba->ktime_seg2_max = 0;
2846 phba->ktime_seg2_min = 0xffffffff;
2847 phba->ktime_seg3_total = 0;
2848 phba->ktime_seg3_max = 0;
2849 phba->ktime_seg3_min = 0xffffffff;
2850 phba->ktime_seg4_total = 0;
2851 phba->ktime_seg4_max = 0;
2852 phba->ktime_seg4_min = 0xffffffff;
2853 phba->ktime_seg5_total = 0;
2854 phba->ktime_seg5_max = 0;
2855 phba->ktime_seg5_min = 0xffffffff;
2856 phba->ktime_seg6_total = 0;
2857 phba->ktime_seg6_max = 0;
2858 phba->ktime_seg6_min = 0xffffffff;
2859 phba->ktime_seg7_total = 0;
2860 phba->ktime_seg7_max = 0;
2861 phba->ktime_seg7_min = 0xffffffff;
2862 phba->ktime_seg8_total = 0;
2863 phba->ktime_seg8_max = 0;
2864 phba->ktime_seg8_min = 0xffffffff;
2865 phba->ktime_seg9_total = 0;
2866 phba->ktime_seg9_max = 0;
2867 phba->ktime_seg9_min = 0xffffffff;
2868 phba->ktime_seg10_total = 0;
2869 phba->ktime_seg10_max = 0;
2870 phba->ktime_seg10_min = 0xffffffff;
2871
2872 phba->ktime_on = 1;
2873 return strlen(pbuf);
2874 } else if ((strncmp(pbuf, "off",
2875 sizeof("off") - 1) == 0)) {
2876 phba->ktime_on = 0;
2877 return strlen(pbuf);
2878 } else if ((strncmp(pbuf, "zero",
2879 sizeof("zero") - 1) == 0)) {
2880 phba->ktime_data_samples = 0;
2881 phba->ktime_status_samples = 0;
2882 phba->ktime_seg1_total = 0;
2883 phba->ktime_seg1_max = 0;
2884 phba->ktime_seg1_min = 0xffffffff;
2885 phba->ktime_seg2_total = 0;
2886 phba->ktime_seg2_max = 0;
2887 phba->ktime_seg2_min = 0xffffffff;
2888 phba->ktime_seg3_total = 0;
2889 phba->ktime_seg3_max = 0;
2890 phba->ktime_seg3_min = 0xffffffff;
2891 phba->ktime_seg4_total = 0;
2892 phba->ktime_seg4_max = 0;
2893 phba->ktime_seg4_min = 0xffffffff;
2894 phba->ktime_seg5_total = 0;
2895 phba->ktime_seg5_max = 0;
2896 phba->ktime_seg5_min = 0xffffffff;
2897 phba->ktime_seg6_total = 0;
2898 phba->ktime_seg6_max = 0;
2899 phba->ktime_seg6_min = 0xffffffff;
2900 phba->ktime_seg7_total = 0;
2901 phba->ktime_seg7_max = 0;
2902 phba->ktime_seg7_min = 0xffffffff;
2903 phba->ktime_seg8_total = 0;
2904 phba->ktime_seg8_max = 0;
2905 phba->ktime_seg8_min = 0xffffffff;
2906 phba->ktime_seg9_total = 0;
2907 phba->ktime_seg9_max = 0;
2908 phba->ktime_seg9_min = 0xffffffff;
2909 phba->ktime_seg10_total = 0;
2910 phba->ktime_seg10_max = 0;
2911 phba->ktime_seg10_min = 0xffffffff;
2912 return strlen(pbuf);
2913 }
2914 return -EINVAL;
2915}
2916
2917static int
2918lpfc_debugfs_nvmeio_trc_open(struct inode *inode, struct file *file)
2919{
2920 struct lpfc_hba *phba = inode->i_private;
2921 struct lpfc_debug *debug;
2922 int rc = -ENOMEM;
2923
2924 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
2925 if (!debug)
2926 goto out;
2927
2928 /* Round to page boundary */
2929 debug->buffer = kmalloc(LPFC_NVMEIO_TRC_SIZE, GFP_KERNEL);
2930 if (!debug->buffer) {
2931 kfree(debug);
2932 goto out;
2933 }
2934
2935 debug->len = lpfc_debugfs_nvmeio_trc_data(phba, debug->buffer,
2936 LPFC_NVMEIO_TRC_SIZE);
2937
2938 debug->i_private = inode->i_private;
2939 file->private_data = debug;
2940
2941 rc = 0;
2942out:
2943 return rc;
2944}
2945
2946static ssize_t
2947lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
2948 size_t nbytes, loff_t *ppos)
2949{
2950 struct lpfc_debug *debug = file->private_data;
2951 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2952 int i;
2953 unsigned long sz;
2954 char mybuf[64];
2955 char *pbuf;
2956
Dan Carpenter9020be12021-12-14 10:05:27 +03002957 if (nbytes > 63)
2958 nbytes = 63;
James Smartbd2cdd52017-02-12 13:52:33 -08002959
James Smartbd2cdd52017-02-12 13:52:33 -08002960 memset(mybuf, 0, sizeof(mybuf));
2961
2962 if (copy_from_user(mybuf, buf, nbytes))
2963 return -EFAULT;
2964 pbuf = &mybuf[0];
2965
2966 if ((strncmp(pbuf, "off", sizeof("off") - 1) == 0)) {
2967 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2968 "0570 nvmeio_trc_off\n");
2969 phba->nvmeio_trc_output_idx = 0;
2970 phba->nvmeio_trc_on = 0;
2971 return strlen(pbuf);
2972 } else if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
2973 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2974 "0571 nvmeio_trc_on\n");
2975 phba->nvmeio_trc_output_idx = 0;
2976 phba->nvmeio_trc_on = 1;
2977 return strlen(pbuf);
2978 }
2979
2980 /* We must be off to allocate the trace buffer */
2981 if (phba->nvmeio_trc_on != 0)
2982 return -EINVAL;
2983
2984 /* If not on or off, the parameter is the trace buffer size */
2985 i = kstrtoul(pbuf, 0, &sz);
2986 if (i)
2987 return -EINVAL;
2988 phba->nvmeio_trc_size = (uint32_t)sz;
2989
2990 /* It must be a power of 2 - round down */
2991 i = 0;
2992 while (sz > 1) {
2993 sz = sz >> 1;
2994 i++;
2995 }
2996 sz = (1 << i);
2997 if (phba->nvmeio_trc_size != sz)
2998 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2999 "0572 nvmeio_trc_size changed to %ld\n",
3000 sz);
3001 phba->nvmeio_trc_size = (uint32_t)sz;
3002
3003 /* If one previously exists, free it */
3004 kfree(phba->nvmeio_trc);
3005
3006 /* Allocate new trace buffer and initialize */
Vasyl Gomonovych1c356ec2017-10-11 21:42:41 +02003007 phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
James Smartbd2cdd52017-02-12 13:52:33 -08003008 sz), GFP_KERNEL);
3009 if (!phba->nvmeio_trc) {
3010 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3011 "0573 Cannot create debugfs "
3012 "nvmeio_trc buffer\n");
3013 return -ENOMEM;
3014 }
James Smartbd2cdd52017-02-12 13:52:33 -08003015 atomic_set(&phba->nvmeio_trc_cnt, 0);
3016 phba->nvmeio_trc_on = 0;
3017 phba->nvmeio_trc_output_idx = 0;
3018
3019 return strlen(pbuf);
3020}
3021
3022static int
James Smart840eda92020-03-22 11:13:00 -07003023lpfc_debugfs_hdwqstat_open(struct inode *inode, struct file *file)
James Smartbd2cdd52017-02-12 13:52:33 -08003024{
3025 struct lpfc_vport *vport = inode->i_private;
3026 struct lpfc_debug *debug;
3027 int rc = -ENOMEM;
3028
3029 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
3030 if (!debug)
3031 goto out;
3032
3033 /* Round to page boundary */
James Smart840eda92020-03-22 11:13:00 -07003034 debug->buffer = kcalloc(1, LPFC_SCSISTAT_SIZE, GFP_KERNEL);
James Smartbd2cdd52017-02-12 13:52:33 -08003035 if (!debug->buffer) {
3036 kfree(debug);
3037 goto out;
3038 }
3039
James Smart840eda92020-03-22 11:13:00 -07003040 debug->len = lpfc_debugfs_hdwqstat_data(vport, debug->buffer,
3041 LPFC_SCSISTAT_SIZE);
James Smartbd2cdd52017-02-12 13:52:33 -08003042
3043 debug->i_private = inode->i_private;
3044 file->private_data = debug;
3045
3046 rc = 0;
3047out:
3048 return rc;
3049}
3050
3051static ssize_t
James Smart840eda92020-03-22 11:13:00 -07003052lpfc_debugfs_hdwqstat_write(struct file *file, const char __user *buf,
James Smartbd2cdd52017-02-12 13:52:33 -08003053 size_t nbytes, loff_t *ppos)
3054{
3055 struct lpfc_debug *debug = file->private_data;
3056 struct lpfc_vport *vport = (struct lpfc_vport *)debug->i_private;
3057 struct lpfc_hba *phba = vport->phba;
James Smart840eda92020-03-22 11:13:00 -07003058 struct lpfc_hdwq_stat *c_stat;
James Smartbd2cdd52017-02-12 13:52:33 -08003059 char mybuf[64];
3060 char *pbuf;
James Smart840eda92020-03-22 11:13:00 -07003061 int i;
James Smartbd2cdd52017-02-12 13:52:33 -08003062
3063 if (nbytes > 64)
3064 nbytes = 64;
3065
James Smartbd2cdd52017-02-12 13:52:33 -08003066 memset(mybuf, 0, sizeof(mybuf));
3067
3068 if (copy_from_user(mybuf, buf, nbytes))
3069 return -EFAULT;
3070 pbuf = &mybuf[0];
3071
3072 if ((strncmp(pbuf, "on", sizeof("on") - 1) == 0)) {
James Smart2b65e182017-02-12 13:52:38 -08003073 if (phba->nvmet_support)
James Smart840eda92020-03-22 11:13:00 -07003074 phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
James Smart2b65e182017-02-12 13:52:38 -08003075 else
James Smart840eda92020-03-22 11:13:00 -07003076 phba->hdwqstat_on |= (LPFC_CHECK_NVME_IO |
James Smart6a828b02019-01-28 11:14:31 -08003077 LPFC_CHECK_SCSI_IO);
3078 return strlen(pbuf);
3079 } else if ((strncmp(pbuf, "nvme_on", sizeof("nvme_on") - 1) == 0)) {
3080 if (phba->nvmet_support)
James Smart840eda92020-03-22 11:13:00 -07003081 phba->hdwqstat_on |= LPFC_CHECK_NVMET_IO;
James Smart6a828b02019-01-28 11:14:31 -08003082 else
James Smart840eda92020-03-22 11:13:00 -07003083 phba->hdwqstat_on |= LPFC_CHECK_NVME_IO;
James Smartbd2cdd52017-02-12 13:52:33 -08003084 return strlen(pbuf);
James Smart6a828b02019-01-28 11:14:31 -08003085 } else if ((strncmp(pbuf, "scsi_on", sizeof("scsi_on") - 1) == 0)) {
James Smart840eda92020-03-22 11:13:00 -07003086 if (!phba->nvmet_support)
3087 phba->hdwqstat_on |= LPFC_CHECK_SCSI_IO;
James Smart6a828b02019-01-28 11:14:31 -08003088 return strlen(pbuf);
James Smart840eda92020-03-22 11:13:00 -07003089 } else if ((strncmp(pbuf, "nvme_off", sizeof("nvme_off") - 1) == 0)) {
3090 phba->hdwqstat_on &= ~(LPFC_CHECK_NVME_IO |
3091 LPFC_CHECK_NVMET_IO);
3092 return strlen(pbuf);
3093 } else if ((strncmp(pbuf, "scsi_off", sizeof("scsi_off") - 1) == 0)) {
3094 phba->hdwqstat_on &= ~LPFC_CHECK_SCSI_IO;
James Smartf358dd02017-02-12 13:52:34 -08003095 return strlen(pbuf);
James Smartbd2cdd52017-02-12 13:52:33 -08003096 } else if ((strncmp(pbuf, "off",
3097 sizeof("off") - 1) == 0)) {
James Smart840eda92020-03-22 11:13:00 -07003098 phba->hdwqstat_on = LPFC_CHECK_OFF;
James Smartbd2cdd52017-02-12 13:52:33 -08003099 return strlen(pbuf);
3100 } else if ((strncmp(pbuf, "zero",
3101 sizeof("zero") - 1) == 0)) {
James Smart840eda92020-03-22 11:13:00 -07003102 for_each_present_cpu(i) {
3103 c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, i);
3104 c_stat->xmt_io = 0;
3105 c_stat->cmpl_io = 0;
3106 c_stat->rcv_io = 0;
James Smartbd2cdd52017-02-12 13:52:33 -08003107 }
3108 return strlen(pbuf);
3109 }
3110 return -EINVAL;
3111}
3112
James Smart2a622bf2011-02-16 12:40:06 -05003113/*
James Smart86a80842011-04-16 11:03:04 -04003114 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05003115 * iDiag debugfs file access methods
James Smart86a80842011-04-16 11:03:04 -04003116 * ---------------------------------
James Smart2a622bf2011-02-16 12:40:06 -05003117 *
James Smart86a80842011-04-16 11:03:04 -04003118 * All access methods are through the proper SLI4 PCI function's debugfs
3119 * iDiag directory:
James Smart2a622bf2011-02-16 12:40:06 -05003120 *
James Smart86a80842011-04-16 11:03:04 -04003121 * /sys/kernel/debug/lpfc/fn<#>/iDiag
James Smart2a622bf2011-02-16 12:40:06 -05003122 */
3123
3124/**
3125 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
3126 * @buf: The pointer to the user space buffer.
3127 * @nbytes: The number of bytes in the user space buffer.
3128 * @idiag_cmd: pointer to the idiag command struct.
3129 *
3130 * This routine reads data from debugfs user space buffer and parses the
3131 * buffer for getting the idiag command and arguments. The while space in
3132 * between the set of data is used as the parsing separator.
3133 *
3134 * This routine returns 0 when successful, it returns proper error code
3135 * back to the user space in error conditions.
3136 */
3137static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
3138 struct lpfc_idiag_cmd *idiag_cmd)
3139{
3140 char mybuf[64];
3141 char *pbuf, *step_str;
Stephen Boydb11d48e2011-05-12 16:50:06 -07003142 int i;
3143 size_t bsize;
James Smart2a622bf2011-02-16 12:40:06 -05003144
James Smart2a622bf2011-02-16 12:40:06 -05003145 memset(mybuf, 0, sizeof(mybuf));
3146 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
3147 bsize = min(nbytes, (sizeof(mybuf)-1));
3148
3149 if (copy_from_user(mybuf, buf, bsize))
3150 return -EFAULT;
3151 pbuf = &mybuf[0];
3152 step_str = strsep(&pbuf, "\t ");
3153
3154 /* The opcode must present */
3155 if (!step_str)
3156 return -EINVAL;
3157
3158 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
3159 if (idiag_cmd->opcode == 0)
3160 return -EINVAL;
3161
3162 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
3163 step_str = strsep(&pbuf, "\t ");
3164 if (!step_str)
James Smart86a80842011-04-16 11:03:04 -04003165 return i;
James Smart2a622bf2011-02-16 12:40:06 -05003166 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
3167 }
James Smart86a80842011-04-16 11:03:04 -04003168 return i;
James Smart2a622bf2011-02-16 12:40:06 -05003169}
3170
3171/**
3172 * lpfc_idiag_open - idiag open debugfs
3173 * @inode: The inode pointer that contains a pointer to phba.
3174 * @file: The file pointer to attach the file operation.
3175 *
3176 * Description:
3177 * This routine is the entry point for the debugfs open file operation. It
3178 * gets the reference to phba from the i_private field in @inode, it then
3179 * allocates buffer for the file operation, performs the necessary PCI config
3180 * space read into the allocated buffer according to the idiag user command
3181 * setup, and then returns a pointer to buffer in the private_data field in
3182 * @file.
3183 *
3184 * Returns:
3185 * This function returns zero if successful. On error it will return an
3186 * negative error value.
3187 **/
3188static int
3189lpfc_idiag_open(struct inode *inode, struct file *file)
3190{
3191 struct lpfc_debug *debug;
3192
3193 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
3194 if (!debug)
3195 return -ENOMEM;
3196
3197 debug->i_private = inode->i_private;
3198 debug->buffer = NULL;
3199 file->private_data = debug;
3200
3201 return 0;
3202}
3203
3204/**
3205 * lpfc_idiag_release - Release idiag access file operation
3206 * @inode: The inode pointer that contains a vport pointer. (unused)
3207 * @file: The file pointer that contains the buffer to release.
3208 *
3209 * Description:
3210 * This routine is the generic release routine for the idiag access file
3211 * operation, it frees the buffer that was allocated when the debugfs file
3212 * was opened.
3213 *
3214 * Returns:
3215 * This function returns zero.
3216 **/
3217static int
3218lpfc_idiag_release(struct inode *inode, struct file *file)
3219{
3220 struct lpfc_debug *debug = file->private_data;
3221
3222 /* Free the buffers to the file operation */
3223 kfree(debug->buffer);
3224 kfree(debug);
3225
3226 return 0;
3227}
3228
3229/**
3230 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
3231 * @inode: The inode pointer that contains a vport pointer. (unused)
3232 * @file: The file pointer that contains the buffer to release.
3233 *
3234 * Description:
3235 * This routine frees the buffer that was allocated when the debugfs file
3236 * was opened. It also reset the fields in the idiag command struct in the
James Smart86a80842011-04-16 11:03:04 -04003237 * case of command for write operation.
James Smart2a622bf2011-02-16 12:40:06 -05003238 *
3239 * Returns:
3240 * This function returns zero.
3241 **/
3242static int
3243lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
3244{
3245 struct lpfc_debug *debug = file->private_data;
3246
James Smart86a80842011-04-16 11:03:04 -04003247 if (debug->op == LPFC_IDIAG_OP_WR) {
3248 switch (idiag.cmd.opcode) {
3249 case LPFC_IDIAG_CMD_PCICFG_WR:
3250 case LPFC_IDIAG_CMD_PCICFG_ST:
3251 case LPFC_IDIAG_CMD_PCICFG_CL:
3252 case LPFC_IDIAG_CMD_QUEACC_WR:
3253 case LPFC_IDIAG_CMD_QUEACC_ST:
3254 case LPFC_IDIAG_CMD_QUEACC_CL:
James Smart2a622bf2011-02-16 12:40:06 -05003255 memset(&idiag, 0, sizeof(idiag));
James Smart86a80842011-04-16 11:03:04 -04003256 break;
3257 default:
3258 break;
3259 }
3260 }
James Smart2a622bf2011-02-16 12:40:06 -05003261
3262 /* Free the buffers to the file operation */
3263 kfree(debug->buffer);
3264 kfree(debug);
3265
3266 return 0;
3267}
3268
3269/**
3270 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
3271 * @file: The file pointer to read from.
3272 * @buf: The buffer to copy the data to.
3273 * @nbytes: The number of bytes to read.
3274 * @ppos: The position in the file to start reading from.
3275 *
3276 * Description:
3277 * This routine reads data from the @phba pci config space according to the
3278 * idiag command, and copies to user @buf. Depending on the PCI config space
3279 * read command setup, it does either a single register read of a byte
3280 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
3281 * registers from the 4K extended PCI config space.
3282 *
3283 * Returns:
3284 * This function returns the amount of data that was read (this could be less
3285 * than @nbytes if the end of the file was reached) or a negative error value.
3286 **/
3287static ssize_t
3288lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
3289 loff_t *ppos)
3290{
3291 struct lpfc_debug *debug = file->private_data;
3292 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3293 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
3294 int where, count;
3295 char *pbuffer;
3296 struct pci_dev *pdev;
3297 uint32_t u32val;
3298 uint16_t u16val;
3299 uint8_t u8val;
3300
3301 pdev = phba->pcidev;
3302 if (!pdev)
3303 return 0;
3304
3305 /* This is a user read operation */
3306 debug->op = LPFC_IDIAG_OP_RD;
3307
3308 if (!debug->buffer)
3309 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
3310 if (!debug->buffer)
3311 return 0;
3312 pbuffer = debug->buffer;
3313
3314 if (*ppos)
3315 return 0;
3316
3317 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04003318 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3319 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05003320 } else
3321 return 0;
3322
3323 /* Read single PCI config space register */
3324 switch (count) {
3325 case SIZE_U8: /* byte (8 bits) */
3326 pci_read_config_byte(pdev, where, &u8val);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003327 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003328 "%03x: %02x\n", where, u8val);
3329 break;
3330 case SIZE_U16: /* word (16 bits) */
3331 pci_read_config_word(pdev, where, &u16val);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003332 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003333 "%03x: %04x\n", where, u16val);
3334 break;
3335 case SIZE_U32: /* double word (32 bits) */
3336 pci_read_config_dword(pdev, where, &u32val);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003337 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003338 "%03x: %08x\n", where, u32val);
3339 break;
James Smart86a80842011-04-16 11:03:04 -04003340 case LPFC_PCI_CFG_BROWSE: /* browse all */
James Smart2a622bf2011-02-16 12:40:06 -05003341 goto pcicfg_browse;
James Smart2a622bf2011-02-16 12:40:06 -05003342 default:
3343 /* illegal count */
3344 len = 0;
3345 break;
3346 }
3347 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3348
3349pcicfg_browse:
3350
3351 /* Browse all PCI config space registers */
3352 offset_label = idiag.offset.last_rd;
3353 offset = offset_label;
3354
3355 /* Read PCI config space */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003356 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003357 "%03x: ", offset_label);
3358 while (index > 0) {
3359 pci_read_config_dword(pdev, offset, &u32val);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003360 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003361 "%08x ", u32val);
3362 offset += sizeof(uint32_t);
James Smartb76f2dc2011-07-22 18:37:42 -04003363 if (offset >= LPFC_PCI_CFG_SIZE) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003364 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003365 LPFC_PCI_CFG_SIZE-len, "\n");
3366 break;
3367 }
James Smart2a622bf2011-02-16 12:40:06 -05003368 index -= sizeof(uint32_t);
3369 if (!index)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003370 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003371 "\n");
3372 else if (!(index % (8 * sizeof(uint32_t)))) {
3373 offset_label += (8 * sizeof(uint32_t));
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003374 len += scnprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
James Smart2a622bf2011-02-16 12:40:06 -05003375 "\n%03x: ", offset_label);
3376 }
3377 }
3378
3379 /* Set up the offset for next portion of pci cfg read */
James Smartb76f2dc2011-07-22 18:37:42 -04003380 if (index == 0) {
3381 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
3382 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
3383 idiag.offset.last_rd = 0;
3384 } else
James Smart2a622bf2011-02-16 12:40:06 -05003385 idiag.offset.last_rd = 0;
3386
3387 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3388}
3389
3390/**
3391 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
3392 * @file: The file pointer to read from.
3393 * @buf: The buffer to copy the user data from.
3394 * @nbytes: The number of bytes to get.
3395 * @ppos: The position in the file to start reading from.
3396 *
3397 * This routine get the debugfs idiag command struct from user space and
3398 * then perform the syntax check for PCI config space read or write command
3399 * accordingly. In the case of PCI config space read command, it sets up
3400 * the command in the idiag command struct for the debugfs read operation.
3401 * In the case of PCI config space write operation, it executes the write
3402 * operation into the PCI config space accordingly.
3403 *
3404 * It returns the @nbytges passing in from debugfs user space when successful.
3405 * In case of error conditions, it returns proper error code back to the user
3406 * space.
3407 */
3408static ssize_t
3409lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
3410 size_t nbytes, loff_t *ppos)
3411{
3412 struct lpfc_debug *debug = file->private_data;
3413 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3414 uint32_t where, value, count;
3415 uint32_t u32val;
3416 uint16_t u16val;
3417 uint8_t u8val;
3418 struct pci_dev *pdev;
3419 int rc;
3420
3421 pdev = phba->pcidev;
3422 if (!pdev)
3423 return -EFAULT;
3424
3425 /* This is a user write operation */
3426 debug->op = LPFC_IDIAG_OP_WR;
3427
3428 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
James Smart86a80842011-04-16 11:03:04 -04003429 if (rc < 0)
James Smart2a622bf2011-02-16 12:40:06 -05003430 return rc;
3431
3432 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
James Smart86a80842011-04-16 11:03:04 -04003433 /* Sanity check on PCI config read command line arguments */
3434 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
3435 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05003436 /* Read command from PCI config space, set up command fields */
James Smartb76f2dc2011-07-22 18:37:42 -04003437 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3438 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04003439 if (count == LPFC_PCI_CFG_BROWSE) {
3440 if (where % sizeof(uint32_t))
James Smart2a622bf2011-02-16 12:40:06 -05003441 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04003442 /* Starting offset to browse */
3443 idiag.offset.last_rd = where;
James Smart2a622bf2011-02-16 12:40:06 -05003444 } else if ((count != sizeof(uint8_t)) &&
3445 (count != sizeof(uint16_t)) &&
3446 (count != sizeof(uint32_t)))
3447 goto error_out;
3448 if (count == sizeof(uint8_t)) {
3449 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
3450 goto error_out;
3451 if (where % sizeof(uint8_t))
3452 goto error_out;
3453 }
3454 if (count == sizeof(uint16_t)) {
3455 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
3456 goto error_out;
3457 if (where % sizeof(uint16_t))
3458 goto error_out;
3459 }
3460 if (count == sizeof(uint32_t)) {
3461 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
3462 goto error_out;
3463 if (where % sizeof(uint32_t))
3464 goto error_out;
3465 }
3466 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
3467 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
3468 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
James Smart86a80842011-04-16 11:03:04 -04003469 /* Sanity check on PCI config write command line arguments */
3470 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
3471 goto error_out;
James Smart2a622bf2011-02-16 12:40:06 -05003472 /* Write command to PCI config space, read-modify-write */
James Smartb76f2dc2011-07-22 18:37:42 -04003473 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
3474 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
3475 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
James Smart2a622bf2011-02-16 12:40:06 -05003476 /* Sanity checks */
3477 if ((count != sizeof(uint8_t)) &&
3478 (count != sizeof(uint16_t)) &&
3479 (count != sizeof(uint32_t)))
3480 goto error_out;
3481 if (count == sizeof(uint8_t)) {
3482 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
3483 goto error_out;
3484 if (where % sizeof(uint8_t))
3485 goto error_out;
3486 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3487 pci_write_config_byte(pdev, where,
3488 (uint8_t)value);
3489 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3490 rc = pci_read_config_byte(pdev, where, &u8val);
3491 if (!rc) {
3492 u8val |= (uint8_t)value;
3493 pci_write_config_byte(pdev, where,
3494 u8val);
3495 }
3496 }
3497 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3498 rc = pci_read_config_byte(pdev, where, &u8val);
3499 if (!rc) {
3500 u8val &= (uint8_t)(~value);
3501 pci_write_config_byte(pdev, where,
3502 u8val);
3503 }
3504 }
3505 }
3506 if (count == sizeof(uint16_t)) {
3507 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
3508 goto error_out;
3509 if (where % sizeof(uint16_t))
3510 goto error_out;
3511 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3512 pci_write_config_word(pdev, where,
3513 (uint16_t)value);
3514 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3515 rc = pci_read_config_word(pdev, where, &u16val);
3516 if (!rc) {
3517 u16val |= (uint16_t)value;
3518 pci_write_config_word(pdev, where,
3519 u16val);
3520 }
3521 }
3522 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3523 rc = pci_read_config_word(pdev, where, &u16val);
3524 if (!rc) {
3525 u16val &= (uint16_t)(~value);
3526 pci_write_config_word(pdev, where,
3527 u16val);
3528 }
3529 }
3530 }
3531 if (count == sizeof(uint32_t)) {
3532 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
3533 goto error_out;
3534 if (where % sizeof(uint32_t))
3535 goto error_out;
3536 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
3537 pci_write_config_dword(pdev, where, value);
3538 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
3539 rc = pci_read_config_dword(pdev, where,
3540 &u32val);
3541 if (!rc) {
3542 u32val |= value;
3543 pci_write_config_dword(pdev, where,
3544 u32val);
3545 }
3546 }
3547 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
3548 rc = pci_read_config_dword(pdev, where,
3549 &u32val);
3550 if (!rc) {
3551 u32val &= ~value;
3552 pci_write_config_dword(pdev, where,
3553 u32val);
3554 }
3555 }
3556 }
3557 } else
3558 /* All other opecodes are illegal for now */
3559 goto error_out;
3560
3561 return nbytes;
3562error_out:
3563 memset(&idiag, 0, sizeof(idiag));
3564 return -EINVAL;
3565}
3566
3567/**
James Smartb76f2dc2011-07-22 18:37:42 -04003568 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
3569 * @file: The file pointer to read from.
3570 * @buf: The buffer to copy the data to.
3571 * @nbytes: The number of bytes to read.
3572 * @ppos: The position in the file to start reading from.
3573 *
3574 * Description:
3575 * This routine reads data from the @phba pci bar memory mapped space
3576 * according to the idiag command, and copies to user @buf.
3577 *
3578 * Returns:
3579 * This function returns the amount of data that was read (this could be less
3580 * than @nbytes if the end of the file was reached) or a negative error value.
3581 **/
3582static ssize_t
3583lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
3584 loff_t *ppos)
3585{
3586 struct lpfc_debug *debug = file->private_data;
3587 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3588 int offset_label, offset, offset_run, len = 0, index;
3589 int bar_num, acc_range, bar_size;
3590 char *pbuffer;
3591 void __iomem *mem_mapped_bar;
3592 uint32_t if_type;
3593 struct pci_dev *pdev;
3594 uint32_t u32val;
3595
3596 pdev = phba->pcidev;
3597 if (!pdev)
3598 return 0;
3599
3600 /* This is a user read operation */
3601 debug->op = LPFC_IDIAG_OP_RD;
3602
3603 if (!debug->buffer)
3604 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
3605 if (!debug->buffer)
3606 return 0;
3607 pbuffer = debug->buffer;
3608
3609 if (*ppos)
3610 return 0;
3611
3612 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3613 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
3614 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3615 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3616 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3617 } else
3618 return 0;
3619
3620 if (acc_range == 0)
3621 return 0;
3622
3623 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3624 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3625 if (bar_num == IDIAG_BARACC_BAR_0)
3626 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3627 else if (bar_num == IDIAG_BARACC_BAR_1)
3628 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
3629 else if (bar_num == IDIAG_BARACC_BAR_2)
3630 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3631 else
3632 return 0;
3633 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3634 if (bar_num == IDIAG_BARACC_BAR_0)
3635 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3636 else
3637 return 0;
3638 } else
3639 return 0;
3640
3641 /* Read single PCI bar space register */
3642 if (acc_range == SINGLE_WORD) {
3643 offset_run = offset;
3644 u32val = readl(mem_mapped_bar + offset_run);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003645 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04003646 "%05x: %08x\n", offset_run, u32val);
3647 } else
3648 goto baracc_browse;
3649
3650 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3651
3652baracc_browse:
3653
3654 /* Browse all PCI bar space registers */
3655 offset_label = idiag.offset.last_rd;
3656 offset_run = offset_label;
3657
3658 /* Read PCI bar memory mapped space */
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003659 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04003660 "%05x: ", offset_label);
3661 index = LPFC_PCI_BAR_RD_SIZE;
3662 while (index > 0) {
3663 u32val = readl(mem_mapped_bar + offset_run);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003664 len += scnprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04003665 "%08x ", u32val);
3666 offset_run += sizeof(uint32_t);
3667 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3668 if (offset_run >= bar_size) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003669 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003670 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3671 break;
3672 }
3673 } else {
3674 if (offset_run >= offset +
3675 (acc_range * sizeof(uint32_t))) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003676 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003677 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3678 break;
3679 }
3680 }
3681 index -= sizeof(uint32_t);
3682 if (!index)
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003683 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003684 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
3685 else if (!(index % (8 * sizeof(uint32_t)))) {
3686 offset_label += (8 * sizeof(uint32_t));
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003687 len += scnprintf(pbuffer+len,
James Smartb76f2dc2011-07-22 18:37:42 -04003688 LPFC_PCI_BAR_RD_BUF_SIZE-len,
3689 "\n%05x: ", offset_label);
3690 }
3691 }
3692
3693 /* Set up the offset for next portion of pci bar read */
3694 if (index == 0) {
3695 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
3696 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3697 if (idiag.offset.last_rd >= bar_size)
3698 idiag.offset.last_rd = 0;
3699 } else {
3700 if (offset_run >= offset +
3701 (acc_range * sizeof(uint32_t)))
3702 idiag.offset.last_rd = offset;
3703 }
3704 } else {
3705 if (acc_range == LPFC_PCI_BAR_BROWSE)
3706 idiag.offset.last_rd = 0;
3707 else
3708 idiag.offset.last_rd = offset;
3709 }
3710
3711 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3712}
3713
3714/**
3715 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
3716 * @file: The file pointer to read from.
3717 * @buf: The buffer to copy the user data from.
3718 * @nbytes: The number of bytes to get.
3719 * @ppos: The position in the file to start reading from.
3720 *
3721 * This routine get the debugfs idiag command struct from user space and
3722 * then perform the syntax check for PCI bar memory mapped space read or
3723 * write command accordingly. In the case of PCI bar memory mapped space
3724 * read command, it sets up the command in the idiag command struct for
3725 * the debugfs read operation. In the case of PCI bar memorpy mapped space
3726 * write operation, it executes the write operation into the PCI bar memory
3727 * mapped space accordingly.
3728 *
3729 * It returns the @nbytges passing in from debugfs user space when successful.
3730 * In case of error conditions, it returns proper error code back to the user
3731 * space.
3732 */
3733static ssize_t
3734lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
3735 size_t nbytes, loff_t *ppos)
3736{
3737 struct lpfc_debug *debug = file->private_data;
3738 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3739 uint32_t bar_num, bar_size, offset, value, acc_range;
3740 struct pci_dev *pdev;
3741 void __iomem *mem_mapped_bar;
3742 uint32_t if_type;
3743 uint32_t u32val;
3744 int rc;
3745
3746 pdev = phba->pcidev;
3747 if (!pdev)
3748 return -EFAULT;
3749
3750 /* This is a user write operation */
3751 debug->op = LPFC_IDIAG_OP_WR;
3752
3753 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3754 if (rc < 0)
3755 return rc;
3756
3757 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3758 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
3759
3760 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3761 if ((bar_num != IDIAG_BARACC_BAR_0) &&
3762 (bar_num != IDIAG_BARACC_BAR_1) &&
3763 (bar_num != IDIAG_BARACC_BAR_2))
3764 goto error_out;
3765 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3766 if (bar_num != IDIAG_BARACC_BAR_0)
3767 goto error_out;
3768 } else
3769 goto error_out;
3770
3771 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
3772 if (bar_num == IDIAG_BARACC_BAR_0) {
3773 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3774 LPFC_PCI_IF0_BAR0_SIZE;
3775 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3776 } else if (bar_num == IDIAG_BARACC_BAR_1) {
3777 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3778 LPFC_PCI_IF0_BAR1_SIZE;
3779 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
3780 } else if (bar_num == IDIAG_BARACC_BAR_2) {
3781 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3782 LPFC_PCI_IF0_BAR2_SIZE;
3783 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
3784 } else
3785 goto error_out;
3786 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
3787 if (bar_num == IDIAG_BARACC_BAR_0) {
3788 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
3789 LPFC_PCI_IF2_BAR0_SIZE;
3790 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
3791 } else
3792 goto error_out;
3793 } else
3794 goto error_out;
3795
3796 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
3797 if (offset % sizeof(uint32_t))
3798 goto error_out;
3799
3800 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
3801 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
3802 /* Sanity check on PCI config read command line arguments */
3803 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
3804 goto error_out;
3805 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
3806 if (acc_range == LPFC_PCI_BAR_BROWSE) {
3807 if (offset > bar_size - sizeof(uint32_t))
3808 goto error_out;
3809 /* Starting offset to browse */
3810 idiag.offset.last_rd = offset;
3811 } else if (acc_range > SINGLE_WORD) {
3812 if (offset + acc_range * sizeof(uint32_t) > bar_size)
3813 goto error_out;
3814 /* Starting offset to browse */
3815 idiag.offset.last_rd = offset;
3816 } else if (acc_range != SINGLE_WORD)
3817 goto error_out;
3818 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
3819 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
3820 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3821 /* Sanity check on PCI bar write command line arguments */
3822 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
3823 goto error_out;
3824 /* Write command to PCI bar space, read-modify-write */
3825 acc_range = SINGLE_WORD;
3826 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
3827 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
3828 writel(value, mem_mapped_bar + offset);
3829 readl(mem_mapped_bar + offset);
3830 }
3831 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
3832 u32val = readl(mem_mapped_bar + offset);
3833 u32val |= value;
3834 writel(u32val, mem_mapped_bar + offset);
3835 readl(mem_mapped_bar + offset);
3836 }
3837 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
3838 u32val = readl(mem_mapped_bar + offset);
3839 u32val &= ~value;
3840 writel(u32val, mem_mapped_bar + offset);
3841 readl(mem_mapped_bar + offset);
3842 }
3843 } else
3844 /* All other opecodes are illegal for now */
3845 goto error_out;
3846
3847 return nbytes;
3848error_out:
3849 memset(&idiag, 0, sizeof(idiag));
3850 return -EINVAL;
3851}
3852
James Smart07bcd982017-02-12 13:52:28 -08003853static int
3854__lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype,
3855 char *pbuffer, int len)
3856{
3857 if (!qp)
3858 return len;
3859
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003860 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003861 "\t\t%s WQ info: ", wqtype);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003862 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003863 "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n",
3864 qp->assoc_qid, qp->q_cnt_1,
3865 (unsigned long long)qp->q_cnt_4);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003866 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07003867 "\t\tWQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08003868 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]",
James Smart07bcd982017-02-12 13:52:28 -08003869 qp->queue_id, qp->entry_count,
3870 qp->entry_size, qp->host_index,
James Smart32517fc2019-01-28 11:14:33 -08003871 qp->hba_index, qp->notify_interval);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003872 len += scnprintf(pbuffer + len,
James Smart07bcd982017-02-12 13:52:28 -08003873 LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n");
3874 return len;
3875}
3876
3877static int
3878lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer,
3879 int *len, int max_cnt, int cq_id)
3880{
3881 struct lpfc_queue *qp;
3882 int qidx;
3883
James Smartcdb42be2019-01-28 11:14:21 -08003884 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smartc00f62e2019-08-14 16:57:11 -07003885 qp = phba->sli4_hba.hdwq[qidx].io_wq;
James Smart07bcd982017-02-12 13:52:28 -08003886 if (qp->assoc_qid != cq_id)
3887 continue;
3888 *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len);
3889 if (*len >= max_cnt)
3890 return 1;
3891 }
3892 return 0;
3893}
3894
3895static int
3896__lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype,
3897 char *pbuffer, int len)
3898{
3899 if (!qp)
3900 return len;
3901
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003902 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003903 "\t%s CQ info: ", cqtype);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003904 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003905 "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x "
3906 "xabt:x%x wq:x%llx]\n",
3907 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3908 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003909 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07003910 "\tCQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08003911 "HST-IDX[%04d], NTFI[%03d], PLMT[%03d]",
James Smart07bcd982017-02-12 13:52:28 -08003912 qp->queue_id, qp->entry_count,
3913 qp->entry_size, qp->host_index,
James Smart32517fc2019-01-28 11:14:33 -08003914 qp->notify_interval, qp->max_proc_limit);
James Smart07bcd982017-02-12 13:52:28 -08003915
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003916 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
3917 "\n");
James Smart07bcd982017-02-12 13:52:28 -08003918
3919 return len;
3920}
3921
3922static int
3923__lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp,
3924 char *rqtype, char *pbuffer, int len)
3925{
3926 if (!qp || !datqp)
3927 return len;
3928
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003929 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003930 "\t\t%s RQ info: ", rqtype);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003931 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08003932 "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x "
James Smart547077a2017-05-15 15:20:40 -07003933 "posted:x%x rcv:x%llx]\n",
James Smart07bcd982017-02-12 13:52:28 -08003934 qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2,
3935 qp->q_cnt_3, (unsigned long long)qp->q_cnt_4);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003936 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07003937 "\t\tHQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08003938 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
James Smart07bcd982017-02-12 13:52:28 -08003939 qp->queue_id, qp->entry_count, qp->entry_size,
James Smart32517fc2019-01-28 11:14:33 -08003940 qp->host_index, qp->hba_index, qp->notify_interval);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07003941 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07003942 "\t\tDQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08003943 "HST-IDX[%04d], PRT-IDX[%04d], NTFI[%03d]\n",
James Smart07bcd982017-02-12 13:52:28 -08003944 datqp->queue_id, datqp->entry_count,
3945 datqp->entry_size, datqp->host_index,
James Smart32517fc2019-01-28 11:14:33 -08003946 datqp->hba_index, datqp->notify_interval);
James Smart07bcd982017-02-12 13:52:28 -08003947 return len;
3948}
3949
3950static int
3951lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer,
James Smart2d7dbc42017-02-12 13:52:35 -08003952 int *len, int max_cnt, int eqidx, int eq_id)
James Smart07bcd982017-02-12 13:52:28 -08003953{
3954 struct lpfc_queue *qp;
James Smart6a828b02019-01-28 11:14:31 -08003955 int rc;
James Smart07bcd982017-02-12 13:52:28 -08003956
James Smartc00f62e2019-08-14 16:57:11 -07003957 qp = phba->sli4_hba.hdwq[eqidx].io_cq;
James Smart07bcd982017-02-12 13:52:28 -08003958
James Smartc00f62e2019-08-14 16:57:11 -07003959 *len = __lpfc_idiag_print_cq(qp, "IO", pbuffer, *len);
James Smart6a828b02019-01-28 11:14:31 -08003960
3961 /* Reset max counter */
3962 qp->CQ_max_cqe = 0;
3963
3964 if (*len >= max_cnt)
3965 return 1;
3966
James Smartc00f62e2019-08-14 16:57:11 -07003967 rc = lpfc_idiag_wqs_for_cq(phba, "IO", pbuffer, len,
James Smart6a828b02019-01-28 11:14:31 -08003968 max_cnt, qp->queue_id);
3969 if (rc)
3970 return 1;
3971
James Smartbcb24f62017-11-20 16:00:36 -08003972 if ((eqidx < phba->cfg_nvmet_mrq) && phba->nvmet_support) {
James Smart2d7dbc42017-02-12 13:52:35 -08003973 /* NVMET CQset */
3974 qp = phba->sli4_hba.nvmet_cqset[eqidx];
3975 *len = __lpfc_idiag_print_cq(qp, "NVMET CQset", pbuffer, *len);
3976
3977 /* Reset max counter */
3978 qp->CQ_max_cqe = 0;
3979
3980 if (*len >= max_cnt)
3981 return 1;
3982
3983 /* RQ header */
3984 qp = phba->sli4_hba.nvmet_mrq_hdr[eqidx];
3985 *len = __lpfc_idiag_print_rqpair(qp,
3986 phba->sli4_hba.nvmet_mrq_data[eqidx],
3987 "NVMET MRQ", pbuffer, *len);
3988
3989 if (*len >= max_cnt)
3990 return 1;
3991 }
3992
James Smart07bcd982017-02-12 13:52:28 -08003993 return 0;
3994}
3995
3996static int
3997__lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype,
3998 char *pbuffer, int len)
3999{
4000 if (!qp)
4001 return len;
4002
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004003 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart07bcd982017-02-12 13:52:28 -08004004 "\n%s EQ info: EQ-STAT[max:x%x noE:x%x "
James Smart07d494f2017-11-20 16:00:35 -08004005 "cqe_proc:x%x eqe_proc:x%llx eqd %d]\n",
James Smart07bcd982017-02-12 13:52:28 -08004006 eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3,
James Smart0cf07f842017-06-01 21:07:10 -07004007 (unsigned long long)qp->q_cnt_4, qp->q_mode);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004008 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
James Smart7869da12017-05-15 15:20:43 -07004009 "EQID[%02d], QE-CNT[%04d], QE-SZ[%04d], "
James Smart32517fc2019-01-28 11:14:33 -08004010 "HST-IDX[%04d], NTFI[%03d], PLMT[%03d], AFFIN[%03d]",
James Smart07bcd982017-02-12 13:52:28 -08004011 qp->queue_id, qp->entry_count, qp->entry_size,
James Smart32517fc2019-01-28 11:14:33 -08004012 qp->host_index, qp->notify_interval,
4013 qp->max_proc_limit, qp->chann);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004014 len += scnprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len,
4015 "\n");
James Smart07bcd982017-02-12 13:52:28 -08004016
4017 return len;
4018}
4019
James Smartb76f2dc2011-07-22 18:37:42 -04004020/**
James Smart2a622bf2011-02-16 12:40:06 -05004021 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
4022 * @file: The file pointer to read from.
4023 * @buf: The buffer to copy the data to.
4024 * @nbytes: The number of bytes to read.
4025 * @ppos: The position in the file to start reading from.
4026 *
4027 * Description:
4028 * This routine reads data from the @phba SLI4 PCI function queue information,
4029 * and copies to user @buf.
James Smart07bcd982017-02-12 13:52:28 -08004030 * This routine only returns 1 EQs worth of information. It remembers the last
4031 * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will
4032 * retrieve all EQs allocated for the phba.
James Smart2a622bf2011-02-16 12:40:06 -05004033 *
4034 * Returns:
4035 * This function returns the amount of data that was read (this could be less
4036 * than @nbytes if the end of the file was reached) or a negative error value.
4037 **/
4038static ssize_t
4039lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
4040 loff_t *ppos)
4041{
4042 struct lpfc_debug *debug = file->private_data;
4043 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
James Smart2a622bf2011-02-16 12:40:06 -05004044 char *pbuffer;
James Smart07bcd982017-02-12 13:52:28 -08004045 int max_cnt, rc, x, len = 0;
James Smartc85a65a2012-08-03 12:37:00 -04004046 struct lpfc_queue *qp = NULL;
4047
James Smart2a622bf2011-02-16 12:40:06 -05004048 if (!debug->buffer)
4049 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
4050 if (!debug->buffer)
4051 return 0;
4052 pbuffer = debug->buffer;
James Smart07bcd982017-02-12 13:52:28 -08004053 max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256;
James Smart2a622bf2011-02-16 12:40:06 -05004054
4055 if (*ppos)
4056 return 0;
4057
James Smartc85a65a2012-08-03 12:37:00 -04004058 spin_lock_irq(&phba->hbalock);
James Smart2a622bf2011-02-16 12:40:06 -05004059
James Smartc85a65a2012-08-03 12:37:00 -04004060 /* Fast-path event queue */
James Smartcdb42be2019-01-28 11:14:21 -08004061 if (phba->sli4_hba.hdwq && phba->cfg_hdw_queue) {
James Smart2a622bf2011-02-16 12:40:06 -05004062
James Smart07bcd982017-02-12 13:52:28 -08004063 x = phba->lpfc_idiag_last_eq;
James Smart07bcd982017-02-12 13:52:28 -08004064 phba->lpfc_idiag_last_eq++;
James Smartcdb42be2019-01-28 11:14:21 -08004065 if (phba->lpfc_idiag_last_eq >= phba->cfg_hdw_queue)
James Smart7370d102019-01-28 11:14:20 -08004066 phba->lpfc_idiag_last_eq = 0;
James Smart2a622bf2011-02-16 12:40:06 -05004067
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004068 len += scnprintf(pbuffer + len,
4069 LPFC_QUE_INFO_GET_BUF_SIZE - len,
4070 "HDWQ %d out of %d HBA HDWQs\n",
4071 x, phba->cfg_hdw_queue);
James Smart07bcd982017-02-12 13:52:28 -08004072
4073 /* Fast-path EQ */
James Smartcdb42be2019-01-28 11:14:21 -08004074 qp = phba->sli4_hba.hdwq[x].hba_eq;
James Smart1ba981f2014-02-20 09:56:45 -05004075 if (!qp)
4076 goto out;
4077
James Smart07bcd982017-02-12 13:52:28 -08004078 len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len);
James Smart1ba981f2014-02-20 09:56:45 -05004079
4080 /* Reset max counter */
4081 qp->EQ_max_eqe = 0;
4082
James Smart07bcd982017-02-12 13:52:28 -08004083 if (len >= max_cnt)
4084 goto too_big;
4085
James Smart895427b2017-02-12 13:52:30 -08004086 /* will dump both fcp and nvme cqs/wqs for the eq */
James Smart07bcd982017-02-12 13:52:28 -08004087 rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len,
James Smart2d7dbc42017-02-12 13:52:35 -08004088 max_cnt, x, qp->queue_id);
James Smart07bcd982017-02-12 13:52:28 -08004089 if (rc)
4090 goto too_big;
4091
4092 /* Only EQ 0 has slow path CQs configured */
4093 if (x)
4094 goto out;
4095
4096 /* Slow-path mailbox CQ */
4097 qp = phba->sli4_hba.mbx_cq;
4098 len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len);
4099 if (len >= max_cnt)
4100 goto too_big;
4101
4102 /* Slow-path MBOX MQ */
4103 qp = phba->sli4_hba.mbx_wq;
4104 len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len);
4105 if (len >= max_cnt)
4106 goto too_big;
4107
4108 /* Slow-path ELS response CQ */
4109 qp = phba->sli4_hba.els_cq;
4110 len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len);
4111 /* Reset max counter */
4112 if (qp)
4113 qp->CQ_max_cqe = 0;
4114 if (len >= max_cnt)
4115 goto too_big;
4116
4117 /* Slow-path ELS WQ */
4118 qp = phba->sli4_hba.els_wq;
4119 len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len);
4120 if (len >= max_cnt)
4121 goto too_big;
4122
James Smart07d494f2017-11-20 16:00:35 -08004123 qp = phba->sli4_hba.hdr_rq;
4124 len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq,
4125 "ELS RQpair", pbuffer, len);
4126 if (len >= max_cnt)
4127 goto too_big;
4128
James Smart895427b2017-02-12 13:52:30 -08004129 /* Slow-path NVME LS response CQ */
4130 qp = phba->sli4_hba.nvmels_cq;
4131 len = __lpfc_idiag_print_cq(qp, "NVME LS",
4132 pbuffer, len);
4133 /* Reset max counter */
4134 if (qp)
4135 qp->CQ_max_cqe = 0;
4136 if (len >= max_cnt)
4137 goto too_big;
4138
4139 /* Slow-path NVME LS WQ */
4140 qp = phba->sli4_hba.nvmels_wq;
4141 len = __lpfc_idiag_print_wq(qp, "NVME LS",
4142 pbuffer, len);
4143 if (len >= max_cnt)
4144 goto too_big;
4145
James Smart07bcd982017-02-12 13:52:28 -08004146 goto out;
4147 }
4148
James Smartc85a65a2012-08-03 12:37:00 -04004149 spin_unlock_irq(&phba->hbalock);
4150 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4151
4152too_big:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004153 len += scnprintf(pbuffer + len,
James Smart07bcd982017-02-12 13:52:28 -08004154 LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n");
4155out:
James Smartc85a65a2012-08-03 12:37:00 -04004156 spin_unlock_irq(&phba->hbalock);
James Smart2a622bf2011-02-16 12:40:06 -05004157 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4158}
4159
James Smart86a80842011-04-16 11:03:04 -04004160/**
4161 * lpfc_idiag_que_param_check - queue access command parameter sanity check
4162 * @q: The pointer to queue structure.
4163 * @index: The index into a queue entry.
4164 * @count: The number of queue entries to access.
4165 *
4166 * Description:
4167 * The routine performs sanity check on device queue access method commands.
4168 *
4169 * Returns:
4170 * This function returns -EINVAL when fails the sanity check, otherwise, it
4171 * returns 0.
4172 **/
4173static int
4174lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
4175{
4176 /* Only support single entry read or browsing */
4177 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
4178 return -EINVAL;
4179 if (index > q->entry_count - 1)
4180 return -EINVAL;
4181 return 0;
4182}
4183
4184/**
4185 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
4186 * @pbuffer: The pointer to buffer to copy the read data into.
Lee Jonese61e0742020-11-02 14:23:46 +00004187 * @len: Length of the buffer.
James Smart86a80842011-04-16 11:03:04 -04004188 * @pque: The pointer to the queue to be read.
4189 * @index: The index into the queue entry.
4190 *
4191 * Description:
4192 * This routine reads out a single entry from the given queue's index location
4193 * and copies it into the buffer provided.
4194 *
4195 * Returns:
4196 * This function returns 0 when it fails, otherwise, it returns the length of
4197 * the data read into the buffer provided.
4198 **/
4199static int
4200lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
4201 uint32_t index)
4202{
4203 int offset, esize;
4204 uint32_t *pentry;
4205
4206 if (!pbuffer || !pque)
4207 return 0;
4208
4209 esize = pque->entry_size;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004210 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04004211 "QE-INDEX[%04d]:\n", index);
4212
4213 offset = 0;
James Smart9afbee32019-03-12 16:30:28 -07004214 pentry = lpfc_sli4_qe(pque, index);
James Smart86a80842011-04-16 11:03:04 -04004215 while (esize > 0) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004216 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04004217 "%08x ", *pentry);
4218 pentry++;
4219 offset += sizeof(uint32_t);
4220 esize -= sizeof(uint32_t);
4221 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004222 len += scnprintf(pbuffer+len,
James Smart86a80842011-04-16 11:03:04 -04004223 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
4224 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004225 len += scnprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
James Smart86a80842011-04-16 11:03:04 -04004226
4227 return len;
4228}
4229
4230/**
4231 * lpfc_idiag_queacc_read - idiag debugfs read port queue
4232 * @file: The file pointer to read from.
4233 * @buf: The buffer to copy the data to.
4234 * @nbytes: The number of bytes to read.
4235 * @ppos: The position in the file to start reading from.
4236 *
4237 * Description:
4238 * This routine reads data from the @phba device queue memory according to the
4239 * idiag command, and copies to user @buf. Depending on the queue dump read
4240 * command setup, it does either a single queue entry read or browing through
4241 * all entries of the queue.
4242 *
4243 * Returns:
4244 * This function returns the amount of data that was read (this could be less
4245 * than @nbytes if the end of the file was reached) or a negative error value.
4246 **/
4247static ssize_t
4248lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
4249 loff_t *ppos)
4250{
4251 struct lpfc_debug *debug = file->private_data;
4252 uint32_t last_index, index, count;
4253 struct lpfc_queue *pque = NULL;
4254 char *pbuffer;
4255 int len = 0;
4256
4257 /* This is a user read operation */
4258 debug->op = LPFC_IDIAG_OP_RD;
4259
4260 if (!debug->buffer)
4261 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
4262 if (!debug->buffer)
4263 return 0;
4264 pbuffer = debug->buffer;
4265
4266 if (*ppos)
4267 return 0;
4268
4269 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
James Smartb76f2dc2011-07-22 18:37:42 -04004270 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
4271 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
James Smart86a80842011-04-16 11:03:04 -04004272 pque = (struct lpfc_queue *)idiag.ptr_private;
4273 } else
4274 return 0;
4275
4276 /* Browse the queue starting from index */
4277 if (count == LPFC_QUE_ACC_BROWSE)
4278 goto que_browse;
4279
4280 /* Read a single entry from the queue */
4281 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
4282
4283 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4284
4285que_browse:
4286
4287 /* Browse all entries from the queue */
4288 last_index = idiag.offset.last_rd;
4289 index = last_index;
4290
4291 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
4292 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
4293 index++;
4294 if (index > pque->entry_count - 1)
4295 break;
4296 }
4297
4298 /* Set up the offset for next portion of pci cfg read */
4299 if (index > pque->entry_count - 1)
4300 index = 0;
4301 idiag.offset.last_rd = index;
4302
4303 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4304}
4305
4306/**
4307 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
4308 * @file: The file pointer to read from.
4309 * @buf: The buffer to copy the user data from.
4310 * @nbytes: The number of bytes to get.
4311 * @ppos: The position in the file to start reading from.
4312 *
4313 * This routine get the debugfs idiag command struct from user space and then
4314 * perform the syntax check for port queue read (dump) or write (set) command
4315 * accordingly. In the case of port queue read command, it sets up the command
4316 * in the idiag command struct for the following debugfs read operation. In
4317 * the case of port queue write operation, it executes the write operation
4318 * into the port queue entry accordingly.
4319 *
4320 * It returns the @nbytges passing in from debugfs user space when successful.
4321 * In case of error conditions, it returns proper error code back to the user
4322 * space.
4323 **/
4324static ssize_t
4325lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
4326 size_t nbytes, loff_t *ppos)
4327{
4328 struct lpfc_debug *debug = file->private_data;
4329 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4330 uint32_t qidx, quetp, queid, index, count, offset, value;
4331 uint32_t *pentry;
James Smart895427b2017-02-12 13:52:30 -08004332 struct lpfc_queue *pque, *qp;
James Smart86a80842011-04-16 11:03:04 -04004333 int rc;
4334
4335 /* This is a user write operation */
4336 debug->op = LPFC_IDIAG_OP_WR;
4337
4338 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4339 if (rc < 0)
4340 return rc;
4341
4342 /* Get and sanity check on command feilds */
James Smartb76f2dc2011-07-22 18:37:42 -04004343 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
4344 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
4345 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
4346 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
4347 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
4348 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04004349
4350 /* Sanity check on command line arguments */
4351 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
4352 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
4353 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
4354 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
4355 goto error_out;
4356 if (count != 1)
4357 goto error_out;
4358 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4359 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
4360 goto error_out;
4361 } else
4362 goto error_out;
4363
4364 switch (quetp) {
4365 case LPFC_IDIAG_EQ:
James Smart67d12732012-08-03 12:36:13 -04004366 /* HBA event queue */
James Smartcdb42be2019-01-28 11:14:21 -08004367 if (phba->sli4_hba.hdwq) {
4368 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
4369 qp = phba->sli4_hba.hdwq[qidx].hba_eq;
James Smart895427b2017-02-12 13:52:30 -08004370 if (qp && qp->queue_id == queid) {
James Smart2e90f4b2011-12-13 13:22:37 -05004371 /* Sanity check */
James Smart895427b2017-02-12 13:52:30 -08004372 rc = lpfc_idiag_que_param_check(qp,
James Smart86a80842011-04-16 11:03:04 -04004373 index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05004374 if (rc)
4375 goto error_out;
James Smart895427b2017-02-12 13:52:30 -08004376 idiag.ptr_private = qp;
James Smart2e90f4b2011-12-13 13:22:37 -05004377 goto pass_check;
4378 }
James Smart86a80842011-04-16 11:03:04 -04004379 }
4380 }
4381 goto error_out;
Tom Rix170b7d22020-10-19 07:23:33 -07004382
James Smart86a80842011-04-16 11:03:04 -04004383 case LPFC_IDIAG_CQ:
4384 /* MBX complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004385 if (phba->sli4_hba.mbx_cq &&
4386 phba->sli4_hba.mbx_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004387 /* Sanity check */
4388 rc = lpfc_idiag_que_param_check(
4389 phba->sli4_hba.mbx_cq, index, count);
4390 if (rc)
4391 goto error_out;
4392 idiag.ptr_private = phba->sli4_hba.mbx_cq;
4393 goto pass_check;
4394 }
4395 /* ELS complete queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004396 if (phba->sli4_hba.els_cq &&
4397 phba->sli4_hba.els_cq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004398 /* Sanity check */
4399 rc = lpfc_idiag_que_param_check(
4400 phba->sli4_hba.els_cq, index, count);
4401 if (rc)
4402 goto error_out;
4403 idiag.ptr_private = phba->sli4_hba.els_cq;
4404 goto pass_check;
4405 }
James Smart895427b2017-02-12 13:52:30 -08004406 /* NVME LS complete queue */
4407 if (phba->sli4_hba.nvmels_cq &&
4408 phba->sli4_hba.nvmels_cq->queue_id == queid) {
4409 /* Sanity check */
4410 rc = lpfc_idiag_que_param_check(
4411 phba->sli4_hba.nvmels_cq, index, count);
4412 if (rc)
4413 goto error_out;
4414 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
4415 goto pass_check;
4416 }
James Smart86a80842011-04-16 11:03:04 -04004417 /* FCP complete queue */
James Smartcdb42be2019-01-28 11:14:21 -08004418 if (phba->sli4_hba.hdwq) {
4419 for (qidx = 0; qidx < phba->cfg_hdw_queue;
James Smart895427b2017-02-12 13:52:30 -08004420 qidx++) {
James Smartc00f62e2019-08-14 16:57:11 -07004421 qp = phba->sli4_hba.hdwq[qidx].io_cq;
James Smart895427b2017-02-12 13:52:30 -08004422 if (qp && qp->queue_id == queid) {
James Smart2e90f4b2011-12-13 13:22:37 -05004423 /* Sanity check */
4424 rc = lpfc_idiag_que_param_check(
James Smart895427b2017-02-12 13:52:30 -08004425 qp, index, count);
James Smart2e90f4b2011-12-13 13:22:37 -05004426 if (rc)
4427 goto error_out;
James Smart895427b2017-02-12 13:52:30 -08004428 idiag.ptr_private = qp;
James Smart2e90f4b2011-12-13 13:22:37 -05004429 goto pass_check;
4430 }
James Smart895427b2017-02-12 13:52:30 -08004431 }
James Smart2e90f4b2011-12-13 13:22:37 -05004432 }
James Smart86a80842011-04-16 11:03:04 -04004433 goto error_out;
Tom Rix170b7d22020-10-19 07:23:33 -07004434
James Smart86a80842011-04-16 11:03:04 -04004435 case LPFC_IDIAG_MQ:
4436 /* MBX work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004437 if (phba->sli4_hba.mbx_wq &&
4438 phba->sli4_hba.mbx_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004439 /* Sanity check */
4440 rc = lpfc_idiag_que_param_check(
4441 phba->sli4_hba.mbx_wq, index, count);
4442 if (rc)
4443 goto error_out;
4444 idiag.ptr_private = phba->sli4_hba.mbx_wq;
4445 goto pass_check;
4446 }
James Smart2e90f4b2011-12-13 13:22:37 -05004447 goto error_out;
Tom Rix170b7d22020-10-19 07:23:33 -07004448
James Smart86a80842011-04-16 11:03:04 -04004449 case LPFC_IDIAG_WQ:
4450 /* ELS work queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004451 if (phba->sli4_hba.els_wq &&
4452 phba->sli4_hba.els_wq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004453 /* Sanity check */
4454 rc = lpfc_idiag_que_param_check(
4455 phba->sli4_hba.els_wq, index, count);
4456 if (rc)
4457 goto error_out;
4458 idiag.ptr_private = phba->sli4_hba.els_wq;
4459 goto pass_check;
4460 }
James Smart895427b2017-02-12 13:52:30 -08004461 /* NVME LS work queue */
4462 if (phba->sli4_hba.nvmels_wq &&
4463 phba->sli4_hba.nvmels_wq->queue_id == queid) {
4464 /* Sanity check */
4465 rc = lpfc_idiag_que_param_check(
4466 phba->sli4_hba.nvmels_wq, index, count);
4467 if (rc)
4468 goto error_out;
4469 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
4470 goto pass_check;
4471 }
James Smartcdb42be2019-01-28 11:14:21 -08004472
4473 if (phba->sli4_hba.hdwq) {
4474 /* FCP/SCSI work queue */
4475 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
James Smartc00f62e2019-08-14 16:57:11 -07004476 qp = phba->sli4_hba.hdwq[qidx].io_wq;
James Smart895427b2017-02-12 13:52:30 -08004477 if (qp && qp->queue_id == queid) {
4478 /* Sanity check */
4479 rc = lpfc_idiag_que_param_check(
4480 qp, index, count);
4481 if (rc)
4482 goto error_out;
4483 idiag.ptr_private = qp;
James Smart2e90f4b2011-12-13 13:22:37 -05004484 goto pass_check;
4485 }
James Smart86a80842011-04-16 11:03:04 -04004486 }
4487 }
4488 goto error_out;
Tom Rix170b7d22020-10-19 07:23:33 -07004489
James Smart86a80842011-04-16 11:03:04 -04004490 case LPFC_IDIAG_RQ:
4491 /* HDR queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004492 if (phba->sli4_hba.hdr_rq &&
4493 phba->sli4_hba.hdr_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004494 /* Sanity check */
4495 rc = lpfc_idiag_que_param_check(
4496 phba->sli4_hba.hdr_rq, index, count);
4497 if (rc)
4498 goto error_out;
4499 idiag.ptr_private = phba->sli4_hba.hdr_rq;
4500 goto pass_check;
4501 }
4502 /* DAT queue */
James Smart2e90f4b2011-12-13 13:22:37 -05004503 if (phba->sli4_hba.dat_rq &&
4504 phba->sli4_hba.dat_rq->queue_id == queid) {
James Smart86a80842011-04-16 11:03:04 -04004505 /* Sanity check */
4506 rc = lpfc_idiag_que_param_check(
4507 phba->sli4_hba.dat_rq, index, count);
4508 if (rc)
4509 goto error_out;
4510 idiag.ptr_private = phba->sli4_hba.dat_rq;
4511 goto pass_check;
4512 }
4513 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04004514 default:
4515 goto error_out;
James Smart86a80842011-04-16 11:03:04 -04004516 }
4517
4518pass_check:
4519
4520 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
4521 if (count == LPFC_QUE_ACC_BROWSE)
4522 idiag.offset.last_rd = index;
4523 }
4524
4525 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
4526 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
4527 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
4528 /* Additional sanity checks on write operation */
4529 pque = (struct lpfc_queue *)idiag.ptr_private;
4530 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
4531 goto error_out;
James Smart9afbee32019-03-12 16:30:28 -07004532 pentry = lpfc_sli4_qe(pque, index);
James Smart86a80842011-04-16 11:03:04 -04004533 pentry += offset;
4534 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
4535 *pentry = value;
4536 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
4537 *pentry |= value;
4538 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
4539 *pentry &= ~value;
4540 }
4541 return nbytes;
4542
4543error_out:
4544 /* Clean out command structure on command error out */
4545 memset(&idiag, 0, sizeof(idiag));
4546 return -EINVAL;
4547}
4548
4549/**
4550 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
4551 * @phba: The pointer to hba structure.
4552 * @pbuffer: The pointer to the buffer to copy the data to.
Matteo Croce92684bf2019-01-04 22:38:54 +01004553 * @len: The length of bytes to copied.
James Smart86a80842011-04-16 11:03:04 -04004554 * @drbregid: The id to doorbell registers.
4555 *
4556 * Description:
4557 * This routine reads a doorbell register and copies its content to the
4558 * user buffer pointed to by @pbuffer.
4559 *
4560 * Returns:
4561 * This function returns the amount of data that was copied into @pbuffer.
4562 **/
4563static int
4564lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4565 int len, uint32_t drbregid)
4566{
4567
4568 if (!pbuffer)
4569 return 0;
4570
4571 switch (drbregid) {
James Smart9dd35422018-02-22 08:18:41 -08004572 case LPFC_DRB_EQ:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004573 len += scnprintf(pbuffer + len, LPFC_DRB_ACC_BUF_SIZE-len,
James Smart9dd35422018-02-22 08:18:41 -08004574 "EQ-DRB-REG: 0x%08x\n",
4575 readl(phba->sli4_hba.EQDBregaddr));
4576 break;
4577 case LPFC_DRB_CQ:
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 "CQ-DRB-REG: 0x%08x\n",
4580 readl(phba->sli4_hba.CQDBregaddr));
James Smart86a80842011-04-16 11:03:04 -04004581 break;
4582 case LPFC_DRB_MQ:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004583 len += scnprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
James Smart86a80842011-04-16 11:03:04 -04004584 "MQ-DRB-REG: 0x%08x\n",
4585 readl(phba->sli4_hba.MQDBregaddr));
4586 break;
4587 case LPFC_DRB_WQ:
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 "WQ-DRB-REG: 0x%08x\n",
4590 readl(phba->sli4_hba.WQDBregaddr));
4591 break;
4592 case LPFC_DRB_RQ:
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 "RQ-DRB-REG: 0x%08x\n",
4595 readl(phba->sli4_hba.RQDBregaddr));
4596 break;
4597 default:
4598 break;
4599 }
4600
4601 return len;
4602}
4603
4604/**
4605 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
4606 * @file: The file pointer to read from.
4607 * @buf: The buffer to copy the data to.
4608 * @nbytes: The number of bytes to read.
4609 * @ppos: The position in the file to start reading from.
4610 *
4611 * Description:
4612 * This routine reads data from the @phba device doorbell register according
4613 * to the idiag command, and copies to user @buf. Depending on the doorbell
4614 * register read command setup, it does either a single doorbell register
4615 * read or dump all doorbell registers.
4616 *
4617 * Returns:
4618 * This function returns the amount of data that was read (this could be less
4619 * than @nbytes if the end of the file was reached) or a negative error value.
4620 **/
4621static ssize_t
4622lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
4623 loff_t *ppos)
4624{
4625 struct lpfc_debug *debug = file->private_data;
4626 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4627 uint32_t drb_reg_id, i;
4628 char *pbuffer;
4629 int len = 0;
4630
4631 /* This is a user read operation */
4632 debug->op = LPFC_IDIAG_OP_RD;
4633
4634 if (!debug->buffer)
4635 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
4636 if (!debug->buffer)
4637 return 0;
4638 pbuffer = debug->buffer;
4639
4640 if (*ppos)
4641 return 0;
4642
4643 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
James Smartb76f2dc2011-07-22 18:37:42 -04004644 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
James Smart86a80842011-04-16 11:03:04 -04004645 else
4646 return 0;
4647
4648 if (drb_reg_id == LPFC_DRB_ACC_ALL)
4649 for (i = 1; i <= LPFC_DRB_MAX; i++)
4650 len = lpfc_idiag_drbacc_read_reg(phba,
4651 pbuffer, len, i);
4652 else
4653 len = lpfc_idiag_drbacc_read_reg(phba,
4654 pbuffer, len, drb_reg_id);
4655
4656 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4657}
4658
4659/**
4660 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
4661 * @file: The file pointer to read from.
4662 * @buf: The buffer to copy the user data from.
4663 * @nbytes: The number of bytes to get.
4664 * @ppos: The position in the file to start reading from.
4665 *
4666 * This routine get the debugfs idiag command struct from user space and then
4667 * perform the syntax check for port doorbell register read (dump) or write
4668 * (set) command accordingly. In the case of port queue read command, it sets
4669 * up the command in the idiag command struct for the following debugfs read
4670 * operation. In the case of port doorbell register write operation, it
4671 * executes the write operation into the port doorbell register accordingly.
4672 *
4673 * It returns the @nbytges passing in from debugfs user space when successful.
4674 * In case of error conditions, it returns proper error code back to the user
4675 * space.
4676 **/
4677static ssize_t
4678lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
4679 size_t nbytes, loff_t *ppos)
4680{
4681 struct lpfc_debug *debug = file->private_data;
4682 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
James Smartb76f2dc2011-07-22 18:37:42 -04004683 uint32_t drb_reg_id, value, reg_val = 0;
James Smart86a80842011-04-16 11:03:04 -04004684 void __iomem *drb_reg;
4685 int rc;
4686
4687 /* This is a user write operation */
4688 debug->op = LPFC_IDIAG_OP_WR;
4689
4690 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4691 if (rc < 0)
4692 return rc;
4693
4694 /* Sanity check on command line arguments */
James Smartb76f2dc2011-07-22 18:37:42 -04004695 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
4696 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
James Smart86a80842011-04-16 11:03:04 -04004697
4698 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4699 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4700 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4701 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
4702 goto error_out;
4703 if (drb_reg_id > LPFC_DRB_MAX)
4704 goto error_out;
4705 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
4706 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
4707 goto error_out;
4708 if ((drb_reg_id > LPFC_DRB_MAX) &&
4709 (drb_reg_id != LPFC_DRB_ACC_ALL))
4710 goto error_out;
4711 } else
4712 goto error_out;
4713
4714 /* Perform the write access operation */
4715 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
4716 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
4717 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4718 switch (drb_reg_id) {
James Smart9dd35422018-02-22 08:18:41 -08004719 case LPFC_DRB_EQ:
4720 drb_reg = phba->sli4_hba.EQDBregaddr;
4721 break;
4722 case LPFC_DRB_CQ:
4723 drb_reg = phba->sli4_hba.CQDBregaddr;
James Smart86a80842011-04-16 11:03:04 -04004724 break;
4725 case LPFC_DRB_MQ:
4726 drb_reg = phba->sli4_hba.MQDBregaddr;
4727 break;
4728 case LPFC_DRB_WQ:
4729 drb_reg = phba->sli4_hba.WQDBregaddr;
4730 break;
4731 case LPFC_DRB_RQ:
4732 drb_reg = phba->sli4_hba.RQDBregaddr;
4733 break;
4734 default:
4735 goto error_out;
4736 }
4737
4738 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
4739 reg_val = value;
4740 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
4741 reg_val = readl(drb_reg);
4742 reg_val |= value;
4743 }
4744 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
4745 reg_val = readl(drb_reg);
4746 reg_val &= ~value;
4747 }
4748 writel(reg_val, drb_reg);
4749 readl(drb_reg); /* flush */
4750 }
4751 return nbytes;
4752
4753error_out:
4754 /* Clean out command structure on command error out */
4755 memset(&idiag, 0, sizeof(idiag));
4756 return -EINVAL;
4757}
4758
James Smartb76f2dc2011-07-22 18:37:42 -04004759/**
4760 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
4761 * @phba: The pointer to hba structure.
4762 * @pbuffer: The pointer to the buffer to copy the data to.
Matteo Croce92684bf2019-01-04 22:38:54 +01004763 * @len: The length of bytes to copied.
Lee Jonese61e0742020-11-02 14:23:46 +00004764 * @ctlregid: The id to doorbell registers.
James Smartb76f2dc2011-07-22 18:37:42 -04004765 *
4766 * Description:
4767 * This routine reads a control register and copies its content to the
4768 * user buffer pointed to by @pbuffer.
4769 *
4770 * Returns:
4771 * This function returns the amount of data that was copied into @pbuffer.
4772 **/
4773static int
4774lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
4775 int len, uint32_t ctlregid)
4776{
4777
4778 if (!pbuffer)
4779 return 0;
4780
4781 switch (ctlregid) {
4782 case LPFC_CTL_PORT_SEM:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004783 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004784 "Port SemReg: 0x%08x\n",
4785 readl(phba->sli4_hba.conf_regs_memmap_p +
4786 LPFC_CTL_PORT_SEM_OFFSET));
4787 break;
4788 case LPFC_CTL_PORT_STA:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004789 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004790 "Port StaReg: 0x%08x\n",
4791 readl(phba->sli4_hba.conf_regs_memmap_p +
4792 LPFC_CTL_PORT_STA_OFFSET));
4793 break;
4794 case LPFC_CTL_PORT_CTL:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004795 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004796 "Port CtlReg: 0x%08x\n",
4797 readl(phba->sli4_hba.conf_regs_memmap_p +
4798 LPFC_CTL_PORT_CTL_OFFSET));
4799 break;
4800 case LPFC_CTL_PORT_ER1:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004801 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004802 "Port Er1Reg: 0x%08x\n",
4803 readl(phba->sli4_hba.conf_regs_memmap_p +
4804 LPFC_CTL_PORT_ER1_OFFSET));
4805 break;
4806 case LPFC_CTL_PORT_ER2:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004807 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004808 "Port Er2Reg: 0x%08x\n",
4809 readl(phba->sli4_hba.conf_regs_memmap_p +
4810 LPFC_CTL_PORT_ER2_OFFSET));
4811 break;
4812 case LPFC_CTL_PDEV_CTL:
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07004813 len += scnprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04004814 "PDev CtlReg: 0x%08x\n",
4815 readl(phba->sli4_hba.conf_regs_memmap_p +
4816 LPFC_CTL_PDEV_CTL_OFFSET));
4817 break;
4818 default:
4819 break;
4820 }
4821 return len;
4822}
4823
4824/**
4825 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
4826 * @file: The file pointer to read from.
4827 * @buf: The buffer to copy the data to.
4828 * @nbytes: The number of bytes to read.
4829 * @ppos: The position in the file to start reading from.
4830 *
4831 * Description:
4832 * This routine reads data from the @phba port and device registers according
4833 * to the idiag command, and copies to user @buf.
4834 *
4835 * Returns:
4836 * This function returns the amount of data that was read (this could be less
4837 * than @nbytes if the end of the file was reached) or a negative error value.
4838 **/
4839static ssize_t
4840lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
4841 loff_t *ppos)
4842{
4843 struct lpfc_debug *debug = file->private_data;
4844 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4845 uint32_t ctl_reg_id, i;
4846 char *pbuffer;
4847 int len = 0;
4848
4849 /* This is a user read operation */
4850 debug->op = LPFC_IDIAG_OP_RD;
4851
4852 if (!debug->buffer)
4853 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
4854 if (!debug->buffer)
4855 return 0;
4856 pbuffer = debug->buffer;
4857
4858 if (*ppos)
4859 return 0;
4860
4861 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
4862 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4863 else
4864 return 0;
4865
4866 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
4867 for (i = 1; i <= LPFC_CTL_MAX; i++)
4868 len = lpfc_idiag_ctlacc_read_reg(phba,
4869 pbuffer, len, i);
4870 else
4871 len = lpfc_idiag_ctlacc_read_reg(phba,
4872 pbuffer, len, ctl_reg_id);
4873
4874 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
4875}
4876
4877/**
4878 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
4879 * @file: The file pointer to read from.
4880 * @buf: The buffer to copy the user data from.
4881 * @nbytes: The number of bytes to get.
4882 * @ppos: The position in the file to start reading from.
4883 *
4884 * This routine get the debugfs idiag command struct from user space and then
4885 * perform the syntax check for port and device control register read (dump)
4886 * or write (set) command accordingly.
4887 *
4888 * It returns the @nbytges passing in from debugfs user space when successful.
4889 * In case of error conditions, it returns proper error code back to the user
4890 * space.
4891 **/
4892static ssize_t
4893lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
4894 size_t nbytes, loff_t *ppos)
4895{
4896 struct lpfc_debug *debug = file->private_data;
4897 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
4898 uint32_t ctl_reg_id, value, reg_val = 0;
4899 void __iomem *ctl_reg;
4900 int rc;
4901
4902 /* This is a user write operation */
4903 debug->op = LPFC_IDIAG_OP_WR;
4904
4905 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
4906 if (rc < 0)
4907 return rc;
4908
4909 /* Sanity check on command line arguments */
4910 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
4911 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
4912
4913 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4914 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4915 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4916 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
4917 goto error_out;
4918 if (ctl_reg_id > LPFC_CTL_MAX)
4919 goto error_out;
4920 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
4921 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
4922 goto error_out;
4923 if ((ctl_reg_id > LPFC_CTL_MAX) &&
4924 (ctl_reg_id != LPFC_CTL_ACC_ALL))
4925 goto error_out;
4926 } else
4927 goto error_out;
4928
4929 /* Perform the write access operation */
4930 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
4931 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
4932 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4933 switch (ctl_reg_id) {
4934 case LPFC_CTL_PORT_SEM:
4935 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4936 LPFC_CTL_PORT_SEM_OFFSET;
4937 break;
4938 case LPFC_CTL_PORT_STA:
4939 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4940 LPFC_CTL_PORT_STA_OFFSET;
4941 break;
4942 case LPFC_CTL_PORT_CTL:
4943 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4944 LPFC_CTL_PORT_CTL_OFFSET;
4945 break;
4946 case LPFC_CTL_PORT_ER1:
4947 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4948 LPFC_CTL_PORT_ER1_OFFSET;
4949 break;
4950 case LPFC_CTL_PORT_ER2:
4951 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4952 LPFC_CTL_PORT_ER2_OFFSET;
4953 break;
4954 case LPFC_CTL_PDEV_CTL:
4955 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
4956 LPFC_CTL_PDEV_CTL_OFFSET;
4957 break;
4958 default:
4959 goto error_out;
4960 }
4961
4962 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
4963 reg_val = value;
4964 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
4965 reg_val = readl(ctl_reg);
4966 reg_val |= value;
4967 }
4968 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
4969 reg_val = readl(ctl_reg);
4970 reg_val &= ~value;
4971 }
4972 writel(reg_val, ctl_reg);
4973 readl(ctl_reg); /* flush */
4974 }
4975 return nbytes;
4976
4977error_out:
4978 /* Clean out command structure on command error out */
4979 memset(&idiag, 0, sizeof(idiag));
4980 return -EINVAL;
4981}
4982
4983/**
4984 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
4985 * @phba: Pointer to HBA context object.
4986 * @pbuffer: Pointer to data buffer.
4987 *
4988 * Description:
4989 * This routine gets the driver mailbox access debugfs setup information.
4990 *
4991 * Returns:
4992 * This function returns the amount of data that was read (this could be less
4993 * than @nbytes if the end of the file was reached) or a negative error value.
4994 **/
4995static int
4996lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
4997{
4998 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
4999 int len = 0;
5000
5001 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5002 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5003 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5004 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5005
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005006 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005007 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005008 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005009 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005010 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005011 "mbx_word_cnt: %04d\n", mbx_word_cnt);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005012 len += scnprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005013 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
5014
5015 return len;
5016}
5017
5018/**
5019 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
5020 * @file: The file pointer to read from.
5021 * @buf: The buffer to copy the data to.
5022 * @nbytes: The number of bytes to read.
5023 * @ppos: The position in the file to start reading from.
5024 *
5025 * Description:
5026 * This routine reads data from the @phba driver mailbox access debugfs setup
5027 * information.
5028 *
5029 * Returns:
5030 * This function returns the amount of data that was read (this could be less
5031 * than @nbytes if the end of the file was reached) or a negative error value.
5032 **/
5033static ssize_t
5034lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
5035 loff_t *ppos)
5036{
5037 struct lpfc_debug *debug = file->private_data;
5038 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5039 char *pbuffer;
5040 int len = 0;
5041
5042 /* This is a user read operation */
5043 debug->op = LPFC_IDIAG_OP_RD;
5044
5045 if (!debug->buffer)
5046 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
5047 if (!debug->buffer)
5048 return 0;
5049 pbuffer = debug->buffer;
5050
5051 if (*ppos)
5052 return 0;
5053
5054 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
5055 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
5056 return 0;
5057
5058 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
5059
5060 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
5061}
5062
5063/**
5064 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
5065 * @file: The file pointer to read from.
5066 * @buf: The buffer to copy the user data from.
5067 * @nbytes: The number of bytes to get.
5068 * @ppos: The position in the file to start reading from.
5069 *
5070 * This routine get the debugfs idiag command struct from user space and then
5071 * perform the syntax check for driver mailbox command (dump) and sets up the
5072 * necessary states in the idiag command struct accordingly.
5073 *
5074 * It returns the @nbytges passing in from debugfs user space when successful.
5075 * In case of error conditions, it returns proper error code back to the user
5076 * space.
5077 **/
5078static ssize_t
5079lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
5080 size_t nbytes, loff_t *ppos)
5081{
5082 struct lpfc_debug *debug = file->private_data;
5083 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
5084 int rc;
5085
5086 /* This is a user write operation */
5087 debug->op = LPFC_IDIAG_OP_WR;
5088
5089 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
5090 if (rc < 0)
5091 return rc;
5092
5093 /* Sanity check on command line arguments */
5094 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5095 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5096 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5097 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5098
5099 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
5100 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
5101 goto error_out;
5102 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
5103 (mbx_dump_map != LPFC_MBX_DMP_ALL))
5104 goto error_out;
5105 if (mbx_word_cnt > sizeof(MAILBOX_t))
5106 goto error_out;
5107 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
5108 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
5109 goto error_out;
5110 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
5111 (mbx_dump_map != LPFC_MBX_DMP_ALL))
5112 goto error_out;
5113 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
5114 goto error_out;
5115 if (mbx_mbox_cmd != 0x9b)
5116 goto error_out;
5117 } else
5118 goto error_out;
5119
5120 if (mbx_word_cnt == 0)
5121 goto error_out;
5122 if (rc != LPFC_MBX_DMP_ARG)
5123 goto error_out;
5124 if (mbx_mbox_cmd & ~0xff)
5125 goto error_out;
5126
5127 /* condition for stop mailbox dump */
5128 if (mbx_dump_cnt == 0)
5129 goto reset_out;
5130
5131 return nbytes;
5132
5133reset_out:
5134 /* Clean out command structure on command error out */
5135 memset(&idiag, 0, sizeof(idiag));
5136 return nbytes;
5137
5138error_out:
5139 /* Clean out command structure on command error out */
5140 memset(&idiag, 0, sizeof(idiag));
5141 return -EINVAL;
5142}
5143
5144/**
5145 * lpfc_idiag_extacc_avail_get - get the available extents information
5146 * @phba: pointer to lpfc hba data structure.
5147 * @pbuffer: pointer to internal buffer.
5148 * @len: length into the internal buffer data has been copied.
5149 *
5150 * Description:
5151 * This routine is to get the available extent information.
5152 *
5153 * Returns:
wengjianfeng89bbf552021-03-22 15:56:45 +08005154 * overall length of the data read into the internal buffer.
James Smartb76f2dc2011-07-22 18:37:42 -04005155 **/
5156static int
5157lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
5158{
5159 uint16_t ext_cnt, ext_size;
5160
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005161 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005162 "\nAvailable Extents Information:\n");
5163
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005164 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005165 "\tPort Available VPI extents: ");
5166 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
5167 &ext_cnt, &ext_size);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005168 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005169 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5170
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005171 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005172 "\tPort Available VFI extents: ");
5173 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
5174 &ext_cnt, &ext_size);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005175 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005176 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5177
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005178 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005179 "\tPort Available RPI extents: ");
5180 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
5181 &ext_cnt, &ext_size);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005182 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005183 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5184
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005185 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005186 "\tPort Available XRI extents: ");
5187 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
5188 &ext_cnt, &ext_size);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005189 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005190 "Count %3d, Size %3d\n", ext_cnt, ext_size);
5191
5192 return len;
5193}
5194
5195/**
5196 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
5197 * @phba: pointer to lpfc hba data structure.
5198 * @pbuffer: pointer to internal buffer.
5199 * @len: length into the internal buffer data has been copied.
5200 *
5201 * Description:
5202 * This routine is to get the allocated extent information.
5203 *
5204 * Returns:
wengjianfeng89bbf552021-03-22 15:56:45 +08005205 * overall length of the data read into the internal buffer.
James Smartb76f2dc2011-07-22 18:37:42 -04005206 **/
5207static int
5208lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
5209{
5210 uint16_t ext_cnt, ext_size;
5211 int rc;
5212
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005213 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005214 "\nAllocated Extents Information:\n");
5215
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005216 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005217 "\tHost Allocated VPI extents: ");
5218 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
5219 &ext_cnt, &ext_size);
5220 if (!rc)
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 "Port %d Extent %3d, Size %3d\n",
5223 phba->brd_no, ext_cnt, ext_size);
5224 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005225 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005226 "N/A\n");
5227
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005228 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005229 "\tHost Allocated VFI extents: ");
5230 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
5231 &ext_cnt, &ext_size);
5232 if (!rc)
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 "Port %d Extent %3d, Size %3d\n",
5235 phba->brd_no, ext_cnt, ext_size);
5236 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005237 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005238 "N/A\n");
5239
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005240 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005241 "\tHost Allocated RPI extents: ");
5242 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
5243 &ext_cnt, &ext_size);
5244 if (!rc)
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 "Port %d Extent %3d, Size %3d\n",
5247 phba->brd_no, ext_cnt, ext_size);
5248 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005249 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005250 "N/A\n");
5251
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005252 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005253 "\tHost Allocated XRI extents: ");
5254 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
5255 &ext_cnt, &ext_size);
5256 if (!rc)
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 "Port %d Extent %3d, Size %3d\n",
5259 phba->brd_no, ext_cnt, ext_size);
5260 else
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005261 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005262 "N/A\n");
5263
5264 return len;
5265}
5266
5267/**
5268 * lpfc_idiag_extacc_drivr_get - get driver extent information
5269 * @phba: pointer to lpfc hba data structure.
5270 * @pbuffer: pointer to internal buffer.
5271 * @len: length into the internal buffer data has been copied.
5272 *
5273 * Description:
5274 * This routine is to get the driver extent information.
5275 *
5276 * Returns:
wengjianfeng89bbf552021-03-22 15:56:45 +08005277 * overall length of the data read into the internal buffer.
James Smartb76f2dc2011-07-22 18:37:42 -04005278 **/
5279static int
5280lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
5281{
5282 struct lpfc_rsrc_blks *rsrc_blks;
5283 int index;
5284
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005285 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005286 "\nDriver Extents Information:\n");
5287
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005288 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005289 "\tVPI extents:\n");
5290 index = 0;
5291 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005292 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005293 "\t\tBlock %3d: Start %4d, Count %4d\n",
5294 index, rsrc_blks->rsrc_start,
5295 rsrc_blks->rsrc_size);
5296 index++;
5297 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005298 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005299 "\tVFI extents:\n");
5300 index = 0;
5301 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
5302 list) {
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 "\t\tBlock %3d: Start %4d, Count %4d\n",
5305 index, rsrc_blks->rsrc_start,
5306 rsrc_blks->rsrc_size);
5307 index++;
5308 }
5309
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005310 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005311 "\tRPI extents:\n");
5312 index = 0;
5313 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
5314 list) {
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 "\t\tBlock %3d: Start %4d, Count %4d\n",
5317 index, rsrc_blks->rsrc_start,
5318 rsrc_blks->rsrc_size);
5319 index++;
5320 }
5321
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005322 len += scnprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005323 "\tXRI extents:\n");
5324 index = 0;
5325 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
5326 list) {
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 "\t\tBlock %3d: Start %4d, Count %4d\n",
5329 index, rsrc_blks->rsrc_start,
5330 rsrc_blks->rsrc_size);
5331 index++;
5332 }
5333
5334 return len;
5335}
5336
5337/**
5338 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
5339 * @file: The file pointer to read from.
5340 * @buf: The buffer to copy the user data from.
5341 * @nbytes: The number of bytes to get.
5342 * @ppos: The position in the file to start reading from.
5343 *
5344 * This routine get the debugfs idiag command struct from user space and then
5345 * perform the syntax check for extent information access commands and sets
5346 * up the necessary states in the idiag command struct accordingly.
5347 *
5348 * It returns the @nbytges passing in from debugfs user space when successful.
5349 * In case of error conditions, it returns proper error code back to the user
5350 * space.
5351 **/
5352static ssize_t
5353lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
5354 size_t nbytes, loff_t *ppos)
5355{
5356 struct lpfc_debug *debug = file->private_data;
5357 uint32_t ext_map;
5358 int rc;
5359
5360 /* This is a user write operation */
5361 debug->op = LPFC_IDIAG_OP_WR;
5362
5363 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
5364 if (rc < 0)
5365 return rc;
5366
5367 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
5368
5369 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
5370 goto error_out;
5371 if (rc != LPFC_EXT_ACC_CMD_ARG)
5372 goto error_out;
5373 if (!(ext_map & LPFC_EXT_ACC_ALL))
5374 goto error_out;
5375
5376 return nbytes;
5377error_out:
5378 /* Clean out command structure on command error out */
5379 memset(&idiag, 0, sizeof(idiag));
5380 return -EINVAL;
5381}
5382
5383/**
5384 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
5385 * @file: The file pointer to read from.
5386 * @buf: The buffer to copy the data to.
5387 * @nbytes: The number of bytes to read.
5388 * @ppos: The position in the file to start reading from.
5389 *
5390 * Description:
5391 * This routine reads data from the proper extent information according to
5392 * the idiag command, and copies to user @buf.
5393 *
5394 * Returns:
5395 * This function returns the amount of data that was read (this could be less
5396 * than @nbytes if the end of the file was reached) or a negative error value.
5397 **/
5398static ssize_t
5399lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
5400 loff_t *ppos)
5401{
5402 struct lpfc_debug *debug = file->private_data;
5403 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5404 char *pbuffer;
5405 uint32_t ext_map;
5406 int len = 0;
5407
5408 /* This is a user read operation */
5409 debug->op = LPFC_IDIAG_OP_RD;
5410
5411 if (!debug->buffer)
5412 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
5413 if (!debug->buffer)
5414 return 0;
5415 pbuffer = debug->buffer;
5416 if (*ppos)
5417 return 0;
5418 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
5419 return 0;
5420
5421 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
5422 if (ext_map & LPFC_EXT_ACC_AVAIL)
5423 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
5424 if (ext_map & LPFC_EXT_ACC_ALLOC)
5425 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
5426 if (ext_map & LPFC_EXT_ACC_DRIVR)
5427 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
5428
5429 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
5430}
5431
James Smart9f778702021-08-16 09:28:57 -07005432static int
5433lpfc_cgn_buffer_open(struct inode *inode, struct file *file)
5434{
5435 struct lpfc_debug *debug;
5436 int rc = -ENOMEM;
5437
5438 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
5439 if (!debug)
5440 goto out;
5441
5442 debug->buffer = vmalloc(LPFC_CGN_BUF_SIZE);
5443 if (!debug->buffer) {
5444 kfree(debug);
5445 goto out;
5446 }
5447
5448 debug->i_private = inode->i_private;
5449 file->private_data = debug;
5450
5451 rc = 0;
5452out:
5453 return rc;
5454}
5455
5456static ssize_t
5457lpfc_cgn_buffer_read(struct file *file, char __user *buf, size_t nbytes,
5458 loff_t *ppos)
5459{
5460 struct lpfc_debug *debug = file->private_data;
5461 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5462 char *buffer = debug->buffer;
5463 uint32_t *ptr;
5464 int cnt, len = 0;
5465
5466 if (!phba->sli4_hba.pc_sli4_params.mi_ver || !phba->cgn_i) {
5467 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5468 "Congestion Mgmt is not supported\n");
5469 goto out;
5470 }
5471 ptr = (uint32_t *)phba->cgn_i->virt;
5472 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5473 "Congestion Buffer Header\n");
5474 /* Dump the first 32 bytes */
5475 cnt = 32;
5476 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5477 "000: %08x %08x %08x %08x %08x %08x %08x %08x\n",
5478 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
5479 *(ptr + 4), *(ptr + 5), *(ptr + 6), *(ptr + 7));
5480 ptr += 8;
5481 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5482 "Congestion Buffer Data\n");
5483 while (cnt < sizeof(struct lpfc_cgn_info)) {
5484 if (len > (LPFC_CGN_BUF_SIZE - LPFC_DEBUG_OUT_LINE_SZ)) {
5485 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5486 "Truncated . . .\n");
James Smart6014a242021-12-03 16:26:43 -08005487 goto out;
James Smart9f778702021-08-16 09:28:57 -07005488 }
5489 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5490 "%03x: %08x %08x %08x %08x "
5491 "%08x %08x %08x %08x\n",
5492 cnt, *ptr, *(ptr + 1), *(ptr + 2),
5493 *(ptr + 3), *(ptr + 4), *(ptr + 5),
5494 *(ptr + 6), *(ptr + 7));
5495 cnt += 32;
5496 ptr += 8;
5497 }
James Smart6014a242021-12-03 16:26:43 -08005498 if (len > (LPFC_CGN_BUF_SIZE - LPFC_DEBUG_OUT_LINE_SZ)) {
5499 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5500 "Truncated . . .\n");
5501 goto out;
5502 }
5503 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5504 "Parameter Data\n");
5505 ptr = (uint32_t *)&phba->cgn_p;
5506 len += scnprintf(buffer + len, LPFC_CGN_BUF_SIZE - len,
5507 "%08x %08x %08x %08x\n",
5508 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3));
James Smart9f778702021-08-16 09:28:57 -07005509out:
5510 return simple_read_from_buffer(buf, nbytes, ppos, buffer, len);
5511}
5512
5513static int
5514lpfc_cgn_buffer_release(struct inode *inode, struct file *file)
5515{
5516 struct lpfc_debug *debug = file->private_data;
5517
5518 vfree(debug->buffer);
5519 kfree(debug);
5520
5521 return 0;
5522}
5523
5524static int
5525lpfc_rx_monitor_open(struct inode *inode, struct file *file)
5526{
5527 struct lpfc_rx_monitor_debug *debug;
5528 int rc = -ENOMEM;
5529
5530 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
5531 if (!debug)
5532 goto out;
5533
5534 debug->buffer = vmalloc(MAX_DEBUGFS_RX_TABLE_SIZE);
5535 if (!debug->buffer) {
5536 kfree(debug);
5537 goto out;
5538 }
5539
5540 debug->i_private = inode->i_private;
5541 file->private_data = debug;
5542
5543 rc = 0;
5544out:
5545 return rc;
5546}
5547
5548static ssize_t
5549lpfc_rx_monitor_read(struct file *file, char __user *buf, size_t nbytes,
5550 loff_t *ppos)
5551{
5552 struct lpfc_rx_monitor_debug *debug = file->private_data;
5553 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
5554 char *buffer = debug->buffer;
5555 struct rxtable_entry *entry;
5556 int i, len = 0, head, tail, last, start;
5557
5558 head = atomic_read(&phba->rxtable_idx_head);
5559 while (head == LPFC_RXMONITOR_TABLE_IN_USE) {
5560 /* Table is getting updated */
5561 msleep(20);
5562 head = atomic_read(&phba->rxtable_idx_head);
5563 }
5564
5565 tail = atomic_xchg(&phba->rxtable_idx_tail, head);
5566 if (!phba->rxtable || head == tail) {
5567 len += scnprintf(buffer + len, MAX_DEBUGFS_RX_TABLE_SIZE - len,
5568 "Rxtable is empty\n");
5569 goto out;
5570 }
5571 last = (head > tail) ? head : LPFC_MAX_RXMONITOR_ENTRY;
5572 start = tail;
5573
5574 len += scnprintf(buffer + len, MAX_DEBUGFS_RX_TABLE_SIZE - len,
James Smarta6269f82021-12-03 16:26:41 -08005575 " MaxBPI Tot_Data_CMF Tot_Data_Cmd "
5576 "Tot_Data_Cmpl Lat(us) Avg_IO Max_IO "
5577 "Bsy IO_cnt Info BWutil(ms)\n");
James Smart9f778702021-08-16 09:28:57 -07005578get_table:
5579 for (i = start; i < last; i++) {
5580 entry = &phba->rxtable[i];
5581 len += scnprintf(buffer + len, MAX_DEBUGFS_RX_TABLE_SIZE - len,
James Smarta6269f82021-12-03 16:26:41 -08005582 "%3d:%12lld %12lld %12lld %12lld "
5583 "%7lldus %8lld %7lld "
5584 "%2d %4d %2d %2d(%2d)\n",
James Smart9f778702021-08-16 09:28:57 -07005585 i, entry->max_bytes_per_interval,
James Smarta6269f82021-12-03 16:26:41 -08005586 entry->cmf_bytes,
James Smart9f778702021-08-16 09:28:57 -07005587 entry->total_bytes,
5588 entry->rcv_bytes,
5589 entry->avg_io_latency,
5590 entry->avg_io_size,
5591 entry->max_read_cnt,
James Smarta6269f82021-12-03 16:26:41 -08005592 entry->cmf_busy,
James Smart9f778702021-08-16 09:28:57 -07005593 entry->io_cnt,
5594 entry->cmf_info,
5595 entry->timer_utilization,
5596 entry->timer_interval);
5597 }
5598
5599 if (head != last) {
5600 start = 0;
5601 last = head;
5602 goto get_table;
5603 }
5604out:
5605 return simple_read_from_buffer(buf, nbytes, ppos, buffer, len);
5606}
5607
5608static int
5609lpfc_rx_monitor_release(struct inode *inode, struct file *file)
5610{
5611 struct lpfc_rx_monitor_debug *debug = file->private_data;
5612
5613 vfree(debug->buffer);
5614 kfree(debug);
5615
5616 return 0;
5617}
5618
James Smart858c9f62007-06-17 19:56:39 -05005619#undef lpfc_debugfs_op_disc_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005620static const struct file_operations lpfc_debugfs_op_disc_trc = {
James Smart858c9f62007-06-17 19:56:39 -05005621 .owner = THIS_MODULE,
5622 .open = lpfc_debugfs_disc_trc_open,
5623 .llseek = lpfc_debugfs_lseek,
5624 .read = lpfc_debugfs_read,
5625 .release = lpfc_debugfs_release,
5626};
5627
5628#undef lpfc_debugfs_op_nodelist
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005629static const struct file_operations lpfc_debugfs_op_nodelist = {
James Smart858c9f62007-06-17 19:56:39 -05005630 .owner = THIS_MODULE,
5631 .open = lpfc_debugfs_nodelist_open,
5632 .llseek = lpfc_debugfs_lseek,
5633 .read = lpfc_debugfs_read,
5634 .release = lpfc_debugfs_release,
5635};
5636
James Smartc4908502019-01-28 11:14:28 -08005637#undef lpfc_debugfs_op_multixripools
5638static const struct file_operations lpfc_debugfs_op_multixripools = {
5639 .owner = THIS_MODULE,
5640 .open = lpfc_debugfs_multixripools_open,
5641 .llseek = lpfc_debugfs_lseek,
5642 .read = lpfc_debugfs_read,
5643 .write = lpfc_debugfs_multixripools_write,
5644 .release = lpfc_debugfs_release,
5645};
5646
James Smart78b2d852007-08-02 11:10:21 -04005647#undef lpfc_debugfs_op_hbqinfo
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005648static const struct file_operations lpfc_debugfs_op_hbqinfo = {
James Smart78b2d852007-08-02 11:10:21 -04005649 .owner = THIS_MODULE,
5650 .open = lpfc_debugfs_hbqinfo_open,
5651 .llseek = lpfc_debugfs_lseek,
5652 .read = lpfc_debugfs_read,
5653 .release = lpfc_debugfs_release,
5654};
5655
James Smart6a828b02019-01-28 11:14:31 -08005656#ifdef LPFC_HDWQ_LOCK_STAT
5657#undef lpfc_debugfs_op_lockstat
5658static const struct file_operations lpfc_debugfs_op_lockstat = {
James Smart5e5b5112019-01-28 11:14:22 -08005659 .owner = THIS_MODULE,
James Smart6a828b02019-01-28 11:14:31 -08005660 .open = lpfc_debugfs_lockstat_open,
James Smart5e5b5112019-01-28 11:14:22 -08005661 .llseek = lpfc_debugfs_lseek,
5662 .read = lpfc_debugfs_read,
James Smart6a828b02019-01-28 11:14:31 -08005663 .write = lpfc_debugfs_lockstat_write,
James Smart5e5b5112019-01-28 11:14:22 -08005664 .release = lpfc_debugfs_release,
5665};
James Smart6a828b02019-01-28 11:14:31 -08005666#endif
James Smart5e5b5112019-01-28 11:14:22 -08005667
James Smart95bfc6d2019-10-18 14:18:27 -07005668#undef lpfc_debugfs_ras_log
5669static const struct file_operations lpfc_debugfs_ras_log = {
5670 .owner = THIS_MODULE,
5671 .open = lpfc_debugfs_ras_log_open,
5672 .llseek = lpfc_debugfs_lseek,
5673 .read = lpfc_debugfs_read,
5674 .release = lpfc_debugfs_ras_log_release,
5675};
James Smart95bfc6d2019-10-18 14:18:27 -07005676
James Smartc95d6c62008-01-11 01:53:23 -05005677#undef lpfc_debugfs_op_dumpHBASlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005678static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
James Smarta58cbd52007-08-02 11:09:43 -04005679 .owner = THIS_MODULE,
James Smartc95d6c62008-01-11 01:53:23 -05005680 .open = lpfc_debugfs_dumpHBASlim_open,
5681 .llseek = lpfc_debugfs_lseek,
5682 .read = lpfc_debugfs_read,
5683 .release = lpfc_debugfs_release,
5684};
5685
5686#undef lpfc_debugfs_op_dumpHostSlim
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005687static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
James Smartc95d6c62008-01-11 01:53:23 -05005688 .owner = THIS_MODULE,
5689 .open = lpfc_debugfs_dumpHostSlim_open,
James Smarta58cbd52007-08-02 11:09:43 -04005690 .llseek = lpfc_debugfs_lseek,
5691 .read = lpfc_debugfs_read,
5692 .release = lpfc_debugfs_release,
5693};
5694
James Smartbd2cdd52017-02-12 13:52:33 -08005695#undef lpfc_debugfs_op_nvmestat
5696static const struct file_operations lpfc_debugfs_op_nvmestat = {
5697 .owner = THIS_MODULE,
5698 .open = lpfc_debugfs_nvmestat_open,
5699 .llseek = lpfc_debugfs_lseek,
5700 .read = lpfc_debugfs_read,
James Smart2b65e182017-02-12 13:52:38 -08005701 .write = lpfc_debugfs_nvmestat_write,
James Smartbd2cdd52017-02-12 13:52:33 -08005702 .release = lpfc_debugfs_release,
5703};
5704
James Smart4c47efc2019-01-28 11:14:25 -08005705#undef lpfc_debugfs_op_scsistat
5706static const struct file_operations lpfc_debugfs_op_scsistat = {
5707 .owner = THIS_MODULE,
5708 .open = lpfc_debugfs_scsistat_open,
5709 .llseek = lpfc_debugfs_lseek,
5710 .read = lpfc_debugfs_read,
5711 .write = lpfc_debugfs_scsistat_write,
5712 .release = lpfc_debugfs_release,
5713};
5714
James Smart2fcbc562020-03-22 11:13:02 -07005715#undef lpfc_debugfs_op_ioktime
5716static const struct file_operations lpfc_debugfs_op_ioktime = {
James Smartbd2cdd52017-02-12 13:52:33 -08005717 .owner = THIS_MODULE,
James Smart2fcbc562020-03-22 11:13:02 -07005718 .open = lpfc_debugfs_ioktime_open,
James Smartbd2cdd52017-02-12 13:52:33 -08005719 .llseek = lpfc_debugfs_lseek,
5720 .read = lpfc_debugfs_read,
James Smart2fcbc562020-03-22 11:13:02 -07005721 .write = lpfc_debugfs_ioktime_write,
James Smartbd2cdd52017-02-12 13:52:33 -08005722 .release = lpfc_debugfs_release,
5723};
5724
5725#undef lpfc_debugfs_op_nvmeio_trc
5726static const struct file_operations lpfc_debugfs_op_nvmeio_trc = {
5727 .owner = THIS_MODULE,
5728 .open = lpfc_debugfs_nvmeio_trc_open,
5729 .llseek = lpfc_debugfs_lseek,
5730 .read = lpfc_debugfs_read,
5731 .write = lpfc_debugfs_nvmeio_trc_write,
5732 .release = lpfc_debugfs_release,
5733};
5734
James Smart840eda92020-03-22 11:13:00 -07005735#undef lpfc_debugfs_op_hdwqstat
5736static const struct file_operations lpfc_debugfs_op_hdwqstat = {
James Smartbd2cdd52017-02-12 13:52:33 -08005737 .owner = THIS_MODULE,
James Smart840eda92020-03-22 11:13:00 -07005738 .open = lpfc_debugfs_hdwqstat_open,
James Smartbd2cdd52017-02-12 13:52:33 -08005739 .llseek = lpfc_debugfs_lseek,
5740 .read = lpfc_debugfs_read,
James Smart840eda92020-03-22 11:13:00 -07005741 .write = lpfc_debugfs_hdwqstat_write,
James Smartbd2cdd52017-02-12 13:52:33 -08005742 .release = lpfc_debugfs_release,
5743};
5744
James Smartf9bb2da2011-10-10 21:34:11 -04005745#undef lpfc_debugfs_op_dif_err
5746static const struct file_operations lpfc_debugfs_op_dif_err = {
5747 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -07005748 .open = simple_open,
James Smartf9bb2da2011-10-10 21:34:11 -04005749 .llseek = lpfc_debugfs_lseek,
5750 .read = lpfc_debugfs_dif_err_read,
5751 .write = lpfc_debugfs_dif_err_write,
5752 .release = lpfc_debugfs_dif_err_release,
5753};
5754
James Smarta58cbd52007-08-02 11:09:43 -04005755#undef lpfc_debugfs_op_slow_ring_trc
Jan Engelhardt71fa7422009-01-11 10:38:59 +01005756static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
James Smarta58cbd52007-08-02 11:09:43 -04005757 .owner = THIS_MODULE,
5758 .open = lpfc_debugfs_slow_ring_trc_open,
5759 .llseek = lpfc_debugfs_lseek,
5760 .read = lpfc_debugfs_read,
5761 .release = lpfc_debugfs_release,
5762};
5763
James Smart858c9f62007-06-17 19:56:39 -05005764static struct dentry *lpfc_debugfs_root = NULL;
5765static atomic_t lpfc_debugfs_hba_count;
James Smart2a622bf2011-02-16 12:40:06 -05005766
5767/*
5768 * File operations for the iDiag debugfs
5769 */
5770#undef lpfc_idiag_op_pciCfg
5771static const struct file_operations lpfc_idiag_op_pciCfg = {
5772 .owner = THIS_MODULE,
5773 .open = lpfc_idiag_open,
5774 .llseek = lpfc_debugfs_lseek,
5775 .read = lpfc_idiag_pcicfg_read,
5776 .write = lpfc_idiag_pcicfg_write,
5777 .release = lpfc_idiag_cmd_release,
5778};
5779
James Smartb76f2dc2011-07-22 18:37:42 -04005780#undef lpfc_idiag_op_barAcc
5781static const struct file_operations lpfc_idiag_op_barAcc = {
5782 .owner = THIS_MODULE,
5783 .open = lpfc_idiag_open,
5784 .llseek = lpfc_debugfs_lseek,
5785 .read = lpfc_idiag_baracc_read,
5786 .write = lpfc_idiag_baracc_write,
5787 .release = lpfc_idiag_cmd_release,
5788};
5789
James Smart2a622bf2011-02-16 12:40:06 -05005790#undef lpfc_idiag_op_queInfo
5791static const struct file_operations lpfc_idiag_op_queInfo = {
5792 .owner = THIS_MODULE,
5793 .open = lpfc_idiag_open,
5794 .read = lpfc_idiag_queinfo_read,
5795 .release = lpfc_idiag_release,
5796};
5797
James Smartb76f2dc2011-07-22 18:37:42 -04005798#undef lpfc_idiag_op_queAcc
James Smart86a80842011-04-16 11:03:04 -04005799static const struct file_operations lpfc_idiag_op_queAcc = {
5800 .owner = THIS_MODULE,
5801 .open = lpfc_idiag_open,
5802 .llseek = lpfc_debugfs_lseek,
5803 .read = lpfc_idiag_queacc_read,
5804 .write = lpfc_idiag_queacc_write,
5805 .release = lpfc_idiag_cmd_release,
5806};
5807
James Smartb76f2dc2011-07-22 18:37:42 -04005808#undef lpfc_idiag_op_drbAcc
James Smart86a80842011-04-16 11:03:04 -04005809static const struct file_operations lpfc_idiag_op_drbAcc = {
5810 .owner = THIS_MODULE,
5811 .open = lpfc_idiag_open,
5812 .llseek = lpfc_debugfs_lseek,
5813 .read = lpfc_idiag_drbacc_read,
5814 .write = lpfc_idiag_drbacc_write,
5815 .release = lpfc_idiag_cmd_release,
5816};
5817
James Smartb76f2dc2011-07-22 18:37:42 -04005818#undef lpfc_idiag_op_ctlAcc
5819static const struct file_operations lpfc_idiag_op_ctlAcc = {
5820 .owner = THIS_MODULE,
5821 .open = lpfc_idiag_open,
5822 .llseek = lpfc_debugfs_lseek,
5823 .read = lpfc_idiag_ctlacc_read,
5824 .write = lpfc_idiag_ctlacc_write,
5825 .release = lpfc_idiag_cmd_release,
5826};
5827
5828#undef lpfc_idiag_op_mbxAcc
5829static const struct file_operations lpfc_idiag_op_mbxAcc = {
5830 .owner = THIS_MODULE,
5831 .open = lpfc_idiag_open,
5832 .llseek = lpfc_debugfs_lseek,
5833 .read = lpfc_idiag_mbxacc_read,
5834 .write = lpfc_idiag_mbxacc_write,
5835 .release = lpfc_idiag_cmd_release,
5836};
5837
5838#undef lpfc_idiag_op_extAcc
5839static const struct file_operations lpfc_idiag_op_extAcc = {
5840 .owner = THIS_MODULE,
5841 .open = lpfc_idiag_open,
5842 .llseek = lpfc_debugfs_lseek,
5843 .read = lpfc_idiag_extacc_read,
5844 .write = lpfc_idiag_extacc_write,
5845 .release = lpfc_idiag_cmd_release,
5846};
James Smart9f778702021-08-16 09:28:57 -07005847#undef lpfc_cgn_buffer_op
5848static const struct file_operations lpfc_cgn_buffer_op = {
5849 .owner = THIS_MODULE,
5850 .open = lpfc_cgn_buffer_open,
5851 .llseek = lpfc_debugfs_lseek,
5852 .read = lpfc_cgn_buffer_read,
5853 .release = lpfc_cgn_buffer_release,
5854};
5855
5856#undef lpfc_rx_monitor_op
5857static const struct file_operations lpfc_rx_monitor_op = {
5858 .owner = THIS_MODULE,
5859 .open = lpfc_rx_monitor_open,
5860 .llseek = lpfc_debugfs_lseek,
5861 .read = lpfc_rx_monitor_read,
5862 .release = lpfc_rx_monitor_release,
5863};
Arnd Bergmann201743b2019-12-16 14:16:49 +01005864#endif
James Smart858c9f62007-06-17 19:56:39 -05005865
James Smartb76f2dc2011-07-22 18:37:42 -04005866/* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
5867 * @phba: Pointer to HBA context object.
5868 * @dmabuf: Pointer to a DMA buffer descriptor.
5869 *
5870 * Description:
5871 * This routine dump a bsg pass-through non-embedded mailbox command with
5872 * external buffer.
5873 **/
5874void
5875lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
5876 enum mbox_type mbox_tp, enum dma_type dma_tp,
5877 enum sta_type sta_tp,
5878 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
5879{
5880#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5881 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
5882 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5883 int len = 0;
5884 uint32_t do_dump = 0;
5885 uint32_t *pword;
5886 uint32_t i;
5887
5888 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
5889 return;
5890
5891 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5892 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5893 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5894 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5895
5896 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
5897 (*mbx_dump_cnt == 0) ||
5898 (*mbx_word_cnt == 0))
5899 return;
5900
5901 if (*mbx_mbox_cmd != 0x9B)
5902 return;
5903
5904 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
5905 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
5906 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
James Smart2ea259e2017-02-12 13:52:27 -08005907 pr_err("\nRead mbox command (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04005908 "nemb:0x%x, extbuf_cnt:%d:\n",
5909 sta_tp, nemb_tp, ext_buf);
5910 }
5911 }
5912 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
5913 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
5914 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
James Smart2ea259e2017-02-12 13:52:27 -08005915 pr_err("\nRead mbox buffer (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04005916 "nemb:0x%x, extbuf_seq:%d:\n",
5917 sta_tp, nemb_tp, ext_buf);
5918 }
5919 }
5920 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
5921 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
5922 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
James Smart2ea259e2017-02-12 13:52:27 -08005923 pr_err("\nWrite mbox command (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04005924 "nemb:0x%x, extbuf_cnt:%d:\n",
5925 sta_tp, nemb_tp, ext_buf);
5926 }
5927 }
5928 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
5929 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
5930 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
James Smart2ea259e2017-02-12 13:52:27 -08005931 pr_err("\nWrite mbox buffer (x%x), "
James Smartb76f2dc2011-07-22 18:37:42 -04005932 "nemb:0x%x, extbuf_seq:%d:\n",
5933 sta_tp, nemb_tp, ext_buf);
5934 }
5935 }
5936
5937 /* dump buffer content */
5938 if (do_dump) {
5939 pword = (uint32_t *)dmabuf->virt;
5940 for (i = 0; i < *mbx_word_cnt; i++) {
5941 if (!(i % 8)) {
5942 if (i != 0)
James Smart2ea259e2017-02-12 13:52:27 -08005943 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04005944 len = 0;
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005945 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04005946 LPFC_MBX_ACC_LBUF_SZ-len,
5947 "%03d: ", i);
5948 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07005949 len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
James Smartb76f2dc2011-07-22 18:37:42 -04005950 "%08x ", (uint32_t)*pword);
5951 pword++;
5952 }
5953 if ((i - 1) % 8)
James Smart2ea259e2017-02-12 13:52:27 -08005954 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04005955 (*mbx_dump_cnt)--;
5956 }
5957
5958 /* Clean out command structure on reaching dump count */
5959 if (*mbx_dump_cnt == 0)
5960 memset(&idiag, 0, sizeof(idiag));
5961 return;
5962#endif
5963}
5964
5965/* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
5966 * @phba: Pointer to HBA context object.
5967 * @dmabuf: Pointer to a DMA buffer descriptor.
5968 *
5969 * Description:
5970 * This routine dump a pass-through non-embedded mailbox command from issue
5971 * mailbox command.
5972 **/
5973void
5974lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
5975{
5976#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
5977 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
5978 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
5979 int len = 0;
5980 uint32_t *pword;
5981 uint8_t *pbyte;
5982 uint32_t i, j;
5983
5984 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
5985 return;
5986
5987 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
5988 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
5989 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
5990 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
5991
5992 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
5993 (*mbx_dump_cnt == 0) ||
5994 (*mbx_word_cnt == 0))
5995 return;
5996
5997 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
5998 (*mbx_mbox_cmd != pmbox->mbxCommand))
5999 return;
6000
6001 /* dump buffer content */
6002 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
James Smart2ea259e2017-02-12 13:52:27 -08006003 pr_err("Mailbox command:0x%x dump by word:\n",
James Smartb76f2dc2011-07-22 18:37:42 -04006004 pmbox->mbxCommand);
6005 pword = (uint32_t *)pmbox;
6006 for (i = 0; i < *mbx_word_cnt; i++) {
6007 if (!(i % 8)) {
6008 if (i != 0)
James Smart2ea259e2017-02-12 13:52:27 -08006009 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04006010 len = 0;
6011 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07006012 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04006013 LPFC_MBX_ACC_LBUF_SZ-len,
6014 "%03d: ", i);
6015 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07006016 len += scnprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
James Smartb76f2dc2011-07-22 18:37:42 -04006017 "%08x ",
6018 ((uint32_t)*pword) & 0xffffffff);
6019 pword++;
6020 }
6021 if ((i - 1) % 8)
James Smart2ea259e2017-02-12 13:52:27 -08006022 pr_err("%s\n", line_buf);
6023 pr_err("\n");
James Smartb76f2dc2011-07-22 18:37:42 -04006024 }
6025 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
James Smart2ea259e2017-02-12 13:52:27 -08006026 pr_err("Mailbox command:0x%x dump by byte:\n",
James Smartb76f2dc2011-07-22 18:37:42 -04006027 pmbox->mbxCommand);
6028 pbyte = (uint8_t *)pmbox;
6029 for (i = 0; i < *mbx_word_cnt; i++) {
6030 if (!(i % 8)) {
6031 if (i != 0)
James Smart2ea259e2017-02-12 13:52:27 -08006032 pr_err("%s\n", line_buf);
James Smartb76f2dc2011-07-22 18:37:42 -04006033 len = 0;
6034 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07006035 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04006036 LPFC_MBX_ACC_LBUF_SZ-len,
6037 "%03d: ", i);
6038 }
6039 for (j = 0; j < 4; j++) {
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07006040 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04006041 LPFC_MBX_ACC_LBUF_SZ-len,
6042 "%02x",
6043 ((uint8_t)*pbyte) & 0xff);
6044 pbyte++;
6045 }
Silvio Cesaree7f7b6f2019-03-21 09:44:32 -07006046 len += scnprintf(line_buf+len,
James Smartb76f2dc2011-07-22 18:37:42 -04006047 LPFC_MBX_ACC_LBUF_SZ-len, " ");
6048 }
6049 if ((i - 1) % 8)
James Smart2ea259e2017-02-12 13:52:27 -08006050 pr_err("%s\n", line_buf);
6051 pr_err("\n");
James Smartb76f2dc2011-07-22 18:37:42 -04006052 }
6053 (*mbx_dump_cnt)--;
6054
6055 /* Clean out command structure on reaching dump count */
6056 if (*mbx_dump_cnt == 0)
6057 memset(&idiag, 0, sizeof(idiag));
6058 return;
6059#endif
6060}
6061
James Smarte59058c2008-08-24 21:49:00 -04006062/**
James Smart3621a712009-04-06 18:47:14 -04006063 * lpfc_debugfs_initialize - Initialize debugfs for a vport
James Smarte59058c2008-08-24 21:49:00 -04006064 * @vport: The vport pointer to initialize.
6065 *
6066 * Description:
6067 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
6068 * If not already created, this routine will create the lpfc directory, and
6069 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
6070 * also create each file used to access lpfc specific debugfs information.
6071 **/
James Smart858c9f62007-06-17 19:56:39 -05006072inline void
6073lpfc_debugfs_initialize(struct lpfc_vport *vport)
6074{
James Smart923e4b62008-12-04 22:40:07 -05006075#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05006076 struct lpfc_hba *phba = vport->phba;
6077 char name[64];
6078 uint32_t num, i;
James Smartf6c3bdf2013-12-17 20:29:59 -05006079 bool pport_setup = false;
James Smart858c9f62007-06-17 19:56:39 -05006080
6081 if (!lpfc_debugfs_enable)
6082 return;
6083
James Smarta58cbd52007-08-02 11:09:43 -04006084 /* Setup lpfc root directory */
6085 if (!lpfc_debugfs_root) {
6086 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
6087 atomic_set(&lpfc_debugfs_hba_count, 0);
James Smarta58cbd52007-08-02 11:09:43 -04006088 }
James Smarta58cbd52007-08-02 11:09:43 -04006089 if (!lpfc_debugfs_start_time)
6090 lpfc_debugfs_start_time = jiffies;
6091
James Smart2a622bf2011-02-16 12:40:06 -05006092 /* Setup funcX directory for specific HBA PCI function */
6093 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
James Smarta58cbd52007-08-02 11:09:43 -04006094 if (!phba->hba_debugfs_root) {
James Smartf6c3bdf2013-12-17 20:29:59 -05006095 pport_setup = true;
James Smarta58cbd52007-08-02 11:09:43 -04006096 phba->hba_debugfs_root =
6097 debugfs_create_dir(name, lpfc_debugfs_root);
James Smarta58cbd52007-08-02 11:09:43 -04006098 atomic_inc(&lpfc_debugfs_hba_count);
6099 atomic_set(&phba->debugfs_vport_count, 0);
6100
James Smartc4908502019-01-28 11:14:28 -08006101 /* Multi-XRI pools */
6102 snprintf(name, sizeof(name), "multixripools");
6103 phba->debug_multixri_pools =
6104 debugfs_create_file(name, S_IFREG | 0644,
6105 phba->hba_debugfs_root,
6106 phba,
6107 &lpfc_debugfs_op_multixripools);
6108 if (!phba->debug_multixri_pools) {
6109 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6110 "0527 Cannot create debugfs multixripools\n");
6111 goto debug_failed;
6112 }
6113
James Smart9f778702021-08-16 09:28:57 -07006114 /* Congestion Info Buffer */
6115 scnprintf(name, sizeof(name), "cgn_buffer");
6116 phba->debug_cgn_buffer =
6117 debugfs_create_file(name, S_IFREG | 0644,
6118 phba->hba_debugfs_root,
6119 phba, &lpfc_cgn_buffer_op);
6120 if (!phba->debug_cgn_buffer) {
6121 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6122 "6527 Cannot create debugfs "
6123 "cgn_buffer\n");
6124 goto debug_failed;
6125 }
6126
6127 /* RX Monitor */
6128 scnprintf(name, sizeof(name), "rx_monitor");
6129 phba->debug_rx_monitor =
6130 debugfs_create_file(name, S_IFREG | 0644,
6131 phba->hba_debugfs_root,
6132 phba, &lpfc_rx_monitor_op);
6133 if (!phba->debug_rx_monitor) {
6134 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6135 "6528 Cannot create debugfs "
6136 "rx_monitor\n");
6137 goto debug_failed;
6138 }
6139
James Smart95bfc6d2019-10-18 14:18:27 -07006140 /* RAS log */
6141 snprintf(name, sizeof(name), "ras_log");
6142 phba->debug_ras_log =
6143 debugfs_create_file(name, 0644,
6144 phba->hba_debugfs_root,
6145 phba, &lpfc_debugfs_ras_log);
6146 if (!phba->debug_ras_log) {
6147 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6148 "6148 Cannot create debugfs"
6149 " ras_log\n");
6150 goto debug_failed;
6151 }
6152
James Smart78b2d852007-08-02 11:10:21 -04006153 /* Setup hbqinfo */
6154 snprintf(name, sizeof(name), "hbqinfo");
6155 phba->debug_hbqinfo =
James Smart63df6d62019-01-28 11:14:24 -08006156 debugfs_create_file(name, S_IFREG | 0644,
6157 phba->hba_debugfs_root,
6158 phba, &lpfc_debugfs_op_hbqinfo);
James Smart78b2d852007-08-02 11:10:21 -04006159
James Smart6a828b02019-01-28 11:14:31 -08006160#ifdef LPFC_HDWQ_LOCK_STAT
6161 /* Setup lockstat */
6162 snprintf(name, sizeof(name), "lockstat");
6163 phba->debug_lockstat =
James Smart5e5b5112019-01-28 11:14:22 -08006164 debugfs_create_file(name, S_IFREG | 0644,
6165 phba->hba_debugfs_root,
James Smart6a828b02019-01-28 11:14:31 -08006166 phba, &lpfc_debugfs_op_lockstat);
6167 if (!phba->debug_lockstat) {
James Smart5e5b5112019-01-28 11:14:22 -08006168 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
Colin Ian Kinga9b83982020-08-10 11:12:38 +01006169 "4610 Can't create debugfs lockstat\n");
James Smart5e5b5112019-01-28 11:14:22 -08006170 goto debug_failed;
6171 }
James Smart6a828b02019-01-28 11:14:31 -08006172#endif
James Smart5e5b5112019-01-28 11:14:22 -08006173
James Smartc95d6c62008-01-11 01:53:23 -05006174 /* Setup dumpHBASlim */
James Smart2a622bf2011-02-16 12:40:06 -05006175 if (phba->sli_rev < LPFC_SLI_REV4) {
6176 snprintf(name, sizeof(name), "dumpHBASlim");
6177 phba->debug_dumpHBASlim =
6178 debugfs_create_file(name,
6179 S_IFREG|S_IRUGO|S_IWUSR,
6180 phba->hba_debugfs_root,
6181 phba, &lpfc_debugfs_op_dumpHBASlim);
James Smart2a622bf2011-02-16 12:40:06 -05006182 } else
6183 phba->debug_dumpHBASlim = NULL;
James Smartc95d6c62008-01-11 01:53:23 -05006184
6185 /* Setup dumpHostSlim */
James Smart2a622bf2011-02-16 12:40:06 -05006186 if (phba->sli_rev < LPFC_SLI_REV4) {
6187 snprintf(name, sizeof(name), "dumpHostSlim");
6188 phba->debug_dumpHostSlim =
6189 debugfs_create_file(name,
6190 S_IFREG|S_IRUGO|S_IWUSR,
6191 phba->hba_debugfs_root,
6192 phba, &lpfc_debugfs_op_dumpHostSlim);
James Smart2a622bf2011-02-16 12:40:06 -05006193 } else
Felipe Penab28d1082013-10-18 20:15:37 -03006194 phba->debug_dumpHostSlim = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04006195
James Smartf9bb2da2011-10-10 21:34:11 -04006196 /* Setup DIF Error Injections */
6197 snprintf(name, sizeof(name), "InjErrLBA");
6198 phba->debug_InjErrLBA =
6199 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6200 phba->hba_debugfs_root,
6201 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006202 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
6203
James Smart4ac9b222012-03-01 22:38:29 -05006204 snprintf(name, sizeof(name), "InjErrNPortID");
6205 phba->debug_InjErrNPortID =
6206 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6207 phba->hba_debugfs_root,
6208 phba, &lpfc_debugfs_op_dif_err);
James Smart4ac9b222012-03-01 22:38:29 -05006209
6210 snprintf(name, sizeof(name), "InjErrWWPN");
6211 phba->debug_InjErrWWPN =
6212 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6213 phba->hba_debugfs_root,
6214 phba, &lpfc_debugfs_op_dif_err);
James Smart4ac9b222012-03-01 22:38:29 -05006215
James Smartf9bb2da2011-10-10 21:34:11 -04006216 snprintf(name, sizeof(name), "writeGuardInjErr");
6217 phba->debug_writeGuard =
6218 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6219 phba->hba_debugfs_root,
6220 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006221
6222 snprintf(name, sizeof(name), "writeAppInjErr");
6223 phba->debug_writeApp =
6224 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6225 phba->hba_debugfs_root,
6226 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006227
6228 snprintf(name, sizeof(name), "writeRefInjErr");
6229 phba->debug_writeRef =
6230 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6231 phba->hba_debugfs_root,
6232 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006233
James Smartacd68592012-01-18 16:25:09 -05006234 snprintf(name, sizeof(name), "readGuardInjErr");
6235 phba->debug_readGuard =
6236 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6237 phba->hba_debugfs_root,
6238 phba, &lpfc_debugfs_op_dif_err);
James Smartacd68592012-01-18 16:25:09 -05006239
James Smartf9bb2da2011-10-10 21:34:11 -04006240 snprintf(name, sizeof(name), "readAppInjErr");
6241 phba->debug_readApp =
6242 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6243 phba->hba_debugfs_root,
6244 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006245
6246 snprintf(name, sizeof(name), "readRefInjErr");
6247 phba->debug_readRef =
6248 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6249 phba->hba_debugfs_root,
6250 phba, &lpfc_debugfs_op_dif_err);
James Smartf9bb2da2011-10-10 21:34:11 -04006251
James Smarta58cbd52007-08-02 11:09:43 -04006252 /* Setup slow ring trace */
6253 if (lpfc_debugfs_max_slow_ring_trc) {
6254 num = lpfc_debugfs_max_slow_ring_trc - 1;
6255 if (num & lpfc_debugfs_max_slow_ring_trc) {
6256 /* Change to be a power of 2 */
6257 num = lpfc_debugfs_max_slow_ring_trc;
6258 i = 0;
6259 while (num > 1) {
6260 num = num >> 1;
6261 i++;
6262 }
6263 lpfc_debugfs_max_slow_ring_trc = (1 << i);
James Smart2ea259e2017-02-12 13:52:27 -08006264 pr_err("lpfc_debugfs_max_disc_trc changed to "
James Smarte8b62012007-08-02 11:10:09 -04006265 "%d\n", lpfc_debugfs_max_disc_trc);
James Smarta58cbd52007-08-02 11:09:43 -04006266 }
6267 }
6268
James Smarta58cbd52007-08-02 11:09:43 -04006269 snprintf(name, sizeof(name), "slow_ring_trace");
6270 phba->debug_slow_ring_trc =
6271 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6272 phba->hba_debugfs_root,
6273 phba, &lpfc_debugfs_op_slow_ring_trc);
James Smarta58cbd52007-08-02 11:09:43 -04006274 if (!phba->slow_ring_trc) {
6275 phba->slow_ring_trc = kmalloc(
6276 (sizeof(struct lpfc_debugfs_trc) *
6277 lpfc_debugfs_max_slow_ring_trc),
6278 GFP_KERNEL);
6279 if (!phba->slow_ring_trc) {
James Smarte8b62012007-08-02 11:10:09 -04006280 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04006281 "0416 Cannot create debugfs "
James Smarte8b62012007-08-02 11:10:09 -04006282 "slow_ring buffer\n");
James Smarta58cbd52007-08-02 11:09:43 -04006283 goto debug_failed;
6284 }
6285 atomic_set(&phba->slow_ring_trc_cnt, 0);
6286 memset(phba->slow_ring_trc, 0,
6287 (sizeof(struct lpfc_debugfs_trc) *
6288 lpfc_debugfs_max_slow_ring_trc));
6289 }
James Smart2ea259e2017-02-12 13:52:27 -08006290
James Smartbd2cdd52017-02-12 13:52:33 -08006291 snprintf(name, sizeof(name), "nvmeio_trc");
6292 phba->debug_nvmeio_trc =
6293 debugfs_create_file(name, 0644,
6294 phba->hba_debugfs_root,
6295 phba, &lpfc_debugfs_op_nvmeio_trc);
James Smartbd2cdd52017-02-12 13:52:33 -08006296
6297 atomic_set(&phba->nvmeio_trc_cnt, 0);
6298 if (lpfc_debugfs_max_nvmeio_trc) {
6299 num = lpfc_debugfs_max_nvmeio_trc - 1;
6300 if (num & lpfc_debugfs_max_disc_trc) {
6301 /* Change to be a power of 2 */
6302 num = lpfc_debugfs_max_nvmeio_trc;
6303 i = 0;
6304 while (num > 1) {
6305 num = num >> 1;
6306 i++;
6307 }
6308 lpfc_debugfs_max_nvmeio_trc = (1 << i);
6309 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6310 "0575 lpfc_debugfs_max_nvmeio_trc "
6311 "changed to %d\n",
6312 lpfc_debugfs_max_nvmeio_trc);
6313 }
6314 phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
6315
6316 /* Allocate trace buffer and initialize */
Vasyl Gomonovych1c356ec2017-10-11 21:42:41 +02006317 phba->nvmeio_trc = kzalloc(
James Smartbd2cdd52017-02-12 13:52:33 -08006318 (sizeof(struct lpfc_debugfs_nvmeio_trc) *
6319 phba->nvmeio_trc_size), GFP_KERNEL);
6320
6321 if (!phba->nvmeio_trc) {
6322 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6323 "0576 Cannot create debugfs "
6324 "nvmeio_trc buffer\n");
6325 goto nvmeio_off;
6326 }
James Smartbd2cdd52017-02-12 13:52:33 -08006327 phba->nvmeio_trc_on = 1;
6328 phba->nvmeio_trc_output_idx = 0;
6329 phba->nvmeio_trc = NULL;
6330 } else {
6331nvmeio_off:
6332 phba->nvmeio_trc_size = 0;
6333 phba->nvmeio_trc_on = 0;
6334 phba->nvmeio_trc_output_idx = 0;
6335 phba->nvmeio_trc = NULL;
6336 }
James Smarta58cbd52007-08-02 11:09:43 -04006337 }
6338
6339 snprintf(name, sizeof(name), "vport%d", vport->vpi);
6340 if (!vport->vport_debugfs_root) {
6341 vport->vport_debugfs_root =
6342 debugfs_create_dir(name, phba->hba_debugfs_root);
James Smarta58cbd52007-08-02 11:09:43 -04006343 atomic_inc(&phba->debugfs_vport_count);
6344 }
6345
James Smart858c9f62007-06-17 19:56:39 -05006346 if (lpfc_debugfs_max_disc_trc) {
6347 num = lpfc_debugfs_max_disc_trc - 1;
6348 if (num & lpfc_debugfs_max_disc_trc) {
6349 /* Change to be a power of 2 */
6350 num = lpfc_debugfs_max_disc_trc;
6351 i = 0;
6352 while (num > 1) {
6353 num = num >> 1;
6354 i++;
6355 }
6356 lpfc_debugfs_max_disc_trc = (1 << i);
James Smart2ea259e2017-02-12 13:52:27 -08006357 pr_err("lpfc_debugfs_max_disc_trc changed to %d\n",
James Smarte8b62012007-08-02 11:10:09 -04006358 lpfc_debugfs_max_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05006359 }
6360 }
6361
Adrian Bunkff86ba52007-10-18 12:52:37 +02006362 vport->disc_trc = kzalloc(
James Smarta58cbd52007-08-02 11:09:43 -04006363 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
James Smart858c9f62007-06-17 19:56:39 -05006364 GFP_KERNEL);
6365
James Smarta58cbd52007-08-02 11:09:43 -04006366 if (!vport->disc_trc) {
James Smarte8b62012007-08-02 11:10:09 -04006367 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04006368 "0418 Cannot create debugfs disc trace "
James Smarte8b62012007-08-02 11:10:09 -04006369 "buffer\n");
James Smart858c9f62007-06-17 19:56:39 -05006370 goto debug_failed;
James Smarta58cbd52007-08-02 11:09:43 -04006371 }
6372 atomic_set(&vport->disc_trc_cnt, 0);
James Smart858c9f62007-06-17 19:56:39 -05006373
6374 snprintf(name, sizeof(name), "discovery_trace");
6375 vport->debug_disc_trc =
6376 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6377 vport->vport_debugfs_root,
6378 vport, &lpfc_debugfs_op_disc_trc);
James Smart858c9f62007-06-17 19:56:39 -05006379 snprintf(name, sizeof(name), "nodelist");
6380 vport->debug_nodelist =
6381 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6382 vport->vport_debugfs_root,
6383 vport, &lpfc_debugfs_op_nodelist);
James Smart2a622bf2011-02-16 12:40:06 -05006384
James Smartbd2cdd52017-02-12 13:52:33 -08006385 snprintf(name, sizeof(name), "nvmestat");
6386 vport->debug_nvmestat =
6387 debugfs_create_file(name, 0644,
6388 vport->vport_debugfs_root,
6389 vport, &lpfc_debugfs_op_nvmestat);
James Smartbd2cdd52017-02-12 13:52:33 -08006390
James Smart4c47efc2019-01-28 11:14:25 -08006391 snprintf(name, sizeof(name), "scsistat");
6392 vport->debug_scsistat =
6393 debugfs_create_file(name, 0644,
6394 vport->vport_debugfs_root,
6395 vport, &lpfc_debugfs_op_scsistat);
6396 if (!vport->debug_scsistat) {
6397 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartc835c082019-03-12 16:30:30 -07006398 "4611 Cannot create debugfs scsistat\n");
James Smart4c47efc2019-01-28 11:14:25 -08006399 goto debug_failed;
6400 }
6401
James Smart2fcbc562020-03-22 11:13:02 -07006402 snprintf(name, sizeof(name), "ioktime");
6403 vport->debug_ioktime =
James Smartbd2cdd52017-02-12 13:52:33 -08006404 debugfs_create_file(name, 0644,
6405 vport->vport_debugfs_root,
James Smart2fcbc562020-03-22 11:13:02 -07006406 vport, &lpfc_debugfs_op_ioktime);
6407 if (!vport->debug_ioktime) {
6408 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
6409 "0815 Cannot create debugfs ioktime\n");
6410 goto debug_failed;
6411 }
James Smartbd2cdd52017-02-12 13:52:33 -08006412
James Smart840eda92020-03-22 11:13:00 -07006413 snprintf(name, sizeof(name), "hdwqstat");
6414 vport->debug_hdwqstat =
James Smartbd2cdd52017-02-12 13:52:33 -08006415 debugfs_create_file(name, 0644,
6416 vport->vport_debugfs_root,
James Smart840eda92020-03-22 11:13:00 -07006417 vport, &lpfc_debugfs_op_hdwqstat);
James Smartbd2cdd52017-02-12 13:52:33 -08006418
James Smart2a622bf2011-02-16 12:40:06 -05006419 /*
James Smartf6c3bdf2013-12-17 20:29:59 -05006420 * The following section is for additional directories/files for the
6421 * physical port.
6422 */
6423
6424 if (!pport_setup)
6425 goto debug_failed;
6426
6427 /*
James Smart2a622bf2011-02-16 12:40:06 -05006428 * iDiag debugfs root entry points for SLI4 device only
6429 */
6430 if (phba->sli_rev < LPFC_SLI_REV4)
6431 goto debug_failed;
6432
6433 snprintf(name, sizeof(name), "iDiag");
6434 if (!phba->idiag_root) {
6435 phba->idiag_root =
6436 debugfs_create_dir(name, phba->hba_debugfs_root);
James Smart2a622bf2011-02-16 12:40:06 -05006437 /* Initialize iDiag data structure */
6438 memset(&idiag, 0, sizeof(idiag));
6439 }
6440
6441 /* iDiag read PCI config space */
6442 snprintf(name, sizeof(name), "pciCfg");
6443 if (!phba->idiag_pci_cfg) {
6444 phba->idiag_pci_cfg =
6445 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6446 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
James Smart2a622bf2011-02-16 12:40:06 -05006447 idiag.offset.last_rd = 0;
6448 }
6449
James Smartb76f2dc2011-07-22 18:37:42 -04006450 /* iDiag PCI BAR access */
6451 snprintf(name, sizeof(name), "barAcc");
6452 if (!phba->idiag_bar_acc) {
6453 phba->idiag_bar_acc =
6454 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6455 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
James Smartb76f2dc2011-07-22 18:37:42 -04006456 idiag.offset.last_rd = 0;
6457 }
6458
James Smart2a622bf2011-02-16 12:40:06 -05006459 /* iDiag get PCI function queue information */
6460 snprintf(name, sizeof(name), "queInfo");
6461 if (!phba->idiag_que_info) {
6462 phba->idiag_que_info =
6463 debugfs_create_file(name, S_IFREG|S_IRUGO,
6464 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
James Smart2a622bf2011-02-16 12:40:06 -05006465 }
6466
James Smart86a80842011-04-16 11:03:04 -04006467 /* iDiag access PCI function queue */
6468 snprintf(name, sizeof(name), "queAcc");
6469 if (!phba->idiag_que_acc) {
6470 phba->idiag_que_acc =
6471 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6472 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
James Smart86a80842011-04-16 11:03:04 -04006473 }
6474
6475 /* iDiag access PCI function doorbell registers */
6476 snprintf(name, sizeof(name), "drbAcc");
6477 if (!phba->idiag_drb_acc) {
6478 phba->idiag_drb_acc =
6479 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6480 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
James Smart86a80842011-04-16 11:03:04 -04006481 }
6482
James Smartb76f2dc2011-07-22 18:37:42 -04006483 /* iDiag access PCI function control registers */
6484 snprintf(name, sizeof(name), "ctlAcc");
6485 if (!phba->idiag_ctl_acc) {
6486 phba->idiag_ctl_acc =
6487 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6488 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
James Smartb76f2dc2011-07-22 18:37:42 -04006489 }
6490
6491 /* iDiag access mbox commands */
6492 snprintf(name, sizeof(name), "mbxAcc");
6493 if (!phba->idiag_mbx_acc) {
6494 phba->idiag_mbx_acc =
6495 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
6496 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
James Smartb76f2dc2011-07-22 18:37:42 -04006497 }
6498
6499 /* iDiag extents access commands */
6500 if (phba->sli4_hba.extents_in_use) {
6501 snprintf(name, sizeof(name), "extAcc");
6502 if (!phba->idiag_ext_acc) {
6503 phba->idiag_ext_acc =
6504 debugfs_create_file(name,
6505 S_IFREG|S_IRUGO|S_IWUSR,
6506 phba->idiag_root, phba,
6507 &lpfc_idiag_op_extAcc);
James Smartb76f2dc2011-07-22 18:37:42 -04006508 }
6509 }
6510
James Smart858c9f62007-06-17 19:56:39 -05006511debug_failed:
6512 return;
6513#endif
6514}
6515
James Smarte59058c2008-08-24 21:49:00 -04006516/**
James Smart3621a712009-04-06 18:47:14 -04006517 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
James Smarte59058c2008-08-24 21:49:00 -04006518 * @vport: The vport pointer to remove from debugfs.
6519 *
6520 * Description:
6521 * When Debugfs is configured this routine removes debugfs file system elements
6522 * that are specific to this vport. It also checks to see if there are any
6523 * users left for the debugfs directories associated with the HBA and driver. If
6524 * this is the last user of the HBA directory or driver directory then it will
6525 * remove those from the debugfs infrastructure as well.
6526 **/
James Smart858c9f62007-06-17 19:56:39 -05006527inline void
6528lpfc_debugfs_terminate(struct lpfc_vport *vport)
6529{
James Smart923e4b62008-12-04 22:40:07 -05006530#ifdef CONFIG_SCSI_LPFC_DEBUG_FS
James Smart858c9f62007-06-17 19:56:39 -05006531 struct lpfc_hba *phba = vport->phba;
6532
James Smarteafe89f2017-04-21 16:04:52 -07006533 kfree(vport->disc_trc);
6534 vport->disc_trc = NULL;
James Smartbd2cdd52017-02-12 13:52:33 -08006535
6536 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
6537 vport->debug_disc_trc = NULL;
6538
6539 debugfs_remove(vport->debug_nodelist); /* nodelist */
6540 vport->debug_nodelist = NULL;
6541
6542 debugfs_remove(vport->debug_nvmestat); /* nvmestat */
6543 vport->debug_nvmestat = NULL;
6544
James Smart4c47efc2019-01-28 11:14:25 -08006545 debugfs_remove(vport->debug_scsistat); /* scsistat */
6546 vport->debug_scsistat = NULL;
6547
James Smart2fcbc562020-03-22 11:13:02 -07006548 debugfs_remove(vport->debug_ioktime); /* ioktime */
6549 vport->debug_ioktime = NULL;
James Smartbd2cdd52017-02-12 13:52:33 -08006550
James Smart840eda92020-03-22 11:13:00 -07006551 debugfs_remove(vport->debug_hdwqstat); /* hdwqstat */
6552 vport->debug_hdwqstat = NULL;
James Smartbd2cdd52017-02-12 13:52:33 -08006553
James Smart858c9f62007-06-17 19:56:39 -05006554 if (vport->vport_debugfs_root) {
6555 debugfs_remove(vport->vport_debugfs_root); /* vportX */
6556 vport->vport_debugfs_root = NULL;
6557 atomic_dec(&phba->debugfs_vport_count);
6558 }
James Smartbd2cdd52017-02-12 13:52:33 -08006559
James Smart858c9f62007-06-17 19:56:39 -05006560 if (atomic_read(&phba->debugfs_vport_count) == 0) {
James Smarta58cbd52007-08-02 11:09:43 -04006561
James Smartc4908502019-01-28 11:14:28 -08006562 debugfs_remove(phba->debug_multixri_pools); /* multixripools*/
6563 phba->debug_multixri_pools = NULL;
6564
James Smartbd2cdd52017-02-12 13:52:33 -08006565 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
6566 phba->debug_hbqinfo = NULL;
James Smarte2a0a9d2008-12-04 22:40:02 -05006567
James Smart9f778702021-08-16 09:28:57 -07006568 debugfs_remove(phba->debug_cgn_buffer);
6569 phba->debug_cgn_buffer = NULL;
6570
6571 debugfs_remove(phba->debug_rx_monitor);
6572 phba->debug_rx_monitor = NULL;
6573
James Smart95bfc6d2019-10-18 14:18:27 -07006574 debugfs_remove(phba->debug_ras_log);
6575 phba->debug_ras_log = NULL;
6576
James Smart6a828b02019-01-28 11:14:31 -08006577#ifdef LPFC_HDWQ_LOCK_STAT
6578 debugfs_remove(phba->debug_lockstat); /* lockstat */
6579 phba->debug_lockstat = NULL;
6580#endif
James Smartbd2cdd52017-02-12 13:52:33 -08006581 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
6582 phba->debug_dumpHBASlim = NULL;
6583
6584 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
6585 phba->debug_dumpHostSlim = NULL;
6586
James Smartbd2cdd52017-02-12 13:52:33 -08006587 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
6588 phba->debug_InjErrLBA = NULL;
6589
6590 debugfs_remove(phba->debug_InjErrNPortID);
6591 phba->debug_InjErrNPortID = NULL;
6592
6593 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
6594 phba->debug_InjErrWWPN = NULL;
6595
6596 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
6597 phba->debug_writeGuard = NULL;
6598
6599 debugfs_remove(phba->debug_writeApp); /* writeApp */
6600 phba->debug_writeApp = NULL;
6601
6602 debugfs_remove(phba->debug_writeRef); /* writeRef */
6603 phba->debug_writeRef = NULL;
6604
6605 debugfs_remove(phba->debug_readGuard); /* readGuard */
6606 phba->debug_readGuard = NULL;
6607
6608 debugfs_remove(phba->debug_readApp); /* readApp */
6609 phba->debug_readApp = NULL;
6610
6611 debugfs_remove(phba->debug_readRef); /* readRef */
6612 phba->debug_readRef = NULL;
James Smarte2a0a9d2008-12-04 22:40:02 -05006613
James Smarteafe89f2017-04-21 16:04:52 -07006614 kfree(phba->slow_ring_trc);
6615 phba->slow_ring_trc = NULL;
James Smartbd2cdd52017-02-12 13:52:33 -08006616
6617 /* slow_ring_trace */
6618 debugfs_remove(phba->debug_slow_ring_trc);
6619 phba->debug_slow_ring_trc = NULL;
6620
6621 debugfs_remove(phba->debug_nvmeio_trc);
6622 phba->debug_nvmeio_trc = NULL;
6623
6624 kfree(phba->nvmeio_trc);
6625 phba->nvmeio_trc = NULL;
James Smarta58cbd52007-08-02 11:09:43 -04006626
James Smart2a622bf2011-02-16 12:40:06 -05006627 /*
6628 * iDiag release
6629 */
6630 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartbd2cdd52017-02-12 13:52:33 -08006631 /* iDiag extAcc */
6632 debugfs_remove(phba->idiag_ext_acc);
6633 phba->idiag_ext_acc = NULL;
6634
6635 /* iDiag mbxAcc */
6636 debugfs_remove(phba->idiag_mbx_acc);
6637 phba->idiag_mbx_acc = NULL;
6638
6639 /* iDiag ctlAcc */
6640 debugfs_remove(phba->idiag_ctl_acc);
6641 phba->idiag_ctl_acc = NULL;
6642
6643 /* iDiag drbAcc */
6644 debugfs_remove(phba->idiag_drb_acc);
6645 phba->idiag_drb_acc = NULL;
6646
6647 /* iDiag queAcc */
6648 debugfs_remove(phba->idiag_que_acc);
6649 phba->idiag_que_acc = NULL;
6650
6651 /* iDiag queInfo */
6652 debugfs_remove(phba->idiag_que_info);
6653 phba->idiag_que_info = NULL;
6654
6655 /* iDiag barAcc */
6656 debugfs_remove(phba->idiag_bar_acc);
6657 phba->idiag_bar_acc = NULL;
6658
6659 /* iDiag pciCfg */
6660 debugfs_remove(phba->idiag_pci_cfg);
6661 phba->idiag_pci_cfg = NULL;
James Smart2a622bf2011-02-16 12:40:06 -05006662
6663 /* Finally remove the iDiag debugfs root */
James Smartbd2cdd52017-02-12 13:52:33 -08006664 debugfs_remove(phba->idiag_root);
6665 phba->idiag_root = NULL;
James Smart2a622bf2011-02-16 12:40:06 -05006666 }
6667
James Smarta58cbd52007-08-02 11:09:43 -04006668 if (phba->hba_debugfs_root) {
James Smart2a622bf2011-02-16 12:40:06 -05006669 debugfs_remove(phba->hba_debugfs_root); /* fnX */
James Smarta58cbd52007-08-02 11:09:43 -04006670 phba->hba_debugfs_root = NULL;
6671 atomic_dec(&lpfc_debugfs_hba_count);
6672 }
6673
James Smart667a7662017-05-15 15:20:48 -07006674 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
6675 debugfs_remove(lpfc_debugfs_root); /* lpfc */
6676 lpfc_debugfs_root = NULL;
6677 }
James Smart858c9f62007-06-17 19:56:39 -05006678 }
6679#endif
James Smarta58cbd52007-08-02 11:09:43 -04006680 return;
James Smart858c9f62007-06-17 19:56:39 -05006681}
James Smart809c7532012-05-09 21:19:25 -04006682
6683/*
6684 * Driver debug utility routines outside of debugfs. The debug utility
6685 * routines implemented here is intended to be used in the instrumented
6686 * debug driver for debugging host or port issues.
6687 */
6688
6689/**
6690 * lpfc_debug_dump_all_queues - dump all the queues with a hba
6691 * @phba: Pointer to HBA context object.
6692 *
6693 * This function dumps entries of all the queues asociated with the @phba.
6694 **/
6695void
6696lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
6697{
James Smart1d9d5a92017-02-12 13:52:29 -08006698 int idx;
James Smart809c7532012-05-09 21:19:25 -04006699
6700 /*
6701 * Dump Work Queues (WQs)
6702 */
James Smart1d9d5a92017-02-12 13:52:29 -08006703 lpfc_debug_dump_wq(phba, DUMP_MBX, 0);
6704 lpfc_debug_dump_wq(phba, DUMP_ELS, 0);
James Smart895427b2017-02-12 13:52:30 -08006705 lpfc_debug_dump_wq(phba, DUMP_NVMELS, 0);
James Smart809c7532012-05-09 21:19:25 -04006706
James Smartcdb42be2019-01-28 11:14:21 -08006707 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
James Smartc00f62e2019-08-14 16:57:11 -07006708 lpfc_debug_dump_wq(phba, DUMP_IO, idx);
James Smart895427b2017-02-12 13:52:30 -08006709
James Smart809c7532012-05-09 21:19:25 -04006710 lpfc_debug_dump_hdr_rq(phba);
6711 lpfc_debug_dump_dat_rq(phba);
6712 /*
6713 * Dump Complete Queues (CQs)
6714 */
James Smart1d9d5a92017-02-12 13:52:29 -08006715 lpfc_debug_dump_cq(phba, DUMP_MBX, 0);
6716 lpfc_debug_dump_cq(phba, DUMP_ELS, 0);
James Smart895427b2017-02-12 13:52:30 -08006717 lpfc_debug_dump_cq(phba, DUMP_NVMELS, 0);
James Smart809c7532012-05-09 21:19:25 -04006718
James Smartcdb42be2019-01-28 11:14:21 -08006719 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
James Smartc00f62e2019-08-14 16:57:11 -07006720 lpfc_debug_dump_cq(phba, DUMP_IO, idx);
James Smart895427b2017-02-12 13:52:30 -08006721
James Smart809c7532012-05-09 21:19:25 -04006722 /*
6723 * Dump Event Queues (EQs)
6724 */
James Smartcdb42be2019-01-28 11:14:21 -08006725 for (idx = 0; idx < phba->cfg_hdw_queue; idx++)
James Smart1d9d5a92017-02-12 13:52:29 -08006726 lpfc_debug_dump_hba_eq(phba, idx);
James Smart809c7532012-05-09 21:19:25 -04006727}