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