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;
1834 unsigned long val = 0;
1838 if (!strncmp("enable", buff_out,
1839 strlen("enable"))) {
1840 pval = buff_out + strlen("enable") + 1;
1841 rc = kstrtoul(pval, 0, &val);
1843 return rc; /* Invalid number */
1844 } else if (!strncmp("disable", buff_out,
1845 strlen("disable"))) {
1848 return -EINVAL; /* Invalid command */
1853 val = 0x0; /* Disable */
1856 val = 0x1; /* Enable two port trunk */
1859 val = 0x2; /* Enable four port trunk */
1865 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1866 "0070 Set trunk mode with val %ld ", val);
1868 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1872 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1873 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1874 12, LPFC_SLI4_MBX_EMBED);
1876 bf_set(lpfc_mbx_set_trunk_mode,
1877 &mbox->u.mqe.un.set_trunk_mode,
1879 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1881 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1882 "0071 Set trunk mode failed with status: %d",
1884 mempool_free(mbox, phba->mbox_mem_pool);
1890 lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr,
1893 struct Scsi_Host *shost = class_to_shost(dev);
1894 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1895 struct lpfc_hba *phba = vport->phba;
1898 struct lpfc_rdp_context *rdp_context;
1906 struct sff_trasnceiver_codes_byte7 *trasn_code_byte7;
1908 /* Get transceiver information */
1909 rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL);
1911 rc = lpfc_get_sfp_info_wait(phba, rdp_context);
1913 len = scnprintf(buf, PAGE_SIZE - len, "SFP info NA:\n");
1917 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_NAME], 16);
1919 len = scnprintf(buf, PAGE_SIZE - len, "VendorName:\t%s\n", chbuf);
1920 len += scnprintf(buf + len, PAGE_SIZE - len,
1921 "VendorOUI:\t%02x-%02x-%02x\n",
1922 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI],
1923 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 1],
1924 (uint8_t)rdp_context->page_a0[SSF_VENDOR_OUI + 2]);
1925 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_PN], 16);
1926 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorPN:\t%s\n", chbuf);
1927 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_SN], 16);
1928 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorSN:\t%s\n", chbuf);
1929 strscpy(chbuf, &rdp_context->page_a0[SSF_VENDOR_REV], 4);
1930 len += scnprintf(buf + len, PAGE_SIZE - len, "VendorRev:\t%s\n", chbuf);
1931 strscpy(chbuf, &rdp_context->page_a0[SSF_DATE_CODE], 8);
1932 len += scnprintf(buf + len, PAGE_SIZE - len, "DateCode:\t%s\n", chbuf);
1933 len += scnprintf(buf + len, PAGE_SIZE - len, "Identifier:\t%xh\n",
1934 (uint8_t)rdp_context->page_a0[SSF_IDENTIFIER]);
1935 len += scnprintf(buf + len, PAGE_SIZE - len, "ExtIdentifier:\t%xh\n",
1936 (uint8_t)rdp_context->page_a0[SSF_EXT_IDENTIFIER]);
1937 len += scnprintf(buf + len, PAGE_SIZE - len, "Connector:\t%xh\n",
1938 (uint8_t)rdp_context->page_a0[SSF_CONNECTOR]);
1939 wavelength = (rdp_context->page_a0[SSF_WAVELENGTH_B1] << 8) |
1940 rdp_context->page_a0[SSF_WAVELENGTH_B0];
1942 len += scnprintf(buf + len, PAGE_SIZE - len, "Wavelength:\t%d nm\n",
1944 trasn_code_byte7 = (struct sff_trasnceiver_codes_byte7 *)
1945 &rdp_context->page_a0[SSF_TRANSCEIVER_CODE_B7];
1947 len += scnprintf(buf + len, PAGE_SIZE - len, "Speeds: \t");
1948 if (*(uint8_t *)trasn_code_byte7 == 0) {
1949 len += scnprintf(buf + len, PAGE_SIZE - len, "Unknown\n");
1951 if (trasn_code_byte7->fc_sp_100MB)
1952 len += scnprintf(buf + len, PAGE_SIZE - len, "1 ");
1953 if (trasn_code_byte7->fc_sp_200mb)
1954 len += scnprintf(buf + len, PAGE_SIZE - len, "2 ");
1955 if (trasn_code_byte7->fc_sp_400MB)
1956 len += scnprintf(buf + len, PAGE_SIZE - len, "4 ");
1957 if (trasn_code_byte7->fc_sp_800MB)
1958 len += scnprintf(buf + len, PAGE_SIZE - len, "8 ");
1959 if (trasn_code_byte7->fc_sp_1600MB)
1960 len += scnprintf(buf + len, PAGE_SIZE - len, "16 ");
1961 if (trasn_code_byte7->fc_sp_3200MB)
1962 len += scnprintf(buf + len, PAGE_SIZE - len, "32 ");
1963 if (trasn_code_byte7->speed_chk_ecc)
1964 len += scnprintf(buf + len, PAGE_SIZE - len, "64 ");
1965 len += scnprintf(buf + len, PAGE_SIZE - len, "GB\n");
1967 temperature = (rdp_context->page_a2[SFF_TEMPERATURE_B1] << 8 |
1968 rdp_context->page_a2[SFF_TEMPERATURE_B0]);
1969 vcc = (rdp_context->page_a2[SFF_VCC_B1] << 8 |
1970 rdp_context->page_a2[SFF_VCC_B0]);
1971 tx_power = (rdp_context->page_a2[SFF_TXPOWER_B1] << 8 |
1972 rdp_context->page_a2[SFF_TXPOWER_B0]);
1973 tx_bias = (rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
1974 rdp_context->page_a2[SFF_TX_BIAS_CURRENT_B0]);
1975 rx_power = (rdp_context->page_a2[SFF_RXPOWER_B1] << 8 |
1976 rdp_context->page_a2[SFF_RXPOWER_B0]);
1978 len += scnprintf(buf + len, PAGE_SIZE - len,
1979 "Temperature:\tx%04x C\n", temperature);
1980 len += scnprintf(buf + len, PAGE_SIZE - len, "Vcc:\t\tx%04x V\n", vcc);
1981 len += scnprintf(buf + len, PAGE_SIZE - len,
1982 "TxBiasCurrent:\tx%04x mA\n", tx_bias);
1983 len += scnprintf(buf + len, PAGE_SIZE - len, "TxPower:\tx%04x mW\n",
1985 len += scnprintf(buf + len, PAGE_SIZE - len, "RxPower:\tx%04x mW\n",
1993 * lpfc_board_mode_show - Return the state of the board
1994 * @dev: class device that is converted into a Scsi_host.
1995 * @attr: device attribute, not used.
1996 * @buf: on return contains the state of the adapter.
1998 * Returns: size of formatted string.
2001 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
2004 struct Scsi_Host *shost = class_to_shost(dev);
2005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2006 struct lpfc_hba *phba = vport->phba;
2009 if (phba->link_state == LPFC_HBA_ERROR)
2011 else if (phba->link_state == LPFC_WARM_START)
2012 state = "warm start";
2013 else if (phba->link_state == LPFC_INIT_START)
2018 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
2022 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
2023 * @dev: class device that is converted into a Scsi_host.
2024 * @attr: device attribute, not used.
2025 * @buf: containing one of the strings "online", "offline", "warm" or "error".
2026 * @count: unused variable.
2029 * -EACCES if enable hba reset not enabled
2030 * -EINVAL if the buffer does not contain a valid string (see above)
2031 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
2032 * buf length greater than zero indicates success
2035 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
2036 const char *buf, size_t count)
2038 struct Scsi_Host *shost = class_to_shost(dev);
2039 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2040 struct lpfc_hba *phba = vport->phba;
2041 struct completion online_compl;
2042 char *board_mode_str = NULL;
2046 if (!phba->cfg_enable_hba_reset) {
2048 goto board_mode_out;
2051 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2052 "3050 lpfc_board_mode set to %s\n", buf);
2054 init_completion(&online_compl);
2056 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
2057 rc = lpfc_workq_post_event(phba, &status, &online_compl,
2061 goto board_mode_out;
2063 wait_for_completion(&online_compl);
2066 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
2067 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2068 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
2069 if (phba->sli_rev == LPFC_SLI_REV4)
2072 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
2073 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
2074 if (phba->sli_rev == LPFC_SLI_REV4)
2077 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
2078 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
2079 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
2080 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
2081 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
2082 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
2083 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
2084 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
2086 status = lpfc_reset_pci_bus(phba);
2087 else if (strncmp(buf, "heartbeat", sizeof("heartbeat") - 1) == 0)
2088 lpfc_issue_hb_tmo(phba);
2089 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
2090 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
2098 board_mode_str = strchr(buf, '\n');
2100 *board_mode_str = '\0';
2101 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2102 "3097 Failed \"%s\", status(%d), "
2104 buf, status, phba->pport->fc_flag);
2110 * lpfc_get_hba_info - Return various bits of informaton about the adapter
2111 * @phba: pointer to the adapter structure.
2112 * @mxri: max xri count.
2113 * @axri: available xri count.
2114 * @mrpi: max rpi count.
2115 * @arpi: available rpi count.
2116 * @mvpi: max vpi count.
2117 * @avpi: available vpi count.
2120 * If an integer pointer for an count is not null then the value for the
2121 * count is returned.
2128 lpfc_get_hba_info(struct lpfc_hba *phba,
2129 uint32_t *mxri, uint32_t *axri,
2130 uint32_t *mrpi, uint32_t *arpi,
2131 uint32_t *mvpi, uint32_t *avpi)
2133 LPFC_MBOXQ_t *pmboxq;
2136 struct lpfc_sli4_hba *sli4_hba;
2137 struct lpfc_max_cfg_param *max_cfg_param;
2138 u16 rsrc_ext_cnt, rsrc_ext_size, max_vpi;
2141 * prevent udev from issuing mailbox commands until the port is
2144 if (phba->link_state < LPFC_LINK_DOWN ||
2145 !phba->mbox_mem_pool ||
2146 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
2149 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
2152 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2155 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2157 pmb = &pmboxq->u.mb;
2158 pmb->mbxCommand = MBX_READ_CONFIG;
2159 pmb->mbxOwner = OWN_HOST;
2160 pmboxq->ctx_buf = NULL;
2162 if (test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))
2163 rc = MBX_NOT_FINISHED;
2165 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2167 if (rc != MBX_SUCCESS) {
2168 if (rc != MBX_TIMEOUT)
2169 mempool_free(pmboxq, phba->mbox_mem_pool);
2173 if (phba->sli_rev == LPFC_SLI_REV4) {
2174 sli4_hba = &phba->sli4_hba;
2175 max_cfg_param = &sli4_hba->max_cfg_param;
2177 /* Normally, extents are not used */
2178 if (!phba->sli4_hba.extents_in_use) {
2180 *mrpi = max_cfg_param->max_rpi;
2182 *mxri = max_cfg_param->max_xri;
2184 max_vpi = max_cfg_param->max_vpi;
2186 /* Limit the max we support */
2187 if (max_vpi > LPFC_MAX_VPI)
2188 max_vpi = LPFC_MAX_VPI;
2191 } else { /* Extents in use */
2193 if (lpfc_sli4_get_avail_extnt_rsrc(phba,
2194 LPFC_RSC_TYPE_FCOE_RPI,
2201 *mrpi = rsrc_ext_cnt * rsrc_ext_size;
2205 if (lpfc_sli4_get_avail_extnt_rsrc(phba,
2206 LPFC_RSC_TYPE_FCOE_XRI,
2213 *mxri = rsrc_ext_cnt * rsrc_ext_size;
2217 if (lpfc_sli4_get_avail_extnt_rsrc(phba,
2218 LPFC_RSC_TYPE_FCOE_VPI,
2225 max_vpi = rsrc_ext_cnt * rsrc_ext_size;
2227 /* Limit the max we support */
2228 if (max_vpi > LPFC_MAX_VPI)
2229 max_vpi = LPFC_MAX_VPI;
2235 *mrpi = pmb->un.varRdConfig.max_rpi;
2237 *arpi = pmb->un.varRdConfig.avail_rpi;
2239 *mxri = pmb->un.varRdConfig.max_xri;
2241 *axri = pmb->un.varRdConfig.avail_xri;
2243 *mvpi = pmb->un.varRdConfig.max_vpi;
2245 /* avail_vpi is only valid if link is up and ready */
2246 if (phba->link_state == LPFC_HBA_READY)
2247 *avpi = pmb->un.varRdConfig.avail_vpi;
2249 *avpi = pmb->un.varRdConfig.max_vpi;
2257 mempool_free(pmboxq, phba->mbox_mem_pool);
2262 * lpfc_max_rpi_show - Return maximum rpi
2263 * @dev: class device that is converted into a Scsi_host.
2264 * @attr: device attribute, not used.
2265 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
2268 * Calls lpfc_get_hba_info() asking for just the mrpi count.
2269 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2270 * to "Unknown" and the buffer length is returned, therefore the caller
2271 * must check for "Unknown" in the buffer to detect a failure.
2273 * Returns: size of formatted string.
2276 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
2279 struct Scsi_Host *shost = class_to_shost(dev);
2280 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2281 struct lpfc_hba *phba = vport->phba;
2284 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
2285 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2286 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2290 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
2291 * @dev: class device that is converted into a Scsi_host.
2292 * @attr: device attribute, not used.
2293 * @buf: containing the used rpi count in decimal or "Unknown".
2296 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
2297 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2298 * to "Unknown" and the buffer length is returned, therefore the caller
2299 * must check for "Unknown" in the buffer to detect a failure.
2301 * Returns: size of formatted string.
2304 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
2307 struct Scsi_Host *shost = class_to_shost(dev);
2308 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2309 struct lpfc_hba *phba = vport->phba;
2310 struct lpfc_sli4_hba *sli4_hba;
2311 struct lpfc_max_cfg_param *max_cfg_param;
2312 u32 cnt = 0, acnt = 0;
2314 if (phba->sli_rev == LPFC_SLI_REV4) {
2315 sli4_hba = &phba->sli4_hba;
2316 max_cfg_param = &sli4_hba->max_cfg_param;
2317 return scnprintf(buf, PAGE_SIZE, "%d\n",
2318 max_cfg_param->rpi_used);
2320 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
2321 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2323 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2327 * lpfc_max_xri_show - Return maximum xri
2328 * @dev: class device that is converted into a Scsi_host.
2329 * @attr: device attribute, not used.
2330 * @buf: on return contains the maximum xri count in decimal or "Unknown".
2333 * Calls lpfc_get_hba_info() asking for just the mrpi count.
2334 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2335 * to "Unknown" and the buffer length is returned, therefore the caller
2336 * must check for "Unknown" in the buffer to detect a failure.
2338 * Returns: size of formatted string.
2341 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
2344 struct Scsi_Host *shost = class_to_shost(dev);
2345 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2346 struct lpfc_hba *phba = vport->phba;
2349 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2350 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2351 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2355 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2356 * @dev: class device that is converted into a Scsi_host.
2357 * @attr: device attribute, not used.
2358 * @buf: on return contains the used xri count in decimal or "Unknown".
2361 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2362 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2363 * to "Unknown" and the buffer length is returned, therefore the caller
2364 * must check for "Unknown" in the buffer to detect a failure.
2366 * Returns: size of formatted string.
2369 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2372 struct Scsi_Host *shost = class_to_shost(dev);
2373 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2374 struct lpfc_hba *phba = vport->phba;
2375 struct lpfc_sli4_hba *sli4_hba;
2376 struct lpfc_max_cfg_param *max_cfg_param;
2377 u32 cnt = 0, acnt = 0;
2379 if (phba->sli_rev == LPFC_SLI_REV4) {
2380 sli4_hba = &phba->sli4_hba;
2381 max_cfg_param = &sli4_hba->max_cfg_param;
2382 return scnprintf(buf, PAGE_SIZE, "%d\n",
2383 max_cfg_param->xri_used);
2385 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2386 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2388 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2392 * lpfc_max_vpi_show - Return maximum vpi
2393 * @dev: class device that is converted into a Scsi_host.
2394 * @attr: device attribute, not used.
2395 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2398 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2399 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2400 * to "Unknown" and the buffer length is returned, therefore the caller
2401 * must check for "Unknown" in the buffer to detect a failure.
2403 * Returns: size of formatted string.
2406 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2409 struct Scsi_Host *shost = class_to_shost(dev);
2410 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2411 struct lpfc_hba *phba = vport->phba;
2414 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2415 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2416 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2420 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2421 * @dev: class device that is converted into a Scsi_host.
2422 * @attr: device attribute, not used.
2423 * @buf: on return contains the used vpi count in decimal or "Unknown".
2426 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2427 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2428 * to "Unknown" and the buffer length is returned, therefore the caller
2429 * must check for "Unknown" in the buffer to detect a failure.
2431 * Returns: size of formatted string.
2434 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2437 struct Scsi_Host *shost = class_to_shost(dev);
2438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2439 struct lpfc_hba *phba = vport->phba;
2440 struct lpfc_sli4_hba *sli4_hba;
2441 struct lpfc_max_cfg_param *max_cfg_param;
2442 u32 cnt = 0, acnt = 0;
2444 if (phba->sli_rev == LPFC_SLI_REV4) {
2445 sli4_hba = &phba->sli4_hba;
2446 max_cfg_param = &sli4_hba->max_cfg_param;
2447 return scnprintf(buf, PAGE_SIZE, "%d\n",
2448 max_cfg_param->vpi_used);
2450 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2451 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2453 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2457 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2458 * @dev: class device that is converted into a Scsi_host.
2459 * @attr: device attribute, not used.
2460 * @buf: text that must be interpreted to determine if npiv is supported.
2463 * Buffer will contain text indicating npiv is not suppoerted on the port,
2464 * the port is an NPIV physical port, or it is an npiv virtual port with
2465 * the id of the vport.
2467 * Returns: size of formatted string.
2470 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2473 struct Scsi_Host *shost = class_to_shost(dev);
2474 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2475 struct lpfc_hba *phba = vport->phba;
2477 if (!(phba->max_vpi))
2478 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2479 if (vport->port_type == LPFC_PHYSICAL_PORT)
2480 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2481 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2485 * lpfc_poll_show - Return text about poll support for the adapter
2486 * @dev: class device that is converted into a Scsi_host.
2487 * @attr: device attribute, not used.
2488 * @buf: on return contains the cfg_poll in hex.
2491 * cfg_poll should be a lpfc_polling_flags type.
2493 * Returns: size of formatted string.
2496 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2499 struct Scsi_Host *shost = class_to_shost(dev);
2500 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2501 struct lpfc_hba *phba = vport->phba;
2503 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2507 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2508 * @dev: class device that is converted into a Scsi_host.
2509 * @attr: device attribute, not used.
2510 * @buf: one or more lpfc_polling_flags values.
2514 * buf contents converted to integer and checked for a valid value.
2517 * -EINVAL if the buffer connot be converted or is out of range
2518 * length of the buf on success
2521 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2522 const char *buf, size_t count)
2524 struct Scsi_Host *shost = class_to_shost(dev);
2525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2526 struct lpfc_hba *phba = vport->phba;
2531 if (!isdigit(buf[0]))
2534 if (sscanf(buf, "%i", &val) != 1)
2537 if ((val & 0x3) != val)
2540 if (phba->sli_rev == LPFC_SLI_REV4)
2543 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2544 "3051 lpfc_poll changed from %d to %d\n",
2545 phba->cfg_poll, val);
2547 spin_lock_irq(&phba->hbalock);
2549 old_val = phba->cfg_poll;
2551 if (val & ENABLE_FCP_RING_POLLING) {
2552 if ((val & DISABLE_FCP_RING_INT) &&
2553 !(old_val & DISABLE_FCP_RING_INT)) {
2554 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2555 spin_unlock_irq(&phba->hbalock);
2558 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2559 writel(creg_val, phba->HCregaddr);
2560 readl(phba->HCregaddr); /* flush */
2562 lpfc_poll_start_timer(phba);
2564 } else if (val != 0x0) {
2565 spin_unlock_irq(&phba->hbalock);
2569 if (!(val & DISABLE_FCP_RING_INT) &&
2570 (old_val & DISABLE_FCP_RING_INT))
2572 spin_unlock_irq(&phba->hbalock);
2573 del_timer(&phba->fcp_poll_timer);
2574 spin_lock_irq(&phba->hbalock);
2575 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2576 spin_unlock_irq(&phba->hbalock);
2579 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2580 writel(creg_val, phba->HCregaddr);
2581 readl(phba->HCregaddr); /* flush */
2584 phba->cfg_poll = val;
2586 spin_unlock_irq(&phba->hbalock);
2592 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2593 * @dev: class converted to a Scsi_host structure.
2594 * @attr: device attribute, not used.
2595 * @buf: on return contains the formatted support level.
2598 * Returns the maximum number of virtual functions a physical function can
2599 * support, 0 will be returned if called on virtual function.
2601 * Returns: size of formatted string.
2604 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2605 struct device_attribute *attr,
2608 struct Scsi_Host *shost = class_to_shost(dev);
2609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2610 struct lpfc_hba *phba = vport->phba;
2611 uint16_t max_nr_virtfn;
2613 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2614 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2618 * lpfc_enable_bbcr_set: Sets an attribute value.
2619 * @phba: pointer to the adapter structure.
2620 * @val: integer attribute value.
2623 * Validates the min and max values then sets the
2624 * adapter config field if in the valid range. prints error message
2625 * and does not set the parameter if invalid.
2629 * -EINVAL if val is invalid
2632 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2634 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2635 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2636 "3068 lpfc_enable_bbcr changed from %d to "
2637 "%d\n", phba->cfg_enable_bbcr, val);
2638 phba->cfg_enable_bbcr = val;
2641 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2642 "0451 lpfc_enable_bbcr cannot set to %d, range is 0, "
2648 * lpfc_param_show - Return a cfg attribute value in decimal
2651 * Macro that given an attr e.g. hba_queue_depth expands
2652 * into a function with the name lpfc_hba_queue_depth_show.
2654 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2655 * @dev: class device that is converted into a Scsi_host.
2656 * @attr: device attribute, not used.
2657 * @buf: on return contains the attribute value in decimal.
2659 * Returns: size of formatted string.
2661 #define lpfc_param_show(attr) \
2663 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2666 struct Scsi_Host *shost = class_to_shost(dev);\
2667 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2668 struct lpfc_hba *phba = vport->phba;\
2669 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2674 * lpfc_param_hex_show - Return a cfg attribute value in hex
2677 * Macro that given an attr e.g. hba_queue_depth expands
2678 * into a function with the name lpfc_hba_queue_depth_show
2680 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2681 * @dev: class device that is converted into a Scsi_host.
2682 * @attr: device attribute, not used.
2683 * @buf: on return contains the attribute value in hexadecimal.
2685 * Returns: size of formatted string.
2687 #define lpfc_param_hex_show(attr) \
2689 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2692 struct Scsi_Host *shost = class_to_shost(dev);\
2693 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2694 struct lpfc_hba *phba = vport->phba;\
2696 val = phba->cfg_##attr;\
2697 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2702 * lpfc_param_init - Initializes a cfg attribute
2705 * Macro that given an attr e.g. hba_queue_depth expands
2706 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2707 * takes a default argument, a minimum and maximum argument.
2709 * lpfc_##attr##_init: Initializes an attribute.
2710 * @phba: pointer to the adapter structure.
2711 * @val: integer attribute value.
2713 * Validates the min and max values then sets the adapter config field
2714 * accordingly, or uses the default if out of range and prints an error message.
2718 * -EINVAL if default used
2720 #define lpfc_param_init(attr, default, minval, maxval) \
2722 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2724 if (lpfc_rangecheck(val, minval, maxval)) {\
2725 phba->cfg_##attr = val;\
2728 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2729 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2730 "allowed range is ["#minval", "#maxval"]\n", val); \
2731 phba->cfg_##attr = default;\
2736 * lpfc_param_set - Set a cfg attribute value
2739 * Macro that given an attr e.g. hba_queue_depth expands
2740 * into a function with the name lpfc_hba_queue_depth_set
2742 * lpfc_##attr##_set: Sets an attribute value.
2743 * @phba: pointer to the adapter structure.
2744 * @val: integer attribute value.
2747 * Validates the min and max values then sets the
2748 * adapter config field if in the valid range. prints error message
2749 * and does not set the parameter if invalid.
2753 * -EINVAL if val is invalid
2755 #define lpfc_param_set(attr, default, minval, maxval) \
2757 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2759 if (lpfc_rangecheck(val, minval, maxval)) {\
2760 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2761 "3052 lpfc_" #attr " changed from %d to %d\n", \
2762 phba->cfg_##attr, val); \
2763 phba->cfg_##attr = val;\
2766 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2767 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2768 "allowed range is ["#minval", "#maxval"]\n", val); \
2773 * lpfc_param_store - Set a vport attribute value
2776 * Macro that given an attr e.g. hba_queue_depth expands
2777 * into a function with the name lpfc_hba_queue_depth_store.
2779 * lpfc_##attr##_store: Set an sttribute value.
2780 * @dev: class device that is converted into a Scsi_host.
2781 * @attr: device attribute, not used.
2782 * @buf: contains the attribute value in ascii.
2786 * Convert the ascii text number to an integer, then
2787 * use the lpfc_##attr##_set function to set the value.
2790 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2791 * length of buffer upon success.
2793 #define lpfc_param_store(attr) \
2795 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2796 const char *buf, size_t count) \
2798 struct Scsi_Host *shost = class_to_shost(dev);\
2799 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2800 struct lpfc_hba *phba = vport->phba;\
2802 if (!isdigit(buf[0]))\
2804 if (sscanf(buf, "%i", &val) != 1)\
2806 if (lpfc_##attr##_set(phba, val) == 0) \
2807 return strlen(buf);\
2813 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2816 * Macro that given an attr e.g. hba_queue_depth expands
2817 * into a function with the name lpfc_hba_queue_depth_show
2819 * lpfc_##attr##_show: prints the attribute value in decimal.
2820 * @dev: class device that is converted into a Scsi_host.
2821 * @attr: device attribute, not used.
2822 * @buf: on return contains the attribute value in decimal.
2824 * Returns: length of formatted string.
2826 #define lpfc_vport_param_show(attr) \
2828 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2831 struct Scsi_Host *shost = class_to_shost(dev);\
2832 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2833 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2837 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2840 * Macro that given an attr e.g.
2841 * hba_queue_depth expands into a function with the name
2842 * lpfc_hba_queue_depth_show
2844 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2845 * @dev: class device that is converted into a Scsi_host.
2846 * @attr: device attribute, not used.
2847 * @buf: on return contains the attribute value in hexadecimal.
2849 * Returns: length of formatted string.
2851 #define lpfc_vport_param_hex_show(attr) \
2853 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2856 struct Scsi_Host *shost = class_to_shost(dev);\
2857 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2858 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2862 * lpfc_vport_param_init - Initialize a vport cfg attribute
2865 * Macro that given an attr e.g. hba_queue_depth expands
2866 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2867 * takes a default argument, a minimum and maximum argument.
2869 * lpfc_##attr##_init: validates the min and max values then sets the
2870 * adapter config field accordingly, or uses the default if out of range
2871 * and prints an error message.
2872 * @phba: pointer to the adapter structure.
2873 * @val: integer attribute value.
2877 * -EINVAL if default used
2879 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2881 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2883 if (lpfc_rangecheck(val, minval, maxval)) {\
2884 vport->cfg_##attr = val;\
2887 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2888 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2889 "allowed range is ["#minval", "#maxval"]\n", val); \
2890 vport->cfg_##attr = default;\
2895 * lpfc_vport_param_set - Set a vport cfg attribute
2898 * Macro that given an attr e.g. hba_queue_depth expands
2899 * into a function with the name lpfc_hba_queue_depth_set
2901 * lpfc_##attr##_set: validates the min and max values then sets the
2902 * adapter config field if in the valid range. prints error message
2903 * and does not set the parameter if invalid.
2904 * @phba: pointer to the adapter structure.
2905 * @val: integer attribute value.
2909 * -EINVAL if val is invalid
2911 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2913 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2915 if (lpfc_rangecheck(val, minval, maxval)) {\
2916 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2917 "3053 lpfc_" #attr \
2918 " changed from %d (x%x) to %d (x%x)\n", \
2919 vport->cfg_##attr, vport->cfg_##attr, \
2921 vport->cfg_##attr = val;\
2924 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2925 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2926 "allowed range is ["#minval", "#maxval"]\n", val); \
2931 * lpfc_vport_param_store - Set a vport attribute
2934 * Macro that given an attr e.g. hba_queue_depth
2935 * expands into a function with the name lpfc_hba_queue_depth_store
2937 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2938 * use the lpfc_##attr##_set function to set the value.
2939 * @cdev: class device that is converted into a Scsi_host.
2940 * @buf: contains the attribute value in decimal.
2944 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2945 * length of buffer upon success.
2947 #define lpfc_vport_param_store(attr) \
2949 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2950 const char *buf, size_t count) \
2952 struct Scsi_Host *shost = class_to_shost(dev);\
2953 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2955 if (!isdigit(buf[0]))\
2957 if (sscanf(buf, "%i", &val) != 1)\
2959 if (lpfc_##attr##_set(vport, val) == 0) \
2960 return strlen(buf);\
2966 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2967 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2968 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2969 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2970 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2971 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2972 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2973 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2974 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2975 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2976 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2977 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2978 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2979 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2980 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2981 lpfc_link_state_store);
2982 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2983 lpfc_option_rom_version_show, NULL);
2984 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2985 lpfc_num_discovered_ports_show, NULL);
2986 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2987 static DEVICE_ATTR_RO(lpfc_drvr_version);
2988 static DEVICE_ATTR_RO(lpfc_enable_fip);
2989 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2990 lpfc_board_mode_show, lpfc_board_mode_store);
2991 static DEVICE_ATTR_RO(lpfc_xcvr_data);
2992 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2993 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2994 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2995 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2996 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2997 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2998 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2999 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
3000 static DEVICE_ATTR_RO(lpfc_temp_sensor);
3001 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
3002 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
3003 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
3005 static DEVICE_ATTR(cmf_info, 0444, lpfc_cmf_info_show, NULL);
3009 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
3011 * @cnt: Length of string.
3012 * @wwn: Array to receive converted wwn value.
3015 * -EINVAL if the buffer does not contain a valid wwn
3019 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
3023 /* Count may include a LF at end of string */
3024 if (buf[cnt-1] == '\n')
3027 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
3028 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
3031 memset(wwn, 0, WWN_SZ);
3033 /* Validate and store the new name */
3034 for (i = 0, j = 0; i < 16; i++) {
3035 if ((*buf >= 'a') && (*buf <= 'f'))
3036 j = ((j << 4) | ((*buf++ - 'a') + 10));
3037 else if ((*buf >= 'A') && (*buf <= 'F'))
3038 j = ((j << 4) | ((*buf++ - 'A') + 10));
3039 else if ((*buf >= '0') && (*buf <= '9'))
3040 j = ((j << 4) | (*buf++ - '0'));
3044 wwn[i/2] = j & 0xff;
3053 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
3054 * Optimized Access Storage (OAS) operations.
3055 * @dev: class device that is converted into a Scsi_host.
3056 * @attr: device attribute, not used.
3057 * @buf: buffer for passing information.
3063 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
3066 struct Scsi_Host *shost = class_to_shost(dev);
3067 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3069 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3070 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
3074 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
3075 * Optimized Access Storage (OAS) operations.
3076 * @dev: class device that is converted into a Scsi_host.
3077 * @attr: device attribute, not used.
3078 * @buf: buffer for passing information.
3079 * @count: Size of the data buffer.
3082 * -EINVAL count is invalid, invalid wwpn byte invalid
3083 * -EPERM oas is not supported by hba
3084 * value of count on success
3087 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
3088 const char *buf, size_t count)
3090 struct Scsi_Host *shost = class_to_shost(dev);
3091 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3092 unsigned int cnt = count;
3093 uint8_t wwpn[WWN_SZ];
3099 /* count may include a LF at end of string */
3100 if (buf[cnt-1] == '\n')
3103 rc = lpfc_wwn_set(buf, cnt, wwpn);
3107 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3108 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3109 if (wwn_to_u64(wwpn) == 0)
3110 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
3112 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
3113 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3114 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3117 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
3118 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
3121 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
3122 * Optimized Access Storage (OAS) operations.
3123 * @dev: class device that is converted into a Scsi_host.
3124 * @attr: device attribute, not used.
3125 * @buf: buffer for passing information.
3131 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3134 struct Scsi_Host *shost = class_to_shost(dev);
3135 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3137 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3141 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3142 * Optimized Access Storage (OAS) operations.
3143 * @dev: class device that is converted into a Scsi_host.
3144 * @attr: device attribute, not used.
3145 * @buf: buffer for passing information.
3146 * @count: Size of the data buffer.
3149 * -EINVAL count is invalid, invalid wwpn byte invalid
3150 * -EPERM oas is not supported by hba
3151 * value of count on success
3154 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3155 const char *buf, size_t count)
3157 struct Scsi_Host *shost = class_to_shost(dev);
3158 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3159 unsigned int cnt = count;
3166 /* count may include a LF at end of string */
3167 if (buf[cnt-1] == '\n')
3170 ret = kstrtoul(buf, 0, &val);
3171 if (ret || (val > 0x7f))
3175 phba->cfg_oas_priority = (uint8_t)val;
3177 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3180 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3181 lpfc_oas_priority_show, lpfc_oas_priority_store);
3184 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3185 * for Optimized Access Storage (OAS) operations.
3186 * @dev: class device that is converted into a Scsi_host.
3187 * @attr: device attribute, not used.
3188 * @buf: buffer for passing information.
3191 * value of count on success
3194 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3197 struct Scsi_Host *shost = class_to_shost(dev);
3198 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3200 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3201 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3205 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3206 * for Optimized Access Storage (OAS) operations.
3207 * @dev: class device that is converted into a Scsi_host.
3208 * @attr: device attribute, not used.
3209 * @buf: buffer for passing information.
3210 * @count: Size of the data buffer.
3213 * -EINVAL count is invalid, invalid wwpn byte invalid
3214 * -EPERM oas is not supported by hba
3215 * value of count on success
3218 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3219 const char *buf, size_t count)
3221 struct Scsi_Host *shost = class_to_shost(dev);
3222 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3223 unsigned int cnt = count;
3224 uint8_t wwpn[WWN_SZ];
3230 /* count may include a LF at end of string */
3231 if (buf[cnt-1] == '\n')
3234 rc = lpfc_wwn_set(buf, cnt, wwpn);
3238 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3239 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3240 if (wwn_to_u64(wwpn) == 0)
3241 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3243 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3244 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3245 if (phba->cfg_oas_priority == 0)
3246 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3247 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3250 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3251 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3254 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3255 * of whether luns will be enabled or disabled
3256 * for Optimized Access Storage (OAS) operations.
3257 * @dev: class device that is converted into a Scsi_host.
3258 * @attr: device attribute, not used.
3259 * @buf: buffer for passing information.
3262 * size of formatted string.
3265 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3268 struct Scsi_Host *shost = class_to_shost(dev);
3269 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3271 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3275 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3276 * of whether luns will be enabled or disabled
3277 * for Optimized Access Storage (OAS) operations.
3278 * @dev: class device that is converted into a Scsi_host.
3279 * @attr: device attribute, not used.
3280 * @buf: buffer for passing information.
3281 * @count: Size of the data buffer.
3284 * -EINVAL count is invalid, invalid wwpn byte invalid
3285 * -EPERM oas is not supported by hba
3286 * value of count on success
3289 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3290 const char *buf, size_t count)
3292 struct Scsi_Host *shost = class_to_shost(dev);
3293 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3299 if (!isdigit(buf[0]))
3302 if (sscanf(buf, "%i", &val) != 1)
3305 if ((val != 0) && (val != 1))
3308 phba->cfg_oas_lun_state = val;
3311 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3312 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3315 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3316 * Storage (OAS) lun returned by the
3317 * lpfc_oas_lun_show function.
3318 * @dev: class device that is converted into a Scsi_host.
3319 * @attr: device attribute, not used.
3320 * @buf: buffer for passing information.
3323 * size of formatted string.
3326 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3329 struct Scsi_Host *shost = class_to_shost(dev);
3330 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3332 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3335 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3337 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3338 lpfc_oas_lun_status_show, NULL);
3342 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3344 * @phba: lpfc_hba pointer.
3345 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3346 * @tgt_wwpn: wwpn of the target associated with the returned lun
3347 * @lun: the fc lun for setting oas state.
3348 * @oas_state: the oas state to be set to the lun.
3353 * -EPERM OAS is not enabled or not supported by this port.
3357 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3358 uint8_t tgt_wwpn[], uint64_t lun,
3359 uint32_t oas_state, uint8_t pri)
3368 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3369 (struct lpfc_name *)tgt_wwpn,
3373 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3374 (struct lpfc_name *)tgt_wwpn, lun, pri);
3381 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3382 * Access Storage (OAS) operations.
3383 * @phba: lpfc_hba pointer.
3384 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3385 * @tgt_wwpn: wwpn of the target associated with the returned lun
3386 * @lun_status: status of the lun returned lun
3387 * @lun_pri: priority of the lun returned lun
3389 * Returns the first or next lun enabled for OAS operations for the vport/target
3390 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3391 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3394 * lun that is OAS enabled for the vport/target
3395 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3398 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3399 uint8_t tgt_wwpn[], uint32_t *lun_status,
3404 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3405 return NOT_OAS_ENABLED_LUN;
3406 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3407 phba->sli4_hba.oas_next_vpt_wwpn,
3408 (struct lpfc_name *)
3409 phba->sli4_hba.oas_next_tgt_wwpn,
3410 &phba->sli4_hba.oas_next_lun,
3411 (struct lpfc_name *)vpt_wwpn,
3412 (struct lpfc_name *)tgt_wwpn,
3413 &found_lun, lun_status, lun_pri))
3416 return NOT_OAS_ENABLED_LUN;
3420 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3421 * @phba: lpfc_hba pointer.
3422 * @vpt_wwpn: vport wwpn by reference.
3423 * @tgt_wwpn: target wwpn by reference.
3424 * @lun: the fc lun for setting oas state.
3425 * @oas_state: the oas state to be set to the oas_lun.
3428 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3429 * a lun for OAS operations.
3433 * -ENOMEM: failed to enable an lun for OAS operations
3434 * -EPERM: OAS is not enabled
3437 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3438 uint8_t tgt_wwpn[], uint64_t lun,
3439 uint32_t oas_state, uint8_t pri)
3444 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3450 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3451 * @dev: class device that is converted into a Scsi_host.
3452 * @attr: device attribute, not used.
3453 * @buf: buffer for passing information.
3455 * This routine returns a lun enabled for OAS each time the function
3459 * SUCCESS: size of formatted string.
3460 * -EFAULT: target or vport wwpn was not set properly.
3461 * -EPERM: oas is not enabled.
3464 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3467 struct Scsi_Host *shost = class_to_shost(dev);
3468 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3476 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3477 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3480 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3481 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3484 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3485 phba->cfg_oas_tgt_wwpn,
3486 &phba->cfg_oas_lun_status,
3487 &phba->cfg_oas_priority);
3488 if (oas_lun != NOT_OAS_ENABLED_LUN)
3489 phba->cfg_oas_flags |= OAS_LUN_VALID;
3491 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3497 * lpfc_oas_lun_store - Sets the OAS state for lun
3498 * @dev: class device that is converted into a Scsi_host.
3499 * @attr: device attribute, not used.
3500 * @buf: buffer for passing information.
3501 * @count: size of the formatting string
3503 * This function sets the OAS state for lun. Before this function is called,
3504 * the vport wwpn, target wwpn, and oas state need to be set.
3507 * SUCCESS: size of formatted string.
3508 * -EFAULT: target or vport wwpn was not set properly.
3509 * -EPERM: oas is not enabled.
3510 * size of formatted string.
3513 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3514 const char *buf, size_t count)
3516 struct Scsi_Host *shost = class_to_shost(dev);
3517 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3525 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3528 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3531 if (!isdigit(buf[0]))
3534 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3537 pri = phba->cfg_oas_priority;
3539 pri = phba->cfg_XLanePriority;
3541 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3542 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3543 "priority 0x%x with oas state %d\n",
3544 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3545 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3546 pri, phba->cfg_oas_lun_state);
3548 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3549 phba->cfg_oas_tgt_wwpn, scsi_lun,
3550 phba->cfg_oas_lun_state, pri);
3556 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3557 lpfc_oas_lun_show, lpfc_oas_lun_store);
3559 int lpfc_enable_nvmet_cnt;
3560 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3561 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3562 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3563 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3564 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3566 static int lpfc_poll = 0;
3567 module_param(lpfc_poll, int, S_IRUGO);
3568 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3570 " 1 - poll with interrupts enabled"
3571 " 3 - poll and disable FCP ring interrupts");
3573 static DEVICE_ATTR_RW(lpfc_poll);
3575 int lpfc_no_hba_reset_cnt;
3576 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3577 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3578 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3579 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3581 LPFC_ATTR(sli_mode, 3, 3, 3,
3582 "SLI mode selector: 3 - select SLI-3");
3584 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3585 "Enable NPIV functionality");
3587 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3588 "FCF Fast failover=1 Priority failover=2");
3591 * lpfc_fcp_wait_abts_rsp: Modifies criteria for reporting completion of
3593 * The range is [0,1]. Default value is 0
3594 * 0, IO completes after ABTS issued (default).
3595 * 1, IO completes after receipt of ABTS response or timeout.
3597 LPFC_ATTR_R(fcp_wait_abts_rsp, 0, 0, 1, "Wait for FCP ABTS completion");
3600 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3601 # 0x0 = disabled, XRI/OXID use not tracked.
3602 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3603 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3605 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3606 "Enable RRQ functionality");
3609 # lpfc_suppress_link_up: Bring link up at initialization
3610 # 0x0 = bring link up (issue MBX_INIT_LINK)
3611 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3612 # 0x2 = never bring up link
3613 # Default value is 0.
3615 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3616 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3617 "Suppress Link Up at initialization");
3620 lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3622 struct Scsi_Host *shost = class_to_shost(dev);
3623 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3625 return scnprintf(buf, PAGE_SIZE, "%d\n",
3626 phba->sli4_hba.pc_sli4_params.pls);
3628 static DEVICE_ATTR(pls, 0444,
3629 lpfc_pls_show, NULL);
3632 lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3634 struct Scsi_Host *shost = class_to_shost(dev);
3635 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3637 return scnprintf(buf, PAGE_SIZE, "%d\n",
3638 test_bit(HBA_PERSISTENT_TOPO,
3639 &phba->hba_flag) ? 1 : 0);
3641 static DEVICE_ATTR(pt, 0444,
3642 lpfc_pt_show, NULL);
3645 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3653 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3655 struct Scsi_Host *shost = class_to_shost(dev);
3656 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3658 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3661 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3662 lpfc_iocb_hw_show, NULL);
3664 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3666 struct Scsi_Host *shost = class_to_shost(dev);
3667 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3668 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3670 return scnprintf(buf, PAGE_SIZE, "%d\n",
3671 pring ? pring->txq_max : 0);
3674 static DEVICE_ATTR(txq_hw, S_IRUGO,
3675 lpfc_txq_hw_show, NULL);
3677 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3680 struct Scsi_Host *shost = class_to_shost(dev);
3681 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3682 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3684 return scnprintf(buf, PAGE_SIZE, "%d\n",
3685 pring ? pring->txcmplq_max : 0);
3688 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3689 lpfc_txcmplq_hw_show, NULL);
3692 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3693 # until the timer expires. Value range is [0,255]. Default value is 30.
3695 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3696 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3697 module_param(lpfc_nodev_tmo, int, 0);
3698 MODULE_PARM_DESC(lpfc_nodev_tmo,
3699 "Seconds driver will hold I/O waiting "
3700 "for a device to come back");
3703 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3704 * @dev: class converted to a Scsi_host structure.
3705 * @attr: device attribute, not used.
3706 * @buf: on return contains the dev loss timeout in decimal.
3708 * Returns: size of formatted string.
3711 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3714 struct Scsi_Host *shost = class_to_shost(dev);
3715 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3717 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3721 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3722 * @vport: lpfc vport structure pointer.
3723 * @val: contains the nodev timeout value.
3726 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3727 * a kernel error message is printed and zero is returned.
3728 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3729 * Otherwise nodev tmo is set to the default value.
3732 * zero if already set or if val is in range
3733 * -EINVAL val out of range
3736 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3738 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3739 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3740 if (val != LPFC_DEF_DEVLOSS_TMO)
3741 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3742 "0407 Ignoring lpfc_nodev_tmo module "
3743 "parameter because lpfc_devloss_tmo "
3748 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3749 vport->cfg_nodev_tmo = val;
3750 vport->cfg_devloss_tmo = val;
3753 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3754 "0400 lpfc_nodev_tmo attribute cannot be set to"
3755 " %d, allowed range is [%d, %d]\n",
3756 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3757 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3762 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3763 * @vport: lpfc vport structure pointer.
3766 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3769 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3771 struct lpfc_nodelist *ndlp;
3772 unsigned long iflags;
3773 #if (IS_ENABLED(CONFIG_NVME_FC))
3774 struct lpfc_nvme_rport *rport;
3775 struct nvme_fc_remote_port *remoteport = NULL;
3778 spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
3779 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3781 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3782 #if (IS_ENABLED(CONFIG_NVME_FC))
3783 spin_lock(&ndlp->lock);
3784 rport = lpfc_ndlp_get_nrport(ndlp);
3786 remoteport = rport->remoteport;
3787 spin_unlock(&ndlp->lock);
3788 if (rport && remoteport)
3789 nvme_fc_set_remoteport_devloss(remoteport,
3790 vport->cfg_devloss_tmo);
3793 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
3797 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3798 * @vport: lpfc vport structure pointer.
3799 * @val: contains the tmo value.
3802 * If the devloss tmo is already set or the vport dev loss tmo has changed
3803 * then a kernel error message is printed and zero is returned.
3804 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3805 * Otherwise nodev tmo is set to the default value.
3808 * zero if already set or if val is in range
3809 * -EINVAL val out of range
3812 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3814 if (vport->dev_loss_tmo_changed ||
3815 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3816 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3817 "0401 Ignoring change to lpfc_nodev_tmo "
3818 "because lpfc_devloss_tmo is set.\n");
3821 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3822 vport->cfg_nodev_tmo = val;
3823 vport->cfg_devloss_tmo = val;
3825 * For compat: set the fc_host dev loss so new rports
3826 * will get the value.
3828 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3829 lpfc_update_rport_devloss_tmo(vport);
3832 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3833 "0403 lpfc_nodev_tmo attribute cannot be set to "
3834 "%d, allowed range is [%d, %d]\n",
3835 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3839 lpfc_vport_param_store(nodev_tmo)
3841 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3844 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3845 # disappear until the timer expires. Value range is [0,255]. Default
3848 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3849 MODULE_PARM_DESC(lpfc_devloss_tmo,
3850 "Seconds driver will hold I/O waiting "
3851 "for a device to come back");
3852 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3853 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3854 lpfc_vport_param_show(devloss_tmo)
3857 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3858 * @vport: lpfc vport structure pointer.
3859 * @val: contains the tmo value.
3862 * If val is in a valid range then set the vport nodev tmo,
3863 * devloss tmo, also set the vport dev loss tmo changed flag.
3864 * Else a kernel error message is printed.
3867 * zero if val is in range
3868 * -EINVAL val out of range
3871 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3873 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3874 vport->cfg_nodev_tmo = val;
3875 vport->cfg_devloss_tmo = val;
3876 vport->dev_loss_tmo_changed = 1;
3877 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3878 lpfc_update_rport_devloss_tmo(vport);
3882 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3883 "0404 lpfc_devloss_tmo attribute cannot be set to "
3884 "%d, allowed range is [%d, %d]\n",
3885 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3889 lpfc_vport_param_store(devloss_tmo)
3890 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3893 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3894 * lpfc_suppress_rsp = 0 Disable
3895 * lpfc_suppress_rsp = 1 Enable (default)
3898 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3899 "Enable suppress rsp feature is firmware supports it");
3902 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3903 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3904 * lpfc_nvmet_mrq = 1 use a single RQ pair
3905 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3908 LPFC_ATTR_R(nvmet_mrq,
3909 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3910 "Specify number of RQ pairs for processing NVMET cmds");
3913 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3914 * to each NVMET RQ. Range 64 to 2048, default is 512.
3916 LPFC_ATTR_R(nvmet_mrq_post,
3917 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3918 LPFC_NVMET_RQE_DEF_COUNT,
3919 "Specify number of RQ buffers to initially post");
3922 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3923 * Supported Values: 1 - register just FCP
3924 * 3 - register both FCP and NVME
3925 * Supported values are [1,3]. Default value is 3
3927 LPFC_ATTR_R(enable_fc4_type, LPFC_DEF_ENBL_FC4_TYPE,
3928 LPFC_ENABLE_FCP, LPFC_MAX_ENBL_FC4_TYPE,
3929 "Enable FC4 Protocol support - FCP / NVME");
3932 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3933 # deluged with LOTS of information.
3934 # You can set a bit mask to record specific types of verbose messages:
3935 # See lpfc_logmsh.h for definitions.
3937 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3938 "Verbose logging bit-mask");
3941 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3942 # objects that have been registered with the nameserver after login.
3944 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3945 "Deregister nameserver objects before LOGO");
3948 # lun_queue_depth: This parameter is used to limit the number of outstanding
3949 # commands per FCP LUN.
3951 LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
3952 "Max number of FCP commands we can queue to a specific LUN");
3955 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3956 # commands per target port. Value range is [10,65535]. Default value is 65535.
3958 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3959 module_param(lpfc_tgt_queue_depth, uint, 0444);
3960 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3961 lpfc_vport_param_show(tgt_queue_depth);
3962 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3963 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3966 * lpfc_tgt_queue_depth_set: Sets an attribute value.
3967 * @vport: lpfc vport structure pointer.
3968 * @val: integer attribute value.
3970 * Description: Sets the parameter to the new value.
3974 * -EINVAL if val is invalid
3977 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3979 struct lpfc_nodelist *ndlp;
3980 unsigned long iflags;
3982 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3985 if (val == vport->cfg_tgt_queue_depth)
3988 vport->cfg_tgt_queue_depth = val;
3990 /* Next loop thru nodelist and change cmd_qdepth */
3991 spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
3992 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3993 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3994 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
3998 lpfc_vport_param_store(tgt_queue_depth);
3999 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
4002 # hba_queue_depth: This parameter is used to limit the number of outstanding
4003 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
4004 # value is greater than the maximum number of exchanges supported by the HBA,
4005 # then maximum number of exchanges supported by the HBA is used to determine
4006 # the hba_queue_depth.
4008 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
4009 "Max number of FCP commands we can queue to a lpfc HBA");
4012 # peer_port_login: This parameter allows/prevents logins
4013 # between peer ports hosted on the same physical port.
4014 # When this parameter is set 0 peer ports of same physical port
4015 # are not allowed to login to each other.
4016 # When this parameter is set 1 peer ports of same physical port
4017 # are allowed to login to each other.
4018 # Default value of this parameter is 0.
4020 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
4021 "Allow peer ports on the same physical port to login to each "
4025 # restrict_login: This parameter allows/prevents logins
4026 # between Virtual Ports and remote initiators.
4027 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
4028 # other initiators and will attempt to PLOGI all remote ports.
4029 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
4030 # remote ports and will not attempt to PLOGI to other initiators.
4031 # This parameter does not restrict to the physical port.
4032 # This parameter does not restrict logins to Fabric resident remote ports.
4033 # Default value of this parameter is 1.
4035 static int lpfc_restrict_login = 1;
4036 module_param(lpfc_restrict_login, int, S_IRUGO);
4037 MODULE_PARM_DESC(lpfc_restrict_login,
4038 "Restrict virtual ports login to remote initiators.");
4039 lpfc_vport_param_show(restrict_login);
4042 * lpfc_restrict_login_init - Set the vport restrict login flag
4043 * @vport: lpfc vport structure pointer.
4044 * @val: contains the restrict login value.
4047 * If val is not in a valid range then log a kernel error message and set
4048 * the vport restrict login to one.
4049 * If the port type is physical clear the restrict login flag and return.
4050 * Else set the restrict login flag to val.
4053 * zero if val is in range
4054 * -EINVAL val out of range
4057 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
4059 if (val < 0 || val > 1) {
4060 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4061 "0422 lpfc_restrict_login attribute cannot "
4062 "be set to %d, allowed range is [0, 1]\n",
4064 vport->cfg_restrict_login = 1;
4067 if (vport->port_type == LPFC_PHYSICAL_PORT) {
4068 vport->cfg_restrict_login = 0;
4071 vport->cfg_restrict_login = val;
4076 * lpfc_restrict_login_set - Set the vport restrict login flag
4077 * @vport: lpfc vport structure pointer.
4078 * @val: contains the restrict login value.
4081 * If val is not in a valid range then log a kernel error message and set
4082 * the vport restrict login to one.
4083 * If the port type is physical and the val is not zero log a kernel
4084 * error message, clear the restrict login flag and return zero.
4085 * Else set the restrict login flag to val.
4088 * zero if val is in range
4089 * -EINVAL val out of range
4092 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
4094 if (val < 0 || val > 1) {
4095 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4096 "0425 lpfc_restrict_login attribute cannot "
4097 "be set to %d, allowed range is [0, 1]\n",
4099 vport->cfg_restrict_login = 1;
4102 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
4103 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4104 "0468 lpfc_restrict_login must be 0 for "
4105 "Physical ports.\n");
4106 vport->cfg_restrict_login = 0;
4109 vport->cfg_restrict_login = val;
4112 lpfc_vport_param_store(restrict_login);
4113 static DEVICE_ATTR_RW(lpfc_restrict_login);
4116 # Some disk devices have a "select ID" or "select Target" capability.
4117 # From a protocol standpoint "select ID" usually means select the
4118 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
4119 # annex" which contains a table that maps a "select ID" (a number
4120 # between 0 and 7F) to an ALPA. By default, for compatibility with
4121 # older drivers, the lpfc driver scans this table from low ALPA to high
4124 # Turning on the scan-down variable (on = 1, off = 0) will
4125 # cause the lpfc driver to use an inverted table, effectively
4126 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
4128 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
4129 # and will not work across a fabric. Also this parameter will take
4130 # effect only in the case when ALPA map is not available.)
4132 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
4133 "Start scanning for devices from highest ALPA to lowest");
4136 # lpfc_topology: link topology for init link
4137 # 0x0 = attempt loop mode then point-to-point
4138 # 0x01 = internal loopback mode
4139 # 0x02 = attempt point-to-point mode only
4140 # 0x04 = attempt loop mode only
4141 # 0x06 = attempt point-to-point mode then loop
4142 # Set point-to-point mode if you want to run as an N_Port.
4143 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4144 # Default value is 0.
4146 LPFC_ATTR(topology, 0, 0, 6,
4147 "Select Fibre Channel topology");
4150 * lpfc_topology_store - Set the adapters topology field
4151 * @dev: class device that is converted into a scsi_host.
4152 * @attr:device attribute, not used.
4153 * @buf: buffer for passing information.
4154 * @count: size of the data buffer.
4157 * If val is in a valid range then set the adapter's topology field and
4158 * issue a lip; if the lip fails reset the topology to the old value.
4160 * If the value is not in range log a kernel error message and return an error.
4163 * zero if val is in range and lip okay
4164 * non-zero return value from lpfc_issue_lip()
4165 * -EINVAL val out of range
4168 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4169 const char *buf, size_t count)
4171 struct Scsi_Host *shost = class_to_shost(dev);
4172 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4173 struct lpfc_hba *phba = vport->phba;
4176 const char *val_buf = buf;
4179 u8 sli_family, if_type;
4181 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4183 val_buf = &buf[strlen("nolip ")];
4186 if (!isdigit(val_buf[0]))
4188 if (sscanf(val_buf, "%i", &val) != 1)
4191 if (val >= 0 && val <= 6) {
4192 prev_val = phba->cfg_topology;
4193 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4195 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4196 "3113 Loop mode not supported at speed %d\n",
4201 * The 'topology' is not a configurable parameter if :
4202 * - persistent topology enabled
4203 * - ASIC_GEN_NUM >= 0xC, with no private loop support
4205 sli_family = bf_get(lpfc_sli_intf_sli_family,
4206 &phba->sli4_hba.sli_intf);
4207 if_type = bf_get(lpfc_sli_intf_if_type,
4208 &phba->sli4_hba.sli_intf);
4209 if ((test_bit(HBA_PERSISTENT_TOPO, &phba->hba_flag) ||
4210 (!phba->sli4_hba.pc_sli4_params.pls &&
4211 (sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
4212 if_type == LPFC_SLI_INTF_IF_TYPE_6))) &&
4214 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4215 "3114 Loop mode not supported\n");
4218 phba->cfg_topology = val;
4222 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4223 "3054 lpfc_topology changed from %d to %d\n",
4225 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4226 phba->fc_topology_changed = 1;
4227 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4229 phba->cfg_topology = prev_val;
4234 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4235 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4236 "allowed range is [0, 6]\n",
4241 lpfc_param_show(topology)
4242 static DEVICE_ATTR_RW(lpfc_topology);
4245 * lpfc_static_vport_show: Read callback function for
4246 * lpfc_static_vport sysfs file.
4247 * @dev: Pointer to class device object.
4248 * @attr: device attribute structure.
4249 * @buf: Data buffer.
4251 * This function is the read call back function for
4252 * lpfc_static_vport sysfs file. The lpfc_static_vport
4253 * sysfs file report the mageability of the vport.
4256 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4259 struct Scsi_Host *shost = class_to_shost(dev);
4260 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4261 if (vport->vport_flag & STATIC_VPORT)
4262 sprintf(buf, "1\n");
4264 sprintf(buf, "0\n");
4270 * Sysfs attribute to control the statistical data collection.
4272 static DEVICE_ATTR_RO(lpfc_static_vport);
4275 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4277 # Value range is [0,16]. Default value is 0.
4280 * lpfc_link_speed_store - Set the adapters link speed
4281 * @dev: Pointer to class device.
4283 * @buf: Data buffer.
4284 * @count: Size of the data buffer.
4287 * If val is in a valid range then set the adapter's link speed field and
4288 * issue a lip; if the lip fails reset the link speed to the old value.
4291 * If the value is not in range log a kernel error message and return an error.
4294 * zero if val is in range and lip okay.
4295 * non-zero return value from lpfc_issue_lip()
4296 * -EINVAL val out of range
4299 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4300 const char *buf, size_t count)
4302 struct Scsi_Host *shost = class_to_shost(dev);
4303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4304 struct lpfc_hba *phba = vport->phba;
4305 int val = LPFC_USER_LINK_SPEED_AUTO;
4307 const char *val_buf = buf;
4309 uint32_t prev_val, if_type;
4311 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4312 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4313 test_bit(HBA_FORCED_LINK_SPEED, &phba->hba_flag))
4316 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4318 val_buf = &buf[strlen("nolip ")];
4321 if (!isdigit(val_buf[0]))
4323 if (sscanf(val_buf, "%i", &val) != 1)
4326 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4327 "3055 lpfc_link_speed changed from %d to %d %s\n",
4328 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4330 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4331 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4332 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4333 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4334 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4335 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4336 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4337 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4338 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4339 "2879 lpfc_link_speed attribute cannot be set "
4340 "to %d. Speed is not supported by this port.\n",
4344 if (val >= LPFC_USER_LINK_SPEED_16G &&
4345 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4347 "3112 lpfc_link_speed attribute cannot be set "
4348 "to %d. Speed is not supported in loop mode.\n",
4354 case LPFC_USER_LINK_SPEED_AUTO:
4355 case LPFC_USER_LINK_SPEED_1G:
4356 case LPFC_USER_LINK_SPEED_2G:
4357 case LPFC_USER_LINK_SPEED_4G:
4358 case LPFC_USER_LINK_SPEED_8G:
4359 case LPFC_USER_LINK_SPEED_16G:
4360 case LPFC_USER_LINK_SPEED_32G:
4361 case LPFC_USER_LINK_SPEED_64G:
4362 prev_val = phba->cfg_link_speed;
4363 phba->cfg_link_speed = val;
4367 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4369 phba->cfg_link_speed = prev_val;
4377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4378 "0469 lpfc_link_speed attribute cannot be set to %d, "
4379 "allowed values are [%s]\n",
4380 val, LPFC_LINK_SPEED_STRING);
4385 static int lpfc_link_speed = 0;
4386 module_param(lpfc_link_speed, int, S_IRUGO);
4387 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4388 lpfc_param_show(link_speed)
4391 * lpfc_link_speed_init - Set the adapters link speed
4392 * @phba: lpfc_hba pointer.
4393 * @val: link speed value.
4396 * If val is in a valid range then set the adapter's link speed field.
4399 * If the value is not in range log a kernel error message, clear the link
4400 * speed and return an error.
4403 * zero if val saved.
4404 * -EINVAL val out of range
4407 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4409 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4410 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4411 "3111 lpfc_link_speed of %d cannot "
4412 "support loop mode, setting topology to default.\n",
4414 phba->cfg_topology = 0;
4418 case LPFC_USER_LINK_SPEED_AUTO:
4419 case LPFC_USER_LINK_SPEED_1G:
4420 case LPFC_USER_LINK_SPEED_2G:
4421 case LPFC_USER_LINK_SPEED_4G:
4422 case LPFC_USER_LINK_SPEED_8G:
4423 case LPFC_USER_LINK_SPEED_16G:
4424 case LPFC_USER_LINK_SPEED_32G:
4425 case LPFC_USER_LINK_SPEED_64G:
4426 phba->cfg_link_speed = val;
4429 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4430 "0405 lpfc_link_speed attribute cannot "
4431 "be set to %d, allowed values are "
4432 "["LPFC_LINK_SPEED_STRING"]\n", val);
4433 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4438 static DEVICE_ATTR_RW(lpfc_link_speed);
4441 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4442 # 1 = aer supported and enabled (default)
4443 # PCIe error reporting is always enabled by the PCI core, so this always
4446 # N.B. Parts of LPFC_ATTR open-coded since some of the underlying
4447 # infrastructure (phba->cfg_aer_support) is gone.
4449 static uint lpfc_aer_support = 1;
4450 module_param(lpfc_aer_support, uint, S_IRUGO);
4451 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
4453 lpfc_aer_support_show(struct device *dev, struct device_attribute *attr,
4456 return scnprintf(buf, PAGE_SIZE, "%d\n", lpfc_aer_support);
4460 * lpfc_aer_support_store - Set the adapter for aer support
4462 * @dev: class device that is converted into a Scsi_host.
4463 * @attr: device attribute, not used.
4464 * @buf: containing enable or disable aer flag.
4465 * @count: unused variable.
4468 * PCIe error reporting is enabled by the PCI core, so drivers don't need
4469 * to do anything. Retain this interface for backwards compatibility,
4473 * length of the buf on success
4474 * -EINVAL if val out of range
4477 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4478 const char *buf, size_t count)
4482 if (!isdigit(buf[0]))
4484 if (sscanf(buf, "%i", &val) != 1)
4487 dev_info_once(dev, "PCIe error reporting automatically enabled by the PCI core; sysfs write ignored\n");
4491 static DEVICE_ATTR_RW(lpfc_aer_support);
4494 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4495 * @dev: class device that is converted into a Scsi_host.
4496 * @attr: device attribute, not used.
4497 * @buf: containing flag 1 for aer cleanup state.
4498 * @count: unused variable.
4501 * If the @buf contains 1, invokes the kernel AER helper routine
4502 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
4503 * error status register.
4508 * -EINVAL if the buf does not contain 1
4509 * -EPERM if the OS cannot clear AER error status, i.e., when platform
4510 * firmware owns the AER Capability
4513 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4514 const char *buf, size_t count)
4516 struct Scsi_Host *shost = class_to_shost(dev);
4517 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4518 struct lpfc_hba *phba = vport->phba;
4521 if (!isdigit(buf[0]))
4523 if (sscanf(buf, "%i", &val) != 1)
4528 rc = pci_aer_clear_nonfatal_status(phba->pcidev);
4536 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4537 lpfc_aer_cleanup_state);
4540 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4542 * @dev: class device that is converted into a Scsi_host.
4543 * @attr: device attribute, not used.
4544 * @buf: containing the string the number of vfs to be enabled.
4545 * @count: unused variable.
4548 * When this api is called either through user sysfs, the driver shall
4549 * try to enable or disable SR-IOV virtual functions according to the
4552 * If zero virtual function has been enabled to the physical function,
4553 * the driver shall invoke the pci enable virtual function api trying
4554 * to enable the virtual functions. If the nr_vfn provided is greater
4555 * than the maximum supported, the maximum virtual function number will
4556 * be used for invoking the api; otherwise, the nr_vfn provided shall
4557 * be used for invoking the api. If the api call returned success, the
4558 * actual number of virtual functions enabled will be set to the driver
4559 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4560 * cfg_sriov_nr_virtfn remains zero.
4562 * If none-zero virtual functions have already been enabled to the
4563 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4564 * -EINVAL will be returned and the driver does nothing;
4566 * If the nr_vfn provided is zero and none-zero virtual functions have
4567 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4568 * disabling virtual function api shall be invoded to disable all the
4569 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4570 * zero. Otherwise, if zero virtual function has been enabled, do
4574 * length of the buf on success if val is in range the intended mode
4576 * -EINVAL if val out of range or intended mode is not supported.
4579 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4580 const char *buf, size_t count)
4582 struct Scsi_Host *shost = class_to_shost(dev);
4583 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4584 struct lpfc_hba *phba = vport->phba;
4585 struct pci_dev *pdev = phba->pcidev;
4586 int val = 0, rc = -EINVAL;
4588 /* Sanity check on user data */
4589 if (!isdigit(buf[0]))
4591 if (sscanf(buf, "%i", &val) != 1)
4596 /* Request disabling virtual functions */
4598 if (phba->cfg_sriov_nr_virtfn > 0) {
4599 pci_disable_sriov(pdev);
4600 phba->cfg_sriov_nr_virtfn = 0;
4605 /* Request enabling virtual functions */
4606 if (phba->cfg_sriov_nr_virtfn > 0) {
4607 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4608 "3018 There are %d virtual functions "
4609 "enabled on physical function.\n",
4610 phba->cfg_sriov_nr_virtfn);
4614 if (val <= LPFC_MAX_VFN_PER_PFN)
4615 phba->cfg_sriov_nr_virtfn = val;
4617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4618 "3019 Enabling %d virtual functions is not "
4623 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4625 phba->cfg_sriov_nr_virtfn = 0;
4633 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4634 "Enable PCIe device SR-IOV virtual fn");
4636 lpfc_param_show(sriov_nr_virtfn)
4637 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4640 * lpfc_request_firmware_upgrade_store - Request for Linux generic firmware upgrade
4642 * @dev: class device that is converted into a Scsi_host.
4643 * @attr: device attribute, not used.
4644 * @buf: containing the string the number of vfs to be enabled.
4645 * @count: unused variable.
4650 * length of the buf on success if val is in range the intended mode
4652 * -EINVAL if val out of range or intended mode is not supported.
4655 lpfc_request_firmware_upgrade_store(struct device *dev,
4656 struct device_attribute *attr,
4657 const char *buf, size_t count)
4659 struct Scsi_Host *shost = class_to_shost(dev);
4660 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4661 struct lpfc_hba *phba = vport->phba;
4664 /* Sanity check on user data */
4665 if (!isdigit(buf[0]))
4667 if (sscanf(buf, "%i", &val) != 1)
4672 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4680 static int lpfc_req_fw_upgrade;
4681 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4682 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4683 lpfc_param_show(request_firmware_upgrade)
4686 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4687 * @phba: lpfc_hba pointer.
4691 * Set the initial Linux generic firmware upgrade enable or disable flag.
4694 * zero if val saved.
4695 * -EINVAL val out of range
4698 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4700 if (val >= 0 && val <= 1) {
4701 phba->cfg_request_firmware_upgrade = val;
4706 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4707 lpfc_request_firmware_upgrade_show,
4708 lpfc_request_firmware_upgrade_store);
4711 * lpfc_force_rscn_store
4713 * @dev: class device that is converted into a Scsi_host.
4714 * @attr: device attribute, not used.
4715 * @buf: unused string
4716 * @count: unused variable.
4719 * Force the switch to send a RSCN to all other NPorts in our zone
4720 * If we are direct connect pt2pt, build the RSCN command ourself
4721 * and send to the other NPort. Not supported for private loop.
4725 * -EIO - if command is not sent
4728 lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4729 const char *buf, size_t count)
4731 struct Scsi_Host *shost = class_to_shost(dev);
4732 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4735 i = lpfc_issue_els_rscn(vport, 0);
4742 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4743 * connected to the HBA.
4745 * Value range is any ascii value
4747 static int lpfc_force_rscn;
4748 module_param(lpfc_force_rscn, int, 0644);
4749 MODULE_PARM_DESC(lpfc_force_rscn,
4750 "Force an RSCN to be sent to all remote NPorts");
4751 lpfc_param_show(force_rscn)
4754 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4755 * @phba: lpfc_hba pointer.
4756 * @val: unused value.
4759 * zero if val saved.
4762 lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
4766 static DEVICE_ATTR_RW(lpfc_force_rscn);
4769 * lpfc_fcp_imax_store
4771 * @dev: class device that is converted into a Scsi_host.
4772 * @attr: device attribute, not used.
4773 * @buf: string with the number of fast-path FCP interrupts per second.
4774 * @count: unused variable.
4777 * If val is in a valid range [636,651042], then set the adapter's
4778 * maximum number of fast-path FCP interrupts per second.
4781 * length of the buf on success if val is in range the intended mode
4783 * -EINVAL if val out of range or intended mode is not supported.
4786 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4787 const char *buf, size_t count)
4789 struct Scsi_Host *shost = class_to_shost(dev);
4790 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4791 struct lpfc_hba *phba = vport->phba;
4792 struct lpfc_eq_intr_info *eqi;
4796 /* fcp_imax is only valid for SLI4 */
4797 if (phba->sli_rev != LPFC_SLI_REV4)
4800 /* Sanity check on user data */
4801 if (!isdigit(buf[0]))
4803 if (sscanf(buf, "%i", &val) != 1)
4807 * Value range for the HBA is [5000,5000000]
4808 * The value for each EQ depends on how many EQs are configured.
4811 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4814 phba->cfg_auto_imax = (val) ? 0 : 1;
4815 if (phba->cfg_fcp_imax && !val) {
4816 queue_delayed_work(phba->wq, &phba->eq_delay_work,
4817 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
4819 for_each_present_cpu(i) {
4820 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
4825 phba->cfg_fcp_imax = (uint32_t)val;
4827 if (phba->cfg_fcp_imax)
4828 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
4832 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4833 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4840 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4843 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4845 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4846 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4847 MODULE_PARM_DESC(lpfc_fcp_imax,
4848 "Set the maximum number of FCP interrupts per second per HBA");
4849 lpfc_param_show(fcp_imax)
4852 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4853 * @phba: lpfc_hba pointer.
4854 * @val: link speed value.
4857 * If val is in a valid range [636,651042], then initialize the adapter's
4858 * maximum number of fast-path FCP interrupts per second.
4861 * zero if val saved.
4862 * -EINVAL val out of range
4865 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4867 if (phba->sli_rev != LPFC_SLI_REV4) {
4868 phba->cfg_fcp_imax = 0;
4872 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4874 phba->cfg_fcp_imax = val;
4878 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4879 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4881 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4886 static DEVICE_ATTR_RW(lpfc_fcp_imax);
4889 * lpfc_cq_max_proc_limit_store
4891 * @dev: class device that is converted into a Scsi_host.
4892 * @attr: device attribute, not used.
4893 * @buf: string with the cq max processing limit of cqes
4894 * @count: unused variable.
4897 * If val is in a valid range, then set value on each cq
4900 * The length of the buf: if successful
4901 * -ERANGE: if val is not in the valid range
4902 * -EINVAL: if bad value format or intended mode is not supported.
4905 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
4906 const char *buf, size_t count)
4908 struct Scsi_Host *shost = class_to_shost(dev);
4909 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4910 struct lpfc_hba *phba = vport->phba;
4911 struct lpfc_queue *eq, *cq;
4915 /* cq_max_proc_limit is only valid for SLI4 */
4916 if (phba->sli_rev != LPFC_SLI_REV4)
4919 /* Sanity check on user data */
4920 if (!isdigit(buf[0]))
4922 if (kstrtoul(buf, 0, &val))
4925 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
4928 phba->cfg_cq_max_proc_limit = (uint32_t)val;
4930 /* set the values on the cq's */
4931 for (i = 0; i < phba->cfg_irq_chann; i++) {
4932 /* Get the EQ corresponding to the IRQ vector */
4933 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
4937 list_for_each_entry(cq, &eq->child_list, list)
4938 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
4946 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
4947 * itteration of CQ processing.
4949 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4950 module_param(lpfc_cq_max_proc_limit, int, 0644);
4951 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
4952 "Set the maximum number CQEs processed in an iteration of "
4954 lpfc_param_show(cq_max_proc_limit)
4957 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
4958 * single handler call which should request a polled completion rather
4959 * than re-enabling interrupts.
4961 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
4962 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
4963 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
4964 "CQE Processing Threshold to enable Polling");
4967 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
4968 * @phba: lpfc_hba pointer.
4972 * If val is in a valid range, then initialize the adapter's maximum
4976 * Always returns 0 for success, even if value not always set to
4977 * requested value. If value out of range or not supported, will fall
4981 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
4983 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4985 if (phba->sli_rev != LPFC_SLI_REV4)
4988 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
4989 phba->cfg_cq_max_proc_limit = val;
4993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4994 "0371 lpfc_cq_max_proc_limit: %d out of range, using "
4996 phba->cfg_cq_max_proc_limit);
5001 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
5004 * lpfc_fcp_cpu_map_show - Display current driver CPU affinity
5005 * @dev: class converted to a Scsi_host structure.
5006 * @attr: device attribute, not used.
5007 * @buf: on return contains text describing the state of the link.
5009 * Returns: size of formatted string.
5012 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5015 struct Scsi_Host *shost = class_to_shost(dev);
5016 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5017 struct lpfc_hba *phba = vport->phba;
5018 struct lpfc_vector_map_info *cpup;
5021 if ((phba->sli_rev != LPFC_SLI_REV4) ||
5022 (phba->intr_type != MSIX))
5025 switch (phba->cfg_fcp_cpu_map) {
5027 len += scnprintf(buf + len, PAGE_SIZE-len,
5028 "fcp_cpu_map: No mapping (%d)\n",
5029 phba->cfg_fcp_cpu_map);
5032 len += scnprintf(buf + len, PAGE_SIZE-len,
5033 "fcp_cpu_map: HBA centric mapping (%d): "
5034 "%d of %d CPUs online from %d possible CPUs\n",
5035 phba->cfg_fcp_cpu_map, num_online_cpus(),
5037 phba->sli4_hba.num_possible_cpu);
5041 while (phba->sli4_hba.curr_disp_cpu <
5042 phba->sli4_hba.num_possible_cpu) {
5043 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5045 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5046 len += scnprintf(buf + len, PAGE_SIZE - len,
5047 "CPU %02d not present\n",
5048 phba->sli4_hba.curr_disp_cpu);
5049 else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
5050 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5052 buf + len, PAGE_SIZE - len,
5053 "CPU %02d hdwq None "
5054 "physid %d coreid %d ht %d ua %d\n",
5055 phba->sli4_hba.curr_disp_cpu,
5056 cpup->phys_id, cpup->core_id,
5057 (cpup->flag & LPFC_CPU_MAP_HYPER),
5058 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5061 buf + len, PAGE_SIZE - len,
5062 "CPU %02d EQ None hdwq %04d "
5063 "physid %d coreid %d ht %d ua %d\n",
5064 phba->sli4_hba.curr_disp_cpu,
5065 cpup->hdwq, cpup->phys_id,
5067 (cpup->flag & LPFC_CPU_MAP_HYPER),
5068 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5070 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5072 buf + len, PAGE_SIZE - len,
5073 "CPU %02d hdwq None "
5074 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5075 phba->sli4_hba.curr_disp_cpu,
5078 (cpup->flag & LPFC_CPU_MAP_HYPER),
5079 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5080 lpfc_get_irq(cpup->eq));
5083 buf + len, PAGE_SIZE - len,
5084 "CPU %02d EQ %04d hdwq %04d "
5085 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5086 phba->sli4_hba.curr_disp_cpu,
5087 cpup->eq, cpup->hdwq, cpup->phys_id,
5089 (cpup->flag & LPFC_CPU_MAP_HYPER),
5090 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5091 lpfc_get_irq(cpup->eq));
5094 phba->sli4_hba.curr_disp_cpu++;
5096 /* display max number of CPUs keeping some margin */
5097 if (phba->sli4_hba.curr_disp_cpu <
5098 phba->sli4_hba.num_possible_cpu &&
5099 (len >= (PAGE_SIZE - 64))) {
5100 len += scnprintf(buf + len,
5101 PAGE_SIZE - len, "more...\n");
5106 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
5107 phba->sli4_hba.curr_disp_cpu = 0;
5113 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5114 * @dev: class device that is converted into a Scsi_host.
5115 * @attr: device attribute, not used.
5116 * @buf: one or more lpfc_polling_flags values.
5120 * -EINVAL - Not implemented yet.
5123 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5124 const char *buf, size_t count)
5130 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5133 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5134 # 0 - Do not affinitze IRQ vectors
5135 # 1 - Affintize HBA vectors with respect to each HBA
5136 # (start with CPU0 for each HBA)
5137 # This also defines how Hardware Queues are mapped to specific CPUs.
5139 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5140 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5141 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5142 "Defines how to map CPUs to IRQ vectors per HBA");
5145 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5146 * @phba: lpfc_hba pointer.
5147 * @val: link speed value.
5150 * If val is in a valid range [0-2], then affinitze the adapter's
5154 * zero if val saved.
5155 * -EINVAL val out of range
5158 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5160 if (phba->sli_rev != LPFC_SLI_REV4) {
5161 phba->cfg_fcp_cpu_map = 0;
5165 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5166 phba->cfg_fcp_cpu_map = val;
5170 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5171 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5173 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5178 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5181 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5182 # Value range is [2,3]. Default value is 3.
5184 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5185 "Select Fibre Channel class of service for FCP sequences");
5188 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5189 # is [0,1]. Default value is 1.
5191 LPFC_VPORT_ATTR_RW(use_adisc, 1, 0, 1,
5192 "Use ADISC on rediscovery to authenticate FCP devices");
5195 # lpfc_first_burst_size: First burst size to use on the NPorts
5196 # that support first burst.
5197 # Value range is [0,65536]. Default value is 0.
5199 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5200 "First burst size for Targets that support first burst");
5203 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5204 * When the driver is configured as an NVME target, this value is
5205 * communicated to the NVME initiator in the PRLI response. It is
5206 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5207 * parameters are set and the target is sending the PRLI RSP.
5208 * Parameter supported on physical port only - no NPIV support.
5209 * Value range is [0,65536]. Default value is 0.
5211 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5212 "NVME Target mode first burst size in 512B increments.");
5215 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5216 * For the Initiator (I), enabling this parameter means that an NVMET
5217 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5218 * processed by the initiator for subsequent NVME FCP IO.
5219 * Currently, this feature is not supported on the NVME target
5220 * Value range is [0,1]. Default value is 0 (disabled).
5222 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5223 "Enable First Burst feature for NVME Initiator.");
5226 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5227 # depth. Default value is 0. When the value of this parameter is zero the
5228 # SCSI command completion time is not used for controlling I/O queue depth. When
5229 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5230 # to limit the I/O completion time to the parameter value.
5231 # The value is set in milliseconds.
5233 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5234 "Use command completion time to control queue depth");
5236 lpfc_vport_param_show(max_scsicmpl_time);
5238 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5240 struct lpfc_nodelist *ndlp, *next_ndlp;
5241 unsigned long iflags;
5243 if (val == vport->cfg_max_scsicmpl_time)
5245 if ((val < 0) || (val > 60000))
5247 vport->cfg_max_scsicmpl_time = val;
5249 spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
5250 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5251 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5253 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5255 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
5258 lpfc_vport_param_store(max_scsicmpl_time);
5259 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5262 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5263 # range is [0,1]. Default value is 0.
5265 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5268 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5269 # range is [0,1]. Default value is 1.
5271 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5274 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5275 * range is [0,1]. Default value is 0.
5276 * For [0], FCP commands are issued to Work Queues based on upper layer
5277 * hardware queue index.
5278 * For [1], FCP commands are issued to a Work Queue associated with the
5281 * LPFC_FCP_SCHED_BY_HDWQ == 0
5282 * LPFC_FCP_SCHED_BY_CPU == 1
5284 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5285 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5286 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5287 * through WQs will be used.
5289 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5290 LPFC_FCP_SCHED_BY_HDWQ,
5291 LPFC_FCP_SCHED_BY_CPU,
5292 "Determine scheduling algorithm for "
5293 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5296 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5297 * range is [0,1]. Default value is 0.
5298 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5299 * For [1], GID_PT is used for NameServer queries after RSCN
5302 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5303 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5304 "Determine algorithm NameServer queries after RSCN "
5305 "[0] - GID_FT, [1] - GID_PT");
5308 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5309 # range is [0,1]. Default value is 0.
5310 # For [0], bus reset issues target reset to ALL devices
5311 # For [1], bus reset issues target reset to non-FCP2 devices
5313 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5314 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5318 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5319 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5320 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5321 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5322 # cr_delay is set to 0.
5324 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5325 "interrupt response is generated");
5327 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5328 "interrupt response is generated");
5331 # lpfc_multi_ring_support: Determines how many rings to spread available
5332 # cmd/rsp IOCB entries across.
5333 # Value range is [1,2]. Default value is 1.
5335 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5336 "SLI rings to spread IOCB entries across");
5339 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5340 # identifies what rctl value to configure the additional ring for.
5341 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5343 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5344 255, "Identifies RCTL for additional ring configuration");
5347 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5348 # identifies what type value to configure the additional ring for.
5349 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5351 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5352 255, "Identifies TYPE for additional ring configuration");
5355 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5356 # 0 = SmartSAN functionality disabled (default)
5357 # 1 = SmartSAN functionality enabled
5358 # This parameter will override the value of lpfc_fdmi_on module parameter.
5359 # Value range is [0,1]. Default value is 0.
5361 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5364 # lpfc_fdmi_on: Controls FDMI support.
5366 # 1 Traditional FDMI support (default)
5367 # Traditional FDMI support means the driver will assume FDMI-2 support;
5368 # however, if that fails, it will fallback to FDMI-1.
5369 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5370 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5372 # Value range [0,1]. Default value is 1.
5374 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5377 # Specifies the maximum number of ELS cmds we can have outstanding (for
5378 # discovery). Value range is [1,64]. Default value = 32.
5380 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5381 "during discovery");
5384 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5385 # will be scanned by the SCSI midlayer when sequential scanning is
5386 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5387 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5388 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5389 # above. The lpfc driver limits the default value to 255 for two reasons.
5390 # As it bounds the sequential scan loop, scanning for thousands of luns
5391 # on a target can take minutes of wall clock time. Additionally,
5392 # there are FC targets, such as JBODs, that only recognize 8-bits of
5393 # LUN ID. When they receive a value greater than 8 bits, they chop off
5394 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5395 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5396 # valid responses at each of the LUN IDs, to believe there are multiple
5397 # devices present, when in fact, there is only 1.
5398 # A customer that is aware of their target behaviors, and the results as
5399 # indicated above, is welcome to increase the lpfc_max_luns value.
5400 # As mentioned, this value is not used by the lpfc driver, only the
5402 # Value range is [0,65535]. Default value is 255.
5403 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5405 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5408 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5409 # Value range is [1,255], default value is 10.
5411 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5412 "Milliseconds driver will wait between polling FCP ring");
5415 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5416 # to complete in seconds. Value range is [5,180], default value is 60.
5418 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5419 "Maximum time to wait for task management commands to complete");
5421 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5422 # support this feature
5425 # 2 = MSI-X enabled (default)
5426 # Value range is [0,2]. Default value is 2.
5428 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5429 "MSI-X (2), if possible");
5432 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5434 * 0 = NVME OAS disabled
5435 * 1 = NVME OAS enabled
5437 * Value range is [0,1]. Default value is 0.
5439 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5440 "Use OAS bit on NVME IOs");
5443 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5445 * 0 = Put NVME Command in SGL
5446 * 1 = Embed NVME Command in WQE (unless G7)
5447 * 2 = Embed NVME Command in WQE (force)
5449 * Value range is [0,2]. Default value is 1.
5451 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5452 "Embed NVME Command in WQE");
5455 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5456 * the driver will advertise it supports to the SCSI layer.
5458 * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
5459 * 1,256 = Manually specify nr_hw_queue value to be advertised,
5461 * Value range is [0,256]. Default value is 8.
5463 LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5464 LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5465 "Set the number of SCSI Queues advertised");
5468 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5469 * will advertise it supports to the NVME and SCSI layers. This also
5470 * will map to the number of CQ/WQ pairs the driver will create.
5472 * The NVME Layer will try to create this many, plus 1 administrative
5473 * hardware queue. The administrative queue will always map to WQ 0
5474 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5476 * 0 = Configure the number of hdw queues to the number of active CPUs.
5477 * 1,256 = Manually specify how many hdw queues to use.
5479 * Value range is [0,256]. Default value is 0.
5481 LPFC_ATTR_R(hdw_queue,
5483 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5484 "Set the number of I/O Hardware Queues");
5486 #if IS_ENABLED(CONFIG_X86)
5488 * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
5490 * @phba: Pointer to HBA context object.
5493 lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)
5495 unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;
5496 const struct cpumask *sibling_mask;
5497 struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;
5499 cpumask_clear(aff_mask);
5501 if (phba->irq_chann_mode == NUMA_MODE) {
5502 /* Check if we're a NUMA architecture */
5503 numa_node = dev_to_node(&phba->pcidev->dev);
5504 if (numa_node == NUMA_NO_NODE) {
5505 phba->irq_chann_mode = NORMAL_MODE;
5510 for_each_possible_cpu(cpu) {
5511 switch (phba->irq_chann_mode) {
5513 if (cpu_to_node(cpu) == numa_node)
5514 cpumask_set_cpu(cpu, aff_mask);
5517 sibling_mask = topology_sibling_cpumask(cpu);
5518 first_cpu = cpumask_first(sibling_mask);
5519 if (first_cpu < nr_cpu_ids)
5520 cpumask_set_cpu(first_cpu, aff_mask);
5530 lpfc_assign_default_irq_chann(struct lpfc_hba *phba)
5532 #if IS_ENABLED(CONFIG_X86)
5533 switch (boot_cpu_data.x86_vendor) {
5534 case X86_VENDOR_AMD:
5535 /* If AMD architecture, then default is NUMA_MODE */
5536 phba->irq_chann_mode = NUMA_MODE;
5538 case X86_VENDOR_INTEL:
5539 /* If Intel architecture, then default is no hyperthread mode */
5540 phba->irq_chann_mode = NHT_MODE;
5543 phba->irq_chann_mode = NORMAL_MODE;
5546 lpfc_cpumask_irq_mode_init(phba);
5548 phba->irq_chann_mode = NORMAL_MODE;
5553 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5554 * for Hardware Queues to utilize. This also will map to the number
5555 * of EQ / MSI-X vectors the driver will create. This should never be
5556 * more than the number of Hardware Queues
5558 * 0 = Configure number of IRQ Channels to:
5559 * if AMD architecture, number of CPUs on HBA's NUMA node
5560 * if Intel architecture, number of physical CPUs.
5561 * otherwise, number of active CPUs.
5562 * [1,256] = Manually specify how many IRQ Channels to use.
5564 * Value range is [0,256]. Default value is [0].
5566 static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
5567 module_param(lpfc_irq_chann, uint, 0444);
5568 MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
5570 /* lpfc_irq_chann_init - Set the hba irq_chann initial value
5571 * @phba: lpfc_hba pointer.
5572 * @val: contains the initial value
5575 * Validates the initial value is within range and assigns it to the
5576 * adapter. If not in range, an error message is posted and the
5577 * default value is assigned.
5580 * zero if value is in range and is set
5581 * -EINVAL if value was out of range
5584 lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
5586 const struct cpumask *aff_mask;
5588 if (phba->cfg_use_msi != 2) {
5589 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5590 "8532 use_msi = %u ignoring cfg_irq_numa\n",
5592 phba->irq_chann_mode = NORMAL_MODE;
5593 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5597 /* Check if default setting was passed */
5598 if (val == LPFC_IRQ_CHANN_DEF &&
5599 phba->cfg_hdw_queue == LPFC_HBA_HDWQ_DEF &&
5600 phba->sli_rev == LPFC_SLI_REV4)
5601 lpfc_assign_default_irq_chann(phba);
5603 if (phba->irq_chann_mode != NORMAL_MODE) {
5604 aff_mask = &phba->sli4_hba.irq_aff_mask;
5606 if (cpumask_empty(aff_mask)) {
5607 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5608 "8533 Could not identify CPUS for "
5609 "mode %d, ignoring\n",
5610 phba->irq_chann_mode);
5611 phba->irq_chann_mode = NORMAL_MODE;
5612 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5614 phba->cfg_irq_chann = cpumask_weight(aff_mask);
5616 /* If no hyperthread mode, then set hdwq count to
5617 * aff_mask weight as well
5619 if (phba->irq_chann_mode == NHT_MODE)
5620 phba->cfg_hdw_queue = phba->cfg_irq_chann;
5622 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5623 "8543 lpfc_irq_chann set to %u "
5624 "(mode: %d)\n", phba->cfg_irq_chann,
5625 phba->irq_chann_mode);
5628 if (val > LPFC_IRQ_CHANN_MAX) {
5629 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5630 "8545 lpfc_irq_chann attribute cannot "
5631 "be set to %u, allowed range is "
5635 LPFC_IRQ_CHANN_MAX);
5636 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5639 if (phba->sli_rev == LPFC_SLI_REV4) {
5640 phba->cfg_irq_chann = val;
5642 phba->cfg_irq_chann = 2;
5643 phba->cfg_hdw_queue = 1;
5651 * lpfc_irq_chann_show - Display value of irq_chann
5652 * @dev: class converted to a Scsi_host structure.
5653 * @attr: device attribute, not used.
5654 * @buf: on return contains a string with the list sizes
5656 * Returns: size of formatted string.
5659 lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
5662 struct Scsi_Host *shost = class_to_shost(dev);
5663 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5664 struct lpfc_hba *phba = vport->phba;
5666 return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
5669 static DEVICE_ATTR_RO(lpfc_irq_chann);
5672 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5673 # 0 = HBA resets disabled
5674 # 1 = HBA resets enabled (default)
5675 # 2 = HBA reset via PCI bus reset enabled
5676 # Value range is [0,2]. Default value is 1.
5678 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5681 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5682 # 0 = HBA Heartbeat disabled
5683 # 1 = HBA Heartbeat enabled (default)
5684 # Value range is [0,1]. Default value is 1.
5686 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5689 # lpfc_EnableXLane: Enable Express Lane Feature
5690 # 0x0 Express Lane Feature disabled
5691 # 0x1 Express Lane Feature enabled
5692 # Value range is [0,1]. Default value is 0.
5694 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5697 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5698 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5699 # Value range is [0x0,0x7f]. Default value is 0
5701 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5704 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5705 # 0 = BlockGuard disabled (default)
5706 # 1 = BlockGuard enabled
5707 # Value range is [0,1]. Default value is 0.
5709 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5713 # - Bit mask of host protection capabilities used to register with the
5715 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5716 # - Allows you to ultimately specify which profiles to use
5717 # - Default will result in registering capabilities for all profiles.
5718 # - SHOST_DIF_TYPE1_PROTECTION 1
5719 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5720 # - SHOST_DIX_TYPE0_PROTECTION 8
5721 # HBA supports DIX Type 0: Host to HBA protection only
5722 # - SHOST_DIX_TYPE1_PROTECTION 16
5723 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5726 LPFC_ATTR(prot_mask,
5727 (SHOST_DIF_TYPE1_PROTECTION |
5728 SHOST_DIX_TYPE0_PROTECTION |
5729 SHOST_DIX_TYPE1_PROTECTION),
5731 (SHOST_DIF_TYPE1_PROTECTION |
5732 SHOST_DIX_TYPE0_PROTECTION |
5733 SHOST_DIX_TYPE1_PROTECTION),
5734 "T10-DIF host protection capabilities mask");
5738 # - Bit mask of protection guard types to register with the SCSI mid-layer
5739 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5740 # - Allows you to ultimately specify which profiles to use
5741 # - Default will result in registering capabilities for all guard types
5744 LPFC_ATTR(prot_guard,
5745 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5746 "T10-DIF host protection guard type");
5749 * Delay initial NPort discovery when Clean Address bit is cleared in
5750 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5751 * This parameter can have value 0 or 1.
5752 * When this parameter is set to 0, no delay is added to the initial
5754 * When this parameter is set to non-zero value, initial Nport discovery is
5755 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5756 * accept and FCID/Fabric name/Fabric portname is changed.
5757 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5758 * when Clean Address bit is cleared in FLOGI/FDISC
5759 * accept and FCID/Fabric name/Fabric portname is changed.
5760 * Default value is 0.
5762 LPFC_ATTR(delay_discovery, 0, 0, 1,
5763 "Delay NPort discovery when Clean Address bit is cleared.");
5766 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5767 * This value can be set to values between 64 and 4096. The default value
5768 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5769 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5770 * Because of the additional overhead involved in setting up T10-DIF,
5771 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5772 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5774 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5775 module_param(lpfc_sg_seg_cnt, uint, 0444);
5776 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5779 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5780 * configured for the adapter
5781 * @dev: class converted to a Scsi_host structure.
5782 * @attr: device attribute, not used.
5783 * @buf: on return contains a string with the list sizes
5785 * Returns: size of formatted string.
5788 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5791 struct Scsi_Host *shost = class_to_shost(dev);
5792 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5793 struct lpfc_hba *phba = vport->phba;
5796 len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
5797 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5799 len += scnprintf(buf + len, PAGE_SIZE - len,
5800 "Cfg: %d SCSI: %d NVME: %d\n",
5801 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5802 phba->cfg_nvme_seg_cnt);
5806 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5809 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5810 * @phba: lpfc_hba pointer.
5811 * @val: contains the initial value
5814 * Validates the initial value is within range and assigns it to the
5815 * adapter. If not in range, an error message is posted and the
5816 * default value is assigned.
5819 * zero if value is in range and is set
5820 * -EINVAL if value was out of range
5823 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5825 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5826 phba->cfg_sg_seg_cnt = val;
5829 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5830 "0409 lpfc_sg_seg_cnt attribute cannot be set to %d, "
5831 "allowed range is [%d, %d]\n",
5832 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5833 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5838 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5839 * 0 = MDS Diagnostics disabled (default)
5840 * 1 = MDS Diagnostics enabled
5841 * Value range is [0,1]. Default value is 0.
5843 LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5846 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5847 * 0 = Disable firmware logging (default)
5848 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
5849 * Value range [0..4]. Default value is 0
5851 LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5852 lpfc_param_show(ras_fwlog_buffsize);
5855 lpfc_ras_fwlog_buffsize_set(struct lpfc_hba *phba, uint val)
5858 enum ras_state state;
5860 if (!lpfc_rangecheck(val, 0, 4))
5863 if (phba->cfg_ras_fwlog_buffsize == val)
5866 if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
5869 spin_lock_irq(&phba->ras_fwlog_lock);
5870 state = phba->ras_fwlog.state;
5871 spin_unlock_irq(&phba->ras_fwlog_lock);
5873 if (state == REG_INPROGRESS) {
5874 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
5875 "registration is in progress\n");
5879 /* For disable logging: stop the logs and free the DMA.
5880 * For ras_fwlog_buffsize size change we still need to free and
5881 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
5883 phba->cfg_ras_fwlog_buffsize = val;
5884 if (state == ACTIVE) {
5885 lpfc_ras_stop_fwlog(phba);
5886 lpfc_sli4_ras_dma_free(phba);
5889 lpfc_sli4_ras_init(phba);
5890 if (phba->ras_fwlog.ras_enabled)
5891 ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
5892 LPFC_RAS_ENABLE_LOGGING);
5896 lpfc_param_store(ras_fwlog_buffsize);
5897 static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
5900 * lpfc_ras_fwlog_level: Firmware logging verbosity level
5901 * Valid only if firmware logging is enabled
5902 * 0(Least Verbosity) 4 (most verbosity)
5903 * Value range is [0..4]. Default value is 0
5905 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5908 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5909 * Default function which has RAS support : 0
5910 * Value Range is [0..3].
5911 * FW logging is a global action and enablement is via a specific
5914 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 3, "Firmware Logging Enabled on Function");
5917 * lpfc_enable_bbcr: Enable BB Credit Recovery
5918 * 0 = BB Credit Recovery disabled
5919 * 1 = BB Credit Recovery enabled (default)
5920 * Value range is [0,1]. Default value is 1.
5922 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5924 /* Signaling module parameters */
5925 int lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
5926 module_param(lpfc_fabric_cgn_frequency, int, 0444);
5927 MODULE_PARM_DESC(lpfc_fabric_cgn_frequency, "Congestion signaling fabric freq");
5929 unsigned char lpfc_acqe_cgn_frequency = 10; /* 10 sec default */
5930 module_param(lpfc_acqe_cgn_frequency, byte, 0444);
5931 MODULE_PARM_DESC(lpfc_acqe_cgn_frequency, "Congestion signaling ACQE freq");
5933 int lpfc_use_cgn_signal = 1; /* 0 - only use FPINs, 1 - Use signals if avail */
5934 module_param(lpfc_use_cgn_signal, int, 0444);
5935 MODULE_PARM_DESC(lpfc_use_cgn_signal, "Use Congestion signaling if available");
5938 * lpfc_enable_dpp: Enable DPP on G7
5939 * 0 = DPP on G7 disabled
5940 * 1 = DPP on G7 enabled (default)
5941 * Value range is [0,1]. Default value is 1.
5943 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5946 * lpfc_enable_mi: Enable FDMI MIB
5948 * 1 = enabled (default)
5949 * Value range is [0,1].
5951 LPFC_ATTR_R(enable_mi, 1, 0, 1, "Enable MI");
5954 * lpfc_max_vmid: Maximum number of VMs to be tagged. This is valid only if
5955 * either vmid_app_header or vmid_priority_tagging is enabled.
5956 * 4 - 255 = vmid support enabled for 4-255 VMs
5957 * Value range is [4,255].
5959 LPFC_ATTR_R(max_vmid, LPFC_MIN_VMID, LPFC_MIN_VMID, LPFC_MAX_VMID,
5960 "Maximum number of VMs supported");
5963 * lpfc_vmid_inactivity_timeout: Inactivity timeout duration in hours
5964 * 0 = Timeout is disabled
5965 * Value range is [0,24].
5967 LPFC_ATTR_R(vmid_inactivity_timeout, 4, 0, 24,
5968 "Inactivity timeout in hours");
5971 * lpfc_vmid_app_header: Enable App Header VMID support
5972 * 0 = Support is disabled (default)
5973 * 1 = Support is enabled
5974 * Value range is [0,1].
5976 LPFC_ATTR_R(vmid_app_header, LPFC_VMID_APP_HEADER_DISABLE,
5977 LPFC_VMID_APP_HEADER_DISABLE, LPFC_VMID_APP_HEADER_ENABLE,
5978 "Enable App Header VMID support");
5981 * lpfc_vmid_priority_tagging: Enable Priority Tagging VMID support
5982 * 0 = Support is disabled (default)
5983 * 1 = Allow supported targets only
5984 * 2 = Allow all targets
5985 * Value range is [0,2].
5987 LPFC_ATTR_R(vmid_priority_tagging, LPFC_VMID_PRIO_TAG_DISABLE,
5988 LPFC_VMID_PRIO_TAG_DISABLE,
5989 LPFC_VMID_PRIO_TAG_ALL_TARGETS,
5990 "Enable Priority Tagging VMID support");
5992 static struct attribute *lpfc_hba_attrs[] = {
5993 &dev_attr_nvme_info.attr,
5994 &dev_attr_scsi_stat.attr,
5995 &dev_attr_bg_info.attr,
5996 &dev_attr_bg_guard_err.attr,
5997 &dev_attr_bg_apptag_err.attr,
5998 &dev_attr_bg_reftag_err.attr,
5999 &dev_attr_info.attr,
6000 &dev_attr_serialnum.attr,
6001 &dev_attr_modeldesc.attr,
6002 &dev_attr_modelname.attr,
6003 &dev_attr_programtype.attr,
6004 &dev_attr_portnum.attr,
6005 &dev_attr_fwrev.attr,
6007 &dev_attr_option_rom_version.attr,
6008 &dev_attr_link_state.attr,
6009 &dev_attr_num_discovered_ports.attr,
6010 &dev_attr_lpfc_drvr_version.attr,
6011 &dev_attr_lpfc_enable_fip.attr,
6012 &dev_attr_lpfc_temp_sensor.attr,
6013 &dev_attr_lpfc_log_verbose.attr,
6014 &dev_attr_lpfc_lun_queue_depth.attr,
6015 &dev_attr_lpfc_tgt_queue_depth.attr,
6016 &dev_attr_lpfc_hba_queue_depth.attr,
6017 &dev_attr_lpfc_peer_port_login.attr,
6018 &dev_attr_lpfc_nodev_tmo.attr,
6019 &dev_attr_lpfc_devloss_tmo.attr,
6020 &dev_attr_lpfc_enable_fc4_type.attr,
6021 &dev_attr_lpfc_fcp_class.attr,
6022 &dev_attr_lpfc_use_adisc.attr,
6023 &dev_attr_lpfc_first_burst_size.attr,
6024 &dev_attr_lpfc_ack0.attr,
6025 &dev_attr_lpfc_xri_rebalancing.attr,
6026 &dev_attr_lpfc_topology.attr,
6027 &dev_attr_lpfc_scan_down.attr,
6028 &dev_attr_lpfc_link_speed.attr,
6029 &dev_attr_lpfc_fcp_io_sched.attr,
6030 &dev_attr_lpfc_ns_query.attr,
6031 &dev_attr_lpfc_fcp2_no_tgt_reset.attr,
6032 &dev_attr_lpfc_cr_delay.attr,
6033 &dev_attr_lpfc_cr_count.attr,
6034 &dev_attr_lpfc_multi_ring_support.attr,
6035 &dev_attr_lpfc_multi_ring_rctl.attr,
6036 &dev_attr_lpfc_multi_ring_type.attr,
6037 &dev_attr_lpfc_fdmi_on.attr,
6038 &dev_attr_lpfc_enable_SmartSAN.attr,
6039 &dev_attr_lpfc_max_luns.attr,
6040 &dev_attr_lpfc_enable_npiv.attr,
6041 &dev_attr_lpfc_fcf_failover_policy.attr,
6042 &dev_attr_lpfc_enable_rrq.attr,
6043 &dev_attr_lpfc_fcp_wait_abts_rsp.attr,
6044 &dev_attr_nport_evt_cnt.attr,
6045 &dev_attr_board_mode.attr,
6046 &dev_attr_lpfc_xcvr_data.attr,
6047 &dev_attr_max_vpi.attr,
6048 &dev_attr_used_vpi.attr,
6049 &dev_attr_max_rpi.attr,
6050 &dev_attr_used_rpi.attr,
6051 &dev_attr_max_xri.attr,
6052 &dev_attr_used_xri.attr,
6053 &dev_attr_npiv_info.attr,
6054 &dev_attr_issue_reset.attr,
6055 &dev_attr_lpfc_poll.attr,
6056 &dev_attr_lpfc_poll_tmo.attr,
6057 &dev_attr_lpfc_task_mgmt_tmo.attr,
6058 &dev_attr_lpfc_use_msi.attr,
6059 &dev_attr_lpfc_nvme_oas.attr,
6060 &dev_attr_lpfc_nvme_embed_cmd.attr,
6061 &dev_attr_lpfc_fcp_imax.attr,
6062 &dev_attr_lpfc_force_rscn.attr,
6063 &dev_attr_lpfc_cq_poll_threshold.attr,
6064 &dev_attr_lpfc_cq_max_proc_limit.attr,
6065 &dev_attr_lpfc_fcp_cpu_map.attr,
6066 &dev_attr_lpfc_fcp_mq_threshold.attr,
6067 &dev_attr_lpfc_hdw_queue.attr,
6068 &dev_attr_lpfc_irq_chann.attr,
6069 &dev_attr_lpfc_suppress_rsp.attr,
6070 &dev_attr_lpfc_nvmet_mrq.attr,
6071 &dev_attr_lpfc_nvmet_mrq_post.attr,
6072 &dev_attr_lpfc_nvme_enable_fb.attr,
6073 &dev_attr_lpfc_nvmet_fb_size.attr,
6074 &dev_attr_lpfc_enable_bg.attr,
6075 &dev_attr_lpfc_enable_hba_reset.attr,
6076 &dev_attr_lpfc_enable_hba_heartbeat.attr,
6077 &dev_attr_lpfc_EnableXLane.attr,
6078 &dev_attr_lpfc_XLanePriority.attr,
6079 &dev_attr_lpfc_xlane_lun.attr,
6080 &dev_attr_lpfc_xlane_tgt.attr,
6081 &dev_attr_lpfc_xlane_vpt.attr,
6082 &dev_attr_lpfc_xlane_lun_state.attr,
6083 &dev_attr_lpfc_xlane_lun_status.attr,
6084 &dev_attr_lpfc_xlane_priority.attr,
6085 &dev_attr_lpfc_sg_seg_cnt.attr,
6086 &dev_attr_lpfc_max_scsicmpl_time.attr,
6087 &dev_attr_lpfc_aer_support.attr,
6088 &dev_attr_lpfc_aer_state_cleanup.attr,
6089 &dev_attr_lpfc_sriov_nr_virtfn.attr,
6090 &dev_attr_lpfc_req_fw_upgrade.attr,
6091 &dev_attr_lpfc_suppress_link_up.attr,
6092 &dev_attr_iocb_hw.attr,
6095 &dev_attr_txq_hw.attr,
6096 &dev_attr_txcmplq_hw.attr,
6097 &dev_attr_lpfc_sriov_hw_max_virtfn.attr,
6098 &dev_attr_protocol.attr,
6099 &dev_attr_lpfc_xlane_supported.attr,
6100 &dev_attr_lpfc_enable_mds_diags.attr,
6101 &dev_attr_lpfc_ras_fwlog_buffsize.attr,
6102 &dev_attr_lpfc_ras_fwlog_level.attr,
6103 &dev_attr_lpfc_ras_fwlog_func.attr,
6104 &dev_attr_lpfc_enable_bbcr.attr,
6105 &dev_attr_lpfc_enable_dpp.attr,
6106 &dev_attr_lpfc_enable_mi.attr,
6107 &dev_attr_cmf_info.attr,
6108 &dev_attr_lpfc_max_vmid.attr,
6109 &dev_attr_lpfc_vmid_inactivity_timeout.attr,
6110 &dev_attr_lpfc_vmid_app_header.attr,
6111 &dev_attr_lpfc_vmid_priority_tagging.attr,
6115 static const struct attribute_group lpfc_hba_attr_group = {
6116 .attrs = lpfc_hba_attrs
6119 const struct attribute_group *lpfc_hba_groups[] = {
6120 &lpfc_hba_attr_group,
6124 static struct attribute *lpfc_vport_attrs[] = {
6125 &dev_attr_info.attr,
6126 &dev_attr_link_state.attr,
6127 &dev_attr_num_discovered_ports.attr,
6128 &dev_attr_lpfc_drvr_version.attr,
6129 &dev_attr_lpfc_log_verbose.attr,
6130 &dev_attr_lpfc_lun_queue_depth.attr,
6131 &dev_attr_lpfc_tgt_queue_depth.attr,
6132 &dev_attr_lpfc_nodev_tmo.attr,
6133 &dev_attr_lpfc_devloss_tmo.attr,
6134 &dev_attr_lpfc_hba_queue_depth.attr,
6135 &dev_attr_lpfc_peer_port_login.attr,
6136 &dev_attr_lpfc_restrict_login.attr,
6137 &dev_attr_lpfc_fcp_class.attr,
6138 &dev_attr_lpfc_use_adisc.attr,
6139 &dev_attr_lpfc_first_burst_size.attr,
6140 &dev_attr_lpfc_max_luns.attr,
6141 &dev_attr_nport_evt_cnt.attr,
6142 &dev_attr_npiv_info.attr,
6143 &dev_attr_lpfc_enable_da_id.attr,
6144 &dev_attr_lpfc_max_scsicmpl_time.attr,
6145 &dev_attr_lpfc_static_vport.attr,
6146 &dev_attr_cmf_info.attr,
6150 static const struct attribute_group lpfc_vport_attr_group = {
6151 .attrs = lpfc_vport_attrs
6154 const struct attribute_group *lpfc_vport_groups[] = {
6155 &lpfc_vport_attr_group,
6160 * sysfs_ctlreg_write - Write method for writing to ctlreg
6161 * @filp: open sysfs file
6162 * @kobj: kernel kobject that contains the kernel class device.
6163 * @bin_attr: kernel attributes passed to us.
6164 * @buf: contains the data to be written to the adapter IOREG space.
6165 * @off: offset into buffer to beginning of data.
6166 * @count: bytes to transfer.
6169 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6170 * Uses the adapter io control registers to send buf contents to the adapter.
6173 * -ERANGE off and count combo out of range
6174 * -EINVAL off, count or buff address invalid
6175 * -EPERM adapter is offline
6176 * value of count, buf contents written
6179 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6180 struct bin_attribute *bin_attr,
6181 char *buf, loff_t off, size_t count)
6184 struct device *dev = container_of(kobj, struct device, kobj);
6185 struct Scsi_Host *shost = class_to_shost(dev);
6186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6187 struct lpfc_hba *phba = vport->phba;
6189 if (phba->sli_rev >= LPFC_SLI_REV4)
6192 if ((off + count) > FF_REG_AREA_SIZE)
6195 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6198 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6201 /* This is to protect HBA registers from accidental writes. */
6202 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6205 if (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
6208 spin_lock_irq(&phba->hbalock);
6209 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6210 buf_off += sizeof(uint32_t))
6211 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6212 phba->ctrl_regs_memmap_p + off + buf_off);
6214 spin_unlock_irq(&phba->hbalock);
6220 * sysfs_ctlreg_read - Read method for reading from ctlreg
6221 * @filp: open sysfs file
6222 * @kobj: kernel kobject that contains the kernel class device.
6223 * @bin_attr: kernel attributes passed to us.
6224 * @buf: if successful contains the data from the adapter IOREG space.
6225 * @off: offset into buffer to beginning of data.
6226 * @count: bytes to transfer.
6229 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6230 * Uses the adapter io control registers to read data into buf.
6233 * -ERANGE off and count combo out of range
6234 * -EINVAL off, count or buff address invalid
6235 * value of count, buf contents read
6238 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6239 struct bin_attribute *bin_attr,
6240 char *buf, loff_t off, size_t count)
6244 struct device *dev = container_of(kobj, struct device, kobj);
6245 struct Scsi_Host *shost = class_to_shost(dev);
6246 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6247 struct lpfc_hba *phba = vport->phba;
6249 if (phba->sli_rev >= LPFC_SLI_REV4)
6252 if (off > FF_REG_AREA_SIZE)
6255 if ((off + count) > FF_REG_AREA_SIZE)
6256 count = FF_REG_AREA_SIZE - off;
6258 if (count == 0) return 0;
6260 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6263 spin_lock_irq(&phba->hbalock);
6265 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6266 tmp_ptr = (uint32_t *)(buf + buf_off);
6267 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6270 spin_unlock_irq(&phba->hbalock);
6275 static struct bin_attribute sysfs_ctlreg_attr = {
6278 .mode = S_IRUSR | S_IWUSR,
6281 .read = sysfs_ctlreg_read,
6282 .write = sysfs_ctlreg_write,
6286 * sysfs_mbox_write - Write method for writing information via mbox
6287 * @filp: open sysfs file
6288 * @kobj: kernel kobject that contains the kernel class device.
6289 * @bin_attr: kernel attributes passed to us.
6290 * @buf: contains the data to be written to sysfs mbox.
6291 * @off: offset into buffer to beginning of data.
6292 * @count: bytes to transfer.
6295 * Deprecated function. All mailbox access from user space is performed via the
6299 * -EPERM operation not permitted
6302 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6303 struct bin_attribute *bin_attr,
6304 char *buf, loff_t off, size_t count)
6310 * sysfs_mbox_read - Read method for reading information via mbox
6311 * @filp: open sysfs file
6312 * @kobj: kernel kobject that contains the kernel class device.
6313 * @bin_attr: kernel attributes passed to us.
6314 * @buf: contains the data to be read from sysfs mbox.
6315 * @off: offset into buffer to beginning of data.
6316 * @count: bytes to transfer.
6319 * Deprecated function. All mailbox access from user space is performed via the
6323 * -EPERM operation not permitted
6326 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6327 struct bin_attribute *bin_attr,
6328 char *buf, loff_t off, size_t count)
6333 static struct bin_attribute sysfs_mbox_attr = {
6336 .mode = S_IRUSR | S_IWUSR,
6338 .size = MAILBOX_SYSFS_MAX,
6339 .read = sysfs_mbox_read,
6340 .write = sysfs_mbox_write,
6344 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6345 * @vport: address of lpfc vport structure.
6349 * error return code from sysfs_create_bin_file()
6352 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6354 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6357 /* Virtual ports do not need ctrl_reg and mbox */
6358 if (vport->port_type == LPFC_NPIV_PORT)
6361 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6362 &sysfs_ctlreg_attr);
6366 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6369 goto out_remove_ctlreg_attr;
6372 out_remove_ctlreg_attr:
6373 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6379 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6380 * @vport: address of lpfc vport structure.
6383 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6385 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6387 /* Virtual ports do not need ctrl_reg and mbox */
6388 if (vport->port_type == LPFC_NPIV_PORT)
6390 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6391 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6395 * Dynamic FC Host Attributes Support
6399 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6400 * @shost: kernel scsi host pointer.
6403 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6405 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6407 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6408 sizeof fc_host_symbolic_name(shost));
6412 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6413 * @shost: kernel scsi host pointer.
6416 lpfc_get_host_port_id(struct Scsi_Host *shost)
6418 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6420 /* note: fc_myDID already in cpu endianness */
6421 fc_host_port_id(shost) = vport->fc_myDID;
6425 * lpfc_get_host_port_type - Set the value of the scsi host port type
6426 * @shost: kernel scsi host pointer.
6429 lpfc_get_host_port_type(struct Scsi_Host *shost)
6431 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6432 struct lpfc_hba *phba = vport->phba;
6434 if (vport->port_type == LPFC_NPIV_PORT) {
6435 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6436 } else if (lpfc_is_link_up(phba)) {
6437 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6438 if (test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
6439 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6441 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6443 if (test_bit(FC_FABRIC, &vport->fc_flag))
6444 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6446 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6449 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6453 * lpfc_get_host_port_state - Set the value of the scsi host port state
6454 * @shost: kernel scsi host pointer.
6457 lpfc_get_host_port_state(struct Scsi_Host *shost)
6459 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6460 struct lpfc_hba *phba = vport->phba;
6462 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
6463 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6465 switch (phba->link_state) {
6466 case LPFC_LINK_UNKNOWN:
6467 case LPFC_LINK_DOWN:
6468 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6472 case LPFC_HBA_READY:
6473 /* Links up, reports port state accordingly */
6474 if (vport->port_state < LPFC_VPORT_READY)
6475 fc_host_port_state(shost) =
6476 FC_PORTSTATE_BYPASSED;
6478 fc_host_port_state(shost) =
6479 FC_PORTSTATE_ONLINE;
6481 case LPFC_HBA_ERROR:
6482 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6485 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6492 * lpfc_get_host_speed - Set the value of the scsi host speed
6493 * @shost: kernel scsi host pointer.
6496 lpfc_get_host_speed(struct Scsi_Host *shost)
6498 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6499 struct lpfc_hba *phba = vport->phba;
6501 if ((lpfc_is_link_up(phba)) &&
6502 !test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
6503 switch(phba->fc_linkspeed) {
6504 case LPFC_LINK_SPEED_1GHZ:
6505 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6507 case LPFC_LINK_SPEED_2GHZ:
6508 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6510 case LPFC_LINK_SPEED_4GHZ:
6511 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6513 case LPFC_LINK_SPEED_8GHZ:
6514 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6516 case LPFC_LINK_SPEED_10GHZ:
6517 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6519 case LPFC_LINK_SPEED_16GHZ:
6520 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6522 case LPFC_LINK_SPEED_32GHZ:
6523 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6525 case LPFC_LINK_SPEED_64GHZ:
6526 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6528 case LPFC_LINK_SPEED_128GHZ:
6529 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6531 case LPFC_LINK_SPEED_256GHZ:
6532 fc_host_speed(shost) = FC_PORTSPEED_256GBIT;
6535 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6538 } else if (lpfc_is_link_up(phba) &&
6539 test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
6540 switch (phba->fc_linkspeed) {
6541 case LPFC_ASYNC_LINK_SPEED_1GBPS:
6542 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6544 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6545 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6547 case LPFC_ASYNC_LINK_SPEED_20GBPS:
6548 fc_host_speed(shost) = FC_PORTSPEED_20GBIT;
6550 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6551 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6553 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6554 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6556 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6557 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6560 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6564 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6568 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6569 * @shost: kernel scsi host pointer.
6572 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6575 struct lpfc_hba *phba = vport->phba;
6578 if (vport->port_state > LPFC_FLOGI &&
6579 (test_bit(FC_FABRIC, &vport->fc_flag) ||
6580 (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
6581 test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))))
6582 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6584 /* fabric is local port if there is no F/FL_Port */
6587 fc_host_fabric_name(shost) = node_name;
6591 * lpfc_get_stats - Return statistical information about the adapter
6592 * @shost: kernel scsi host pointer.
6595 * NULL on error for link down, no mbox pool, sli2 active,
6596 * management not allowed, memory allocation error, or mbox error.
6600 * address of the adapter host statistics
6602 static struct fc_host_statistics *
6603 lpfc_get_stats(struct Scsi_Host *shost)
6605 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6606 struct lpfc_hba *phba = vport->phba;
6607 struct lpfc_sli *psli = &phba->sli;
6608 struct fc_host_statistics *hs = &phba->link_stats;
6609 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6610 LPFC_MBOXQ_t *pmboxq;
6615 * prevent udev from issuing mailbox commands until the port is
6618 if (phba->link_state < LPFC_LINK_DOWN ||
6619 !phba->mbox_mem_pool ||
6620 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6623 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6626 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6629 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6631 pmb = &pmboxq->u.mb;
6632 pmb->mbxCommand = MBX_READ_STATUS;
6633 pmb->mbxOwner = OWN_HOST;
6634 pmboxq->ctx_buf = NULL;
6635 pmboxq->vport = vport;
6637 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
6638 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6639 if (rc != MBX_SUCCESS) {
6640 mempool_free(pmboxq, phba->mbox_mem_pool);
6644 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6645 if (rc != MBX_SUCCESS) {
6646 if (rc != MBX_TIMEOUT)
6647 mempool_free(pmboxq, phba->mbox_mem_pool);
6652 memset(hs, 0, sizeof (struct fc_host_statistics));
6654 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6655 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6658 * The MBX_READ_STATUS returns tx_k_bytes which has to be
6659 * converted to words.
6661 * Check if extended byte flag is set, to know when to collect upper
6662 * bits of 64 bit wide statistics counter.
6664 if (pmb->un.varRdStatus.xkb & RD_ST_XKB) {
6665 hs->tx_words = (u64)
6666 ((((u64)(pmb->un.varRdStatus.xmit_xkb &
6667 RD_ST_XMIT_XKB_MASK) << 32) |
6668 (u64)pmb->un.varRdStatus.xmitByteCnt) *
6670 hs->rx_words = (u64)
6671 ((((u64)(pmb->un.varRdStatus.rcv_xkb &
6672 RD_ST_RCV_XKB_MASK) << 32) |
6673 (u64)pmb->un.varRdStatus.rcvByteCnt) *
6676 hs->tx_words = (uint64_t)
6677 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6679 hs->rx_words = (uint64_t)
6680 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6684 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6685 pmb->mbxCommand = MBX_READ_LNK_STAT;
6686 pmb->mbxOwner = OWN_HOST;
6687 pmboxq->ctx_buf = NULL;
6688 pmboxq->vport = vport;
6690 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
6691 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6692 if (rc != MBX_SUCCESS) {
6693 mempool_free(pmboxq, phba->mbox_mem_pool);
6697 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6698 if (rc != MBX_SUCCESS) {
6699 if (rc != MBX_TIMEOUT)
6700 mempool_free(pmboxq, phba->mbox_mem_pool);
6705 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6706 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6707 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6708 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6709 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6710 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6711 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6713 hs->cn_sig_warn = atomic64_read(&phba->cgn_acqe_stat.warn);
6714 hs->cn_sig_alarm = atomic64_read(&phba->cgn_acqe_stat.alarm);
6716 hs->link_failure_count -= lso->link_failure_count;
6717 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6718 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6719 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6720 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6721 hs->invalid_crc_count -= lso->invalid_crc_count;
6722 hs->error_frames -= lso->error_frames;
6724 if (test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
6726 hs->nos_count = (phba->link_events >> 1);
6727 hs->nos_count -= lso->link_events;
6728 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6729 hs->lip_count = (phba->fc_eventTag >> 1);
6730 hs->lip_count -= lso->link_events;
6734 hs->nos_count = (phba->fc_eventTag >> 1);
6735 hs->nos_count -= lso->link_events;
6738 hs->dumped_frames = -1;
6740 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6742 mempool_free(pmboxq, phba->mbox_mem_pool);
6748 * lpfc_reset_stats - Copy the adapter link stats information
6749 * @shost: kernel scsi host pointer.
6752 lpfc_reset_stats(struct Scsi_Host *shost)
6754 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6755 struct lpfc_hba *phba = vport->phba;
6756 struct lpfc_sli *psli = &phba->sli;
6757 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6758 LPFC_MBOXQ_t *pmboxq;
6762 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6765 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6768 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6770 pmb = &pmboxq->u.mb;
6771 pmb->mbxCommand = MBX_READ_STATUS;
6772 pmb->mbxOwner = OWN_HOST;
6773 pmb->un.varWords[0] = 0x1; /* reset request */
6774 pmboxq->ctx_buf = NULL;
6775 pmboxq->vport = vport;
6777 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
6778 !(psli->sli_flag & LPFC_SLI_ACTIVE)) {
6779 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6780 if (rc != MBX_SUCCESS) {
6781 mempool_free(pmboxq, phba->mbox_mem_pool);
6785 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6786 if (rc != MBX_SUCCESS) {
6787 if (rc != MBX_TIMEOUT)
6788 mempool_free(pmboxq, phba->mbox_mem_pool);
6793 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6794 pmb->mbxCommand = MBX_READ_LNK_STAT;
6795 pmb->mbxOwner = OWN_HOST;
6796 pmboxq->ctx_buf = NULL;
6797 pmboxq->vport = vport;
6799 if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
6800 !(psli->sli_flag & LPFC_SLI_ACTIVE)) {
6801 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6802 if (rc != MBX_SUCCESS) {
6803 mempool_free(pmboxq, phba->mbox_mem_pool);
6807 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6808 if (rc != MBX_SUCCESS) {
6809 if (rc != MBX_TIMEOUT)
6810 mempool_free(pmboxq, phba->mbox_mem_pool);
6815 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6816 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6817 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6818 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6819 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6820 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6821 lso->error_frames = pmb->un.varRdLnk.crcCnt;
6822 if (test_bit(HBA_FCOE_MODE, &phba->hba_flag))
6823 lso->link_events = (phba->link_events >> 1);
6825 lso->link_events = (phba->fc_eventTag >> 1);
6827 atomic64_set(&phba->cgn_acqe_stat.warn, 0);
6828 atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
6830 memset(&shost_to_fc_host(shost)->fpin_stats, 0,
6831 sizeof(shost_to_fc_host(shost)->fpin_stats));
6833 psli->stats_start = ktime_get_seconds();
6835 mempool_free(pmboxq, phba->mbox_mem_pool);
6841 * The LPFC driver treats linkdown handling as target loss events so there
6842 * are no sysfs handlers for link_down_tmo.
6846 * lpfc_get_node_by_target - Return the nodelist for a target
6847 * @starget: kernel scsi target pointer.
6850 * address of the node list if found
6851 * NULL target not found
6853 static struct lpfc_nodelist *
6854 lpfc_get_node_by_target(struct scsi_target *starget)
6856 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6857 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6858 struct lpfc_nodelist *ndlp;
6859 unsigned long iflags;
6861 spin_lock_irqsave(&vport->fc_nodes_list_lock, iflags);
6862 /* Search for this, mapped, target ID */
6863 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6864 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6865 starget->id == ndlp->nlp_sid) {
6866 spin_unlock_irqrestore(&vport->fc_nodes_list_lock,
6871 spin_unlock_irqrestore(&vport->fc_nodes_list_lock, iflags);
6876 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6877 * @starget: kernel scsi target pointer.
6880 lpfc_get_starget_port_id(struct scsi_target *starget)
6882 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6884 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6888 * lpfc_get_starget_node_name - Set the target node name
6889 * @starget: kernel scsi target pointer.
6891 * Description: Set the target node name to the ndlp node name wwn or zero.
6894 lpfc_get_starget_node_name(struct scsi_target *starget)
6896 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6898 fc_starget_node_name(starget) =
6899 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6903 * lpfc_get_starget_port_name - Set the target port name
6904 * @starget: kernel scsi target pointer.
6906 * Description: set the target port name to the ndlp port name wwn or zero.
6909 lpfc_get_starget_port_name(struct scsi_target *starget)
6911 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6913 fc_starget_port_name(starget) =
6914 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6918 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6919 * @rport: fc rport address.
6920 * @timeout: new value for dev loss tmo.
6923 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6924 * dev_loss_tmo to one.
6927 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6929 struct lpfc_rport_data *rdata = rport->dd_data;
6930 struct lpfc_nodelist *ndlp = rdata->pnode;
6931 #if (IS_ENABLED(CONFIG_NVME_FC))
6932 struct lpfc_nvme_rport *nrport = NULL;
6936 rport->dev_loss_tmo = timeout;
6938 rport->dev_loss_tmo = 1;
6941 dev_info(&rport->dev, "Cannot find remote node to "
6942 "set rport dev loss tmo, port_id x%x\n",
6947 #if (IS_ENABLED(CONFIG_NVME_FC))
6948 nrport = lpfc_ndlp_get_nrport(ndlp);
6950 if (nrport && nrport->remoteport)
6951 nvme_fc_set_remoteport_devloss(nrport->remoteport,
6952 rport->dev_loss_tmo);
6957 * lpfc_rport_show_function - Return rport target information
6960 * Macro that uses field to generate a function with the name lpfc_show_rport_
6962 * lpfc_show_rport_##field: returns the bytes formatted in buf
6963 * @cdev: class converted to an fc_rport.
6964 * @buf: on return contains the target_field or zero.
6966 * Returns: size of formatted string.
6968 #define lpfc_rport_show_function(field, format_string, sz, cast) \
6970 lpfc_show_rport_##field (struct device *dev, \
6971 struct device_attribute *attr, \
6974 struct fc_rport *rport = transport_class_to_rport(dev); \
6975 struct lpfc_rport_data *rdata = rport->hostdata; \
6976 return scnprintf(buf, sz, format_string, \
6977 (rdata->target) ? cast rdata->target->field : 0); \
6980 #define lpfc_rport_rd_attr(field, format_string, sz) \
6981 lpfc_rport_show_function(field, format_string, sz, ) \
6982 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6985 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6986 * @fc_vport: The fc_vport who's symbolic name has been changed.
6989 * This function is called by the transport after the @fc_vport's symbolic name
6990 * has been changed. This function re-registers the symbolic name with the
6991 * switch to propagate the change into the fabric if the vport is active.
6994 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6996 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6998 if (vport->port_state == LPFC_VPORT_READY)
6999 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
7003 * lpfc_hba_log_verbose_init - Set hba's log verbose level
7004 * @phba: Pointer to lpfc_hba struct.
7005 * @verbose: Verbose level to set.
7007 * This function is called by the lpfc_get_cfgparam() routine to set the
7008 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
7009 * log message according to the module's lpfc_log_verbose parameter setting
7010 * before hba port or vport created.
7013 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
7015 phba->cfg_log_verbose = verbose;
7018 struct fc_function_template lpfc_transport_functions = {
7019 /* fixed attributes the driver supports */
7020 .show_host_node_name = 1,
7021 .show_host_port_name = 1,
7022 .show_host_supported_classes = 1,
7023 .show_host_supported_fc4s = 1,
7024 .show_host_supported_speeds = 1,
7025 .show_host_maxframe_size = 1,
7027 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7028 .show_host_symbolic_name = 1,
7030 /* dynamic attributes the driver supports */
7031 .get_host_port_id = lpfc_get_host_port_id,
7032 .show_host_port_id = 1,
7034 .get_host_port_type = lpfc_get_host_port_type,
7035 .show_host_port_type = 1,
7037 .get_host_port_state = lpfc_get_host_port_state,
7038 .show_host_port_state = 1,
7040 /* active_fc4s is shown but doesn't change (thus no get function) */
7041 .show_host_active_fc4s = 1,
7043 .get_host_speed = lpfc_get_host_speed,
7044 .show_host_speed = 1,
7046 .get_host_fabric_name = lpfc_get_host_fabric_name,
7047 .show_host_fabric_name = 1,
7050 * The LPFC driver treats linkdown handling as target loss events
7051 * so there are no sysfs handlers for link_down_tmo.
7054 .get_fc_host_stats = lpfc_get_stats,
7055 .reset_fc_host_stats = lpfc_reset_stats,
7057 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7058 .show_rport_maxframe_size = 1,
7059 .show_rport_supported_classes = 1,
7061 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7062 .show_rport_dev_loss_tmo = 1,
7064 .get_starget_port_id = lpfc_get_starget_port_id,
7065 .show_starget_port_id = 1,
7067 .get_starget_node_name = lpfc_get_starget_node_name,
7068 .show_starget_node_name = 1,
7070 .get_starget_port_name = lpfc_get_starget_port_name,
7071 .show_starget_port_name = 1,
7073 .issue_fc_host_lip = lpfc_issue_lip,
7074 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7075 .terminate_rport_io = lpfc_terminate_rport_io,
7077 .dd_fcvport_size = sizeof(struct lpfc_vport *),
7079 .vport_disable = lpfc_vport_disable,
7081 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7083 .bsg_request = lpfc_bsg_request,
7084 .bsg_timeout = lpfc_bsg_timeout,
7087 struct fc_function_template lpfc_vport_transport_functions = {
7088 /* fixed attributes the driver supports */
7089 .show_host_node_name = 1,
7090 .show_host_port_name = 1,
7091 .show_host_supported_classes = 1,
7092 .show_host_supported_fc4s = 1,
7093 .show_host_supported_speeds = 1,
7094 .show_host_maxframe_size = 1,
7096 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7097 .show_host_symbolic_name = 1,
7099 /* dynamic attributes the driver supports */
7100 .get_host_port_id = lpfc_get_host_port_id,
7101 .show_host_port_id = 1,
7103 .get_host_port_type = lpfc_get_host_port_type,
7104 .show_host_port_type = 1,
7106 .get_host_port_state = lpfc_get_host_port_state,
7107 .show_host_port_state = 1,
7109 /* active_fc4s is shown but doesn't change (thus no get function) */
7110 .show_host_active_fc4s = 1,
7112 .get_host_speed = lpfc_get_host_speed,
7113 .show_host_speed = 1,
7115 .get_host_fabric_name = lpfc_get_host_fabric_name,
7116 .show_host_fabric_name = 1,
7119 * The LPFC driver treats linkdown handling as target loss events
7120 * so there are no sysfs handlers for link_down_tmo.
7123 .get_fc_host_stats = lpfc_get_stats,
7124 .reset_fc_host_stats = lpfc_reset_stats,
7126 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7127 .show_rport_maxframe_size = 1,
7128 .show_rport_supported_classes = 1,
7130 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7131 .show_rport_dev_loss_tmo = 1,
7133 .get_starget_port_id = lpfc_get_starget_port_id,
7134 .show_starget_port_id = 1,
7136 .get_starget_node_name = lpfc_get_starget_node_name,
7137 .show_starget_node_name = 1,
7139 .get_starget_port_name = lpfc_get_starget_port_name,
7140 .show_starget_port_name = 1,
7142 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7143 .terminate_rport_io = lpfc_terminate_rport_io,
7145 .vport_disable = lpfc_vport_disable,
7147 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7151 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7153 * @phba: lpfc_hba pointer.
7156 lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7158 /* If the adapter supports FCoE mode */
7159 switch (phba->pcidev->device) {
7160 case PCI_DEVICE_ID_SKYHAWK:
7161 case PCI_DEVICE_ID_SKYHAWK_VF:
7162 case PCI_DEVICE_ID_LANCER_FCOE:
7163 case PCI_DEVICE_ID_LANCER_FCOE_VF:
7164 case PCI_DEVICE_ID_ZEPHYR_DCSP:
7165 case PCI_DEVICE_ID_TIGERSHARK:
7166 case PCI_DEVICE_ID_TOMCAT:
7167 set_bit(HBA_FCOE_MODE, &phba->hba_flag);
7170 /* for others, clear the flag */
7171 clear_bit(HBA_FCOE_MODE, &phba->hba_flag);
7176 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7177 * @phba: lpfc_hba pointer.
7180 lpfc_get_cfgparam(struct lpfc_hba *phba)
7182 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7183 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
7184 lpfc_ns_query_init(phba, lpfc_ns_query);
7185 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7186 lpfc_cr_delay_init(phba, lpfc_cr_delay);
7187 lpfc_cr_count_init(phba, lpfc_cr_count);
7188 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
7189 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7190 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7191 lpfc_ack0_init(phba, lpfc_ack0);
7192 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
7193 lpfc_topology_init(phba, lpfc_topology);
7194 lpfc_link_speed_init(phba, lpfc_link_speed);
7195 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
7196 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
7197 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7198 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
7199 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
7200 lpfc_fcp_wait_abts_rsp_init(phba, lpfc_fcp_wait_abts_rsp);
7201 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7202 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
7203 lpfc_use_msi_init(phba, lpfc_use_msi);
7204 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
7205 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
7206 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7207 lpfc_force_rscn_init(phba, lpfc_force_rscn);
7208 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7209 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
7210 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
7211 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7212 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
7214 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7216 lpfc_max_vmid_init(phba, lpfc_max_vmid);
7217 lpfc_vmid_inactivity_timeout_init(phba, lpfc_vmid_inactivity_timeout);
7218 lpfc_vmid_app_header_init(phba, lpfc_vmid_app_header);
7219 lpfc_vmid_priority_tagging_init(phba, lpfc_vmid_priority_tagging);
7220 if (phba->sli_rev != LPFC_SLI_REV4)
7221 phba->cfg_EnableXLane = 0;
7222 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
7224 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7225 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7226 phba->cfg_oas_lun_state = 0;
7227 phba->cfg_oas_lun_status = 0;
7228 phba->cfg_oas_flags = 0;
7229 phba->cfg_oas_priority = 0;
7230 lpfc_enable_bg_init(phba, lpfc_enable_bg);
7231 lpfc_prot_mask_init(phba, lpfc_prot_mask);
7232 lpfc_prot_guard_init(phba, lpfc_prot_guard);
7233 if (phba->sli_rev == LPFC_SLI_REV4)
7236 phba->cfg_poll = lpfc_poll;
7238 /* Get the function mode */
7239 lpfc_get_hba_function_mode(phba);
7241 /* BlockGuard allowed for FC only. */
7242 if (phba->cfg_enable_bg && test_bit(HBA_FCOE_MODE, &phba->hba_flag)) {
7243 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7244 "0581 BlockGuard feature not supported\n");
7245 /* If set, clear the BlockGuard support param */
7246 phba->cfg_enable_bg = 0;
7247 } else if (phba->cfg_enable_bg) {
7248 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
7251 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
7253 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
7254 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
7255 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
7257 /* Initialize first burst. Target vs Initiator are different. */
7258 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
7259 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
7260 lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
7261 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
7262 lpfc_irq_chann_init(phba, lpfc_irq_chann);
7263 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7264 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7265 lpfc_enable_mi_init(phba, lpfc_enable_mi);
7267 phba->cgn_p.cgn_param_mode = LPFC_CFG_OFF;
7268 phba->cmf_active_mode = LPFC_CFG_OFF;
7269 if (lpfc_fabric_cgn_frequency > EDC_CG_SIGFREQ_CNT_MAX ||
7270 lpfc_fabric_cgn_frequency < EDC_CG_SIGFREQ_CNT_MIN)
7271 lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
7273 if (phba->sli_rev != LPFC_SLI_REV4) {
7274 /* NVME only supported on SLI4 */
7275 phba->nvmet_support = 0;
7276 phba->cfg_nvmet_mrq = 0;
7277 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7278 phba->cfg_enable_bbcr = 0;
7279 phba->cfg_xri_rebalancing = 0;
7281 /* We MUST have FCP support */
7282 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7283 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7286 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7288 phba->cfg_enable_pbde = 0;
7290 /* A value of 0 means use the number of CPUs found in the system */
7291 if (phba->cfg_hdw_queue == 0)
7292 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7293 if (phba->cfg_irq_chann == 0)
7294 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7295 if (phba->cfg_irq_chann > phba->cfg_hdw_queue &&
7296 phba->sli_rev == LPFC_SLI_REV4)
7297 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7299 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7300 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7301 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7302 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7303 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7304 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7305 lpfc_sli_mode_init(phba, lpfc_sli_mode);
7306 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7307 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7308 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7309 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7315 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7316 * dependencies between protocols and roles.
7317 * @phba: lpfc_hba pointer.
7320 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7324 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu) {
7325 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7328 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu) {
7329 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7332 if (phba->cfg_irq_chann > phba->cfg_hdw_queue) {
7333 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7337 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7338 "2006 Reducing Queues - CPU limitation: "
7340 phba->cfg_irq_chann,
7341 phba->cfg_hdw_queue);
7343 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7344 phba->nvmet_support) {
7345 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7347 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7348 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7349 "NVME Target PRLI ACC enable_fb ",
7350 phba->cfg_nvme_enable_fb,
7351 phba->cfg_nvmet_fb_size,
7352 LPFC_NVMET_FB_SZ_MAX);
7354 if (phba->cfg_nvme_enable_fb == 0)
7355 phba->cfg_nvmet_fb_size = 0;
7357 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7358 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7361 if (!phba->cfg_nvmet_mrq)
7362 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7364 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7365 if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
7366 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7367 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7368 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7369 phba->cfg_nvmet_mrq);
7371 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7372 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7375 /* Not NVME Target mode. Turn off Target parameters. */
7376 phba->nvmet_support = 0;
7377 phba->cfg_nvmet_mrq = 0;
7378 phba->cfg_nvmet_fb_size = 0;
7383 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7384 * @vport: lpfc_vport pointer.
7387 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7389 lpfc_log_verbose_init(vport, lpfc_log_verbose);
7390 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7391 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7392 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7393 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7394 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7395 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7396 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7397 lpfc_use_adisc_init(vport, lpfc_use_adisc);
7398 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7399 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7400 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7401 lpfc_max_luns_init(vport, lpfc_max_luns);
7402 lpfc_scan_down_init(vport, lpfc_scan_down);
7403 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);