1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2024 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 (test_bit(HBA_FIP_SUPPORT, &phba->hba_flag))
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;
347 unsigned long iflags;
351 char tmp[LPFC_MAX_INFO_TMP_LEN] = {0};
353 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
354 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
357 if (phba->nvmet_support) {
358 if (!phba->targetport) {
359 len = scnprintf(buf, PAGE_SIZE,
360 "NVME Target: x%llx is not allocated\n",
361 wwn_to_u64(vport->fc_portname.u.wwn));
364 /* Port state is only one of two values for now. */
365 if (phba->targetport->port_id)
366 statep = "REGISTERED";
369 scnprintf(tmp, sizeof(tmp),
370 "NVME Target Enabled State %s\n",
372 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
375 scnprintf(tmp, sizeof(tmp),
376 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
379 wwn_to_u64(vport->fc_portname.u.wwn),
380 wwn_to_u64(vport->fc_nodename.u.wwn),
381 phba->targetport->port_id);
382 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
385 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
389 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
390 scnprintf(tmp, sizeof(tmp),
391 "LS: Rcv %08x Drop %08x Abort %08x\n",
392 atomic_read(&tgtp->rcv_ls_req_in),
393 atomic_read(&tgtp->rcv_ls_req_drop),
394 atomic_read(&tgtp->xmt_ls_abort));
395 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
398 if (atomic_read(&tgtp->rcv_ls_req_in) !=
399 atomic_read(&tgtp->rcv_ls_req_out)) {
400 scnprintf(tmp, sizeof(tmp),
401 "Rcv LS: in %08x != out %08x\n",
402 atomic_read(&tgtp->rcv_ls_req_in),
403 atomic_read(&tgtp->rcv_ls_req_out));
404 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
408 scnprintf(tmp, sizeof(tmp),
409 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
410 atomic_read(&tgtp->xmt_ls_rsp),
411 atomic_read(&tgtp->xmt_ls_drop),
412 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
413 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
416 scnprintf(tmp, sizeof(tmp),
417 "LS: RSP Abort %08x xb %08x Err %08x\n",
418 atomic_read(&tgtp->xmt_ls_rsp_aborted),
419 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
420 atomic_read(&tgtp->xmt_ls_rsp_error));
421 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
424 scnprintf(tmp, sizeof(tmp),
425 "FCP: Rcv %08x Defer %08x Release %08x "
427 atomic_read(&tgtp->rcv_fcp_cmd_in),
428 atomic_read(&tgtp->rcv_fcp_cmd_defer),
429 atomic_read(&tgtp->xmt_fcp_release),
430 atomic_read(&tgtp->rcv_fcp_cmd_drop));
431 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
434 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
435 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
436 scnprintf(tmp, sizeof(tmp),
437 "Rcv FCP: in %08x != out %08x\n",
438 atomic_read(&tgtp->rcv_fcp_cmd_in),
439 atomic_read(&tgtp->rcv_fcp_cmd_out));
440 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
444 scnprintf(tmp, sizeof(tmp),
445 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
447 atomic_read(&tgtp->xmt_fcp_read),
448 atomic_read(&tgtp->xmt_fcp_read_rsp),
449 atomic_read(&tgtp->xmt_fcp_write),
450 atomic_read(&tgtp->xmt_fcp_rsp),
451 atomic_read(&tgtp->xmt_fcp_drop));
452 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
455 scnprintf(tmp, sizeof(tmp),
456 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
457 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
458 atomic_read(&tgtp->xmt_fcp_rsp_error),
459 atomic_read(&tgtp->xmt_fcp_rsp_drop));
460 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
463 scnprintf(tmp, sizeof(tmp),
464 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
465 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
466 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
467 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
468 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
471 scnprintf(tmp, sizeof(tmp),
472 "ABORT: Xmt %08x Cmpl %08x\n",
473 atomic_read(&tgtp->xmt_fcp_abort),
474 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
475 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
478 scnprintf(tmp, sizeof(tmp),
479 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
480 atomic_read(&tgtp->xmt_abort_sol),
481 atomic_read(&tgtp->xmt_abort_unsol),
482 atomic_read(&tgtp->xmt_abort_rsp),
483 atomic_read(&tgtp->xmt_abort_rsp_error));
484 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
487 scnprintf(tmp, sizeof(tmp),
488 "DELAY: ctx %08x fod %08x wqfull %08x\n",
489 atomic_read(&tgtp->defer_ctx),
490 atomic_read(&tgtp->defer_fod),
491 atomic_read(&tgtp->defer_wqfull));
492 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
495 /* Calculate outstanding IOs */
496 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
497 tot += atomic_read(&tgtp->xmt_fcp_release);
498 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
500 scnprintf(tmp, sizeof(tmp),
501 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
502 "CTX Outstanding %08llx\n\n",
503 phba->sli4_hba.nvmet_xri_cnt,
504 phba->sli4_hba.nvmet_io_wait_cnt,
505 phba->sli4_hba.nvmet_io_wait_total,
507 strlcat(buf, tmp, PAGE_SIZE);
511 localport = vport->localport;
513 len = scnprintf(buf, PAGE_SIZE,
514 "NVME Initiator x%llx is not allocated\n",
515 wwn_to_u64(vport->fc_portname.u.wwn));
518 lport = (struct lpfc_nvme_lport *)localport->private;
519 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
522 scnprintf(tmp, sizeof(tmp),
523 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
525 phba->sli4_hba.max_cfg_param.max_xri,
526 phba->sli4_hba.io_xri_max,
527 lpfc_sli4_get_els_iocb_cnt(phba));
528 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
531 /* Port state is only one of two values for now. */
532 if (localport->port_id)
537 scnprintf(tmp, sizeof(tmp),
538 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
541 wwn_to_u64(vport->fc_portname.u.wwn),
542 wwn_to_u64(vport->fc_nodename.u.wwn),
543 localport->port_id, statep);
544 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
547 spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
549 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
551 spin_lock(&ndlp->lock);
552 rport = lpfc_ndlp_get_nrport(ndlp);
554 nrport = rport->remoteport;
555 spin_unlock(&ndlp->lock);
559 /* Port state is only one of two values for now. */
560 switch (nrport->port_state) {
561 case FC_OBJSTATE_ONLINE:
564 case FC_OBJSTATE_UNKNOWN:
568 statep = "UNSUPPORTED";
572 /* Tab in to show lport ownership. */
573 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
574 goto unlock_buf_done;
575 if (phba->brd_no >= 10) {
576 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
577 goto unlock_buf_done;
580 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
582 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
583 goto unlock_buf_done;
585 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
587 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
588 goto unlock_buf_done;
590 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
592 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
593 goto unlock_buf_done;
595 /* An NVME rport can have multiple roles. */
596 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
597 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
598 goto unlock_buf_done;
600 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
601 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
602 goto unlock_buf_done;
604 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
605 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
606 goto unlock_buf_done;
608 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
609 FC_PORT_ROLE_NVME_TARGET |
610 FC_PORT_ROLE_NVME_DISCOVERY)) {
611 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
613 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
614 goto unlock_buf_done;
617 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
618 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
619 goto unlock_buf_done;
621 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
626 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
629 scnprintf(tmp, sizeof(tmp),
630 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
631 atomic_read(&lport->fc4NvmeLsRequests),
632 atomic_read(&lport->fc4NvmeLsCmpls),
633 atomic_read(&lport->xmt_ls_abort));
634 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
637 scnprintf(tmp, sizeof(tmp),
638 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
639 atomic_read(&lport->xmt_ls_err),
640 atomic_read(&lport->cmpl_ls_xb),
641 atomic_read(&lport->cmpl_ls_err));
642 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
647 for (i = 0; i < phba->cfg_hdw_queue; i++) {
648 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
649 tot = cstat->io_cmpls;
651 data1 = cstat->input_requests;
652 data2 = cstat->output_requests;
653 data3 = cstat->control_requests;
654 totout += (data1 + data2 + data3);
656 scnprintf(tmp, sizeof(tmp),
657 "Total FCP Cmpl %016llx Issue %016llx "
659 totin, totout, totout - totin);
660 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
663 scnprintf(tmp, sizeof(tmp),
664 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
665 "wqerr %08x err %08x\n",
666 atomic_read(&lport->xmt_fcp_abort),
667 atomic_read(&lport->xmt_fcp_noxri),
668 atomic_read(&lport->xmt_fcp_bad_ndlp),
669 atomic_read(&lport->xmt_fcp_qdepth),
670 atomic_read(&lport->xmt_fcp_wqerr),
671 atomic_read(&lport->xmt_fcp_err));
672 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
675 scnprintf(tmp, sizeof(tmp),
676 "FCP CMPL: xb %08x Err %08x\n",
677 atomic_read(&lport->cmpl_fcp_xb),
678 atomic_read(&lport->cmpl_fcp_err));
679 strlcat(buf, tmp, PAGE_SIZE);
681 /* host_lock is already unlocked. */
685 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
688 len = strnlen(buf, PAGE_SIZE);
690 if (unlikely(len >= (PAGE_SIZE - 1))) {
691 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
692 "6314 Catching potential buffer "
693 "overflow > PAGE_SIZE = %lu bytes\n",
695 strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),
697 sizeof(LPFC_INFO_MORE_STR) + 1);
704 lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
707 struct Scsi_Host *shost = class_to_shost(dev);
708 struct lpfc_vport *vport = shost_priv(shost);
709 struct lpfc_hba *phba = vport->phba;
711 struct lpfc_fc4_ctrl_stat *cstat;
712 u64 data1, data2, data3;
713 u64 tot, totin, totout;
715 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
717 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
718 (phba->sli_rev != LPFC_SLI_REV4))
721 scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
725 for (i = 0; i < phba->cfg_hdw_queue; i++) {
726 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
727 tot = cstat->io_cmpls;
729 data1 = cstat->input_requests;
730 data2 = cstat->output_requests;
731 data3 = cstat->control_requests;
732 totout += (data1 + data2 + data3);
734 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
735 "IO %016llx ", i, data1, data2, data3);
736 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
739 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
740 tot, ((data1 + data2 + data3) - tot));
741 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
744 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
745 "OutIO %016llx\n", totin, totout, totout - totin);
746 strlcat(buf, tmp, PAGE_SIZE);
749 len = strnlen(buf, PAGE_SIZE);
755 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
758 struct Scsi_Host *shost = class_to_shost(dev);
759 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
760 struct lpfc_hba *phba = vport->phba;
762 if (phba->cfg_enable_bg) {
763 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
764 return scnprintf(buf, PAGE_SIZE,
765 "BlockGuard Enabled\n");
767 return scnprintf(buf, PAGE_SIZE,
768 "BlockGuard Not Supported\n");
770 return scnprintf(buf, PAGE_SIZE,
771 "BlockGuard Disabled\n");
775 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
778 struct Scsi_Host *shost = class_to_shost(dev);
779 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
780 struct lpfc_hba *phba = vport->phba;
782 return scnprintf(buf, PAGE_SIZE, "%llu\n",
783 (unsigned long long)phba->bg_guard_err_cnt);
787 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
790 struct Scsi_Host *shost = class_to_shost(dev);
791 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
792 struct lpfc_hba *phba = vport->phba;
794 return scnprintf(buf, PAGE_SIZE, "%llu\n",
795 (unsigned long long)phba->bg_apptag_err_cnt);
799 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
802 struct Scsi_Host *shost = class_to_shost(dev);
803 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
804 struct lpfc_hba *phba = vport->phba;
806 return scnprintf(buf, PAGE_SIZE, "%llu\n",
807 (unsigned long long)phba->bg_reftag_err_cnt);
811 * lpfc_info_show - Return some pci info about the host in ascii
812 * @dev: class converted to a Scsi_host structure.
813 * @attr: device attribute, not used.
814 * @buf: on return contains the formatted text from lpfc_info().
816 * Returns: size of formatted string.
819 lpfc_info_show(struct device *dev, struct device_attribute *attr,
822 struct Scsi_Host *host = class_to_shost(dev);
824 return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
828 * lpfc_serialnum_show - Return the hba serial number in ascii
829 * @dev: class converted to a Scsi_host structure.
830 * @attr: device attribute, not used.
831 * @buf: on return contains the formatted text serial number.
833 * Returns: size of formatted string.
836 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
839 struct Scsi_Host *shost = class_to_shost(dev);
840 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
841 struct lpfc_hba *phba = vport->phba;
843 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
847 * lpfc_temp_sensor_show - Return the temperature sensor level
848 * @dev: class converted to a Scsi_host structure.
849 * @attr: device attribute, not used.
850 * @buf: on return contains the formatted support level.
853 * Returns a number indicating the temperature sensor level currently
854 * supported, zero or one in ascii.
856 * Returns: size of formatted string.
859 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
862 struct Scsi_Host *shost = class_to_shost(dev);
863 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
864 struct lpfc_hba *phba = vport->phba;
865 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
869 * lpfc_modeldesc_show - Return the model description of the hba
870 * @dev: class converted to a Scsi_host structure.
871 * @attr: device attribute, not used.
872 * @buf: on return contains the scsi vpd model description.
874 * Returns: size of formatted string.
877 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
880 struct Scsi_Host *shost = class_to_shost(dev);
881 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
882 struct lpfc_hba *phba = vport->phba;
884 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
888 * lpfc_modelname_show - Return the model name of the hba
889 * @dev: class converted to a Scsi_host structure.
890 * @attr: device attribute, not used.
891 * @buf: on return contains the scsi vpd model name.
893 * Returns: size of formatted string.
896 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
899 struct Scsi_Host *shost = class_to_shost(dev);
900 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
901 struct lpfc_hba *phba = vport->phba;
903 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
907 * lpfc_programtype_show - Return the program type of the hba
908 * @dev: class converted to a Scsi_host structure.
909 * @attr: device attribute, not used.
910 * @buf: on return contains the scsi vpd program type.
912 * Returns: size of formatted string.
915 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
918 struct Scsi_Host *shost = class_to_shost(dev);
919 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
920 struct lpfc_hba *phba = vport->phba;
922 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
926 * lpfc_vportnum_show - Return the port number in ascii of the hba
927 * @dev: class converted to a Scsi_host structure.
928 * @attr: device attribute, not used.
929 * @buf: on return contains scsi vpd program type.
931 * Returns: size of formatted string.
934 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
937 struct Scsi_Host *shost = class_to_shost(dev);
938 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
939 struct lpfc_hba *phba = vport->phba;
941 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
945 * lpfc_fwrev_show - Return the firmware rev running in the hba
946 * @dev: class converted to a Scsi_host structure.
947 * @attr: device attribute, not used.
948 * @buf: on return contains the scsi vpd program type.
950 * Returns: size of formatted string.
953 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
956 struct Scsi_Host *shost = class_to_shost(dev);
957 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
958 struct lpfc_hba *phba = vport->phba;
961 char fwrev[FW_REV_STR_SIZE];
964 lpfc_decode_firmware_rev(phba, fwrev, 1);
965 if_type = phba->sli4_hba.pc_sli4_params.if_type;
966 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
968 if (phba->sli_rev < LPFC_SLI_REV4)
969 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
970 fwrev, phba->sli_rev);
972 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
973 fwrev, phba->sli_rev, if_type, sli_family);
979 * lpfc_hdw_show - Return the jedec information about the hba
980 * @dev: class converted to a Scsi_host structure.
981 * @attr: device attribute, not used.
982 * @buf: on return contains the scsi vpd program type.
984 * Returns: size of formatted string.
987 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
990 struct Scsi_Host *shost = class_to_shost(dev);
991 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
992 struct lpfc_hba *phba = vport->phba;
993 lpfc_vpd_t *vp = &phba->vpd;
995 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
996 return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
997 vp->rev.smRev, vp->rev.smFwRev);
1001 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
1002 * @dev: class converted to a Scsi_host structure.
1003 * @attr: device attribute, not used.
1004 * @buf: on return contains the ROM and FCode ascii strings.
1006 * Returns: size of formatted string.
1009 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
1012 struct Scsi_Host *shost = class_to_shost(dev);
1013 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1014 struct lpfc_hba *phba = vport->phba;
1015 char fwrev[FW_REV_STR_SIZE];
1017 if (phba->sli_rev < LPFC_SLI_REV4)
1018 return scnprintf(buf, PAGE_SIZE, "%s\n",
1019 phba->OptionROMVersion);
1021 lpfc_decode_firmware_rev(phba, fwrev, 1);
1022 return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
1026 * lpfc_link_state_show - Return the link state of the port
1027 * @dev: class converted to a Scsi_host structure.
1028 * @attr: device attribute, not used.
1029 * @buf: on return contains text describing the state of the link.
1032 * The switch statement has no default so zero will be returned.
1034 * Returns: size of formatted string.
1037 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
1040 struct Scsi_Host *shost = class_to_shost(dev);
1041 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1042 struct lpfc_hba *phba = vport->phba;
1045 switch (phba->link_state) {
1046 case LPFC_LINK_UNKNOWN:
1047 case LPFC_WARM_START:
1048 case LPFC_INIT_START:
1049 case LPFC_INIT_MBX_CMDS:
1050 case LPFC_LINK_DOWN:
1051 case LPFC_HBA_ERROR:
1052 if (test_bit(LINK_DISABLED, &phba->hba_flag))
1053 len += scnprintf(buf + len, PAGE_SIZE-len,
1054 "Link Down - User disabled\n");
1056 len += scnprintf(buf + len, PAGE_SIZE-len,
1061 case LPFC_HBA_READY:
1062 len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
1064 switch (vport->port_state) {
1065 case LPFC_LOCAL_CFG_LINK:
1066 len += scnprintf(buf + len, PAGE_SIZE-len,
1067 "Configuring Link\n");
1071 case LPFC_FABRIC_CFG_LINK:
1074 case LPFC_BUILD_DISC_LIST:
1075 case LPFC_DISC_AUTH:
1076 len += scnprintf(buf + len, PAGE_SIZE - len,
1079 case LPFC_VPORT_READY:
1080 len += scnprintf(buf + len, PAGE_SIZE - len,
1084 case LPFC_VPORT_FAILED:
1085 len += scnprintf(buf + len, PAGE_SIZE - len,
1089 case LPFC_VPORT_UNKNOWN:
1090 len += scnprintf(buf + len, PAGE_SIZE - len,
1094 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1095 if (test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
1096 len += scnprintf(buf + len, PAGE_SIZE-len,
1099 len += scnprintf(buf + len, PAGE_SIZE-len,
1102 if (test_bit(FC_FABRIC, &vport->fc_flag)) {
1103 if (phba->sli_rev == LPFC_SLI_REV4 &&
1104 vport->port_type == LPFC_PHYSICAL_PORT &&
1105 phba->sli4_hba.fawwpn_flag &
1107 len += scnprintf(buf + len,
1109 " Fabric FA-PWWN\n");
1111 len += scnprintf(buf + len,
1115 len += scnprintf(buf + len, PAGE_SIZE-len,
1116 " Point-2-Point\n");
1121 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1122 ((bf_get(lpfc_sli_intf_if_type,
1123 &phba->sli4_hba.sli_intf) ==
1124 LPFC_SLI_INTF_IF_TYPE_6))) {
1125 struct lpfc_trunk_link link = phba->trunk_link;
1127 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
1128 len += scnprintf(buf + len, PAGE_SIZE - len,
1129 "Trunk port 0: Link %s %s\n",
1130 (link.link0.state == LPFC_LINK_UP) ?
1132 trunk_errmsg[link.link0.fault]);
1134 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
1135 len += scnprintf(buf + len, PAGE_SIZE - len,
1136 "Trunk port 1: Link %s %s\n",
1137 (link.link1.state == LPFC_LINK_UP) ?
1139 trunk_errmsg[link.link1.fault]);
1141 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
1142 len += scnprintf(buf + len, PAGE_SIZE - len,
1143 "Trunk port 2: Link %s %s\n",
1144 (link.link2.state == LPFC_LINK_UP) ?
1146 trunk_errmsg[link.link2.fault]);
1148 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
1149 len += scnprintf(buf + len, PAGE_SIZE - len,
1150 "Trunk port 3: Link %s %s\n",
1151 (link.link3.state == LPFC_LINK_UP) ?
1153 trunk_errmsg[link.link3.fault]);
1161 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
1162 * @dev: class unused variable.
1163 * @attr: device attribute, not used.
1164 * @buf: on return contains the module description text.
1166 * Returns: size of formatted string.
1169 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
1172 struct Scsi_Host *shost = class_to_shost(dev);
1173 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1174 struct lpfc_hba *phba = vport->phba;
1176 if (phba->sli_rev < LPFC_SLI_REV4)
1177 return scnprintf(buf, PAGE_SIZE, "fc\n");
1179 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
1180 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
1181 return scnprintf(buf, PAGE_SIZE, "fcoe\n");
1182 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
1183 return scnprintf(buf, PAGE_SIZE, "fc\n");
1185 return scnprintf(buf, PAGE_SIZE, "unknown\n");
1189 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1190 * (OAS) is supported.
1191 * @dev: class unused variable.
1192 * @attr: device attribute, not used.
1193 * @buf: on return contains the module description text.
1195 * Returns: size of formatted string.
1198 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1201 struct Scsi_Host *shost = class_to_shost(dev);
1202 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1203 struct lpfc_hba *phba = vport->phba;
1205 return scnprintf(buf, PAGE_SIZE, "%d\n",
1206 phba->sli4_hba.pc_sli4_params.oas_supported);
1210 * lpfc_link_state_store - Transition the link_state on an HBA port
1211 * @dev: class device that is converted into a Scsi_host.
1212 * @attr: device attribute, not used.
1213 * @buf: one or more lpfc_polling_flags values.
1217 * -EINVAL if the buffer is not "up" or "down"
1218 * return from link state change function if non-zero
1219 * length of the buf on success
1222 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1223 const char *buf, size_t count)
1225 struct Scsi_Host *shost = class_to_shost(dev);
1226 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1227 struct lpfc_hba *phba = vport->phba;
1229 int status = -EINVAL;
1231 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1232 (phba->link_state == LPFC_LINK_DOWN))
1233 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
1234 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1235 (phba->link_state >= LPFC_LINK_UP))
1236 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1245 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1246 * @dev: class device that is converted into a Scsi_host.
1247 * @attr: device attribute, not used.
1248 * @buf: on return contains the sum of fc mapped and unmapped.
1251 * Returns the ascii text number of the sum of the fc mapped and unmapped
1254 * Returns: size of formatted string.
1257 lpfc_num_discovered_ports_show(struct device *dev,
1258 struct device_attribute *attr, char *buf)
1260 struct Scsi_Host *shost = class_to_shost(dev);
1261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1263 return scnprintf(buf, PAGE_SIZE, "%d\n",
1264 atomic_read(&vport->fc_map_cnt) +
1265 atomic_read(&vport->fc_unmap_cnt));
1269 * lpfc_issue_lip - Misnomer, name carried over from long ago
1270 * @shost: Scsi_Host pointer.
1273 * Bring the link down gracefully then re-init the link. The firmware will
1274 * re-init the fiber channel interface as required. Does not issue a LIP.
1277 * -EPERM port offline or management commands are being blocked
1278 * -ENOMEM cannot allocate memory for the mailbox command
1279 * -EIO error sending the mailbox command
1283 lpfc_issue_lip(struct Scsi_Host *shost)
1285 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1286 struct lpfc_hba *phba = vport->phba;
1287 LPFC_MBOXQ_t *pmboxq;
1288 int mbxstatus = MBXERR_ERROR;
1291 * If the link is offline, disabled or BLOCK_MGMT_IO
1292 * it doesn't make any sense to allow issue_lip
1294 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
1295 test_bit(LINK_DISABLED, &phba->hba_flag) ||
1296 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1299 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1304 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1305 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1306 pmboxq->u.mb.mbxOwner = OWN_HOST;
1308 if (test_bit(FC_PT2PT, &vport->fc_flag))
1309 clear_bit(FC_PT2PT_NO_NVME, &vport->fc_flag);
1311 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1313 if ((mbxstatus == MBX_SUCCESS) &&
1314 (pmboxq->u.mb.mbxStatus == 0 ||
1315 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1316 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1317 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1318 phba->cfg_link_speed);
1319 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1320 phba->fc_ratov * 2);
1321 if ((mbxstatus == MBX_SUCCESS) &&
1322 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1323 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1324 "2859 SLI authentication is required "
1325 "for INIT_LINK but has not done yet\n");
1328 lpfc_set_loopback_flag(phba);
1329 if (mbxstatus != MBX_TIMEOUT)
1330 mempool_free(pmboxq, phba->mbox_mem_pool);
1332 if (mbxstatus == MBXERR_ERROR)
1339 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1343 spin_lock_irq(lock);
1344 while (!list_empty(q)) {
1345 spin_unlock_irq(lock);
1347 if (cnt++ > 250) { /* 5 secs */
1348 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1349 "0466 Outstanding IO when "
1350 "bringing Adapter offline\n");
1353 spin_lock_irq(lock);
1355 spin_unlock_irq(lock);
1360 * lpfc_do_offline - Issues a mailbox command to bring the link down
1361 * @phba: lpfc_hba pointer.
1362 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1365 * Assumes any error from lpfc_do_offline() will be negative.
1366 * Can wait up to 5 seconds for the port ring buffers count
1367 * to reach zero, prints a warning if it is not zero and continues.
1368 * lpfc_workq_post_event() returns a non-zero return code if call fails.
1371 * -EIO error posting the event
1375 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1377 struct completion online_compl;
1378 struct lpfc_queue *qp = NULL;
1379 struct lpfc_sli_ring *pring;
1380 struct lpfc_sli *psli;
1385 init_completion(&online_compl);
1386 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1387 LPFC_EVT_OFFLINE_PREP);
1391 wait_for_completion(&online_compl);
1399 * If freeing the queues have already started, don't access them.
1400 * Otherwise set FREE_WAIT to indicate that queues are being used
1401 * to hold the freeing process until we finish.
1403 spin_lock_irq(&phba->hbalock);
1404 if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {
1405 psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;
1407 spin_unlock_irq(&phba->hbalock);
1410 spin_unlock_irq(&phba->hbalock);
1412 /* Wait a little for things to settle down, but not
1413 * long enough for dev loss timeout to expire.
1415 if (phba->sli_rev != LPFC_SLI_REV4) {
1416 for (i = 0; i < psli->num_rings; i++) {
1417 pring = &psli->sli3_ring[i];
1418 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1423 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1427 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1433 spin_lock_irq(&phba->hbalock);
1434 psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;
1435 spin_unlock_irq(&phba->hbalock);
1438 init_completion(&online_compl);
1439 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1443 wait_for_completion(&online_compl);
1452 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1453 * @phba: lpfc_hba pointer.
1456 * Issues a PCI secondary bus reset for the phba->pcidev.
1459 * First walks the bus_list to ensure only PCI devices with Emulex
1460 * vendor id, device ids that support hot reset, only one occurrence
1461 * of function 0, and all ports on the bus are in offline mode to ensure the
1462 * hot reset only affects one valid HBA.
1465 * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1466 * -ENODEV, NULL ptr to pcidev
1467 * -EBADSLT, detected invalid device
1468 * -EBUSY, port is not in offline state
1472 lpfc_reset_pci_bus(struct lpfc_hba *phba)
1474 struct pci_dev *pdev = phba->pcidev;
1475 struct Scsi_Host *shost = NULL;
1476 struct lpfc_hba *phba_other = NULL;
1477 struct pci_dev *ptr = NULL;
1480 if (phba->cfg_enable_hba_reset != 2)
1484 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1488 res = lpfc_check_pci_resettable(phba);
1492 /* Walk the list of devices on the pci_dev's bus */
1493 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1494 /* Check port is offline */
1495 shost = pci_get_drvdata(ptr);
1498 ((struct lpfc_vport *)shost->hostdata)->phba;
1499 if (!test_bit(FC_OFFLINE_MODE,
1500 &phba_other->pport->fc_flag)) {
1501 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1502 "8349 WWPN = 0x%02x%02x%02x%02x"
1503 "%02x%02x%02x%02x is not "
1505 phba_other->wwpn[0],
1506 phba_other->wwpn[1],
1507 phba_other->wwpn[2],
1508 phba_other->wwpn[3],
1509 phba_other->wwpn[4],
1510 phba_other->wwpn[5],
1511 phba_other->wwpn[6],
1512 phba_other->wwpn[7]);
1518 /* Issue PCI bus reset */
1519 res = pci_reset_bus(pdev);
1521 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1522 "8350 PCI reset bus failed: %d\n", res);
1529 * lpfc_selective_reset - Offline then onlines the port
1530 * @phba: lpfc_hba pointer.
1533 * If the port is configured to allow a reset then the hba is brought
1534 * offline then online.
1537 * Assumes any error from lpfc_do_offline() will be negative.
1538 * Do not make this function static.
1541 * lpfc_do_offline() return code if not zero
1542 * -EIO reset not configured or error posting the event
1546 lpfc_selective_reset(struct lpfc_hba *phba)
1548 struct completion online_compl;
1552 if (!phba->cfg_enable_hba_reset)
1555 if (!test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag)) {
1556 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1562 init_completion(&online_compl);
1563 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1568 wait_for_completion(&online_compl);
1577 * lpfc_issue_reset - Selectively resets an adapter
1578 * @dev: class device that is converted into a Scsi_host.
1579 * @attr: device attribute, not used.
1580 * @buf: containing the string "selective".
1581 * @count: unused variable.
1584 * If the buf contains the string "selective" then lpfc_selective_reset()
1585 * is called to perform the reset.
1588 * Assumes any error from lpfc_selective_reset() will be negative.
1589 * If lpfc_selective_reset() returns zero then the length of the buffer
1590 * is returned which indicates success
1593 * -EINVAL if the buffer does not contain the string "selective"
1594 * length of buf if lpfc-selective_reset() if the call succeeds
1595 * return value of lpfc_selective_reset() if the call fails
1598 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1599 const char *buf, size_t count)
1601 struct Scsi_Host *shost = class_to_shost(dev);
1602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1603 struct lpfc_hba *phba = vport->phba;
1604 int status = -EINVAL;
1606 if (!phba->cfg_enable_hba_reset)
1609 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1610 status = phba->lpfc_selective_reset(phba);
1619 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1620 * @phba: lpfc_hba pointer.
1623 * SLI4 interface type-2 device to wait on the sliport status register for
1624 * the readyness after performing a firmware reset.
1627 * zero for success, -EPERM when port does not have privilege to perform the
1628 * reset, -EIO when port timeout from recovering from the reset.
1631 * As the caller will interpret the return code by value, be careful in making
1632 * change or addition to return codes.
1635 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1637 struct lpfc_register portstat_reg = {0};
1641 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1642 &portstat_reg.word0))
1645 /* verify if privileged for the request operation */
1646 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1647 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1650 /* There is no point to wait if the port is in an unrecoverable
1653 if (lpfc_sli4_unrecoverable_port(&portstat_reg))
1656 /* wait for the SLI port firmware ready after firmware reset */
1657 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1659 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1660 &portstat_reg.word0))
1662 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1664 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1666 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1671 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1678 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1679 * @phba: lpfc_hba pointer.
1680 * @opcode: The sli4 config command opcode.
1683 * Request SLI4 interface type-2 device to perform a physical register set
1690 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1692 struct completion online_compl;
1693 struct pci_dev *pdev = phba->pcidev;
1694 unsigned long before_fc_flag;
1695 uint32_t sriov_nr_virtfn;
1697 int status = 0, rc = 0;
1698 int job_posted = 1, sriov_err;
1700 if (!phba->cfg_enable_hba_reset)
1703 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1704 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1705 LPFC_SLI_INTF_IF_TYPE_2))
1708 /* Keep state if we need to restore back */
1709 before_fc_flag = phba->pport->fc_flag;
1710 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1712 if (opcode == LPFC_FW_DUMP) {
1713 init_completion(&online_compl);
1714 phba->fw_dump_cmpl = &online_compl;
1716 /* Disable SR-IOV virtual functions if enabled */
1717 if (phba->cfg_sriov_nr_virtfn) {
1718 pci_disable_sriov(pdev);
1719 phba->cfg_sriov_nr_virtfn = 0;
1722 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1727 /* wait for the device to be quiesced before firmware reset */
1731 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1732 LPFC_CTL_PDEV_CTL_OFFSET);
1734 if (opcode == LPFC_FW_DUMP)
1735 reg_val |= LPFC_FW_DUMP_REQUEST;
1736 else if (opcode == LPFC_FW_RESET)
1737 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1738 else if (opcode == LPFC_DV_RESET)
1739 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1741 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1742 LPFC_CTL_PDEV_CTL_OFFSET);
1744 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1746 /* delay driver action following IF_TYPE_2 reset */
1747 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1750 /* no privilege for reset */
1751 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1752 "3150 No privilege to perform the requested "
1753 "access: x%x\n", reg_val);
1754 } else if (rc == -EIO) {
1755 /* reset failed, there is nothing more we can do */
1756 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1757 "3153 Fail to perform the requested "
1758 "access: x%x\n", reg_val);
1759 if (phba->fw_dump_cmpl)
1760 phba->fw_dump_cmpl = NULL;
1764 /* keep the original port state */
1765 if (test_bit(FC_OFFLINE_MODE, &before_fc_flag)) {
1766 if (phba->fw_dump_cmpl)
1767 phba->fw_dump_cmpl = NULL;
1771 /* Firmware dump will trigger an HA_ERATT event, and
1772 * lpfc_handle_eratt_s4 routine already handles bringing the port back
1775 if (opcode == LPFC_FW_DUMP) {
1776 wait_for_completion(phba->fw_dump_cmpl);
1778 init_completion(&online_compl);
1779 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1784 wait_for_completion(&online_compl);
1787 /* in any case, restore the virtual functions enabled as before */
1788 if (sriov_nr_virtfn) {
1789 /* If fw_dump was performed, first disable to clean up */
1790 if (opcode == LPFC_FW_DUMP) {
1791 pci_disable_sriov(pdev);
1792 phba->cfg_sriov_nr_virtfn = 0;
1796 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1798 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1801 /* return proper error code */
1812 * lpfc_nport_evt_cnt_show - Return the number of nport events
1813 * @dev: class device that is converted into a Scsi_host.
1814 * @attr: device attribute, not used.
1815 * @buf: on return contains the ascii number of nport events.
1817 * Returns: size of formatted string.
1820 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1823 struct Scsi_Host *shost = class_to_shost(dev);
1824 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1825 struct lpfc_hba *phba = vport->phba;
1827 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1831 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1833 LPFC_MBOXQ_t *mbox = NULL;
1835 unsigned long val = 0;
1839 if (!strncmp("enable", buff_out,
1840 strlen("enable"))) {
1841 pval = buff_out + strlen("enable") + 1;
1842 rc = kstrtoul(pval, 0, &val);
1844 return rc; /* Invalid number */
1845 } else if (!strncmp("disable", buff_out,
1846 strlen("disable"))) {
1849 return -EINVAL; /* Invalid command */
1854 val = 0x0; /* Disable */
1857 val = 0x1; /* Enable two port trunk */
1860 val = 0x2; /* Enable four port trunk */
1866 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1867 "0070 Set trunk mode with val %ld ", val);
1869 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1873 payload_len = sizeof(struct lpfc_mbx_set_trunk_mode) -
1874 sizeof(struct lpfc_sli4_cfg_mhdr);
1875 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1876 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1877 payload_len, LPFC_SLI4_MBX_EMBED);
1879 bf_set(lpfc_mbx_set_trunk_mode,
1880 &mbox->u.mqe.un.set_trunk_mode,
1882 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1884 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1885 "0071 Set trunk mode failed with status: %d",
1887 mempool_free(mbox, phba->mbox_mem_pool);
1893 lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr,
1896 struct Scsi_Host *shost = class_to_shost(dev);
1897 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1898 struct lpfc_hba *phba = vport->phba;
1901 struct lpfc_rdp_context *rdp_context;
1909 struct sff_trasnceiver_codes_byte7 *trasn_code_byte7;
1911 /* Get transceiver information */
1912 rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL);
1914 len = scnprintf(buf, PAGE_SIZE - len,
1915 "SPF info NA: alloc failure\n");
1919 rc = lpfc_get_sfp_info_wait(phba, rdp_context);
1921 len = scnprintf(buf, PAGE_SIZE - len, "SFP info NA:\n");
1925 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_NAME], 16);
1927 len = scnprintf(buf, PAGE_SIZE - len, "VendorName:\t%s\n", chbuf);
1928 len += scnprintf(buf + len, PAGE_SIZE - len,
1929 "VendorOUI:\t%02x-%02x-%02x\n",
1930 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI],
1931 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 1],
1932 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 2]);
1933 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_PN], 16);
1934 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorPN:\t%s\n", chbuf);
1935 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_SN], 16);
1936 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorSN:\t%s\n", chbuf);
1937 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_REV], 4);
1938 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorRev:\t%s\n", chbuf);
1939 strscpy(chbuf, &rdp_context->page_a0[SSF_DATE_CODE], 8);
1940 len += scnprintf(buf + len, PAGE_SIZE - len, "DateCode:\t%s\n", chbuf);
1941 len += scnprintf(buf + len, PAGE_SIZE - len, "Identifier:\t%xh\n",
1942 (uint8_t)rdp_context->page_a0[SSF_IDENTIFIER]);
1943 len += scnprintf(buf + len, PAGE_SIZE - len, "ExtIdentifier:\t%xh\n",
1944 (uint8_t)rdp_context->page_a0[SSF_EXT_IDENTIFIER]);
1945 len += scnprintf(buf + len, PAGE_SIZE - len, "Connector:\t%xh\n",
1946 (uint8_t)rdp_context->page_a0[SSF_CONNECTOR]);
1947 wavelength = (rdp_context->page_a0[SSF_WAVELENGTH_B1] << 8) |
1948 rdp_context->page_a0[SSF_WAVELENGTH_B0];
1950 len += scnprintf(buf + len, PAGE_SIZE - len, "Wavelength:\t%d nm\n",
1952 trasn_code_byte7 = (struct sff_trasnceiver_codes_byte7 *)
1953 &rdp_context->page_a0[SSF_TRANSCEIVER_CODE_B7];
1955 len += scnprintf(buf + len, PAGE_SIZE - len, "Speeds: \t");
1956 if (*(uint8_t *)trasn_code_byte7 == 0) {
1957 len += scnprintf(buf + len, PAGE_SIZE - len, "Unknown\n");
1959 if (trasn_code_byte7->fc_sp_100MB)
1960 len += scnprintf(buf + len, PAGE_SIZE - len, "1 ");
1961 if (trasn_code_byte7->fc_sp_200mb)
1962 len += scnprintf(buf + len, PAGE_SIZE - len, "2 ");
1963 if (trasn_code_byte7->fc_sp_400MB)
1964 len += scnprintf(buf + len, PAGE_SIZE - len, "4 ");
1965 if (trasn_code_byte7->fc_sp_800MB)
1966 len += scnprintf(buf + len, PAGE_SIZE - len, "8 ");
1967 if (trasn_code_byte7->fc_sp_1600MB)
1968 len += scnprintf(buf + len, PAGE_SIZE - len, "16 ");
1969 if (trasn_code_byte7->fc_sp_3200MB)
1970 len += scnprintf(buf + len, PAGE_SIZE - len, "32 ");
1971 if (trasn_code_byte7->speed_chk_ecc)
1972 len += scnprintf(buf + len, PAGE_SIZE - len, "64 ");
1973 len += scnprintf(buf + len, PAGE_SIZE - len, "GB\n");
1975 temperature = (rdp_context->page_a2[SFF_TEMPERATURE_B1] << 8 |
1976 rdp_context->page_a2[SFF_TEMPERATURE_B0]);
1977 vcc = (rdp_context->page_a2[SFF_VCC_B1] << 8 |
1978 rdp_context->page_a2[SFF_VCC_B0]);
1979 tx_power = (rdp_context->page_a2[SFF_TXPOWER_B1] << 8 |
1980 rdp_context->page_a2[SFF_TXPOWER_B0]);
1981 tx_bias = (rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
1982 rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B0]);
1983 rx_power = (rdp_context->page_a2[SFF_RXPOWER_B1] << 8 |
1984 rdp_context->page_a2[SFF_RXPOWER_B0]);
1986 len += scnprintf(buf + len, PAGE_SIZE - len,
1987 "Temperature:\tx%04x C\n", temperature);
1988 len += scnprintf(buf + len, PAGE_SIZE - len, "Vcc:\t\tx%04x V\n", vcc);
1989 len += scnprintf(buf + len, PAGE_SIZE - len,
1990 "TxBiasCurrent:\tx%04x mA\n", tx_bias);
1991 len += scnprintf(buf + len, PAGE_SIZE - len, "TxPower:\tx%04x mW\n",
1993 len += scnprintf(buf + len, PAGE_SIZE - len, "RxPower:\tx%04x mW\n",
2001 * lpfc_board_mode_show - Return the state of the board
2002 * @dev: class device that is converted into a Scsi_host.
2003 * @attr: device attribute, not used.
2004 * @buf: on return contains the state of the adapter.
2006 * Returns: size of formatted string.
2009 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
2012 struct Scsi_Host *shost = class_to_shost(dev);
2013 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2014 struct lpfc_hba *phba = vport->phba;
2017 if (phba->link_state == LPFC_HBA_ERROR)
2019 else if (phba->link_state == LPFC_WARM_START)
2020 state = "warm start";
2021 else if (phba->link_state == LPFC_INIT_START)
2026 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
2030 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
2031 * @dev: class device that is converted into a Scsi_host.
2032 * @attr: device attribute, not used.
2033 * @buf: containing one of the strings "online", "offline", "warm" or "error".
2034 * @count: unused variable.
2037 * -EACCES if enable hba reset not enabled
2038 * -EINVAL if the buffer does not contain a valid string (see above)
2039 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
2040 * buf length greater than zero indicates success
2043 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
2044 const char *buf, size_t count)
2046 struct Scsi_Host *shost = class_to_shost(dev);
2047 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2048 struct lpfc_hba *phba = vport->phba;
2049 struct completion online_compl;
2050 char *board_mode_str = NULL;
2054 if (!phba->cfg_enable_hba_reset) {
2056 goto board_mode_out;
2059 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2060 "3050 lpfc_board_mode set to %s\n", buf);
2062 init_completion(&online_compl);
2064 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
2065 rc = lpfc_workq_post_event(phba, &status, &online_compl,
2069 goto board_mode_out;
2071 wait_for_completion(&online_compl);
2074 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
2075 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2076 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
2077 if (phba->sli_rev == LPFC_SLI_REV4)
2080 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
2081 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
2082 if (phba->sli_rev == LPFC_SLI_REV4)
2085 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
2086 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
2087 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
2088 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
2089 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
2090 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
2091 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
2092 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
2094 status = lpfc_reset_pci_bus(phba);
2095 else if (strncmp(buf, "heartbeat", sizeof("heartbeat") - 1) == 0)
2096 lpfc_issue_hb_tmo(phba);
2097 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
2098 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
2106 board_mode_str = strchr(buf, '\n');
2108 *board_mode_str = '\0';
2109 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2110 "3097 Failed \"%s\", status(%d), "
2112 buf, status, phba->pport->fc_flag);
2118 * lpfc_get_hba_info - Return various bits of informaton about the adapter
2119 * @phba: pointer to the adapter structure.
2120 * @mxri: max xri count.
2121 * @axri: available xri count.
2122 * @mrpi: max rpi count.
2123 * @arpi: available rpi count.
2124 * @mvpi: max vpi count.
2125 * @avpi: available vpi count.
2128 * If an integer pointer for an count is not null then the value for the
2129 * count is returned.
2136 lpfc_get_hba_info(struct lpfc_hba *phba,
2137 uint32_t *mxri, uint32_t *axri,
2138 uint32_t *mrpi, uint32_t *arpi,
2139 uint32_t *mvpi, uint32_t *avpi)
2141 LPFC_MBOXQ_t *pmboxq;
2144 struct lpfc_sli4_hba *sli4_hba;
2145 struct lpfc_max_cfg_param *max_cfg_param;
2146 u16 rsrc_ext_cnt, rsrc_ext_size, max_vpi;
2149 * prevent udev from issuing mailbox commands until the port is
2152 if (phba->link_state < LPFC_LINK_DOWN ||
2153 !phba->mbox_mem_pool ||
2154 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
2157 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
2160 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2163 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2165 pmb = &pmboxq->u.mb;
2166 pmb->mbxCommand = MBX_READ_CONFIG;
2167 pmb->mbxOwner = OWN_HOST;
2168 pmboxq->ctx_buf = NULL;
2170 if (test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))
2171 rc = MBX_NOT_FINISHED;
2173 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2175 if (rc != MBX_SUCCESS) {
2176 if (rc != MBX_TIMEOUT)
2177 mempool_free(pmboxq, phba->mbox_mem_pool);
2181 if (phba->sli_rev == LPFC_SLI_REV4) {
2182 sli4_hba = &phba->sli4_hba;
2183 max_cfg_param = &sli4_hba->max_cfg_param;
2185 /* Normally, extents are not used */
2186 if (!phba->sli4_hba.extents_in_use) {
2188 *mrpi = max_cfg_param->max_rpi;
2190 *mxri = max_cfg_param->max_xri;
2192 max_vpi = max_cfg_param->max_vpi;
2194 /* Limit the max we support */
2195 if (max_vpi > LPFC_MAX_VPI)
2196 max_vpi = LPFC_MAX_VPI;
2199 } else { /* Extents in use */
2201 if (lpfc_sli4_get_avail_extnt_rsrc(phba,
2202 LPFC_RSC_TYPE_FCOE_RPI,
2209 *mrpi = rsrc_ext_cnt * rsrc_ext_size;
2213 if (lpfc_sli4_get_avail_extnt_rsrc(phba,
2214 LPFC_RSC_TYPE_FCOE_XRI,
2221 *mxri = rsrc_ext_cnt * rsrc_ext_size;
2225 if (lpfc_sli4_get_avail_extnt_rsrc(phba,
2226 LPFC_RSC_TYPE_FCOE_VPI,
2233 max_vpi = rsrc_ext_cnt * rsrc_ext_size;
2235 /* Limit the max we support */
2236 if (max_vpi > LPFC_MAX_VPI)
2237 max_vpi = LPFC_MAX_VPI;
2243 *mrpi = pmb->un.varRdConfig.max_rpi;
2245 *arpi = pmb->un.varRdConfig.avail_rpi;
2247 *mxri = pmb->un.varRdConfig.max_xri;
2249 *axri = pmb->un.varRdConfig.avail_xri;
2251 *mvpi = pmb->un.varRdConfig.max_vpi;
2253 /* avail_vpi is only valid if link is up and ready */
2254 if (phba->link_state == LPFC_HBA_READY)
2255 *avpi = pmb->un.varRdConfig.avail_vpi;
2257 *avpi = pmb->un.varRdConfig.max_vpi;
2265 mempool_free(pmboxq, phba->mbox_mem_pool);
2270 * lpfc_max_rpi_show - Return maximum rpi
2271 * @dev: class device that is converted into a Scsi_host.
2272 * @attr: device attribute, not used.
2273 * @buf: on return contains the maximum rpi 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_rpi_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, NULL, NULL, &cnt, NULL, NULL, NULL))
2293 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2294 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2298 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
2299 * @dev: class device that is converted into a Scsi_host.
2300 * @attr: device attribute, not used.
2301 * @buf: containing the used rpi count in decimal or "Unknown".
2304 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi 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_rpi_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;
2318 struct lpfc_sli4_hba *sli4_hba;
2319 struct lpfc_max_cfg_param *max_cfg_param;
2320 u32 cnt = 0, acnt = 0;
2322 if (phba->sli_rev == LPFC_SLI_REV4) {
2323 sli4_hba = &phba->sli4_hba;
2324 max_cfg_param = &sli4_hba->max_cfg_param;
2325 return scnprintf(buf, PAGE_SIZE, "%d\n",
2326 max_cfg_param->rpi_used);
2328 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
2329 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2331 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2335 * lpfc_max_xri_show - Return maximum xri
2336 * @dev: class device that is converted into a Scsi_host.
2337 * @attr: device attribute, not used.
2338 * @buf: on return contains the maximum xri count in decimal or "Unknown".
2341 * Calls lpfc_get_hba_info() asking for just the mrpi count.
2342 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2343 * to "Unknown" and the buffer length is returned, therefore the caller
2344 * must check for "Unknown" in the buffer to detect a failure.
2346 * Returns: size of formatted string.
2349 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
2352 struct Scsi_Host *shost = class_to_shost(dev);
2353 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2354 struct lpfc_hba *phba = vport->phba;
2357 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2358 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2359 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2363 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2364 * @dev: class device that is converted into a Scsi_host.
2365 * @attr: device attribute, not used.
2366 * @buf: on return contains the used xri count in decimal or "Unknown".
2369 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2370 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2371 * to "Unknown" and the buffer length is returned, therefore the caller
2372 * must check for "Unknown" in the buffer to detect a failure.
2374 * Returns: size of formatted string.
2377 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2380 struct Scsi_Host *shost = class_to_shost(dev);
2381 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2382 struct lpfc_hba *phba = vport->phba;
2383 struct lpfc_sli4_hba *sli4_hba;
2384 struct lpfc_max_cfg_param *max_cfg_param;
2385 u32 cnt = 0, acnt = 0;
2387 if (phba->sli_rev == LPFC_SLI_REV4) {
2388 sli4_hba = &phba->sli4_hba;
2389 max_cfg_param = &sli4_hba->max_cfg_param;
2390 return scnprintf(buf, PAGE_SIZE, "%d\n",
2391 max_cfg_param->xri_used);
2393 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2394 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2396 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2400 * lpfc_max_vpi_show - Return maximum vpi
2401 * @dev: class device that is converted into a Scsi_host.
2402 * @attr: device attribute, not used.
2403 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2406 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2407 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2408 * to "Unknown" and the buffer length is returned, therefore the caller
2409 * must check for "Unknown" in the buffer to detect a failure.
2411 * Returns: size of formatted string.
2414 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2417 struct Scsi_Host *shost = class_to_shost(dev);
2418 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2419 struct lpfc_hba *phba = vport->phba;
2422 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2423 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2424 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2428 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2429 * @dev: class device that is converted into a Scsi_host.
2430 * @attr: device attribute, not used.
2431 * @buf: on return contains the used vpi count in decimal or "Unknown".
2434 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2435 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2436 * to "Unknown" and the buffer length is returned, therefore the caller
2437 * must check for "Unknown" in the buffer to detect a failure.
2439 * Returns: size of formatted string.
2442 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2445 struct Scsi_Host *shost = class_to_shost(dev);
2446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2447 struct lpfc_hba *phba = vport->phba;
2448 struct lpfc_sli4_hba *sli4_hba;
2449 struct lpfc_max_cfg_param *max_cfg_param;
2450 u32 cnt = 0, acnt = 0;
2452 if (phba->sli_rev == LPFC_SLI_REV4) {
2453 sli4_hba = &phba->sli4_hba;
2454 max_cfg_param = &sli4_hba->max_cfg_param;
2455 return scnprintf(buf, PAGE_SIZE, "%d\n",
2456 max_cfg_param->vpi_used);
2458 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2459 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2461 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2465 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2466 * @dev: class device that is converted into a Scsi_host.
2467 * @attr: device attribute, not used.
2468 * @buf: text that must be interpreted to determine if npiv is supported.
2471 * Buffer will contain text indicating npiv is not suppoerted on the port,
2472 * the port is an NPIV physical port, or it is an npiv virtual port with
2473 * the id of the vport.
2475 * Returns: size of formatted string.
2478 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2481 struct Scsi_Host *shost = class_to_shost(dev);
2482 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2483 struct lpfc_hba *phba = vport->phba;
2485 if (!(phba->max_vpi))
2486 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2487 if (vport->port_type == LPFC_PHYSICAL_PORT)
2488 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2489 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2493 * lpfc_poll_show - Return text about poll support for the adapter
2494 * @dev: class device that is converted into a Scsi_host.
2495 * @attr: device attribute, not used.
2496 * @buf: on return contains the cfg_poll in hex.
2499 * cfg_poll should be a lpfc_polling_flags type.
2501 * Returns: size of formatted string.
2504 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2507 struct Scsi_Host *shost = class_to_shost(dev);
2508 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2509 struct lpfc_hba *phba = vport->phba;
2511 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2515 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2516 * @dev: class device that is converted into a Scsi_host.
2517 * @attr: device attribute, not used.
2518 * @buf: one or more lpfc_polling_flags values.
2522 * buf contents converted to integer and checked for a valid value.
2525 * -EINVAL if the buffer connot be converted or is out of range
2526 * length of the buf on success
2529 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2530 const char *buf, size_t count)
2532 struct Scsi_Host *shost = class_to_shost(dev);
2533 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2534 struct lpfc_hba *phba = vport->phba;
2539 if (!isdigit(buf[0]))
2542 if (sscanf(buf, "%i", &val) != 1)
2545 if ((val & 0x3) != val)
2548 if (phba->sli_rev == LPFC_SLI_REV4)
2551 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2552 "3051 lpfc_poll changed from %d to %d\n",
2553 phba->cfg_poll, val);
2555 spin_lock_irq(&phba->hbalock);
2557 old_val = phba->cfg_poll;
2559 if (val & ENABLE_FCP_RING_POLLING) {
2560 if ((val & DISABLE_FCP_RING_INT) &&
2561 !(old_val & DISABLE_FCP_RING_INT)) {
2562 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2563 spin_unlock_irq(&phba->hbalock);
2566 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2567 writel(creg_val, phba->HCregaddr);
2568 readl(phba->HCregaddr); /* flush */
2570 lpfc_poll_start_timer(phba);
2572 } else if (val != 0x0) {
2573 spin_unlock_irq(&phba->hbalock);
2577 if (!(val & DISABLE_FCP_RING_INT) &&
2578 (old_val & DISABLE_FCP_RING_INT))
2580 spin_unlock_irq(&phba->hbalock);
2581 del_timer(&phba->fcp_poll_timer);
2582 spin_lock_irq(&phba->hbalock);
2583 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2584 spin_unlock_irq(&phba->hbalock);
2587 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2588 writel(creg_val, phba->HCregaddr);
2589 readl(phba->HCregaddr); /* flush */
2592 phba->cfg_poll = val;
2594 spin_unlock_irq(&phba->hbalock);
2600 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2601 * @dev: class converted to a Scsi_host structure.
2602 * @attr: device attribute, not used.
2603 * @buf: on return contains the formatted support level.
2606 * Returns the maximum number of virtual functions a physical function can
2607 * support, 0 will be returned if called on virtual function.
2609 * Returns: size of formatted string.
2612 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2613 struct device_attribute *attr,
2616 struct Scsi_Host *shost = class_to_shost(dev);
2617 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2618 struct lpfc_hba *phba = vport->phba;
2619 uint16_t max_nr_virtfn;
2621 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2622 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2626 * lpfc_enable_bbcr_set: Sets an attribute value.
2627 * @phba: pointer to the adapter structure.
2628 * @val: integer attribute value.
2631 * Validates the min and max values then sets the
2632 * adapter config field if in the valid range. prints error message
2633 * and does not set the parameter if invalid.
2637 * -EINVAL if val is invalid
2640 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2642 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2643 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2644 "3068 lpfc_enable_bbcr changed from %d to "
2645 "%d\n", phba->cfg_enable_bbcr, val);
2646 phba->cfg_enable_bbcr = val;
2649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2650 "0451 lpfc_enable_bbcr cannot set to %d, range is 0, "
2656 * lpfc_param_show - Return a cfg attribute value in decimal
2659 * Macro that given an attr e.g. hba_queue_depth expands
2660 * into a function with the name lpfc_hba_queue_depth_show.
2662 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2663 * @dev: class device that is converted into a Scsi_host.
2664 * @attr: device attribute, not used.
2665 * @buf: on return contains the attribute value in decimal.
2667 * Returns: size of formatted string.
2669 #define lpfc_param_show(attr) \
2671 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2674 struct Scsi_Host *shost = class_to_shost(dev);\
2675 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2676 struct lpfc_hba *phba = vport->phba;\
2677 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2682 * lpfc_param_hex_show - Return a cfg attribute value in hex
2685 * Macro that given an attr e.g. hba_queue_depth expands
2686 * into a function with the name lpfc_hba_queue_depth_show
2688 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2689 * @dev: class device that is converted into a Scsi_host.
2690 * @attr: device attribute, not used.
2691 * @buf: on return contains the attribute value in hexadecimal.
2693 * Returns: size of formatted string.
2695 #define lpfc_param_hex_show(attr) \
2697 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2700 struct Scsi_Host *shost = class_to_shost(dev);\
2701 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2702 struct lpfc_hba *phba = vport->phba;\
2704 val = phba->cfg_##attr;\
2705 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2710 * lpfc_param_init - Initializes a cfg attribute
2713 * Macro that given an attr e.g. hba_queue_depth expands
2714 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2715 * takes a default argument, a minimum and maximum argument.
2717 * lpfc_##attr##_init: Initializes an attribute.
2718 * @phba: pointer to the adapter structure.
2719 * @val: integer attribute value.
2721 * Validates the min and max values then sets the adapter config field
2722 * accordingly, or uses the default if out of range and prints an error message.
2726 * -EINVAL if default used
2728 #define lpfc_param_init(attr, default, minval, maxval) \
2730 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2732 if (lpfc_rangecheck(val, minval, maxval)) {\
2733 phba->cfg_##attr = val;\
2736 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2737 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2738 "allowed range is ["#minval", "#maxval"]\n", val); \
2739 phba->cfg_##attr = default;\
2744 * lpfc_param_set - Set a cfg attribute value
2747 * Macro that given an attr e.g. hba_queue_depth expands
2748 * into a function with the name lpfc_hba_queue_depth_set
2750 * lpfc_##attr##_set: Sets an attribute value.
2751 * @phba: pointer to the adapter structure.
2752 * @val: integer attribute value.
2755 * Validates the min and max values then sets the
2756 * adapter config field if in the valid range. prints error message
2757 * and does not set the parameter if invalid.
2761 * -EINVAL if val is invalid
2763 #define lpfc_param_set(attr, default, minval, maxval) \
2765 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2767 if (lpfc_rangecheck(val, minval, maxval)) {\
2768 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2769 "3052 lpfc_" #attr " changed from %d to %d\n", \
2770 phba->cfg_##attr, val); \
2771 phba->cfg_##attr = val;\
2774 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2775 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2776 "allowed range is ["#minval", "#maxval"]\n", val); \
2781 * lpfc_param_store - Set a vport attribute value
2784 * Macro that given an attr e.g. hba_queue_depth expands
2785 * into a function with the name lpfc_hba_queue_depth_store.
2787 * lpfc_##attr##_store: Set an sttribute value.
2788 * @dev: class device that is converted into a Scsi_host.
2789 * @attr: device attribute, not used.
2790 * @buf: contains the attribute value in ascii.
2794 * Convert the ascii text number to an integer, then
2795 * use the lpfc_##attr##_set function to set the value.
2798 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2799 * length of buffer upon success.
2801 #define lpfc_param_store(attr) \
2803 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2804 const char *buf, size_t count) \
2806 struct Scsi_Host *shost = class_to_shost(dev);\
2807 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2808 struct lpfc_hba *phba = vport->phba;\
2810 if (!isdigit(buf[0]))\
2812 if (sscanf(buf, "%i", &val) != 1)\
2814 if (lpfc_##attr##_set(phba, val) == 0) \
2815 return strlen(buf);\
2821 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2824 * Macro that given an attr e.g. hba_queue_depth expands
2825 * into a function with the name lpfc_hba_queue_depth_show
2827 * lpfc_##attr##_show: prints the attribute value in decimal.
2828 * @dev: class device that is converted into a Scsi_host.
2829 * @attr: device attribute, not used.
2830 * @buf: on return contains the attribute value in decimal.
2832 * Returns: length of formatted string.
2834 #define lpfc_vport_param_show(attr) \
2836 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2839 struct Scsi_Host *shost = class_to_shost(dev);\
2840 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2841 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2845 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2848 * Macro that given an attr e.g.
2849 * hba_queue_depth expands into a function with the name
2850 * lpfc_hba_queue_depth_show
2852 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2853 * @dev: class device that is converted into a Scsi_host.
2854 * @attr: device attribute, not used.
2855 * @buf: on return contains the attribute value in hexadecimal.
2857 * Returns: length of formatted string.
2859 #define lpfc_vport_param_hex_show(attr) \
2861 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2864 struct Scsi_Host *shost = class_to_shost(dev);\
2865 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2866 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2870 * lpfc_vport_param_init - Initialize a vport cfg attribute
2873 * Macro that given an attr e.g. hba_queue_depth expands
2874 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2875 * takes a default argument, a minimum and maximum argument.
2877 * lpfc_##attr##_init: validates the min and max values then sets the
2878 * adapter config field accordingly, or uses the default if out of range
2879 * and prints an error message.
2880 * @phba: pointer to the adapter structure.
2881 * @val: integer attribute value.
2885 * -EINVAL if default used
2887 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2889 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2891 if (lpfc_rangecheck(val, minval, maxval)) {\
2892 vport->cfg_##attr = val;\
2895 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2896 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2897 "allowed range is ["#minval", "#maxval"]\n", val); \
2898 vport->cfg_##attr = default;\
2903 * lpfc_vport_param_set - Set a vport cfg attribute
2906 * Macro that given an attr e.g. hba_queue_depth expands
2907 * into a function with the name lpfc_hba_queue_depth_set
2909 * lpfc_##attr##_set: validates the min and max values then sets the
2910 * adapter config field if in the valid range. prints error message
2911 * and does not set the parameter if invalid.
2912 * @phba: pointer to the adapter structure.
2913 * @val: integer attribute value.
2917 * -EINVAL if val is invalid
2919 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2921 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2923 if (lpfc_rangecheck(val, minval, maxval)) {\
2924 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2925 "3053 lpfc_" #attr \
2926 " changed from %d (x%x) to %d (x%x)\n", \
2927 vport->cfg_##attr, vport->cfg_##attr, \
2929 vport->cfg_##attr = val;\
2932 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2933 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2934 "allowed range is ["#minval", "#maxval"]\n", val); \
2939 * lpfc_vport_param_store - Set a vport attribute
2942 * Macro that given an attr e.g. hba_queue_depth
2943 * expands into a function with the name lpfc_hba_queue_depth_store
2945 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2946 * use the lpfc_##attr##_set function to set the value.
2947 * @cdev: class device that is converted into a Scsi_host.
2948 * @buf: contains the attribute value in decimal.
2952 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2953 * length of buffer upon success.
2955 #define lpfc_vport_param_store(attr) \
2957 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2958 const char *buf, size_t count) \
2960 struct Scsi_Host *shost = class_to_shost(dev);\
2961 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2963 if (!isdigit(buf[0]))\
2965 if (sscanf(buf, "%i", &val) != 1)\
2967 if (lpfc_##attr##_set(vport, val) == 0) \
2968 return strlen(buf);\
2974 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2975 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2976 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2977 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2978 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2979 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2980 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2981 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2982 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2983 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2984 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2985 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2986 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2987 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2988 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2989 lpfc_link_state_store);
2990 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2991 lpfc_option_rom_version_show, NULL);
2992 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2993 lpfc_num_discovered_ports_show, NULL);
2994 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2995 static DEVICE_ATTR_RO(lpfc_drvr_version);
2996 static DEVICE_ATTR_RO(lpfc_enable_fip);
2997 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2998 lpfc_board_mode_show, lpfc_board_mode_store);
2999 static DEVICE_ATTR_RO(lpfc_xcvr_data);
3000 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
3001 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
3002 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
3003 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
3004 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
3005 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
3006 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
3007 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
3008 static DEVICE_ATTR_RO(lpfc_temp_sensor);
3009 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
3010 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
3011 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
3013 static DEVICE_ATTR(cmf_info, 0444, lpfc_cmf_info_show, NULL);
3017 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
3019 * @cnt: Length of string.
3020 * @wwn: Array to receive converted wwn value.
3023 * -EINVAL if the buffer does not contain a valid wwn
3027 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
3031 /* Count may include a LF at end of string */
3032 if (buf[cnt-1] == '\n')
3035 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
3036 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
3039 memset(wwn, 0, WWN_SZ);
3041 /* Validate and store the new name */
3042 for (i = 0, j = 0; i < 16; i++) {
3043 if ((*buf >= 'a') && (*buf <= 'f'))
3044 j = ((j << 4) | ((*buf++ - 'a') + 10));
3045 else if ((*buf >= 'A') && (*buf <= 'F'))
3046 j = ((j << 4) | ((*buf++ - 'A') + 10));
3047 else if ((*buf >= '0') && (*buf <= '9'))
3048 j = ((j << 4) | (*buf++ - '0'));
3052 wwn[i/2] = j & 0xff;
3061 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
3062 * Optimized Access Storage (OAS) operations.
3063 * @dev: class device that is converted into a Scsi_host.
3064 * @attr: device attribute, not used.
3065 * @buf: buffer for passing information.
3071 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
3074 struct Scsi_Host *shost = class_to_shost(dev);
3075 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3077 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3078 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
3082 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
3083 * Optimized Access Storage (OAS) operations.
3084 * @dev: class device that is converted into a Scsi_host.
3085 * @attr: device attribute, not used.
3086 * @buf: buffer for passing information.
3087 * @count: Size of the data buffer.
3090 * -EINVAL count is invalid, invalid wwpn byte invalid
3091 * -EPERM oas is not supported by hba
3092 * value of count on success
3095 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
3096 const char *buf, size_t count)
3098 struct Scsi_Host *shost = class_to_shost(dev);
3099 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3100 unsigned int cnt = count;
3101 uint8_t wwpn[WWN_SZ];
3107 /* count may include a LF at end of string */
3108 if (buf[cnt-1] == '\n')
3111 rc = lpfc_wwn_set(buf, cnt, wwpn);
3115 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3116 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3117 if (wwn_to_u64(wwpn) == 0)
3118 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
3120 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
3121 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3122 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3125 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
3126 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
3129 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
3130 * Optimized Access Storage (OAS) operations.
3131 * @dev: class device that is converted into a Scsi_host.
3132 * @attr: device attribute, not used.
3133 * @buf: buffer for passing information.
3139 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3142 struct Scsi_Host *shost = class_to_shost(dev);
3143 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3145 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3149 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3150 * Optimized Access Storage (OAS) operations.
3151 * @dev: class device that is converted into a Scsi_host.
3152 * @attr: device attribute, not used.
3153 * @buf: buffer for passing information.
3154 * @count: Size of the data buffer.
3157 * -EINVAL count is invalid, invalid wwpn byte invalid
3158 * -EPERM oas is not supported by hba
3159 * value of count on success
3162 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3163 const char *buf, size_t count)
3165 struct Scsi_Host *shost = class_to_shost(dev);
3166 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3167 unsigned int cnt = count;
3174 /* count may include a LF at end of string */
3175 if (buf[cnt-1] == '\n')
3178 ret = kstrtoul(buf, 0, &val);
3179 if (ret || (val > 0x7f))
3183 phba->cfg_oas_priority = (uint8_t)val;
3185 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3188 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3189 lpfc_oas_priority_show, lpfc_oas_priority_store);
3192 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3193 * for Optimized Access Storage (OAS) operations.
3194 * @dev: class device that is converted into a Scsi_host.
3195 * @attr: device attribute, not used.
3196 * @buf: buffer for passing information.
3199 * value of count on success
3202 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3205 struct Scsi_Host *shost = class_to_shost(dev);
3206 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3208 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3209 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3213 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3214 * for Optimized Access Storage (OAS) operations.
3215 * @dev: class device that is converted into a Scsi_host.
3216 * @attr: device attribute, not used.
3217 * @buf: buffer for passing information.
3218 * @count: Size of the data buffer.
3221 * -EINVAL count is invalid, invalid wwpn byte invalid
3222 * -EPERM oas is not supported by hba
3223 * value of count on success
3226 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3227 const char *buf, size_t count)
3229 struct Scsi_Host *shost = class_to_shost(dev);
3230 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3231 unsigned int cnt = count;
3232 uint8_t wwpn[WWN_SZ];
3238 /* count may include a LF at end of string */
3239 if (buf[cnt-1] == '\n')
3242 rc = lpfc_wwn_set(buf, cnt, wwpn);
3246 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3247 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3248 if (wwn_to_u64(wwpn) == 0)
3249 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3251 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3252 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3253 if (phba->cfg_oas_priority == 0)
3254 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3255 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3258 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3259 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3262 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3263 * of whether luns will be enabled or disabled
3264 * for Optimized Access Storage (OAS) operations.
3265 * @dev: class device that is converted into a Scsi_host.
3266 * @attr: device attribute, not used.
3267 * @buf: buffer for passing information.
3270 * size of formatted string.
3273 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3276 struct Scsi_Host *shost = class_to_shost(dev);
3277 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3279 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3283 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3284 * of whether luns will be enabled or disabled
3285 * for Optimized Access Storage (OAS) operations.
3286 * @dev: class device that is converted into a Scsi_host.
3287 * @attr: device attribute, not used.
3288 * @buf: buffer for passing information.
3289 * @count: Size of the data buffer.
3292 * -EINVAL count is invalid, invalid wwpn byte invalid
3293 * -EPERM oas is not supported by hba
3294 * value of count on success
3297 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3298 const char *buf, size_t count)
3300 struct Scsi_Host *shost = class_to_shost(dev);
3301 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3307 if (!isdigit(buf[0]))
3310 if (sscanf(buf, "%i", &val) != 1)
3313 if ((val != 0) && (val != 1))
3316 phba->cfg_oas_lun_state = val;
3319 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3320 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3323 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3324 * Storage (OAS) lun returned by the
3325 * lpfc_oas_lun_show function.
3326 * @dev: class device that is converted into a Scsi_host.
3327 * @attr: device attribute, not used.
3328 * @buf: buffer for passing information.
3331 * size of formatted string.
3334 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3337 struct Scsi_Host *shost = class_to_shost(dev);
3338 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3340 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3343 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3345 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3346 lpfc_oas_lun_status_show, NULL);
3350 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3352 * @phba: lpfc_hba pointer.
3353 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3354 * @tgt_wwpn: wwpn of the target associated with the returned lun
3355 * @lun: the fc lun for setting oas state.
3356 * @oas_state: the oas state to be set to the lun.
3361 * -EPERM OAS is not enabled or not supported by this port.
3365 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3366 uint8_t tgt_wwpn[], uint64_t lun,
3367 uint32_t oas_state, uint8_t pri)
3376 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3377 (struct lpfc_name *)tgt_wwpn,
3381 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3382 (struct lpfc_name *)tgt_wwpn, lun, pri);
3389 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3390 * Access Storage (OAS) operations.
3391 * @phba: lpfc_hba pointer.
3392 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3393 * @tgt_wwpn: wwpn of the target associated with the returned lun
3394 * @lun_status: status of the lun returned lun
3395 * @lun_pri: priority of the lun returned lun
3397 * Returns the first or next lun enabled for OAS operations for the vport/target
3398 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3399 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3402 * lun that is OAS enabled for the vport/target
3403 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3406 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3407 uint8_t tgt_wwpn[], uint32_t *lun_status,
3412 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3413 return NOT_OAS_ENABLED_LUN;
3414 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3415 phba->sli4_hba.oas_next_vpt_wwpn,
3416 (struct lpfc_name *)
3417 phba->sli4_hba.oas_next_tgt_wwpn,
3418 &phba->sli4_hba.oas_next_lun,
3419 (struct lpfc_name *)vpt_wwpn,
3420 (struct lpfc_name *)tgt_wwpn,
3421 &found_lun, lun_status, lun_pri))
3424 return NOT_OAS_ENABLED_LUN;
3428 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3429 * @phba: lpfc_hba pointer.
3430 * @vpt_wwpn: vport wwpn by reference.
3431 * @tgt_wwpn: target wwpn by reference.
3432 * @lun: the fc lun for setting oas state.
3433 * @oas_state: the oas state to be set to the oas_lun.
3436 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3437 * a lun for OAS operations.
3441 * -ENOMEM: failed to enable an lun for OAS operations
3442 * -EPERM: OAS is not enabled
3445 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3446 uint8_t tgt_wwpn[], uint64_t lun,
3447 uint32_t oas_state, uint8_t pri)
3452 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3458 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3459 * @dev: class device that is converted into a Scsi_host.
3460 * @attr: device attribute, not used.
3461 * @buf: buffer for passing information.
3463 * This routine returns a lun enabled for OAS each time the function
3467 * SUCCESS: size of formatted string.
3468 * -EFAULT: target or vport wwpn was not set properly.
3469 * -EPERM: oas is not enabled.
3472 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3475 struct Scsi_Host *shost = class_to_shost(dev);
3476 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3484 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3485 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3488 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3489 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3492 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3493 phba->cfg_oas_tgt_wwpn,
3494 &phba->cfg_oas_lun_status,
3495 &phba->cfg_oas_priority);
3496 if (oas_lun != NOT_OAS_ENABLED_LUN)
3497 phba->cfg_oas_flags |= OAS_LUN_VALID;
3499 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3505 * lpfc_oas_lun_store - Sets the OAS state for lun
3506 * @dev: class device that is converted into a Scsi_host.
3507 * @attr: device attribute, not used.
3508 * @buf: buffer for passing information.
3509 * @count: size of the formatting string
3511 * This function sets the OAS state for lun. Before this function is called,
3512 * the vport wwpn, target wwpn, and oas state need to be set.
3515 * SUCCESS: size of formatted string.
3516 * -EFAULT: target or vport wwpn was not set properly.
3517 * -EPERM: oas is not enabled.
3518 * size of formatted string.
3521 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3522 const char *buf, size_t count)
3524 struct Scsi_Host *shost = class_to_shost(dev);
3525 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3533 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3536 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3539 if (!isdigit(buf[0]))
3542 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3545 pri = phba->cfg_oas_priority;
3547 pri = phba->cfg_XLanePriority;
3549 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3550 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3551 "priority 0x%x with oas state %d\n",
3552 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3553 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3554 pri, phba->cfg_oas_lun_state);
3556 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3557 phba->cfg_oas_tgt_wwpn, scsi_lun,
3558 phba->cfg_oas_lun_state, pri);
3564 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3565 lpfc_oas_lun_show, lpfc_oas_lun_store);
3567 int lpfc_enable_nvmet_cnt;
3568 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3569 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3570 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3571 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3572 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3574 static int lpfc_poll = 0;
3575 module_param(lpfc_poll, int, S_IRUGO);
3576 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3578 " 1 - poll with interrupts enabled"
3579 " 3 - poll and disable FCP ring interrupts");
3581 static DEVICE_ATTR_RW(lpfc_poll);
3583 int lpfc_no_hba_reset_cnt;
3584 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3585 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3586 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3587 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3589 LPFC_ATTR(sli_mode, 3, 3, 3,
3590 "SLI mode selector: 3 - select SLI-3");
3592 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3593 "Enable NPIV functionality");
3595 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3596 "FCF Fast failover=1 Priority failover=2");
3599 * lpfc_fcp_wait_abts_rsp: Modifies criteria for reporting completion of
3601 * The range is [0,1]. Default value is 0
3602 * 0, IO completes after ABTS issued (default).
3603 * 1, IO completes after receipt of ABTS response or timeout.
3605 LPFC_ATTR_R(fcp_wait_abts_rsp, 0, 0, 1, "Wait for FCP ABTS completion");
3608 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3609 # 0x0 = disabled, XRI/OXID use not tracked.
3610 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3611 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3613 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3614 "Enable RRQ functionality");
3617 # lpfc_suppress_link_up: Bring link up at initialization
3618 # 0x0 = bring link up (issue MBX_INIT_LINK)
3619 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3620 # 0x2 = never bring up link
3621 # Default value is 0.
3623 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3624 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3625 "Suppress Link Up at initialization");
3628 lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3630 struct Scsi_Host *shost = class_to_shost(dev);
3631 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3633 return scnprintf(buf, PAGE_SIZE, "%d\n",
3634 phba->sli4_hba.pc_sli4_params.pls);
3636 static DEVICE_ATTR(pls, 0444,
3637 lpfc_pls_show, NULL);
3640 lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3642 struct Scsi_Host *shost = class_to_shost(dev);
3643 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3645 return scnprintf(buf, PAGE_SIZE, "%d\n",
3646 test_bit(HBA_PERSISTENT_TOPO,
3647 &phba->hba_flag) ? 1 : 0);
3649 static DEVICE_ATTR(pt, 0444,
3650 lpfc_pt_show, NULL);
3653 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3661 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3663 struct Scsi_Host *shost = class_to_shost(dev);
3664 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3666 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3669 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3670 lpfc_iocb_hw_show, NULL);
3672 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3674 struct Scsi_Host *shost = class_to_shost(dev);
3675 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3676 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3678 return scnprintf(buf, PAGE_SIZE, "%d\n",
3679 pring ? pring->txq_max : 0);
3682 static DEVICE_ATTR(txq_hw, S_IRUGO,
3683 lpfc_txq_hw_show, NULL);
3685 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3688 struct Scsi_Host *shost = class_to_shost(dev);
3689 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3690 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3692 return scnprintf(buf, PAGE_SIZE, "%d\n",
3693 pring ? pring->txcmplq_max : 0);
3696 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3697 lpfc_txcmplq_hw_show, NULL);
3700 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3701 # until the timer expires. Value range is [0,255]. Default value is 30.
3703 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3704 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3705 module_param(lpfc_nodev_tmo, int, 0);
3706 MODULE_PARM_DESC(lpfc_nodev_tmo,
3707 "Seconds driver will hold I/O waiting "
3708 "for a device to come back");
3711 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3712 * @dev: class converted to a Scsi_host structure.
3713 * @attr: device attribute, not used.
3714 * @buf: on return contains the dev loss timeout in decimal.
3716 * Returns: size of formatted string.
3719 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3722 struct Scsi_Host *shost = class_to_shost(dev);
3723 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3725 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3729 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3730 * @vport: lpfc vport structure pointer.
3731 * @val: contains the nodev timeout value.
3734 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3735 * a kernel error message is printed and zero is returned.
3736 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3737 * Otherwise nodev tmo is set to the default value.
3740 * zero if already set or if val is in range
3741 * -EINVAL val out of range
3744 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3746 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3747 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3748 if (val != LPFC_DEF_DEVLOSS_TMO)
3749 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3750 "0407 Ignoring lpfc_nodev_tmo module "
3751 "parameter because lpfc_devloss_tmo "
3756 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3757 vport->cfg_nodev_tmo = val;
3758 vport->cfg_devloss_tmo = val;
3761 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3762 "0400 lpfc_nodev_tmo attribute cannot be set to"
3763 " %d, allowed range is [%d, %d]\n",
3764 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3765 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3770 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3771 * @vport: lpfc vport structure pointer.
3774 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3777 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3779 struct lpfc_nodelist *ndlp;
3780 unsigned long iflags;
3781 #if (IS_ENABLED(CONFIG_NVME_FC))
3782 struct lpfc_nvme_rport *rport;
3783 struct nvme_fc_remote_port *remoteport = NULL;
3786 spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
3787 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3789 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3790 #if (IS_ENABLED(CONFIG_NVME_FC))
3791 spin_lock(&ndlp->lock);
3792 rport = lpfc_ndlp_get_nrport(ndlp);
3794 remoteport = rport->remoteport;
3795 spin_unlock(&ndlp->lock);
3796 if (rport && remoteport)
3797 nvme_fc_set_remoteport_devloss(remoteport,
3798 vport->cfg_devloss_tmo);
3801 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
3805 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3806 * @vport: lpfc vport structure pointer.
3807 * @val: contains the tmo value.
3810 * If the devloss tmo is already set or the vport dev loss tmo has changed
3811 * then a kernel error message is printed and zero is returned.
3812 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3813 * Otherwise nodev tmo is set to the default value.
3816 * zero if already set or if val is in range
3817 * -EINVAL val out of range
3820 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3822 if (vport->dev_loss_tmo_changed ||
3823 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3824 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3825 "0401 Ignoring change to lpfc_nodev_tmo "
3826 "because lpfc_devloss_tmo is set.\n");
3829 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3830 vport->cfg_nodev_tmo = val;
3831 vport->cfg_devloss_tmo = val;
3833 * For compat: set the fc_host dev loss so new rports
3834 * will get the value.
3836 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3837 lpfc_update_rport_devloss_tmo(vport);
3840 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3841 "0403 lpfc_nodev_tmo attribute cannot be set to "
3842 "%d, allowed range is [%d, %d]\n",
3843 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3847 lpfc_vport_param_store(nodev_tmo)
3849 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3852 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3853 # disappear until the timer expires. Value range is [0,255]. Default
3856 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3857 MODULE_PARM_DESC(lpfc_devloss_tmo,
3858 "Seconds driver will hold I/O waiting "
3859 "for a device to come back");
3860 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3861 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3862 lpfc_vport_param_show(devloss_tmo)
3865 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3866 * @vport: lpfc vport structure pointer.
3867 * @val: contains the tmo value.
3870 * If val is in a valid range then set the vport nodev tmo,
3871 * devloss tmo, also set the vport dev loss tmo changed flag.
3872 * Else a kernel error message is printed.
3875 * zero if val is in range
3876 * -EINVAL val out of range
3879 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3881 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3882 vport->cfg_nodev_tmo = val;
3883 vport->cfg_devloss_tmo = val;
3884 vport->dev_loss_tmo_changed = 1;
3885 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3886 lpfc_update_rport_devloss_tmo(vport);
3890 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3891 "0404 lpfc_devloss_tmo attribute cannot be set to "
3892 "%d, allowed range is [%d, %d]\n",
3893 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3897 lpfc_vport_param_store(devloss_tmo)
3898 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3901 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3902 * lpfc_suppress_rsp = 0 Disable
3903 * lpfc_suppress_rsp = 1 Enable (default)
3906 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3907 "Enable suppress rsp feature is firmware supports it");
3910 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3911 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3912 * lpfc_nvmet_mrq = 1 use a single RQ pair
3913 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3916 LPFC_ATTR_R(nvmet_mrq,
3917 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3918 "Specify number of RQ pairs for processing NVMET cmds");
3921 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3922 * to each NVMET RQ. Range 64 to 2048, default is 512.
3924 LPFC_ATTR_R(nvmet_mrq_post,
3925 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3926 LPFC_NVMET_RQE_DEF_COUNT,
3927 "Specify number of RQ buffers to initially post");
3930 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3931 * Supported Values: 1 - register just FCP
3932 * 3 - register both FCP and NVME
3933 * Supported values are [1,3]. Default value is 3
3935 LPFC_ATTR_R(enable_fc4_type, LPFC_DEF_ENBL_FC4_TYPE,
3936 LPFC_ENABLE_FCP, LPFC_MAX_ENBL_FC4_TYPE,
3937 "Enable FC4 Protocol support - FCP / NVME");
3940 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3941 # deluged with LOTS of information.
3942 # You can set a bit mask to record specific types of verbose messages:
3943 # See lpfc_logmsh.h for definitions.
3945 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3946 "Verbose logging bit-mask");
3949 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3950 # objects that have been registered with the nameserver after login.
3952 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3953 "Deregister nameserver objects before LOGO");
3956 # lun_queue_depth: This parameter is used to limit the number of outstanding
3957 # commands per FCP LUN.
3959 LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
3960 "Max number of FCP commands we can queue to a specific LUN");
3963 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3964 # commands per target port. Value range is [10,65535]. Default value is 65535.
3966 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3967 module_param(lpfc_tgt_queue_depth, uint, 0444);
3968 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3969 lpfc_vport_param_show(tgt_queue_depth);
3970 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3971 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3974 * lpfc_tgt_queue_depth_set: Sets an attribute value.
3975 * @vport: lpfc vport structure pointer.
3976 * @val: integer attribute value.
3978 * Description: Sets the parameter to the new value.
3982 * -EINVAL if val is invalid
3985 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3987 struct lpfc_nodelist *ndlp;
3988 unsigned long iflags;
3990 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3993 if (val == vport->cfg_tgt_queue_depth)
3996 vport->cfg_tgt_queue_depth = val;
3998 /* Next loop thru nodelist and change cmd_qdepth */
3999 spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
4000 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
4001 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4002 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
4006 lpfc_vport_param_store(tgt_queue_depth);
4007 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
4010 # hba_queue_depth: This parameter is used to limit the number of outstanding
4011 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
4012 # value is greater than the maximum number of exchanges supported by the HBA,
4013 # then maximum number of exchanges supported by the HBA is used to determine
4014 # the hba_queue_depth.
4016 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
4017 "Max number of FCP commands we can queue to a lpfc HBA");
4020 # peer_port_login: This parameter allows/prevents logins
4021 # between peer ports hosted on the same physical port.
4022 # When this parameter is set 0 peer ports of same physical port
4023 # are not allowed to login to each other.
4024 # When this parameter is set 1 peer ports of same physical port
4025 # are allowed to login to each other.
4026 # Default value of this parameter is 0.
4028 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
4029 "Allow peer ports on the same physical port to login to each "
4033 # restrict_login: This parameter allows/prevents logins
4034 # between Virtual Ports and remote initiators.
4035 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
4036 # other initiators and will attempt to PLOGI all remote ports.
4037 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
4038 # remote ports and will not attempt to PLOGI to other initiators.
4039 # This parameter does not restrict to the physical port.
4040 # This parameter does not restrict logins to Fabric resident remote ports.
4041 # Default value of this parameter is 1.
4043 static int lpfc_restrict_login = 1;
4044 module_param(lpfc_restrict_login, int, S_IRUGO);
4045 MODULE_PARM_DESC(lpfc_restrict_login,
4046 "Restrict virtual ports login to remote initiators.");
4047 lpfc_vport_param_show(restrict_login);
4050 * lpfc_restrict_login_init - Set the vport restrict login flag
4051 * @vport: lpfc vport structure pointer.
4052 * @val: contains the restrict login value.
4055 * If val is not in a valid range then log a kernel error message and set
4056 * the vport restrict login to one.
4057 * If the port type is physical clear the restrict login flag and return.
4058 * Else set the restrict login flag to val.
4061 * zero if val is in range
4062 * -EINVAL val out of range
4065 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
4067 if (val < 0 || val > 1) {
4068 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4069 "0422 lpfc_restrict_login attribute cannot "
4070 "be set to %d, allowed range is [0, 1]\n",
4072 vport->cfg_restrict_login = 1;
4075 if (vport->port_type == LPFC_PHYSICAL_PORT) {
4076 vport->cfg_restrict_login = 0;
4079 vport->cfg_restrict_login = val;
4084 * lpfc_restrict_login_set - Set the vport restrict login flag
4085 * @vport: lpfc vport structure pointer.
4086 * @val: contains the restrict login value.
4089 * If val is not in a valid range then log a kernel error message and set
4090 * the vport restrict login to one.
4091 * If the port type is physical and the val is not zero log a kernel
4092 * error message, clear the restrict login flag and return zero.
4093 * Else set the restrict login flag to val.
4096 * zero if val is in range
4097 * -EINVAL val out of range
4100 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
4102 if (val < 0 || val > 1) {
4103 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4104 "0425 lpfc_restrict_login attribute cannot "
4105 "be set to %d, allowed range is [0, 1]\n",
4107 vport->cfg_restrict_login = 1;
4110 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
4111 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4112 "0468 lpfc_restrict_login must be 0 for "
4113 "Physical ports.\n");
4114 vport->cfg_restrict_login = 0;
4117 vport->cfg_restrict_login = val;
4120 lpfc_vport_param_store(restrict_login);
4121 static DEVICE_ATTR_RW(lpfc_restrict_login);
4124 # Some disk devices have a "select ID" or "select Target" capability.
4125 # From a protocol standpoint "select ID" usually means select the
4126 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
4127 # annex" which contains a table that maps a "select ID" (a number
4128 # between 0 and 7F) to an ALPA. By default, for compatibility with
4129 # older drivers, the lpfc driver scans this table from low ALPA to high
4132 # Turning on the scan-down variable (on = 1, off = 0) will
4133 # cause the lpfc driver to use an inverted table, effectively
4134 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
4136 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
4137 # and will not work across a fabric. Also this parameter will take
4138 # effect only in the case when ALPA map is not available.)
4140 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
4141 "Start scanning for devices from highest ALPA to lowest");
4144 # lpfc_topology: link topology for init link
4145 # 0x0 = attempt loop mode then point-to-point
4146 # 0x01 = internal loopback mode
4147 # 0x02 = attempt point-to-point mode only
4148 # 0x04 = attempt loop mode only
4149 # 0x06 = attempt point-to-point mode then loop
4150 # Set point-to-point mode if you want to run as an N_Port.
4151 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4152 # Default value is 0.
4154 LPFC_ATTR(topology, 0, 0, 6,
4155 "Select Fibre Channel topology");
4158 * lpfc_topology_store - Set the adapters topology field
4159 * @dev: class device that is converted into a scsi_host.
4160 * @attr:device attribute, not used.
4161 * @buf: buffer for passing information.
4162 * @count: size of the data buffer.
4165 * If val is in a valid range then set the adapter's topology field and
4166 * issue a lip; if the lip fails reset the topology to the old value.
4168 * If the value is not in range log a kernel error message and return an error.
4171 * zero if val is in range and lip okay
4172 * non-zero return value from lpfc_issue_lip()
4173 * -EINVAL val out of range
4176 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4177 const char *buf, size_t count)
4179 struct Scsi_Host *shost = class_to_shost(dev);
4180 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4181 struct lpfc_hba *phba = vport->phba;
4184 const char *val_buf = buf;
4187 u8 sli_family, if_type;
4189 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4191 val_buf = &buf[strlen("nolip ")];
4194 if (!isdigit(val_buf[0]))
4196 if (sscanf(val_buf, "%i", &val) != 1)
4199 if (val >= 0 && val <= 6) {
4200 prev_val = phba->cfg_topology;
4201 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4203 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4204 "3113 Loop mode not supported at speed %d\n",
4209 * The 'topology' is not a configurable parameter if :
4210 * - persistent topology enabled
4211 * - ASIC_GEN_NUM >= 0xC, with no private loop support
4213 sli_family = bf_get(lpfc_sli_intf_sli_family,
4214 &phba->sli4_hba.sli_intf);
4215 if_type = bf_get(lpfc_sli_intf_if_type,
4216 &phba->sli4_hba.sli_intf);
4217 if ((test_bit(HBA_PERSISTENT_TOPO, &phba->hba_flag) ||
4218 (!phba->sli4_hba.pc_sli4_params.pls &&
4219 (sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
4220 if_type == LPFC_SLI_INTF_IF_TYPE_6))) &&
4222 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4223 "3114 Loop mode not supported\n");
4226 phba->cfg_topology = val;
4230 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4231 "3054 lpfc_topology changed from %d to %d\n",
4233 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4234 phba->fc_topology_changed = 1;
4235 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4237 phba->cfg_topology = prev_val;
4242 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4243 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4244 "allowed range is [0, 6]\n",
4249 lpfc_param_show(topology)
4250 static DEVICE_ATTR_RW(lpfc_topology);
4253 * lpfc_static_vport_show: Read callback function for
4254 * lpfc_static_vport sysfs file.
4255 * @dev: Pointer to class device object.
4256 * @attr: device attribute structure.
4257 * @buf: Data buffer.
4259 * This function is the read call back function for
4260 * lpfc_static_vport sysfs file. The lpfc_static_vport
4261 * sysfs file report the mageability of the vport.
4264 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4267 struct Scsi_Host *shost = class_to_shost(dev);
4268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4269 if (vport->vport_flag & STATIC_VPORT)
4270 sprintf(buf, "1\n");
4272 sprintf(buf, "0\n");
4278 * Sysfs attribute to control the statistical data collection.
4280 static DEVICE_ATTR_RO(lpfc_static_vport);
4283 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4285 # Value range is [0,16]. Default value is 0.
4288 * lpfc_link_speed_store - Set the adapters link speed
4289 * @dev: Pointer to class device.
4291 * @buf: Data buffer.
4292 * @count: Size of the data buffer.
4295 * If val is in a valid range then set the adapter's link speed field and
4296 * issue a lip; if the lip fails reset the link speed to the old value.
4299 * If the value is not in range log a kernel error message and return an error.
4302 * zero if val is in range and lip okay.
4303 * non-zero return value from lpfc_issue_lip()
4304 * -EINVAL val out of range
4307 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4308 const char *buf, size_t count)
4310 struct Scsi_Host *shost = class_to_shost(dev);
4311 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4312 struct lpfc_hba *phba = vport->phba;
4313 int val = LPFC_USER_LINK_SPEED_AUTO;
4315 const char *val_buf = buf;
4317 uint32_t prev_val, if_type;
4319 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4320 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4321 test_bit(HBA_FORCED_LINK_SPEED, &phba->hba_flag))
4324 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4326 val_buf = &buf[strlen("nolip ")];
4329 if (!isdigit(val_buf[0]))
4331 if (sscanf(val_buf, "%i", &val) != 1)
4334 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4335 "3055 lpfc_link_speed changed from %d to %d %s\n",
4336 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4338 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4339 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4340 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4341 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4342 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4343 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4344 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4345 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4347 "2879 lpfc_link_speed attribute cannot be set "
4348 "to %d. Speed is not supported by this port.\n",
4352 if (val >= LPFC_USER_LINK_SPEED_16G &&
4353 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4354 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4355 "3112 lpfc_link_speed attribute cannot be set "
4356 "to %d. Speed is not supported in loop mode.\n",
4362 case LPFC_USER_LINK_SPEED_AUTO:
4363 case LPFC_USER_LINK_SPEED_1G:
4364 case LPFC_USER_LINK_SPEED_2G:
4365 case LPFC_USER_LINK_SPEED_4G:
4366 case LPFC_USER_LINK_SPEED_8G:
4367 case LPFC_USER_LINK_SPEED_16G:
4368 case LPFC_USER_LINK_SPEED_32G:
4369 case LPFC_USER_LINK_SPEED_64G:
4370 prev_val = phba->cfg_link_speed;
4371 phba->cfg_link_speed = val;
4375 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4377 phba->cfg_link_speed = prev_val;
4385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4386 "0469 lpfc_link_speed attribute cannot be set to %d, "
4387 "allowed values are [%s]\n",
4388 val, LPFC_LINK_SPEED_STRING);
4393 static int lpfc_link_speed = 0;
4394 module_param(lpfc_link_speed, int, S_IRUGO);
4395 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4396 lpfc_param_show(link_speed)
4399 * lpfc_link_speed_init - Set the adapters link speed
4400 * @phba: lpfc_hba pointer.
4401 * @val: link speed value.
4404 * If val is in a valid range then set the adapter's link speed field.
4407 * If the value is not in range log a kernel error message, clear the link
4408 * speed and return an error.
4411 * zero if val saved.
4412 * -EINVAL val out of range
4415 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4417 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4418 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4419 "3111 lpfc_link_speed of %d cannot "
4420 "support loop mode, setting topology to default.\n",
4422 phba->cfg_topology = 0;
4426 case LPFC_USER_LINK_SPEED_AUTO:
4427 case LPFC_USER_LINK_SPEED_1G:
4428 case LPFC_USER_LINK_SPEED_2G:
4429 case LPFC_USER_LINK_SPEED_4G:
4430 case LPFC_USER_LINK_SPEED_8G:
4431 case LPFC_USER_LINK_SPEED_16G:
4432 case LPFC_USER_LINK_SPEED_32G:
4433 case LPFC_USER_LINK_SPEED_64G:
4434 phba->cfg_link_speed = val;
4437 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4438 "0405 lpfc_link_speed attribute cannot "
4439 "be set to %d, allowed values are "
4440 "["LPFC_LINK_SPEED_STRING"]\n", val);
4441 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4446 static DEVICE_ATTR_RW(lpfc_link_speed);
4449 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4450 # 1 = aer supported and enabled (default)
4451 # PCIe error reporting is always enabled by the PCI core, so this always
4454 # N.B. Parts of LPFC_ATTR open-coded since some of the underlying
4455 # infrastructure (phba->cfg_aer_support) is gone.
4457 static uint lpfc_aer_support = 1;
4458 module_param(lpfc_aer_support, uint, S_IRUGO);
4459 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
4461 lpfc_aer_support_show(struct device *dev, struct device_attribute *attr,
4464 return scnprintf(buf, PAGE_SIZE, "%d\n", lpfc_aer_support);
4468 * lpfc_aer_support_store - Set the adapter for aer support
4470 * @dev: class device that is converted into a Scsi_host.
4471 * @attr: device attribute, not used.
4472 * @buf: containing enable or disable aer flag.
4473 * @count: unused variable.
4476 * PCIe error reporting is enabled by the PCI core, so drivers don't need
4477 * to do anything. Retain this interface for backwards compatibility,
4481 * length of the buf on success
4482 * -EINVAL if val out of range
4485 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4486 const char *buf, size_t count)
4490 if (!isdigit(buf[0]))
4492 if (sscanf(buf, "%i", &val) != 1)
4495 dev_info_once(dev, "PCIe error reporting automatically enabled by the PCI core; sysfs write ignored\n");
4499 static DEVICE_ATTR_RW(lpfc_aer_support);
4502 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4503 * @dev: class device that is converted into a Scsi_host.
4504 * @attr: device attribute, not used.
4505 * @buf: containing flag 1 for aer cleanup state.
4506 * @count: unused variable.
4509 * If the @buf contains 1, invokes the kernel AER helper routine
4510 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
4511 * error status register.
4516 * -EINVAL if the buf does not contain 1
4517 * -EPERM if the OS cannot clear AER error status, i.e., when platform
4518 * firmware owns the AER Capability
4521 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4522 const char *buf, size_t count)
4524 struct Scsi_Host *shost = class_to_shost(dev);
4525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4526 struct lpfc_hba *phba = vport->phba;
4529 if (!isdigit(buf[0]))
4531 if (sscanf(buf, "%i", &val) != 1)
4536 rc = pci_aer_clear_nonfatal_status(phba->pcidev);
4544 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4545 lpfc_aer_cleanup_state);
4548 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4550 * @dev: class device that is converted into a Scsi_host.
4551 * @attr: device attribute, not used.
4552 * @buf: containing the string the number of vfs to be enabled.
4553 * @count: unused variable.
4556 * When this api is called either through user sysfs, the driver shall
4557 * try to enable or disable SR-IOV virtual functions according to the
4560 * If zero virtual function has been enabled to the physical function,
4561 * the driver shall invoke the pci enable virtual function api trying
4562 * to enable the virtual functions. If the nr_vfn provided is greater
4563 * than the maximum supported, the maximum virtual function number will
4564 * be used for invoking the api; otherwise, the nr_vfn provided shall
4565 * be used for invoking the api. If the api call returned success, the
4566 * actual number of virtual functions enabled will be set to the driver
4567 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4568 * cfg_sriov_nr_virtfn remains zero.
4570 * If none-zero virtual functions have already been enabled to the
4571 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4572 * -EINVAL will be returned and the driver does nothing;
4574 * If the nr_vfn provided is zero and none-zero virtual functions have
4575 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4576 * disabling virtual function api shall be invoded to disable all the
4577 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4578 * zero. Otherwise, if zero virtual function has been enabled, do
4582 * length of the buf on success if val is in range the intended mode
4584 * -EINVAL if val out of range or intended mode is not supported.
4587 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4588 const char *buf, size_t count)
4590 struct Scsi_Host *shost = class_to_shost(dev);
4591 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4592 struct lpfc_hba *phba = vport->phba;
4593 struct pci_dev *pdev = phba->pcidev;
4594 int val = 0, rc = -EINVAL;
4596 /* Sanity check on user data */
4597 if (!isdigit(buf[0]))
4599 if (sscanf(buf, "%i", &val) != 1)
4604 /* Request disabling virtual functions */
4606 if (phba->cfg_sriov_nr_virtfn > 0) {
4607 pci_disable_sriov(pdev);
4608 phba->cfg_sriov_nr_virtfn = 0;
4613 /* Request enabling virtual functions */
4614 if (phba->cfg_sriov_nr_virtfn > 0) {
4615 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4616 "3018 There are %d virtual functions "
4617 "enabled on physical function.\n",
4618 phba->cfg_sriov_nr_virtfn);
4622 if (val <= LPFC_MAX_VFN_PER_PFN)
4623 phba->cfg_sriov_nr_virtfn = val;
4625 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4626 "3019 Enabling %d virtual functions is not "
4631 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4633 phba->cfg_sriov_nr_virtfn = 0;
4641 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4642 "Enable PCIe device SR-IOV virtual fn");
4644 lpfc_param_show(sriov_nr_virtfn)
4645 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4648 * lpfc_request_firmware_upgrade_store - Request for Linux generic firmware upgrade
4650 * @dev: class device that is converted into a Scsi_host.
4651 * @attr: device attribute, not used.
4652 * @buf: containing the string the number of vfs to be enabled.
4653 * @count: unused variable.
4658 * length of the buf on success if val is in range the intended mode
4660 * -EINVAL if val out of range or intended mode is not supported.
4663 lpfc_request_firmware_upgrade_store(struct device *dev,
4664 struct device_attribute *attr,
4665 const char *buf, size_t count)
4667 struct Scsi_Host *shost = class_to_shost(dev);
4668 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4669 struct lpfc_hba *phba = vport->phba;
4672 /* Sanity check on user data */
4673 if (!isdigit(buf[0]))
4675 if (sscanf(buf, "%i", &val) != 1)
4680 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4688 static int lpfc_req_fw_upgrade;
4689 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4690 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4691 lpfc_param_show(request_firmware_upgrade)
4694 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4695 * @phba: lpfc_hba pointer.
4699 * Set the initial Linux generic firmware upgrade enable or disable flag.
4702 * zero if val saved.
4703 * -EINVAL val out of range
4706 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4708 if (val >= 0 && val <= 1) {
4709 phba->cfg_request_firmware_upgrade = val;
4714 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4715 lpfc_request_firmware_upgrade_show,
4716 lpfc_request_firmware_upgrade_store);
4719 * lpfc_force_rscn_store
4721 * @dev: class device that is converted into a Scsi_host.
4722 * @attr: device attribute, not used.
4723 * @buf: unused string
4724 * @count: unused variable.
4727 * Force the switch to send a RSCN to all other NPorts in our zone
4728 * If we are direct connect pt2pt, build the RSCN command ourself
4729 * and send to the other NPort. Not supported for private loop.
4733 * -EIO - if command is not sent
4736 lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4737 const char *buf, size_t count)
4739 struct Scsi_Host *shost = class_to_shost(dev);
4740 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4743 i = lpfc_issue_els_rscn(vport, 0);
4750 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4751 * connected to the HBA.
4753 * Value range is any ascii value
4755 static int lpfc_force_rscn;
4756 module_param(lpfc_force_rscn, int, 0644);
4757 MODULE_PARM_DESC(lpfc_force_rscn,
4758 "Force an RSCN to be sent to all remote NPorts");
4759 lpfc_param_show(force_rscn)
4762 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4763 * @phba: lpfc_hba pointer.
4764 * @val: unused value.
4767 * zero if val saved.
4770 lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
4774 static DEVICE_ATTR_RW(lpfc_force_rscn);
4777 * lpfc_fcp_imax_store
4779 * @dev: class device that is converted into a Scsi_host.
4780 * @attr: device attribute, not used.
4781 * @buf: string with the number of fast-path FCP interrupts per second.
4782 * @count: unused variable.
4785 * If val is in a valid range [636,651042], then set the adapter's
4786 * maximum number of fast-path FCP interrupts per second.
4789 * length of the buf on success if val is in range the intended mode
4791 * -EINVAL if val out of range or intended mode is not supported.
4794 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4795 const char *buf, size_t count)
4797 struct Scsi_Host *shost = class_to_shost(dev);
4798 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4799 struct lpfc_hba *phba = vport->phba;
4800 struct lpfc_eq_intr_info *eqi;
4804 /* fcp_imax is only valid for SLI4 */
4805 if (phba->sli_rev != LPFC_SLI_REV4)
4808 /* Sanity check on user data */
4809 if (!isdigit(buf[0]))
4811 if (sscanf(buf, "%i", &val) != 1)
4815 * Value range for the HBA is [5000,5000000]
4816 * The value for each EQ depends on how many EQs are configured.
4819 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4822 phba->cfg_auto_imax = (val) ? 0 : 1;
4823 if (phba->cfg_fcp_imax && !val) {
4824 queue_delayed_work(phba->wq, &phba->eq_delay_work,
4825 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
4827 for_each_present_cpu(i) {
4828 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
4833 phba->cfg_fcp_imax = (uint32_t)val;
4835 if (phba->cfg_fcp_imax)
4836 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
4840 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4841 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4848 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4851 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4853 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4854 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4855 MODULE_PARM_DESC(lpfc_fcp_imax,
4856 "Set the maximum number of FCP interrupts per second per HBA");
4857 lpfc_param_show(fcp_imax)
4860 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4861 * @phba: lpfc_hba pointer.
4862 * @val: link speed value.
4865 * If val is in a valid range [636,651042], then initialize the adapter's
4866 * maximum number of fast-path FCP interrupts per second.
4869 * zero if val saved.
4870 * -EINVAL val out of range
4873 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4875 if (phba->sli_rev != LPFC_SLI_REV4) {
4876 phba->cfg_fcp_imax = 0;
4880 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4882 phba->cfg_fcp_imax = val;
4886 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4887 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4889 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4894 static DEVICE_ATTR_RW(lpfc_fcp_imax);
4897 * lpfc_cq_max_proc_limit_store
4899 * @dev: class device that is converted into a Scsi_host.
4900 * @attr: device attribute, not used.
4901 * @buf: string with the cq max processing limit of cqes
4902 * @count: unused variable.
4905 * If val is in a valid range, then set value on each cq
4908 * The length of the buf: if successful
4909 * -ERANGE: if val is not in the valid range
4910 * -EINVAL: if bad value format or intended mode is not supported.
4913 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
4914 const char *buf, size_t count)
4916 struct Scsi_Host *shost = class_to_shost(dev);
4917 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4918 struct lpfc_hba *phba = vport->phba;
4919 struct lpfc_queue *eq, *cq;
4923 /* cq_max_proc_limit is only valid for SLI4 */
4924 if (phba->sli_rev != LPFC_SLI_REV4)
4927 /* Sanity check on user data */
4928 if (!isdigit(buf[0]))
4930 if (kstrtoul(buf, 0, &val))
4933 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
4936 phba->cfg_cq_max_proc_limit = (uint32_t)val;
4938 /* set the values on the cq's */
4939 for (i = 0; i < phba->cfg_irq_chann; i++) {
4940 /* Get the EQ corresponding to the IRQ vector */
4941 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
4945 list_for_each_entry(cq, &eq->child_list, list)
4946 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
4954 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
4955 * itteration of CQ processing.
4957 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4958 module_param(lpfc_cq_max_proc_limit, int, 0644);
4959 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
4960 "Set the maximum number CQEs processed in an iteration of "
4962 lpfc_param_show(cq_max_proc_limit)
4965 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
4966 * single handler call which should request a polled completion rather
4967 * than re-enabling interrupts.
4969 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
4970 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
4971 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
4972 "CQE Processing Threshold to enable Polling");
4975 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
4976 * @phba: lpfc_hba pointer.
4980 * If val is in a valid range, then initialize the adapter's maximum
4984 * Always returns 0 for success, even if value not always set to
4985 * requested value. If value out of range or not supported, will fall
4989 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
4991 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4993 if (phba->sli_rev != LPFC_SLI_REV4)
4996 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
4997 phba->cfg_cq_max_proc_limit = val;
5001 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5002 "0371 lpfc_cq_max_proc_limit: %d out of range, using "
5004 phba->cfg_cq_max_proc_limit);
5009 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
5012 * lpfc_fcp_cpu_map_show - Display current driver CPU affinity
5013 * @dev: class converted to a Scsi_host structure.
5014 * @attr: device attribute, not used.
5015 * @buf: on return contains text describing the state of the link.
5017 * Returns: size of formatted string.
5020 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5023 struct Scsi_Host *shost = class_to_shost(dev);
5024 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5025 struct lpfc_hba *phba = vport->phba;
5026 struct lpfc_vector_map_info *cpup;
5029 if ((phba->sli_rev != LPFC_SLI_REV4) ||
5030 (phba->intr_type != MSIX))
5033 switch (phba->cfg_fcp_cpu_map) {
5035 len += scnprintf(buf + len, PAGE_SIZE-len,
5036 "fcp_cpu_map: No mapping (%d)\n",
5037 phba->cfg_fcp_cpu_map);
5040 len += scnprintf(buf + len, PAGE_SIZE-len,
5041 "fcp_cpu_map: HBA centric mapping (%d): "
5042 "%d of %d CPUs online from %d possible CPUs\n",
5043 phba->cfg_fcp_cpu_map, num_online_cpus(),
5045 phba->sli4_hba.num_possible_cpu);
5049 while (phba->sli4_hba.curr_disp_cpu <
5050 phba->sli4_hba.num_possible_cpu) {
5051 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5053 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5054 len += scnprintf(buf + len, PAGE_SIZE - len,
5055 "CPU %02d not present\n",
5056 phba->sli4_hba.curr_disp_cpu);
5057 else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
5058 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5060 buf + len, PAGE_SIZE - len,
5061 "CPU %02d hdwq None "
5062 "physid %d coreid %d ht %d ua %d\n",
5063 phba->sli4_hba.curr_disp_cpu,
5064 cpup->phys_id, cpup->core_id,
5065 (cpup->flag & LPFC_CPU_MAP_HYPER),
5066 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5069 buf + len, PAGE_SIZE - len,
5070 "CPU %02d EQ None hdwq %04d "
5071 "physid %d coreid %d ht %d ua %d\n",
5072 phba->sli4_hba.curr_disp_cpu,
5073 cpup->hdwq, cpup->phys_id,
5075 (cpup->flag & LPFC_CPU_MAP_HYPER),
5076 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5078 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5080 buf + len, PAGE_SIZE - len,
5081 "CPU %02d hdwq None "
5082 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5083 phba->sli4_hba.curr_disp_cpu,
5086 (cpup->flag & LPFC_CPU_MAP_HYPER),
5087 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5088 lpfc_get_irq(cpup->eq));
5091 buf + len, PAGE_SIZE - len,
5092 "CPU %02d EQ %04d hdwq %04d "
5093 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5094 phba->sli4_hba.curr_disp_cpu,
5095 cpup->eq, cpup->hdwq, cpup->phys_id,
5097 (cpup->flag & LPFC_CPU_MAP_HYPER),
5098 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5099 lpfc_get_irq(cpup->eq));
5102 phba->sli4_hba.curr_disp_cpu++;
5104 /* display max number of CPUs keeping some margin */
5105 if (phba->sli4_hba.curr_disp_cpu <
5106 phba->sli4_hba.num_possible_cpu &&
5107 (len >= (PAGE_SIZE - 64))) {
5108 len += scnprintf(buf + len,
5109 PAGE_SIZE - len, "more...\n");
5114 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
5115 phba->sli4_hba.curr_disp_cpu = 0;
5121 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5122 * @dev: class device that is converted into a Scsi_host.
5123 * @attr: device attribute, not used.
5124 * @buf: one or more lpfc_polling_flags values.
5128 * -EINVAL - Not implemented yet.
5131 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5132 const char *buf, size_t count)
5138 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5141 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5142 # 0 - Do not affinitze IRQ vectors
5143 # 1 - Affintize HBA vectors with respect to each HBA
5144 # (start with CPU0 for each HBA)
5145 # This also defines how Hardware Queues are mapped to specific CPUs.
5147 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5148 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5149 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5150 "Defines how to map CPUs to IRQ vectors per HBA");
5153 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5154 * @phba: lpfc_hba pointer.
5155 * @val: link speed value.
5158 * If val is in a valid range [0-2], then affinitze the adapter's
5162 * zero if val saved.
5163 * -EINVAL val out of range
5166 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5168 if (phba->sli_rev != LPFC_SLI_REV4) {
5169 phba->cfg_fcp_cpu_map = 0;
5173 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5174 phba->cfg_fcp_cpu_map = val;
5178 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5179 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5181 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5186 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5189 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5190 # Value range is [2,3]. Default value is 3.
5192 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5193 "Select Fibre Channel class of service for FCP sequences");
5196 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5197 # is [0,1]. Default value is 1.
5199 LPFC_VPORT_ATTR_RW(use_adisc, 1, 0, 1,
5200 "Use ADISC on rediscovery to authenticate FCP devices");
5203 # lpfc_first_burst_size: First burst size to use on the NPorts
5204 # that support first burst.
5205 # Value range is [0,65536]. Default value is 0.
5207 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5208 "First burst size for Targets that support first burst");
5211 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5212 * When the driver is configured as an NVME target, this value is
5213 * communicated to the NVME initiator in the PRLI response. It is
5214 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5215 * parameters are set and the target is sending the PRLI RSP.
5216 * Parameter supported on physical port only - no NPIV support.
5217 * Value range is [0,65536]. Default value is 0.
5219 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5220 "NVME Target mode first burst size in 512B increments.");
5223 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5224 * For the Initiator (I), enabling this parameter means that an NVMET
5225 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5226 * processed by the initiator for subsequent NVME FCP IO.
5227 * Currently, this feature is not supported on the NVME target
5228 * Value range is [0,1]. Default value is 0 (disabled).
5230 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5231 "Enable First Burst feature for NVME Initiator.");
5234 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5235 # depth. Default value is 0. When the value of this parameter is zero the
5236 # SCSI command completion time is not used for controlling I/O queue depth. When
5237 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5238 # to limit the I/O completion time to the parameter value.
5239 # The value is set in milliseconds.
5241 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5242 "Use command completion time to control queue depth");
5244 lpfc_vport_param_show(max_scsicmpl_time);
5246 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5248 struct lpfc_nodelist *ndlp, *next_ndlp;
5249 unsigned long iflags;
5251 if (val == vport->cfg_max_scsicmpl_time)
5253 if ((val < 0) || (val > 60000))
5255 vport->cfg_max_scsicmpl_time = val;
5257 spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
5258 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5259 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5261 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5263 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
5266 lpfc_vport_param_store(max_scsicmpl_time);
5267 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5270 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5271 # range is [0,1]. Default value is 0.
5273 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5276 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5277 # range is [0,1]. Default value is 1.
5279 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5282 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5283 * range is [0,1]. Default value is 0.
5284 * For [0], FCP commands are issued to Work Queues based on upper layer
5285 * hardware queue index.
5286 * For [1], FCP commands are issued to a Work Queue associated with the
5289 * LPFC_FCP_SCHED_BY_HDWQ == 0
5290 * LPFC_FCP_SCHED_BY_CPU == 1
5292 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5293 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5294 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5295 * through WQs will be used.
5297 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5298 LPFC_FCP_SCHED_BY_HDWQ,
5299 LPFC_FCP_SCHED_BY_CPU,
5300 "Determine scheduling algorithm for "
5301 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5304 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5305 * range is [0,1]. Default value is 0.
5306 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5307 * For [1], GID_PT is used for NameServer queries after RSCN
5310 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5311 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5312 "Determine algorithm NameServer queries after RSCN "
5313 "[0] - GID_FT, [1] - GID_PT");
5316 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5317 # range is [0,1]. Default value is 0.
5318 # For [0], bus reset issues target reset to ALL devices
5319 # For [1], bus reset issues target reset to non-FCP2 devices
5321 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5322 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5326 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5327 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5328 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5329 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5330 # cr_delay is set to 0.
5332 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5333 "interrupt response is generated");
5335 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5336 "interrupt response is generated");
5339 # lpfc_multi_ring_support: Determines how many rings to spread available
5340 # cmd/rsp IOCB entries across.
5341 # Value range is [1,2]. Default value is 1.
5343 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5344 "SLI rings to spread IOCB entries across");
5347 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5348 # identifies what rctl value to configure the additional ring for.
5349 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5351 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5352 255, "Identifies RCTL for additional ring configuration");
5355 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5356 # identifies what type value to configure the additional ring for.
5357 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5359 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5360 255, "Identifies TYPE for additional ring configuration");
5363 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5364 # 0 = SmartSAN functionality disabled (default)
5365 # 1 = SmartSAN functionality enabled
5366 # This parameter will override the value of lpfc_fdmi_on module parameter.
5367 # Value range is [0,1]. Default value is 0.
5369 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5372 # lpfc_fdmi_on: Controls FDMI support.
5374 # 1 Traditional FDMI support (default)
5375 # Traditional FDMI support means the driver will assume FDMI-2 support;
5376 # however, if that fails, it will fallback to FDMI-1.
5377 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5378 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5380 # Value range [0,1]. Default value is 1.
5382 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5385 # Specifies the maximum number of ELS cmds we can have outstanding (for
5386 # discovery). Value range is [1,64]. Default value = 32.
5388 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5389 "during discovery");
5392 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5393 # will be scanned by the SCSI midlayer when sequential scanning is
5394 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5395 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5396 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5397 # above. The lpfc driver limits the default value to 255 for two reasons.
5398 # As it bounds the sequential scan loop, scanning for thousands of luns
5399 # on a target can take minutes of wall clock time. Additionally,
5400 # there are FC targets, such as JBODs, that only recognize 8-bits of
5401 # LUN ID. When they receive a value greater than 8 bits, they chop off
5402 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5403 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5404 # valid responses at each of the LUN IDs, to believe there are multiple
5405 # devices present, when in fact, there is only 1.
5406 # A customer that is aware of their target behaviors, and the results as
5407 # indicated above, is welcome to increase the lpfc_max_luns value.
5408 # As mentioned, this value is not used by the lpfc driver, only the
5410 # Value range is [0,65535]. Default value is 255.
5411 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5413 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5416 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5417 # Value range is [1,255], default value is 10.
5419 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5420 "Milliseconds driver will wait between polling FCP ring");
5423 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5424 # to complete in seconds. Value range is [5,180], default value is 60.
5426 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5427 "Maximum time to wait for task management commands to complete");
5429 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5430 # support this feature
5433 # 2 = MSI-X enabled (default)
5434 # Value range is [0,2]. Default value is 2.
5436 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5437 "MSI-X (2), if possible");
5440 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5442 * 0 = NVME OAS disabled
5443 * 1 = NVME OAS enabled
5445 * Value range is [0,1]. Default value is 0.
5447 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5448 "Use OAS bit on NVME IOs");
5451 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5453 * 0 = Put NVME Command in SGL
5454 * 1 = Embed NVME Command in WQE (unless G7)
5455 * 2 = Embed NVME Command in WQE (force)
5457 * Value range is [0,2]. Default value is 1.
5459 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5460 "Embed NVME Command in WQE");
5463 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5464 * the driver will advertise it supports to the SCSI layer.
5466 * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
5467 * 1,256 = Manually specify nr_hw_queue value to be advertised,
5469 * Value range is [0,256]. Default value is 8.
5471 LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5472 LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5473 "Set the number of SCSI Queues advertised");
5476 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5477 * will advertise it supports to the NVME and SCSI layers. This also
5478 * will map to the number of CQ/WQ pairs the driver will create.
5480 * The NVME Layer will try to create this many, plus 1 administrative
5481 * hardware queue. The administrative queue will always map to WQ 0
5482 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5484 * 0 = Configure the number of hdw queues to the number of active CPUs.
5485 * 1,256 = Manually specify how many hdw queues to use.
5487 * Value range is [0,256]. Default value is 0.
5489 LPFC_ATTR_R(hdw_queue,
5491 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5492 "Set the number of I/O Hardware Queues");
5494 #if IS_ENABLED(CONFIG_X86)
5496 * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
5498 * @phba: Pointer to HBA context object.
5501 lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)
5503 unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;
5504 const struct cpumask *sibling_mask;
5505 struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;
5507 cpumask_clear(aff_mask);
5509 if (phba->irq_chann_mode == NUMA_MODE) {
5510 /* Check if we're a NUMA architecture */
5511 numa_node = dev_to_node(&phba->pcidev->dev);
5512 if (numa_node == NUMA_NO_NODE) {
5513 phba->irq_chann_mode = NORMAL_MODE;
5518 for_each_possible_cpu(cpu) {
5519 switch (phba->irq_chann_mode) {
5521 if (cpu_to_node(cpu) == numa_node)
5522 cpumask_set_cpu(cpu, aff_mask);
5525 sibling_mask = topology_sibling_cpumask(cpu);
5526 first_cpu = cpumask_first(sibling_mask);
5527 if (first_cpu < nr_cpu_ids)
5528 cpumask_set_cpu(first_cpu, aff_mask);
5538 lpfc_assign_default_irq_chann(struct lpfc_hba *phba)
5540 #if IS_ENABLED(CONFIG_X86)
5541 switch (boot_cpu_data.x86_vendor) {
5542 case X86_VENDOR_AMD:
5543 /* If AMD architecture, then default is NUMA_MODE */
5544 phba->irq_chann_mode = NUMA_MODE;
5546 case X86_VENDOR_INTEL:
5547 /* If Intel architecture, then default is no hyperthread mode */
5548 phba->irq_chann_mode = NHT_MODE;
5551 phba->irq_chann_mode = NORMAL_MODE;
5554 lpfc_cpumask_irq_mode_init(phba);
5556 phba->irq_chann_mode = NORMAL_MODE;
5561 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5562 * for Hardware Queues to utilize. This also will map to the number
5563 * of EQ / MSI-X vectors the driver will create. This should never be
5564 * more than the number of Hardware Queues
5566 * 0 = Configure number of IRQ Channels to:
5567 * if AMD architecture, number of CPUs on HBA's NUMA node
5568 * if Intel architecture, number of physical CPUs.
5569 * otherwise, number of active CPUs.
5570 * [1,256] = Manually specify how many IRQ Channels to use.
5572 * Value range is [0,256]. Default value is [0].
5574 static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
5575 module_param(lpfc_irq_chann, uint, 0444);
5576 MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
5578 /* lpfc_irq_chann_init - Set the hba irq_chann initial value
5579 * @phba: lpfc_hba pointer.
5580 * @val: contains the initial value
5583 * Validates the initial value is within range and assigns it to the
5584 * adapter. If not in range, an error message is posted and the
5585 * default value is assigned.
5588 * zero if value is in range and is set
5589 * -EINVAL if value was out of range
5592 lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
5594 const struct cpumask *aff_mask;
5596 if (phba->cfg_use_msi != 2) {
5597 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5598 "8532 use_msi = %u ignoring cfg_irq_numa\n",
5600 phba->irq_chann_mode = NORMAL_MODE;
5601 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5605 /* Check if default setting was passed */
5606 if (val == LPFC_IRQ_CHANN_DEF &&
5607 phba->cfg_hdw_queue == LPFC_HBA_HDWQ_DEF &&
5608 phba->sli_rev == LPFC_SLI_REV4)
5609 lpfc_assign_default_irq_chann(phba);
5611 if (phba->irq_chann_mode != NORMAL_MODE) {
5612 aff_mask = &phba->sli4_hba.irq_aff_mask;
5614 if (cpumask_empty(aff_mask)) {
5615 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5616 "8533 Could not identify CPUS for "
5617 "mode %d, ignoring\n",
5618 phba->irq_chann_mode);
5619 phba->irq_chann_mode = NORMAL_MODE;
5620 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5622 phba->cfg_irq_chann = cpumask_weight(aff_mask);
5624 /* If no hyperthread mode, then set hdwq count to
5625 * aff_mask weight as well
5627 if (phba->irq_chann_mode == NHT_MODE)
5628 phba->cfg_hdw_queue = phba->cfg_irq_chann;
5630 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5631 "8543 lpfc_irq_chann set to %u "
5632 "(mode: %d)\n", phba->cfg_irq_chann,
5633 phba->irq_chann_mode);
5636 if (val > LPFC_IRQ_CHANN_MAX) {
5637 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5638 "8545 lpfc_irq_chann attribute cannot "
5639 "be set to %u, allowed range is "
5643 LPFC_IRQ_CHANN_MAX);
5644 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5647 if (phba->sli_rev == LPFC_SLI_REV4) {
5648 phba->cfg_irq_chann = val;
5650 phba->cfg_irq_chann = 2;
5651 phba->cfg_hdw_queue = 1;
5659 * lpfc_irq_chann_show - Display value of irq_chann
5660 * @dev: class converted to a Scsi_host structure.
5661 * @attr: device attribute, not used.
5662 * @buf: on return contains a string with the list sizes
5664 * Returns: size of formatted string.
5667 lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
5670 struct Scsi_Host *shost = class_to_shost(dev);
5671 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5672 struct lpfc_hba *phba = vport->phba;
5674 return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
5677 static DEVICE_ATTR_RO(lpfc_irq_chann);
5680 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5681 # 0 = HBA resets disabled
5682 # 1 = HBA resets enabled (default)
5683 # 2 = HBA reset via PCI bus reset enabled
5684 # Value range is [0,2]. Default value is 1.
5686 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5689 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5690 # 0 = HBA Heartbeat disabled
5691 # 1 = HBA Heartbeat enabled (default)
5692 # Value range is [0,1]. Default value is 1.
5694 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5697 # lpfc_EnableXLane: Enable Express Lane Feature
5698 # 0x0 Express Lane Feature disabled
5699 # 0x1 Express Lane Feature enabled
5700 # Value range is [0,1]. Default value is 0.
5702 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5705 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5706 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5707 # Value range is [0x0,0x7f]. Default value is 0
5709 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5712 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5713 # 0 = BlockGuard disabled (default)
5714 # 1 = BlockGuard enabled
5715 # Value range is [0,1]. Default value is 0.
5717 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5721 # - Bit mask of host protection capabilities used to register with the
5723 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5724 # - Allows you to ultimately specify which profiles to use
5725 # - Default will result in registering capabilities for all profiles.
5726 # - SHOST_DIF_TYPE1_PROTECTION 1
5727 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5728 # - SHOST_DIX_TYPE0_PROTECTION 8
5729 # HBA supports DIX Type 0: Host to HBA protection only
5730 # - SHOST_DIX_TYPE1_PROTECTION 16
5731 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5734 LPFC_ATTR(prot_mask,
5735 (SHOST_DIF_TYPE1_PROTECTION |
5736 SHOST_DIX_TYPE0_PROTECTION |
5737 SHOST_DIX_TYPE1_PROTECTION),
5739 (SHOST_DIF_TYPE1_PROTECTION |
5740 SHOST_DIX_TYPE0_PROTECTION |
5741 SHOST_DIX_TYPE1_PROTECTION),
5742 "T10-DIF host protection capabilities mask");
5746 # - Bit mask of protection guard types to register with the SCSI mid-layer
5747 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5748 # - Allows you to ultimately specify which profiles to use
5749 # - Default will result in registering capabilities for all guard types
5752 LPFC_ATTR(prot_guard,
5753 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5754 "T10-DIF host protection guard type");
5757 * Delay initial NPort discovery when Clean Address bit is cleared in
5758 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5759 * This parameter can have value 0 or 1.
5760 * When this parameter is set to 0, no delay is added to the initial
5762 * When this parameter is set to non-zero value, initial Nport discovery is
5763 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5764 * accept and FCID/Fabric name/Fabric portname is changed.
5765 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5766 * when Clean Address bit is cleared in FLOGI/FDISC
5767 * accept and FCID/Fabric name/Fabric portname is changed.
5768 * Default value is 0.
5770 LPFC_ATTR(delay_discovery, 0, 0, 1,
5771 "Delay NPort discovery when Clean Address bit is cleared.");
5774 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5775 * This value can be set to values between 64 and 4096. The default value
5776 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5777 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5778 * Because of the additional overhead involved in setting up T10-DIF,
5779 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5780 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5782 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5783 module_param(lpfc_sg_seg_cnt, uint, 0444);
5784 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5787 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5788 * configured for the adapter
5789 * @dev: class converted to a Scsi_host structure.
5790 * @attr: device attribute, not used.
5791 * @buf: on return contains a string with the list sizes
5793 * Returns: size of formatted string.
5796 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5799 struct Scsi_Host *shost = class_to_shost(dev);
5800 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5801 struct lpfc_hba *phba = vport->phba;
5804 len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
5805 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5807 len += scnprintf(buf + len, PAGE_SIZE - len,
5808 "Cfg: %d SCSI: %d NVME: %d\n",
5809 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5810 phba->cfg_nvme_seg_cnt);
5814 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5817 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5818 * @phba: lpfc_hba pointer.
5819 * @val: contains the initial value
5822 * Validates the initial value is within range and assigns it to the
5823 * adapter. If not in range, an error message is posted and the
5824 * default value is assigned.
5827 * zero if value is in range and is set
5828 * -EINVAL if value was out of range
5831 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5833 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5834 phba->cfg_sg_seg_cnt = val;
5837 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5838 "0409 lpfc_sg_seg_cnt attribute cannot be set to %d, "
5839 "allowed range is [%d, %d]\n",
5840 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5841 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5846 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5847 * 0 = MDS Diagnostics disabled (default)
5848 * 1 = MDS Diagnostics enabled
5849 * Value range is [0,1]. Default value is 0.
5851 LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5854 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5855 * 0 = Disable firmware logging (default)
5856 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
5857 * Value range [0..4]. Default value is 0
5859 LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5860 lpfc_param_show(ras_fwlog_buffsize);
5863 lpfc_ras_fwlog_buffsize_set(struct lpfc_hba *phba, uint val)
5866 enum ras_state state;
5868 if (!lpfc_rangecheck(val, 0, 4))
5871 if (phba->cfg_ras_fwlog_buffsize == val)
5874 if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
5877 spin_lock_irq(&phba->ras_fwlog_lock);
5878 state = phba->ras_fwlog.state;
5879 spin_unlock_irq(&phba->ras_fwlog_lock);
5881 if (state == REG_INPROGRESS) {
5882 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
5883 "registration is in progress\n");
5887 /* For disable logging: stop the logs and free the DMA.
5888 * For ras_fwlog_buffsize size change we still need to free and
5889 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
5891 phba->cfg_ras_fwlog_buffsize = val;
5892 if (state == ACTIVE) {
5893 lpfc_ras_stop_fwlog(phba);
5894 lpfc_sli4_ras_dma_free(phba);
5897 lpfc_sli4_ras_init(phba);
5898 if (phba->ras_fwlog.ras_enabled)
5899 ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
5900 LPFC_RAS_ENABLE_LOGGING);
5904 lpfc_param_store(ras_fwlog_buffsize);
5905 static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
5908 * lpfc_ras_fwlog_level: Firmware logging verbosity level
5909 * Valid only if firmware logging is enabled
5910 * 0(Least Verbosity) 4 (most verbosity)
5911 * Value range is [0..4]. Default value is 0
5913 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5916 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5917 * Default function which has RAS support : 0
5918 * Value Range is [0..3].
5919 * FW logging is a global action and enablement is via a specific
5922 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 3, "Firmware Logging Enabled on Function");
5925 * lpfc_enable_bbcr: Enable BB Credit Recovery
5926 * 0 = BB Credit Recovery disabled
5927 * 1 = BB Credit Recovery enabled (default)
5928 * Value range is [0,1]. Default value is 1.
5930 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5932 /* Signaling module parameters */
5933 int lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
5934 module_param(lpfc_fabric_cgn_frequency, int, 0444);
5935 MODULE_PARM_DESC(lpfc_fabric_cgn_frequency, "Congestion signaling fabric freq");
5937 unsigned char lpfc_acqe_cgn_frequency = 10; /* 10 sec default */
5938 module_param(lpfc_acqe_cgn_frequency, byte, 0444);
5939 MODULE_PARM_DESC(lpfc_acqe_cgn_frequency, "Congestion signaling ACQE freq");
5941 int lpfc_use_cgn_signal = 1; /* 0 - only use FPINs, 1 - Use signals if avail */
5942 module_param(lpfc_use_cgn_signal, int, 0444);
5943 MODULE_PARM_DESC(lpfc_use_cgn_signal, "Use Congestion signaling if available");
5946 * lpfc_enable_dpp: Enable DPP on G7
5947 * 0 = DPP on G7 disabled
5948 * 1 = DPP on G7 enabled (default)
5949 * Value range is [0,1]. Default value is 1.
5951 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5954 * lpfc_enable_mi: Enable FDMI MIB
5956 * 1 = enabled (default)
5957 * Value range is [0,1].
5959 LPFC_ATTR_R(enable_mi, 1, 0, 1, "Enable MI");
5962 * lpfc_max_vmid: Maximum number of VMs to be tagged. This is valid only if
5963 * either vmid_app_header or vmid_priority_tagging is enabled.
5964 * 4 - 255 = vmid support enabled for 4-255 VMs
5965 * Value range is [4,255].
5967 LPFC_ATTR_R(max_vmid, LPFC_MIN_VMID, LPFC_MIN_VMID, LPFC_MAX_VMID,
5968 "Maximum number of VMs supported");
5971 * lpfc_vmid_inactivity_timeout: Inactivity timeout duration in hours
5972 * 0 = Timeout is disabled
5973 * Value range is [0,24].
5975 LPFC_ATTR_R(vmid_inactivity_timeout, 4, 0, 24,
5976 "Inactivity timeout in hours");
5979 * lpfc_vmid_app_header: Enable App Header VMID support
5980 * 0 = Support is disabled (default)
5981 * 1 = Support is enabled
5982 * Value range is [0,1].
5984 LPFC_ATTR_R(vmid_app_header, LPFC_VMID_APP_HEADER_DISABLE,
5985 LPFC_VMID_APP_HEADER_DISABLE, LPFC_VMID_APP_HEADER_ENABLE,
5986 "Enable App Header VMID support");
5989 * lpfc_vmid_priority_tagging: Enable Priority Tagging VMID support
5990 * 0 = Support is disabled (default)
5991 * 1 = Allow supported targets only
5992 * 2 = Allow all targets
5993 * Value range is [0,2].
5995 LPFC_ATTR_R(vmid_priority_tagging, LPFC_VMID_PRIO_TAG_DISABLE,
5996 LPFC_VMID_PRIO_TAG_DISABLE,
5997 LPFC_VMID_PRIO_TAG_ALL_TARGETS,
5998 "Enable Priority Tagging VMID support");
6000 static struct attribute *lpfc_hba_attrs[] = {
6001 &dev_attr_nvme_info.attr,
6002 &dev_attr_scsi_stat.attr,
6003 &dev_attr_bg_info.attr,
6004 &dev_attr_bg_guard_err.attr,
6005 &dev_attr_bg_apptag_err.attr,
6006 &dev_attr_bg_reftag_err.attr,
6007 &dev_attr_info.attr,
6008 &dev_attr_serialnum.attr,
6009 &dev_attr_modeldesc.attr,
6010 &dev_attr_modelname.attr,
6011 &dev_attr_programtype.attr,
6012 &dev_attr_portnum.attr,
6013 &dev_attr_fwrev.attr,
6015 &dev_attr_option_rom_version.attr,
6016 &dev_attr_link_state.attr,
6017 &dev_attr_num_discovered_ports.attr,
6018 &dev_attr_lpfc_drvr_version.attr,
6019 &dev_attr_lpfc_enable_fip.attr,
6020 &dev_attr_lpfc_temp_sensor.attr,
6021 &dev_attr_lpfc_log_verbose.attr,
6022 &dev_attr_lpfc_lun_queue_depth.attr,
6023 &dev_attr_lpfc_tgt_queue_depth.attr,
6024 &dev_attr_lpfc_hba_queue_depth.attr,
6025 &dev_attr_lpfc_peer_port_login.attr,
6026 &dev_attr_lpfc_nodev_tmo.attr,
6027 &dev_attr_lpfc_devloss_tmo.attr,
6028 &dev_attr_lpfc_enable_fc4_type.attr,
6029 &dev_attr_lpfc_fcp_class.attr,
6030 &dev_attr_lpfc_use_adisc.attr,
6031 &dev_attr_lpfc_first_burst_size.attr,
6032 &dev_attr_lpfc_ack0.attr,
6033 &dev_attr_lpfc_xri_rebalancing.attr,
6034 &dev_attr_lpfc_topology.attr,
6035 &dev_attr_lpfc_scan_down.attr,
6036 &dev_attr_lpfc_link_speed.attr,
6037 &dev_attr_lpfc_fcp_io_sched.attr,
6038 &dev_attr_lpfc_ns_query.attr,
6039 &dev_attr_lpfc_fcp2_no_tgt_reset.attr,
6040 &dev_attr_lpfc_cr_delay.attr,
6041 &dev_attr_lpfc_cr_count.attr,
6042 &dev_attr_lpfc_multi_ring_support.attr,
6043 &dev_attr_lpfc_multi_ring_rctl.attr,
6044 &dev_attr_lpfc_multi_ring_type.attr,
6045 &dev_attr_lpfc_fdmi_on.attr,
6046 &dev_attr_lpfc_enable_SmartSAN.attr,
6047 &dev_attr_lpfc_max_luns.attr,
6048 &dev_attr_lpfc_enable_npiv.attr,
6049 &dev_attr_lpfc_fcf_failover_policy.attr,
6050 &dev_attr_lpfc_enable_rrq.attr,
6051 &dev_attr_lpfc_fcp_wait_abts_rsp.attr,
6052 &dev_attr_nport_evt_cnt.attr,
6053 &dev_attr_board_mode.attr,
6054 &dev_attr_lpfc_xcvr_data.attr,
6055 &dev_attr_max_vpi.attr,
6056 &dev_attr_used_vpi.attr,
6057 &dev_attr_max_rpi.attr,
6058 &dev_attr_used_rpi.attr,
6059 &dev_attr_max_xri.attr,
6060 &dev_attr_used_xri.attr,
6061 &dev_attr_npiv_info.attr,
6062 &dev_attr_issue_reset.attr,
6063 &dev_attr_lpfc_poll.attr,
6064 &dev_attr_lpfc_poll_tmo.attr,
6065 &dev_attr_lpfc_task_mgmt_tmo.attr,
6066 &dev_attr_lpfc_use_msi.attr,
6067 &dev_attr_lpfc_nvme_oas.attr,
6068 &dev_attr_lpfc_nvme_embed_cmd.attr,
6069 &dev_attr_lpfc_fcp_imax.attr,
6070 &dev_attr_lpfc_force_rscn.attr,
6071 &dev_attr_lpfc_cq_poll_threshold.attr,
6072 &dev_attr_lpfc_cq_max_proc_limit.attr,
6073 &dev_attr_lpfc_fcp_cpu_map.attr,
6074 &dev_attr_lpfc_fcp_mq_threshold.attr,
6075 &dev_attr_lpfc_hdw_queue.attr,
6076 &dev_attr_lpfc_irq_chann.attr,
6077 &dev_attr_lpfc_suppress_rsp.attr,
6078 &dev_attr_lpfc_nvmet_mrq.attr,
6079 &dev_attr_lpfc_nvmet_mrq_post.attr,
6080 &dev_attr_lpfc_nvme_enable_fb.attr,
6081 &dev_attr_lpfc_nvmet_fb_size.attr,
6082 &dev_attr_lpfc_enable_bg.attr,
6083 &dev_attr_lpfc_enable_hba_reset.attr,
6084 &dev_attr_lpfc_enable_hba_heartbeat.attr,
6085 &dev_attr_lpfc_EnableXLane.attr,
6086 &dev_attr_lpfc_XLanePriority.attr,
6087 &dev_attr_lpfc_xlane_lun.attr,
6088 &dev_attr_lpfc_xlane_tgt.attr,
6089 &dev_attr_lpfc_xlane_vpt.attr,
6090 &dev_attr_lpfc_xlane_lun_state.attr,
6091 &dev_attr_lpfc_xlane_lun_status.attr,
6092 &dev_attr_lpfc_xlane_priority.attr,
6093 &dev_attr_lpfc_sg_seg_cnt.attr,
6094 &dev_attr_lpfc_max_scsicmpl_time.attr,
6095 &dev_attr_lpfc_aer_support.attr,
6096 &dev_attr_lpfc_aer_state_cleanup.attr,
6097 &dev_attr_lpfc_sriov_nr_virtfn.attr,
6098 &dev_attr_lpfc_req_fw_upgrade.attr,
6099 &dev_attr_lpfc_suppress_link_up.attr,
6100 &dev_attr_iocb_hw.attr,
6103 &dev_attr_txq_hw.attr,
6104 &dev_attr_txcmplq_hw.attr,
6105 &dev_attr_lpfc_sriov_hw_max_virtfn.attr,
6106 &dev_attr_protocol.attr,
6107 &dev_attr_lpfc_xlane_supported.attr,
6108 &dev_attr_lpfc_enable_mds_diags.attr,
6109 &dev_attr_lpfc_ras_fwlog_buffsize.attr,
6110 &dev_attr_lpfc_ras_fwlog_level.attr,
6111 &dev_attr_lpfc_ras_fwlog_func.attr,
6112 &dev_attr_lpfc_enable_bbcr.attr,
6113 &dev_attr_lpfc_enable_dpp.attr,
6114 &dev_attr_lpfc_enable_mi.attr,
6115 &dev_attr_cmf_info.attr,
6116 &dev_attr_lpfc_max_vmid.attr,
6117 &dev_attr_lpfc_vmid_inactivity_timeout.attr,
6118 &dev_attr_lpfc_vmid_app_header.attr,
6119 &dev_attr_lpfc_vmid_priority_tagging.attr,
6123 static const struct attribute_group lpfc_hba_attr_group = {
6124 .attrs = lpfc_hba_attrs
6127 const struct attribute_group *lpfc_hba_groups[] = {
6128 &lpfc_hba_attr_group,
6132 static struct attribute *lpfc_vport_attrs[] = {
6133 &dev_attr_info.attr,
6134 &dev_attr_link_state.attr,
6135 &dev_attr_num_discovered_ports.attr,
6136 &dev_attr_lpfc_drvr_version.attr,
6137 &dev_attr_lpfc_log_verbose.attr,
6138 &dev_attr_lpfc_lun_queue_depth.attr,
6139 &dev_attr_lpfc_tgt_queue_depth.attr,
6140 &dev_attr_lpfc_nodev_tmo.attr,
6141 &dev_attr_lpfc_devloss_tmo.attr,
6142 &dev_attr_lpfc_hba_queue_depth.attr,
6143 &dev_attr_lpfc_peer_port_login.attr,
6144 &dev_attr_lpfc_restrict_login.attr,
6145 &dev_attr_lpfc_fcp_class.attr,
6146 &dev_attr_lpfc_use_adisc.attr,
6147 &dev_attr_lpfc_first_burst_size.attr,
6148 &dev_attr_lpfc_max_luns.attr,
6149 &dev_attr_nport_evt_cnt.attr,
6150 &dev_attr_npiv_info.attr,
6151 &dev_attr_lpfc_enable_da_id.attr,
6152 &dev_attr_lpfc_max_scsicmpl_time.attr,
6153 &dev_attr_lpfc_static_vport.attr,
6154 &dev_attr_cmf_info.attr,
6158 static const struct attribute_group lpfc_vport_attr_group = {
6159 .attrs = lpfc_vport_attrs
6162 const struct attribute_group *lpfc_vport_groups[] = {
6163 &lpfc_vport_attr_group,
6168 * sysfs_ctlreg_write - Write method for writing to ctlreg
6169 * @filp: open sysfs file
6170 * @kobj: kernel kobject that contains the kernel class device.
6171 * @bin_attr: kernel attributes passed to us.
6172 * @buf: contains the data to be written to the adapter IOREG space.
6173 * @off: offset into buffer to beginning of data.
6174 * @count: bytes to transfer.
6177 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6178 * Uses the adapter io control registers to send buf contents to the adapter.
6181 * -ERANGE off and count combo out of range
6182 * -EINVAL off, count or buff address invalid
6183 * -EPERM adapter is offline
6184 * value of count, buf contents written
6187 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6188 struct bin_attribute *bin_attr,
6189 char *buf, loff_t off, size_t count)
6192 struct device *dev = container_of(kobj, struct device, kobj);
6193 struct Scsi_Host *shost = class_to_shost(dev);
6194 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6195 struct lpfc_hba *phba = vport->phba;
6197 if (phba->sli_rev >= LPFC_SLI_REV4)
6200 if ((off + count) > FF_REG_AREA_SIZE)
6203 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6206 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6209 /* This is to protect HBA registers from accidental writes. */
6210 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6213 if (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
6216 spin_lock_irq(&phba->hbalock);
6217 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6218 buf_off += sizeof(uint32_t))
6219 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6220 phba->ctrl_regs_memmap_p + off + buf_off);
6222 spin_unlock_irq(&phba->hbalock);
6228 * sysfs_ctlreg_read - Read method for reading from ctlreg
6229 * @filp: open sysfs file
6230 * @kobj: kernel kobject that contains the kernel class device.
6231 * @bin_attr: kernel attributes passed to us.
6232 * @buf: if successful contains the data from the adapter IOREG space.
6233 * @off: offset into buffer to beginning of data.
6234 * @count: bytes to transfer.
6237 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6238 * Uses the adapter io control registers to read data into buf.
6241 * -ERANGE off and count combo out of range
6242 * -EINVAL off, count or buff address invalid
6243 * value of count, buf contents read
6246 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6247 struct bin_attribute *bin_attr,
6248 char *buf, loff_t off, size_t count)
6252 struct device *dev = container_of(kobj, struct device, kobj);
6253 struct Scsi_Host *shost = class_to_shost(dev);
6254 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6255 struct lpfc_hba *phba = vport->phba;
6257 if (phba->sli_rev >= LPFC_SLI_REV4)
6260 if (off > FF_REG_AREA_SIZE)
6263 if ((off + count) > FF_REG_AREA_SIZE)
6264 count = FF_REG_AREA_SIZE - off;
6266 if (count == 0) return 0;
6268 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6271 spin_lock_irq(&phba->hbalock);
6273 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6274 tmp_ptr = (uint32_t *)(buf + buf_off);
6275 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6278 spin_unlock_irq(&phba->hbalock);
6283 static struct bin_attribute sysfs_ctlreg_attr = {
6286 .mode = S_IRUSR | S_IWUSR,
6289 .read = sysfs_ctlreg_read,
6290 .write = sysfs_ctlreg_write,
6294 * sysfs_mbox_write - Write method for writing information via mbox
6295 * @filp: open sysfs file
6296 * @kobj: kernel kobject that contains the kernel class device.
6297 * @bin_attr: kernel attributes passed to us.
6298 * @buf: contains the data to be written to sysfs mbox.
6299 * @off: offset into buffer to beginning of data.
6300 * @count: bytes to transfer.
6303 * Deprecated function. All mailbox access from user space is performed via the
6307 * -EPERM operation not permitted
6310 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6311 struct bin_attribute *bin_attr,
6312 char *buf, loff_t off, size_t count)
6318 * sysfs_mbox_read - Read method for reading information via mbox
6319 * @filp: open sysfs file
6320 * @kobj: kernel kobject that contains the kernel class device.
6321 * @bin_attr: kernel attributes passed to us.
6322 * @buf: contains the data to be read from sysfs mbox.
6323 * @off: offset into buffer to beginning of data.
6324 * @count: bytes to transfer.
6327 * Deprecated function. All mailbox access from user space is performed via the
6331 * -EPERM operation not permitted
6334 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6335 struct bin_attribute *bin_attr,
6336 char *buf, loff_t off, size_t count)
6341 static struct bin_attribute sysfs_mbox_attr = {
6344 .mode = S_IRUSR | S_IWUSR,
6346 .size = MAILBOX_SYSFS_MAX,
6347 .read = sysfs_mbox_read,
6348 .write = sysfs_mbox_write,
6352 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6353 * @vport: address of lpfc vport structure.
6357 * error return code from sysfs_create_bin_file()
6360 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6362 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6365 /* Virtual ports do not need ctrl_reg and mbox */
6366 if (vport->port_type == LPFC_NPIV_PORT)
6369 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6370 &sysfs_ctlreg_attr);
6374 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6377 goto out_remove_ctlreg_attr;
6380 out_remove_ctlreg_attr:
6381 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6387 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6388 * @vport: address of lpfc vport structure.
6391 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6393 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6395 /* Virtual ports do not need ctrl_reg and mbox */
6396 if (vport->port_type == LPFC_NPIV_PORT)
6398 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6399 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6403 * Dynamic FC Host Attributes Support
6407 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6408 * @shost: kernel scsi host pointer.
6411 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6413 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6415 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6416 sizeof fc_host_symbolic_name(shost));
6420 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6421 * @shost: kernel scsi host pointer.
6424 lpfc_get_host_port_id(struct Scsi_Host *shost)
6426 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6428 /* note: fc_myDID already in cpu endianness */
6429 fc_host_port_id(shost) = vport->fc_myDID;
6433 * lpfc_get_host_port_type - Set the value of the scsi host port type
6434 * @shost: kernel scsi host pointer.
6437 lpfc_get_host_port_type(struct Scsi_Host *shost)
6439 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6440 struct lpfc_hba *phba = vport->phba;
6442 if (vport->port_type == LPFC_NPIV_PORT) {
6443 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6444 } else if (lpfc_is_link_up(phba)) {
6445 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6446 if (test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
6447 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6449 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6451 if (test_bit(FC_FABRIC, &vport->fc_flag))
6452 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6454 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6457 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6461 * lpfc_get_host_port_state - Set the value of the scsi host port state
6462 * @shost: kernel scsi host pointer.
6465 lpfc_get_host_port_state(struct Scsi_Host *shost)
6467 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6468 struct lpfc_hba *phba = vport->phba;
6470 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
6471 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6473 switch (phba->link_state) {
6474 case LPFC_LINK_UNKNOWN:
6475 case LPFC_LINK_DOWN:
6476 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6480 case LPFC_HBA_READY:
6481 /* Links up, reports port state accordingly */
6482 if (vport->port_state < LPFC_VPORT_READY)
6483 fc_host_port_state(shost) =
6484 FC_PORTSTATE_BYPASSED;
6486 fc_host_port_state(shost) =
6487 FC_PORTSTATE_ONLINE;
6489 case LPFC_HBA_ERROR:
6490 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6493 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6500 * lpfc_get_host_speed - Set the value of the scsi host speed
6501 * @shost: kernel scsi host pointer.
6504 lpfc_get_host_speed(struct Scsi_Host *shost)
6506 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6507 struct lpfc_hba *phba = vport->phba;
6509 if ((lpfc_is_link_up(phba)) &&
6510 !test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
6511 switch(phba->fc_linkspeed) {
6512 case LPFC_LINK_SPEED_1GHZ:
6513 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6515 case LPFC_LINK_SPEED_2GHZ:
6516 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6518 case LPFC_LINK_SPEED_4GHZ:
6519 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6521 case LPFC_LINK_SPEED_8GHZ:
6522 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6524 case LPFC_LINK_SPEED_10GHZ:
6525 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6527 case LPFC_LINK_SPEED_16GHZ:
6528 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6530 case LPFC_LINK_SPEED_32GHZ:
6531 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6533 case LPFC_LINK_SPEED_64GHZ:
6534 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6536 case LPFC_LINK_SPEED_128GHZ:
6537 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6539 case LPFC_LINK_SPEED_256GHZ:
6540 fc_host_speed(shost) = FC_PORTSPEED_256GBIT;
6543 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6546 } else if (lpfc_is_link_up(phba) &&
6547 test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
6548 switch (phba->fc_linkspeed) {
6549 case LPFC_ASYNC_LINK_SPEED_1GBPS:
6550 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6552 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6553 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6555 case LPFC_ASYNC_LINK_SPEED_20GBPS:
6556 fc_host_speed(shost) = FC_PORTSPEED_20GBIT;
6558 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6559 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6561 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6562 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6564 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6565 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6568 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6572 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6576 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6577 * @shost: kernel scsi host pointer.
6580 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6582 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6583 struct lpfc_hba *phba = vport->phba;
6586 if (vport->port_state > LPFC_FLOGI &&
6587 (test_bit(FC_FABRIC, &vport->fc_flag) ||
6588 (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
6589 test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))))
6590 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6592 /* fabric is local port if there is no F/FL_Port */
6595 fc_host_fabric_name(shost) = node_name;
6599 * lpfc_get_stats - Return statistical information about the adapter
6600 * @shost: kernel scsi host pointer.
6603 * NULL on error for link down, no mbox pool, sli2 active,
6604 * management not allowed, memory allocation error, or mbox error.
6608 * address of the adapter host statistics
6610 static struct fc_host_statistics *
6611 lpfc_get_stats(struct Scsi_Host *shost)
6613 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6614 struct lpfc_hba *phba = vport->phba;
6615 struct lpfc_sli *psli = &phba->sli;
6616 struct fc_host_statistics *hs = &phba->link_stats;
6617 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6618 LPFC_MBOXQ_t *pmboxq;
6623 * prevent udev from issuing mailbox commands until the port is
6626 if (phba->link_state < LPFC_LINK_DOWN ||
6627 !phba->mbox_mem_pool ||
6628 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6631 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6634 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6637 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6639 pmb = &pmboxq->u.mb;
6640 pmb->mbxCommand = MBX_READ_STATUS;
6641 pmb->mbxOwner = OWN_HOST;
6642 pmboxq->ctx_buf = NULL;
6643 pmboxq->vport = vport;
6645 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
6646 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6647 if (rc != MBX_SUCCESS) {
6648 mempool_free(pmboxq, phba->mbox_mem_pool);
6652 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6653 if (rc != MBX_SUCCESS) {
6654 if (rc != MBX_TIMEOUT)
6655 mempool_free(pmboxq, phba->mbox_mem_pool);
6660 memset(hs, 0, sizeof (struct fc_host_statistics));
6662 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6663 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6666 * The MBX_READ_STATUS returns tx_k_bytes which has to be
6667 * converted to words.
6669 * Check if extended byte flag is set, to know when to collect upper
6670 * bits of 64 bit wide statistics counter.
6672 if (pmb->un.varRdStatus.xkb & RD_ST_XKB) {
6673 hs->tx_words = (u64)
6674 ((((u64)(pmb->un.varRdStatus.xmit_xkb &
6675 RD_ST_XMIT_XKB_MASK) << 32) |
6676 (u64)pmb->un.varRdStatus.xmitByteCnt) *
6678 hs->rx_words = (u64)
6679 ((((u64)(pmb->un.varRdStatus.rcv_xkb &
6680 RD_ST_RCV_XKB_MASK) << 32) |
6681 (u64)pmb->un.varRdStatus.rcvByteCnt) *
6684 hs->tx_words = (uint64_t)
6685 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6687 hs->rx_words = (uint64_t)
6688 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6692 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6693 pmb->mbxCommand = MBX_READ_LNK_STAT;
6694 pmb->mbxOwner = OWN_HOST;
6695 pmboxq->ctx_buf = NULL;
6696 pmboxq->vport = vport;
6698 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
6699 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6700 if (rc != MBX_SUCCESS) {
6701 mempool_free(pmboxq, phba->mbox_mem_pool);
6705 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6706 if (rc != MBX_SUCCESS) {
6707 if (rc != MBX_TIMEOUT)
6708 mempool_free(pmboxq, phba->mbox_mem_pool);
6713 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6714 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6715 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6716 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6717 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6718 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6719 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6721 hs->cn_sig_warn = atomic64_read(&phba->cgn_acqe_stat.warn);
6722 hs->cn_sig_alarm = atomic64_read(&phba->cgn_acqe_stat.alarm);
6724 hs->link_failure_count -= lso->link_failure_count;
6725 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6726 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6727 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6728 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6729 hs->invalid_crc_count -= lso->invalid_crc_count;
6730 hs->error_frames -= lso->error_frames;
6732 if (test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
6734 hs->nos_count = (phba->link_events >> 1);
6735 hs->nos_count -= lso->link_events;
6736 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6737 hs->lip_count = (phba->fc_eventTag >> 1);
6738 hs->lip_count -= lso->link_events;
6742 hs->nos_count = (phba->fc_eventTag >> 1);
6743 hs->nos_count -= lso->link_events;
6746 hs->dumped_frames = -1;
6748 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6750 mempool_free(pmboxq, phba->mbox_mem_pool);
6756 * lpfc_reset_stats - Copy the adapter link stats information
6757 * @shost: kernel scsi host pointer.
6760 lpfc_reset_stats(struct Scsi_Host *shost)
6762 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6763 struct lpfc_hba *phba = vport->phba;
6764 struct lpfc_sli *psli = &phba->sli;
6765 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6766 LPFC_MBOXQ_t *pmboxq;
6770 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6773 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6776 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6778 pmb = &pmboxq->u.mb;
6779 pmb->mbxCommand = MBX_READ_STATUS;
6780 pmb->mbxOwner = OWN_HOST;
6781 pmb->un.varWords[0] = 0x1; /* reset request */
6782 pmboxq->ctx_buf = NULL;
6783 pmboxq->vport = vport;
6785 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
6786 !(psli->sli_flag & LPFC_SLI_ACTIVE)) {
6787 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6788 if (rc != MBX_SUCCESS) {
6789 mempool_free(pmboxq, phba->mbox_mem_pool);
6793 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6794 if (rc != MBX_SUCCESS) {
6795 if (rc != MBX_TIMEOUT)
6796 mempool_free(pmboxq, phba->mbox_mem_pool);
6801 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6802 pmb->mbxCommand = MBX_READ_LNK_STAT;
6803 pmb->mbxOwner = OWN_HOST;
6804 pmboxq->ctx_buf = NULL;
6805 pmboxq->vport = vport;
6807 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
6808 !(psli->sli_flag & LPFC_SLI_ACTIVE)) {
6809 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6810 if (rc != MBX_SUCCESS) {
6811 mempool_free(pmboxq, phba->mbox_mem_pool);
6815 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6816 if (rc != MBX_SUCCESS) {
6817 if (rc != MBX_TIMEOUT)
6818 mempool_free(pmboxq, phba->mbox_mem_pool);
6823 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6824 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6825 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6826 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6827 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6828 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6829 lso->error_frames = pmb->un.varRdLnk.crcCnt;
6830 if (test_bit(HBA_FCOE_MODE, &phba->hba_flag))
6831 lso->link_events = (phba->link_events >> 1);
6833 lso->link_events = (phba->fc_eventTag >> 1);
6835 atomic64_set(&phba->cgn_acqe_stat.warn, 0);
6836 atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
6838 memset(&shost_to_fc_host(shost)->fpin_stats, 0,
6839 sizeof(shost_to_fc_host(shost)->fpin_stats));
6841 psli->stats_start = ktime_get_seconds();
6843 mempool_free(pmboxq, phba->mbox_mem_pool);
6849 * The LPFC driver treats linkdown handling as target loss events so there
6850 * are no sysfs handlers for link_down_tmo.
6854 * lpfc_get_node_by_target - Return the nodelist for a target
6855 * @starget: kernel scsi target pointer.
6858 * address of the node list if found
6859 * NULL target not found
6861 static struct lpfc_nodelist *
6862 lpfc_get_node_by_target(struct scsi_target *starget)
6864 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6865 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6866 struct lpfc_nodelist *ndlp;
6867 unsigned long iflags;
6869 spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
6870 /* Search for this, mapped, target ID */
6871 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6872 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6873 starget->id == ndlp->nlp_sid) {
6874 spin_unlock_irqrestore(&vport->fc_nodes_list_lock,
6879 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
6884 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6885 * @starget: kernel scsi target pointer.
6888 lpfc_get_starget_port_id(struct scsi_target *starget)
6890 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6892 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6896 * lpfc_get_starget_node_name - Set the target node name
6897 * @starget: kernel scsi target pointer.
6899 * Description: Set the target node name to the ndlp node name wwn or zero.
6902 lpfc_get_starget_node_name(struct scsi_target *starget)
6904 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6906 fc_starget_node_name(starget) =
6907 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6911 * lpfc_get_starget_port_name - Set the target port name
6912 * @starget: kernel scsi target pointer.
6914 * Description: set the target port name to the ndlp port name wwn or zero.
6917 lpfc_get_starget_port_name(struct scsi_target *starget)
6919 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6921 fc_starget_port_name(starget) =
6922 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6926 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6927 * @rport: fc rport address.
6928 * @timeout: new value for dev loss tmo.
6931 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6932 * dev_loss_tmo to one.
6935 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6937 struct lpfc_rport_data *rdata = rport->dd_data;
6938 struct lpfc_nodelist *ndlp = rdata->pnode;
6939 #if (IS_ENABLED(CONFIG_NVME_FC))
6940 struct lpfc_nvme_rport *nrport = NULL;
6944 rport->dev_loss_tmo = timeout;
6946 rport->dev_loss_tmo = 1;
6949 dev_info(&rport->dev, "Cannot find remote node to "
6950 "set rport dev loss tmo, port_id x%x\n",
6955 #if (IS_ENABLED(CONFIG_NVME_FC))
6956 nrport = lpfc_ndlp_get_nrport(ndlp);
6958 if (nrport && nrport->remoteport)
6959 nvme_fc_set_remoteport_devloss(nrport->remoteport,
6960 rport->dev_loss_tmo);
6965 * lpfc_rport_show_function - Return rport target information
6968 * Macro that uses field to generate a function with the name lpfc_show_rport_
6970 * lpfc_show_rport_##field: returns the bytes formatted in buf
6971 * @cdev: class converted to an fc_rport.
6972 * @buf: on return contains the target_field or zero.
6974 * Returns: size of formatted string.
6976 #define lpfc_rport_show_function(field, format_string, sz, cast) \
6978 lpfc_show_rport_##field (struct device *dev, \
6979 struct device_attribute *attr, \
6982 struct fc_rport *rport = transport_class_to_rport(dev); \
6983 struct lpfc_rport_data *rdata = rport->hostdata; \
6984 return scnprintf(buf, sz, format_string, \
6985 (rdata->target) ? cast rdata->target->field : 0); \
6988 #define lpfc_rport_rd_attr(field, format_string, sz) \
6989 lpfc_rport_show_function(field, format_string, sz, ) \
6990 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6993 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6994 * @fc_vport: The fc_vport who's symbolic name has been changed.
6997 * This function is called by the transport after the @fc_vport's symbolic name
6998 * has been changed. This function re-registers the symbolic name with the
6999 * switch to propagate the change into the fabric if the vport is active.
7002 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
7004 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
7006 if (vport->port_state == LPFC_VPORT_READY)
7007 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
7011 * lpfc_hba_log_verbose_init - Set hba's log verbose level
7012 * @phba: Pointer to lpfc_hba struct.
7013 * @verbose: Verbose level to set.
7015 * This function is called by the lpfc_get_cfgparam() routine to set the
7016 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
7017 * log message according to the module's lpfc_log_verbose parameter setting
7018 * before hba port or vport created.
7021 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
7023 phba->cfg_log_verbose = verbose;
7026 struct fc_function_template lpfc_transport_functions = {
7027 /* fixed attributes the driver supports */
7028 .show_host_node_name = 1,
7029 .show_host_port_name = 1,
7030 .show_host_supported_classes = 1,
7031 .show_host_supported_fc4s = 1,
7032 .show_host_supported_speeds = 1,
7033 .show_host_maxframe_size = 1,
7035 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7036 .show_host_symbolic_name = 1,
7038 /* dynamic attributes the driver supports */
7039 .get_host_port_id = lpfc_get_host_port_id,
7040 .show_host_port_id = 1,
7042 .get_host_port_type = lpfc_get_host_port_type,
7043 .show_host_port_type = 1,
7045 .get_host_port_state = lpfc_get_host_port_state,
7046 .show_host_port_state = 1,
7048 /* active_fc4s is shown but doesn't change (thus no get function) */
7049 .show_host_active_fc4s = 1,
7051 .get_host_speed = lpfc_get_host_speed,
7052 .show_host_speed = 1,
7054 .get_host_fabric_name = lpfc_get_host_fabric_name,
7055 .show_host_fabric_name = 1,
7058 * The LPFC driver treats linkdown handling as target loss events
7059 * so there are no sysfs handlers for link_down_tmo.
7062 .get_fc_host_stats = lpfc_get_stats,
7063 .reset_fc_host_stats = lpfc_reset_stats,
7065 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7066 .show_rport_maxframe_size = 1,
7067 .show_rport_supported_classes = 1,
7069 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7070 .show_rport_dev_loss_tmo = 1,
7072 .get_starget_port_id = lpfc_get_starget_port_id,
7073 .show_starget_port_id = 1,
7075 .get_starget_node_name = lpfc_get_starget_node_name,
7076 .show_starget_node_name = 1,
7078 .get_starget_port_name = lpfc_get_starget_port_name,
7079 .show_starget_port_name = 1,
7081 .issue_fc_host_lip = lpfc_issue_lip,
7082 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7083 .terminate_rport_io = lpfc_terminate_rport_io,
7085 .dd_fcvport_size = sizeof(struct lpfc_vport *),
7087 .vport_disable = lpfc_vport_disable,
7089 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7091 .bsg_request = lpfc_bsg_request,
7092 .bsg_timeout = lpfc_bsg_timeout,
7095 struct fc_function_template lpfc_vport_transport_functions = {
7096 /* fixed attributes the driver supports */
7097 .show_host_node_name = 1,
7098 .show_host_port_name = 1,
7099 .show_host_supported_classes = 1,
7100 .show_host_supported_fc4s = 1,
7101 .show_host_supported_speeds = 1,
7102 .show_host_maxframe_size = 1,
7104 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7105 .show_host_symbolic_name = 1,
7107 /* dynamic attributes the driver supports */
7108 .get_host_port_id = lpfc_get_host_port_id,
7109 .show_host_port_id = 1,
7111 .get_host_port_type = lpfc_get_host_port_type,
7112 .show_host_port_type = 1,
7114 .get_host_port_state = lpfc_get_host_port_state,
7115 .show_host_port_state = 1,
7117 /* active_fc4s is shown but doesn't change (thus no get function) */
7118 .show_host_active_fc4s = 1,
7120 .get_host_speed = lpfc_get_host_speed,
7121 .show_host_speed = 1,
7123 .get_host_fabric_name = lpfc_get_host_fabric_name,
7124 .show_host_fabric_name = 1,
7127 * The LPFC driver treats linkdown handling as target loss events
7128 * so there are no sysfs handlers for link_down_tmo.
7131 .get_fc_host_stats = lpfc_get_stats,
7132 .reset_fc_host_stats = lpfc_reset_stats,
7134 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7135 .show_rport_maxframe_size = 1,
7136 .show_rport_supported_classes = 1,
7138 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7139 .show_rport_dev_loss_tmo = 1,
7141 .get_starget_port_id = lpfc_get_starget_port_id,
7142 .show_starget_port_id = 1,
7144 .get_starget_node_name = lpfc_get_starget_node_name,
7145 .show_starget_node_name = 1,
7147 .get_starget_port_name = lpfc_get_starget_port_name,
7148 .show_starget_port_name = 1,
7150 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7151 .terminate_rport_io = lpfc_terminate_rport_io,
7153 .vport_disable = lpfc_vport_disable,
7155 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7159 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7161 * @phba: lpfc_hba pointer.
7164 lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7166 /* If the adapter supports FCoE mode */
7167 switch (phba->pcidev->device) {
7168 case PCI_DEVICE_ID_SKYHAWK:
7169 case PCI_DEVICE_ID_SKYHAWK_VF:
7170 case PCI_DEVICE_ID_LANCER_FCOE:
7171 case PCI_DEVICE_ID_LANCER_FCOE_VF:
7172 case PCI_DEVICE_ID_ZEPHYR_DCSP:
7173 case PCI_DEVICE_ID_TIGERSHARK:
7174 case PCI_DEVICE_ID_TOMCAT:
7175 set_bit(HBA_FCOE_MODE, &phba->hba_flag);
7178 /* for others, clear the flag */
7179 clear_bit(HBA_FCOE_MODE, &phba->hba_flag);
7184 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7185 * @phba: lpfc_hba pointer.
7188 lpfc_get_cfgparam(struct lpfc_hba *phba)
7190 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7191 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
7192 lpfc_ns_query_init(phba, lpfc_ns_query);
7193 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7194 lpfc_cr_delay_init(phba, lpfc_cr_delay);
7195 lpfc_cr_count_init(phba, lpfc_cr_count);
7196 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
7197 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7198 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7199 lpfc_ack0_init(phba, lpfc_ack0);
7200 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
7201 lpfc_topology_init(phba, lpfc_topology);
7202 lpfc_link_speed_init(phba, lpfc_link_speed);
7203 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
7204 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
7205 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7206 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
7207 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
7208 lpfc_fcp_wait_abts_rsp_init(phba, lpfc_fcp_wait_abts_rsp);
7209 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7210 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
7211 lpfc_use_msi_init(phba, lpfc_use_msi);
7212 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
7213 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
7214 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7215 lpfc_force_rscn_init(phba, lpfc_force_rscn);
7216 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7217 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
7218 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
7219 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7220 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
7222 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7224 lpfc_max_vmid_init(phba, lpfc_max_vmid);
7225 lpfc_vmid_inactivity_timeout_init(phba, lpfc_vmid_inactivity_timeout);
7226 lpfc_vmid_app_header_init(phba, lpfc_vmid_app_header);
7227 lpfc_vmid_priority_tagging_init(phba, lpfc_vmid_priority_tagging);
7228 if (phba->sli_rev != LPFC_SLI_REV4)
7229 phba->cfg_EnableXLane = 0;
7230 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
7232 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7233 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7234 phba->cfg_oas_lun_state = 0;
7235 phba->cfg_oas_lun_status = 0;
7236 phba->cfg_oas_flags = 0;
7237 phba->cfg_oas_priority = 0;
7238 lpfc_enable_bg_init(phba, lpfc_enable_bg);
7239 lpfc_prot_mask_init(phba, lpfc_prot_mask);
7240 lpfc_prot_guard_init(phba, lpfc_prot_guard);
7241 if (phba->sli_rev == LPFC_SLI_REV4)
7244 phba->cfg_poll = lpfc_poll;
7246 /* Get the function mode */
7247 lpfc_get_hba_function_mode(phba);
7249 /* BlockGuard allowed for FC only. */
7250 if (phba->cfg_enable_bg && test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
7251 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7252 "0581 BlockGuard feature not supported\n");
7253 /* If set, clear the BlockGuard support param */
7254 phba->cfg_enable_bg = 0;
7255 } else if (phba->cfg_enable_bg) {
7256 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
7259 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
7261 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
7262 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
7263 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
7265 /* Initialize first burst. Target vs Initiator are different. */
7266 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
7267 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
7268 lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
7269 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
7270 lpfc_irq_chann_init(phba, lpfc_irq_chann);
7271 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7272 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7273 lpfc_enable_mi_init(phba, lpfc_enable_mi);
7275 phba->cgn_p.cgn_param_mode = LPFC_CFG_OFF;
7276 phba->cmf_active_mode = LPFC_CFG_OFF;
7277 if (lpfc_fabric_cgn_frequency > EDC_CG_SIGFREQ_CNT_MAX ||
7278 lpfc_fabric_cgn_frequency < EDC_CG_SIGFREQ_CNT_MIN)
7279 lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
7281 if (phba->sli_rev != LPFC_SLI_REV4) {
7282 /* NVME only supported on SLI4 */
7283 phba->nvmet_support = 0;
7284 phba->cfg_nvmet_mrq = 0;
7285 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7286 phba->cfg_enable_bbcr = 0;
7287 phba->cfg_xri_rebalancing = 0;
7289 /* We MUST have FCP support */
7290 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7291 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7294 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7296 phba->cfg_enable_pbde = 0;
7298 /* A value of 0 means use the number of CPUs found in the system */
7299 if (phba->cfg_hdw_queue == 0)
7300 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7301 if (phba->cfg_irq_chann == 0)
7302 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7303 if (phba->cfg_irq_chann > phba->cfg_hdw_queue &&
7304 phba->sli_rev == LPFC_SLI_REV4)
7305 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7307 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7308 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7309 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7310 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7311 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7312 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7313 lpfc_sli_mode_init(phba, lpfc_sli_mode);
7314 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7315 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7316 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7317 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7323 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7324 * dependencies between protocols and roles.
7325 * @phba: lpfc_hba pointer.
7328 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7332 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu) {
7333 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7336 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu) {
7337 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7340 if (phba->cfg_irq_chann > phba->cfg_hdw_queue) {
7341 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7345 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7346 "2006 Reducing Queues - CPU limitation: "
7348 phba->cfg_irq_chann,
7349 phba->cfg_hdw_queue);
7351 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7352 phba->nvmet_support) {
7353 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7355 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7356 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7357 "NVME Target PRLI ACC enable_fb ",
7358 phba->cfg_nvme_enable_fb,
7359 phba->cfg_nvmet_fb_size,
7360 LPFC_NVMET_FB_SZ_MAX);
7362 if (phba->cfg_nvme_enable_fb == 0)
7363 phba->cfg_nvmet_fb_size = 0;
7365 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7366 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7369 if (!phba->cfg_nvmet_mrq)
7370 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7372 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7373 if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
7374 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7375 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7376 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7377 phba->cfg_nvmet_mrq);
7379 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7380 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7383 /* Not NVME Target mode. Turn off Target parameters. */
7384 phba->nvmet_support = 0;
7385 phba->cfg_nvmet_mrq = 0;
7386 phba->cfg_nvmet_fb_size = 0;
7391 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7392 * @vport: lpfc_vport pointer.
7395 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7397 lpfc_log_verbose_init(vport, lpfc_log_verbose);
7398 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7399 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7400 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7401 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7402 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7403 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7404 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7405 lpfc_use_adisc_init(vport, lpfc_use_adisc);
7406 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7407 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7408 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7409 lpfc_max_luns_init(vport, lpfc_max_luns);
7410 lpfc_scan_down_init(vport, lpfc_scan_down);
7411 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);