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