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