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