Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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