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