1 /******************************************************************* 2 * This file is part of the Emulex Linux Device Driver for * 3 * Fibre Channel Host Bus Adapters. * 4 * Copyright (C) 2004-2008 Emulex. All rights reserved. * 5 * EMULEX and SLI are trademarks of Emulex. * 6 * www.emulex.com * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 8 * * 9 * This program is free software; you can redistribute it and/or * 10 * modify it under the terms of version 2 of the GNU General * 11 * Public License as published by the Free Software Foundation. * 12 * This program is distributed in the hope that it will be useful. * 13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 17 * TO BE LEGALLY INVALID. See the GNU General Public License for * 18 * more details, a copy of which can be found in the file COPYING * 19 * included with this package. * 20 *******************************************************************/ 21 22 #include <linux/ctype.h> 23 #include <linux/delay.h> 24 #include <linux/pci.h> 25 #include <linux/interrupt.h> 26 27 #include <scsi/scsi.h> 28 #include <scsi/scsi_device.h> 29 #include <scsi/scsi_host.h> 30 #include <scsi/scsi_tcq.h> 31 #include <scsi/scsi_transport_fc.h> 32 33 #include "lpfc_hw.h" 34 #include "lpfc_sli.h" 35 #include "lpfc_nl.h" 36 #include "lpfc_disc.h" 37 #include "lpfc_scsi.h" 38 #include "lpfc.h" 39 #include "lpfc_logmsg.h" 40 #include "lpfc_version.h" 41 #include "lpfc_compat.h" 42 #include "lpfc_crtn.h" 43 #include "lpfc_vport.h" 44 45 #define LPFC_DEF_DEVLOSS_TMO 30 46 #define LPFC_MIN_DEVLOSS_TMO 1 47 #define LPFC_MAX_DEVLOSS_TMO 255 48 49 #define LPFC_MAX_LINK_SPEED 8 50 #define LPFC_LINK_SPEED_BITMAP 0x00000117 51 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8" 52 53 /** 54 * lpfc_jedec_to_ascii: Hex to ascii convertor according to JEDEC rules. 55 * @incr: integer to convert. 56 * @hdw: ascii string holding converted integer plus a string terminator. 57 * 58 * Description: 59 * JEDEC Joint Electron Device Engineering Council. 60 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii 61 * character string. The string is then terminated with a NULL in byte 9. 62 * Hex 0-9 becomes ascii '0' to '9'. 63 * Hex a-f becomes ascii '=' to 'B' capital B. 64 * 65 * Notes: 66 * Coded for 32 bit integers only. 67 **/ 68 static void 69 lpfc_jedec_to_ascii(int incr, char hdw[]) 70 { 71 int i, j; 72 for (i = 0; i < 8; i++) { 73 j = (incr & 0xf); 74 if (j <= 9) 75 hdw[7 - i] = 0x30 + j; 76 else 77 hdw[7 - i] = 0x61 + j - 10; 78 incr = (incr >> 4); 79 } 80 hdw[8] = 0; 81 return; 82 } 83 84 /** 85 * lpfc_drvr_version_show: Return the Emulex driver string with version number. 86 * @dev: class unused variable. 87 * @attr: device attribute, not used. 88 * @buf: on return contains the module description text. 89 * 90 * Returns: size of formatted string. 91 **/ 92 static ssize_t 93 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr, 94 char *buf) 95 { 96 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); 97 } 98 99 /** 100 * lpfc_info_show: Return some pci info about the host in ascii. 101 * @dev: class converted to a Scsi_host structure. 102 * @attr: device attribute, not used. 103 * @buf: on return contains the formatted text from lpfc_info(). 104 * 105 * Returns: size of formatted string. 106 **/ 107 static ssize_t 108 lpfc_info_show(struct device *dev, struct device_attribute *attr, 109 char *buf) 110 { 111 struct Scsi_Host *host = class_to_shost(dev); 112 113 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); 114 } 115 116 /** 117 * lpfc_serialnum_show: Return the hba serial number in ascii. 118 * @dev: class converted to a Scsi_host structure. 119 * @attr: device attribute, not used. 120 * @buf: on return contains the formatted text serial number. 121 * 122 * Returns: size of formatted string. 123 **/ 124 static ssize_t 125 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr, 126 char *buf) 127 { 128 struct Scsi_Host *shost = class_to_shost(dev); 129 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 130 struct lpfc_hba *phba = vport->phba; 131 132 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); 133 } 134 135 /** 136 * lpfc_temp_sensor_show: Return the temperature sensor level. 137 * @dev: class converted to a Scsi_host structure. 138 * @attr: device attribute, not used. 139 * @buf: on return contains the formatted support level. 140 * 141 * Description: 142 * Returns a number indicating the temperature sensor level currently 143 * supported, zero or one in ascii. 144 * 145 * Returns: size of formatted string. 146 **/ 147 static ssize_t 148 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr, 149 char *buf) 150 { 151 struct Scsi_Host *shost = class_to_shost(dev); 152 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 153 struct lpfc_hba *phba = vport->phba; 154 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support); 155 } 156 157 /** 158 * lpfc_modeldesc_show: Return the model description of the hba. 159 * @dev: class converted to a Scsi_host structure. 160 * @attr: device attribute, not used. 161 * @buf: on return contains the scsi vpd model description. 162 * 163 * Returns: size of formatted string. 164 **/ 165 static ssize_t 166 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr, 167 char *buf) 168 { 169 struct Scsi_Host *shost = class_to_shost(dev); 170 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 171 struct lpfc_hba *phba = vport->phba; 172 173 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); 174 } 175 176 /** 177 * lpfc_modelname_show: Return the model name of the hba. 178 * @dev: class converted to a Scsi_host structure. 179 * @attr: device attribute, not used. 180 * @buf: on return contains the scsi vpd model name. 181 * 182 * Returns: size of formatted string. 183 **/ 184 static ssize_t 185 lpfc_modelname_show(struct device *dev, struct device_attribute *attr, 186 char *buf) 187 { 188 struct Scsi_Host *shost = class_to_shost(dev); 189 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 190 struct lpfc_hba *phba = vport->phba; 191 192 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); 193 } 194 195 /** 196 * lpfc_programtype_show: Return the program type of the hba. 197 * @dev: class converted to a Scsi_host structure. 198 * @attr: device attribute, not used. 199 * @buf: on return contains the scsi vpd program type. 200 * 201 * Returns: size of formatted string. 202 **/ 203 static ssize_t 204 lpfc_programtype_show(struct device *dev, struct device_attribute *attr, 205 char *buf) 206 { 207 struct Scsi_Host *shost = class_to_shost(dev); 208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 209 struct lpfc_hba *phba = vport->phba; 210 211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); 212 } 213 214 /** 215 * lpfc_mlomgmt_show: Return the Menlo Maintenance sli flag. 216 * @dev: class converted to a Scsi_host structure. 217 * @attr: device attribute, not used. 218 * @buf: on return contains the Menlo Maintenance sli flag. 219 * 220 * Returns: size of formatted string. 221 **/ 222 static ssize_t 223 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf) 224 { 225 struct Scsi_Host *shost = class_to_shost(dev); 226 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; 227 struct lpfc_hba *phba = vport->phba; 228 229 return snprintf(buf, PAGE_SIZE, "%d\n", 230 (phba->sli.sli_flag & LPFC_MENLO_MAINT)); 231 } 232 233 /** 234 * lpfc_vportnum_show: Return the port number in ascii of the hba. 235 * @dev: class converted to a Scsi_host structure. 236 * @attr: device attribute, not used. 237 * @buf: on return contains scsi vpd program type. 238 * 239 * Returns: size of formatted string. 240 **/ 241 static ssize_t 242 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr, 243 char *buf) 244 { 245 struct Scsi_Host *shost = class_to_shost(dev); 246 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 247 struct lpfc_hba *phba = vport->phba; 248 249 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); 250 } 251 252 /** 253 * lpfc_fwrev_show: Return the firmware rev running in the hba. 254 * @dev: class converted to a Scsi_host structure. 255 * @attr: device attribute, not used. 256 * @buf: on return contains the scsi vpd program type. 257 * 258 * Returns: size of formatted string. 259 **/ 260 static ssize_t 261 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr, 262 char *buf) 263 { 264 struct Scsi_Host *shost = class_to_shost(dev); 265 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 266 struct lpfc_hba *phba = vport->phba; 267 char fwrev[32]; 268 269 lpfc_decode_firmware_rev(phba, fwrev, 1); 270 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev); 271 } 272 273 /** 274 * lpfc_hdw_show: Return the jedec information about the hba. 275 * @dev: class converted to a Scsi_host structure. 276 * @attr: device attribute, not used. 277 * @buf: on return contains the scsi vpd program type. 278 * 279 * Returns: size of formatted string. 280 **/ 281 static ssize_t 282 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf) 283 { 284 char hdw[9]; 285 struct Scsi_Host *shost = class_to_shost(dev); 286 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 287 struct lpfc_hba *phba = vport->phba; 288 lpfc_vpd_t *vp = &phba->vpd; 289 290 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); 291 return snprintf(buf, PAGE_SIZE, "%s\n", hdw); 292 } 293 294 /** 295 * lpfc_option_rom_version_show: Return the adapter ROM FCode version. 296 * @dev: class converted to a Scsi_host structure. 297 * @attr: device attribute, not used. 298 * @buf: on return contains the ROM and FCode ascii strings. 299 * 300 * Returns: size of formatted string. 301 **/ 302 static ssize_t 303 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr, 304 char *buf) 305 { 306 struct Scsi_Host *shost = class_to_shost(dev); 307 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 308 struct lpfc_hba *phba = vport->phba; 309 310 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); 311 } 312 313 /** 314 * lpfc_state_show: Return the link state of the port. 315 * @dev: class converted to a Scsi_host structure. 316 * @attr: device attribute, not used. 317 * @buf: on return contains text describing the state of the link. 318 * 319 * Notes: 320 * The switch statement has no default so zero will be returned. 321 * 322 * Returns: size of formatted string. 323 **/ 324 static ssize_t 325 lpfc_link_state_show(struct device *dev, struct device_attribute *attr, 326 char *buf) 327 { 328 struct Scsi_Host *shost = class_to_shost(dev); 329 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 330 struct lpfc_hba *phba = vport->phba; 331 int len = 0; 332 333 switch (phba->link_state) { 334 case LPFC_LINK_UNKNOWN: 335 case LPFC_WARM_START: 336 case LPFC_INIT_START: 337 case LPFC_INIT_MBX_CMDS: 338 case LPFC_LINK_DOWN: 339 case LPFC_HBA_ERROR: 340 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n"); 341 break; 342 case LPFC_LINK_UP: 343 case LPFC_CLEAR_LA: 344 case LPFC_HBA_READY: 345 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - "); 346 347 switch (vport->port_state) { 348 case LPFC_LOCAL_CFG_LINK: 349 len += snprintf(buf + len, PAGE_SIZE-len, 350 "Configuring Link\n"); 351 break; 352 case LPFC_FDISC: 353 case LPFC_FLOGI: 354 case LPFC_FABRIC_CFG_LINK: 355 case LPFC_NS_REG: 356 case LPFC_NS_QRY: 357 case LPFC_BUILD_DISC_LIST: 358 case LPFC_DISC_AUTH: 359 len += snprintf(buf + len, PAGE_SIZE - len, 360 "Discovery\n"); 361 break; 362 case LPFC_VPORT_READY: 363 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n"); 364 break; 365 366 case LPFC_VPORT_FAILED: 367 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n"); 368 break; 369 370 case LPFC_VPORT_UNKNOWN: 371 len += snprintf(buf + len, PAGE_SIZE - len, 372 "Unknown\n"); 373 break; 374 } 375 if (phba->sli.sli_flag & LPFC_MENLO_MAINT) 376 len += snprintf(buf + len, PAGE_SIZE-len, 377 " Menlo Maint Mode\n"); 378 else if (phba->fc_topology == TOPOLOGY_LOOP) { 379 if (vport->fc_flag & FC_PUBLIC_LOOP) 380 len += snprintf(buf + len, PAGE_SIZE-len, 381 " Public Loop\n"); 382 else 383 len += snprintf(buf + len, PAGE_SIZE-len, 384 " Private Loop\n"); 385 } else { 386 if (vport->fc_flag & FC_FABRIC) 387 len += snprintf(buf + len, PAGE_SIZE-len, 388 " Fabric\n"); 389 else 390 len += snprintf(buf + len, PAGE_SIZE-len, 391 " Point-2-Point\n"); 392 } 393 } 394 395 return len; 396 } 397 398 /** 399 * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports. 400 * @dev: class device that is converted into a Scsi_host. 401 * @attr: device attribute, not used. 402 * @buf: on return contains the sum of fc mapped and unmapped. 403 * 404 * Description: 405 * Returns the ascii text number of the sum of the fc mapped and unmapped 406 * vport counts. 407 * 408 * Returns: size of formatted string. 409 **/ 410 static ssize_t 411 lpfc_num_discovered_ports_show(struct device *dev, 412 struct device_attribute *attr, char *buf) 413 { 414 struct Scsi_Host *shost = class_to_shost(dev); 415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 416 417 return snprintf(buf, PAGE_SIZE, "%d\n", 418 vport->fc_map_cnt + vport->fc_unmap_cnt); 419 } 420 421 /** 422 * lpfc_issue_lip: Misnomer, name carried over from long ago. 423 * @shost: Scsi_Host pointer. 424 * 425 * Description: 426 * Bring the link down gracefully then re-init the link. The firmware will 427 * re-init the fiber channel interface as required. Does not issue a LIP. 428 * 429 * Returns: 430 * -EPERM port offline or management commands are being blocked 431 * -ENOMEM cannot allocate memory for the mailbox command 432 * -EIO error sending the mailbox command 433 * zero for success 434 **/ 435 static int 436 lpfc_issue_lip(struct Scsi_Host *shost) 437 { 438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 439 struct lpfc_hba *phba = vport->phba; 440 LPFC_MBOXQ_t *pmboxq; 441 int mbxstatus = MBXERR_ERROR; 442 443 if ((vport->fc_flag & FC_OFFLINE_MODE) || 444 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)) 445 return -EPERM; 446 447 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); 448 449 if (!pmboxq) 450 return -ENOMEM; 451 452 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 453 pmboxq->mb.mbxCommand = MBX_DOWN_LINK; 454 pmboxq->mb.mbxOwner = OWN_HOST; 455 456 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2); 457 458 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) { 459 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 460 lpfc_init_link(phba, pmboxq, phba->cfg_topology, 461 phba->cfg_link_speed); 462 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, 463 phba->fc_ratov * 2); 464 } 465 466 lpfc_set_loopback_flag(phba); 467 if (mbxstatus != MBX_TIMEOUT) 468 mempool_free(pmboxq, phba->mbox_mem_pool); 469 470 if (mbxstatus == MBXERR_ERROR) 471 return -EIO; 472 473 return 0; 474 } 475 476 /** 477 * lpfc_do_offline: Issues a mailbox command to bring the link down. 478 * @phba: lpfc_hba pointer. 479 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL. 480 * 481 * Notes: 482 * Assumes any error from lpfc_do_offline() will be negative. 483 * Can wait up to 5 seconds for the port ring buffers count 484 * to reach zero, prints a warning if it is not zero and continues. 485 * lpfc_workq_post_event() returns a non-zero return coce if call fails. 486 * 487 * Returns: 488 * -EIO error posting the event 489 * zero for success 490 **/ 491 static int 492 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type) 493 { 494 struct completion online_compl; 495 struct lpfc_sli_ring *pring; 496 struct lpfc_sli *psli; 497 int status = 0; 498 int cnt = 0; 499 int i; 500 501 init_completion(&online_compl); 502 lpfc_workq_post_event(phba, &status, &online_compl, 503 LPFC_EVT_OFFLINE_PREP); 504 wait_for_completion(&online_compl); 505 506 if (status != 0) 507 return -EIO; 508 509 psli = &phba->sli; 510 511 /* Wait a little for things to settle down, but not 512 * long enough for dev loss timeout to expire. 513 */ 514 for (i = 0; i < psli->num_rings; i++) { 515 pring = &psli->ring[i]; 516 while (pring->txcmplq_cnt) { 517 msleep(10); 518 if (cnt++ > 500) { /* 5 secs */ 519 lpfc_printf_log(phba, 520 KERN_WARNING, LOG_INIT, 521 "0466 Outstanding IO when " 522 "bringing Adapter offline\n"); 523 break; 524 } 525 } 526 } 527 528 init_completion(&online_compl); 529 lpfc_workq_post_event(phba, &status, &online_compl, type); 530 wait_for_completion(&online_compl); 531 532 if (status != 0) 533 return -EIO; 534 535 return 0; 536 } 537 538 /** 539 * lpfc_selective_reset: Offline then onlines the port. 540 * @phba: lpfc_hba pointer. 541 * 542 * Description: 543 * If the port is configured to allow a reset then the hba is brought 544 * offline then online. 545 * 546 * Notes: 547 * Assumes any error from lpfc_do_offline() will be negative. 548 * 549 * Returns: 550 * lpfc_do_offline() return code if not zero 551 * -EIO reset not configured or error posting the event 552 * zero for success 553 **/ 554 static int 555 lpfc_selective_reset(struct lpfc_hba *phba) 556 { 557 struct completion online_compl; 558 int status = 0; 559 560 if (!phba->cfg_enable_hba_reset) 561 return -EIO; 562 563 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); 564 565 if (status != 0) 566 return status; 567 568 init_completion(&online_compl); 569 lpfc_workq_post_event(phba, &status, &online_compl, 570 LPFC_EVT_ONLINE); 571 wait_for_completion(&online_compl); 572 573 if (status != 0) 574 return -EIO; 575 576 return 0; 577 } 578 579 /** 580 * lpfc_issue_reset: Selectively resets an adapter. 581 * @dev: class device that is converted into a Scsi_host. 582 * @attr: device attribute, not used. 583 * @buf: containing the string "selective". 584 * @count: unused variable. 585 * 586 * Description: 587 * If the buf contains the string "selective" then lpfc_selective_reset() 588 * is called to perform the reset. 589 * 590 * Notes: 591 * Assumes any error from lpfc_selective_reset() will be negative. 592 * If lpfc_selective_reset() returns zero then the length of the buffer 593 * is returned which indicates succcess 594 * 595 * Returns: 596 * -EINVAL if the buffer does not contain the string "selective" 597 * length of buf if lpfc-selective_reset() if the call succeeds 598 * return value of lpfc_selective_reset() if the call fails 599 **/ 600 static ssize_t 601 lpfc_issue_reset(struct device *dev, struct device_attribute *attr, 602 const char *buf, size_t count) 603 { 604 struct Scsi_Host *shost = class_to_shost(dev); 605 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 606 struct lpfc_hba *phba = vport->phba; 607 608 int status = -EINVAL; 609 610 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) 611 status = lpfc_selective_reset(phba); 612 613 if (status == 0) 614 return strlen(buf); 615 else 616 return status; 617 } 618 619 /** 620 * lpfc_nport_evt_cnt_show: Return the number of nport events. 621 * @dev: class device that is converted into a Scsi_host. 622 * @attr: device attribute, not used. 623 * @buf: on return contains the ascii number of nport events. 624 * 625 * Returns: size of formatted string. 626 **/ 627 static ssize_t 628 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr, 629 char *buf) 630 { 631 struct Scsi_Host *shost = class_to_shost(dev); 632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 633 struct lpfc_hba *phba = vport->phba; 634 635 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); 636 } 637 638 /** 639 * lpfc_board_mode_show: Return the state of the board. 640 * @dev: class device that is converted into a Scsi_host. 641 * @attr: device attribute, not used. 642 * @buf: on return contains the state of the adapter. 643 * 644 * Returns: size of formatted string. 645 **/ 646 static ssize_t 647 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr, 648 char *buf) 649 { 650 struct Scsi_Host *shost = class_to_shost(dev); 651 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 652 struct lpfc_hba *phba = vport->phba; 653 char * state; 654 655 if (phba->link_state == LPFC_HBA_ERROR) 656 state = "error"; 657 else if (phba->link_state == LPFC_WARM_START) 658 state = "warm start"; 659 else if (phba->link_state == LPFC_INIT_START) 660 state = "offline"; 661 else 662 state = "online"; 663 664 return snprintf(buf, PAGE_SIZE, "%s\n", state); 665 } 666 667 /** 668 * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state. 669 * @dev: class device that is converted into a Scsi_host. 670 * @attr: device attribute, not used. 671 * @buf: containing one of the strings "online", "offline", "warm" or "error". 672 * @count: unused variable. 673 * 674 * Returns: 675 * -EACCES if enable hba reset not enabled 676 * -EINVAL if the buffer does not contain a valid string (see above) 677 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails 678 * buf length greater than zero indicates success 679 **/ 680 static ssize_t 681 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr, 682 const char *buf, size_t count) 683 { 684 struct Scsi_Host *shost = class_to_shost(dev); 685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 686 struct lpfc_hba *phba = vport->phba; 687 struct completion online_compl; 688 int status=0; 689 690 if (!phba->cfg_enable_hba_reset) 691 return -EACCES; 692 init_completion(&online_compl); 693 694 if(strncmp(buf, "online", sizeof("online") - 1) == 0) { 695 lpfc_workq_post_event(phba, &status, &online_compl, 696 LPFC_EVT_ONLINE); 697 wait_for_completion(&online_compl); 698 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) 699 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); 700 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) 701 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START); 702 else if (strncmp(buf, "error", sizeof("error") - 1) == 0) 703 status = lpfc_do_offline(phba, LPFC_EVT_KILL); 704 else 705 return -EINVAL; 706 707 if (!status) 708 return strlen(buf); 709 else 710 return -EIO; 711 } 712 713 /** 714 * lpfc_get_hba_info: Return various bits of informaton about the adapter. 715 * @phba: pointer to the adapter structure. 716 * @mxri max xri count. 717 * @axri available xri count. 718 * @mrpi max rpi count. 719 * @arpi available rpi count. 720 * @mvpi max vpi count. 721 * @avpi available vpi count. 722 * 723 * Description: 724 * If an integer pointer for an count is not null then the value for the 725 * count is returned. 726 * 727 * Returns: 728 * zero on error 729 * one for success 730 **/ 731 static int 732 lpfc_get_hba_info(struct lpfc_hba *phba, 733 uint32_t *mxri, uint32_t *axri, 734 uint32_t *mrpi, uint32_t *arpi, 735 uint32_t *mvpi, uint32_t *avpi) 736 { 737 struct lpfc_sli *psli = &phba->sli; 738 LPFC_MBOXQ_t *pmboxq; 739 MAILBOX_t *pmb; 740 int rc = 0; 741 742 /* 743 * prevent udev from issuing mailbox commands until the port is 744 * configured. 745 */ 746 if (phba->link_state < LPFC_LINK_DOWN || 747 !phba->mbox_mem_pool || 748 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0) 749 return 0; 750 751 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) 752 return 0; 753 754 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 755 if (!pmboxq) 756 return 0; 757 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 758 759 pmb = &pmboxq->mb; 760 pmb->mbxCommand = MBX_READ_CONFIG; 761 pmb->mbxOwner = OWN_HOST; 762 pmboxq->context1 = NULL; 763 764 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) || 765 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 766 rc = MBX_NOT_FINISHED; 767 else 768 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 769 770 if (rc != MBX_SUCCESS) { 771 if (rc != MBX_TIMEOUT) 772 mempool_free(pmboxq, phba->mbox_mem_pool); 773 return 0; 774 } 775 776 if (mrpi) 777 *mrpi = pmb->un.varRdConfig.max_rpi; 778 if (arpi) 779 *arpi = pmb->un.varRdConfig.avail_rpi; 780 if (mxri) 781 *mxri = pmb->un.varRdConfig.max_xri; 782 if (axri) 783 *axri = pmb->un.varRdConfig.avail_xri; 784 if (mvpi) 785 *mvpi = pmb->un.varRdConfig.max_vpi; 786 if (avpi) 787 *avpi = pmb->un.varRdConfig.avail_vpi; 788 789 mempool_free(pmboxq, phba->mbox_mem_pool); 790 return 1; 791 } 792 793 /** 794 * lpfc_max_rpi_show: Return maximum rpi. 795 * @dev: class device that is converted into a Scsi_host. 796 * @attr: device attribute, not used. 797 * @buf: on return contains the maximum rpi count in decimal or "Unknown". 798 * 799 * Description: 800 * Calls lpfc_get_hba_info() asking for just the mrpi count. 801 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 802 * to "Unknown" and the buffer length is returned, therefore the caller 803 * must check for "Unknown" in the buffer to detect a failure. 804 * 805 * Returns: size of formatted string. 806 **/ 807 static ssize_t 808 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr, 809 char *buf) 810 { 811 struct Scsi_Host *shost = class_to_shost(dev); 812 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 813 struct lpfc_hba *phba = vport->phba; 814 uint32_t cnt; 815 816 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL)) 817 return snprintf(buf, PAGE_SIZE, "%d\n", cnt); 818 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 819 } 820 821 /** 822 * lpfc_used_rpi_show: Return maximum rpi minus available rpi. 823 * @dev: class device that is converted into a Scsi_host. 824 * @attr: device attribute, not used. 825 * @buf: containing the used rpi count in decimal or "Unknown". 826 * 827 * Description: 828 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts. 829 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 830 * to "Unknown" and the buffer length is returned, therefore the caller 831 * must check for "Unknown" in the buffer to detect a failure. 832 * 833 * Returns: size of formatted string. 834 **/ 835 static ssize_t 836 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr, 837 char *buf) 838 { 839 struct Scsi_Host *shost = class_to_shost(dev); 840 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 841 struct lpfc_hba *phba = vport->phba; 842 uint32_t cnt, acnt; 843 844 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) 845 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 846 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 847 } 848 849 /** 850 * lpfc_max_xri_show: Return maximum xri. 851 * @dev: class device that is converted into a Scsi_host. 852 * @attr: device attribute, not used. 853 * @buf: on return contains the maximum xri count in decimal or "Unknown". 854 * 855 * Description: 856 * Calls lpfc_get_hba_info() asking for just the mrpi count. 857 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 858 * to "Unknown" and the buffer length is returned, therefore the caller 859 * must check for "Unknown" in the buffer to detect a failure. 860 * 861 * Returns: size of formatted string. 862 **/ 863 static ssize_t 864 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr, 865 char *buf) 866 { 867 struct Scsi_Host *shost = class_to_shost(dev); 868 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 869 struct lpfc_hba *phba = vport->phba; 870 uint32_t cnt; 871 872 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL)) 873 return snprintf(buf, PAGE_SIZE, "%d\n", cnt); 874 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 875 } 876 877 /** 878 * lpfc_used_xri_show: Return maximum xpi minus the available xpi. 879 * @dev: class device that is converted into a Scsi_host. 880 * @attr: device attribute, not used. 881 * @buf: on return contains the used xri count in decimal or "Unknown". 882 * 883 * Description: 884 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts. 885 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 886 * to "Unknown" and the buffer length is returned, therefore the caller 887 * must check for "Unknown" in the buffer to detect a failure. 888 * 889 * Returns: size of formatted string. 890 **/ 891 static ssize_t 892 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr, 893 char *buf) 894 { 895 struct Scsi_Host *shost = class_to_shost(dev); 896 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 897 struct lpfc_hba *phba = vport->phba; 898 uint32_t cnt, acnt; 899 900 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) 901 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 902 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 903 } 904 905 /** 906 * lpfc_max_vpi_show: Return maximum vpi. 907 * @dev: class device that is converted into a Scsi_host. 908 * @attr: device attribute, not used. 909 * @buf: on return contains the maximum vpi count in decimal or "Unknown". 910 * 911 * Description: 912 * Calls lpfc_get_hba_info() asking for just the mvpi count. 913 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 914 * to "Unknown" and the buffer length is returned, therefore the caller 915 * must check for "Unknown" in the buffer to detect a failure. 916 * 917 * Returns: size of formatted string. 918 **/ 919 static ssize_t 920 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr, 921 char *buf) 922 { 923 struct Scsi_Host *shost = class_to_shost(dev); 924 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 925 struct lpfc_hba *phba = vport->phba; 926 uint32_t cnt; 927 928 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL)) 929 return snprintf(buf, PAGE_SIZE, "%d\n", cnt); 930 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 931 } 932 933 /** 934 * lpfc_used_vpi_show: Return maximum vpi minus the available vpi. 935 * @dev: class device that is converted into a Scsi_host. 936 * @attr: device attribute, not used. 937 * @buf: on return contains the used vpi count in decimal or "Unknown". 938 * 939 * Description: 940 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts. 941 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 942 * to "Unknown" and the buffer length is returned, therefore the caller 943 * must check for "Unknown" in the buffer to detect a failure. 944 * 945 * Returns: size of formatted string. 946 **/ 947 static ssize_t 948 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr, 949 char *buf) 950 { 951 struct Scsi_Host *shost = class_to_shost(dev); 952 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 953 struct lpfc_hba *phba = vport->phba; 954 uint32_t cnt, acnt; 955 956 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) 957 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 958 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 959 } 960 961 /** 962 * lpfc_npiv_info_show: Return text about NPIV support for the adapter. 963 * @dev: class device that is converted into a Scsi_host. 964 * @attr: device attribute, not used. 965 * @buf: text that must be interpreted to determine if npiv is supported. 966 * 967 * Description: 968 * Buffer will contain text indicating npiv is not suppoerted on the port, 969 * the port is an NPIV physical port, or it is an npiv virtual port with 970 * the id of the vport. 971 * 972 * Returns: size of formatted string. 973 **/ 974 static ssize_t 975 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr, 976 char *buf) 977 { 978 struct Scsi_Host *shost = class_to_shost(dev); 979 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 980 struct lpfc_hba *phba = vport->phba; 981 982 if (!(phba->max_vpi)) 983 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n"); 984 if (vport->port_type == LPFC_PHYSICAL_PORT) 985 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n"); 986 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi); 987 } 988 989 /** 990 * lpfc_poll_show: Return text about poll support for the adapter. 991 * @dev: class device that is converted into a Scsi_host. 992 * @attr: device attribute, not used. 993 * @buf: on return contains the cfg_poll in hex. 994 * 995 * Notes: 996 * cfg_poll should be a lpfc_polling_flags type. 997 * 998 * Returns: size of formatted string. 999 **/ 1000 static ssize_t 1001 lpfc_poll_show(struct device *dev, struct device_attribute *attr, 1002 char *buf) 1003 { 1004 struct Scsi_Host *shost = class_to_shost(dev); 1005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1006 struct lpfc_hba *phba = vport->phba; 1007 1008 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); 1009 } 1010 1011 /** 1012 * lpfc_poll_store: Set the value of cfg_poll for the adapter. 1013 * @dev: class device that is converted into a Scsi_host. 1014 * @attr: device attribute, not used. 1015 * @buf: one or more lpfc_polling_flags values. 1016 * @count: not used. 1017 * 1018 * Notes: 1019 * buf contents converted to integer and checked for a valid value. 1020 * 1021 * Returns: 1022 * -EINVAL if the buffer connot be converted or is out of range 1023 * length of the buf on success 1024 **/ 1025 static ssize_t 1026 lpfc_poll_store(struct device *dev, struct device_attribute *attr, 1027 const char *buf, size_t count) 1028 { 1029 struct Scsi_Host *shost = class_to_shost(dev); 1030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1031 struct lpfc_hba *phba = vport->phba; 1032 uint32_t creg_val; 1033 uint32_t old_val; 1034 int val=0; 1035 1036 if (!isdigit(buf[0])) 1037 return -EINVAL; 1038 1039 if (sscanf(buf, "%i", &val) != 1) 1040 return -EINVAL; 1041 1042 if ((val & 0x3) != val) 1043 return -EINVAL; 1044 1045 spin_lock_irq(&phba->hbalock); 1046 1047 old_val = phba->cfg_poll; 1048 1049 if (val & ENABLE_FCP_RING_POLLING) { 1050 if ((val & DISABLE_FCP_RING_INT) && 1051 !(old_val & DISABLE_FCP_RING_INT)) { 1052 creg_val = readl(phba->HCregaddr); 1053 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); 1054 writel(creg_val, phba->HCregaddr); 1055 readl(phba->HCregaddr); /* flush */ 1056 1057 lpfc_poll_start_timer(phba); 1058 } 1059 } else if (val != 0x0) { 1060 spin_unlock_irq(&phba->hbalock); 1061 return -EINVAL; 1062 } 1063 1064 if (!(val & DISABLE_FCP_RING_INT) && 1065 (old_val & DISABLE_FCP_RING_INT)) 1066 { 1067 spin_unlock_irq(&phba->hbalock); 1068 del_timer(&phba->fcp_poll_timer); 1069 spin_lock_irq(&phba->hbalock); 1070 creg_val = readl(phba->HCregaddr); 1071 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); 1072 writel(creg_val, phba->HCregaddr); 1073 readl(phba->HCregaddr); /* flush */ 1074 } 1075 1076 phba->cfg_poll = val; 1077 1078 spin_unlock_irq(&phba->hbalock); 1079 1080 return strlen(buf); 1081 } 1082 1083 /** 1084 * lpfc_param_show: Return a cfg attribute value in decimal. 1085 * 1086 * Description: 1087 * Macro that given an attr e.g. hba_queue_depth expands 1088 * into a function with the name lpfc_hba_queue_depth_show. 1089 * 1090 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field. 1091 * @dev: class device that is converted into a Scsi_host. 1092 * @attr: device attribute, not used. 1093 * @buf: on return contains the attribute value in decimal. 1094 * 1095 * Returns: size of formatted string. 1096 **/ 1097 #define lpfc_param_show(attr) \ 1098 static ssize_t \ 1099 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 1100 char *buf) \ 1101 { \ 1102 struct Scsi_Host *shost = class_to_shost(dev);\ 1103 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1104 struct lpfc_hba *phba = vport->phba;\ 1105 int val = 0;\ 1106 val = phba->cfg_##attr;\ 1107 return snprintf(buf, PAGE_SIZE, "%d\n",\ 1108 phba->cfg_##attr);\ 1109 } 1110 1111 /** 1112 * lpfc_param_hex_show: Return a cfg attribute value in hex. 1113 * 1114 * Description: 1115 * Macro that given an attr e.g. hba_queue_depth expands 1116 * into a function with the name lpfc_hba_queue_depth_show 1117 * 1118 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field. 1119 * @dev: class device that is converted into a Scsi_host. 1120 * @attr: device attribute, not used. 1121 * @buf: on return contains the attribute value in hexidecimal. 1122 * 1123 * Returns: size of formatted string. 1124 **/ 1125 #define lpfc_param_hex_show(attr) \ 1126 static ssize_t \ 1127 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 1128 char *buf) \ 1129 { \ 1130 struct Scsi_Host *shost = class_to_shost(dev);\ 1131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1132 struct lpfc_hba *phba = vport->phba;\ 1133 int val = 0;\ 1134 val = phba->cfg_##attr;\ 1135 return snprintf(buf, PAGE_SIZE, "%#x\n",\ 1136 phba->cfg_##attr);\ 1137 } 1138 1139 /** 1140 * lpfc_param_init: Intializes a cfg attribute. 1141 * 1142 * Description: 1143 * Macro that given an attr e.g. hba_queue_depth expands 1144 * into a function with the name lpfc_hba_queue_depth_init. The macro also 1145 * takes a default argument, a minimum and maximum argument. 1146 * 1147 * lpfc_##attr##_init: Initializes an attribute. 1148 * @phba: pointer the the adapter structure. 1149 * @val: integer attribute value. 1150 * 1151 * Validates the min and max values then sets the adapter config field 1152 * accordingly, or uses the default if out of range and prints an error message. 1153 * 1154 * Returns: 1155 * zero on success 1156 * -EINVAL if default used 1157 **/ 1158 #define lpfc_param_init(attr, default, minval, maxval) \ 1159 static int \ 1160 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \ 1161 { \ 1162 if (val >= minval && val <= maxval) {\ 1163 phba->cfg_##attr = val;\ 1164 return 0;\ 1165 }\ 1166 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ 1167 "0449 lpfc_"#attr" attribute cannot be set to %d, "\ 1168 "allowed range is ["#minval", "#maxval"]\n", val); \ 1169 phba->cfg_##attr = default;\ 1170 return -EINVAL;\ 1171 } 1172 1173 /** 1174 * lpfc_param_set: Set a cfg attribute value. 1175 * 1176 * Description: 1177 * Macro that given an attr e.g. hba_queue_depth expands 1178 * into a function with the name lpfc_hba_queue_depth_set 1179 * 1180 * lpfc_##attr##_set: Sets an attribute value. 1181 * @phba: pointer the the adapter structure. 1182 * @val: integer attribute value. 1183 * 1184 * Description: 1185 * Validates the min and max values then sets the 1186 * adapter config field if in the valid range. prints error message 1187 * and does not set the parameter if invalid. 1188 * 1189 * Returns: 1190 * zero on success 1191 * -EINVAL if val is invalid 1192 **/ 1193 #define lpfc_param_set(attr, default, minval, maxval) \ 1194 static int \ 1195 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \ 1196 { \ 1197 if (val >= minval && val <= maxval) {\ 1198 phba->cfg_##attr = val;\ 1199 return 0;\ 1200 }\ 1201 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ 1202 "0450 lpfc_"#attr" attribute cannot be set to %d, "\ 1203 "allowed range is ["#minval", "#maxval"]\n", val); \ 1204 return -EINVAL;\ 1205 } 1206 1207 /** 1208 * lpfc_param_store: Set a vport attribute value. 1209 * 1210 * Description: 1211 * Macro that given an attr e.g. hba_queue_depth expands 1212 * into a function with the name lpfc_hba_queue_depth_store. 1213 * 1214 * lpfc_##attr##_store: Set an sttribute value. 1215 * @dev: class device that is converted into a Scsi_host. 1216 * @attr: device attribute, not used. 1217 * @buf: contains the attribute value in ascii. 1218 * @count: not used. 1219 * 1220 * Description: 1221 * Convert the ascii text number to an integer, then 1222 * use the lpfc_##attr##_set function to set the value. 1223 * 1224 * Returns: 1225 * -EINVAL if val is invalid or lpfc_##attr##_set() fails 1226 * length of buffer upon success. 1227 **/ 1228 #define lpfc_param_store(attr) \ 1229 static ssize_t \ 1230 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ 1231 const char *buf, size_t count) \ 1232 { \ 1233 struct Scsi_Host *shost = class_to_shost(dev);\ 1234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1235 struct lpfc_hba *phba = vport->phba;\ 1236 int val=0;\ 1237 if (!isdigit(buf[0]))\ 1238 return -EINVAL;\ 1239 if (sscanf(buf, "%i", &val) != 1)\ 1240 return -EINVAL;\ 1241 if (lpfc_##attr##_set(phba, val) == 0) \ 1242 return strlen(buf);\ 1243 else \ 1244 return -EINVAL;\ 1245 } 1246 1247 /** 1248 * lpfc_vport_param_show: Return decimal formatted cfg attribute value. 1249 * 1250 * Description: 1251 * Macro that given an attr e.g. hba_queue_depth expands 1252 * into a function with the name lpfc_hba_queue_depth_show 1253 * 1254 * lpfc_##attr##_show: prints the attribute value in decimal. 1255 * @dev: class device that is converted into a Scsi_host. 1256 * @attr: device attribute, not used. 1257 * @buf: on return contains the attribute value in decimal. 1258 * 1259 * Returns: length of formatted string. 1260 **/ 1261 #define lpfc_vport_param_show(attr) \ 1262 static ssize_t \ 1263 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 1264 char *buf) \ 1265 { \ 1266 struct Scsi_Host *shost = class_to_shost(dev);\ 1267 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1268 int val = 0;\ 1269 val = vport->cfg_##attr;\ 1270 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ 1271 } 1272 1273 /** 1274 * lpfc_vport_param_hex_show: Return hex formatted attribute value. 1275 * 1276 * Description: 1277 * Macro that given an attr e.g. 1278 * hba_queue_depth expands into a function with the name 1279 * lpfc_hba_queue_depth_show 1280 * 1281 * lpfc_##attr##_show: prints the attribute value in hexidecimal. 1282 * @dev: class device that is converted into a Scsi_host. 1283 * @attr: device attribute, not used. 1284 * @buf: on return contains the attribute value in hexidecimal. 1285 * 1286 * Returns: length of formatted string. 1287 **/ 1288 #define lpfc_vport_param_hex_show(attr) \ 1289 static ssize_t \ 1290 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 1291 char *buf) \ 1292 { \ 1293 struct Scsi_Host *shost = class_to_shost(dev);\ 1294 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1295 int val = 0;\ 1296 val = vport->cfg_##attr;\ 1297 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ 1298 } 1299 1300 /** 1301 * lpfc_vport_param_init: Initialize a vport cfg attribute. 1302 * 1303 * Description: 1304 * Macro that given an attr e.g. hba_queue_depth expands 1305 * into a function with the name lpfc_hba_queue_depth_init. The macro also 1306 * takes a default argument, a minimum and maximum argument. 1307 * 1308 * lpfc_##attr##_init: validates the min and max values then sets the 1309 * adapter config field accordingly, or uses the default if out of range 1310 * and prints an error message. 1311 * @phba: pointer the the adapter structure. 1312 * @val: integer attribute value. 1313 * 1314 * Returns: 1315 * zero on success 1316 * -EINVAL if default used 1317 **/ 1318 #define lpfc_vport_param_init(attr, default, minval, maxval) \ 1319 static int \ 1320 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \ 1321 { \ 1322 if (val >= minval && val <= maxval) {\ 1323 vport->cfg_##attr = val;\ 1324 return 0;\ 1325 }\ 1326 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ 1327 "0423 lpfc_"#attr" attribute cannot be set to %d, "\ 1328 "allowed range is ["#minval", "#maxval"]\n", val); \ 1329 vport->cfg_##attr = default;\ 1330 return -EINVAL;\ 1331 } 1332 1333 /** 1334 * lpfc_vport_param_set: Set a vport cfg attribute. 1335 * 1336 * Description: 1337 * Macro that given an attr e.g. hba_queue_depth expands 1338 * into a function with the name lpfc_hba_queue_depth_set 1339 * 1340 * lpfc_##attr##_set: validates the min and max values then sets the 1341 * adapter config field if in the valid range. prints error message 1342 * and does not set the parameter if invalid. 1343 * @phba: pointer the the adapter structure. 1344 * @val: integer attribute value. 1345 * 1346 * Returns: 1347 * zero on success 1348 * -EINVAL if val is invalid 1349 **/ 1350 #define lpfc_vport_param_set(attr, default, minval, maxval) \ 1351 static int \ 1352 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \ 1353 { \ 1354 if (val >= minval && val <= maxval) {\ 1355 vport->cfg_##attr = val;\ 1356 return 0;\ 1357 }\ 1358 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ 1359 "0424 lpfc_"#attr" attribute cannot be set to %d, "\ 1360 "allowed range is ["#minval", "#maxval"]\n", val); \ 1361 return -EINVAL;\ 1362 } 1363 1364 /** 1365 * lpfc_vport_param_store: Set a vport attribute. 1366 * 1367 * Description: 1368 * Macro that given an attr e.g. hba_queue_depth 1369 * expands into a function with the name lpfc_hba_queue_depth_store 1370 * 1371 * lpfc_##attr##_store: convert the ascii text number to an integer, then 1372 * use the lpfc_##attr##_set function to set the value. 1373 * @cdev: class device that is converted into a Scsi_host. 1374 * @buf: contains the attribute value in decimal. 1375 * @count: not used. 1376 * 1377 * Returns: 1378 * -EINVAL if val is invalid or lpfc_##attr##_set() fails 1379 * length of buffer upon success. 1380 **/ 1381 #define lpfc_vport_param_store(attr) \ 1382 static ssize_t \ 1383 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ 1384 const char *buf, size_t count) \ 1385 { \ 1386 struct Scsi_Host *shost = class_to_shost(dev);\ 1387 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1388 int val=0;\ 1389 if (!isdigit(buf[0]))\ 1390 return -EINVAL;\ 1391 if (sscanf(buf, "%i", &val) != 1)\ 1392 return -EINVAL;\ 1393 if (lpfc_##attr##_set(vport, val) == 0) \ 1394 return strlen(buf);\ 1395 else \ 1396 return -EINVAL;\ 1397 } 1398 1399 1400 #define LPFC_ATTR(name, defval, minval, maxval, desc) \ 1401 static int lpfc_##name = defval;\ 1402 module_param(lpfc_##name, int, 0);\ 1403 MODULE_PARM_DESC(lpfc_##name, desc);\ 1404 lpfc_param_init(name, defval, minval, maxval) 1405 1406 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ 1407 static int lpfc_##name = defval;\ 1408 module_param(lpfc_##name, int, 0);\ 1409 MODULE_PARM_DESC(lpfc_##name, desc);\ 1410 lpfc_param_show(name)\ 1411 lpfc_param_init(name, defval, minval, maxval)\ 1412 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 1413 1414 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ 1415 static int lpfc_##name = defval;\ 1416 module_param(lpfc_##name, int, 0);\ 1417 MODULE_PARM_DESC(lpfc_##name, desc);\ 1418 lpfc_param_show(name)\ 1419 lpfc_param_init(name, defval, minval, maxval)\ 1420 lpfc_param_set(name, defval, minval, maxval)\ 1421 lpfc_param_store(name)\ 1422 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ 1423 lpfc_##name##_show, lpfc_##name##_store) 1424 1425 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \ 1426 static int lpfc_##name = defval;\ 1427 module_param(lpfc_##name, int, 0);\ 1428 MODULE_PARM_DESC(lpfc_##name, desc);\ 1429 lpfc_param_hex_show(name)\ 1430 lpfc_param_init(name, defval, minval, maxval)\ 1431 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 1432 1433 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ 1434 static int lpfc_##name = defval;\ 1435 module_param(lpfc_##name, int, 0);\ 1436 MODULE_PARM_DESC(lpfc_##name, desc);\ 1437 lpfc_param_hex_show(name)\ 1438 lpfc_param_init(name, defval, minval, maxval)\ 1439 lpfc_param_set(name, defval, minval, maxval)\ 1440 lpfc_param_store(name)\ 1441 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ 1442 lpfc_##name##_show, lpfc_##name##_store) 1443 1444 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \ 1445 static int lpfc_##name = defval;\ 1446 module_param(lpfc_##name, int, 0);\ 1447 MODULE_PARM_DESC(lpfc_##name, desc);\ 1448 lpfc_vport_param_init(name, defval, minval, maxval) 1449 1450 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \ 1451 static int lpfc_##name = defval;\ 1452 module_param(lpfc_##name, int, 0);\ 1453 MODULE_PARM_DESC(lpfc_##name, desc);\ 1454 lpfc_vport_param_show(name)\ 1455 lpfc_vport_param_init(name, defval, minval, maxval)\ 1456 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 1457 1458 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \ 1459 static int lpfc_##name = defval;\ 1460 module_param(lpfc_##name, int, 0);\ 1461 MODULE_PARM_DESC(lpfc_##name, desc);\ 1462 lpfc_vport_param_show(name)\ 1463 lpfc_vport_param_init(name, defval, minval, maxval)\ 1464 lpfc_vport_param_set(name, defval, minval, maxval)\ 1465 lpfc_vport_param_store(name)\ 1466 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ 1467 lpfc_##name##_show, lpfc_##name##_store) 1468 1469 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \ 1470 static int lpfc_##name = defval;\ 1471 module_param(lpfc_##name, int, 0);\ 1472 MODULE_PARM_DESC(lpfc_##name, desc);\ 1473 lpfc_vport_param_hex_show(name)\ 1474 lpfc_vport_param_init(name, defval, minval, maxval)\ 1475 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 1476 1477 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ 1478 static int lpfc_##name = defval;\ 1479 module_param(lpfc_##name, int, 0);\ 1480 MODULE_PARM_DESC(lpfc_##name, desc);\ 1481 lpfc_vport_param_hex_show(name)\ 1482 lpfc_vport_param_init(name, defval, minval, maxval)\ 1483 lpfc_vport_param_set(name, defval, minval, maxval)\ 1484 lpfc_vport_param_store(name)\ 1485 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ 1486 lpfc_##name##_show, lpfc_##name##_store) 1487 1488 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); 1489 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); 1490 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); 1491 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); 1492 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); 1493 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL); 1494 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); 1495 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); 1496 static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL); 1497 static DEVICE_ATTR(option_rom_version, S_IRUGO, 1498 lpfc_option_rom_version_show, NULL); 1499 static DEVICE_ATTR(num_discovered_ports, S_IRUGO, 1500 lpfc_num_discovered_ports_show, NULL); 1501 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL); 1502 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); 1503 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL); 1504 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, 1505 lpfc_board_mode_show, lpfc_board_mode_store); 1506 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); 1507 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL); 1508 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL); 1509 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL); 1510 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL); 1511 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL); 1512 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL); 1513 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL); 1514 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL); 1515 1516 1517 static char *lpfc_soft_wwn_key = "C99G71SL8032A"; 1518 1519 /** 1520 * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid. 1521 * @dev: class device that is converted into a Scsi_host. 1522 * @attr: device attribute, not used. 1523 * @buf: containing the string lpfc_soft_wwn_key. 1524 * @count: must be size of lpfc_soft_wwn_key. 1525 * 1526 * Returns: 1527 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key 1528 * length of buf indicates success 1529 **/ 1530 static ssize_t 1531 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr, 1532 const char *buf, size_t count) 1533 { 1534 struct Scsi_Host *shost = class_to_shost(dev); 1535 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1536 struct lpfc_hba *phba = vport->phba; 1537 unsigned int cnt = count; 1538 1539 /* 1540 * We're doing a simple sanity check for soft_wwpn setting. 1541 * We require that the user write a specific key to enable 1542 * the soft_wwpn attribute to be settable. Once the attribute 1543 * is written, the enable key resets. If further updates are 1544 * desired, the key must be written again to re-enable the 1545 * attribute. 1546 * 1547 * The "key" is not secret - it is a hardcoded string shown 1548 * here. The intent is to protect against the random user or 1549 * application that is just writing attributes. 1550 */ 1551 1552 /* count may include a LF at end of string */ 1553 if (buf[cnt-1] == '\n') 1554 cnt--; 1555 1556 if ((cnt != strlen(lpfc_soft_wwn_key)) || 1557 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0)) 1558 return -EINVAL; 1559 1560 phba->soft_wwn_enable = 1; 1561 return count; 1562 } 1563 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL, 1564 lpfc_soft_wwn_enable_store); 1565 1566 /** 1567 * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter. 1568 * @dev: class device that is converted into a Scsi_host. 1569 * @attr: device attribute, not used. 1570 * @buf: on return contains the wwpn in hexidecimal. 1571 * 1572 * Returns: size of formatted string. 1573 **/ 1574 static ssize_t 1575 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr, 1576 char *buf) 1577 { 1578 struct Scsi_Host *shost = class_to_shost(dev); 1579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1580 struct lpfc_hba *phba = vport->phba; 1581 1582 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 1583 (unsigned long long)phba->cfg_soft_wwpn); 1584 } 1585 1586 /** 1587 * lpfc_soft_wwpn_store: Set the ww port name of the adapter. 1588 * @dev class device that is converted into a Scsi_host. 1589 * @attr: device attribute, not used. 1590 * @buf: contains the wwpn in hexidecimal. 1591 * @count: number of wwpn bytes in buf 1592 * 1593 * Returns: 1594 * -EACCES hba reset not enabled, adapter over temp 1595 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid 1596 * -EIO error taking adapter offline or online 1597 * value of count on success 1598 **/ 1599 static ssize_t 1600 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr, 1601 const char *buf, size_t count) 1602 { 1603 struct Scsi_Host *shost = class_to_shost(dev); 1604 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1605 struct lpfc_hba *phba = vport->phba; 1606 struct completion online_compl; 1607 int stat1=0, stat2=0; 1608 unsigned int i, j, cnt=count; 1609 u8 wwpn[8]; 1610 1611 if (!phba->cfg_enable_hba_reset) 1612 return -EACCES; 1613 spin_lock_irq(&phba->hbalock); 1614 if (phba->over_temp_state == HBA_OVER_TEMP) { 1615 spin_unlock_irq(&phba->hbalock); 1616 return -EACCES; 1617 } 1618 spin_unlock_irq(&phba->hbalock); 1619 /* count may include a LF at end of string */ 1620 if (buf[cnt-1] == '\n') 1621 cnt--; 1622 1623 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || 1624 ((cnt == 17) && (*buf++ != 'x')) || 1625 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) 1626 return -EINVAL; 1627 1628 phba->soft_wwn_enable = 0; 1629 1630 memset(wwpn, 0, sizeof(wwpn)); 1631 1632 /* Validate and store the new name */ 1633 for (i=0, j=0; i < 16; i++) { 1634 if ((*buf >= 'a') && (*buf <= 'f')) 1635 j = ((j << 4) | ((*buf++ -'a') + 10)); 1636 else if ((*buf >= 'A') && (*buf <= 'F')) 1637 j = ((j << 4) | ((*buf++ -'A') + 10)); 1638 else if ((*buf >= '0') && (*buf <= '9')) 1639 j = ((j << 4) | (*buf++ -'0')); 1640 else 1641 return -EINVAL; 1642 if (i % 2) { 1643 wwpn[i/2] = j & 0xff; 1644 j = 0; 1645 } 1646 } 1647 phba->cfg_soft_wwpn = wwn_to_u64(wwpn); 1648 fc_host_port_name(shost) = phba->cfg_soft_wwpn; 1649 if (phba->cfg_soft_wwnn) 1650 fc_host_node_name(shost) = phba->cfg_soft_wwnn; 1651 1652 dev_printk(KERN_NOTICE, &phba->pcidev->dev, 1653 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); 1654 1655 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); 1656 if (stat1) 1657 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 1658 "0463 lpfc_soft_wwpn attribute set failed to " 1659 "reinit adapter - %d\n", stat1); 1660 init_completion(&online_compl); 1661 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE); 1662 wait_for_completion(&online_compl); 1663 if (stat2) 1664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 1665 "0464 lpfc_soft_wwpn attribute set failed to " 1666 "reinit adapter - %d\n", stat2); 1667 return (stat1 || stat2) ? -EIO : count; 1668 } 1669 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\ 1670 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store); 1671 1672 /** 1673 * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter. 1674 * @dev: class device that is converted into a Scsi_host. 1675 * @attr: device attribute, not used. 1676 * @buf: on return contains the wwnn in hexidecimal. 1677 * 1678 * Returns: size of formatted string. 1679 **/ 1680 static ssize_t 1681 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr, 1682 char *buf) 1683 { 1684 struct Scsi_Host *shost = class_to_shost(dev); 1685 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 1686 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 1687 (unsigned long long)phba->cfg_soft_wwnn); 1688 } 1689 1690 /** 1691 * lpfc_soft_wwnn_store: sets the ww node name of the adapter. 1692 * @cdev: class device that is converted into a Scsi_host. 1693 * @buf: contains the ww node name in hexidecimal. 1694 * @count: number of wwnn bytes in buf. 1695 * 1696 * Returns: 1697 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid 1698 * value of count on success 1699 **/ 1700 static ssize_t 1701 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr, 1702 const char *buf, size_t count) 1703 { 1704 struct Scsi_Host *shost = class_to_shost(dev); 1705 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 1706 unsigned int i, j, cnt=count; 1707 u8 wwnn[8]; 1708 1709 /* count may include a LF at end of string */ 1710 if (buf[cnt-1] == '\n') 1711 cnt--; 1712 1713 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || 1714 ((cnt == 17) && (*buf++ != 'x')) || 1715 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) 1716 return -EINVAL; 1717 1718 /* 1719 * Allow wwnn to be set many times, as long as the enable is set. 1720 * However, once the wwpn is set, everything locks. 1721 */ 1722 1723 memset(wwnn, 0, sizeof(wwnn)); 1724 1725 /* Validate and store the new name */ 1726 for (i=0, j=0; i < 16; i++) { 1727 if ((*buf >= 'a') && (*buf <= 'f')) 1728 j = ((j << 4) | ((*buf++ -'a') + 10)); 1729 else if ((*buf >= 'A') && (*buf <= 'F')) 1730 j = ((j << 4) | ((*buf++ -'A') + 10)); 1731 else if ((*buf >= '0') && (*buf <= '9')) 1732 j = ((j << 4) | (*buf++ -'0')); 1733 else 1734 return -EINVAL; 1735 if (i % 2) { 1736 wwnn[i/2] = j & 0xff; 1737 j = 0; 1738 } 1739 } 1740 phba->cfg_soft_wwnn = wwn_to_u64(wwnn); 1741 1742 dev_printk(KERN_NOTICE, &phba->pcidev->dev, 1743 "lpfc%d: soft_wwnn set. Value will take effect upon " 1744 "setting of the soft_wwpn\n", phba->brd_no); 1745 1746 return count; 1747 } 1748 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\ 1749 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store); 1750 1751 1752 static int lpfc_poll = 0; 1753 module_param(lpfc_poll, int, 0); 1754 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" 1755 " 0 - none," 1756 " 1 - poll with interrupts enabled" 1757 " 3 - poll and disable FCP ring interrupts"); 1758 1759 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, 1760 lpfc_poll_show, lpfc_poll_store); 1761 1762 int lpfc_sli_mode = 0; 1763 module_param(lpfc_sli_mode, int, 0); 1764 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:" 1765 " 0 - auto (SLI-3 if supported)," 1766 " 2 - select SLI-2 even on SLI-3 capable HBAs," 1767 " 3 - select SLI-3"); 1768 1769 int lpfc_enable_npiv = 0; 1770 module_param(lpfc_enable_npiv, int, 0); 1771 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality"); 1772 lpfc_param_show(enable_npiv); 1773 lpfc_param_init(enable_npiv, 0, 0, 1); 1774 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, 1775 lpfc_enable_npiv_show, NULL); 1776 1777 /* 1778 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear 1779 # until the timer expires. Value range is [0,255]. Default value is 30. 1780 */ 1781 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; 1782 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO; 1783 module_param(lpfc_nodev_tmo, int, 0); 1784 MODULE_PARM_DESC(lpfc_nodev_tmo, 1785 "Seconds driver will hold I/O waiting " 1786 "for a device to come back"); 1787 1788 /** 1789 * lpfc_nodev_tmo_show: Return the hba dev loss timeout value. 1790 * @dev: class converted to a Scsi_host structure. 1791 * @attr: device attribute, not used. 1792 * @buf: on return contains the dev loss timeout in decimal. 1793 * 1794 * Returns: size of formatted string. 1795 **/ 1796 static ssize_t 1797 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr, 1798 char *buf) 1799 { 1800 struct Scsi_Host *shost = class_to_shost(dev); 1801 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1802 int val = 0; 1803 val = vport->cfg_devloss_tmo; 1804 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo); 1805 } 1806 1807 /** 1808 * lpfc_nodev_tmo_init: Set the hba nodev timeout value. 1809 * @vport: lpfc vport structure pointer. 1810 * @val: contains the nodev timeout value. 1811 * 1812 * Description: 1813 * If the devloss tmo is already set then nodev tmo is set to devloss tmo, 1814 * a kernel error message is printed and zero is returned. 1815 * Else if val is in range then nodev tmo and devloss tmo are set to val. 1816 * Otherwise nodev tmo is set to the default value. 1817 * 1818 * Returns: 1819 * zero if already set or if val is in range 1820 * -EINVAL val out of range 1821 **/ 1822 static int 1823 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val) 1824 { 1825 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) { 1826 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo; 1827 if (val != LPFC_DEF_DEVLOSS_TMO) 1828 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1829 "0407 Ignoring nodev_tmo module " 1830 "parameter because devloss_tmo is " 1831 "set.\n"); 1832 return 0; 1833 } 1834 1835 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { 1836 vport->cfg_nodev_tmo = val; 1837 vport->cfg_devloss_tmo = val; 1838 return 0; 1839 } 1840 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1841 "0400 lpfc_nodev_tmo attribute cannot be set to" 1842 " %d, allowed range is [%d, %d]\n", 1843 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); 1844 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; 1845 return -EINVAL; 1846 } 1847 1848 /** 1849 * lpfc_update_rport_devloss_tmo: Update dev loss tmo value. 1850 * @vport: lpfc vport structure pointer. 1851 * 1852 * Description: 1853 * Update all the ndlp's dev loss tmo with the vport devloss tmo value. 1854 **/ 1855 static void 1856 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport) 1857 { 1858 struct Scsi_Host *shost; 1859 struct lpfc_nodelist *ndlp; 1860 1861 shost = lpfc_shost_from_vport(vport); 1862 spin_lock_irq(shost->host_lock); 1863 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) 1864 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport) 1865 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo; 1866 spin_unlock_irq(shost->host_lock); 1867 } 1868 1869 /** 1870 * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values. 1871 * @vport: lpfc vport structure pointer. 1872 * @val: contains the tmo value. 1873 * 1874 * Description: 1875 * If the devloss tmo is already set or the vport dev loss tmo has changed 1876 * then a kernel error message is printed and zero is returned. 1877 * Else if val is in range then nodev tmo and devloss tmo are set to val. 1878 * Otherwise nodev tmo is set to the default value. 1879 * 1880 * Returns: 1881 * zero if already set or if val is in range 1882 * -EINVAL val out of range 1883 **/ 1884 static int 1885 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val) 1886 { 1887 if (vport->dev_loss_tmo_changed || 1888 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) { 1889 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1890 "0401 Ignoring change to nodev_tmo " 1891 "because devloss_tmo is set.\n"); 1892 return 0; 1893 } 1894 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { 1895 vport->cfg_nodev_tmo = val; 1896 vport->cfg_devloss_tmo = val; 1897 lpfc_update_rport_devloss_tmo(vport); 1898 return 0; 1899 } 1900 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1901 "0403 lpfc_nodev_tmo attribute cannot be set to" 1902 "%d, allowed range is [%d, %d]\n", 1903 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); 1904 return -EINVAL; 1905 } 1906 1907 lpfc_vport_param_store(nodev_tmo) 1908 1909 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR, 1910 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store); 1911 1912 /* 1913 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that 1914 # disappear until the timer expires. Value range is [0,255]. Default 1915 # value is 30. 1916 */ 1917 module_param(lpfc_devloss_tmo, int, 0); 1918 MODULE_PARM_DESC(lpfc_devloss_tmo, 1919 "Seconds driver will hold I/O waiting " 1920 "for a device to come back"); 1921 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, 1922 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) 1923 lpfc_vport_param_show(devloss_tmo) 1924 1925 /** 1926 * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit. 1927 * @vport: lpfc vport structure pointer. 1928 * @val: contains the tmo value. 1929 * 1930 * Description: 1931 * If val is in a valid range then set the vport nodev tmo, 1932 * devloss tmo, also set the vport dev loss tmo changed flag. 1933 * Else a kernel error message is printed. 1934 * 1935 * Returns: 1936 * zero if val is in range 1937 * -EINVAL val out of range 1938 **/ 1939 static int 1940 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val) 1941 { 1942 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { 1943 vport->cfg_nodev_tmo = val; 1944 vport->cfg_devloss_tmo = val; 1945 vport->dev_loss_tmo_changed = 1; 1946 lpfc_update_rport_devloss_tmo(vport); 1947 return 0; 1948 } 1949 1950 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1951 "0404 lpfc_devloss_tmo attribute cannot be set to" 1952 " %d, allowed range is [%d, %d]\n", 1953 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); 1954 return -EINVAL; 1955 } 1956 1957 lpfc_vport_param_store(devloss_tmo) 1958 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR, 1959 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store); 1960 1961 /* 1962 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being 1963 # deluged with LOTS of information. 1964 # You can set a bit mask to record specific types of verbose messages: 1965 # 1966 # LOG_ELS 0x1 ELS events 1967 # LOG_DISCOVERY 0x2 Link discovery events 1968 # LOG_MBOX 0x4 Mailbox events 1969 # LOG_INIT 0x8 Initialization events 1970 # LOG_LINK_EVENT 0x10 Link events 1971 # LOG_FCP 0x40 FCP traffic history 1972 # LOG_NODE 0x80 Node table events 1973 # LOG_MISC 0x400 Miscellaneous events 1974 # LOG_SLI 0x800 SLI events 1975 # LOG_FCP_ERROR 0x1000 Only log FCP errors 1976 # LOG_LIBDFC 0x2000 LIBDFC events 1977 # LOG_ALL_MSG 0xffff LOG all messages 1978 */ 1979 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, 1980 "Verbose logging bit-mask"); 1981 1982 /* 1983 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters 1984 # objects that have been registered with the nameserver after login. 1985 */ 1986 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1, 1987 "Deregister nameserver objects before LOGO"); 1988 1989 /* 1990 # lun_queue_depth: This parameter is used to limit the number of outstanding 1991 # commands per FCP LUN. Value range is [1,128]. Default value is 30. 1992 */ 1993 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128, 1994 "Max number of FCP commands we can queue to a specific LUN"); 1995 1996 /* 1997 # hba_queue_depth: This parameter is used to limit the number of outstanding 1998 # commands per lpfc HBA. Value range is [32,8192]. If this parameter 1999 # value is greater than the maximum number of exchanges supported by the HBA, 2000 # then maximum number of exchanges supported by the HBA is used to determine 2001 # the hba_queue_depth. 2002 */ 2003 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192, 2004 "Max number of FCP commands we can queue to a lpfc HBA"); 2005 2006 /* 2007 # peer_port_login: This parameter allows/prevents logins 2008 # between peer ports hosted on the same physical port. 2009 # When this parameter is set 0 peer ports of same physical port 2010 # are not allowed to login to each other. 2011 # When this parameter is set 1 peer ports of same physical port 2012 # are allowed to login to each other. 2013 # Default value of this parameter is 0. 2014 */ 2015 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1, 2016 "Allow peer ports on the same physical port to login to each " 2017 "other."); 2018 2019 /* 2020 # restrict_login: This parameter allows/prevents logins 2021 # between Virtual Ports and remote initiators. 2022 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from 2023 # other initiators and will attempt to PLOGI all remote ports. 2024 # When this parameter is set (1) Virtual Ports will reject PLOGIs from 2025 # remote ports and will not attempt to PLOGI to other initiators. 2026 # This parameter does not restrict to the physical port. 2027 # This parameter does not restrict logins to Fabric resident remote ports. 2028 # Default value of this parameter is 1. 2029 */ 2030 static int lpfc_restrict_login = 1; 2031 module_param(lpfc_restrict_login, int, 0); 2032 MODULE_PARM_DESC(lpfc_restrict_login, 2033 "Restrict virtual ports login to remote initiators."); 2034 lpfc_vport_param_show(restrict_login); 2035 2036 /** 2037 * lpfc_restrict_login_init: Set the vport restrict login flag. 2038 * @vport: lpfc vport structure pointer. 2039 * @val: contains the restrict login value. 2040 * 2041 * Description: 2042 * If val is not in a valid range then log a kernel error message and set 2043 * the vport restrict login to one. 2044 * If the port type is physical clear the restrict login flag and return. 2045 * Else set the restrict login flag to val. 2046 * 2047 * Returns: 2048 * zero if val is in range 2049 * -EINVAL val out of range 2050 **/ 2051 static int 2052 lpfc_restrict_login_init(struct lpfc_vport *vport, int val) 2053 { 2054 if (val < 0 || val > 1) { 2055 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 2056 "0422 lpfc_restrict_login attribute cannot " 2057 "be set to %d, allowed range is [0, 1]\n", 2058 val); 2059 vport->cfg_restrict_login = 1; 2060 return -EINVAL; 2061 } 2062 if (vport->port_type == LPFC_PHYSICAL_PORT) { 2063 vport->cfg_restrict_login = 0; 2064 return 0; 2065 } 2066 vport->cfg_restrict_login = val; 2067 return 0; 2068 } 2069 2070 /** 2071 * lpfc_restrict_login_set: Set the vport restrict login flag. 2072 * @vport: lpfc vport structure pointer. 2073 * @val: contains the restrict login value. 2074 * 2075 * Description: 2076 * If val is not in a valid range then log a kernel error message and set 2077 * the vport restrict login to one. 2078 * If the port type is physical and the val is not zero log a kernel 2079 * error message, clear the restrict login flag and return zero. 2080 * Else set the restrict login flag to val. 2081 * 2082 * Returns: 2083 * zero if val is in range 2084 * -EINVAL val out of range 2085 **/ 2086 static int 2087 lpfc_restrict_login_set(struct lpfc_vport *vport, int val) 2088 { 2089 if (val < 0 || val > 1) { 2090 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 2091 "0425 lpfc_restrict_login attribute cannot " 2092 "be set to %d, allowed range is [0, 1]\n", 2093 val); 2094 vport->cfg_restrict_login = 1; 2095 return -EINVAL; 2096 } 2097 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) { 2098 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 2099 "0468 lpfc_restrict_login must be 0 for " 2100 "Physical ports.\n"); 2101 vport->cfg_restrict_login = 0; 2102 return 0; 2103 } 2104 vport->cfg_restrict_login = val; 2105 return 0; 2106 } 2107 lpfc_vport_param_store(restrict_login); 2108 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR, 2109 lpfc_restrict_login_show, lpfc_restrict_login_store); 2110 2111 /* 2112 # Some disk devices have a "select ID" or "select Target" capability. 2113 # From a protocol standpoint "select ID" usually means select the 2114 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative 2115 # annex" which contains a table that maps a "select ID" (a number 2116 # between 0 and 7F) to an ALPA. By default, for compatibility with 2117 # older drivers, the lpfc driver scans this table from low ALPA to high 2118 # ALPA. 2119 # 2120 # Turning on the scan-down variable (on = 1, off = 0) will 2121 # cause the lpfc driver to use an inverted table, effectively 2122 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. 2123 # 2124 # (Note: This "select ID" functionality is a LOOP ONLY characteristic 2125 # and will not work across a fabric. Also this parameter will take 2126 # effect only in the case when ALPA map is not available.) 2127 */ 2128 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1, 2129 "Start scanning for devices from highest ALPA to lowest"); 2130 2131 /* 2132 # lpfc_topology: link topology for init link 2133 # 0x0 = attempt loop mode then point-to-point 2134 # 0x01 = internal loopback mode 2135 # 0x02 = attempt point-to-point mode only 2136 # 0x04 = attempt loop mode only 2137 # 0x06 = attempt point-to-point mode then loop 2138 # Set point-to-point mode if you want to run as an N_Port. 2139 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. 2140 # Default value is 0. 2141 */ 2142 2143 /** 2144 * lpfc_topology_set: Set the adapters topology field. 2145 * @phba: lpfc_hba pointer. 2146 * @val: topology value. 2147 * 2148 * Description: 2149 * If val is in a valid range then set the adapter's topology field and 2150 * issue a lip; if the lip fails reset the topology to the old value. 2151 * 2152 * If the value is not in range log a kernel error message and return an error. 2153 * 2154 * Returns: 2155 * zero if val is in range and lip okay 2156 * non-zero return value from lpfc_issue_lip() 2157 * -EINVAL val out of range 2158 **/ 2159 static int 2160 lpfc_topology_set(struct lpfc_hba *phba, int val) 2161 { 2162 int err; 2163 uint32_t prev_val; 2164 if (val >= 0 && val <= 6) { 2165 prev_val = phba->cfg_topology; 2166 phba->cfg_topology = val; 2167 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); 2168 if (err) 2169 phba->cfg_topology = prev_val; 2170 return err; 2171 } 2172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2173 "%d:0467 lpfc_topology attribute cannot be set to %d, " 2174 "allowed range is [0, 6]\n", 2175 phba->brd_no, val); 2176 return -EINVAL; 2177 } 2178 static int lpfc_topology = 0; 2179 module_param(lpfc_topology, int, 0); 2180 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology"); 2181 lpfc_param_show(topology) 2182 lpfc_param_init(topology, 0, 0, 6) 2183 lpfc_param_store(topology) 2184 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR, 2185 lpfc_topology_show, lpfc_topology_store); 2186 2187 2188 /** 2189 * lpfc_stat_data_ctrl_store: write call back for lpfc_stat_data_ctrl 2190 * sysfs file. 2191 * @dev: Pointer to class device. 2192 * @buf: Data buffer. 2193 * @count: Size of the data buffer. 2194 * 2195 * This function get called when an user write to the lpfc_stat_data_ctrl 2196 * sysfs file. This function parse the command written to the sysfs file 2197 * and take appropriate action. These commands are used for controlling 2198 * driver statistical data collection. 2199 * Following are the command this function handles. 2200 * 2201 * setbucket <bucket_type> <base> <step> 2202 * = Set the latency buckets. 2203 * destroybucket = destroy all the buckets. 2204 * start = start data collection 2205 * stop = stop data collection 2206 * reset = reset the collected data 2207 **/ 2208 static ssize_t 2209 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr, 2210 const char *buf, size_t count) 2211 { 2212 struct Scsi_Host *shost = class_to_shost(dev); 2213 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2214 struct lpfc_hba *phba = vport->phba; 2215 #define LPFC_MAX_DATA_CTRL_LEN 1024 2216 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN]; 2217 unsigned long i; 2218 char *str_ptr, *token; 2219 struct lpfc_vport **vports; 2220 struct Scsi_Host *v_shost; 2221 char *bucket_type_str, *base_str, *step_str; 2222 unsigned long base, step, bucket_type; 2223 2224 if (!strncmp(buf, "setbucket", strlen("setbucket"))) { 2225 if (strlen(buf) > LPFC_MAX_DATA_CTRL_LEN) 2226 return -EINVAL; 2227 2228 strcpy(bucket_data, buf); 2229 str_ptr = &bucket_data[0]; 2230 /* Ignore this token - this is command token */ 2231 token = strsep(&str_ptr, "\t "); 2232 if (!token) 2233 return -EINVAL; 2234 2235 bucket_type_str = strsep(&str_ptr, "\t "); 2236 if (!bucket_type_str) 2237 return -EINVAL; 2238 2239 if (!strncmp(bucket_type_str, "linear", strlen("linear"))) 2240 bucket_type = LPFC_LINEAR_BUCKET; 2241 else if (!strncmp(bucket_type_str, "power2", strlen("power2"))) 2242 bucket_type = LPFC_POWER2_BUCKET; 2243 else 2244 return -EINVAL; 2245 2246 base_str = strsep(&str_ptr, "\t "); 2247 if (!base_str) 2248 return -EINVAL; 2249 base = simple_strtoul(base_str, NULL, 0); 2250 2251 step_str = strsep(&str_ptr, "\t "); 2252 if (!step_str) 2253 return -EINVAL; 2254 step = simple_strtoul(step_str, NULL, 0); 2255 if (!step) 2256 return -EINVAL; 2257 2258 /* Block the data collection for every vport */ 2259 vports = lpfc_create_vport_work_array(phba); 2260 if (vports == NULL) 2261 return -ENOMEM; 2262 2263 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { 2264 v_shost = lpfc_shost_from_vport(vports[i]); 2265 spin_lock_irq(v_shost->host_lock); 2266 /* Block and reset data collection */ 2267 vports[i]->stat_data_blocked = 1; 2268 if (vports[i]->stat_data_enabled) 2269 lpfc_vport_reset_stat_data(vports[i]); 2270 spin_unlock_irq(v_shost->host_lock); 2271 } 2272 2273 /* Set the bucket attributes */ 2274 phba->bucket_type = bucket_type; 2275 phba->bucket_base = base; 2276 phba->bucket_step = step; 2277 2278 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { 2279 v_shost = lpfc_shost_from_vport(vports[i]); 2280 2281 /* Unblock data collection */ 2282 spin_lock_irq(v_shost->host_lock); 2283 vports[i]->stat_data_blocked = 0; 2284 spin_unlock_irq(v_shost->host_lock); 2285 } 2286 lpfc_destroy_vport_work_array(phba, vports); 2287 return strlen(buf); 2288 } 2289 2290 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) { 2291 vports = lpfc_create_vport_work_array(phba); 2292 if (vports == NULL) 2293 return -ENOMEM; 2294 2295 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { 2296 v_shost = lpfc_shost_from_vport(vports[i]); 2297 spin_lock_irq(shost->host_lock); 2298 vports[i]->stat_data_blocked = 1; 2299 lpfc_free_bucket(vport); 2300 vport->stat_data_enabled = 0; 2301 vports[i]->stat_data_blocked = 0; 2302 spin_unlock_irq(shost->host_lock); 2303 } 2304 lpfc_destroy_vport_work_array(phba, vports); 2305 phba->bucket_type = LPFC_NO_BUCKET; 2306 phba->bucket_base = 0; 2307 phba->bucket_step = 0; 2308 return strlen(buf); 2309 } 2310 2311 if (!strncmp(buf, "start", strlen("start"))) { 2312 /* If no buckets configured return error */ 2313 if (phba->bucket_type == LPFC_NO_BUCKET) 2314 return -EINVAL; 2315 spin_lock_irq(shost->host_lock); 2316 if (vport->stat_data_enabled) { 2317 spin_unlock_irq(shost->host_lock); 2318 return strlen(buf); 2319 } 2320 lpfc_alloc_bucket(vport); 2321 vport->stat_data_enabled = 1; 2322 spin_unlock_irq(shost->host_lock); 2323 return strlen(buf); 2324 } 2325 2326 if (!strncmp(buf, "stop", strlen("stop"))) { 2327 spin_lock_irq(shost->host_lock); 2328 if (vport->stat_data_enabled == 0) { 2329 spin_unlock_irq(shost->host_lock); 2330 return strlen(buf); 2331 } 2332 lpfc_free_bucket(vport); 2333 vport->stat_data_enabled = 0; 2334 spin_unlock_irq(shost->host_lock); 2335 return strlen(buf); 2336 } 2337 2338 if (!strncmp(buf, "reset", strlen("reset"))) { 2339 if ((phba->bucket_type == LPFC_NO_BUCKET) 2340 || !vport->stat_data_enabled) 2341 return strlen(buf); 2342 spin_lock_irq(shost->host_lock); 2343 vport->stat_data_blocked = 1; 2344 lpfc_vport_reset_stat_data(vport); 2345 vport->stat_data_blocked = 0; 2346 spin_unlock_irq(shost->host_lock); 2347 return strlen(buf); 2348 } 2349 return -EINVAL; 2350 } 2351 2352 2353 /** 2354 * lpfc_stat_data_ctrl_show: Read callback function for 2355 * lpfc_stat_data_ctrl sysfs file. 2356 * @dev: Pointer to class device object. 2357 * @buf: Data buffer. 2358 * 2359 * This function is the read call back function for 2360 * lpfc_stat_data_ctrl sysfs file. This function report the 2361 * current statistical data collection state. 2362 **/ 2363 static ssize_t 2364 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr, 2365 char *buf) 2366 { 2367 struct Scsi_Host *shost = class_to_shost(dev); 2368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2369 struct lpfc_hba *phba = vport->phba; 2370 int index = 0; 2371 int i; 2372 char *bucket_type; 2373 unsigned long bucket_value; 2374 2375 switch (phba->bucket_type) { 2376 case LPFC_LINEAR_BUCKET: 2377 bucket_type = "linear"; 2378 break; 2379 case LPFC_POWER2_BUCKET: 2380 bucket_type = "power2"; 2381 break; 2382 default: 2383 bucket_type = "No Bucket"; 2384 break; 2385 } 2386 2387 sprintf(&buf[index], "Statistical Data enabled :%d, " 2388 "blocked :%d, Bucket type :%s, Bucket base :%d," 2389 " Bucket step :%d\nLatency Ranges :", 2390 vport->stat_data_enabled, vport->stat_data_blocked, 2391 bucket_type, phba->bucket_base, phba->bucket_step); 2392 index = strlen(buf); 2393 if (phba->bucket_type != LPFC_NO_BUCKET) { 2394 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { 2395 if (phba->bucket_type == LPFC_LINEAR_BUCKET) 2396 bucket_value = phba->bucket_base + 2397 phba->bucket_step * i; 2398 else 2399 bucket_value = phba->bucket_base + 2400 (1 << i) * phba->bucket_step; 2401 2402 if (index + 10 > PAGE_SIZE) 2403 break; 2404 sprintf(&buf[index], "%08ld ", bucket_value); 2405 index = strlen(buf); 2406 } 2407 } 2408 sprintf(&buf[index], "\n"); 2409 return strlen(buf); 2410 } 2411 2412 /* 2413 * Sysfs attribute to control the statistical data collection. 2414 */ 2415 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR, 2416 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store); 2417 2418 /* 2419 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data. 2420 */ 2421 2422 /* 2423 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN 2424 * for each target. 2425 */ 2426 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18) 2427 #define MAX_STAT_DATA_SIZE_PER_TARGET \ 2428 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT) 2429 2430 2431 /** 2432 * sysfs_drvr_stat_data_read: Read callback function for lpfc_drvr_stat_data 2433 * sysfs attribute. 2434 * @kobj: Pointer to the kernel object 2435 * @bin_attr: Attribute object 2436 * @buff: Buffer pointer 2437 * @off: File offset 2438 * @count: Buffer size 2439 * 2440 * This function is the read call back function for lpfc_drvr_stat_data 2441 * sysfs file. This function export the statistical data to user 2442 * applications. 2443 **/ 2444 static ssize_t 2445 sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr, 2446 char *buf, loff_t off, size_t count) 2447 { 2448 struct device *dev = container_of(kobj, struct device, 2449 kobj); 2450 struct Scsi_Host *shost = class_to_shost(dev); 2451 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2452 struct lpfc_hba *phba = vport->phba; 2453 int i = 0, index = 0; 2454 unsigned long nport_index; 2455 struct lpfc_nodelist *ndlp = NULL; 2456 nport_index = (unsigned long)off / 2457 MAX_STAT_DATA_SIZE_PER_TARGET; 2458 2459 if (!vport->stat_data_enabled || vport->stat_data_blocked 2460 || (phba->bucket_type == LPFC_NO_BUCKET)) 2461 return 0; 2462 2463 spin_lock_irq(shost->host_lock); 2464 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 2465 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data) 2466 continue; 2467 2468 if (nport_index > 0) { 2469 nport_index--; 2470 continue; 2471 } 2472 2473 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET) 2474 > count) 2475 break; 2476 2477 if (!ndlp->lat_data) 2478 continue; 2479 2480 /* Print the WWN */ 2481 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:", 2482 ndlp->nlp_portname.u.wwn[0], 2483 ndlp->nlp_portname.u.wwn[1], 2484 ndlp->nlp_portname.u.wwn[2], 2485 ndlp->nlp_portname.u.wwn[3], 2486 ndlp->nlp_portname.u.wwn[4], 2487 ndlp->nlp_portname.u.wwn[5], 2488 ndlp->nlp_portname.u.wwn[6], 2489 ndlp->nlp_portname.u.wwn[7]); 2490 2491 index = strlen(buf); 2492 2493 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { 2494 sprintf(&buf[index], "%010u,", 2495 ndlp->lat_data[i].cmd_count); 2496 index = strlen(buf); 2497 } 2498 sprintf(&buf[index], "\n"); 2499 index = strlen(buf); 2500 } 2501 spin_unlock_irq(shost->host_lock); 2502 return index; 2503 } 2504 2505 static struct bin_attribute sysfs_drvr_stat_data_attr = { 2506 .attr = { 2507 .name = "lpfc_drvr_stat_data", 2508 .mode = S_IRUSR, 2509 .owner = THIS_MODULE, 2510 }, 2511 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET, 2512 .read = sysfs_drvr_stat_data_read, 2513 .write = NULL, 2514 }; 2515 2516 /* 2517 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel 2518 # connection. 2519 # 0 = auto select (default) 2520 # 1 = 1 Gigabaud 2521 # 2 = 2 Gigabaud 2522 # 4 = 4 Gigabaud 2523 # 8 = 8 Gigabaud 2524 # Value range is [0,8]. Default value is 0. 2525 */ 2526 2527 /** 2528 * lpfc_link_speed_set: Set the adapters link speed. 2529 * @phba: lpfc_hba pointer. 2530 * @val: link speed value. 2531 * 2532 * Description: 2533 * If val is in a valid range then set the adapter's link speed field and 2534 * issue a lip; if the lip fails reset the link speed to the old value. 2535 * 2536 * Notes: 2537 * If the value is not in range log a kernel error message and return an error. 2538 * 2539 * Returns: 2540 * zero if val is in range and lip okay. 2541 * non-zero return value from lpfc_issue_lip() 2542 * -EINVAL val out of range 2543 **/ 2544 static int 2545 lpfc_link_speed_set(struct lpfc_hba *phba, int val) 2546 { 2547 int err; 2548 uint32_t prev_val; 2549 2550 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) || 2551 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) || 2552 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) || 2553 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) || 2554 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb))) 2555 return -EINVAL; 2556 2557 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED) 2558 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) { 2559 prev_val = phba->cfg_link_speed; 2560 phba->cfg_link_speed = val; 2561 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); 2562 if (err) 2563 phba->cfg_link_speed = prev_val; 2564 return err; 2565 } 2566 2567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2568 "%d:0469 lpfc_link_speed attribute cannot be set to %d, " 2569 "allowed range is [0, 8]\n", 2570 phba->brd_no, val); 2571 return -EINVAL; 2572 } 2573 2574 static int lpfc_link_speed = 0; 2575 module_param(lpfc_link_speed, int, 0); 2576 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed"); 2577 lpfc_param_show(link_speed) 2578 2579 /** 2580 * lpfc_link_speed_init: Set the adapters link speed. 2581 * @phba: lpfc_hba pointer. 2582 * @val: link speed value. 2583 * 2584 * Description: 2585 * If val is in a valid range then set the adapter's link speed field. 2586 * 2587 * Notes: 2588 * If the value is not in range log a kernel error message, clear the link 2589 * speed and return an error. 2590 * 2591 * Returns: 2592 * zero if val saved. 2593 * -EINVAL val out of range 2594 **/ 2595 static int 2596 lpfc_link_speed_init(struct lpfc_hba *phba, int val) 2597 { 2598 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED) 2599 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) { 2600 phba->cfg_link_speed = val; 2601 return 0; 2602 } 2603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2604 "0405 lpfc_link_speed attribute cannot " 2605 "be set to %d, allowed values are " 2606 "["LPFC_LINK_SPEED_STRING"]\n", val); 2607 phba->cfg_link_speed = 0; 2608 return -EINVAL; 2609 } 2610 2611 lpfc_param_store(link_speed) 2612 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR, 2613 lpfc_link_speed_show, lpfc_link_speed_store); 2614 2615 /* 2616 # lpfc_fcp_class: Determines FC class to use for the FCP protocol. 2617 # Value range is [2,3]. Default value is 3. 2618 */ 2619 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3, 2620 "Select Fibre Channel class of service for FCP sequences"); 2621 2622 /* 2623 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range 2624 # is [0,1]. Default value is 0. 2625 */ 2626 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1, 2627 "Use ADISC on rediscovery to authenticate FCP devices"); 2628 2629 /* 2630 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue 2631 # depth. Default value is 0. When the value of this parameter is zero the 2632 # SCSI command completion time is not used for controlling I/O queue depth. When 2633 # the parameter is set to a non-zero value, the I/O queue depth is controlled 2634 # to limit the I/O completion time to the parameter value. 2635 # The value is set in milliseconds. 2636 */ 2637 static int lpfc_max_scsicmpl_time; 2638 module_param(lpfc_max_scsicmpl_time, int, 0); 2639 MODULE_PARM_DESC(lpfc_max_scsicmpl_time, 2640 "Use command completion time to control queue depth"); 2641 lpfc_vport_param_show(max_scsicmpl_time); 2642 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000); 2643 static int 2644 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val) 2645 { 2646 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 2647 struct lpfc_nodelist *ndlp, *next_ndlp; 2648 2649 if (val == vport->cfg_max_scsicmpl_time) 2650 return 0; 2651 if ((val < 0) || (val > 60000)) 2652 return -EINVAL; 2653 vport->cfg_max_scsicmpl_time = val; 2654 2655 spin_lock_irq(shost->host_lock); 2656 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { 2657 if (!NLP_CHK_NODE_ACT(ndlp)) 2658 continue; 2659 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) 2660 continue; 2661 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH; 2662 } 2663 spin_unlock_irq(shost->host_lock); 2664 return 0; 2665 } 2666 lpfc_vport_param_store(max_scsicmpl_time); 2667 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR, 2668 lpfc_max_scsicmpl_time_show, 2669 lpfc_max_scsicmpl_time_store); 2670 2671 /* 2672 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value 2673 # range is [0,1]. Default value is 0. 2674 */ 2675 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); 2676 2677 /* 2678 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing 2679 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take 2680 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay 2681 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if 2682 # cr_delay is set to 0. 2683 */ 2684 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an " 2685 "interrupt response is generated"); 2686 2687 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an " 2688 "interrupt response is generated"); 2689 2690 /* 2691 # lpfc_multi_ring_support: Determines how many rings to spread available 2692 # cmd/rsp IOCB entries across. 2693 # Value range is [1,2]. Default value is 1. 2694 */ 2695 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary " 2696 "SLI rings to spread IOCB entries across"); 2697 2698 /* 2699 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this 2700 # identifies what rctl value to configure the additional ring for. 2701 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data). 2702 */ 2703 LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1, 2704 255, "Identifies RCTL for additional ring configuration"); 2705 2706 /* 2707 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this 2708 # identifies what type value to configure the additional ring for. 2709 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP). 2710 */ 2711 LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1, 2712 255, "Identifies TYPE for additional ring configuration"); 2713 2714 /* 2715 # lpfc_fdmi_on: controls FDMI support. 2716 # 0 = no FDMI support 2717 # 1 = support FDMI without attribute of hostname 2718 # 2 = support FDMI with attribute of hostname 2719 # Value range [0,2]. Default value is 0. 2720 */ 2721 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support"); 2722 2723 /* 2724 # Specifies the maximum number of ELS cmds we can have outstanding (for 2725 # discovery). Value range is [1,64]. Default value = 32. 2726 */ 2727 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands " 2728 "during discovery"); 2729 2730 /* 2731 # lpfc_max_luns: maximum allowed LUN. 2732 # Value range is [0,65535]. Default value is 255. 2733 # NOTE: The SCSI layer might probe all allowed LUN on some old targets. 2734 */ 2735 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN"); 2736 2737 /* 2738 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. 2739 # Value range is [1,255], default value is 10. 2740 */ 2741 LPFC_ATTR_RW(poll_tmo, 10, 1, 255, 2742 "Milliseconds driver will wait between polling FCP ring"); 2743 2744 /* 2745 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that 2746 # support this feature 2747 # 0 = MSI disabled 2748 # 1 = MSI enabled 2749 # 2 = MSI-X enabled (default) 2750 # Value range is [0,2]. Default value is 2. 2751 */ 2752 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or " 2753 "MSI-X (2), if possible"); 2754 2755 /* 2756 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware. 2757 # 0 = HBA resets disabled 2758 # 1 = HBA resets enabled (default) 2759 # Value range is [0,1]. Default value is 1. 2760 */ 2761 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver."); 2762 2763 /* 2764 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer.. 2765 # 0 = HBA Heartbeat disabled 2766 # 1 = HBA Heartbeat enabled (default) 2767 # Value range is [0,1]. Default value is 1. 2768 */ 2769 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat."); 2770 2771 /* 2772 * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count 2773 * This value can be set to values between 64 and 256. The default value is 2774 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer 2775 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE). 2776 */ 2777 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT, 2778 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count"); 2779 2780 struct device_attribute *lpfc_hba_attrs[] = { 2781 &dev_attr_info, 2782 &dev_attr_serialnum, 2783 &dev_attr_modeldesc, 2784 &dev_attr_modelname, 2785 &dev_attr_programtype, 2786 &dev_attr_portnum, 2787 &dev_attr_fwrev, 2788 &dev_attr_hdw, 2789 &dev_attr_option_rom_version, 2790 &dev_attr_link_state, 2791 &dev_attr_num_discovered_ports, 2792 &dev_attr_menlo_mgmt_mode, 2793 &dev_attr_lpfc_drvr_version, 2794 &dev_attr_lpfc_temp_sensor, 2795 &dev_attr_lpfc_log_verbose, 2796 &dev_attr_lpfc_lun_queue_depth, 2797 &dev_attr_lpfc_hba_queue_depth, 2798 &dev_attr_lpfc_peer_port_login, 2799 &dev_attr_lpfc_nodev_tmo, 2800 &dev_attr_lpfc_devloss_tmo, 2801 &dev_attr_lpfc_fcp_class, 2802 &dev_attr_lpfc_use_adisc, 2803 &dev_attr_lpfc_ack0, 2804 &dev_attr_lpfc_topology, 2805 &dev_attr_lpfc_scan_down, 2806 &dev_attr_lpfc_link_speed, 2807 &dev_attr_lpfc_cr_delay, 2808 &dev_attr_lpfc_cr_count, 2809 &dev_attr_lpfc_multi_ring_support, 2810 &dev_attr_lpfc_multi_ring_rctl, 2811 &dev_attr_lpfc_multi_ring_type, 2812 &dev_attr_lpfc_fdmi_on, 2813 &dev_attr_lpfc_max_luns, 2814 &dev_attr_lpfc_enable_npiv, 2815 &dev_attr_nport_evt_cnt, 2816 &dev_attr_board_mode, 2817 &dev_attr_max_vpi, 2818 &dev_attr_used_vpi, 2819 &dev_attr_max_rpi, 2820 &dev_attr_used_rpi, 2821 &dev_attr_max_xri, 2822 &dev_attr_used_xri, 2823 &dev_attr_npiv_info, 2824 &dev_attr_issue_reset, 2825 &dev_attr_lpfc_poll, 2826 &dev_attr_lpfc_poll_tmo, 2827 &dev_attr_lpfc_use_msi, 2828 &dev_attr_lpfc_soft_wwnn, 2829 &dev_attr_lpfc_soft_wwpn, 2830 &dev_attr_lpfc_soft_wwn_enable, 2831 &dev_attr_lpfc_enable_hba_reset, 2832 &dev_attr_lpfc_enable_hba_heartbeat, 2833 &dev_attr_lpfc_sg_seg_cnt, 2834 &dev_attr_lpfc_max_scsicmpl_time, 2835 &dev_attr_lpfc_stat_data_ctrl, 2836 NULL, 2837 }; 2838 2839 struct device_attribute *lpfc_vport_attrs[] = { 2840 &dev_attr_info, 2841 &dev_attr_link_state, 2842 &dev_attr_num_discovered_ports, 2843 &dev_attr_lpfc_drvr_version, 2844 &dev_attr_lpfc_log_verbose, 2845 &dev_attr_lpfc_lun_queue_depth, 2846 &dev_attr_lpfc_nodev_tmo, 2847 &dev_attr_lpfc_devloss_tmo, 2848 &dev_attr_lpfc_hba_queue_depth, 2849 &dev_attr_lpfc_peer_port_login, 2850 &dev_attr_lpfc_restrict_login, 2851 &dev_attr_lpfc_fcp_class, 2852 &dev_attr_lpfc_use_adisc, 2853 &dev_attr_lpfc_fdmi_on, 2854 &dev_attr_lpfc_max_luns, 2855 &dev_attr_nport_evt_cnt, 2856 &dev_attr_npiv_info, 2857 &dev_attr_lpfc_enable_da_id, 2858 &dev_attr_lpfc_max_scsicmpl_time, 2859 &dev_attr_lpfc_stat_data_ctrl, 2860 NULL, 2861 }; 2862 2863 /** 2864 * sysfs_ctlreg_write: Write method for writing to ctlreg. 2865 * @kobj: kernel kobject that contains the kernel class device. 2866 * @bin_attr: kernel attributes passed to us. 2867 * @buf: contains the data to be written to the adapter IOREG space. 2868 * @off: offset into buffer to beginning of data. 2869 * @count: bytes to transfer. 2870 * 2871 * Description: 2872 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. 2873 * Uses the adapter io control registers to send buf contents to the adapter. 2874 * 2875 * Returns: 2876 * -ERANGE off and count combo out of range 2877 * -EINVAL off, count or buff address invalid 2878 * -EPERM adapter is offline 2879 * value of count, buf contents written 2880 **/ 2881 static ssize_t 2882 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr, 2883 char *buf, loff_t off, size_t count) 2884 { 2885 size_t buf_off; 2886 struct device *dev = container_of(kobj, struct device, kobj); 2887 struct Scsi_Host *shost = class_to_shost(dev); 2888 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2889 struct lpfc_hba *phba = vport->phba; 2890 2891 if ((off + count) > FF_REG_AREA_SIZE) 2892 return -ERANGE; 2893 2894 if (count == 0) return 0; 2895 2896 if (off % 4 || count % 4 || (unsigned long)buf % 4) 2897 return -EINVAL; 2898 2899 if (!(vport->fc_flag & FC_OFFLINE_MODE)) { 2900 return -EPERM; 2901 } 2902 2903 spin_lock_irq(&phba->hbalock); 2904 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) 2905 writel(*((uint32_t *)(buf + buf_off)), 2906 phba->ctrl_regs_memmap_p + off + buf_off); 2907 2908 spin_unlock_irq(&phba->hbalock); 2909 2910 return count; 2911 } 2912 2913 /** 2914 * sysfs_ctlreg_read: Read method for reading from ctlreg. 2915 * @kobj: kernel kobject that contains the kernel class device. 2916 * @bin_attr: kernel attributes passed to us. 2917 * @buf: if succesful contains the data from the adapter IOREG space. 2918 * @off: offset into buffer to beginning of data. 2919 * @count: bytes to transfer. 2920 * 2921 * Description: 2922 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. 2923 * Uses the adapter io control registers to read data into buf. 2924 * 2925 * Returns: 2926 * -ERANGE off and count combo out of range 2927 * -EINVAL off, count or buff address invalid 2928 * value of count, buf contents read 2929 **/ 2930 static ssize_t 2931 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr, 2932 char *buf, loff_t off, size_t count) 2933 { 2934 size_t buf_off; 2935 uint32_t * tmp_ptr; 2936 struct device *dev = container_of(kobj, struct device, kobj); 2937 struct Scsi_Host *shost = class_to_shost(dev); 2938 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2939 struct lpfc_hba *phba = vport->phba; 2940 2941 if (off > FF_REG_AREA_SIZE) 2942 return -ERANGE; 2943 2944 if ((off + count) > FF_REG_AREA_SIZE) 2945 count = FF_REG_AREA_SIZE - off; 2946 2947 if (count == 0) return 0; 2948 2949 if (off % 4 || count % 4 || (unsigned long)buf % 4) 2950 return -EINVAL; 2951 2952 spin_lock_irq(&phba->hbalock); 2953 2954 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { 2955 tmp_ptr = (uint32_t *)(buf + buf_off); 2956 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); 2957 } 2958 2959 spin_unlock_irq(&phba->hbalock); 2960 2961 return count; 2962 } 2963 2964 static struct bin_attribute sysfs_ctlreg_attr = { 2965 .attr = { 2966 .name = "ctlreg", 2967 .mode = S_IRUSR | S_IWUSR, 2968 }, 2969 .size = 256, 2970 .read = sysfs_ctlreg_read, 2971 .write = sysfs_ctlreg_write, 2972 }; 2973 2974 /** 2975 * sysfs_mbox_idle: frees the sysfs mailbox. 2976 * @phba: lpfc_hba pointer 2977 **/ 2978 static void 2979 sysfs_mbox_idle(struct lpfc_hba *phba) 2980 { 2981 phba->sysfs_mbox.state = SMBOX_IDLE; 2982 phba->sysfs_mbox.offset = 0; 2983 2984 if (phba->sysfs_mbox.mbox) { 2985 mempool_free(phba->sysfs_mbox.mbox, 2986 phba->mbox_mem_pool); 2987 phba->sysfs_mbox.mbox = NULL; 2988 } 2989 } 2990 2991 /** 2992 * sysfs_mbox_write: Write method for writing information via mbox. 2993 * @kobj: kernel kobject that contains the kernel class device. 2994 * @bin_attr: kernel attributes passed to us. 2995 * @buf: contains the data to be written to sysfs mbox. 2996 * @off: offset into buffer to beginning of data. 2997 * @count: bytes to transfer. 2998 * 2999 * Description: 3000 * Accessed via /sys/class/scsi_host/hostxxx/mbox. 3001 * Uses the sysfs mbox to send buf contents to the adapter. 3002 * 3003 * Returns: 3004 * -ERANGE off and count combo out of range 3005 * -EINVAL off, count or buff address invalid 3006 * zero if count is zero 3007 * -EPERM adapter is offline 3008 * -ENOMEM failed to allocate memory for the mail box 3009 * -EAGAIN offset, state or mbox is NULL 3010 * count number of bytes transferred 3011 **/ 3012 static ssize_t 3013 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr, 3014 char *buf, loff_t off, size_t count) 3015 { 3016 struct device *dev = container_of(kobj, struct device, kobj); 3017 struct Scsi_Host *shost = class_to_shost(dev); 3018 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3019 struct lpfc_hba *phba = vport->phba; 3020 struct lpfcMboxq *mbox = NULL; 3021 3022 if ((count + off) > MAILBOX_CMD_SIZE) 3023 return -ERANGE; 3024 3025 if (off % 4 || count % 4 || (unsigned long)buf % 4) 3026 return -EINVAL; 3027 3028 if (count == 0) 3029 return 0; 3030 3031 if (off == 0) { 3032 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 3033 if (!mbox) 3034 return -ENOMEM; 3035 memset(mbox, 0, sizeof (LPFC_MBOXQ_t)); 3036 } 3037 3038 spin_lock_irq(&phba->hbalock); 3039 3040 if (off == 0) { 3041 if (phba->sysfs_mbox.mbox) 3042 mempool_free(mbox, phba->mbox_mem_pool); 3043 else 3044 phba->sysfs_mbox.mbox = mbox; 3045 phba->sysfs_mbox.state = SMBOX_WRITING; 3046 } else { 3047 if (phba->sysfs_mbox.state != SMBOX_WRITING || 3048 phba->sysfs_mbox.offset != off || 3049 phba->sysfs_mbox.mbox == NULL) { 3050 sysfs_mbox_idle(phba); 3051 spin_unlock_irq(&phba->hbalock); 3052 return -EAGAIN; 3053 } 3054 } 3055 3056 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off, 3057 buf, count); 3058 3059 phba->sysfs_mbox.offset = off + count; 3060 3061 spin_unlock_irq(&phba->hbalock); 3062 3063 return count; 3064 } 3065 3066 /** 3067 * sysfs_mbox_read: Read method for reading information via mbox. 3068 * @kobj: kernel kobject that contains the kernel class device. 3069 * @bin_attr: kernel attributes passed to us. 3070 * @buf: contains the data to be read from sysfs mbox. 3071 * @off: offset into buffer to beginning of data. 3072 * @count: bytes to transfer. 3073 * 3074 * Description: 3075 * Accessed via /sys/class/scsi_host/hostxxx/mbox. 3076 * Uses the sysfs mbox to receive data from to the adapter. 3077 * 3078 * Returns: 3079 * -ERANGE off greater than mailbox command size 3080 * -EINVAL off, count or buff address invalid 3081 * zero if off and count are zero 3082 * -EACCES adapter over temp 3083 * -EPERM garbage can value to catch a multitude of errors 3084 * -EAGAIN management IO not permitted, state or off error 3085 * -ETIME mailbox timeout 3086 * -ENODEV mailbox error 3087 * count number of bytes transferred 3088 **/ 3089 static ssize_t 3090 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr, 3091 char *buf, loff_t off, size_t count) 3092 { 3093 struct device *dev = container_of(kobj, struct device, kobj); 3094 struct Scsi_Host *shost = class_to_shost(dev); 3095 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3096 struct lpfc_hba *phba = vport->phba; 3097 int rc; 3098 3099 if (off > MAILBOX_CMD_SIZE) 3100 return -ERANGE; 3101 3102 if ((count + off) > MAILBOX_CMD_SIZE) 3103 count = MAILBOX_CMD_SIZE - off; 3104 3105 if (off % 4 || count % 4 || (unsigned long)buf % 4) 3106 return -EINVAL; 3107 3108 if (off && count == 0) 3109 return 0; 3110 3111 spin_lock_irq(&phba->hbalock); 3112 3113 if (phba->over_temp_state == HBA_OVER_TEMP) { 3114 sysfs_mbox_idle(phba); 3115 spin_unlock_irq(&phba->hbalock); 3116 return -EACCES; 3117 } 3118 3119 if (off == 0 && 3120 phba->sysfs_mbox.state == SMBOX_WRITING && 3121 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) { 3122 3123 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) { 3124 /* Offline only */ 3125 case MBX_INIT_LINK: 3126 case MBX_DOWN_LINK: 3127 case MBX_CONFIG_LINK: 3128 case MBX_CONFIG_RING: 3129 case MBX_RESET_RING: 3130 case MBX_UNREG_LOGIN: 3131 case MBX_CLEAR_LA: 3132 case MBX_DUMP_CONTEXT: 3133 case MBX_RUN_DIAGS: 3134 case MBX_RESTART: 3135 case MBX_SET_MASK: 3136 case MBX_SET_DEBUG: 3137 if (!(vport->fc_flag & FC_OFFLINE_MODE)) { 3138 printk(KERN_WARNING "mbox_read:Command 0x%x " 3139 "is illegal in on-line state\n", 3140 phba->sysfs_mbox.mbox->mb.mbxCommand); 3141 sysfs_mbox_idle(phba); 3142 spin_unlock_irq(&phba->hbalock); 3143 return -EPERM; 3144 } 3145 case MBX_WRITE_NV: 3146 case MBX_WRITE_VPARMS: 3147 case MBX_LOAD_SM: 3148 case MBX_READ_NV: 3149 case MBX_READ_CONFIG: 3150 case MBX_READ_RCONFIG: 3151 case MBX_READ_STATUS: 3152 case MBX_READ_XRI: 3153 case MBX_READ_REV: 3154 case MBX_READ_LNK_STAT: 3155 case MBX_DUMP_MEMORY: 3156 case MBX_DOWN_LOAD: 3157 case MBX_UPDATE_CFG: 3158 case MBX_KILL_BOARD: 3159 case MBX_LOAD_AREA: 3160 case MBX_LOAD_EXP_ROM: 3161 case MBX_BEACON: 3162 case MBX_DEL_LD_ENTRY: 3163 case MBX_SET_VARIABLE: 3164 case MBX_WRITE_WWN: 3165 case MBX_PORT_CAPABILITIES: 3166 case MBX_PORT_IOV_CONTROL: 3167 break; 3168 case MBX_READ_SPARM64: 3169 case MBX_READ_LA: 3170 case MBX_READ_LA64: 3171 case MBX_REG_LOGIN: 3172 case MBX_REG_LOGIN64: 3173 case MBX_CONFIG_PORT: 3174 case MBX_RUN_BIU_DIAG: 3175 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", 3176 phba->sysfs_mbox.mbox->mb.mbxCommand); 3177 sysfs_mbox_idle(phba); 3178 spin_unlock_irq(&phba->hbalock); 3179 return -EPERM; 3180 default: 3181 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", 3182 phba->sysfs_mbox.mbox->mb.mbxCommand); 3183 sysfs_mbox_idle(phba); 3184 spin_unlock_irq(&phba->hbalock); 3185 return -EPERM; 3186 } 3187 3188 /* If HBA encountered an error attention, allow only DUMP 3189 * or RESTART mailbox commands until the HBA is restarted. 3190 */ 3191 if (phba->pport->stopped && 3192 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_DUMP_MEMORY && 3193 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_RESTART && 3194 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_VPARMS && 3195 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_WWN) 3196 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 3197 "1259 mbox: Issued mailbox cmd " 3198 "0x%x while in stopped state.\n", 3199 phba->sysfs_mbox.mbox->mb.mbxCommand); 3200 3201 phba->sysfs_mbox.mbox->vport = vport; 3202 3203 /* Don't allow mailbox commands to be sent when blocked 3204 * or when in the middle of discovery 3205 */ 3206 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) { 3207 sysfs_mbox_idle(phba); 3208 spin_unlock_irq(&phba->hbalock); 3209 return -EAGAIN; 3210 } 3211 3212 if ((vport->fc_flag & FC_OFFLINE_MODE) || 3213 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){ 3214 3215 spin_unlock_irq(&phba->hbalock); 3216 rc = lpfc_sli_issue_mbox (phba, 3217 phba->sysfs_mbox.mbox, 3218 MBX_POLL); 3219 spin_lock_irq(&phba->hbalock); 3220 3221 } else { 3222 spin_unlock_irq(&phba->hbalock); 3223 rc = lpfc_sli_issue_mbox_wait (phba, 3224 phba->sysfs_mbox.mbox, 3225 lpfc_mbox_tmo_val(phba, 3226 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ); 3227 spin_lock_irq(&phba->hbalock); 3228 } 3229 3230 if (rc != MBX_SUCCESS) { 3231 if (rc == MBX_TIMEOUT) { 3232 phba->sysfs_mbox.mbox = NULL; 3233 } 3234 sysfs_mbox_idle(phba); 3235 spin_unlock_irq(&phba->hbalock); 3236 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; 3237 } 3238 phba->sysfs_mbox.state = SMBOX_READING; 3239 } 3240 else if (phba->sysfs_mbox.offset != off || 3241 phba->sysfs_mbox.state != SMBOX_READING) { 3242 printk(KERN_WARNING "mbox_read: Bad State\n"); 3243 sysfs_mbox_idle(phba); 3244 spin_unlock_irq(&phba->hbalock); 3245 return -EAGAIN; 3246 } 3247 3248 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count); 3249 3250 phba->sysfs_mbox.offset = off + count; 3251 3252 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE) 3253 sysfs_mbox_idle(phba); 3254 3255 spin_unlock_irq(&phba->hbalock); 3256 3257 return count; 3258 } 3259 3260 static struct bin_attribute sysfs_mbox_attr = { 3261 .attr = { 3262 .name = "mbox", 3263 .mode = S_IRUSR | S_IWUSR, 3264 }, 3265 .size = MAILBOX_CMD_SIZE, 3266 .read = sysfs_mbox_read, 3267 .write = sysfs_mbox_write, 3268 }; 3269 3270 /** 3271 * lpfc_alloc_sysfs_attr: Creates the ctlreg and mbox entries. 3272 * @vport: address of lpfc vport structure. 3273 * 3274 * Return codes: 3275 * zero on success 3276 * error return code from sysfs_create_bin_file() 3277 **/ 3278 int 3279 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport) 3280 { 3281 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 3282 int error; 3283 3284 error = sysfs_create_bin_file(&shost->shost_dev.kobj, 3285 &sysfs_ctlreg_attr); 3286 if (error) 3287 goto out; 3288 3289 error = sysfs_create_bin_file(&shost->shost_dev.kobj, 3290 &sysfs_mbox_attr); 3291 if (error) 3292 goto out_remove_ctlreg_attr; 3293 3294 error = sysfs_create_bin_file(&shost->shost_dev.kobj, 3295 &sysfs_drvr_stat_data_attr); 3296 if (error) 3297 goto out_remove_mbox_attr; 3298 3299 return 0; 3300 out_remove_mbox_attr: 3301 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr); 3302 out_remove_ctlreg_attr: 3303 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); 3304 out: 3305 return error; 3306 } 3307 3308 /** 3309 * lpfc_free_sysfs_attr: Removes the ctlreg and mbox entries. 3310 * @vport: address of lpfc vport structure. 3311 **/ 3312 void 3313 lpfc_free_sysfs_attr(struct lpfc_vport *vport) 3314 { 3315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 3316 sysfs_remove_bin_file(&shost->shost_dev.kobj, 3317 &sysfs_drvr_stat_data_attr); 3318 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr); 3319 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); 3320 } 3321 3322 3323 /* 3324 * Dynamic FC Host Attributes Support 3325 */ 3326 3327 /** 3328 * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id. 3329 * @shost: kernel scsi host pointer. 3330 **/ 3331 static void 3332 lpfc_get_host_port_id(struct Scsi_Host *shost) 3333 { 3334 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3335 3336 /* note: fc_myDID already in cpu endianness */ 3337 fc_host_port_id(shost) = vport->fc_myDID; 3338 } 3339 3340 /** 3341 * lpfc_get_host_port_type: Set the value of the scsi host port type. 3342 * @shost: kernel scsi host pointer. 3343 **/ 3344 static void 3345 lpfc_get_host_port_type(struct Scsi_Host *shost) 3346 { 3347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3348 struct lpfc_hba *phba = vport->phba; 3349 3350 spin_lock_irq(shost->host_lock); 3351 3352 if (vport->port_type == LPFC_NPIV_PORT) { 3353 fc_host_port_type(shost) = FC_PORTTYPE_NPIV; 3354 } else if (lpfc_is_link_up(phba)) { 3355 if (phba->fc_topology == TOPOLOGY_LOOP) { 3356 if (vport->fc_flag & FC_PUBLIC_LOOP) 3357 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; 3358 else 3359 fc_host_port_type(shost) = FC_PORTTYPE_LPORT; 3360 } else { 3361 if (vport->fc_flag & FC_FABRIC) 3362 fc_host_port_type(shost) = FC_PORTTYPE_NPORT; 3363 else 3364 fc_host_port_type(shost) = FC_PORTTYPE_PTP; 3365 } 3366 } else 3367 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; 3368 3369 spin_unlock_irq(shost->host_lock); 3370 } 3371 3372 /** 3373 * lpfc_get_host_port_state: Set the value of the scsi host port state. 3374 * @shost: kernel scsi host pointer. 3375 **/ 3376 static void 3377 lpfc_get_host_port_state(struct Scsi_Host *shost) 3378 { 3379 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3380 struct lpfc_hba *phba = vport->phba; 3381 3382 spin_lock_irq(shost->host_lock); 3383 3384 if (vport->fc_flag & FC_OFFLINE_MODE) 3385 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; 3386 else { 3387 switch (phba->link_state) { 3388 case LPFC_LINK_UNKNOWN: 3389 case LPFC_LINK_DOWN: 3390 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; 3391 break; 3392 case LPFC_LINK_UP: 3393 case LPFC_CLEAR_LA: 3394 case LPFC_HBA_READY: 3395 /* Links up, beyond this port_type reports state */ 3396 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; 3397 break; 3398 case LPFC_HBA_ERROR: 3399 fc_host_port_state(shost) = FC_PORTSTATE_ERROR; 3400 break; 3401 default: 3402 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; 3403 break; 3404 } 3405 } 3406 3407 spin_unlock_irq(shost->host_lock); 3408 } 3409 3410 /** 3411 * lpfc_get_host_speed: Set the value of the scsi host speed. 3412 * @shost: kernel scsi host pointer. 3413 **/ 3414 static void 3415 lpfc_get_host_speed(struct Scsi_Host *shost) 3416 { 3417 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3418 struct lpfc_hba *phba = vport->phba; 3419 3420 spin_lock_irq(shost->host_lock); 3421 3422 if (lpfc_is_link_up(phba)) { 3423 switch(phba->fc_linkspeed) { 3424 case LA_1GHZ_LINK: 3425 fc_host_speed(shost) = FC_PORTSPEED_1GBIT; 3426 break; 3427 case LA_2GHZ_LINK: 3428 fc_host_speed(shost) = FC_PORTSPEED_2GBIT; 3429 break; 3430 case LA_4GHZ_LINK: 3431 fc_host_speed(shost) = FC_PORTSPEED_4GBIT; 3432 break; 3433 case LA_8GHZ_LINK: 3434 fc_host_speed(shost) = FC_PORTSPEED_8GBIT; 3435 break; 3436 default: 3437 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; 3438 break; 3439 } 3440 } else 3441 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; 3442 3443 spin_unlock_irq(shost->host_lock); 3444 } 3445 3446 /** 3447 * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name. 3448 * @shost: kernel scsi host pointer. 3449 **/ 3450 static void 3451 lpfc_get_host_fabric_name (struct Scsi_Host *shost) 3452 { 3453 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3454 struct lpfc_hba *phba = vport->phba; 3455 u64 node_name; 3456 3457 spin_lock_irq(shost->host_lock); 3458 3459 if ((vport->fc_flag & FC_FABRIC) || 3460 ((phba->fc_topology == TOPOLOGY_LOOP) && 3461 (vport->fc_flag & FC_PUBLIC_LOOP))) 3462 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); 3463 else 3464 /* fabric is local port if there is no F/FL_Port */ 3465 node_name = 0; 3466 3467 spin_unlock_irq(shost->host_lock); 3468 3469 fc_host_fabric_name(shost) = node_name; 3470 } 3471 3472 /** 3473 * lpfc_get_stats: Return statistical information about the adapter. 3474 * @shost: kernel scsi host pointer. 3475 * 3476 * Notes: 3477 * NULL on error for link down, no mbox pool, sli2 active, 3478 * management not allowed, memory allocation error, or mbox error. 3479 * 3480 * Returns: 3481 * NULL for error 3482 * address of the adapter host statistics 3483 **/ 3484 static struct fc_host_statistics * 3485 lpfc_get_stats(struct Scsi_Host *shost) 3486 { 3487 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3488 struct lpfc_hba *phba = vport->phba; 3489 struct lpfc_sli *psli = &phba->sli; 3490 struct fc_host_statistics *hs = &phba->link_stats; 3491 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; 3492 LPFC_MBOXQ_t *pmboxq; 3493 MAILBOX_t *pmb; 3494 unsigned long seconds; 3495 int rc = 0; 3496 3497 /* 3498 * prevent udev from issuing mailbox commands until the port is 3499 * configured. 3500 */ 3501 if (phba->link_state < LPFC_LINK_DOWN || 3502 !phba->mbox_mem_pool || 3503 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0) 3504 return NULL; 3505 3506 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) 3507 return NULL; 3508 3509 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 3510 if (!pmboxq) 3511 return NULL; 3512 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 3513 3514 pmb = &pmboxq->mb; 3515 pmb->mbxCommand = MBX_READ_STATUS; 3516 pmb->mbxOwner = OWN_HOST; 3517 pmboxq->context1 = NULL; 3518 pmboxq->vport = vport; 3519 3520 if ((vport->fc_flag & FC_OFFLINE_MODE) || 3521 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 3522 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 3523 else 3524 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 3525 3526 if (rc != MBX_SUCCESS) { 3527 if (rc != MBX_TIMEOUT) 3528 mempool_free(pmboxq, phba->mbox_mem_pool); 3529 return NULL; 3530 } 3531 3532 memset(hs, 0, sizeof (struct fc_host_statistics)); 3533 3534 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; 3535 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256); 3536 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; 3537 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256); 3538 3539 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 3540 pmb->mbxCommand = MBX_READ_LNK_STAT; 3541 pmb->mbxOwner = OWN_HOST; 3542 pmboxq->context1 = NULL; 3543 pmboxq->vport = vport; 3544 3545 if ((vport->fc_flag & FC_OFFLINE_MODE) || 3546 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 3547 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 3548 else 3549 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 3550 3551 if (rc != MBX_SUCCESS) { 3552 if (rc != MBX_TIMEOUT) 3553 mempool_free(pmboxq, phba->mbox_mem_pool); 3554 return NULL; 3555 } 3556 3557 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; 3558 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; 3559 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; 3560 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; 3561 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; 3562 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; 3563 hs->error_frames = pmb->un.varRdLnk.crcCnt; 3564 3565 hs->link_failure_count -= lso->link_failure_count; 3566 hs->loss_of_sync_count -= lso->loss_of_sync_count; 3567 hs->loss_of_signal_count -= lso->loss_of_signal_count; 3568 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count; 3569 hs->invalid_tx_word_count -= lso->invalid_tx_word_count; 3570 hs->invalid_crc_count -= lso->invalid_crc_count; 3571 hs->error_frames -= lso->error_frames; 3572 3573 if (phba->fc_topology == TOPOLOGY_LOOP) { 3574 hs->lip_count = (phba->fc_eventTag >> 1); 3575 hs->lip_count -= lso->link_events; 3576 hs->nos_count = -1; 3577 } else { 3578 hs->lip_count = -1; 3579 hs->nos_count = (phba->fc_eventTag >> 1); 3580 hs->nos_count -= lso->link_events; 3581 } 3582 3583 hs->dumped_frames = -1; 3584 3585 seconds = get_seconds(); 3586 if (seconds < psli->stats_start) 3587 hs->seconds_since_last_reset = seconds + 3588 ((unsigned long)-1 - psli->stats_start); 3589 else 3590 hs->seconds_since_last_reset = seconds - psli->stats_start; 3591 3592 mempool_free(pmboxq, phba->mbox_mem_pool); 3593 3594 return hs; 3595 } 3596 3597 /** 3598 * lpfc_reset_stats: Copy the adapter link stats information. 3599 * @shost: kernel scsi host pointer. 3600 **/ 3601 static void 3602 lpfc_reset_stats(struct Scsi_Host *shost) 3603 { 3604 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3605 struct lpfc_hba *phba = vport->phba; 3606 struct lpfc_sli *psli = &phba->sli; 3607 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets; 3608 LPFC_MBOXQ_t *pmboxq; 3609 MAILBOX_t *pmb; 3610 int rc = 0; 3611 3612 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) 3613 return; 3614 3615 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 3616 if (!pmboxq) 3617 return; 3618 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); 3619 3620 pmb = &pmboxq->mb; 3621 pmb->mbxCommand = MBX_READ_STATUS; 3622 pmb->mbxOwner = OWN_HOST; 3623 pmb->un.varWords[0] = 0x1; /* reset request */ 3624 pmboxq->context1 = NULL; 3625 pmboxq->vport = vport; 3626 3627 if ((vport->fc_flag & FC_OFFLINE_MODE) || 3628 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 3629 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 3630 else 3631 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 3632 3633 if (rc != MBX_SUCCESS) { 3634 if (rc != MBX_TIMEOUT) 3635 mempool_free(pmboxq, phba->mbox_mem_pool); 3636 return; 3637 } 3638 3639 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); 3640 pmb->mbxCommand = MBX_READ_LNK_STAT; 3641 pmb->mbxOwner = OWN_HOST; 3642 pmboxq->context1 = NULL; 3643 pmboxq->vport = vport; 3644 3645 if ((vport->fc_flag & FC_OFFLINE_MODE) || 3646 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 3647 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 3648 else 3649 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 3650 3651 if (rc != MBX_SUCCESS) { 3652 if (rc != MBX_TIMEOUT) 3653 mempool_free( pmboxq, phba->mbox_mem_pool); 3654 return; 3655 } 3656 3657 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; 3658 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; 3659 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; 3660 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; 3661 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; 3662 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt; 3663 lso->error_frames = pmb->un.varRdLnk.crcCnt; 3664 lso->link_events = (phba->fc_eventTag >> 1); 3665 3666 psli->stats_start = get_seconds(); 3667 3668 mempool_free(pmboxq, phba->mbox_mem_pool); 3669 3670 return; 3671 } 3672 3673 /* 3674 * The LPFC driver treats linkdown handling as target loss events so there 3675 * are no sysfs handlers for link_down_tmo. 3676 */ 3677 3678 /** 3679 * lpfc_get_node_by_target: Return the nodelist for a target. 3680 * @starget: kernel scsi target pointer. 3681 * 3682 * Returns: 3683 * address of the node list if found 3684 * NULL target not found 3685 **/ 3686 static struct lpfc_nodelist * 3687 lpfc_get_node_by_target(struct scsi_target *starget) 3688 { 3689 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 3690 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3691 struct lpfc_nodelist *ndlp; 3692 3693 spin_lock_irq(shost->host_lock); 3694 /* Search for this, mapped, target ID */ 3695 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 3696 if (NLP_CHK_NODE_ACT(ndlp) && 3697 ndlp->nlp_state == NLP_STE_MAPPED_NODE && 3698 starget->id == ndlp->nlp_sid) { 3699 spin_unlock_irq(shost->host_lock); 3700 return ndlp; 3701 } 3702 } 3703 spin_unlock_irq(shost->host_lock); 3704 return NULL; 3705 } 3706 3707 /** 3708 * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1. 3709 * @starget: kernel scsi target pointer. 3710 **/ 3711 static void 3712 lpfc_get_starget_port_id(struct scsi_target *starget) 3713 { 3714 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); 3715 3716 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1; 3717 } 3718 3719 /** 3720 * lpfc_get_starget_node_name: Set the target node name. 3721 * @starget: kernel scsi target pointer. 3722 * 3723 * Description: Set the target node name to the ndlp node name wwn or zero. 3724 **/ 3725 static void 3726 lpfc_get_starget_node_name(struct scsi_target *starget) 3727 { 3728 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); 3729 3730 fc_starget_node_name(starget) = 3731 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0; 3732 } 3733 3734 /** 3735 * lpfc_get_starget_port_name: Set the target port name. 3736 * @starget: kernel scsi target pointer. 3737 * 3738 * Description: set the target port name to the ndlp port name wwn or zero. 3739 **/ 3740 static void 3741 lpfc_get_starget_port_name(struct scsi_target *starget) 3742 { 3743 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); 3744 3745 fc_starget_port_name(starget) = 3746 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0; 3747 } 3748 3749 /** 3750 * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo. 3751 * @rport: fc rport address. 3752 * @timeout: new value for dev loss tmo. 3753 * 3754 * Description: 3755 * If timeout is non zero set the dev_loss_tmo to timeout, else set 3756 * dev_loss_tmo to one. 3757 **/ 3758 static void 3759 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) 3760 { 3761 if (timeout) 3762 rport->dev_loss_tmo = timeout; 3763 else 3764 rport->dev_loss_tmo = 1; 3765 } 3766 3767 /** 3768 * lpfc_rport_show_function: Return rport target information. 3769 * 3770 * Description: 3771 * Macro that uses field to generate a function with the name lpfc_show_rport_ 3772 * 3773 * lpfc_show_rport_##field: returns the bytes formatted in buf 3774 * @cdev: class converted to an fc_rport. 3775 * @buf: on return contains the target_field or zero. 3776 * 3777 * Returns: size of formatted string. 3778 **/ 3779 #define lpfc_rport_show_function(field, format_string, sz, cast) \ 3780 static ssize_t \ 3781 lpfc_show_rport_##field (struct device *dev, \ 3782 struct device_attribute *attr, \ 3783 char *buf) \ 3784 { \ 3785 struct fc_rport *rport = transport_class_to_rport(dev); \ 3786 struct lpfc_rport_data *rdata = rport->hostdata; \ 3787 return snprintf(buf, sz, format_string, \ 3788 (rdata->target) ? cast rdata->target->field : 0); \ 3789 } 3790 3791 #define lpfc_rport_rd_attr(field, format_string, sz) \ 3792 lpfc_rport_show_function(field, format_string, sz, ) \ 3793 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) 3794 3795 3796 struct fc_function_template lpfc_transport_functions = { 3797 /* fixed attributes the driver supports */ 3798 .show_host_node_name = 1, 3799 .show_host_port_name = 1, 3800 .show_host_supported_classes = 1, 3801 .show_host_supported_fc4s = 1, 3802 .show_host_supported_speeds = 1, 3803 .show_host_maxframe_size = 1, 3804 3805 /* dynamic attributes the driver supports */ 3806 .get_host_port_id = lpfc_get_host_port_id, 3807 .show_host_port_id = 1, 3808 3809 .get_host_port_type = lpfc_get_host_port_type, 3810 .show_host_port_type = 1, 3811 3812 .get_host_port_state = lpfc_get_host_port_state, 3813 .show_host_port_state = 1, 3814 3815 /* active_fc4s is shown but doesn't change (thus no get function) */ 3816 .show_host_active_fc4s = 1, 3817 3818 .get_host_speed = lpfc_get_host_speed, 3819 .show_host_speed = 1, 3820 3821 .get_host_fabric_name = lpfc_get_host_fabric_name, 3822 .show_host_fabric_name = 1, 3823 3824 /* 3825 * The LPFC driver treats linkdown handling as target loss events 3826 * so there are no sysfs handlers for link_down_tmo. 3827 */ 3828 3829 .get_fc_host_stats = lpfc_get_stats, 3830 .reset_fc_host_stats = lpfc_reset_stats, 3831 3832 .dd_fcrport_size = sizeof(struct lpfc_rport_data), 3833 .show_rport_maxframe_size = 1, 3834 .show_rport_supported_classes = 1, 3835 3836 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, 3837 .show_rport_dev_loss_tmo = 1, 3838 3839 .get_starget_port_id = lpfc_get_starget_port_id, 3840 .show_starget_port_id = 1, 3841 3842 .get_starget_node_name = lpfc_get_starget_node_name, 3843 .show_starget_node_name = 1, 3844 3845 .get_starget_port_name = lpfc_get_starget_port_name, 3846 .show_starget_port_name = 1, 3847 3848 .issue_fc_host_lip = lpfc_issue_lip, 3849 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, 3850 .terminate_rport_io = lpfc_terminate_rport_io, 3851 3852 .dd_fcvport_size = sizeof(struct lpfc_vport *), 3853 }; 3854 3855 struct fc_function_template lpfc_vport_transport_functions = { 3856 /* fixed attributes the driver supports */ 3857 .show_host_node_name = 1, 3858 .show_host_port_name = 1, 3859 .show_host_supported_classes = 1, 3860 .show_host_supported_fc4s = 1, 3861 .show_host_supported_speeds = 1, 3862 .show_host_maxframe_size = 1, 3863 3864 /* dynamic attributes the driver supports */ 3865 .get_host_port_id = lpfc_get_host_port_id, 3866 .show_host_port_id = 1, 3867 3868 .get_host_port_type = lpfc_get_host_port_type, 3869 .show_host_port_type = 1, 3870 3871 .get_host_port_state = lpfc_get_host_port_state, 3872 .show_host_port_state = 1, 3873 3874 /* active_fc4s is shown but doesn't change (thus no get function) */ 3875 .show_host_active_fc4s = 1, 3876 3877 .get_host_speed = lpfc_get_host_speed, 3878 .show_host_speed = 1, 3879 3880 .get_host_fabric_name = lpfc_get_host_fabric_name, 3881 .show_host_fabric_name = 1, 3882 3883 /* 3884 * The LPFC driver treats linkdown handling as target loss events 3885 * so there are no sysfs handlers for link_down_tmo. 3886 */ 3887 3888 .get_fc_host_stats = lpfc_get_stats, 3889 .reset_fc_host_stats = lpfc_reset_stats, 3890 3891 .dd_fcrport_size = sizeof(struct lpfc_rport_data), 3892 .show_rport_maxframe_size = 1, 3893 .show_rport_supported_classes = 1, 3894 3895 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, 3896 .show_rport_dev_loss_tmo = 1, 3897 3898 .get_starget_port_id = lpfc_get_starget_port_id, 3899 .show_starget_port_id = 1, 3900 3901 .get_starget_node_name = lpfc_get_starget_node_name, 3902 .show_starget_node_name = 1, 3903 3904 .get_starget_port_name = lpfc_get_starget_port_name, 3905 .show_starget_port_name = 1, 3906 3907 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, 3908 .terminate_rport_io = lpfc_terminate_rport_io, 3909 3910 .vport_disable = lpfc_vport_disable, 3911 }; 3912 3913 /** 3914 * lpfc_get_cfgparam: Used during probe_one to init the adapter structure. 3915 * @phba: lpfc_hba pointer. 3916 **/ 3917 void 3918 lpfc_get_cfgparam(struct lpfc_hba *phba) 3919 { 3920 lpfc_cr_delay_init(phba, lpfc_cr_delay); 3921 lpfc_cr_count_init(phba, lpfc_cr_count); 3922 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support); 3923 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl); 3924 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type); 3925 lpfc_ack0_init(phba, lpfc_ack0); 3926 lpfc_topology_init(phba, lpfc_topology); 3927 lpfc_link_speed_init(phba, lpfc_link_speed); 3928 lpfc_poll_tmo_init(phba, lpfc_poll_tmo); 3929 lpfc_enable_npiv_init(phba, lpfc_enable_npiv); 3930 lpfc_use_msi_init(phba, lpfc_use_msi); 3931 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset); 3932 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat); 3933 phba->cfg_poll = lpfc_poll; 3934 phba->cfg_soft_wwnn = 0L; 3935 phba->cfg_soft_wwpn = 0L; 3936 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt); 3937 /* Also reinitialize the host templates with new values. */ 3938 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; 3939 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; 3940 /* 3941 * Since the sg_tablesize is module parameter, the sg_dma_buf_size 3942 * used to create the sg_dma_buf_pool must be dynamically calculated. 3943 * 2 segments are added since the IOCB needs a command and response bde. 3944 */ 3945 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + 3946 sizeof(struct fcp_rsp) + 3947 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); 3948 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); 3949 return; 3950 } 3951 3952 /** 3953 * lpfc_get_vport_cfgparam: Used during port create, init the vport structure. 3954 * @vport: lpfc_vport pointer. 3955 **/ 3956 void 3957 lpfc_get_vport_cfgparam(struct lpfc_vport *vport) 3958 { 3959 lpfc_log_verbose_init(vport, lpfc_log_verbose); 3960 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth); 3961 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo); 3962 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo); 3963 lpfc_peer_port_login_init(vport, lpfc_peer_port_login); 3964 lpfc_restrict_login_init(vport, lpfc_restrict_login); 3965 lpfc_fcp_class_init(vport, lpfc_fcp_class); 3966 lpfc_use_adisc_init(vport, lpfc_use_adisc); 3967 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time); 3968 lpfc_fdmi_on_init(vport, lpfc_fdmi_on); 3969 lpfc_discovery_threads_init(vport, lpfc_discovery_threads); 3970 lpfc_max_luns_init(vport, lpfc_max_luns); 3971 lpfc_scan_down_init(vport, lpfc_scan_down); 3972 lpfc_enable_da_id_init(vport, lpfc_enable_da_id); 3973 return; 3974 } 3975