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 /* wait for the SLI port firmware ready after firmware reset */
1648 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1650 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1651 &portstat_reg.word0))
1653 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1655 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1657 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1662 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1669 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1670 * @phba: lpfc_hba pointer.
1671 * @opcode: The sli4 config command opcode.
1674 * Request SLI4 interface type-2 device to perform a physical register set
1681 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1683 struct completion online_compl;
1684 struct pci_dev *pdev = phba->pcidev;
1685 uint32_t before_fc_flag;
1686 uint32_t sriov_nr_virtfn;
1688 int status = 0, rc = 0;
1689 int job_posted = 1, sriov_err;
1691 if (!phba->cfg_enable_hba_reset)
1694 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1695 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1696 LPFC_SLI_INTF_IF_TYPE_2))
1699 /* Keep state if we need to restore back */
1700 before_fc_flag = phba->pport->fc_flag;
1701 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1703 if (opcode == LPFC_FW_DUMP) {
1704 init_completion(&online_compl);
1705 phba->fw_dump_cmpl = &online_compl;
1707 /* Disable SR-IOV virtual functions if enabled */
1708 if (phba->cfg_sriov_nr_virtfn) {
1709 pci_disable_sriov(pdev);
1710 phba->cfg_sriov_nr_virtfn = 0;
1713 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1718 /* wait for the device to be quiesced before firmware reset */
1722 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1723 LPFC_CTL_PDEV_CTL_OFFSET);
1725 if (opcode == LPFC_FW_DUMP)
1726 reg_val |= LPFC_FW_DUMP_REQUEST;
1727 else if (opcode == LPFC_FW_RESET)
1728 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1729 else if (opcode == LPFC_DV_RESET)
1730 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1732 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1733 LPFC_CTL_PDEV_CTL_OFFSET);
1735 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1737 /* delay driver action following IF_TYPE_2 reset */
1738 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1741 /* no privilege for reset */
1742 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1743 "3150 No privilege to perform the requested "
1744 "access: x%x\n", reg_val);
1745 } else if (rc == -EIO) {
1746 /* reset failed, there is nothing more we can do */
1747 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1748 "3153 Fail to perform the requested "
1749 "access: x%x\n", reg_val);
1750 if (phba->fw_dump_cmpl)
1751 phba->fw_dump_cmpl = NULL;
1755 /* keep the original port state */
1756 if (before_fc_flag & FC_OFFLINE_MODE) {
1757 if (phba->fw_dump_cmpl)
1758 phba->fw_dump_cmpl = NULL;
1762 /* Firmware dump will trigger an HA_ERATT event, and
1763 * lpfc_handle_eratt_s4 routine already handles bringing the port back
1766 if (opcode == LPFC_FW_DUMP) {
1767 wait_for_completion(phba->fw_dump_cmpl);
1769 init_completion(&online_compl);
1770 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1775 wait_for_completion(&online_compl);
1778 /* in any case, restore the virtual functions enabled as before */
1779 if (sriov_nr_virtfn) {
1780 /* If fw_dump was performed, first disable to clean up */
1781 if (opcode == LPFC_FW_DUMP) {
1782 pci_disable_sriov(pdev);
1783 phba->cfg_sriov_nr_virtfn = 0;
1787 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1789 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1792 /* return proper error code */
1803 * lpfc_nport_evt_cnt_show - Return the number of nport events
1804 * @dev: class device that is converted into a Scsi_host.
1805 * @attr: device attribute, not used.
1806 * @buf: on return contains the ascii number of nport events.
1808 * Returns: size of formatted string.
1811 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1814 struct Scsi_Host *shost = class_to_shost(dev);
1815 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1816 struct lpfc_hba *phba = vport->phba;
1818 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1822 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1824 LPFC_MBOXQ_t *mbox = NULL;
1825 unsigned long val = 0;
1829 if (!strncmp("enable", buff_out,
1830 strlen("enable"))) {
1831 pval = buff_out + strlen("enable") + 1;
1832 rc = kstrtoul(pval, 0, &val);
1834 return rc; /* Invalid number */
1835 } else if (!strncmp("disable", buff_out,
1836 strlen("disable"))) {
1839 return -EINVAL; /* Invalid command */
1844 val = 0x0; /* Disable */
1847 val = 0x1; /* Enable two port trunk */
1850 val = 0x2; /* Enable four port trunk */
1856 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1857 "0070 Set trunk mode with val %ld ", val);
1859 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1863 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1864 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1865 12, LPFC_SLI4_MBX_EMBED);
1867 bf_set(lpfc_mbx_set_trunk_mode,
1868 &mbox->u.mqe.un.set_trunk_mode,
1870 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1872 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1873 "0071 Set trunk mode failed with status: %d",
1875 mempool_free(mbox, phba->mbox_mem_pool);
1881 lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr,
1884 struct Scsi_Host *shost = class_to_shost(dev);
1885 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1886 struct lpfc_hba *phba = vport->phba;
1889 struct lpfc_rdp_context *rdp_context;
1897 struct sff_trasnceiver_codes_byte7 *trasn_code_byte7;
1899 /* Get transceiver information */
1900 rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL);
1902 rc = lpfc_get_sfp_info_wait(phba, rdp_context);
1904 len = scnprintf(buf, PAGE_SIZE - len, "SFP info NA:\n");
1908 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_NAME], 16);
1910 len = scnprintf(buf, PAGE_SIZE - len, "VendorName:\t%s\n", chbuf);
1911 len += scnprintf(buf + len, PAGE_SIZE - len,
1912 "VendorOUI:\t%02x-%02x-%02x\n",
1913 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI],
1914 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 1],
1915 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 2]);
1916 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_PN], 16);
1917 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorPN:\t%s\n", chbuf);
1918 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_SN], 16);
1919 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorSN:\t%s\n", chbuf);
1920 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_REV], 4);
1921 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorRev:\t%s\n", chbuf);
1922 strscpy(chbuf, &rdp_context->page_a0[SSF_DATE_CODE], 8);
1923 len += scnprintf(buf + len, PAGE_SIZE - len, "DateCode:\t%s\n", chbuf);
1924 len += scnprintf(buf + len, PAGE_SIZE - len, "Identifier:\t%xh\n",
1925 (uint8_t)rdp_context->page_a0[SSF_IDENTIFIER]);
1926 len += scnprintf(buf + len, PAGE_SIZE - len, "ExtIdentifier:\t%xh\n",
1927 (uint8_t)rdp_context->page_a0[SSF_EXT_IDENTIFIER]);
1928 len += scnprintf(buf + len, PAGE_SIZE - len, "Connector:\t%xh\n",
1929 (uint8_t)rdp_context->page_a0[SSF_CONNECTOR]);
1930 wavelength = (rdp_context->page_a0[SSF_WAVELENGTH_B1] << 8) |
1931 rdp_context->page_a0[SSF_WAVELENGTH_B0];
1933 len += scnprintf(buf + len, PAGE_SIZE - len, "Wavelength:\t%d nm\n",
1935 trasn_code_byte7 = (struct sff_trasnceiver_codes_byte7 *)
1936 &rdp_context->page_a0[SSF_TRANSCEIVER_CODE_B7];
1938 len += scnprintf(buf + len, PAGE_SIZE - len, "Speeds: \t");
1939 if (*(uint8_t *)trasn_code_byte7 == 0) {
1940 len += scnprintf(buf + len, PAGE_SIZE - len, "Unknown\n");
1942 if (trasn_code_byte7->fc_sp_100MB)
1943 len += scnprintf(buf + len, PAGE_SIZE - len, "1 ");
1944 if (trasn_code_byte7->fc_sp_200mb)
1945 len += scnprintf(buf + len, PAGE_SIZE - len, "2 ");
1946 if (trasn_code_byte7->fc_sp_400MB)
1947 len += scnprintf(buf + len, PAGE_SIZE - len, "4 ");
1948 if (trasn_code_byte7->fc_sp_800MB)
1949 len += scnprintf(buf + len, PAGE_SIZE - len, "8 ");
1950 if (trasn_code_byte7->fc_sp_1600MB)
1951 len += scnprintf(buf + len, PAGE_SIZE - len, "16 ");
1952 if (trasn_code_byte7->fc_sp_3200MB)
1953 len += scnprintf(buf + len, PAGE_SIZE - len, "32 ");
1954 if (trasn_code_byte7->speed_chk_ecc)
1955 len += scnprintf(buf + len, PAGE_SIZE - len, "64 ");
1956 len += scnprintf(buf + len, PAGE_SIZE - len, "GB\n");
1958 temperature = (rdp_context->page_a2[SFF_TEMPERATURE_B1] << 8 |
1959 rdp_context->page_a2[SFF_TEMPERATURE_B0]);
1960 vcc = (rdp_context->page_a2[SFF_VCC_B1] << 8 |
1961 rdp_context->page_a2[SFF_VCC_B0]);
1962 tx_power = (rdp_context->page_a2[SFF_TXPOWER_B1] << 8 |
1963 rdp_context->page_a2[SFF_TXPOWER_B0]);
1964 tx_bias = (rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
1965 rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B0]);
1966 rx_power = (rdp_context->page_a2[SFF_RXPOWER_B1] << 8 |
1967 rdp_context->page_a2[SFF_RXPOWER_B0]);
1969 len += scnprintf(buf + len, PAGE_SIZE - len,
1970 "Temperature:\tx%04x C\n", temperature);
1971 len += scnprintf(buf + len, PAGE_SIZE - len, "Vcc:\t\tx%04x V\n", vcc);
1972 len += scnprintf(buf + len, PAGE_SIZE - len,
1973 "TxBiasCurrent:\tx%04x mA\n", tx_bias);
1974 len += scnprintf(buf + len, PAGE_SIZE - len, "TxPower:\tx%04x mW\n",
1976 len += scnprintf(buf + len, PAGE_SIZE - len, "RxPower:\tx%04x mW\n",
1984 * lpfc_board_mode_show - Return the state of the board
1985 * @dev: class device that is converted into a Scsi_host.
1986 * @attr: device attribute, not used.
1987 * @buf: on return contains the state of the adapter.
1989 * Returns: size of formatted string.
1992 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1995 struct Scsi_Host *shost = class_to_shost(dev);
1996 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1997 struct lpfc_hba *phba = vport->phba;
2000 if (phba->link_state == LPFC_HBA_ERROR)
2002 else if (phba->link_state == LPFC_WARM_START)
2003 state = "warm start";
2004 else if (phba->link_state == LPFC_INIT_START)
2009 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
2013 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
2014 * @dev: class device that is converted into a Scsi_host.
2015 * @attr: device attribute, not used.
2016 * @buf: containing one of the strings "online", "offline", "warm" or "error".
2017 * @count: unused variable.
2020 * -EACCES if enable hba reset not enabled
2021 * -EINVAL if the buffer does not contain a valid string (see above)
2022 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
2023 * buf length greater than zero indicates success
2026 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
2027 const char *buf, size_t count)
2029 struct Scsi_Host *shost = class_to_shost(dev);
2030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2031 struct lpfc_hba *phba = vport->phba;
2032 struct completion online_compl;
2033 char *board_mode_str = NULL;
2037 if (!phba->cfg_enable_hba_reset) {
2039 goto board_mode_out;
2042 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2043 "3050 lpfc_board_mode set to %s\n", buf);
2045 init_completion(&online_compl);
2047 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
2048 rc = lpfc_workq_post_event(phba, &status, &online_compl,
2052 goto board_mode_out;
2054 wait_for_completion(&online_compl);
2057 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
2058 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2059 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
2060 if (phba->sli_rev == LPFC_SLI_REV4)
2063 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
2064 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
2065 if (phba->sli_rev == LPFC_SLI_REV4)
2068 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
2069 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
2070 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
2071 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
2072 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
2073 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
2074 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
2075 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
2077 status = lpfc_reset_pci_bus(phba);
2078 else if (strncmp(buf, "heartbeat", sizeof("heartbeat") - 1) == 0)
2079 lpfc_issue_hb_tmo(phba);
2080 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
2081 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
2089 board_mode_str = strchr(buf, '\n');
2091 *board_mode_str = '\0';
2092 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2093 "3097 Failed \"%s\", status(%d), "
2095 buf, status, phba->pport->fc_flag);
2101 * lpfc_get_hba_info - Return various bits of informaton about the adapter
2102 * @phba: pointer to the adapter structure.
2103 * @mxri: max xri count.
2104 * @axri: available xri count.
2105 * @mrpi: max rpi count.
2106 * @arpi: available rpi count.
2107 * @mvpi: max vpi count.
2108 * @avpi: available vpi count.
2111 * If an integer pointer for an count is not null then the value for the
2112 * count is returned.
2119 lpfc_get_hba_info(struct lpfc_hba *phba,
2120 uint32_t *mxri, uint32_t *axri,
2121 uint32_t *mrpi, uint32_t *arpi,
2122 uint32_t *mvpi, uint32_t *avpi)
2124 struct lpfc_mbx_read_config *rd_config;
2125 LPFC_MBOXQ_t *pmboxq;
2131 * prevent udev from issuing mailbox commands until the port is
2134 if (phba->link_state < LPFC_LINK_DOWN ||
2135 !phba->mbox_mem_pool ||
2136 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
2139 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
2142 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2145 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2147 pmb = &pmboxq->u.mb;
2148 pmb->mbxCommand = MBX_READ_CONFIG;
2149 pmb->mbxOwner = OWN_HOST;
2150 pmboxq->ctx_buf = NULL;
2152 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
2153 rc = MBX_NOT_FINISHED;
2155 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2157 if (rc != MBX_SUCCESS) {
2158 if (rc != MBX_TIMEOUT)
2159 mempool_free(pmboxq, phba->mbox_mem_pool);
2163 if (phba->sli_rev == LPFC_SLI_REV4) {
2164 rd_config = &pmboxq->u.mqe.un.rd_config;
2166 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
2168 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
2169 phba->sli4_hba.max_cfg_param.rpi_used;
2171 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
2173 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
2174 phba->sli4_hba.max_cfg_param.xri_used;
2176 /* Account for differences with SLI-3. Get vpi count from
2177 * mailbox data and subtract one for max vpi value.
2179 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
2180 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
2182 /* Limit the max we support */
2183 if (max_vpi > LPFC_MAX_VPI)
2184 max_vpi = LPFC_MAX_VPI;
2188 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
2191 *mrpi = pmb->un.varRdConfig.max_rpi;
2193 *arpi = pmb->un.varRdConfig.avail_rpi;
2195 *mxri = pmb->un.varRdConfig.max_xri;
2197 *axri = pmb->un.varRdConfig.avail_xri;
2199 *mvpi = pmb->un.varRdConfig.max_vpi;
2201 /* avail_vpi is only valid if link is up and ready */
2202 if (phba->link_state == LPFC_HBA_READY)
2203 *avpi = pmb->un.varRdConfig.avail_vpi;
2205 *avpi = pmb->un.varRdConfig.max_vpi;
2209 mempool_free(pmboxq, phba->mbox_mem_pool);
2214 * lpfc_max_rpi_show - Return maximum rpi
2215 * @dev: class device that is converted into a Scsi_host.
2216 * @attr: device attribute, not used.
2217 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
2220 * Calls lpfc_get_hba_info() asking for just the mrpi count.
2221 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2222 * to "Unknown" and the buffer length is returned, therefore the caller
2223 * must check for "Unknown" in the buffer to detect a failure.
2225 * Returns: size of formatted string.
2228 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
2231 struct Scsi_Host *shost = class_to_shost(dev);
2232 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2233 struct lpfc_hba *phba = vport->phba;
2236 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
2237 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2238 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2242 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
2243 * @dev: class device that is converted into a Scsi_host.
2244 * @attr: device attribute, not used.
2245 * @buf: containing the used rpi count in decimal or "Unknown".
2248 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
2249 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2250 * to "Unknown" and the buffer length is returned, therefore the caller
2251 * must check for "Unknown" in the buffer to detect a failure.
2253 * Returns: size of formatted string.
2256 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
2259 struct Scsi_Host *shost = class_to_shost(dev);
2260 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2261 struct lpfc_hba *phba = vport->phba;
2264 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
2265 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2266 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2270 * lpfc_max_xri_show - Return maximum xri
2271 * @dev: class device that is converted into a Scsi_host.
2272 * @attr: device attribute, not used.
2273 * @buf: on return contains the maximum xri count in decimal or "Unknown".
2276 * Calls lpfc_get_hba_info() asking for just the mrpi count.
2277 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2278 * to "Unknown" and the buffer length is returned, therefore the caller
2279 * must check for "Unknown" in the buffer to detect a failure.
2281 * Returns: size of formatted string.
2284 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
2287 struct Scsi_Host *shost = class_to_shost(dev);
2288 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2289 struct lpfc_hba *phba = vport->phba;
2292 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2293 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2294 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2298 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2299 * @dev: class device that is converted into a Scsi_host.
2300 * @attr: device attribute, not used.
2301 * @buf: on return contains the used xri count in decimal or "Unknown".
2304 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2305 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2306 * to "Unknown" and the buffer length is returned, therefore the caller
2307 * must check for "Unknown" in the buffer to detect a failure.
2309 * Returns: size of formatted string.
2312 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2315 struct Scsi_Host *shost = class_to_shost(dev);
2316 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2317 struct lpfc_hba *phba = vport->phba;
2320 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2321 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2322 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2326 * lpfc_max_vpi_show - Return maximum vpi
2327 * @dev: class device that is converted into a Scsi_host.
2328 * @attr: device attribute, not used.
2329 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2332 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2333 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2334 * to "Unknown" and the buffer length is returned, therefore the caller
2335 * must check for "Unknown" in the buffer to detect a failure.
2337 * Returns: size of formatted string.
2340 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2343 struct Scsi_Host *shost = class_to_shost(dev);
2344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2345 struct lpfc_hba *phba = vport->phba;
2348 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2349 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2350 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2354 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2355 * @dev: class device that is converted into a Scsi_host.
2356 * @attr: device attribute, not used.
2357 * @buf: on return contains the used vpi count in decimal or "Unknown".
2360 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2361 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2362 * to "Unknown" and the buffer length is returned, therefore the caller
2363 * must check for "Unknown" in the buffer to detect a failure.
2365 * Returns: size of formatted string.
2368 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2371 struct Scsi_Host *shost = class_to_shost(dev);
2372 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2373 struct lpfc_hba *phba = vport->phba;
2376 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2377 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2378 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2382 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2383 * @dev: class device that is converted into a Scsi_host.
2384 * @attr: device attribute, not used.
2385 * @buf: text that must be interpreted to determine if npiv is supported.
2388 * Buffer will contain text indicating npiv is not suppoerted on the port,
2389 * the port is an NPIV physical port, or it is an npiv virtual port with
2390 * the id of the vport.
2392 * Returns: size of formatted string.
2395 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2398 struct Scsi_Host *shost = class_to_shost(dev);
2399 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2400 struct lpfc_hba *phba = vport->phba;
2402 if (!(phba->max_vpi))
2403 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2404 if (vport->port_type == LPFC_PHYSICAL_PORT)
2405 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2406 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2410 * lpfc_poll_show - Return text about poll support for the adapter
2411 * @dev: class device that is converted into a Scsi_host.
2412 * @attr: device attribute, not used.
2413 * @buf: on return contains the cfg_poll in hex.
2416 * cfg_poll should be a lpfc_polling_flags type.
2418 * Returns: size of formatted string.
2421 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2424 struct Scsi_Host *shost = class_to_shost(dev);
2425 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2426 struct lpfc_hba *phba = vport->phba;
2428 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2432 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2433 * @dev: class device that is converted into a Scsi_host.
2434 * @attr: device attribute, not used.
2435 * @buf: one or more lpfc_polling_flags values.
2439 * buf contents converted to integer and checked for a valid value.
2442 * -EINVAL if the buffer connot be converted or is out of range
2443 * length of the buf on success
2446 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2447 const char *buf, size_t count)
2449 struct Scsi_Host *shost = class_to_shost(dev);
2450 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2451 struct lpfc_hba *phba = vport->phba;
2456 if (!isdigit(buf[0]))
2459 if (sscanf(buf, "%i", &val) != 1)
2462 if ((val & 0x3) != val)
2465 if (phba->sli_rev == LPFC_SLI_REV4)
2468 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2469 "3051 lpfc_poll changed from %d to %d\n",
2470 phba->cfg_poll, val);
2472 spin_lock_irq(&phba->hbalock);
2474 old_val = phba->cfg_poll;
2476 if (val & ENABLE_FCP_RING_POLLING) {
2477 if ((val & DISABLE_FCP_RING_INT) &&
2478 !(old_val & DISABLE_FCP_RING_INT)) {
2479 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2480 spin_unlock_irq(&phba->hbalock);
2483 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2484 writel(creg_val, phba->HCregaddr);
2485 readl(phba->HCregaddr); /* flush */
2487 lpfc_poll_start_timer(phba);
2489 } else if (val != 0x0) {
2490 spin_unlock_irq(&phba->hbalock);
2494 if (!(val & DISABLE_FCP_RING_INT) &&
2495 (old_val & DISABLE_FCP_RING_INT))
2497 spin_unlock_irq(&phba->hbalock);
2498 del_timer(&phba->fcp_poll_timer);
2499 spin_lock_irq(&phba->hbalock);
2500 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2501 spin_unlock_irq(&phba->hbalock);
2504 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2505 writel(creg_val, phba->HCregaddr);
2506 readl(phba->HCregaddr); /* flush */
2509 phba->cfg_poll = val;
2511 spin_unlock_irq(&phba->hbalock);
2517 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2518 * @dev: class converted to a Scsi_host structure.
2519 * @attr: device attribute, not used.
2520 * @buf: on return contains the formatted support level.
2523 * Returns the maximum number of virtual functions a physical function can
2524 * support, 0 will be returned if called on virtual function.
2526 * Returns: size of formatted string.
2529 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2530 struct device_attribute *attr,
2533 struct Scsi_Host *shost = class_to_shost(dev);
2534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2535 struct lpfc_hba *phba = vport->phba;
2536 uint16_t max_nr_virtfn;
2538 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2539 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2543 * lpfc_enable_bbcr_set: Sets an attribute value.
2544 * @phba: pointer to the adapter structure.
2545 * @val: integer attribute value.
2548 * Validates the min and max values then sets the
2549 * adapter config field if in the valid range. prints error message
2550 * and does not set the parameter if invalid.
2554 * -EINVAL if val is invalid
2557 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2559 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2560 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2561 "3068 lpfc_enable_bbcr changed from %d to "
2562 "%d\n", phba->cfg_enable_bbcr, val);
2563 phba->cfg_enable_bbcr = val;
2566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2567 "0451 lpfc_enable_bbcr cannot set to %d, range is 0, "
2573 * lpfc_param_show - Return a cfg attribute value in decimal
2576 * Macro that given an attr e.g. hba_queue_depth expands
2577 * into a function with the name lpfc_hba_queue_depth_show.
2579 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2580 * @dev: class device that is converted into a Scsi_host.
2581 * @attr: device attribute, not used.
2582 * @buf: on return contains the attribute value in decimal.
2584 * Returns: size of formatted string.
2586 #define lpfc_param_show(attr) \
2588 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2591 struct Scsi_Host *shost = class_to_shost(dev);\
2592 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2593 struct lpfc_hba *phba = vport->phba;\
2594 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2599 * lpfc_param_hex_show - Return a cfg attribute value in hex
2602 * Macro that given an attr e.g. hba_queue_depth expands
2603 * into a function with the name lpfc_hba_queue_depth_show
2605 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2606 * @dev: class device that is converted into a Scsi_host.
2607 * @attr: device attribute, not used.
2608 * @buf: on return contains the attribute value in hexadecimal.
2610 * Returns: size of formatted string.
2612 #define lpfc_param_hex_show(attr) \
2614 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2617 struct Scsi_Host *shost = class_to_shost(dev);\
2618 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2619 struct lpfc_hba *phba = vport->phba;\
2621 val = phba->cfg_##attr;\
2622 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2627 * lpfc_param_init - Initializes a cfg attribute
2630 * Macro that given an attr e.g. hba_queue_depth expands
2631 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2632 * takes a default argument, a minimum and maximum argument.
2634 * lpfc_##attr##_init: Initializes an attribute.
2635 * @phba: pointer to the adapter structure.
2636 * @val: integer attribute value.
2638 * Validates the min and max values then sets the adapter config field
2639 * accordingly, or uses the default if out of range and prints an error message.
2643 * -EINVAL if default used
2645 #define lpfc_param_init(attr, default, minval, maxval) \
2647 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2649 if (lpfc_rangecheck(val, minval, maxval)) {\
2650 phba->cfg_##attr = val;\
2653 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2654 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2655 "allowed range is ["#minval", "#maxval"]\n", val); \
2656 phba->cfg_##attr = default;\
2661 * lpfc_param_set - Set a cfg attribute value
2664 * Macro that given an attr e.g. hba_queue_depth expands
2665 * into a function with the name lpfc_hba_queue_depth_set
2667 * lpfc_##attr##_set: Sets an attribute value.
2668 * @phba: pointer to the adapter structure.
2669 * @val: integer attribute value.
2672 * Validates the min and max values then sets the
2673 * adapter config field if in the valid range. prints error message
2674 * and does not set the parameter if invalid.
2678 * -EINVAL if val is invalid
2680 #define lpfc_param_set(attr, default, minval, maxval) \
2682 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2684 if (lpfc_rangecheck(val, minval, maxval)) {\
2685 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2686 "3052 lpfc_" #attr " changed from %d to %d\n", \
2687 phba->cfg_##attr, val); \
2688 phba->cfg_##attr = val;\
2691 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2692 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2693 "allowed range is ["#minval", "#maxval"]\n", val); \
2698 * lpfc_param_store - Set a vport attribute value
2701 * Macro that given an attr e.g. hba_queue_depth expands
2702 * into a function with the name lpfc_hba_queue_depth_store.
2704 * lpfc_##attr##_store: Set an sttribute value.
2705 * @dev: class device that is converted into a Scsi_host.
2706 * @attr: device attribute, not used.
2707 * @buf: contains the attribute value in ascii.
2711 * Convert the ascii text number to an integer, then
2712 * use the lpfc_##attr##_set function to set the value.
2715 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2716 * length of buffer upon success.
2718 #define lpfc_param_store(attr) \
2720 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2721 const char *buf, size_t count) \
2723 struct Scsi_Host *shost = class_to_shost(dev);\
2724 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2725 struct lpfc_hba *phba = vport->phba;\
2727 if (!isdigit(buf[0]))\
2729 if (sscanf(buf, "%i", &val) != 1)\
2731 if (lpfc_##attr##_set(phba, val) == 0) \
2732 return strlen(buf);\
2738 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2741 * Macro that given an attr e.g. hba_queue_depth expands
2742 * into a function with the name lpfc_hba_queue_depth_show
2744 * lpfc_##attr##_show: prints the attribute value in decimal.
2745 * @dev: class device that is converted into a Scsi_host.
2746 * @attr: device attribute, not used.
2747 * @buf: on return contains the attribute value in decimal.
2749 * Returns: length of formatted string.
2751 #define lpfc_vport_param_show(attr) \
2753 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2756 struct Scsi_Host *shost = class_to_shost(dev);\
2757 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2758 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2762 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2765 * Macro that given an attr e.g.
2766 * hba_queue_depth expands into a function with the name
2767 * lpfc_hba_queue_depth_show
2769 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2770 * @dev: class device that is converted into a Scsi_host.
2771 * @attr: device attribute, not used.
2772 * @buf: on return contains the attribute value in hexadecimal.
2774 * Returns: length of formatted string.
2776 #define lpfc_vport_param_hex_show(attr) \
2778 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2781 struct Scsi_Host *shost = class_to_shost(dev);\
2782 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2783 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2787 * lpfc_vport_param_init - Initialize a vport cfg attribute
2790 * Macro that given an attr e.g. hba_queue_depth expands
2791 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2792 * takes a default argument, a minimum and maximum argument.
2794 * lpfc_##attr##_init: validates the min and max values then sets the
2795 * adapter config field accordingly, or uses the default if out of range
2796 * and prints an error message.
2797 * @phba: pointer to the adapter structure.
2798 * @val: integer attribute value.
2802 * -EINVAL if default used
2804 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2806 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2808 if (lpfc_rangecheck(val, minval, maxval)) {\
2809 vport->cfg_##attr = val;\
2812 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2813 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2814 "allowed range is ["#minval", "#maxval"]\n", val); \
2815 vport->cfg_##attr = default;\
2820 * lpfc_vport_param_set - Set a vport cfg attribute
2823 * Macro that given an attr e.g. hba_queue_depth expands
2824 * into a function with the name lpfc_hba_queue_depth_set
2826 * lpfc_##attr##_set: validates the min and max values then sets the
2827 * adapter config field if in the valid range. prints error message
2828 * and does not set the parameter if invalid.
2829 * @phba: pointer to the adapter structure.
2830 * @val: integer attribute value.
2834 * -EINVAL if val is invalid
2836 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2838 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2840 if (lpfc_rangecheck(val, minval, maxval)) {\
2841 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2842 "3053 lpfc_" #attr \
2843 " changed from %d (x%x) to %d (x%x)\n", \
2844 vport->cfg_##attr, vport->cfg_##attr, \
2846 vport->cfg_##attr = val;\
2849 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2850 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2851 "allowed range is ["#minval", "#maxval"]\n", val); \
2856 * lpfc_vport_param_store - Set a vport attribute
2859 * Macro that given an attr e.g. hba_queue_depth
2860 * expands into a function with the name lpfc_hba_queue_depth_store
2862 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2863 * use the lpfc_##attr##_set function to set the value.
2864 * @cdev: class device that is converted into a Scsi_host.
2865 * @buf: contains the attribute value in decimal.
2869 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2870 * length of buffer upon success.
2872 #define lpfc_vport_param_store(attr) \
2874 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2875 const char *buf, size_t count) \
2877 struct Scsi_Host *shost = class_to_shost(dev);\
2878 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2880 if (!isdigit(buf[0]))\
2882 if (sscanf(buf, "%i", &val) != 1)\
2884 if (lpfc_##attr##_set(vport, val) == 0) \
2885 return strlen(buf);\
2891 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2892 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2893 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2894 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2895 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2896 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2897 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2898 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2899 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2900 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2901 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2902 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2903 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2904 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2905 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2906 lpfc_link_state_store);
2907 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2908 lpfc_option_rom_version_show, NULL);
2909 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2910 lpfc_num_discovered_ports_show, NULL);
2911 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2912 static DEVICE_ATTR_RO(lpfc_drvr_version);
2913 static DEVICE_ATTR_RO(lpfc_enable_fip);
2914 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2915 lpfc_board_mode_show, lpfc_board_mode_store);
2916 static DEVICE_ATTR_RO(lpfc_xcvr_data);
2917 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2918 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2919 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2920 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2921 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2922 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2923 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2924 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2925 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2926 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2927 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2928 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2930 static DEVICE_ATTR(cmf_info, 0444, lpfc_cmf_info_show, NULL);
2934 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2936 * @cnt: Length of string.
2937 * @wwn: Array to receive converted wwn value.
2940 * -EINVAL if the buffer does not contain a valid wwn
2944 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2948 /* Count may include a LF at end of string */
2949 if (buf[cnt-1] == '\n')
2952 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2953 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2956 memset(wwn, 0, WWN_SZ);
2958 /* Validate and store the new name */
2959 for (i = 0, j = 0; i < 16; i++) {
2960 if ((*buf >= 'a') && (*buf <= 'f'))
2961 j = ((j << 4) | ((*buf++ - 'a') + 10));
2962 else if ((*buf >= 'A') && (*buf <= 'F'))
2963 j = ((j << 4) | ((*buf++ - 'A') + 10));
2964 else if ((*buf >= '0') && (*buf <= '9'))
2965 j = ((j << 4) | (*buf++ - '0'));
2969 wwn[i/2] = j & 0xff;
2978 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2979 * Optimized Access Storage (OAS) operations.
2980 * @dev: class device that is converted into a Scsi_host.
2981 * @attr: device attribute, not used.
2982 * @buf: buffer for passing information.
2988 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2991 struct Scsi_Host *shost = class_to_shost(dev);
2992 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2994 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2995 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2999 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
3000 * Optimized Access Storage (OAS) operations.
3001 * @dev: class device that is converted into a Scsi_host.
3002 * @attr: device attribute, not used.
3003 * @buf: buffer for passing information.
3004 * @count: Size of the data buffer.
3007 * -EINVAL count is invalid, invalid wwpn byte invalid
3008 * -EPERM oas is not supported by hba
3009 * value of count on success
3012 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
3013 const char *buf, size_t count)
3015 struct Scsi_Host *shost = class_to_shost(dev);
3016 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3017 unsigned int cnt = count;
3018 uint8_t wwpn[WWN_SZ];
3024 /* count may include a LF at end of string */
3025 if (buf[cnt-1] == '\n')
3028 rc = lpfc_wwn_set(buf, cnt, wwpn);
3032 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3033 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3034 if (wwn_to_u64(wwpn) == 0)
3035 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
3037 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
3038 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3039 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3042 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
3043 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
3046 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
3047 * Optimized Access Storage (OAS) operations.
3048 * @dev: class device that is converted into a Scsi_host.
3049 * @attr: device attribute, not used.
3050 * @buf: buffer for passing information.
3056 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3059 struct Scsi_Host *shost = class_to_shost(dev);
3060 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3062 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3066 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3067 * Optimized Access Storage (OAS) operations.
3068 * @dev: class device that is converted into a Scsi_host.
3069 * @attr: device attribute, not used.
3070 * @buf: buffer for passing information.
3071 * @count: Size of the data buffer.
3074 * -EINVAL count is invalid, invalid wwpn byte invalid
3075 * -EPERM oas is not supported by hba
3076 * value of count on success
3079 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3080 const char *buf, size_t count)
3082 struct Scsi_Host *shost = class_to_shost(dev);
3083 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3084 unsigned int cnt = count;
3091 /* count may include a LF at end of string */
3092 if (buf[cnt-1] == '\n')
3095 ret = kstrtoul(buf, 0, &val);
3096 if (ret || (val > 0x7f))
3100 phba->cfg_oas_priority = (uint8_t)val;
3102 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3105 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3106 lpfc_oas_priority_show, lpfc_oas_priority_store);
3109 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3110 * for Optimized Access Storage (OAS) operations.
3111 * @dev: class device that is converted into a Scsi_host.
3112 * @attr: device attribute, not used.
3113 * @buf: buffer for passing information.
3116 * value of count on success
3119 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3122 struct Scsi_Host *shost = class_to_shost(dev);
3123 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3125 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3126 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3130 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3131 * for Optimized Access Storage (OAS) operations.
3132 * @dev: class device that is converted into a Scsi_host.
3133 * @attr: device attribute, not used.
3134 * @buf: buffer for passing information.
3135 * @count: Size of the data buffer.
3138 * -EINVAL count is invalid, invalid wwpn byte invalid
3139 * -EPERM oas is not supported by hba
3140 * value of count on success
3143 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3144 const char *buf, size_t count)
3146 struct Scsi_Host *shost = class_to_shost(dev);
3147 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3148 unsigned int cnt = count;
3149 uint8_t wwpn[WWN_SZ];
3155 /* count may include a LF at end of string */
3156 if (buf[cnt-1] == '\n')
3159 rc = lpfc_wwn_set(buf, cnt, wwpn);
3163 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3164 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3165 if (wwn_to_u64(wwpn) == 0)
3166 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3168 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3169 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3170 if (phba->cfg_oas_priority == 0)
3171 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3172 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3175 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3176 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3179 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3180 * of whether luns will be enabled or disabled
3181 * for Optimized Access Storage (OAS) operations.
3182 * @dev: class device that is converted into a Scsi_host.
3183 * @attr: device attribute, not used.
3184 * @buf: buffer for passing information.
3187 * size of formatted string.
3190 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3193 struct Scsi_Host *shost = class_to_shost(dev);
3194 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3196 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3200 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3201 * of whether luns will be enabled or disabled
3202 * for Optimized Access Storage (OAS) operations.
3203 * @dev: class device that is converted into a Scsi_host.
3204 * @attr: device attribute, not used.
3205 * @buf: buffer for passing information.
3206 * @count: Size of the data buffer.
3209 * -EINVAL count is invalid, invalid wwpn byte invalid
3210 * -EPERM oas is not supported by hba
3211 * value of count on success
3214 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3215 const char *buf, size_t count)
3217 struct Scsi_Host *shost = class_to_shost(dev);
3218 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3224 if (!isdigit(buf[0]))
3227 if (sscanf(buf, "%i", &val) != 1)
3230 if ((val != 0) && (val != 1))
3233 phba->cfg_oas_lun_state = val;
3236 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3237 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3240 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3241 * Storage (OAS) lun returned by the
3242 * lpfc_oas_lun_show function.
3243 * @dev: class device that is converted into a Scsi_host.
3244 * @attr: device attribute, not used.
3245 * @buf: buffer for passing information.
3248 * size of formatted string.
3251 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3254 struct Scsi_Host *shost = class_to_shost(dev);
3255 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3257 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3260 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3262 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3263 lpfc_oas_lun_status_show, NULL);
3267 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3269 * @phba: lpfc_hba pointer.
3270 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3271 * @tgt_wwpn: wwpn of the target associated with the returned lun
3272 * @lun: the fc lun for setting oas state.
3273 * @oas_state: the oas state to be set to the lun.
3278 * -EPERM OAS is not enabled or not supported by this port.
3282 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3283 uint8_t tgt_wwpn[], uint64_t lun,
3284 uint32_t oas_state, uint8_t pri)
3293 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3294 (struct lpfc_name *)tgt_wwpn,
3298 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3299 (struct lpfc_name *)tgt_wwpn, lun, pri);
3306 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3307 * Access Storage (OAS) operations.
3308 * @phba: lpfc_hba pointer.
3309 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3310 * @tgt_wwpn: wwpn of the target associated with the returned lun
3311 * @lun_status: status of the lun returned lun
3312 * @lun_pri: priority of the lun returned lun
3314 * Returns the first or next lun enabled for OAS operations for the vport/target
3315 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3316 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3319 * lun that is OAS enabled for the vport/target
3320 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3323 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3324 uint8_t tgt_wwpn[], uint32_t *lun_status,
3329 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3330 return NOT_OAS_ENABLED_LUN;
3331 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3332 phba->sli4_hba.oas_next_vpt_wwpn,
3333 (struct lpfc_name *)
3334 phba->sli4_hba.oas_next_tgt_wwpn,
3335 &phba->sli4_hba.oas_next_lun,
3336 (struct lpfc_name *)vpt_wwpn,
3337 (struct lpfc_name *)tgt_wwpn,
3338 &found_lun, lun_status, lun_pri))
3341 return NOT_OAS_ENABLED_LUN;
3345 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3346 * @phba: lpfc_hba pointer.
3347 * @vpt_wwpn: vport wwpn by reference.
3348 * @tgt_wwpn: target wwpn by reference.
3349 * @lun: the fc lun for setting oas state.
3350 * @oas_state: the oas state to be set to the oas_lun.
3353 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3354 * a lun for OAS operations.
3358 * -ENOMEM: failed to enable an lun for OAS operations
3359 * -EPERM: OAS is not enabled
3362 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3363 uint8_t tgt_wwpn[], uint64_t lun,
3364 uint32_t oas_state, uint8_t pri)
3369 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3375 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3376 * @dev: class device that is converted into a Scsi_host.
3377 * @attr: device attribute, not used.
3378 * @buf: buffer for passing information.
3380 * This routine returns a lun enabled for OAS each time the function
3384 * SUCCESS: size of formatted string.
3385 * -EFAULT: target or vport wwpn was not set properly.
3386 * -EPERM: oas is not enabled.
3389 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3392 struct Scsi_Host *shost = class_to_shost(dev);
3393 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3401 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3402 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3405 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3406 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3409 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3410 phba->cfg_oas_tgt_wwpn,
3411 &phba->cfg_oas_lun_status,
3412 &phba->cfg_oas_priority);
3413 if (oas_lun != NOT_OAS_ENABLED_LUN)
3414 phba->cfg_oas_flags |= OAS_LUN_VALID;
3416 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3422 * lpfc_oas_lun_store - Sets the OAS state for lun
3423 * @dev: class device that is converted into a Scsi_host.
3424 * @attr: device attribute, not used.
3425 * @buf: buffer for passing information.
3426 * @count: size of the formatting string
3428 * This function sets the OAS state for lun. Before this function is called,
3429 * the vport wwpn, target wwpn, and oas state need to be set.
3432 * SUCCESS: size of formatted string.
3433 * -EFAULT: target or vport wwpn was not set properly.
3434 * -EPERM: oas is not enabled.
3435 * size of formatted string.
3438 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3439 const char *buf, size_t count)
3441 struct Scsi_Host *shost = class_to_shost(dev);
3442 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3450 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3453 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3456 if (!isdigit(buf[0]))
3459 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3462 pri = phba->cfg_oas_priority;
3464 pri = phba->cfg_XLanePriority;
3466 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3467 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3468 "priority 0x%x with oas state %d\n",
3469 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3470 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3471 pri, phba->cfg_oas_lun_state);
3473 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3474 phba->cfg_oas_tgt_wwpn, scsi_lun,
3475 phba->cfg_oas_lun_state, pri);
3481 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3482 lpfc_oas_lun_show, lpfc_oas_lun_store);
3484 int lpfc_enable_nvmet_cnt;
3485 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3486 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3487 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3488 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3489 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3491 static int lpfc_poll = 0;
3492 module_param(lpfc_poll, int, S_IRUGO);
3493 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3495 " 1 - poll with interrupts enabled"
3496 " 3 - poll and disable FCP ring interrupts");
3498 static DEVICE_ATTR_RW(lpfc_poll);
3500 int lpfc_no_hba_reset_cnt;
3501 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3502 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3503 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3504 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3506 LPFC_ATTR(sli_mode, 3, 3, 3,
3507 "SLI mode selector: 3 - select SLI-3");
3509 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3510 "Enable NPIV functionality");
3512 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3513 "FCF Fast failover=1 Priority failover=2");
3516 * lpfc_fcp_wait_abts_rsp: Modifies criteria for reporting completion of
3518 * The range is [0,1]. Default value is 0
3519 * 0, IO completes after ABTS issued (default).
3520 * 1, IO completes after receipt of ABTS response or timeout.
3522 LPFC_ATTR_R(fcp_wait_abts_rsp, 0, 0, 1, "Wait for FCP ABTS completion");
3525 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3526 # 0x0 = disabled, XRI/OXID use not tracked.
3527 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3528 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3530 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3531 "Enable RRQ functionality");
3534 # lpfc_suppress_link_up: Bring link up at initialization
3535 # 0x0 = bring link up (issue MBX_INIT_LINK)
3536 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3537 # 0x2 = never bring up link
3538 # Default value is 0.
3540 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3541 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3542 "Suppress Link Up at initialization");
3545 lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3547 struct Scsi_Host *shost = class_to_shost(dev);
3548 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3550 return scnprintf(buf, PAGE_SIZE, "%d\n",
3551 phba->sli4_hba.pc_sli4_params.pls);
3553 static DEVICE_ATTR(pls, 0444,
3554 lpfc_pls_show, NULL);
3557 lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3559 struct Scsi_Host *shost = class_to_shost(dev);
3560 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3562 return scnprintf(buf, PAGE_SIZE, "%d\n",
3563 (phba->hba_flag & HBA_PERSISTENT_TOPO) ? 1 : 0);
3565 static DEVICE_ATTR(pt, 0444,
3566 lpfc_pt_show, NULL);
3569 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3577 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3579 struct Scsi_Host *shost = class_to_shost(dev);
3580 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3582 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3585 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3586 lpfc_iocb_hw_show, NULL);
3588 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3590 struct Scsi_Host *shost = class_to_shost(dev);
3591 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3592 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3594 return scnprintf(buf, PAGE_SIZE, "%d\n",
3595 pring ? pring->txq_max : 0);
3598 static DEVICE_ATTR(txq_hw, S_IRUGO,
3599 lpfc_txq_hw_show, NULL);
3601 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3604 struct Scsi_Host *shost = class_to_shost(dev);
3605 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3606 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3608 return scnprintf(buf, PAGE_SIZE, "%d\n",
3609 pring ? pring->txcmplq_max : 0);
3612 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3613 lpfc_txcmplq_hw_show, NULL);
3616 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3617 # until the timer expires. Value range is [0,255]. Default value is 30.
3619 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3620 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3621 module_param(lpfc_nodev_tmo, int, 0);
3622 MODULE_PARM_DESC(lpfc_nodev_tmo,
3623 "Seconds driver will hold I/O waiting "
3624 "for a device to come back");
3627 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3628 * @dev: class converted to a Scsi_host structure.
3629 * @attr: device attribute, not used.
3630 * @buf: on return contains the dev loss timeout in decimal.
3632 * Returns: size of formatted string.
3635 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3638 struct Scsi_Host *shost = class_to_shost(dev);
3639 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3641 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3645 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3646 * @vport: lpfc vport structure pointer.
3647 * @val: contains the nodev timeout value.
3650 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3651 * a kernel error message is printed and zero is returned.
3652 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3653 * Otherwise nodev tmo is set to the default value.
3656 * zero if already set or if val is in range
3657 * -EINVAL val out of range
3660 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3662 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3663 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3664 if (val != LPFC_DEF_DEVLOSS_TMO)
3665 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3666 "0407 Ignoring lpfc_nodev_tmo module "
3667 "parameter because lpfc_devloss_tmo "
3672 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3673 vport->cfg_nodev_tmo = val;
3674 vport->cfg_devloss_tmo = val;
3677 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3678 "0400 lpfc_nodev_tmo attribute cannot be set to"
3679 " %d, allowed range is [%d, %d]\n",
3680 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3681 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3686 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3687 * @vport: lpfc vport structure pointer.
3690 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3693 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3695 struct Scsi_Host *shost;
3696 struct lpfc_nodelist *ndlp;
3697 #if (IS_ENABLED(CONFIG_NVME_FC))
3698 struct lpfc_nvme_rport *rport;
3699 struct nvme_fc_remote_port *remoteport = NULL;
3702 shost = lpfc_shost_from_vport(vport);
3703 spin_lock_irq(shost->host_lock);
3704 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3706 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3707 #if (IS_ENABLED(CONFIG_NVME_FC))
3708 spin_lock(&ndlp->lock);
3709 rport = lpfc_ndlp_get_nrport(ndlp);
3711 remoteport = rport->remoteport;
3712 spin_unlock(&ndlp->lock);
3713 if (rport && remoteport)
3714 nvme_fc_set_remoteport_devloss(remoteport,
3715 vport->cfg_devloss_tmo);
3718 spin_unlock_irq(shost->host_lock);
3722 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3723 * @vport: lpfc vport structure pointer.
3724 * @val: contains the tmo value.
3727 * If the devloss tmo is already set or the vport dev loss tmo has changed
3728 * then a kernel error message is printed and zero is returned.
3729 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3730 * Otherwise nodev tmo is set to the default value.
3733 * zero if already set or if val is in range
3734 * -EINVAL val out of range
3737 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3739 if (vport->dev_loss_tmo_changed ||
3740 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3741 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3742 "0401 Ignoring change to lpfc_nodev_tmo "
3743 "because lpfc_devloss_tmo is set.\n");
3746 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3747 vport->cfg_nodev_tmo = val;
3748 vport->cfg_devloss_tmo = val;
3750 * For compat: set the fc_host dev loss so new rports
3751 * will get the value.
3753 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3754 lpfc_update_rport_devloss_tmo(vport);
3757 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3758 "0403 lpfc_nodev_tmo attribute cannot be set to "
3759 "%d, allowed range is [%d, %d]\n",
3760 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3764 lpfc_vport_param_store(nodev_tmo)
3766 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3769 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3770 # disappear until the timer expires. Value range is [0,255]. Default
3773 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3774 MODULE_PARM_DESC(lpfc_devloss_tmo,
3775 "Seconds driver will hold I/O waiting "
3776 "for a device to come back");
3777 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3778 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3779 lpfc_vport_param_show(devloss_tmo)
3782 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3783 * @vport: lpfc vport structure pointer.
3784 * @val: contains the tmo value.
3787 * If val is in a valid range then set the vport nodev tmo,
3788 * devloss tmo, also set the vport dev loss tmo changed flag.
3789 * Else a kernel error message is printed.
3792 * zero if val is in range
3793 * -EINVAL val out of range
3796 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3798 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3799 vport->cfg_nodev_tmo = val;
3800 vport->cfg_devloss_tmo = val;
3801 vport->dev_loss_tmo_changed = 1;
3802 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3803 lpfc_update_rport_devloss_tmo(vport);
3807 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3808 "0404 lpfc_devloss_tmo attribute cannot be set to "
3809 "%d, allowed range is [%d, %d]\n",
3810 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3814 lpfc_vport_param_store(devloss_tmo)
3815 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3818 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3819 * lpfc_suppress_rsp = 0 Disable
3820 * lpfc_suppress_rsp = 1 Enable (default)
3823 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3824 "Enable suppress rsp feature is firmware supports it");
3827 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3828 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3829 * lpfc_nvmet_mrq = 1 use a single RQ pair
3830 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3833 LPFC_ATTR_R(nvmet_mrq,
3834 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3835 "Specify number of RQ pairs for processing NVMET cmds");
3838 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3839 * to each NVMET RQ. Range 64 to 2048, default is 512.
3841 LPFC_ATTR_R(nvmet_mrq_post,
3842 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3843 LPFC_NVMET_RQE_DEF_COUNT,
3844 "Specify number of RQ buffers to initially post");
3847 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3848 * Supported Values: 1 - register just FCP
3849 * 3 - register both FCP and NVME
3850 * Supported values are [1,3]. Default value is 3
3852 LPFC_ATTR_R(enable_fc4_type, LPFC_DEF_ENBL_FC4_TYPE,
3853 LPFC_ENABLE_FCP, LPFC_MAX_ENBL_FC4_TYPE,
3854 "Enable FC4 Protocol support - FCP / NVME");
3857 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3858 # deluged with LOTS of information.
3859 # You can set a bit mask to record specific types of verbose messages:
3860 # See lpfc_logmsh.h for definitions.
3862 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3863 "Verbose logging bit-mask");
3866 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3867 # objects that have been registered with the nameserver after login.
3869 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3870 "Deregister nameserver objects before LOGO");
3873 # lun_queue_depth: This parameter is used to limit the number of outstanding
3874 # commands per FCP LUN.
3876 LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
3877 "Max number of FCP commands we can queue to a specific LUN");
3880 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3881 # commands per target port. Value range is [10,65535]. Default value is 65535.
3883 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3884 module_param(lpfc_tgt_queue_depth, uint, 0444);
3885 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3886 lpfc_vport_param_show(tgt_queue_depth);
3887 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3888 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3891 * lpfc_tgt_queue_depth_set: Sets an attribute value.
3892 * @vport: lpfc vport structure pointer.
3893 * @val: integer attribute value.
3895 * Description: Sets the parameter to the new value.
3899 * -EINVAL if val is invalid
3902 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3904 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3905 struct lpfc_nodelist *ndlp;
3907 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3910 if (val == vport->cfg_tgt_queue_depth)
3913 spin_lock_irq(shost->host_lock);
3914 vport->cfg_tgt_queue_depth = val;
3916 /* Next loop thru nodelist and change cmd_qdepth */
3917 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3918 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3920 spin_unlock_irq(shost->host_lock);
3924 lpfc_vport_param_store(tgt_queue_depth);
3925 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3928 # hba_queue_depth: This parameter is used to limit the number of outstanding
3929 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3930 # value is greater than the maximum number of exchanges supported by the HBA,
3931 # then maximum number of exchanges supported by the HBA is used to determine
3932 # the hba_queue_depth.
3934 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3935 "Max number of FCP commands we can queue to a lpfc HBA");
3938 # peer_port_login: This parameter allows/prevents logins
3939 # between peer ports hosted on the same physical port.
3940 # When this parameter is set 0 peer ports of same physical port
3941 # are not allowed to login to each other.
3942 # When this parameter is set 1 peer ports of same physical port
3943 # are allowed to login to each other.
3944 # Default value of this parameter is 0.
3946 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3947 "Allow peer ports on the same physical port to login to each "
3951 # restrict_login: This parameter allows/prevents logins
3952 # between Virtual Ports and remote initiators.
3953 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3954 # other initiators and will attempt to PLOGI all remote ports.
3955 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3956 # remote ports and will not attempt to PLOGI to other initiators.
3957 # This parameter does not restrict to the physical port.
3958 # This parameter does not restrict logins to Fabric resident remote ports.
3959 # Default value of this parameter is 1.
3961 static int lpfc_restrict_login = 1;
3962 module_param(lpfc_restrict_login, int, S_IRUGO);
3963 MODULE_PARM_DESC(lpfc_restrict_login,
3964 "Restrict virtual ports login to remote initiators.");
3965 lpfc_vport_param_show(restrict_login);
3968 * lpfc_restrict_login_init - Set the vport restrict login flag
3969 * @vport: lpfc vport structure pointer.
3970 * @val: contains the restrict login value.
3973 * If val is not in a valid range then log a kernel error message and set
3974 * the vport restrict login to one.
3975 * If the port type is physical clear the restrict login flag and return.
3976 * Else set the restrict login flag to val.
3979 * zero if val is in range
3980 * -EINVAL val out of range
3983 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3985 if (val < 0 || val > 1) {
3986 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3987 "0422 lpfc_restrict_login attribute cannot "
3988 "be set to %d, allowed range is [0, 1]\n",
3990 vport->cfg_restrict_login = 1;
3993 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3994 vport->cfg_restrict_login = 0;
3997 vport->cfg_restrict_login = val;
4002 * lpfc_restrict_login_set - Set the vport restrict login flag
4003 * @vport: lpfc vport structure pointer.
4004 * @val: contains the restrict login value.
4007 * If val is not in a valid range then log a kernel error message and set
4008 * the vport restrict login to one.
4009 * If the port type is physical and the val is not zero log a kernel
4010 * error message, clear the restrict login flag and return zero.
4011 * Else set the restrict login flag to val.
4014 * zero if val is in range
4015 * -EINVAL val out of range
4018 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
4020 if (val < 0 || val > 1) {
4021 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4022 "0425 lpfc_restrict_login attribute cannot "
4023 "be set to %d, allowed range is [0, 1]\n",
4025 vport->cfg_restrict_login = 1;
4028 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
4029 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4030 "0468 lpfc_restrict_login must be 0 for "
4031 "Physical ports.\n");
4032 vport->cfg_restrict_login = 0;
4035 vport->cfg_restrict_login = val;
4038 lpfc_vport_param_store(restrict_login);
4039 static DEVICE_ATTR_RW(lpfc_restrict_login);
4042 # Some disk devices have a "select ID" or "select Target" capability.
4043 # From a protocol standpoint "select ID" usually means select the
4044 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
4045 # annex" which contains a table that maps a "select ID" (a number
4046 # between 0 and 7F) to an ALPA. By default, for compatibility with
4047 # older drivers, the lpfc driver scans this table from low ALPA to high
4050 # Turning on the scan-down variable (on = 1, off = 0) will
4051 # cause the lpfc driver to use an inverted table, effectively
4052 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
4054 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
4055 # and will not work across a fabric. Also this parameter will take
4056 # effect only in the case when ALPA map is not available.)
4058 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
4059 "Start scanning for devices from highest ALPA to lowest");
4062 # lpfc_topology: link topology for init link
4063 # 0x0 = attempt loop mode then point-to-point
4064 # 0x01 = internal loopback mode
4065 # 0x02 = attempt point-to-point mode only
4066 # 0x04 = attempt loop mode only
4067 # 0x06 = attempt point-to-point mode then loop
4068 # Set point-to-point mode if you want to run as an N_Port.
4069 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4070 # Default value is 0.
4072 LPFC_ATTR(topology, 0, 0, 6,
4073 "Select Fibre Channel topology");
4076 * lpfc_topology_store - Set the adapters topology field
4077 * @dev: class device that is converted into a scsi_host.
4078 * @attr:device attribute, not used.
4079 * @buf: buffer for passing information.
4080 * @count: size of the data buffer.
4083 * If val is in a valid range then set the adapter's topology field and
4084 * issue a lip; if the lip fails reset the topology to the old value.
4086 * If the value is not in range log a kernel error message and return an error.
4089 * zero if val is in range and lip okay
4090 * non-zero return value from lpfc_issue_lip()
4091 * -EINVAL val out of range
4094 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4095 const char *buf, size_t count)
4097 struct Scsi_Host *shost = class_to_shost(dev);
4098 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4099 struct lpfc_hba *phba = vport->phba;
4102 const char *val_buf = buf;
4105 u8 sli_family, if_type;
4107 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4109 val_buf = &buf[strlen("nolip ")];
4112 if (!isdigit(val_buf[0]))
4114 if (sscanf(val_buf, "%i", &val) != 1)
4117 if (val >= 0 && val <= 6) {
4118 prev_val = phba->cfg_topology;
4119 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4121 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4122 "3113 Loop mode not supported at speed %d\n",
4127 * The 'topology' is not a configurable parameter if :
4128 * - persistent topology enabled
4129 * - ASIC_GEN_NUM >= 0xC, with no private loop support
4131 sli_family = bf_get(lpfc_sli_intf_sli_family,
4132 &phba->sli4_hba.sli_intf);
4133 if_type = bf_get(lpfc_sli_intf_if_type,
4134 &phba->sli4_hba.sli_intf);
4135 if ((phba->hba_flag & HBA_PERSISTENT_TOPO ||
4136 (!phba->sli4_hba.pc_sli4_params.pls &&
4137 (sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
4138 if_type == LPFC_SLI_INTF_IF_TYPE_6))) &&
4140 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4141 "3114 Loop mode not supported\n");
4144 phba->cfg_topology = val;
4148 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4149 "3054 lpfc_topology changed from %d to %d\n",
4151 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4152 phba->fc_topology_changed = 1;
4153 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4155 phba->cfg_topology = prev_val;
4160 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4161 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4162 "allowed range is [0, 6]\n",
4167 lpfc_param_show(topology)
4168 static DEVICE_ATTR_RW(lpfc_topology);
4171 * lpfc_static_vport_show: Read callback function for
4172 * lpfc_static_vport sysfs file.
4173 * @dev: Pointer to class device object.
4174 * @attr: device attribute structure.
4175 * @buf: Data buffer.
4177 * This function is the read call back function for
4178 * lpfc_static_vport sysfs file. The lpfc_static_vport
4179 * sysfs file report the mageability of the vport.
4182 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4185 struct Scsi_Host *shost = class_to_shost(dev);
4186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4187 if (vport->vport_flag & STATIC_VPORT)
4188 sprintf(buf, "1\n");
4190 sprintf(buf, "0\n");
4196 * Sysfs attribute to control the statistical data collection.
4198 static DEVICE_ATTR_RO(lpfc_static_vport);
4201 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4203 # Value range is [0,16]. Default value is 0.
4206 * lpfc_link_speed_store - Set the adapters link speed
4207 * @dev: Pointer to class device.
4209 * @buf: Data buffer.
4210 * @count: Size of the data buffer.
4213 * If val is in a valid range then set the adapter's link speed field and
4214 * issue a lip; if the lip fails reset the link speed to the old value.
4217 * If the value is not in range log a kernel error message and return an error.
4220 * zero if val is in range and lip okay.
4221 * non-zero return value from lpfc_issue_lip()
4222 * -EINVAL val out of range
4225 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4226 const char *buf, size_t count)
4228 struct Scsi_Host *shost = class_to_shost(dev);
4229 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4230 struct lpfc_hba *phba = vport->phba;
4231 int val = LPFC_USER_LINK_SPEED_AUTO;
4233 const char *val_buf = buf;
4235 uint32_t prev_val, if_type;
4237 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4238 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4239 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4242 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4244 val_buf = &buf[strlen("nolip ")];
4247 if (!isdigit(val_buf[0]))
4249 if (sscanf(val_buf, "%i", &val) != 1)
4252 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4253 "3055 lpfc_link_speed changed from %d to %d %s\n",
4254 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4256 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4257 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4258 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4259 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4260 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4261 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4262 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4263 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4264 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4265 "2879 lpfc_link_speed attribute cannot be set "
4266 "to %d. Speed is not supported by this port.\n",
4270 if (val >= LPFC_USER_LINK_SPEED_16G &&
4271 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4272 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4273 "3112 lpfc_link_speed attribute cannot be set "
4274 "to %d. Speed is not supported in loop mode.\n",
4280 case LPFC_USER_LINK_SPEED_AUTO:
4281 case LPFC_USER_LINK_SPEED_1G:
4282 case LPFC_USER_LINK_SPEED_2G:
4283 case LPFC_USER_LINK_SPEED_4G:
4284 case LPFC_USER_LINK_SPEED_8G:
4285 case LPFC_USER_LINK_SPEED_16G:
4286 case LPFC_USER_LINK_SPEED_32G:
4287 case LPFC_USER_LINK_SPEED_64G:
4288 prev_val = phba->cfg_link_speed;
4289 phba->cfg_link_speed = val;
4293 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4295 phba->cfg_link_speed = prev_val;
4303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4304 "0469 lpfc_link_speed attribute cannot be set to %d, "
4305 "allowed values are [%s]\n",
4306 val, LPFC_LINK_SPEED_STRING);
4311 static int lpfc_link_speed = 0;
4312 module_param(lpfc_link_speed, int, S_IRUGO);
4313 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4314 lpfc_param_show(link_speed)
4317 * lpfc_link_speed_init - Set the adapters link speed
4318 * @phba: lpfc_hba pointer.
4319 * @val: link speed value.
4322 * If val is in a valid range then set the adapter's link speed field.
4325 * If the value is not in range log a kernel error message, clear the link
4326 * speed and return an error.
4329 * zero if val saved.
4330 * -EINVAL val out of range
4333 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4335 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4336 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4337 "3111 lpfc_link_speed of %d cannot "
4338 "support loop mode, setting topology to default.\n",
4340 phba->cfg_topology = 0;
4344 case LPFC_USER_LINK_SPEED_AUTO:
4345 case LPFC_USER_LINK_SPEED_1G:
4346 case LPFC_USER_LINK_SPEED_2G:
4347 case LPFC_USER_LINK_SPEED_4G:
4348 case LPFC_USER_LINK_SPEED_8G:
4349 case LPFC_USER_LINK_SPEED_16G:
4350 case LPFC_USER_LINK_SPEED_32G:
4351 case LPFC_USER_LINK_SPEED_64G:
4352 phba->cfg_link_speed = val;
4355 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4356 "0405 lpfc_link_speed attribute cannot "
4357 "be set to %d, allowed values are "
4358 "["LPFC_LINK_SPEED_STRING"]\n", val);
4359 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4364 static DEVICE_ATTR_RW(lpfc_link_speed);
4367 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4368 # 0 = aer disabled or not supported
4369 # 1 = aer supported and enabled (default)
4370 # Value range is [0,1]. Default value is 1.
4372 LPFC_ATTR(aer_support, 1, 0, 1,
4373 "Enable PCIe device AER support");
4374 lpfc_param_show(aer_support)
4377 * lpfc_aer_support_store - Set the adapter for aer support
4379 * @dev: class device that is converted into a Scsi_host.
4380 * @attr: device attribute, not used.
4381 * @buf: containing enable or disable aer flag.
4382 * @count: unused variable.
4385 * If the val is 1 and currently the device's AER capability was not
4386 * enabled, invoke the kernel's enable AER helper routine, trying to
4387 * enable the device's AER capability. If the helper routine enabling
4388 * AER returns success, update the device's cfg_aer_support flag to
4389 * indicate AER is supported by the device; otherwise, if the device
4390 * AER capability is already enabled to support AER, then do nothing.
4392 * If the val is 0 and currently the device's AER support was enabled,
4393 * invoke the kernel's disable AER helper routine. After that, update
4394 * the device's cfg_aer_support flag to indicate AER is not supported
4395 * by the device; otherwise, if the device AER capability is already
4396 * disabled from supporting AER, then do nothing.
4399 * length of the buf on success if val is in range the intended mode
4401 * -EINVAL if val out of range or intended mode is not supported.
4404 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4405 const char *buf, size_t count)
4407 struct Scsi_Host *shost = class_to_shost(dev);
4408 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4409 struct lpfc_hba *phba = vport->phba;
4410 int val = 0, rc = -EINVAL;
4412 if (!isdigit(buf[0]))
4414 if (sscanf(buf, "%i", &val) != 1)
4419 if (phba->hba_flag & HBA_AER_ENABLED) {
4420 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4422 spin_lock_irq(&phba->hbalock);
4423 phba->hba_flag &= ~HBA_AER_ENABLED;
4424 spin_unlock_irq(&phba->hbalock);
4425 phba->cfg_aer_support = 0;
4430 phba->cfg_aer_support = 0;
4435 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4436 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4438 spin_lock_irq(&phba->hbalock);
4439 phba->hba_flag |= HBA_AER_ENABLED;
4440 spin_unlock_irq(&phba->hbalock);
4441 phba->cfg_aer_support = 1;
4446 phba->cfg_aer_support = 1;
4457 static DEVICE_ATTR_RW(lpfc_aer_support);
4460 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4461 * @dev: class device that is converted into a Scsi_host.
4462 * @attr: device attribute, not used.
4463 * @buf: containing flag 1 for aer cleanup state.
4464 * @count: unused variable.
4467 * If the @buf contains 1 and the device currently has the AER support
4468 * enabled, then invokes the kernel AER helper routine
4469 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
4470 * error status register.
4475 * -EINVAL if the buf does not contain the 1 or the device is not currently
4476 * enabled with the AER support.
4479 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4480 const char *buf, size_t count)
4482 struct Scsi_Host *shost = class_to_shost(dev);
4483 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4484 struct lpfc_hba *phba = vport->phba;
4487 if (!isdigit(buf[0]))
4489 if (sscanf(buf, "%i", &val) != 1)
4494 if (phba->hba_flag & HBA_AER_ENABLED)
4495 rc = pci_aer_clear_nonfatal_status(phba->pcidev);
4503 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4504 lpfc_aer_cleanup_state);
4507 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4509 * @dev: class device that is converted into a Scsi_host.
4510 * @attr: device attribute, not used.
4511 * @buf: containing the string the number of vfs to be enabled.
4512 * @count: unused variable.
4515 * When this api is called either through user sysfs, the driver shall
4516 * try to enable or disable SR-IOV virtual functions according to the
4519 * If zero virtual function has been enabled to the physical function,
4520 * the driver shall invoke the pci enable virtual function api trying
4521 * to enable the virtual functions. If the nr_vfn provided is greater
4522 * than the maximum supported, the maximum virtual function number will
4523 * be used for invoking the api; otherwise, the nr_vfn provided shall
4524 * be used for invoking the api. If the api call returned success, the
4525 * actual number of virtual functions enabled will be set to the driver
4526 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4527 * cfg_sriov_nr_virtfn remains zero.
4529 * If none-zero virtual functions have already been enabled to the
4530 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4531 * -EINVAL will be returned and the driver does nothing;
4533 * If the nr_vfn provided is zero and none-zero virtual functions have
4534 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4535 * disabling virtual function api shall be invoded to disable all the
4536 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4537 * zero. Otherwise, if zero virtual function has been enabled, do
4541 * length of the buf on success if val is in range the intended mode
4543 * -EINVAL if val out of range or intended mode is not supported.
4546 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4547 const char *buf, size_t count)
4549 struct Scsi_Host *shost = class_to_shost(dev);
4550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4551 struct lpfc_hba *phba = vport->phba;
4552 struct pci_dev *pdev = phba->pcidev;
4553 int val = 0, rc = -EINVAL;
4555 /* Sanity check on user data */
4556 if (!isdigit(buf[0]))
4558 if (sscanf(buf, "%i", &val) != 1)
4563 /* Request disabling virtual functions */
4565 if (phba->cfg_sriov_nr_virtfn > 0) {
4566 pci_disable_sriov(pdev);
4567 phba->cfg_sriov_nr_virtfn = 0;
4572 /* Request enabling virtual functions */
4573 if (phba->cfg_sriov_nr_virtfn > 0) {
4574 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4575 "3018 There are %d virtual functions "
4576 "enabled on physical function.\n",
4577 phba->cfg_sriov_nr_virtfn);
4581 if (val <= LPFC_MAX_VFN_PER_PFN)
4582 phba->cfg_sriov_nr_virtfn = val;
4584 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4585 "3019 Enabling %d virtual functions is not "
4590 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4592 phba->cfg_sriov_nr_virtfn = 0;
4600 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4601 "Enable PCIe device SR-IOV virtual fn");
4603 lpfc_param_show(sriov_nr_virtfn)
4604 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4607 * lpfc_request_firmware_upgrade_store - Request for Linux generic firmware upgrade
4609 * @dev: class device that is converted into a Scsi_host.
4610 * @attr: device attribute, not used.
4611 * @buf: containing the string the number of vfs to be enabled.
4612 * @count: unused variable.
4617 * length of the buf on success if val is in range the intended mode
4619 * -EINVAL if val out of range or intended mode is not supported.
4622 lpfc_request_firmware_upgrade_store(struct device *dev,
4623 struct device_attribute *attr,
4624 const char *buf, size_t count)
4626 struct Scsi_Host *shost = class_to_shost(dev);
4627 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4628 struct lpfc_hba *phba = vport->phba;
4631 /* Sanity check on user data */
4632 if (!isdigit(buf[0]))
4634 if (sscanf(buf, "%i", &val) != 1)
4639 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4647 static int lpfc_req_fw_upgrade;
4648 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4649 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4650 lpfc_param_show(request_firmware_upgrade)
4653 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4654 * @phba: lpfc_hba pointer.
4658 * Set the initial Linux generic firmware upgrade enable or disable flag.
4661 * zero if val saved.
4662 * -EINVAL val out of range
4665 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4667 if (val >= 0 && val <= 1) {
4668 phba->cfg_request_firmware_upgrade = val;
4673 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4674 lpfc_request_firmware_upgrade_show,
4675 lpfc_request_firmware_upgrade_store);
4678 * lpfc_force_rscn_store
4680 * @dev: class device that is converted into a Scsi_host.
4681 * @attr: device attribute, not used.
4682 * @buf: unused string
4683 * @count: unused variable.
4686 * Force the switch to send a RSCN to all other NPorts in our zone
4687 * If we are direct connect pt2pt, build the RSCN command ourself
4688 * and send to the other NPort. Not supported for private loop.
4692 * -EIO - if command is not sent
4695 lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4696 const char *buf, size_t count)
4698 struct Scsi_Host *shost = class_to_shost(dev);
4699 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4702 i = lpfc_issue_els_rscn(vport, 0);
4709 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4710 * connected to the HBA.
4712 * Value range is any ascii value
4714 static int lpfc_force_rscn;
4715 module_param(lpfc_force_rscn, int, 0644);
4716 MODULE_PARM_DESC(lpfc_force_rscn,
4717 "Force an RSCN to be sent to all remote NPorts");
4718 lpfc_param_show(force_rscn)
4721 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4722 * @phba: lpfc_hba pointer.
4723 * @val: unused value.
4726 * zero if val saved.
4729 lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
4733 static DEVICE_ATTR_RW(lpfc_force_rscn);
4736 * lpfc_fcp_imax_store
4738 * @dev: class device that is converted into a Scsi_host.
4739 * @attr: device attribute, not used.
4740 * @buf: string with the number of fast-path FCP interrupts per second.
4741 * @count: unused variable.
4744 * If val is in a valid range [636,651042], then set the adapter's
4745 * maximum number of fast-path FCP interrupts per second.
4748 * length of the buf on success if val is in range the intended mode
4750 * -EINVAL if val out of range or intended mode is not supported.
4753 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4754 const char *buf, size_t count)
4756 struct Scsi_Host *shost = class_to_shost(dev);
4757 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4758 struct lpfc_hba *phba = vport->phba;
4759 struct lpfc_eq_intr_info *eqi;
4763 /* fcp_imax is only valid for SLI4 */
4764 if (phba->sli_rev != LPFC_SLI_REV4)
4767 /* Sanity check on user data */
4768 if (!isdigit(buf[0]))
4770 if (sscanf(buf, "%i", &val) != 1)
4774 * Value range for the HBA is [5000,5000000]
4775 * The value for each EQ depends on how many EQs are configured.
4778 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4781 phba->cfg_auto_imax = (val) ? 0 : 1;
4782 if (phba->cfg_fcp_imax && !val) {
4783 queue_delayed_work(phba->wq, &phba->eq_delay_work,
4784 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
4786 for_each_present_cpu(i) {
4787 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
4792 phba->cfg_fcp_imax = (uint32_t)val;
4794 if (phba->cfg_fcp_imax)
4795 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
4799 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4800 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4807 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4810 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4812 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4813 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4814 MODULE_PARM_DESC(lpfc_fcp_imax,
4815 "Set the maximum number of FCP interrupts per second per HBA");
4816 lpfc_param_show(fcp_imax)
4819 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4820 * @phba: lpfc_hba pointer.
4821 * @val: link speed value.
4824 * If val is in a valid range [636,651042], then initialize the adapter's
4825 * maximum number of fast-path FCP interrupts per second.
4828 * zero if val saved.
4829 * -EINVAL val out of range
4832 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4834 if (phba->sli_rev != LPFC_SLI_REV4) {
4835 phba->cfg_fcp_imax = 0;
4839 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4841 phba->cfg_fcp_imax = val;
4845 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4846 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4848 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4853 static DEVICE_ATTR_RW(lpfc_fcp_imax);
4856 * lpfc_cq_max_proc_limit_store
4858 * @dev: class device that is converted into a Scsi_host.
4859 * @attr: device attribute, not used.
4860 * @buf: string with the cq max processing limit of cqes
4861 * @count: unused variable.
4864 * If val is in a valid range, then set value on each cq
4867 * The length of the buf: if successful
4868 * -ERANGE: if val is not in the valid range
4869 * -EINVAL: if bad value format or intended mode is not supported.
4872 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
4873 const char *buf, size_t count)
4875 struct Scsi_Host *shost = class_to_shost(dev);
4876 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4877 struct lpfc_hba *phba = vport->phba;
4878 struct lpfc_queue *eq, *cq;
4882 /* cq_max_proc_limit is only valid for SLI4 */
4883 if (phba->sli_rev != LPFC_SLI_REV4)
4886 /* Sanity check on user data */
4887 if (!isdigit(buf[0]))
4889 if (kstrtoul(buf, 0, &val))
4892 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
4895 phba->cfg_cq_max_proc_limit = (uint32_t)val;
4897 /* set the values on the cq's */
4898 for (i = 0; i < phba->cfg_irq_chann; i++) {
4899 /* Get the EQ corresponding to the IRQ vector */
4900 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
4904 list_for_each_entry(cq, &eq->child_list, list)
4905 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
4913 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
4914 * itteration of CQ processing.
4916 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4917 module_param(lpfc_cq_max_proc_limit, int, 0644);
4918 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
4919 "Set the maximum number CQEs processed in an iteration of "
4921 lpfc_param_show(cq_max_proc_limit)
4924 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
4925 * single handler call which should request a polled completion rather
4926 * than re-enabling interrupts.
4928 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
4929 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
4930 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
4931 "CQE Processing Threshold to enable Polling");
4934 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
4935 * @phba: lpfc_hba pointer.
4939 * If val is in a valid range, then initialize the adapter's maximum
4943 * Always returns 0 for success, even if value not always set to
4944 * requested value. If value out of range or not supported, will fall
4948 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
4950 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4952 if (phba->sli_rev != LPFC_SLI_REV4)
4955 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
4956 phba->cfg_cq_max_proc_limit = val;
4960 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4961 "0371 lpfc_cq_max_proc_limit: %d out of range, using "
4963 phba->cfg_cq_max_proc_limit);
4968 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
4971 * lpfc_fcp_cpu_map_show - Display current driver CPU affinity
4972 * @dev: class converted to a Scsi_host structure.
4973 * @attr: device attribute, not used.
4974 * @buf: on return contains text describing the state of the link.
4976 * Returns: size of formatted string.
4979 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4982 struct Scsi_Host *shost = class_to_shost(dev);
4983 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4984 struct lpfc_hba *phba = vport->phba;
4985 struct lpfc_vector_map_info *cpup;
4988 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4989 (phba->intr_type != MSIX))
4992 switch (phba->cfg_fcp_cpu_map) {
4994 len += scnprintf(buf + len, PAGE_SIZE-len,
4995 "fcp_cpu_map: No mapping (%d)\n",
4996 phba->cfg_fcp_cpu_map);
4999 len += scnprintf(buf + len, PAGE_SIZE-len,
5000 "fcp_cpu_map: HBA centric mapping (%d): "
5001 "%d of %d CPUs online from %d possible CPUs\n",
5002 phba->cfg_fcp_cpu_map, num_online_cpus(),
5004 phba->sli4_hba.num_possible_cpu);
5008 while (phba->sli4_hba.curr_disp_cpu <
5009 phba->sli4_hba.num_possible_cpu) {
5010 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5012 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5013 len += scnprintf(buf + len, PAGE_SIZE - len,
5014 "CPU %02d not present\n",
5015 phba->sli4_hba.curr_disp_cpu);
5016 else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
5017 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5019 buf + len, PAGE_SIZE - len,
5020 "CPU %02d hdwq None "
5021 "physid %d coreid %d ht %d ua %d\n",
5022 phba->sli4_hba.curr_disp_cpu,
5023 cpup->phys_id, cpup->core_id,
5024 (cpup->flag & LPFC_CPU_MAP_HYPER),
5025 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5028 buf + len, PAGE_SIZE - len,
5029 "CPU %02d EQ None hdwq %04d "
5030 "physid %d coreid %d ht %d ua %d\n",
5031 phba->sli4_hba.curr_disp_cpu,
5032 cpup->hdwq, cpup->phys_id,
5034 (cpup->flag & LPFC_CPU_MAP_HYPER),
5035 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5037 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5039 buf + len, PAGE_SIZE - len,
5040 "CPU %02d hdwq None "
5041 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5042 phba->sli4_hba.curr_disp_cpu,
5045 (cpup->flag & LPFC_CPU_MAP_HYPER),
5046 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5047 lpfc_get_irq(cpup->eq));
5050 buf + len, PAGE_SIZE - len,
5051 "CPU %02d EQ %04d hdwq %04d "
5052 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5053 phba->sli4_hba.curr_disp_cpu,
5054 cpup->eq, cpup->hdwq, cpup->phys_id,
5056 (cpup->flag & LPFC_CPU_MAP_HYPER),
5057 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5058 lpfc_get_irq(cpup->eq));
5061 phba->sli4_hba.curr_disp_cpu++;
5063 /* display max number of CPUs keeping some margin */
5064 if (phba->sli4_hba.curr_disp_cpu <
5065 phba->sli4_hba.num_possible_cpu &&
5066 (len >= (PAGE_SIZE - 64))) {
5067 len += scnprintf(buf + len,
5068 PAGE_SIZE - len, "more...\n");
5073 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
5074 phba->sli4_hba.curr_disp_cpu = 0;
5080 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5081 * @dev: class device that is converted into a Scsi_host.
5082 * @attr: device attribute, not used.
5083 * @buf: one or more lpfc_polling_flags values.
5087 * -EINVAL - Not implemented yet.
5090 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5091 const char *buf, size_t count)
5097 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5100 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5101 # 0 - Do not affinitze IRQ vectors
5102 # 1 - Affintize HBA vectors with respect to each HBA
5103 # (start with CPU0 for each HBA)
5104 # This also defines how Hardware Queues are mapped to specific CPUs.
5106 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5107 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5108 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5109 "Defines how to map CPUs to IRQ vectors per HBA");
5112 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5113 * @phba: lpfc_hba pointer.
5114 * @val: link speed value.
5117 * If val is in a valid range [0-2], then affinitze the adapter's
5121 * zero if val saved.
5122 * -EINVAL val out of range
5125 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5127 if (phba->sli_rev != LPFC_SLI_REV4) {
5128 phba->cfg_fcp_cpu_map = 0;
5132 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5133 phba->cfg_fcp_cpu_map = val;
5137 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5138 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5140 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5145 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5148 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5149 # Value range is [2,3]. Default value is 3.
5151 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5152 "Select Fibre Channel class of service for FCP sequences");
5155 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5156 # is [0,1]. Default value is 1.
5158 LPFC_VPORT_ATTR_RW(use_adisc, 1, 0, 1,
5159 "Use ADISC on rediscovery to authenticate FCP devices");
5162 # lpfc_first_burst_size: First burst size to use on the NPorts
5163 # that support first burst.
5164 # Value range is [0,65536]. Default value is 0.
5166 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5167 "First burst size for Targets that support first burst");
5170 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5171 * When the driver is configured as an NVME target, this value is
5172 * communicated to the NVME initiator in the PRLI response. It is
5173 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5174 * parameters are set and the target is sending the PRLI RSP.
5175 * Parameter supported on physical port only - no NPIV support.
5176 * Value range is [0,65536]. Default value is 0.
5178 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5179 "NVME Target mode first burst size in 512B increments.");
5182 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5183 * For the Initiator (I), enabling this parameter means that an NVMET
5184 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5185 * processed by the initiator for subsequent NVME FCP IO.
5186 * Currently, this feature is not supported on the NVME target
5187 * Value range is [0,1]. Default value is 0 (disabled).
5189 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5190 "Enable First Burst feature for NVME Initiator.");
5193 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5194 # depth. Default value is 0. When the value of this parameter is zero the
5195 # SCSI command completion time is not used for controlling I/O queue depth. When
5196 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5197 # to limit the I/O completion time to the parameter value.
5198 # The value is set in milliseconds.
5200 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5201 "Use command completion time to control queue depth");
5203 lpfc_vport_param_show(max_scsicmpl_time);
5205 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5207 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5208 struct lpfc_nodelist *ndlp, *next_ndlp;
5210 if (val == vport->cfg_max_scsicmpl_time)
5212 if ((val < 0) || (val > 60000))
5214 vport->cfg_max_scsicmpl_time = val;
5216 spin_lock_irq(shost->host_lock);
5217 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5218 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5220 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5222 spin_unlock_irq(shost->host_lock);
5225 lpfc_vport_param_store(max_scsicmpl_time);
5226 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5229 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5230 # range is [0,1]. Default value is 0.
5232 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5235 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5236 # range is [0,1]. Default value is 1.
5238 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5241 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5242 * range is [0,1]. Default value is 0.
5243 * For [0], FCP commands are issued to Work Queues based on upper layer
5244 * hardware queue index.
5245 * For [1], FCP commands are issued to a Work Queue associated with the
5248 * LPFC_FCP_SCHED_BY_HDWQ == 0
5249 * LPFC_FCP_SCHED_BY_CPU == 1
5251 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5252 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5253 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5254 * through WQs will be used.
5256 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5257 LPFC_FCP_SCHED_BY_HDWQ,
5258 LPFC_FCP_SCHED_BY_CPU,
5259 "Determine scheduling algorithm for "
5260 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5263 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5264 * range is [0,1]. Default value is 0.
5265 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5266 * For [1], GID_PT is used for NameServer queries after RSCN
5269 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5270 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5271 "Determine algorithm NameServer queries after RSCN "
5272 "[0] - GID_FT, [1] - GID_PT");
5275 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5276 # range is [0,1]. Default value is 0.
5277 # For [0], bus reset issues target reset to ALL devices
5278 # For [1], bus reset issues target reset to non-FCP2 devices
5280 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5281 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5285 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5286 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5287 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5288 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5289 # cr_delay is set to 0.
5291 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5292 "interrupt response is generated");
5294 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5295 "interrupt response is generated");
5298 # lpfc_multi_ring_support: Determines how many rings to spread available
5299 # cmd/rsp IOCB entries across.
5300 # Value range is [1,2]. Default value is 1.
5302 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5303 "SLI rings to spread IOCB entries across");
5306 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5307 # identifies what rctl value to configure the additional ring for.
5308 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5310 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5311 255, "Identifies RCTL for additional ring configuration");
5314 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5315 # identifies what type value to configure the additional ring for.
5316 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5318 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5319 255, "Identifies TYPE for additional ring configuration");
5322 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5323 # 0 = SmartSAN functionality disabled (default)
5324 # 1 = SmartSAN functionality enabled
5325 # This parameter will override the value of lpfc_fdmi_on module parameter.
5326 # Value range is [0,1]. Default value is 0.
5328 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5331 # lpfc_fdmi_on: Controls FDMI support.
5333 # 1 Traditional FDMI support (default)
5334 # Traditional FDMI support means the driver will assume FDMI-2 support;
5335 # however, if that fails, it will fallback to FDMI-1.
5336 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5337 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5339 # Value range [0,1]. Default value is 1.
5341 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5344 # Specifies the maximum number of ELS cmds we can have outstanding (for
5345 # discovery). Value range is [1,64]. Default value = 32.
5347 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5348 "during discovery");
5351 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5352 # will be scanned by the SCSI midlayer when sequential scanning is
5353 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5354 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5355 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5356 # above. The lpfc driver limits the default value to 255 for two reasons.
5357 # As it bounds the sequential scan loop, scanning for thousands of luns
5358 # on a target can take minutes of wall clock time. Additionally,
5359 # there are FC targets, such as JBODs, that only recognize 8-bits of
5360 # LUN ID. When they receive a value greater than 8 bits, they chop off
5361 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5362 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5363 # valid responses at each of the LUN IDs, to believe there are multiple
5364 # devices present, when in fact, there is only 1.
5365 # A customer that is aware of their target behaviors, and the results as
5366 # indicated above, is welcome to increase the lpfc_max_luns value.
5367 # As mentioned, this value is not used by the lpfc driver, only the
5369 # Value range is [0,65535]. Default value is 255.
5370 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5372 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5375 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5376 # Value range is [1,255], default value is 10.
5378 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5379 "Milliseconds driver will wait between polling FCP ring");
5382 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5383 # to complete in seconds. Value range is [5,180], default value is 60.
5385 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5386 "Maximum time to wait for task management commands to complete");
5388 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5389 # support this feature
5392 # 2 = MSI-X enabled (default)
5393 # Value range is [0,2]. Default value is 2.
5395 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5396 "MSI-X (2), if possible");
5399 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5401 * 0 = NVME OAS disabled
5402 * 1 = NVME OAS enabled
5404 * Value range is [0,1]. Default value is 0.
5406 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5407 "Use OAS bit on NVME IOs");
5410 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5412 * 0 = Put NVME Command in SGL
5413 * 1 = Embed NVME Command in WQE (unless G7)
5414 * 2 = Embed NVME Command in WQE (force)
5416 * Value range is [0,2]. Default value is 1.
5418 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5419 "Embed NVME Command in WQE");
5422 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5423 * the driver will advertise it supports to the SCSI layer.
5425 * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
5426 * 1,256 = Manually specify nr_hw_queue value to be advertised,
5428 * Value range is [0,256]. Default value is 8.
5430 LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5431 LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5432 "Set the number of SCSI Queues advertised");
5435 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5436 * will advertise it supports to the NVME and SCSI layers. This also
5437 * will map to the number of CQ/WQ pairs the driver will create.
5439 * The NVME Layer will try to create this many, plus 1 administrative
5440 * hardware queue. The administrative queue will always map to WQ 0
5441 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5443 * 0 = Configure the number of hdw queues to the number of active CPUs.
5444 * 1,256 = Manually specify how many hdw queues to use.
5446 * Value range is [0,256]. Default value is 0.
5448 LPFC_ATTR_R(hdw_queue,
5450 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5451 "Set the number of I/O Hardware Queues");
5453 #if IS_ENABLED(CONFIG_X86)
5455 * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
5457 * @phba: Pointer to HBA context object.
5460 lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)
5462 unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;
5463 const struct cpumask *sibling_mask;
5464 struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;
5466 cpumask_clear(aff_mask);
5468 if (phba->irq_chann_mode == NUMA_MODE) {
5469 /* Check if we're a NUMA architecture */
5470 numa_node = dev_to_node(&phba->pcidev->dev);
5471 if (numa_node == NUMA_NO_NODE) {
5472 phba->irq_chann_mode = NORMAL_MODE;
5477 for_each_possible_cpu(cpu) {
5478 switch (phba->irq_chann_mode) {
5480 if (cpu_to_node(cpu) == numa_node)
5481 cpumask_set_cpu(cpu, aff_mask);
5484 sibling_mask = topology_sibling_cpumask(cpu);
5485 first_cpu = cpumask_first(sibling_mask);
5486 if (first_cpu < nr_cpu_ids)
5487 cpumask_set_cpu(first_cpu, aff_mask);
5497 lpfc_assign_default_irq_chann(struct lpfc_hba *phba)
5499 #if IS_ENABLED(CONFIG_X86)
5500 switch (boot_cpu_data.x86_vendor) {
5501 case X86_VENDOR_AMD:
5502 /* If AMD architecture, then default is NUMA_MODE */
5503 phba->irq_chann_mode = NUMA_MODE;
5505 case X86_VENDOR_INTEL:
5506 /* If Intel architecture, then default is no hyperthread mode */
5507 phba->irq_chann_mode = NHT_MODE;
5510 phba->irq_chann_mode = NORMAL_MODE;
5513 lpfc_cpumask_irq_mode_init(phba);
5515 phba->irq_chann_mode = NORMAL_MODE;
5520 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5521 * for Hardware Queues to utilize. This also will map to the number
5522 * of EQ / MSI-X vectors the driver will create. This should never be
5523 * more than the number of Hardware Queues
5525 * 0 = Configure number of IRQ Channels to:
5526 * if AMD architecture, number of CPUs on HBA's NUMA node
5527 * if Intel architecture, number of physical CPUs.
5528 * otherwise, number of active CPUs.
5529 * [1,256] = Manually specify how many IRQ Channels to use.
5531 * Value range is [0,256]. Default value is [0].
5533 static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
5534 module_param(lpfc_irq_chann, uint, 0444);
5535 MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
5537 /* lpfc_irq_chann_init - Set the hba irq_chann initial value
5538 * @phba: lpfc_hba pointer.
5539 * @val: contains the initial value
5542 * Validates the initial value is within range and assigns it to the
5543 * adapter. If not in range, an error message is posted and the
5544 * default value is assigned.
5547 * zero if value is in range and is set
5548 * -EINVAL if value was out of range
5551 lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
5553 const struct cpumask *aff_mask;
5555 if (phba->cfg_use_msi != 2) {
5556 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5557 "8532 use_msi = %u ignoring cfg_irq_numa\n",
5559 phba->irq_chann_mode = NORMAL_MODE;
5560 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5564 /* Check if default setting was passed */
5565 if (val == LPFC_IRQ_CHANN_DEF &&
5566 phba->cfg_hdw_queue == LPFC_HBA_HDWQ_DEF &&
5567 phba->sli_rev == LPFC_SLI_REV4)
5568 lpfc_assign_default_irq_chann(phba);
5570 if (phba->irq_chann_mode != NORMAL_MODE) {
5571 aff_mask = &phba->sli4_hba.irq_aff_mask;
5573 if (cpumask_empty(aff_mask)) {
5574 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5575 "8533 Could not identify CPUS for "
5576 "mode %d, ignoring\n",
5577 phba->irq_chann_mode);
5578 phba->irq_chann_mode = NORMAL_MODE;
5579 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5581 phba->cfg_irq_chann = cpumask_weight(aff_mask);
5583 /* If no hyperthread mode, then set hdwq count to
5584 * aff_mask weight as well
5586 if (phba->irq_chann_mode == NHT_MODE)
5587 phba->cfg_hdw_queue = phba->cfg_irq_chann;
5589 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5590 "8543 lpfc_irq_chann set to %u "
5591 "(mode: %d)\n", phba->cfg_irq_chann,
5592 phba->irq_chann_mode);
5595 if (val > LPFC_IRQ_CHANN_MAX) {
5596 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5597 "8545 lpfc_irq_chann attribute cannot "
5598 "be set to %u, allowed range is "
5602 LPFC_IRQ_CHANN_MAX);
5603 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5606 if (phba->sli_rev == LPFC_SLI_REV4) {
5607 phba->cfg_irq_chann = val;
5609 phba->cfg_irq_chann = 2;
5610 phba->cfg_hdw_queue = 1;
5618 * lpfc_irq_chann_show - Display value of irq_chann
5619 * @dev: class converted to a Scsi_host structure.
5620 * @attr: device attribute, not used.
5621 * @buf: on return contains a string with the list sizes
5623 * Returns: size of formatted string.
5626 lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
5629 struct Scsi_Host *shost = class_to_shost(dev);
5630 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5631 struct lpfc_hba *phba = vport->phba;
5633 return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
5636 static DEVICE_ATTR_RO(lpfc_irq_chann);
5639 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5640 # 0 = HBA resets disabled
5641 # 1 = HBA resets enabled (default)
5642 # 2 = HBA reset via PCI bus reset enabled
5643 # Value range is [0,2]. Default value is 1.
5645 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5648 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5649 # 0 = HBA Heartbeat disabled
5650 # 1 = HBA Heartbeat enabled (default)
5651 # Value range is [0,1]. Default value is 1.
5653 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5656 # lpfc_EnableXLane: Enable Express Lane Feature
5657 # 0x0 Express Lane Feature disabled
5658 # 0x1 Express Lane Feature enabled
5659 # Value range is [0,1]. Default value is 0.
5661 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5664 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5665 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5666 # Value range is [0x0,0x7f]. Default value is 0
5668 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5671 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5672 # 0 = BlockGuard disabled (default)
5673 # 1 = BlockGuard enabled
5674 # Value range is [0,1]. Default value is 0.
5676 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5680 # - Bit mask of host protection capabilities used to register with the
5682 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5683 # - Allows you to ultimately specify which profiles to use
5684 # - Default will result in registering capabilities for all profiles.
5685 # - SHOST_DIF_TYPE1_PROTECTION 1
5686 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5687 # - SHOST_DIX_TYPE0_PROTECTION 8
5688 # HBA supports DIX Type 0: Host to HBA protection only
5689 # - SHOST_DIX_TYPE1_PROTECTION 16
5690 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5693 LPFC_ATTR(prot_mask,
5694 (SHOST_DIF_TYPE1_PROTECTION |
5695 SHOST_DIX_TYPE0_PROTECTION |
5696 SHOST_DIX_TYPE1_PROTECTION),
5698 (SHOST_DIF_TYPE1_PROTECTION |
5699 SHOST_DIX_TYPE0_PROTECTION |
5700 SHOST_DIX_TYPE1_PROTECTION),
5701 "T10-DIF host protection capabilities mask");
5705 # - Bit mask of protection guard types to register with the SCSI mid-layer
5706 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5707 # - Allows you to ultimately specify which profiles to use
5708 # - Default will result in registering capabilities for all guard types
5711 LPFC_ATTR(prot_guard,
5712 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5713 "T10-DIF host protection guard type");
5716 * Delay initial NPort discovery when Clean Address bit is cleared in
5717 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5718 * This parameter can have value 0 or 1.
5719 * When this parameter is set to 0, no delay is added to the initial
5721 * When this parameter is set to non-zero value, initial Nport discovery is
5722 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5723 * accept and FCID/Fabric name/Fabric portname is changed.
5724 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5725 * when Clean Address bit is cleared in FLOGI/FDISC
5726 * accept and FCID/Fabric name/Fabric portname is changed.
5727 * Default value is 0.
5729 LPFC_ATTR(delay_discovery, 0, 0, 1,
5730 "Delay NPort discovery when Clean Address bit is cleared.");
5733 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5734 * This value can be set to values between 64 and 4096. The default value
5735 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5736 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5737 * Because of the additional overhead involved in setting up T10-DIF,
5738 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5739 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5741 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5742 module_param(lpfc_sg_seg_cnt, uint, 0444);
5743 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5746 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5747 * configured for the adapter
5748 * @dev: class converted to a Scsi_host structure.
5749 * @attr: device attribute, not used.
5750 * @buf: on return contains a string with the list sizes
5752 * Returns: size of formatted string.
5755 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5758 struct Scsi_Host *shost = class_to_shost(dev);
5759 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5760 struct lpfc_hba *phba = vport->phba;
5763 len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
5764 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5766 len += scnprintf(buf + len, PAGE_SIZE - len,
5767 "Cfg: %d SCSI: %d NVME: %d\n",
5768 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5769 phba->cfg_nvme_seg_cnt);
5773 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5776 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5777 * @phba: lpfc_hba pointer.
5778 * @val: contains the initial value
5781 * Validates the initial value is within range and assigns it to the
5782 * adapter. If not in range, an error message is posted and the
5783 * default value is assigned.
5786 * zero if value is in range and is set
5787 * -EINVAL if value was out of range
5790 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5792 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5793 phba->cfg_sg_seg_cnt = val;
5796 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5797 "0409 lpfc_sg_seg_cnt attribute cannot be set to %d, "
5798 "allowed range is [%d, %d]\n",
5799 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5800 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5805 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5806 * 0 = MDS Diagnostics disabled (default)
5807 * 1 = MDS Diagnostics enabled
5808 * Value range is [0,1]. Default value is 0.
5810 LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5813 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5814 * 0 = Disable firmware logging (default)
5815 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
5816 * Value range [0..4]. Default value is 0
5818 LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5819 lpfc_param_show(ras_fwlog_buffsize);
5822 lpfc_ras_fwlog_buffsize_set(struct lpfc_hba *phba, uint val)
5825 enum ras_state state;
5827 if (!lpfc_rangecheck(val, 0, 4))
5830 if (phba->cfg_ras_fwlog_buffsize == val)
5833 if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
5836 spin_lock_irq(&phba->hbalock);
5837 state = phba->ras_fwlog.state;
5838 spin_unlock_irq(&phba->hbalock);
5840 if (state == REG_INPROGRESS) {
5841 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
5842 "registration is in progress\n");
5846 /* For disable logging: stop the logs and free the DMA.
5847 * For ras_fwlog_buffsize size change we still need to free and
5848 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
5850 phba->cfg_ras_fwlog_buffsize = val;
5851 if (state == ACTIVE) {
5852 lpfc_ras_stop_fwlog(phba);
5853 lpfc_sli4_ras_dma_free(phba);
5856 lpfc_sli4_ras_init(phba);
5857 if (phba->ras_fwlog.ras_enabled)
5858 ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
5859 LPFC_RAS_ENABLE_LOGGING);
5863 lpfc_param_store(ras_fwlog_buffsize);
5864 static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
5867 * lpfc_ras_fwlog_level: Firmware logging verbosity level
5868 * Valid only if firmware logging is enabled
5869 * 0(Least Verbosity) 4 (most verbosity)
5870 * Value range is [0..4]. Default value is 0
5872 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5875 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5876 * Default function which has RAS support : 0
5877 * Value Range is [0..7].
5878 * FW logging is a global action and enablement is via a specific
5881 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
5884 * lpfc_enable_bbcr: Enable BB Credit Recovery
5885 * 0 = BB Credit Recovery disabled
5886 * 1 = BB Credit Recovery enabled (default)
5887 * Value range is [0,1]. Default value is 1.
5889 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5891 /* Signaling module parameters */
5892 int lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
5893 module_param(lpfc_fabric_cgn_frequency, int, 0444);
5894 MODULE_PARM_DESC(lpfc_fabric_cgn_frequency, "Congestion signaling fabric freq");
5896 int lpfc_acqe_cgn_frequency = 10; /* 10 sec default */
5897 module_param(lpfc_acqe_cgn_frequency, int, 0444);
5898 MODULE_PARM_DESC(lpfc_acqe_cgn_frequency, "Congestion signaling ACQE freq");
5900 int lpfc_use_cgn_signal = 1; /* 0 - only use FPINs, 1 - Use signals if avail */
5901 module_param(lpfc_use_cgn_signal, int, 0444);
5902 MODULE_PARM_DESC(lpfc_use_cgn_signal, "Use Congestion signaling if available");
5905 * lpfc_enable_dpp: Enable DPP on G7
5906 * 0 = DPP on G7 disabled
5907 * 1 = DPP on G7 enabled (default)
5908 * Value range is [0,1]. Default value is 1.
5910 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5913 * lpfc_enable_mi: Enable FDMI MIB
5915 * 1 = enabled (default)
5916 * Value range is [0,1].
5918 LPFC_ATTR_R(enable_mi, 1, 0, 1, "Enable MI");
5921 * lpfc_max_vmid: Maximum number of VMs to be tagged. This is valid only if
5922 * either vmid_app_header or vmid_priority_tagging is enabled.
5923 * 4 - 255 = vmid support enabled for 4-255 VMs
5924 * Value range is [4,255].
5926 LPFC_ATTR_RW(max_vmid, LPFC_MIN_VMID, LPFC_MIN_VMID, LPFC_MAX_VMID,
5927 "Maximum number of VMs supported");
5930 * lpfc_vmid_inactivity_timeout: Inactivity timeout duration in hours
5931 * 0 = Timeout is disabled
5932 * Value range is [0,24].
5934 LPFC_ATTR_RW(vmid_inactivity_timeout, 4, 0, 24,
5935 "Inactivity timeout in hours");
5938 * lpfc_vmid_app_header: Enable App Header VMID support
5939 * 0 = Support is disabled (default)
5940 * 1 = Support is enabled
5941 * Value range is [0,1].
5943 LPFC_ATTR_RW(vmid_app_header, LPFC_VMID_APP_HEADER_DISABLE,
5944 LPFC_VMID_APP_HEADER_DISABLE, LPFC_VMID_APP_HEADER_ENABLE,
5945 "Enable App Header VMID support");
5948 * lpfc_vmid_priority_tagging: Enable Priority Tagging VMID support
5949 * 0 = Support is disabled (default)
5950 * 1 = Allow supported targets only
5951 * 2 = Allow all targets
5952 * Value range is [0,2].
5954 LPFC_ATTR_RW(vmid_priority_tagging, LPFC_VMID_PRIO_TAG_DISABLE,
5955 LPFC_VMID_PRIO_TAG_DISABLE,
5956 LPFC_VMID_PRIO_TAG_ALL_TARGETS,
5957 "Enable Priority Tagging VMID support");
5959 static struct attribute *lpfc_hba_attrs[] = {
5960 &dev_attr_nvme_info.attr,
5961 &dev_attr_scsi_stat.attr,
5962 &dev_attr_bg_info.attr,
5963 &dev_attr_bg_guard_err.attr,
5964 &dev_attr_bg_apptag_err.attr,
5965 &dev_attr_bg_reftag_err.attr,
5966 &dev_attr_info.attr,
5967 &dev_attr_serialnum.attr,
5968 &dev_attr_modeldesc.attr,
5969 &dev_attr_modelname.attr,
5970 &dev_attr_programtype.attr,
5971 &dev_attr_portnum.attr,
5972 &dev_attr_fwrev.attr,
5974 &dev_attr_option_rom_version.attr,
5975 &dev_attr_link_state.attr,
5976 &dev_attr_num_discovered_ports.attr,
5977 &dev_attr_lpfc_drvr_version.attr,
5978 &dev_attr_lpfc_enable_fip.attr,
5979 &dev_attr_lpfc_temp_sensor.attr,
5980 &dev_attr_lpfc_log_verbose.attr,
5981 &dev_attr_lpfc_lun_queue_depth.attr,
5982 &dev_attr_lpfc_tgt_queue_depth.attr,
5983 &dev_attr_lpfc_hba_queue_depth.attr,
5984 &dev_attr_lpfc_peer_port_login.attr,
5985 &dev_attr_lpfc_nodev_tmo.attr,
5986 &dev_attr_lpfc_devloss_tmo.attr,
5987 &dev_attr_lpfc_enable_fc4_type.attr,
5988 &dev_attr_lpfc_fcp_class.attr,
5989 &dev_attr_lpfc_use_adisc.attr,
5990 &dev_attr_lpfc_first_burst_size.attr,
5991 &dev_attr_lpfc_ack0.attr,
5992 &dev_attr_lpfc_xri_rebalancing.attr,
5993 &dev_attr_lpfc_topology.attr,
5994 &dev_attr_lpfc_scan_down.attr,
5995 &dev_attr_lpfc_link_speed.attr,
5996 &dev_attr_lpfc_fcp_io_sched.attr,
5997 &dev_attr_lpfc_ns_query.attr,
5998 &dev_attr_lpfc_fcp2_no_tgt_reset.attr,
5999 &dev_attr_lpfc_cr_delay.attr,
6000 &dev_attr_lpfc_cr_count.attr,
6001 &dev_attr_lpfc_multi_ring_support.attr,
6002 &dev_attr_lpfc_multi_ring_rctl.attr,
6003 &dev_attr_lpfc_multi_ring_type.attr,
6004 &dev_attr_lpfc_fdmi_on.attr,
6005 &dev_attr_lpfc_enable_SmartSAN.attr,
6006 &dev_attr_lpfc_max_luns.attr,
6007 &dev_attr_lpfc_enable_npiv.attr,
6008 &dev_attr_lpfc_fcf_failover_policy.attr,
6009 &dev_attr_lpfc_enable_rrq.attr,
6010 &dev_attr_lpfc_fcp_wait_abts_rsp.attr,
6011 &dev_attr_nport_evt_cnt.attr,
6012 &dev_attr_board_mode.attr,
6013 &dev_attr_lpfc_xcvr_data.attr,
6014 &dev_attr_max_vpi.attr,
6015 &dev_attr_used_vpi.attr,
6016 &dev_attr_max_rpi.attr,
6017 &dev_attr_used_rpi.attr,
6018 &dev_attr_max_xri.attr,
6019 &dev_attr_used_xri.attr,
6020 &dev_attr_npiv_info.attr,
6021 &dev_attr_issue_reset.attr,
6022 &dev_attr_lpfc_poll.attr,
6023 &dev_attr_lpfc_poll_tmo.attr,
6024 &dev_attr_lpfc_task_mgmt_tmo.attr,
6025 &dev_attr_lpfc_use_msi.attr,
6026 &dev_attr_lpfc_nvme_oas.attr,
6027 &dev_attr_lpfc_nvme_embed_cmd.attr,
6028 &dev_attr_lpfc_fcp_imax.attr,
6029 &dev_attr_lpfc_force_rscn.attr,
6030 &dev_attr_lpfc_cq_poll_threshold.attr,
6031 &dev_attr_lpfc_cq_max_proc_limit.attr,
6032 &dev_attr_lpfc_fcp_cpu_map.attr,
6033 &dev_attr_lpfc_fcp_mq_threshold.attr,
6034 &dev_attr_lpfc_hdw_queue.attr,
6035 &dev_attr_lpfc_irq_chann.attr,
6036 &dev_attr_lpfc_suppress_rsp.attr,
6037 &dev_attr_lpfc_nvmet_mrq.attr,
6038 &dev_attr_lpfc_nvmet_mrq_post.attr,
6039 &dev_attr_lpfc_nvme_enable_fb.attr,
6040 &dev_attr_lpfc_nvmet_fb_size.attr,
6041 &dev_attr_lpfc_enable_bg.attr,
6042 &dev_attr_lpfc_enable_hba_reset.attr,
6043 &dev_attr_lpfc_enable_hba_heartbeat.attr,
6044 &dev_attr_lpfc_EnableXLane.attr,
6045 &dev_attr_lpfc_XLanePriority.attr,
6046 &dev_attr_lpfc_xlane_lun.attr,
6047 &dev_attr_lpfc_xlane_tgt.attr,
6048 &dev_attr_lpfc_xlane_vpt.attr,
6049 &dev_attr_lpfc_xlane_lun_state.attr,
6050 &dev_attr_lpfc_xlane_lun_status.attr,
6051 &dev_attr_lpfc_xlane_priority.attr,
6052 &dev_attr_lpfc_sg_seg_cnt.attr,
6053 &dev_attr_lpfc_max_scsicmpl_time.attr,
6054 &dev_attr_lpfc_aer_support.attr,
6055 &dev_attr_lpfc_aer_state_cleanup.attr,
6056 &dev_attr_lpfc_sriov_nr_virtfn.attr,
6057 &dev_attr_lpfc_req_fw_upgrade.attr,
6058 &dev_attr_lpfc_suppress_link_up.attr,
6059 &dev_attr_iocb_hw.attr,
6062 &dev_attr_txq_hw.attr,
6063 &dev_attr_txcmplq_hw.attr,
6064 &dev_attr_lpfc_sriov_hw_max_virtfn.attr,
6065 &dev_attr_protocol.attr,
6066 &dev_attr_lpfc_xlane_supported.attr,
6067 &dev_attr_lpfc_enable_mds_diags.attr,
6068 &dev_attr_lpfc_ras_fwlog_buffsize.attr,
6069 &dev_attr_lpfc_ras_fwlog_level.attr,
6070 &dev_attr_lpfc_ras_fwlog_func.attr,
6071 &dev_attr_lpfc_enable_bbcr.attr,
6072 &dev_attr_lpfc_enable_dpp.attr,
6073 &dev_attr_lpfc_enable_mi.attr,
6074 &dev_attr_cmf_info.attr,
6075 &dev_attr_lpfc_max_vmid.attr,
6076 &dev_attr_lpfc_vmid_inactivity_timeout.attr,
6077 &dev_attr_lpfc_vmid_app_header.attr,
6078 &dev_attr_lpfc_vmid_priority_tagging.attr,
6082 static const struct attribute_group lpfc_hba_attr_group = {
6083 .attrs = lpfc_hba_attrs
6086 const struct attribute_group *lpfc_hba_groups[] = {
6087 &lpfc_hba_attr_group,
6091 static struct attribute *lpfc_vport_attrs[] = {
6092 &dev_attr_info.attr,
6093 &dev_attr_link_state.attr,
6094 &dev_attr_num_discovered_ports.attr,
6095 &dev_attr_lpfc_drvr_version.attr,
6096 &dev_attr_lpfc_log_verbose.attr,
6097 &dev_attr_lpfc_lun_queue_depth.attr,
6098 &dev_attr_lpfc_tgt_queue_depth.attr,
6099 &dev_attr_lpfc_nodev_tmo.attr,
6100 &dev_attr_lpfc_devloss_tmo.attr,
6101 &dev_attr_lpfc_hba_queue_depth.attr,
6102 &dev_attr_lpfc_peer_port_login.attr,
6103 &dev_attr_lpfc_restrict_login.attr,
6104 &dev_attr_lpfc_fcp_class.attr,
6105 &dev_attr_lpfc_use_adisc.attr,
6106 &dev_attr_lpfc_first_burst_size.attr,
6107 &dev_attr_lpfc_max_luns.attr,
6108 &dev_attr_nport_evt_cnt.attr,
6109 &dev_attr_npiv_info.attr,
6110 &dev_attr_lpfc_enable_da_id.attr,
6111 &dev_attr_lpfc_max_scsicmpl_time.attr,
6112 &dev_attr_lpfc_static_vport.attr,
6113 &dev_attr_cmf_info.attr,
6117 static const struct attribute_group lpfc_vport_attr_group = {
6118 .attrs = lpfc_vport_attrs
6121 const struct attribute_group *lpfc_vport_groups[] = {
6122 &lpfc_vport_attr_group,
6127 * sysfs_ctlreg_write - Write method for writing to ctlreg
6128 * @filp: open sysfs file
6129 * @kobj: kernel kobject that contains the kernel class device.
6130 * @bin_attr: kernel attributes passed to us.
6131 * @buf: contains the data to be written to the adapter IOREG space.
6132 * @off: offset into buffer to beginning of data.
6133 * @count: bytes to transfer.
6136 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6137 * Uses the adapter io control registers to send buf contents to the adapter.
6140 * -ERANGE off and count combo out of range
6141 * -EINVAL off, count or buff address invalid
6142 * -EPERM adapter is offline
6143 * value of count, buf contents written
6146 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6147 struct bin_attribute *bin_attr,
6148 char *buf, loff_t off, size_t count)
6151 struct device *dev = container_of(kobj, struct device, kobj);
6152 struct Scsi_Host *shost = class_to_shost(dev);
6153 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6154 struct lpfc_hba *phba = vport->phba;
6156 if (phba->sli_rev >= LPFC_SLI_REV4)
6159 if ((off + count) > FF_REG_AREA_SIZE)
6162 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6165 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6168 /* This is to protect HBA registers from accidental writes. */
6169 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6172 if (!(vport->fc_flag & FC_OFFLINE_MODE))
6175 spin_lock_irq(&phba->hbalock);
6176 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6177 buf_off += sizeof(uint32_t))
6178 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6179 phba->ctrl_regs_memmap_p + off + buf_off);
6181 spin_unlock_irq(&phba->hbalock);
6187 * sysfs_ctlreg_read - Read method for reading from ctlreg
6188 * @filp: open sysfs file
6189 * @kobj: kernel kobject that contains the kernel class device.
6190 * @bin_attr: kernel attributes passed to us.
6191 * @buf: if successful contains the data from the adapter IOREG space.
6192 * @off: offset into buffer to beginning of data.
6193 * @count: bytes to transfer.
6196 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6197 * Uses the adapter io control registers to read data into buf.
6200 * -ERANGE off and count combo out of range
6201 * -EINVAL off, count or buff address invalid
6202 * value of count, buf contents read
6205 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6206 struct bin_attribute *bin_attr,
6207 char *buf, loff_t off, size_t count)
6211 struct device *dev = container_of(kobj, struct device, kobj);
6212 struct Scsi_Host *shost = class_to_shost(dev);
6213 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6214 struct lpfc_hba *phba = vport->phba;
6216 if (phba->sli_rev >= LPFC_SLI_REV4)
6219 if (off > FF_REG_AREA_SIZE)
6222 if ((off + count) > FF_REG_AREA_SIZE)
6223 count = FF_REG_AREA_SIZE - off;
6225 if (count == 0) return 0;
6227 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6230 spin_lock_irq(&phba->hbalock);
6232 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6233 tmp_ptr = (uint32_t *)(buf + buf_off);
6234 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6237 spin_unlock_irq(&phba->hbalock);
6242 static struct bin_attribute sysfs_ctlreg_attr = {
6245 .mode = S_IRUSR | S_IWUSR,
6248 .read = sysfs_ctlreg_read,
6249 .write = sysfs_ctlreg_write,
6253 * sysfs_mbox_write - Write method for writing information via mbox
6254 * @filp: open sysfs file
6255 * @kobj: kernel kobject that contains the kernel class device.
6256 * @bin_attr: kernel attributes passed to us.
6257 * @buf: contains the data to be written to sysfs mbox.
6258 * @off: offset into buffer to beginning of data.
6259 * @count: bytes to transfer.
6262 * Deprecated function. All mailbox access from user space is performed via the
6266 * -EPERM operation not permitted
6269 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6270 struct bin_attribute *bin_attr,
6271 char *buf, loff_t off, size_t count)
6277 * sysfs_mbox_read - Read method for reading information via mbox
6278 * @filp: open sysfs file
6279 * @kobj: kernel kobject that contains the kernel class device.
6280 * @bin_attr: kernel attributes passed to us.
6281 * @buf: contains the data to be read from sysfs mbox.
6282 * @off: offset into buffer to beginning of data.
6283 * @count: bytes to transfer.
6286 * Deprecated function. All mailbox access from user space is performed via the
6290 * -EPERM operation not permitted
6293 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6294 struct bin_attribute *bin_attr,
6295 char *buf, loff_t off, size_t count)
6300 static struct bin_attribute sysfs_mbox_attr = {
6303 .mode = S_IRUSR | S_IWUSR,
6305 .size = MAILBOX_SYSFS_MAX,
6306 .read = sysfs_mbox_read,
6307 .write = sysfs_mbox_write,
6311 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6312 * @vport: address of lpfc vport structure.
6316 * error return code from sysfs_create_bin_file()
6319 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6321 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6324 /* Virtual ports do not need ctrl_reg and mbox */
6325 if (vport->port_type == LPFC_NPIV_PORT)
6328 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6329 &sysfs_ctlreg_attr);
6333 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6336 goto out_remove_ctlreg_attr;
6339 out_remove_ctlreg_attr:
6340 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6346 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6347 * @vport: address of lpfc vport structure.
6350 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6352 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6354 /* Virtual ports do not need ctrl_reg and mbox */
6355 if (vport->port_type == LPFC_NPIV_PORT)
6357 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6358 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6362 * Dynamic FC Host Attributes Support
6366 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6367 * @shost: kernel scsi host pointer.
6370 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6372 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6374 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6375 sizeof fc_host_symbolic_name(shost));
6379 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6380 * @shost: kernel scsi host pointer.
6383 lpfc_get_host_port_id(struct Scsi_Host *shost)
6385 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6387 /* note: fc_myDID already in cpu endianness */
6388 fc_host_port_id(shost) = vport->fc_myDID;
6392 * lpfc_get_host_port_type - Set the value of the scsi host port type
6393 * @shost: kernel scsi host pointer.
6396 lpfc_get_host_port_type(struct Scsi_Host *shost)
6398 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6399 struct lpfc_hba *phba = vport->phba;
6401 spin_lock_irq(shost->host_lock);
6403 if (vport->port_type == LPFC_NPIV_PORT) {
6404 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6405 } else if (lpfc_is_link_up(phba)) {
6406 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6407 if (vport->fc_flag & FC_PUBLIC_LOOP)
6408 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6410 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6412 if (vport->fc_flag & FC_FABRIC)
6413 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6415 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6418 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6420 spin_unlock_irq(shost->host_lock);
6424 * lpfc_get_host_port_state - Set the value of the scsi host port state
6425 * @shost: kernel scsi host pointer.
6428 lpfc_get_host_port_state(struct Scsi_Host *shost)
6430 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6431 struct lpfc_hba *phba = vport->phba;
6433 spin_lock_irq(shost->host_lock);
6435 if (vport->fc_flag & FC_OFFLINE_MODE)
6436 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6438 switch (phba->link_state) {
6439 case LPFC_LINK_UNKNOWN:
6440 case LPFC_LINK_DOWN:
6441 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6445 case LPFC_HBA_READY:
6446 /* Links up, reports port state accordingly */
6447 if (vport->port_state < LPFC_VPORT_READY)
6448 fc_host_port_state(shost) =
6449 FC_PORTSTATE_BYPASSED;
6451 fc_host_port_state(shost) =
6452 FC_PORTSTATE_ONLINE;
6454 case LPFC_HBA_ERROR:
6455 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6458 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6463 spin_unlock_irq(shost->host_lock);
6467 * lpfc_get_host_speed - Set the value of the scsi host speed
6468 * @shost: kernel scsi host pointer.
6471 lpfc_get_host_speed(struct Scsi_Host *shost)
6473 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6474 struct lpfc_hba *phba = vport->phba;
6476 spin_lock_irq(shost->host_lock);
6478 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
6479 switch(phba->fc_linkspeed) {
6480 case LPFC_LINK_SPEED_1GHZ:
6481 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6483 case LPFC_LINK_SPEED_2GHZ:
6484 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6486 case LPFC_LINK_SPEED_4GHZ:
6487 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6489 case LPFC_LINK_SPEED_8GHZ:
6490 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6492 case LPFC_LINK_SPEED_10GHZ:
6493 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6495 case LPFC_LINK_SPEED_16GHZ:
6496 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6498 case LPFC_LINK_SPEED_32GHZ:
6499 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6501 case LPFC_LINK_SPEED_64GHZ:
6502 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6504 case LPFC_LINK_SPEED_128GHZ:
6505 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6507 case LPFC_LINK_SPEED_256GHZ:
6508 fc_host_speed(shost) = FC_PORTSPEED_256GBIT;
6511 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6514 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6515 switch (phba->fc_linkspeed) {
6516 case LPFC_ASYNC_LINK_SPEED_1GBPS:
6517 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6519 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6520 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6522 case LPFC_ASYNC_LINK_SPEED_20GBPS:
6523 fc_host_speed(shost) = FC_PORTSPEED_20GBIT;
6525 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6526 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6528 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6529 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6531 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6532 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6535 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6539 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6541 spin_unlock_irq(shost->host_lock);
6545 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6546 * @shost: kernel scsi host pointer.
6549 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6552 struct lpfc_hba *phba = vport->phba;
6555 spin_lock_irq(shost->host_lock);
6557 if ((vport->port_state > LPFC_FLOGI) &&
6558 ((vport->fc_flag & FC_FABRIC) ||
6559 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6560 (vport->fc_flag & FC_PUBLIC_LOOP))))
6561 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6563 /* fabric is local port if there is no F/FL_Port */
6566 spin_unlock_irq(shost->host_lock);
6568 fc_host_fabric_name(shost) = node_name;
6572 * lpfc_get_stats - Return statistical information about the adapter
6573 * @shost: kernel scsi host pointer.
6576 * NULL on error for link down, no mbox pool, sli2 active,
6577 * management not allowed, memory allocation error, or mbox error.
6581 * address of the adapter host statistics
6583 static struct fc_host_statistics *
6584 lpfc_get_stats(struct Scsi_Host *shost)
6586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6587 struct lpfc_hba *phba = vport->phba;
6588 struct lpfc_sli *psli = &phba->sli;
6589 struct fc_host_statistics *hs = &phba->link_stats;
6590 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6591 LPFC_MBOXQ_t *pmboxq;
6596 * prevent udev from issuing mailbox commands until the port is
6599 if (phba->link_state < LPFC_LINK_DOWN ||
6600 !phba->mbox_mem_pool ||
6601 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6604 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6607 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6610 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6612 pmb = &pmboxq->u.mb;
6613 pmb->mbxCommand = MBX_READ_STATUS;
6614 pmb->mbxOwner = OWN_HOST;
6615 pmboxq->ctx_buf = NULL;
6616 pmboxq->vport = vport;
6618 if (vport->fc_flag & FC_OFFLINE_MODE) {
6619 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6620 if (rc != MBX_SUCCESS) {
6621 mempool_free(pmboxq, phba->mbox_mem_pool);
6625 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6626 if (rc != MBX_SUCCESS) {
6627 if (rc != MBX_TIMEOUT)
6628 mempool_free(pmboxq, phba->mbox_mem_pool);
6633 memset(hs, 0, sizeof (struct fc_host_statistics));
6635 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6636 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6639 * The MBX_READ_STATUS returns tx_k_bytes which has to be
6640 * converted to words.
6642 * Check if extended byte flag is set, to know when to collect upper
6643 * bits of 64 bit wide statistics counter.
6645 if (pmb->un.varRdStatus.xkb & RD_ST_XKB) {
6646 hs->tx_words = (u64)
6647 ((((u64)(pmb->un.varRdStatus.xmit_xkb &
6648 RD_ST_XMIT_XKB_MASK) << 32) |
6649 (u64)pmb->un.varRdStatus.xmitByteCnt) *
6651 hs->rx_words = (u64)
6652 ((((u64)(pmb->un.varRdStatus.rcv_xkb &
6653 RD_ST_RCV_XKB_MASK) << 32) |
6654 (u64)pmb->un.varRdStatus.rcvByteCnt) *
6657 hs->tx_words = (uint64_t)
6658 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6660 hs->rx_words = (uint64_t)
6661 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6665 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6666 pmb->mbxCommand = MBX_READ_LNK_STAT;
6667 pmb->mbxOwner = OWN_HOST;
6668 pmboxq->ctx_buf = NULL;
6669 pmboxq->vport = vport;
6671 if (vport->fc_flag & FC_OFFLINE_MODE) {
6672 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6673 if (rc != MBX_SUCCESS) {
6674 mempool_free(pmboxq, phba->mbox_mem_pool);
6678 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6679 if (rc != MBX_SUCCESS) {
6680 if (rc != MBX_TIMEOUT)
6681 mempool_free(pmboxq, phba->mbox_mem_pool);
6686 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6687 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6688 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6689 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6690 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6691 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6692 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6694 hs->cn_sig_warn = atomic64_read(&phba->cgn_acqe_stat.warn);
6695 hs->cn_sig_alarm = atomic64_read(&phba->cgn_acqe_stat.alarm);
6697 hs->link_failure_count -= lso->link_failure_count;
6698 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6699 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6700 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6701 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6702 hs->invalid_crc_count -= lso->invalid_crc_count;
6703 hs->error_frames -= lso->error_frames;
6705 if (phba->hba_flag & HBA_FCOE_MODE) {
6707 hs->nos_count = (phba->link_events >> 1);
6708 hs->nos_count -= lso->link_events;
6709 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6710 hs->lip_count = (phba->fc_eventTag >> 1);
6711 hs->lip_count -= lso->link_events;
6715 hs->nos_count = (phba->fc_eventTag >> 1);
6716 hs->nos_count -= lso->link_events;
6719 hs->dumped_frames = -1;
6721 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6723 mempool_free(pmboxq, phba->mbox_mem_pool);
6729 * lpfc_reset_stats - Copy the adapter link stats information
6730 * @shost: kernel scsi host pointer.
6733 lpfc_reset_stats(struct Scsi_Host *shost)
6735 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6736 struct lpfc_hba *phba = vport->phba;
6737 struct lpfc_sli *psli = &phba->sli;
6738 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6739 LPFC_MBOXQ_t *pmboxq;
6743 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6746 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6749 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6751 pmb = &pmboxq->u.mb;
6752 pmb->mbxCommand = MBX_READ_STATUS;
6753 pmb->mbxOwner = OWN_HOST;
6754 pmb->un.varWords[0] = 0x1; /* reset request */
6755 pmboxq->ctx_buf = NULL;
6756 pmboxq->vport = vport;
6758 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6759 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6760 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6761 if (rc != MBX_SUCCESS) {
6762 mempool_free(pmboxq, phba->mbox_mem_pool);
6766 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6767 if (rc != MBX_SUCCESS) {
6768 if (rc != MBX_TIMEOUT)
6769 mempool_free(pmboxq, phba->mbox_mem_pool);
6774 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6775 pmb->mbxCommand = MBX_READ_LNK_STAT;
6776 pmb->mbxOwner = OWN_HOST;
6777 pmboxq->ctx_buf = NULL;
6778 pmboxq->vport = vport;
6780 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6781 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6782 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6783 if (rc != MBX_SUCCESS) {
6784 mempool_free(pmboxq, phba->mbox_mem_pool);
6788 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6789 if (rc != MBX_SUCCESS) {
6790 if (rc != MBX_TIMEOUT)
6791 mempool_free(pmboxq, phba->mbox_mem_pool);
6796 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6797 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6798 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6799 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6800 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6801 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6802 lso->error_frames = pmb->un.varRdLnk.crcCnt;
6803 if (phba->hba_flag & HBA_FCOE_MODE)
6804 lso->link_events = (phba->link_events >> 1);
6806 lso->link_events = (phba->fc_eventTag >> 1);
6808 atomic64_set(&phba->cgn_acqe_stat.warn, 0);
6809 atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
6811 memset(&shost_to_fc_host(shost)->fpin_stats, 0,
6812 sizeof(shost_to_fc_host(shost)->fpin_stats));
6814 psli->stats_start = ktime_get_seconds();
6816 mempool_free(pmboxq, phba->mbox_mem_pool);
6822 * The LPFC driver treats linkdown handling as target loss events so there
6823 * are no sysfs handlers for link_down_tmo.
6827 * lpfc_get_node_by_target - Return the nodelist for a target
6828 * @starget: kernel scsi target pointer.
6831 * address of the node list if found
6832 * NULL target not found
6834 static struct lpfc_nodelist *
6835 lpfc_get_node_by_target(struct scsi_target *starget)
6837 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6838 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6839 struct lpfc_nodelist *ndlp;
6841 spin_lock_irq(shost->host_lock);
6842 /* Search for this, mapped, target ID */
6843 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6844 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6845 starget->id == ndlp->nlp_sid) {
6846 spin_unlock_irq(shost->host_lock);
6850 spin_unlock_irq(shost->host_lock);
6855 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6856 * @starget: kernel scsi target pointer.
6859 lpfc_get_starget_port_id(struct scsi_target *starget)
6861 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6863 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6867 * lpfc_get_starget_node_name - Set the target node name
6868 * @starget: kernel scsi target pointer.
6870 * Description: Set the target node name to the ndlp node name wwn or zero.
6873 lpfc_get_starget_node_name(struct scsi_target *starget)
6875 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6877 fc_starget_node_name(starget) =
6878 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6882 * lpfc_get_starget_port_name - Set the target port name
6883 * @starget: kernel scsi target pointer.
6885 * Description: set the target port name to the ndlp port name wwn or zero.
6888 lpfc_get_starget_port_name(struct scsi_target *starget)
6890 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6892 fc_starget_port_name(starget) =
6893 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6897 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6898 * @rport: fc rport address.
6899 * @timeout: new value for dev loss tmo.
6902 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6903 * dev_loss_tmo to one.
6906 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6908 struct lpfc_rport_data *rdata = rport->dd_data;
6909 struct lpfc_nodelist *ndlp = rdata->pnode;
6910 #if (IS_ENABLED(CONFIG_NVME_FC))
6911 struct lpfc_nvme_rport *nrport = NULL;
6915 rport->dev_loss_tmo = timeout;
6917 rport->dev_loss_tmo = 1;
6920 dev_info(&rport->dev, "Cannot find remote node to "
6921 "set rport dev loss tmo, port_id x%x\n",
6926 #if (IS_ENABLED(CONFIG_NVME_FC))
6927 nrport = lpfc_ndlp_get_nrport(ndlp);
6929 if (nrport && nrport->remoteport)
6930 nvme_fc_set_remoteport_devloss(nrport->remoteport,
6931 rport->dev_loss_tmo);
6936 * lpfc_rport_show_function - Return rport target information
6939 * Macro that uses field to generate a function with the name lpfc_show_rport_
6941 * lpfc_show_rport_##field: returns the bytes formatted in buf
6942 * @cdev: class converted to an fc_rport.
6943 * @buf: on return contains the target_field or zero.
6945 * Returns: size of formatted string.
6947 #define lpfc_rport_show_function(field, format_string, sz, cast) \
6949 lpfc_show_rport_##field (struct device *dev, \
6950 struct device_attribute *attr, \
6953 struct fc_rport *rport = transport_class_to_rport(dev); \
6954 struct lpfc_rport_data *rdata = rport->hostdata; \
6955 return scnprintf(buf, sz, format_string, \
6956 (rdata->target) ? cast rdata->target->field : 0); \
6959 #define lpfc_rport_rd_attr(field, format_string, sz) \
6960 lpfc_rport_show_function(field, format_string, sz, ) \
6961 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6964 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6965 * @fc_vport: The fc_vport who's symbolic name has been changed.
6968 * This function is called by the transport after the @fc_vport's symbolic name
6969 * has been changed. This function re-registers the symbolic name with the
6970 * switch to propagate the change into the fabric if the vport is active.
6973 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6975 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6977 if (vport->port_state == LPFC_VPORT_READY)
6978 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6982 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6983 * @phba: Pointer to lpfc_hba struct.
6984 * @verbose: Verbose level to set.
6986 * This function is called by the lpfc_get_cfgparam() routine to set the
6987 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6988 * log message according to the module's lpfc_log_verbose parameter setting
6989 * before hba port or vport created.
6992 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6994 phba->cfg_log_verbose = verbose;
6997 struct fc_function_template lpfc_transport_functions = {
6998 /* fixed attributes the driver supports */
6999 .show_host_node_name = 1,
7000 .show_host_port_name = 1,
7001 .show_host_supported_classes = 1,
7002 .show_host_supported_fc4s = 1,
7003 .show_host_supported_speeds = 1,
7004 .show_host_maxframe_size = 1,
7006 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7007 .show_host_symbolic_name = 1,
7009 /* dynamic attributes the driver supports */
7010 .get_host_port_id = lpfc_get_host_port_id,
7011 .show_host_port_id = 1,
7013 .get_host_port_type = lpfc_get_host_port_type,
7014 .show_host_port_type = 1,
7016 .get_host_port_state = lpfc_get_host_port_state,
7017 .show_host_port_state = 1,
7019 /* active_fc4s is shown but doesn't change (thus no get function) */
7020 .show_host_active_fc4s = 1,
7022 .get_host_speed = lpfc_get_host_speed,
7023 .show_host_speed = 1,
7025 .get_host_fabric_name = lpfc_get_host_fabric_name,
7026 .show_host_fabric_name = 1,
7029 * The LPFC driver treats linkdown handling as target loss events
7030 * so there are no sysfs handlers for link_down_tmo.
7033 .get_fc_host_stats = lpfc_get_stats,
7034 .reset_fc_host_stats = lpfc_reset_stats,
7036 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7037 .show_rport_maxframe_size = 1,
7038 .show_rport_supported_classes = 1,
7040 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7041 .show_rport_dev_loss_tmo = 1,
7043 .get_starget_port_id = lpfc_get_starget_port_id,
7044 .show_starget_port_id = 1,
7046 .get_starget_node_name = lpfc_get_starget_node_name,
7047 .show_starget_node_name = 1,
7049 .get_starget_port_name = lpfc_get_starget_port_name,
7050 .show_starget_port_name = 1,
7052 .issue_fc_host_lip = lpfc_issue_lip,
7053 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7054 .terminate_rport_io = lpfc_terminate_rport_io,
7056 .dd_fcvport_size = sizeof(struct lpfc_vport *),
7058 .vport_disable = lpfc_vport_disable,
7060 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7062 .bsg_request = lpfc_bsg_request,
7063 .bsg_timeout = lpfc_bsg_timeout,
7066 struct fc_function_template lpfc_vport_transport_functions = {
7067 /* fixed attributes the driver supports */
7068 .show_host_node_name = 1,
7069 .show_host_port_name = 1,
7070 .show_host_supported_classes = 1,
7071 .show_host_supported_fc4s = 1,
7072 .show_host_supported_speeds = 1,
7073 .show_host_maxframe_size = 1,
7075 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7076 .show_host_symbolic_name = 1,
7078 /* dynamic attributes the driver supports */
7079 .get_host_port_id = lpfc_get_host_port_id,
7080 .show_host_port_id = 1,
7082 .get_host_port_type = lpfc_get_host_port_type,
7083 .show_host_port_type = 1,
7085 .get_host_port_state = lpfc_get_host_port_state,
7086 .show_host_port_state = 1,
7088 /* active_fc4s is shown but doesn't change (thus no get function) */
7089 .show_host_active_fc4s = 1,
7091 .get_host_speed = lpfc_get_host_speed,
7092 .show_host_speed = 1,
7094 .get_host_fabric_name = lpfc_get_host_fabric_name,
7095 .show_host_fabric_name = 1,
7098 * The LPFC driver treats linkdown handling as target loss events
7099 * so there are no sysfs handlers for link_down_tmo.
7102 .get_fc_host_stats = lpfc_get_stats,
7103 .reset_fc_host_stats = lpfc_reset_stats,
7105 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7106 .show_rport_maxframe_size = 1,
7107 .show_rport_supported_classes = 1,
7109 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7110 .show_rport_dev_loss_tmo = 1,
7112 .get_starget_port_id = lpfc_get_starget_port_id,
7113 .show_starget_port_id = 1,
7115 .get_starget_node_name = lpfc_get_starget_node_name,
7116 .show_starget_node_name = 1,
7118 .get_starget_port_name = lpfc_get_starget_port_name,
7119 .show_starget_port_name = 1,
7121 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7122 .terminate_rport_io = lpfc_terminate_rport_io,
7124 .vport_disable = lpfc_vport_disable,
7126 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7130 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7132 * @phba: lpfc_hba pointer.
7135 lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7137 /* If the adapter supports FCoE mode */
7138 switch (phba->pcidev->device) {
7139 case PCI_DEVICE_ID_SKYHAWK:
7140 case PCI_DEVICE_ID_SKYHAWK_VF:
7141 case PCI_DEVICE_ID_LANCER_FCOE:
7142 case PCI_DEVICE_ID_LANCER_FCOE_VF:
7143 case PCI_DEVICE_ID_ZEPHYR_DCSP:
7144 case PCI_DEVICE_ID_TIGERSHARK:
7145 case PCI_DEVICE_ID_TOMCAT:
7146 phba->hba_flag |= HBA_FCOE_MODE;
7149 /* for others, clear the flag */
7150 phba->hba_flag &= ~HBA_FCOE_MODE;
7155 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7156 * @phba: lpfc_hba pointer.
7159 lpfc_get_cfgparam(struct lpfc_hba *phba)
7161 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7162 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
7163 lpfc_ns_query_init(phba, lpfc_ns_query);
7164 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7165 lpfc_cr_delay_init(phba, lpfc_cr_delay);
7166 lpfc_cr_count_init(phba, lpfc_cr_count);
7167 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
7168 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7169 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7170 lpfc_ack0_init(phba, lpfc_ack0);
7171 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
7172 lpfc_topology_init(phba, lpfc_topology);
7173 lpfc_link_speed_init(phba, lpfc_link_speed);
7174 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
7175 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
7176 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7177 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
7178 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
7179 lpfc_fcp_wait_abts_rsp_init(phba, lpfc_fcp_wait_abts_rsp);
7180 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7181 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
7182 lpfc_use_msi_init(phba, lpfc_use_msi);
7183 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
7184 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
7185 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7186 lpfc_force_rscn_init(phba, lpfc_force_rscn);
7187 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7188 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
7189 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
7190 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7191 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
7193 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7195 lpfc_max_vmid_init(phba, lpfc_max_vmid);
7196 lpfc_vmid_inactivity_timeout_init(phba, lpfc_vmid_inactivity_timeout);
7197 lpfc_vmid_app_header_init(phba, lpfc_vmid_app_header);
7198 lpfc_vmid_priority_tagging_init(phba, lpfc_vmid_priority_tagging);
7199 if (phba->sli_rev != LPFC_SLI_REV4)
7200 phba->cfg_EnableXLane = 0;
7201 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
7203 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7204 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7205 phba->cfg_oas_lun_state = 0;
7206 phba->cfg_oas_lun_status = 0;
7207 phba->cfg_oas_flags = 0;
7208 phba->cfg_oas_priority = 0;
7209 lpfc_enable_bg_init(phba, lpfc_enable_bg);
7210 lpfc_prot_mask_init(phba, lpfc_prot_mask);
7211 lpfc_prot_guard_init(phba, lpfc_prot_guard);
7212 if (phba->sli_rev == LPFC_SLI_REV4)
7215 phba->cfg_poll = lpfc_poll;
7217 /* Get the function mode */
7218 lpfc_get_hba_function_mode(phba);
7220 /* BlockGuard allowed for FC only. */
7221 if (phba->cfg_enable_bg && phba->hba_flag & HBA_FCOE_MODE) {
7222 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7223 "0581 BlockGuard feature not supported\n");
7224 /* If set, clear the BlockGuard support param */
7225 phba->cfg_enable_bg = 0;
7226 } else if (phba->cfg_enable_bg) {
7227 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
7230 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
7232 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
7233 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
7234 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
7236 /* Initialize first burst. Target vs Initiator are different. */
7237 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
7238 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
7239 lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
7240 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
7241 lpfc_irq_chann_init(phba, lpfc_irq_chann);
7242 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7243 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7244 lpfc_enable_mi_init(phba, lpfc_enable_mi);
7246 phba->cgn_p.cgn_param_mode = LPFC_CFG_OFF;
7247 phba->cmf_active_mode = LPFC_CFG_OFF;
7248 if (lpfc_fabric_cgn_frequency > EDC_CG_SIGFREQ_CNT_MAX ||
7249 lpfc_fabric_cgn_frequency < EDC_CG_SIGFREQ_CNT_MIN)
7250 lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
7252 if (phba->sli_rev != LPFC_SLI_REV4) {
7253 /* NVME only supported on SLI4 */
7254 phba->nvmet_support = 0;
7255 phba->cfg_nvmet_mrq = 0;
7256 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7257 phba->cfg_enable_bbcr = 0;
7258 phba->cfg_xri_rebalancing = 0;
7260 /* We MUST have FCP support */
7261 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7262 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7265 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7267 phba->cfg_enable_pbde = 0;
7269 /* A value of 0 means use the number of CPUs found in the system */
7270 if (phba->cfg_hdw_queue == 0)
7271 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7272 if (phba->cfg_irq_chann == 0)
7273 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7274 if (phba->cfg_irq_chann > phba->cfg_hdw_queue &&
7275 phba->sli_rev == LPFC_SLI_REV4)
7276 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7278 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7279 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7280 lpfc_aer_support_init(phba, lpfc_aer_support);
7281 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7282 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7283 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7284 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7285 lpfc_sli_mode_init(phba, lpfc_sli_mode);
7286 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7287 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7288 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7289 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7295 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7296 * dependencies between protocols and roles.
7297 * @phba: lpfc_hba pointer.
7300 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7304 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu) {
7305 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7308 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu) {
7309 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7312 if (phba->cfg_irq_chann > phba->cfg_hdw_queue) {
7313 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7317 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7318 "2006 Reducing Queues - CPU limitation: "
7320 phba->cfg_irq_chann,
7321 phba->cfg_hdw_queue);
7323 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7324 phba->nvmet_support) {
7325 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7327 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7328 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7329 "NVME Target PRLI ACC enable_fb ",
7330 phba->cfg_nvme_enable_fb,
7331 phba->cfg_nvmet_fb_size,
7332 LPFC_NVMET_FB_SZ_MAX);
7334 if (phba->cfg_nvme_enable_fb == 0)
7335 phba->cfg_nvmet_fb_size = 0;
7337 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7338 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7341 if (!phba->cfg_nvmet_mrq)
7342 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7344 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7345 if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
7346 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7347 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7348 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7349 phba->cfg_nvmet_mrq);
7351 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7352 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7355 /* Not NVME Target mode. Turn off Target parameters. */
7356 phba->nvmet_support = 0;
7357 phba->cfg_nvmet_mrq = 0;
7358 phba->cfg_nvmet_fb_size = 0;
7363 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7364 * @vport: lpfc_vport pointer.
7367 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7369 lpfc_log_verbose_init(vport, lpfc_log_verbose);
7370 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7371 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7372 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7373 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7374 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7375 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7376 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7377 lpfc_use_adisc_init(vport, lpfc_use_adisc);
7378 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7379 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7380 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7381 lpfc_max_luns_init(vport, lpfc_max_luns);
7382 lpfc_scan_down_init(vport, lpfc_scan_down);
7383 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);