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