1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2023 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. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
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 *******************************************************************/
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>
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>
43 #include "lpfc_sli4.h"
45 #include "lpfc_disc.h"
47 #include "lpfc_scsi.h"
48 #include "lpfc_nvme.h"
49 #include "lpfc_logmsg.h"
50 #include "lpfc_version.h"
51 #include "lpfc_compat.h"
52 #include "lpfc_crtn.h"
53 #include "lpfc_vport.h"
54 #include "lpfc_attr.h"
56 #define LPFC_DEF_DEVLOSS_TMO 30
57 #define LPFC_MIN_DEVLOSS_TMO 1
58 #define LPFC_MAX_DEVLOSS_TMO 255
60 #define LPFC_MAX_INFO_TMP_LEN 100
61 #define LPFC_INFO_MORE_STR "\nCould be more info...\n"
63 * Write key size should be multiple of 4. If write key is changed
64 * make sure that library write key is also changed.
66 #define LPFC_REG_WRITE_KEY_SIZE 4
67 #define LPFC_REG_WRITE_KEY "EMLX"
69 const char *const trunk_errmsg[] = { /* map errcode */
70 "", /* There is no such error code at index 0*/
71 "link negotiated speed does not match existing"
72 " trunk - link was \"low\" speed",
73 "link negotiated speed does not match"
74 " existing trunk - link was \"middle\" speed",
75 "link negotiated speed does not match existing"
76 " trunk - link was \"high\" speed",
77 "Attached to non-trunking port - F_Port",
78 "Attached to non-trunking port - N_Port",
79 "FLOGI response timeout",
80 "non-FLOGI frame received",
81 "Invalid FLOGI response",
82 "Trunking initialization protocol",
83 "Trunk peer device mismatch",
87 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
88 * @incr: integer to convert.
89 * @hdw: ascii string holding converted integer plus a string terminator.
92 * JEDEC Joint Electron Device Engineering Council.
93 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
94 * character string. The string is then terminated with a NULL in byte 9.
95 * Hex 0-9 becomes ascii '0' to '9'.
96 * Hex a-f becomes ascii '=' to 'B' capital B.
99 * Coded for 32 bit integers only.
102 lpfc_jedec_to_ascii(int incr, char hdw[])
105 for (i = 0; i < 8; i++) {
108 hdw[7 - i] = 0x30 + j;
110 hdw[7 - i] = 0x61 + j - 10;
118 lpfc_cmf_info_show(struct device *dev, struct device_attribute *attr,
121 struct Scsi_Host *shost = class_to_shost(dev);
122 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
123 struct lpfc_hba *phba = vport->phba;
124 struct lpfc_cgn_info *cp = NULL;
125 struct lpfc_cgn_stat *cgs;
129 char tmp[LPFC_MAX_INFO_TMP_LEN] = {0};
132 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
134 scnprintf(tmp, sizeof(tmp),
135 "Congestion Mgmt Info: E2Eattr %d Ver %d "
137 phba->sli4_hba.pc_sli4_params.mi_cap,
138 cp ? cp->cgn_info_version : 0,
139 phba->sli4_hba.pc_sli4_params.cmf, phba->cmf_timer_cnt);
141 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
144 if (!phba->sli4_hba.pc_sli4_params.cmf)
147 switch (phba->cgn_init_reg_signal) {
148 case EDC_CG_SIG_WARN_ONLY:
149 scnprintf(tmp, sizeof(tmp),
150 "Register: Init: Signal:WARN ");
152 case EDC_CG_SIG_WARN_ALARM:
153 scnprintf(tmp, sizeof(tmp),
154 "Register: Init: Signal:WARN|ALARM ");
157 scnprintf(tmp, sizeof(tmp),
158 "Register: Init: Signal:NONE ");
161 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
164 switch (phba->cgn_init_reg_fpin) {
165 case LPFC_CGN_FPIN_WARN:
166 scnprintf(tmp, sizeof(tmp),
169 case LPFC_CGN_FPIN_ALARM:
170 scnprintf(tmp, sizeof(tmp),
173 case LPFC_CGN_FPIN_BOTH:
174 scnprintf(tmp, sizeof(tmp),
175 "FPIN:WARN|ALARM\n");
178 scnprintf(tmp, sizeof(tmp),
182 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
185 switch (phba->cgn_reg_signal) {
186 case EDC_CG_SIG_WARN_ONLY:
187 scnprintf(tmp, sizeof(tmp),
188 " Current: Signal:WARN ");
190 case EDC_CG_SIG_WARN_ALARM:
191 scnprintf(tmp, sizeof(tmp),
192 " Current: Signal:WARN|ALARM ");
195 scnprintf(tmp, sizeof(tmp),
196 " Current: Signal:NONE ");
199 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
202 switch (phba->cgn_reg_fpin) {
203 case LPFC_CGN_FPIN_WARN:
204 scnprintf(tmp, sizeof(tmp),
205 "FPIN:WARN ACQEcnt:%d\n", phba->cgn_acqe_cnt);
207 case LPFC_CGN_FPIN_ALARM:
208 scnprintf(tmp, sizeof(tmp),
209 "FPIN:ALARM ACQEcnt:%d\n", phba->cgn_acqe_cnt);
211 case LPFC_CGN_FPIN_BOTH:
212 scnprintf(tmp, sizeof(tmp),
213 "FPIN:WARN|ALARM ACQEcnt:%d\n", phba->cgn_acqe_cnt);
216 scnprintf(tmp, sizeof(tmp),
217 "FPIN:NONE ACQEcnt:%d\n", phba->cgn_acqe_cnt);
220 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
223 if (phba->cmf_active_mode != phba->cgn_p.cgn_param_mode) {
224 switch (phba->cmf_active_mode) {
226 scnprintf(tmp, sizeof(tmp), "Active: Mode:Off\n");
228 case LPFC_CFG_MANAGED:
229 scnprintf(tmp, sizeof(tmp), "Active: Mode:Managed\n");
231 case LPFC_CFG_MONITOR:
232 scnprintf(tmp, sizeof(tmp), "Active: Mode:Monitor\n");
235 scnprintf(tmp, sizeof(tmp), "Active: Mode:Unknown\n");
237 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
241 switch (phba->cgn_p.cgn_param_mode) {
243 scnprintf(tmp, sizeof(tmp), "Config: Mode:Off ");
245 case LPFC_CFG_MANAGED:
246 scnprintf(tmp, sizeof(tmp), "Config: Mode:Managed ");
248 case LPFC_CFG_MONITOR:
249 scnprintf(tmp, sizeof(tmp), "Config: Mode:Monitor ");
252 scnprintf(tmp, sizeof(tmp), "Config: Mode:Unknown ");
254 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
259 for_each_present_cpu(cpu) {
260 cgs = per_cpu_ptr(phba->cmf_stat, cpu);
261 total += atomic64_read(&cgs->total_bytes);
262 rcv += atomic64_read(&cgs->rcv_bytes);
265 scnprintf(tmp, sizeof(tmp),
266 "IObusy:%d Info:%d Bytes: Rcv:x%llx Total:x%llx\n",
267 atomic_read(&phba->cmf_busy),
268 phba->cmf_active_info, rcv, total);
269 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
272 scnprintf(tmp, sizeof(tmp),
273 "Port_speed:%d Link_byte_cnt:%ld "
274 "Max_byte_per_interval:%ld\n",
275 lpfc_sli_port_speed_get(phba),
276 (unsigned long)phba->cmf_link_byte_count,
277 (unsigned long)phba->cmf_max_bytes_per_interval);
278 strlcat(buf, tmp, PAGE_SIZE);
281 len = strnlen(buf, PAGE_SIZE);
283 if (unlikely(len >= (PAGE_SIZE - 1))) {
284 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
285 "6312 Catching potential buffer "
286 "overflow > PAGE_SIZE = %lu bytes\n",
288 strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),
289 LPFC_INFO_MORE_STR, sizeof(LPFC_INFO_MORE_STR) + 1);
295 * lpfc_drvr_version_show - Return the Emulex driver string with version number
296 * @dev: class unused variable.
297 * @attr: device attribute, not used.
298 * @buf: on return contains the module description text.
300 * Returns: size of formatted string.
303 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
306 return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
310 * lpfc_enable_fip_show - Return the fip mode of the HBA
311 * @dev: class unused variable.
312 * @attr: device attribute, not used.
313 * @buf: on return contains the module description text.
315 * Returns: size of formatted string.
318 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
321 struct Scsi_Host *shost = class_to_shost(dev);
322 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
323 struct lpfc_hba *phba = vport->phba;
325 if (phba->hba_flag & HBA_FIP_SUPPORT)
326 return scnprintf(buf, PAGE_SIZE, "1\n");
328 return scnprintf(buf, PAGE_SIZE, "0\n");
332 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
335 struct Scsi_Host *shost = class_to_shost(dev);
336 struct lpfc_vport *vport = shost_priv(shost);
337 struct lpfc_hba *phba = vport->phba;
338 struct lpfc_nvmet_tgtport *tgtp;
339 struct nvme_fc_local_port *localport;
340 struct lpfc_nvme_lport *lport;
341 struct lpfc_nvme_rport *rport;
342 struct lpfc_nodelist *ndlp;
343 struct nvme_fc_remote_port *nrport;
344 struct lpfc_fc4_ctrl_stat *cstat;
345 uint64_t data1, data2, data3;
346 uint64_t totin, totout, tot;
350 char tmp[LPFC_MAX_INFO_TMP_LEN] = {0};
352 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
353 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
356 if (phba->nvmet_support) {
357 if (!phba->targetport) {
358 len = scnprintf(buf, PAGE_SIZE,
359 "NVME Target: x%llx is not allocated\n",
360 wwn_to_u64(vport->fc_portname.u.wwn));
363 /* Port state is only one of two values for now. */
364 if (phba->targetport->port_id)
365 statep = "REGISTERED";
368 scnprintf(tmp, sizeof(tmp),
369 "NVME Target Enabled State %s\n",
371 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
374 scnprintf(tmp, sizeof(tmp),
375 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
378 wwn_to_u64(vport->fc_portname.u.wwn),
379 wwn_to_u64(vport->fc_nodename.u.wwn),
380 phba->targetport->port_id);
381 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
384 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
388 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
389 scnprintf(tmp, sizeof(tmp),
390 "LS: Rcv %08x Drop %08x Abort %08x\n",
391 atomic_read(&tgtp->rcv_ls_req_in),
392 atomic_read(&tgtp->rcv_ls_req_drop),
393 atomic_read(&tgtp->xmt_ls_abort));
394 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
397 if (atomic_read(&tgtp->rcv_ls_req_in) !=
398 atomic_read(&tgtp->rcv_ls_req_out)) {
399 scnprintf(tmp, sizeof(tmp),
400 "Rcv LS: in %08x != out %08x\n",
401 atomic_read(&tgtp->rcv_ls_req_in),
402 atomic_read(&tgtp->rcv_ls_req_out));
403 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
407 scnprintf(tmp, sizeof(tmp),
408 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
409 atomic_read(&tgtp->xmt_ls_rsp),
410 atomic_read(&tgtp->xmt_ls_drop),
411 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
412 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
415 scnprintf(tmp, sizeof(tmp),
416 "LS: RSP Abort %08x xb %08x Err %08x\n",
417 atomic_read(&tgtp->xmt_ls_rsp_aborted),
418 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
419 atomic_read(&tgtp->xmt_ls_rsp_error));
420 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
423 scnprintf(tmp, sizeof(tmp),
424 "FCP: Rcv %08x Defer %08x Release %08x "
426 atomic_read(&tgtp->rcv_fcp_cmd_in),
427 atomic_read(&tgtp->rcv_fcp_cmd_defer),
428 atomic_read(&tgtp->xmt_fcp_release),
429 atomic_read(&tgtp->rcv_fcp_cmd_drop));
430 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
433 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
434 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
435 scnprintf(tmp, sizeof(tmp),
436 "Rcv FCP: in %08x != out %08x\n",
437 atomic_read(&tgtp->rcv_fcp_cmd_in),
438 atomic_read(&tgtp->rcv_fcp_cmd_out));
439 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
443 scnprintf(tmp, sizeof(tmp),
444 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
446 atomic_read(&tgtp->xmt_fcp_read),
447 atomic_read(&tgtp->xmt_fcp_read_rsp),
448 atomic_read(&tgtp->xmt_fcp_write),
449 atomic_read(&tgtp->xmt_fcp_rsp),
450 atomic_read(&tgtp->xmt_fcp_drop));
451 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
454 scnprintf(tmp, sizeof(tmp),
455 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
456 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
457 atomic_read(&tgtp->xmt_fcp_rsp_error),
458 atomic_read(&tgtp->xmt_fcp_rsp_drop));
459 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
462 scnprintf(tmp, sizeof(tmp),
463 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
464 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
465 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
466 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
467 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
470 scnprintf(tmp, sizeof(tmp),
471 "ABORT: Xmt %08x Cmpl %08x\n",
472 atomic_read(&tgtp->xmt_fcp_abort),
473 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
474 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
477 scnprintf(tmp, sizeof(tmp),
478 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
479 atomic_read(&tgtp->xmt_abort_sol),
480 atomic_read(&tgtp->xmt_abort_unsol),
481 atomic_read(&tgtp->xmt_abort_rsp),
482 atomic_read(&tgtp->xmt_abort_rsp_error));
483 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
486 scnprintf(tmp, sizeof(tmp),
487 "DELAY: ctx %08x fod %08x wqfull %08x\n",
488 atomic_read(&tgtp->defer_ctx),
489 atomic_read(&tgtp->defer_fod),
490 atomic_read(&tgtp->defer_wqfull));
491 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
494 /* Calculate outstanding IOs */
495 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
496 tot += atomic_read(&tgtp->xmt_fcp_release);
497 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
499 scnprintf(tmp, sizeof(tmp),
500 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
501 "CTX Outstanding %08llx\n\n",
502 phba->sli4_hba.nvmet_xri_cnt,
503 phba->sli4_hba.nvmet_io_wait_cnt,
504 phba->sli4_hba.nvmet_io_wait_total,
506 strlcat(buf, tmp, PAGE_SIZE);
510 localport = vport->localport;
512 len = scnprintf(buf, PAGE_SIZE,
513 "NVME Initiator x%llx is not allocated\n",
514 wwn_to_u64(vport->fc_portname.u.wwn));
517 lport = (struct lpfc_nvme_lport *)localport->private;
518 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
521 scnprintf(tmp, sizeof(tmp),
522 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
524 phba->sli4_hba.max_cfg_param.max_xri,
525 phba->sli4_hba.io_xri_max,
526 lpfc_sli4_get_els_iocb_cnt(phba));
527 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
530 /* Port state is only one of two values for now. */
531 if (localport->port_id)
536 scnprintf(tmp, sizeof(tmp),
537 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
540 wwn_to_u64(vport->fc_portname.u.wwn),
541 wwn_to_u64(vport->fc_nodename.u.wwn),
542 localport->port_id, statep);
543 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
546 spin_lock_irq(shost->host_lock);
548 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
550 spin_lock(&ndlp->lock);
551 rport = lpfc_ndlp_get_nrport(ndlp);
553 nrport = rport->remoteport;
554 spin_unlock(&ndlp->lock);
558 /* Port state is only one of two values for now. */
559 switch (nrport->port_state) {
560 case FC_OBJSTATE_ONLINE:
563 case FC_OBJSTATE_UNKNOWN:
567 statep = "UNSUPPORTED";
571 /* Tab in to show lport ownership. */
572 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
573 goto unlock_buf_done;
574 if (phba->brd_no >= 10) {
575 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
576 goto unlock_buf_done;
579 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
581 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
582 goto unlock_buf_done;
584 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
586 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
587 goto unlock_buf_done;
589 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
591 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
592 goto unlock_buf_done;
594 /* An NVME rport can have multiple roles. */
595 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
596 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
597 goto unlock_buf_done;
599 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
600 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
601 goto unlock_buf_done;
603 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
604 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
605 goto unlock_buf_done;
607 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
608 FC_PORT_ROLE_NVME_TARGET |
609 FC_PORT_ROLE_NVME_DISCOVERY)) {
610 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
612 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
613 goto unlock_buf_done;
616 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
617 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
618 goto unlock_buf_done;
620 spin_unlock_irq(shost->host_lock);
625 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
628 scnprintf(tmp, sizeof(tmp),
629 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
630 atomic_read(&lport->fc4NvmeLsRequests),
631 atomic_read(&lport->fc4NvmeLsCmpls),
632 atomic_read(&lport->xmt_ls_abort));
633 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
636 scnprintf(tmp, sizeof(tmp),
637 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
638 atomic_read(&lport->xmt_ls_err),
639 atomic_read(&lport->cmpl_ls_xb),
640 atomic_read(&lport->cmpl_ls_err));
641 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
646 for (i = 0; i < phba->cfg_hdw_queue; i++) {
647 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
648 tot = cstat->io_cmpls;
650 data1 = cstat->input_requests;
651 data2 = cstat->output_requests;
652 data3 = cstat->control_requests;
653 totout += (data1 + data2 + data3);
655 scnprintf(tmp, sizeof(tmp),
656 "Total FCP Cmpl %016llx Issue %016llx "
658 totin, totout, totout - totin);
659 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
662 scnprintf(tmp, sizeof(tmp),
663 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
664 "wqerr %08x err %08x\n",
665 atomic_read(&lport->xmt_fcp_abort),
666 atomic_read(&lport->xmt_fcp_noxri),
667 atomic_read(&lport->xmt_fcp_bad_ndlp),
668 atomic_read(&lport->xmt_fcp_qdepth),
669 atomic_read(&lport->xmt_fcp_wqerr),
670 atomic_read(&lport->xmt_fcp_err));
671 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
674 scnprintf(tmp, sizeof(tmp),
675 "FCP CMPL: xb %08x Err %08x\n",
676 atomic_read(&lport->cmpl_fcp_xb),
677 atomic_read(&lport->cmpl_fcp_err));
678 strlcat(buf, tmp, PAGE_SIZE);
680 /* host_lock is already unlocked. */
684 spin_unlock_irq(shost->host_lock);
687 len = strnlen(buf, PAGE_SIZE);
689 if (unlikely(len >= (PAGE_SIZE - 1))) {
690 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
691 "6314 Catching potential buffer "
692 "overflow > PAGE_SIZE = %lu bytes\n",
694 strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),
696 sizeof(LPFC_INFO_MORE_STR) + 1);
703 lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
706 struct Scsi_Host *shost = class_to_shost(dev);
707 struct lpfc_vport *vport = shost_priv(shost);
708 struct lpfc_hba *phba = vport->phba;
710 struct lpfc_fc4_ctrl_stat *cstat;
711 u64 data1, data2, data3;
712 u64 tot, totin, totout;
714 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
716 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
717 (phba->sli_rev != LPFC_SLI_REV4))
720 scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
724 for (i = 0; i < phba->cfg_hdw_queue; i++) {
725 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
726 tot = cstat->io_cmpls;
728 data1 = cstat->input_requests;
729 data2 = cstat->output_requests;
730 data3 = cstat->control_requests;
731 totout += (data1 + data2 + data3);
733 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
734 "IO %016llx ", i, data1, data2, data3);
735 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
738 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
739 tot, ((data1 + data2 + data3) - tot));
740 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
743 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
744 "OutIO %016llx\n", totin, totout, totout - totin);
745 strlcat(buf, tmp, PAGE_SIZE);
748 len = strnlen(buf, PAGE_SIZE);
754 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
757 struct Scsi_Host *shost = class_to_shost(dev);
758 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
759 struct lpfc_hba *phba = vport->phba;
761 if (phba->cfg_enable_bg) {
762 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
763 return scnprintf(buf, PAGE_SIZE,
764 "BlockGuard Enabled\n");
766 return scnprintf(buf, PAGE_SIZE,
767 "BlockGuard Not Supported\n");
769 return scnprintf(buf, PAGE_SIZE,
770 "BlockGuard Disabled\n");
774 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
777 struct Scsi_Host *shost = class_to_shost(dev);
778 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
779 struct lpfc_hba *phba = vport->phba;
781 return scnprintf(buf, PAGE_SIZE, "%llu\n",
782 (unsigned long long)phba->bg_guard_err_cnt);
786 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
789 struct Scsi_Host *shost = class_to_shost(dev);
790 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
791 struct lpfc_hba *phba = vport->phba;
793 return scnprintf(buf, PAGE_SIZE, "%llu\n",
794 (unsigned long long)phba->bg_apptag_err_cnt);
798 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
801 struct Scsi_Host *shost = class_to_shost(dev);
802 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
803 struct lpfc_hba *phba = vport->phba;
805 return scnprintf(buf, PAGE_SIZE, "%llu\n",
806 (unsigned long long)phba->bg_reftag_err_cnt);
810 * lpfc_info_show - Return some pci info about the host in ascii
811 * @dev: class converted to a Scsi_host structure.
812 * @attr: device attribute, not used.
813 * @buf: on return contains the formatted text from lpfc_info().
815 * Returns: size of formatted string.
818 lpfc_info_show(struct device *dev, struct device_attribute *attr,
821 struct Scsi_Host *host = class_to_shost(dev);
823 return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
827 * lpfc_serialnum_show - Return the hba serial number in ascii
828 * @dev: class converted to a Scsi_host structure.
829 * @attr: device attribute, not used.
830 * @buf: on return contains the formatted text serial number.
832 * Returns: size of formatted string.
835 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
838 struct Scsi_Host *shost = class_to_shost(dev);
839 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
840 struct lpfc_hba *phba = vport->phba;
842 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
846 * lpfc_temp_sensor_show - Return the temperature sensor level
847 * @dev: class converted to a Scsi_host structure.
848 * @attr: device attribute, not used.
849 * @buf: on return contains the formatted support level.
852 * Returns a number indicating the temperature sensor level currently
853 * supported, zero or one in ascii.
855 * Returns: size of formatted string.
858 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
861 struct Scsi_Host *shost = class_to_shost(dev);
862 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
863 struct lpfc_hba *phba = vport->phba;
864 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
868 * lpfc_modeldesc_show - Return the model description of the hba
869 * @dev: class converted to a Scsi_host structure.
870 * @attr: device attribute, not used.
871 * @buf: on return contains the scsi vpd model description.
873 * Returns: size of formatted string.
876 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
879 struct Scsi_Host *shost = class_to_shost(dev);
880 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
881 struct lpfc_hba *phba = vport->phba;
883 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
887 * lpfc_modelname_show - Return the model name of the hba
888 * @dev: class converted to a Scsi_host structure.
889 * @attr: device attribute, not used.
890 * @buf: on return contains the scsi vpd model name.
892 * Returns: size of formatted string.
895 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
898 struct Scsi_Host *shost = class_to_shost(dev);
899 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
900 struct lpfc_hba *phba = vport->phba;
902 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
906 * lpfc_programtype_show - Return the program type of the hba
907 * @dev: class converted to a Scsi_host structure.
908 * @attr: device attribute, not used.
909 * @buf: on return contains the scsi vpd program type.
911 * Returns: size of formatted string.
914 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
917 struct Scsi_Host *shost = class_to_shost(dev);
918 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
919 struct lpfc_hba *phba = vport->phba;
921 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
925 * lpfc_vportnum_show - Return the port number in ascii of the hba
926 * @dev: class converted to a Scsi_host structure.
927 * @attr: device attribute, not used.
928 * @buf: on return contains scsi vpd program type.
930 * Returns: size of formatted string.
933 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
936 struct Scsi_Host *shost = class_to_shost(dev);
937 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
938 struct lpfc_hba *phba = vport->phba;
940 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
944 * lpfc_fwrev_show - Return the firmware rev running in the hba
945 * @dev: class converted to a Scsi_host structure.
946 * @attr: device attribute, not used.
947 * @buf: on return contains the scsi vpd program type.
949 * Returns: size of formatted string.
952 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
955 struct Scsi_Host *shost = class_to_shost(dev);
956 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
957 struct lpfc_hba *phba = vport->phba;
960 char fwrev[FW_REV_STR_SIZE];
963 lpfc_decode_firmware_rev(phba, fwrev, 1);
964 if_type = phba->sli4_hba.pc_sli4_params.if_type;
965 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
967 if (phba->sli_rev < LPFC_SLI_REV4)
968 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
969 fwrev, phba->sli_rev);
971 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
972 fwrev, phba->sli_rev, if_type, sli_family);
978 * lpfc_hdw_show - Return the jedec information about the hba
979 * @dev: class converted to a Scsi_host structure.
980 * @attr: device attribute, not used.
981 * @buf: on return contains the scsi vpd program type.
983 * Returns: size of formatted string.
986 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
989 struct Scsi_Host *shost = class_to_shost(dev);
990 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
991 struct lpfc_hba *phba = vport->phba;
992 lpfc_vpd_t *vp = &phba->vpd;
994 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
995 return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
996 vp->rev.smRev, vp->rev.smFwRev);
1000 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
1001 * @dev: class converted to a Scsi_host structure.
1002 * @attr: device attribute, not used.
1003 * @buf: on return contains the ROM and FCode ascii strings.
1005 * Returns: size of formatted string.
1008 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
1011 struct Scsi_Host *shost = class_to_shost(dev);
1012 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1013 struct lpfc_hba *phba = vport->phba;
1014 char fwrev[FW_REV_STR_SIZE];
1016 if (phba->sli_rev < LPFC_SLI_REV4)
1017 return scnprintf(buf, PAGE_SIZE, "%s\n",
1018 phba->OptionROMVersion);
1020 lpfc_decode_firmware_rev(phba, fwrev, 1);
1021 return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
1025 * lpfc_link_state_show - Return the link state of the port
1026 * @dev: class converted to a Scsi_host structure.
1027 * @attr: device attribute, not used.
1028 * @buf: on return contains text describing the state of the link.
1031 * The switch statement has no default so zero will be returned.
1033 * Returns: size of formatted string.
1036 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
1039 struct Scsi_Host *shost = class_to_shost(dev);
1040 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1041 struct lpfc_hba *phba = vport->phba;
1044 switch (phba->link_state) {
1045 case LPFC_LINK_UNKNOWN:
1046 case LPFC_WARM_START:
1047 case LPFC_INIT_START:
1048 case LPFC_INIT_MBX_CMDS:
1049 case LPFC_LINK_DOWN:
1050 case LPFC_HBA_ERROR:
1051 if (phba->hba_flag & LINK_DISABLED)
1052 len += scnprintf(buf + len, PAGE_SIZE-len,
1053 "Link Down - User disabled\n");
1055 len += scnprintf(buf + len, PAGE_SIZE-len,
1060 case LPFC_HBA_READY:
1061 len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
1063 switch (vport->port_state) {
1064 case LPFC_LOCAL_CFG_LINK:
1065 len += scnprintf(buf + len, PAGE_SIZE-len,
1066 "Configuring Link\n");
1070 case LPFC_FABRIC_CFG_LINK:
1073 case LPFC_BUILD_DISC_LIST:
1074 case LPFC_DISC_AUTH:
1075 len += scnprintf(buf + len, PAGE_SIZE - len,
1078 case LPFC_VPORT_READY:
1079 len += scnprintf(buf + len, PAGE_SIZE - len,
1083 case LPFC_VPORT_FAILED:
1084 len += scnprintf(buf + len, PAGE_SIZE - len,
1088 case LPFC_VPORT_UNKNOWN:
1089 len += scnprintf(buf + len, PAGE_SIZE - len,
1093 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1094 if (vport->fc_flag & FC_PUBLIC_LOOP)
1095 len += scnprintf(buf + len, PAGE_SIZE-len,
1098 len += scnprintf(buf + len, PAGE_SIZE-len,
1101 if (vport->fc_flag & FC_FABRIC) {
1102 if (phba->sli_rev == LPFC_SLI_REV4 &&
1103 vport->port_type == LPFC_PHYSICAL_PORT &&
1104 phba->sli4_hba.fawwpn_flag &
1106 len += scnprintf(buf + len,
1108 " Fabric FA-PWWN\n");
1110 len += scnprintf(buf + len,
1114 len += scnprintf(buf + len, PAGE_SIZE-len,
1115 " Point-2-Point\n");
1120 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1121 ((bf_get(lpfc_sli_intf_if_type,
1122 &phba->sli4_hba.sli_intf) ==
1123 LPFC_SLI_INTF_IF_TYPE_6))) {
1124 struct lpfc_trunk_link link = phba->trunk_link;
1126 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
1127 len += scnprintf(buf + len, PAGE_SIZE - len,
1128 "Trunk port 0: Link %s %s\n",
1129 (link.link0.state == LPFC_LINK_UP) ?
1131 trunk_errmsg[link.link0.fault]);
1133 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
1134 len += scnprintf(buf + len, PAGE_SIZE - len,
1135 "Trunk port 1: Link %s %s\n",
1136 (link.link1.state == LPFC_LINK_UP) ?
1138 trunk_errmsg[link.link1.fault]);
1140 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
1141 len += scnprintf(buf + len, PAGE_SIZE - len,
1142 "Trunk port 2: Link %s %s\n",
1143 (link.link2.state == LPFC_LINK_UP) ?
1145 trunk_errmsg[link.link2.fault]);
1147 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
1148 len += scnprintf(buf + len, PAGE_SIZE - len,
1149 "Trunk port 3: Link %s %s\n",
1150 (link.link3.state == LPFC_LINK_UP) ?
1152 trunk_errmsg[link.link3.fault]);
1160 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
1161 * @dev: class unused variable.
1162 * @attr: device attribute, not used.
1163 * @buf: on return contains the module description text.
1165 * Returns: size of formatted string.
1168 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
1171 struct Scsi_Host *shost = class_to_shost(dev);
1172 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1173 struct lpfc_hba *phba = vport->phba;
1175 if (phba->sli_rev < LPFC_SLI_REV4)
1176 return scnprintf(buf, PAGE_SIZE, "fc\n");
1178 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
1179 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
1180 return scnprintf(buf, PAGE_SIZE, "fcoe\n");
1181 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
1182 return scnprintf(buf, PAGE_SIZE, "fc\n");
1184 return scnprintf(buf, PAGE_SIZE, "unknown\n");
1188 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1189 * (OAS) is supported.
1190 * @dev: class unused variable.
1191 * @attr: device attribute, not used.
1192 * @buf: on return contains the module description text.
1194 * Returns: size of formatted string.
1197 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1200 struct Scsi_Host *shost = class_to_shost(dev);
1201 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1202 struct lpfc_hba *phba = vport->phba;
1204 return scnprintf(buf, PAGE_SIZE, "%d\n",
1205 phba->sli4_hba.pc_sli4_params.oas_supported);
1209 * lpfc_link_state_store - Transition the link_state on an HBA port
1210 * @dev: class device that is converted into a Scsi_host.
1211 * @attr: device attribute, not used.
1212 * @buf: one or more lpfc_polling_flags values.
1216 * -EINVAL if the buffer is not "up" or "down"
1217 * return from link state change function if non-zero
1218 * length of the buf on success
1221 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1222 const char *buf, size_t count)
1224 struct Scsi_Host *shost = class_to_shost(dev);
1225 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1226 struct lpfc_hba *phba = vport->phba;
1228 int status = -EINVAL;
1230 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1231 (phba->link_state == LPFC_LINK_DOWN))
1232 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
1233 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1234 (phba->link_state >= LPFC_LINK_UP))
1235 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1244 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1245 * @dev: class device that is converted into a Scsi_host.
1246 * @attr: device attribute, not used.
1247 * @buf: on return contains the sum of fc mapped and unmapped.
1250 * Returns the ascii text number of the sum of the fc mapped and unmapped
1253 * Returns: size of formatted string.
1256 lpfc_num_discovered_ports_show(struct device *dev,
1257 struct device_attribute *attr, char *buf)
1259 struct Scsi_Host *shost = class_to_shost(dev);
1260 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1262 return scnprintf(buf, PAGE_SIZE, "%d\n",
1263 vport->fc_map_cnt + vport->fc_unmap_cnt);
1267 * lpfc_issue_lip - Misnomer, name carried over from long ago
1268 * @shost: Scsi_Host pointer.
1271 * Bring the link down gracefully then re-init the link. The firmware will
1272 * re-init the fiber channel interface as required. Does not issue a LIP.
1275 * -EPERM port offline or management commands are being blocked
1276 * -ENOMEM cannot allocate memory for the mailbox command
1277 * -EIO error sending the mailbox command
1281 lpfc_issue_lip(struct Scsi_Host *shost)
1283 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1284 struct lpfc_hba *phba = vport->phba;
1285 LPFC_MBOXQ_t *pmboxq;
1286 int mbxstatus = MBXERR_ERROR;
1289 * If the link is offline, disabled or BLOCK_MGMT_IO
1290 * it doesn't make any sense to allow issue_lip
1292 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1293 (phba->hba_flag & LINK_DISABLED) ||
1294 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1297 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1302 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1303 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1304 pmboxq->u.mb.mbxOwner = OWN_HOST;
1306 if ((vport->fc_flag & FC_PT2PT) && (vport->fc_flag & FC_PT2PT_NO_NVME))
1307 vport->fc_flag &= ~FC_PT2PT_NO_NVME;
1309 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1311 if ((mbxstatus == MBX_SUCCESS) &&
1312 (pmboxq->u.mb.mbxStatus == 0 ||
1313 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1314 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1315 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1316 phba->cfg_link_speed);
1317 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1318 phba->fc_ratov * 2);
1319 if ((mbxstatus == MBX_SUCCESS) &&
1320 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1321 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1322 "2859 SLI authentication is required "
1323 "for INIT_LINK but has not done yet\n");
1326 lpfc_set_loopback_flag(phba);
1327 if (mbxstatus != MBX_TIMEOUT)
1328 mempool_free(pmboxq, phba->mbox_mem_pool);
1330 if (mbxstatus == MBXERR_ERROR)
1337 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1341 spin_lock_irq(lock);
1342 while (!list_empty(q)) {
1343 spin_unlock_irq(lock);
1345 if (cnt++ > 250) { /* 5 secs */
1346 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1347 "0466 Outstanding IO when "
1348 "bringing Adapter offline\n");
1351 spin_lock_irq(lock);
1353 spin_unlock_irq(lock);
1358 * lpfc_do_offline - Issues a mailbox command to bring the link down
1359 * @phba: lpfc_hba pointer.
1360 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1363 * Assumes any error from lpfc_do_offline() will be negative.
1364 * Can wait up to 5 seconds for the port ring buffers count
1365 * to reach zero, prints a warning if it is not zero and continues.
1366 * lpfc_workq_post_event() returns a non-zero return code if call fails.
1369 * -EIO error posting the event
1373 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1375 struct completion online_compl;
1376 struct lpfc_queue *qp = NULL;
1377 struct lpfc_sli_ring *pring;
1378 struct lpfc_sli *psli;
1383 init_completion(&online_compl);
1384 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1385 LPFC_EVT_OFFLINE_PREP);
1389 wait_for_completion(&online_compl);
1397 * If freeing the queues have already started, don't access them.
1398 * Otherwise set FREE_WAIT to indicate that queues are being used
1399 * to hold the freeing process until we finish.
1401 spin_lock_irq(&phba->hbalock);
1402 if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {
1403 psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;
1405 spin_unlock_irq(&phba->hbalock);
1408 spin_unlock_irq(&phba->hbalock);
1410 /* Wait a little for things to settle down, but not
1411 * long enough for dev loss timeout to expire.
1413 if (phba->sli_rev != LPFC_SLI_REV4) {
1414 for (i = 0; i < psli->num_rings; i++) {
1415 pring = &psli->sli3_ring[i];
1416 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1421 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1425 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1431 spin_lock_irq(&phba->hbalock);
1432 psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;
1433 spin_unlock_irq(&phba->hbalock);
1436 init_completion(&online_compl);
1437 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1441 wait_for_completion(&online_compl);
1450 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1451 * @phba: lpfc_hba pointer.
1454 * Issues a PCI secondary bus reset for the phba->pcidev.
1457 * First walks the bus_list to ensure only PCI devices with Emulex
1458 * vendor id, device ids that support hot reset, only one occurrence
1459 * of function 0, and all ports on the bus are in offline mode to ensure the
1460 * hot reset only affects one valid HBA.
1463 * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1464 * -ENODEV, NULL ptr to pcidev
1465 * -EBADSLT, detected invalid device
1466 * -EBUSY, port is not in offline state
1470 lpfc_reset_pci_bus(struct lpfc_hba *phba)
1472 struct pci_dev *pdev = phba->pcidev;
1473 struct Scsi_Host *shost = NULL;
1474 struct lpfc_hba *phba_other = NULL;
1475 struct pci_dev *ptr = NULL;
1478 if (phba->cfg_enable_hba_reset != 2)
1482 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1486 res = lpfc_check_pci_resettable(phba);
1490 /* Walk the list of devices on the pci_dev's bus */
1491 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1492 /* Check port is offline */
1493 shost = pci_get_drvdata(ptr);
1496 ((struct lpfc_vport *)shost->hostdata)->phba;
1497 if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1498 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1499 "8349 WWPN = 0x%02x%02x%02x%02x"
1500 "%02x%02x%02x%02x is not "
1502 phba_other->wwpn[0],
1503 phba_other->wwpn[1],
1504 phba_other->wwpn[2],
1505 phba_other->wwpn[3],
1506 phba_other->wwpn[4],
1507 phba_other->wwpn[5],
1508 phba_other->wwpn[6],
1509 phba_other->wwpn[7]);
1515 /* Issue PCI bus reset */
1516 res = pci_reset_bus(pdev);
1518 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1519 "8350 PCI reset bus failed: %d\n", res);
1526 * lpfc_selective_reset - Offline then onlines the port
1527 * @phba: lpfc_hba pointer.
1530 * If the port is configured to allow a reset then the hba is brought
1531 * offline then online.
1534 * Assumes any error from lpfc_do_offline() will be negative.
1535 * Do not make this function static.
1538 * lpfc_do_offline() return code if not zero
1539 * -EIO reset not configured or error posting the event
1543 lpfc_selective_reset(struct lpfc_hba *phba)
1545 struct completion online_compl;
1549 if (!phba->cfg_enable_hba_reset)
1552 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1553 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1559 init_completion(&online_compl);
1560 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1565 wait_for_completion(&online_compl);
1574 * lpfc_issue_reset - Selectively resets an adapter
1575 * @dev: class device that is converted into a Scsi_host.
1576 * @attr: device attribute, not used.
1577 * @buf: containing the string "selective".
1578 * @count: unused variable.
1581 * If the buf contains the string "selective" then lpfc_selective_reset()
1582 * is called to perform the reset.
1585 * Assumes any error from lpfc_selective_reset() will be negative.
1586 * If lpfc_selective_reset() returns zero then the length of the buffer
1587 * is returned which indicates success
1590 * -EINVAL if the buffer does not contain the string "selective"
1591 * length of buf if lpfc-selective_reset() if the call succeeds
1592 * return value of lpfc_selective_reset() if the call fails
1595 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1596 const char *buf, size_t count)
1598 struct Scsi_Host *shost = class_to_shost(dev);
1599 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1600 struct lpfc_hba *phba = vport->phba;
1601 int status = -EINVAL;
1603 if (!phba->cfg_enable_hba_reset)
1606 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1607 status = phba->lpfc_selective_reset(phba);
1616 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1617 * @phba: lpfc_hba pointer.
1620 * SLI4 interface type-2 device to wait on the sliport status register for
1621 * the readyness after performing a firmware reset.
1624 * zero for success, -EPERM when port does not have privilege to perform the
1625 * reset, -EIO when port timeout from recovering from the reset.
1628 * As the caller will interpret the return code by value, be careful in making
1629 * change or addition to return codes.
1632 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1634 struct lpfc_register portstat_reg = {0};
1638 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1639 &portstat_reg.word0))
1642 /* verify if privileged for the request operation */
1643 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1644 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1647 /* There is no point to wait if the port is in an unrecoverable
1650 if (lpfc_sli4_unrecoverable_port(&portstat_reg))
1653 /* wait for the SLI port firmware ready after firmware reset */
1654 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1656 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1657 &portstat_reg.word0))
1659 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1661 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1663 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1668 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1675 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1676 * @phba: lpfc_hba pointer.
1677 * @opcode: The sli4 config command opcode.
1680 * Request SLI4 interface type-2 device to perform a physical register set
1687 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1689 struct completion online_compl;
1690 struct pci_dev *pdev = phba->pcidev;
1691 uint32_t before_fc_flag;
1692 uint32_t sriov_nr_virtfn;
1694 int status = 0, rc = 0;
1695 int job_posted = 1, sriov_err;
1697 if (!phba->cfg_enable_hba_reset)
1700 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1701 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1702 LPFC_SLI_INTF_IF_TYPE_2))
1705 /* Keep state if we need to restore back */
1706 before_fc_flag = phba->pport->fc_flag;
1707 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1709 if (opcode == LPFC_FW_DUMP) {
1710 init_completion(&online_compl);
1711 phba->fw_dump_cmpl = &online_compl;
1713 /* Disable SR-IOV virtual functions if enabled */
1714 if (phba->cfg_sriov_nr_virtfn) {
1715 pci_disable_sriov(pdev);
1716 phba->cfg_sriov_nr_virtfn = 0;
1719 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1724 /* wait for the device to be quiesced before firmware reset */
1728 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1729 LPFC_CTL_PDEV_CTL_OFFSET);
1731 if (opcode == LPFC_FW_DUMP)
1732 reg_val |= LPFC_FW_DUMP_REQUEST;
1733 else if (opcode == LPFC_FW_RESET)
1734 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1735 else if (opcode == LPFC_DV_RESET)
1736 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1738 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1739 LPFC_CTL_PDEV_CTL_OFFSET);
1741 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1743 /* delay driver action following IF_TYPE_2 reset */
1744 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1747 /* no privilege for reset */
1748 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1749 "3150 No privilege to perform the requested "
1750 "access: x%x\n", reg_val);
1751 } else if (rc == -EIO) {
1752 /* reset failed, there is nothing more we can do */
1753 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1754 "3153 Fail to perform the requested "
1755 "access: x%x\n", reg_val);
1756 if (phba->fw_dump_cmpl)
1757 phba->fw_dump_cmpl = NULL;
1761 /* keep the original port state */
1762 if (before_fc_flag & FC_OFFLINE_MODE) {
1763 if (phba->fw_dump_cmpl)
1764 phba->fw_dump_cmpl = NULL;
1768 /* Firmware dump will trigger an HA_ERATT event, and
1769 * lpfc_handle_eratt_s4 routine already handles bringing the port back
1772 if (opcode == LPFC_FW_DUMP) {
1773 wait_for_completion(phba->fw_dump_cmpl);
1775 init_completion(&online_compl);
1776 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1781 wait_for_completion(&online_compl);
1784 /* in any case, restore the virtual functions enabled as before */
1785 if (sriov_nr_virtfn) {
1786 /* If fw_dump was performed, first disable to clean up */
1787 if (opcode == LPFC_FW_DUMP) {
1788 pci_disable_sriov(pdev);
1789 phba->cfg_sriov_nr_virtfn = 0;
1793 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1795 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1798 /* return proper error code */
1809 * lpfc_nport_evt_cnt_show - Return the number of nport events
1810 * @dev: class device that is converted into a Scsi_host.
1811 * @attr: device attribute, not used.
1812 * @buf: on return contains the ascii number of nport events.
1814 * Returns: size of formatted string.
1817 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1820 struct Scsi_Host *shost = class_to_shost(dev);
1821 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1822 struct lpfc_hba *phba = vport->phba;
1824 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1828 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1830 LPFC_MBOXQ_t *mbox = NULL;
1831 unsigned long val = 0;
1835 if (!strncmp("enable", buff_out,
1836 strlen("enable"))) {
1837 pval = buff_out + strlen("enable") + 1;
1838 rc = kstrtoul(pval, 0, &val);
1840 return rc; /* Invalid number */
1841 } else if (!strncmp("disable", buff_out,
1842 strlen("disable"))) {
1845 return -EINVAL; /* Invalid command */
1850 val = 0x0; /* Disable */
1853 val = 0x1; /* Enable two port trunk */
1856 val = 0x2; /* Enable four port trunk */
1862 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1863 "0070 Set trunk mode with val %ld ", val);
1865 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1869 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1870 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1871 12, LPFC_SLI4_MBX_EMBED);
1873 bf_set(lpfc_mbx_set_trunk_mode,
1874 &mbox->u.mqe.un.set_trunk_mode,
1876 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1878 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1879 "0071 Set trunk mode failed with status: %d",
1881 mempool_free(mbox, phba->mbox_mem_pool);
1887 lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr,
1890 struct Scsi_Host *shost = class_to_shost(dev);
1891 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1892 struct lpfc_hba *phba = vport->phba;
1895 struct lpfc_rdp_context *rdp_context;
1903 struct sff_trasnceiver_codes_byte7 *trasn_code_byte7;
1905 /* Get transceiver information */
1906 rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL);
1908 rc = lpfc_get_sfp_info_wait(phba, rdp_context);
1910 len = scnprintf(buf, PAGE_SIZE - len, "SFP info NA:\n");
1914 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_NAME], 16);
1916 len = scnprintf(buf, PAGE_SIZE - len, "VendorName:\t%s\n", chbuf);
1917 len += scnprintf(buf + len, PAGE_SIZE - len,
1918 "VendorOUI:\t%02x-%02x-%02x\n",
1919 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI],
1920 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 1],
1921 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 2]);
1922 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_PN], 16);
1923 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorPN:\t%s\n", chbuf);
1924 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_SN], 16);
1925 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorSN:\t%s\n", chbuf);
1926 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_REV], 4);
1927 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorRev:\t%s\n", chbuf);
1928 strscpy(chbuf, &rdp_context->page_a0[SSF_DATE_CODE], 8);
1929 len += scnprintf(buf + len, PAGE_SIZE - len, "DateCode:\t%s\n", chbuf);
1930 len += scnprintf(buf + len, PAGE_SIZE - len, "Identifier:\t%xh\n",
1931 (uint8_t)rdp_context->page_a0[SSF_IDENTIFIER]);
1932 len += scnprintf(buf + len, PAGE_SIZE - len, "ExtIdentifier:\t%xh\n",
1933 (uint8_t)rdp_context->page_a0[SSF_EXT_IDENTIFIER]);
1934 len += scnprintf(buf + len, PAGE_SIZE - len, "Connector:\t%xh\n",
1935 (uint8_t)rdp_context->page_a0[SSF_CONNECTOR]);
1936 wavelength = (rdp_context->page_a0[SSF_WAVELENGTH_B1] << 8) |
1937 rdp_context->page_a0[SSF_WAVELENGTH_B0];
1939 len += scnprintf(buf + len, PAGE_SIZE - len, "Wavelength:\t%d nm\n",
1941 trasn_code_byte7 = (struct sff_trasnceiver_codes_byte7 *)
1942 &rdp_context->page_a0[SSF_TRANSCEIVER_CODE_B7];
1944 len += scnprintf(buf + len, PAGE_SIZE - len, "Speeds: \t");
1945 if (*(uint8_t *)trasn_code_byte7 == 0) {
1946 len += scnprintf(buf + len, PAGE_SIZE - len, "Unknown\n");
1948 if (trasn_code_byte7->fc_sp_100MB)
1949 len += scnprintf(buf + len, PAGE_SIZE - len, "1 ");
1950 if (trasn_code_byte7->fc_sp_200mb)
1951 len += scnprintf(buf + len, PAGE_SIZE - len, "2 ");
1952 if (trasn_code_byte7->fc_sp_400MB)
1953 len += scnprintf(buf + len, PAGE_SIZE - len, "4 ");
1954 if (trasn_code_byte7->fc_sp_800MB)
1955 len += scnprintf(buf + len, PAGE_SIZE - len, "8 ");
1956 if (trasn_code_byte7->fc_sp_1600MB)
1957 len += scnprintf(buf + len, PAGE_SIZE - len, "16 ");
1958 if (trasn_code_byte7->fc_sp_3200MB)
1959 len += scnprintf(buf + len, PAGE_SIZE - len, "32 ");
1960 if (trasn_code_byte7->speed_chk_ecc)
1961 len += scnprintf(buf + len, PAGE_SIZE - len, "64 ");
1962 len += scnprintf(buf + len, PAGE_SIZE - len, "GB\n");
1964 temperature = (rdp_context->page_a2[SFF_TEMPERATURE_B1] << 8 |
1965 rdp_context->page_a2[SFF_TEMPERATURE_B0]);
1966 vcc = (rdp_context->page_a2[SFF_VCC_B1] << 8 |
1967 rdp_context->page_a2[SFF_VCC_B0]);
1968 tx_power = (rdp_context->page_a2[SFF_TXPOWER_B1] << 8 |
1969 rdp_context->page_a2[SFF_TXPOWER_B0]);
1970 tx_bias = (rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
1971 rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B0]);
1972 rx_power = (rdp_context->page_a2[SFF_RXPOWER_B1] << 8 |
1973 rdp_context->page_a2[SFF_RXPOWER_B0]);
1975 len += scnprintf(buf + len, PAGE_SIZE - len,
1976 "Temperature:\tx%04x C\n", temperature);
1977 len += scnprintf(buf + len, PAGE_SIZE - len, "Vcc:\t\tx%04x V\n", vcc);
1978 len += scnprintf(buf + len, PAGE_SIZE - len,
1979 "TxBiasCurrent:\tx%04x mA\n", tx_bias);
1980 len += scnprintf(buf + len, PAGE_SIZE - len, "TxPower:\tx%04x mW\n",
1982 len += scnprintf(buf + len, PAGE_SIZE - len, "RxPower:\tx%04x mW\n",
1990 * lpfc_board_mode_show - Return the state of the board
1991 * @dev: class device that is converted into a Scsi_host.
1992 * @attr: device attribute, not used.
1993 * @buf: on return contains the state of the adapter.
1995 * Returns: size of formatted string.
1998 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
2001 struct Scsi_Host *shost = class_to_shost(dev);
2002 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2003 struct lpfc_hba *phba = vport->phba;
2006 if (phba->link_state == LPFC_HBA_ERROR)
2008 else if (phba->link_state == LPFC_WARM_START)
2009 state = "warm start";
2010 else if (phba->link_state == LPFC_INIT_START)
2015 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
2019 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
2020 * @dev: class device that is converted into a Scsi_host.
2021 * @attr: device attribute, not used.
2022 * @buf: containing one of the strings "online", "offline", "warm" or "error".
2023 * @count: unused variable.
2026 * -EACCES if enable hba reset not enabled
2027 * -EINVAL if the buffer does not contain a valid string (see above)
2028 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
2029 * buf length greater than zero indicates success
2032 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
2033 const char *buf, size_t count)
2035 struct Scsi_Host *shost = class_to_shost(dev);
2036 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2037 struct lpfc_hba *phba = vport->phba;
2038 struct completion online_compl;
2039 char *board_mode_str = NULL;
2043 if (!phba->cfg_enable_hba_reset) {
2045 goto board_mode_out;
2048 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2049 "3050 lpfc_board_mode set to %s\n", buf);
2051 init_completion(&online_compl);
2053 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
2054 rc = lpfc_workq_post_event(phba, &status, &online_compl,
2058 goto board_mode_out;
2060 wait_for_completion(&online_compl);
2063 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
2064 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2065 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
2066 if (phba->sli_rev == LPFC_SLI_REV4)
2069 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
2070 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
2071 if (phba->sli_rev == LPFC_SLI_REV4)
2074 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
2075 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
2076 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
2077 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
2078 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
2079 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
2080 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
2081 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
2083 status = lpfc_reset_pci_bus(phba);
2084 else if (strncmp(buf, "heartbeat", sizeof("heartbeat") - 1) == 0)
2085 lpfc_issue_hb_tmo(phba);
2086 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
2087 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
2095 board_mode_str = strchr(buf, '\n');
2097 *board_mode_str = '\0';
2098 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2099 "3097 Failed \"%s\", status(%d), "
2101 buf, status, phba->pport->fc_flag);
2107 * lpfc_get_hba_info - Return various bits of informaton about the adapter
2108 * @phba: pointer to the adapter structure.
2109 * @mxri: max xri count.
2110 * @axri: available xri count.
2111 * @mrpi: max rpi count.
2112 * @arpi: available rpi count.
2113 * @mvpi: max vpi count.
2114 * @avpi: available vpi count.
2117 * If an integer pointer for an count is not null then the value for the
2118 * count is returned.
2125 lpfc_get_hba_info(struct lpfc_hba *phba,
2126 uint32_t *mxri, uint32_t *axri,
2127 uint32_t *mrpi, uint32_t *arpi,
2128 uint32_t *mvpi, uint32_t *avpi)
2130 LPFC_MBOXQ_t *pmboxq;
2133 struct lpfc_sli4_hba *sli4_hba;
2134 struct lpfc_max_cfg_param *max_cfg_param;
2135 u16 rsrc_ext_cnt, rsrc_ext_size, max_vpi;
2138 * prevent udev from issuing mailbox commands until the port is
2141 if (phba->link_state < LPFC_LINK_DOWN ||
2142 !phba->mbox_mem_pool ||
2143 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
2146 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
2149 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2152 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2154 pmb = &pmboxq->u.mb;
2155 pmb->mbxCommand = MBX_READ_CONFIG;
2156 pmb->mbxOwner = OWN_HOST;
2157 pmboxq->ctx_buf = NULL;
2159 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
2160 rc = MBX_NOT_FINISHED;
2162 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2164 if (rc != MBX_SUCCESS) {
2165 if (rc != MBX_TIMEOUT)
2166 mempool_free(pmboxq, phba->mbox_mem_pool);
2170 if (phba->sli_rev == LPFC_SLI_REV4) {
2171 sli4_hba = &phba->sli4_hba;
2172 max_cfg_param = &sli4_hba->max_cfg_param;
2174 /* Normally, extents are not used */
2175 if (!phba->sli4_hba.extents_in_use) {
2177 *mrpi = max_cfg_param->max_rpi;
2179 *mxri = max_cfg_param->max_xri;
2181 max_vpi = max_cfg_param->max_vpi;
2183 /* Limit the max we support */
2184 if (max_vpi > LPFC_MAX_VPI)
2185 max_vpi = LPFC_MAX_VPI;
2188 } else { /* Extents in use */
2190 if (lpfc_sli4_get_avail_extnt_rsrc(phba,
2191 LPFC_RSC_TYPE_FCOE_RPI,
2198 *mrpi = rsrc_ext_cnt * rsrc_ext_size;
2202 if (lpfc_sli4_get_avail_extnt_rsrc(phba,
2203 LPFC_RSC_TYPE_FCOE_XRI,
2210 *mxri = rsrc_ext_cnt * rsrc_ext_size;
2214 if (lpfc_sli4_get_avail_extnt_rsrc(phba,
2215 LPFC_RSC_TYPE_FCOE_VPI,
2222 max_vpi = rsrc_ext_cnt * rsrc_ext_size;
2224 /* Limit the max we support */
2225 if (max_vpi > LPFC_MAX_VPI)
2226 max_vpi = LPFC_MAX_VPI;
2232 *mrpi = pmb->un.varRdConfig.max_rpi;
2234 *arpi = pmb->un.varRdConfig.avail_rpi;
2236 *mxri = pmb->un.varRdConfig.max_xri;
2238 *axri = pmb->un.varRdConfig.avail_xri;
2240 *mvpi = pmb->un.varRdConfig.max_vpi;
2242 /* avail_vpi is only valid if link is up and ready */
2243 if (phba->link_state == LPFC_HBA_READY)
2244 *avpi = pmb->un.varRdConfig.avail_vpi;
2246 *avpi = pmb->un.varRdConfig.max_vpi;
2254 mempool_free(pmboxq, phba->mbox_mem_pool);
2259 * lpfc_max_rpi_show - Return maximum rpi
2260 * @dev: class device that is converted into a Scsi_host.
2261 * @attr: device attribute, not used.
2262 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
2265 * Calls lpfc_get_hba_info() asking for just the mrpi count.
2266 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2267 * to "Unknown" and the buffer length is returned, therefore the caller
2268 * must check for "Unknown" in the buffer to detect a failure.
2270 * Returns: size of formatted string.
2273 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
2276 struct Scsi_Host *shost = class_to_shost(dev);
2277 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2278 struct lpfc_hba *phba = vport->phba;
2281 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
2282 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2283 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2287 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
2288 * @dev: class device that is converted into a Scsi_host.
2289 * @attr: device attribute, not used.
2290 * @buf: containing the used rpi count in decimal or "Unknown".
2293 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
2294 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2295 * to "Unknown" and the buffer length is returned, therefore the caller
2296 * must check for "Unknown" in the buffer to detect a failure.
2298 * Returns: size of formatted string.
2301 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
2304 struct Scsi_Host *shost = class_to_shost(dev);
2305 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2306 struct lpfc_hba *phba = vport->phba;
2307 struct lpfc_sli4_hba *sli4_hba;
2308 struct lpfc_max_cfg_param *max_cfg_param;
2309 u32 cnt = 0, acnt = 0;
2311 if (phba->sli_rev == LPFC_SLI_REV4) {
2312 sli4_hba = &phba->sli4_hba;
2313 max_cfg_param = &sli4_hba->max_cfg_param;
2314 return scnprintf(buf, PAGE_SIZE, "%d\n",
2315 max_cfg_param->rpi_used);
2317 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
2318 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2320 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2324 * lpfc_max_xri_show - Return maximum xri
2325 * @dev: class device that is converted into a Scsi_host.
2326 * @attr: device attribute, not used.
2327 * @buf: on return contains the maximum xri count in decimal or "Unknown".
2330 * Calls lpfc_get_hba_info() asking for just the mrpi count.
2331 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2332 * to "Unknown" and the buffer length is returned, therefore the caller
2333 * must check for "Unknown" in the buffer to detect a failure.
2335 * Returns: size of formatted string.
2338 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
2341 struct Scsi_Host *shost = class_to_shost(dev);
2342 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2343 struct lpfc_hba *phba = vport->phba;
2346 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2347 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2348 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2352 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2353 * @dev: class device that is converted into a Scsi_host.
2354 * @attr: device attribute, not used.
2355 * @buf: on return contains the used xri count in decimal or "Unknown".
2358 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2359 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2360 * to "Unknown" and the buffer length is returned, therefore the caller
2361 * must check for "Unknown" in the buffer to detect a failure.
2363 * Returns: size of formatted string.
2366 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2369 struct Scsi_Host *shost = class_to_shost(dev);
2370 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2371 struct lpfc_hba *phba = vport->phba;
2372 struct lpfc_sli4_hba *sli4_hba;
2373 struct lpfc_max_cfg_param *max_cfg_param;
2374 u32 cnt = 0, acnt = 0;
2376 if (phba->sli_rev == LPFC_SLI_REV4) {
2377 sli4_hba = &phba->sli4_hba;
2378 max_cfg_param = &sli4_hba->max_cfg_param;
2379 return scnprintf(buf, PAGE_SIZE, "%d\n",
2380 max_cfg_param->xri_used);
2382 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2383 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2385 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2389 * lpfc_max_vpi_show - Return maximum vpi
2390 * @dev: class device that is converted into a Scsi_host.
2391 * @attr: device attribute, not used.
2392 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2395 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2396 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2397 * to "Unknown" and the buffer length is returned, therefore the caller
2398 * must check for "Unknown" in the buffer to detect a failure.
2400 * Returns: size of formatted string.
2403 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2406 struct Scsi_Host *shost = class_to_shost(dev);
2407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2408 struct lpfc_hba *phba = vport->phba;
2411 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2412 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2413 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2417 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2418 * @dev: class device that is converted into a Scsi_host.
2419 * @attr: device attribute, not used.
2420 * @buf: on return contains the used vpi count in decimal or "Unknown".
2423 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2424 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2425 * to "Unknown" and the buffer length is returned, therefore the caller
2426 * must check for "Unknown" in the buffer to detect a failure.
2428 * Returns: size of formatted string.
2431 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2434 struct Scsi_Host *shost = class_to_shost(dev);
2435 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2436 struct lpfc_hba *phba = vport->phba;
2437 struct lpfc_sli4_hba *sli4_hba;
2438 struct lpfc_max_cfg_param *max_cfg_param;
2439 u32 cnt = 0, acnt = 0;
2441 if (phba->sli_rev == LPFC_SLI_REV4) {
2442 sli4_hba = &phba->sli4_hba;
2443 max_cfg_param = &sli4_hba->max_cfg_param;
2444 return scnprintf(buf, PAGE_SIZE, "%d\n",
2445 max_cfg_param->vpi_used);
2447 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2448 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2450 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2454 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2455 * @dev: class device that is converted into a Scsi_host.
2456 * @attr: device attribute, not used.
2457 * @buf: text that must be interpreted to determine if npiv is supported.
2460 * Buffer will contain text indicating npiv is not suppoerted on the port,
2461 * the port is an NPIV physical port, or it is an npiv virtual port with
2462 * the id of the vport.
2464 * Returns: size of formatted string.
2467 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2470 struct Scsi_Host *shost = class_to_shost(dev);
2471 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2472 struct lpfc_hba *phba = vport->phba;
2474 if (!(phba->max_vpi))
2475 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2476 if (vport->port_type == LPFC_PHYSICAL_PORT)
2477 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2478 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2482 * lpfc_poll_show - Return text about poll support for the adapter
2483 * @dev: class device that is converted into a Scsi_host.
2484 * @attr: device attribute, not used.
2485 * @buf: on return contains the cfg_poll in hex.
2488 * cfg_poll should be a lpfc_polling_flags type.
2490 * Returns: size of formatted string.
2493 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2496 struct Scsi_Host *shost = class_to_shost(dev);
2497 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2498 struct lpfc_hba *phba = vport->phba;
2500 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2504 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2505 * @dev: class device that is converted into a Scsi_host.
2506 * @attr: device attribute, not used.
2507 * @buf: one or more lpfc_polling_flags values.
2511 * buf contents converted to integer and checked for a valid value.
2514 * -EINVAL if the buffer connot be converted or is out of range
2515 * length of the buf on success
2518 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2519 const char *buf, size_t count)
2521 struct Scsi_Host *shost = class_to_shost(dev);
2522 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2523 struct lpfc_hba *phba = vport->phba;
2528 if (!isdigit(buf[0]))
2531 if (sscanf(buf, "%i", &val) != 1)
2534 if ((val & 0x3) != val)
2537 if (phba->sli_rev == LPFC_SLI_REV4)
2540 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2541 "3051 lpfc_poll changed from %d to %d\n",
2542 phba->cfg_poll, val);
2544 spin_lock_irq(&phba->hbalock);
2546 old_val = phba->cfg_poll;
2548 if (val & ENABLE_FCP_RING_POLLING) {
2549 if ((val & DISABLE_FCP_RING_INT) &&
2550 !(old_val & DISABLE_FCP_RING_INT)) {
2551 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2552 spin_unlock_irq(&phba->hbalock);
2555 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2556 writel(creg_val, phba->HCregaddr);
2557 readl(phba->HCregaddr); /* flush */
2559 lpfc_poll_start_timer(phba);
2561 } else if (val != 0x0) {
2562 spin_unlock_irq(&phba->hbalock);
2566 if (!(val & DISABLE_FCP_RING_INT) &&
2567 (old_val & DISABLE_FCP_RING_INT))
2569 spin_unlock_irq(&phba->hbalock);
2570 del_timer(&phba->fcp_poll_timer);
2571 spin_lock_irq(&phba->hbalock);
2572 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2573 spin_unlock_irq(&phba->hbalock);
2576 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2577 writel(creg_val, phba->HCregaddr);
2578 readl(phba->HCregaddr); /* flush */
2581 phba->cfg_poll = val;
2583 spin_unlock_irq(&phba->hbalock);
2589 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2590 * @dev: class converted to a Scsi_host structure.
2591 * @attr: device attribute, not used.
2592 * @buf: on return contains the formatted support level.
2595 * Returns the maximum number of virtual functions a physical function can
2596 * support, 0 will be returned if called on virtual function.
2598 * Returns: size of formatted string.
2601 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2602 struct device_attribute *attr,
2605 struct Scsi_Host *shost = class_to_shost(dev);
2606 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2607 struct lpfc_hba *phba = vport->phba;
2608 uint16_t max_nr_virtfn;
2610 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2611 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2615 * lpfc_enable_bbcr_set: Sets an attribute value.
2616 * @phba: pointer to the adapter structure.
2617 * @val: integer attribute value.
2620 * Validates the min and max values then sets the
2621 * adapter config field if in the valid range. prints error message
2622 * and does not set the parameter if invalid.
2626 * -EINVAL if val is invalid
2629 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2631 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2632 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2633 "3068 lpfc_enable_bbcr changed from %d to "
2634 "%d\n", phba->cfg_enable_bbcr, val);
2635 phba->cfg_enable_bbcr = val;
2638 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2639 "0451 lpfc_enable_bbcr cannot set to %d, range is 0, "
2645 * lpfc_param_show - Return a cfg attribute value in decimal
2648 * Macro that given an attr e.g. hba_queue_depth expands
2649 * into a function with the name lpfc_hba_queue_depth_show.
2651 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2652 * @dev: class device that is converted into a Scsi_host.
2653 * @attr: device attribute, not used.
2654 * @buf: on return contains the attribute value in decimal.
2656 * Returns: size of formatted string.
2658 #define lpfc_param_show(attr) \
2660 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2663 struct Scsi_Host *shost = class_to_shost(dev);\
2664 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2665 struct lpfc_hba *phba = vport->phba;\
2666 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2671 * lpfc_param_hex_show - Return a cfg attribute value in hex
2674 * Macro that given an attr e.g. hba_queue_depth expands
2675 * into a function with the name lpfc_hba_queue_depth_show
2677 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2678 * @dev: class device that is converted into a Scsi_host.
2679 * @attr: device attribute, not used.
2680 * @buf: on return contains the attribute value in hexadecimal.
2682 * Returns: size of formatted string.
2684 #define lpfc_param_hex_show(attr) \
2686 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2689 struct Scsi_Host *shost = class_to_shost(dev);\
2690 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2691 struct lpfc_hba *phba = vport->phba;\
2693 val = phba->cfg_##attr;\
2694 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2699 * lpfc_param_init - Initializes a cfg attribute
2702 * Macro that given an attr e.g. hba_queue_depth expands
2703 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2704 * takes a default argument, a minimum and maximum argument.
2706 * lpfc_##attr##_init: Initializes an attribute.
2707 * @phba: pointer to the adapter structure.
2708 * @val: integer attribute value.
2710 * Validates the min and max values then sets the adapter config field
2711 * accordingly, or uses the default if out of range and prints an error message.
2715 * -EINVAL if default used
2717 #define lpfc_param_init(attr, default, minval, maxval) \
2719 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2721 if (lpfc_rangecheck(val, minval, maxval)) {\
2722 phba->cfg_##attr = val;\
2725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2726 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2727 "allowed range is ["#minval", "#maxval"]\n", val); \
2728 phba->cfg_##attr = default;\
2733 * lpfc_param_set - Set a cfg attribute value
2736 * Macro that given an attr e.g. hba_queue_depth expands
2737 * into a function with the name lpfc_hba_queue_depth_set
2739 * lpfc_##attr##_set: Sets an attribute value.
2740 * @phba: pointer to the adapter structure.
2741 * @val: integer attribute value.
2744 * Validates the min and max values then sets the
2745 * adapter config field if in the valid range. prints error message
2746 * and does not set the parameter if invalid.
2750 * -EINVAL if val is invalid
2752 #define lpfc_param_set(attr, default, minval, maxval) \
2754 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2756 if (lpfc_rangecheck(val, minval, maxval)) {\
2757 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2758 "3052 lpfc_" #attr " changed from %d to %d\n", \
2759 phba->cfg_##attr, val); \
2760 phba->cfg_##attr = val;\
2763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2764 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2765 "allowed range is ["#minval", "#maxval"]\n", val); \
2770 * lpfc_param_store - Set a vport attribute value
2773 * Macro that given an attr e.g. hba_queue_depth expands
2774 * into a function with the name lpfc_hba_queue_depth_store.
2776 * lpfc_##attr##_store: Set an sttribute value.
2777 * @dev: class device that is converted into a Scsi_host.
2778 * @attr: device attribute, not used.
2779 * @buf: contains the attribute value in ascii.
2783 * Convert the ascii text number to an integer, then
2784 * use the lpfc_##attr##_set function to set the value.
2787 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2788 * length of buffer upon success.
2790 #define lpfc_param_store(attr) \
2792 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2793 const char *buf, size_t count) \
2795 struct Scsi_Host *shost = class_to_shost(dev);\
2796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2797 struct lpfc_hba *phba = vport->phba;\
2799 if (!isdigit(buf[0]))\
2801 if (sscanf(buf, "%i", &val) != 1)\
2803 if (lpfc_##attr##_set(phba, val) == 0) \
2804 return strlen(buf);\
2810 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2813 * Macro that given an attr e.g. hba_queue_depth expands
2814 * into a function with the name lpfc_hba_queue_depth_show
2816 * lpfc_##attr##_show: prints the attribute value in decimal.
2817 * @dev: class device that is converted into a Scsi_host.
2818 * @attr: device attribute, not used.
2819 * @buf: on return contains the attribute value in decimal.
2821 * Returns: length of formatted string.
2823 #define lpfc_vport_param_show(attr) \
2825 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2828 struct Scsi_Host *shost = class_to_shost(dev);\
2829 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2830 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2834 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2837 * Macro that given an attr e.g.
2838 * hba_queue_depth expands into a function with the name
2839 * lpfc_hba_queue_depth_show
2841 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2842 * @dev: class device that is converted into a Scsi_host.
2843 * @attr: device attribute, not used.
2844 * @buf: on return contains the attribute value in hexadecimal.
2846 * Returns: length of formatted string.
2848 #define lpfc_vport_param_hex_show(attr) \
2850 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2853 struct Scsi_Host *shost = class_to_shost(dev);\
2854 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2855 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2859 * lpfc_vport_param_init - Initialize a vport cfg attribute
2862 * Macro that given an attr e.g. hba_queue_depth expands
2863 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2864 * takes a default argument, a minimum and maximum argument.
2866 * lpfc_##attr##_init: validates the min and max values then sets the
2867 * adapter config field accordingly, or uses the default if out of range
2868 * and prints an error message.
2869 * @phba: pointer to the adapter structure.
2870 * @val: integer attribute value.
2874 * -EINVAL if default used
2876 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2878 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2880 if (lpfc_rangecheck(val, minval, maxval)) {\
2881 vport->cfg_##attr = val;\
2884 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2885 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2886 "allowed range is ["#minval", "#maxval"]\n", val); \
2887 vport->cfg_##attr = default;\
2892 * lpfc_vport_param_set - Set a vport cfg attribute
2895 * Macro that given an attr e.g. hba_queue_depth expands
2896 * into a function with the name lpfc_hba_queue_depth_set
2898 * lpfc_##attr##_set: validates the min and max values then sets the
2899 * adapter config field if in the valid range. prints error message
2900 * and does not set the parameter if invalid.
2901 * @phba: pointer to the adapter structure.
2902 * @val: integer attribute value.
2906 * -EINVAL if val is invalid
2908 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2910 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2912 if (lpfc_rangecheck(val, minval, maxval)) {\
2913 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2914 "3053 lpfc_" #attr \
2915 " changed from %d (x%x) to %d (x%x)\n", \
2916 vport->cfg_##attr, vport->cfg_##attr, \
2918 vport->cfg_##attr = val;\
2921 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2922 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2923 "allowed range is ["#minval", "#maxval"]\n", val); \
2928 * lpfc_vport_param_store - Set a vport attribute
2931 * Macro that given an attr e.g. hba_queue_depth
2932 * expands into a function with the name lpfc_hba_queue_depth_store
2934 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2935 * use the lpfc_##attr##_set function to set the value.
2936 * @cdev: class device that is converted into a Scsi_host.
2937 * @buf: contains the attribute value in decimal.
2941 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2942 * length of buffer upon success.
2944 #define lpfc_vport_param_store(attr) \
2946 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2947 const char *buf, size_t count) \
2949 struct Scsi_Host *shost = class_to_shost(dev);\
2950 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2952 if (!isdigit(buf[0]))\
2954 if (sscanf(buf, "%i", &val) != 1)\
2956 if (lpfc_##attr##_set(vport, val) == 0) \
2957 return strlen(buf);\
2963 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2964 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2965 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2966 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2967 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2968 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2969 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2970 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2971 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2972 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2973 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2974 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2975 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2976 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2977 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2978 lpfc_link_state_store);
2979 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2980 lpfc_option_rom_version_show, NULL);
2981 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2982 lpfc_num_discovered_ports_show, NULL);
2983 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2984 static DEVICE_ATTR_RO(lpfc_drvr_version);
2985 static DEVICE_ATTR_RO(lpfc_enable_fip);
2986 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2987 lpfc_board_mode_show, lpfc_board_mode_store);
2988 static DEVICE_ATTR_RO(lpfc_xcvr_data);
2989 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2990 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2991 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2992 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2993 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2994 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2995 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2996 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2997 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2998 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2999 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
3000 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
3002 static DEVICE_ATTR(cmf_info, 0444, lpfc_cmf_info_show, NULL);
3006 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
3008 * @cnt: Length of string.
3009 * @wwn: Array to receive converted wwn value.
3012 * -EINVAL if the buffer does not contain a valid wwn
3016 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
3020 /* Count may include a LF at end of string */
3021 if (buf[cnt-1] == '\n')
3024 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
3025 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
3028 memset(wwn, 0, WWN_SZ);
3030 /* Validate and store the new name */
3031 for (i = 0, j = 0; i < 16; i++) {
3032 if ((*buf >= 'a') && (*buf <= 'f'))
3033 j = ((j << 4) | ((*buf++ - 'a') + 10));
3034 else if ((*buf >= 'A') && (*buf <= 'F'))
3035 j = ((j << 4) | ((*buf++ - 'A') + 10));
3036 else if ((*buf >= '0') && (*buf <= '9'))
3037 j = ((j << 4) | (*buf++ - '0'));
3041 wwn[i/2] = j & 0xff;
3050 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
3051 * Optimized Access Storage (OAS) operations.
3052 * @dev: class device that is converted into a Scsi_host.
3053 * @attr: device attribute, not used.
3054 * @buf: buffer for passing information.
3060 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
3063 struct Scsi_Host *shost = class_to_shost(dev);
3064 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3066 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3067 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
3071 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
3072 * Optimized Access Storage (OAS) operations.
3073 * @dev: class device that is converted into a Scsi_host.
3074 * @attr: device attribute, not used.
3075 * @buf: buffer for passing information.
3076 * @count: Size of the data buffer.
3079 * -EINVAL count is invalid, invalid wwpn byte invalid
3080 * -EPERM oas is not supported by hba
3081 * value of count on success
3084 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
3085 const char *buf, size_t count)
3087 struct Scsi_Host *shost = class_to_shost(dev);
3088 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3089 unsigned int cnt = count;
3090 uint8_t wwpn[WWN_SZ];
3096 /* count may include a LF at end of string */
3097 if (buf[cnt-1] == '\n')
3100 rc = lpfc_wwn_set(buf, cnt, wwpn);
3104 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3105 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3106 if (wwn_to_u64(wwpn) == 0)
3107 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
3109 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
3110 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3111 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3114 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
3115 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
3118 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
3119 * Optimized Access Storage (OAS) operations.
3120 * @dev: class device that is converted into a Scsi_host.
3121 * @attr: device attribute, not used.
3122 * @buf: buffer for passing information.
3128 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3131 struct Scsi_Host *shost = class_to_shost(dev);
3132 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3134 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3138 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3139 * Optimized Access Storage (OAS) operations.
3140 * @dev: class device that is converted into a Scsi_host.
3141 * @attr: device attribute, not used.
3142 * @buf: buffer for passing information.
3143 * @count: Size of the data buffer.
3146 * -EINVAL count is invalid, invalid wwpn byte invalid
3147 * -EPERM oas is not supported by hba
3148 * value of count on success
3151 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3152 const char *buf, size_t count)
3154 struct Scsi_Host *shost = class_to_shost(dev);
3155 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3156 unsigned int cnt = count;
3163 /* count may include a LF at end of string */
3164 if (buf[cnt-1] == '\n')
3167 ret = kstrtoul(buf, 0, &val);
3168 if (ret || (val > 0x7f))
3172 phba->cfg_oas_priority = (uint8_t)val;
3174 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3177 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3178 lpfc_oas_priority_show, lpfc_oas_priority_store);
3181 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3182 * for Optimized Access Storage (OAS) operations.
3183 * @dev: class device that is converted into a Scsi_host.
3184 * @attr: device attribute, not used.
3185 * @buf: buffer for passing information.
3188 * value of count on success
3191 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3194 struct Scsi_Host *shost = class_to_shost(dev);
3195 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3197 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3198 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3202 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3203 * for Optimized Access Storage (OAS) operations.
3204 * @dev: class device that is converted into a Scsi_host.
3205 * @attr: device attribute, not used.
3206 * @buf: buffer for passing information.
3207 * @count: Size of the data buffer.
3210 * -EINVAL count is invalid, invalid wwpn byte invalid
3211 * -EPERM oas is not supported by hba
3212 * value of count on success
3215 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3216 const char *buf, size_t count)
3218 struct Scsi_Host *shost = class_to_shost(dev);
3219 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3220 unsigned int cnt = count;
3221 uint8_t wwpn[WWN_SZ];
3227 /* count may include a LF at end of string */
3228 if (buf[cnt-1] == '\n')
3231 rc = lpfc_wwn_set(buf, cnt, wwpn);
3235 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3236 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3237 if (wwn_to_u64(wwpn) == 0)
3238 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3240 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3241 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3242 if (phba->cfg_oas_priority == 0)
3243 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3244 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3247 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3248 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3251 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3252 * of whether luns will be enabled or disabled
3253 * for Optimized Access Storage (OAS) operations.
3254 * @dev: class device that is converted into a Scsi_host.
3255 * @attr: device attribute, not used.
3256 * @buf: buffer for passing information.
3259 * size of formatted string.
3262 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3265 struct Scsi_Host *shost = class_to_shost(dev);
3266 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3268 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3272 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3273 * of whether luns will be enabled or disabled
3274 * for Optimized Access Storage (OAS) operations.
3275 * @dev: class device that is converted into a Scsi_host.
3276 * @attr: device attribute, not used.
3277 * @buf: buffer for passing information.
3278 * @count: Size of the data buffer.
3281 * -EINVAL count is invalid, invalid wwpn byte invalid
3282 * -EPERM oas is not supported by hba
3283 * value of count on success
3286 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3287 const char *buf, size_t count)
3289 struct Scsi_Host *shost = class_to_shost(dev);
3290 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3296 if (!isdigit(buf[0]))
3299 if (sscanf(buf, "%i", &val) != 1)
3302 if ((val != 0) && (val != 1))
3305 phba->cfg_oas_lun_state = val;
3308 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3309 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3312 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3313 * Storage (OAS) lun returned by the
3314 * lpfc_oas_lun_show function.
3315 * @dev: class device that is converted into a Scsi_host.
3316 * @attr: device attribute, not used.
3317 * @buf: buffer for passing information.
3320 * size of formatted string.
3323 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3326 struct Scsi_Host *shost = class_to_shost(dev);
3327 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3329 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3332 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3334 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3335 lpfc_oas_lun_status_show, NULL);
3339 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3341 * @phba: lpfc_hba pointer.
3342 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3343 * @tgt_wwpn: wwpn of the target associated with the returned lun
3344 * @lun: the fc lun for setting oas state.
3345 * @oas_state: the oas state to be set to the lun.
3350 * -EPERM OAS is not enabled or not supported by this port.
3354 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3355 uint8_t tgt_wwpn[], uint64_t lun,
3356 uint32_t oas_state, uint8_t pri)
3365 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3366 (struct lpfc_name *)tgt_wwpn,
3370 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3371 (struct lpfc_name *)tgt_wwpn, lun, pri);
3378 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3379 * Access Storage (OAS) operations.
3380 * @phba: lpfc_hba pointer.
3381 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3382 * @tgt_wwpn: wwpn of the target associated with the returned lun
3383 * @lun_status: status of the lun returned lun
3384 * @lun_pri: priority of the lun returned lun
3386 * Returns the first or next lun enabled for OAS operations for the vport/target
3387 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3388 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3391 * lun that is OAS enabled for the vport/target
3392 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3395 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3396 uint8_t tgt_wwpn[], uint32_t *lun_status,
3401 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3402 return NOT_OAS_ENABLED_LUN;
3403 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3404 phba->sli4_hba.oas_next_vpt_wwpn,
3405 (struct lpfc_name *)
3406 phba->sli4_hba.oas_next_tgt_wwpn,
3407 &phba->sli4_hba.oas_next_lun,
3408 (struct lpfc_name *)vpt_wwpn,
3409 (struct lpfc_name *)tgt_wwpn,
3410 &found_lun, lun_status, lun_pri))
3413 return NOT_OAS_ENABLED_LUN;
3417 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3418 * @phba: lpfc_hba pointer.
3419 * @vpt_wwpn: vport wwpn by reference.
3420 * @tgt_wwpn: target wwpn by reference.
3421 * @lun: the fc lun for setting oas state.
3422 * @oas_state: the oas state to be set to the oas_lun.
3425 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3426 * a lun for OAS operations.
3430 * -ENOMEM: failed to enable an lun for OAS operations
3431 * -EPERM: OAS is not enabled
3434 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3435 uint8_t tgt_wwpn[], uint64_t lun,
3436 uint32_t oas_state, uint8_t pri)
3441 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3447 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3448 * @dev: class device that is converted into a Scsi_host.
3449 * @attr: device attribute, not used.
3450 * @buf: buffer for passing information.
3452 * This routine returns a lun enabled for OAS each time the function
3456 * SUCCESS: size of formatted string.
3457 * -EFAULT: target or vport wwpn was not set properly.
3458 * -EPERM: oas is not enabled.
3461 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3464 struct Scsi_Host *shost = class_to_shost(dev);
3465 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3473 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3474 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3477 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3478 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3481 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3482 phba->cfg_oas_tgt_wwpn,
3483 &phba->cfg_oas_lun_status,
3484 &phba->cfg_oas_priority);
3485 if (oas_lun != NOT_OAS_ENABLED_LUN)
3486 phba->cfg_oas_flags |= OAS_LUN_VALID;
3488 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3494 * lpfc_oas_lun_store - Sets the OAS state for lun
3495 * @dev: class device that is converted into a Scsi_host.
3496 * @attr: device attribute, not used.
3497 * @buf: buffer for passing information.
3498 * @count: size of the formatting string
3500 * This function sets the OAS state for lun. Before this function is called,
3501 * the vport wwpn, target wwpn, and oas state need to be set.
3504 * SUCCESS: size of formatted string.
3505 * -EFAULT: target or vport wwpn was not set properly.
3506 * -EPERM: oas is not enabled.
3507 * size of formatted string.
3510 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3511 const char *buf, size_t count)
3513 struct Scsi_Host *shost = class_to_shost(dev);
3514 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3522 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3525 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3528 if (!isdigit(buf[0]))
3531 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3534 pri = phba->cfg_oas_priority;
3536 pri = phba->cfg_XLanePriority;
3538 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3539 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3540 "priority 0x%x with oas state %d\n",
3541 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3542 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3543 pri, phba->cfg_oas_lun_state);
3545 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3546 phba->cfg_oas_tgt_wwpn, scsi_lun,
3547 phba->cfg_oas_lun_state, pri);
3553 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3554 lpfc_oas_lun_show, lpfc_oas_lun_store);
3556 int lpfc_enable_nvmet_cnt;
3557 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3558 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3559 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3560 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3561 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3563 static int lpfc_poll = 0;
3564 module_param(lpfc_poll, int, S_IRUGO);
3565 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3567 " 1 - poll with interrupts enabled"
3568 " 3 - poll and disable FCP ring interrupts");
3570 static DEVICE_ATTR_RW(lpfc_poll);
3572 int lpfc_no_hba_reset_cnt;
3573 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3574 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3575 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3576 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3578 LPFC_ATTR(sli_mode, 3, 3, 3,
3579 "SLI mode selector: 3 - select SLI-3");
3581 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3582 "Enable NPIV functionality");
3584 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3585 "FCF Fast failover=1 Priority failover=2");
3588 * lpfc_fcp_wait_abts_rsp: Modifies criteria for reporting completion of
3590 * The range is [0,1]. Default value is 0
3591 * 0, IO completes after ABTS issued (default).
3592 * 1, IO completes after receipt of ABTS response or timeout.
3594 LPFC_ATTR_R(fcp_wait_abts_rsp, 0, 0, 1, "Wait for FCP ABTS completion");
3597 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3598 # 0x0 = disabled, XRI/OXID use not tracked.
3599 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3600 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3602 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3603 "Enable RRQ functionality");
3606 # lpfc_suppress_link_up: Bring link up at initialization
3607 # 0x0 = bring link up (issue MBX_INIT_LINK)
3608 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3609 # 0x2 = never bring up link
3610 # Default value is 0.
3612 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3613 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3614 "Suppress Link Up at initialization");
3617 lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3619 struct Scsi_Host *shost = class_to_shost(dev);
3620 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3622 return scnprintf(buf, PAGE_SIZE, "%d\n",
3623 phba->sli4_hba.pc_sli4_params.pls);
3625 static DEVICE_ATTR(pls, 0444,
3626 lpfc_pls_show, NULL);
3629 lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3631 struct Scsi_Host *shost = class_to_shost(dev);
3632 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3634 return scnprintf(buf, PAGE_SIZE, "%d\n",
3635 (phba->hba_flag & HBA_PERSISTENT_TOPO) ? 1 : 0);
3637 static DEVICE_ATTR(pt, 0444,
3638 lpfc_pt_show, NULL);
3641 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3649 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3651 struct Scsi_Host *shost = class_to_shost(dev);
3652 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3654 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3657 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3658 lpfc_iocb_hw_show, NULL);
3660 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3662 struct Scsi_Host *shost = class_to_shost(dev);
3663 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3664 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3666 return scnprintf(buf, PAGE_SIZE, "%d\n",
3667 pring ? pring->txq_max : 0);
3670 static DEVICE_ATTR(txq_hw, S_IRUGO,
3671 lpfc_txq_hw_show, NULL);
3673 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3676 struct Scsi_Host *shost = class_to_shost(dev);
3677 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3678 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3680 return scnprintf(buf, PAGE_SIZE, "%d\n",
3681 pring ? pring->txcmplq_max : 0);
3684 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3685 lpfc_txcmplq_hw_show, NULL);
3688 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3689 # until the timer expires. Value range is [0,255]. Default value is 30.
3691 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3692 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3693 module_param(lpfc_nodev_tmo, int, 0);
3694 MODULE_PARM_DESC(lpfc_nodev_tmo,
3695 "Seconds driver will hold I/O waiting "
3696 "for a device to come back");
3699 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3700 * @dev: class converted to a Scsi_host structure.
3701 * @attr: device attribute, not used.
3702 * @buf: on return contains the dev loss timeout in decimal.
3704 * Returns: size of formatted string.
3707 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3710 struct Scsi_Host *shost = class_to_shost(dev);
3711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3713 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3717 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3718 * @vport: lpfc vport structure pointer.
3719 * @val: contains the nodev timeout value.
3722 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3723 * a kernel error message is printed and zero is returned.
3724 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3725 * Otherwise nodev tmo is set to the default value.
3728 * zero if already set or if val is in range
3729 * -EINVAL val out of range
3732 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3734 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3735 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3736 if (val != LPFC_DEF_DEVLOSS_TMO)
3737 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3738 "0407 Ignoring lpfc_nodev_tmo module "
3739 "parameter because lpfc_devloss_tmo "
3744 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3745 vport->cfg_nodev_tmo = val;
3746 vport->cfg_devloss_tmo = val;
3749 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3750 "0400 lpfc_nodev_tmo attribute cannot be set to"
3751 " %d, allowed range is [%d, %d]\n",
3752 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3753 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3758 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3759 * @vport: lpfc vport structure pointer.
3762 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3765 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3767 struct Scsi_Host *shost;
3768 struct lpfc_nodelist *ndlp;
3769 #if (IS_ENABLED(CONFIG_NVME_FC))
3770 struct lpfc_nvme_rport *rport;
3771 struct nvme_fc_remote_port *remoteport = NULL;
3774 shost = lpfc_shost_from_vport(vport);
3775 spin_lock_irq(shost->host_lock);
3776 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3778 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3779 #if (IS_ENABLED(CONFIG_NVME_FC))
3780 spin_lock(&ndlp->lock);
3781 rport = lpfc_ndlp_get_nrport(ndlp);
3783 remoteport = rport->remoteport;
3784 spin_unlock(&ndlp->lock);
3785 if (rport && remoteport)
3786 nvme_fc_set_remoteport_devloss(remoteport,
3787 vport->cfg_devloss_tmo);
3790 spin_unlock_irq(shost->host_lock);
3794 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3795 * @vport: lpfc vport structure pointer.
3796 * @val: contains the tmo value.
3799 * If the devloss tmo is already set or the vport dev loss tmo has changed
3800 * then a kernel error message is printed and zero is returned.
3801 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3802 * Otherwise nodev tmo is set to the default value.
3805 * zero if already set or if val is in range
3806 * -EINVAL val out of range
3809 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3811 if (vport->dev_loss_tmo_changed ||
3812 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3813 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3814 "0401 Ignoring change to lpfc_nodev_tmo "
3815 "because lpfc_devloss_tmo is set.\n");
3818 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3819 vport->cfg_nodev_tmo = val;
3820 vport->cfg_devloss_tmo = val;
3822 * For compat: set the fc_host dev loss so new rports
3823 * will get the value.
3825 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3826 lpfc_update_rport_devloss_tmo(vport);
3829 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3830 "0403 lpfc_nodev_tmo attribute cannot be set to "
3831 "%d, allowed range is [%d, %d]\n",
3832 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3836 lpfc_vport_param_store(nodev_tmo)
3838 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3841 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3842 # disappear until the timer expires. Value range is [0,255]. Default
3845 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3846 MODULE_PARM_DESC(lpfc_devloss_tmo,
3847 "Seconds driver will hold I/O waiting "
3848 "for a device to come back");
3849 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3850 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3851 lpfc_vport_param_show(devloss_tmo)
3854 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3855 * @vport: lpfc vport structure pointer.
3856 * @val: contains the tmo value.
3859 * If val is in a valid range then set the vport nodev tmo,
3860 * devloss tmo, also set the vport dev loss tmo changed flag.
3861 * Else a kernel error message is printed.
3864 * zero if val is in range
3865 * -EINVAL val out of range
3868 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3870 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3871 vport->cfg_nodev_tmo = val;
3872 vport->cfg_devloss_tmo = val;
3873 vport->dev_loss_tmo_changed = 1;
3874 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3875 lpfc_update_rport_devloss_tmo(vport);
3879 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3880 "0404 lpfc_devloss_tmo attribute cannot be set to "
3881 "%d, allowed range is [%d, %d]\n",
3882 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3886 lpfc_vport_param_store(devloss_tmo)
3887 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3890 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3891 * lpfc_suppress_rsp = 0 Disable
3892 * lpfc_suppress_rsp = 1 Enable (default)
3895 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3896 "Enable suppress rsp feature is firmware supports it");
3899 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3900 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3901 * lpfc_nvmet_mrq = 1 use a single RQ pair
3902 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3905 LPFC_ATTR_R(nvmet_mrq,
3906 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3907 "Specify number of RQ pairs for processing NVMET cmds");
3910 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3911 * to each NVMET RQ. Range 64 to 2048, default is 512.
3913 LPFC_ATTR_R(nvmet_mrq_post,
3914 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3915 LPFC_NVMET_RQE_DEF_COUNT,
3916 "Specify number of RQ buffers to initially post");
3919 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3920 * Supported Values: 1 - register just FCP
3921 * 3 - register both FCP and NVME
3922 * Supported values are [1,3]. Default value is 3
3924 LPFC_ATTR_R(enable_fc4_type, LPFC_DEF_ENBL_FC4_TYPE,
3925 LPFC_ENABLE_FCP, LPFC_MAX_ENBL_FC4_TYPE,
3926 "Enable FC4 Protocol support - FCP / NVME");
3929 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3930 # deluged with LOTS of information.
3931 # You can set a bit mask to record specific types of verbose messages:
3932 # See lpfc_logmsh.h for definitions.
3934 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3935 "Verbose logging bit-mask");
3938 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3939 # objects that have been registered with the nameserver after login.
3941 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3942 "Deregister nameserver objects before LOGO");
3945 # lun_queue_depth: This parameter is used to limit the number of outstanding
3946 # commands per FCP LUN.
3948 LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
3949 "Max number of FCP commands we can queue to a specific LUN");
3952 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3953 # commands per target port. Value range is [10,65535]. Default value is 65535.
3955 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3956 module_param(lpfc_tgt_queue_depth, uint, 0444);
3957 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3958 lpfc_vport_param_show(tgt_queue_depth);
3959 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3960 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3963 * lpfc_tgt_queue_depth_set: Sets an attribute value.
3964 * @vport: lpfc vport structure pointer.
3965 * @val: integer attribute value.
3967 * Description: Sets the parameter to the new value.
3971 * -EINVAL if val is invalid
3974 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3976 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3977 struct lpfc_nodelist *ndlp;
3979 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3982 if (val == vport->cfg_tgt_queue_depth)
3985 spin_lock_irq(shost->host_lock);
3986 vport->cfg_tgt_queue_depth = val;
3988 /* Next loop thru nodelist and change cmd_qdepth */
3989 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3990 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3992 spin_unlock_irq(shost->host_lock);
3996 lpfc_vport_param_store(tgt_queue_depth);
3997 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
4000 # hba_queue_depth: This parameter is used to limit the number of outstanding
4001 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
4002 # value is greater than the maximum number of exchanges supported by the HBA,
4003 # then maximum number of exchanges supported by the HBA is used to determine
4004 # the hba_queue_depth.
4006 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
4007 "Max number of FCP commands we can queue to a lpfc HBA");
4010 # peer_port_login: This parameter allows/prevents logins
4011 # between peer ports hosted on the same physical port.
4012 # When this parameter is set 0 peer ports of same physical port
4013 # are not allowed to login to each other.
4014 # When this parameter is set 1 peer ports of same physical port
4015 # are allowed to login to each other.
4016 # Default value of this parameter is 0.
4018 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
4019 "Allow peer ports on the same physical port to login to each "
4023 # restrict_login: This parameter allows/prevents logins
4024 # between Virtual Ports and remote initiators.
4025 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
4026 # other initiators and will attempt to PLOGI all remote ports.
4027 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
4028 # remote ports and will not attempt to PLOGI to other initiators.
4029 # This parameter does not restrict to the physical port.
4030 # This parameter does not restrict logins to Fabric resident remote ports.
4031 # Default value of this parameter is 1.
4033 static int lpfc_restrict_login = 1;
4034 module_param(lpfc_restrict_login, int, S_IRUGO);
4035 MODULE_PARM_DESC(lpfc_restrict_login,
4036 "Restrict virtual ports login to remote initiators.");
4037 lpfc_vport_param_show(restrict_login);
4040 * lpfc_restrict_login_init - Set the vport restrict login flag
4041 * @vport: lpfc vport structure pointer.
4042 * @val: contains the restrict login value.
4045 * If val is not in a valid range then log a kernel error message and set
4046 * the vport restrict login to one.
4047 * If the port type is physical clear the restrict login flag and return.
4048 * Else set the restrict login flag to val.
4051 * zero if val is in range
4052 * -EINVAL val out of range
4055 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
4057 if (val < 0 || val > 1) {
4058 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4059 "0422 lpfc_restrict_login attribute cannot "
4060 "be set to %d, allowed range is [0, 1]\n",
4062 vport->cfg_restrict_login = 1;
4065 if (vport->port_type == LPFC_PHYSICAL_PORT) {
4066 vport->cfg_restrict_login = 0;
4069 vport->cfg_restrict_login = val;
4074 * lpfc_restrict_login_set - Set the vport restrict login flag
4075 * @vport: lpfc vport structure pointer.
4076 * @val: contains the restrict login value.
4079 * If val is not in a valid range then log a kernel error message and set
4080 * the vport restrict login to one.
4081 * If the port type is physical and the val is not zero log a kernel
4082 * error message, clear the restrict login flag and return zero.
4083 * Else set the restrict login flag to val.
4086 * zero if val is in range
4087 * -EINVAL val out of range
4090 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
4092 if (val < 0 || val > 1) {
4093 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4094 "0425 lpfc_restrict_login attribute cannot "
4095 "be set to %d, allowed range is [0, 1]\n",
4097 vport->cfg_restrict_login = 1;
4100 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
4101 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4102 "0468 lpfc_restrict_login must be 0 for "
4103 "Physical ports.\n");
4104 vport->cfg_restrict_login = 0;
4107 vport->cfg_restrict_login = val;
4110 lpfc_vport_param_store(restrict_login);
4111 static DEVICE_ATTR_RW(lpfc_restrict_login);
4114 # Some disk devices have a "select ID" or "select Target" capability.
4115 # From a protocol standpoint "select ID" usually means select the
4116 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
4117 # annex" which contains a table that maps a "select ID" (a number
4118 # between 0 and 7F) to an ALPA. By default, for compatibility with
4119 # older drivers, the lpfc driver scans this table from low ALPA to high
4122 # Turning on the scan-down variable (on = 1, off = 0) will
4123 # cause the lpfc driver to use an inverted table, effectively
4124 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
4126 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
4127 # and will not work across a fabric. Also this parameter will take
4128 # effect only in the case when ALPA map is not available.)
4130 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
4131 "Start scanning for devices from highest ALPA to lowest");
4134 # lpfc_topology: link topology for init link
4135 # 0x0 = attempt loop mode then point-to-point
4136 # 0x01 = internal loopback mode
4137 # 0x02 = attempt point-to-point mode only
4138 # 0x04 = attempt loop mode only
4139 # 0x06 = attempt point-to-point mode then loop
4140 # Set point-to-point mode if you want to run as an N_Port.
4141 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4142 # Default value is 0.
4144 LPFC_ATTR(topology, 0, 0, 6,
4145 "Select Fibre Channel topology");
4148 * lpfc_topology_store - Set the adapters topology field
4149 * @dev: class device that is converted into a scsi_host.
4150 * @attr:device attribute, not used.
4151 * @buf: buffer for passing information.
4152 * @count: size of the data buffer.
4155 * If val is in a valid range then set the adapter's topology field and
4156 * issue a lip; if the lip fails reset the topology to the old value.
4158 * If the value is not in range log a kernel error message and return an error.
4161 * zero if val is in range and lip okay
4162 * non-zero return value from lpfc_issue_lip()
4163 * -EINVAL val out of range
4166 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4167 const char *buf, size_t count)
4169 struct Scsi_Host *shost = class_to_shost(dev);
4170 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4171 struct lpfc_hba *phba = vport->phba;
4174 const char *val_buf = buf;
4177 u8 sli_family, if_type;
4179 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4181 val_buf = &buf[strlen("nolip ")];
4184 if (!isdigit(val_buf[0]))
4186 if (sscanf(val_buf, "%i", &val) != 1)
4189 if (val >= 0 && val <= 6) {
4190 prev_val = phba->cfg_topology;
4191 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4193 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4194 "3113 Loop mode not supported at speed %d\n",
4199 * The 'topology' is not a configurable parameter if :
4200 * - persistent topology enabled
4201 * - ASIC_GEN_NUM >= 0xC, with no private loop support
4203 sli_family = bf_get(lpfc_sli_intf_sli_family,
4204 &phba->sli4_hba.sli_intf);
4205 if_type = bf_get(lpfc_sli_intf_if_type,
4206 &phba->sli4_hba.sli_intf);
4207 if ((phba->hba_flag & HBA_PERSISTENT_TOPO ||
4208 (!phba->sli4_hba.pc_sli4_params.pls &&
4209 (sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
4210 if_type == LPFC_SLI_INTF_IF_TYPE_6))) &&
4212 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4213 "3114 Loop mode not supported\n");
4216 phba->cfg_topology = val;
4220 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4221 "3054 lpfc_topology changed from %d to %d\n",
4223 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4224 phba->fc_topology_changed = 1;
4225 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4227 phba->cfg_topology = prev_val;
4232 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4233 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4234 "allowed range is [0, 6]\n",
4239 lpfc_param_show(topology)
4240 static DEVICE_ATTR_RW(lpfc_topology);
4243 * lpfc_static_vport_show: Read callback function for
4244 * lpfc_static_vport sysfs file.
4245 * @dev: Pointer to class device object.
4246 * @attr: device attribute structure.
4247 * @buf: Data buffer.
4249 * This function is the read call back function for
4250 * lpfc_static_vport sysfs file. The lpfc_static_vport
4251 * sysfs file report the mageability of the vport.
4254 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4257 struct Scsi_Host *shost = class_to_shost(dev);
4258 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4259 if (vport->vport_flag & STATIC_VPORT)
4260 sprintf(buf, "1\n");
4262 sprintf(buf, "0\n");
4268 * Sysfs attribute to control the statistical data collection.
4270 static DEVICE_ATTR_RO(lpfc_static_vport);
4273 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4275 # Value range is [0,16]. Default value is 0.
4278 * lpfc_link_speed_store - Set the adapters link speed
4279 * @dev: Pointer to class device.
4281 * @buf: Data buffer.
4282 * @count: Size of the data buffer.
4285 * If val is in a valid range then set the adapter's link speed field and
4286 * issue a lip; if the lip fails reset the link speed to the old value.
4289 * If the value is not in range log a kernel error message and return an error.
4292 * zero if val is in range and lip okay.
4293 * non-zero return value from lpfc_issue_lip()
4294 * -EINVAL val out of range
4297 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4298 const char *buf, size_t count)
4300 struct Scsi_Host *shost = class_to_shost(dev);
4301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4302 struct lpfc_hba *phba = vport->phba;
4303 int val = LPFC_USER_LINK_SPEED_AUTO;
4305 const char *val_buf = buf;
4307 uint32_t prev_val, if_type;
4309 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4310 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4311 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4314 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4316 val_buf = &buf[strlen("nolip ")];
4319 if (!isdigit(val_buf[0]))
4321 if (sscanf(val_buf, "%i", &val) != 1)
4324 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4325 "3055 lpfc_link_speed changed from %d to %d %s\n",
4326 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4328 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4329 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4330 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4331 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4332 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4333 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4334 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4335 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4336 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4337 "2879 lpfc_link_speed attribute cannot be set "
4338 "to %d. Speed is not supported by this port.\n",
4342 if (val >= LPFC_USER_LINK_SPEED_16G &&
4343 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4344 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4345 "3112 lpfc_link_speed attribute cannot be set "
4346 "to %d. Speed is not supported in loop mode.\n",
4352 case LPFC_USER_LINK_SPEED_AUTO:
4353 case LPFC_USER_LINK_SPEED_1G:
4354 case LPFC_USER_LINK_SPEED_2G:
4355 case LPFC_USER_LINK_SPEED_4G:
4356 case LPFC_USER_LINK_SPEED_8G:
4357 case LPFC_USER_LINK_SPEED_16G:
4358 case LPFC_USER_LINK_SPEED_32G:
4359 case LPFC_USER_LINK_SPEED_64G:
4360 prev_val = phba->cfg_link_speed;
4361 phba->cfg_link_speed = val;
4365 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4367 phba->cfg_link_speed = prev_val;
4375 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4376 "0469 lpfc_link_speed attribute cannot be set to %d, "
4377 "allowed values are [%s]\n",
4378 val, LPFC_LINK_SPEED_STRING);
4383 static int lpfc_link_speed = 0;
4384 module_param(lpfc_link_speed, int, S_IRUGO);
4385 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4386 lpfc_param_show(link_speed)
4389 * lpfc_link_speed_init - Set the adapters link speed
4390 * @phba: lpfc_hba pointer.
4391 * @val: link speed value.
4394 * If val is in a valid range then set the adapter's link speed field.
4397 * If the value is not in range log a kernel error message, clear the link
4398 * speed and return an error.
4401 * zero if val saved.
4402 * -EINVAL val out of range
4405 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4407 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4409 "3111 lpfc_link_speed of %d cannot "
4410 "support loop mode, setting topology to default.\n",
4412 phba->cfg_topology = 0;
4416 case LPFC_USER_LINK_SPEED_AUTO:
4417 case LPFC_USER_LINK_SPEED_1G:
4418 case LPFC_USER_LINK_SPEED_2G:
4419 case LPFC_USER_LINK_SPEED_4G:
4420 case LPFC_USER_LINK_SPEED_8G:
4421 case LPFC_USER_LINK_SPEED_16G:
4422 case LPFC_USER_LINK_SPEED_32G:
4423 case LPFC_USER_LINK_SPEED_64G:
4424 phba->cfg_link_speed = val;
4427 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4428 "0405 lpfc_link_speed attribute cannot "
4429 "be set to %d, allowed values are "
4430 "["LPFC_LINK_SPEED_STRING"]\n", val);
4431 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4436 static DEVICE_ATTR_RW(lpfc_link_speed);
4439 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4440 # 1 = aer supported and enabled (default)
4441 # PCIe error reporting is always enabled by the PCI core, so this always
4444 # N.B. Parts of LPFC_ATTR open-coded since some of the underlying
4445 # infrastructure (phba->cfg_aer_support) is gone.
4447 static uint lpfc_aer_support = 1;
4448 module_param(lpfc_aer_support, uint, S_IRUGO);
4449 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
4451 lpfc_aer_support_show(struct device *dev, struct device_attribute *attr,
4454 return scnprintf(buf, PAGE_SIZE, "%d\n", lpfc_aer_support);
4458 * lpfc_aer_support_store - Set the adapter for aer support
4460 * @dev: class device that is converted into a Scsi_host.
4461 * @attr: device attribute, not used.
4462 * @buf: containing enable or disable aer flag.
4463 * @count: unused variable.
4466 * PCIe error reporting is enabled by the PCI core, so drivers don't need
4467 * to do anything. Retain this interface for backwards compatibility,
4471 * length of the buf on success
4472 * -EINVAL if val out of range
4475 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4476 const char *buf, size_t count)
4480 if (!isdigit(buf[0]))
4482 if (sscanf(buf, "%i", &val) != 1)
4485 dev_info_once(dev, "PCIe error reporting automatically enabled by the PCI core; sysfs write ignored\n");
4489 static DEVICE_ATTR_RW(lpfc_aer_support);
4492 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4493 * @dev: class device that is converted into a Scsi_host.
4494 * @attr: device attribute, not used.
4495 * @buf: containing flag 1 for aer cleanup state.
4496 * @count: unused variable.
4499 * If the @buf contains 1, invokes the kernel AER helper routine
4500 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
4501 * error status register.
4506 * -EINVAL if the buf does not contain 1
4507 * -EPERM if the OS cannot clear AER error status, i.e., when platform
4508 * firmware owns the AER Capability
4511 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4512 const char *buf, size_t count)
4514 struct Scsi_Host *shost = class_to_shost(dev);
4515 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4516 struct lpfc_hba *phba = vport->phba;
4519 if (!isdigit(buf[0]))
4521 if (sscanf(buf, "%i", &val) != 1)
4526 rc = pci_aer_clear_nonfatal_status(phba->pcidev);
4534 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4535 lpfc_aer_cleanup_state);
4538 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4540 * @dev: class device that is converted into a Scsi_host.
4541 * @attr: device attribute, not used.
4542 * @buf: containing the string the number of vfs to be enabled.
4543 * @count: unused variable.
4546 * When this api is called either through user sysfs, the driver shall
4547 * try to enable or disable SR-IOV virtual functions according to the
4550 * If zero virtual function has been enabled to the physical function,
4551 * the driver shall invoke the pci enable virtual function api trying
4552 * to enable the virtual functions. If the nr_vfn provided is greater
4553 * than the maximum supported, the maximum virtual function number will
4554 * be used for invoking the api; otherwise, the nr_vfn provided shall
4555 * be used for invoking the api. If the api call returned success, the
4556 * actual number of virtual functions enabled will be set to the driver
4557 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4558 * cfg_sriov_nr_virtfn remains zero.
4560 * If none-zero virtual functions have already been enabled to the
4561 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4562 * -EINVAL will be returned and the driver does nothing;
4564 * If the nr_vfn provided is zero and none-zero virtual functions have
4565 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4566 * disabling virtual function api shall be invoded to disable all the
4567 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4568 * zero. Otherwise, if zero virtual function has been enabled, do
4572 * length of the buf on success if val is in range the intended mode
4574 * -EINVAL if val out of range or intended mode is not supported.
4577 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4578 const char *buf, size_t count)
4580 struct Scsi_Host *shost = class_to_shost(dev);
4581 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4582 struct lpfc_hba *phba = vport->phba;
4583 struct pci_dev *pdev = phba->pcidev;
4584 int val = 0, rc = -EINVAL;
4586 /* Sanity check on user data */
4587 if (!isdigit(buf[0]))
4589 if (sscanf(buf, "%i", &val) != 1)
4594 /* Request disabling virtual functions */
4596 if (phba->cfg_sriov_nr_virtfn > 0) {
4597 pci_disable_sriov(pdev);
4598 phba->cfg_sriov_nr_virtfn = 0;
4603 /* Request enabling virtual functions */
4604 if (phba->cfg_sriov_nr_virtfn > 0) {
4605 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4606 "3018 There are %d virtual functions "
4607 "enabled on physical function.\n",
4608 phba->cfg_sriov_nr_virtfn);
4612 if (val <= LPFC_MAX_VFN_PER_PFN)
4613 phba->cfg_sriov_nr_virtfn = val;
4615 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4616 "3019 Enabling %d virtual functions is not "
4621 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4623 phba->cfg_sriov_nr_virtfn = 0;
4631 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4632 "Enable PCIe device SR-IOV virtual fn");
4634 lpfc_param_show(sriov_nr_virtfn)
4635 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4638 * lpfc_request_firmware_upgrade_store - Request for Linux generic firmware upgrade
4640 * @dev: class device that is converted into a Scsi_host.
4641 * @attr: device attribute, not used.
4642 * @buf: containing the string the number of vfs to be enabled.
4643 * @count: unused variable.
4648 * length of the buf on success if val is in range the intended mode
4650 * -EINVAL if val out of range or intended mode is not supported.
4653 lpfc_request_firmware_upgrade_store(struct device *dev,
4654 struct device_attribute *attr,
4655 const char *buf, size_t count)
4657 struct Scsi_Host *shost = class_to_shost(dev);
4658 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4659 struct lpfc_hba *phba = vport->phba;
4662 /* Sanity check on user data */
4663 if (!isdigit(buf[0]))
4665 if (sscanf(buf, "%i", &val) != 1)
4670 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4678 static int lpfc_req_fw_upgrade;
4679 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4680 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4681 lpfc_param_show(request_firmware_upgrade)
4684 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4685 * @phba: lpfc_hba pointer.
4689 * Set the initial Linux generic firmware upgrade enable or disable flag.
4692 * zero if val saved.
4693 * -EINVAL val out of range
4696 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4698 if (val >= 0 && val <= 1) {
4699 phba->cfg_request_firmware_upgrade = val;
4704 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4705 lpfc_request_firmware_upgrade_show,
4706 lpfc_request_firmware_upgrade_store);
4709 * lpfc_force_rscn_store
4711 * @dev: class device that is converted into a Scsi_host.
4712 * @attr: device attribute, not used.
4713 * @buf: unused string
4714 * @count: unused variable.
4717 * Force the switch to send a RSCN to all other NPorts in our zone
4718 * If we are direct connect pt2pt, build the RSCN command ourself
4719 * and send to the other NPort. Not supported for private loop.
4723 * -EIO - if command is not sent
4726 lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4727 const char *buf, size_t count)
4729 struct Scsi_Host *shost = class_to_shost(dev);
4730 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4733 i = lpfc_issue_els_rscn(vport, 0);
4740 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4741 * connected to the HBA.
4743 * Value range is any ascii value
4745 static int lpfc_force_rscn;
4746 module_param(lpfc_force_rscn, int, 0644);
4747 MODULE_PARM_DESC(lpfc_force_rscn,
4748 "Force an RSCN to be sent to all remote NPorts");
4749 lpfc_param_show(force_rscn)
4752 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4753 * @phba: lpfc_hba pointer.
4754 * @val: unused value.
4757 * zero if val saved.
4760 lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
4764 static DEVICE_ATTR_RW(lpfc_force_rscn);
4767 * lpfc_fcp_imax_store
4769 * @dev: class device that is converted into a Scsi_host.
4770 * @attr: device attribute, not used.
4771 * @buf: string with the number of fast-path FCP interrupts per second.
4772 * @count: unused variable.
4775 * If val is in a valid range [636,651042], then set the adapter's
4776 * maximum number of fast-path FCP interrupts per second.
4779 * length of the buf on success if val is in range the intended mode
4781 * -EINVAL if val out of range or intended mode is not supported.
4784 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4785 const char *buf, size_t count)
4787 struct Scsi_Host *shost = class_to_shost(dev);
4788 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4789 struct lpfc_hba *phba = vport->phba;
4790 struct lpfc_eq_intr_info *eqi;
4794 /* fcp_imax is only valid for SLI4 */
4795 if (phba->sli_rev != LPFC_SLI_REV4)
4798 /* Sanity check on user data */
4799 if (!isdigit(buf[0]))
4801 if (sscanf(buf, "%i", &val) != 1)
4805 * Value range for the HBA is [5000,5000000]
4806 * The value for each EQ depends on how many EQs are configured.
4809 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4812 phba->cfg_auto_imax = (val) ? 0 : 1;
4813 if (phba->cfg_fcp_imax && !val) {
4814 queue_delayed_work(phba->wq, &phba->eq_delay_work,
4815 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
4817 for_each_present_cpu(i) {
4818 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
4823 phba->cfg_fcp_imax = (uint32_t)val;
4825 if (phba->cfg_fcp_imax)
4826 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
4830 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4831 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4838 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4841 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4843 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4844 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4845 MODULE_PARM_DESC(lpfc_fcp_imax,
4846 "Set the maximum number of FCP interrupts per second per HBA");
4847 lpfc_param_show(fcp_imax)
4850 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4851 * @phba: lpfc_hba pointer.
4852 * @val: link speed value.
4855 * If val is in a valid range [636,651042], then initialize the adapter's
4856 * maximum number of fast-path FCP interrupts per second.
4859 * zero if val saved.
4860 * -EINVAL val out of range
4863 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4865 if (phba->sli_rev != LPFC_SLI_REV4) {
4866 phba->cfg_fcp_imax = 0;
4870 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4872 phba->cfg_fcp_imax = val;
4876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4877 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4879 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4884 static DEVICE_ATTR_RW(lpfc_fcp_imax);
4887 * lpfc_cq_max_proc_limit_store
4889 * @dev: class device that is converted into a Scsi_host.
4890 * @attr: device attribute, not used.
4891 * @buf: string with the cq max processing limit of cqes
4892 * @count: unused variable.
4895 * If val is in a valid range, then set value on each cq
4898 * The length of the buf: if successful
4899 * -ERANGE: if val is not in the valid range
4900 * -EINVAL: if bad value format or intended mode is not supported.
4903 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
4904 const char *buf, size_t count)
4906 struct Scsi_Host *shost = class_to_shost(dev);
4907 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4908 struct lpfc_hba *phba = vport->phba;
4909 struct lpfc_queue *eq, *cq;
4913 /* cq_max_proc_limit is only valid for SLI4 */
4914 if (phba->sli_rev != LPFC_SLI_REV4)
4917 /* Sanity check on user data */
4918 if (!isdigit(buf[0]))
4920 if (kstrtoul(buf, 0, &val))
4923 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
4926 phba->cfg_cq_max_proc_limit = (uint32_t)val;
4928 /* set the values on the cq's */
4929 for (i = 0; i < phba->cfg_irq_chann; i++) {
4930 /* Get the EQ corresponding to the IRQ vector */
4931 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
4935 list_for_each_entry(cq, &eq->child_list, list)
4936 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
4944 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
4945 * itteration of CQ processing.
4947 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4948 module_param(lpfc_cq_max_proc_limit, int, 0644);
4949 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
4950 "Set the maximum number CQEs processed in an iteration of "
4952 lpfc_param_show(cq_max_proc_limit)
4955 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
4956 * single handler call which should request a polled completion rather
4957 * than re-enabling interrupts.
4959 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
4960 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
4961 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
4962 "CQE Processing Threshold to enable Polling");
4965 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
4966 * @phba: lpfc_hba pointer.
4970 * If val is in a valid range, then initialize the adapter's maximum
4974 * Always returns 0 for success, even if value not always set to
4975 * requested value. If value out of range or not supported, will fall
4979 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
4981 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4983 if (phba->sli_rev != LPFC_SLI_REV4)
4986 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
4987 phba->cfg_cq_max_proc_limit = val;
4991 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4992 "0371 lpfc_cq_max_proc_limit: %d out of range, using "
4994 phba->cfg_cq_max_proc_limit);
4999 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
5002 * lpfc_fcp_cpu_map_show - Display current driver CPU affinity
5003 * @dev: class converted to a Scsi_host structure.
5004 * @attr: device attribute, not used.
5005 * @buf: on return contains text describing the state of the link.
5007 * Returns: size of formatted string.
5010 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5013 struct Scsi_Host *shost = class_to_shost(dev);
5014 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5015 struct lpfc_hba *phba = vport->phba;
5016 struct lpfc_vector_map_info *cpup;
5019 if ((phba->sli_rev != LPFC_SLI_REV4) ||
5020 (phba->intr_type != MSIX))
5023 switch (phba->cfg_fcp_cpu_map) {
5025 len += scnprintf(buf + len, PAGE_SIZE-len,
5026 "fcp_cpu_map: No mapping (%d)\n",
5027 phba->cfg_fcp_cpu_map);
5030 len += scnprintf(buf + len, PAGE_SIZE-len,
5031 "fcp_cpu_map: HBA centric mapping (%d): "
5032 "%d of %d CPUs online from %d possible CPUs\n",
5033 phba->cfg_fcp_cpu_map, num_online_cpus(),
5035 phba->sli4_hba.num_possible_cpu);
5039 while (phba->sli4_hba.curr_disp_cpu <
5040 phba->sli4_hba.num_possible_cpu) {
5041 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5043 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5044 len += scnprintf(buf + len, PAGE_SIZE - len,
5045 "CPU %02d not present\n",
5046 phba->sli4_hba.curr_disp_cpu);
5047 else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
5048 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5050 buf + len, PAGE_SIZE - len,
5051 "CPU %02d hdwq None "
5052 "physid %d coreid %d ht %d ua %d\n",
5053 phba->sli4_hba.curr_disp_cpu,
5054 cpup->phys_id, cpup->core_id,
5055 (cpup->flag & LPFC_CPU_MAP_HYPER),
5056 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5059 buf + len, PAGE_SIZE - len,
5060 "CPU %02d EQ None hdwq %04d "
5061 "physid %d coreid %d ht %d ua %d\n",
5062 phba->sli4_hba.curr_disp_cpu,
5063 cpup->hdwq, cpup->phys_id,
5065 (cpup->flag & LPFC_CPU_MAP_HYPER),
5066 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5068 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5070 buf + len, PAGE_SIZE - len,
5071 "CPU %02d hdwq None "
5072 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5073 phba->sli4_hba.curr_disp_cpu,
5076 (cpup->flag & LPFC_CPU_MAP_HYPER),
5077 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5078 lpfc_get_irq(cpup->eq));
5081 buf + len, PAGE_SIZE - len,
5082 "CPU %02d EQ %04d hdwq %04d "
5083 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5084 phba->sli4_hba.curr_disp_cpu,
5085 cpup->eq, cpup->hdwq, cpup->phys_id,
5087 (cpup->flag & LPFC_CPU_MAP_HYPER),
5088 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5089 lpfc_get_irq(cpup->eq));
5092 phba->sli4_hba.curr_disp_cpu++;
5094 /* display max number of CPUs keeping some margin */
5095 if (phba->sli4_hba.curr_disp_cpu <
5096 phba->sli4_hba.num_possible_cpu &&
5097 (len >= (PAGE_SIZE - 64))) {
5098 len += scnprintf(buf + len,
5099 PAGE_SIZE - len, "more...\n");
5104 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
5105 phba->sli4_hba.curr_disp_cpu = 0;
5111 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5112 * @dev: class device that is converted into a Scsi_host.
5113 * @attr: device attribute, not used.
5114 * @buf: one or more lpfc_polling_flags values.
5118 * -EINVAL - Not implemented yet.
5121 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5122 const char *buf, size_t count)
5128 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5131 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5132 # 0 - Do not affinitze IRQ vectors
5133 # 1 - Affintize HBA vectors with respect to each HBA
5134 # (start with CPU0 for each HBA)
5135 # This also defines how Hardware Queues are mapped to specific CPUs.
5137 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5138 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5139 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5140 "Defines how to map CPUs to IRQ vectors per HBA");
5143 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5144 * @phba: lpfc_hba pointer.
5145 * @val: link speed value.
5148 * If val is in a valid range [0-2], then affinitze the adapter's
5152 * zero if val saved.
5153 * -EINVAL val out of range
5156 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5158 if (phba->sli_rev != LPFC_SLI_REV4) {
5159 phba->cfg_fcp_cpu_map = 0;
5163 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5164 phba->cfg_fcp_cpu_map = val;
5168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5169 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5171 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5176 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5179 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5180 # Value range is [2,3]. Default value is 3.
5182 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5183 "Select Fibre Channel class of service for FCP sequences");
5186 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5187 # is [0,1]. Default value is 1.
5189 LPFC_VPORT_ATTR_RW(use_adisc, 1, 0, 1,
5190 "Use ADISC on rediscovery to authenticate FCP devices");
5193 # lpfc_first_burst_size: First burst size to use on the NPorts
5194 # that support first burst.
5195 # Value range is [0,65536]. Default value is 0.
5197 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5198 "First burst size for Targets that support first burst");
5201 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5202 * When the driver is configured as an NVME target, this value is
5203 * communicated to the NVME initiator in the PRLI response. It is
5204 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5205 * parameters are set and the target is sending the PRLI RSP.
5206 * Parameter supported on physical port only - no NPIV support.
5207 * Value range is [0,65536]. Default value is 0.
5209 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5210 "NVME Target mode first burst size in 512B increments.");
5213 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5214 * For the Initiator (I), enabling this parameter means that an NVMET
5215 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5216 * processed by the initiator for subsequent NVME FCP IO.
5217 * Currently, this feature is not supported on the NVME target
5218 * Value range is [0,1]. Default value is 0 (disabled).
5220 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5221 "Enable First Burst feature for NVME Initiator.");
5224 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5225 # depth. Default value is 0. When the value of this parameter is zero the
5226 # SCSI command completion time is not used for controlling I/O queue depth. When
5227 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5228 # to limit the I/O completion time to the parameter value.
5229 # The value is set in milliseconds.
5231 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5232 "Use command completion time to control queue depth");
5234 lpfc_vport_param_show(max_scsicmpl_time);
5236 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5238 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5239 struct lpfc_nodelist *ndlp, *next_ndlp;
5241 if (val == vport->cfg_max_scsicmpl_time)
5243 if ((val < 0) || (val > 60000))
5245 vport->cfg_max_scsicmpl_time = val;
5247 spin_lock_irq(shost->host_lock);
5248 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5249 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5251 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5253 spin_unlock_irq(shost->host_lock);
5256 lpfc_vport_param_store(max_scsicmpl_time);
5257 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5260 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5261 # range is [0,1]. Default value is 0.
5263 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5266 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5267 # range is [0,1]. Default value is 1.
5269 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5272 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5273 * range is [0,1]. Default value is 0.
5274 * For [0], FCP commands are issued to Work Queues based on upper layer
5275 * hardware queue index.
5276 * For [1], FCP commands are issued to a Work Queue associated with the
5279 * LPFC_FCP_SCHED_BY_HDWQ == 0
5280 * LPFC_FCP_SCHED_BY_CPU == 1
5282 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5283 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5284 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5285 * through WQs will be used.
5287 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5288 LPFC_FCP_SCHED_BY_HDWQ,
5289 LPFC_FCP_SCHED_BY_CPU,
5290 "Determine scheduling algorithm for "
5291 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5294 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5295 * range is [0,1]. Default value is 0.
5296 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5297 * For [1], GID_PT is used for NameServer queries after RSCN
5300 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5301 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5302 "Determine algorithm NameServer queries after RSCN "
5303 "[0] - GID_FT, [1] - GID_PT");
5306 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5307 # range is [0,1]. Default value is 0.
5308 # For [0], bus reset issues target reset to ALL devices
5309 # For [1], bus reset issues target reset to non-FCP2 devices
5311 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5312 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5316 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5317 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5318 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5319 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5320 # cr_delay is set to 0.
5322 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5323 "interrupt response is generated");
5325 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5326 "interrupt response is generated");
5329 # lpfc_multi_ring_support: Determines how many rings to spread available
5330 # cmd/rsp IOCB entries across.
5331 # Value range is [1,2]. Default value is 1.
5333 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5334 "SLI rings to spread IOCB entries across");
5337 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5338 # identifies what rctl value to configure the additional ring for.
5339 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5341 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5342 255, "Identifies RCTL for additional ring configuration");
5345 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5346 # identifies what type value to configure the additional ring for.
5347 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5349 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5350 255, "Identifies TYPE for additional ring configuration");
5353 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5354 # 0 = SmartSAN functionality disabled (default)
5355 # 1 = SmartSAN functionality enabled
5356 # This parameter will override the value of lpfc_fdmi_on module parameter.
5357 # Value range is [0,1]. Default value is 0.
5359 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5362 # lpfc_fdmi_on: Controls FDMI support.
5364 # 1 Traditional FDMI support (default)
5365 # Traditional FDMI support means the driver will assume FDMI-2 support;
5366 # however, if that fails, it will fallback to FDMI-1.
5367 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5368 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5370 # Value range [0,1]. Default value is 1.
5372 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5375 # Specifies the maximum number of ELS cmds we can have outstanding (for
5376 # discovery). Value range is [1,64]. Default value = 32.
5378 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5379 "during discovery");
5382 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5383 # will be scanned by the SCSI midlayer when sequential scanning is
5384 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5385 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5386 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5387 # above. The lpfc driver limits the default value to 255 for two reasons.
5388 # As it bounds the sequential scan loop, scanning for thousands of luns
5389 # on a target can take minutes of wall clock time. Additionally,
5390 # there are FC targets, such as JBODs, that only recognize 8-bits of
5391 # LUN ID. When they receive a value greater than 8 bits, they chop off
5392 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5393 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5394 # valid responses at each of the LUN IDs, to believe there are multiple
5395 # devices present, when in fact, there is only 1.
5396 # A customer that is aware of their target behaviors, and the results as
5397 # indicated above, is welcome to increase the lpfc_max_luns value.
5398 # As mentioned, this value is not used by the lpfc driver, only the
5400 # Value range is [0,65535]. Default value is 255.
5401 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5403 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5406 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5407 # Value range is [1,255], default value is 10.
5409 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5410 "Milliseconds driver will wait between polling FCP ring");
5413 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5414 # to complete in seconds. Value range is [5,180], default value is 60.
5416 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5417 "Maximum time to wait for task management commands to complete");
5419 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5420 # support this feature
5423 # 2 = MSI-X enabled (default)
5424 # Value range is [0,2]. Default value is 2.
5426 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5427 "MSI-X (2), if possible");
5430 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5432 * 0 = NVME OAS disabled
5433 * 1 = NVME OAS enabled
5435 * Value range is [0,1]. Default value is 0.
5437 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5438 "Use OAS bit on NVME IOs");
5441 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5443 * 0 = Put NVME Command in SGL
5444 * 1 = Embed NVME Command in WQE (unless G7)
5445 * 2 = Embed NVME Command in WQE (force)
5447 * Value range is [0,2]. Default value is 1.
5449 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5450 "Embed NVME Command in WQE");
5453 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5454 * the driver will advertise it supports to the SCSI layer.
5456 * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
5457 * 1,256 = Manually specify nr_hw_queue value to be advertised,
5459 * Value range is [0,256]. Default value is 8.
5461 LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5462 LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5463 "Set the number of SCSI Queues advertised");
5466 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5467 * will advertise it supports to the NVME and SCSI layers. This also
5468 * will map to the number of CQ/WQ pairs the driver will create.
5470 * The NVME Layer will try to create this many, plus 1 administrative
5471 * hardware queue. The administrative queue will always map to WQ 0
5472 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5474 * 0 = Configure the number of hdw queues to the number of active CPUs.
5475 * 1,256 = Manually specify how many hdw queues to use.
5477 * Value range is [0,256]. Default value is 0.
5479 LPFC_ATTR_R(hdw_queue,
5481 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5482 "Set the number of I/O Hardware Queues");
5484 #if IS_ENABLED(CONFIG_X86)
5486 * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
5488 * @phba: Pointer to HBA context object.
5491 lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)
5493 unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;
5494 const struct cpumask *sibling_mask;
5495 struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;
5497 cpumask_clear(aff_mask);
5499 if (phba->irq_chann_mode == NUMA_MODE) {
5500 /* Check if we're a NUMA architecture */
5501 numa_node = dev_to_node(&phba->pcidev->dev);
5502 if (numa_node == NUMA_NO_NODE) {
5503 phba->irq_chann_mode = NORMAL_MODE;
5508 for_each_possible_cpu(cpu) {
5509 switch (phba->irq_chann_mode) {
5511 if (cpu_to_node(cpu) == numa_node)
5512 cpumask_set_cpu(cpu, aff_mask);
5515 sibling_mask = topology_sibling_cpumask(cpu);
5516 first_cpu = cpumask_first(sibling_mask);
5517 if (first_cpu < nr_cpu_ids)
5518 cpumask_set_cpu(first_cpu, aff_mask);
5528 lpfc_assign_default_irq_chann(struct lpfc_hba *phba)
5530 #if IS_ENABLED(CONFIG_X86)
5531 switch (boot_cpu_data.x86_vendor) {
5532 case X86_VENDOR_AMD:
5533 /* If AMD architecture, then default is NUMA_MODE */
5534 phba->irq_chann_mode = NUMA_MODE;
5536 case X86_VENDOR_INTEL:
5537 /* If Intel architecture, then default is no hyperthread mode */
5538 phba->irq_chann_mode = NHT_MODE;
5541 phba->irq_chann_mode = NORMAL_MODE;
5544 lpfc_cpumask_irq_mode_init(phba);
5546 phba->irq_chann_mode = NORMAL_MODE;
5551 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5552 * for Hardware Queues to utilize. This also will map to the number
5553 * of EQ / MSI-X vectors the driver will create. This should never be
5554 * more than the number of Hardware Queues
5556 * 0 = Configure number of IRQ Channels to:
5557 * if AMD architecture, number of CPUs on HBA's NUMA node
5558 * if Intel architecture, number of physical CPUs.
5559 * otherwise, number of active CPUs.
5560 * [1,256] = Manually specify how many IRQ Channels to use.
5562 * Value range is [0,256]. Default value is [0].
5564 static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
5565 module_param(lpfc_irq_chann, uint, 0444);
5566 MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
5568 /* lpfc_irq_chann_init - Set the hba irq_chann initial value
5569 * @phba: lpfc_hba pointer.
5570 * @val: contains the initial value
5573 * Validates the initial value is within range and assigns it to the
5574 * adapter. If not in range, an error message is posted and the
5575 * default value is assigned.
5578 * zero if value is in range and is set
5579 * -EINVAL if value was out of range
5582 lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
5584 const struct cpumask *aff_mask;
5586 if (phba->cfg_use_msi != 2) {
5587 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5588 "8532 use_msi = %u ignoring cfg_irq_numa\n",
5590 phba->irq_chann_mode = NORMAL_MODE;
5591 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5595 /* Check if default setting was passed */
5596 if (val == LPFC_IRQ_CHANN_DEF &&
5597 phba->cfg_hdw_queue == LPFC_HBA_HDWQ_DEF &&
5598 phba->sli_rev == LPFC_SLI_REV4)
5599 lpfc_assign_default_irq_chann(phba);
5601 if (phba->irq_chann_mode != NORMAL_MODE) {
5602 aff_mask = &phba->sli4_hba.irq_aff_mask;
5604 if (cpumask_empty(aff_mask)) {
5605 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5606 "8533 Could not identify CPUS for "
5607 "mode %d, ignoring\n",
5608 phba->irq_chann_mode);
5609 phba->irq_chann_mode = NORMAL_MODE;
5610 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5612 phba->cfg_irq_chann = cpumask_weight(aff_mask);
5614 /* If no hyperthread mode, then set hdwq count to
5615 * aff_mask weight as well
5617 if (phba->irq_chann_mode == NHT_MODE)
5618 phba->cfg_hdw_queue = phba->cfg_irq_chann;
5620 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5621 "8543 lpfc_irq_chann set to %u "
5622 "(mode: %d)\n", phba->cfg_irq_chann,
5623 phba->irq_chann_mode);
5626 if (val > LPFC_IRQ_CHANN_MAX) {
5627 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5628 "8545 lpfc_irq_chann attribute cannot "
5629 "be set to %u, allowed range is "
5633 LPFC_IRQ_CHANN_MAX);
5634 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5637 if (phba->sli_rev == LPFC_SLI_REV4) {
5638 phba->cfg_irq_chann = val;
5640 phba->cfg_irq_chann = 2;
5641 phba->cfg_hdw_queue = 1;
5649 * lpfc_irq_chann_show - Display value of irq_chann
5650 * @dev: class converted to a Scsi_host structure.
5651 * @attr: device attribute, not used.
5652 * @buf: on return contains a string with the list sizes
5654 * Returns: size of formatted string.
5657 lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
5660 struct Scsi_Host *shost = class_to_shost(dev);
5661 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5662 struct lpfc_hba *phba = vport->phba;
5664 return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
5667 static DEVICE_ATTR_RO(lpfc_irq_chann);
5670 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5671 # 0 = HBA resets disabled
5672 # 1 = HBA resets enabled (default)
5673 # 2 = HBA reset via PCI bus reset enabled
5674 # Value range is [0,2]. Default value is 1.
5676 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5679 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5680 # 0 = HBA Heartbeat disabled
5681 # 1 = HBA Heartbeat enabled (default)
5682 # Value range is [0,1]. Default value is 1.
5684 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5687 # lpfc_EnableXLane: Enable Express Lane Feature
5688 # 0x0 Express Lane Feature disabled
5689 # 0x1 Express Lane Feature enabled
5690 # Value range is [0,1]. Default value is 0.
5692 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5695 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5696 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5697 # Value range is [0x0,0x7f]. Default value is 0
5699 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5702 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5703 # 0 = BlockGuard disabled (default)
5704 # 1 = BlockGuard enabled
5705 # Value range is [0,1]. Default value is 0.
5707 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5711 # - Bit mask of host protection capabilities used to register with the
5713 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5714 # - Allows you to ultimately specify which profiles to use
5715 # - Default will result in registering capabilities for all profiles.
5716 # - SHOST_DIF_TYPE1_PROTECTION 1
5717 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5718 # - SHOST_DIX_TYPE0_PROTECTION 8
5719 # HBA supports DIX Type 0: Host to HBA protection only
5720 # - SHOST_DIX_TYPE1_PROTECTION 16
5721 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5724 LPFC_ATTR(prot_mask,
5725 (SHOST_DIF_TYPE1_PROTECTION |
5726 SHOST_DIX_TYPE0_PROTECTION |
5727 SHOST_DIX_TYPE1_PROTECTION),
5729 (SHOST_DIF_TYPE1_PROTECTION |
5730 SHOST_DIX_TYPE0_PROTECTION |
5731 SHOST_DIX_TYPE1_PROTECTION),
5732 "T10-DIF host protection capabilities mask");
5736 # - Bit mask of protection guard types to register with the SCSI mid-layer
5737 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5738 # - Allows you to ultimately specify which profiles to use
5739 # - Default will result in registering capabilities for all guard types
5742 LPFC_ATTR(prot_guard,
5743 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5744 "T10-DIF host protection guard type");
5747 * Delay initial NPort discovery when Clean Address bit is cleared in
5748 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5749 * This parameter can have value 0 or 1.
5750 * When this parameter is set to 0, no delay is added to the initial
5752 * When this parameter is set to non-zero value, initial Nport discovery is
5753 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5754 * accept and FCID/Fabric name/Fabric portname is changed.
5755 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5756 * when Clean Address bit is cleared in FLOGI/FDISC
5757 * accept and FCID/Fabric name/Fabric portname is changed.
5758 * Default value is 0.
5760 LPFC_ATTR(delay_discovery, 0, 0, 1,
5761 "Delay NPort discovery when Clean Address bit is cleared.");
5764 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5765 * This value can be set to values between 64 and 4096. The default value
5766 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5767 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5768 * Because of the additional overhead involved in setting up T10-DIF,
5769 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5770 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5772 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5773 module_param(lpfc_sg_seg_cnt, uint, 0444);
5774 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5777 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5778 * configured for the adapter
5779 * @dev: class converted to a Scsi_host structure.
5780 * @attr: device attribute, not used.
5781 * @buf: on return contains a string with the list sizes
5783 * Returns: size of formatted string.
5786 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5789 struct Scsi_Host *shost = class_to_shost(dev);
5790 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5791 struct lpfc_hba *phba = vport->phba;
5794 len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
5795 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5797 len += scnprintf(buf + len, PAGE_SIZE - len,
5798 "Cfg: %d SCSI: %d NVME: %d\n",
5799 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5800 phba->cfg_nvme_seg_cnt);
5804 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5807 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5808 * @phba: lpfc_hba pointer.
5809 * @val: contains the initial value
5812 * Validates the initial value is within range and assigns it to the
5813 * adapter. If not in range, an error message is posted and the
5814 * default value is assigned.
5817 * zero if value is in range and is set
5818 * -EINVAL if value was out of range
5821 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5823 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5824 phba->cfg_sg_seg_cnt = val;
5827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5828 "0409 lpfc_sg_seg_cnt attribute cannot be set to %d, "
5829 "allowed range is [%d, %d]\n",
5830 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5831 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5836 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5837 * 0 = MDS Diagnostics disabled (default)
5838 * 1 = MDS Diagnostics enabled
5839 * Value range is [0,1]. Default value is 0.
5841 LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5844 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5845 * 0 = Disable firmware logging (default)
5846 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
5847 * Value range [0..4]. Default value is 0
5849 LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5850 lpfc_param_show(ras_fwlog_buffsize);
5853 lpfc_ras_fwlog_buffsize_set(struct lpfc_hba *phba, uint val)
5856 enum ras_state state;
5858 if (!lpfc_rangecheck(val, 0, 4))
5861 if (phba->cfg_ras_fwlog_buffsize == val)
5864 if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
5867 spin_lock_irq(&phba->hbalock);
5868 state = phba->ras_fwlog.state;
5869 spin_unlock_irq(&phba->hbalock);
5871 if (state == REG_INPROGRESS) {
5872 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
5873 "registration is in progress\n");
5877 /* For disable logging: stop the logs and free the DMA.
5878 * For ras_fwlog_buffsize size change we still need to free and
5879 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
5881 phba->cfg_ras_fwlog_buffsize = val;
5882 if (state == ACTIVE) {
5883 lpfc_ras_stop_fwlog(phba);
5884 lpfc_sli4_ras_dma_free(phba);
5887 lpfc_sli4_ras_init(phba);
5888 if (phba->ras_fwlog.ras_enabled)
5889 ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
5890 LPFC_RAS_ENABLE_LOGGING);
5894 lpfc_param_store(ras_fwlog_buffsize);
5895 static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
5898 * lpfc_ras_fwlog_level: Firmware logging verbosity level
5899 * Valid only if firmware logging is enabled
5900 * 0(Least Verbosity) 4 (most verbosity)
5901 * Value range is [0..4]. Default value is 0
5903 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5906 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5907 * Default function which has RAS support : 0
5908 * Value Range is [0..7].
5909 * FW logging is a global action and enablement is via a specific
5912 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
5915 * lpfc_enable_bbcr: Enable BB Credit Recovery
5916 * 0 = BB Credit Recovery disabled
5917 * 1 = BB Credit Recovery enabled (default)
5918 * Value range is [0,1]. Default value is 1.
5920 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5922 /* Signaling module parameters */
5923 int lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
5924 module_param(lpfc_fabric_cgn_frequency, int, 0444);
5925 MODULE_PARM_DESC(lpfc_fabric_cgn_frequency, "Congestion signaling fabric freq");
5927 unsigned char lpfc_acqe_cgn_frequency = 10; /* 10 sec default */
5928 module_param(lpfc_acqe_cgn_frequency, byte, 0444);
5929 MODULE_PARM_DESC(lpfc_acqe_cgn_frequency, "Congestion signaling ACQE freq");
5931 int lpfc_use_cgn_signal = 1; /* 0 - only use FPINs, 1 - Use signals if avail */
5932 module_param(lpfc_use_cgn_signal, int, 0444);
5933 MODULE_PARM_DESC(lpfc_use_cgn_signal, "Use Congestion signaling if available");
5936 * lpfc_enable_dpp: Enable DPP on G7
5937 * 0 = DPP on G7 disabled
5938 * 1 = DPP on G7 enabled (default)
5939 * Value range is [0,1]. Default value is 1.
5941 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5944 * lpfc_enable_mi: Enable FDMI MIB
5946 * 1 = enabled (default)
5947 * Value range is [0,1].
5949 LPFC_ATTR_R(enable_mi, 1, 0, 1, "Enable MI");
5952 * lpfc_max_vmid: Maximum number of VMs to be tagged. This is valid only if
5953 * either vmid_app_header or vmid_priority_tagging is enabled.
5954 * 4 - 255 = vmid support enabled for 4-255 VMs
5955 * Value range is [4,255].
5957 LPFC_ATTR_RW(max_vmid, LPFC_MIN_VMID, LPFC_MIN_VMID, LPFC_MAX_VMID,
5958 "Maximum number of VMs supported");
5961 * lpfc_vmid_inactivity_timeout: Inactivity timeout duration in hours
5962 * 0 = Timeout is disabled
5963 * Value range is [0,24].
5965 LPFC_ATTR_RW(vmid_inactivity_timeout, 4, 0, 24,
5966 "Inactivity timeout in hours");
5969 * lpfc_vmid_app_header: Enable App Header VMID support
5970 * 0 = Support is disabled (default)
5971 * 1 = Support is enabled
5972 * Value range is [0,1].
5974 LPFC_ATTR_RW(vmid_app_header, LPFC_VMID_APP_HEADER_DISABLE,
5975 LPFC_VMID_APP_HEADER_DISABLE, LPFC_VMID_APP_HEADER_ENABLE,
5976 "Enable App Header VMID support");
5979 * lpfc_vmid_priority_tagging: Enable Priority Tagging VMID support
5980 * 0 = Support is disabled (default)
5981 * 1 = Allow supported targets only
5982 * 2 = Allow all targets
5983 * Value range is [0,2].
5985 LPFC_ATTR_RW(vmid_priority_tagging, LPFC_VMID_PRIO_TAG_DISABLE,
5986 LPFC_VMID_PRIO_TAG_DISABLE,
5987 LPFC_VMID_PRIO_TAG_ALL_TARGETS,
5988 "Enable Priority Tagging VMID support");
5990 static struct attribute *lpfc_hba_attrs[] = {
5991 &dev_attr_nvme_info.attr,
5992 &dev_attr_scsi_stat.attr,
5993 &dev_attr_bg_info.attr,
5994 &dev_attr_bg_guard_err.attr,
5995 &dev_attr_bg_apptag_err.attr,
5996 &dev_attr_bg_reftag_err.attr,
5997 &dev_attr_info.attr,
5998 &dev_attr_serialnum.attr,
5999 &dev_attr_modeldesc.attr,
6000 &dev_attr_modelname.attr,
6001 &dev_attr_programtype.attr,
6002 &dev_attr_portnum.attr,
6003 &dev_attr_fwrev.attr,
6005 &dev_attr_option_rom_version.attr,
6006 &dev_attr_link_state.attr,
6007 &dev_attr_num_discovered_ports.attr,
6008 &dev_attr_lpfc_drvr_version.attr,
6009 &dev_attr_lpfc_enable_fip.attr,
6010 &dev_attr_lpfc_temp_sensor.attr,
6011 &dev_attr_lpfc_log_verbose.attr,
6012 &dev_attr_lpfc_lun_queue_depth.attr,
6013 &dev_attr_lpfc_tgt_queue_depth.attr,
6014 &dev_attr_lpfc_hba_queue_depth.attr,
6015 &dev_attr_lpfc_peer_port_login.attr,
6016 &dev_attr_lpfc_nodev_tmo.attr,
6017 &dev_attr_lpfc_devloss_tmo.attr,
6018 &dev_attr_lpfc_enable_fc4_type.attr,
6019 &dev_attr_lpfc_fcp_class.attr,
6020 &dev_attr_lpfc_use_adisc.attr,
6021 &dev_attr_lpfc_first_burst_size.attr,
6022 &dev_attr_lpfc_ack0.attr,
6023 &dev_attr_lpfc_xri_rebalancing.attr,
6024 &dev_attr_lpfc_topology.attr,
6025 &dev_attr_lpfc_scan_down.attr,
6026 &dev_attr_lpfc_link_speed.attr,
6027 &dev_attr_lpfc_fcp_io_sched.attr,
6028 &dev_attr_lpfc_ns_query.attr,
6029 &dev_attr_lpfc_fcp2_no_tgt_reset.attr,
6030 &dev_attr_lpfc_cr_delay.attr,
6031 &dev_attr_lpfc_cr_count.attr,
6032 &dev_attr_lpfc_multi_ring_support.attr,
6033 &dev_attr_lpfc_multi_ring_rctl.attr,
6034 &dev_attr_lpfc_multi_ring_type.attr,
6035 &dev_attr_lpfc_fdmi_on.attr,
6036 &dev_attr_lpfc_enable_SmartSAN.attr,
6037 &dev_attr_lpfc_max_luns.attr,
6038 &dev_attr_lpfc_enable_npiv.attr,
6039 &dev_attr_lpfc_fcf_failover_policy.attr,
6040 &dev_attr_lpfc_enable_rrq.attr,
6041 &dev_attr_lpfc_fcp_wait_abts_rsp.attr,
6042 &dev_attr_nport_evt_cnt.attr,
6043 &dev_attr_board_mode.attr,
6044 &dev_attr_lpfc_xcvr_data.attr,
6045 &dev_attr_max_vpi.attr,
6046 &dev_attr_used_vpi.attr,
6047 &dev_attr_max_rpi.attr,
6048 &dev_attr_used_rpi.attr,
6049 &dev_attr_max_xri.attr,
6050 &dev_attr_used_xri.attr,
6051 &dev_attr_npiv_info.attr,
6052 &dev_attr_issue_reset.attr,
6053 &dev_attr_lpfc_poll.attr,
6054 &dev_attr_lpfc_poll_tmo.attr,
6055 &dev_attr_lpfc_task_mgmt_tmo.attr,
6056 &dev_attr_lpfc_use_msi.attr,
6057 &dev_attr_lpfc_nvme_oas.attr,
6058 &dev_attr_lpfc_nvme_embed_cmd.attr,
6059 &dev_attr_lpfc_fcp_imax.attr,
6060 &dev_attr_lpfc_force_rscn.attr,
6061 &dev_attr_lpfc_cq_poll_threshold.attr,
6062 &dev_attr_lpfc_cq_max_proc_limit.attr,
6063 &dev_attr_lpfc_fcp_cpu_map.attr,
6064 &dev_attr_lpfc_fcp_mq_threshold.attr,
6065 &dev_attr_lpfc_hdw_queue.attr,
6066 &dev_attr_lpfc_irq_chann.attr,
6067 &dev_attr_lpfc_suppress_rsp.attr,
6068 &dev_attr_lpfc_nvmet_mrq.attr,
6069 &dev_attr_lpfc_nvmet_mrq_post.attr,
6070 &dev_attr_lpfc_nvme_enable_fb.attr,
6071 &dev_attr_lpfc_nvmet_fb_size.attr,
6072 &dev_attr_lpfc_enable_bg.attr,
6073 &dev_attr_lpfc_enable_hba_reset.attr,
6074 &dev_attr_lpfc_enable_hba_heartbeat.attr,
6075 &dev_attr_lpfc_EnableXLane.attr,
6076 &dev_attr_lpfc_XLanePriority.attr,
6077 &dev_attr_lpfc_xlane_lun.attr,
6078 &dev_attr_lpfc_xlane_tgt.attr,
6079 &dev_attr_lpfc_xlane_vpt.attr,
6080 &dev_attr_lpfc_xlane_lun_state.attr,
6081 &dev_attr_lpfc_xlane_lun_status.attr,
6082 &dev_attr_lpfc_xlane_priority.attr,
6083 &dev_attr_lpfc_sg_seg_cnt.attr,
6084 &dev_attr_lpfc_max_scsicmpl_time.attr,
6085 &dev_attr_lpfc_aer_support.attr,
6086 &dev_attr_lpfc_aer_state_cleanup.attr,
6087 &dev_attr_lpfc_sriov_nr_virtfn.attr,
6088 &dev_attr_lpfc_req_fw_upgrade.attr,
6089 &dev_attr_lpfc_suppress_link_up.attr,
6090 &dev_attr_iocb_hw.attr,
6093 &dev_attr_txq_hw.attr,
6094 &dev_attr_txcmplq_hw.attr,
6095 &dev_attr_lpfc_sriov_hw_max_virtfn.attr,
6096 &dev_attr_protocol.attr,
6097 &dev_attr_lpfc_xlane_supported.attr,
6098 &dev_attr_lpfc_enable_mds_diags.attr,
6099 &dev_attr_lpfc_ras_fwlog_buffsize.attr,
6100 &dev_attr_lpfc_ras_fwlog_level.attr,
6101 &dev_attr_lpfc_ras_fwlog_func.attr,
6102 &dev_attr_lpfc_enable_bbcr.attr,
6103 &dev_attr_lpfc_enable_dpp.attr,
6104 &dev_attr_lpfc_enable_mi.attr,
6105 &dev_attr_cmf_info.attr,
6106 &dev_attr_lpfc_max_vmid.attr,
6107 &dev_attr_lpfc_vmid_inactivity_timeout.attr,
6108 &dev_attr_lpfc_vmid_app_header.attr,
6109 &dev_attr_lpfc_vmid_priority_tagging.attr,
6113 static const struct attribute_group lpfc_hba_attr_group = {
6114 .attrs = lpfc_hba_attrs
6117 const struct attribute_group *lpfc_hba_groups[] = {
6118 &lpfc_hba_attr_group,
6122 static struct attribute *lpfc_vport_attrs[] = {
6123 &dev_attr_info.attr,
6124 &dev_attr_link_state.attr,
6125 &dev_attr_num_discovered_ports.attr,
6126 &dev_attr_lpfc_drvr_version.attr,
6127 &dev_attr_lpfc_log_verbose.attr,
6128 &dev_attr_lpfc_lun_queue_depth.attr,
6129 &dev_attr_lpfc_tgt_queue_depth.attr,
6130 &dev_attr_lpfc_nodev_tmo.attr,
6131 &dev_attr_lpfc_devloss_tmo.attr,
6132 &dev_attr_lpfc_hba_queue_depth.attr,
6133 &dev_attr_lpfc_peer_port_login.attr,
6134 &dev_attr_lpfc_restrict_login.attr,
6135 &dev_attr_lpfc_fcp_class.attr,
6136 &dev_attr_lpfc_use_adisc.attr,
6137 &dev_attr_lpfc_first_burst_size.attr,
6138 &dev_attr_lpfc_max_luns.attr,
6139 &dev_attr_nport_evt_cnt.attr,
6140 &dev_attr_npiv_info.attr,
6141 &dev_attr_lpfc_enable_da_id.attr,
6142 &dev_attr_lpfc_max_scsicmpl_time.attr,
6143 &dev_attr_lpfc_static_vport.attr,
6144 &dev_attr_cmf_info.attr,
6148 static const struct attribute_group lpfc_vport_attr_group = {
6149 .attrs = lpfc_vport_attrs
6152 const struct attribute_group *lpfc_vport_groups[] = {
6153 &lpfc_vport_attr_group,
6158 * sysfs_ctlreg_write - Write method for writing to ctlreg
6159 * @filp: open sysfs file
6160 * @kobj: kernel kobject that contains the kernel class device.
6161 * @bin_attr: kernel attributes passed to us.
6162 * @buf: contains the data to be written to the adapter IOREG space.
6163 * @off: offset into buffer to beginning of data.
6164 * @count: bytes to transfer.
6167 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6168 * Uses the adapter io control registers to send buf contents to the adapter.
6171 * -ERANGE off and count combo out of range
6172 * -EINVAL off, count or buff address invalid
6173 * -EPERM adapter is offline
6174 * value of count, buf contents written
6177 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6178 struct bin_attribute *bin_attr,
6179 char *buf, loff_t off, size_t count)
6182 struct device *dev = container_of(kobj, struct device, kobj);
6183 struct Scsi_Host *shost = class_to_shost(dev);
6184 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6185 struct lpfc_hba *phba = vport->phba;
6187 if (phba->sli_rev >= LPFC_SLI_REV4)
6190 if ((off + count) > FF_REG_AREA_SIZE)
6193 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6196 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6199 /* This is to protect HBA registers from accidental writes. */
6200 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6203 if (!(vport->fc_flag & FC_OFFLINE_MODE))
6206 spin_lock_irq(&phba->hbalock);
6207 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6208 buf_off += sizeof(uint32_t))
6209 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6210 phba->ctrl_regs_memmap_p + off + buf_off);
6212 spin_unlock_irq(&phba->hbalock);
6218 * sysfs_ctlreg_read - Read method for reading from ctlreg
6219 * @filp: open sysfs file
6220 * @kobj: kernel kobject that contains the kernel class device.
6221 * @bin_attr: kernel attributes passed to us.
6222 * @buf: if successful contains the data from the adapter IOREG space.
6223 * @off: offset into buffer to beginning of data.
6224 * @count: bytes to transfer.
6227 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6228 * Uses the adapter io control registers to read data into buf.
6231 * -ERANGE off and count combo out of range
6232 * -EINVAL off, count or buff address invalid
6233 * value of count, buf contents read
6236 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6237 struct bin_attribute *bin_attr,
6238 char *buf, loff_t off, size_t count)
6242 struct device *dev = container_of(kobj, struct device, kobj);
6243 struct Scsi_Host *shost = class_to_shost(dev);
6244 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6245 struct lpfc_hba *phba = vport->phba;
6247 if (phba->sli_rev >= LPFC_SLI_REV4)
6250 if (off > FF_REG_AREA_SIZE)
6253 if ((off + count) > FF_REG_AREA_SIZE)
6254 count = FF_REG_AREA_SIZE - off;
6256 if (count == 0) return 0;
6258 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6261 spin_lock_irq(&phba->hbalock);
6263 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6264 tmp_ptr = (uint32_t *)(buf + buf_off);
6265 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6268 spin_unlock_irq(&phba->hbalock);
6273 static struct bin_attribute sysfs_ctlreg_attr = {
6276 .mode = S_IRUSR | S_IWUSR,
6279 .read = sysfs_ctlreg_read,
6280 .write = sysfs_ctlreg_write,
6284 * sysfs_mbox_write - Write method for writing information via mbox
6285 * @filp: open sysfs file
6286 * @kobj: kernel kobject that contains the kernel class device.
6287 * @bin_attr: kernel attributes passed to us.
6288 * @buf: contains the data to be written to sysfs mbox.
6289 * @off: offset into buffer to beginning of data.
6290 * @count: bytes to transfer.
6293 * Deprecated function. All mailbox access from user space is performed via the
6297 * -EPERM operation not permitted
6300 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6301 struct bin_attribute *bin_attr,
6302 char *buf, loff_t off, size_t count)
6308 * sysfs_mbox_read - Read method for reading information via mbox
6309 * @filp: open sysfs file
6310 * @kobj: kernel kobject that contains the kernel class device.
6311 * @bin_attr: kernel attributes passed to us.
6312 * @buf: contains the data to be read from sysfs mbox.
6313 * @off: offset into buffer to beginning of data.
6314 * @count: bytes to transfer.
6317 * Deprecated function. All mailbox access from user space is performed via the
6321 * -EPERM operation not permitted
6324 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6325 struct bin_attribute *bin_attr,
6326 char *buf, loff_t off, size_t count)
6331 static struct bin_attribute sysfs_mbox_attr = {
6334 .mode = S_IRUSR | S_IWUSR,
6336 .size = MAILBOX_SYSFS_MAX,
6337 .read = sysfs_mbox_read,
6338 .write = sysfs_mbox_write,
6342 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6343 * @vport: address of lpfc vport structure.
6347 * error return code from sysfs_create_bin_file()
6350 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6352 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6355 /* Virtual ports do not need ctrl_reg and mbox */
6356 if (vport->port_type == LPFC_NPIV_PORT)
6359 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6360 &sysfs_ctlreg_attr);
6364 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6367 goto out_remove_ctlreg_attr;
6370 out_remove_ctlreg_attr:
6371 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6377 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6378 * @vport: address of lpfc vport structure.
6381 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6383 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6385 /* Virtual ports do not need ctrl_reg and mbox */
6386 if (vport->port_type == LPFC_NPIV_PORT)
6388 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6389 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6393 * Dynamic FC Host Attributes Support
6397 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6398 * @shost: kernel scsi host pointer.
6401 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6403 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6405 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6406 sizeof fc_host_symbolic_name(shost));
6410 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6411 * @shost: kernel scsi host pointer.
6414 lpfc_get_host_port_id(struct Scsi_Host *shost)
6416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6418 /* note: fc_myDID already in cpu endianness */
6419 fc_host_port_id(shost) = vport->fc_myDID;
6423 * lpfc_get_host_port_type - Set the value of the scsi host port type
6424 * @shost: kernel scsi host pointer.
6427 lpfc_get_host_port_type(struct Scsi_Host *shost)
6429 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6430 struct lpfc_hba *phba = vport->phba;
6432 spin_lock_irq(shost->host_lock);
6434 if (vport->port_type == LPFC_NPIV_PORT) {
6435 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6436 } else if (lpfc_is_link_up(phba)) {
6437 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6438 if (vport->fc_flag & FC_PUBLIC_LOOP)
6439 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6441 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6443 if (vport->fc_flag & FC_FABRIC)
6444 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6446 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6449 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6451 spin_unlock_irq(shost->host_lock);
6455 * lpfc_get_host_port_state - Set the value of the scsi host port state
6456 * @shost: kernel scsi host pointer.
6459 lpfc_get_host_port_state(struct Scsi_Host *shost)
6461 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6462 struct lpfc_hba *phba = vport->phba;
6464 spin_lock_irq(shost->host_lock);
6466 if (vport->fc_flag & FC_OFFLINE_MODE)
6467 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6469 switch (phba->link_state) {
6470 case LPFC_LINK_UNKNOWN:
6471 case LPFC_LINK_DOWN:
6472 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6476 case LPFC_HBA_READY:
6477 /* Links up, reports port state accordingly */
6478 if (vport->port_state < LPFC_VPORT_READY)
6479 fc_host_port_state(shost) =
6480 FC_PORTSTATE_BYPASSED;
6482 fc_host_port_state(shost) =
6483 FC_PORTSTATE_ONLINE;
6485 case LPFC_HBA_ERROR:
6486 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6489 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6494 spin_unlock_irq(shost->host_lock);
6498 * lpfc_get_host_speed - Set the value of the scsi host speed
6499 * @shost: kernel scsi host pointer.
6502 lpfc_get_host_speed(struct Scsi_Host *shost)
6504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6505 struct lpfc_hba *phba = vport->phba;
6507 spin_lock_irq(shost->host_lock);
6509 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
6510 switch(phba->fc_linkspeed) {
6511 case LPFC_LINK_SPEED_1GHZ:
6512 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6514 case LPFC_LINK_SPEED_2GHZ:
6515 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6517 case LPFC_LINK_SPEED_4GHZ:
6518 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6520 case LPFC_LINK_SPEED_8GHZ:
6521 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6523 case LPFC_LINK_SPEED_10GHZ:
6524 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6526 case LPFC_LINK_SPEED_16GHZ:
6527 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6529 case LPFC_LINK_SPEED_32GHZ:
6530 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6532 case LPFC_LINK_SPEED_64GHZ:
6533 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6535 case LPFC_LINK_SPEED_128GHZ:
6536 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6538 case LPFC_LINK_SPEED_256GHZ:
6539 fc_host_speed(shost) = FC_PORTSPEED_256GBIT;
6542 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6545 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6546 switch (phba->fc_linkspeed) {
6547 case LPFC_ASYNC_LINK_SPEED_1GBPS:
6548 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6550 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6551 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6553 case LPFC_ASYNC_LINK_SPEED_20GBPS:
6554 fc_host_speed(shost) = FC_PORTSPEED_20GBIT;
6556 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6557 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6559 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6560 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6562 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6563 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6566 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6570 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6572 spin_unlock_irq(shost->host_lock);
6576 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6577 * @shost: kernel scsi host pointer.
6580 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6582 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6583 struct lpfc_hba *phba = vport->phba;
6586 spin_lock_irq(shost->host_lock);
6588 if ((vport->port_state > LPFC_FLOGI) &&
6589 ((vport->fc_flag & FC_FABRIC) ||
6590 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6591 (vport->fc_flag & FC_PUBLIC_LOOP))))
6592 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6594 /* fabric is local port if there is no F/FL_Port */
6597 spin_unlock_irq(shost->host_lock);
6599 fc_host_fabric_name(shost) = node_name;
6603 * lpfc_get_stats - Return statistical information about the adapter
6604 * @shost: kernel scsi host pointer.
6607 * NULL on error for link down, no mbox pool, sli2 active,
6608 * management not allowed, memory allocation error, or mbox error.
6612 * address of the adapter host statistics
6614 static struct fc_host_statistics *
6615 lpfc_get_stats(struct Scsi_Host *shost)
6617 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6618 struct lpfc_hba *phba = vport->phba;
6619 struct lpfc_sli *psli = &phba->sli;
6620 struct fc_host_statistics *hs = &phba->link_stats;
6621 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6622 LPFC_MBOXQ_t *pmboxq;
6627 * prevent udev from issuing mailbox commands until the port is
6630 if (phba->link_state < LPFC_LINK_DOWN ||
6631 !phba->mbox_mem_pool ||
6632 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6635 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6638 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6641 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6643 pmb = &pmboxq->u.mb;
6644 pmb->mbxCommand = MBX_READ_STATUS;
6645 pmb->mbxOwner = OWN_HOST;
6646 pmboxq->ctx_buf = NULL;
6647 pmboxq->vport = vport;
6649 if (vport->fc_flag & FC_OFFLINE_MODE) {
6650 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6651 if (rc != MBX_SUCCESS) {
6652 mempool_free(pmboxq, phba->mbox_mem_pool);
6656 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6657 if (rc != MBX_SUCCESS) {
6658 if (rc != MBX_TIMEOUT)
6659 mempool_free(pmboxq, phba->mbox_mem_pool);
6664 memset(hs, 0, sizeof (struct fc_host_statistics));
6666 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6667 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6670 * The MBX_READ_STATUS returns tx_k_bytes which has to be
6671 * converted to words.
6673 * Check if extended byte flag is set, to know when to collect upper
6674 * bits of 64 bit wide statistics counter.
6676 if (pmb->un.varRdStatus.xkb & RD_ST_XKB) {
6677 hs->tx_words = (u64)
6678 ((((u64)(pmb->un.varRdStatus.xmit_xkb &
6679 RD_ST_XMIT_XKB_MASK) << 32) |
6680 (u64)pmb->un.varRdStatus.xmitByteCnt) *
6682 hs->rx_words = (u64)
6683 ((((u64)(pmb->un.varRdStatus.rcv_xkb &
6684 RD_ST_RCV_XKB_MASK) << 32) |
6685 (u64)pmb->un.varRdStatus.rcvByteCnt) *
6688 hs->tx_words = (uint64_t)
6689 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6691 hs->rx_words = (uint64_t)
6692 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6696 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6697 pmb->mbxCommand = MBX_READ_LNK_STAT;
6698 pmb->mbxOwner = OWN_HOST;
6699 pmboxq->ctx_buf = NULL;
6700 pmboxq->vport = vport;
6702 if (vport->fc_flag & FC_OFFLINE_MODE) {
6703 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6704 if (rc != MBX_SUCCESS) {
6705 mempool_free(pmboxq, phba->mbox_mem_pool);
6709 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6710 if (rc != MBX_SUCCESS) {
6711 if (rc != MBX_TIMEOUT)
6712 mempool_free(pmboxq, phba->mbox_mem_pool);
6717 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6718 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6719 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6720 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6721 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6722 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6723 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6725 hs->cn_sig_warn = atomic64_read(&phba->cgn_acqe_stat.warn);
6726 hs->cn_sig_alarm = atomic64_read(&phba->cgn_acqe_stat.alarm);
6728 hs->link_failure_count -= lso->link_failure_count;
6729 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6730 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6731 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6732 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6733 hs->invalid_crc_count -= lso->invalid_crc_count;
6734 hs->error_frames -= lso->error_frames;
6736 if (phba->hba_flag & HBA_FCOE_MODE) {
6738 hs->nos_count = (phba->link_events >> 1);
6739 hs->nos_count -= lso->link_events;
6740 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6741 hs->lip_count = (phba->fc_eventTag >> 1);
6742 hs->lip_count -= lso->link_events;
6746 hs->nos_count = (phba->fc_eventTag >> 1);
6747 hs->nos_count -= lso->link_events;
6750 hs->dumped_frames = -1;
6752 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6754 mempool_free(pmboxq, phba->mbox_mem_pool);
6760 * lpfc_reset_stats - Copy the adapter link stats information
6761 * @shost: kernel scsi host pointer.
6764 lpfc_reset_stats(struct Scsi_Host *shost)
6766 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6767 struct lpfc_hba *phba = vport->phba;
6768 struct lpfc_sli *psli = &phba->sli;
6769 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6770 LPFC_MBOXQ_t *pmboxq;
6774 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6777 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6780 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6782 pmb = &pmboxq->u.mb;
6783 pmb->mbxCommand = MBX_READ_STATUS;
6784 pmb->mbxOwner = OWN_HOST;
6785 pmb->un.varWords[0] = 0x1; /* reset request */
6786 pmboxq->ctx_buf = NULL;
6787 pmboxq->vport = vport;
6789 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6790 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6791 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6792 if (rc != MBX_SUCCESS) {
6793 mempool_free(pmboxq, phba->mbox_mem_pool);
6797 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6798 if (rc != MBX_SUCCESS) {
6799 if (rc != MBX_TIMEOUT)
6800 mempool_free(pmboxq, phba->mbox_mem_pool);
6805 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6806 pmb->mbxCommand = MBX_READ_LNK_STAT;
6807 pmb->mbxOwner = OWN_HOST;
6808 pmboxq->ctx_buf = NULL;
6809 pmboxq->vport = vport;
6811 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6812 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6813 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6814 if (rc != MBX_SUCCESS) {
6815 mempool_free(pmboxq, phba->mbox_mem_pool);
6819 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6820 if (rc != MBX_SUCCESS) {
6821 if (rc != MBX_TIMEOUT)
6822 mempool_free(pmboxq, phba->mbox_mem_pool);
6827 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6828 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6829 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6830 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6831 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6832 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6833 lso->error_frames = pmb->un.varRdLnk.crcCnt;
6834 if (phba->hba_flag & HBA_FCOE_MODE)
6835 lso->link_events = (phba->link_events >> 1);
6837 lso->link_events = (phba->fc_eventTag >> 1);
6839 atomic64_set(&phba->cgn_acqe_stat.warn, 0);
6840 atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
6842 memset(&shost_to_fc_host(shost)->fpin_stats, 0,
6843 sizeof(shost_to_fc_host(shost)->fpin_stats));
6845 psli->stats_start = ktime_get_seconds();
6847 mempool_free(pmboxq, phba->mbox_mem_pool);
6853 * The LPFC driver treats linkdown handling as target loss events so there
6854 * are no sysfs handlers for link_down_tmo.
6858 * lpfc_get_node_by_target - Return the nodelist for a target
6859 * @starget: kernel scsi target pointer.
6862 * address of the node list if found
6863 * NULL target not found
6865 static struct lpfc_nodelist *
6866 lpfc_get_node_by_target(struct scsi_target *starget)
6868 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6869 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6870 struct lpfc_nodelist *ndlp;
6872 spin_lock_irq(shost->host_lock);
6873 /* Search for this, mapped, target ID */
6874 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6875 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6876 starget->id == ndlp->nlp_sid) {
6877 spin_unlock_irq(shost->host_lock);
6881 spin_unlock_irq(shost->host_lock);
6886 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6887 * @starget: kernel scsi target pointer.
6890 lpfc_get_starget_port_id(struct scsi_target *starget)
6892 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6894 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6898 * lpfc_get_starget_node_name - Set the target node name
6899 * @starget: kernel scsi target pointer.
6901 * Description: Set the target node name to the ndlp node name wwn or zero.
6904 lpfc_get_starget_node_name(struct scsi_target *starget)
6906 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6908 fc_starget_node_name(starget) =
6909 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6913 * lpfc_get_starget_port_name - Set the target port name
6914 * @starget: kernel scsi target pointer.
6916 * Description: set the target port name to the ndlp port name wwn or zero.
6919 lpfc_get_starget_port_name(struct scsi_target *starget)
6921 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6923 fc_starget_port_name(starget) =
6924 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6928 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6929 * @rport: fc rport address.
6930 * @timeout: new value for dev loss tmo.
6933 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6934 * dev_loss_tmo to one.
6937 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6939 struct lpfc_rport_data *rdata = rport->dd_data;
6940 struct lpfc_nodelist *ndlp = rdata->pnode;
6941 #if (IS_ENABLED(CONFIG_NVME_FC))
6942 struct lpfc_nvme_rport *nrport = NULL;
6946 rport->dev_loss_tmo = timeout;
6948 rport->dev_loss_tmo = 1;
6951 dev_info(&rport->dev, "Cannot find remote node to "
6952 "set rport dev loss tmo, port_id x%x\n",
6957 #if (IS_ENABLED(CONFIG_NVME_FC))
6958 nrport = lpfc_ndlp_get_nrport(ndlp);
6960 if (nrport && nrport->remoteport)
6961 nvme_fc_set_remoteport_devloss(nrport->remoteport,
6962 rport->dev_loss_tmo);
6967 * lpfc_rport_show_function - Return rport target information
6970 * Macro that uses field to generate a function with the name lpfc_show_rport_
6972 * lpfc_show_rport_##field: returns the bytes formatted in buf
6973 * @cdev: class converted to an fc_rport.
6974 * @buf: on return contains the target_field or zero.
6976 * Returns: size of formatted string.
6978 #define lpfc_rport_show_function(field, format_string, sz, cast) \
6980 lpfc_show_rport_##field (struct device *dev, \
6981 struct device_attribute *attr, \
6984 struct fc_rport *rport = transport_class_to_rport(dev); \
6985 struct lpfc_rport_data *rdata = rport->hostdata; \
6986 return scnprintf(buf, sz, format_string, \
6987 (rdata->target) ? cast rdata->target->field : 0); \
6990 #define lpfc_rport_rd_attr(field, format_string, sz) \
6991 lpfc_rport_show_function(field, format_string, sz, ) \
6992 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6995 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6996 * @fc_vport: The fc_vport who's symbolic name has been changed.
6999 * This function is called by the transport after the @fc_vport's symbolic name
7000 * has been changed. This function re-registers the symbolic name with the
7001 * switch to propagate the change into the fabric if the vport is active.
7004 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
7006 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
7008 if (vport->port_state == LPFC_VPORT_READY)
7009 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
7013 * lpfc_hba_log_verbose_init - Set hba's log verbose level
7014 * @phba: Pointer to lpfc_hba struct.
7015 * @verbose: Verbose level to set.
7017 * This function is called by the lpfc_get_cfgparam() routine to set the
7018 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
7019 * log message according to the module's lpfc_log_verbose parameter setting
7020 * before hba port or vport created.
7023 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
7025 phba->cfg_log_verbose = verbose;
7028 struct fc_function_template lpfc_transport_functions = {
7029 /* fixed attributes the driver supports */
7030 .show_host_node_name = 1,
7031 .show_host_port_name = 1,
7032 .show_host_supported_classes = 1,
7033 .show_host_supported_fc4s = 1,
7034 .show_host_supported_speeds = 1,
7035 .show_host_maxframe_size = 1,
7037 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7038 .show_host_symbolic_name = 1,
7040 /* dynamic attributes the driver supports */
7041 .get_host_port_id = lpfc_get_host_port_id,
7042 .show_host_port_id = 1,
7044 .get_host_port_type = lpfc_get_host_port_type,
7045 .show_host_port_type = 1,
7047 .get_host_port_state = lpfc_get_host_port_state,
7048 .show_host_port_state = 1,
7050 /* active_fc4s is shown but doesn't change (thus no get function) */
7051 .show_host_active_fc4s = 1,
7053 .get_host_speed = lpfc_get_host_speed,
7054 .show_host_speed = 1,
7056 .get_host_fabric_name = lpfc_get_host_fabric_name,
7057 .show_host_fabric_name = 1,
7060 * The LPFC driver treats linkdown handling as target loss events
7061 * so there are no sysfs handlers for link_down_tmo.
7064 .get_fc_host_stats = lpfc_get_stats,
7065 .reset_fc_host_stats = lpfc_reset_stats,
7067 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7068 .show_rport_maxframe_size = 1,
7069 .show_rport_supported_classes = 1,
7071 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7072 .show_rport_dev_loss_tmo = 1,
7074 .get_starget_port_id = lpfc_get_starget_port_id,
7075 .show_starget_port_id = 1,
7077 .get_starget_node_name = lpfc_get_starget_node_name,
7078 .show_starget_node_name = 1,
7080 .get_starget_port_name = lpfc_get_starget_port_name,
7081 .show_starget_port_name = 1,
7083 .issue_fc_host_lip = lpfc_issue_lip,
7084 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7085 .terminate_rport_io = lpfc_terminate_rport_io,
7087 .dd_fcvport_size = sizeof(struct lpfc_vport *),
7089 .vport_disable = lpfc_vport_disable,
7091 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7093 .bsg_request = lpfc_bsg_request,
7094 .bsg_timeout = lpfc_bsg_timeout,
7097 struct fc_function_template lpfc_vport_transport_functions = {
7098 /* fixed attributes the driver supports */
7099 .show_host_node_name = 1,
7100 .show_host_port_name = 1,
7101 .show_host_supported_classes = 1,
7102 .show_host_supported_fc4s = 1,
7103 .show_host_supported_speeds = 1,
7104 .show_host_maxframe_size = 1,
7106 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7107 .show_host_symbolic_name = 1,
7109 /* dynamic attributes the driver supports */
7110 .get_host_port_id = lpfc_get_host_port_id,
7111 .show_host_port_id = 1,
7113 .get_host_port_type = lpfc_get_host_port_type,
7114 .show_host_port_type = 1,
7116 .get_host_port_state = lpfc_get_host_port_state,
7117 .show_host_port_state = 1,
7119 /* active_fc4s is shown but doesn't change (thus no get function) */
7120 .show_host_active_fc4s = 1,
7122 .get_host_speed = lpfc_get_host_speed,
7123 .show_host_speed = 1,
7125 .get_host_fabric_name = lpfc_get_host_fabric_name,
7126 .show_host_fabric_name = 1,
7129 * The LPFC driver treats linkdown handling as target loss events
7130 * so there are no sysfs handlers for link_down_tmo.
7133 .get_fc_host_stats = lpfc_get_stats,
7134 .reset_fc_host_stats = lpfc_reset_stats,
7136 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7137 .show_rport_maxframe_size = 1,
7138 .show_rport_supported_classes = 1,
7140 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7141 .show_rport_dev_loss_tmo = 1,
7143 .get_starget_port_id = lpfc_get_starget_port_id,
7144 .show_starget_port_id = 1,
7146 .get_starget_node_name = lpfc_get_starget_node_name,
7147 .show_starget_node_name = 1,
7149 .get_starget_port_name = lpfc_get_starget_port_name,
7150 .show_starget_port_name = 1,
7152 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7153 .terminate_rport_io = lpfc_terminate_rport_io,
7155 .vport_disable = lpfc_vport_disable,
7157 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7161 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7163 * @phba: lpfc_hba pointer.
7166 lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7168 /* If the adapter supports FCoE mode */
7169 switch (phba->pcidev->device) {
7170 case PCI_DEVICE_ID_SKYHAWK:
7171 case PCI_DEVICE_ID_SKYHAWK_VF:
7172 case PCI_DEVICE_ID_LANCER_FCOE:
7173 case PCI_DEVICE_ID_LANCER_FCOE_VF:
7174 case PCI_DEVICE_ID_ZEPHYR_DCSP:
7175 case PCI_DEVICE_ID_TIGERSHARK:
7176 case PCI_DEVICE_ID_TOMCAT:
7177 phba->hba_flag |= HBA_FCOE_MODE;
7180 /* for others, clear the flag */
7181 phba->hba_flag &= ~HBA_FCOE_MODE;
7186 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7187 * @phba: lpfc_hba pointer.
7190 lpfc_get_cfgparam(struct lpfc_hba *phba)
7192 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7193 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
7194 lpfc_ns_query_init(phba, lpfc_ns_query);
7195 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7196 lpfc_cr_delay_init(phba, lpfc_cr_delay);
7197 lpfc_cr_count_init(phba, lpfc_cr_count);
7198 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
7199 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7200 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7201 lpfc_ack0_init(phba, lpfc_ack0);
7202 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
7203 lpfc_topology_init(phba, lpfc_topology);
7204 lpfc_link_speed_init(phba, lpfc_link_speed);
7205 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
7206 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
7207 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7208 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
7209 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
7210 lpfc_fcp_wait_abts_rsp_init(phba, lpfc_fcp_wait_abts_rsp);
7211 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7212 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
7213 lpfc_use_msi_init(phba, lpfc_use_msi);
7214 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
7215 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
7216 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7217 lpfc_force_rscn_init(phba, lpfc_force_rscn);
7218 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7219 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
7220 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
7221 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7222 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
7224 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7226 lpfc_max_vmid_init(phba, lpfc_max_vmid);
7227 lpfc_vmid_inactivity_timeout_init(phba, lpfc_vmid_inactivity_timeout);
7228 lpfc_vmid_app_header_init(phba, lpfc_vmid_app_header);
7229 lpfc_vmid_priority_tagging_init(phba, lpfc_vmid_priority_tagging);
7230 if (phba->sli_rev != LPFC_SLI_REV4)
7231 phba->cfg_EnableXLane = 0;
7232 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
7234 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7235 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7236 phba->cfg_oas_lun_state = 0;
7237 phba->cfg_oas_lun_status = 0;
7238 phba->cfg_oas_flags = 0;
7239 phba->cfg_oas_priority = 0;
7240 lpfc_enable_bg_init(phba, lpfc_enable_bg);
7241 lpfc_prot_mask_init(phba, lpfc_prot_mask);
7242 lpfc_prot_guard_init(phba, lpfc_prot_guard);
7243 if (phba->sli_rev == LPFC_SLI_REV4)
7246 phba->cfg_poll = lpfc_poll;
7248 /* Get the function mode */
7249 lpfc_get_hba_function_mode(phba);
7251 /* BlockGuard allowed for FC only. */
7252 if (phba->cfg_enable_bg && phba->hba_flag & HBA_FCOE_MODE) {
7253 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7254 "0581 BlockGuard feature not supported\n");
7255 /* If set, clear the BlockGuard support param */
7256 phba->cfg_enable_bg = 0;
7257 } else if (phba->cfg_enable_bg) {
7258 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
7261 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
7263 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
7264 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
7265 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
7267 /* Initialize first burst. Target vs Initiator are different. */
7268 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
7269 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
7270 lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
7271 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
7272 lpfc_irq_chann_init(phba, lpfc_irq_chann);
7273 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7274 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7275 lpfc_enable_mi_init(phba, lpfc_enable_mi);
7277 phba->cgn_p.cgn_param_mode = LPFC_CFG_OFF;
7278 phba->cmf_active_mode = LPFC_CFG_OFF;
7279 if (lpfc_fabric_cgn_frequency > EDC_CG_SIGFREQ_CNT_MAX ||
7280 lpfc_fabric_cgn_frequency < EDC_CG_SIGFREQ_CNT_MIN)
7281 lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
7283 if (phba->sli_rev != LPFC_SLI_REV4) {
7284 /* NVME only supported on SLI4 */
7285 phba->nvmet_support = 0;
7286 phba->cfg_nvmet_mrq = 0;
7287 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7288 phba->cfg_enable_bbcr = 0;
7289 phba->cfg_xri_rebalancing = 0;
7291 /* We MUST have FCP support */
7292 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7293 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7296 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7298 phba->cfg_enable_pbde = 0;
7300 /* A value of 0 means use the number of CPUs found in the system */
7301 if (phba->cfg_hdw_queue == 0)
7302 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7303 if (phba->cfg_irq_chann == 0)
7304 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7305 if (phba->cfg_irq_chann > phba->cfg_hdw_queue &&
7306 phba->sli_rev == LPFC_SLI_REV4)
7307 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7309 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7310 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7311 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7312 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7313 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7314 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7315 lpfc_sli_mode_init(phba, lpfc_sli_mode);
7316 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7317 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7318 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7319 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7325 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7326 * dependencies between protocols and roles.
7327 * @phba: lpfc_hba pointer.
7330 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7334 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu) {
7335 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7338 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu) {
7339 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7342 if (phba->cfg_irq_chann > phba->cfg_hdw_queue) {
7343 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7347 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7348 "2006 Reducing Queues - CPU limitation: "
7350 phba->cfg_irq_chann,
7351 phba->cfg_hdw_queue);
7353 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7354 phba->nvmet_support) {
7355 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7357 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7358 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7359 "NVME Target PRLI ACC enable_fb ",
7360 phba->cfg_nvme_enable_fb,
7361 phba->cfg_nvmet_fb_size,
7362 LPFC_NVMET_FB_SZ_MAX);
7364 if (phba->cfg_nvme_enable_fb == 0)
7365 phba->cfg_nvmet_fb_size = 0;
7367 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7368 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7371 if (!phba->cfg_nvmet_mrq)
7372 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7374 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7375 if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
7376 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7377 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7378 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7379 phba->cfg_nvmet_mrq);
7381 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7382 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7385 /* Not NVME Target mode. Turn off Target parameters. */
7386 phba->nvmet_support = 0;
7387 phba->cfg_nvmet_mrq = 0;
7388 phba->cfg_nvmet_fb_size = 0;
7393 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7394 * @vport: lpfc_vport pointer.
7397 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7399 lpfc_log_verbose_init(vport, lpfc_log_verbose);
7400 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7401 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7402 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7403 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7404 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7405 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7406 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7407 lpfc_use_adisc_init(vport, lpfc_use_adisc);
7408 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7409 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7410 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7411 lpfc_max_luns_init(vport, lpfc_max_luns);
7412 lpfc_scan_down_init(vport, lpfc_scan_down);
7413 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);