1 /******************************************************************* 2 * This file is part of the Emulex Linux Device Driver for * 3 * Fibre Channel Host Bus Adapters. * 4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * 5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * 6 * Copyright (C) 2004-2016 Emulex. All rights reserved. * 7 * EMULEX and SLI are trademarks of Emulex. * 8 * www.broadcom.com * 9 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 10 * * 11 * This program is free software; you can redistribute it and/or * 12 * modify it under the terms of version 2 of the GNU General * 13 * Public License as published by the Free Software Foundation. * 14 * This program is distributed in the hope that it will be useful. * 15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 19 * TO BE LEGALLY INVALID. See the GNU General Public License for * 20 * more details, a copy of which can be found in the file COPYING * 21 * included with this package. * 22 *******************************************************************/ 23 24 #include <linux/ctype.h> 25 #include <linux/delay.h> 26 #include <linux/pci.h> 27 #include <linux/interrupt.h> 28 #include <linux/module.h> 29 #include <linux/aer.h> 30 #include <linux/gfp.h> 31 #include <linux/kernel.h> 32 33 #include <scsi/scsi.h> 34 #include <scsi/scsi_device.h> 35 #include <scsi/scsi_host.h> 36 #include <scsi/scsi_tcq.h> 37 #include <scsi/scsi_transport_fc.h> 38 #include <scsi/fc/fc_fs.h> 39 40 #include <linux/nvme-fc-driver.h> 41 42 #include "lpfc_hw4.h" 43 #include "lpfc_hw.h" 44 #include "lpfc_sli.h" 45 #include "lpfc_sli4.h" 46 #include "lpfc_nl.h" 47 #include "lpfc_disc.h" 48 #include "lpfc.h" 49 #include "lpfc_scsi.h" 50 #include "lpfc_nvme.h" 51 #include "lpfc_nvmet.h" 52 #include "lpfc_logmsg.h" 53 #include "lpfc_version.h" 54 #include "lpfc_compat.h" 55 #include "lpfc_crtn.h" 56 #include "lpfc_vport.h" 57 #include "lpfc_attr.h" 58 59 #define LPFC_DEF_DEVLOSS_TMO 30 60 #define LPFC_MIN_DEVLOSS_TMO 1 61 #define LPFC_MAX_DEVLOSS_TMO 255 62 63 #define LPFC_DEF_MRQ_POST 512 64 #define LPFC_MIN_MRQ_POST 512 65 #define LPFC_MAX_MRQ_POST 2048 66 67 /* 68 * Write key size should be multiple of 4. If write key is changed 69 * make sure that library write key is also changed. 70 */ 71 #define LPFC_REG_WRITE_KEY_SIZE 4 72 #define LPFC_REG_WRITE_KEY "EMLX" 73 74 /** 75 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules 76 * @incr: integer to convert. 77 * @hdw: ascii string holding converted integer plus a string terminator. 78 * 79 * Description: 80 * JEDEC Joint Electron Device Engineering Council. 81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii 82 * character string. The string is then terminated with a NULL in byte 9. 83 * Hex 0-9 becomes ascii '0' to '9'. 84 * Hex a-f becomes ascii '=' to 'B' capital B. 85 * 86 * Notes: 87 * Coded for 32 bit integers only. 88 **/ 89 static void 90 lpfc_jedec_to_ascii(int incr, char hdw[]) 91 { 92 int i, j; 93 for (i = 0; i < 8; i++) { 94 j = (incr & 0xf); 95 if (j <= 9) 96 hdw[7 - i] = 0x30 + j; 97 else 98 hdw[7 - i] = 0x61 + j - 10; 99 incr = (incr >> 4); 100 } 101 hdw[8] = 0; 102 return; 103 } 104 105 /** 106 * lpfc_drvr_version_show - Return the Emulex driver string with version number 107 * @dev: class unused variable. 108 * @attr: device attribute, not used. 109 * @buf: on return contains the module description text. 110 * 111 * Returns: size of formatted string. 112 **/ 113 static ssize_t 114 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr, 115 char *buf) 116 { 117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); 118 } 119 120 /** 121 * lpfc_enable_fip_show - Return the fip mode of the HBA 122 * @dev: class unused variable. 123 * @attr: device attribute, not used. 124 * @buf: on return contains the module description text. 125 * 126 * Returns: size of formatted string. 127 **/ 128 static ssize_t 129 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr, 130 char *buf) 131 { 132 struct Scsi_Host *shost = class_to_shost(dev); 133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 134 struct lpfc_hba *phba = vport->phba; 135 136 if (phba->hba_flag & HBA_FIP_SUPPORT) 137 return snprintf(buf, PAGE_SIZE, "1\n"); 138 else 139 return snprintf(buf, PAGE_SIZE, "0\n"); 140 } 141 142 static ssize_t 143 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr, 144 char *buf) 145 { 146 struct Scsi_Host *shost = class_to_shost(dev); 147 struct lpfc_vport *vport = shost_priv(shost); 148 struct lpfc_hba *phba = vport->phba; 149 struct lpfc_nvmet_tgtport *tgtp; 150 struct nvme_fc_local_port *localport; 151 struct lpfc_nvme_lport *lport; 152 struct lpfc_nodelist *ndlp; 153 struct nvme_fc_remote_port *nrport; 154 uint64_t data1, data2, data3, tot; 155 char *statep; 156 int len = 0; 157 158 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) { 159 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n"); 160 return len; 161 } 162 if (phba->nvmet_support) { 163 if (!phba->targetport) { 164 len = snprintf(buf, PAGE_SIZE, 165 "NVME Target: x%llx is not allocated\n", 166 wwn_to_u64(vport->fc_portname.u.wwn)); 167 return len; 168 } 169 /* Port state is only one of two values for now. */ 170 if (phba->targetport->port_id) 171 statep = "REGISTERED"; 172 else 173 statep = "INIT"; 174 len += snprintf(buf + len, PAGE_SIZE - len, 175 "NVME Target Enabled State %s\n", 176 statep); 177 len += snprintf(buf + len, PAGE_SIZE - len, 178 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n", 179 "NVME Target: lpfc", 180 phba->brd_no, 181 wwn_to_u64(vport->fc_portname.u.wwn), 182 wwn_to_u64(vport->fc_nodename.u.wwn), 183 phba->targetport->port_id); 184 185 len += snprintf(buf + len, PAGE_SIZE - len, 186 "\nNVME Target: Statistics\n"); 187 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 188 len += snprintf(buf+len, PAGE_SIZE-len, 189 "LS: Rcv %08x Drop %08x Abort %08x\n", 190 atomic_read(&tgtp->rcv_ls_req_in), 191 atomic_read(&tgtp->rcv_ls_req_drop), 192 atomic_read(&tgtp->xmt_ls_abort)); 193 if (atomic_read(&tgtp->rcv_ls_req_in) != 194 atomic_read(&tgtp->rcv_ls_req_out)) { 195 len += snprintf(buf+len, PAGE_SIZE-len, 196 "Rcv LS: in %08x != out %08x\n", 197 atomic_read(&tgtp->rcv_ls_req_in), 198 atomic_read(&tgtp->rcv_ls_req_out)); 199 } 200 201 len += snprintf(buf+len, PAGE_SIZE-len, 202 "LS: Xmt %08x Drop %08x Cmpl %08x\n", 203 atomic_read(&tgtp->xmt_ls_rsp), 204 atomic_read(&tgtp->xmt_ls_drop), 205 atomic_read(&tgtp->xmt_ls_rsp_cmpl)); 206 207 len += snprintf(buf + len, PAGE_SIZE - len, 208 "LS: RSP Abort %08x xb %08x Err %08x\n", 209 atomic_read(&tgtp->xmt_ls_rsp_aborted), 210 atomic_read(&tgtp->xmt_ls_rsp_xb_set), 211 atomic_read(&tgtp->xmt_ls_rsp_error)); 212 213 len += snprintf(buf+len, PAGE_SIZE-len, 214 "FCP: Rcv %08x Defer %08x Release %08x " 215 "Drop %08x\n", 216 atomic_read(&tgtp->rcv_fcp_cmd_in), 217 atomic_read(&tgtp->rcv_fcp_cmd_defer), 218 atomic_read(&tgtp->xmt_fcp_release), 219 atomic_read(&tgtp->rcv_fcp_cmd_drop)); 220 221 if (atomic_read(&tgtp->rcv_fcp_cmd_in) != 222 atomic_read(&tgtp->rcv_fcp_cmd_out)) { 223 len += snprintf(buf+len, PAGE_SIZE-len, 224 "Rcv FCP: in %08x != out %08x\n", 225 atomic_read(&tgtp->rcv_fcp_cmd_in), 226 atomic_read(&tgtp->rcv_fcp_cmd_out)); 227 } 228 229 len += snprintf(buf+len, PAGE_SIZE-len, 230 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x " 231 "drop %08x\n", 232 atomic_read(&tgtp->xmt_fcp_read), 233 atomic_read(&tgtp->xmt_fcp_read_rsp), 234 atomic_read(&tgtp->xmt_fcp_write), 235 atomic_read(&tgtp->xmt_fcp_rsp), 236 atomic_read(&tgtp->xmt_fcp_drop)); 237 238 len += snprintf(buf+len, PAGE_SIZE-len, 239 "FCP Rsp Cmpl: %08x err %08x drop %08x\n", 240 atomic_read(&tgtp->xmt_fcp_rsp_cmpl), 241 atomic_read(&tgtp->xmt_fcp_rsp_error), 242 atomic_read(&tgtp->xmt_fcp_rsp_drop)); 243 244 len += snprintf(buf+len, PAGE_SIZE-len, 245 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n", 246 atomic_read(&tgtp->xmt_fcp_rsp_aborted), 247 atomic_read(&tgtp->xmt_fcp_rsp_xb_set), 248 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe)); 249 250 len += snprintf(buf + len, PAGE_SIZE - len, 251 "ABORT: Xmt %08x Cmpl %08x\n", 252 atomic_read(&tgtp->xmt_fcp_abort), 253 atomic_read(&tgtp->xmt_fcp_abort_cmpl)); 254 255 len += snprintf(buf + len, PAGE_SIZE - len, 256 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x", 257 atomic_read(&tgtp->xmt_abort_sol), 258 atomic_read(&tgtp->xmt_abort_unsol), 259 atomic_read(&tgtp->xmt_abort_rsp), 260 atomic_read(&tgtp->xmt_abort_rsp_error)); 261 262 len += snprintf(buf + len, PAGE_SIZE - len, 263 "DELAY: ctx %08x fod %08x wqfull %08x\n", 264 atomic_read(&tgtp->defer_ctx), 265 atomic_read(&tgtp->defer_fod), 266 atomic_read(&tgtp->defer_wqfull)); 267 268 /* Calculate outstanding IOs */ 269 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop); 270 tot += atomic_read(&tgtp->xmt_fcp_release); 271 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot; 272 273 len += snprintf(buf + len, PAGE_SIZE - len, 274 "IO_CTX: %08x WAIT: cur %08x tot %08x\n" 275 "CTX Outstanding %08llx\n", 276 phba->sli4_hba.nvmet_xri_cnt, 277 phba->sli4_hba.nvmet_io_wait_cnt, 278 phba->sli4_hba.nvmet_io_wait_total, 279 tot); 280 281 len += snprintf(buf+len, PAGE_SIZE-len, "\n"); 282 return len; 283 } 284 285 localport = vport->localport; 286 if (!localport) { 287 len = snprintf(buf, PAGE_SIZE, 288 "NVME Initiator x%llx is not allocated\n", 289 wwn_to_u64(vport->fc_portname.u.wwn)); 290 return len; 291 } 292 lport = (struct lpfc_nvme_lport *)localport->private; 293 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n"); 294 295 spin_lock_irq(shost->host_lock); 296 297 /* Port state is only one of two values for now. */ 298 if (localport->port_id) 299 statep = "ONLINE"; 300 else 301 statep = "UNKNOWN "; 302 303 len += snprintf(buf + len, PAGE_SIZE - len, 304 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n", 305 "NVME LPORT lpfc", 306 phba->brd_no, 307 wwn_to_u64(vport->fc_portname.u.wwn), 308 wwn_to_u64(vport->fc_nodename.u.wwn), 309 localport->port_id, statep); 310 311 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 312 if (!ndlp->nrport) 313 continue; 314 315 /* local short-hand pointer. */ 316 nrport = ndlp->nrport->remoteport; 317 318 /* Port state is only one of two values for now. */ 319 switch (nrport->port_state) { 320 case FC_OBJSTATE_ONLINE: 321 statep = "ONLINE"; 322 break; 323 case FC_OBJSTATE_UNKNOWN: 324 statep = "UNKNOWN "; 325 break; 326 default: 327 statep = "UNSUPPORTED"; 328 break; 329 } 330 331 /* Tab in to show lport ownership. */ 332 len += snprintf(buf + len, PAGE_SIZE - len, 333 "NVME RPORT "); 334 if (phba->brd_no >= 10) 335 len += snprintf(buf + len, PAGE_SIZE - len, " "); 336 337 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ", 338 nrport->port_name); 339 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ", 340 nrport->node_name); 341 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ", 342 nrport->port_id); 343 344 /* An NVME rport can have multiple roles. */ 345 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) 346 len += snprintf(buf + len, PAGE_SIZE - len, 347 "INITIATOR "); 348 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) 349 len += snprintf(buf + len, PAGE_SIZE - len, 350 "TARGET "); 351 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) 352 len += snprintf(buf + len, PAGE_SIZE - len, 353 "DISCSRVC "); 354 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR | 355 FC_PORT_ROLE_NVME_TARGET | 356 FC_PORT_ROLE_NVME_DISCOVERY)) 357 len += snprintf(buf + len, PAGE_SIZE - len, 358 "UNKNOWN ROLE x%x", 359 nrport->port_role); 360 361 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep); 362 /* Terminate the string. */ 363 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); 364 } 365 spin_unlock_irq(shost->host_lock); 366 367 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n"); 368 len += snprintf(buf+len, PAGE_SIZE-len, 369 "LS: Xmt %010x Cmpl %010x Abort %08x\n", 370 atomic_read(&phba->fc4NvmeLsRequests), 371 atomic_read(&phba->fc4NvmeLsCmpls), 372 atomic_read(&lport->xmt_ls_abort)); 373 374 len += snprintf(buf + len, PAGE_SIZE - len, 375 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n", 376 atomic_read(&lport->xmt_ls_err), 377 atomic_read(&lport->cmpl_ls_xb), 378 atomic_read(&lport->cmpl_ls_err)); 379 380 tot = atomic_read(&phba->fc4NvmeIoCmpls); 381 data1 = atomic_read(&phba->fc4NvmeInputRequests); 382 data2 = atomic_read(&phba->fc4NvmeOutputRequests); 383 data3 = atomic_read(&phba->fc4NvmeControlRequests); 384 len += snprintf(buf+len, PAGE_SIZE-len, 385 "FCP: Rd %016llx Wr %016llx IO %016llx\n", 386 data1, data2, data3); 387 388 len += snprintf(buf+len, PAGE_SIZE-len, 389 " noxri %08x nondlp %08x qdepth %08x " 390 "wqerr %08x\n", 391 atomic_read(&lport->xmt_fcp_noxri), 392 atomic_read(&lport->xmt_fcp_bad_ndlp), 393 atomic_read(&lport->xmt_fcp_qdepth), 394 atomic_read(&lport->xmt_fcp_wqerr)); 395 396 len += snprintf(buf + len, PAGE_SIZE - len, 397 " Cmpl %016llx Outstanding %016llx Abort %08x\n", 398 tot, ((data1 + data2 + data3) - tot), 399 atomic_read(&lport->xmt_fcp_abort)); 400 401 len += snprintf(buf + len, PAGE_SIZE - len, 402 "FCP CMPL: xb %08x Err %08x\n", 403 atomic_read(&lport->cmpl_fcp_xb), 404 atomic_read(&lport->cmpl_fcp_err)); 405 return len; 406 } 407 408 static ssize_t 409 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr, 410 char *buf) 411 { 412 struct Scsi_Host *shost = class_to_shost(dev); 413 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 414 struct lpfc_hba *phba = vport->phba; 415 416 if (phba->cfg_enable_bg) 417 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) 418 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n"); 419 else 420 return snprintf(buf, PAGE_SIZE, 421 "BlockGuard Not Supported\n"); 422 else 423 return snprintf(buf, PAGE_SIZE, 424 "BlockGuard Disabled\n"); 425 } 426 427 static ssize_t 428 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr, 429 char *buf) 430 { 431 struct Scsi_Host *shost = class_to_shost(dev); 432 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 433 struct lpfc_hba *phba = vport->phba; 434 435 return snprintf(buf, PAGE_SIZE, "%llu\n", 436 (unsigned long long)phba->bg_guard_err_cnt); 437 } 438 439 static ssize_t 440 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr, 441 char *buf) 442 { 443 struct Scsi_Host *shost = class_to_shost(dev); 444 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 445 struct lpfc_hba *phba = vport->phba; 446 447 return snprintf(buf, PAGE_SIZE, "%llu\n", 448 (unsigned long long)phba->bg_apptag_err_cnt); 449 } 450 451 static ssize_t 452 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr, 453 char *buf) 454 { 455 struct Scsi_Host *shost = class_to_shost(dev); 456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 457 struct lpfc_hba *phba = vport->phba; 458 459 return snprintf(buf, PAGE_SIZE, "%llu\n", 460 (unsigned long long)phba->bg_reftag_err_cnt); 461 } 462 463 /** 464 * lpfc_info_show - Return some pci info about the host in ascii 465 * @dev: class converted to a Scsi_host structure. 466 * @attr: device attribute, not used. 467 * @buf: on return contains the formatted text from lpfc_info(). 468 * 469 * Returns: size of formatted string. 470 **/ 471 static ssize_t 472 lpfc_info_show(struct device *dev, struct device_attribute *attr, 473 char *buf) 474 { 475 struct Scsi_Host *host = class_to_shost(dev); 476 477 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); 478 } 479 480 /** 481 * lpfc_serialnum_show - Return the hba serial number in ascii 482 * @dev: class converted to a Scsi_host structure. 483 * @attr: device attribute, not used. 484 * @buf: on return contains the formatted text serial number. 485 * 486 * Returns: size of formatted string. 487 **/ 488 static ssize_t 489 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr, 490 char *buf) 491 { 492 struct Scsi_Host *shost = class_to_shost(dev); 493 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 494 struct lpfc_hba *phba = vport->phba; 495 496 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); 497 } 498 499 /** 500 * lpfc_temp_sensor_show - Return the temperature sensor level 501 * @dev: class converted to a Scsi_host structure. 502 * @attr: device attribute, not used. 503 * @buf: on return contains the formatted support level. 504 * 505 * Description: 506 * Returns a number indicating the temperature sensor level currently 507 * supported, zero or one in ascii. 508 * 509 * Returns: size of formatted string. 510 **/ 511 static ssize_t 512 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr, 513 char *buf) 514 { 515 struct Scsi_Host *shost = class_to_shost(dev); 516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 517 struct lpfc_hba *phba = vport->phba; 518 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support); 519 } 520 521 /** 522 * lpfc_modeldesc_show - Return the model description of the hba 523 * @dev: class converted to a Scsi_host structure. 524 * @attr: device attribute, not used. 525 * @buf: on return contains the scsi vpd model description. 526 * 527 * Returns: size of formatted string. 528 **/ 529 static ssize_t 530 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr, 531 char *buf) 532 { 533 struct Scsi_Host *shost = class_to_shost(dev); 534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 535 struct lpfc_hba *phba = vport->phba; 536 537 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); 538 } 539 540 /** 541 * lpfc_modelname_show - Return the model name of the hba 542 * @dev: class converted to a Scsi_host structure. 543 * @attr: device attribute, not used. 544 * @buf: on return contains the scsi vpd model name. 545 * 546 * Returns: size of formatted string. 547 **/ 548 static ssize_t 549 lpfc_modelname_show(struct device *dev, struct device_attribute *attr, 550 char *buf) 551 { 552 struct Scsi_Host *shost = class_to_shost(dev); 553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 554 struct lpfc_hba *phba = vport->phba; 555 556 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); 557 } 558 559 /** 560 * lpfc_programtype_show - Return the program type of the hba 561 * @dev: class converted to a Scsi_host structure. 562 * @attr: device attribute, not used. 563 * @buf: on return contains the scsi vpd program type. 564 * 565 * Returns: size of formatted string. 566 **/ 567 static ssize_t 568 lpfc_programtype_show(struct device *dev, struct device_attribute *attr, 569 char *buf) 570 { 571 struct Scsi_Host *shost = class_to_shost(dev); 572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 573 struct lpfc_hba *phba = vport->phba; 574 575 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); 576 } 577 578 /** 579 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag 580 * @dev: class converted to a Scsi_host structure. 581 * @attr: device attribute, not used. 582 * @buf: on return contains the Menlo Maintenance sli flag. 583 * 584 * Returns: size of formatted string. 585 **/ 586 static ssize_t 587 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf) 588 { 589 struct Scsi_Host *shost = class_to_shost(dev); 590 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; 591 struct lpfc_hba *phba = vport->phba; 592 593 return snprintf(buf, PAGE_SIZE, "%d\n", 594 (phba->sli.sli_flag & LPFC_MENLO_MAINT)); 595 } 596 597 /** 598 * lpfc_vportnum_show - Return the port number in ascii of the hba 599 * @dev: class converted to a Scsi_host structure. 600 * @attr: device attribute, not used. 601 * @buf: on return contains scsi vpd program type. 602 * 603 * Returns: size of formatted string. 604 **/ 605 static ssize_t 606 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr, 607 char *buf) 608 { 609 struct Scsi_Host *shost = class_to_shost(dev); 610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 611 struct lpfc_hba *phba = vport->phba; 612 613 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); 614 } 615 616 /** 617 * lpfc_fwrev_show - Return the firmware rev running in the hba 618 * @dev: class converted to a Scsi_host structure. 619 * @attr: device attribute, not used. 620 * @buf: on return contains the scsi vpd program type. 621 * 622 * Returns: size of formatted string. 623 **/ 624 static ssize_t 625 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr, 626 char *buf) 627 { 628 struct Scsi_Host *shost = class_to_shost(dev); 629 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 630 struct lpfc_hba *phba = vport->phba; 631 uint32_t if_type; 632 uint8_t sli_family; 633 char fwrev[FW_REV_STR_SIZE]; 634 int len; 635 636 lpfc_decode_firmware_rev(phba, fwrev, 1); 637 if_type = phba->sli4_hba.pc_sli4_params.if_type; 638 sli_family = phba->sli4_hba.pc_sli4_params.sli_family; 639 640 if (phba->sli_rev < LPFC_SLI_REV4) 641 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", 642 fwrev, phba->sli_rev); 643 else 644 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n", 645 fwrev, phba->sli_rev, if_type, sli_family); 646 647 return len; 648 } 649 650 /** 651 * lpfc_hdw_show - Return the jedec information about the hba 652 * @dev: class converted to a Scsi_host structure. 653 * @attr: device attribute, not used. 654 * @buf: on return contains the scsi vpd program type. 655 * 656 * Returns: size of formatted string. 657 **/ 658 static ssize_t 659 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf) 660 { 661 char hdw[9]; 662 struct Scsi_Host *shost = class_to_shost(dev); 663 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 664 struct lpfc_hba *phba = vport->phba; 665 lpfc_vpd_t *vp = &phba->vpd; 666 667 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); 668 return snprintf(buf, PAGE_SIZE, "%s\n", hdw); 669 } 670 671 /** 672 * lpfc_option_rom_version_show - Return the adapter ROM FCode version 673 * @dev: class converted to a Scsi_host structure. 674 * @attr: device attribute, not used. 675 * @buf: on return contains the ROM and FCode ascii strings. 676 * 677 * Returns: size of formatted string. 678 **/ 679 static ssize_t 680 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr, 681 char *buf) 682 { 683 struct Scsi_Host *shost = class_to_shost(dev); 684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 685 struct lpfc_hba *phba = vport->phba; 686 char fwrev[FW_REV_STR_SIZE]; 687 688 if (phba->sli_rev < LPFC_SLI_REV4) 689 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); 690 691 lpfc_decode_firmware_rev(phba, fwrev, 1); 692 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev); 693 } 694 695 /** 696 * lpfc_state_show - Return the link state of the port 697 * @dev: class converted to a Scsi_host structure. 698 * @attr: device attribute, not used. 699 * @buf: on return contains text describing the state of the link. 700 * 701 * Notes: 702 * The switch statement has no default so zero will be returned. 703 * 704 * Returns: size of formatted string. 705 **/ 706 static ssize_t 707 lpfc_link_state_show(struct device *dev, struct device_attribute *attr, 708 char *buf) 709 { 710 struct Scsi_Host *shost = class_to_shost(dev); 711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 712 struct lpfc_hba *phba = vport->phba; 713 int len = 0; 714 715 switch (phba->link_state) { 716 case LPFC_LINK_UNKNOWN: 717 case LPFC_WARM_START: 718 case LPFC_INIT_START: 719 case LPFC_INIT_MBX_CMDS: 720 case LPFC_LINK_DOWN: 721 case LPFC_HBA_ERROR: 722 if (phba->hba_flag & LINK_DISABLED) 723 len += snprintf(buf + len, PAGE_SIZE-len, 724 "Link Down - User disabled\n"); 725 else 726 len += snprintf(buf + len, PAGE_SIZE-len, 727 "Link Down\n"); 728 break; 729 case LPFC_LINK_UP: 730 case LPFC_CLEAR_LA: 731 case LPFC_HBA_READY: 732 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - "); 733 734 switch (vport->port_state) { 735 case LPFC_LOCAL_CFG_LINK: 736 len += snprintf(buf + len, PAGE_SIZE-len, 737 "Configuring Link\n"); 738 break; 739 case LPFC_FDISC: 740 case LPFC_FLOGI: 741 case LPFC_FABRIC_CFG_LINK: 742 case LPFC_NS_REG: 743 case LPFC_NS_QRY: 744 case LPFC_BUILD_DISC_LIST: 745 case LPFC_DISC_AUTH: 746 len += snprintf(buf + len, PAGE_SIZE - len, 747 "Discovery\n"); 748 break; 749 case LPFC_VPORT_READY: 750 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n"); 751 break; 752 753 case LPFC_VPORT_FAILED: 754 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n"); 755 break; 756 757 case LPFC_VPORT_UNKNOWN: 758 len += snprintf(buf + len, PAGE_SIZE - len, 759 "Unknown\n"); 760 break; 761 } 762 if (phba->sli.sli_flag & LPFC_MENLO_MAINT) 763 len += snprintf(buf + len, PAGE_SIZE-len, 764 " Menlo Maint Mode\n"); 765 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { 766 if (vport->fc_flag & FC_PUBLIC_LOOP) 767 len += snprintf(buf + len, PAGE_SIZE-len, 768 " Public Loop\n"); 769 else 770 len += snprintf(buf + len, PAGE_SIZE-len, 771 " Private Loop\n"); 772 } else { 773 if (vport->fc_flag & FC_FABRIC) 774 len += snprintf(buf + len, PAGE_SIZE-len, 775 " Fabric\n"); 776 else 777 len += snprintf(buf + len, PAGE_SIZE-len, 778 " Point-2-Point\n"); 779 } 780 } 781 782 return len; 783 } 784 785 /** 786 * lpfc_sli4_protocol_show - Return the fip mode of the HBA 787 * @dev: class unused variable. 788 * @attr: device attribute, not used. 789 * @buf: on return contains the module description text. 790 * 791 * Returns: size of formatted string. 792 **/ 793 static ssize_t 794 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr, 795 char *buf) 796 { 797 struct Scsi_Host *shost = class_to_shost(dev); 798 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 799 struct lpfc_hba *phba = vport->phba; 800 801 if (phba->sli_rev < LPFC_SLI_REV4) 802 return snprintf(buf, PAGE_SIZE, "fc\n"); 803 804 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) { 805 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE) 806 return snprintf(buf, PAGE_SIZE, "fcoe\n"); 807 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) 808 return snprintf(buf, PAGE_SIZE, "fc\n"); 809 } 810 return snprintf(buf, PAGE_SIZE, "unknown\n"); 811 } 812 813 /** 814 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage 815 * (OAS) is supported. 816 * @dev: class unused variable. 817 * @attr: device attribute, not used. 818 * @buf: on return contains the module description text. 819 * 820 * Returns: size of formatted string. 821 **/ 822 static ssize_t 823 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr, 824 char *buf) 825 { 826 struct Scsi_Host *shost = class_to_shost(dev); 827 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; 828 struct lpfc_hba *phba = vport->phba; 829 830 return snprintf(buf, PAGE_SIZE, "%d\n", 831 phba->sli4_hba.pc_sli4_params.oas_supported); 832 } 833 834 /** 835 * lpfc_link_state_store - Transition the link_state on an HBA port 836 * @dev: class device that is converted into a Scsi_host. 837 * @attr: device attribute, not used. 838 * @buf: one or more lpfc_polling_flags values. 839 * @count: not used. 840 * 841 * Returns: 842 * -EINVAL if the buffer is not "up" or "down" 843 * return from link state change function if non-zero 844 * length of the buf on success 845 **/ 846 static ssize_t 847 lpfc_link_state_store(struct device *dev, struct device_attribute *attr, 848 const char *buf, size_t count) 849 { 850 struct Scsi_Host *shost = class_to_shost(dev); 851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 852 struct lpfc_hba *phba = vport->phba; 853 854 int status = -EINVAL; 855 856 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) && 857 (phba->link_state == LPFC_LINK_DOWN)) 858 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); 859 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) && 860 (phba->link_state >= LPFC_LINK_UP)) 861 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT); 862 863 if (status == 0) 864 return strlen(buf); 865 else 866 return status; 867 } 868 869 /** 870 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports 871 * @dev: class device that is converted into a Scsi_host. 872 * @attr: device attribute, not used. 873 * @buf: on return contains the sum of fc mapped and unmapped. 874 * 875 * Description: 876 * Returns the ascii text number of the sum of the fc mapped and unmapped 877 * vport counts. 878 * 879 * Returns: size of formatted string. 880 **/ 881 static ssize_t 882 lpfc_num_discovered_ports_show(struct device *dev, 883 struct device_attribute *attr, char *buf) 884 { 885 struct Scsi_Host *shost = class_to_shost(dev); 886 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 887 888 return snprintf(buf, PAGE_SIZE, "%d\n", 889 vport->fc_map_cnt + vport->fc_unmap_cnt); 890 } 891 892 /** 893 * lpfc_issue_lip - Misnomer, name carried over from long ago 894 * @shost: Scsi_Host pointer. 895 * 896 * Description: 897 * Bring the link down gracefully then re-init the link. The firmware will 898 * re-init the fiber channel interface as required. Does not issue a LIP. 899 * 900 * Returns: 901 * -EPERM port offline or management commands are being blocked 902 * -ENOMEM cannot allocate memory for the mailbox command 903 * -EIO error sending the mailbox command 904 * zero for success 905 **/ 906 static int 907 lpfc_issue_lip(struct Scsi_Host *shost) 908 { 909 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 910 struct lpfc_hba *phba = vport->phba; 911 LPFC_MBOXQ_t *pmboxq; 912 int mbxstatus = MBXERR_ERROR; 913 914 /* 915 * If the link is offline, disabled or BLOCK_MGMT_IO 916 * it doesn't make any sense to allow issue_lip 917 */ 918 if ((vport->fc_flag & FC_OFFLINE_MODE) || 919 (phba->hba_flag & LINK_DISABLED) || 920 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)) 921 return -EPERM; 922 923 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); 924 925 if (!pmboxq) 926 return -ENOMEM; 927 928 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 929 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK; 930 pmboxq->u.mb.mbxOwner = OWN_HOST; 931 932 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2); 933 934 if ((mbxstatus == MBX_SUCCESS) && 935 (pmboxq->u.mb.mbxStatus == 0 || 936 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) { 937 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 938 lpfc_init_link(phba, pmboxq, phba->cfg_topology, 939 phba->cfg_link_speed); 940 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, 941 phba->fc_ratov * 2); 942 if ((mbxstatus == MBX_SUCCESS) && 943 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) 944 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, 945 "2859 SLI authentication is required " 946 "for INIT_LINK but has not done yet\n"); 947 } 948 949 lpfc_set_loopback_flag(phba); 950 if (mbxstatus != MBX_TIMEOUT) 951 mempool_free(pmboxq, phba->mbox_mem_pool); 952 953 if (mbxstatus == MBXERR_ERROR) 954 return -EIO; 955 956 return 0; 957 } 958 959 int 960 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock) 961 { 962 int cnt = 0; 963 964 spin_lock_irq(lock); 965 while (!list_empty(q)) { 966 spin_unlock_irq(lock); 967 msleep(20); 968 if (cnt++ > 250) { /* 5 secs */ 969 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, 970 "0466 %s %s\n", 971 "Outstanding IO when ", 972 "bringing Adapter offline\n"); 973 return 0; 974 } 975 spin_lock_irq(lock); 976 } 977 spin_unlock_irq(lock); 978 return 1; 979 } 980 981 /** 982 * lpfc_do_offline - Issues a mailbox command to bring the link down 983 * @phba: lpfc_hba pointer. 984 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL. 985 * 986 * Notes: 987 * Assumes any error from lpfc_do_offline() will be negative. 988 * Can wait up to 5 seconds for the port ring buffers count 989 * to reach zero, prints a warning if it is not zero and continues. 990 * lpfc_workq_post_event() returns a non-zero return code if call fails. 991 * 992 * Returns: 993 * -EIO error posting the event 994 * zero for success 995 **/ 996 static int 997 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type) 998 { 999 struct completion online_compl; 1000 struct lpfc_queue *qp = NULL; 1001 struct lpfc_sli_ring *pring; 1002 struct lpfc_sli *psli; 1003 int status = 0; 1004 int i; 1005 int rc; 1006 1007 init_completion(&online_compl); 1008 rc = lpfc_workq_post_event(phba, &status, &online_compl, 1009 LPFC_EVT_OFFLINE_PREP); 1010 if (rc == 0) 1011 return -ENOMEM; 1012 1013 wait_for_completion(&online_compl); 1014 1015 if (status != 0) 1016 return -EIO; 1017 1018 psli = &phba->sli; 1019 1020 /* Wait a little for things to settle down, but not 1021 * long enough for dev loss timeout to expire. 1022 */ 1023 if (phba->sli_rev != LPFC_SLI_REV4) { 1024 for (i = 0; i < psli->num_rings; i++) { 1025 pring = &psli->sli3_ring[i]; 1026 if (!lpfc_emptyq_wait(phba, &pring->txcmplq, 1027 &phba->hbalock)) 1028 goto out; 1029 } 1030 } else { 1031 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { 1032 pring = qp->pring; 1033 if (!pring) 1034 continue; 1035 if (!lpfc_emptyq_wait(phba, &pring->txcmplq, 1036 &pring->ring_lock)) 1037 goto out; 1038 } 1039 } 1040 out: 1041 init_completion(&online_compl); 1042 rc = lpfc_workq_post_event(phba, &status, &online_compl, type); 1043 if (rc == 0) 1044 return -ENOMEM; 1045 1046 wait_for_completion(&online_compl); 1047 1048 if (status != 0) 1049 return -EIO; 1050 1051 return 0; 1052 } 1053 1054 /** 1055 * lpfc_selective_reset - Offline then onlines the port 1056 * @phba: lpfc_hba pointer. 1057 * 1058 * Description: 1059 * If the port is configured to allow a reset then the hba is brought 1060 * offline then online. 1061 * 1062 * Notes: 1063 * Assumes any error from lpfc_do_offline() will be negative. 1064 * Do not make this function static. 1065 * 1066 * Returns: 1067 * lpfc_do_offline() return code if not zero 1068 * -EIO reset not configured or error posting the event 1069 * zero for success 1070 **/ 1071 int 1072 lpfc_selective_reset(struct lpfc_hba *phba) 1073 { 1074 struct completion online_compl; 1075 int status = 0; 1076 int rc; 1077 1078 if (!phba->cfg_enable_hba_reset) 1079 return -EACCES; 1080 1081 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) { 1082 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); 1083 1084 if (status != 0) 1085 return status; 1086 } 1087 1088 init_completion(&online_compl); 1089 rc = lpfc_workq_post_event(phba, &status, &online_compl, 1090 LPFC_EVT_ONLINE); 1091 if (rc == 0) 1092 return -ENOMEM; 1093 1094 wait_for_completion(&online_compl); 1095 1096 if (status != 0) 1097 return -EIO; 1098 1099 return 0; 1100 } 1101 1102 /** 1103 * lpfc_issue_reset - Selectively resets an adapter 1104 * @dev: class device that is converted into a Scsi_host. 1105 * @attr: device attribute, not used. 1106 * @buf: containing the string "selective". 1107 * @count: unused variable. 1108 * 1109 * Description: 1110 * If the buf contains the string "selective" then lpfc_selective_reset() 1111 * is called to perform the reset. 1112 * 1113 * Notes: 1114 * Assumes any error from lpfc_selective_reset() will be negative. 1115 * If lpfc_selective_reset() returns zero then the length of the buffer 1116 * is returned which indicates success 1117 * 1118 * Returns: 1119 * -EINVAL if the buffer does not contain the string "selective" 1120 * length of buf if lpfc-selective_reset() if the call succeeds 1121 * return value of lpfc_selective_reset() if the call fails 1122 **/ 1123 static ssize_t 1124 lpfc_issue_reset(struct device *dev, struct device_attribute *attr, 1125 const char *buf, size_t count) 1126 { 1127 struct Scsi_Host *shost = class_to_shost(dev); 1128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1129 struct lpfc_hba *phba = vport->phba; 1130 int status = -EINVAL; 1131 1132 if (!phba->cfg_enable_hba_reset) 1133 return -EACCES; 1134 1135 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) 1136 status = phba->lpfc_selective_reset(phba); 1137 1138 if (status == 0) 1139 return strlen(buf); 1140 else 1141 return status; 1142 } 1143 1144 /** 1145 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness 1146 * @phba: lpfc_hba pointer. 1147 * 1148 * Description: 1149 * SLI4 interface type-2 device to wait on the sliport status register for 1150 * the readyness after performing a firmware reset. 1151 * 1152 * Returns: 1153 * zero for success, -EPERM when port does not have privilege to perform the 1154 * reset, -EIO when port timeout from recovering from the reset. 1155 * 1156 * Note: 1157 * As the caller will interpret the return code by value, be careful in making 1158 * change or addition to return codes. 1159 **/ 1160 int 1161 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba) 1162 { 1163 struct lpfc_register portstat_reg = {0}; 1164 int i; 1165 1166 msleep(100); 1167 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, 1168 &portstat_reg.word0); 1169 1170 /* verify if privileged for the request operation */ 1171 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) && 1172 !bf_get(lpfc_sliport_status_err, &portstat_reg)) 1173 return -EPERM; 1174 1175 /* wait for the SLI port firmware ready after firmware reset */ 1176 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) { 1177 msleep(10); 1178 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, 1179 &portstat_reg.word0); 1180 if (!bf_get(lpfc_sliport_status_err, &portstat_reg)) 1181 continue; 1182 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg)) 1183 continue; 1184 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg)) 1185 continue; 1186 break; 1187 } 1188 1189 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT) 1190 return 0; 1191 else 1192 return -EIO; 1193 } 1194 1195 /** 1196 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc 1197 * @phba: lpfc_hba pointer. 1198 * 1199 * Description: 1200 * Request SLI4 interface type-2 device to perform a physical register set 1201 * access. 1202 * 1203 * Returns: 1204 * zero for success 1205 **/ 1206 static ssize_t 1207 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode) 1208 { 1209 struct completion online_compl; 1210 struct pci_dev *pdev = phba->pcidev; 1211 uint32_t before_fc_flag; 1212 uint32_t sriov_nr_virtfn; 1213 uint32_t reg_val; 1214 int status = 0, rc = 0; 1215 int job_posted = 1, sriov_err; 1216 1217 if (!phba->cfg_enable_hba_reset) 1218 return -EACCES; 1219 1220 if ((phba->sli_rev < LPFC_SLI_REV4) || 1221 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != 1222 LPFC_SLI_INTF_IF_TYPE_2)) 1223 return -EPERM; 1224 1225 /* Keep state if we need to restore back */ 1226 before_fc_flag = phba->pport->fc_flag; 1227 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn; 1228 1229 /* Disable SR-IOV virtual functions if enabled */ 1230 if (phba->cfg_sriov_nr_virtfn) { 1231 pci_disable_sriov(pdev); 1232 phba->cfg_sriov_nr_virtfn = 0; 1233 } 1234 1235 if (opcode == LPFC_FW_DUMP) 1236 phba->hba_flag |= HBA_FW_DUMP_OP; 1237 1238 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); 1239 1240 if (status != 0) { 1241 phba->hba_flag &= ~HBA_FW_DUMP_OP; 1242 return status; 1243 } 1244 1245 /* wait for the device to be quiesced before firmware reset */ 1246 msleep(100); 1247 1248 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p + 1249 LPFC_CTL_PDEV_CTL_OFFSET); 1250 1251 if (opcode == LPFC_FW_DUMP) 1252 reg_val |= LPFC_FW_DUMP_REQUEST; 1253 else if (opcode == LPFC_FW_RESET) 1254 reg_val |= LPFC_CTL_PDEV_CTL_FRST; 1255 else if (opcode == LPFC_DV_RESET) 1256 reg_val |= LPFC_CTL_PDEV_CTL_DRST; 1257 1258 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p + 1259 LPFC_CTL_PDEV_CTL_OFFSET); 1260 /* flush */ 1261 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); 1262 1263 /* delay driver action following IF_TYPE_2 reset */ 1264 rc = lpfc_sli4_pdev_status_reg_wait(phba); 1265 1266 if (rc == -EPERM) { 1267 /* no privilege for reset */ 1268 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 1269 "3150 No privilege to perform the requested " 1270 "access: x%x\n", reg_val); 1271 } else if (rc == -EIO) { 1272 /* reset failed, there is nothing more we can do */ 1273 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 1274 "3153 Fail to perform the requested " 1275 "access: x%x\n", reg_val); 1276 return rc; 1277 } 1278 1279 /* keep the original port state */ 1280 if (before_fc_flag & FC_OFFLINE_MODE) 1281 goto out; 1282 1283 init_completion(&online_compl); 1284 job_posted = lpfc_workq_post_event(phba, &status, &online_compl, 1285 LPFC_EVT_ONLINE); 1286 if (!job_posted) 1287 goto out; 1288 1289 wait_for_completion(&online_compl); 1290 1291 out: 1292 /* in any case, restore the virtual functions enabled as before */ 1293 if (sriov_nr_virtfn) { 1294 sriov_err = 1295 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn); 1296 if (!sriov_err) 1297 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn; 1298 } 1299 1300 /* return proper error code */ 1301 if (!rc) { 1302 if (!job_posted) 1303 rc = -ENOMEM; 1304 else if (status) 1305 rc = -EIO; 1306 } 1307 return rc; 1308 } 1309 1310 /** 1311 * lpfc_nport_evt_cnt_show - Return the number of nport events 1312 * @dev: class device that is converted into a Scsi_host. 1313 * @attr: device attribute, not used. 1314 * @buf: on return contains the ascii number of nport events. 1315 * 1316 * Returns: size of formatted string. 1317 **/ 1318 static ssize_t 1319 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr, 1320 char *buf) 1321 { 1322 struct Scsi_Host *shost = class_to_shost(dev); 1323 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1324 struct lpfc_hba *phba = vport->phba; 1325 1326 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); 1327 } 1328 1329 /** 1330 * lpfc_board_mode_show - Return the state of the board 1331 * @dev: class device that is converted into a Scsi_host. 1332 * @attr: device attribute, not used. 1333 * @buf: on return contains the state of the adapter. 1334 * 1335 * Returns: size of formatted string. 1336 **/ 1337 static ssize_t 1338 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr, 1339 char *buf) 1340 { 1341 struct Scsi_Host *shost = class_to_shost(dev); 1342 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1343 struct lpfc_hba *phba = vport->phba; 1344 char * state; 1345 1346 if (phba->link_state == LPFC_HBA_ERROR) 1347 state = "error"; 1348 else if (phba->link_state == LPFC_WARM_START) 1349 state = "warm start"; 1350 else if (phba->link_state == LPFC_INIT_START) 1351 state = "offline"; 1352 else 1353 state = "online"; 1354 1355 return snprintf(buf, PAGE_SIZE, "%s\n", state); 1356 } 1357 1358 /** 1359 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state 1360 * @dev: class device that is converted into a Scsi_host. 1361 * @attr: device attribute, not used. 1362 * @buf: containing one of the strings "online", "offline", "warm" or "error". 1363 * @count: unused variable. 1364 * 1365 * Returns: 1366 * -EACCES if enable hba reset not enabled 1367 * -EINVAL if the buffer does not contain a valid string (see above) 1368 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails 1369 * buf length greater than zero indicates success 1370 **/ 1371 static ssize_t 1372 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr, 1373 const char *buf, size_t count) 1374 { 1375 struct Scsi_Host *shost = class_to_shost(dev); 1376 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1377 struct lpfc_hba *phba = vport->phba; 1378 struct completion online_compl; 1379 char *board_mode_str = NULL; 1380 int status = 0; 1381 int rc; 1382 1383 if (!phba->cfg_enable_hba_reset) { 1384 status = -EACCES; 1385 goto board_mode_out; 1386 } 1387 1388 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1389 "3050 lpfc_board_mode set to %s\n", buf); 1390 1391 init_completion(&online_compl); 1392 1393 if(strncmp(buf, "online", sizeof("online") - 1) == 0) { 1394 rc = lpfc_workq_post_event(phba, &status, &online_compl, 1395 LPFC_EVT_ONLINE); 1396 if (rc == 0) { 1397 status = -ENOMEM; 1398 goto board_mode_out; 1399 } 1400 wait_for_completion(&online_compl); 1401 if (status) 1402 status = -EIO; 1403 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) 1404 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); 1405 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) 1406 if (phba->sli_rev == LPFC_SLI_REV4) 1407 status = -EINVAL; 1408 else 1409 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START); 1410 else if (strncmp(buf, "error", sizeof("error") - 1) == 0) 1411 if (phba->sli_rev == LPFC_SLI_REV4) 1412 status = -EINVAL; 1413 else 1414 status = lpfc_do_offline(phba, LPFC_EVT_KILL); 1415 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0) 1416 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP); 1417 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0) 1418 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET); 1419 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0) 1420 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET); 1421 else 1422 status = -EINVAL; 1423 1424 board_mode_out: 1425 if (!status) 1426 return strlen(buf); 1427 else { 1428 board_mode_str = strchr(buf, '\n'); 1429 if (board_mode_str) 1430 *board_mode_str = '\0'; 1431 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1432 "3097 Failed \"%s\", status(%d), " 1433 "fc_flag(x%x)\n", 1434 buf, status, phba->pport->fc_flag); 1435 return status; 1436 } 1437 } 1438 1439 /** 1440 * lpfc_get_hba_info - Return various bits of informaton about the adapter 1441 * @phba: pointer to the adapter structure. 1442 * @mxri: max xri count. 1443 * @axri: available xri count. 1444 * @mrpi: max rpi count. 1445 * @arpi: available rpi count. 1446 * @mvpi: max vpi count. 1447 * @avpi: available vpi count. 1448 * 1449 * Description: 1450 * If an integer pointer for an count is not null then the value for the 1451 * count is returned. 1452 * 1453 * Returns: 1454 * zero on error 1455 * one for success 1456 **/ 1457 static int 1458 lpfc_get_hba_info(struct lpfc_hba *phba, 1459 uint32_t *mxri, uint32_t *axri, 1460 uint32_t *mrpi, uint32_t *arpi, 1461 uint32_t *mvpi, uint32_t *avpi) 1462 { 1463 struct lpfc_mbx_read_config *rd_config; 1464 LPFC_MBOXQ_t *pmboxq; 1465 MAILBOX_t *pmb; 1466 int rc = 0; 1467 uint32_t max_vpi; 1468 1469 /* 1470 * prevent udev from issuing mailbox commands until the port is 1471 * configured. 1472 */ 1473 if (phba->link_state < LPFC_LINK_DOWN || 1474 !phba->mbox_mem_pool || 1475 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) 1476 return 0; 1477 1478 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) 1479 return 0; 1480 1481 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1482 if (!pmboxq) 1483 return 0; 1484 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 1485 1486 pmb = &pmboxq->u.mb; 1487 pmb->mbxCommand = MBX_READ_CONFIG; 1488 pmb->mbxOwner = OWN_HOST; 1489 pmboxq->context1 = NULL; 1490 1491 if (phba->pport->fc_flag & FC_OFFLINE_MODE) 1492 rc = MBX_NOT_FINISHED; 1493 else 1494 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 1495 1496 if (rc != MBX_SUCCESS) { 1497 if (rc != MBX_TIMEOUT) 1498 mempool_free(pmboxq, phba->mbox_mem_pool); 1499 return 0; 1500 } 1501 1502 if (phba->sli_rev == LPFC_SLI_REV4) { 1503 rd_config = &pmboxq->u.mqe.un.rd_config; 1504 if (mrpi) 1505 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); 1506 if (arpi) 1507 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) - 1508 phba->sli4_hba.max_cfg_param.rpi_used; 1509 if (mxri) 1510 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); 1511 if (axri) 1512 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) - 1513 phba->sli4_hba.max_cfg_param.xri_used; 1514 1515 /* Account for differences with SLI-3. Get vpi count from 1516 * mailbox data and subtract one for max vpi value. 1517 */ 1518 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ? 1519 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0; 1520 1521 if (mvpi) 1522 *mvpi = max_vpi; 1523 if (avpi) 1524 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used; 1525 } else { 1526 if (mrpi) 1527 *mrpi = pmb->un.varRdConfig.max_rpi; 1528 if (arpi) 1529 *arpi = pmb->un.varRdConfig.avail_rpi; 1530 if (mxri) 1531 *mxri = pmb->un.varRdConfig.max_xri; 1532 if (axri) 1533 *axri = pmb->un.varRdConfig.avail_xri; 1534 if (mvpi) 1535 *mvpi = pmb->un.varRdConfig.max_vpi; 1536 if (avpi) 1537 *avpi = pmb->un.varRdConfig.avail_vpi; 1538 } 1539 1540 mempool_free(pmboxq, phba->mbox_mem_pool); 1541 return 1; 1542 } 1543 1544 /** 1545 * lpfc_max_rpi_show - Return maximum rpi 1546 * @dev: class device that is converted into a Scsi_host. 1547 * @attr: device attribute, not used. 1548 * @buf: on return contains the maximum rpi count in decimal or "Unknown". 1549 * 1550 * Description: 1551 * Calls lpfc_get_hba_info() asking for just the mrpi count. 1552 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 1553 * to "Unknown" and the buffer length is returned, therefore the caller 1554 * must check for "Unknown" in the buffer to detect a failure. 1555 * 1556 * Returns: size of formatted string. 1557 **/ 1558 static ssize_t 1559 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr, 1560 char *buf) 1561 { 1562 struct Scsi_Host *shost = class_to_shost(dev); 1563 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1564 struct lpfc_hba *phba = vport->phba; 1565 uint32_t cnt; 1566 1567 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL)) 1568 return snprintf(buf, PAGE_SIZE, "%d\n", cnt); 1569 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 1570 } 1571 1572 /** 1573 * lpfc_used_rpi_show - Return maximum rpi minus available rpi 1574 * @dev: class device that is converted into a Scsi_host. 1575 * @attr: device attribute, not used. 1576 * @buf: containing the used rpi count in decimal or "Unknown". 1577 * 1578 * Description: 1579 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts. 1580 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 1581 * to "Unknown" and the buffer length is returned, therefore the caller 1582 * must check for "Unknown" in the buffer to detect a failure. 1583 * 1584 * Returns: size of formatted string. 1585 **/ 1586 static ssize_t 1587 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr, 1588 char *buf) 1589 { 1590 struct Scsi_Host *shost = class_to_shost(dev); 1591 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1592 struct lpfc_hba *phba = vport->phba; 1593 uint32_t cnt, acnt; 1594 1595 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) 1596 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 1597 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 1598 } 1599 1600 /** 1601 * lpfc_max_xri_show - Return maximum xri 1602 * @dev: class device that is converted into a Scsi_host. 1603 * @attr: device attribute, not used. 1604 * @buf: on return contains the maximum xri count in decimal or "Unknown". 1605 * 1606 * Description: 1607 * Calls lpfc_get_hba_info() asking for just the mrpi count. 1608 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 1609 * to "Unknown" and the buffer length is returned, therefore the caller 1610 * must check for "Unknown" in the buffer to detect a failure. 1611 * 1612 * Returns: size of formatted string. 1613 **/ 1614 static ssize_t 1615 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr, 1616 char *buf) 1617 { 1618 struct Scsi_Host *shost = class_to_shost(dev); 1619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1620 struct lpfc_hba *phba = vport->phba; 1621 uint32_t cnt; 1622 1623 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL)) 1624 return snprintf(buf, PAGE_SIZE, "%d\n", cnt); 1625 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 1626 } 1627 1628 /** 1629 * lpfc_used_xri_show - Return maximum xpi minus the available xpi 1630 * @dev: class device that is converted into a Scsi_host. 1631 * @attr: device attribute, not used. 1632 * @buf: on return contains the used xri count in decimal or "Unknown". 1633 * 1634 * Description: 1635 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts. 1636 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 1637 * to "Unknown" and the buffer length is returned, therefore the caller 1638 * must check for "Unknown" in the buffer to detect a failure. 1639 * 1640 * Returns: size of formatted string. 1641 **/ 1642 static ssize_t 1643 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr, 1644 char *buf) 1645 { 1646 struct Scsi_Host *shost = class_to_shost(dev); 1647 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1648 struct lpfc_hba *phba = vport->phba; 1649 uint32_t cnt, acnt; 1650 1651 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) 1652 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 1653 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 1654 } 1655 1656 /** 1657 * lpfc_max_vpi_show - Return maximum vpi 1658 * @dev: class device that is converted into a Scsi_host. 1659 * @attr: device attribute, not used. 1660 * @buf: on return contains the maximum vpi count in decimal or "Unknown". 1661 * 1662 * Description: 1663 * Calls lpfc_get_hba_info() asking for just the mvpi count. 1664 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 1665 * to "Unknown" and the buffer length is returned, therefore the caller 1666 * must check for "Unknown" in the buffer to detect a failure. 1667 * 1668 * Returns: size of formatted string. 1669 **/ 1670 static ssize_t 1671 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr, 1672 char *buf) 1673 { 1674 struct Scsi_Host *shost = class_to_shost(dev); 1675 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1676 struct lpfc_hba *phba = vport->phba; 1677 uint32_t cnt; 1678 1679 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL)) 1680 return snprintf(buf, PAGE_SIZE, "%d\n", cnt); 1681 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 1682 } 1683 1684 /** 1685 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi 1686 * @dev: class device that is converted into a Scsi_host. 1687 * @attr: device attribute, not used. 1688 * @buf: on return contains the used vpi count in decimal or "Unknown". 1689 * 1690 * Description: 1691 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts. 1692 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set 1693 * to "Unknown" and the buffer length is returned, therefore the caller 1694 * must check for "Unknown" in the buffer to detect a failure. 1695 * 1696 * Returns: size of formatted string. 1697 **/ 1698 static ssize_t 1699 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr, 1700 char *buf) 1701 { 1702 struct Scsi_Host *shost = class_to_shost(dev); 1703 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1704 struct lpfc_hba *phba = vport->phba; 1705 uint32_t cnt, acnt; 1706 1707 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) 1708 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 1709 return snprintf(buf, PAGE_SIZE, "Unknown\n"); 1710 } 1711 1712 /** 1713 * lpfc_npiv_info_show - Return text about NPIV support for the adapter 1714 * @dev: class device that is converted into a Scsi_host. 1715 * @attr: device attribute, not used. 1716 * @buf: text that must be interpreted to determine if npiv is supported. 1717 * 1718 * Description: 1719 * Buffer will contain text indicating npiv is not suppoerted on the port, 1720 * the port is an NPIV physical port, or it is an npiv virtual port with 1721 * the id of the vport. 1722 * 1723 * Returns: size of formatted string. 1724 **/ 1725 static ssize_t 1726 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr, 1727 char *buf) 1728 { 1729 struct Scsi_Host *shost = class_to_shost(dev); 1730 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1731 struct lpfc_hba *phba = vport->phba; 1732 1733 if (!(phba->max_vpi)) 1734 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n"); 1735 if (vport->port_type == LPFC_PHYSICAL_PORT) 1736 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n"); 1737 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi); 1738 } 1739 1740 /** 1741 * lpfc_poll_show - Return text about poll support for the adapter 1742 * @dev: class device that is converted into a Scsi_host. 1743 * @attr: device attribute, not used. 1744 * @buf: on return contains the cfg_poll in hex. 1745 * 1746 * Notes: 1747 * cfg_poll should be a lpfc_polling_flags type. 1748 * 1749 * Returns: size of formatted string. 1750 **/ 1751 static ssize_t 1752 lpfc_poll_show(struct device *dev, struct device_attribute *attr, 1753 char *buf) 1754 { 1755 struct Scsi_Host *shost = class_to_shost(dev); 1756 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1757 struct lpfc_hba *phba = vport->phba; 1758 1759 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); 1760 } 1761 1762 /** 1763 * lpfc_poll_store - Set the value of cfg_poll for the adapter 1764 * @dev: class device that is converted into a Scsi_host. 1765 * @attr: device attribute, not used. 1766 * @buf: one or more lpfc_polling_flags values. 1767 * @count: not used. 1768 * 1769 * Notes: 1770 * buf contents converted to integer and checked for a valid value. 1771 * 1772 * Returns: 1773 * -EINVAL if the buffer connot be converted or is out of range 1774 * length of the buf on success 1775 **/ 1776 static ssize_t 1777 lpfc_poll_store(struct device *dev, struct device_attribute *attr, 1778 const char *buf, size_t count) 1779 { 1780 struct Scsi_Host *shost = class_to_shost(dev); 1781 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1782 struct lpfc_hba *phba = vport->phba; 1783 uint32_t creg_val; 1784 uint32_t old_val; 1785 int val=0; 1786 1787 if (!isdigit(buf[0])) 1788 return -EINVAL; 1789 1790 if (sscanf(buf, "%i", &val) != 1) 1791 return -EINVAL; 1792 1793 if ((val & 0x3) != val) 1794 return -EINVAL; 1795 1796 if (phba->sli_rev == LPFC_SLI_REV4) 1797 val = 0; 1798 1799 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 1800 "3051 lpfc_poll changed from %d to %d\n", 1801 phba->cfg_poll, val); 1802 1803 spin_lock_irq(&phba->hbalock); 1804 1805 old_val = phba->cfg_poll; 1806 1807 if (val & ENABLE_FCP_RING_POLLING) { 1808 if ((val & DISABLE_FCP_RING_INT) && 1809 !(old_val & DISABLE_FCP_RING_INT)) { 1810 if (lpfc_readl(phba->HCregaddr, &creg_val)) { 1811 spin_unlock_irq(&phba->hbalock); 1812 return -EINVAL; 1813 } 1814 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); 1815 writel(creg_val, phba->HCregaddr); 1816 readl(phba->HCregaddr); /* flush */ 1817 1818 lpfc_poll_start_timer(phba); 1819 } 1820 } else if (val != 0x0) { 1821 spin_unlock_irq(&phba->hbalock); 1822 return -EINVAL; 1823 } 1824 1825 if (!(val & DISABLE_FCP_RING_INT) && 1826 (old_val & DISABLE_FCP_RING_INT)) 1827 { 1828 spin_unlock_irq(&phba->hbalock); 1829 del_timer(&phba->fcp_poll_timer); 1830 spin_lock_irq(&phba->hbalock); 1831 if (lpfc_readl(phba->HCregaddr, &creg_val)) { 1832 spin_unlock_irq(&phba->hbalock); 1833 return -EINVAL; 1834 } 1835 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); 1836 writel(creg_val, phba->HCregaddr); 1837 readl(phba->HCregaddr); /* flush */ 1838 } 1839 1840 phba->cfg_poll = val; 1841 1842 spin_unlock_irq(&phba->hbalock); 1843 1844 return strlen(buf); 1845 } 1846 1847 /** 1848 * lpfc_fips_level_show - Return the current FIPS level for the HBA 1849 * @dev: class unused variable. 1850 * @attr: device attribute, not used. 1851 * @buf: on return contains the module description text. 1852 * 1853 * Returns: size of formatted string. 1854 **/ 1855 static ssize_t 1856 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr, 1857 char *buf) 1858 { 1859 struct Scsi_Host *shost = class_to_shost(dev); 1860 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1861 struct lpfc_hba *phba = vport->phba; 1862 1863 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level); 1864 } 1865 1866 /** 1867 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA 1868 * @dev: class unused variable. 1869 * @attr: device attribute, not used. 1870 * @buf: on return contains the module description text. 1871 * 1872 * Returns: size of formatted string. 1873 **/ 1874 static ssize_t 1875 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr, 1876 char *buf) 1877 { 1878 struct Scsi_Host *shost = class_to_shost(dev); 1879 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1880 struct lpfc_hba *phba = vport->phba; 1881 1882 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev); 1883 } 1884 1885 /** 1886 * lpfc_dss_show - Return the current state of dss and the configured state 1887 * @dev: class converted to a Scsi_host structure. 1888 * @attr: device attribute, not used. 1889 * @buf: on return contains the formatted text. 1890 * 1891 * Returns: size of formatted string. 1892 **/ 1893 static ssize_t 1894 lpfc_dss_show(struct device *dev, struct device_attribute *attr, 1895 char *buf) 1896 { 1897 struct Scsi_Host *shost = class_to_shost(dev); 1898 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1899 struct lpfc_hba *phba = vport->phba; 1900 1901 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n", 1902 (phba->cfg_enable_dss) ? "Enabled" : "Disabled", 1903 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ? 1904 "" : "Not "); 1905 } 1906 1907 /** 1908 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions 1909 * @dev: class converted to a Scsi_host structure. 1910 * @attr: device attribute, not used. 1911 * @buf: on return contains the formatted support level. 1912 * 1913 * Description: 1914 * Returns the maximum number of virtual functions a physical function can 1915 * support, 0 will be returned if called on virtual function. 1916 * 1917 * Returns: size of formatted string. 1918 **/ 1919 static ssize_t 1920 lpfc_sriov_hw_max_virtfn_show(struct device *dev, 1921 struct device_attribute *attr, 1922 char *buf) 1923 { 1924 struct Scsi_Host *shost = class_to_shost(dev); 1925 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 1926 struct lpfc_hba *phba = vport->phba; 1927 uint16_t max_nr_virtfn; 1928 1929 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba); 1930 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn); 1931 } 1932 1933 static inline bool lpfc_rangecheck(uint val, uint min, uint max) 1934 { 1935 return val >= min && val <= max; 1936 } 1937 1938 /** 1939 * lpfc_enable_bbcr_set: Sets an attribute value. 1940 * @phba: pointer the the adapter structure. 1941 * @val: integer attribute value. 1942 * 1943 * Description: 1944 * Validates the min and max values then sets the 1945 * adapter config field if in the valid range. prints error message 1946 * and does not set the parameter if invalid. 1947 * 1948 * Returns: 1949 * zero on success 1950 * -EINVAL if val is invalid 1951 */ 1952 static ssize_t 1953 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val) 1954 { 1955 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) { 1956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 1957 "3068 %s_enable_bbcr changed from %d to %d\n", 1958 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val); 1959 phba->cfg_enable_bbcr = val; 1960 return 0; 1961 } 1962 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 1963 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n", 1964 LPFC_DRIVER_NAME, val); 1965 return -EINVAL; 1966 } 1967 1968 /** 1969 * lpfc_param_show - Return a cfg attribute value in decimal 1970 * 1971 * Description: 1972 * Macro that given an attr e.g. hba_queue_depth expands 1973 * into a function with the name lpfc_hba_queue_depth_show. 1974 * 1975 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field. 1976 * @dev: class device that is converted into a Scsi_host. 1977 * @attr: device attribute, not used. 1978 * @buf: on return contains the attribute value in decimal. 1979 * 1980 * Returns: size of formatted string. 1981 **/ 1982 #define lpfc_param_show(attr) \ 1983 static ssize_t \ 1984 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 1985 char *buf) \ 1986 { \ 1987 struct Scsi_Host *shost = class_to_shost(dev);\ 1988 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1989 struct lpfc_hba *phba = vport->phba;\ 1990 return snprintf(buf, PAGE_SIZE, "%d\n",\ 1991 phba->cfg_##attr);\ 1992 } 1993 1994 /** 1995 * lpfc_param_hex_show - Return a cfg attribute value in hex 1996 * 1997 * Description: 1998 * Macro that given an attr e.g. hba_queue_depth expands 1999 * into a function with the name lpfc_hba_queue_depth_show 2000 * 2001 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field. 2002 * @dev: class device that is converted into a Scsi_host. 2003 * @attr: device attribute, not used. 2004 * @buf: on return contains the attribute value in hexadecimal. 2005 * 2006 * Returns: size of formatted string. 2007 **/ 2008 #define lpfc_param_hex_show(attr) \ 2009 static ssize_t \ 2010 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 2011 char *buf) \ 2012 { \ 2013 struct Scsi_Host *shost = class_to_shost(dev);\ 2014 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 2015 struct lpfc_hba *phba = vport->phba;\ 2016 uint val = 0;\ 2017 val = phba->cfg_##attr;\ 2018 return snprintf(buf, PAGE_SIZE, "%#x\n",\ 2019 phba->cfg_##attr);\ 2020 } 2021 2022 /** 2023 * lpfc_param_init - Initializes a cfg attribute 2024 * 2025 * Description: 2026 * Macro that given an attr e.g. hba_queue_depth expands 2027 * into a function with the name lpfc_hba_queue_depth_init. The macro also 2028 * takes a default argument, a minimum and maximum argument. 2029 * 2030 * lpfc_##attr##_init: Initializes an attribute. 2031 * @phba: pointer the the adapter structure. 2032 * @val: integer attribute value. 2033 * 2034 * Validates the min and max values then sets the adapter config field 2035 * accordingly, or uses the default if out of range and prints an error message. 2036 * 2037 * Returns: 2038 * zero on success 2039 * -EINVAL if default used 2040 **/ 2041 #define lpfc_param_init(attr, default, minval, maxval) \ 2042 static int \ 2043 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \ 2044 { \ 2045 if (lpfc_rangecheck(val, minval, maxval)) {\ 2046 phba->cfg_##attr = val;\ 2047 return 0;\ 2048 }\ 2049 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ 2050 "0449 lpfc_"#attr" attribute cannot be set to %d, "\ 2051 "allowed range is ["#minval", "#maxval"]\n", val); \ 2052 phba->cfg_##attr = default;\ 2053 return -EINVAL;\ 2054 } 2055 2056 /** 2057 * lpfc_param_set - Set a cfg attribute value 2058 * 2059 * Description: 2060 * Macro that given an attr e.g. hba_queue_depth expands 2061 * into a function with the name lpfc_hba_queue_depth_set 2062 * 2063 * lpfc_##attr##_set: Sets an attribute value. 2064 * @phba: pointer the the adapter structure. 2065 * @val: integer attribute value. 2066 * 2067 * Description: 2068 * Validates the min and max values then sets the 2069 * adapter config field if in the valid range. prints error message 2070 * and does not set the parameter if invalid. 2071 * 2072 * Returns: 2073 * zero on success 2074 * -EINVAL if val is invalid 2075 **/ 2076 #define lpfc_param_set(attr, default, minval, maxval) \ 2077 static int \ 2078 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \ 2079 { \ 2080 if (lpfc_rangecheck(val, minval, maxval)) {\ 2081 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ 2082 "3052 lpfc_" #attr " changed from %d to %d\n", \ 2083 phba->cfg_##attr, val); \ 2084 phba->cfg_##attr = val;\ 2085 return 0;\ 2086 }\ 2087 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ 2088 "0450 lpfc_"#attr" attribute cannot be set to %d, "\ 2089 "allowed range is ["#minval", "#maxval"]\n", val); \ 2090 return -EINVAL;\ 2091 } 2092 2093 /** 2094 * lpfc_param_store - Set a vport attribute value 2095 * 2096 * Description: 2097 * Macro that given an attr e.g. hba_queue_depth expands 2098 * into a function with the name lpfc_hba_queue_depth_store. 2099 * 2100 * lpfc_##attr##_store: Set an sttribute value. 2101 * @dev: class device that is converted into a Scsi_host. 2102 * @attr: device attribute, not used. 2103 * @buf: contains the attribute value in ascii. 2104 * @count: not used. 2105 * 2106 * Description: 2107 * Convert the ascii text number to an integer, then 2108 * use the lpfc_##attr##_set function to set the value. 2109 * 2110 * Returns: 2111 * -EINVAL if val is invalid or lpfc_##attr##_set() fails 2112 * length of buffer upon success. 2113 **/ 2114 #define lpfc_param_store(attr) \ 2115 static ssize_t \ 2116 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ 2117 const char *buf, size_t count) \ 2118 { \ 2119 struct Scsi_Host *shost = class_to_shost(dev);\ 2120 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 2121 struct lpfc_hba *phba = vport->phba;\ 2122 uint val = 0;\ 2123 if (!isdigit(buf[0]))\ 2124 return -EINVAL;\ 2125 if (sscanf(buf, "%i", &val) != 1)\ 2126 return -EINVAL;\ 2127 if (lpfc_##attr##_set(phba, val) == 0) \ 2128 return strlen(buf);\ 2129 else \ 2130 return -EINVAL;\ 2131 } 2132 2133 /** 2134 * lpfc_vport_param_show - Return decimal formatted cfg attribute value 2135 * 2136 * Description: 2137 * Macro that given an attr e.g. hba_queue_depth expands 2138 * into a function with the name lpfc_hba_queue_depth_show 2139 * 2140 * lpfc_##attr##_show: prints the attribute value in decimal. 2141 * @dev: class device that is converted into a Scsi_host. 2142 * @attr: device attribute, not used. 2143 * @buf: on return contains the attribute value in decimal. 2144 * 2145 * Returns: length of formatted string. 2146 **/ 2147 #define lpfc_vport_param_show(attr) \ 2148 static ssize_t \ 2149 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 2150 char *buf) \ 2151 { \ 2152 struct Scsi_Host *shost = class_to_shost(dev);\ 2153 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 2154 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ 2155 } 2156 2157 /** 2158 * lpfc_vport_param_hex_show - Return hex formatted attribute value 2159 * 2160 * Description: 2161 * Macro that given an attr e.g. 2162 * hba_queue_depth expands into a function with the name 2163 * lpfc_hba_queue_depth_show 2164 * 2165 * lpfc_##attr##_show: prints the attribute value in hexadecimal. 2166 * @dev: class device that is converted into a Scsi_host. 2167 * @attr: device attribute, not used. 2168 * @buf: on return contains the attribute value in hexadecimal. 2169 * 2170 * Returns: length of formatted string. 2171 **/ 2172 #define lpfc_vport_param_hex_show(attr) \ 2173 static ssize_t \ 2174 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ 2175 char *buf) \ 2176 { \ 2177 struct Scsi_Host *shost = class_to_shost(dev);\ 2178 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 2179 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ 2180 } 2181 2182 /** 2183 * lpfc_vport_param_init - Initialize a vport cfg attribute 2184 * 2185 * Description: 2186 * Macro that given an attr e.g. hba_queue_depth expands 2187 * into a function with the name lpfc_hba_queue_depth_init. The macro also 2188 * takes a default argument, a minimum and maximum argument. 2189 * 2190 * lpfc_##attr##_init: validates the min and max values then sets the 2191 * adapter config field accordingly, or uses the default if out of range 2192 * and prints an error message. 2193 * @phba: pointer the the adapter structure. 2194 * @val: integer attribute value. 2195 * 2196 * Returns: 2197 * zero on success 2198 * -EINVAL if default used 2199 **/ 2200 #define lpfc_vport_param_init(attr, default, minval, maxval) \ 2201 static int \ 2202 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \ 2203 { \ 2204 if (lpfc_rangecheck(val, minval, maxval)) {\ 2205 vport->cfg_##attr = val;\ 2206 return 0;\ 2207 }\ 2208 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ 2209 "0423 lpfc_"#attr" attribute cannot be set to %d, "\ 2210 "allowed range is ["#minval", "#maxval"]\n", val); \ 2211 vport->cfg_##attr = default;\ 2212 return -EINVAL;\ 2213 } 2214 2215 /** 2216 * lpfc_vport_param_set - Set a vport cfg attribute 2217 * 2218 * Description: 2219 * Macro that given an attr e.g. hba_queue_depth expands 2220 * into a function with the name lpfc_hba_queue_depth_set 2221 * 2222 * lpfc_##attr##_set: validates the min and max values then sets the 2223 * adapter config field if in the valid range. prints error message 2224 * and does not set the parameter if invalid. 2225 * @phba: pointer the the adapter structure. 2226 * @val: integer attribute value. 2227 * 2228 * Returns: 2229 * zero on success 2230 * -EINVAL if val is invalid 2231 **/ 2232 #define lpfc_vport_param_set(attr, default, minval, maxval) \ 2233 static int \ 2234 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \ 2235 { \ 2236 if (lpfc_rangecheck(val, minval, maxval)) {\ 2237 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ 2238 "3053 lpfc_" #attr \ 2239 " changed from %d (x%x) to %d (x%x)\n", \ 2240 vport->cfg_##attr, vport->cfg_##attr, \ 2241 val, val); \ 2242 vport->cfg_##attr = val;\ 2243 return 0;\ 2244 }\ 2245 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ 2246 "0424 lpfc_"#attr" attribute cannot be set to %d, "\ 2247 "allowed range is ["#minval", "#maxval"]\n", val); \ 2248 return -EINVAL;\ 2249 } 2250 2251 /** 2252 * lpfc_vport_param_store - Set a vport attribute 2253 * 2254 * Description: 2255 * Macro that given an attr e.g. hba_queue_depth 2256 * expands into a function with the name lpfc_hba_queue_depth_store 2257 * 2258 * lpfc_##attr##_store: convert the ascii text number to an integer, then 2259 * use the lpfc_##attr##_set function to set the value. 2260 * @cdev: class device that is converted into a Scsi_host. 2261 * @buf: contains the attribute value in decimal. 2262 * @count: not used. 2263 * 2264 * Returns: 2265 * -EINVAL if val is invalid or lpfc_##attr##_set() fails 2266 * length of buffer upon success. 2267 **/ 2268 #define lpfc_vport_param_store(attr) \ 2269 static ssize_t \ 2270 lpfc_##attr##_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 uint val = 0;\ 2276 if (!isdigit(buf[0]))\ 2277 return -EINVAL;\ 2278 if (sscanf(buf, "%i", &val) != 1)\ 2279 return -EINVAL;\ 2280 if (lpfc_##attr##_set(vport, val) == 0) \ 2281 return strlen(buf);\ 2282 else \ 2283 return -EINVAL;\ 2284 } 2285 2286 2287 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL); 2288 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL); 2289 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL); 2290 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL); 2291 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL); 2292 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); 2293 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); 2294 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); 2295 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); 2296 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); 2297 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL); 2298 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); 2299 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); 2300 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show, 2301 lpfc_link_state_store); 2302 static DEVICE_ATTR(option_rom_version, S_IRUGO, 2303 lpfc_option_rom_version_show, NULL); 2304 static DEVICE_ATTR(num_discovered_ports, S_IRUGO, 2305 lpfc_num_discovered_ports_show, NULL); 2306 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL); 2307 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); 2308 static DEVICE_ATTR_RO(lpfc_drvr_version); 2309 static DEVICE_ATTR_RO(lpfc_enable_fip); 2310 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, 2311 lpfc_board_mode_show, lpfc_board_mode_store); 2312 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); 2313 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL); 2314 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL); 2315 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL); 2316 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL); 2317 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL); 2318 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL); 2319 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL); 2320 static DEVICE_ATTR_RO(lpfc_temp_sensor); 2321 static DEVICE_ATTR_RO(lpfc_fips_level); 2322 static DEVICE_ATTR_RO(lpfc_fips_rev); 2323 static DEVICE_ATTR_RO(lpfc_dss); 2324 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn); 2325 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL); 2326 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show, 2327 NULL); 2328 2329 static char *lpfc_soft_wwn_key = "C99G71SL8032A"; 2330 #define WWN_SZ 8 2331 /** 2332 * lpfc_wwn_set - Convert string to the 8 byte WWN value. 2333 * @buf: WWN string. 2334 * @cnt: Length of string. 2335 * @wwn: Array to receive converted wwn value. 2336 * 2337 * Returns: 2338 * -EINVAL if the buffer does not contain a valid wwn 2339 * 0 success 2340 **/ 2341 static size_t 2342 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[]) 2343 { 2344 unsigned int i, j; 2345 2346 /* Count may include a LF at end of string */ 2347 if (buf[cnt-1] == '\n') 2348 cnt--; 2349 2350 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) || 2351 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) 2352 return -EINVAL; 2353 2354 memset(wwn, 0, WWN_SZ); 2355 2356 /* Validate and store the new name */ 2357 for (i = 0, j = 0; i < 16; i++) { 2358 if ((*buf >= 'a') && (*buf <= 'f')) 2359 j = ((j << 4) | ((*buf++ - 'a') + 10)); 2360 else if ((*buf >= 'A') && (*buf <= 'F')) 2361 j = ((j << 4) | ((*buf++ - 'A') + 10)); 2362 else if ((*buf >= '0') && (*buf <= '9')) 2363 j = ((j << 4) | (*buf++ - '0')); 2364 else 2365 return -EINVAL; 2366 if (i % 2) { 2367 wwn[i/2] = j & 0xff; 2368 j = 0; 2369 } 2370 } 2371 return 0; 2372 } 2373 /** 2374 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid 2375 * @dev: class device that is converted into a Scsi_host. 2376 * @attr: device attribute, not used. 2377 * @buf: containing the string lpfc_soft_wwn_key. 2378 * @count: must be size of lpfc_soft_wwn_key. 2379 * 2380 * Returns: 2381 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key 2382 * length of buf indicates success 2383 **/ 2384 static ssize_t 2385 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr, 2386 const char *buf, size_t count) 2387 { 2388 struct Scsi_Host *shost = class_to_shost(dev); 2389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2390 struct lpfc_hba *phba = vport->phba; 2391 unsigned int cnt = count; 2392 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; 2393 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0]; 2394 2395 /* 2396 * We're doing a simple sanity check for soft_wwpn setting. 2397 * We require that the user write a specific key to enable 2398 * the soft_wwpn attribute to be settable. Once the attribute 2399 * is written, the enable key resets. If further updates are 2400 * desired, the key must be written again to re-enable the 2401 * attribute. 2402 * 2403 * The "key" is not secret - it is a hardcoded string shown 2404 * here. The intent is to protect against the random user or 2405 * application that is just writing attributes. 2406 */ 2407 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) { 2408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2409 "0051 "LPFC_DRIVER_NAME" soft wwpn can not" 2410 " be enabled: fawwpn is enabled\n"); 2411 return -EINVAL; 2412 } 2413 2414 /* count may include a LF at end of string */ 2415 if (buf[cnt-1] == '\n') 2416 cnt--; 2417 2418 if ((cnt != strlen(lpfc_soft_wwn_key)) || 2419 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0)) 2420 return -EINVAL; 2421 2422 phba->soft_wwn_enable = 1; 2423 2424 dev_printk(KERN_WARNING, &phba->pcidev->dev, 2425 "lpfc%d: soft_wwpn assignment has been enabled.\n", 2426 phba->brd_no); 2427 dev_printk(KERN_WARNING, &phba->pcidev->dev, 2428 " The soft_wwpn feature is not supported by Broadcom."); 2429 2430 return count; 2431 } 2432 static DEVICE_ATTR_WO(lpfc_soft_wwn_enable); 2433 2434 /** 2435 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter 2436 * @dev: class device that is converted into a Scsi_host. 2437 * @attr: device attribute, not used. 2438 * @buf: on return contains the wwpn in hexadecimal. 2439 * 2440 * Returns: size of formatted string. 2441 **/ 2442 static ssize_t 2443 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr, 2444 char *buf) 2445 { 2446 struct Scsi_Host *shost = class_to_shost(dev); 2447 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2448 struct lpfc_hba *phba = vport->phba; 2449 2450 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 2451 (unsigned long long)phba->cfg_soft_wwpn); 2452 } 2453 2454 /** 2455 * lpfc_soft_wwpn_store - Set the ww port name of the adapter 2456 * @dev class device that is converted into a Scsi_host. 2457 * @attr: device attribute, not used. 2458 * @buf: contains the wwpn in hexadecimal. 2459 * @count: number of wwpn bytes in buf 2460 * 2461 * Returns: 2462 * -EACCES hba reset not enabled, adapter over temp 2463 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid 2464 * -EIO error taking adapter offline or online 2465 * value of count on success 2466 **/ 2467 static ssize_t 2468 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr, 2469 const char *buf, size_t count) 2470 { 2471 struct Scsi_Host *shost = class_to_shost(dev); 2472 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2473 struct lpfc_hba *phba = vport->phba; 2474 struct completion online_compl; 2475 int stat1 = 0, stat2 = 0; 2476 unsigned int cnt = count; 2477 u8 wwpn[WWN_SZ]; 2478 int rc; 2479 2480 if (!phba->cfg_enable_hba_reset) 2481 return -EACCES; 2482 spin_lock_irq(&phba->hbalock); 2483 if (phba->over_temp_state == HBA_OVER_TEMP) { 2484 spin_unlock_irq(&phba->hbalock); 2485 return -EACCES; 2486 } 2487 spin_unlock_irq(&phba->hbalock); 2488 /* count may include a LF at end of string */ 2489 if (buf[cnt-1] == '\n') 2490 cnt--; 2491 2492 if (!phba->soft_wwn_enable) 2493 return -EINVAL; 2494 2495 /* lock setting wwpn, wwnn down */ 2496 phba->soft_wwn_enable = 0; 2497 2498 rc = lpfc_wwn_set(buf, cnt, wwpn); 2499 if (rc) { 2500 /* not able to set wwpn, unlock it */ 2501 phba->soft_wwn_enable = 1; 2502 return rc; 2503 } 2504 2505 phba->cfg_soft_wwpn = wwn_to_u64(wwpn); 2506 fc_host_port_name(shost) = phba->cfg_soft_wwpn; 2507 if (phba->cfg_soft_wwnn) 2508 fc_host_node_name(shost) = phba->cfg_soft_wwnn; 2509 2510 dev_printk(KERN_NOTICE, &phba->pcidev->dev, 2511 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); 2512 2513 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); 2514 if (stat1) 2515 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2516 "0463 lpfc_soft_wwpn attribute set failed to " 2517 "reinit adapter - %d\n", stat1); 2518 init_completion(&online_compl); 2519 rc = lpfc_workq_post_event(phba, &stat2, &online_compl, 2520 LPFC_EVT_ONLINE); 2521 if (rc == 0) 2522 return -ENOMEM; 2523 2524 wait_for_completion(&online_compl); 2525 if (stat2) 2526 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2527 "0464 lpfc_soft_wwpn attribute set failed to " 2528 "reinit adapter - %d\n", stat2); 2529 return (stat1 || stat2) ? -EIO : count; 2530 } 2531 static DEVICE_ATTR_RW(lpfc_soft_wwpn); 2532 2533 /** 2534 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter 2535 * @dev: class device that is converted into a Scsi_host. 2536 * @attr: device attribute, not used. 2537 * @buf: on return contains the wwnn in hexadecimal. 2538 * 2539 * Returns: size of formatted string. 2540 **/ 2541 static ssize_t 2542 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr, 2543 char *buf) 2544 { 2545 struct Scsi_Host *shost = class_to_shost(dev); 2546 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2547 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 2548 (unsigned long long)phba->cfg_soft_wwnn); 2549 } 2550 2551 /** 2552 * lpfc_soft_wwnn_store - sets the ww node name of the adapter 2553 * @cdev: class device that is converted into a Scsi_host. 2554 * @buf: contains the ww node name in hexadecimal. 2555 * @count: number of wwnn bytes in buf. 2556 * 2557 * Returns: 2558 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid 2559 * value of count on success 2560 **/ 2561 static ssize_t 2562 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr, 2563 const char *buf, size_t count) 2564 { 2565 struct Scsi_Host *shost = class_to_shost(dev); 2566 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2567 unsigned int cnt = count; 2568 u8 wwnn[WWN_SZ]; 2569 int rc; 2570 2571 /* count may include a LF at end of string */ 2572 if (buf[cnt-1] == '\n') 2573 cnt--; 2574 2575 if (!phba->soft_wwn_enable) 2576 return -EINVAL; 2577 2578 rc = lpfc_wwn_set(buf, cnt, wwnn); 2579 if (rc) { 2580 /* Allow wwnn to be set many times, as long as the enable 2581 * is set. However, once the wwpn is set, everything locks. 2582 */ 2583 return rc; 2584 } 2585 2586 phba->cfg_soft_wwnn = wwn_to_u64(wwnn); 2587 2588 dev_printk(KERN_NOTICE, &phba->pcidev->dev, 2589 "lpfc%d: soft_wwnn set. Value will take effect upon " 2590 "setting of the soft_wwpn\n", phba->brd_no); 2591 2592 return count; 2593 } 2594 static DEVICE_ATTR_RW(lpfc_soft_wwnn); 2595 2596 /** 2597 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for 2598 * Optimized Access Storage (OAS) operations. 2599 * @dev: class device that is converted into a Scsi_host. 2600 * @attr: device attribute, not used. 2601 * @buf: buffer for passing information. 2602 * 2603 * Returns: 2604 * value of count 2605 **/ 2606 static ssize_t 2607 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr, 2608 char *buf) 2609 { 2610 struct Scsi_Host *shost = class_to_shost(dev); 2611 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2612 2613 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 2614 wwn_to_u64(phba->cfg_oas_tgt_wwpn)); 2615 } 2616 2617 /** 2618 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for 2619 * Optimized Access Storage (OAS) operations. 2620 * @dev: class device that is converted into a Scsi_host. 2621 * @attr: device attribute, not used. 2622 * @buf: buffer for passing information. 2623 * @count: Size of the data buffer. 2624 * 2625 * Returns: 2626 * -EINVAL count is invalid, invalid wwpn byte invalid 2627 * -EPERM oas is not supported by hba 2628 * value of count on success 2629 **/ 2630 static ssize_t 2631 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr, 2632 const char *buf, size_t count) 2633 { 2634 struct Scsi_Host *shost = class_to_shost(dev); 2635 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2636 unsigned int cnt = count; 2637 uint8_t wwpn[WWN_SZ]; 2638 int rc; 2639 2640 if (!phba->cfg_fof) 2641 return -EPERM; 2642 2643 /* count may include a LF at end of string */ 2644 if (buf[cnt-1] == '\n') 2645 cnt--; 2646 2647 rc = lpfc_wwn_set(buf, cnt, wwpn); 2648 if (rc) 2649 return rc; 2650 2651 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t))); 2652 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t))); 2653 if (wwn_to_u64(wwpn) == 0) 2654 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET; 2655 else 2656 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET; 2657 phba->cfg_oas_flags &= ~OAS_LUN_VALID; 2658 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN; 2659 return count; 2660 } 2661 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR, 2662 lpfc_oas_tgt_show, lpfc_oas_tgt_store); 2663 2664 /** 2665 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for 2666 * Optimized Access Storage (OAS) operations. 2667 * @dev: class device that is converted into a Scsi_host. 2668 * @attr: device attribute, not used. 2669 * @buf: buffer for passing information. 2670 * 2671 * Returns: 2672 * value of count 2673 **/ 2674 static ssize_t 2675 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr, 2676 char *buf) 2677 { 2678 struct Scsi_Host *shost = class_to_shost(dev); 2679 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2680 2681 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority); 2682 } 2683 2684 /** 2685 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for 2686 * Optimized Access Storage (OAS) operations. 2687 * @dev: class device that is converted into a Scsi_host. 2688 * @attr: device attribute, not used. 2689 * @buf: buffer for passing information. 2690 * @count: Size of the data buffer. 2691 * 2692 * Returns: 2693 * -EINVAL count is invalid, invalid wwpn byte invalid 2694 * -EPERM oas is not supported by hba 2695 * value of count on success 2696 **/ 2697 static ssize_t 2698 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr, 2699 const char *buf, size_t count) 2700 { 2701 struct Scsi_Host *shost = class_to_shost(dev); 2702 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2703 unsigned int cnt = count; 2704 unsigned long val; 2705 int ret; 2706 2707 if (!phba->cfg_fof) 2708 return -EPERM; 2709 2710 /* count may include a LF at end of string */ 2711 if (buf[cnt-1] == '\n') 2712 cnt--; 2713 2714 ret = kstrtoul(buf, 0, &val); 2715 if (ret || (val > 0x7f)) 2716 return -EINVAL; 2717 2718 if (val) 2719 phba->cfg_oas_priority = (uint8_t)val; 2720 else 2721 phba->cfg_oas_priority = phba->cfg_XLanePriority; 2722 return count; 2723 } 2724 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR, 2725 lpfc_oas_priority_show, lpfc_oas_priority_store); 2726 2727 /** 2728 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled 2729 * for Optimized Access Storage (OAS) operations. 2730 * @dev: class device that is converted into a Scsi_host. 2731 * @attr: device attribute, not used. 2732 * @buf: buffer for passing information. 2733 * 2734 * Returns: 2735 * value of count on success 2736 **/ 2737 static ssize_t 2738 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr, 2739 char *buf) 2740 { 2741 struct Scsi_Host *shost = class_to_shost(dev); 2742 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2743 2744 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 2745 wwn_to_u64(phba->cfg_oas_vpt_wwpn)); 2746 } 2747 2748 /** 2749 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled 2750 * for Optimized Access Storage (OAS) operations. 2751 * @dev: class device that is converted into a Scsi_host. 2752 * @attr: device attribute, not used. 2753 * @buf: buffer for passing information. 2754 * @count: Size of the data buffer. 2755 * 2756 * Returns: 2757 * -EINVAL count is invalid, invalid wwpn byte invalid 2758 * -EPERM oas is not supported by hba 2759 * value of count on success 2760 **/ 2761 static ssize_t 2762 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr, 2763 const char *buf, size_t count) 2764 { 2765 struct Scsi_Host *shost = class_to_shost(dev); 2766 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2767 unsigned int cnt = count; 2768 uint8_t wwpn[WWN_SZ]; 2769 int rc; 2770 2771 if (!phba->cfg_fof) 2772 return -EPERM; 2773 2774 /* count may include a LF at end of string */ 2775 if (buf[cnt-1] == '\n') 2776 cnt--; 2777 2778 rc = lpfc_wwn_set(buf, cnt, wwpn); 2779 if (rc) 2780 return rc; 2781 2782 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t))); 2783 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t))); 2784 if (wwn_to_u64(wwpn) == 0) 2785 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT; 2786 else 2787 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT; 2788 phba->cfg_oas_flags &= ~OAS_LUN_VALID; 2789 if (phba->cfg_oas_priority == 0) 2790 phba->cfg_oas_priority = phba->cfg_XLanePriority; 2791 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN; 2792 return count; 2793 } 2794 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR, 2795 lpfc_oas_vpt_show, lpfc_oas_vpt_store); 2796 2797 /** 2798 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled) 2799 * of whether luns will be enabled or disabled 2800 * for Optimized Access Storage (OAS) operations. 2801 * @dev: class device that is converted into a Scsi_host. 2802 * @attr: device attribute, not used. 2803 * @buf: buffer for passing information. 2804 * 2805 * Returns: 2806 * size of formatted string. 2807 **/ 2808 static ssize_t 2809 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr, 2810 char *buf) 2811 { 2812 struct Scsi_Host *shost = class_to_shost(dev); 2813 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2814 2815 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state); 2816 } 2817 2818 /** 2819 * lpfc_oas_lun_state_store - Store the state (enabled or disabled) 2820 * of whether luns will be enabled or disabled 2821 * for Optimized Access Storage (OAS) operations. 2822 * @dev: class device that is converted into a Scsi_host. 2823 * @attr: device attribute, not used. 2824 * @buf: buffer for passing information. 2825 * @count: Size of the data buffer. 2826 * 2827 * Returns: 2828 * -EINVAL count is invalid, invalid wwpn byte invalid 2829 * -EPERM oas is not supported by hba 2830 * value of count on success 2831 **/ 2832 static ssize_t 2833 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr, 2834 const char *buf, size_t count) 2835 { 2836 struct Scsi_Host *shost = class_to_shost(dev); 2837 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2838 int val = 0; 2839 2840 if (!phba->cfg_fof) 2841 return -EPERM; 2842 2843 if (!isdigit(buf[0])) 2844 return -EINVAL; 2845 2846 if (sscanf(buf, "%i", &val) != 1) 2847 return -EINVAL; 2848 2849 if ((val != 0) && (val != 1)) 2850 return -EINVAL; 2851 2852 phba->cfg_oas_lun_state = val; 2853 return strlen(buf); 2854 } 2855 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR, 2856 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store); 2857 2858 /** 2859 * lpfc_oas_lun_status_show - Return the status of the Optimized Access 2860 * Storage (OAS) lun returned by the 2861 * lpfc_oas_lun_show function. 2862 * @dev: class device that is converted into a Scsi_host. 2863 * @attr: device attribute, not used. 2864 * @buf: buffer for passing information. 2865 * 2866 * Returns: 2867 * size of formatted string. 2868 **/ 2869 static ssize_t 2870 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr, 2871 char *buf) 2872 { 2873 struct Scsi_Host *shost = class_to_shost(dev); 2874 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 2875 2876 if (!(phba->cfg_oas_flags & OAS_LUN_VALID)) 2877 return -EFAULT; 2878 2879 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status); 2880 } 2881 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO, 2882 lpfc_oas_lun_status_show, NULL); 2883 2884 2885 /** 2886 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage 2887 * (OAS) operations. 2888 * @phba: lpfc_hba pointer. 2889 * @ndlp: pointer to fcp target node. 2890 * @lun: the fc lun for setting oas state. 2891 * @oas_state: the oas state to be set to the lun. 2892 * 2893 * Returns: 2894 * SUCCESS : 0 2895 * -EPERM OAS is not enabled or not supported by this port. 2896 * 2897 */ 2898 static size_t 2899 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[], 2900 uint8_t tgt_wwpn[], uint64_t lun, 2901 uint32_t oas_state, uint8_t pri) 2902 { 2903 2904 int rc = 0; 2905 2906 if (!phba->cfg_fof) 2907 return -EPERM; 2908 2909 if (oas_state) { 2910 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn, 2911 (struct lpfc_name *)tgt_wwpn, 2912 lun, pri)) 2913 rc = -ENOMEM; 2914 } else { 2915 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn, 2916 (struct lpfc_name *)tgt_wwpn, lun, pri); 2917 } 2918 return rc; 2919 2920 } 2921 2922 /** 2923 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized 2924 * Access Storage (OAS) operations. 2925 * @phba: lpfc_hba pointer. 2926 * @vpt_wwpn: wwpn of the vport associated with the returned lun 2927 * @tgt_wwpn: wwpn of the target associated with the returned lun 2928 * @lun_status: status of the lun returned lun 2929 * 2930 * Returns the first or next lun enabled for OAS operations for the vport/target 2931 * specified. If a lun is found, its vport wwpn, target wwpn and status is 2932 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned. 2933 * 2934 * Return: 2935 * lun that is OAS enabled for the vport/target 2936 * NOT_OAS_ENABLED_LUN when no oas enabled lun found. 2937 */ 2938 static uint64_t 2939 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[], 2940 uint8_t tgt_wwpn[], uint32_t *lun_status, 2941 uint32_t *lun_pri) 2942 { 2943 uint64_t found_lun; 2944 2945 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn) 2946 return NOT_OAS_ENABLED_LUN; 2947 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *) 2948 phba->sli4_hba.oas_next_vpt_wwpn, 2949 (struct lpfc_name *) 2950 phba->sli4_hba.oas_next_tgt_wwpn, 2951 &phba->sli4_hba.oas_next_lun, 2952 (struct lpfc_name *)vpt_wwpn, 2953 (struct lpfc_name *)tgt_wwpn, 2954 &found_lun, lun_status, lun_pri)) 2955 return found_lun; 2956 else 2957 return NOT_OAS_ENABLED_LUN; 2958 } 2959 2960 /** 2961 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations 2962 * @phba: lpfc_hba pointer. 2963 * @vpt_wwpn: vport wwpn by reference. 2964 * @tgt_wwpn: target wwpn by reference. 2965 * @lun: the fc lun for setting oas state. 2966 * @oas_state: the oas state to be set to the oas_lun. 2967 * 2968 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE) 2969 * a lun for OAS operations. 2970 * 2971 * Return: 2972 * SUCCESS: 0 2973 * -ENOMEM: failed to enable an lun for OAS operations 2974 * -EPERM: OAS is not enabled 2975 */ 2976 static ssize_t 2977 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[], 2978 uint8_t tgt_wwpn[], uint64_t lun, 2979 uint32_t oas_state, uint8_t pri) 2980 { 2981 2982 int rc; 2983 2984 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun, 2985 oas_state, pri); 2986 return rc; 2987 } 2988 2989 /** 2990 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target 2991 * @dev: class device that is converted into a Scsi_host. 2992 * @attr: device attribute, not used. 2993 * @buf: buffer for passing information. 2994 * 2995 * This routine returns a lun enabled for OAS each time the function 2996 * is called. 2997 * 2998 * Returns: 2999 * SUCCESS: size of formatted string. 3000 * -EFAULT: target or vport wwpn was not set properly. 3001 * -EPERM: oas is not enabled. 3002 **/ 3003 static ssize_t 3004 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr, 3005 char *buf) 3006 { 3007 struct Scsi_Host *shost = class_to_shost(dev); 3008 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 3009 3010 uint64_t oas_lun; 3011 int len = 0; 3012 3013 if (!phba->cfg_fof) 3014 return -EPERM; 3015 3016 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0) 3017 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)) 3018 return -EFAULT; 3019 3020 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0) 3021 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET)) 3022 return -EFAULT; 3023 3024 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn, 3025 phba->cfg_oas_tgt_wwpn, 3026 &phba->cfg_oas_lun_status, 3027 &phba->cfg_oas_priority); 3028 if (oas_lun != NOT_OAS_ENABLED_LUN) 3029 phba->cfg_oas_flags |= OAS_LUN_VALID; 3030 3031 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun); 3032 3033 return len; 3034 } 3035 3036 /** 3037 * lpfc_oas_lun_store - Sets the OAS state for lun 3038 * @dev: class device that is converted into a Scsi_host. 3039 * @attr: device attribute, not used. 3040 * @buf: buffer for passing information. 3041 * 3042 * This function sets the OAS state for lun. Before this function is called, 3043 * the vport wwpn, target wwpn, and oas state need to be set. 3044 * 3045 * Returns: 3046 * SUCCESS: size of formatted string. 3047 * -EFAULT: target or vport wwpn was not set properly. 3048 * -EPERM: oas is not enabled. 3049 * size of formatted string. 3050 **/ 3051 static ssize_t 3052 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr, 3053 const char *buf, size_t count) 3054 { 3055 struct Scsi_Host *shost = class_to_shost(dev); 3056 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; 3057 uint64_t scsi_lun; 3058 uint32_t pri; 3059 ssize_t rc; 3060 3061 if (!phba->cfg_fof) 3062 return -EPERM; 3063 3064 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0) 3065 return -EFAULT; 3066 3067 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0) 3068 return -EFAULT; 3069 3070 if (!isdigit(buf[0])) 3071 return -EINVAL; 3072 3073 if (sscanf(buf, "0x%llx", &scsi_lun) != 1) 3074 return -EINVAL; 3075 3076 pri = phba->cfg_oas_priority; 3077 if (pri == 0) 3078 pri = phba->cfg_XLanePriority; 3079 3080 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 3081 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx " 3082 "priority 0x%x with oas state %d\n", 3083 wwn_to_u64(phba->cfg_oas_vpt_wwpn), 3084 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun, 3085 pri, phba->cfg_oas_lun_state); 3086 3087 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn, 3088 phba->cfg_oas_tgt_wwpn, scsi_lun, 3089 phba->cfg_oas_lun_state, pri); 3090 if (rc) 3091 return rc; 3092 3093 return count; 3094 } 3095 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR, 3096 lpfc_oas_lun_show, lpfc_oas_lun_store); 3097 3098 int lpfc_enable_nvmet_cnt; 3099 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = { 3100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 3102 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444); 3103 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target"); 3104 3105 static int lpfc_poll = 0; 3106 module_param(lpfc_poll, int, S_IRUGO); 3107 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" 3108 " 0 - none," 3109 " 1 - poll with interrupts enabled" 3110 " 3 - poll and disable FCP ring interrupts"); 3111 3112 static DEVICE_ATTR_RW(lpfc_poll); 3113 3114 int lpfc_no_hba_reset_cnt; 3115 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = { 3116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 3117 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444); 3118 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset"); 3119 3120 LPFC_ATTR(sli_mode, 0, 0, 3, 3121 "SLI mode selector:" 3122 " 0 - auto (SLI-3 if supported)," 3123 " 2 - select SLI-2 even on SLI-3 capable HBAs," 3124 " 3 - select SLI-3"); 3125 3126 LPFC_ATTR_R(enable_npiv, 1, 0, 1, 3127 "Enable NPIV functionality"); 3128 3129 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2, 3130 "FCF Fast failover=1 Priority failover=2"); 3131 3132 /* 3133 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures 3134 # 0x0 = disabled, XRI/OXID use not tracked. 3135 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent. 3136 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent. 3137 */ 3138 LPFC_ATTR_R(enable_rrq, 2, 0, 2, 3139 "Enable RRQ functionality"); 3140 3141 /* 3142 # lpfc_suppress_link_up: Bring link up at initialization 3143 # 0x0 = bring link up (issue MBX_INIT_LINK) 3144 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK) 3145 # 0x2 = never bring up link 3146 # Default value is 0. 3147 */ 3148 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK, 3149 LPFC_DELAY_INIT_LINK_INDEFINITELY, 3150 "Suppress Link Up at initialization"); 3151 /* 3152 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS 3153 # 1 - (1024) 3154 # 2 - (2048) 3155 # 3 - (3072) 3156 # 4 - (4096) 3157 # 5 - (5120) 3158 */ 3159 static ssize_t 3160 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf) 3161 { 3162 struct Scsi_Host *shost = class_to_shost(dev); 3163 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; 3164 3165 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max); 3166 } 3167 3168 static DEVICE_ATTR(iocb_hw, S_IRUGO, 3169 lpfc_iocb_hw_show, NULL); 3170 static ssize_t 3171 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf) 3172 { 3173 struct Scsi_Host *shost = class_to_shost(dev); 3174 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; 3175 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba); 3176 3177 return snprintf(buf, PAGE_SIZE, "%d\n", 3178 pring ? pring->txq_max : 0); 3179 } 3180 3181 static DEVICE_ATTR(txq_hw, S_IRUGO, 3182 lpfc_txq_hw_show, NULL); 3183 static ssize_t 3184 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr, 3185 char *buf) 3186 { 3187 struct Scsi_Host *shost = class_to_shost(dev); 3188 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; 3189 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba); 3190 3191 return snprintf(buf, PAGE_SIZE, "%d\n", 3192 pring ? pring->txcmplq_max : 0); 3193 } 3194 3195 static DEVICE_ATTR(txcmplq_hw, S_IRUGO, 3196 lpfc_txcmplq_hw_show, NULL); 3197 3198 LPFC_ATTR_R(iocb_cnt, 2, 1, 5, 3199 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs"); 3200 3201 /* 3202 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear 3203 # until the timer expires. Value range is [0,255]. Default value is 30. 3204 */ 3205 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; 3206 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO; 3207 module_param(lpfc_nodev_tmo, int, 0); 3208 MODULE_PARM_DESC(lpfc_nodev_tmo, 3209 "Seconds driver will hold I/O waiting " 3210 "for a device to come back"); 3211 3212 /** 3213 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value 3214 * @dev: class converted to a Scsi_host structure. 3215 * @attr: device attribute, not used. 3216 * @buf: on return contains the dev loss timeout in decimal. 3217 * 3218 * Returns: size of formatted string. 3219 **/ 3220 static ssize_t 3221 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr, 3222 char *buf) 3223 { 3224 struct Scsi_Host *shost = class_to_shost(dev); 3225 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3226 3227 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo); 3228 } 3229 3230 /** 3231 * lpfc_nodev_tmo_init - Set the hba nodev timeout value 3232 * @vport: lpfc vport structure pointer. 3233 * @val: contains the nodev timeout value. 3234 * 3235 * Description: 3236 * If the devloss tmo is already set then nodev tmo is set to devloss tmo, 3237 * a kernel error message is printed and zero is returned. 3238 * Else if val is in range then nodev tmo and devloss tmo are set to val. 3239 * Otherwise nodev tmo is set to the default value. 3240 * 3241 * Returns: 3242 * zero if already set or if val is in range 3243 * -EINVAL val out of range 3244 **/ 3245 static int 3246 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val) 3247 { 3248 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) { 3249 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo; 3250 if (val != LPFC_DEF_DEVLOSS_TMO) 3251 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3252 "0407 Ignoring lpfc_nodev_tmo module " 3253 "parameter because lpfc_devloss_tmo " 3254 "is set.\n"); 3255 return 0; 3256 } 3257 3258 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { 3259 vport->cfg_nodev_tmo = val; 3260 vport->cfg_devloss_tmo = val; 3261 return 0; 3262 } 3263 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3264 "0400 lpfc_nodev_tmo attribute cannot be set to" 3265 " %d, allowed range is [%d, %d]\n", 3266 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); 3267 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; 3268 return -EINVAL; 3269 } 3270 3271 /** 3272 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value 3273 * @vport: lpfc vport structure pointer. 3274 * 3275 * Description: 3276 * Update all the ndlp's dev loss tmo with the vport devloss tmo value. 3277 **/ 3278 static void 3279 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport) 3280 { 3281 struct Scsi_Host *shost; 3282 struct lpfc_nodelist *ndlp; 3283 3284 shost = lpfc_shost_from_vport(vport); 3285 spin_lock_irq(shost->host_lock); 3286 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 3287 if (!NLP_CHK_NODE_ACT(ndlp)) 3288 continue; 3289 if (ndlp->rport) 3290 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo; 3291 #if (IS_ENABLED(CONFIG_NVME_FC)) 3292 if (ndlp->nrport) 3293 nvme_fc_set_remoteport_devloss(ndlp->nrport->remoteport, 3294 vport->cfg_devloss_tmo); 3295 #endif 3296 } 3297 spin_unlock_irq(shost->host_lock); 3298 } 3299 3300 /** 3301 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values 3302 * @vport: lpfc vport structure pointer. 3303 * @val: contains the tmo value. 3304 * 3305 * Description: 3306 * If the devloss tmo is already set or the vport dev loss tmo has changed 3307 * then a kernel error message is printed and zero is returned. 3308 * Else if val is in range then nodev tmo and devloss tmo are set to val. 3309 * Otherwise nodev tmo is set to the default value. 3310 * 3311 * Returns: 3312 * zero if already set or if val is in range 3313 * -EINVAL val out of range 3314 **/ 3315 static int 3316 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val) 3317 { 3318 if (vport->dev_loss_tmo_changed || 3319 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) { 3320 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3321 "0401 Ignoring change to lpfc_nodev_tmo " 3322 "because lpfc_devloss_tmo is set.\n"); 3323 return 0; 3324 } 3325 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { 3326 vport->cfg_nodev_tmo = val; 3327 vport->cfg_devloss_tmo = val; 3328 /* 3329 * For compat: set the fc_host dev loss so new rports 3330 * will get the value. 3331 */ 3332 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; 3333 lpfc_update_rport_devloss_tmo(vport); 3334 return 0; 3335 } 3336 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3337 "0403 lpfc_nodev_tmo attribute cannot be set to " 3338 "%d, allowed range is [%d, %d]\n", 3339 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); 3340 return -EINVAL; 3341 } 3342 3343 lpfc_vport_param_store(nodev_tmo) 3344 3345 static DEVICE_ATTR_RW(lpfc_nodev_tmo); 3346 3347 /* 3348 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that 3349 # disappear until the timer expires. Value range is [0,255]. Default 3350 # value is 30. 3351 */ 3352 module_param(lpfc_devloss_tmo, int, S_IRUGO); 3353 MODULE_PARM_DESC(lpfc_devloss_tmo, 3354 "Seconds driver will hold I/O waiting " 3355 "for a device to come back"); 3356 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, 3357 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) 3358 lpfc_vport_param_show(devloss_tmo) 3359 3360 /** 3361 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit 3362 * @vport: lpfc vport structure pointer. 3363 * @val: contains the tmo value. 3364 * 3365 * Description: 3366 * If val is in a valid range then set the vport nodev tmo, 3367 * devloss tmo, also set the vport dev loss tmo changed flag. 3368 * Else a kernel error message is printed. 3369 * 3370 * Returns: 3371 * zero if val is in range 3372 * -EINVAL val out of range 3373 **/ 3374 static int 3375 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val) 3376 { 3377 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { 3378 vport->cfg_nodev_tmo = val; 3379 vport->cfg_devloss_tmo = val; 3380 vport->dev_loss_tmo_changed = 1; 3381 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; 3382 lpfc_update_rport_devloss_tmo(vport); 3383 return 0; 3384 } 3385 3386 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3387 "0404 lpfc_devloss_tmo attribute cannot be set to " 3388 "%d, allowed range is [%d, %d]\n", 3389 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); 3390 return -EINVAL; 3391 } 3392 3393 lpfc_vport_param_store(devloss_tmo) 3394 static DEVICE_ATTR_RW(lpfc_devloss_tmo); 3395 3396 /* 3397 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it 3398 * lpfc_suppress_rsp = 0 Disable 3399 * lpfc_suppress_rsp = 1 Enable (default) 3400 * 3401 */ 3402 LPFC_ATTR_R(suppress_rsp, 1, 0, 1, 3403 "Enable suppress rsp feature is firmware supports it"); 3404 3405 /* 3406 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds 3407 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs 3408 * lpfc_nvmet_mrq = 1 use a single RQ pair 3409 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ 3410 * 3411 */ 3412 LPFC_ATTR_R(nvmet_mrq, 3413 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX, 3414 "Specify number of RQ pairs for processing NVMET cmds"); 3415 3416 /* 3417 * lpfc_enable_fc4_type: Defines what FC4 types are supported. 3418 * Supported Values: 1 - register just FCP 3419 * 3 - register both FCP and NVME 3420 * Supported values are [1,3]. Default value is 1 3421 */ 3422 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP, 3423 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH, 3424 "Enable FC4 Protocol support - FCP / NVME"); 3425 3426 /* 3427 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME 3428 * This parameter is only used if: 3429 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and 3430 * port is not configured for NVMET. 3431 * 3432 * ELS/CT always get 10% of XRIs, up to a maximum of 250 3433 * The remaining XRIs get split up based on lpfc_xri_split per port: 3434 * 3435 * Supported Values are in percentages 3436 * the xri_split value is the percentage the SCSI port will get. The remaining 3437 * percentage will go to NVME. 3438 */ 3439 LPFC_ATTR_R(xri_split, 50, 10, 90, 3440 "Percentage of FCP XRI resources versus NVME"); 3441 3442 /* 3443 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being 3444 # deluged with LOTS of information. 3445 # You can set a bit mask to record specific types of verbose messages: 3446 # See lpfc_logmsh.h for definitions. 3447 */ 3448 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff, 3449 "Verbose logging bit-mask"); 3450 3451 /* 3452 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters 3453 # objects that have been registered with the nameserver after login. 3454 */ 3455 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1, 3456 "Deregister nameserver objects before LOGO"); 3457 3458 /* 3459 # lun_queue_depth: This parameter is used to limit the number of outstanding 3460 # commands per FCP LUN. Value range is [1,512]. Default value is 30. 3461 # If this parameter value is greater than 1/8th the maximum number of exchanges 3462 # supported by the HBA port, then the lun queue depth will be reduced to 3463 # 1/8th the maximum number of exchanges. 3464 */ 3465 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512, 3466 "Max number of FCP commands we can queue to a specific LUN"); 3467 3468 /* 3469 # tgt_queue_depth: This parameter is used to limit the number of outstanding 3470 # commands per target port. Value range is [10,65535]. Default value is 65535. 3471 */ 3472 LPFC_VPORT_ATTR_RW(tgt_queue_depth, 65535, 10, 65535, 3473 "Max number of FCP commands we can queue to a specific target port"); 3474 3475 /* 3476 # hba_queue_depth: This parameter is used to limit the number of outstanding 3477 # commands per lpfc HBA. Value range is [32,8192]. If this parameter 3478 # value is greater than the maximum number of exchanges supported by the HBA, 3479 # then maximum number of exchanges supported by the HBA is used to determine 3480 # the hba_queue_depth. 3481 */ 3482 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192, 3483 "Max number of FCP commands we can queue to a lpfc HBA"); 3484 3485 /* 3486 # peer_port_login: This parameter allows/prevents logins 3487 # between peer ports hosted on the same physical port. 3488 # When this parameter is set 0 peer ports of same physical port 3489 # are not allowed to login to each other. 3490 # When this parameter is set 1 peer ports of same physical port 3491 # are allowed to login to each other. 3492 # Default value of this parameter is 0. 3493 */ 3494 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1, 3495 "Allow peer ports on the same physical port to login to each " 3496 "other."); 3497 3498 /* 3499 # restrict_login: This parameter allows/prevents logins 3500 # between Virtual Ports and remote initiators. 3501 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from 3502 # other initiators and will attempt to PLOGI all remote ports. 3503 # When this parameter is set (1) Virtual Ports will reject PLOGIs from 3504 # remote ports and will not attempt to PLOGI to other initiators. 3505 # This parameter does not restrict to the physical port. 3506 # This parameter does not restrict logins to Fabric resident remote ports. 3507 # Default value of this parameter is 1. 3508 */ 3509 static int lpfc_restrict_login = 1; 3510 module_param(lpfc_restrict_login, int, S_IRUGO); 3511 MODULE_PARM_DESC(lpfc_restrict_login, 3512 "Restrict virtual ports login to remote initiators."); 3513 lpfc_vport_param_show(restrict_login); 3514 3515 /** 3516 * lpfc_restrict_login_init - Set the vport restrict login flag 3517 * @vport: lpfc vport structure pointer. 3518 * @val: contains the restrict login value. 3519 * 3520 * Description: 3521 * If val is not in a valid range then log a kernel error message and set 3522 * the vport restrict login to one. 3523 * If the port type is physical clear the restrict login flag and return. 3524 * Else set the restrict login flag to val. 3525 * 3526 * Returns: 3527 * zero if val is in range 3528 * -EINVAL val out of range 3529 **/ 3530 static int 3531 lpfc_restrict_login_init(struct lpfc_vport *vport, int val) 3532 { 3533 if (val < 0 || val > 1) { 3534 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3535 "0422 lpfc_restrict_login attribute cannot " 3536 "be set to %d, allowed range is [0, 1]\n", 3537 val); 3538 vport->cfg_restrict_login = 1; 3539 return -EINVAL; 3540 } 3541 if (vport->port_type == LPFC_PHYSICAL_PORT) { 3542 vport->cfg_restrict_login = 0; 3543 return 0; 3544 } 3545 vport->cfg_restrict_login = val; 3546 return 0; 3547 } 3548 3549 /** 3550 * lpfc_restrict_login_set - Set the vport restrict login flag 3551 * @vport: lpfc vport structure pointer. 3552 * @val: contains the restrict login value. 3553 * 3554 * Description: 3555 * If val is not in a valid range then log a kernel error message and set 3556 * the vport restrict login to one. 3557 * If the port type is physical and the val is not zero log a kernel 3558 * error message, clear the restrict login flag and return zero. 3559 * Else set the restrict login flag to val. 3560 * 3561 * Returns: 3562 * zero if val is in range 3563 * -EINVAL val out of range 3564 **/ 3565 static int 3566 lpfc_restrict_login_set(struct lpfc_vport *vport, int val) 3567 { 3568 if (val < 0 || val > 1) { 3569 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3570 "0425 lpfc_restrict_login attribute cannot " 3571 "be set to %d, allowed range is [0, 1]\n", 3572 val); 3573 vport->cfg_restrict_login = 1; 3574 return -EINVAL; 3575 } 3576 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) { 3577 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3578 "0468 lpfc_restrict_login must be 0 for " 3579 "Physical ports.\n"); 3580 vport->cfg_restrict_login = 0; 3581 return 0; 3582 } 3583 vport->cfg_restrict_login = val; 3584 return 0; 3585 } 3586 lpfc_vport_param_store(restrict_login); 3587 static DEVICE_ATTR_RW(lpfc_restrict_login); 3588 3589 /* 3590 # Some disk devices have a "select ID" or "select Target" capability. 3591 # From a protocol standpoint "select ID" usually means select the 3592 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative 3593 # annex" which contains a table that maps a "select ID" (a number 3594 # between 0 and 7F) to an ALPA. By default, for compatibility with 3595 # older drivers, the lpfc driver scans this table from low ALPA to high 3596 # ALPA. 3597 # 3598 # Turning on the scan-down variable (on = 1, off = 0) will 3599 # cause the lpfc driver to use an inverted table, effectively 3600 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. 3601 # 3602 # (Note: This "select ID" functionality is a LOOP ONLY characteristic 3603 # and will not work across a fabric. Also this parameter will take 3604 # effect only in the case when ALPA map is not available.) 3605 */ 3606 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1, 3607 "Start scanning for devices from highest ALPA to lowest"); 3608 3609 /* 3610 # lpfc_topology: link topology for init link 3611 # 0x0 = attempt loop mode then point-to-point 3612 # 0x01 = internal loopback mode 3613 # 0x02 = attempt point-to-point mode only 3614 # 0x04 = attempt loop mode only 3615 # 0x06 = attempt point-to-point mode then loop 3616 # Set point-to-point mode if you want to run as an N_Port. 3617 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. 3618 # Default value is 0. 3619 */ 3620 LPFC_ATTR(topology, 0, 0, 6, 3621 "Select Fibre Channel topology"); 3622 3623 /** 3624 * lpfc_topology_set - Set the adapters topology field 3625 * @phba: lpfc_hba pointer. 3626 * @val: topology value. 3627 * 3628 * Description: 3629 * If val is in a valid range then set the adapter's topology field and 3630 * issue a lip; if the lip fails reset the topology to the old value. 3631 * 3632 * If the value is not in range log a kernel error message and return an error. 3633 * 3634 * Returns: 3635 * zero if val is in range and lip okay 3636 * non-zero return value from lpfc_issue_lip() 3637 * -EINVAL val out of range 3638 **/ 3639 static ssize_t 3640 lpfc_topology_store(struct device *dev, struct device_attribute *attr, 3641 const char *buf, size_t count) 3642 { 3643 struct Scsi_Host *shost = class_to_shost(dev); 3644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3645 struct lpfc_hba *phba = vport->phba; 3646 int val = 0; 3647 int nolip = 0; 3648 const char *val_buf = buf; 3649 int err; 3650 uint32_t prev_val; 3651 3652 if (!strncmp(buf, "nolip ", strlen("nolip "))) { 3653 nolip = 1; 3654 val_buf = &buf[strlen("nolip ")]; 3655 } 3656 3657 if (!isdigit(val_buf[0])) 3658 return -EINVAL; 3659 if (sscanf(val_buf, "%i", &val) != 1) 3660 return -EINVAL; 3661 3662 if (val >= 0 && val <= 6) { 3663 prev_val = phba->cfg_topology; 3664 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G && 3665 val == 4) { 3666 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3667 "3113 Loop mode not supported at speed %d\n", 3668 val); 3669 return -EINVAL; 3670 } 3671 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && 3672 val == 4) { 3673 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3674 "3114 Loop mode not supported\n"); 3675 return -EINVAL; 3676 } 3677 phba->cfg_topology = val; 3678 if (nolip) 3679 return strlen(buf); 3680 3681 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 3682 "3054 lpfc_topology changed from %d to %d\n", 3683 prev_val, val); 3684 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4) 3685 phba->fc_topology_changed = 1; 3686 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); 3687 if (err) { 3688 phba->cfg_topology = prev_val; 3689 return -EINVAL; 3690 } else 3691 return strlen(buf); 3692 } 3693 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 3694 "%d:0467 lpfc_topology attribute cannot be set to %d, " 3695 "allowed range is [0, 6]\n", 3696 phba->brd_no, val); 3697 return -EINVAL; 3698 } 3699 3700 lpfc_param_show(topology) 3701 static DEVICE_ATTR_RW(lpfc_topology); 3702 3703 /** 3704 * lpfc_static_vport_show: Read callback function for 3705 * lpfc_static_vport sysfs file. 3706 * @dev: Pointer to class device object. 3707 * @attr: device attribute structure. 3708 * @buf: Data buffer. 3709 * 3710 * This function is the read call back function for 3711 * lpfc_static_vport sysfs file. The lpfc_static_vport 3712 * sysfs file report the mageability of the vport. 3713 **/ 3714 static ssize_t 3715 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr, 3716 char *buf) 3717 { 3718 struct Scsi_Host *shost = class_to_shost(dev); 3719 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3720 if (vport->vport_flag & STATIC_VPORT) 3721 sprintf(buf, "1\n"); 3722 else 3723 sprintf(buf, "0\n"); 3724 3725 return strlen(buf); 3726 } 3727 3728 /* 3729 * Sysfs attribute to control the statistical data collection. 3730 */ 3731 static DEVICE_ATTR_RO(lpfc_static_vport); 3732 3733 /** 3734 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file 3735 * @dev: Pointer to class device. 3736 * @buf: Data buffer. 3737 * @count: Size of the data buffer. 3738 * 3739 * This function get called when a user write to the lpfc_stat_data_ctrl 3740 * sysfs file. This function parse the command written to the sysfs file 3741 * and take appropriate action. These commands are used for controlling 3742 * driver statistical data collection. 3743 * Following are the command this function handles. 3744 * 3745 * setbucket <bucket_type> <base> <step> 3746 * = Set the latency buckets. 3747 * destroybucket = destroy all the buckets. 3748 * start = start data collection 3749 * stop = stop data collection 3750 * reset = reset the collected data 3751 **/ 3752 static ssize_t 3753 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr, 3754 const char *buf, size_t count) 3755 { 3756 struct Scsi_Host *shost = class_to_shost(dev); 3757 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3758 struct lpfc_hba *phba = vport->phba; 3759 #define LPFC_MAX_DATA_CTRL_LEN 1024 3760 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN]; 3761 unsigned long i; 3762 char *str_ptr, *token; 3763 struct lpfc_vport **vports; 3764 struct Scsi_Host *v_shost; 3765 char *bucket_type_str, *base_str, *step_str; 3766 unsigned long base, step, bucket_type; 3767 3768 if (!strncmp(buf, "setbucket", strlen("setbucket"))) { 3769 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1)) 3770 return -EINVAL; 3771 3772 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN); 3773 str_ptr = &bucket_data[0]; 3774 /* Ignore this token - this is command token */ 3775 token = strsep(&str_ptr, "\t "); 3776 if (!token) 3777 return -EINVAL; 3778 3779 bucket_type_str = strsep(&str_ptr, "\t "); 3780 if (!bucket_type_str) 3781 return -EINVAL; 3782 3783 if (!strncmp(bucket_type_str, "linear", strlen("linear"))) 3784 bucket_type = LPFC_LINEAR_BUCKET; 3785 else if (!strncmp(bucket_type_str, "power2", strlen("power2"))) 3786 bucket_type = LPFC_POWER2_BUCKET; 3787 else 3788 return -EINVAL; 3789 3790 base_str = strsep(&str_ptr, "\t "); 3791 if (!base_str) 3792 return -EINVAL; 3793 base = simple_strtoul(base_str, NULL, 0); 3794 3795 step_str = strsep(&str_ptr, "\t "); 3796 if (!step_str) 3797 return -EINVAL; 3798 step = simple_strtoul(step_str, NULL, 0); 3799 if (!step) 3800 return -EINVAL; 3801 3802 /* Block the data collection for every vport */ 3803 vports = lpfc_create_vport_work_array(phba); 3804 if (vports == NULL) 3805 return -ENOMEM; 3806 3807 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 3808 v_shost = lpfc_shost_from_vport(vports[i]); 3809 spin_lock_irq(v_shost->host_lock); 3810 /* Block and reset data collection */ 3811 vports[i]->stat_data_blocked = 1; 3812 if (vports[i]->stat_data_enabled) 3813 lpfc_vport_reset_stat_data(vports[i]); 3814 spin_unlock_irq(v_shost->host_lock); 3815 } 3816 3817 /* Set the bucket attributes */ 3818 phba->bucket_type = bucket_type; 3819 phba->bucket_base = base; 3820 phba->bucket_step = step; 3821 3822 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 3823 v_shost = lpfc_shost_from_vport(vports[i]); 3824 3825 /* Unblock data collection */ 3826 spin_lock_irq(v_shost->host_lock); 3827 vports[i]->stat_data_blocked = 0; 3828 spin_unlock_irq(v_shost->host_lock); 3829 } 3830 lpfc_destroy_vport_work_array(phba, vports); 3831 return strlen(buf); 3832 } 3833 3834 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) { 3835 vports = lpfc_create_vport_work_array(phba); 3836 if (vports == NULL) 3837 return -ENOMEM; 3838 3839 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 3840 v_shost = lpfc_shost_from_vport(vports[i]); 3841 spin_lock_irq(shost->host_lock); 3842 vports[i]->stat_data_blocked = 1; 3843 lpfc_free_bucket(vport); 3844 vport->stat_data_enabled = 0; 3845 vports[i]->stat_data_blocked = 0; 3846 spin_unlock_irq(shost->host_lock); 3847 } 3848 lpfc_destroy_vport_work_array(phba, vports); 3849 phba->bucket_type = LPFC_NO_BUCKET; 3850 phba->bucket_base = 0; 3851 phba->bucket_step = 0; 3852 return strlen(buf); 3853 } 3854 3855 if (!strncmp(buf, "start", strlen("start"))) { 3856 /* If no buckets configured return error */ 3857 if (phba->bucket_type == LPFC_NO_BUCKET) 3858 return -EINVAL; 3859 spin_lock_irq(shost->host_lock); 3860 if (vport->stat_data_enabled) { 3861 spin_unlock_irq(shost->host_lock); 3862 return strlen(buf); 3863 } 3864 lpfc_alloc_bucket(vport); 3865 vport->stat_data_enabled = 1; 3866 spin_unlock_irq(shost->host_lock); 3867 return strlen(buf); 3868 } 3869 3870 if (!strncmp(buf, "stop", strlen("stop"))) { 3871 spin_lock_irq(shost->host_lock); 3872 if (vport->stat_data_enabled == 0) { 3873 spin_unlock_irq(shost->host_lock); 3874 return strlen(buf); 3875 } 3876 lpfc_free_bucket(vport); 3877 vport->stat_data_enabled = 0; 3878 spin_unlock_irq(shost->host_lock); 3879 return strlen(buf); 3880 } 3881 3882 if (!strncmp(buf, "reset", strlen("reset"))) { 3883 if ((phba->bucket_type == LPFC_NO_BUCKET) 3884 || !vport->stat_data_enabled) 3885 return strlen(buf); 3886 spin_lock_irq(shost->host_lock); 3887 vport->stat_data_blocked = 1; 3888 lpfc_vport_reset_stat_data(vport); 3889 vport->stat_data_blocked = 0; 3890 spin_unlock_irq(shost->host_lock); 3891 return strlen(buf); 3892 } 3893 return -EINVAL; 3894 } 3895 3896 3897 /** 3898 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file 3899 * @dev: Pointer to class device object. 3900 * @buf: Data buffer. 3901 * 3902 * This function is the read call back function for 3903 * lpfc_stat_data_ctrl sysfs file. This function report the 3904 * current statistical data collection state. 3905 **/ 3906 static ssize_t 3907 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr, 3908 char *buf) 3909 { 3910 struct Scsi_Host *shost = class_to_shost(dev); 3911 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3912 struct lpfc_hba *phba = vport->phba; 3913 int index = 0; 3914 int i; 3915 char *bucket_type; 3916 unsigned long bucket_value; 3917 3918 switch (phba->bucket_type) { 3919 case LPFC_LINEAR_BUCKET: 3920 bucket_type = "linear"; 3921 break; 3922 case LPFC_POWER2_BUCKET: 3923 bucket_type = "power2"; 3924 break; 3925 default: 3926 bucket_type = "No Bucket"; 3927 break; 3928 } 3929 3930 sprintf(&buf[index], "Statistical Data enabled :%d, " 3931 "blocked :%d, Bucket type :%s, Bucket base :%d," 3932 " Bucket step :%d\nLatency Ranges :", 3933 vport->stat_data_enabled, vport->stat_data_blocked, 3934 bucket_type, phba->bucket_base, phba->bucket_step); 3935 index = strlen(buf); 3936 if (phba->bucket_type != LPFC_NO_BUCKET) { 3937 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { 3938 if (phba->bucket_type == LPFC_LINEAR_BUCKET) 3939 bucket_value = phba->bucket_base + 3940 phba->bucket_step * i; 3941 else 3942 bucket_value = phba->bucket_base + 3943 (1 << i) * phba->bucket_step; 3944 3945 if (index + 10 > PAGE_SIZE) 3946 break; 3947 sprintf(&buf[index], "%08ld ", bucket_value); 3948 index = strlen(buf); 3949 } 3950 } 3951 sprintf(&buf[index], "\n"); 3952 return strlen(buf); 3953 } 3954 3955 /* 3956 * Sysfs attribute to control the statistical data collection. 3957 */ 3958 static DEVICE_ATTR_RW(lpfc_stat_data_ctrl); 3959 3960 /* 3961 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data. 3962 */ 3963 3964 /* 3965 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN 3966 * for each target. 3967 */ 3968 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18) 3969 #define MAX_STAT_DATA_SIZE_PER_TARGET \ 3970 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT) 3971 3972 3973 /** 3974 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute 3975 * @filp: sysfs file 3976 * @kobj: Pointer to the kernel object 3977 * @bin_attr: Attribute object 3978 * @buff: Buffer pointer 3979 * @off: File offset 3980 * @count: Buffer size 3981 * 3982 * This function is the read call back function for lpfc_drvr_stat_data 3983 * sysfs file. This function export the statistical data to user 3984 * applications. 3985 **/ 3986 static ssize_t 3987 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj, 3988 struct bin_attribute *bin_attr, 3989 char *buf, loff_t off, size_t count) 3990 { 3991 struct device *dev = container_of(kobj, struct device, 3992 kobj); 3993 struct Scsi_Host *shost = class_to_shost(dev); 3994 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 3995 struct lpfc_hba *phba = vport->phba; 3996 int i = 0, index = 0; 3997 unsigned long nport_index; 3998 struct lpfc_nodelist *ndlp = NULL; 3999 nport_index = (unsigned long)off / 4000 MAX_STAT_DATA_SIZE_PER_TARGET; 4001 4002 if (!vport->stat_data_enabled || vport->stat_data_blocked 4003 || (phba->bucket_type == LPFC_NO_BUCKET)) 4004 return 0; 4005 4006 spin_lock_irq(shost->host_lock); 4007 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 4008 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data) 4009 continue; 4010 4011 if (nport_index > 0) { 4012 nport_index--; 4013 continue; 4014 } 4015 4016 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET) 4017 > count) 4018 break; 4019 4020 if (!ndlp->lat_data) 4021 continue; 4022 4023 /* Print the WWN */ 4024 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:", 4025 ndlp->nlp_portname.u.wwn[0], 4026 ndlp->nlp_portname.u.wwn[1], 4027 ndlp->nlp_portname.u.wwn[2], 4028 ndlp->nlp_portname.u.wwn[3], 4029 ndlp->nlp_portname.u.wwn[4], 4030 ndlp->nlp_portname.u.wwn[5], 4031 ndlp->nlp_portname.u.wwn[6], 4032 ndlp->nlp_portname.u.wwn[7]); 4033 4034 index = strlen(buf); 4035 4036 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { 4037 sprintf(&buf[index], "%010u,", 4038 ndlp->lat_data[i].cmd_count); 4039 index = strlen(buf); 4040 } 4041 sprintf(&buf[index], "\n"); 4042 index = strlen(buf); 4043 } 4044 spin_unlock_irq(shost->host_lock); 4045 return index; 4046 } 4047 4048 static struct bin_attribute sysfs_drvr_stat_data_attr = { 4049 .attr = { 4050 .name = "lpfc_drvr_stat_data", 4051 .mode = S_IRUSR, 4052 }, 4053 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET, 4054 .read = sysfs_drvr_stat_data_read, 4055 .write = NULL, 4056 }; 4057 4058 /* 4059 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel 4060 # connection. 4061 # Value range is [0,16]. Default value is 0. 4062 */ 4063 /** 4064 * lpfc_link_speed_set - Set the adapters link speed 4065 * @phba: lpfc_hba pointer. 4066 * @val: link speed value. 4067 * 4068 * Description: 4069 * If val is in a valid range then set the adapter's link speed field and 4070 * issue a lip; if the lip fails reset the link speed to the old value. 4071 * 4072 * Notes: 4073 * If the value is not in range log a kernel error message and return an error. 4074 * 4075 * Returns: 4076 * zero if val is in range and lip okay. 4077 * non-zero return value from lpfc_issue_lip() 4078 * -EINVAL val out of range 4079 **/ 4080 static ssize_t 4081 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr, 4082 const char *buf, size_t count) 4083 { 4084 struct Scsi_Host *shost = class_to_shost(dev); 4085 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 4086 struct lpfc_hba *phba = vport->phba; 4087 int val = LPFC_USER_LINK_SPEED_AUTO; 4088 int nolip = 0; 4089 const char *val_buf = buf; 4090 int err; 4091 uint32_t prev_val, if_type; 4092 4093 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); 4094 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 && 4095 phba->hba_flag & HBA_FORCED_LINK_SPEED) 4096 return -EPERM; 4097 4098 if (!strncmp(buf, "nolip ", strlen("nolip "))) { 4099 nolip = 1; 4100 val_buf = &buf[strlen("nolip ")]; 4101 } 4102 4103 if (!isdigit(val_buf[0])) 4104 return -EINVAL; 4105 if (sscanf(val_buf, "%i", &val) != 1) 4106 return -EINVAL; 4107 4108 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, 4109 "3055 lpfc_link_speed changed from %d to %d %s\n", 4110 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)"); 4111 4112 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) || 4113 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) || 4114 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) || 4115 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) || 4116 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) || 4117 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) || 4118 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) || 4119 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) { 4120 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4121 "2879 lpfc_link_speed attribute cannot be set " 4122 "to %d. Speed is not supported by this port.\n", 4123 val); 4124 return -EINVAL; 4125 } 4126 if (val >= LPFC_USER_LINK_SPEED_16G && 4127 phba->fc_topology == LPFC_TOPOLOGY_LOOP) { 4128 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4129 "3112 lpfc_link_speed attribute cannot be set " 4130 "to %d. Speed is not supported in loop mode.\n", 4131 val); 4132 return -EINVAL; 4133 } 4134 4135 switch (val) { 4136 case LPFC_USER_LINK_SPEED_AUTO: 4137 case LPFC_USER_LINK_SPEED_1G: 4138 case LPFC_USER_LINK_SPEED_2G: 4139 case LPFC_USER_LINK_SPEED_4G: 4140 case LPFC_USER_LINK_SPEED_8G: 4141 case LPFC_USER_LINK_SPEED_16G: 4142 case LPFC_USER_LINK_SPEED_32G: 4143 case LPFC_USER_LINK_SPEED_64G: 4144 prev_val = phba->cfg_link_speed; 4145 phba->cfg_link_speed = val; 4146 if (nolip) 4147 return strlen(buf); 4148 4149 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); 4150 if (err) { 4151 phba->cfg_link_speed = prev_val; 4152 return -EINVAL; 4153 } 4154 return strlen(buf); 4155 default: 4156 break; 4157 } 4158 4159 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4160 "0469 lpfc_link_speed attribute cannot be set to %d, " 4161 "allowed values are [%s]\n", 4162 val, LPFC_LINK_SPEED_STRING); 4163 return -EINVAL; 4164 4165 } 4166 4167 static int lpfc_link_speed = 0; 4168 module_param(lpfc_link_speed, int, S_IRUGO); 4169 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed"); 4170 lpfc_param_show(link_speed) 4171 4172 /** 4173 * lpfc_link_speed_init - Set the adapters link speed 4174 * @phba: lpfc_hba pointer. 4175 * @val: link speed value. 4176 * 4177 * Description: 4178 * If val is in a valid range then set the adapter's link speed field. 4179 * 4180 * Notes: 4181 * If the value is not in range log a kernel error message, clear the link 4182 * speed and return an error. 4183 * 4184 * Returns: 4185 * zero if val saved. 4186 * -EINVAL val out of range 4187 **/ 4188 static int 4189 lpfc_link_speed_init(struct lpfc_hba *phba, int val) 4190 { 4191 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) { 4192 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4193 "3111 lpfc_link_speed of %d cannot " 4194 "support loop mode, setting topology to default.\n", 4195 val); 4196 phba->cfg_topology = 0; 4197 } 4198 4199 switch (val) { 4200 case LPFC_USER_LINK_SPEED_AUTO: 4201 case LPFC_USER_LINK_SPEED_1G: 4202 case LPFC_USER_LINK_SPEED_2G: 4203 case LPFC_USER_LINK_SPEED_4G: 4204 case LPFC_USER_LINK_SPEED_8G: 4205 case LPFC_USER_LINK_SPEED_16G: 4206 case LPFC_USER_LINK_SPEED_32G: 4207 case LPFC_USER_LINK_SPEED_64G: 4208 phba->cfg_link_speed = val; 4209 return 0; 4210 default: 4211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4212 "0405 lpfc_link_speed attribute cannot " 4213 "be set to %d, allowed values are " 4214 "["LPFC_LINK_SPEED_STRING"]\n", val); 4215 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; 4216 return -EINVAL; 4217 } 4218 } 4219 4220 static DEVICE_ATTR_RW(lpfc_link_speed); 4221 4222 /* 4223 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER) 4224 # 0 = aer disabled or not supported 4225 # 1 = aer supported and enabled (default) 4226 # Value range is [0,1]. Default value is 1. 4227 */ 4228 LPFC_ATTR(aer_support, 1, 0, 1, 4229 "Enable PCIe device AER support"); 4230 lpfc_param_show(aer_support) 4231 4232 /** 4233 * lpfc_aer_support_store - Set the adapter for aer support 4234 * 4235 * @dev: class device that is converted into a Scsi_host. 4236 * @attr: device attribute, not used. 4237 * @buf: containing enable or disable aer flag. 4238 * @count: unused variable. 4239 * 4240 * Description: 4241 * If the val is 1 and currently the device's AER capability was not 4242 * enabled, invoke the kernel's enable AER helper routine, trying to 4243 * enable the device's AER capability. If the helper routine enabling 4244 * AER returns success, update the device's cfg_aer_support flag to 4245 * indicate AER is supported by the device; otherwise, if the device 4246 * AER capability is already enabled to support AER, then do nothing. 4247 * 4248 * If the val is 0 and currently the device's AER support was enabled, 4249 * invoke the kernel's disable AER helper routine. After that, update 4250 * the device's cfg_aer_support flag to indicate AER is not supported 4251 * by the device; otherwise, if the device AER capability is already 4252 * disabled from supporting AER, then do nothing. 4253 * 4254 * Returns: 4255 * length of the buf on success if val is in range the intended mode 4256 * is supported. 4257 * -EINVAL if val out of range or intended mode is not supported. 4258 **/ 4259 static ssize_t 4260 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr, 4261 const char *buf, size_t count) 4262 { 4263 struct Scsi_Host *shost = class_to_shost(dev); 4264 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; 4265 struct lpfc_hba *phba = vport->phba; 4266 int val = 0, rc = -EINVAL; 4267 4268 if (!isdigit(buf[0])) 4269 return -EINVAL; 4270 if (sscanf(buf, "%i", &val) != 1) 4271 return -EINVAL; 4272 4273 switch (val) { 4274 case 0: 4275 if (phba->hba_flag & HBA_AER_ENABLED) { 4276 rc = pci_disable_pcie_error_reporting(phba->pcidev); 4277 if (!rc) { 4278 spin_lock_irq(&phba->hbalock); 4279 phba->hba_flag &= ~HBA_AER_ENABLED; 4280 spin_unlock_irq(&phba->hbalock); 4281 phba->cfg_aer_support = 0; 4282 rc = strlen(buf); 4283 } else 4284 rc = -EPERM; 4285 } else { 4286 phba->cfg_aer_support = 0; 4287 rc = strlen(buf); 4288 } 4289 break; 4290 case 1: 4291 if (!(phba->hba_flag & HBA_AER_ENABLED)) { 4292 rc = pci_enable_pcie_error_reporting(phba->pcidev); 4293 if (!rc) { 4294 spin_lock_irq(&phba->hbalock); 4295 phba->hba_flag |= HBA_AER_ENABLED; 4296 spin_unlock_irq(&phba->hbalock); 4297 phba->cfg_aer_support = 1; 4298 rc = strlen(buf); 4299 } else 4300 rc = -EPERM; 4301 } else { 4302 phba->cfg_aer_support = 1; 4303 rc = strlen(buf); 4304 } 4305 break; 4306 default: 4307 rc = -EINVAL; 4308 break; 4309 } 4310 return rc; 4311 } 4312 4313 static DEVICE_ATTR_RW(lpfc_aer_support); 4314 4315 /** 4316 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device 4317 * @dev: class device that is converted into a Scsi_host. 4318 * @attr: device attribute, not used. 4319 * @buf: containing flag 1 for aer cleanup state. 4320 * @count: unused variable. 4321 * 4322 * Description: 4323 * If the @buf contains 1 and the device currently has the AER support 4324 * enabled, then invokes the kernel AER helper routine 4325 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable 4326 * error status register. 4327 * 4328 * Notes: 4329 * 4330 * Returns: 4331 * -EINVAL if the buf does not contain the 1 or the device is not currently 4332 * enabled with the AER support. 4333 **/ 4334 static ssize_t 4335 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr, 4336 const char *buf, size_t count) 4337 { 4338 struct Scsi_Host *shost = class_to_shost(dev); 4339 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 4340 struct lpfc_hba *phba = vport->phba; 4341 int val, rc = -1; 4342 4343 if (!isdigit(buf[0])) 4344 return -EINVAL; 4345 if (sscanf(buf, "%i", &val) != 1) 4346 return -EINVAL; 4347 if (val != 1) 4348 return -EINVAL; 4349 4350 if (phba->hba_flag & HBA_AER_ENABLED) 4351 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev); 4352 4353 if (rc == 0) 4354 return strlen(buf); 4355 else 4356 return -EPERM; 4357 } 4358 4359 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL, 4360 lpfc_aer_cleanup_state); 4361 4362 /** 4363 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions 4364 * 4365 * @dev: class device that is converted into a Scsi_host. 4366 * @attr: device attribute, not used. 4367 * @buf: containing the string the number of vfs to be enabled. 4368 * @count: unused variable. 4369 * 4370 * Description: 4371 * When this api is called either through user sysfs, the driver shall 4372 * try to enable or disable SR-IOV virtual functions according to the 4373 * following: 4374 * 4375 * If zero virtual function has been enabled to the physical function, 4376 * the driver shall invoke the pci enable virtual function api trying 4377 * to enable the virtual functions. If the nr_vfn provided is greater 4378 * than the maximum supported, the maximum virtual function number will 4379 * be used for invoking the api; otherwise, the nr_vfn provided shall 4380 * be used for invoking the api. If the api call returned success, the 4381 * actual number of virtual functions enabled will be set to the driver 4382 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver 4383 * cfg_sriov_nr_virtfn remains zero. 4384 * 4385 * If none-zero virtual functions have already been enabled to the 4386 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn, 4387 * -EINVAL will be returned and the driver does nothing; 4388 * 4389 * If the nr_vfn provided is zero and none-zero virtual functions have 4390 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the 4391 * disabling virtual function api shall be invoded to disable all the 4392 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to 4393 * zero. Otherwise, if zero virtual function has been enabled, do 4394 * nothing. 4395 * 4396 * Returns: 4397 * length of the buf on success if val is in range the intended mode 4398 * is supported. 4399 * -EINVAL if val out of range or intended mode is not supported. 4400 **/ 4401 static ssize_t 4402 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr, 4403 const char *buf, size_t count) 4404 { 4405 struct Scsi_Host *shost = class_to_shost(dev); 4406 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; 4407 struct lpfc_hba *phba = vport->phba; 4408 struct pci_dev *pdev = phba->pcidev; 4409 int val = 0, rc = -EINVAL; 4410 4411 /* Sanity check on user data */ 4412 if (!isdigit(buf[0])) 4413 return -EINVAL; 4414 if (sscanf(buf, "%i", &val) != 1) 4415 return -EINVAL; 4416 if (val < 0) 4417 return -EINVAL; 4418 4419 /* Request disabling virtual functions */ 4420 if (val == 0) { 4421 if (phba->cfg_sriov_nr_virtfn > 0) { 4422 pci_disable_sriov(pdev); 4423 phba->cfg_sriov_nr_virtfn = 0; 4424 } 4425 return strlen(buf); 4426 } 4427 4428 /* Request enabling virtual functions */ 4429 if (phba->cfg_sriov_nr_virtfn > 0) { 4430 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4431 "3018 There are %d virtual functions " 4432 "enabled on physical function.\n", 4433 phba->cfg_sriov_nr_virtfn); 4434 return -EEXIST; 4435 } 4436 4437 if (val <= LPFC_MAX_VFN_PER_PFN) 4438 phba->cfg_sriov_nr_virtfn = val; 4439 else { 4440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4441 "3019 Enabling %d virtual functions is not " 4442 "allowed.\n", val); 4443 return -EINVAL; 4444 } 4445 4446 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn); 4447 if (rc) { 4448 phba->cfg_sriov_nr_virtfn = 0; 4449 rc = -EPERM; 4450 } else 4451 rc = strlen(buf); 4452 4453 return rc; 4454 } 4455 4456 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN, 4457 "Enable PCIe device SR-IOV virtual fn"); 4458 4459 lpfc_param_show(sriov_nr_virtfn) 4460 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn); 4461 4462 /** 4463 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade 4464 * 4465 * @dev: class device that is converted into a Scsi_host. 4466 * @attr: device attribute, not used. 4467 * @buf: containing the string the number of vfs to be enabled. 4468 * @count: unused variable. 4469 * 4470 * Description: 4471 * 4472 * Returns: 4473 * length of the buf on success if val is in range the intended mode 4474 * is supported. 4475 * -EINVAL if val out of range or intended mode is not supported. 4476 **/ 4477 static ssize_t 4478 lpfc_request_firmware_upgrade_store(struct device *dev, 4479 struct device_attribute *attr, 4480 const char *buf, size_t count) 4481 { 4482 struct Scsi_Host *shost = class_to_shost(dev); 4483 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; 4484 struct lpfc_hba *phba = vport->phba; 4485 int val = 0, rc = -EINVAL; 4486 4487 /* Sanity check on user data */ 4488 if (!isdigit(buf[0])) 4489 return -EINVAL; 4490 if (sscanf(buf, "%i", &val) != 1) 4491 return -EINVAL; 4492 if (val != 1) 4493 return -EINVAL; 4494 4495 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE); 4496 if (rc) 4497 rc = -EPERM; 4498 else 4499 rc = strlen(buf); 4500 return rc; 4501 } 4502 4503 static int lpfc_req_fw_upgrade; 4504 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR); 4505 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade"); 4506 lpfc_param_show(request_firmware_upgrade) 4507 4508 /** 4509 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade 4510 * @phba: lpfc_hba pointer. 4511 * @val: 0 or 1. 4512 * 4513 * Description: 4514 * Set the initial Linux generic firmware upgrade enable or disable flag. 4515 * 4516 * Returns: 4517 * zero if val saved. 4518 * -EINVAL val out of range 4519 **/ 4520 static int 4521 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val) 4522 { 4523 if (val >= 0 && val <= 1) { 4524 phba->cfg_request_firmware_upgrade = val; 4525 return 0; 4526 } 4527 return -EINVAL; 4528 } 4529 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR, 4530 lpfc_request_firmware_upgrade_show, 4531 lpfc_request_firmware_upgrade_store); 4532 4533 /** 4534 * lpfc_fcp_imax_store 4535 * 4536 * @dev: class device that is converted into a Scsi_host. 4537 * @attr: device attribute, not used. 4538 * @buf: string with the number of fast-path FCP interrupts per second. 4539 * @count: unused variable. 4540 * 4541 * Description: 4542 * If val is in a valid range [636,651042], then set the adapter's 4543 * maximum number of fast-path FCP interrupts per second. 4544 * 4545 * Returns: 4546 * length of the buf on success if val is in range the intended mode 4547 * is supported. 4548 * -EINVAL if val out of range or intended mode is not supported. 4549 **/ 4550 static ssize_t 4551 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr, 4552 const char *buf, size_t count) 4553 { 4554 struct Scsi_Host *shost = class_to_shost(dev); 4555 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; 4556 struct lpfc_hba *phba = vport->phba; 4557 int val = 0, i; 4558 4559 /* fcp_imax is only valid for SLI4 */ 4560 if (phba->sli_rev != LPFC_SLI_REV4) 4561 return -EINVAL; 4562 4563 /* Sanity check on user data */ 4564 if (!isdigit(buf[0])) 4565 return -EINVAL; 4566 if (sscanf(buf, "%i", &val) != 1) 4567 return -EINVAL; 4568 4569 /* 4570 * Value range for the HBA is [5000,5000000] 4571 * The value for each EQ depends on how many EQs are configured. 4572 * Allow value == 0 4573 */ 4574 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)) 4575 return -EINVAL; 4576 4577 phba->cfg_fcp_imax = (uint32_t)val; 4578 phba->initial_imax = phba->cfg_fcp_imax; 4579 4580 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT) 4581 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT, 4582 val); 4583 4584 return strlen(buf); 4585 } 4586 4587 /* 4588 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second 4589 # for the HBA. 4590 # 4591 # Value range is [5,000 to 5,000,000]. Default value is 50,000. 4592 */ 4593 static int lpfc_fcp_imax = LPFC_DEF_IMAX; 4594 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR); 4595 MODULE_PARM_DESC(lpfc_fcp_imax, 4596 "Set the maximum number of FCP interrupts per second per HBA"); 4597 lpfc_param_show(fcp_imax) 4598 4599 /** 4600 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable 4601 * @phba: lpfc_hba pointer. 4602 * @val: link speed value. 4603 * 4604 * Description: 4605 * If val is in a valid range [636,651042], then initialize the adapter's 4606 * maximum number of fast-path FCP interrupts per second. 4607 * 4608 * Returns: 4609 * zero if val saved. 4610 * -EINVAL val out of range 4611 **/ 4612 static int 4613 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val) 4614 { 4615 if (phba->sli_rev != LPFC_SLI_REV4) { 4616 phba->cfg_fcp_imax = 0; 4617 return 0; 4618 } 4619 4620 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) || 4621 (val == 0)) { 4622 phba->cfg_fcp_imax = val; 4623 return 0; 4624 } 4625 4626 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4627 "3016 lpfc_fcp_imax: %d out of range, using default\n", 4628 val); 4629 phba->cfg_fcp_imax = LPFC_DEF_IMAX; 4630 4631 return 0; 4632 } 4633 4634 static DEVICE_ATTR_RW(lpfc_fcp_imax); 4635 4636 /* 4637 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support. 4638 * 0 No auto_imax support 4639 * 1 auto imax on 4640 * Auto imax will change the value of fcp_imax on a per EQ basis, using 4641 * the EQ Delay Multiplier, depending on the activity for that EQ. 4642 * Value range [0,1]. Default value is 1. 4643 */ 4644 LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax"); 4645 4646 /** 4647 * lpfc_state_show - Display current driver CPU affinity 4648 * @dev: class converted to a Scsi_host structure. 4649 * @attr: device attribute, not used. 4650 * @buf: on return contains text describing the state of the link. 4651 * 4652 * Returns: size of formatted string. 4653 **/ 4654 static ssize_t 4655 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr, 4656 char *buf) 4657 { 4658 struct Scsi_Host *shost = class_to_shost(dev); 4659 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; 4660 struct lpfc_hba *phba = vport->phba; 4661 struct lpfc_vector_map_info *cpup; 4662 int len = 0; 4663 4664 if ((phba->sli_rev != LPFC_SLI_REV4) || 4665 (phba->intr_type != MSIX)) 4666 return len; 4667 4668 switch (phba->cfg_fcp_cpu_map) { 4669 case 0: 4670 len += snprintf(buf + len, PAGE_SIZE-len, 4671 "fcp_cpu_map: No mapping (%d)\n", 4672 phba->cfg_fcp_cpu_map); 4673 return len; 4674 case 1: 4675 len += snprintf(buf + len, PAGE_SIZE-len, 4676 "fcp_cpu_map: HBA centric mapping (%d): " 4677 "%d online CPUs\n", 4678 phba->cfg_fcp_cpu_map, 4679 phba->sli4_hba.num_online_cpu); 4680 break; 4681 case 2: 4682 len += snprintf(buf + len, PAGE_SIZE-len, 4683 "fcp_cpu_map: Driver centric mapping (%d): " 4684 "%d online CPUs\n", 4685 phba->cfg_fcp_cpu_map, 4686 phba->sli4_hba.num_online_cpu); 4687 break; 4688 } 4689 4690 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) { 4691 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu]; 4692 4693 /* margin should fit in this and the truncated message */ 4694 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY) 4695 len += snprintf(buf + len, PAGE_SIZE-len, 4696 "CPU %02d io_chan %02d " 4697 "physid %d coreid %d\n", 4698 phba->sli4_hba.curr_disp_cpu, 4699 cpup->channel_id, cpup->phys_id, 4700 cpup->core_id); 4701 else 4702 len += snprintf(buf + len, PAGE_SIZE-len, 4703 "CPU %02d io_chan %02d " 4704 "physid %d coreid %d IRQ %d\n", 4705 phba->sli4_hba.curr_disp_cpu, 4706 cpup->channel_id, cpup->phys_id, 4707 cpup->core_id, cpup->irq); 4708 4709 phba->sli4_hba.curr_disp_cpu++; 4710 4711 /* display max number of CPUs keeping some margin */ 4712 if (phba->sli4_hba.curr_disp_cpu < 4713 phba->sli4_hba.num_present_cpu && 4714 (len >= (PAGE_SIZE - 64))) { 4715 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n"); 4716 break; 4717 } 4718 } 4719 4720 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu) 4721 phba->sli4_hba.curr_disp_cpu = 0; 4722 4723 return len; 4724 } 4725 4726 /** 4727 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors 4728 * @dev: class device that is converted into a Scsi_host. 4729 * @attr: device attribute, not used. 4730 * @buf: one or more lpfc_polling_flags values. 4731 * @count: not used. 4732 * 4733 * Returns: 4734 * -EINVAL - Not implemented yet. 4735 **/ 4736 static ssize_t 4737 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr, 4738 const char *buf, size_t count) 4739 { 4740 int status = -EINVAL; 4741 return status; 4742 } 4743 4744 /* 4745 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors 4746 # for the HBA. 4747 # 4748 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2). 4749 # 0 - Do not affinitze IRQ vectors 4750 # 1 - Affintize HBA vectors with respect to each HBA 4751 # (start with CPU0 for each HBA) 4752 # 2 - Affintize HBA vectors with respect to the entire driver 4753 # (round robin thru all CPUs across all HBAs) 4754 */ 4755 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP; 4756 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR); 4757 MODULE_PARM_DESC(lpfc_fcp_cpu_map, 4758 "Defines how to map CPUs to IRQ vectors per HBA"); 4759 4760 /** 4761 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable 4762 * @phba: lpfc_hba pointer. 4763 * @val: link speed value. 4764 * 4765 * Description: 4766 * If val is in a valid range [0-2], then affinitze the adapter's 4767 * MSIX vectors. 4768 * 4769 * Returns: 4770 * zero if val saved. 4771 * -EINVAL val out of range 4772 **/ 4773 static int 4774 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val) 4775 { 4776 if (phba->sli_rev != LPFC_SLI_REV4) { 4777 phba->cfg_fcp_cpu_map = 0; 4778 return 0; 4779 } 4780 4781 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) { 4782 phba->cfg_fcp_cpu_map = val; 4783 return 0; 4784 } 4785 4786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4787 "3326 lpfc_fcp_cpu_map: %d out of range, using " 4788 "default\n", val); 4789 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP; 4790 4791 return 0; 4792 } 4793 4794 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map); 4795 4796 /* 4797 # lpfc_fcp_class: Determines FC class to use for the FCP protocol. 4798 # Value range is [2,3]. Default value is 3. 4799 */ 4800 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3, 4801 "Select Fibre Channel class of service for FCP sequences"); 4802 4803 /* 4804 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range 4805 # is [0,1]. Default value is 0. 4806 */ 4807 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1, 4808 "Use ADISC on rediscovery to authenticate FCP devices"); 4809 4810 /* 4811 # lpfc_first_burst_size: First burst size to use on the NPorts 4812 # that support first burst. 4813 # Value range is [0,65536]. Default value is 0. 4814 */ 4815 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536, 4816 "First burst size for Targets that support first burst"); 4817 4818 /* 4819 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size. 4820 * When the driver is configured as an NVME target, this value is 4821 * communicated to the NVME initiator in the PRLI response. It is 4822 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support 4823 * parameters are set and the target is sending the PRLI RSP. 4824 * Parameter supported on physical port only - no NPIV support. 4825 * Value range is [0,65536]. Default value is 0. 4826 */ 4827 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536, 4828 "NVME Target mode first burst size in 512B increments."); 4829 4830 /* 4831 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions. 4832 * For the Initiator (I), enabling this parameter means that an NVMET 4833 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be 4834 * processed by the initiator for subsequent NVME FCP IO. For the target 4835 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size 4836 * driver parameter as the target function's first burst size returned to the 4837 * initiator in the target's NVME PRLI response. Parameter supported on physical 4838 * port only - no NPIV support. 4839 * Value range is [0,1]. Default value is 0 (disabled). 4840 */ 4841 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1, 4842 "Enable First Burst feature on I and T functions."); 4843 4844 /* 4845 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue 4846 # depth. Default value is 0. When the value of this parameter is zero the 4847 # SCSI command completion time is not used for controlling I/O queue depth. When 4848 # the parameter is set to a non-zero value, the I/O queue depth is controlled 4849 # to limit the I/O completion time to the parameter value. 4850 # The value is set in milliseconds. 4851 */ 4852 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000, 4853 "Use command completion time to control queue depth"); 4854 4855 lpfc_vport_param_show(max_scsicmpl_time); 4856 static int 4857 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val) 4858 { 4859 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 4860 struct lpfc_nodelist *ndlp, *next_ndlp; 4861 4862 if (val == vport->cfg_max_scsicmpl_time) 4863 return 0; 4864 if ((val < 0) || (val > 60000)) 4865 return -EINVAL; 4866 vport->cfg_max_scsicmpl_time = val; 4867 4868 spin_lock_irq(shost->host_lock); 4869 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { 4870 if (!NLP_CHK_NODE_ACT(ndlp)) 4871 continue; 4872 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) 4873 continue; 4874 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; 4875 } 4876 spin_unlock_irq(shost->host_lock); 4877 return 0; 4878 } 4879 lpfc_vport_param_store(max_scsicmpl_time); 4880 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time); 4881 4882 /* 4883 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value 4884 # range is [0,1]. Default value is 0. 4885 */ 4886 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); 4887 4888 /* 4889 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds 4890 * range is [0,1]. Default value is 0. 4891 * For [0], FCP commands are issued to Work Queues ina round robin fashion. 4892 * For [1], FCP commands are issued to a Work Queue associated with the 4893 * current CPU. 4894 * 4895 * LPFC_FCP_SCHED_ROUND_ROBIN == 0 4896 * LPFC_FCP_SCHED_BY_CPU == 1 4897 * 4898 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu 4899 * affinity for FCP/NVME I/Os through Work Queues associated with the current 4900 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os 4901 * through WQs will be used. 4902 */ 4903 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN, 4904 LPFC_FCP_SCHED_ROUND_ROBIN, 4905 LPFC_FCP_SCHED_BY_CPU, 4906 "Determine scheduling algorithm for " 4907 "issuing commands [0] - Round Robin, [1] - Current CPU"); 4908 4909 /* 4910 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior 4911 # range is [0,1]. Default value is 0. 4912 # For [0], bus reset issues target reset to ALL devices 4913 # For [1], bus reset issues target reset to non-FCP2 devices 4914 */ 4915 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for " 4916 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset"); 4917 4918 4919 /* 4920 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing 4921 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take 4922 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay 4923 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if 4924 # cr_delay is set to 0. 4925 */ 4926 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an " 4927 "interrupt response is generated"); 4928 4929 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an " 4930 "interrupt response is generated"); 4931 4932 /* 4933 # lpfc_multi_ring_support: Determines how many rings to spread available 4934 # cmd/rsp IOCB entries across. 4935 # Value range is [1,2]. Default value is 1. 4936 */ 4937 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary " 4938 "SLI rings to spread IOCB entries across"); 4939 4940 /* 4941 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this 4942 # identifies what rctl value to configure the additional ring for. 4943 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data). 4944 */ 4945 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1, 4946 255, "Identifies RCTL for additional ring configuration"); 4947 4948 /* 4949 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this 4950 # identifies what type value to configure the additional ring for. 4951 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP). 4952 */ 4953 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1, 4954 255, "Identifies TYPE for additional ring configuration"); 4955 4956 /* 4957 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN 4958 # 0 = SmartSAN functionality disabled (default) 4959 # 1 = SmartSAN functionality enabled 4960 # This parameter will override the value of lpfc_fdmi_on module parameter. 4961 # Value range is [0,1]. Default value is 0. 4962 */ 4963 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality"); 4964 4965 /* 4966 # lpfc_fdmi_on: Controls FDMI support. 4967 # 0 No FDMI support (default) 4968 # 1 Traditional FDMI support 4969 # Traditional FDMI support means the driver will assume FDMI-2 support; 4970 # however, if that fails, it will fallback to FDMI-1. 4971 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on. 4972 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of 4973 # lpfc_fdmi_on. 4974 # Value range [0,1]. Default value is 0. 4975 */ 4976 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support"); 4977 4978 /* 4979 # Specifies the maximum number of ELS cmds we can have outstanding (for 4980 # discovery). Value range is [1,64]. Default value = 32. 4981 */ 4982 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands " 4983 "during discovery"); 4984 4985 /* 4986 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that 4987 # will be scanned by the SCSI midlayer when sequential scanning is 4988 # used; and is also the highest LUN ID allowed when the SCSI midlayer 4989 # parses REPORT_LUN responses. The lpfc driver has no LUN count or 4990 # LUN ID limit, but the SCSI midlayer requires this field for the uses 4991 # above. The lpfc driver limits the default value to 255 for two reasons. 4992 # As it bounds the sequential scan loop, scanning for thousands of luns 4993 # on a target can take minutes of wall clock time. Additionally, 4994 # there are FC targets, such as JBODs, that only recognize 8-bits of 4995 # LUN ID. When they receive a value greater than 8 bits, they chop off 4996 # the high order bits. In other words, they see LUN IDs 0, 256, 512, 4997 # and so on all as LUN ID 0. This causes the linux kernel, which sees 4998 # valid responses at each of the LUN IDs, to believe there are multiple 4999 # devices present, when in fact, there is only 1. 5000 # A customer that is aware of their target behaviors, and the results as 5001 # indicated above, is welcome to increase the lpfc_max_luns value. 5002 # As mentioned, this value is not used by the lpfc driver, only the 5003 # SCSI midlayer. 5004 # Value range is [0,65535]. Default value is 255. 5005 # NOTE: The SCSI layer might probe all allowed LUN on some old targets. 5006 */ 5007 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID"); 5008 5009 /* 5010 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. 5011 # Value range is [1,255], default value is 10. 5012 */ 5013 LPFC_ATTR_RW(poll_tmo, 10, 1, 255, 5014 "Milliseconds driver will wait between polling FCP ring"); 5015 5016 /* 5017 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands 5018 # to complete in seconds. Value range is [5,180], default value is 60. 5019 */ 5020 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180, 5021 "Maximum time to wait for task management commands to complete"); 5022 /* 5023 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that 5024 # support this feature 5025 # 0 = MSI disabled 5026 # 1 = MSI enabled 5027 # 2 = MSI-X enabled (default) 5028 # Value range is [0,2]. Default value is 2. 5029 */ 5030 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or " 5031 "MSI-X (2), if possible"); 5032 5033 /* 5034 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs 5035 * 5036 * 0 = NVME OAS disabled 5037 * 1 = NVME OAS enabled 5038 * 5039 * Value range is [0,1]. Default value is 0. 5040 */ 5041 LPFC_ATTR_RW(nvme_oas, 0, 0, 1, 5042 "Use OAS bit on NVME IOs"); 5043 5044 /* 5045 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs 5046 * 5047 * 0 = Put NVME Command in SGL 5048 * 1 = Embed NVME Command in WQE (unless G7) 5049 * 2 = Embed NVME Command in WQE (force) 5050 * 5051 * Value range is [0,2]. Default value is 1. 5052 */ 5053 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2, 5054 "Embed NVME Command in WQE"); 5055 5056 /* 5057 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver 5058 * will advertise it supports to the SCSI layer. This also will map to 5059 * the number of WQs the driver will create. 5060 * 5061 * 0 = Configure the number of io channels to the number of active CPUs. 5062 * 1,32 = Manually specify how many io channels to use. 5063 * 5064 * Value range is [0,32]. Default value is 4. 5065 */ 5066 LPFC_ATTR_R(fcp_io_channel, 5067 LPFC_FCP_IO_CHAN_DEF, 5068 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX, 5069 "Set the number of FCP I/O channels"); 5070 5071 /* 5072 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver 5073 * will advertise it supports to the NVME layer. This also will map to 5074 * the number of WQs the driver will create. 5075 * 5076 * This module parameter is valid when lpfc_enable_fc4_type is set 5077 * to support NVME. 5078 * 5079 * The NVME Layer will try to create this many, plus 1 administrative 5080 * hardware queue. The administrative queue will always map to WQ 0 5081 * A hardware IO queue maps (qidx) to a specific driver WQ. 5082 * 5083 * 0 = Configure the number of io channels to the number of active CPUs. 5084 * 1,32 = Manually specify how many io channels to use. 5085 * 5086 * Value range is [0,32]. Default value is 0. 5087 */ 5088 LPFC_ATTR_R(nvme_io_channel, 5089 LPFC_NVME_IO_CHAN_DEF, 5090 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX, 5091 "Set the number of NVME I/O channels"); 5092 5093 /* 5094 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware. 5095 # 0 = HBA resets disabled 5096 # 1 = HBA resets enabled (default) 5097 # Value range is [0,1]. Default value is 1. 5098 */ 5099 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver."); 5100 5101 /* 5102 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer.. 5103 # 0 = HBA Heartbeat disabled 5104 # 1 = HBA Heartbeat enabled (default) 5105 # Value range is [0,1]. Default value is 1. 5106 */ 5107 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat."); 5108 5109 /* 5110 # lpfc_EnableXLane: Enable Express Lane Feature 5111 # 0x0 Express Lane Feature disabled 5112 # 0x1 Express Lane Feature enabled 5113 # Value range is [0,1]. Default value is 0. 5114 */ 5115 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature."); 5116 5117 /* 5118 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature 5119 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits) 5120 # Value range is [0x0,0x7f]. Default value is 0 5121 */ 5122 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature."); 5123 5124 /* 5125 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF) 5126 # 0 = BlockGuard disabled (default) 5127 # 1 = BlockGuard enabled 5128 # Value range is [0,1]. Default value is 0. 5129 */ 5130 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support"); 5131 5132 /* 5133 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine 5134 # 0 = disabled (default) 5135 # 1 = enabled 5136 # Value range is [0,1]. Default value is 0. 5137 # 5138 # This feature in under investigation and may be supported in the future. 5139 */ 5140 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF; 5141 5142 /* 5143 # lpfc_prot_mask: i 5144 # - Bit mask of host protection capabilities used to register with the 5145 # SCSI mid-layer 5146 # - Only meaningful if BG is turned on (lpfc_enable_bg=1). 5147 # - Allows you to ultimately specify which profiles to use 5148 # - Default will result in registering capabilities for all profiles. 5149 # - SHOST_DIF_TYPE1_PROTECTION 1 5150 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection 5151 # - SHOST_DIX_TYPE0_PROTECTION 8 5152 # HBA supports DIX Type 0: Host to HBA protection only 5153 # - SHOST_DIX_TYPE1_PROTECTION 16 5154 # HBA supports DIX Type 1: Host to HBA Type 1 protection 5155 # 5156 */ 5157 LPFC_ATTR(prot_mask, 5158 (SHOST_DIF_TYPE1_PROTECTION | 5159 SHOST_DIX_TYPE0_PROTECTION | 5160 SHOST_DIX_TYPE1_PROTECTION), 5161 0, 5162 (SHOST_DIF_TYPE1_PROTECTION | 5163 SHOST_DIX_TYPE0_PROTECTION | 5164 SHOST_DIX_TYPE1_PROTECTION), 5165 "T10-DIF host protection capabilities mask"); 5166 5167 /* 5168 # lpfc_prot_guard: i 5169 # - Bit mask of protection guard types to register with the SCSI mid-layer 5170 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum 5171 # - Allows you to ultimately specify which profiles to use 5172 # - Default will result in registering capabilities for all guard types 5173 # 5174 */ 5175 LPFC_ATTR(prot_guard, 5176 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP, 5177 "T10-DIF host protection guard type"); 5178 5179 /* 5180 * Delay initial NPort discovery when Clean Address bit is cleared in 5181 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed. 5182 * This parameter can have value 0 or 1. 5183 * When this parameter is set to 0, no delay is added to the initial 5184 * discovery. 5185 * When this parameter is set to non-zero value, initial Nport discovery is 5186 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC 5187 * accept and FCID/Fabric name/Fabric portname is changed. 5188 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion 5189 * when Clean Address bit is cleared in FLOGI/FDISC 5190 * accept and FCID/Fabric name/Fabric portname is changed. 5191 * Default value is 0. 5192 */ 5193 LPFC_ATTR(delay_discovery, 0, 0, 1, 5194 "Delay NPort discovery when Clean Address bit is cleared."); 5195 5196 /* 5197 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count 5198 * This value can be set to values between 64 and 4096. The default value is 5199 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer 5200 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE). 5201 * Because of the additional overhead involved in setting up T10-DIF, 5202 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4 5203 * and will be limited to 512 if BlockGuard is enabled under SLI3. 5204 */ 5205 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_MIN_SG_SEG_CNT, 5206 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count"); 5207 5208 /* 5209 * lpfc_enable_mds_diags: Enable MDS Diagnostics 5210 * 0 = MDS Diagnostics disabled (default) 5211 * 1 = MDS Diagnostics enabled 5212 * Value range is [0,1]. Default value is 0. 5213 */ 5214 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics"); 5215 5216 /* 5217 * lpfc_enable_bbcr: Enable BB Credit Recovery 5218 * 0 = BB Credit Recovery disabled 5219 * 1 = BB Credit Recovery enabled (default) 5220 * Value range is [0,1]. Default value is 1. 5221 */ 5222 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery"); 5223 5224 /* 5225 * lpfc_enable_dpp: Enable DPP on G7 5226 * 0 = DPP on G7 disabled 5227 * 1 = DPP on G7 enabled (default) 5228 * Value range is [0,1]. Default value is 1. 5229 */ 5230 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push"); 5231 5232 struct device_attribute *lpfc_hba_attrs[] = { 5233 &dev_attr_nvme_info, 5234 &dev_attr_bg_info, 5235 &dev_attr_bg_guard_err, 5236 &dev_attr_bg_apptag_err, 5237 &dev_attr_bg_reftag_err, 5238 &dev_attr_info, 5239 &dev_attr_serialnum, 5240 &dev_attr_modeldesc, 5241 &dev_attr_modelname, 5242 &dev_attr_programtype, 5243 &dev_attr_portnum, 5244 &dev_attr_fwrev, 5245 &dev_attr_hdw, 5246 &dev_attr_option_rom_version, 5247 &dev_attr_link_state, 5248 &dev_attr_num_discovered_ports, 5249 &dev_attr_menlo_mgmt_mode, 5250 &dev_attr_lpfc_drvr_version, 5251 &dev_attr_lpfc_enable_fip, 5252 &dev_attr_lpfc_temp_sensor, 5253 &dev_attr_lpfc_log_verbose, 5254 &dev_attr_lpfc_lun_queue_depth, 5255 &dev_attr_lpfc_tgt_queue_depth, 5256 &dev_attr_lpfc_hba_queue_depth, 5257 &dev_attr_lpfc_peer_port_login, 5258 &dev_attr_lpfc_nodev_tmo, 5259 &dev_attr_lpfc_devloss_tmo, 5260 &dev_attr_lpfc_enable_fc4_type, 5261 &dev_attr_lpfc_xri_split, 5262 &dev_attr_lpfc_fcp_class, 5263 &dev_attr_lpfc_use_adisc, 5264 &dev_attr_lpfc_first_burst_size, 5265 &dev_attr_lpfc_ack0, 5266 &dev_attr_lpfc_topology, 5267 &dev_attr_lpfc_scan_down, 5268 &dev_attr_lpfc_link_speed, 5269 &dev_attr_lpfc_fcp_io_sched, 5270 &dev_attr_lpfc_fcp2_no_tgt_reset, 5271 &dev_attr_lpfc_cr_delay, 5272 &dev_attr_lpfc_cr_count, 5273 &dev_attr_lpfc_multi_ring_support, 5274 &dev_attr_lpfc_multi_ring_rctl, 5275 &dev_attr_lpfc_multi_ring_type, 5276 &dev_attr_lpfc_fdmi_on, 5277 &dev_attr_lpfc_enable_SmartSAN, 5278 &dev_attr_lpfc_max_luns, 5279 &dev_attr_lpfc_enable_npiv, 5280 &dev_attr_lpfc_fcf_failover_policy, 5281 &dev_attr_lpfc_enable_rrq, 5282 &dev_attr_nport_evt_cnt, 5283 &dev_attr_board_mode, 5284 &dev_attr_max_vpi, 5285 &dev_attr_used_vpi, 5286 &dev_attr_max_rpi, 5287 &dev_attr_used_rpi, 5288 &dev_attr_max_xri, 5289 &dev_attr_used_xri, 5290 &dev_attr_npiv_info, 5291 &dev_attr_issue_reset, 5292 &dev_attr_lpfc_poll, 5293 &dev_attr_lpfc_poll_tmo, 5294 &dev_attr_lpfc_task_mgmt_tmo, 5295 &dev_attr_lpfc_use_msi, 5296 &dev_attr_lpfc_nvme_oas, 5297 &dev_attr_lpfc_nvme_embed_cmd, 5298 &dev_attr_lpfc_auto_imax, 5299 &dev_attr_lpfc_fcp_imax, 5300 &dev_attr_lpfc_fcp_cpu_map, 5301 &dev_attr_lpfc_fcp_io_channel, 5302 &dev_attr_lpfc_suppress_rsp, 5303 &dev_attr_lpfc_nvme_io_channel, 5304 &dev_attr_lpfc_nvmet_mrq, 5305 &dev_attr_lpfc_nvme_enable_fb, 5306 &dev_attr_lpfc_nvmet_fb_size, 5307 &dev_attr_lpfc_enable_bg, 5308 &dev_attr_lpfc_soft_wwnn, 5309 &dev_attr_lpfc_soft_wwpn, 5310 &dev_attr_lpfc_soft_wwn_enable, 5311 &dev_attr_lpfc_enable_hba_reset, 5312 &dev_attr_lpfc_enable_hba_heartbeat, 5313 &dev_attr_lpfc_EnableXLane, 5314 &dev_attr_lpfc_XLanePriority, 5315 &dev_attr_lpfc_xlane_lun, 5316 &dev_attr_lpfc_xlane_tgt, 5317 &dev_attr_lpfc_xlane_vpt, 5318 &dev_attr_lpfc_xlane_lun_state, 5319 &dev_attr_lpfc_xlane_lun_status, 5320 &dev_attr_lpfc_xlane_priority, 5321 &dev_attr_lpfc_sg_seg_cnt, 5322 &dev_attr_lpfc_max_scsicmpl_time, 5323 &dev_attr_lpfc_stat_data_ctrl, 5324 &dev_attr_lpfc_aer_support, 5325 &dev_attr_lpfc_aer_state_cleanup, 5326 &dev_attr_lpfc_sriov_nr_virtfn, 5327 &dev_attr_lpfc_req_fw_upgrade, 5328 &dev_attr_lpfc_suppress_link_up, 5329 &dev_attr_lpfc_iocb_cnt, 5330 &dev_attr_iocb_hw, 5331 &dev_attr_txq_hw, 5332 &dev_attr_txcmplq_hw, 5333 &dev_attr_lpfc_fips_level, 5334 &dev_attr_lpfc_fips_rev, 5335 &dev_attr_lpfc_dss, 5336 &dev_attr_lpfc_sriov_hw_max_virtfn, 5337 &dev_attr_protocol, 5338 &dev_attr_lpfc_xlane_supported, 5339 &dev_attr_lpfc_enable_mds_diags, 5340 &dev_attr_lpfc_enable_bbcr, 5341 &dev_attr_lpfc_enable_dpp, 5342 NULL, 5343 }; 5344 5345 struct device_attribute *lpfc_vport_attrs[] = { 5346 &dev_attr_info, 5347 &dev_attr_link_state, 5348 &dev_attr_num_discovered_ports, 5349 &dev_attr_lpfc_drvr_version, 5350 &dev_attr_lpfc_log_verbose, 5351 &dev_attr_lpfc_lun_queue_depth, 5352 &dev_attr_lpfc_tgt_queue_depth, 5353 &dev_attr_lpfc_nodev_tmo, 5354 &dev_attr_lpfc_devloss_tmo, 5355 &dev_attr_lpfc_hba_queue_depth, 5356 &dev_attr_lpfc_peer_port_login, 5357 &dev_attr_lpfc_restrict_login, 5358 &dev_attr_lpfc_fcp_class, 5359 &dev_attr_lpfc_use_adisc, 5360 &dev_attr_lpfc_first_burst_size, 5361 &dev_attr_lpfc_max_luns, 5362 &dev_attr_nport_evt_cnt, 5363 &dev_attr_npiv_info, 5364 &dev_attr_lpfc_enable_da_id, 5365 &dev_attr_lpfc_max_scsicmpl_time, 5366 &dev_attr_lpfc_stat_data_ctrl, 5367 &dev_attr_lpfc_static_vport, 5368 &dev_attr_lpfc_fips_level, 5369 &dev_attr_lpfc_fips_rev, 5370 NULL, 5371 }; 5372 5373 /** 5374 * sysfs_ctlreg_write - Write method for writing to ctlreg 5375 * @filp: open sysfs file 5376 * @kobj: kernel kobject that contains the kernel class device. 5377 * @bin_attr: kernel attributes passed to us. 5378 * @buf: contains the data to be written to the adapter IOREG space. 5379 * @off: offset into buffer to beginning of data. 5380 * @count: bytes to transfer. 5381 * 5382 * Description: 5383 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. 5384 * Uses the adapter io control registers to send buf contents to the adapter. 5385 * 5386 * Returns: 5387 * -ERANGE off and count combo out of range 5388 * -EINVAL off, count or buff address invalid 5389 * -EPERM adapter is offline 5390 * value of count, buf contents written 5391 **/ 5392 static ssize_t 5393 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj, 5394 struct bin_attribute *bin_attr, 5395 char *buf, loff_t off, size_t count) 5396 { 5397 size_t buf_off; 5398 struct device *dev = container_of(kobj, struct device, kobj); 5399 struct Scsi_Host *shost = class_to_shost(dev); 5400 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 5401 struct lpfc_hba *phba = vport->phba; 5402 5403 if (phba->sli_rev >= LPFC_SLI_REV4) 5404 return -EPERM; 5405 5406 if ((off + count) > FF_REG_AREA_SIZE) 5407 return -ERANGE; 5408 5409 if (count <= LPFC_REG_WRITE_KEY_SIZE) 5410 return 0; 5411 5412 if (off % 4 || count % 4 || (unsigned long)buf % 4) 5413 return -EINVAL; 5414 5415 /* This is to protect HBA registers from accidental writes. */ 5416 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE)) 5417 return -EINVAL; 5418 5419 if (!(vport->fc_flag & FC_OFFLINE_MODE)) 5420 return -EPERM; 5421 5422 spin_lock_irq(&phba->hbalock); 5423 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE; 5424 buf_off += sizeof(uint32_t)) 5425 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)), 5426 phba->ctrl_regs_memmap_p + off + buf_off); 5427 5428 spin_unlock_irq(&phba->hbalock); 5429 5430 return count; 5431 } 5432 5433 /** 5434 * sysfs_ctlreg_read - Read method for reading from ctlreg 5435 * @filp: open sysfs file 5436 * @kobj: kernel kobject that contains the kernel class device. 5437 * @bin_attr: kernel attributes passed to us. 5438 * @buf: if successful contains the data from the adapter IOREG space. 5439 * @off: offset into buffer to beginning of data. 5440 * @count: bytes to transfer. 5441 * 5442 * Description: 5443 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. 5444 * Uses the adapter io control registers to read data into buf. 5445 * 5446 * Returns: 5447 * -ERANGE off and count combo out of range 5448 * -EINVAL off, count or buff address invalid 5449 * value of count, buf contents read 5450 **/ 5451 static ssize_t 5452 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj, 5453 struct bin_attribute *bin_attr, 5454 char *buf, loff_t off, size_t count) 5455 { 5456 size_t buf_off; 5457 uint32_t * tmp_ptr; 5458 struct device *dev = container_of(kobj, struct device, kobj); 5459 struct Scsi_Host *shost = class_to_shost(dev); 5460 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 5461 struct lpfc_hba *phba = vport->phba; 5462 5463 if (phba->sli_rev >= LPFC_SLI_REV4) 5464 return -EPERM; 5465 5466 if (off > FF_REG_AREA_SIZE) 5467 return -ERANGE; 5468 5469 if ((off + count) > FF_REG_AREA_SIZE) 5470 count = FF_REG_AREA_SIZE - off; 5471 5472 if (count == 0) return 0; 5473 5474 if (off % 4 || count % 4 || (unsigned long)buf % 4) 5475 return -EINVAL; 5476 5477 spin_lock_irq(&phba->hbalock); 5478 5479 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { 5480 tmp_ptr = (uint32_t *)(buf + buf_off); 5481 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); 5482 } 5483 5484 spin_unlock_irq(&phba->hbalock); 5485 5486 return count; 5487 } 5488 5489 static struct bin_attribute sysfs_ctlreg_attr = { 5490 .attr = { 5491 .name = "ctlreg", 5492 .mode = S_IRUSR | S_IWUSR, 5493 }, 5494 .size = 256, 5495 .read = sysfs_ctlreg_read, 5496 .write = sysfs_ctlreg_write, 5497 }; 5498 5499 /** 5500 * sysfs_mbox_write - Write method for writing information via mbox 5501 * @filp: open sysfs file 5502 * @kobj: kernel kobject that contains the kernel class device. 5503 * @bin_attr: kernel attributes passed to us. 5504 * @buf: contains the data to be written to sysfs mbox. 5505 * @off: offset into buffer to beginning of data. 5506 * @count: bytes to transfer. 5507 * 5508 * Description: 5509 * Deprecated function. All mailbox access from user space is performed via the 5510 * bsg interface. 5511 * 5512 * Returns: 5513 * -EPERM operation not permitted 5514 **/ 5515 static ssize_t 5516 sysfs_mbox_write(struct file *filp, struct kobject *kobj, 5517 struct bin_attribute *bin_attr, 5518 char *buf, loff_t off, size_t count) 5519 { 5520 return -EPERM; 5521 } 5522 5523 /** 5524 * sysfs_mbox_read - Read method for reading information via mbox 5525 * @filp: open sysfs file 5526 * @kobj: kernel kobject that contains the kernel class device. 5527 * @bin_attr: kernel attributes passed to us. 5528 * @buf: contains the data to be read from sysfs mbox. 5529 * @off: offset into buffer to beginning of data. 5530 * @count: bytes to transfer. 5531 * 5532 * Description: 5533 * Deprecated function. All mailbox access from user space is performed via the 5534 * bsg interface. 5535 * 5536 * Returns: 5537 * -EPERM operation not permitted 5538 **/ 5539 static ssize_t 5540 sysfs_mbox_read(struct file *filp, struct kobject *kobj, 5541 struct bin_attribute *bin_attr, 5542 char *buf, loff_t off, size_t count) 5543 { 5544 return -EPERM; 5545 } 5546 5547 static struct bin_attribute sysfs_mbox_attr = { 5548 .attr = { 5549 .name = "mbox", 5550 .mode = S_IRUSR | S_IWUSR, 5551 }, 5552 .size = MAILBOX_SYSFS_MAX, 5553 .read = sysfs_mbox_read, 5554 .write = sysfs_mbox_write, 5555 }; 5556 5557 /** 5558 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries 5559 * @vport: address of lpfc vport structure. 5560 * 5561 * Return codes: 5562 * zero on success 5563 * error return code from sysfs_create_bin_file() 5564 **/ 5565 int 5566 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport) 5567 { 5568 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 5569 int error; 5570 5571 error = sysfs_create_bin_file(&shost->shost_dev.kobj, 5572 &sysfs_drvr_stat_data_attr); 5573 5574 /* Virtual ports do not need ctrl_reg and mbox */ 5575 if (error || vport->port_type == LPFC_NPIV_PORT) 5576 goto out; 5577 5578 error = sysfs_create_bin_file(&shost->shost_dev.kobj, 5579 &sysfs_ctlreg_attr); 5580 if (error) 5581 goto out_remove_stat_attr; 5582 5583 error = sysfs_create_bin_file(&shost->shost_dev.kobj, 5584 &sysfs_mbox_attr); 5585 if (error) 5586 goto out_remove_ctlreg_attr; 5587 5588 return 0; 5589 out_remove_ctlreg_attr: 5590 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); 5591 out_remove_stat_attr: 5592 sysfs_remove_bin_file(&shost->shost_dev.kobj, 5593 &sysfs_drvr_stat_data_attr); 5594 out: 5595 return error; 5596 } 5597 5598 /** 5599 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries 5600 * @vport: address of lpfc vport structure. 5601 **/ 5602 void 5603 lpfc_free_sysfs_attr(struct lpfc_vport *vport) 5604 { 5605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 5606 sysfs_remove_bin_file(&shost->shost_dev.kobj, 5607 &sysfs_drvr_stat_data_attr); 5608 /* Virtual ports do not need ctrl_reg and mbox */ 5609 if (vport->port_type == LPFC_NPIV_PORT) 5610 return; 5611 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr); 5612 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); 5613 } 5614 5615 /* 5616 * Dynamic FC Host Attributes Support 5617 */ 5618 5619 /** 5620 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host 5621 * @shost: kernel scsi host pointer. 5622 **/ 5623 static void 5624 lpfc_get_host_symbolic_name(struct Scsi_Host *shost) 5625 { 5626 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; 5627 5628 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), 5629 sizeof fc_host_symbolic_name(shost)); 5630 } 5631 5632 /** 5633 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id 5634 * @shost: kernel scsi host pointer. 5635 **/ 5636 static void 5637 lpfc_get_host_port_id(struct Scsi_Host *shost) 5638 { 5639 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 5640 5641 /* note: fc_myDID already in cpu endianness */ 5642 fc_host_port_id(shost) = vport->fc_myDID; 5643 } 5644 5645 /** 5646 * lpfc_get_host_port_type - Set the value of the scsi host port type 5647 * @shost: kernel scsi host pointer. 5648 **/ 5649 static void 5650 lpfc_get_host_port_type(struct Scsi_Host *shost) 5651 { 5652 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 5653 struct lpfc_hba *phba = vport->phba; 5654 5655 spin_lock_irq(shost->host_lock); 5656 5657 if (vport->port_type == LPFC_NPIV_PORT) { 5658 fc_host_port_type(shost) = FC_PORTTYPE_NPIV; 5659 } else if (lpfc_is_link_up(phba)) { 5660 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { 5661 if (vport->fc_flag & FC_PUBLIC_LOOP) 5662 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; 5663 else 5664 fc_host_port_type(shost) = FC_PORTTYPE_LPORT; 5665 } else { 5666 if (vport->fc_flag & FC_FABRIC) 5667 fc_host_port_type(shost) = FC_PORTTYPE_NPORT; 5668 else 5669 fc_host_port_type(shost) = FC_PORTTYPE_PTP; 5670 } 5671 } else 5672 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; 5673 5674 spin_unlock_irq(shost->host_lock); 5675 } 5676 5677 /** 5678 * lpfc_get_host_port_state - Set the value of the scsi host port state 5679 * @shost: kernel scsi host pointer. 5680 **/ 5681 static void 5682 lpfc_get_host_port_state(struct Scsi_Host *shost) 5683 { 5684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 5685 struct lpfc_hba *phba = vport->phba; 5686 5687 spin_lock_irq(shost->host_lock); 5688 5689 if (vport->fc_flag & FC_OFFLINE_MODE) 5690 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; 5691 else { 5692 switch (phba->link_state) { 5693 case LPFC_LINK_UNKNOWN: 5694 case LPFC_LINK_DOWN: 5695 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; 5696 break; 5697 case LPFC_LINK_UP: 5698 case LPFC_CLEAR_LA: 5699 case LPFC_HBA_READY: 5700 /* Links up, reports port state accordingly */ 5701 if (vport->port_state < LPFC_VPORT_READY) 5702 fc_host_port_state(shost) = 5703 FC_PORTSTATE_BYPASSED; 5704 else 5705 fc_host_port_state(shost) = 5706 FC_PORTSTATE_ONLINE; 5707 break; 5708 case LPFC_HBA_ERROR: 5709 fc_host_port_state(shost) = FC_PORTSTATE_ERROR; 5710 break; 5711 default: 5712 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; 5713 break; 5714 } 5715 } 5716 5717 spin_unlock_irq(shost->host_lock); 5718 } 5719 5720 /** 5721 * lpfc_get_host_speed - Set the value of the scsi host speed 5722 * @shost: kernel scsi host pointer. 5723 **/ 5724 static void 5725 lpfc_get_host_speed(struct Scsi_Host *shost) 5726 { 5727 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 5728 struct lpfc_hba *phba = vport->phba; 5729 5730 spin_lock_irq(shost->host_lock); 5731 5732 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) { 5733 switch(phba->fc_linkspeed) { 5734 case LPFC_LINK_SPEED_1GHZ: 5735 fc_host_speed(shost) = FC_PORTSPEED_1GBIT; 5736 break; 5737 case LPFC_LINK_SPEED_2GHZ: 5738 fc_host_speed(shost) = FC_PORTSPEED_2GBIT; 5739 break; 5740 case LPFC_LINK_SPEED_4GHZ: 5741 fc_host_speed(shost) = FC_PORTSPEED_4GBIT; 5742 break; 5743 case LPFC_LINK_SPEED_8GHZ: 5744 fc_host_speed(shost) = FC_PORTSPEED_8GBIT; 5745 break; 5746 case LPFC_LINK_SPEED_10GHZ: 5747 fc_host_speed(shost) = FC_PORTSPEED_10GBIT; 5748 break; 5749 case LPFC_LINK_SPEED_16GHZ: 5750 fc_host_speed(shost) = FC_PORTSPEED_16GBIT; 5751 break; 5752 case LPFC_LINK_SPEED_32GHZ: 5753 fc_host_speed(shost) = FC_PORTSPEED_32GBIT; 5754 break; 5755 case LPFC_LINK_SPEED_64GHZ: 5756 fc_host_speed(shost) = FC_PORTSPEED_64GBIT; 5757 break; 5758 default: 5759 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; 5760 break; 5761 } 5762 } else 5763 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; 5764 5765 spin_unlock_irq(shost->host_lock); 5766 } 5767 5768 /** 5769 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name 5770 * @shost: kernel scsi host pointer. 5771 **/ 5772 static void 5773 lpfc_get_host_fabric_name (struct Scsi_Host *shost) 5774 { 5775 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 5776 struct lpfc_hba *phba = vport->phba; 5777 u64 node_name; 5778 5779 spin_lock_irq(shost->host_lock); 5780 5781 if ((vport->port_state > LPFC_FLOGI) && 5782 ((vport->fc_flag & FC_FABRIC) || 5783 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && 5784 (vport->fc_flag & FC_PUBLIC_LOOP)))) 5785 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); 5786 else 5787 /* fabric is local port if there is no F/FL_Port */ 5788 node_name = 0; 5789 5790 spin_unlock_irq(shost->host_lock); 5791 5792 fc_host_fabric_name(shost) = node_name; 5793 } 5794 5795 /** 5796 * lpfc_get_stats - Return statistical information about the adapter 5797 * @shost: kernel scsi host pointer. 5798 * 5799 * Notes: 5800 * NULL on error for link down, no mbox pool, sli2 active, 5801 * management not allowed, memory allocation error, or mbox error. 5802 * 5803 * Returns: 5804 * NULL for error 5805 * address of the adapter host statistics 5806 **/ 5807 static struct fc_host_statistics * 5808 lpfc_get_stats(struct Scsi_Host *shost) 5809 { 5810 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 5811 struct lpfc_hba *phba = vport->phba; 5812 struct lpfc_sli *psli = &phba->sli; 5813 struct fc_host_statistics *hs = &phba->link_stats; 5814 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; 5815 LPFC_MBOXQ_t *pmboxq; 5816 MAILBOX_t *pmb; 5817 unsigned long seconds; 5818 int rc = 0; 5819 5820 /* 5821 * prevent udev from issuing mailbox commands until the port is 5822 * configured. 5823 */ 5824 if (phba->link_state < LPFC_LINK_DOWN || 5825 !phba->mbox_mem_pool || 5826 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) 5827 return NULL; 5828 5829 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) 5830 return NULL; 5831 5832 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 5833 if (!pmboxq) 5834 return NULL; 5835 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 5836 5837 pmb = &pmboxq->u.mb; 5838 pmb->mbxCommand = MBX_READ_STATUS; 5839 pmb->mbxOwner = OWN_HOST; 5840 pmboxq->context1 = NULL; 5841 pmboxq->vport = vport; 5842 5843 if (vport->fc_flag & FC_OFFLINE_MODE) 5844 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 5845 else 5846 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 5847 5848 if (rc != MBX_SUCCESS) { 5849 if (rc != MBX_TIMEOUT) 5850 mempool_free(pmboxq, phba->mbox_mem_pool); 5851 return NULL; 5852 } 5853 5854 memset(hs, 0, sizeof (struct fc_host_statistics)); 5855 5856 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; 5857 /* 5858 * The MBX_READ_STATUS returns tx_k_bytes which has to 5859 * converted to words 5860 */ 5861 hs->tx_words = (uint64_t) 5862 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt 5863 * (uint64_t)256); 5864 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; 5865 hs->rx_words = (uint64_t) 5866 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt 5867 * (uint64_t)256); 5868 5869 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 5870 pmb->mbxCommand = MBX_READ_LNK_STAT; 5871 pmb->mbxOwner = OWN_HOST; 5872 pmboxq->context1 = NULL; 5873 pmboxq->vport = vport; 5874 5875 if (vport->fc_flag & FC_OFFLINE_MODE) 5876 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 5877 else 5878 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 5879 5880 if (rc != MBX_SUCCESS) { 5881 if (rc != MBX_TIMEOUT) 5882 mempool_free(pmboxq, phba->mbox_mem_pool); 5883 return NULL; 5884 } 5885 5886 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; 5887 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; 5888 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; 5889 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; 5890 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; 5891 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; 5892 hs->error_frames = pmb->un.varRdLnk.crcCnt; 5893 5894 hs->link_failure_count -= lso->link_failure_count; 5895 hs->loss_of_sync_count -= lso->loss_of_sync_count; 5896 hs->loss_of_signal_count -= lso->loss_of_signal_count; 5897 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count; 5898 hs->invalid_tx_word_count -= lso->invalid_tx_word_count; 5899 hs->invalid_crc_count -= lso->invalid_crc_count; 5900 hs->error_frames -= lso->error_frames; 5901 5902 if (phba->hba_flag & HBA_FCOE_MODE) { 5903 hs->lip_count = -1; 5904 hs->nos_count = (phba->link_events >> 1); 5905 hs->nos_count -= lso->link_events; 5906 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { 5907 hs->lip_count = (phba->fc_eventTag >> 1); 5908 hs->lip_count -= lso->link_events; 5909 hs->nos_count = -1; 5910 } else { 5911 hs->lip_count = -1; 5912 hs->nos_count = (phba->fc_eventTag >> 1); 5913 hs->nos_count -= lso->link_events; 5914 } 5915 5916 hs->dumped_frames = -1; 5917 5918 seconds = get_seconds(); 5919 if (seconds < psli->stats_start) 5920 hs->seconds_since_last_reset = seconds + 5921 ((unsigned long)-1 - psli->stats_start); 5922 else 5923 hs->seconds_since_last_reset = seconds - psli->stats_start; 5924 5925 mempool_free(pmboxq, phba->mbox_mem_pool); 5926 5927 return hs; 5928 } 5929 5930 /** 5931 * lpfc_reset_stats - Copy the adapter link stats information 5932 * @shost: kernel scsi host pointer. 5933 **/ 5934 static void 5935 lpfc_reset_stats(struct Scsi_Host *shost) 5936 { 5937 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 5938 struct lpfc_hba *phba = vport->phba; 5939 struct lpfc_sli *psli = &phba->sli; 5940 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets; 5941 LPFC_MBOXQ_t *pmboxq; 5942 MAILBOX_t *pmb; 5943 int rc = 0; 5944 5945 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) 5946 return; 5947 5948 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 5949 if (!pmboxq) 5950 return; 5951 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); 5952 5953 pmb = &pmboxq->u.mb; 5954 pmb->mbxCommand = MBX_READ_STATUS; 5955 pmb->mbxOwner = OWN_HOST; 5956 pmb->un.varWords[0] = 0x1; /* reset request */ 5957 pmboxq->context1 = NULL; 5958 pmboxq->vport = vport; 5959 5960 if ((vport->fc_flag & FC_OFFLINE_MODE) || 5961 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) 5962 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 5963 else 5964 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 5965 5966 if (rc != MBX_SUCCESS) { 5967 if (rc != MBX_TIMEOUT) 5968 mempool_free(pmboxq, phba->mbox_mem_pool); 5969 return; 5970 } 5971 5972 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); 5973 pmb->mbxCommand = MBX_READ_LNK_STAT; 5974 pmb->mbxOwner = OWN_HOST; 5975 pmboxq->context1 = NULL; 5976 pmboxq->vport = vport; 5977 5978 if ((vport->fc_flag & FC_OFFLINE_MODE) || 5979 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) 5980 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 5981 else 5982 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 5983 5984 if (rc != MBX_SUCCESS) { 5985 if (rc != MBX_TIMEOUT) 5986 mempool_free( pmboxq, phba->mbox_mem_pool); 5987 return; 5988 } 5989 5990 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; 5991 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; 5992 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; 5993 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; 5994 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; 5995 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt; 5996 lso->error_frames = pmb->un.varRdLnk.crcCnt; 5997 if (phba->hba_flag & HBA_FCOE_MODE) 5998 lso->link_events = (phba->link_events >> 1); 5999 else 6000 lso->link_events = (phba->fc_eventTag >> 1); 6001 6002 psli->stats_start = get_seconds(); 6003 6004 mempool_free(pmboxq, phba->mbox_mem_pool); 6005 6006 return; 6007 } 6008 6009 /* 6010 * The LPFC driver treats linkdown handling as target loss events so there 6011 * are no sysfs handlers for link_down_tmo. 6012 */ 6013 6014 /** 6015 * lpfc_get_node_by_target - Return the nodelist for a target 6016 * @starget: kernel scsi target pointer. 6017 * 6018 * Returns: 6019 * address of the node list if found 6020 * NULL target not found 6021 **/ 6022 static struct lpfc_nodelist * 6023 lpfc_get_node_by_target(struct scsi_target *starget) 6024 { 6025 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 6026 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 6027 struct lpfc_nodelist *ndlp; 6028 6029 spin_lock_irq(shost->host_lock); 6030 /* Search for this, mapped, target ID */ 6031 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { 6032 if (NLP_CHK_NODE_ACT(ndlp) && 6033 ndlp->nlp_state == NLP_STE_MAPPED_NODE && 6034 starget->id == ndlp->nlp_sid) { 6035 spin_unlock_irq(shost->host_lock); 6036 return ndlp; 6037 } 6038 } 6039 spin_unlock_irq(shost->host_lock); 6040 return NULL; 6041 } 6042 6043 /** 6044 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1 6045 * @starget: kernel scsi target pointer. 6046 **/ 6047 static void 6048 lpfc_get_starget_port_id(struct scsi_target *starget) 6049 { 6050 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); 6051 6052 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1; 6053 } 6054 6055 /** 6056 * lpfc_get_starget_node_name - Set the target node name 6057 * @starget: kernel scsi target pointer. 6058 * 6059 * Description: Set the target node name to the ndlp node name wwn or zero. 6060 **/ 6061 static void 6062 lpfc_get_starget_node_name(struct scsi_target *starget) 6063 { 6064 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); 6065 6066 fc_starget_node_name(starget) = 6067 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0; 6068 } 6069 6070 /** 6071 * lpfc_get_starget_port_name - Set the target port name 6072 * @starget: kernel scsi target pointer. 6073 * 6074 * Description: set the target port name to the ndlp port name wwn or zero. 6075 **/ 6076 static void 6077 lpfc_get_starget_port_name(struct scsi_target *starget) 6078 { 6079 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); 6080 6081 fc_starget_port_name(starget) = 6082 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0; 6083 } 6084 6085 /** 6086 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo 6087 * @rport: fc rport address. 6088 * @timeout: new value for dev loss tmo. 6089 * 6090 * Description: 6091 * If timeout is non zero set the dev_loss_tmo to timeout, else set 6092 * dev_loss_tmo to one. 6093 **/ 6094 static void 6095 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) 6096 { 6097 if (timeout) 6098 rport->dev_loss_tmo = timeout; 6099 else 6100 rport->dev_loss_tmo = 1; 6101 } 6102 6103 /** 6104 * lpfc_rport_show_function - Return rport target information 6105 * 6106 * Description: 6107 * Macro that uses field to generate a function with the name lpfc_show_rport_ 6108 * 6109 * lpfc_show_rport_##field: returns the bytes formatted in buf 6110 * @cdev: class converted to an fc_rport. 6111 * @buf: on return contains the target_field or zero. 6112 * 6113 * Returns: size of formatted string. 6114 **/ 6115 #define lpfc_rport_show_function(field, format_string, sz, cast) \ 6116 static ssize_t \ 6117 lpfc_show_rport_##field (struct device *dev, \ 6118 struct device_attribute *attr, \ 6119 char *buf) \ 6120 { \ 6121 struct fc_rport *rport = transport_class_to_rport(dev); \ 6122 struct lpfc_rport_data *rdata = rport->hostdata; \ 6123 return snprintf(buf, sz, format_string, \ 6124 (rdata->target) ? cast rdata->target->field : 0); \ 6125 } 6126 6127 #define lpfc_rport_rd_attr(field, format_string, sz) \ 6128 lpfc_rport_show_function(field, format_string, sz, ) \ 6129 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) 6130 6131 /** 6132 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name 6133 * @fc_vport: The fc_vport who's symbolic name has been changed. 6134 * 6135 * Description: 6136 * This function is called by the transport after the @fc_vport's symbolic name 6137 * has been changed. This function re-registers the symbolic name with the 6138 * switch to propagate the change into the fabric if the vport is active. 6139 **/ 6140 static void 6141 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport) 6142 { 6143 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data; 6144 6145 if (vport->port_state == LPFC_VPORT_READY) 6146 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); 6147 } 6148 6149 /** 6150 * lpfc_hba_log_verbose_init - Set hba's log verbose level 6151 * @phba: Pointer to lpfc_hba struct. 6152 * 6153 * This function is called by the lpfc_get_cfgparam() routine to set the 6154 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with 6155 * log message according to the module's lpfc_log_verbose parameter setting 6156 * before hba port or vport created. 6157 **/ 6158 static void 6159 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose) 6160 { 6161 phba->cfg_log_verbose = verbose; 6162 } 6163 6164 struct fc_function_template lpfc_transport_functions = { 6165 /* fixed attributes the driver supports */ 6166 .show_host_node_name = 1, 6167 .show_host_port_name = 1, 6168 .show_host_supported_classes = 1, 6169 .show_host_supported_fc4s = 1, 6170 .show_host_supported_speeds = 1, 6171 .show_host_maxframe_size = 1, 6172 6173 .get_host_symbolic_name = lpfc_get_host_symbolic_name, 6174 .show_host_symbolic_name = 1, 6175 6176 /* dynamic attributes the driver supports */ 6177 .get_host_port_id = lpfc_get_host_port_id, 6178 .show_host_port_id = 1, 6179 6180 .get_host_port_type = lpfc_get_host_port_type, 6181 .show_host_port_type = 1, 6182 6183 .get_host_port_state = lpfc_get_host_port_state, 6184 .show_host_port_state = 1, 6185 6186 /* active_fc4s is shown but doesn't change (thus no get function) */ 6187 .show_host_active_fc4s = 1, 6188 6189 .get_host_speed = lpfc_get_host_speed, 6190 .show_host_speed = 1, 6191 6192 .get_host_fabric_name = lpfc_get_host_fabric_name, 6193 .show_host_fabric_name = 1, 6194 6195 /* 6196 * The LPFC driver treats linkdown handling as target loss events 6197 * so there are no sysfs handlers for link_down_tmo. 6198 */ 6199 6200 .get_fc_host_stats = lpfc_get_stats, 6201 .reset_fc_host_stats = lpfc_reset_stats, 6202 6203 .dd_fcrport_size = sizeof(struct lpfc_rport_data), 6204 .show_rport_maxframe_size = 1, 6205 .show_rport_supported_classes = 1, 6206 6207 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, 6208 .show_rport_dev_loss_tmo = 1, 6209 6210 .get_starget_port_id = lpfc_get_starget_port_id, 6211 .show_starget_port_id = 1, 6212 6213 .get_starget_node_name = lpfc_get_starget_node_name, 6214 .show_starget_node_name = 1, 6215 6216 .get_starget_port_name = lpfc_get_starget_port_name, 6217 .show_starget_port_name = 1, 6218 6219 .issue_fc_host_lip = lpfc_issue_lip, 6220 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, 6221 .terminate_rport_io = lpfc_terminate_rport_io, 6222 6223 .dd_fcvport_size = sizeof(struct lpfc_vport *), 6224 6225 .vport_disable = lpfc_vport_disable, 6226 6227 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, 6228 6229 .bsg_request = lpfc_bsg_request, 6230 .bsg_timeout = lpfc_bsg_timeout, 6231 }; 6232 6233 struct fc_function_template lpfc_vport_transport_functions = { 6234 /* fixed attributes the driver supports */ 6235 .show_host_node_name = 1, 6236 .show_host_port_name = 1, 6237 .show_host_supported_classes = 1, 6238 .show_host_supported_fc4s = 1, 6239 .show_host_supported_speeds = 1, 6240 .show_host_maxframe_size = 1, 6241 6242 .get_host_symbolic_name = lpfc_get_host_symbolic_name, 6243 .show_host_symbolic_name = 1, 6244 6245 /* dynamic attributes the driver supports */ 6246 .get_host_port_id = lpfc_get_host_port_id, 6247 .show_host_port_id = 1, 6248 6249 .get_host_port_type = lpfc_get_host_port_type, 6250 .show_host_port_type = 1, 6251 6252 .get_host_port_state = lpfc_get_host_port_state, 6253 .show_host_port_state = 1, 6254 6255 /* active_fc4s is shown but doesn't change (thus no get function) */ 6256 .show_host_active_fc4s = 1, 6257 6258 .get_host_speed = lpfc_get_host_speed, 6259 .show_host_speed = 1, 6260 6261 .get_host_fabric_name = lpfc_get_host_fabric_name, 6262 .show_host_fabric_name = 1, 6263 6264 /* 6265 * The LPFC driver treats linkdown handling as target loss events 6266 * so there are no sysfs handlers for link_down_tmo. 6267 */ 6268 6269 .get_fc_host_stats = lpfc_get_stats, 6270 .reset_fc_host_stats = lpfc_reset_stats, 6271 6272 .dd_fcrport_size = sizeof(struct lpfc_rport_data), 6273 .show_rport_maxframe_size = 1, 6274 .show_rport_supported_classes = 1, 6275 6276 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, 6277 .show_rport_dev_loss_tmo = 1, 6278 6279 .get_starget_port_id = lpfc_get_starget_port_id, 6280 .show_starget_port_id = 1, 6281 6282 .get_starget_node_name = lpfc_get_starget_node_name, 6283 .show_starget_node_name = 1, 6284 6285 .get_starget_port_name = lpfc_get_starget_port_name, 6286 .show_starget_port_name = 1, 6287 6288 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, 6289 .terminate_rport_io = lpfc_terminate_rport_io, 6290 6291 .vport_disable = lpfc_vport_disable, 6292 6293 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, 6294 }; 6295 6296 /** 6297 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure 6298 * @phba: lpfc_hba pointer. 6299 **/ 6300 void 6301 lpfc_get_cfgparam(struct lpfc_hba *phba) 6302 { 6303 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched); 6304 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset); 6305 lpfc_cr_delay_init(phba, lpfc_cr_delay); 6306 lpfc_cr_count_init(phba, lpfc_cr_count); 6307 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support); 6308 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl); 6309 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type); 6310 lpfc_ack0_init(phba, lpfc_ack0); 6311 lpfc_topology_init(phba, lpfc_topology); 6312 lpfc_link_speed_init(phba, lpfc_link_speed); 6313 lpfc_poll_tmo_init(phba, lpfc_poll_tmo); 6314 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo); 6315 lpfc_enable_npiv_init(phba, lpfc_enable_npiv); 6316 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy); 6317 lpfc_enable_rrq_init(phba, lpfc_enable_rrq); 6318 lpfc_fdmi_on_init(phba, lpfc_fdmi_on); 6319 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN); 6320 lpfc_use_msi_init(phba, lpfc_use_msi); 6321 lpfc_nvme_oas_init(phba, lpfc_nvme_oas); 6322 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd); 6323 lpfc_auto_imax_init(phba, lpfc_auto_imax); 6324 lpfc_fcp_imax_init(phba, lpfc_fcp_imax); 6325 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map); 6326 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset); 6327 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat); 6328 6329 lpfc_EnableXLane_init(phba, lpfc_EnableXLane); 6330 if (phba->sli_rev != LPFC_SLI_REV4) 6331 phba->cfg_EnableXLane = 0; 6332 lpfc_XLanePriority_init(phba, lpfc_XLanePriority); 6333 6334 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t))); 6335 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t))); 6336 phba->cfg_oas_lun_state = 0; 6337 phba->cfg_oas_lun_status = 0; 6338 phba->cfg_oas_flags = 0; 6339 phba->cfg_oas_priority = 0; 6340 lpfc_enable_bg_init(phba, lpfc_enable_bg); 6341 lpfc_prot_mask_init(phba, lpfc_prot_mask); 6342 lpfc_prot_guard_init(phba, lpfc_prot_guard); 6343 if (phba->sli_rev == LPFC_SLI_REV4) 6344 phba->cfg_poll = 0; 6345 else 6346 phba->cfg_poll = lpfc_poll; 6347 6348 if (phba->cfg_enable_bg) 6349 phba->sli3_options |= LPFC_SLI3_BG_ENABLED; 6350 6351 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp); 6352 6353 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type); 6354 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq); 6355 6356 /* Initialize first burst. Target vs Initiator are different. */ 6357 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb); 6358 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size); 6359 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel); 6360 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel); 6361 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr); 6362 lpfc_enable_dpp_init(phba, lpfc_enable_dpp); 6363 6364 if (phba->sli_rev != LPFC_SLI_REV4) { 6365 /* NVME only supported on SLI4 */ 6366 phba->nvmet_support = 0; 6367 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; 6368 phba->cfg_enable_bbcr = 0; 6369 } else { 6370 /* We MUST have FCP support */ 6371 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) 6372 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP; 6373 } 6374 6375 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax) 6376 phba->cfg_auto_imax = 0; 6377 phba->initial_imax = phba->cfg_fcp_imax; 6378 6379 /* A value of 0 means use the number of CPUs found in the system */ 6380 if (phba->cfg_fcp_io_channel == 0) 6381 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu; 6382 if (phba->cfg_nvme_io_channel == 0) 6383 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu; 6384 6385 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME) 6386 phba->cfg_fcp_io_channel = 0; 6387 6388 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) 6389 phba->cfg_nvme_io_channel = 0; 6390 6391 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel) 6392 phba->io_channel_irqs = phba->cfg_fcp_io_channel; 6393 else 6394 phba->io_channel_irqs = phba->cfg_nvme_io_channel; 6395 6396 phba->cfg_soft_wwnn = 0L; 6397 phba->cfg_soft_wwpn = 0L; 6398 lpfc_xri_split_init(phba, lpfc_xri_split); 6399 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt); 6400 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); 6401 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose); 6402 lpfc_aer_support_init(phba, lpfc_aer_support); 6403 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn); 6404 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade); 6405 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up); 6406 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt); 6407 lpfc_delay_discovery_init(phba, lpfc_delay_discovery); 6408 lpfc_sli_mode_init(phba, lpfc_sli_mode); 6409 phba->cfg_enable_dss = 1; 6410 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags); 6411 return; 6412 } 6413 6414 /** 6415 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on 6416 * dependencies between protocols and roles. 6417 * @phba: lpfc_hba pointer. 6418 **/ 6419 void 6420 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba) 6421 { 6422 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu) 6423 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu; 6424 6425 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu) 6426 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu; 6427 6428 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && 6429 phba->nvmet_support) { 6430 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP; 6431 phba->cfg_fcp_io_channel = 0; 6432 6433 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, 6434 "6013 %s x%x fb_size x%x, fb_max x%x\n", 6435 "NVME Target PRLI ACC enable_fb ", 6436 phba->cfg_nvme_enable_fb, 6437 phba->cfg_nvmet_fb_size, 6438 LPFC_NVMET_FB_SZ_MAX); 6439 6440 if (phba->cfg_nvme_enable_fb == 0) 6441 phba->cfg_nvmet_fb_size = 0; 6442 else { 6443 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX) 6444 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX; 6445 } 6446 6447 if (!phba->cfg_nvmet_mrq) 6448 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel; 6449 6450 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */ 6451 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) { 6452 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel; 6453 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 6454 "6018 Adjust lpfc_nvmet_mrq to %d\n", 6455 phba->cfg_nvmet_mrq); 6456 } 6457 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) 6458 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; 6459 6460 } else { 6461 /* Not NVME Target mode. Turn off Target parameters. */ 6462 phba->nvmet_support = 0; 6463 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF; 6464 phba->cfg_nvmet_fb_size = 0; 6465 } 6466 6467 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel) 6468 phba->io_channel_irqs = phba->cfg_fcp_io_channel; 6469 else 6470 phba->io_channel_irqs = phba->cfg_nvme_io_channel; 6471 } 6472 6473 /** 6474 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure 6475 * @vport: lpfc_vport pointer. 6476 **/ 6477 void 6478 lpfc_get_vport_cfgparam(struct lpfc_vport *vport) 6479 { 6480 lpfc_log_verbose_init(vport, lpfc_log_verbose); 6481 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth); 6482 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth); 6483 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo); 6484 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo); 6485 lpfc_peer_port_login_init(vport, lpfc_peer_port_login); 6486 lpfc_restrict_login_init(vport, lpfc_restrict_login); 6487 lpfc_fcp_class_init(vport, lpfc_fcp_class); 6488 lpfc_use_adisc_init(vport, lpfc_use_adisc); 6489 lpfc_first_burst_size_init(vport, lpfc_first_burst_size); 6490 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time); 6491 lpfc_discovery_threads_init(vport, lpfc_discovery_threads); 6492 lpfc_max_luns_init(vport, lpfc_max_luns); 6493 lpfc_scan_down_init(vport, lpfc_scan_down); 6494 lpfc_enable_da_id_init(vport, lpfc_enable_da_id); 6495 return; 6496 } 6497