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