Merge git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-edac
[deliverable/linux.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) 2007-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *******************************************************************/
20
21 #include <linux/blkdev.h>
22 #include <linux/delay.h>
23 #include <linux/module.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/kthread.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/ctype.h>
32
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37
38 #include "lpfc_hw4.h"
39 #include "lpfc_hw.h"
40 #include "lpfc_sli.h"
41 #include "lpfc_sli4.h"
42 #include "lpfc_nl.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
45 #include "lpfc.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
49 #include "lpfc_version.h"
50 #include "lpfc_compat.h"
51 #include "lpfc_debugfs.h"
52 #include "lpfc_bsg.h"
53
54 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
55 /*
56 * debugfs interface
57 *
58 * To access this interface the user should:
59 * # mount -t debugfs none /sys/kernel/debug
60 *
61 * The lpfc debugfs directory hierarchy is:
62 * /sys/kernel/debug/lpfc/fnX/vportY
63 * where X is the lpfc hba function unique_id
64 * where Y is the vport VPI on that hba
65 *
66 * Debugging services available per vport:
67 * discovery_trace
68 * This is an ACSII readable file that contains a trace of the last
69 * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
70 * See lpfc_debugfs.h for different categories of discovery events.
71 * To enable the discovery trace, the following module parameters must be set:
72 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
73 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
74 * EACH vport. X MUST also be a power of 2.
75 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
76 * lpfc_debugfs.h .
77 *
78 * slow_ring_trace
79 * This is an ACSII readable file that contains a trace of the last
80 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
81 * To enable the slow ring trace, the following module parameters must be set:
82 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
83 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
84 * the HBA. X MUST also be a power of 2.
85 */
86 static int lpfc_debugfs_enable = 1;
87 module_param(lpfc_debugfs_enable, int, S_IRUGO);
88 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
89
90 /* This MUST be a power of 2 */
91 static int lpfc_debugfs_max_disc_trc;
92 module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
93 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
94 "Set debugfs discovery trace depth");
95
96 /* This MUST be a power of 2 */
97 static int lpfc_debugfs_max_slow_ring_trc;
98 module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
99 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
100 "Set debugfs slow ring trace depth");
101
102 static int lpfc_debugfs_mask_disc_trc;
103 module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
104 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
105 "Set debugfs discovery trace mask");
106
107 #include <linux/debugfs.h>
108
109 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
110 static unsigned long lpfc_debugfs_start_time = 0L;
111
112 /* iDiag */
113 static struct lpfc_idiag idiag;
114
115 /**
116 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
117 * @vport: The vport to gather the log info from.
118 * @buf: The buffer to dump log into.
119 * @size: The maximum amount of data to process.
120 *
121 * Description:
122 * This routine gathers the lpfc discovery debugfs data from the @vport and
123 * dumps it to @buf up to @size number of bytes. It will start at the next entry
124 * in the log and process the log until the end of the buffer. Then it will
125 * gather from the beginning of the log and process until the current entry.
126 *
127 * Notes:
128 * Discovery logging will be disabled while while this routine dumps the log.
129 *
130 * Return Value:
131 * This routine returns the amount of bytes that were dumped into @buf and will
132 * not exceed @size.
133 **/
134 static int
135 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
136 {
137 int i, index, len, enable;
138 uint32_t ms;
139 struct lpfc_debugfs_trc *dtp;
140 char *buffer;
141
142 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
143 if (!buffer)
144 return 0;
145
146 enable = lpfc_debugfs_enable;
147 lpfc_debugfs_enable = 0;
148
149 len = 0;
150 index = (atomic_read(&vport->disc_trc_cnt) + 1) &
151 (lpfc_debugfs_max_disc_trc - 1);
152 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
153 dtp = vport->disc_trc + i;
154 if (!dtp->fmt)
155 continue;
156 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
157 snprintf(buffer,
158 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
159 dtp->seq_cnt, ms, dtp->fmt);
160 len += snprintf(buf+len, size-len, buffer,
161 dtp->data1, dtp->data2, dtp->data3);
162 }
163 for (i = 0; i < index; i++) {
164 dtp = vport->disc_trc + i;
165 if (!dtp->fmt)
166 continue;
167 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
168 snprintf(buffer,
169 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
170 dtp->seq_cnt, ms, dtp->fmt);
171 len += snprintf(buf+len, size-len, buffer,
172 dtp->data1, dtp->data2, dtp->data3);
173 }
174
175 lpfc_debugfs_enable = enable;
176 kfree(buffer);
177
178 return len;
179 }
180
181 /**
182 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
183 * @phba: The HBA to gather the log info from.
184 * @buf: The buffer to dump log into.
185 * @size: The maximum amount of data to process.
186 *
187 * Description:
188 * This routine gathers the lpfc slow ring debugfs data from the @phba and
189 * dumps it to @buf up to @size number of bytes. It will start at the next entry
190 * in the log and process the log until the end of the buffer. Then it will
191 * gather from the beginning of the log and process until the current entry.
192 *
193 * Notes:
194 * Slow ring logging will be disabled while while this routine dumps the log.
195 *
196 * Return Value:
197 * This routine returns the amount of bytes that were dumped into @buf and will
198 * not exceed @size.
199 **/
200 static int
201 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
202 {
203 int i, index, len, enable;
204 uint32_t ms;
205 struct lpfc_debugfs_trc *dtp;
206 char *buffer;
207
208 buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
209 if (!buffer)
210 return 0;
211
212 enable = lpfc_debugfs_enable;
213 lpfc_debugfs_enable = 0;
214
215 len = 0;
216 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
217 (lpfc_debugfs_max_slow_ring_trc - 1);
218 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
219 dtp = phba->slow_ring_trc + i;
220 if (!dtp->fmt)
221 continue;
222 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
223 snprintf(buffer,
224 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
225 dtp->seq_cnt, ms, dtp->fmt);
226 len += snprintf(buf+len, size-len, buffer,
227 dtp->data1, dtp->data2, dtp->data3);
228 }
229 for (i = 0; i < index; i++) {
230 dtp = phba->slow_ring_trc + i;
231 if (!dtp->fmt)
232 continue;
233 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
234 snprintf(buffer,
235 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
236 dtp->seq_cnt, ms, dtp->fmt);
237 len += snprintf(buf+len, size-len, buffer,
238 dtp->data1, dtp->data2, dtp->data3);
239 }
240
241 lpfc_debugfs_enable = enable;
242 kfree(buffer);
243
244 return len;
245 }
246
247 static int lpfc_debugfs_last_hbq = -1;
248
249 /**
250 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
251 * @phba: The HBA to gather host buffer info from.
252 * @buf: The buffer to dump log into.
253 * @size: The maximum amount of data to process.
254 *
255 * Description:
256 * This routine dumps the host buffer queue info from the @phba to @buf up to
257 * @size number of bytes. A header that describes the current hbq state will be
258 * dumped to @buf first and then info on each hbq entry will be dumped to @buf
259 * until @size bytes have been dumped or all the hbq info has been dumped.
260 *
261 * Notes:
262 * This routine will rotate through each configured HBQ each time called.
263 *
264 * Return Value:
265 * This routine returns the amount of bytes that were dumped into @buf and will
266 * not exceed @size.
267 **/
268 static int
269 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
270 {
271 int len = 0;
272 int cnt, i, j, found, posted, low;
273 uint32_t phys, raw_index, getidx;
274 struct lpfc_hbq_init *hip;
275 struct hbq_s *hbqs;
276 struct lpfc_hbq_entry *hbqe;
277 struct lpfc_dmabuf *d_buf;
278 struct hbq_dmabuf *hbq_buf;
279
280 if (phba->sli_rev != 3)
281 return 0;
282 cnt = LPFC_HBQINFO_SIZE;
283 spin_lock_irq(&phba->hbalock);
284
285 /* toggle between multiple hbqs, if any */
286 i = lpfc_sli_hbq_count();
287 if (i > 1) {
288 lpfc_debugfs_last_hbq++;
289 if (lpfc_debugfs_last_hbq >= i)
290 lpfc_debugfs_last_hbq = 0;
291 }
292 else
293 lpfc_debugfs_last_hbq = 0;
294
295 i = lpfc_debugfs_last_hbq;
296
297 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
298
299 hbqs = &phba->hbqs[i];
300 posted = 0;
301 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
302 posted++;
303
304 hip = lpfc_hbq_defs[i];
305 len += snprintf(buf+len, size-len,
306 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
307 hip->hbq_index, hip->profile, hip->rn,
308 hip->buffer_count, hip->init_count, hip->add_count, posted);
309
310 raw_index = phba->hbq_get[i];
311 getidx = le32_to_cpu(raw_index);
312 len += snprintf(buf+len, size-len,
313 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
314 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
315 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
316
317 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
318 for (j=0; j<hbqs->entry_count; j++) {
319 len += snprintf(buf+len, size-len,
320 "%03d: %08x %04x %05x ", j,
321 le32_to_cpu(hbqe->bde.addrLow),
322 le32_to_cpu(hbqe->bde.tus.w),
323 le32_to_cpu(hbqe->buffer_tag));
324 i = 0;
325 found = 0;
326
327 /* First calculate if slot has an associated posted buffer */
328 low = hbqs->hbqPutIdx - posted;
329 if (low >= 0) {
330 if ((j >= hbqs->hbqPutIdx) || (j < low)) {
331 len += snprintf(buf+len, size-len, "Unused\n");
332 goto skipit;
333 }
334 }
335 else {
336 if ((j >= hbqs->hbqPutIdx) &&
337 (j < (hbqs->entry_count+low))) {
338 len += snprintf(buf+len, size-len, "Unused\n");
339 goto skipit;
340 }
341 }
342
343 /* Get the Buffer info for the posted buffer */
344 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
345 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
346 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
347 if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
348 len += snprintf(buf+len, size-len,
349 "Buf%d: %p %06x\n", i,
350 hbq_buf->dbuf.virt, hbq_buf->tag);
351 found = 1;
352 break;
353 }
354 i++;
355 }
356 if (!found) {
357 len += snprintf(buf+len, size-len, "No DMAinfo?\n");
358 }
359 skipit:
360 hbqe++;
361 if (len > LPFC_HBQINFO_SIZE - 54)
362 break;
363 }
364 spin_unlock_irq(&phba->hbalock);
365 return len;
366 }
367
368 static int lpfc_debugfs_last_hba_slim_off;
369
370 /**
371 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
372 * @phba: The HBA to gather SLIM info from.
373 * @buf: The buffer to dump log into.
374 * @size: The maximum amount of data to process.
375 *
376 * Description:
377 * This routine dumps the current contents of HBA SLIM for the HBA associated
378 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
379 *
380 * Notes:
381 * This routine will only dump up to 1024 bytes of data each time called and
382 * should be called multiple times to dump the entire HBA SLIM.
383 *
384 * Return Value:
385 * This routine returns the amount of bytes that were dumped into @buf and will
386 * not exceed @size.
387 **/
388 static int
389 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
390 {
391 int len = 0;
392 int i, off;
393 uint32_t *ptr;
394 char *buffer;
395
396 buffer = kmalloc(1024, GFP_KERNEL);
397 if (!buffer)
398 return 0;
399
400 off = 0;
401 spin_lock_irq(&phba->hbalock);
402
403 len += snprintf(buf+len, size-len, "HBA SLIM\n");
404 lpfc_memcpy_from_slim(buffer,
405 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
406
407 ptr = (uint32_t *)&buffer[0];
408 off = lpfc_debugfs_last_hba_slim_off;
409
410 /* Set it up for the next time */
411 lpfc_debugfs_last_hba_slim_off += 1024;
412 if (lpfc_debugfs_last_hba_slim_off >= 4096)
413 lpfc_debugfs_last_hba_slim_off = 0;
414
415 i = 1024;
416 while (i > 0) {
417 len += snprintf(buf+len, size-len,
418 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
419 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
420 *(ptr+5), *(ptr+6), *(ptr+7));
421 ptr += 8;
422 i -= (8 * sizeof(uint32_t));
423 off += (8 * sizeof(uint32_t));
424 }
425
426 spin_unlock_irq(&phba->hbalock);
427 kfree(buffer);
428
429 return len;
430 }
431
432 /**
433 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
434 * @phba: The HBA to gather Host SLIM info from.
435 * @buf: The buffer to dump log into.
436 * @size: The maximum amount of data to process.
437 *
438 * Description:
439 * This routine dumps the current contents of host SLIM for the host associated
440 * with @phba to @buf up to @size bytes of data. The dump will contain the
441 * Mailbox, PCB, Rings, and Registers that are located in host memory.
442 *
443 * Return Value:
444 * This routine returns the amount of bytes that were dumped into @buf and will
445 * not exceed @size.
446 **/
447 static int
448 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
449 {
450 int len = 0;
451 int i, off;
452 uint32_t word0, word1, word2, word3;
453 uint32_t *ptr;
454 struct lpfc_pgp *pgpp;
455 struct lpfc_sli *psli = &phba->sli;
456 struct lpfc_sli_ring *pring;
457
458 off = 0;
459 spin_lock_irq(&phba->hbalock);
460
461 len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
462 ptr = (uint32_t *)phba->slim2p.virt;
463 i = sizeof(MAILBOX_t);
464 while (i > 0) {
465 len += snprintf(buf+len, size-len,
466 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
467 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
468 *(ptr+5), *(ptr+6), *(ptr+7));
469 ptr += 8;
470 i -= (8 * sizeof(uint32_t));
471 off += (8 * sizeof(uint32_t));
472 }
473
474 len += snprintf(buf+len, size-len, "SLIM PCB\n");
475 ptr = (uint32_t *)phba->pcb;
476 i = sizeof(PCB_t);
477 while (i > 0) {
478 len += snprintf(buf+len, size-len,
479 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
480 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
481 *(ptr+5), *(ptr+6), *(ptr+7));
482 ptr += 8;
483 i -= (8 * sizeof(uint32_t));
484 off += (8 * sizeof(uint32_t));
485 }
486
487 for (i = 0; i < 4; i++) {
488 pgpp = &phba->port_gp[i];
489 pring = &psli->ring[i];
490 len += snprintf(buf+len, size-len,
491 "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
492 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
493 i, pgpp->cmdGetInx, pring->numCiocb,
494 pring->next_cmdidx, pring->local_getidx,
495 pring->flag, pgpp->rspPutInx, pring->numRiocb);
496 }
497
498 if (phba->sli_rev <= LPFC_SLI_REV3) {
499 word0 = readl(phba->HAregaddr);
500 word1 = readl(phba->CAregaddr);
501 word2 = readl(phba->HSregaddr);
502 word3 = readl(phba->HCregaddr);
503 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
504 "HC:%08x\n", word0, word1, word2, word3);
505 }
506 spin_unlock_irq(&phba->hbalock);
507 return len;
508 }
509
510 /**
511 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
512 * @vport: The vport to gather target node info from.
513 * @buf: The buffer to dump log into.
514 * @size: The maximum amount of data to process.
515 *
516 * Description:
517 * This routine dumps the current target node list associated with @vport to
518 * @buf up to @size bytes of data. Each node entry in the dump will contain a
519 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
520 *
521 * Return Value:
522 * This routine returns the amount of bytes that were dumped into @buf and will
523 * not exceed @size.
524 **/
525 static int
526 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
527 {
528 int len = 0;
529 int cnt;
530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
531 struct lpfc_nodelist *ndlp;
532 unsigned char *statep, *name;
533
534 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
535
536 spin_lock_irq(shost->host_lock);
537 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
538 if (!cnt) {
539 len += snprintf(buf+len, size-len,
540 "Missing Nodelist Entries\n");
541 break;
542 }
543 cnt--;
544 switch (ndlp->nlp_state) {
545 case NLP_STE_UNUSED_NODE:
546 statep = "UNUSED";
547 break;
548 case NLP_STE_PLOGI_ISSUE:
549 statep = "PLOGI ";
550 break;
551 case NLP_STE_ADISC_ISSUE:
552 statep = "ADISC ";
553 break;
554 case NLP_STE_REG_LOGIN_ISSUE:
555 statep = "REGLOG";
556 break;
557 case NLP_STE_PRLI_ISSUE:
558 statep = "PRLI ";
559 break;
560 case NLP_STE_UNMAPPED_NODE:
561 statep = "UNMAP ";
562 break;
563 case NLP_STE_MAPPED_NODE:
564 statep = "MAPPED";
565 break;
566 case NLP_STE_NPR_NODE:
567 statep = "NPR ";
568 break;
569 default:
570 statep = "UNKNOWN";
571 }
572 len += snprintf(buf+len, size-len, "%s DID:x%06x ",
573 statep, ndlp->nlp_DID);
574 name = (unsigned char *)&ndlp->nlp_portname;
575 len += snprintf(buf+len, size-len,
576 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
577 *name, *(name+1), *(name+2), *(name+3),
578 *(name+4), *(name+5), *(name+6), *(name+7));
579 name = (unsigned char *)&ndlp->nlp_nodename;
580 len += snprintf(buf+len, size-len,
581 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
582 *name, *(name+1), *(name+2), *(name+3),
583 *(name+4), *(name+5), *(name+6), *(name+7));
584 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
585 ndlp->nlp_rpi, ndlp->nlp_flag);
586 if (!ndlp->nlp_type)
587 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
588 if (ndlp->nlp_type & NLP_FC_NODE)
589 len += snprintf(buf+len, size-len, "FC_NODE ");
590 if (ndlp->nlp_type & NLP_FABRIC)
591 len += snprintf(buf+len, size-len, "FABRIC ");
592 if (ndlp->nlp_type & NLP_FCP_TARGET)
593 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
594 ndlp->nlp_sid);
595 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
596 len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
597 len += snprintf(buf+len, size-len, "usgmap:%x ",
598 ndlp->nlp_usg_map);
599 len += snprintf(buf+len, size-len, "refcnt:%x",
600 atomic_read(&ndlp->kref.refcount));
601 len += snprintf(buf+len, size-len, "\n");
602 }
603 spin_unlock_irq(shost->host_lock);
604 return len;
605 }
606 #endif
607
608 /**
609 * lpfc_debugfs_disc_trc - Store discovery trace log
610 * @vport: The vport to associate this trace string with for retrieval.
611 * @mask: Log entry classification.
612 * @fmt: Format string to be displayed when dumping the log.
613 * @data1: 1st data parameter to be applied to @fmt.
614 * @data2: 2nd data parameter to be applied to @fmt.
615 * @data3: 3rd data parameter to be applied to @fmt.
616 *
617 * Description:
618 * This routine is used by the driver code to add a debugfs log entry to the
619 * discovery trace buffer associated with @vport. Only entries with a @mask that
620 * match the current debugfs discovery mask will be saved. Entries that do not
621 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
622 * printf when displaying the log.
623 **/
624 inline void
625 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
626 uint32_t data1, uint32_t data2, uint32_t data3)
627 {
628 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
629 struct lpfc_debugfs_trc *dtp;
630 int index;
631
632 if (!(lpfc_debugfs_mask_disc_trc & mask))
633 return;
634
635 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
636 !vport || !vport->disc_trc)
637 return;
638
639 index = atomic_inc_return(&vport->disc_trc_cnt) &
640 (lpfc_debugfs_max_disc_trc - 1);
641 dtp = vport->disc_trc + index;
642 dtp->fmt = fmt;
643 dtp->data1 = data1;
644 dtp->data2 = data2;
645 dtp->data3 = data3;
646 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
647 dtp->jif = jiffies;
648 #endif
649 return;
650 }
651
652 /**
653 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
654 * @phba: The phba to associate this trace string with for retrieval.
655 * @fmt: Format string to be displayed when dumping the log.
656 * @data1: 1st data parameter to be applied to @fmt.
657 * @data2: 2nd data parameter to be applied to @fmt.
658 * @data3: 3rd data parameter to be applied to @fmt.
659 *
660 * Description:
661 * This routine is used by the driver code to add a debugfs log entry to the
662 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
663 * @data3 are used like printf when displaying the log.
664 **/
665 inline void
666 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
667 uint32_t data1, uint32_t data2, uint32_t data3)
668 {
669 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
670 struct lpfc_debugfs_trc *dtp;
671 int index;
672
673 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
674 !phba || !phba->slow_ring_trc)
675 return;
676
677 index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
678 (lpfc_debugfs_max_slow_ring_trc - 1);
679 dtp = phba->slow_ring_trc + index;
680 dtp->fmt = fmt;
681 dtp->data1 = data1;
682 dtp->data2 = data2;
683 dtp->data3 = data3;
684 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
685 dtp->jif = jiffies;
686 #endif
687 return;
688 }
689
690 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
691 /**
692 * lpfc_debugfs_disc_trc_open - Open the discovery trace log
693 * @inode: The inode pointer that contains a vport pointer.
694 * @file: The file pointer to attach the log output.
695 *
696 * Description:
697 * This routine is the entry point for the debugfs open file operation. It gets
698 * the vport from the i_private field in @inode, allocates the necessary buffer
699 * for the log, fills the buffer from the in-memory log for this vport, and then
700 * returns a pointer to that log in the private_data field in @file.
701 *
702 * Returns:
703 * This function returns zero if successful. On error it will return an negative
704 * error value.
705 **/
706 static int
707 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
708 {
709 struct lpfc_vport *vport = inode->i_private;
710 struct lpfc_debug *debug;
711 int size;
712 int rc = -ENOMEM;
713
714 if (!lpfc_debugfs_max_disc_trc) {
715 rc = -ENOSPC;
716 goto out;
717 }
718
719 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
720 if (!debug)
721 goto out;
722
723 /* Round to page boundary */
724 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
725 size = PAGE_ALIGN(size);
726
727 debug->buffer = kmalloc(size, GFP_KERNEL);
728 if (!debug->buffer) {
729 kfree(debug);
730 goto out;
731 }
732
733 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
734 file->private_data = debug;
735
736 rc = 0;
737 out:
738 return rc;
739 }
740
741 /**
742 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
743 * @inode: The inode pointer that contains a vport pointer.
744 * @file: The file pointer to attach the log output.
745 *
746 * Description:
747 * This routine is the entry point for the debugfs open file operation. It gets
748 * the vport from the i_private field in @inode, allocates the necessary buffer
749 * for the log, fills the buffer from the in-memory log for this vport, and then
750 * returns a pointer to that log in the private_data field in @file.
751 *
752 * Returns:
753 * This function returns zero if successful. On error it will return an negative
754 * error value.
755 **/
756 static int
757 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
758 {
759 struct lpfc_hba *phba = inode->i_private;
760 struct lpfc_debug *debug;
761 int size;
762 int rc = -ENOMEM;
763
764 if (!lpfc_debugfs_max_slow_ring_trc) {
765 rc = -ENOSPC;
766 goto out;
767 }
768
769 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
770 if (!debug)
771 goto out;
772
773 /* Round to page boundary */
774 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
775 size = PAGE_ALIGN(size);
776
777 debug->buffer = kmalloc(size, GFP_KERNEL);
778 if (!debug->buffer) {
779 kfree(debug);
780 goto out;
781 }
782
783 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
784 file->private_data = debug;
785
786 rc = 0;
787 out:
788 return rc;
789 }
790
791 /**
792 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
793 * @inode: The inode pointer that contains a vport pointer.
794 * @file: The file pointer to attach the log output.
795 *
796 * Description:
797 * This routine is the entry point for the debugfs open file operation. It gets
798 * the vport from the i_private field in @inode, allocates the necessary buffer
799 * for the log, fills the buffer from the in-memory log for this vport, and then
800 * returns a pointer to that log in the private_data field in @file.
801 *
802 * Returns:
803 * This function returns zero if successful. On error it will return an negative
804 * error value.
805 **/
806 static int
807 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
808 {
809 struct lpfc_hba *phba = inode->i_private;
810 struct lpfc_debug *debug;
811 int rc = -ENOMEM;
812
813 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
814 if (!debug)
815 goto out;
816
817 /* Round to page boundary */
818 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
819 if (!debug->buffer) {
820 kfree(debug);
821 goto out;
822 }
823
824 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
825 LPFC_HBQINFO_SIZE);
826 file->private_data = debug;
827
828 rc = 0;
829 out:
830 return rc;
831 }
832
833 /**
834 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
835 * @inode: The inode pointer that contains a vport pointer.
836 * @file: The file pointer to attach the log output.
837 *
838 * Description:
839 * This routine is the entry point for the debugfs open file operation. It gets
840 * the vport from the i_private field in @inode, allocates the necessary buffer
841 * for the log, fills the buffer from the in-memory log for this vport, and then
842 * returns a pointer to that log in the private_data field in @file.
843 *
844 * Returns:
845 * This function returns zero if successful. On error it will return an negative
846 * error value.
847 **/
848 static int
849 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
850 {
851 struct lpfc_hba *phba = inode->i_private;
852 struct lpfc_debug *debug;
853 int rc = -ENOMEM;
854
855 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
856 if (!debug)
857 goto out;
858
859 /* Round to page boundary */
860 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
861 if (!debug->buffer) {
862 kfree(debug);
863 goto out;
864 }
865
866 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
867 LPFC_DUMPHBASLIM_SIZE);
868 file->private_data = debug;
869
870 rc = 0;
871 out:
872 return rc;
873 }
874
875 /**
876 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
877 * @inode: The inode pointer that contains a vport pointer.
878 * @file: The file pointer to attach the log output.
879 *
880 * Description:
881 * This routine is the entry point for the debugfs open file operation. It gets
882 * the vport from the i_private field in @inode, allocates the necessary buffer
883 * for the log, fills the buffer from the in-memory log for this vport, and then
884 * returns a pointer to that log in the private_data field in @file.
885 *
886 * Returns:
887 * This function returns zero if successful. On error it will return an negative
888 * error value.
889 **/
890 static int
891 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
892 {
893 struct lpfc_hba *phba = inode->i_private;
894 struct lpfc_debug *debug;
895 int rc = -ENOMEM;
896
897 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
898 if (!debug)
899 goto out;
900
901 /* Round to page boundary */
902 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
903 if (!debug->buffer) {
904 kfree(debug);
905 goto out;
906 }
907
908 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
909 LPFC_DUMPHOSTSLIM_SIZE);
910 file->private_data = debug;
911
912 rc = 0;
913 out:
914 return rc;
915 }
916
917 static int
918 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
919 {
920 struct lpfc_debug *debug;
921 int rc = -ENOMEM;
922
923 if (!_dump_buf_data)
924 return -EBUSY;
925
926 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
927 if (!debug)
928 goto out;
929
930 /* Round to page boundary */
931 printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
932 __func__, _dump_buf_data);
933 debug->buffer = _dump_buf_data;
934 if (!debug->buffer) {
935 kfree(debug);
936 goto out;
937 }
938
939 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
940 file->private_data = debug;
941
942 rc = 0;
943 out:
944 return rc;
945 }
946
947 static int
948 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
949 {
950 struct lpfc_debug *debug;
951 int rc = -ENOMEM;
952
953 if (!_dump_buf_dif)
954 return -EBUSY;
955
956 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
957 if (!debug)
958 goto out;
959
960 /* Round to page boundary */
961 printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
962 __func__, _dump_buf_dif, file->f_dentry->d_name.name);
963 debug->buffer = _dump_buf_dif;
964 if (!debug->buffer) {
965 kfree(debug);
966 goto out;
967 }
968
969 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
970 file->private_data = debug;
971
972 rc = 0;
973 out:
974 return rc;
975 }
976
977 static ssize_t
978 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
979 size_t nbytes, loff_t *ppos)
980 {
981 /*
982 * The Data/DIF buffers only save one failing IO
983 * The write op is used as a reset mechanism after an IO has
984 * already been saved to the next one can be saved
985 */
986 spin_lock(&_dump_buf_lock);
987
988 memset((void *)_dump_buf_data, 0,
989 ((1 << PAGE_SHIFT) << _dump_buf_data_order));
990 memset((void *)_dump_buf_dif, 0,
991 ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
992
993 _dump_buf_done = 0;
994
995 spin_unlock(&_dump_buf_lock);
996
997 return nbytes;
998 }
999
1000 static ssize_t
1001 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
1002 size_t nbytes, loff_t *ppos)
1003 {
1004 struct dentry *dent = file->f_dentry;
1005 struct lpfc_hba *phba = file->private_data;
1006 char cbuf[32];
1007 uint64_t tmp = 0;
1008 int cnt = 0;
1009
1010 if (dent == phba->debug_writeGuard)
1011 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
1012 else if (dent == phba->debug_writeApp)
1013 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
1014 else if (dent == phba->debug_writeRef)
1015 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
1016 else if (dent == phba->debug_readGuard)
1017 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
1018 else if (dent == phba->debug_readApp)
1019 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
1020 else if (dent == phba->debug_readRef)
1021 cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
1022 else if (dent == phba->debug_InjErrNPortID)
1023 cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid);
1024 else if (dent == phba->debug_InjErrWWPN) {
1025 memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
1026 tmp = cpu_to_be64(tmp);
1027 cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp);
1028 } else if (dent == phba->debug_InjErrLBA) {
1029 if (phba->lpfc_injerr_lba == (sector_t)(-1))
1030 cnt = snprintf(cbuf, 32, "off\n");
1031 else
1032 cnt = snprintf(cbuf, 32, "0x%llx\n",
1033 (uint64_t) phba->lpfc_injerr_lba);
1034 } else
1035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1036 "0547 Unknown debugfs error injection entry\n");
1037
1038 return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
1039 }
1040
1041 static ssize_t
1042 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
1043 size_t nbytes, loff_t *ppos)
1044 {
1045 struct dentry *dent = file->f_dentry;
1046 struct lpfc_hba *phba = file->private_data;
1047 char dstbuf[32];
1048 uint64_t tmp = 0;
1049 int size;
1050
1051 memset(dstbuf, 0, 32);
1052 size = (nbytes < 32) ? nbytes : 32;
1053 if (copy_from_user(dstbuf, buf, size))
1054 return 0;
1055
1056 if (dent == phba->debug_InjErrLBA) {
1057 if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f'))
1058 tmp = (uint64_t)(-1);
1059 }
1060
1061 if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
1062 return 0;
1063
1064 if (dent == phba->debug_writeGuard)
1065 phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
1066 else if (dent == phba->debug_writeApp)
1067 phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
1068 else if (dent == phba->debug_writeRef)
1069 phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
1070 else if (dent == phba->debug_readGuard)
1071 phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
1072 else if (dent == phba->debug_readApp)
1073 phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
1074 else if (dent == phba->debug_readRef)
1075 phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
1076 else if (dent == phba->debug_InjErrLBA)
1077 phba->lpfc_injerr_lba = (sector_t)tmp;
1078 else if (dent == phba->debug_InjErrNPortID)
1079 phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
1080 else if (dent == phba->debug_InjErrWWPN) {
1081 tmp = cpu_to_be64(tmp);
1082 memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
1083 } else
1084 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1085 "0548 Unknown debugfs error injection entry\n");
1086
1087 return nbytes;
1088 }
1089
1090 static int
1091 lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
1092 {
1093 return 0;
1094 }
1095
1096 /**
1097 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
1098 * @inode: The inode pointer that contains a vport pointer.
1099 * @file: The file pointer to attach the log output.
1100 *
1101 * Description:
1102 * This routine is the entry point for the debugfs open file operation. It gets
1103 * the vport from the i_private field in @inode, allocates the necessary buffer
1104 * for the log, fills the buffer from the in-memory log for this vport, and then
1105 * returns a pointer to that log in the private_data field in @file.
1106 *
1107 * Returns:
1108 * This function returns zero if successful. On error it will return an negative
1109 * error value.
1110 **/
1111 static int
1112 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
1113 {
1114 struct lpfc_vport *vport = inode->i_private;
1115 struct lpfc_debug *debug;
1116 int rc = -ENOMEM;
1117
1118 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1119 if (!debug)
1120 goto out;
1121
1122 /* Round to page boundary */
1123 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
1124 if (!debug->buffer) {
1125 kfree(debug);
1126 goto out;
1127 }
1128
1129 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
1130 LPFC_NODELIST_SIZE);
1131 file->private_data = debug;
1132
1133 rc = 0;
1134 out:
1135 return rc;
1136 }
1137
1138 /**
1139 * lpfc_debugfs_lseek - Seek through a debugfs file
1140 * @file: The file pointer to seek through.
1141 * @off: The offset to seek to or the amount to seek by.
1142 * @whence: Indicates how to seek.
1143 *
1144 * Description:
1145 * This routine is the entry point for the debugfs lseek file operation. The
1146 * @whence parameter indicates whether @off is the offset to directly seek to,
1147 * or if it is a value to seek forward or reverse by. This function figures out
1148 * what the new offset of the debugfs file will be and assigns that value to the
1149 * f_pos field of @file.
1150 *
1151 * Returns:
1152 * This function returns the new offset if successful and returns a negative
1153 * error if unable to process the seek.
1154 **/
1155 static loff_t
1156 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
1157 {
1158 struct lpfc_debug *debug;
1159 loff_t pos = -1;
1160
1161 debug = file->private_data;
1162
1163 switch (whence) {
1164 case 0:
1165 pos = off;
1166 break;
1167 case 1:
1168 pos = file->f_pos + off;
1169 break;
1170 case 2:
1171 pos = debug->len - off;
1172 }
1173 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
1174 }
1175
1176 /**
1177 * lpfc_debugfs_read - Read a debugfs file
1178 * @file: The file pointer to read from.
1179 * @buf: The buffer to copy the data to.
1180 * @nbytes: The number of bytes to read.
1181 * @ppos: The position in the file to start reading from.
1182 *
1183 * Description:
1184 * This routine reads data from from the buffer indicated in the private_data
1185 * field of @file. It will start reading at @ppos and copy up to @nbytes of
1186 * data to @buf.
1187 *
1188 * Returns:
1189 * This function returns the amount of data that was read (this could be less
1190 * than @nbytes if the end of the file was reached) or a negative error value.
1191 **/
1192 static ssize_t
1193 lpfc_debugfs_read(struct file *file, char __user *buf,
1194 size_t nbytes, loff_t *ppos)
1195 {
1196 struct lpfc_debug *debug = file->private_data;
1197
1198 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
1199 debug->len);
1200 }
1201
1202 /**
1203 * lpfc_debugfs_release - Release the buffer used to store debugfs file data
1204 * @inode: The inode pointer that contains a vport pointer. (unused)
1205 * @file: The file pointer that contains the buffer to release.
1206 *
1207 * Description:
1208 * This routine frees the buffer that was allocated when the debugfs file was
1209 * opened.
1210 *
1211 * Returns:
1212 * This function returns zero.
1213 **/
1214 static int
1215 lpfc_debugfs_release(struct inode *inode, struct file *file)
1216 {
1217 struct lpfc_debug *debug = file->private_data;
1218
1219 kfree(debug->buffer);
1220 kfree(debug);
1221
1222 return 0;
1223 }
1224
1225 static int
1226 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
1227 {
1228 struct lpfc_debug *debug = file->private_data;
1229
1230 debug->buffer = NULL;
1231 kfree(debug);
1232
1233 return 0;
1234 }
1235
1236 /*
1237 * ---------------------------------
1238 * iDiag debugfs file access methods
1239 * ---------------------------------
1240 *
1241 * All access methods are through the proper SLI4 PCI function's debugfs
1242 * iDiag directory:
1243 *
1244 * /sys/kernel/debug/lpfc/fn<#>/iDiag
1245 */
1246
1247 /**
1248 * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
1249 * @buf: The pointer to the user space buffer.
1250 * @nbytes: The number of bytes in the user space buffer.
1251 * @idiag_cmd: pointer to the idiag command struct.
1252 *
1253 * This routine reads data from debugfs user space buffer and parses the
1254 * buffer for getting the idiag command and arguments. The while space in
1255 * between the set of data is used as the parsing separator.
1256 *
1257 * This routine returns 0 when successful, it returns proper error code
1258 * back to the user space in error conditions.
1259 */
1260 static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
1261 struct lpfc_idiag_cmd *idiag_cmd)
1262 {
1263 char mybuf[64];
1264 char *pbuf, *step_str;
1265 int i;
1266 size_t bsize;
1267
1268 /* Protect copy from user */
1269 if (!access_ok(VERIFY_READ, buf, nbytes))
1270 return -EFAULT;
1271
1272 memset(mybuf, 0, sizeof(mybuf));
1273 memset(idiag_cmd, 0, sizeof(*idiag_cmd));
1274 bsize = min(nbytes, (sizeof(mybuf)-1));
1275
1276 if (copy_from_user(mybuf, buf, bsize))
1277 return -EFAULT;
1278 pbuf = &mybuf[0];
1279 step_str = strsep(&pbuf, "\t ");
1280
1281 /* The opcode must present */
1282 if (!step_str)
1283 return -EINVAL;
1284
1285 idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
1286 if (idiag_cmd->opcode == 0)
1287 return -EINVAL;
1288
1289 for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
1290 step_str = strsep(&pbuf, "\t ");
1291 if (!step_str)
1292 return i;
1293 idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
1294 }
1295 return i;
1296 }
1297
1298 /**
1299 * lpfc_idiag_open - idiag open debugfs
1300 * @inode: The inode pointer that contains a pointer to phba.
1301 * @file: The file pointer to attach the file operation.
1302 *
1303 * Description:
1304 * This routine is the entry point for the debugfs open file operation. It
1305 * gets the reference to phba from the i_private field in @inode, it then
1306 * allocates buffer for the file operation, performs the necessary PCI config
1307 * space read into the allocated buffer according to the idiag user command
1308 * setup, and then returns a pointer to buffer in the private_data field in
1309 * @file.
1310 *
1311 * Returns:
1312 * This function returns zero if successful. On error it will return an
1313 * negative error value.
1314 **/
1315 static int
1316 lpfc_idiag_open(struct inode *inode, struct file *file)
1317 {
1318 struct lpfc_debug *debug;
1319
1320 debug = kmalloc(sizeof(*debug), GFP_KERNEL);
1321 if (!debug)
1322 return -ENOMEM;
1323
1324 debug->i_private = inode->i_private;
1325 debug->buffer = NULL;
1326 file->private_data = debug;
1327
1328 return 0;
1329 }
1330
1331 /**
1332 * lpfc_idiag_release - Release idiag access file operation
1333 * @inode: The inode pointer that contains a vport pointer. (unused)
1334 * @file: The file pointer that contains the buffer to release.
1335 *
1336 * Description:
1337 * This routine is the generic release routine for the idiag access file
1338 * operation, it frees the buffer that was allocated when the debugfs file
1339 * was opened.
1340 *
1341 * Returns:
1342 * This function returns zero.
1343 **/
1344 static int
1345 lpfc_idiag_release(struct inode *inode, struct file *file)
1346 {
1347 struct lpfc_debug *debug = file->private_data;
1348
1349 /* Free the buffers to the file operation */
1350 kfree(debug->buffer);
1351 kfree(debug);
1352
1353 return 0;
1354 }
1355
1356 /**
1357 * lpfc_idiag_cmd_release - Release idiag cmd access file operation
1358 * @inode: The inode pointer that contains a vport pointer. (unused)
1359 * @file: The file pointer that contains the buffer to release.
1360 *
1361 * Description:
1362 * This routine frees the buffer that was allocated when the debugfs file
1363 * was opened. It also reset the fields in the idiag command struct in the
1364 * case of command for write operation.
1365 *
1366 * Returns:
1367 * This function returns zero.
1368 **/
1369 static int
1370 lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
1371 {
1372 struct lpfc_debug *debug = file->private_data;
1373
1374 if (debug->op == LPFC_IDIAG_OP_WR) {
1375 switch (idiag.cmd.opcode) {
1376 case LPFC_IDIAG_CMD_PCICFG_WR:
1377 case LPFC_IDIAG_CMD_PCICFG_ST:
1378 case LPFC_IDIAG_CMD_PCICFG_CL:
1379 case LPFC_IDIAG_CMD_QUEACC_WR:
1380 case LPFC_IDIAG_CMD_QUEACC_ST:
1381 case LPFC_IDIAG_CMD_QUEACC_CL:
1382 memset(&idiag, 0, sizeof(idiag));
1383 break;
1384 default:
1385 break;
1386 }
1387 }
1388
1389 /* Free the buffers to the file operation */
1390 kfree(debug->buffer);
1391 kfree(debug);
1392
1393 return 0;
1394 }
1395
1396 /**
1397 * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
1398 * @file: The file pointer to read from.
1399 * @buf: The buffer to copy the data to.
1400 * @nbytes: The number of bytes to read.
1401 * @ppos: The position in the file to start reading from.
1402 *
1403 * Description:
1404 * This routine reads data from the @phba pci config space according to the
1405 * idiag command, and copies to user @buf. Depending on the PCI config space
1406 * read command setup, it does either a single register read of a byte
1407 * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
1408 * registers from the 4K extended PCI config space.
1409 *
1410 * Returns:
1411 * This function returns the amount of data that was read (this could be less
1412 * than @nbytes if the end of the file was reached) or a negative error value.
1413 **/
1414 static ssize_t
1415 lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
1416 loff_t *ppos)
1417 {
1418 struct lpfc_debug *debug = file->private_data;
1419 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1420 int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
1421 int where, count;
1422 char *pbuffer;
1423 struct pci_dev *pdev;
1424 uint32_t u32val;
1425 uint16_t u16val;
1426 uint8_t u8val;
1427
1428 pdev = phba->pcidev;
1429 if (!pdev)
1430 return 0;
1431
1432 /* This is a user read operation */
1433 debug->op = LPFC_IDIAG_OP_RD;
1434
1435 if (!debug->buffer)
1436 debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
1437 if (!debug->buffer)
1438 return 0;
1439 pbuffer = debug->buffer;
1440
1441 if (*ppos)
1442 return 0;
1443
1444 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1445 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1446 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1447 } else
1448 return 0;
1449
1450 /* Read single PCI config space register */
1451 switch (count) {
1452 case SIZE_U8: /* byte (8 bits) */
1453 pci_read_config_byte(pdev, where, &u8val);
1454 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1455 "%03x: %02x\n", where, u8val);
1456 break;
1457 case SIZE_U16: /* word (16 bits) */
1458 pci_read_config_word(pdev, where, &u16val);
1459 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1460 "%03x: %04x\n", where, u16val);
1461 break;
1462 case SIZE_U32: /* double word (32 bits) */
1463 pci_read_config_dword(pdev, where, &u32val);
1464 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1465 "%03x: %08x\n", where, u32val);
1466 break;
1467 case LPFC_PCI_CFG_BROWSE: /* browse all */
1468 goto pcicfg_browse;
1469 break;
1470 default:
1471 /* illegal count */
1472 len = 0;
1473 break;
1474 }
1475 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1476
1477 pcicfg_browse:
1478
1479 /* Browse all PCI config space registers */
1480 offset_label = idiag.offset.last_rd;
1481 offset = offset_label;
1482
1483 /* Read PCI config space */
1484 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1485 "%03x: ", offset_label);
1486 while (index > 0) {
1487 pci_read_config_dword(pdev, offset, &u32val);
1488 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1489 "%08x ", u32val);
1490 offset += sizeof(uint32_t);
1491 if (offset >= LPFC_PCI_CFG_SIZE) {
1492 len += snprintf(pbuffer+len,
1493 LPFC_PCI_CFG_SIZE-len, "\n");
1494 break;
1495 }
1496 index -= sizeof(uint32_t);
1497 if (!index)
1498 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1499 "\n");
1500 else if (!(index % (8 * sizeof(uint32_t)))) {
1501 offset_label += (8 * sizeof(uint32_t));
1502 len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
1503 "\n%03x: ", offset_label);
1504 }
1505 }
1506
1507 /* Set up the offset for next portion of pci cfg read */
1508 if (index == 0) {
1509 idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
1510 if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
1511 idiag.offset.last_rd = 0;
1512 } else
1513 idiag.offset.last_rd = 0;
1514
1515 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1516 }
1517
1518 /**
1519 * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
1520 * @file: The file pointer to read from.
1521 * @buf: The buffer to copy the user data from.
1522 * @nbytes: The number of bytes to get.
1523 * @ppos: The position in the file to start reading from.
1524 *
1525 * This routine get the debugfs idiag command struct from user space and
1526 * then perform the syntax check for PCI config space read or write command
1527 * accordingly. In the case of PCI config space read command, it sets up
1528 * the command in the idiag command struct for the debugfs read operation.
1529 * In the case of PCI config space write operation, it executes the write
1530 * operation into the PCI config space accordingly.
1531 *
1532 * It returns the @nbytges passing in from debugfs user space when successful.
1533 * In case of error conditions, it returns proper error code back to the user
1534 * space.
1535 */
1536 static ssize_t
1537 lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
1538 size_t nbytes, loff_t *ppos)
1539 {
1540 struct lpfc_debug *debug = file->private_data;
1541 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1542 uint32_t where, value, count;
1543 uint32_t u32val;
1544 uint16_t u16val;
1545 uint8_t u8val;
1546 struct pci_dev *pdev;
1547 int rc;
1548
1549 pdev = phba->pcidev;
1550 if (!pdev)
1551 return -EFAULT;
1552
1553 /* This is a user write operation */
1554 debug->op = LPFC_IDIAG_OP_WR;
1555
1556 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1557 if (rc < 0)
1558 return rc;
1559
1560 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
1561 /* Sanity check on PCI config read command line arguments */
1562 if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
1563 goto error_out;
1564 /* Read command from PCI config space, set up command fields */
1565 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1566 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1567 if (count == LPFC_PCI_CFG_BROWSE) {
1568 if (where % sizeof(uint32_t))
1569 goto error_out;
1570 /* Starting offset to browse */
1571 idiag.offset.last_rd = where;
1572 } else if ((count != sizeof(uint8_t)) &&
1573 (count != sizeof(uint16_t)) &&
1574 (count != sizeof(uint32_t)))
1575 goto error_out;
1576 if (count == sizeof(uint8_t)) {
1577 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1578 goto error_out;
1579 if (where % sizeof(uint8_t))
1580 goto error_out;
1581 }
1582 if (count == sizeof(uint16_t)) {
1583 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1584 goto error_out;
1585 if (where % sizeof(uint16_t))
1586 goto error_out;
1587 }
1588 if (count == sizeof(uint32_t)) {
1589 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1590 goto error_out;
1591 if (where % sizeof(uint32_t))
1592 goto error_out;
1593 }
1594 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
1595 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
1596 idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1597 /* Sanity check on PCI config write command line arguments */
1598 if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
1599 goto error_out;
1600 /* Write command to PCI config space, read-modify-write */
1601 where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
1602 count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
1603 value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
1604 /* Sanity checks */
1605 if ((count != sizeof(uint8_t)) &&
1606 (count != sizeof(uint16_t)) &&
1607 (count != sizeof(uint32_t)))
1608 goto error_out;
1609 if (count == sizeof(uint8_t)) {
1610 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
1611 goto error_out;
1612 if (where % sizeof(uint8_t))
1613 goto error_out;
1614 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1615 pci_write_config_byte(pdev, where,
1616 (uint8_t)value);
1617 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1618 rc = pci_read_config_byte(pdev, where, &u8val);
1619 if (!rc) {
1620 u8val |= (uint8_t)value;
1621 pci_write_config_byte(pdev, where,
1622 u8val);
1623 }
1624 }
1625 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1626 rc = pci_read_config_byte(pdev, where, &u8val);
1627 if (!rc) {
1628 u8val &= (uint8_t)(~value);
1629 pci_write_config_byte(pdev, where,
1630 u8val);
1631 }
1632 }
1633 }
1634 if (count == sizeof(uint16_t)) {
1635 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
1636 goto error_out;
1637 if (where % sizeof(uint16_t))
1638 goto error_out;
1639 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1640 pci_write_config_word(pdev, where,
1641 (uint16_t)value);
1642 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1643 rc = pci_read_config_word(pdev, where, &u16val);
1644 if (!rc) {
1645 u16val |= (uint16_t)value;
1646 pci_write_config_word(pdev, where,
1647 u16val);
1648 }
1649 }
1650 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1651 rc = pci_read_config_word(pdev, where, &u16val);
1652 if (!rc) {
1653 u16val &= (uint16_t)(~value);
1654 pci_write_config_word(pdev, where,
1655 u16val);
1656 }
1657 }
1658 }
1659 if (count == sizeof(uint32_t)) {
1660 if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
1661 goto error_out;
1662 if (where % sizeof(uint32_t))
1663 goto error_out;
1664 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
1665 pci_write_config_dword(pdev, where, value);
1666 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
1667 rc = pci_read_config_dword(pdev, where,
1668 &u32val);
1669 if (!rc) {
1670 u32val |= value;
1671 pci_write_config_dword(pdev, where,
1672 u32val);
1673 }
1674 }
1675 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
1676 rc = pci_read_config_dword(pdev, where,
1677 &u32val);
1678 if (!rc) {
1679 u32val &= ~value;
1680 pci_write_config_dword(pdev, where,
1681 u32val);
1682 }
1683 }
1684 }
1685 } else
1686 /* All other opecodes are illegal for now */
1687 goto error_out;
1688
1689 return nbytes;
1690 error_out:
1691 memset(&idiag, 0, sizeof(idiag));
1692 return -EINVAL;
1693 }
1694
1695 /**
1696 * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
1697 * @file: The file pointer to read from.
1698 * @buf: The buffer to copy the data to.
1699 * @nbytes: The number of bytes to read.
1700 * @ppos: The position in the file to start reading from.
1701 *
1702 * Description:
1703 * This routine reads data from the @phba pci bar memory mapped space
1704 * according to the idiag command, and copies to user @buf.
1705 *
1706 * Returns:
1707 * This function returns the amount of data that was read (this could be less
1708 * than @nbytes if the end of the file was reached) or a negative error value.
1709 **/
1710 static ssize_t
1711 lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
1712 loff_t *ppos)
1713 {
1714 struct lpfc_debug *debug = file->private_data;
1715 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1716 int offset_label, offset, offset_run, len = 0, index;
1717 int bar_num, acc_range, bar_size;
1718 char *pbuffer;
1719 void __iomem *mem_mapped_bar;
1720 uint32_t if_type;
1721 struct pci_dev *pdev;
1722 uint32_t u32val;
1723
1724 pdev = phba->pcidev;
1725 if (!pdev)
1726 return 0;
1727
1728 /* This is a user read operation */
1729 debug->op = LPFC_IDIAG_OP_RD;
1730
1731 if (!debug->buffer)
1732 debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
1733 if (!debug->buffer)
1734 return 0;
1735 pbuffer = debug->buffer;
1736
1737 if (*ppos)
1738 return 0;
1739
1740 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1741 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1742 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1743 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1744 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1745 } else
1746 return 0;
1747
1748 if (acc_range == 0)
1749 return 0;
1750
1751 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1752 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1753 if (bar_num == IDIAG_BARACC_BAR_0)
1754 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1755 else if (bar_num == IDIAG_BARACC_BAR_1)
1756 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1757 else if (bar_num == IDIAG_BARACC_BAR_2)
1758 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1759 else
1760 return 0;
1761 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1762 if (bar_num == IDIAG_BARACC_BAR_0)
1763 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1764 else
1765 return 0;
1766 } else
1767 return 0;
1768
1769 /* Read single PCI bar space register */
1770 if (acc_range == SINGLE_WORD) {
1771 offset_run = offset;
1772 u32val = readl(mem_mapped_bar + offset_run);
1773 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1774 "%05x: %08x\n", offset_run, u32val);
1775 } else
1776 goto baracc_browse;
1777
1778 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1779
1780 baracc_browse:
1781
1782 /* Browse all PCI bar space registers */
1783 offset_label = idiag.offset.last_rd;
1784 offset_run = offset_label;
1785
1786 /* Read PCI bar memory mapped space */
1787 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1788 "%05x: ", offset_label);
1789 index = LPFC_PCI_BAR_RD_SIZE;
1790 while (index > 0) {
1791 u32val = readl(mem_mapped_bar + offset_run);
1792 len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
1793 "%08x ", u32val);
1794 offset_run += sizeof(uint32_t);
1795 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1796 if (offset_run >= bar_size) {
1797 len += snprintf(pbuffer+len,
1798 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1799 break;
1800 }
1801 } else {
1802 if (offset_run >= offset +
1803 (acc_range * sizeof(uint32_t))) {
1804 len += snprintf(pbuffer+len,
1805 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1806 break;
1807 }
1808 }
1809 index -= sizeof(uint32_t);
1810 if (!index)
1811 len += snprintf(pbuffer+len,
1812 LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
1813 else if (!(index % (8 * sizeof(uint32_t)))) {
1814 offset_label += (8 * sizeof(uint32_t));
1815 len += snprintf(pbuffer+len,
1816 LPFC_PCI_BAR_RD_BUF_SIZE-len,
1817 "\n%05x: ", offset_label);
1818 }
1819 }
1820
1821 /* Set up the offset for next portion of pci bar read */
1822 if (index == 0) {
1823 idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
1824 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1825 if (idiag.offset.last_rd >= bar_size)
1826 idiag.offset.last_rd = 0;
1827 } else {
1828 if (offset_run >= offset +
1829 (acc_range * sizeof(uint32_t)))
1830 idiag.offset.last_rd = offset;
1831 }
1832 } else {
1833 if (acc_range == LPFC_PCI_BAR_BROWSE)
1834 idiag.offset.last_rd = 0;
1835 else
1836 idiag.offset.last_rd = offset;
1837 }
1838
1839 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
1840 }
1841
1842 /**
1843 * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
1844 * @file: The file pointer to read from.
1845 * @buf: The buffer to copy the user data from.
1846 * @nbytes: The number of bytes to get.
1847 * @ppos: The position in the file to start reading from.
1848 *
1849 * This routine get the debugfs idiag command struct from user space and
1850 * then perform the syntax check for PCI bar memory mapped space read or
1851 * write command accordingly. In the case of PCI bar memory mapped space
1852 * read command, it sets up the command in the idiag command struct for
1853 * the debugfs read operation. In the case of PCI bar memorpy mapped space
1854 * write operation, it executes the write operation into the PCI bar memory
1855 * mapped space accordingly.
1856 *
1857 * It returns the @nbytges passing in from debugfs user space when successful.
1858 * In case of error conditions, it returns proper error code back to the user
1859 * space.
1860 */
1861 static ssize_t
1862 lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
1863 size_t nbytes, loff_t *ppos)
1864 {
1865 struct lpfc_debug *debug = file->private_data;
1866 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
1867 uint32_t bar_num, bar_size, offset, value, acc_range;
1868 struct pci_dev *pdev;
1869 void __iomem *mem_mapped_bar;
1870 uint32_t if_type;
1871 uint32_t u32val;
1872 int rc;
1873
1874 pdev = phba->pcidev;
1875 if (!pdev)
1876 return -EFAULT;
1877
1878 /* This is a user write operation */
1879 debug->op = LPFC_IDIAG_OP_WR;
1880
1881 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
1882 if (rc < 0)
1883 return rc;
1884
1885 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1886 bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
1887
1888 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1889 if ((bar_num != IDIAG_BARACC_BAR_0) &&
1890 (bar_num != IDIAG_BARACC_BAR_1) &&
1891 (bar_num != IDIAG_BARACC_BAR_2))
1892 goto error_out;
1893 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1894 if (bar_num != IDIAG_BARACC_BAR_0)
1895 goto error_out;
1896 } else
1897 goto error_out;
1898
1899 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
1900 if (bar_num == IDIAG_BARACC_BAR_0) {
1901 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1902 LPFC_PCI_IF0_BAR0_SIZE;
1903 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1904 } else if (bar_num == IDIAG_BARACC_BAR_1) {
1905 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1906 LPFC_PCI_IF0_BAR1_SIZE;
1907 mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
1908 } else if (bar_num == IDIAG_BARACC_BAR_2) {
1909 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1910 LPFC_PCI_IF0_BAR2_SIZE;
1911 mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
1912 } else
1913 goto error_out;
1914 } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
1915 if (bar_num == IDIAG_BARACC_BAR_0) {
1916 idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
1917 LPFC_PCI_IF2_BAR0_SIZE;
1918 mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
1919 } else
1920 goto error_out;
1921 } else
1922 goto error_out;
1923
1924 offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
1925 if (offset % sizeof(uint32_t))
1926 goto error_out;
1927
1928 bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
1929 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
1930 /* Sanity check on PCI config read command line arguments */
1931 if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
1932 goto error_out;
1933 acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
1934 if (acc_range == LPFC_PCI_BAR_BROWSE) {
1935 if (offset > bar_size - sizeof(uint32_t))
1936 goto error_out;
1937 /* Starting offset to browse */
1938 idiag.offset.last_rd = offset;
1939 } else if (acc_range > SINGLE_WORD) {
1940 if (offset + acc_range * sizeof(uint32_t) > bar_size)
1941 goto error_out;
1942 /* Starting offset to browse */
1943 idiag.offset.last_rd = offset;
1944 } else if (acc_range != SINGLE_WORD)
1945 goto error_out;
1946 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
1947 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
1948 idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1949 /* Sanity check on PCI bar write command line arguments */
1950 if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
1951 goto error_out;
1952 /* Write command to PCI bar space, read-modify-write */
1953 acc_range = SINGLE_WORD;
1954 value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
1955 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
1956 writel(value, mem_mapped_bar + offset);
1957 readl(mem_mapped_bar + offset);
1958 }
1959 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
1960 u32val = readl(mem_mapped_bar + offset);
1961 u32val |= value;
1962 writel(u32val, mem_mapped_bar + offset);
1963 readl(mem_mapped_bar + offset);
1964 }
1965 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
1966 u32val = readl(mem_mapped_bar + offset);
1967 u32val &= ~value;
1968 writel(u32val, mem_mapped_bar + offset);
1969 readl(mem_mapped_bar + offset);
1970 }
1971 } else
1972 /* All other opecodes are illegal for now */
1973 goto error_out;
1974
1975 return nbytes;
1976 error_out:
1977 memset(&idiag, 0, sizeof(idiag));
1978 return -EINVAL;
1979 }
1980
1981 /**
1982 * lpfc_idiag_queinfo_read - idiag debugfs read queue information
1983 * @file: The file pointer to read from.
1984 * @buf: The buffer to copy the data to.
1985 * @nbytes: The number of bytes to read.
1986 * @ppos: The position in the file to start reading from.
1987 *
1988 * Description:
1989 * This routine reads data from the @phba SLI4 PCI function queue information,
1990 * and copies to user @buf.
1991 *
1992 * Returns:
1993 * This function returns the amount of data that was read (this could be less
1994 * than @nbytes if the end of the file was reached) or a negative error value.
1995 **/
1996 static ssize_t
1997 lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
1998 loff_t *ppos)
1999 {
2000 struct lpfc_debug *debug = file->private_data;
2001 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2002 int len = 0, fcp_qidx;
2003 char *pbuffer;
2004
2005 if (!debug->buffer)
2006 debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
2007 if (!debug->buffer)
2008 return 0;
2009 pbuffer = debug->buffer;
2010
2011 if (*ppos)
2012 return 0;
2013
2014 /* Get slow-path event queue information */
2015 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2016 "Slow-path EQ information:\n");
2017 if (phba->sli4_hba.sp_eq) {
2018 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2019 "\tEQID[%02d], "
2020 "QE-COUNT[%04d], QE-SIZE[%04d], "
2021 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2022 phba->sli4_hba.sp_eq->queue_id,
2023 phba->sli4_hba.sp_eq->entry_count,
2024 phba->sli4_hba.sp_eq->entry_size,
2025 phba->sli4_hba.sp_eq->host_index,
2026 phba->sli4_hba.sp_eq->hba_index);
2027 }
2028
2029 /* Get fast-path event queue information */
2030 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2031 "Fast-path EQ information:\n");
2032 if (phba->sli4_hba.fp_eq) {
2033 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count;
2034 fcp_qidx++) {
2035 if (phba->sli4_hba.fp_eq[fcp_qidx]) {
2036 len += snprintf(pbuffer+len,
2037 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2038 "\tEQID[%02d], "
2039 "QE-COUNT[%04d], QE-SIZE[%04d], "
2040 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2041 phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
2042 phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
2043 phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
2044 phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
2045 phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
2046 }
2047 }
2048 }
2049 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2050
2051 /* Get mailbox complete queue information */
2052 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2053 "Slow-path MBX CQ information:\n");
2054 if (phba->sli4_hba.mbx_cq) {
2055 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2056 "Associated EQID[%02d]:\n",
2057 phba->sli4_hba.mbx_cq->assoc_qid);
2058 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2059 "\tCQID[%02d], "
2060 "QE-COUNT[%04d], QE-SIZE[%04d], "
2061 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2062 phba->sli4_hba.mbx_cq->queue_id,
2063 phba->sli4_hba.mbx_cq->entry_count,
2064 phba->sli4_hba.mbx_cq->entry_size,
2065 phba->sli4_hba.mbx_cq->host_index,
2066 phba->sli4_hba.mbx_cq->hba_index);
2067 }
2068
2069 /* Get slow-path complete queue information */
2070 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2071 "Slow-path ELS CQ information:\n");
2072 if (phba->sli4_hba.els_cq) {
2073 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2074 "Associated EQID[%02d]:\n",
2075 phba->sli4_hba.els_cq->assoc_qid);
2076 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2077 "\tCQID [%02d], "
2078 "QE-COUNT[%04d], QE-SIZE[%04d], "
2079 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2080 phba->sli4_hba.els_cq->queue_id,
2081 phba->sli4_hba.els_cq->entry_count,
2082 phba->sli4_hba.els_cq->entry_size,
2083 phba->sli4_hba.els_cq->host_index,
2084 phba->sli4_hba.els_cq->hba_index);
2085 }
2086
2087 /* Get fast-path complete queue information */
2088 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2089 "Fast-path FCP CQ information:\n");
2090 fcp_qidx = 0;
2091 if (phba->sli4_hba.fcp_cq) {
2092 do {
2093 if (phba->sli4_hba.fcp_cq[fcp_qidx]) {
2094 len += snprintf(pbuffer+len,
2095 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2096 "Associated EQID[%02d]:\n",
2097 phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
2098 len += snprintf(pbuffer+len,
2099 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2100 "\tCQID[%02d], "
2101 "QE-COUNT[%04d], QE-SIZE[%04d], "
2102 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2103 phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
2104 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
2105 phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
2106 phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
2107 phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
2108 }
2109 } while (++fcp_qidx < phba->cfg_fcp_eq_count);
2110 len += snprintf(pbuffer+len,
2111 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2112 }
2113
2114 /* Get mailbox queue information */
2115 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2116 "Slow-path MBX MQ information:\n");
2117 if (phba->sli4_hba.mbx_wq) {
2118 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2119 "Associated CQID[%02d]:\n",
2120 phba->sli4_hba.mbx_wq->assoc_qid);
2121 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2122 "\tWQID[%02d], "
2123 "QE-COUNT[%04d], QE-SIZE[%04d], "
2124 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2125 phba->sli4_hba.mbx_wq->queue_id,
2126 phba->sli4_hba.mbx_wq->entry_count,
2127 phba->sli4_hba.mbx_wq->entry_size,
2128 phba->sli4_hba.mbx_wq->host_index,
2129 phba->sli4_hba.mbx_wq->hba_index);
2130 }
2131
2132 /* Get slow-path work queue information */
2133 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2134 "Slow-path ELS WQ information:\n");
2135 if (phba->sli4_hba.els_wq) {
2136 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2137 "Associated CQID[%02d]:\n",
2138 phba->sli4_hba.els_wq->assoc_qid);
2139 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2140 "\tWQID[%02d], "
2141 "QE-COUNT[%04d], QE-SIZE[%04d], "
2142 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
2143 phba->sli4_hba.els_wq->queue_id,
2144 phba->sli4_hba.els_wq->entry_count,
2145 phba->sli4_hba.els_wq->entry_size,
2146 phba->sli4_hba.els_wq->host_index,
2147 phba->sli4_hba.els_wq->hba_index);
2148 }
2149
2150 /* Get fast-path work queue information */
2151 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2152 "Fast-path FCP WQ information:\n");
2153 if (phba->sli4_hba.fcp_wq) {
2154 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count;
2155 fcp_qidx++) {
2156 if (!phba->sli4_hba.fcp_wq[fcp_qidx])
2157 continue;
2158 len += snprintf(pbuffer+len,
2159 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2160 "Associated CQID[%02d]:\n",
2161 phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
2162 len += snprintf(pbuffer+len,
2163 LPFC_QUE_INFO_GET_BUF_SIZE-len,
2164 "\tWQID[%02d], "
2165 "QE-COUNT[%04d], WQE-SIZE[%04d], "
2166 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2167 phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
2168 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
2169 phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
2170 phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
2171 phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
2172 }
2173 len += snprintf(pbuffer+len,
2174 LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
2175 }
2176
2177 /* Get receive queue information */
2178 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2179 "Slow-path RQ information:\n");
2180 if (phba->sli4_hba.hdr_rq && phba->sli4_hba.dat_rq) {
2181 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2182 "Associated CQID[%02d]:\n",
2183 phba->sli4_hba.hdr_rq->assoc_qid);
2184 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2185 "\tHQID[%02d], "
2186 "QE-COUNT[%04d], QE-SIZE[%04d], "
2187 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2188 phba->sli4_hba.hdr_rq->queue_id,
2189 phba->sli4_hba.hdr_rq->entry_count,
2190 phba->sli4_hba.hdr_rq->entry_size,
2191 phba->sli4_hba.hdr_rq->host_index,
2192 phba->sli4_hba.hdr_rq->hba_index);
2193 len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
2194 "\tDQID[%02d], "
2195 "QE-COUNT[%04d], QE-SIZE[%04d], "
2196 "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
2197 phba->sli4_hba.dat_rq->queue_id,
2198 phba->sli4_hba.dat_rq->entry_count,
2199 phba->sli4_hba.dat_rq->entry_size,
2200 phba->sli4_hba.dat_rq->host_index,
2201 phba->sli4_hba.dat_rq->hba_index);
2202 }
2203 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2204 }
2205
2206 /**
2207 * lpfc_idiag_que_param_check - queue access command parameter sanity check
2208 * @q: The pointer to queue structure.
2209 * @index: The index into a queue entry.
2210 * @count: The number of queue entries to access.
2211 *
2212 * Description:
2213 * The routine performs sanity check on device queue access method commands.
2214 *
2215 * Returns:
2216 * This function returns -EINVAL when fails the sanity check, otherwise, it
2217 * returns 0.
2218 **/
2219 static int
2220 lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
2221 {
2222 /* Only support single entry read or browsing */
2223 if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
2224 return -EINVAL;
2225 if (index > q->entry_count - 1)
2226 return -EINVAL;
2227 return 0;
2228 }
2229
2230 /**
2231 * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
2232 * @pbuffer: The pointer to buffer to copy the read data into.
2233 * @pque: The pointer to the queue to be read.
2234 * @index: The index into the queue entry.
2235 *
2236 * Description:
2237 * This routine reads out a single entry from the given queue's index location
2238 * and copies it into the buffer provided.
2239 *
2240 * Returns:
2241 * This function returns 0 when it fails, otherwise, it returns the length of
2242 * the data read into the buffer provided.
2243 **/
2244 static int
2245 lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
2246 uint32_t index)
2247 {
2248 int offset, esize;
2249 uint32_t *pentry;
2250
2251 if (!pbuffer || !pque)
2252 return 0;
2253
2254 esize = pque->entry_size;
2255 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2256 "QE-INDEX[%04d]:\n", index);
2257
2258 offset = 0;
2259 pentry = pque->qe[index].address;
2260 while (esize > 0) {
2261 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
2262 "%08x ", *pentry);
2263 pentry++;
2264 offset += sizeof(uint32_t);
2265 esize -= sizeof(uint32_t);
2266 if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
2267 len += snprintf(pbuffer+len,
2268 LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2269 }
2270 len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
2271
2272 return len;
2273 }
2274
2275 /**
2276 * lpfc_idiag_queacc_read - idiag debugfs read port queue
2277 * @file: The file pointer to read from.
2278 * @buf: The buffer to copy the data to.
2279 * @nbytes: The number of bytes to read.
2280 * @ppos: The position in the file to start reading from.
2281 *
2282 * Description:
2283 * This routine reads data from the @phba device queue memory according to the
2284 * idiag command, and copies to user @buf. Depending on the queue dump read
2285 * command setup, it does either a single queue entry read or browing through
2286 * all entries of the queue.
2287 *
2288 * Returns:
2289 * This function returns the amount of data that was read (this could be less
2290 * than @nbytes if the end of the file was reached) or a negative error value.
2291 **/
2292 static ssize_t
2293 lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
2294 loff_t *ppos)
2295 {
2296 struct lpfc_debug *debug = file->private_data;
2297 uint32_t last_index, index, count;
2298 struct lpfc_queue *pque = NULL;
2299 char *pbuffer;
2300 int len = 0;
2301
2302 /* This is a user read operation */
2303 debug->op = LPFC_IDIAG_OP_RD;
2304
2305 if (!debug->buffer)
2306 debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
2307 if (!debug->buffer)
2308 return 0;
2309 pbuffer = debug->buffer;
2310
2311 if (*ppos)
2312 return 0;
2313
2314 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2315 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2316 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2317 pque = (struct lpfc_queue *)idiag.ptr_private;
2318 } else
2319 return 0;
2320
2321 /* Browse the queue starting from index */
2322 if (count == LPFC_QUE_ACC_BROWSE)
2323 goto que_browse;
2324
2325 /* Read a single entry from the queue */
2326 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2327
2328 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2329
2330 que_browse:
2331
2332 /* Browse all entries from the queue */
2333 last_index = idiag.offset.last_rd;
2334 index = last_index;
2335
2336 while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
2337 len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
2338 index++;
2339 if (index > pque->entry_count - 1)
2340 break;
2341 }
2342
2343 /* Set up the offset for next portion of pci cfg read */
2344 if (index > pque->entry_count - 1)
2345 index = 0;
2346 idiag.offset.last_rd = index;
2347
2348 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2349 }
2350
2351 /**
2352 * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
2353 * @file: The file pointer to read from.
2354 * @buf: The buffer to copy the user data from.
2355 * @nbytes: The number of bytes to get.
2356 * @ppos: The position in the file to start reading from.
2357 *
2358 * This routine get the debugfs idiag command struct from user space and then
2359 * perform the syntax check for port queue read (dump) or write (set) command
2360 * accordingly. In the case of port queue read command, it sets up the command
2361 * in the idiag command struct for the following debugfs read operation. In
2362 * the case of port queue write operation, it executes the write operation
2363 * into the port queue entry accordingly.
2364 *
2365 * It returns the @nbytges passing in from debugfs user space when successful.
2366 * In case of error conditions, it returns proper error code back to the user
2367 * space.
2368 **/
2369 static ssize_t
2370 lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
2371 size_t nbytes, loff_t *ppos)
2372 {
2373 struct lpfc_debug *debug = file->private_data;
2374 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2375 uint32_t qidx, quetp, queid, index, count, offset, value;
2376 uint32_t *pentry;
2377 struct lpfc_queue *pque;
2378 int rc;
2379
2380 /* This is a user write operation */
2381 debug->op = LPFC_IDIAG_OP_WR;
2382
2383 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2384 if (rc < 0)
2385 return rc;
2386
2387 /* Get and sanity check on command feilds */
2388 quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
2389 queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
2390 index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
2391 count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
2392 offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
2393 value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
2394
2395 /* Sanity check on command line arguments */
2396 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2397 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2398 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2399 if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
2400 goto error_out;
2401 if (count != 1)
2402 goto error_out;
2403 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2404 if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
2405 goto error_out;
2406 } else
2407 goto error_out;
2408
2409 switch (quetp) {
2410 case LPFC_IDIAG_EQ:
2411 /* Slow-path event queue */
2412 if (phba->sli4_hba.sp_eq &&
2413 phba->sli4_hba.sp_eq->queue_id == queid) {
2414 /* Sanity check */
2415 rc = lpfc_idiag_que_param_check(
2416 phba->sli4_hba.sp_eq, index, count);
2417 if (rc)
2418 goto error_out;
2419 idiag.ptr_private = phba->sli4_hba.sp_eq;
2420 goto pass_check;
2421 }
2422 /* Fast-path event queue */
2423 if (phba->sli4_hba.fp_eq) {
2424 for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
2425 if (phba->sli4_hba.fp_eq[qidx] &&
2426 phba->sli4_hba.fp_eq[qidx]->queue_id ==
2427 queid) {
2428 /* Sanity check */
2429 rc = lpfc_idiag_que_param_check(
2430 phba->sli4_hba.fp_eq[qidx],
2431 index, count);
2432 if (rc)
2433 goto error_out;
2434 idiag.ptr_private =
2435 phba->sli4_hba.fp_eq[qidx];
2436 goto pass_check;
2437 }
2438 }
2439 }
2440 goto error_out;
2441 break;
2442 case LPFC_IDIAG_CQ:
2443 /* MBX complete queue */
2444 if (phba->sli4_hba.mbx_cq &&
2445 phba->sli4_hba.mbx_cq->queue_id == queid) {
2446 /* Sanity check */
2447 rc = lpfc_idiag_que_param_check(
2448 phba->sli4_hba.mbx_cq, index, count);
2449 if (rc)
2450 goto error_out;
2451 idiag.ptr_private = phba->sli4_hba.mbx_cq;
2452 goto pass_check;
2453 }
2454 /* ELS complete queue */
2455 if (phba->sli4_hba.els_cq &&
2456 phba->sli4_hba.els_cq->queue_id == queid) {
2457 /* Sanity check */
2458 rc = lpfc_idiag_que_param_check(
2459 phba->sli4_hba.els_cq, index, count);
2460 if (rc)
2461 goto error_out;
2462 idiag.ptr_private = phba->sli4_hba.els_cq;
2463 goto pass_check;
2464 }
2465 /* FCP complete queue */
2466 if (phba->sli4_hba.fcp_cq) {
2467 qidx = 0;
2468 do {
2469 if (phba->sli4_hba.fcp_cq[qidx] &&
2470 phba->sli4_hba.fcp_cq[qidx]->queue_id ==
2471 queid) {
2472 /* Sanity check */
2473 rc = lpfc_idiag_que_param_check(
2474 phba->sli4_hba.fcp_cq[qidx],
2475 index, count);
2476 if (rc)
2477 goto error_out;
2478 idiag.ptr_private =
2479 phba->sli4_hba.fcp_cq[qidx];
2480 goto pass_check;
2481 }
2482 } while (++qidx < phba->cfg_fcp_eq_count);
2483 }
2484 goto error_out;
2485 break;
2486 case LPFC_IDIAG_MQ:
2487 /* MBX work queue */
2488 if (phba->sli4_hba.mbx_wq &&
2489 phba->sli4_hba.mbx_wq->queue_id == queid) {
2490 /* Sanity check */
2491 rc = lpfc_idiag_que_param_check(
2492 phba->sli4_hba.mbx_wq, index, count);
2493 if (rc)
2494 goto error_out;
2495 idiag.ptr_private = phba->sli4_hba.mbx_wq;
2496 goto pass_check;
2497 }
2498 goto error_out;
2499 break;
2500 case LPFC_IDIAG_WQ:
2501 /* ELS work queue */
2502 if (phba->sli4_hba.els_wq &&
2503 phba->sli4_hba.els_wq->queue_id == queid) {
2504 /* Sanity check */
2505 rc = lpfc_idiag_que_param_check(
2506 phba->sli4_hba.els_wq, index, count);
2507 if (rc)
2508 goto error_out;
2509 idiag.ptr_private = phba->sli4_hba.els_wq;
2510 goto pass_check;
2511 }
2512 /* FCP work queue */
2513 if (phba->sli4_hba.fcp_wq) {
2514 for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
2515 if (!phba->sli4_hba.fcp_wq[qidx])
2516 continue;
2517 if (phba->sli4_hba.fcp_wq[qidx]->queue_id ==
2518 queid) {
2519 /* Sanity check */
2520 rc = lpfc_idiag_que_param_check(
2521 phba->sli4_hba.fcp_wq[qidx],
2522 index, count);
2523 if (rc)
2524 goto error_out;
2525 idiag.ptr_private =
2526 phba->sli4_hba.fcp_wq[qidx];
2527 goto pass_check;
2528 }
2529 }
2530 }
2531 goto error_out;
2532 break;
2533 case LPFC_IDIAG_RQ:
2534 /* HDR queue */
2535 if (phba->sli4_hba.hdr_rq &&
2536 phba->sli4_hba.hdr_rq->queue_id == queid) {
2537 /* Sanity check */
2538 rc = lpfc_idiag_que_param_check(
2539 phba->sli4_hba.hdr_rq, index, count);
2540 if (rc)
2541 goto error_out;
2542 idiag.ptr_private = phba->sli4_hba.hdr_rq;
2543 goto pass_check;
2544 }
2545 /* DAT queue */
2546 if (phba->sli4_hba.dat_rq &&
2547 phba->sli4_hba.dat_rq->queue_id == queid) {
2548 /* Sanity check */
2549 rc = lpfc_idiag_que_param_check(
2550 phba->sli4_hba.dat_rq, index, count);
2551 if (rc)
2552 goto error_out;
2553 idiag.ptr_private = phba->sli4_hba.dat_rq;
2554 goto pass_check;
2555 }
2556 goto error_out;
2557 break;
2558 default:
2559 goto error_out;
2560 break;
2561 }
2562
2563 pass_check:
2564
2565 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
2566 if (count == LPFC_QUE_ACC_BROWSE)
2567 idiag.offset.last_rd = index;
2568 }
2569
2570 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
2571 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
2572 idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
2573 /* Additional sanity checks on write operation */
2574 pque = (struct lpfc_queue *)idiag.ptr_private;
2575 if (offset > pque->entry_size/sizeof(uint32_t) - 1)
2576 goto error_out;
2577 pentry = pque->qe[index].address;
2578 pentry += offset;
2579 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
2580 *pentry = value;
2581 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
2582 *pentry |= value;
2583 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
2584 *pentry &= ~value;
2585 }
2586 return nbytes;
2587
2588 error_out:
2589 /* Clean out command structure on command error out */
2590 memset(&idiag, 0, sizeof(idiag));
2591 return -EINVAL;
2592 }
2593
2594 /**
2595 * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
2596 * @phba: The pointer to hba structure.
2597 * @pbuffer: The pointer to the buffer to copy the data to.
2598 * @len: The lenght of bytes to copied.
2599 * @drbregid: The id to doorbell registers.
2600 *
2601 * Description:
2602 * This routine reads a doorbell register and copies its content to the
2603 * user buffer pointed to by @pbuffer.
2604 *
2605 * Returns:
2606 * This function returns the amount of data that was copied into @pbuffer.
2607 **/
2608 static int
2609 lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2610 int len, uint32_t drbregid)
2611 {
2612
2613 if (!pbuffer)
2614 return 0;
2615
2616 switch (drbregid) {
2617 case LPFC_DRB_EQCQ:
2618 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2619 "EQCQ-DRB-REG: 0x%08x\n",
2620 readl(phba->sli4_hba.EQCQDBregaddr));
2621 break;
2622 case LPFC_DRB_MQ:
2623 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2624 "MQ-DRB-REG: 0x%08x\n",
2625 readl(phba->sli4_hba.MQDBregaddr));
2626 break;
2627 case LPFC_DRB_WQ:
2628 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2629 "WQ-DRB-REG: 0x%08x\n",
2630 readl(phba->sli4_hba.WQDBregaddr));
2631 break;
2632 case LPFC_DRB_RQ:
2633 len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
2634 "RQ-DRB-REG: 0x%08x\n",
2635 readl(phba->sli4_hba.RQDBregaddr));
2636 break;
2637 default:
2638 break;
2639 }
2640
2641 return len;
2642 }
2643
2644 /**
2645 * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
2646 * @file: The file pointer to read from.
2647 * @buf: The buffer to copy the data to.
2648 * @nbytes: The number of bytes to read.
2649 * @ppos: The position in the file to start reading from.
2650 *
2651 * Description:
2652 * This routine reads data from the @phba device doorbell register according
2653 * to the idiag command, and copies to user @buf. Depending on the doorbell
2654 * register read command setup, it does either a single doorbell register
2655 * read or dump all doorbell registers.
2656 *
2657 * Returns:
2658 * This function returns the amount of data that was read (this could be less
2659 * than @nbytes if the end of the file was reached) or a negative error value.
2660 **/
2661 static ssize_t
2662 lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
2663 loff_t *ppos)
2664 {
2665 struct lpfc_debug *debug = file->private_data;
2666 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2667 uint32_t drb_reg_id, i;
2668 char *pbuffer;
2669 int len = 0;
2670
2671 /* This is a user read operation */
2672 debug->op = LPFC_IDIAG_OP_RD;
2673
2674 if (!debug->buffer)
2675 debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
2676 if (!debug->buffer)
2677 return 0;
2678 pbuffer = debug->buffer;
2679
2680 if (*ppos)
2681 return 0;
2682
2683 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
2684 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2685 else
2686 return 0;
2687
2688 if (drb_reg_id == LPFC_DRB_ACC_ALL)
2689 for (i = 1; i <= LPFC_DRB_MAX; i++)
2690 len = lpfc_idiag_drbacc_read_reg(phba,
2691 pbuffer, len, i);
2692 else
2693 len = lpfc_idiag_drbacc_read_reg(phba,
2694 pbuffer, len, drb_reg_id);
2695
2696 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2697 }
2698
2699 /**
2700 * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
2701 * @file: The file pointer to read from.
2702 * @buf: The buffer to copy the user data from.
2703 * @nbytes: The number of bytes to get.
2704 * @ppos: The position in the file to start reading from.
2705 *
2706 * This routine get the debugfs idiag command struct from user space and then
2707 * perform the syntax check for port doorbell register read (dump) or write
2708 * (set) command accordingly. In the case of port queue read command, it sets
2709 * up the command in the idiag command struct for the following debugfs read
2710 * operation. In the case of port doorbell register write operation, it
2711 * executes the write operation into the port doorbell register accordingly.
2712 *
2713 * It returns the @nbytges passing in from debugfs user space when successful.
2714 * In case of error conditions, it returns proper error code back to the user
2715 * space.
2716 **/
2717 static ssize_t
2718 lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
2719 size_t nbytes, loff_t *ppos)
2720 {
2721 struct lpfc_debug *debug = file->private_data;
2722 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2723 uint32_t drb_reg_id, value, reg_val = 0;
2724 void __iomem *drb_reg;
2725 int rc;
2726
2727 /* This is a user write operation */
2728 debug->op = LPFC_IDIAG_OP_WR;
2729
2730 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2731 if (rc < 0)
2732 return rc;
2733
2734 /* Sanity check on command line arguments */
2735 drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
2736 value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
2737
2738 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2739 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2740 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2741 if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
2742 goto error_out;
2743 if (drb_reg_id > LPFC_DRB_MAX)
2744 goto error_out;
2745 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
2746 if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
2747 goto error_out;
2748 if ((drb_reg_id > LPFC_DRB_MAX) &&
2749 (drb_reg_id != LPFC_DRB_ACC_ALL))
2750 goto error_out;
2751 } else
2752 goto error_out;
2753
2754 /* Perform the write access operation */
2755 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
2756 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
2757 idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2758 switch (drb_reg_id) {
2759 case LPFC_DRB_EQCQ:
2760 drb_reg = phba->sli4_hba.EQCQDBregaddr;
2761 break;
2762 case LPFC_DRB_MQ:
2763 drb_reg = phba->sli4_hba.MQDBregaddr;
2764 break;
2765 case LPFC_DRB_WQ:
2766 drb_reg = phba->sli4_hba.WQDBregaddr;
2767 break;
2768 case LPFC_DRB_RQ:
2769 drb_reg = phba->sli4_hba.RQDBregaddr;
2770 break;
2771 default:
2772 goto error_out;
2773 }
2774
2775 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
2776 reg_val = value;
2777 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
2778 reg_val = readl(drb_reg);
2779 reg_val |= value;
2780 }
2781 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
2782 reg_val = readl(drb_reg);
2783 reg_val &= ~value;
2784 }
2785 writel(reg_val, drb_reg);
2786 readl(drb_reg); /* flush */
2787 }
2788 return nbytes;
2789
2790 error_out:
2791 /* Clean out command structure on command error out */
2792 memset(&idiag, 0, sizeof(idiag));
2793 return -EINVAL;
2794 }
2795
2796 /**
2797 * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
2798 * @phba: The pointer to hba structure.
2799 * @pbuffer: The pointer to the buffer to copy the data to.
2800 * @len: The lenght of bytes to copied.
2801 * @drbregid: The id to doorbell registers.
2802 *
2803 * Description:
2804 * This routine reads a control register and copies its content to the
2805 * user buffer pointed to by @pbuffer.
2806 *
2807 * Returns:
2808 * This function returns the amount of data that was copied into @pbuffer.
2809 **/
2810 static int
2811 lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
2812 int len, uint32_t ctlregid)
2813 {
2814
2815 if (!pbuffer)
2816 return 0;
2817
2818 switch (ctlregid) {
2819 case LPFC_CTL_PORT_SEM:
2820 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2821 "Port SemReg: 0x%08x\n",
2822 readl(phba->sli4_hba.conf_regs_memmap_p +
2823 LPFC_CTL_PORT_SEM_OFFSET));
2824 break;
2825 case LPFC_CTL_PORT_STA:
2826 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2827 "Port StaReg: 0x%08x\n",
2828 readl(phba->sli4_hba.conf_regs_memmap_p +
2829 LPFC_CTL_PORT_STA_OFFSET));
2830 break;
2831 case LPFC_CTL_PORT_CTL:
2832 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2833 "Port CtlReg: 0x%08x\n",
2834 readl(phba->sli4_hba.conf_regs_memmap_p +
2835 LPFC_CTL_PORT_CTL_OFFSET));
2836 break;
2837 case LPFC_CTL_PORT_ER1:
2838 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2839 "Port Er1Reg: 0x%08x\n",
2840 readl(phba->sli4_hba.conf_regs_memmap_p +
2841 LPFC_CTL_PORT_ER1_OFFSET));
2842 break;
2843 case LPFC_CTL_PORT_ER2:
2844 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2845 "Port Er2Reg: 0x%08x\n",
2846 readl(phba->sli4_hba.conf_regs_memmap_p +
2847 LPFC_CTL_PORT_ER2_OFFSET));
2848 break;
2849 case LPFC_CTL_PDEV_CTL:
2850 len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
2851 "PDev CtlReg: 0x%08x\n",
2852 readl(phba->sli4_hba.conf_regs_memmap_p +
2853 LPFC_CTL_PDEV_CTL_OFFSET));
2854 break;
2855 default:
2856 break;
2857 }
2858 return len;
2859 }
2860
2861 /**
2862 * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
2863 * @file: The file pointer to read from.
2864 * @buf: The buffer to copy the data to.
2865 * @nbytes: The number of bytes to read.
2866 * @ppos: The position in the file to start reading from.
2867 *
2868 * Description:
2869 * This routine reads data from the @phba port and device registers according
2870 * to the idiag command, and copies to user @buf.
2871 *
2872 * Returns:
2873 * This function returns the amount of data that was read (this could be less
2874 * than @nbytes if the end of the file was reached) or a negative error value.
2875 **/
2876 static ssize_t
2877 lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
2878 loff_t *ppos)
2879 {
2880 struct lpfc_debug *debug = file->private_data;
2881 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2882 uint32_t ctl_reg_id, i;
2883 char *pbuffer;
2884 int len = 0;
2885
2886 /* This is a user read operation */
2887 debug->op = LPFC_IDIAG_OP_RD;
2888
2889 if (!debug->buffer)
2890 debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
2891 if (!debug->buffer)
2892 return 0;
2893 pbuffer = debug->buffer;
2894
2895 if (*ppos)
2896 return 0;
2897
2898 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
2899 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2900 else
2901 return 0;
2902
2903 if (ctl_reg_id == LPFC_CTL_ACC_ALL)
2904 for (i = 1; i <= LPFC_CTL_MAX; i++)
2905 len = lpfc_idiag_ctlacc_read_reg(phba,
2906 pbuffer, len, i);
2907 else
2908 len = lpfc_idiag_ctlacc_read_reg(phba,
2909 pbuffer, len, ctl_reg_id);
2910
2911 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
2912 }
2913
2914 /**
2915 * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
2916 * @file: The file pointer to read from.
2917 * @buf: The buffer to copy the user data from.
2918 * @nbytes: The number of bytes to get.
2919 * @ppos: The position in the file to start reading from.
2920 *
2921 * This routine get the debugfs idiag command struct from user space and then
2922 * perform the syntax check for port and device control register read (dump)
2923 * or write (set) command accordingly.
2924 *
2925 * It returns the @nbytges passing in from debugfs user space when successful.
2926 * In case of error conditions, it returns proper error code back to the user
2927 * space.
2928 **/
2929 static ssize_t
2930 lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
2931 size_t nbytes, loff_t *ppos)
2932 {
2933 struct lpfc_debug *debug = file->private_data;
2934 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
2935 uint32_t ctl_reg_id, value, reg_val = 0;
2936 void __iomem *ctl_reg;
2937 int rc;
2938
2939 /* This is a user write operation */
2940 debug->op = LPFC_IDIAG_OP_WR;
2941
2942 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
2943 if (rc < 0)
2944 return rc;
2945
2946 /* Sanity check on command line arguments */
2947 ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
2948 value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
2949
2950 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2951 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2952 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2953 if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
2954 goto error_out;
2955 if (ctl_reg_id > LPFC_CTL_MAX)
2956 goto error_out;
2957 } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
2958 if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
2959 goto error_out;
2960 if ((ctl_reg_id > LPFC_CTL_MAX) &&
2961 (ctl_reg_id != LPFC_CTL_ACC_ALL))
2962 goto error_out;
2963 } else
2964 goto error_out;
2965
2966 /* Perform the write access operation */
2967 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
2968 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
2969 idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
2970 switch (ctl_reg_id) {
2971 case LPFC_CTL_PORT_SEM:
2972 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2973 LPFC_CTL_PORT_SEM_OFFSET;
2974 break;
2975 case LPFC_CTL_PORT_STA:
2976 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2977 LPFC_CTL_PORT_STA_OFFSET;
2978 break;
2979 case LPFC_CTL_PORT_CTL:
2980 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2981 LPFC_CTL_PORT_CTL_OFFSET;
2982 break;
2983 case LPFC_CTL_PORT_ER1:
2984 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2985 LPFC_CTL_PORT_ER1_OFFSET;
2986 break;
2987 case LPFC_CTL_PORT_ER2:
2988 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2989 LPFC_CTL_PORT_ER2_OFFSET;
2990 break;
2991 case LPFC_CTL_PDEV_CTL:
2992 ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
2993 LPFC_CTL_PDEV_CTL_OFFSET;
2994 break;
2995 default:
2996 goto error_out;
2997 }
2998
2999 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
3000 reg_val = value;
3001 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
3002 reg_val = readl(ctl_reg);
3003 reg_val |= value;
3004 }
3005 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
3006 reg_val = readl(ctl_reg);
3007 reg_val &= ~value;
3008 }
3009 writel(reg_val, ctl_reg);
3010 readl(ctl_reg); /* flush */
3011 }
3012 return nbytes;
3013
3014 error_out:
3015 /* Clean out command structure on command error out */
3016 memset(&idiag, 0, sizeof(idiag));
3017 return -EINVAL;
3018 }
3019
3020 /**
3021 * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
3022 * @phba: Pointer to HBA context object.
3023 * @pbuffer: Pointer to data buffer.
3024 *
3025 * Description:
3026 * This routine gets the driver mailbox access debugfs setup information.
3027 *
3028 * Returns:
3029 * This function returns the amount of data that was read (this could be less
3030 * than @nbytes if the end of the file was reached) or a negative error value.
3031 **/
3032 static int
3033 lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
3034 {
3035 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3036 int len = 0;
3037
3038 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3039 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3040 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3041 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3042
3043 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3044 "mbx_dump_map: 0x%08x\n", mbx_dump_map);
3045 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3046 "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
3047 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3048 "mbx_word_cnt: %04d\n", mbx_word_cnt);
3049 len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
3050 "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
3051
3052 return len;
3053 }
3054
3055 /**
3056 * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
3057 * @file: The file pointer to read from.
3058 * @buf: The buffer to copy the data to.
3059 * @nbytes: The number of bytes to read.
3060 * @ppos: The position in the file to start reading from.
3061 *
3062 * Description:
3063 * This routine reads data from the @phba driver mailbox access debugfs setup
3064 * information.
3065 *
3066 * Returns:
3067 * This function returns the amount of data that was read (this could be less
3068 * than @nbytes if the end of the file was reached) or a negative error value.
3069 **/
3070 static ssize_t
3071 lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
3072 loff_t *ppos)
3073 {
3074 struct lpfc_debug *debug = file->private_data;
3075 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3076 char *pbuffer;
3077 int len = 0;
3078
3079 /* This is a user read operation */
3080 debug->op = LPFC_IDIAG_OP_RD;
3081
3082 if (!debug->buffer)
3083 debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
3084 if (!debug->buffer)
3085 return 0;
3086 pbuffer = debug->buffer;
3087
3088 if (*ppos)
3089 return 0;
3090
3091 if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
3092 (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
3093 return 0;
3094
3095 len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
3096
3097 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3098 }
3099
3100 /**
3101 * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
3102 * @file: The file pointer to read from.
3103 * @buf: The buffer to copy the user data from.
3104 * @nbytes: The number of bytes to get.
3105 * @ppos: The position in the file to start reading from.
3106 *
3107 * This routine get the debugfs idiag command struct from user space and then
3108 * perform the syntax check for driver mailbox command (dump) and sets up the
3109 * necessary states in the idiag command struct accordingly.
3110 *
3111 * It returns the @nbytges passing in from debugfs user space when successful.
3112 * In case of error conditions, it returns proper error code back to the user
3113 * space.
3114 **/
3115 static ssize_t
3116 lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
3117 size_t nbytes, loff_t *ppos)
3118 {
3119 struct lpfc_debug *debug = file->private_data;
3120 uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
3121 int rc;
3122
3123 /* This is a user write operation */
3124 debug->op = LPFC_IDIAG_OP_WR;
3125
3126 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3127 if (rc < 0)
3128 return rc;
3129
3130 /* Sanity check on command line arguments */
3131 mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3132 mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3133 mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3134 mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3135
3136 if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
3137 if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
3138 goto error_out;
3139 if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
3140 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3141 goto error_out;
3142 if (mbx_word_cnt > sizeof(MAILBOX_t))
3143 goto error_out;
3144 } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
3145 if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
3146 goto error_out;
3147 if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
3148 (mbx_dump_map != LPFC_MBX_DMP_ALL))
3149 goto error_out;
3150 if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
3151 goto error_out;
3152 if (mbx_mbox_cmd != 0x9b)
3153 goto error_out;
3154 } else
3155 goto error_out;
3156
3157 if (mbx_word_cnt == 0)
3158 goto error_out;
3159 if (rc != LPFC_MBX_DMP_ARG)
3160 goto error_out;
3161 if (mbx_mbox_cmd & ~0xff)
3162 goto error_out;
3163
3164 /* condition for stop mailbox dump */
3165 if (mbx_dump_cnt == 0)
3166 goto reset_out;
3167
3168 return nbytes;
3169
3170 reset_out:
3171 /* Clean out command structure on command error out */
3172 memset(&idiag, 0, sizeof(idiag));
3173 return nbytes;
3174
3175 error_out:
3176 /* Clean out command structure on command error out */
3177 memset(&idiag, 0, sizeof(idiag));
3178 return -EINVAL;
3179 }
3180
3181 /**
3182 * lpfc_idiag_extacc_avail_get - get the available extents information
3183 * @phba: pointer to lpfc hba data structure.
3184 * @pbuffer: pointer to internal buffer.
3185 * @len: length into the internal buffer data has been copied.
3186 *
3187 * Description:
3188 * This routine is to get the available extent information.
3189 *
3190 * Returns:
3191 * overall lenth of the data read into the internal buffer.
3192 **/
3193 static int
3194 lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
3195 {
3196 uint16_t ext_cnt, ext_size;
3197
3198 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3199 "\nAvailable Extents Information:\n");
3200
3201 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3202 "\tPort Available VPI extents: ");
3203 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
3204 &ext_cnt, &ext_size);
3205 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3206 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3207
3208 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3209 "\tPort Available VFI extents: ");
3210 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
3211 &ext_cnt, &ext_size);
3212 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3213 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3214
3215 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3216 "\tPort Available RPI extents: ");
3217 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
3218 &ext_cnt, &ext_size);
3219 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3220 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3221
3222 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3223 "\tPort Available XRI extents: ");
3224 lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
3225 &ext_cnt, &ext_size);
3226 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3227 "Count %3d, Size %3d\n", ext_cnt, ext_size);
3228
3229 return len;
3230 }
3231
3232 /**
3233 * lpfc_idiag_extacc_alloc_get - get the allocated extents information
3234 * @phba: pointer to lpfc hba data structure.
3235 * @pbuffer: pointer to internal buffer.
3236 * @len: length into the internal buffer data has been copied.
3237 *
3238 * Description:
3239 * This routine is to get the allocated extent information.
3240 *
3241 * Returns:
3242 * overall lenth of the data read into the internal buffer.
3243 **/
3244 static int
3245 lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
3246 {
3247 uint16_t ext_cnt, ext_size;
3248 int rc;
3249
3250 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3251 "\nAllocated Extents Information:\n");
3252
3253 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3254 "\tHost Allocated VPI extents: ");
3255 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
3256 &ext_cnt, &ext_size);
3257 if (!rc)
3258 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3259 "Port %d Extent %3d, Size %3d\n",
3260 phba->brd_no, ext_cnt, ext_size);
3261 else
3262 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3263 "N/A\n");
3264
3265 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3266 "\tHost Allocated VFI extents: ");
3267 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
3268 &ext_cnt, &ext_size);
3269 if (!rc)
3270 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3271 "Port %d Extent %3d, Size %3d\n",
3272 phba->brd_no, ext_cnt, ext_size);
3273 else
3274 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3275 "N/A\n");
3276
3277 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3278 "\tHost Allocated RPI extents: ");
3279 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
3280 &ext_cnt, &ext_size);
3281 if (!rc)
3282 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3283 "Port %d Extent %3d, Size %3d\n",
3284 phba->brd_no, ext_cnt, ext_size);
3285 else
3286 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3287 "N/A\n");
3288
3289 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3290 "\tHost Allocated XRI extents: ");
3291 rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
3292 &ext_cnt, &ext_size);
3293 if (!rc)
3294 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3295 "Port %d Extent %3d, Size %3d\n",
3296 phba->brd_no, ext_cnt, ext_size);
3297 else
3298 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3299 "N/A\n");
3300
3301 return len;
3302 }
3303
3304 /**
3305 * lpfc_idiag_extacc_drivr_get - get driver extent information
3306 * @phba: pointer to lpfc hba data structure.
3307 * @pbuffer: pointer to internal buffer.
3308 * @len: length into the internal buffer data has been copied.
3309 *
3310 * Description:
3311 * This routine is to get the driver extent information.
3312 *
3313 * Returns:
3314 * overall lenth of the data read into the internal buffer.
3315 **/
3316 static int
3317 lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
3318 {
3319 struct lpfc_rsrc_blks *rsrc_blks;
3320 int index;
3321
3322 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3323 "\nDriver Extents Information:\n");
3324
3325 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3326 "\tVPI extents:\n");
3327 index = 0;
3328 list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
3329 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3330 "\t\tBlock %3d: Start %4d, Count %4d\n",
3331 index, rsrc_blks->rsrc_start,
3332 rsrc_blks->rsrc_size);
3333 index++;
3334 }
3335 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3336 "\tVFI extents:\n");
3337 index = 0;
3338 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
3339 list) {
3340 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3341 "\t\tBlock %3d: Start %4d, Count %4d\n",
3342 index, rsrc_blks->rsrc_start,
3343 rsrc_blks->rsrc_size);
3344 index++;
3345 }
3346
3347 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3348 "\tRPI extents:\n");
3349 index = 0;
3350 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
3351 list) {
3352 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3353 "\t\tBlock %3d: Start %4d, Count %4d\n",
3354 index, rsrc_blks->rsrc_start,
3355 rsrc_blks->rsrc_size);
3356 index++;
3357 }
3358
3359 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3360 "\tXRI extents:\n");
3361 index = 0;
3362 list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
3363 list) {
3364 len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
3365 "\t\tBlock %3d: Start %4d, Count %4d\n",
3366 index, rsrc_blks->rsrc_start,
3367 rsrc_blks->rsrc_size);
3368 index++;
3369 }
3370
3371 return len;
3372 }
3373
3374 /**
3375 * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
3376 * @file: The file pointer to read from.
3377 * @buf: The buffer to copy the user data from.
3378 * @nbytes: The number of bytes to get.
3379 * @ppos: The position in the file to start reading from.
3380 *
3381 * This routine get the debugfs idiag command struct from user space and then
3382 * perform the syntax check for extent information access commands and sets
3383 * up the necessary states in the idiag command struct accordingly.
3384 *
3385 * It returns the @nbytges passing in from debugfs user space when successful.
3386 * In case of error conditions, it returns proper error code back to the user
3387 * space.
3388 **/
3389 static ssize_t
3390 lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
3391 size_t nbytes, loff_t *ppos)
3392 {
3393 struct lpfc_debug *debug = file->private_data;
3394 uint32_t ext_map;
3395 int rc;
3396
3397 /* This is a user write operation */
3398 debug->op = LPFC_IDIAG_OP_WR;
3399
3400 rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
3401 if (rc < 0)
3402 return rc;
3403
3404 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3405
3406 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3407 goto error_out;
3408 if (rc != LPFC_EXT_ACC_CMD_ARG)
3409 goto error_out;
3410 if (!(ext_map & LPFC_EXT_ACC_ALL))
3411 goto error_out;
3412
3413 return nbytes;
3414 error_out:
3415 /* Clean out command structure on command error out */
3416 memset(&idiag, 0, sizeof(idiag));
3417 return -EINVAL;
3418 }
3419
3420 /**
3421 * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
3422 * @file: The file pointer to read from.
3423 * @buf: The buffer to copy the data to.
3424 * @nbytes: The number of bytes to read.
3425 * @ppos: The position in the file to start reading from.
3426 *
3427 * Description:
3428 * This routine reads data from the proper extent information according to
3429 * the idiag command, and copies to user @buf.
3430 *
3431 * Returns:
3432 * This function returns the amount of data that was read (this could be less
3433 * than @nbytes if the end of the file was reached) or a negative error value.
3434 **/
3435 static ssize_t
3436 lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
3437 loff_t *ppos)
3438 {
3439 struct lpfc_debug *debug = file->private_data;
3440 struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
3441 char *pbuffer;
3442 uint32_t ext_map;
3443 int len = 0;
3444
3445 /* This is a user read operation */
3446 debug->op = LPFC_IDIAG_OP_RD;
3447
3448 if (!debug->buffer)
3449 debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
3450 if (!debug->buffer)
3451 return 0;
3452 pbuffer = debug->buffer;
3453 if (*ppos)
3454 return 0;
3455 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
3456 return 0;
3457
3458 ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
3459 if (ext_map & LPFC_EXT_ACC_AVAIL)
3460 len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
3461 if (ext_map & LPFC_EXT_ACC_ALLOC)
3462 len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
3463 if (ext_map & LPFC_EXT_ACC_DRIVR)
3464 len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
3465
3466 return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
3467 }
3468
3469 #undef lpfc_debugfs_op_disc_trc
3470 static const struct file_operations lpfc_debugfs_op_disc_trc = {
3471 .owner = THIS_MODULE,
3472 .open = lpfc_debugfs_disc_trc_open,
3473 .llseek = lpfc_debugfs_lseek,
3474 .read = lpfc_debugfs_read,
3475 .release = lpfc_debugfs_release,
3476 };
3477
3478 #undef lpfc_debugfs_op_nodelist
3479 static const struct file_operations lpfc_debugfs_op_nodelist = {
3480 .owner = THIS_MODULE,
3481 .open = lpfc_debugfs_nodelist_open,
3482 .llseek = lpfc_debugfs_lseek,
3483 .read = lpfc_debugfs_read,
3484 .release = lpfc_debugfs_release,
3485 };
3486
3487 #undef lpfc_debugfs_op_hbqinfo
3488 static const struct file_operations lpfc_debugfs_op_hbqinfo = {
3489 .owner = THIS_MODULE,
3490 .open = lpfc_debugfs_hbqinfo_open,
3491 .llseek = lpfc_debugfs_lseek,
3492 .read = lpfc_debugfs_read,
3493 .release = lpfc_debugfs_release,
3494 };
3495
3496 #undef lpfc_debugfs_op_dumpHBASlim
3497 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
3498 .owner = THIS_MODULE,
3499 .open = lpfc_debugfs_dumpHBASlim_open,
3500 .llseek = lpfc_debugfs_lseek,
3501 .read = lpfc_debugfs_read,
3502 .release = lpfc_debugfs_release,
3503 };
3504
3505 #undef lpfc_debugfs_op_dumpHostSlim
3506 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
3507 .owner = THIS_MODULE,
3508 .open = lpfc_debugfs_dumpHostSlim_open,
3509 .llseek = lpfc_debugfs_lseek,
3510 .read = lpfc_debugfs_read,
3511 .release = lpfc_debugfs_release,
3512 };
3513
3514 #undef lpfc_debugfs_op_dumpData
3515 static const struct file_operations lpfc_debugfs_op_dumpData = {
3516 .owner = THIS_MODULE,
3517 .open = lpfc_debugfs_dumpData_open,
3518 .llseek = lpfc_debugfs_lseek,
3519 .read = lpfc_debugfs_read,
3520 .write = lpfc_debugfs_dumpDataDif_write,
3521 .release = lpfc_debugfs_dumpDataDif_release,
3522 };
3523
3524 #undef lpfc_debugfs_op_dumpDif
3525 static const struct file_operations lpfc_debugfs_op_dumpDif = {
3526 .owner = THIS_MODULE,
3527 .open = lpfc_debugfs_dumpDif_open,
3528 .llseek = lpfc_debugfs_lseek,
3529 .read = lpfc_debugfs_read,
3530 .write = lpfc_debugfs_dumpDataDif_write,
3531 .release = lpfc_debugfs_dumpDataDif_release,
3532 };
3533
3534 #undef lpfc_debugfs_op_dif_err
3535 static const struct file_operations lpfc_debugfs_op_dif_err = {
3536 .owner = THIS_MODULE,
3537 .open = simple_open,
3538 .llseek = lpfc_debugfs_lseek,
3539 .read = lpfc_debugfs_dif_err_read,
3540 .write = lpfc_debugfs_dif_err_write,
3541 .release = lpfc_debugfs_dif_err_release,
3542 };
3543
3544 #undef lpfc_debugfs_op_slow_ring_trc
3545 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
3546 .owner = THIS_MODULE,
3547 .open = lpfc_debugfs_slow_ring_trc_open,
3548 .llseek = lpfc_debugfs_lseek,
3549 .read = lpfc_debugfs_read,
3550 .release = lpfc_debugfs_release,
3551 };
3552
3553 static struct dentry *lpfc_debugfs_root = NULL;
3554 static atomic_t lpfc_debugfs_hba_count;
3555
3556 /*
3557 * File operations for the iDiag debugfs
3558 */
3559 #undef lpfc_idiag_op_pciCfg
3560 static const struct file_operations lpfc_idiag_op_pciCfg = {
3561 .owner = THIS_MODULE,
3562 .open = lpfc_idiag_open,
3563 .llseek = lpfc_debugfs_lseek,
3564 .read = lpfc_idiag_pcicfg_read,
3565 .write = lpfc_idiag_pcicfg_write,
3566 .release = lpfc_idiag_cmd_release,
3567 };
3568
3569 #undef lpfc_idiag_op_barAcc
3570 static const struct file_operations lpfc_idiag_op_barAcc = {
3571 .owner = THIS_MODULE,
3572 .open = lpfc_idiag_open,
3573 .llseek = lpfc_debugfs_lseek,
3574 .read = lpfc_idiag_baracc_read,
3575 .write = lpfc_idiag_baracc_write,
3576 .release = lpfc_idiag_cmd_release,
3577 };
3578
3579 #undef lpfc_idiag_op_queInfo
3580 static const struct file_operations lpfc_idiag_op_queInfo = {
3581 .owner = THIS_MODULE,
3582 .open = lpfc_idiag_open,
3583 .read = lpfc_idiag_queinfo_read,
3584 .release = lpfc_idiag_release,
3585 };
3586
3587 #undef lpfc_idiag_op_queAcc
3588 static const struct file_operations lpfc_idiag_op_queAcc = {
3589 .owner = THIS_MODULE,
3590 .open = lpfc_idiag_open,
3591 .llseek = lpfc_debugfs_lseek,
3592 .read = lpfc_idiag_queacc_read,
3593 .write = lpfc_idiag_queacc_write,
3594 .release = lpfc_idiag_cmd_release,
3595 };
3596
3597 #undef lpfc_idiag_op_drbAcc
3598 static const struct file_operations lpfc_idiag_op_drbAcc = {
3599 .owner = THIS_MODULE,
3600 .open = lpfc_idiag_open,
3601 .llseek = lpfc_debugfs_lseek,
3602 .read = lpfc_idiag_drbacc_read,
3603 .write = lpfc_idiag_drbacc_write,
3604 .release = lpfc_idiag_cmd_release,
3605 };
3606
3607 #undef lpfc_idiag_op_ctlAcc
3608 static const struct file_operations lpfc_idiag_op_ctlAcc = {
3609 .owner = THIS_MODULE,
3610 .open = lpfc_idiag_open,
3611 .llseek = lpfc_debugfs_lseek,
3612 .read = lpfc_idiag_ctlacc_read,
3613 .write = lpfc_idiag_ctlacc_write,
3614 .release = lpfc_idiag_cmd_release,
3615 };
3616
3617 #undef lpfc_idiag_op_mbxAcc
3618 static const struct file_operations lpfc_idiag_op_mbxAcc = {
3619 .owner = THIS_MODULE,
3620 .open = lpfc_idiag_open,
3621 .llseek = lpfc_debugfs_lseek,
3622 .read = lpfc_idiag_mbxacc_read,
3623 .write = lpfc_idiag_mbxacc_write,
3624 .release = lpfc_idiag_cmd_release,
3625 };
3626
3627 #undef lpfc_idiag_op_extAcc
3628 static const struct file_operations lpfc_idiag_op_extAcc = {
3629 .owner = THIS_MODULE,
3630 .open = lpfc_idiag_open,
3631 .llseek = lpfc_debugfs_lseek,
3632 .read = lpfc_idiag_extacc_read,
3633 .write = lpfc_idiag_extacc_write,
3634 .release = lpfc_idiag_cmd_release,
3635 };
3636
3637 #endif
3638
3639 /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
3640 * @phba: Pointer to HBA context object.
3641 * @dmabuf: Pointer to a DMA buffer descriptor.
3642 *
3643 * Description:
3644 * This routine dump a bsg pass-through non-embedded mailbox command with
3645 * external buffer.
3646 **/
3647 void
3648 lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
3649 enum mbox_type mbox_tp, enum dma_type dma_tp,
3650 enum sta_type sta_tp,
3651 struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
3652 {
3653 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3654 uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
3655 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3656 int len = 0;
3657 uint32_t do_dump = 0;
3658 uint32_t *pword;
3659 uint32_t i;
3660
3661 if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
3662 return;
3663
3664 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3665 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3666 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3667 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3668
3669 if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
3670 (*mbx_dump_cnt == 0) ||
3671 (*mbx_word_cnt == 0))
3672 return;
3673
3674 if (*mbx_mbox_cmd != 0x9B)
3675 return;
3676
3677 if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
3678 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
3679 do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
3680 printk(KERN_ERR "\nRead mbox command (x%x), "
3681 "nemb:0x%x, extbuf_cnt:%d:\n",
3682 sta_tp, nemb_tp, ext_buf);
3683 }
3684 }
3685 if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
3686 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
3687 do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
3688 printk(KERN_ERR "\nRead mbox buffer (x%x), "
3689 "nemb:0x%x, extbuf_seq:%d:\n",
3690 sta_tp, nemb_tp, ext_buf);
3691 }
3692 }
3693 if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
3694 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
3695 do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
3696 printk(KERN_ERR "\nWrite mbox command (x%x), "
3697 "nemb:0x%x, extbuf_cnt:%d:\n",
3698 sta_tp, nemb_tp, ext_buf);
3699 }
3700 }
3701 if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
3702 if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
3703 do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
3704 printk(KERN_ERR "\nWrite mbox buffer (x%x), "
3705 "nemb:0x%x, extbuf_seq:%d:\n",
3706 sta_tp, nemb_tp, ext_buf);
3707 }
3708 }
3709
3710 /* dump buffer content */
3711 if (do_dump) {
3712 pword = (uint32_t *)dmabuf->virt;
3713 for (i = 0; i < *mbx_word_cnt; i++) {
3714 if (!(i % 8)) {
3715 if (i != 0)
3716 printk(KERN_ERR "%s\n", line_buf);
3717 len = 0;
3718 len += snprintf(line_buf+len,
3719 LPFC_MBX_ACC_LBUF_SZ-len,
3720 "%03d: ", i);
3721 }
3722 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3723 "%08x ", (uint32_t)*pword);
3724 pword++;
3725 }
3726 if ((i - 1) % 8)
3727 printk(KERN_ERR "%s\n", line_buf);
3728 (*mbx_dump_cnt)--;
3729 }
3730
3731 /* Clean out command structure on reaching dump count */
3732 if (*mbx_dump_cnt == 0)
3733 memset(&idiag, 0, sizeof(idiag));
3734 return;
3735 #endif
3736 }
3737
3738 /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
3739 * @phba: Pointer to HBA context object.
3740 * @dmabuf: Pointer to a DMA buffer descriptor.
3741 *
3742 * Description:
3743 * This routine dump a pass-through non-embedded mailbox command from issue
3744 * mailbox command.
3745 **/
3746 void
3747 lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
3748 {
3749 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3750 uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
3751 char line_buf[LPFC_MBX_ACC_LBUF_SZ];
3752 int len = 0;
3753 uint32_t *pword;
3754 uint8_t *pbyte;
3755 uint32_t i, j;
3756
3757 if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
3758 return;
3759
3760 mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
3761 mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
3762 mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
3763 mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
3764
3765 if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
3766 (*mbx_dump_cnt == 0) ||
3767 (*mbx_word_cnt == 0))
3768 return;
3769
3770 if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
3771 (*mbx_mbox_cmd != pmbox->mbxCommand))
3772 return;
3773
3774 /* dump buffer content */
3775 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
3776 printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
3777 pmbox->mbxCommand);
3778 pword = (uint32_t *)pmbox;
3779 for (i = 0; i < *mbx_word_cnt; i++) {
3780 if (!(i % 8)) {
3781 if (i != 0)
3782 printk(KERN_ERR "%s\n", line_buf);
3783 len = 0;
3784 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3785 len += snprintf(line_buf+len,
3786 LPFC_MBX_ACC_LBUF_SZ-len,
3787 "%03d: ", i);
3788 }
3789 len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
3790 "%08x ",
3791 ((uint32_t)*pword) & 0xffffffff);
3792 pword++;
3793 }
3794 if ((i - 1) % 8)
3795 printk(KERN_ERR "%s\n", line_buf);
3796 printk(KERN_ERR "\n");
3797 }
3798 if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
3799 printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
3800 pmbox->mbxCommand);
3801 pbyte = (uint8_t *)pmbox;
3802 for (i = 0; i < *mbx_word_cnt; i++) {
3803 if (!(i % 8)) {
3804 if (i != 0)
3805 printk(KERN_ERR "%s\n", line_buf);
3806 len = 0;
3807 memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
3808 len += snprintf(line_buf+len,
3809 LPFC_MBX_ACC_LBUF_SZ-len,
3810 "%03d: ", i);
3811 }
3812 for (j = 0; j < 4; j++) {
3813 len += snprintf(line_buf+len,
3814 LPFC_MBX_ACC_LBUF_SZ-len,
3815 "%02x",
3816 ((uint8_t)*pbyte) & 0xff);
3817 pbyte++;
3818 }
3819 len += snprintf(line_buf+len,
3820 LPFC_MBX_ACC_LBUF_SZ-len, " ");
3821 }
3822 if ((i - 1) % 8)
3823 printk(KERN_ERR "%s\n", line_buf);
3824 printk(KERN_ERR "\n");
3825 }
3826 (*mbx_dump_cnt)--;
3827
3828 /* Clean out command structure on reaching dump count */
3829 if (*mbx_dump_cnt == 0)
3830 memset(&idiag, 0, sizeof(idiag));
3831 return;
3832 #endif
3833 }
3834
3835 /**
3836 * lpfc_debugfs_initialize - Initialize debugfs for a vport
3837 * @vport: The vport pointer to initialize.
3838 *
3839 * Description:
3840 * When Debugfs is configured this routine sets up the lpfc debugfs file system.
3841 * If not already created, this routine will create the lpfc directory, and
3842 * lpfcX directory (for this HBA), and vportX directory for this vport. It will
3843 * also create each file used to access lpfc specific debugfs information.
3844 **/
3845 inline void
3846 lpfc_debugfs_initialize(struct lpfc_vport *vport)
3847 {
3848 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
3849 struct lpfc_hba *phba = vport->phba;
3850 char name[64];
3851 uint32_t num, i;
3852
3853 if (!lpfc_debugfs_enable)
3854 return;
3855
3856 /* Setup lpfc root directory */
3857 if (!lpfc_debugfs_root) {
3858 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
3859 atomic_set(&lpfc_debugfs_hba_count, 0);
3860 if (!lpfc_debugfs_root) {
3861 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3862 "0408 Cannot create debugfs root\n");
3863 goto debug_failed;
3864 }
3865 }
3866 if (!lpfc_debugfs_start_time)
3867 lpfc_debugfs_start_time = jiffies;
3868
3869 /* Setup funcX directory for specific HBA PCI function */
3870 snprintf(name, sizeof(name), "fn%d", phba->brd_no);
3871 if (!phba->hba_debugfs_root) {
3872 phba->hba_debugfs_root =
3873 debugfs_create_dir(name, lpfc_debugfs_root);
3874 if (!phba->hba_debugfs_root) {
3875 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3876 "0412 Cannot create debugfs hba\n");
3877 goto debug_failed;
3878 }
3879 atomic_inc(&lpfc_debugfs_hba_count);
3880 atomic_set(&phba->debugfs_vport_count, 0);
3881
3882 /* Setup hbqinfo */
3883 snprintf(name, sizeof(name), "hbqinfo");
3884 phba->debug_hbqinfo =
3885 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3886 phba->hba_debugfs_root,
3887 phba, &lpfc_debugfs_op_hbqinfo);
3888 if (!phba->debug_hbqinfo) {
3889 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3890 "0411 Cannot create debugfs hbqinfo\n");
3891 goto debug_failed;
3892 }
3893
3894 /* Setup dumpHBASlim */
3895 if (phba->sli_rev < LPFC_SLI_REV4) {
3896 snprintf(name, sizeof(name), "dumpHBASlim");
3897 phba->debug_dumpHBASlim =
3898 debugfs_create_file(name,
3899 S_IFREG|S_IRUGO|S_IWUSR,
3900 phba->hba_debugfs_root,
3901 phba, &lpfc_debugfs_op_dumpHBASlim);
3902 if (!phba->debug_dumpHBASlim) {
3903 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3904 "0413 Cannot create debugfs "
3905 "dumpHBASlim\n");
3906 goto debug_failed;
3907 }
3908 } else
3909 phba->debug_dumpHBASlim = NULL;
3910
3911 /* Setup dumpHostSlim */
3912 if (phba->sli_rev < LPFC_SLI_REV4) {
3913 snprintf(name, sizeof(name), "dumpHostSlim");
3914 phba->debug_dumpHostSlim =
3915 debugfs_create_file(name,
3916 S_IFREG|S_IRUGO|S_IWUSR,
3917 phba->hba_debugfs_root,
3918 phba, &lpfc_debugfs_op_dumpHostSlim);
3919 if (!phba->debug_dumpHostSlim) {
3920 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3921 "0414 Cannot create debugfs "
3922 "dumpHostSlim\n");
3923 goto debug_failed;
3924 }
3925 } else
3926 phba->debug_dumpHBASlim = NULL;
3927
3928 /* Setup dumpData */
3929 snprintf(name, sizeof(name), "dumpData");
3930 phba->debug_dumpData =
3931 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3932 phba->hba_debugfs_root,
3933 phba, &lpfc_debugfs_op_dumpData);
3934 if (!phba->debug_dumpData) {
3935 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3936 "0800 Cannot create debugfs dumpData\n");
3937 goto debug_failed;
3938 }
3939
3940 /* Setup dumpDif */
3941 snprintf(name, sizeof(name), "dumpDif");
3942 phba->debug_dumpDif =
3943 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3944 phba->hba_debugfs_root,
3945 phba, &lpfc_debugfs_op_dumpDif);
3946 if (!phba->debug_dumpDif) {
3947 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3948 "0801 Cannot create debugfs dumpDif\n");
3949 goto debug_failed;
3950 }
3951
3952 /* Setup DIF Error Injections */
3953 snprintf(name, sizeof(name), "InjErrLBA");
3954 phba->debug_InjErrLBA =
3955 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3956 phba->hba_debugfs_root,
3957 phba, &lpfc_debugfs_op_dif_err);
3958 if (!phba->debug_InjErrLBA) {
3959 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3960 "0807 Cannot create debugfs InjErrLBA\n");
3961 goto debug_failed;
3962 }
3963 phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
3964
3965 snprintf(name, sizeof(name), "InjErrNPortID");
3966 phba->debug_InjErrNPortID =
3967 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3968 phba->hba_debugfs_root,
3969 phba, &lpfc_debugfs_op_dif_err);
3970 if (!phba->debug_InjErrNPortID) {
3971 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3972 "0809 Cannot create debugfs InjErrNPortID\n");
3973 goto debug_failed;
3974 }
3975
3976 snprintf(name, sizeof(name), "InjErrWWPN");
3977 phba->debug_InjErrWWPN =
3978 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3979 phba->hba_debugfs_root,
3980 phba, &lpfc_debugfs_op_dif_err);
3981 if (!phba->debug_InjErrWWPN) {
3982 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3983 "0810 Cannot create debugfs InjErrWWPN\n");
3984 goto debug_failed;
3985 }
3986
3987 snprintf(name, sizeof(name), "writeGuardInjErr");
3988 phba->debug_writeGuard =
3989 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
3990 phba->hba_debugfs_root,
3991 phba, &lpfc_debugfs_op_dif_err);
3992 if (!phba->debug_writeGuard) {
3993 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3994 "0802 Cannot create debugfs writeGuard\n");
3995 goto debug_failed;
3996 }
3997
3998 snprintf(name, sizeof(name), "writeAppInjErr");
3999 phba->debug_writeApp =
4000 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4001 phba->hba_debugfs_root,
4002 phba, &lpfc_debugfs_op_dif_err);
4003 if (!phba->debug_writeApp) {
4004 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4005 "0803 Cannot create debugfs writeApp\n");
4006 goto debug_failed;
4007 }
4008
4009 snprintf(name, sizeof(name), "writeRefInjErr");
4010 phba->debug_writeRef =
4011 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4012 phba->hba_debugfs_root,
4013 phba, &lpfc_debugfs_op_dif_err);
4014 if (!phba->debug_writeRef) {
4015 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4016 "0804 Cannot create debugfs writeRef\n");
4017 goto debug_failed;
4018 }
4019
4020 snprintf(name, sizeof(name), "readGuardInjErr");
4021 phba->debug_readGuard =
4022 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4023 phba->hba_debugfs_root,
4024 phba, &lpfc_debugfs_op_dif_err);
4025 if (!phba->debug_readGuard) {
4026 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4027 "0808 Cannot create debugfs readGuard\n");
4028 goto debug_failed;
4029 }
4030
4031 snprintf(name, sizeof(name), "readAppInjErr");
4032 phba->debug_readApp =
4033 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4034 phba->hba_debugfs_root,
4035 phba, &lpfc_debugfs_op_dif_err);
4036 if (!phba->debug_readApp) {
4037 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4038 "0805 Cannot create debugfs readApp\n");
4039 goto debug_failed;
4040 }
4041
4042 snprintf(name, sizeof(name), "readRefInjErr");
4043 phba->debug_readRef =
4044 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4045 phba->hba_debugfs_root,
4046 phba, &lpfc_debugfs_op_dif_err);
4047 if (!phba->debug_readRef) {
4048 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4049 "0806 Cannot create debugfs readApp\n");
4050 goto debug_failed;
4051 }
4052
4053 /* Setup slow ring trace */
4054 if (lpfc_debugfs_max_slow_ring_trc) {
4055 num = lpfc_debugfs_max_slow_ring_trc - 1;
4056 if (num & lpfc_debugfs_max_slow_ring_trc) {
4057 /* Change to be a power of 2 */
4058 num = lpfc_debugfs_max_slow_ring_trc;
4059 i = 0;
4060 while (num > 1) {
4061 num = num >> 1;
4062 i++;
4063 }
4064 lpfc_debugfs_max_slow_ring_trc = (1 << i);
4065 printk(KERN_ERR
4066 "lpfc_debugfs_max_disc_trc changed to "
4067 "%d\n", lpfc_debugfs_max_disc_trc);
4068 }
4069 }
4070
4071 snprintf(name, sizeof(name), "slow_ring_trace");
4072 phba->debug_slow_ring_trc =
4073 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4074 phba->hba_debugfs_root,
4075 phba, &lpfc_debugfs_op_slow_ring_trc);
4076 if (!phba->debug_slow_ring_trc) {
4077 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4078 "0415 Cannot create debugfs "
4079 "slow_ring_trace\n");
4080 goto debug_failed;
4081 }
4082 if (!phba->slow_ring_trc) {
4083 phba->slow_ring_trc = kmalloc(
4084 (sizeof(struct lpfc_debugfs_trc) *
4085 lpfc_debugfs_max_slow_ring_trc),
4086 GFP_KERNEL);
4087 if (!phba->slow_ring_trc) {
4088 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4089 "0416 Cannot create debugfs "
4090 "slow_ring buffer\n");
4091 goto debug_failed;
4092 }
4093 atomic_set(&phba->slow_ring_trc_cnt, 0);
4094 memset(phba->slow_ring_trc, 0,
4095 (sizeof(struct lpfc_debugfs_trc) *
4096 lpfc_debugfs_max_slow_ring_trc));
4097 }
4098 }
4099
4100 snprintf(name, sizeof(name), "vport%d", vport->vpi);
4101 if (!vport->vport_debugfs_root) {
4102 vport->vport_debugfs_root =
4103 debugfs_create_dir(name, phba->hba_debugfs_root);
4104 if (!vport->vport_debugfs_root) {
4105 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4106 "0417 Can't create debugfs\n");
4107 goto debug_failed;
4108 }
4109 atomic_inc(&phba->debugfs_vport_count);
4110 }
4111
4112 if (lpfc_debugfs_max_disc_trc) {
4113 num = lpfc_debugfs_max_disc_trc - 1;
4114 if (num & lpfc_debugfs_max_disc_trc) {
4115 /* Change to be a power of 2 */
4116 num = lpfc_debugfs_max_disc_trc;
4117 i = 0;
4118 while (num > 1) {
4119 num = num >> 1;
4120 i++;
4121 }
4122 lpfc_debugfs_max_disc_trc = (1 << i);
4123 printk(KERN_ERR
4124 "lpfc_debugfs_max_disc_trc changed to %d\n",
4125 lpfc_debugfs_max_disc_trc);
4126 }
4127 }
4128
4129 vport->disc_trc = kzalloc(
4130 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
4131 GFP_KERNEL);
4132
4133 if (!vport->disc_trc) {
4134 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4135 "0418 Cannot create debugfs disc trace "
4136 "buffer\n");
4137 goto debug_failed;
4138 }
4139 atomic_set(&vport->disc_trc_cnt, 0);
4140
4141 snprintf(name, sizeof(name), "discovery_trace");
4142 vport->debug_disc_trc =
4143 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4144 vport->vport_debugfs_root,
4145 vport, &lpfc_debugfs_op_disc_trc);
4146 if (!vport->debug_disc_trc) {
4147 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4148 "0419 Cannot create debugfs "
4149 "discovery_trace\n");
4150 goto debug_failed;
4151 }
4152 snprintf(name, sizeof(name), "nodelist");
4153 vport->debug_nodelist =
4154 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4155 vport->vport_debugfs_root,
4156 vport, &lpfc_debugfs_op_nodelist);
4157 if (!vport->debug_nodelist) {
4158 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4159 "2985 Can't create debugfs nodelist\n");
4160 goto debug_failed;
4161 }
4162
4163 /*
4164 * iDiag debugfs root entry points for SLI4 device only
4165 */
4166 if (phba->sli_rev < LPFC_SLI_REV4)
4167 goto debug_failed;
4168
4169 snprintf(name, sizeof(name), "iDiag");
4170 if (!phba->idiag_root) {
4171 phba->idiag_root =
4172 debugfs_create_dir(name, phba->hba_debugfs_root);
4173 if (!phba->idiag_root) {
4174 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4175 "2922 Can't create idiag debugfs\n");
4176 goto debug_failed;
4177 }
4178 /* Initialize iDiag data structure */
4179 memset(&idiag, 0, sizeof(idiag));
4180 }
4181
4182 /* iDiag read PCI config space */
4183 snprintf(name, sizeof(name), "pciCfg");
4184 if (!phba->idiag_pci_cfg) {
4185 phba->idiag_pci_cfg =
4186 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4187 phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
4188 if (!phba->idiag_pci_cfg) {
4189 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4190 "2923 Can't create idiag debugfs\n");
4191 goto debug_failed;
4192 }
4193 idiag.offset.last_rd = 0;
4194 }
4195
4196 /* iDiag PCI BAR access */
4197 snprintf(name, sizeof(name), "barAcc");
4198 if (!phba->idiag_bar_acc) {
4199 phba->idiag_bar_acc =
4200 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4201 phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
4202 if (!phba->idiag_bar_acc) {
4203 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4204 "3056 Can't create idiag debugfs\n");
4205 goto debug_failed;
4206 }
4207 idiag.offset.last_rd = 0;
4208 }
4209
4210 /* iDiag get PCI function queue information */
4211 snprintf(name, sizeof(name), "queInfo");
4212 if (!phba->idiag_que_info) {
4213 phba->idiag_que_info =
4214 debugfs_create_file(name, S_IFREG|S_IRUGO,
4215 phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
4216 if (!phba->idiag_que_info) {
4217 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4218 "2924 Can't create idiag debugfs\n");
4219 goto debug_failed;
4220 }
4221 }
4222
4223 /* iDiag access PCI function queue */
4224 snprintf(name, sizeof(name), "queAcc");
4225 if (!phba->idiag_que_acc) {
4226 phba->idiag_que_acc =
4227 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4228 phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
4229 if (!phba->idiag_que_acc) {
4230 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4231 "2926 Can't create idiag debugfs\n");
4232 goto debug_failed;
4233 }
4234 }
4235
4236 /* iDiag access PCI function doorbell registers */
4237 snprintf(name, sizeof(name), "drbAcc");
4238 if (!phba->idiag_drb_acc) {
4239 phba->idiag_drb_acc =
4240 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4241 phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
4242 if (!phba->idiag_drb_acc) {
4243 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4244 "2927 Can't create idiag debugfs\n");
4245 goto debug_failed;
4246 }
4247 }
4248
4249 /* iDiag access PCI function control registers */
4250 snprintf(name, sizeof(name), "ctlAcc");
4251 if (!phba->idiag_ctl_acc) {
4252 phba->idiag_ctl_acc =
4253 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4254 phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
4255 if (!phba->idiag_ctl_acc) {
4256 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4257 "2981 Can't create idiag debugfs\n");
4258 goto debug_failed;
4259 }
4260 }
4261
4262 /* iDiag access mbox commands */
4263 snprintf(name, sizeof(name), "mbxAcc");
4264 if (!phba->idiag_mbx_acc) {
4265 phba->idiag_mbx_acc =
4266 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
4267 phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
4268 if (!phba->idiag_mbx_acc) {
4269 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4270 "2980 Can't create idiag debugfs\n");
4271 goto debug_failed;
4272 }
4273 }
4274
4275 /* iDiag extents access commands */
4276 if (phba->sli4_hba.extents_in_use) {
4277 snprintf(name, sizeof(name), "extAcc");
4278 if (!phba->idiag_ext_acc) {
4279 phba->idiag_ext_acc =
4280 debugfs_create_file(name,
4281 S_IFREG|S_IRUGO|S_IWUSR,
4282 phba->idiag_root, phba,
4283 &lpfc_idiag_op_extAcc);
4284 if (!phba->idiag_ext_acc) {
4285 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4286 "2986 Cant create "
4287 "idiag debugfs\n");
4288 goto debug_failed;
4289 }
4290 }
4291 }
4292
4293 debug_failed:
4294 return;
4295 #endif
4296 }
4297
4298 /**
4299 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
4300 * @vport: The vport pointer to remove from debugfs.
4301 *
4302 * Description:
4303 * When Debugfs is configured this routine removes debugfs file system elements
4304 * that are specific to this vport. It also checks to see if there are any
4305 * users left for the debugfs directories associated with the HBA and driver. If
4306 * this is the last user of the HBA directory or driver directory then it will
4307 * remove those from the debugfs infrastructure as well.
4308 **/
4309 inline void
4310 lpfc_debugfs_terminate(struct lpfc_vport *vport)
4311 {
4312 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
4313 struct lpfc_hba *phba = vport->phba;
4314
4315 if (vport->disc_trc) {
4316 kfree(vport->disc_trc);
4317 vport->disc_trc = NULL;
4318 }
4319 if (vport->debug_disc_trc) {
4320 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
4321 vport->debug_disc_trc = NULL;
4322 }
4323 if (vport->debug_nodelist) {
4324 debugfs_remove(vport->debug_nodelist); /* nodelist */
4325 vport->debug_nodelist = NULL;
4326 }
4327 if (vport->vport_debugfs_root) {
4328 debugfs_remove(vport->vport_debugfs_root); /* vportX */
4329 vport->vport_debugfs_root = NULL;
4330 atomic_dec(&phba->debugfs_vport_count);
4331 }
4332 if (atomic_read(&phba->debugfs_vport_count) == 0) {
4333
4334 if (phba->debug_hbqinfo) {
4335 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
4336 phba->debug_hbqinfo = NULL;
4337 }
4338 if (phba->debug_dumpHBASlim) {
4339 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
4340 phba->debug_dumpHBASlim = NULL;
4341 }
4342 if (phba->debug_dumpHostSlim) {
4343 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
4344 phba->debug_dumpHostSlim = NULL;
4345 }
4346 if (phba->debug_dumpData) {
4347 debugfs_remove(phba->debug_dumpData); /* dumpData */
4348 phba->debug_dumpData = NULL;
4349 }
4350
4351 if (phba->debug_dumpDif) {
4352 debugfs_remove(phba->debug_dumpDif); /* dumpDif */
4353 phba->debug_dumpDif = NULL;
4354 }
4355 if (phba->debug_InjErrLBA) {
4356 debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
4357 phba->debug_InjErrLBA = NULL;
4358 }
4359 if (phba->debug_InjErrNPortID) { /* InjErrNPortID */
4360 debugfs_remove(phba->debug_InjErrNPortID);
4361 phba->debug_InjErrNPortID = NULL;
4362 }
4363 if (phba->debug_InjErrWWPN) {
4364 debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */
4365 phba->debug_InjErrWWPN = NULL;
4366 }
4367 if (phba->debug_writeGuard) {
4368 debugfs_remove(phba->debug_writeGuard); /* writeGuard */
4369 phba->debug_writeGuard = NULL;
4370 }
4371 if (phba->debug_writeApp) {
4372 debugfs_remove(phba->debug_writeApp); /* writeApp */
4373 phba->debug_writeApp = NULL;
4374 }
4375 if (phba->debug_writeRef) {
4376 debugfs_remove(phba->debug_writeRef); /* writeRef */
4377 phba->debug_writeRef = NULL;
4378 }
4379 if (phba->debug_readGuard) {
4380 debugfs_remove(phba->debug_readGuard); /* readGuard */
4381 phba->debug_readGuard = NULL;
4382 }
4383 if (phba->debug_readApp) {
4384 debugfs_remove(phba->debug_readApp); /* readApp */
4385 phba->debug_readApp = NULL;
4386 }
4387 if (phba->debug_readRef) {
4388 debugfs_remove(phba->debug_readRef); /* readRef */
4389 phba->debug_readRef = NULL;
4390 }
4391
4392 if (phba->slow_ring_trc) {
4393 kfree(phba->slow_ring_trc);
4394 phba->slow_ring_trc = NULL;
4395 }
4396 if (phba->debug_slow_ring_trc) {
4397 /* slow_ring_trace */
4398 debugfs_remove(phba->debug_slow_ring_trc);
4399 phba->debug_slow_ring_trc = NULL;
4400 }
4401
4402 /*
4403 * iDiag release
4404 */
4405 if (phba->sli_rev == LPFC_SLI_REV4) {
4406 if (phba->idiag_ext_acc) {
4407 /* iDiag extAcc */
4408 debugfs_remove(phba->idiag_ext_acc);
4409 phba->idiag_ext_acc = NULL;
4410 }
4411 if (phba->idiag_mbx_acc) {
4412 /* iDiag mbxAcc */
4413 debugfs_remove(phba->idiag_mbx_acc);
4414 phba->idiag_mbx_acc = NULL;
4415 }
4416 if (phba->idiag_ctl_acc) {
4417 /* iDiag ctlAcc */
4418 debugfs_remove(phba->idiag_ctl_acc);
4419 phba->idiag_ctl_acc = NULL;
4420 }
4421 if (phba->idiag_drb_acc) {
4422 /* iDiag drbAcc */
4423 debugfs_remove(phba->idiag_drb_acc);
4424 phba->idiag_drb_acc = NULL;
4425 }
4426 if (phba->idiag_que_acc) {
4427 /* iDiag queAcc */
4428 debugfs_remove(phba->idiag_que_acc);
4429 phba->idiag_que_acc = NULL;
4430 }
4431 if (phba->idiag_que_info) {
4432 /* iDiag queInfo */
4433 debugfs_remove(phba->idiag_que_info);
4434 phba->idiag_que_info = NULL;
4435 }
4436 if (phba->idiag_bar_acc) {
4437 /* iDiag barAcc */
4438 debugfs_remove(phba->idiag_bar_acc);
4439 phba->idiag_bar_acc = NULL;
4440 }
4441 if (phba->idiag_pci_cfg) {
4442 /* iDiag pciCfg */
4443 debugfs_remove(phba->idiag_pci_cfg);
4444 phba->idiag_pci_cfg = NULL;
4445 }
4446
4447 /* Finally remove the iDiag debugfs root */
4448 if (phba->idiag_root) {
4449 /* iDiag root */
4450 debugfs_remove(phba->idiag_root);
4451 phba->idiag_root = NULL;
4452 }
4453 }
4454
4455 if (phba->hba_debugfs_root) {
4456 debugfs_remove(phba->hba_debugfs_root); /* fnX */
4457 phba->hba_debugfs_root = NULL;
4458 atomic_dec(&lpfc_debugfs_hba_count);
4459 }
4460
4461 if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
4462 debugfs_remove(lpfc_debugfs_root); /* lpfc */
4463 lpfc_debugfs_root = NULL;
4464 }
4465 }
4466 #endif
4467 return;
4468 }
4469
4470 /*
4471 * Driver debug utility routines outside of debugfs. The debug utility
4472 * routines implemented here is intended to be used in the instrumented
4473 * debug driver for debugging host or port issues.
4474 */
4475
4476 /**
4477 * lpfc_debug_dump_all_queues - dump all the queues with a hba
4478 * @phba: Pointer to HBA context object.
4479 *
4480 * This function dumps entries of all the queues asociated with the @phba.
4481 **/
4482 void
4483 lpfc_debug_dump_all_queues(struct lpfc_hba *phba)
4484 {
4485 int fcp_wqidx;
4486
4487 /*
4488 * Dump Work Queues (WQs)
4489 */
4490 lpfc_debug_dump_mbx_wq(phba);
4491 lpfc_debug_dump_els_wq(phba);
4492
4493 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++)
4494 lpfc_debug_dump_fcp_wq(phba, fcp_wqidx);
4495
4496 lpfc_debug_dump_hdr_rq(phba);
4497 lpfc_debug_dump_dat_rq(phba);
4498 /*
4499 * Dump Complete Queues (CQs)
4500 */
4501 lpfc_debug_dump_mbx_cq(phba);
4502 lpfc_debug_dump_els_cq(phba);
4503
4504 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++)
4505 lpfc_debug_dump_fcp_cq(phba, fcp_wqidx);
4506
4507 /*
4508 * Dump Event Queues (EQs)
4509 */
4510 lpfc_debug_dump_sp_eq(phba);
4511
4512 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++)
4513 lpfc_debug_dump_fcp_eq(phba, fcp_wqidx);
4514 }
This page took 0.130157 seconds and 5 git commands to generate.