1 /******************************************************************* 2 * This file is part of the Emulex Linux Device Driver for * 3 * Fibre Channel Host Bus Adapters. * 4 * Copyright (C) 2007-2008 Emulex. All rights reserved. * 5 * EMULEX and SLI are trademarks of Emulex. * 6 * www.emulex.com * 7 * * 8 * This program is free software; you can redistribute it and/or * 9 * modify it under the terms of version 2 of the GNU General * 10 * Public License as published by the Free Software Foundation. * 11 * This program is distributed in the hope that it will be useful. * 12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 16 * TO BE LEGALLY INVALID. See the GNU General Public License for * 17 * more details, a copy of which can be found in the file COPYING * 18 * included with this package. * 19 *******************************************************************/ 20 21 #include <linux/blkdev.h> 22 #include <linux/delay.h> 23 #include <linux/dma-mapping.h> 24 #include <linux/idr.h> 25 #include <linux/interrupt.h> 26 #include <linux/kthread.h> 27 #include <linux/pci.h> 28 #include <linux/spinlock.h> 29 #include <linux/ctype.h> 30 31 #include <scsi/scsi.h> 32 #include <scsi/scsi_device.h> 33 #include <scsi/scsi_host.h> 34 #include <scsi/scsi_transport_fc.h> 35 36 #include "lpfc_hw.h" 37 #include "lpfc_sli.h" 38 #include "lpfc_nl.h" 39 #include "lpfc_disc.h" 40 #include "lpfc_scsi.h" 41 #include "lpfc.h" 42 #include "lpfc_logmsg.h" 43 #include "lpfc_crtn.h" 44 #include "lpfc_vport.h" 45 #include "lpfc_version.h" 46 #include "lpfc_compat.h" 47 #include "lpfc_debugfs.h" 48 49 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 50 /* 51 * debugfs interface 52 * 53 * To access this interface the user should: 54 * # mkdir /debug 55 * # mount -t debugfs none /debug 56 * 57 * The lpfc debugfs directory hierarchy is: 58 * lpfc/lpfcX/vportY 59 * where X is the lpfc hba unique_id 60 * where Y is the vport VPI on that hba 61 * 62 * Debugging services available per vport: 63 * discovery_trace 64 * This is an ACSII readable file that contains a trace of the last 65 * lpfc_debugfs_max_disc_trc events that happened on a specific vport. 66 * See lpfc_debugfs.h for different categories of discovery events. 67 * To enable the discovery trace, the following module parameters must be set: 68 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support 69 * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for 70 * EACH vport. X MUST also be a power of 2. 71 * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in 72 * lpfc_debugfs.h . 73 * 74 * slow_ring_trace 75 * This is an ACSII readable file that contains a trace of the last 76 * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA. 77 * To enable the slow ring trace, the following module parameters must be set: 78 * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support 79 * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for 80 * the HBA. X MUST also be a power of 2. 81 */ 82 static int lpfc_debugfs_enable = 1; 83 module_param(lpfc_debugfs_enable, int, 0); 84 MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services"); 85 86 /* This MUST be a power of 2 */ 87 static int lpfc_debugfs_max_disc_trc; 88 module_param(lpfc_debugfs_max_disc_trc, int, 0); 89 MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc, 90 "Set debugfs discovery trace depth"); 91 92 /* This MUST be a power of 2 */ 93 static int lpfc_debugfs_max_slow_ring_trc; 94 module_param(lpfc_debugfs_max_slow_ring_trc, int, 0); 95 MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc, 96 "Set debugfs slow ring trace depth"); 97 98 static int lpfc_debugfs_mask_disc_trc; 99 module_param(lpfc_debugfs_mask_disc_trc, int, 0); 100 MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc, 101 "Set debugfs discovery trace mask"); 102 103 #include <linux/debugfs.h> 104 105 /* size of output line, for discovery_trace and slow_ring_trace */ 106 #define LPFC_DEBUG_TRC_ENTRY_SIZE 100 107 108 /* nodelist output buffer size */ 109 #define LPFC_NODELIST_SIZE 8192 110 #define LPFC_NODELIST_ENTRY_SIZE 120 111 112 /* dumpHBASlim output buffer size */ 113 #define LPFC_DUMPHBASLIM_SIZE 4096 114 115 /* dumpHostSlim output buffer size */ 116 #define LPFC_DUMPHOSTSLIM_SIZE 4096 117 118 /* hbqinfo output buffer size */ 119 #define LPFC_HBQINFO_SIZE 8192 120 121 struct lpfc_debug { 122 char *buffer; 123 int len; 124 }; 125 126 static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0); 127 static unsigned long lpfc_debugfs_start_time = 0L; 128 129 /** 130 * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer 131 * @vport: The vport to gather the log info from. 132 * @buf: The buffer to dump log into. 133 * @size: The maximum amount of data to process. 134 * 135 * Description: 136 * This routine gathers the lpfc discovery debugfs data from the @vport and 137 * dumps it to @buf up to @size number of bytes. It will start at the next entry 138 * in the log and process the log until the end of the buffer. Then it will 139 * gather from the beginning of the log and process until the current entry. 140 * 141 * Notes: 142 * Discovery logging will be disabled while while this routine dumps the log. 143 * 144 * Return Value: 145 * This routine returns the amount of bytes that were dumped into @buf and will 146 * not exceed @size. 147 **/ 148 static int 149 lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size) 150 { 151 int i, index, len, enable; 152 uint32_t ms; 153 struct lpfc_debugfs_trc *dtp; 154 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE]; 155 156 enable = lpfc_debugfs_enable; 157 lpfc_debugfs_enable = 0; 158 159 len = 0; 160 index = (atomic_read(&vport->disc_trc_cnt) + 1) & 161 (lpfc_debugfs_max_disc_trc - 1); 162 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) { 163 dtp = vport->disc_trc + i; 164 if (!dtp->fmt) 165 continue; 166 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); 167 snprintf(buffer, 168 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", 169 dtp->seq_cnt, ms, dtp->fmt); 170 len += snprintf(buf+len, size-len, buffer, 171 dtp->data1, dtp->data2, dtp->data3); 172 } 173 for (i = 0; i < index; i++) { 174 dtp = vport->disc_trc + i; 175 if (!dtp->fmt) 176 continue; 177 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); 178 snprintf(buffer, 179 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", 180 dtp->seq_cnt, ms, dtp->fmt); 181 len += snprintf(buf+len, size-len, buffer, 182 dtp->data1, dtp->data2, dtp->data3); 183 } 184 185 lpfc_debugfs_enable = enable; 186 return len; 187 } 188 189 /** 190 * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer 191 * @phba: The HBA to gather the log info from. 192 * @buf: The buffer to dump log into. 193 * @size: The maximum amount of data to process. 194 * 195 * Description: 196 * This routine gathers the lpfc slow ring debugfs data from the @phba and 197 * dumps it to @buf up to @size number of bytes. It will start at the next entry 198 * in the log and process the log until the end of the buffer. Then it will 199 * gather from the beginning of the log and process until the current entry. 200 * 201 * Notes: 202 * Slow ring logging will be disabled while while this routine dumps the log. 203 * 204 * Return Value: 205 * This routine returns the amount of bytes that were dumped into @buf and will 206 * not exceed @size. 207 **/ 208 static int 209 lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size) 210 { 211 int i, index, len, enable; 212 uint32_t ms; 213 struct lpfc_debugfs_trc *dtp; 214 char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE]; 215 216 217 enable = lpfc_debugfs_enable; 218 lpfc_debugfs_enable = 0; 219 220 len = 0; 221 index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) & 222 (lpfc_debugfs_max_slow_ring_trc - 1); 223 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) { 224 dtp = phba->slow_ring_trc + i; 225 if (!dtp->fmt) 226 continue; 227 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); 228 snprintf(buffer, 229 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", 230 dtp->seq_cnt, ms, dtp->fmt); 231 len += snprintf(buf+len, size-len, buffer, 232 dtp->data1, dtp->data2, dtp->data3); 233 } 234 for (i = 0; i < index; i++) { 235 dtp = phba->slow_ring_trc + i; 236 if (!dtp->fmt) 237 continue; 238 ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); 239 snprintf(buffer, 240 LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", 241 dtp->seq_cnt, ms, dtp->fmt); 242 len += snprintf(buf+len, size-len, buffer, 243 dtp->data1, dtp->data2, dtp->data3); 244 } 245 246 lpfc_debugfs_enable = enable; 247 return len; 248 } 249 250 static int lpfc_debugfs_last_hbq = -1; 251 252 /** 253 * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer 254 * @phba: The HBA to gather host buffer info from. 255 * @buf: The buffer to dump log into. 256 * @size: The maximum amount of data to process. 257 * 258 * Description: 259 * This routine dumps the host buffer queue info from the @phba to @buf up to 260 * @size number of bytes. A header that describes the current hbq state will be 261 * dumped to @buf first and then info on each hbq entry will be dumped to @buf 262 * until @size bytes have been dumped or all the hbq info has been dumped. 263 * 264 * Notes: 265 * This routine will rotate through each configured HBQ each time called. 266 * 267 * Return Value: 268 * This routine returns the amount of bytes that were dumped into @buf and will 269 * not exceed @size. 270 **/ 271 static int 272 lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size) 273 { 274 int len = 0; 275 int cnt, i, j, found, posted, low; 276 uint32_t phys, raw_index, getidx; 277 struct lpfc_hbq_init *hip; 278 struct hbq_s *hbqs; 279 struct lpfc_hbq_entry *hbqe; 280 struct lpfc_dmabuf *d_buf; 281 struct hbq_dmabuf *hbq_buf; 282 283 cnt = LPFC_HBQINFO_SIZE; 284 spin_lock_irq(&phba->hbalock); 285 286 /* toggle between multiple hbqs, if any */ 287 i = lpfc_sli_hbq_count(); 288 if (i > 1) { 289 lpfc_debugfs_last_hbq++; 290 if (lpfc_debugfs_last_hbq >= i) 291 lpfc_debugfs_last_hbq = 0; 292 } 293 else 294 lpfc_debugfs_last_hbq = 0; 295 296 i = lpfc_debugfs_last_hbq; 297 298 len += snprintf(buf+len, size-len, "HBQ %d Info\n", i); 299 300 hbqs = &phba->hbqs[i]; 301 posted = 0; 302 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) 303 posted++; 304 305 hip = lpfc_hbq_defs[i]; 306 len += snprintf(buf+len, size-len, 307 "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n", 308 hip->hbq_index, hip->profile, hip->rn, 309 hip->buffer_count, hip->init_count, hip->add_count, posted); 310 311 raw_index = phba->hbq_get[i]; 312 getidx = le32_to_cpu(raw_index); 313 len += snprintf(buf+len, size-len, 314 "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n", 315 hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx, 316 hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx); 317 318 hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt; 319 for (j=0; j<hbqs->entry_count; j++) { 320 len += snprintf(buf+len, size-len, 321 "%03d: %08x %04x %05x ", j, 322 le32_to_cpu(hbqe->bde.addrLow), 323 le32_to_cpu(hbqe->bde.tus.w), 324 le32_to_cpu(hbqe->buffer_tag)); 325 i = 0; 326 found = 0; 327 328 /* First calculate if slot has an associated posted buffer */ 329 low = hbqs->hbqPutIdx - posted; 330 if (low >= 0) { 331 if ((j >= hbqs->hbqPutIdx) || (j < low)) { 332 len += snprintf(buf+len, size-len, "Unused\n"); 333 goto skipit; 334 } 335 } 336 else { 337 if ((j >= hbqs->hbqPutIdx) && 338 (j < (hbqs->entry_count+low))) { 339 len += snprintf(buf+len, size-len, "Unused\n"); 340 goto skipit; 341 } 342 } 343 344 /* Get the Buffer info for the posted buffer */ 345 list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) { 346 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); 347 phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff); 348 if (phys == le32_to_cpu(hbqe->bde.addrLow)) { 349 len += snprintf(buf+len, size-len, 350 "Buf%d: %p %06x\n", i, 351 hbq_buf->dbuf.virt, hbq_buf->tag); 352 found = 1; 353 break; 354 } 355 i++; 356 } 357 if (!found) { 358 len += snprintf(buf+len, size-len, "No DMAinfo?\n"); 359 } 360 skipit: 361 hbqe++; 362 if (len > LPFC_HBQINFO_SIZE - 54) 363 break; 364 } 365 spin_unlock_irq(&phba->hbalock); 366 return len; 367 } 368 369 static int lpfc_debugfs_last_hba_slim_off; 370 371 /** 372 * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer 373 * @phba: The HBA to gather SLIM info from. 374 * @buf: The buffer to dump log into. 375 * @size: The maximum amount of data to process. 376 * 377 * Description: 378 * This routine dumps the current contents of HBA SLIM for the HBA associated 379 * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data. 380 * 381 * Notes: 382 * This routine will only dump up to 1024 bytes of data each time called and 383 * should be called multiple times to dump the entire HBA SLIM. 384 * 385 * Return Value: 386 * This routine returns the amount of bytes that were dumped into @buf and will 387 * not exceed @size. 388 **/ 389 static int 390 lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size) 391 { 392 int len = 0; 393 int i, off; 394 uint32_t *ptr; 395 char buffer[1024]; 396 397 off = 0; 398 spin_lock_irq(&phba->hbalock); 399 400 len += snprintf(buf+len, size-len, "HBA SLIM\n"); 401 lpfc_memcpy_from_slim(buffer, 402 phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024); 403 404 ptr = (uint32_t *)&buffer[0]; 405 off = lpfc_debugfs_last_hba_slim_off; 406 407 /* Set it up for the next time */ 408 lpfc_debugfs_last_hba_slim_off += 1024; 409 if (lpfc_debugfs_last_hba_slim_off >= 4096) 410 lpfc_debugfs_last_hba_slim_off = 0; 411 412 i = 1024; 413 while (i > 0) { 414 len += snprintf(buf+len, size-len, 415 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", 416 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), 417 *(ptr+5), *(ptr+6), *(ptr+7)); 418 ptr += 8; 419 i -= (8 * sizeof(uint32_t)); 420 off += (8 * sizeof(uint32_t)); 421 } 422 423 spin_unlock_irq(&phba->hbalock); 424 return len; 425 } 426 427 /** 428 * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer 429 * @phba: The HBA to gather Host SLIM info from. 430 * @buf: The buffer to dump log into. 431 * @size: The maximum amount of data to process. 432 * 433 * Description: 434 * This routine dumps the current contents of host SLIM for the host associated 435 * with @phba to @buf up to @size bytes of data. The dump will contain the 436 * Mailbox, PCB, Rings, and Registers that are located in host memory. 437 * 438 * Return Value: 439 * This routine returns the amount of bytes that were dumped into @buf and will 440 * not exceed @size. 441 **/ 442 static int 443 lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size) 444 { 445 int len = 0; 446 int i, off; 447 uint32_t word0, word1, word2, word3; 448 uint32_t *ptr; 449 struct lpfc_pgp *pgpp; 450 struct lpfc_sli *psli = &phba->sli; 451 struct lpfc_sli_ring *pring; 452 453 off = 0; 454 spin_lock_irq(&phba->hbalock); 455 456 len += snprintf(buf+len, size-len, "SLIM Mailbox\n"); 457 ptr = (uint32_t *)phba->slim2p.virt; 458 i = sizeof(MAILBOX_t); 459 while (i > 0) { 460 len += snprintf(buf+len, size-len, 461 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", 462 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), 463 *(ptr+5), *(ptr+6), *(ptr+7)); 464 ptr += 8; 465 i -= (8 * sizeof(uint32_t)); 466 off += (8 * sizeof(uint32_t)); 467 } 468 469 len += snprintf(buf+len, size-len, "SLIM PCB\n"); 470 ptr = (uint32_t *)phba->pcb; 471 i = sizeof(PCB_t); 472 while (i > 0) { 473 len += snprintf(buf+len, size-len, 474 "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", 475 off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), 476 *(ptr+5), *(ptr+6), *(ptr+7)); 477 ptr += 8; 478 i -= (8 * sizeof(uint32_t)); 479 off += (8 * sizeof(uint32_t)); 480 } 481 482 for (i = 0; i < 4; i++) { 483 pgpp = &phba->port_gp[i]; 484 pring = &psli->ring[i]; 485 len += snprintf(buf+len, size-len, 486 "Ring %d: CMD GetInx:%d (Max:%d Next:%d " 487 "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n", 488 i, pgpp->cmdGetInx, pring->numCiocb, 489 pring->next_cmdidx, pring->local_getidx, 490 pring->flag, pgpp->rspPutInx, pring->numRiocb); 491 } 492 word0 = readl(phba->HAregaddr); 493 word1 = readl(phba->CAregaddr); 494 word2 = readl(phba->HSregaddr); 495 word3 = readl(phba->HCregaddr); 496 len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n", 497 word0, word1, word2, word3); 498 spin_unlock_irq(&phba->hbalock); 499 return len; 500 } 501 502 /** 503 * lpfc_debugfs_nodelist_data - Dump target node list to a buffer 504 * @vport: The vport to gather target node info from. 505 * @buf: The buffer to dump log into. 506 * @size: The maximum amount of data to process. 507 * 508 * Description: 509 * This routine dumps the current target node list associated with @vport to 510 * @buf up to @size bytes of data. Each node entry in the dump will contain a 511 * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields. 512 * 513 * Return Value: 514 * This routine returns the amount of bytes that were dumped into @buf and will 515 * not exceed @size. 516 **/ 517 static int 518 lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size) 519 { 520 int len = 0; 521 int cnt; 522 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 523 struct lpfc_nodelist *ndlp; 524 unsigned char *statep, *name; 525 526 cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE); 527 528 spin_lock_irq(shost->host_lock); 529 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 530 if (!cnt) { 531 len += snprintf(buf+len, size-len, 532 "Missing Nodelist Entries\n"); 533 break; 534 } 535 cnt--; 536 switch (ndlp->nlp_state) { 537 case NLP_STE_UNUSED_NODE: 538 statep = "UNUSED"; 539 break; 540 case NLP_STE_PLOGI_ISSUE: 541 statep = "PLOGI "; 542 break; 543 case NLP_STE_ADISC_ISSUE: 544 statep = "ADISC "; 545 break; 546 case NLP_STE_REG_LOGIN_ISSUE: 547 statep = "REGLOG"; 548 break; 549 case NLP_STE_PRLI_ISSUE: 550 statep = "PRLI "; 551 break; 552 case NLP_STE_UNMAPPED_NODE: 553 statep = "UNMAP "; 554 break; 555 case NLP_STE_MAPPED_NODE: 556 statep = "MAPPED"; 557 break; 558 case NLP_STE_NPR_NODE: 559 statep = "NPR "; 560 break; 561 default: 562 statep = "UNKNOWN"; 563 } 564 len += snprintf(buf+len, size-len, "%s DID:x%06x ", 565 statep, ndlp->nlp_DID); 566 name = (unsigned char *)&ndlp->nlp_portname; 567 len += snprintf(buf+len, size-len, 568 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", 569 *name, *(name+1), *(name+2), *(name+3), 570 *(name+4), *(name+5), *(name+6), *(name+7)); 571 name = (unsigned char *)&ndlp->nlp_nodename; 572 len += snprintf(buf+len, size-len, 573 "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", 574 *name, *(name+1), *(name+2), *(name+3), 575 *(name+4), *(name+5), *(name+6), *(name+7)); 576 len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ", 577 ndlp->nlp_rpi, ndlp->nlp_flag); 578 if (!ndlp->nlp_type) 579 len += snprintf(buf+len, size-len, "UNKNOWN_TYPE "); 580 if (ndlp->nlp_type & NLP_FC_NODE) 581 len += snprintf(buf+len, size-len, "FC_NODE "); 582 if (ndlp->nlp_type & NLP_FABRIC) 583 len += snprintf(buf+len, size-len, "FABRIC "); 584 if (ndlp->nlp_type & NLP_FCP_TARGET) 585 len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ", 586 ndlp->nlp_sid); 587 if (ndlp->nlp_type & NLP_FCP_INITIATOR) 588 len += snprintf(buf+len, size-len, "FCP_INITIATOR "); 589 len += snprintf(buf+len, size-len, "usgmap:%x ", 590 ndlp->nlp_usg_map); 591 len += snprintf(buf+len, size-len, "refcnt:%x", 592 atomic_read(&ndlp->kref.refcount)); 593 len += snprintf(buf+len, size-len, "\n"); 594 } 595 spin_unlock_irq(shost->host_lock); 596 return len; 597 } 598 #endif 599 600 /** 601 * lpfc_debugfs_disc_trc - Store discovery trace log 602 * @vport: The vport to associate this trace string with for retrieval. 603 * @mask: Log entry classification. 604 * @fmt: Format string to be displayed when dumping the log. 605 * @data1: 1st data parameter to be applied to @fmt. 606 * @data2: 2nd data parameter to be applied to @fmt. 607 * @data3: 3rd data parameter to be applied to @fmt. 608 * 609 * Description: 610 * This routine is used by the driver code to add a debugfs log entry to the 611 * discovery trace buffer associated with @vport. Only entries with a @mask that 612 * match the current debugfs discovery mask will be saved. Entries that do not 613 * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like 614 * printf when displaying the log. 615 **/ 616 inline void 617 lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt, 618 uint32_t data1, uint32_t data2, uint32_t data3) 619 { 620 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 621 struct lpfc_debugfs_trc *dtp; 622 int index; 623 624 if (!(lpfc_debugfs_mask_disc_trc & mask)) 625 return; 626 627 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc || 628 !vport || !vport->disc_trc) 629 return; 630 631 index = atomic_inc_return(&vport->disc_trc_cnt) & 632 (lpfc_debugfs_max_disc_trc - 1); 633 dtp = vport->disc_trc + index; 634 dtp->fmt = fmt; 635 dtp->data1 = data1; 636 dtp->data2 = data2; 637 dtp->data3 = data3; 638 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt); 639 dtp->jif = jiffies; 640 #endif 641 return; 642 } 643 644 /** 645 * lpfc_debugfs_slow_ring_trc - Store slow ring trace log 646 * @phba: The phba to associate this trace string with for retrieval. 647 * @fmt: Format string to be displayed when dumping the log. 648 * @data1: 1st data parameter to be applied to @fmt. 649 * @data2: 2nd data parameter to be applied to @fmt. 650 * @data3: 3rd data parameter to be applied to @fmt. 651 * 652 * Description: 653 * This routine is used by the driver code to add a debugfs log entry to the 654 * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and 655 * @data3 are used like printf when displaying the log. 656 **/ 657 inline void 658 lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt, 659 uint32_t data1, uint32_t data2, uint32_t data3) 660 { 661 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 662 struct lpfc_debugfs_trc *dtp; 663 int index; 664 665 if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc || 666 !phba || !phba->slow_ring_trc) 667 return; 668 669 index = atomic_inc_return(&phba->slow_ring_trc_cnt) & 670 (lpfc_debugfs_max_slow_ring_trc - 1); 671 dtp = phba->slow_ring_trc + index; 672 dtp->fmt = fmt; 673 dtp->data1 = data1; 674 dtp->data2 = data2; 675 dtp->data3 = data3; 676 dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt); 677 dtp->jif = jiffies; 678 #endif 679 return; 680 } 681 682 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 683 /** 684 * lpfc_debugfs_disc_trc_open - Open the discovery trace log 685 * @inode: The inode pointer that contains a vport pointer. 686 * @file: The file pointer to attach the log output. 687 * 688 * Description: 689 * This routine is the entry point for the debugfs open file operation. It gets 690 * the vport from the i_private field in @inode, allocates the necessary buffer 691 * for the log, fills the buffer from the in-memory log for this vport, and then 692 * returns a pointer to that log in the private_data field in @file. 693 * 694 * Returns: 695 * This function returns zero if successful. On error it will return an negative 696 * error value. 697 **/ 698 static int 699 lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file) 700 { 701 struct lpfc_vport *vport = inode->i_private; 702 struct lpfc_debug *debug; 703 int size; 704 int rc = -ENOMEM; 705 706 if (!lpfc_debugfs_max_disc_trc) { 707 rc = -ENOSPC; 708 goto out; 709 } 710 711 debug = kmalloc(sizeof(*debug), GFP_KERNEL); 712 if (!debug) 713 goto out; 714 715 /* Round to page boundary */ 716 size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); 717 size = PAGE_ALIGN(size); 718 719 debug->buffer = kmalloc(size, GFP_KERNEL); 720 if (!debug->buffer) { 721 kfree(debug); 722 goto out; 723 } 724 725 debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size); 726 file->private_data = debug; 727 728 rc = 0; 729 out: 730 return rc; 731 } 732 733 /** 734 * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log 735 * @inode: The inode pointer that contains a vport pointer. 736 * @file: The file pointer to attach the log output. 737 * 738 * Description: 739 * This routine is the entry point for the debugfs open file operation. It gets 740 * the vport from the i_private field in @inode, allocates the necessary buffer 741 * for the log, fills the buffer from the in-memory log for this vport, and then 742 * returns a pointer to that log in the private_data field in @file. 743 * 744 * Returns: 745 * This function returns zero if successful. On error it will return an negative 746 * error value. 747 **/ 748 static int 749 lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file) 750 { 751 struct lpfc_hba *phba = inode->i_private; 752 struct lpfc_debug *debug; 753 int size; 754 int rc = -ENOMEM; 755 756 if (!lpfc_debugfs_max_slow_ring_trc) { 757 rc = -ENOSPC; 758 goto out; 759 } 760 761 debug = kmalloc(sizeof(*debug), GFP_KERNEL); 762 if (!debug) 763 goto out; 764 765 /* Round to page boundary */ 766 size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); 767 size = PAGE_ALIGN(size); 768 769 debug->buffer = kmalloc(size, GFP_KERNEL); 770 if (!debug->buffer) { 771 kfree(debug); 772 goto out; 773 } 774 775 debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size); 776 file->private_data = debug; 777 778 rc = 0; 779 out: 780 return rc; 781 } 782 783 /** 784 * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer 785 * @inode: The inode pointer that contains a vport pointer. 786 * @file: The file pointer to attach the log output. 787 * 788 * Description: 789 * This routine is the entry point for the debugfs open file operation. It gets 790 * the vport from the i_private field in @inode, allocates the necessary buffer 791 * for the log, fills the buffer from the in-memory log for this vport, and then 792 * returns a pointer to that log in the private_data field in @file. 793 * 794 * Returns: 795 * This function returns zero if successful. On error it will return an negative 796 * error value. 797 **/ 798 static int 799 lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file) 800 { 801 struct lpfc_hba *phba = inode->i_private; 802 struct lpfc_debug *debug; 803 int rc = -ENOMEM; 804 805 debug = kmalloc(sizeof(*debug), GFP_KERNEL); 806 if (!debug) 807 goto out; 808 809 /* Round to page boundary */ 810 debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL); 811 if (!debug->buffer) { 812 kfree(debug); 813 goto out; 814 } 815 816 debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer, 817 LPFC_HBQINFO_SIZE); 818 file->private_data = debug; 819 820 rc = 0; 821 out: 822 return rc; 823 } 824 825 /** 826 * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer 827 * @inode: The inode pointer that contains a vport pointer. 828 * @file: The file pointer to attach the log output. 829 * 830 * Description: 831 * This routine is the entry point for the debugfs open file operation. It gets 832 * the vport from the i_private field in @inode, allocates the necessary buffer 833 * for the log, fills the buffer from the in-memory log for this vport, and then 834 * returns a pointer to that log in the private_data field in @file. 835 * 836 * Returns: 837 * This function returns zero if successful. On error it will return an negative 838 * error value. 839 **/ 840 static int 841 lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file) 842 { 843 struct lpfc_hba *phba = inode->i_private; 844 struct lpfc_debug *debug; 845 int rc = -ENOMEM; 846 847 debug = kmalloc(sizeof(*debug), GFP_KERNEL); 848 if (!debug) 849 goto out; 850 851 /* Round to page boundary */ 852 debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL); 853 if (!debug->buffer) { 854 kfree(debug); 855 goto out; 856 } 857 858 debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer, 859 LPFC_DUMPHBASLIM_SIZE); 860 file->private_data = debug; 861 862 rc = 0; 863 out: 864 return rc; 865 } 866 867 /** 868 * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer 869 * @inode: The inode pointer that contains a vport pointer. 870 * @file: The file pointer to attach the log output. 871 * 872 * Description: 873 * This routine is the entry point for the debugfs open file operation. It gets 874 * the vport from the i_private field in @inode, allocates the necessary buffer 875 * for the log, fills the buffer from the in-memory log for this vport, and then 876 * returns a pointer to that log in the private_data field in @file. 877 * 878 * Returns: 879 * This function returns zero if successful. On error it will return an negative 880 * error value. 881 **/ 882 static int 883 lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file) 884 { 885 struct lpfc_hba *phba = inode->i_private; 886 struct lpfc_debug *debug; 887 int rc = -ENOMEM; 888 889 debug = kmalloc(sizeof(*debug), GFP_KERNEL); 890 if (!debug) 891 goto out; 892 893 /* Round to page boundary */ 894 debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL); 895 if (!debug->buffer) { 896 kfree(debug); 897 goto out; 898 } 899 900 debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer, 901 LPFC_DUMPHOSTSLIM_SIZE); 902 file->private_data = debug; 903 904 rc = 0; 905 out: 906 return rc; 907 } 908 909 static int 910 lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file) 911 { 912 struct lpfc_debug *debug; 913 int rc = -ENOMEM; 914 915 if (!_dump_buf_data) 916 return -EBUSY; 917 918 debug = kmalloc(sizeof(*debug), GFP_KERNEL); 919 if (!debug) 920 goto out; 921 922 /* Round to page boundry */ 923 printk(KERN_ERR "BLKGRD %s: _dump_buf_data=0x%p\n", 924 __func__, _dump_buf_data); 925 debug->buffer = _dump_buf_data; 926 if (!debug->buffer) { 927 kfree(debug); 928 goto out; 929 } 930 931 debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT; 932 file->private_data = debug; 933 934 rc = 0; 935 out: 936 return rc; 937 } 938 939 static int 940 lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file) 941 { 942 struct lpfc_debug *debug; 943 int rc = -ENOMEM; 944 945 if (!_dump_buf_dif) 946 return -EBUSY; 947 948 debug = kmalloc(sizeof(*debug), GFP_KERNEL); 949 if (!debug) 950 goto out; 951 952 /* Round to page boundry */ 953 printk(KERN_ERR "BLKGRD %s: _dump_buf_dif=0x%p file=%s\n", __func__, 954 _dump_buf_dif, file->f_dentry->d_name.name); 955 debug->buffer = _dump_buf_dif; 956 if (!debug->buffer) { 957 kfree(debug); 958 goto out; 959 } 960 961 debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT; 962 file->private_data = debug; 963 964 rc = 0; 965 out: 966 return rc; 967 } 968 969 static ssize_t 970 lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf, 971 size_t nbytes, loff_t *ppos) 972 { 973 /* 974 * The Data/DIF buffers only save one failing IO 975 * The write op is used as a reset mechanism after an IO has 976 * already been saved to the next one can be saved 977 */ 978 spin_lock(&_dump_buf_lock); 979 980 memset((void *)_dump_buf_data, 0, 981 ((1 << PAGE_SHIFT) << _dump_buf_data_order)); 982 memset((void *)_dump_buf_dif, 0, 983 ((1 << PAGE_SHIFT) << _dump_buf_dif_order)); 984 985 _dump_buf_done = 0; 986 987 spin_unlock(&_dump_buf_lock); 988 989 return nbytes; 990 } 991 992 993 994 /** 995 * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file 996 * @inode: The inode pointer that contains a vport pointer. 997 * @file: The file pointer to attach the log output. 998 * 999 * Description: 1000 * This routine is the entry point for the debugfs open file operation. It gets 1001 * the vport from the i_private field in @inode, allocates the necessary buffer 1002 * for the log, fills the buffer from the in-memory log for this vport, and then 1003 * returns a pointer to that log in the private_data field in @file. 1004 * 1005 * Returns: 1006 * This function returns zero if successful. On error it will return an negative 1007 * error value. 1008 **/ 1009 static int 1010 lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file) 1011 { 1012 struct lpfc_vport *vport = inode->i_private; 1013 struct lpfc_debug *debug; 1014 int rc = -ENOMEM; 1015 1016 debug = kmalloc(sizeof(*debug), GFP_KERNEL); 1017 if (!debug) 1018 goto out; 1019 1020 /* Round to page boundary */ 1021 debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL); 1022 if (!debug->buffer) { 1023 kfree(debug); 1024 goto out; 1025 } 1026 1027 debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer, 1028 LPFC_NODELIST_SIZE); 1029 file->private_data = debug; 1030 1031 rc = 0; 1032 out: 1033 return rc; 1034 } 1035 1036 /** 1037 * lpfc_debugfs_lseek - Seek through a debugfs file 1038 * @file: The file pointer to seek through. 1039 * @off: The offset to seek to or the amount to seek by. 1040 * @whence: Indicates how to seek. 1041 * 1042 * Description: 1043 * This routine is the entry point for the debugfs lseek file operation. The 1044 * @whence parameter indicates whether @off is the offset to directly seek to, 1045 * or if it is a value to seek forward or reverse by. This function figures out 1046 * what the new offset of the debugfs file will be and assigns that value to the 1047 * f_pos field of @file. 1048 * 1049 * Returns: 1050 * This function returns the new offset if successful and returns a negative 1051 * error if unable to process the seek. 1052 **/ 1053 static loff_t 1054 lpfc_debugfs_lseek(struct file *file, loff_t off, int whence) 1055 { 1056 struct lpfc_debug *debug; 1057 loff_t pos = -1; 1058 1059 debug = file->private_data; 1060 1061 switch (whence) { 1062 case 0: 1063 pos = off; 1064 break; 1065 case 1: 1066 pos = file->f_pos + off; 1067 break; 1068 case 2: 1069 pos = debug->len - off; 1070 } 1071 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos); 1072 } 1073 1074 /** 1075 * lpfc_debugfs_read - Read a debugfs file 1076 * @file: The file pointer to read from. 1077 * @buf: The buffer to copy the data to. 1078 * @nbytes: The number of bytes to read. 1079 * @ppos: The position in the file to start reading from. 1080 * 1081 * Description: 1082 * This routine reads data from from the buffer indicated in the private_data 1083 * field of @file. It will start reading at @ppos and copy up to @nbytes of 1084 * data to @buf. 1085 * 1086 * Returns: 1087 * This function returns the amount of data that was read (this could be less 1088 * than @nbytes if the end of the file was reached) or a negative error value. 1089 **/ 1090 static ssize_t 1091 lpfc_debugfs_read(struct file *file, char __user *buf, 1092 size_t nbytes, loff_t *ppos) 1093 { 1094 struct lpfc_debug *debug = file->private_data; 1095 return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer, 1096 debug->len); 1097 } 1098 1099 /** 1100 * lpfc_debugfs_release - Release the buffer used to store debugfs file data 1101 * @inode: The inode pointer that contains a vport pointer. (unused) 1102 * @file: The file pointer that contains the buffer to release. 1103 * 1104 * Description: 1105 * This routine frees the buffer that was allocated when the debugfs file was 1106 * opened. 1107 * 1108 * Returns: 1109 * This function returns zero. 1110 **/ 1111 static int 1112 lpfc_debugfs_release(struct inode *inode, struct file *file) 1113 { 1114 struct lpfc_debug *debug = file->private_data; 1115 1116 kfree(debug->buffer); 1117 kfree(debug); 1118 1119 return 0; 1120 } 1121 1122 static int 1123 lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file) 1124 { 1125 struct lpfc_debug *debug = file->private_data; 1126 1127 debug->buffer = NULL; 1128 kfree(debug); 1129 1130 return 0; 1131 } 1132 1133 #undef lpfc_debugfs_op_disc_trc 1134 static const struct file_operations lpfc_debugfs_op_disc_trc = { 1135 .owner = THIS_MODULE, 1136 .open = lpfc_debugfs_disc_trc_open, 1137 .llseek = lpfc_debugfs_lseek, 1138 .read = lpfc_debugfs_read, 1139 .release = lpfc_debugfs_release, 1140 }; 1141 1142 #undef lpfc_debugfs_op_nodelist 1143 static const struct file_operations lpfc_debugfs_op_nodelist = { 1144 .owner = THIS_MODULE, 1145 .open = lpfc_debugfs_nodelist_open, 1146 .llseek = lpfc_debugfs_lseek, 1147 .read = lpfc_debugfs_read, 1148 .release = lpfc_debugfs_release, 1149 }; 1150 1151 #undef lpfc_debugfs_op_hbqinfo 1152 static const struct file_operations lpfc_debugfs_op_hbqinfo = { 1153 .owner = THIS_MODULE, 1154 .open = lpfc_debugfs_hbqinfo_open, 1155 .llseek = lpfc_debugfs_lseek, 1156 .read = lpfc_debugfs_read, 1157 .release = lpfc_debugfs_release, 1158 }; 1159 1160 #undef lpfc_debugfs_op_dumpHBASlim 1161 static const struct file_operations lpfc_debugfs_op_dumpHBASlim = { 1162 .owner = THIS_MODULE, 1163 .open = lpfc_debugfs_dumpHBASlim_open, 1164 .llseek = lpfc_debugfs_lseek, 1165 .read = lpfc_debugfs_read, 1166 .release = lpfc_debugfs_release, 1167 }; 1168 1169 #undef lpfc_debugfs_op_dumpHostSlim 1170 static const struct file_operations lpfc_debugfs_op_dumpHostSlim = { 1171 .owner = THIS_MODULE, 1172 .open = lpfc_debugfs_dumpHostSlim_open, 1173 .llseek = lpfc_debugfs_lseek, 1174 .read = lpfc_debugfs_read, 1175 .release = lpfc_debugfs_release, 1176 }; 1177 1178 #undef lpfc_debugfs_op_dumpData 1179 static const struct file_operations lpfc_debugfs_op_dumpData = { 1180 .owner = THIS_MODULE, 1181 .open = lpfc_debugfs_dumpData_open, 1182 .llseek = lpfc_debugfs_lseek, 1183 .read = lpfc_debugfs_read, 1184 .write = lpfc_debugfs_dumpDataDif_write, 1185 .release = lpfc_debugfs_dumpDataDif_release, 1186 }; 1187 1188 #undef lpfc_debugfs_op_dumpDif 1189 static const struct file_operations lpfc_debugfs_op_dumpDif = { 1190 .owner = THIS_MODULE, 1191 .open = lpfc_debugfs_dumpDif_open, 1192 .llseek = lpfc_debugfs_lseek, 1193 .read = lpfc_debugfs_read, 1194 .write = lpfc_debugfs_dumpDataDif_write, 1195 .release = lpfc_debugfs_dumpDataDif_release, 1196 }; 1197 1198 #undef lpfc_debugfs_op_slow_ring_trc 1199 static const struct file_operations lpfc_debugfs_op_slow_ring_trc = { 1200 .owner = THIS_MODULE, 1201 .open = lpfc_debugfs_slow_ring_trc_open, 1202 .llseek = lpfc_debugfs_lseek, 1203 .read = lpfc_debugfs_read, 1204 .release = lpfc_debugfs_release, 1205 }; 1206 1207 static struct dentry *lpfc_debugfs_root = NULL; 1208 static atomic_t lpfc_debugfs_hba_count; 1209 #endif 1210 1211 /** 1212 * lpfc_debugfs_initialize - Initialize debugfs for a vport 1213 * @vport: The vport pointer to initialize. 1214 * 1215 * Description: 1216 * When Debugfs is configured this routine sets up the lpfc debugfs file system. 1217 * If not already created, this routine will create the lpfc directory, and 1218 * lpfcX directory (for this HBA), and vportX directory for this vport. It will 1219 * also create each file used to access lpfc specific debugfs information. 1220 **/ 1221 inline void 1222 lpfc_debugfs_initialize(struct lpfc_vport *vport) 1223 { 1224 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1225 struct lpfc_hba *phba = vport->phba; 1226 char name[64]; 1227 uint32_t num, i; 1228 1229 if (!lpfc_debugfs_enable) 1230 return; 1231 1232 /* Setup lpfc root directory */ 1233 if (!lpfc_debugfs_root) { 1234 lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL); 1235 atomic_set(&lpfc_debugfs_hba_count, 0); 1236 if (!lpfc_debugfs_root) { 1237 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1238 "0408 Cannot create debugfs root\n"); 1239 goto debug_failed; 1240 } 1241 } 1242 if (!lpfc_debugfs_start_time) 1243 lpfc_debugfs_start_time = jiffies; 1244 1245 /* Setup lpfcX directory for specific HBA */ 1246 snprintf(name, sizeof(name), "lpfc%d", phba->brd_no); 1247 if (!phba->hba_debugfs_root) { 1248 phba->hba_debugfs_root = 1249 debugfs_create_dir(name, lpfc_debugfs_root); 1250 if (!phba->hba_debugfs_root) { 1251 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1252 "0412 Cannot create debugfs hba\n"); 1253 goto debug_failed; 1254 } 1255 atomic_inc(&lpfc_debugfs_hba_count); 1256 atomic_set(&phba->debugfs_vport_count, 0); 1257 1258 /* Setup hbqinfo */ 1259 snprintf(name, sizeof(name), "hbqinfo"); 1260 phba->debug_hbqinfo = 1261 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 1262 phba->hba_debugfs_root, 1263 phba, &lpfc_debugfs_op_hbqinfo); 1264 if (!phba->debug_hbqinfo) { 1265 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1266 "0411 Cannot create debugfs hbqinfo\n"); 1267 goto debug_failed; 1268 } 1269 1270 /* Setup dumpHBASlim */ 1271 snprintf(name, sizeof(name), "dumpHBASlim"); 1272 phba->debug_dumpHBASlim = 1273 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 1274 phba->hba_debugfs_root, 1275 phba, &lpfc_debugfs_op_dumpHBASlim); 1276 if (!phba->debug_dumpHBASlim) { 1277 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1278 "0413 Cannot create debugfs dumpHBASlim\n"); 1279 goto debug_failed; 1280 } 1281 1282 /* Setup dumpHostSlim */ 1283 snprintf(name, sizeof(name), "dumpHostSlim"); 1284 phba->debug_dumpHostSlim = 1285 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 1286 phba->hba_debugfs_root, 1287 phba, &lpfc_debugfs_op_dumpHostSlim); 1288 if (!phba->debug_dumpHostSlim) { 1289 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1290 "0414 Cannot create debugfs dumpHostSlim\n"); 1291 goto debug_failed; 1292 } 1293 1294 /* Setup dumpData */ 1295 snprintf(name, sizeof(name), "dumpData"); 1296 phba->debug_dumpData = 1297 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 1298 phba->hba_debugfs_root, 1299 phba, &lpfc_debugfs_op_dumpData); 1300 if (!phba->debug_dumpData) { 1301 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1302 "0800 Cannot create debugfs dumpData\n"); 1303 goto debug_failed; 1304 } 1305 1306 /* Setup dumpDif */ 1307 snprintf(name, sizeof(name), "dumpDif"); 1308 phba->debug_dumpDif = 1309 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 1310 phba->hba_debugfs_root, 1311 phba, &lpfc_debugfs_op_dumpDif); 1312 if (!phba->debug_dumpDif) { 1313 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1314 "0801 Cannot create debugfs dumpDif\n"); 1315 goto debug_failed; 1316 } 1317 1318 1319 1320 /* Setup slow ring trace */ 1321 if (lpfc_debugfs_max_slow_ring_trc) { 1322 num = lpfc_debugfs_max_slow_ring_trc - 1; 1323 if (num & lpfc_debugfs_max_slow_ring_trc) { 1324 /* Change to be a power of 2 */ 1325 num = lpfc_debugfs_max_slow_ring_trc; 1326 i = 0; 1327 while (num > 1) { 1328 num = num >> 1; 1329 i++; 1330 } 1331 lpfc_debugfs_max_slow_ring_trc = (1 << i); 1332 printk(KERN_ERR 1333 "lpfc_debugfs_max_disc_trc changed to " 1334 "%d\n", lpfc_debugfs_max_disc_trc); 1335 } 1336 } 1337 1338 1339 snprintf(name, sizeof(name), "slow_ring_trace"); 1340 phba->debug_slow_ring_trc = 1341 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 1342 phba->hba_debugfs_root, 1343 phba, &lpfc_debugfs_op_slow_ring_trc); 1344 if (!phba->debug_slow_ring_trc) { 1345 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1346 "0415 Cannot create debugfs " 1347 "slow_ring_trace\n"); 1348 goto debug_failed; 1349 } 1350 if (!phba->slow_ring_trc) { 1351 phba->slow_ring_trc = kmalloc( 1352 (sizeof(struct lpfc_debugfs_trc) * 1353 lpfc_debugfs_max_slow_ring_trc), 1354 GFP_KERNEL); 1355 if (!phba->slow_ring_trc) { 1356 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1357 "0416 Cannot create debugfs " 1358 "slow_ring buffer\n"); 1359 goto debug_failed; 1360 } 1361 atomic_set(&phba->slow_ring_trc_cnt, 0); 1362 memset(phba->slow_ring_trc, 0, 1363 (sizeof(struct lpfc_debugfs_trc) * 1364 lpfc_debugfs_max_slow_ring_trc)); 1365 } 1366 } 1367 1368 snprintf(name, sizeof(name), "vport%d", vport->vpi); 1369 if (!vport->vport_debugfs_root) { 1370 vport->vport_debugfs_root = 1371 debugfs_create_dir(name, phba->hba_debugfs_root); 1372 if (!vport->vport_debugfs_root) { 1373 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1374 "0417 Cant create debugfs"); 1375 goto debug_failed; 1376 } 1377 atomic_inc(&phba->debugfs_vport_count); 1378 } 1379 1380 if (lpfc_debugfs_max_disc_trc) { 1381 num = lpfc_debugfs_max_disc_trc - 1; 1382 if (num & lpfc_debugfs_max_disc_trc) { 1383 /* Change to be a power of 2 */ 1384 num = lpfc_debugfs_max_disc_trc; 1385 i = 0; 1386 while (num > 1) { 1387 num = num >> 1; 1388 i++; 1389 } 1390 lpfc_debugfs_max_disc_trc = (1 << i); 1391 printk(KERN_ERR 1392 "lpfc_debugfs_max_disc_trc changed to %d\n", 1393 lpfc_debugfs_max_disc_trc); 1394 } 1395 } 1396 1397 vport->disc_trc = kzalloc( 1398 (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc), 1399 GFP_KERNEL); 1400 1401 if (!vport->disc_trc) { 1402 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1403 "0418 Cannot create debugfs disc trace " 1404 "buffer\n"); 1405 goto debug_failed; 1406 } 1407 atomic_set(&vport->disc_trc_cnt, 0); 1408 1409 snprintf(name, sizeof(name), "discovery_trace"); 1410 vport->debug_disc_trc = 1411 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 1412 vport->vport_debugfs_root, 1413 vport, &lpfc_debugfs_op_disc_trc); 1414 if (!vport->debug_disc_trc) { 1415 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1416 "0419 Cannot create debugfs " 1417 "discovery_trace\n"); 1418 goto debug_failed; 1419 } 1420 snprintf(name, sizeof(name), "nodelist"); 1421 vport->debug_nodelist = 1422 debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, 1423 vport->vport_debugfs_root, 1424 vport, &lpfc_debugfs_op_nodelist); 1425 if (!vport->debug_nodelist) { 1426 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1427 "0409 Cant create debugfs nodelist"); 1428 goto debug_failed; 1429 } 1430 debug_failed: 1431 return; 1432 #endif 1433 } 1434 1435 /** 1436 * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport 1437 * @vport: The vport pointer to remove from debugfs. 1438 * 1439 * Description: 1440 * When Debugfs is configured this routine removes debugfs file system elements 1441 * that are specific to this vport. It also checks to see if there are any 1442 * users left for the debugfs directories associated with the HBA and driver. If 1443 * this is the last user of the HBA directory or driver directory then it will 1444 * remove those from the debugfs infrastructure as well. 1445 **/ 1446 inline void 1447 lpfc_debugfs_terminate(struct lpfc_vport *vport) 1448 { 1449 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS 1450 struct lpfc_hba *phba = vport->phba; 1451 1452 if (vport->disc_trc) { 1453 kfree(vport->disc_trc); 1454 vport->disc_trc = NULL; 1455 } 1456 if (vport->debug_disc_trc) { 1457 debugfs_remove(vport->debug_disc_trc); /* discovery_trace */ 1458 vport->debug_disc_trc = NULL; 1459 } 1460 if (vport->debug_nodelist) { 1461 debugfs_remove(vport->debug_nodelist); /* nodelist */ 1462 vport->debug_nodelist = NULL; 1463 } 1464 1465 if (vport->vport_debugfs_root) { 1466 debugfs_remove(vport->vport_debugfs_root); /* vportX */ 1467 vport->vport_debugfs_root = NULL; 1468 atomic_dec(&phba->debugfs_vport_count); 1469 } 1470 if (atomic_read(&phba->debugfs_vport_count) == 0) { 1471 1472 if (phba->debug_hbqinfo) { 1473 debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */ 1474 phba->debug_hbqinfo = NULL; 1475 } 1476 if (phba->debug_dumpHBASlim) { 1477 debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */ 1478 phba->debug_dumpHBASlim = NULL; 1479 } 1480 if (phba->debug_dumpHostSlim) { 1481 debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */ 1482 phba->debug_dumpHostSlim = NULL; 1483 } 1484 if (phba->debug_dumpData) { 1485 debugfs_remove(phba->debug_dumpData); /* dumpData */ 1486 phba->debug_dumpData = NULL; 1487 } 1488 1489 if (phba->debug_dumpDif) { 1490 debugfs_remove(phba->debug_dumpDif); /* dumpDif */ 1491 phba->debug_dumpDif = NULL; 1492 } 1493 1494 if (phba->slow_ring_trc) { 1495 kfree(phba->slow_ring_trc); 1496 phba->slow_ring_trc = NULL; 1497 } 1498 if (phba->debug_slow_ring_trc) { 1499 /* slow_ring_trace */ 1500 debugfs_remove(phba->debug_slow_ring_trc); 1501 phba->debug_slow_ring_trc = NULL; 1502 } 1503 1504 if (phba->hba_debugfs_root) { 1505 debugfs_remove(phba->hba_debugfs_root); /* lpfcX */ 1506 phba->hba_debugfs_root = NULL; 1507 atomic_dec(&lpfc_debugfs_hba_count); 1508 } 1509 1510 if (atomic_read(&lpfc_debugfs_hba_count) == 0) { 1511 debugfs_remove(lpfc_debugfs_root); /* lpfc */ 1512 lpfc_debugfs_root = NULL; 1513 } 1514 } 1515 #endif 1516 return; 1517 } 1518