1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 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
61 * Write key size should be multiple of 4. If write key is changed
62 * make sure that library write key is also changed.
64 #define LPFC_REG_WRITE_KEY_SIZE 4
65 #define LPFC_REG_WRITE_KEY "EMLX"
67 const char *const trunk_errmsg[] = { /* map errcode */
68 "", /* There is no such error code at index 0*/
69 "link negotiated speed does not match existing"
70 " trunk - link was \"low\" speed",
71 "link negotiated speed does not match"
72 " existing trunk - link was \"middle\" speed",
73 "link negotiated speed does not match existing"
74 " trunk - link was \"high\" speed",
75 "Attached to non-trunking port - F_Port",
76 "Attached to non-trunking port - N_Port",
77 "FLOGI response timeout",
78 "non-FLOGI frame received",
79 "Invalid FLOGI response",
80 "Trunking initialization protocol",
81 "Trunk peer device mismatch",
85 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
86 * @incr: integer to convert.
87 * @hdw: ascii string holding converted integer plus a string terminator.
90 * JEDEC Joint Electron Device Engineering Council.
91 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
92 * character string. The string is then terminated with a NULL in byte 9.
93 * Hex 0-9 becomes ascii '0' to '9'.
94 * Hex a-f becomes ascii '=' to 'B' capital B.
97 * Coded for 32 bit integers only.
100 lpfc_jedec_to_ascii(int incr, char hdw[])
103 for (i = 0; i < 8; i++) {
106 hdw[7 - i] = 0x30 + j;
108 hdw[7 - i] = 0x61 + j - 10;
116 * lpfc_drvr_version_show - Return the Emulex driver string with version number
117 * @dev: class unused variable.
118 * @attr: device attribute, not used.
119 * @buf: on return contains the module description text.
121 * Returns: size of formatted string.
124 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
127 return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
131 * lpfc_enable_fip_show - Return the fip mode of the HBA
132 * @dev: class unused variable.
133 * @attr: device attribute, not used.
134 * @buf: on return contains the module description text.
136 * Returns: size of formatted string.
139 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
142 struct Scsi_Host *shost = class_to_shost(dev);
143 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
144 struct lpfc_hba *phba = vport->phba;
146 if (phba->hba_flag & HBA_FIP_SUPPORT)
147 return scnprintf(buf, PAGE_SIZE, "1\n");
149 return scnprintf(buf, PAGE_SIZE, "0\n");
153 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
156 struct Scsi_Host *shost = class_to_shost(dev);
157 struct lpfc_vport *vport = shost_priv(shost);
158 struct lpfc_hba *phba = vport->phba;
159 struct lpfc_nvmet_tgtport *tgtp;
160 struct nvme_fc_local_port *localport;
161 struct lpfc_nvme_lport *lport;
162 struct lpfc_nvme_rport *rport;
163 struct lpfc_nodelist *ndlp;
164 struct nvme_fc_remote_port *nrport;
165 struct lpfc_fc4_ctrl_stat *cstat;
166 uint64_t data1, data2, data3;
167 uint64_t totin, totout, tot;
171 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
173 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
174 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
177 if (phba->nvmet_support) {
178 if (!phba->targetport) {
179 len = scnprintf(buf, PAGE_SIZE,
180 "NVME Target: x%llx is not allocated\n",
181 wwn_to_u64(vport->fc_portname.u.wwn));
184 /* Port state is only one of two values for now. */
185 if (phba->targetport->port_id)
186 statep = "REGISTERED";
189 scnprintf(tmp, sizeof(tmp),
190 "NVME Target Enabled State %s\n",
192 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
195 scnprintf(tmp, sizeof(tmp),
196 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
199 wwn_to_u64(vport->fc_portname.u.wwn),
200 wwn_to_u64(vport->fc_nodename.u.wwn),
201 phba->targetport->port_id);
202 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
205 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
209 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
210 scnprintf(tmp, sizeof(tmp),
211 "LS: Rcv %08x Drop %08x Abort %08x\n",
212 atomic_read(&tgtp->rcv_ls_req_in),
213 atomic_read(&tgtp->rcv_ls_req_drop),
214 atomic_read(&tgtp->xmt_ls_abort));
215 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
218 if (atomic_read(&tgtp->rcv_ls_req_in) !=
219 atomic_read(&tgtp->rcv_ls_req_out)) {
220 scnprintf(tmp, sizeof(tmp),
221 "Rcv LS: in %08x != out %08x\n",
222 atomic_read(&tgtp->rcv_ls_req_in),
223 atomic_read(&tgtp->rcv_ls_req_out));
224 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
228 scnprintf(tmp, sizeof(tmp),
229 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
230 atomic_read(&tgtp->xmt_ls_rsp),
231 atomic_read(&tgtp->xmt_ls_drop),
232 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
233 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
236 scnprintf(tmp, sizeof(tmp),
237 "LS: RSP Abort %08x xb %08x Err %08x\n",
238 atomic_read(&tgtp->xmt_ls_rsp_aborted),
239 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
240 atomic_read(&tgtp->xmt_ls_rsp_error));
241 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
244 scnprintf(tmp, sizeof(tmp),
245 "FCP: Rcv %08x Defer %08x Release %08x "
247 atomic_read(&tgtp->rcv_fcp_cmd_in),
248 atomic_read(&tgtp->rcv_fcp_cmd_defer),
249 atomic_read(&tgtp->xmt_fcp_release),
250 atomic_read(&tgtp->rcv_fcp_cmd_drop));
251 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
254 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
255 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
256 scnprintf(tmp, sizeof(tmp),
257 "Rcv FCP: in %08x != out %08x\n",
258 atomic_read(&tgtp->rcv_fcp_cmd_in),
259 atomic_read(&tgtp->rcv_fcp_cmd_out));
260 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
264 scnprintf(tmp, sizeof(tmp),
265 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
267 atomic_read(&tgtp->xmt_fcp_read),
268 atomic_read(&tgtp->xmt_fcp_read_rsp),
269 atomic_read(&tgtp->xmt_fcp_write),
270 atomic_read(&tgtp->xmt_fcp_rsp),
271 atomic_read(&tgtp->xmt_fcp_drop));
272 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
275 scnprintf(tmp, sizeof(tmp),
276 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
277 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
278 atomic_read(&tgtp->xmt_fcp_rsp_error),
279 atomic_read(&tgtp->xmt_fcp_rsp_drop));
280 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
283 scnprintf(tmp, sizeof(tmp),
284 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
285 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
286 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
287 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
288 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
291 scnprintf(tmp, sizeof(tmp),
292 "ABORT: Xmt %08x Cmpl %08x\n",
293 atomic_read(&tgtp->xmt_fcp_abort),
294 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
295 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
298 scnprintf(tmp, sizeof(tmp),
299 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
300 atomic_read(&tgtp->xmt_abort_sol),
301 atomic_read(&tgtp->xmt_abort_unsol),
302 atomic_read(&tgtp->xmt_abort_rsp),
303 atomic_read(&tgtp->xmt_abort_rsp_error));
304 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
307 scnprintf(tmp, sizeof(tmp),
308 "DELAY: ctx %08x fod %08x wqfull %08x\n",
309 atomic_read(&tgtp->defer_ctx),
310 atomic_read(&tgtp->defer_fod),
311 atomic_read(&tgtp->defer_wqfull));
312 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
315 /* Calculate outstanding IOs */
316 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
317 tot += atomic_read(&tgtp->xmt_fcp_release);
318 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
320 scnprintf(tmp, sizeof(tmp),
321 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
322 "CTX Outstanding %08llx\n\n",
323 phba->sli4_hba.nvmet_xri_cnt,
324 phba->sli4_hba.nvmet_io_wait_cnt,
325 phba->sli4_hba.nvmet_io_wait_total,
327 strlcat(buf, tmp, PAGE_SIZE);
331 localport = vport->localport;
333 len = scnprintf(buf, PAGE_SIZE,
334 "NVME Initiator x%llx is not allocated\n",
335 wwn_to_u64(vport->fc_portname.u.wwn));
338 lport = (struct lpfc_nvme_lport *)localport->private;
339 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
342 scnprintf(tmp, sizeof(tmp),
343 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
345 phba->sli4_hba.max_cfg_param.max_xri,
346 phba->sli4_hba.io_xri_max,
347 lpfc_sli4_get_els_iocb_cnt(phba));
348 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
351 /* Port state is only one of two values for now. */
352 if (localport->port_id)
357 scnprintf(tmp, sizeof(tmp),
358 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
361 wwn_to_u64(vport->fc_portname.u.wwn),
362 wwn_to_u64(vport->fc_nodename.u.wwn),
363 localport->port_id, statep);
364 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
367 spin_lock_irq(shost->host_lock);
369 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
371 spin_lock(&ndlp->lock);
372 rport = lpfc_ndlp_get_nrport(ndlp);
374 nrport = rport->remoteport;
375 spin_unlock(&ndlp->lock);
379 /* Port state is only one of two values for now. */
380 switch (nrport->port_state) {
381 case FC_OBJSTATE_ONLINE:
384 case FC_OBJSTATE_UNKNOWN:
388 statep = "UNSUPPORTED";
392 /* Tab in to show lport ownership. */
393 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
394 goto unlock_buf_done;
395 if (phba->brd_no >= 10) {
396 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
397 goto unlock_buf_done;
400 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
402 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
403 goto unlock_buf_done;
405 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
407 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
408 goto unlock_buf_done;
410 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
412 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
413 goto unlock_buf_done;
415 /* An NVME rport can have multiple roles. */
416 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
417 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
418 goto unlock_buf_done;
420 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
421 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
422 goto unlock_buf_done;
424 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
425 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
426 goto unlock_buf_done;
428 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
429 FC_PORT_ROLE_NVME_TARGET |
430 FC_PORT_ROLE_NVME_DISCOVERY)) {
431 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
433 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
434 goto unlock_buf_done;
437 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
438 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
439 goto unlock_buf_done;
441 spin_unlock_irq(shost->host_lock);
446 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
449 scnprintf(tmp, sizeof(tmp),
450 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
451 atomic_read(&lport->fc4NvmeLsRequests),
452 atomic_read(&lport->fc4NvmeLsCmpls),
453 atomic_read(&lport->xmt_ls_abort));
454 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
457 scnprintf(tmp, sizeof(tmp),
458 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
459 atomic_read(&lport->xmt_ls_err),
460 atomic_read(&lport->cmpl_ls_xb),
461 atomic_read(&lport->cmpl_ls_err));
462 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
467 for (i = 0; i < phba->cfg_hdw_queue; i++) {
468 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
469 tot = cstat->io_cmpls;
471 data1 = cstat->input_requests;
472 data2 = cstat->output_requests;
473 data3 = cstat->control_requests;
474 totout += (data1 + data2 + data3);
476 scnprintf(tmp, sizeof(tmp),
477 "Total FCP Cmpl %016llx Issue %016llx "
479 totin, totout, totout - totin);
480 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
483 scnprintf(tmp, sizeof(tmp),
484 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
485 "wqerr %08x err %08x\n",
486 atomic_read(&lport->xmt_fcp_abort),
487 atomic_read(&lport->xmt_fcp_noxri),
488 atomic_read(&lport->xmt_fcp_bad_ndlp),
489 atomic_read(&lport->xmt_fcp_qdepth),
490 atomic_read(&lport->xmt_fcp_wqerr),
491 atomic_read(&lport->xmt_fcp_err));
492 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
495 scnprintf(tmp, sizeof(tmp),
496 "FCP CMPL: xb %08x Err %08x\n",
497 atomic_read(&lport->cmpl_fcp_xb),
498 atomic_read(&lport->cmpl_fcp_err));
499 strlcat(buf, tmp, PAGE_SIZE);
501 /* host_lock is already unlocked. */
505 spin_unlock_irq(shost->host_lock);
508 len = strnlen(buf, PAGE_SIZE);
510 if (unlikely(len >= (PAGE_SIZE - 1))) {
511 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
512 "6314 Catching potential buffer "
513 "overflow > PAGE_SIZE = %lu bytes\n",
515 strlcpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_NVME_INFO_MORE_STR),
516 LPFC_NVME_INFO_MORE_STR,
517 sizeof(LPFC_NVME_INFO_MORE_STR) + 1);
524 lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
527 struct Scsi_Host *shost = class_to_shost(dev);
528 struct lpfc_vport *vport = shost_priv(shost);
529 struct lpfc_hba *phba = vport->phba;
531 struct lpfc_fc4_ctrl_stat *cstat;
532 u64 data1, data2, data3;
533 u64 tot, totin, totout;
535 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
537 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
538 (phba->sli_rev != LPFC_SLI_REV4))
541 scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
545 for (i = 0; i < phba->cfg_hdw_queue; i++) {
546 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
547 tot = cstat->io_cmpls;
549 data1 = cstat->input_requests;
550 data2 = cstat->output_requests;
551 data3 = cstat->control_requests;
552 totout += (data1 + data2 + data3);
554 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
555 "IO %016llx ", i, data1, data2, data3);
556 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
559 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
560 tot, ((data1 + data2 + data3) - tot));
561 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
564 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
565 "OutIO %016llx\n", totin, totout, totout - totin);
566 strlcat(buf, tmp, PAGE_SIZE);
569 len = strnlen(buf, PAGE_SIZE);
575 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
578 struct Scsi_Host *shost = class_to_shost(dev);
579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
580 struct lpfc_hba *phba = vport->phba;
582 if (phba->cfg_enable_bg) {
583 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
584 return scnprintf(buf, PAGE_SIZE,
585 "BlockGuard Enabled\n");
587 return scnprintf(buf, PAGE_SIZE,
588 "BlockGuard Not Supported\n");
590 return scnprintf(buf, PAGE_SIZE,
591 "BlockGuard Disabled\n");
595 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
598 struct Scsi_Host *shost = class_to_shost(dev);
599 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
600 struct lpfc_hba *phba = vport->phba;
602 return scnprintf(buf, PAGE_SIZE, "%llu\n",
603 (unsigned long long)phba->bg_guard_err_cnt);
607 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
610 struct Scsi_Host *shost = class_to_shost(dev);
611 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
612 struct lpfc_hba *phba = vport->phba;
614 return scnprintf(buf, PAGE_SIZE, "%llu\n",
615 (unsigned long long)phba->bg_apptag_err_cnt);
619 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
622 struct Scsi_Host *shost = class_to_shost(dev);
623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
624 struct lpfc_hba *phba = vport->phba;
626 return scnprintf(buf, PAGE_SIZE, "%llu\n",
627 (unsigned long long)phba->bg_reftag_err_cnt);
631 * lpfc_info_show - Return some pci info about the host in ascii
632 * @dev: class converted to a Scsi_host structure.
633 * @attr: device attribute, not used.
634 * @buf: on return contains the formatted text from lpfc_info().
636 * Returns: size of formatted string.
639 lpfc_info_show(struct device *dev, struct device_attribute *attr,
642 struct Scsi_Host *host = class_to_shost(dev);
644 return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
648 * lpfc_serialnum_show - Return the hba serial number in ascii
649 * @dev: class converted to a Scsi_host structure.
650 * @attr: device attribute, not used.
651 * @buf: on return contains the formatted text serial number.
653 * Returns: size of formatted string.
656 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
659 struct Scsi_Host *shost = class_to_shost(dev);
660 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
661 struct lpfc_hba *phba = vport->phba;
663 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
667 * lpfc_temp_sensor_show - Return the temperature sensor level
668 * @dev: class converted to a Scsi_host structure.
669 * @attr: device attribute, not used.
670 * @buf: on return contains the formatted support level.
673 * Returns a number indicating the temperature sensor level currently
674 * supported, zero or one in ascii.
676 * Returns: size of formatted string.
679 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
682 struct Scsi_Host *shost = class_to_shost(dev);
683 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
684 struct lpfc_hba *phba = vport->phba;
685 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
689 * lpfc_modeldesc_show - Return the model description of the hba
690 * @dev: class converted to a Scsi_host structure.
691 * @attr: device attribute, not used.
692 * @buf: on return contains the scsi vpd model description.
694 * Returns: size of formatted string.
697 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
700 struct Scsi_Host *shost = class_to_shost(dev);
701 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
702 struct lpfc_hba *phba = vport->phba;
704 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
708 * lpfc_modelname_show - Return the model name of the hba
709 * @dev: class converted to a Scsi_host structure.
710 * @attr: device attribute, not used.
711 * @buf: on return contains the scsi vpd model name.
713 * Returns: size of formatted string.
716 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
719 struct Scsi_Host *shost = class_to_shost(dev);
720 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
721 struct lpfc_hba *phba = vport->phba;
723 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
727 * lpfc_programtype_show - Return the program type of the hba
728 * @dev: class converted to a Scsi_host structure.
729 * @attr: device attribute, not used.
730 * @buf: on return contains the scsi vpd program type.
732 * Returns: size of formatted string.
735 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
738 struct Scsi_Host *shost = class_to_shost(dev);
739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
740 struct lpfc_hba *phba = vport->phba;
742 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
746 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
747 * @dev: class converted to a Scsi_host structure.
748 * @attr: device attribute, not used.
749 * @buf: on return contains the Menlo Maintenance sli flag.
751 * Returns: size of formatted string.
754 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
756 struct Scsi_Host *shost = class_to_shost(dev);
757 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
758 struct lpfc_hba *phba = vport->phba;
760 return scnprintf(buf, PAGE_SIZE, "%d\n",
761 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
765 * lpfc_vportnum_show - Return the port number in ascii of the hba
766 * @dev: class converted to a Scsi_host structure.
767 * @attr: device attribute, not used.
768 * @buf: on return contains scsi vpd program type.
770 * Returns: size of formatted string.
773 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
776 struct Scsi_Host *shost = class_to_shost(dev);
777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
778 struct lpfc_hba *phba = vport->phba;
780 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
784 * lpfc_fwrev_show - Return the firmware rev running in the hba
785 * @dev: class converted to a Scsi_host structure.
786 * @attr: device attribute, not used.
787 * @buf: on return contains the scsi vpd program type.
789 * Returns: size of formatted string.
792 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
795 struct Scsi_Host *shost = class_to_shost(dev);
796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
797 struct lpfc_hba *phba = vport->phba;
800 char fwrev[FW_REV_STR_SIZE];
803 lpfc_decode_firmware_rev(phba, fwrev, 1);
804 if_type = phba->sli4_hba.pc_sli4_params.if_type;
805 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
807 if (phba->sli_rev < LPFC_SLI_REV4)
808 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
809 fwrev, phba->sli_rev);
811 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
812 fwrev, phba->sli_rev, if_type, sli_family);
818 * lpfc_hdw_show - Return the jedec information about the hba
819 * @dev: class converted to a Scsi_host structure.
820 * @attr: device attribute, not used.
821 * @buf: on return contains the scsi vpd program type.
823 * Returns: size of formatted string.
826 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
829 struct Scsi_Host *shost = class_to_shost(dev);
830 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
831 struct lpfc_hba *phba = vport->phba;
832 lpfc_vpd_t *vp = &phba->vpd;
834 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
835 return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
836 vp->rev.smRev, vp->rev.smFwRev);
840 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
841 * @dev: class converted to a Scsi_host structure.
842 * @attr: device attribute, not used.
843 * @buf: on return contains the ROM and FCode ascii strings.
845 * Returns: size of formatted string.
848 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
851 struct Scsi_Host *shost = class_to_shost(dev);
852 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
853 struct lpfc_hba *phba = vport->phba;
854 char fwrev[FW_REV_STR_SIZE];
856 if (phba->sli_rev < LPFC_SLI_REV4)
857 return scnprintf(buf, PAGE_SIZE, "%s\n",
858 phba->OptionROMVersion);
860 lpfc_decode_firmware_rev(phba, fwrev, 1);
861 return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
865 * lpfc_link_state_show - Return the link state of the port
866 * @dev: class converted to a Scsi_host structure.
867 * @attr: device attribute, not used.
868 * @buf: on return contains text describing the state of the link.
871 * The switch statement has no default so zero will be returned.
873 * Returns: size of formatted string.
876 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
879 struct Scsi_Host *shost = class_to_shost(dev);
880 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
881 struct lpfc_hba *phba = vport->phba;
884 switch (phba->link_state) {
885 case LPFC_LINK_UNKNOWN:
886 case LPFC_WARM_START:
887 case LPFC_INIT_START:
888 case LPFC_INIT_MBX_CMDS:
891 if (phba->hba_flag & LINK_DISABLED)
892 len += scnprintf(buf + len, PAGE_SIZE-len,
893 "Link Down - User disabled\n");
895 len += scnprintf(buf + len, PAGE_SIZE-len,
901 len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
903 switch (vport->port_state) {
904 case LPFC_LOCAL_CFG_LINK:
905 len += scnprintf(buf + len, PAGE_SIZE-len,
906 "Configuring Link\n");
910 case LPFC_FABRIC_CFG_LINK:
913 case LPFC_BUILD_DISC_LIST:
915 len += scnprintf(buf + len, PAGE_SIZE - len,
918 case LPFC_VPORT_READY:
919 len += scnprintf(buf + len, PAGE_SIZE - len,
923 case LPFC_VPORT_FAILED:
924 len += scnprintf(buf + len, PAGE_SIZE - len,
928 case LPFC_VPORT_UNKNOWN:
929 len += scnprintf(buf + len, PAGE_SIZE - len,
933 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
934 len += scnprintf(buf + len, PAGE_SIZE-len,
935 " Menlo Maint Mode\n");
936 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
937 if (vport->fc_flag & FC_PUBLIC_LOOP)
938 len += scnprintf(buf + len, PAGE_SIZE-len,
941 len += scnprintf(buf + len, PAGE_SIZE-len,
944 if (vport->fc_flag & FC_FABRIC)
945 len += scnprintf(buf + len, PAGE_SIZE-len,
948 len += scnprintf(buf + len, PAGE_SIZE-len,
953 if ((phba->sli_rev == LPFC_SLI_REV4) &&
954 ((bf_get(lpfc_sli_intf_if_type,
955 &phba->sli4_hba.sli_intf) ==
956 LPFC_SLI_INTF_IF_TYPE_6))) {
957 struct lpfc_trunk_link link = phba->trunk_link;
959 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
960 len += scnprintf(buf + len, PAGE_SIZE - len,
961 "Trunk port 0: Link %s %s\n",
962 (link.link0.state == LPFC_LINK_UP) ?
964 trunk_errmsg[link.link0.fault]);
966 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
967 len += scnprintf(buf + len, PAGE_SIZE - len,
968 "Trunk port 1: Link %s %s\n",
969 (link.link1.state == LPFC_LINK_UP) ?
971 trunk_errmsg[link.link1.fault]);
973 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
974 len += scnprintf(buf + len, PAGE_SIZE - len,
975 "Trunk port 2: Link %s %s\n",
976 (link.link2.state == LPFC_LINK_UP) ?
978 trunk_errmsg[link.link2.fault]);
980 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
981 len += scnprintf(buf + len, PAGE_SIZE - len,
982 "Trunk port 3: Link %s %s\n",
983 (link.link3.state == LPFC_LINK_UP) ?
985 trunk_errmsg[link.link3.fault]);
993 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
994 * @dev: class unused variable.
995 * @attr: device attribute, not used.
996 * @buf: on return contains the module description text.
998 * Returns: size of formatted string.
1001 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
1004 struct Scsi_Host *shost = class_to_shost(dev);
1005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1006 struct lpfc_hba *phba = vport->phba;
1008 if (phba->sli_rev < LPFC_SLI_REV4)
1009 return scnprintf(buf, PAGE_SIZE, "fc\n");
1011 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
1012 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
1013 return scnprintf(buf, PAGE_SIZE, "fcoe\n");
1014 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
1015 return scnprintf(buf, PAGE_SIZE, "fc\n");
1017 return scnprintf(buf, PAGE_SIZE, "unknown\n");
1021 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1022 * (OAS) is supported.
1023 * @dev: class unused variable.
1024 * @attr: device attribute, not used.
1025 * @buf: on return contains the module description text.
1027 * Returns: size of formatted string.
1030 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1033 struct Scsi_Host *shost = class_to_shost(dev);
1034 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1035 struct lpfc_hba *phba = vport->phba;
1037 return scnprintf(buf, PAGE_SIZE, "%d\n",
1038 phba->sli4_hba.pc_sli4_params.oas_supported);
1042 * lpfc_link_state_store - Transition the link_state on an HBA port
1043 * @dev: class device that is converted into a Scsi_host.
1044 * @attr: device attribute, not used.
1045 * @buf: one or more lpfc_polling_flags values.
1049 * -EINVAL if the buffer is not "up" or "down"
1050 * return from link state change function if non-zero
1051 * length of the buf on success
1054 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1055 const char *buf, size_t count)
1057 struct Scsi_Host *shost = class_to_shost(dev);
1058 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1059 struct lpfc_hba *phba = vport->phba;
1061 int status = -EINVAL;
1063 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1064 (phba->link_state == LPFC_LINK_DOWN))
1065 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
1066 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1067 (phba->link_state >= LPFC_LINK_UP))
1068 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1077 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1078 * @dev: class device that is converted into a Scsi_host.
1079 * @attr: device attribute, not used.
1080 * @buf: on return contains the sum of fc mapped and unmapped.
1083 * Returns the ascii text number of the sum of the fc mapped and unmapped
1086 * Returns: size of formatted string.
1089 lpfc_num_discovered_ports_show(struct device *dev,
1090 struct device_attribute *attr, char *buf)
1092 struct Scsi_Host *shost = class_to_shost(dev);
1093 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1095 return scnprintf(buf, PAGE_SIZE, "%d\n",
1096 vport->fc_map_cnt + vport->fc_unmap_cnt);
1100 * lpfc_issue_lip - Misnomer, name carried over from long ago
1101 * @shost: Scsi_Host pointer.
1104 * Bring the link down gracefully then re-init the link. The firmware will
1105 * re-init the fiber channel interface as required. Does not issue a LIP.
1108 * -EPERM port offline or management commands are being blocked
1109 * -ENOMEM cannot allocate memory for the mailbox command
1110 * -EIO error sending the mailbox command
1114 lpfc_issue_lip(struct Scsi_Host *shost)
1116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1117 struct lpfc_hba *phba = vport->phba;
1118 LPFC_MBOXQ_t *pmboxq;
1119 int mbxstatus = MBXERR_ERROR;
1122 * If the link is offline, disabled or BLOCK_MGMT_IO
1123 * it doesn't make any sense to allow issue_lip
1125 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1126 (phba->hba_flag & LINK_DISABLED) ||
1127 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1130 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1135 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1136 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1137 pmboxq->u.mb.mbxOwner = OWN_HOST;
1139 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1141 if ((mbxstatus == MBX_SUCCESS) &&
1142 (pmboxq->u.mb.mbxStatus == 0 ||
1143 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1144 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1145 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1146 phba->cfg_link_speed);
1147 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1148 phba->fc_ratov * 2);
1149 if ((mbxstatus == MBX_SUCCESS) &&
1150 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1151 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1152 "2859 SLI authentication is required "
1153 "for INIT_LINK but has not done yet\n");
1156 lpfc_set_loopback_flag(phba);
1157 if (mbxstatus != MBX_TIMEOUT)
1158 mempool_free(pmboxq, phba->mbox_mem_pool);
1160 if (mbxstatus == MBXERR_ERROR)
1167 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1171 spin_lock_irq(lock);
1172 while (!list_empty(q)) {
1173 spin_unlock_irq(lock);
1175 if (cnt++ > 250) { /* 5 secs */
1176 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1177 "0466 Outstanding IO when "
1178 "bringing Adapter offline\n");
1181 spin_lock_irq(lock);
1183 spin_unlock_irq(lock);
1188 * lpfc_do_offline - Issues a mailbox command to bring the link down
1189 * @phba: lpfc_hba pointer.
1190 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1193 * Assumes any error from lpfc_do_offline() will be negative.
1194 * Can wait up to 5 seconds for the port ring buffers count
1195 * to reach zero, prints a warning if it is not zero and continues.
1196 * lpfc_workq_post_event() returns a non-zero return code if call fails.
1199 * -EIO error posting the event
1203 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1205 struct completion online_compl;
1206 struct lpfc_queue *qp = NULL;
1207 struct lpfc_sli_ring *pring;
1208 struct lpfc_sli *psli;
1213 init_completion(&online_compl);
1214 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1215 LPFC_EVT_OFFLINE_PREP);
1219 wait_for_completion(&online_compl);
1227 * If freeing the queues have already started, don't access them.
1228 * Otherwise set FREE_WAIT to indicate that queues are being used
1229 * to hold the freeing process until we finish.
1231 spin_lock_irq(&phba->hbalock);
1232 if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {
1233 psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;
1235 spin_unlock_irq(&phba->hbalock);
1238 spin_unlock_irq(&phba->hbalock);
1240 /* Wait a little for things to settle down, but not
1241 * long enough for dev loss timeout to expire.
1243 if (phba->sli_rev != LPFC_SLI_REV4) {
1244 for (i = 0; i < psli->num_rings; i++) {
1245 pring = &psli->sli3_ring[i];
1246 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1251 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1255 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1261 spin_lock_irq(&phba->hbalock);
1262 psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;
1263 spin_unlock_irq(&phba->hbalock);
1266 init_completion(&online_compl);
1267 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1271 wait_for_completion(&online_compl);
1280 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1281 * @phba: lpfc_hba pointer.
1284 * Issues a PCI secondary bus reset for the phba->pcidev.
1287 * First walks the bus_list to ensure only PCI devices with Emulex
1288 * vendor id, device ids that support hot reset, only one occurrence
1289 * of function 0, and all ports on the bus are in offline mode to ensure the
1290 * hot reset only affects one valid HBA.
1293 * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1294 * -ENODEV, NULL ptr to pcidev
1295 * -EBADSLT, detected invalid device
1296 * -EBUSY, port is not in offline state
1300 lpfc_reset_pci_bus(struct lpfc_hba *phba)
1302 struct pci_dev *pdev = phba->pcidev;
1303 struct Scsi_Host *shost = NULL;
1304 struct lpfc_hba *phba_other = NULL;
1305 struct pci_dev *ptr = NULL;
1308 if (phba->cfg_enable_hba_reset != 2)
1312 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1316 res = lpfc_check_pci_resettable(phba);
1320 /* Walk the list of devices on the pci_dev's bus */
1321 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1322 /* Check port is offline */
1323 shost = pci_get_drvdata(ptr);
1326 ((struct lpfc_vport *)shost->hostdata)->phba;
1327 if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1328 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1329 "8349 WWPN = 0x%02x%02x%02x%02x"
1330 "%02x%02x%02x%02x is not "
1332 phba_other->wwpn[0],
1333 phba_other->wwpn[1],
1334 phba_other->wwpn[2],
1335 phba_other->wwpn[3],
1336 phba_other->wwpn[4],
1337 phba_other->wwpn[5],
1338 phba_other->wwpn[6],
1339 phba_other->wwpn[7]);
1345 /* Issue PCI bus reset */
1346 res = pci_reset_bus(pdev);
1348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1349 "8350 PCI reset bus failed: %d\n", res);
1356 * lpfc_selective_reset - Offline then onlines the port
1357 * @phba: lpfc_hba pointer.
1360 * If the port is configured to allow a reset then the hba is brought
1361 * offline then online.
1364 * Assumes any error from lpfc_do_offline() will be negative.
1365 * Do not make this function static.
1368 * lpfc_do_offline() return code if not zero
1369 * -EIO reset not configured or error posting the event
1373 lpfc_selective_reset(struct lpfc_hba *phba)
1375 struct completion online_compl;
1379 if (!phba->cfg_enable_hba_reset)
1382 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1383 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1389 init_completion(&online_compl);
1390 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1395 wait_for_completion(&online_compl);
1404 * lpfc_issue_reset - Selectively resets an adapter
1405 * @dev: class device that is converted into a Scsi_host.
1406 * @attr: device attribute, not used.
1407 * @buf: containing the string "selective".
1408 * @count: unused variable.
1411 * If the buf contains the string "selective" then lpfc_selective_reset()
1412 * is called to perform the reset.
1415 * Assumes any error from lpfc_selective_reset() will be negative.
1416 * If lpfc_selective_reset() returns zero then the length of the buffer
1417 * is returned which indicates success
1420 * -EINVAL if the buffer does not contain the string "selective"
1421 * length of buf if lpfc-selective_reset() if the call succeeds
1422 * return value of lpfc_selective_reset() if the call fails
1425 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1426 const char *buf, size_t count)
1428 struct Scsi_Host *shost = class_to_shost(dev);
1429 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1430 struct lpfc_hba *phba = vport->phba;
1431 int status = -EINVAL;
1433 if (!phba->cfg_enable_hba_reset)
1436 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1437 status = phba->lpfc_selective_reset(phba);
1446 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1447 * @phba: lpfc_hba pointer.
1450 * SLI4 interface type-2 device to wait on the sliport status register for
1451 * the readyness after performing a firmware reset.
1454 * zero for success, -EPERM when port does not have privilege to perform the
1455 * reset, -EIO when port timeout from recovering from the reset.
1458 * As the caller will interpret the return code by value, be careful in making
1459 * change or addition to return codes.
1462 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1464 struct lpfc_register portstat_reg = {0};
1468 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1469 &portstat_reg.word0))
1472 /* verify if privileged for the request operation */
1473 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1474 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1477 /* wait for the SLI port firmware ready after firmware reset */
1478 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1480 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1481 &portstat_reg.word0))
1483 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1485 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1487 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1492 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1499 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1500 * @phba: lpfc_hba pointer.
1501 * @opcode: The sli4 config command opcode.
1504 * Request SLI4 interface type-2 device to perform a physical register set
1511 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1513 struct completion online_compl;
1514 struct pci_dev *pdev = phba->pcidev;
1515 uint32_t before_fc_flag;
1516 uint32_t sriov_nr_virtfn;
1518 int status = 0, rc = 0;
1519 int job_posted = 1, sriov_err;
1521 if (!phba->cfg_enable_hba_reset)
1524 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1525 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1526 LPFC_SLI_INTF_IF_TYPE_2))
1529 /* Keep state if we need to restore back */
1530 before_fc_flag = phba->pport->fc_flag;
1531 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1533 /* Disable SR-IOV virtual functions if enabled */
1534 if (phba->cfg_sriov_nr_virtfn) {
1535 pci_disable_sriov(pdev);
1536 phba->cfg_sriov_nr_virtfn = 0;
1539 if (opcode == LPFC_FW_DUMP)
1540 phba->hba_flag |= HBA_FW_DUMP_OP;
1542 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1545 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1549 /* wait for the device to be quiesced before firmware reset */
1552 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1553 LPFC_CTL_PDEV_CTL_OFFSET);
1555 if (opcode == LPFC_FW_DUMP)
1556 reg_val |= LPFC_FW_DUMP_REQUEST;
1557 else if (opcode == LPFC_FW_RESET)
1558 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1559 else if (opcode == LPFC_DV_RESET)
1560 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1562 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1563 LPFC_CTL_PDEV_CTL_OFFSET);
1565 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1567 /* delay driver action following IF_TYPE_2 reset */
1568 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1571 /* no privilege for reset */
1572 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1573 "3150 No privilege to perform the requested "
1574 "access: x%x\n", reg_val);
1575 } else if (rc == -EIO) {
1576 /* reset failed, there is nothing more we can do */
1577 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1578 "3153 Fail to perform the requested "
1579 "access: x%x\n", reg_val);
1583 /* keep the original port state */
1584 if (before_fc_flag & FC_OFFLINE_MODE)
1587 init_completion(&online_compl);
1588 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1593 wait_for_completion(&online_compl);
1596 /* in any case, restore the virtual functions enabled as before */
1597 if (sriov_nr_virtfn) {
1599 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1601 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1604 /* return proper error code */
1615 * lpfc_nport_evt_cnt_show - Return the number of nport events
1616 * @dev: class device that is converted into a Scsi_host.
1617 * @attr: device attribute, not used.
1618 * @buf: on return contains the ascii number of nport events.
1620 * Returns: size of formatted string.
1623 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1626 struct Scsi_Host *shost = class_to_shost(dev);
1627 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1628 struct lpfc_hba *phba = vport->phba;
1630 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1634 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1636 LPFC_MBOXQ_t *mbox = NULL;
1637 unsigned long val = 0;
1641 if (!strncmp("enable", buff_out,
1642 strlen("enable"))) {
1643 pval = buff_out + strlen("enable") + 1;
1644 rc = kstrtoul(pval, 0, &val);
1646 return rc; /* Invalid number */
1647 } else if (!strncmp("disable", buff_out,
1648 strlen("disable"))) {
1651 return -EINVAL; /* Invalid command */
1656 val = 0x0; /* Disable */
1659 val = 0x1; /* Enable two port trunk */
1662 val = 0x2; /* Enable four port trunk */
1668 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1669 "0070 Set trunk mode with val %ld ", val);
1671 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1675 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1676 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1677 12, LPFC_SLI4_MBX_EMBED);
1679 bf_set(lpfc_mbx_set_trunk_mode,
1680 &mbox->u.mqe.un.set_trunk_mode,
1682 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1684 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1685 "0071 Set trunk mode failed with status: %d",
1687 mempool_free(mbox, phba->mbox_mem_pool);
1693 * lpfc_board_mode_show - Return the state of the board
1694 * @dev: class device that is converted into a Scsi_host.
1695 * @attr: device attribute, not used.
1696 * @buf: on return contains the state of the adapter.
1698 * Returns: size of formatted string.
1701 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1704 struct Scsi_Host *shost = class_to_shost(dev);
1705 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1706 struct lpfc_hba *phba = vport->phba;
1709 if (phba->link_state == LPFC_HBA_ERROR)
1711 else if (phba->link_state == LPFC_WARM_START)
1712 state = "warm start";
1713 else if (phba->link_state == LPFC_INIT_START)
1718 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
1722 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1723 * @dev: class device that is converted into a Scsi_host.
1724 * @attr: device attribute, not used.
1725 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1726 * @count: unused variable.
1729 * -EACCES if enable hba reset not enabled
1730 * -EINVAL if the buffer does not contain a valid string (see above)
1731 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1732 * buf length greater than zero indicates success
1735 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1736 const char *buf, size_t count)
1738 struct Scsi_Host *shost = class_to_shost(dev);
1739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1740 struct lpfc_hba *phba = vport->phba;
1741 struct completion online_compl;
1742 char *board_mode_str = NULL;
1746 if (!phba->cfg_enable_hba_reset) {
1748 goto board_mode_out;
1751 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1752 "3050 lpfc_board_mode set to %s\n", buf);
1754 init_completion(&online_compl);
1756 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1757 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1761 goto board_mode_out;
1763 wait_for_completion(&online_compl);
1766 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1767 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1768 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1769 if (phba->sli_rev == LPFC_SLI_REV4)
1772 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1773 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1774 if (phba->sli_rev == LPFC_SLI_REV4)
1777 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1778 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1779 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1780 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1781 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1782 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1783 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1784 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1786 status = lpfc_reset_pci_bus(phba);
1787 else if (strncmp(buf, "heartbeat", sizeof("heartbeat") - 1) == 0)
1788 lpfc_issue_hb_tmo(phba);
1789 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1790 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
1798 board_mode_str = strchr(buf, '\n');
1800 *board_mode_str = '\0';
1801 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1802 "3097 Failed \"%s\", status(%d), "
1804 buf, status, phba->pport->fc_flag);
1810 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1811 * @phba: pointer to the adapter structure.
1812 * @mxri: max xri count.
1813 * @axri: available xri count.
1814 * @mrpi: max rpi count.
1815 * @arpi: available rpi count.
1816 * @mvpi: max vpi count.
1817 * @avpi: available vpi count.
1820 * If an integer pointer for an count is not null then the value for the
1821 * count is returned.
1828 lpfc_get_hba_info(struct lpfc_hba *phba,
1829 uint32_t *mxri, uint32_t *axri,
1830 uint32_t *mrpi, uint32_t *arpi,
1831 uint32_t *mvpi, uint32_t *avpi)
1833 struct lpfc_mbx_read_config *rd_config;
1834 LPFC_MBOXQ_t *pmboxq;
1840 * prevent udev from issuing mailbox commands until the port is
1843 if (phba->link_state < LPFC_LINK_DOWN ||
1844 !phba->mbox_mem_pool ||
1845 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1848 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1851 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1854 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1856 pmb = &pmboxq->u.mb;
1857 pmb->mbxCommand = MBX_READ_CONFIG;
1858 pmb->mbxOwner = OWN_HOST;
1859 pmboxq->ctx_buf = NULL;
1861 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1862 rc = MBX_NOT_FINISHED;
1864 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1866 if (rc != MBX_SUCCESS) {
1867 if (rc != MBX_TIMEOUT)
1868 mempool_free(pmboxq, phba->mbox_mem_pool);
1872 if (phba->sli_rev == LPFC_SLI_REV4) {
1873 rd_config = &pmboxq->u.mqe.un.rd_config;
1875 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1877 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1878 phba->sli4_hba.max_cfg_param.rpi_used;
1880 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1882 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1883 phba->sli4_hba.max_cfg_param.xri_used;
1885 /* Account for differences with SLI-3. Get vpi count from
1886 * mailbox data and subtract one for max vpi value.
1888 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1889 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1891 /* Limit the max we support */
1892 if (max_vpi > LPFC_MAX_VPI)
1893 max_vpi = LPFC_MAX_VPI;
1897 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1900 *mrpi = pmb->un.varRdConfig.max_rpi;
1902 *arpi = pmb->un.varRdConfig.avail_rpi;
1904 *mxri = pmb->un.varRdConfig.max_xri;
1906 *axri = pmb->un.varRdConfig.avail_xri;
1908 *mvpi = pmb->un.varRdConfig.max_vpi;
1910 /* avail_vpi is only valid if link is up and ready */
1911 if (phba->link_state == LPFC_HBA_READY)
1912 *avpi = pmb->un.varRdConfig.avail_vpi;
1914 *avpi = pmb->un.varRdConfig.max_vpi;
1918 mempool_free(pmboxq, phba->mbox_mem_pool);
1923 * lpfc_max_rpi_show - Return maximum rpi
1924 * @dev: class device that is converted into a Scsi_host.
1925 * @attr: device attribute, not used.
1926 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1929 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1930 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1931 * to "Unknown" and the buffer length is returned, therefore the caller
1932 * must check for "Unknown" in the buffer to detect a failure.
1934 * Returns: size of formatted string.
1937 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1940 struct Scsi_Host *shost = class_to_shost(dev);
1941 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1942 struct lpfc_hba *phba = vport->phba;
1945 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1946 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
1947 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1951 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1952 * @dev: class device that is converted into a Scsi_host.
1953 * @attr: device attribute, not used.
1954 * @buf: containing the used rpi count in decimal or "Unknown".
1957 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1958 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1959 * to "Unknown" and the buffer length is returned, therefore the caller
1960 * must check for "Unknown" in the buffer to detect a failure.
1962 * Returns: size of formatted string.
1965 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1968 struct Scsi_Host *shost = class_to_shost(dev);
1969 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1970 struct lpfc_hba *phba = vport->phba;
1973 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1974 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1975 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1979 * lpfc_max_xri_show - Return maximum xri
1980 * @dev: class device that is converted into a Scsi_host.
1981 * @attr: device attribute, not used.
1982 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1985 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1986 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1987 * to "Unknown" and the buffer length is returned, therefore the caller
1988 * must check for "Unknown" in the buffer to detect a failure.
1990 * Returns: size of formatted string.
1993 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1996 struct Scsi_Host *shost = class_to_shost(dev);
1997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1998 struct lpfc_hba *phba = vport->phba;
2001 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2002 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2003 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2007 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2008 * @dev: class device that is converted into a Scsi_host.
2009 * @attr: device attribute, not used.
2010 * @buf: on return contains the used xri count in decimal or "Unknown".
2013 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2014 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2015 * to "Unknown" and the buffer length is returned, therefore the caller
2016 * must check for "Unknown" in the buffer to detect a failure.
2018 * Returns: size of formatted string.
2021 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2024 struct Scsi_Host *shost = class_to_shost(dev);
2025 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2026 struct lpfc_hba *phba = vport->phba;
2029 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2030 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2031 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2035 * lpfc_max_vpi_show - Return maximum vpi
2036 * @dev: class device that is converted into a Scsi_host.
2037 * @attr: device attribute, not used.
2038 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2041 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2042 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2043 * to "Unknown" and the buffer length is returned, therefore the caller
2044 * must check for "Unknown" in the buffer to detect a failure.
2046 * Returns: size of formatted string.
2049 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2052 struct Scsi_Host *shost = class_to_shost(dev);
2053 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2054 struct lpfc_hba *phba = vport->phba;
2057 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2058 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2059 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2063 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2064 * @dev: class device that is converted into a Scsi_host.
2065 * @attr: device attribute, not used.
2066 * @buf: on return contains the used vpi count in decimal or "Unknown".
2069 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2070 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2071 * to "Unknown" and the buffer length is returned, therefore the caller
2072 * must check for "Unknown" in the buffer to detect a failure.
2074 * Returns: size of formatted string.
2077 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2080 struct Scsi_Host *shost = class_to_shost(dev);
2081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2082 struct lpfc_hba *phba = vport->phba;
2085 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2086 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2087 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2091 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2092 * @dev: class device that is converted into a Scsi_host.
2093 * @attr: device attribute, not used.
2094 * @buf: text that must be interpreted to determine if npiv is supported.
2097 * Buffer will contain text indicating npiv is not suppoerted on the port,
2098 * the port is an NPIV physical port, or it is an npiv virtual port with
2099 * the id of the vport.
2101 * Returns: size of formatted string.
2104 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2107 struct Scsi_Host *shost = class_to_shost(dev);
2108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2109 struct lpfc_hba *phba = vport->phba;
2111 if (!(phba->max_vpi))
2112 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2113 if (vport->port_type == LPFC_PHYSICAL_PORT)
2114 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2115 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2119 * lpfc_poll_show - Return text about poll support for the adapter
2120 * @dev: class device that is converted into a Scsi_host.
2121 * @attr: device attribute, not used.
2122 * @buf: on return contains the cfg_poll in hex.
2125 * cfg_poll should be a lpfc_polling_flags type.
2127 * Returns: size of formatted string.
2130 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2133 struct Scsi_Host *shost = class_to_shost(dev);
2134 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2135 struct lpfc_hba *phba = vport->phba;
2137 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2141 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2142 * @dev: class device that is converted into a Scsi_host.
2143 * @attr: device attribute, not used.
2144 * @buf: one or more lpfc_polling_flags values.
2148 * buf contents converted to integer and checked for a valid value.
2151 * -EINVAL if the buffer connot be converted or is out of range
2152 * length of the buf on success
2155 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2156 const char *buf, size_t count)
2158 struct Scsi_Host *shost = class_to_shost(dev);
2159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2160 struct lpfc_hba *phba = vport->phba;
2165 if (!isdigit(buf[0]))
2168 if (sscanf(buf, "%i", &val) != 1)
2171 if ((val & 0x3) != val)
2174 if (phba->sli_rev == LPFC_SLI_REV4)
2177 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2178 "3051 lpfc_poll changed from %d to %d\n",
2179 phba->cfg_poll, val);
2181 spin_lock_irq(&phba->hbalock);
2183 old_val = phba->cfg_poll;
2185 if (val & ENABLE_FCP_RING_POLLING) {
2186 if ((val & DISABLE_FCP_RING_INT) &&
2187 !(old_val & DISABLE_FCP_RING_INT)) {
2188 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2189 spin_unlock_irq(&phba->hbalock);
2192 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2193 writel(creg_val, phba->HCregaddr);
2194 readl(phba->HCregaddr); /* flush */
2196 lpfc_poll_start_timer(phba);
2198 } else if (val != 0x0) {
2199 spin_unlock_irq(&phba->hbalock);
2203 if (!(val & DISABLE_FCP_RING_INT) &&
2204 (old_val & DISABLE_FCP_RING_INT))
2206 spin_unlock_irq(&phba->hbalock);
2207 del_timer(&phba->fcp_poll_timer);
2208 spin_lock_irq(&phba->hbalock);
2209 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2210 spin_unlock_irq(&phba->hbalock);
2213 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2214 writel(creg_val, phba->HCregaddr);
2215 readl(phba->HCregaddr); /* flush */
2218 phba->cfg_poll = val;
2220 spin_unlock_irq(&phba->hbalock);
2226 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2227 * @dev: class converted to a Scsi_host structure.
2228 * @attr: device attribute, not used.
2229 * @buf: on return contains the formatted support level.
2232 * Returns the maximum number of virtual functions a physical function can
2233 * support, 0 will be returned if called on virtual function.
2235 * Returns: size of formatted string.
2238 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2239 struct device_attribute *attr,
2242 struct Scsi_Host *shost = class_to_shost(dev);
2243 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2244 struct lpfc_hba *phba = vport->phba;
2245 uint16_t max_nr_virtfn;
2247 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2248 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2251 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2253 return val >= min && val <= max;
2257 * lpfc_enable_bbcr_set: Sets an attribute value.
2258 * @phba: pointer the the adapter structure.
2259 * @val: integer attribute value.
2262 * Validates the min and max values then sets the
2263 * adapter config field if in the valid range. prints error message
2264 * and does not set the parameter if invalid.
2268 * -EINVAL if val is invalid
2271 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2273 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2274 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2275 "3068 lpfc_enable_bbcr changed from %d to "
2276 "%d\n", phba->cfg_enable_bbcr, val);
2277 phba->cfg_enable_bbcr = val;
2280 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2281 "0451 lpfc_enable_bbcr cannot set to %d, range is 0, "
2287 * lpfc_param_show - Return a cfg attribute value in decimal
2290 * Macro that given an attr e.g. hba_queue_depth expands
2291 * into a function with the name lpfc_hba_queue_depth_show.
2293 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2294 * @dev: class device that is converted into a Scsi_host.
2295 * @attr: device attribute, not used.
2296 * @buf: on return contains the attribute value in decimal.
2298 * Returns: size of formatted string.
2300 #define lpfc_param_show(attr) \
2302 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2305 struct Scsi_Host *shost = class_to_shost(dev);\
2306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2307 struct lpfc_hba *phba = vport->phba;\
2308 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2313 * lpfc_param_hex_show - Return a cfg attribute value in hex
2316 * Macro that given an attr e.g. hba_queue_depth expands
2317 * into a function with the name lpfc_hba_queue_depth_show
2319 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2320 * @dev: class device that is converted into a Scsi_host.
2321 * @attr: device attribute, not used.
2322 * @buf: on return contains the attribute value in hexadecimal.
2324 * Returns: size of formatted string.
2326 #define lpfc_param_hex_show(attr) \
2328 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2331 struct Scsi_Host *shost = class_to_shost(dev);\
2332 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2333 struct lpfc_hba *phba = vport->phba;\
2335 val = phba->cfg_##attr;\
2336 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2341 * lpfc_param_init - Initializes a cfg attribute
2344 * Macro that given an attr e.g. hba_queue_depth expands
2345 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2346 * takes a default argument, a minimum and maximum argument.
2348 * lpfc_##attr##_init: Initializes an attribute.
2349 * @phba: pointer the the adapter structure.
2350 * @val: integer attribute value.
2352 * Validates the min and max values then sets the adapter config field
2353 * accordingly, or uses the default if out of range and prints an error message.
2357 * -EINVAL if default used
2359 #define lpfc_param_init(attr, default, minval, maxval) \
2361 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2363 if (lpfc_rangecheck(val, minval, maxval)) {\
2364 phba->cfg_##attr = val;\
2367 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2368 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2369 "allowed range is ["#minval", "#maxval"]\n", val); \
2370 phba->cfg_##attr = default;\
2375 * lpfc_param_set - Set a cfg attribute value
2378 * Macro that given an attr e.g. hba_queue_depth expands
2379 * into a function with the name lpfc_hba_queue_depth_set
2381 * lpfc_##attr##_set: Sets an attribute value.
2382 * @phba: pointer the the adapter structure.
2383 * @val: integer attribute value.
2386 * Validates the min and max values then sets the
2387 * adapter config field if in the valid range. prints error message
2388 * and does not set the parameter if invalid.
2392 * -EINVAL if val is invalid
2394 #define lpfc_param_set(attr, default, minval, maxval) \
2396 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2398 if (lpfc_rangecheck(val, minval, maxval)) {\
2399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2400 "3052 lpfc_" #attr " changed from %d to %d\n", \
2401 phba->cfg_##attr, val); \
2402 phba->cfg_##attr = val;\
2405 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2406 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2407 "allowed range is ["#minval", "#maxval"]\n", val); \
2412 * lpfc_param_store - Set a vport attribute value
2415 * Macro that given an attr e.g. hba_queue_depth expands
2416 * into a function with the name lpfc_hba_queue_depth_store.
2418 * lpfc_##attr##_store: Set an sttribute value.
2419 * @dev: class device that is converted into a Scsi_host.
2420 * @attr: device attribute, not used.
2421 * @buf: contains the attribute value in ascii.
2425 * Convert the ascii text number to an integer, then
2426 * use the lpfc_##attr##_set function to set the value.
2429 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2430 * length of buffer upon success.
2432 #define lpfc_param_store(attr) \
2434 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2435 const char *buf, size_t count) \
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;\
2441 if (!isdigit(buf[0]))\
2443 if (sscanf(buf, "%i", &val) != 1)\
2445 if (lpfc_##attr##_set(phba, val) == 0) \
2446 return strlen(buf);\
2452 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2455 * Macro that given an attr e.g. hba_queue_depth expands
2456 * into a function with the name lpfc_hba_queue_depth_show
2458 * lpfc_##attr##_show: prints the attribute value in decimal.
2459 * @dev: class device that is converted into a Scsi_host.
2460 * @attr: device attribute, not used.
2461 * @buf: on return contains the attribute value in decimal.
2463 * Returns: length of formatted string.
2465 #define lpfc_vport_param_show(attr) \
2467 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2470 struct Scsi_Host *shost = class_to_shost(dev);\
2471 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2472 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2476 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2479 * Macro that given an attr e.g.
2480 * hba_queue_depth expands into a function with the name
2481 * lpfc_hba_queue_depth_show
2483 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2484 * @dev: class device that is converted into a Scsi_host.
2485 * @attr: device attribute, not used.
2486 * @buf: on return contains the attribute value in hexadecimal.
2488 * Returns: length of formatted string.
2490 #define lpfc_vport_param_hex_show(attr) \
2492 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2495 struct Scsi_Host *shost = class_to_shost(dev);\
2496 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2497 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2501 * lpfc_vport_param_init - Initialize a vport cfg attribute
2504 * Macro that given an attr e.g. hba_queue_depth expands
2505 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2506 * takes a default argument, a minimum and maximum argument.
2508 * lpfc_##attr##_init: validates the min and max values then sets the
2509 * adapter config field accordingly, or uses the default if out of range
2510 * and prints an error message.
2511 * @phba: pointer the the adapter structure.
2512 * @val: integer attribute value.
2516 * -EINVAL if default used
2518 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2520 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2522 if (lpfc_rangecheck(val, minval, maxval)) {\
2523 vport->cfg_##attr = val;\
2526 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2527 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2528 "allowed range is ["#minval", "#maxval"]\n", val); \
2529 vport->cfg_##attr = default;\
2534 * lpfc_vport_param_set - Set a vport cfg attribute
2537 * Macro that given an attr e.g. hba_queue_depth expands
2538 * into a function with the name lpfc_hba_queue_depth_set
2540 * lpfc_##attr##_set: validates the min and max values then sets the
2541 * adapter config field if in the valid range. prints error message
2542 * and does not set the parameter if invalid.
2543 * @phba: pointer the the adapter structure.
2544 * @val: integer attribute value.
2548 * -EINVAL if val is invalid
2550 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2552 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2554 if (lpfc_rangecheck(val, minval, maxval)) {\
2555 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2556 "3053 lpfc_" #attr \
2557 " changed from %d (x%x) to %d (x%x)\n", \
2558 vport->cfg_##attr, vport->cfg_##attr, \
2560 vport->cfg_##attr = val;\
2563 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2564 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2565 "allowed range is ["#minval", "#maxval"]\n", val); \
2570 * lpfc_vport_param_store - Set a vport attribute
2573 * Macro that given an attr e.g. hba_queue_depth
2574 * expands into a function with the name lpfc_hba_queue_depth_store
2576 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2577 * use the lpfc_##attr##_set function to set the value.
2578 * @cdev: class device that is converted into a Scsi_host.
2579 * @buf: contains the attribute value in decimal.
2583 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2584 * length of buffer upon success.
2586 #define lpfc_vport_param_store(attr) \
2588 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2589 const char *buf, size_t count) \
2591 struct Scsi_Host *shost = class_to_shost(dev);\
2592 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2594 if (!isdigit(buf[0]))\
2596 if (sscanf(buf, "%i", &val) != 1)\
2598 if (lpfc_##attr##_set(vport, val) == 0) \
2599 return strlen(buf);\
2605 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2606 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2607 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2608 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2609 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2610 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2611 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2612 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2613 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2614 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2615 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2616 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2617 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2618 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2619 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2620 lpfc_link_state_store);
2621 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2622 lpfc_option_rom_version_show, NULL);
2623 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2624 lpfc_num_discovered_ports_show, NULL);
2625 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2626 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2627 static DEVICE_ATTR_RO(lpfc_drvr_version);
2628 static DEVICE_ATTR_RO(lpfc_enable_fip);
2629 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2630 lpfc_board_mode_show, lpfc_board_mode_store);
2631 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2632 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2633 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2634 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2635 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2636 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2637 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2638 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2639 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2640 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2641 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2642 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2645 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2648 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2650 * @cnt: Length of string.
2651 * @wwn: Array to receive converted wwn value.
2654 * -EINVAL if the buffer does not contain a valid wwn
2658 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2662 /* Count may include a LF at end of string */
2663 if (buf[cnt-1] == '\n')
2666 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2667 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2670 memset(wwn, 0, WWN_SZ);
2672 /* Validate and store the new name */
2673 for (i = 0, j = 0; i < 16; i++) {
2674 if ((*buf >= 'a') && (*buf <= 'f'))
2675 j = ((j << 4) | ((*buf++ - 'a') + 10));
2676 else if ((*buf >= 'A') && (*buf <= 'F'))
2677 j = ((j << 4) | ((*buf++ - 'A') + 10));
2678 else if ((*buf >= '0') && (*buf <= '9'))
2679 j = ((j << 4) | (*buf++ - '0'));
2683 wwn[i/2] = j & 0xff;
2690 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2691 * @dev: class device that is converted into a Scsi_host.
2692 * @attr: device attribute, not used.
2693 * @buf: containing the string lpfc_soft_wwn_key.
2694 * @count: must be size of lpfc_soft_wwn_key.
2697 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2698 * length of buf indicates success
2701 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2702 const char *buf, size_t count)
2704 struct Scsi_Host *shost = class_to_shost(dev);
2705 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2706 struct lpfc_hba *phba = vport->phba;
2707 unsigned int cnt = count;
2708 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2709 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2712 * We're doing a simple sanity check for soft_wwpn setting.
2713 * We require that the user write a specific key to enable
2714 * the soft_wwpn attribute to be settable. Once the attribute
2715 * is written, the enable key resets. If further updates are
2716 * desired, the key must be written again to re-enable the
2719 * The "key" is not secret - it is a hardcoded string shown
2720 * here. The intent is to protect against the random user or
2721 * application that is just writing attributes.
2723 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2724 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2725 "0051 lpfc soft wwpn can not be enabled: "
2726 "fawwpn is enabled\n");
2730 /* count may include a LF at end of string */
2731 if (buf[cnt-1] == '\n')
2734 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2735 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2738 phba->soft_wwn_enable = 1;
2740 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2741 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2743 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2744 " The soft_wwpn feature is not supported by Broadcom.");
2748 static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
2751 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2752 * @dev: class device that is converted into a Scsi_host.
2753 * @attr: device attribute, not used.
2754 * @buf: on return contains the wwpn in hexadecimal.
2756 * Returns: size of formatted string.
2759 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2762 struct Scsi_Host *shost = class_to_shost(dev);
2763 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2764 struct lpfc_hba *phba = vport->phba;
2766 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2767 (unsigned long long)phba->cfg_soft_wwpn);
2771 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2772 * @dev: class device that is converted into a Scsi_host.
2773 * @attr: device attribute, not used.
2774 * @buf: contains the wwpn in hexadecimal.
2775 * @count: number of wwpn bytes in buf
2778 * -EACCES hba reset not enabled, adapter over temp
2779 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2780 * -EIO error taking adapter offline or online
2781 * value of count on success
2784 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2785 const char *buf, size_t count)
2787 struct Scsi_Host *shost = class_to_shost(dev);
2788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2789 struct lpfc_hba *phba = vport->phba;
2790 struct completion online_compl;
2791 int stat1 = 0, stat2 = 0;
2792 unsigned int cnt = count;
2796 if (!phba->cfg_enable_hba_reset)
2798 spin_lock_irq(&phba->hbalock);
2799 if (phba->over_temp_state == HBA_OVER_TEMP) {
2800 spin_unlock_irq(&phba->hbalock);
2803 spin_unlock_irq(&phba->hbalock);
2804 /* count may include a LF at end of string */
2805 if (buf[cnt-1] == '\n')
2808 if (!phba->soft_wwn_enable)
2811 /* lock setting wwpn, wwnn down */
2812 phba->soft_wwn_enable = 0;
2814 rc = lpfc_wwn_set(buf, cnt, wwpn);
2816 /* not able to set wwpn, unlock it */
2817 phba->soft_wwn_enable = 1;
2821 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2822 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2823 if (phba->cfg_soft_wwnn)
2824 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2826 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2827 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2829 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2831 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2832 "0463 lpfc_soft_wwpn attribute set failed to "
2833 "reinit adapter - %d\n", stat1);
2834 init_completion(&online_compl);
2835 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2840 wait_for_completion(&online_compl);
2842 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2843 "0464 lpfc_soft_wwpn attribute set failed to "
2844 "reinit adapter - %d\n", stat2);
2845 return (stat1 || stat2) ? -EIO : count;
2847 static DEVICE_ATTR_RW(lpfc_soft_wwpn);
2850 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2851 * @dev: class device that is converted into a Scsi_host.
2852 * @attr: device attribute, not used.
2853 * @buf: on return contains the wwnn in hexadecimal.
2855 * Returns: size of formatted string.
2858 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2861 struct Scsi_Host *shost = class_to_shost(dev);
2862 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2863 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2864 (unsigned long long)phba->cfg_soft_wwnn);
2868 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2869 * @dev: class device that is converted into a Scsi_host.
2870 * @attr: device attribute, not used.
2871 * @buf: contains the ww node name in hexadecimal.
2872 * @count: number of wwnn bytes in buf.
2875 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2876 * value of count on success
2879 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2880 const char *buf, size_t count)
2882 struct Scsi_Host *shost = class_to_shost(dev);
2883 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2884 unsigned int cnt = count;
2888 /* count may include a LF at end of string */
2889 if (buf[cnt-1] == '\n')
2892 if (!phba->soft_wwn_enable)
2895 rc = lpfc_wwn_set(buf, cnt, wwnn);
2897 /* Allow wwnn to be set many times, as long as the enable
2898 * is set. However, once the wwpn is set, everything locks.
2903 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2905 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2906 "lpfc%d: soft_wwnn set. Value will take effect upon "
2907 "setting of the soft_wwpn\n", phba->brd_no);
2911 static DEVICE_ATTR_RW(lpfc_soft_wwnn);
2914 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2915 * Optimized Access Storage (OAS) operations.
2916 * @dev: class device that is converted into a Scsi_host.
2917 * @attr: device attribute, not used.
2918 * @buf: buffer for passing information.
2924 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2927 struct Scsi_Host *shost = class_to_shost(dev);
2928 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2930 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2931 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2935 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2936 * Optimized Access Storage (OAS) operations.
2937 * @dev: class device that is converted into a Scsi_host.
2938 * @attr: device attribute, not used.
2939 * @buf: buffer for passing information.
2940 * @count: Size of the data buffer.
2943 * -EINVAL count is invalid, invalid wwpn byte invalid
2944 * -EPERM oas is not supported by hba
2945 * value of count on success
2948 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2949 const char *buf, size_t count)
2951 struct Scsi_Host *shost = class_to_shost(dev);
2952 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2953 unsigned int cnt = count;
2954 uint8_t wwpn[WWN_SZ];
2960 /* count may include a LF at end of string */
2961 if (buf[cnt-1] == '\n')
2964 rc = lpfc_wwn_set(buf, cnt, wwpn);
2968 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2969 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2970 if (wwn_to_u64(wwpn) == 0)
2971 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2973 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2974 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2975 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2978 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2979 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2982 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2983 * Optimized Access Storage (OAS) operations.
2984 * @dev: class device that is converted into a Scsi_host.
2985 * @attr: device attribute, not used.
2986 * @buf: buffer for passing information.
2992 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2995 struct Scsi_Host *shost = class_to_shost(dev);
2996 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2998 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3002 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3003 * Optimized Access Storage (OAS) operations.
3004 * @dev: class device that is converted into a Scsi_host.
3005 * @attr: device attribute, not used.
3006 * @buf: buffer for passing information.
3007 * @count: Size of the data buffer.
3010 * -EINVAL count is invalid, invalid wwpn byte invalid
3011 * -EPERM oas is not supported by hba
3012 * value of count on success
3015 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3016 const char *buf, size_t count)
3018 struct Scsi_Host *shost = class_to_shost(dev);
3019 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3020 unsigned int cnt = count;
3027 /* count may include a LF at end of string */
3028 if (buf[cnt-1] == '\n')
3031 ret = kstrtoul(buf, 0, &val);
3032 if (ret || (val > 0x7f))
3036 phba->cfg_oas_priority = (uint8_t)val;
3038 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3041 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3042 lpfc_oas_priority_show, lpfc_oas_priority_store);
3045 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3046 * for Optimized Access Storage (OAS) operations.
3047 * @dev: class device that is converted into a Scsi_host.
3048 * @attr: device attribute, not used.
3049 * @buf: buffer for passing information.
3052 * value of count on success
3055 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3058 struct Scsi_Host *shost = class_to_shost(dev);
3059 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3061 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3062 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3066 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3067 * for Optimized Access Storage (OAS) operations.
3068 * @dev: class device that is converted into a Scsi_host.
3069 * @attr: device attribute, not used.
3070 * @buf: buffer for passing information.
3071 * @count: Size of the data buffer.
3074 * -EINVAL count is invalid, invalid wwpn byte invalid
3075 * -EPERM oas is not supported by hba
3076 * value of count on success
3079 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3080 const char *buf, size_t count)
3082 struct Scsi_Host *shost = class_to_shost(dev);
3083 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3084 unsigned int cnt = count;
3085 uint8_t wwpn[WWN_SZ];
3091 /* count may include a LF at end of string */
3092 if (buf[cnt-1] == '\n')
3095 rc = lpfc_wwn_set(buf, cnt, wwpn);
3099 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3100 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3101 if (wwn_to_u64(wwpn) == 0)
3102 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3104 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3105 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3106 if (phba->cfg_oas_priority == 0)
3107 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3108 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3111 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3112 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3115 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3116 * of whether luns will be enabled or disabled
3117 * for Optimized Access Storage (OAS) operations.
3118 * @dev: class device that is converted into a Scsi_host.
3119 * @attr: device attribute, not used.
3120 * @buf: buffer for passing information.
3123 * size of formatted string.
3126 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3129 struct Scsi_Host *shost = class_to_shost(dev);
3130 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3132 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3136 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3137 * of whether luns will be enabled or disabled
3138 * for Optimized Access Storage (OAS) operations.
3139 * @dev: class device that is converted into a Scsi_host.
3140 * @attr: device attribute, not used.
3141 * @buf: buffer for passing information.
3142 * @count: Size of the data buffer.
3145 * -EINVAL count is invalid, invalid wwpn byte invalid
3146 * -EPERM oas is not supported by hba
3147 * value of count on success
3150 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3151 const char *buf, size_t count)
3153 struct Scsi_Host *shost = class_to_shost(dev);
3154 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3160 if (!isdigit(buf[0]))
3163 if (sscanf(buf, "%i", &val) != 1)
3166 if ((val != 0) && (val != 1))
3169 phba->cfg_oas_lun_state = val;
3172 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3173 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3176 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3177 * Storage (OAS) lun returned by the
3178 * lpfc_oas_lun_show function.
3179 * @dev: class device that is converted into a Scsi_host.
3180 * @attr: device attribute, not used.
3181 * @buf: buffer for passing information.
3184 * size of formatted string.
3187 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3190 struct Scsi_Host *shost = class_to_shost(dev);
3191 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3193 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3196 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3198 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3199 lpfc_oas_lun_status_show, NULL);
3203 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3205 * @phba: lpfc_hba pointer.
3206 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3207 * @tgt_wwpn: wwpn of the target associated with the returned lun
3208 * @lun: the fc lun for setting oas state.
3209 * @oas_state: the oas state to be set to the lun.
3214 * -EPERM OAS is not enabled or not supported by this port.
3218 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3219 uint8_t tgt_wwpn[], uint64_t lun,
3220 uint32_t oas_state, uint8_t pri)
3229 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3230 (struct lpfc_name *)tgt_wwpn,
3234 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3235 (struct lpfc_name *)tgt_wwpn, lun, pri);
3242 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3243 * Access Storage (OAS) operations.
3244 * @phba: lpfc_hba pointer.
3245 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3246 * @tgt_wwpn: wwpn of the target associated with the returned lun
3247 * @lun_status: status of the lun returned lun
3248 * @lun_pri: priority of the lun returned lun
3250 * Returns the first or next lun enabled for OAS operations for the vport/target
3251 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3252 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3255 * lun that is OAS enabled for the vport/target
3256 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3259 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3260 uint8_t tgt_wwpn[], uint32_t *lun_status,
3265 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3266 return NOT_OAS_ENABLED_LUN;
3267 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3268 phba->sli4_hba.oas_next_vpt_wwpn,
3269 (struct lpfc_name *)
3270 phba->sli4_hba.oas_next_tgt_wwpn,
3271 &phba->sli4_hba.oas_next_lun,
3272 (struct lpfc_name *)vpt_wwpn,
3273 (struct lpfc_name *)tgt_wwpn,
3274 &found_lun, lun_status, lun_pri))
3277 return NOT_OAS_ENABLED_LUN;
3281 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3282 * @phba: lpfc_hba pointer.
3283 * @vpt_wwpn: vport wwpn by reference.
3284 * @tgt_wwpn: target wwpn by reference.
3285 * @lun: the fc lun for setting oas state.
3286 * @oas_state: the oas state to be set to the oas_lun.
3289 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3290 * a lun for OAS operations.
3294 * -ENOMEM: failed to enable an lun for OAS operations
3295 * -EPERM: OAS is not enabled
3298 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3299 uint8_t tgt_wwpn[], uint64_t lun,
3300 uint32_t oas_state, uint8_t pri)
3305 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3311 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3312 * @dev: class device that is converted into a Scsi_host.
3313 * @attr: device attribute, not used.
3314 * @buf: buffer for passing information.
3316 * This routine returns a lun enabled for OAS each time the function
3320 * SUCCESS: size of formatted string.
3321 * -EFAULT: target or vport wwpn was not set properly.
3322 * -EPERM: oas is not enabled.
3325 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3328 struct Scsi_Host *shost = class_to_shost(dev);
3329 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3337 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3338 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3341 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3342 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3345 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3346 phba->cfg_oas_tgt_wwpn,
3347 &phba->cfg_oas_lun_status,
3348 &phba->cfg_oas_priority);
3349 if (oas_lun != NOT_OAS_ENABLED_LUN)
3350 phba->cfg_oas_flags |= OAS_LUN_VALID;
3352 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3358 * lpfc_oas_lun_store - Sets the OAS state for lun
3359 * @dev: class device that is converted into a Scsi_host.
3360 * @attr: device attribute, not used.
3361 * @buf: buffer for passing information.
3362 * @count: size of the formatting string
3364 * This function sets the OAS state for lun. Before this function is called,
3365 * the vport wwpn, target wwpn, and oas state need to be set.
3368 * SUCCESS: size of formatted string.
3369 * -EFAULT: target or vport wwpn was not set properly.
3370 * -EPERM: oas is not enabled.
3371 * size of formatted string.
3374 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3375 const char *buf, size_t count)
3377 struct Scsi_Host *shost = class_to_shost(dev);
3378 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3386 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3389 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3392 if (!isdigit(buf[0]))
3395 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3398 pri = phba->cfg_oas_priority;
3400 pri = phba->cfg_XLanePriority;
3402 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3403 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3404 "priority 0x%x with oas state %d\n",
3405 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3406 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3407 pri, phba->cfg_oas_lun_state);
3409 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3410 phba->cfg_oas_tgt_wwpn, scsi_lun,
3411 phba->cfg_oas_lun_state, pri);
3417 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3418 lpfc_oas_lun_show, lpfc_oas_lun_store);
3420 int lpfc_enable_nvmet_cnt;
3421 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3422 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3423 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3424 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3425 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3427 static int lpfc_poll = 0;
3428 module_param(lpfc_poll, int, S_IRUGO);
3429 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3431 " 1 - poll with interrupts enabled"
3432 " 3 - poll and disable FCP ring interrupts");
3434 static DEVICE_ATTR_RW(lpfc_poll);
3436 int lpfc_no_hba_reset_cnt;
3437 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3438 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3439 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3440 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3442 LPFC_ATTR(sli_mode, 3, 3, 3,
3443 "SLI mode selector: 3 - select SLI-3");
3445 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3446 "Enable NPIV functionality");
3448 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3449 "FCF Fast failover=1 Priority failover=2");
3452 * lpfc_fcp_wait_abts_rsp: Modifies criteria for reporting completion of
3454 * The range is [0,1]. Default value is 0
3455 * 0, IO completes after ABTS issued (default).
3456 * 1, IO completes after receipt of ABTS response or timeout.
3458 LPFC_ATTR_R(fcp_wait_abts_rsp, 0, 0, 1, "Wait for FCP ABTS completion");
3461 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3462 # 0x0 = disabled, XRI/OXID use not tracked.
3463 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3464 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3466 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3467 "Enable RRQ functionality");
3470 # lpfc_suppress_link_up: Bring link up at initialization
3471 # 0x0 = bring link up (issue MBX_INIT_LINK)
3472 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3473 # 0x2 = never bring up link
3474 # Default value is 0.
3476 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3477 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3478 "Suppress Link Up at initialization");
3481 lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3483 struct Scsi_Host *shost = class_to_shost(dev);
3484 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3486 return scnprintf(buf, PAGE_SIZE, "%d\n",
3487 phba->sli4_hba.pc_sli4_params.pls);
3489 static DEVICE_ATTR(pls, 0444,
3490 lpfc_pls_show, NULL);
3493 lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3495 struct Scsi_Host *shost = class_to_shost(dev);
3496 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3498 return scnprintf(buf, PAGE_SIZE, "%d\n",
3499 (phba->hba_flag & HBA_PERSISTENT_TOPO) ? 1 : 0);
3501 static DEVICE_ATTR(pt, 0444,
3502 lpfc_pt_show, NULL);
3505 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3513 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3515 struct Scsi_Host *shost = class_to_shost(dev);
3516 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3518 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3521 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3522 lpfc_iocb_hw_show, NULL);
3524 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3526 struct Scsi_Host *shost = class_to_shost(dev);
3527 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3528 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3530 return scnprintf(buf, PAGE_SIZE, "%d\n",
3531 pring ? pring->txq_max : 0);
3534 static DEVICE_ATTR(txq_hw, S_IRUGO,
3535 lpfc_txq_hw_show, NULL);
3537 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3540 struct Scsi_Host *shost = class_to_shost(dev);
3541 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3542 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3544 return scnprintf(buf, PAGE_SIZE, "%d\n",
3545 pring ? pring->txcmplq_max : 0);
3548 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3549 lpfc_txcmplq_hw_show, NULL);
3552 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3553 # until the timer expires. Value range is [0,255]. Default value is 30.
3555 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3556 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3557 module_param(lpfc_nodev_tmo, int, 0);
3558 MODULE_PARM_DESC(lpfc_nodev_tmo,
3559 "Seconds driver will hold I/O waiting "
3560 "for a device to come back");
3563 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3564 * @dev: class converted to a Scsi_host structure.
3565 * @attr: device attribute, not used.
3566 * @buf: on return contains the dev loss timeout in decimal.
3568 * Returns: size of formatted string.
3571 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3574 struct Scsi_Host *shost = class_to_shost(dev);
3575 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3577 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3581 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3582 * @vport: lpfc vport structure pointer.
3583 * @val: contains the nodev timeout value.
3586 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3587 * a kernel error message is printed and zero is returned.
3588 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3589 * Otherwise nodev tmo is set to the default value.
3592 * zero if already set or if val is in range
3593 * -EINVAL val out of range
3596 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3598 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3599 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3600 if (val != LPFC_DEF_DEVLOSS_TMO)
3601 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3602 "0407 Ignoring lpfc_nodev_tmo module "
3603 "parameter because lpfc_devloss_tmo "
3608 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3609 vport->cfg_nodev_tmo = val;
3610 vport->cfg_devloss_tmo = val;
3613 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3614 "0400 lpfc_nodev_tmo attribute cannot be set to"
3615 " %d, allowed range is [%d, %d]\n",
3616 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3617 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3622 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3623 * @vport: lpfc vport structure pointer.
3626 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3629 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3631 struct Scsi_Host *shost;
3632 struct lpfc_nodelist *ndlp;
3633 #if (IS_ENABLED(CONFIG_NVME_FC))
3634 struct lpfc_nvme_rport *rport;
3635 struct nvme_fc_remote_port *remoteport = NULL;
3638 shost = lpfc_shost_from_vport(vport);
3639 spin_lock_irq(shost->host_lock);
3640 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3642 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3643 #if (IS_ENABLED(CONFIG_NVME_FC))
3644 spin_lock(&ndlp->lock);
3645 rport = lpfc_ndlp_get_nrport(ndlp);
3647 remoteport = rport->remoteport;
3648 spin_unlock(&ndlp->lock);
3649 if (rport && remoteport)
3650 nvme_fc_set_remoteport_devloss(remoteport,
3651 vport->cfg_devloss_tmo);
3654 spin_unlock_irq(shost->host_lock);
3658 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3659 * @vport: lpfc vport structure pointer.
3660 * @val: contains the tmo value.
3663 * If the devloss tmo is already set or the vport dev loss tmo has changed
3664 * then a kernel error message is printed and zero is returned.
3665 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3666 * Otherwise nodev tmo is set to the default value.
3669 * zero if already set or if val is in range
3670 * -EINVAL val out of range
3673 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3675 if (vport->dev_loss_tmo_changed ||
3676 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3677 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3678 "0401 Ignoring change to lpfc_nodev_tmo "
3679 "because lpfc_devloss_tmo is set.\n");
3682 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3683 vport->cfg_nodev_tmo = val;
3684 vport->cfg_devloss_tmo = val;
3686 * For compat: set the fc_host dev loss so new rports
3687 * will get the value.
3689 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3690 lpfc_update_rport_devloss_tmo(vport);
3693 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3694 "0403 lpfc_nodev_tmo attribute cannot be set to "
3695 "%d, allowed range is [%d, %d]\n",
3696 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3700 lpfc_vport_param_store(nodev_tmo)
3702 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3705 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3706 # disappear until the timer expires. Value range is [0,255]. Default
3709 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3710 MODULE_PARM_DESC(lpfc_devloss_tmo,
3711 "Seconds driver will hold I/O waiting "
3712 "for a device to come back");
3713 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3714 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3715 lpfc_vport_param_show(devloss_tmo)
3718 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3719 * @vport: lpfc vport structure pointer.
3720 * @val: contains the tmo value.
3723 * If val is in a valid range then set the vport nodev tmo,
3724 * devloss tmo, also set the vport dev loss tmo changed flag.
3725 * Else a kernel error message is printed.
3728 * zero if val is in range
3729 * -EINVAL val out of range
3732 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3734 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3735 vport->cfg_nodev_tmo = val;
3736 vport->cfg_devloss_tmo = val;
3737 vport->dev_loss_tmo_changed = 1;
3738 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3739 lpfc_update_rport_devloss_tmo(vport);
3743 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3744 "0404 lpfc_devloss_tmo attribute cannot be set to "
3745 "%d, allowed range is [%d, %d]\n",
3746 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3750 lpfc_vport_param_store(devloss_tmo)
3751 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3754 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3755 * lpfc_suppress_rsp = 0 Disable
3756 * lpfc_suppress_rsp = 1 Enable (default)
3759 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3760 "Enable suppress rsp feature is firmware supports it");
3763 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3764 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3765 * lpfc_nvmet_mrq = 1 use a single RQ pair
3766 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3769 LPFC_ATTR_R(nvmet_mrq,
3770 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3771 "Specify number of RQ pairs for processing NVMET cmds");
3774 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3775 * to each NVMET RQ. Range 64 to 2048, default is 512.
3777 LPFC_ATTR_R(nvmet_mrq_post,
3778 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3779 LPFC_NVMET_RQE_DEF_COUNT,
3780 "Specify number of RQ buffers to initially post");
3783 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3784 * Supported Values: 1 - register just FCP
3785 * 3 - register both FCP and NVME
3786 * Supported values are [1,3]. Default value is 3
3788 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3789 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3790 "Enable FC4 Protocol support - FCP / NVME");
3793 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3794 # deluged with LOTS of information.
3795 # You can set a bit mask to record specific types of verbose messages:
3796 # See lpfc_logmsh.h for definitions.
3798 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3799 "Verbose logging bit-mask");
3802 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3803 # objects that have been registered with the nameserver after login.
3805 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3806 "Deregister nameserver objects before LOGO");
3809 # lun_queue_depth: This parameter is used to limit the number of outstanding
3810 # commands per FCP LUN.
3812 LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
3813 "Max number of FCP commands we can queue to a specific LUN");
3816 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3817 # commands per target port. Value range is [10,65535]. Default value is 65535.
3819 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3820 module_param(lpfc_tgt_queue_depth, uint, 0444);
3821 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3822 lpfc_vport_param_show(tgt_queue_depth);
3823 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3824 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3827 * lpfc_tgt_queue_depth_set: Sets an attribute value.
3828 * @vport: lpfc vport structure pointer.
3829 * @val: integer attribute value.
3831 * Description: Sets the parameter to the new value.
3835 * -EINVAL if val is invalid
3838 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3840 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3841 struct lpfc_nodelist *ndlp;
3843 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3846 if (val == vport->cfg_tgt_queue_depth)
3849 spin_lock_irq(shost->host_lock);
3850 vport->cfg_tgt_queue_depth = val;
3852 /* Next loop thru nodelist and change cmd_qdepth */
3853 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3854 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3856 spin_unlock_irq(shost->host_lock);
3860 lpfc_vport_param_store(tgt_queue_depth);
3861 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3864 # hba_queue_depth: This parameter is used to limit the number of outstanding
3865 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3866 # value is greater than the maximum number of exchanges supported by the HBA,
3867 # then maximum number of exchanges supported by the HBA is used to determine
3868 # the hba_queue_depth.
3870 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3871 "Max number of FCP commands we can queue to a lpfc HBA");
3874 # peer_port_login: This parameter allows/prevents logins
3875 # between peer ports hosted on the same physical port.
3876 # When this parameter is set 0 peer ports of same physical port
3877 # are not allowed to login to each other.
3878 # When this parameter is set 1 peer ports of same physical port
3879 # are allowed to login to each other.
3880 # Default value of this parameter is 0.
3882 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3883 "Allow peer ports on the same physical port to login to each "
3887 # restrict_login: This parameter allows/prevents logins
3888 # between Virtual Ports and remote initiators.
3889 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3890 # other initiators and will attempt to PLOGI all remote ports.
3891 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3892 # remote ports and will not attempt to PLOGI to other initiators.
3893 # This parameter does not restrict to the physical port.
3894 # This parameter does not restrict logins to Fabric resident remote ports.
3895 # Default value of this parameter is 1.
3897 static int lpfc_restrict_login = 1;
3898 module_param(lpfc_restrict_login, int, S_IRUGO);
3899 MODULE_PARM_DESC(lpfc_restrict_login,
3900 "Restrict virtual ports login to remote initiators.");
3901 lpfc_vport_param_show(restrict_login);
3904 * lpfc_restrict_login_init - Set the vport restrict login flag
3905 * @vport: lpfc vport structure pointer.
3906 * @val: contains the restrict login value.
3909 * If val is not in a valid range then log a kernel error message and set
3910 * the vport restrict login to one.
3911 * If the port type is physical clear the restrict login flag and return.
3912 * Else set the restrict login flag to val.
3915 * zero if val is in range
3916 * -EINVAL val out of range
3919 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3921 if (val < 0 || val > 1) {
3922 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3923 "0422 lpfc_restrict_login attribute cannot "
3924 "be set to %d, allowed range is [0, 1]\n",
3926 vport->cfg_restrict_login = 1;
3929 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3930 vport->cfg_restrict_login = 0;
3933 vport->cfg_restrict_login = val;
3938 * lpfc_restrict_login_set - Set the vport restrict login flag
3939 * @vport: lpfc vport structure pointer.
3940 * @val: contains the restrict login value.
3943 * If val is not in a valid range then log a kernel error message and set
3944 * the vport restrict login to one.
3945 * If the port type is physical and the val is not zero log a kernel
3946 * error message, clear the restrict login flag and return zero.
3947 * Else set the restrict login flag to val.
3950 * zero if val is in range
3951 * -EINVAL val out of range
3954 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3956 if (val < 0 || val > 1) {
3957 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3958 "0425 lpfc_restrict_login attribute cannot "
3959 "be set to %d, allowed range is [0, 1]\n",
3961 vport->cfg_restrict_login = 1;
3964 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3965 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3966 "0468 lpfc_restrict_login must be 0 for "
3967 "Physical ports.\n");
3968 vport->cfg_restrict_login = 0;
3971 vport->cfg_restrict_login = val;
3974 lpfc_vport_param_store(restrict_login);
3975 static DEVICE_ATTR_RW(lpfc_restrict_login);
3978 # Some disk devices have a "select ID" or "select Target" capability.
3979 # From a protocol standpoint "select ID" usually means select the
3980 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3981 # annex" which contains a table that maps a "select ID" (a number
3982 # between 0 and 7F) to an ALPA. By default, for compatibility with
3983 # older drivers, the lpfc driver scans this table from low ALPA to high
3986 # Turning on the scan-down variable (on = 1, off = 0) will
3987 # cause the lpfc driver to use an inverted table, effectively
3988 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3990 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3991 # and will not work across a fabric. Also this parameter will take
3992 # effect only in the case when ALPA map is not available.)
3994 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3995 "Start scanning for devices from highest ALPA to lowest");
3998 # lpfc_topology: link topology for init link
3999 # 0x0 = attempt loop mode then point-to-point
4000 # 0x01 = internal loopback mode
4001 # 0x02 = attempt point-to-point mode only
4002 # 0x04 = attempt loop mode only
4003 # 0x06 = attempt point-to-point mode then loop
4004 # Set point-to-point mode if you want to run as an N_Port.
4005 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4006 # Default value is 0.
4008 LPFC_ATTR(topology, 0, 0, 6,
4009 "Select Fibre Channel topology");
4012 * lpfc_topology_store - Set the adapters topology field
4013 * @dev: class device that is converted into a scsi_host.
4014 * @attr:device attribute, not used.
4015 * @buf: buffer for passing information.
4016 * @count: size of the data buffer.
4019 * If val is in a valid range then set the adapter's topology field and
4020 * issue a lip; if the lip fails reset the topology to the old value.
4022 * If the value is not in range log a kernel error message and return an error.
4025 * zero if val is in range and lip okay
4026 * non-zero return value from lpfc_issue_lip()
4027 * -EINVAL val out of range
4030 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4031 const char *buf, size_t count)
4033 struct Scsi_Host *shost = class_to_shost(dev);
4034 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4035 struct lpfc_hba *phba = vport->phba;
4038 const char *val_buf = buf;
4041 u8 sli_family, if_type;
4043 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4045 val_buf = &buf[strlen("nolip ")];
4048 if (!isdigit(val_buf[0]))
4050 if (sscanf(val_buf, "%i", &val) != 1)
4053 if (val >= 0 && val <= 6) {
4054 prev_val = phba->cfg_topology;
4055 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4057 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4058 "3113 Loop mode not supported at speed %d\n",
4063 * The 'topology' is not a configurable parameter if :
4064 * - persistent topology enabled
4065 * - ASIC_GEN_NUM >= 0xC, with no private loop support
4067 sli_family = bf_get(lpfc_sli_intf_sli_family,
4068 &phba->sli4_hba.sli_intf);
4069 if_type = bf_get(lpfc_sli_intf_if_type,
4070 &phba->sli4_hba.sli_intf);
4071 if ((phba->hba_flag & HBA_PERSISTENT_TOPO ||
4072 (!phba->sli4_hba.pc_sli4_params.pls &&
4073 (sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
4074 if_type == LPFC_SLI_INTF_IF_TYPE_6))) &&
4076 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4077 "3114 Loop mode not supported\n");
4080 phba->cfg_topology = val;
4084 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4085 "3054 lpfc_topology changed from %d to %d\n",
4087 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4088 phba->fc_topology_changed = 1;
4089 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4091 phba->cfg_topology = prev_val;
4096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4097 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4098 "allowed range is [0, 6]\n",
4103 lpfc_param_show(topology)
4104 static DEVICE_ATTR_RW(lpfc_topology);
4107 * lpfc_static_vport_show: Read callback function for
4108 * lpfc_static_vport sysfs file.
4109 * @dev: Pointer to class device object.
4110 * @attr: device attribute structure.
4111 * @buf: Data buffer.
4113 * This function is the read call back function for
4114 * lpfc_static_vport sysfs file. The lpfc_static_vport
4115 * sysfs file report the mageability of the vport.
4118 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4121 struct Scsi_Host *shost = class_to_shost(dev);
4122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4123 if (vport->vport_flag & STATIC_VPORT)
4124 sprintf(buf, "1\n");
4126 sprintf(buf, "0\n");
4132 * Sysfs attribute to control the statistical data collection.
4134 static DEVICE_ATTR_RO(lpfc_static_vport);
4137 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
4138 * @dev: Pointer to class device.
4140 * @buf: Data buffer.
4141 * @count: Size of the data buffer.
4143 * This function get called when a user write to the lpfc_stat_data_ctrl
4144 * sysfs file. This function parse the command written to the sysfs file
4145 * and take appropriate action. These commands are used for controlling
4146 * driver statistical data collection.
4147 * Following are the command this function handles.
4149 * setbucket <bucket_type> <base> <step>
4150 * = Set the latency buckets.
4151 * destroybucket = destroy all the buckets.
4152 * start = start data collection
4153 * stop = stop data collection
4154 * reset = reset the collected data
4157 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4158 const char *buf, size_t count)
4160 struct Scsi_Host *shost = class_to_shost(dev);
4161 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4162 struct lpfc_hba *phba = vport->phba;
4163 #define LPFC_MAX_DATA_CTRL_LEN 1024
4164 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4166 char *str_ptr, *token;
4167 struct lpfc_vport **vports;
4168 struct Scsi_Host *v_shost;
4169 char *bucket_type_str, *base_str, *step_str;
4170 unsigned long base, step, bucket_type;
4172 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
4173 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
4176 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
4177 str_ptr = &bucket_data[0];
4178 /* Ignore this token - this is command token */
4179 token = strsep(&str_ptr, "\t ");
4183 bucket_type_str = strsep(&str_ptr, "\t ");
4184 if (!bucket_type_str)
4187 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4188 bucket_type = LPFC_LINEAR_BUCKET;
4189 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4190 bucket_type = LPFC_POWER2_BUCKET;
4194 base_str = strsep(&str_ptr, "\t ");
4197 base = simple_strtoul(base_str, NULL, 0);
4199 step_str = strsep(&str_ptr, "\t ");
4202 step = simple_strtoul(step_str, NULL, 0);
4206 /* Block the data collection for every vport */
4207 vports = lpfc_create_vport_work_array(phba);
4211 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4212 v_shost = lpfc_shost_from_vport(vports[i]);
4213 spin_lock_irq(v_shost->host_lock);
4214 /* Block and reset data collection */
4215 vports[i]->stat_data_blocked = 1;
4216 if (vports[i]->stat_data_enabled)
4217 lpfc_vport_reset_stat_data(vports[i]);
4218 spin_unlock_irq(v_shost->host_lock);
4221 /* Set the bucket attributes */
4222 phba->bucket_type = bucket_type;
4223 phba->bucket_base = base;
4224 phba->bucket_step = step;
4226 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4227 v_shost = lpfc_shost_from_vport(vports[i]);
4229 /* Unblock data collection */
4230 spin_lock_irq(v_shost->host_lock);
4231 vports[i]->stat_data_blocked = 0;
4232 spin_unlock_irq(v_shost->host_lock);
4234 lpfc_destroy_vport_work_array(phba, vports);
4238 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4239 vports = lpfc_create_vport_work_array(phba);
4243 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4244 v_shost = lpfc_shost_from_vport(vports[i]);
4245 spin_lock_irq(shost->host_lock);
4246 vports[i]->stat_data_blocked = 1;
4247 lpfc_free_bucket(vport);
4248 vport->stat_data_enabled = 0;
4249 vports[i]->stat_data_blocked = 0;
4250 spin_unlock_irq(shost->host_lock);
4252 lpfc_destroy_vport_work_array(phba, vports);
4253 phba->bucket_type = LPFC_NO_BUCKET;
4254 phba->bucket_base = 0;
4255 phba->bucket_step = 0;
4259 if (!strncmp(buf, "start", strlen("start"))) {
4260 /* If no buckets configured return error */
4261 if (phba->bucket_type == LPFC_NO_BUCKET)
4263 spin_lock_irq(shost->host_lock);
4264 if (vport->stat_data_enabled) {
4265 spin_unlock_irq(shost->host_lock);
4268 lpfc_alloc_bucket(vport);
4269 vport->stat_data_enabled = 1;
4270 spin_unlock_irq(shost->host_lock);
4274 if (!strncmp(buf, "stop", strlen("stop"))) {
4275 spin_lock_irq(shost->host_lock);
4276 if (vport->stat_data_enabled == 0) {
4277 spin_unlock_irq(shost->host_lock);
4280 lpfc_free_bucket(vport);
4281 vport->stat_data_enabled = 0;
4282 spin_unlock_irq(shost->host_lock);
4286 if (!strncmp(buf, "reset", strlen("reset"))) {
4287 if ((phba->bucket_type == LPFC_NO_BUCKET)
4288 || !vport->stat_data_enabled)
4290 spin_lock_irq(shost->host_lock);
4291 vport->stat_data_blocked = 1;
4292 lpfc_vport_reset_stat_data(vport);
4293 vport->stat_data_blocked = 0;
4294 spin_unlock_irq(shost->host_lock);
4302 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
4303 * @dev: Pointer to class device.
4305 * @buf: Data buffer.
4307 * This function is the read call back function for
4308 * lpfc_stat_data_ctrl sysfs file. This function report the
4309 * current statistical data collection state.
4312 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4315 struct Scsi_Host *shost = class_to_shost(dev);
4316 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4317 struct lpfc_hba *phba = vport->phba;
4321 unsigned long bucket_value;
4323 switch (phba->bucket_type) {
4324 case LPFC_LINEAR_BUCKET:
4325 bucket_type = "linear";
4327 case LPFC_POWER2_BUCKET:
4328 bucket_type = "power2";
4331 bucket_type = "No Bucket";
4335 sprintf(&buf[index], "Statistical Data enabled :%d, "
4336 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4337 " Bucket step :%d\nLatency Ranges :",
4338 vport->stat_data_enabled, vport->stat_data_blocked,
4339 bucket_type, phba->bucket_base, phba->bucket_step);
4340 index = strlen(buf);
4341 if (phba->bucket_type != LPFC_NO_BUCKET) {
4342 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4343 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4344 bucket_value = phba->bucket_base +
4345 phba->bucket_step * i;
4347 bucket_value = phba->bucket_base +
4348 (1 << i) * phba->bucket_step;
4350 if (index + 10 > PAGE_SIZE)
4352 sprintf(&buf[index], "%08ld ", bucket_value);
4353 index = strlen(buf);
4356 sprintf(&buf[index], "\n");
4361 * Sysfs attribute to control the statistical data collection.
4363 static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
4366 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4370 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4373 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4374 #define MAX_STAT_DATA_SIZE_PER_TARGET \
4375 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4379 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
4381 * @kobj: Pointer to the kernel object
4382 * @bin_attr: Attribute object
4383 * @buf: Buffer pointer
4385 * @count: Buffer size
4387 * This function is the read call back function for lpfc_drvr_stat_data
4388 * sysfs file. This function export the statistical data to user
4392 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4393 struct bin_attribute *bin_attr,
4394 char *buf, loff_t off, size_t count)
4396 struct device *dev = container_of(kobj, struct device,
4398 struct Scsi_Host *shost = class_to_shost(dev);
4399 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4400 struct lpfc_hba *phba = vport->phba;
4401 int i = 0, index = 0;
4402 unsigned long nport_index;
4403 struct lpfc_nodelist *ndlp = NULL;
4404 nport_index = (unsigned long)off /
4405 MAX_STAT_DATA_SIZE_PER_TARGET;
4407 if (!vport->stat_data_enabled || vport->stat_data_blocked
4408 || (phba->bucket_type == LPFC_NO_BUCKET))
4411 spin_lock_irq(shost->host_lock);
4412 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4413 if (!ndlp->lat_data)
4416 if (nport_index > 0) {
4421 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4425 if (!ndlp->lat_data)
4429 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4430 ndlp->nlp_portname.u.wwn[0],
4431 ndlp->nlp_portname.u.wwn[1],
4432 ndlp->nlp_portname.u.wwn[2],
4433 ndlp->nlp_portname.u.wwn[3],
4434 ndlp->nlp_portname.u.wwn[4],
4435 ndlp->nlp_portname.u.wwn[5],
4436 ndlp->nlp_portname.u.wwn[6],
4437 ndlp->nlp_portname.u.wwn[7]);
4439 index = strlen(buf);
4441 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4442 sprintf(&buf[index], "%010u,",
4443 ndlp->lat_data[i].cmd_count);
4444 index = strlen(buf);
4446 sprintf(&buf[index], "\n");
4447 index = strlen(buf);
4449 spin_unlock_irq(shost->host_lock);
4453 static struct bin_attribute sysfs_drvr_stat_data_attr = {
4455 .name = "lpfc_drvr_stat_data",
4458 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4459 .read = sysfs_drvr_stat_data_read,
4464 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4466 # Value range is [0,16]. Default value is 0.
4469 * lpfc_link_speed_store - Set the adapters link speed
4470 * @dev: Pointer to class device.
4472 * @buf: Data buffer.
4473 * @count: Size of the data buffer.
4476 * If val is in a valid range then set the adapter's link speed field and
4477 * issue a lip; if the lip fails reset the link speed to the old value.
4480 * If the value is not in range log a kernel error message and return an error.
4483 * zero if val is in range and lip okay.
4484 * non-zero return value from lpfc_issue_lip()
4485 * -EINVAL val out of range
4488 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4489 const char *buf, size_t count)
4491 struct Scsi_Host *shost = class_to_shost(dev);
4492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4493 struct lpfc_hba *phba = vport->phba;
4494 int val = LPFC_USER_LINK_SPEED_AUTO;
4496 const char *val_buf = buf;
4498 uint32_t prev_val, if_type;
4500 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4501 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4502 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4505 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4507 val_buf = &buf[strlen("nolip ")];
4510 if (!isdigit(val_buf[0]))
4512 if (sscanf(val_buf, "%i", &val) != 1)
4515 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4516 "3055 lpfc_link_speed changed from %d to %d %s\n",
4517 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4519 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4520 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4521 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4522 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4523 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4524 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4525 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4526 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4527 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4528 "2879 lpfc_link_speed attribute cannot be set "
4529 "to %d. Speed is not supported by this port.\n",
4533 if (val >= LPFC_USER_LINK_SPEED_16G &&
4534 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4535 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4536 "3112 lpfc_link_speed attribute cannot be set "
4537 "to %d. Speed is not supported in loop mode.\n",
4543 case LPFC_USER_LINK_SPEED_AUTO:
4544 case LPFC_USER_LINK_SPEED_1G:
4545 case LPFC_USER_LINK_SPEED_2G:
4546 case LPFC_USER_LINK_SPEED_4G:
4547 case LPFC_USER_LINK_SPEED_8G:
4548 case LPFC_USER_LINK_SPEED_16G:
4549 case LPFC_USER_LINK_SPEED_32G:
4550 case LPFC_USER_LINK_SPEED_64G:
4551 prev_val = phba->cfg_link_speed;
4552 phba->cfg_link_speed = val;
4556 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4558 phba->cfg_link_speed = prev_val;
4566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4567 "0469 lpfc_link_speed attribute cannot be set to %d, "
4568 "allowed values are [%s]\n",
4569 val, LPFC_LINK_SPEED_STRING);
4574 static int lpfc_link_speed = 0;
4575 module_param(lpfc_link_speed, int, S_IRUGO);
4576 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4577 lpfc_param_show(link_speed)
4580 * lpfc_link_speed_init - Set the adapters link speed
4581 * @phba: lpfc_hba pointer.
4582 * @val: link speed value.
4585 * If val is in a valid range then set the adapter's link speed field.
4588 * If the value is not in range log a kernel error message, clear the link
4589 * speed and return an error.
4592 * zero if val saved.
4593 * -EINVAL val out of range
4596 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4598 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4600 "3111 lpfc_link_speed of %d cannot "
4601 "support loop mode, setting topology to default.\n",
4603 phba->cfg_topology = 0;
4607 case LPFC_USER_LINK_SPEED_AUTO:
4608 case LPFC_USER_LINK_SPEED_1G:
4609 case LPFC_USER_LINK_SPEED_2G:
4610 case LPFC_USER_LINK_SPEED_4G:
4611 case LPFC_USER_LINK_SPEED_8G:
4612 case LPFC_USER_LINK_SPEED_16G:
4613 case LPFC_USER_LINK_SPEED_32G:
4614 case LPFC_USER_LINK_SPEED_64G:
4615 phba->cfg_link_speed = val;
4618 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4619 "0405 lpfc_link_speed attribute cannot "
4620 "be set to %d, allowed values are "
4621 "["LPFC_LINK_SPEED_STRING"]\n", val);
4622 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4627 static DEVICE_ATTR_RW(lpfc_link_speed);
4630 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4631 # 0 = aer disabled or not supported
4632 # 1 = aer supported and enabled (default)
4633 # Value range is [0,1]. Default value is 1.
4635 LPFC_ATTR(aer_support, 1, 0, 1,
4636 "Enable PCIe device AER support");
4637 lpfc_param_show(aer_support)
4640 * lpfc_aer_support_store - Set the adapter for aer support
4642 * @dev: class device that is converted into a Scsi_host.
4643 * @attr: device attribute, not used.
4644 * @buf: containing enable or disable aer flag.
4645 * @count: unused variable.
4648 * If the val is 1 and currently the device's AER capability was not
4649 * enabled, invoke the kernel's enable AER helper routine, trying to
4650 * enable the device's AER capability. If the helper routine enabling
4651 * AER returns success, update the device's cfg_aer_support flag to
4652 * indicate AER is supported by the device; otherwise, if the device
4653 * AER capability is already enabled to support AER, then do nothing.
4655 * If the val is 0 and currently the device's AER support was enabled,
4656 * invoke the kernel's disable AER helper routine. After that, update
4657 * the device's cfg_aer_support flag to indicate AER is not supported
4658 * by the device; otherwise, if the device AER capability is already
4659 * disabled from supporting AER, then do nothing.
4662 * length of the buf on success if val is in range the intended mode
4664 * -EINVAL if val out of range or intended mode is not supported.
4667 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4668 const char *buf, size_t count)
4670 struct Scsi_Host *shost = class_to_shost(dev);
4671 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4672 struct lpfc_hba *phba = vport->phba;
4673 int val = 0, rc = -EINVAL;
4675 if (!isdigit(buf[0]))
4677 if (sscanf(buf, "%i", &val) != 1)
4682 if (phba->hba_flag & HBA_AER_ENABLED) {
4683 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4685 spin_lock_irq(&phba->hbalock);
4686 phba->hba_flag &= ~HBA_AER_ENABLED;
4687 spin_unlock_irq(&phba->hbalock);
4688 phba->cfg_aer_support = 0;
4693 phba->cfg_aer_support = 0;
4698 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4699 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4701 spin_lock_irq(&phba->hbalock);
4702 phba->hba_flag |= HBA_AER_ENABLED;
4703 spin_unlock_irq(&phba->hbalock);
4704 phba->cfg_aer_support = 1;
4709 phba->cfg_aer_support = 1;
4720 static DEVICE_ATTR_RW(lpfc_aer_support);
4723 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4724 * @dev: class device that is converted into a Scsi_host.
4725 * @attr: device attribute, not used.
4726 * @buf: containing flag 1 for aer cleanup state.
4727 * @count: unused variable.
4730 * If the @buf contains 1 and the device currently has the AER support
4731 * enabled, then invokes the kernel AER helper routine
4732 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
4733 * error status register.
4738 * -EINVAL if the buf does not contain the 1 or the device is not currently
4739 * enabled with the AER support.
4742 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4743 const char *buf, size_t count)
4745 struct Scsi_Host *shost = class_to_shost(dev);
4746 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4747 struct lpfc_hba *phba = vport->phba;
4750 if (!isdigit(buf[0]))
4752 if (sscanf(buf, "%i", &val) != 1)
4757 if (phba->hba_flag & HBA_AER_ENABLED)
4758 rc = pci_aer_clear_nonfatal_status(phba->pcidev);
4766 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4767 lpfc_aer_cleanup_state);
4770 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4772 * @dev: class device that is converted into a Scsi_host.
4773 * @attr: device attribute, not used.
4774 * @buf: containing the string the number of vfs to be enabled.
4775 * @count: unused variable.
4778 * When this api is called either through user sysfs, the driver shall
4779 * try to enable or disable SR-IOV virtual functions according to the
4782 * If zero virtual function has been enabled to the physical function,
4783 * the driver shall invoke the pci enable virtual function api trying
4784 * to enable the virtual functions. If the nr_vfn provided is greater
4785 * than the maximum supported, the maximum virtual function number will
4786 * be used for invoking the api; otherwise, the nr_vfn provided shall
4787 * be used for invoking the api. If the api call returned success, the
4788 * actual number of virtual functions enabled will be set to the driver
4789 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4790 * cfg_sriov_nr_virtfn remains zero.
4792 * If none-zero virtual functions have already been enabled to the
4793 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4794 * -EINVAL will be returned and the driver does nothing;
4796 * If the nr_vfn provided is zero and none-zero virtual functions have
4797 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4798 * disabling virtual function api shall be invoded to disable all the
4799 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4800 * zero. Otherwise, if zero virtual function has been enabled, do
4804 * length of the buf on success if val is in range the intended mode
4806 * -EINVAL if val out of range or intended mode is not supported.
4809 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4810 const char *buf, size_t count)
4812 struct Scsi_Host *shost = class_to_shost(dev);
4813 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4814 struct lpfc_hba *phba = vport->phba;
4815 struct pci_dev *pdev = phba->pcidev;
4816 int val = 0, rc = -EINVAL;
4818 /* Sanity check on user data */
4819 if (!isdigit(buf[0]))
4821 if (sscanf(buf, "%i", &val) != 1)
4826 /* Request disabling virtual functions */
4828 if (phba->cfg_sriov_nr_virtfn > 0) {
4829 pci_disable_sriov(pdev);
4830 phba->cfg_sriov_nr_virtfn = 0;
4835 /* Request enabling virtual functions */
4836 if (phba->cfg_sriov_nr_virtfn > 0) {
4837 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4838 "3018 There are %d virtual functions "
4839 "enabled on physical function.\n",
4840 phba->cfg_sriov_nr_virtfn);
4844 if (val <= LPFC_MAX_VFN_PER_PFN)
4845 phba->cfg_sriov_nr_virtfn = val;
4847 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4848 "3019 Enabling %d virtual functions is not "
4853 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4855 phba->cfg_sriov_nr_virtfn = 0;
4863 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4864 "Enable PCIe device SR-IOV virtual fn");
4866 lpfc_param_show(sriov_nr_virtfn)
4867 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4870 * lpfc_request_firmware_upgrade_store - Request for Linux generic firmware upgrade
4872 * @dev: class device that is converted into a Scsi_host.
4873 * @attr: device attribute, not used.
4874 * @buf: containing the string the number of vfs to be enabled.
4875 * @count: unused variable.
4880 * length of the buf on success if val is in range the intended mode
4882 * -EINVAL if val out of range or intended mode is not supported.
4885 lpfc_request_firmware_upgrade_store(struct device *dev,
4886 struct device_attribute *attr,
4887 const char *buf, size_t count)
4889 struct Scsi_Host *shost = class_to_shost(dev);
4890 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4891 struct lpfc_hba *phba = vport->phba;
4894 /* Sanity check on user data */
4895 if (!isdigit(buf[0]))
4897 if (sscanf(buf, "%i", &val) != 1)
4902 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4910 static int lpfc_req_fw_upgrade;
4911 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4912 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4913 lpfc_param_show(request_firmware_upgrade)
4916 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4917 * @phba: lpfc_hba pointer.
4921 * Set the initial Linux generic firmware upgrade enable or disable flag.
4924 * zero if val saved.
4925 * -EINVAL val out of range
4928 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4930 if (val >= 0 && val <= 1) {
4931 phba->cfg_request_firmware_upgrade = val;
4936 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4937 lpfc_request_firmware_upgrade_show,
4938 lpfc_request_firmware_upgrade_store);
4941 * lpfc_force_rscn_store
4943 * @dev: class device that is converted into a Scsi_host.
4944 * @attr: device attribute, not used.
4945 * @buf: unused string
4946 * @count: unused variable.
4949 * Force the switch to send a RSCN to all other NPorts in our zone
4950 * If we are direct connect pt2pt, build the RSCN command ourself
4951 * and send to the other NPort. Not supported for private loop.
4955 * -EIO - if command is not sent
4958 lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4959 const char *buf, size_t count)
4961 struct Scsi_Host *shost = class_to_shost(dev);
4962 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4965 i = lpfc_issue_els_rscn(vport, 0);
4972 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4973 * connected to the HBA.
4975 * Value range is any ascii value
4977 static int lpfc_force_rscn;
4978 module_param(lpfc_force_rscn, int, 0644);
4979 MODULE_PARM_DESC(lpfc_force_rscn,
4980 "Force an RSCN to be sent to all remote NPorts");
4981 lpfc_param_show(force_rscn)
4984 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4985 * @phba: lpfc_hba pointer.
4986 * @val: unused value.
4989 * zero if val saved.
4992 lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
4996 static DEVICE_ATTR_RW(lpfc_force_rscn);
4999 * lpfc_fcp_imax_store
5001 * @dev: class device that is converted into a Scsi_host.
5002 * @attr: device attribute, not used.
5003 * @buf: string with the number of fast-path FCP interrupts per second.
5004 * @count: unused variable.
5007 * If val is in a valid range [636,651042], then set the adapter's
5008 * maximum number of fast-path FCP interrupts per second.
5011 * length of the buf on success if val is in range the intended mode
5013 * -EINVAL if val out of range or intended mode is not supported.
5016 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
5017 const char *buf, size_t count)
5019 struct Scsi_Host *shost = class_to_shost(dev);
5020 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5021 struct lpfc_hba *phba = vport->phba;
5022 struct lpfc_eq_intr_info *eqi;
5026 /* fcp_imax is only valid for SLI4 */
5027 if (phba->sli_rev != LPFC_SLI_REV4)
5030 /* Sanity check on user data */
5031 if (!isdigit(buf[0]))
5033 if (sscanf(buf, "%i", &val) != 1)
5037 * Value range for the HBA is [5000,5000000]
5038 * The value for each EQ depends on how many EQs are configured.
5041 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
5044 phba->cfg_auto_imax = (val) ? 0 : 1;
5045 if (phba->cfg_fcp_imax && !val) {
5046 queue_delayed_work(phba->wq, &phba->eq_delay_work,
5047 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
5049 for_each_present_cpu(i) {
5050 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
5055 phba->cfg_fcp_imax = (uint32_t)val;
5057 if (phba->cfg_fcp_imax)
5058 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
5062 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
5063 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
5070 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
5073 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
5075 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
5076 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
5077 MODULE_PARM_DESC(lpfc_fcp_imax,
5078 "Set the maximum number of FCP interrupts per second per HBA");
5079 lpfc_param_show(fcp_imax)
5082 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
5083 * @phba: lpfc_hba pointer.
5084 * @val: link speed value.
5087 * If val is in a valid range [636,651042], then initialize the adapter's
5088 * maximum number of fast-path FCP interrupts per second.
5091 * zero if val saved.
5092 * -EINVAL val out of range
5095 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
5097 if (phba->sli_rev != LPFC_SLI_REV4) {
5098 phba->cfg_fcp_imax = 0;
5102 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
5104 phba->cfg_fcp_imax = val;
5108 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5109 "3016 lpfc_fcp_imax: %d out of range, using default\n",
5111 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
5116 static DEVICE_ATTR_RW(lpfc_fcp_imax);
5119 * lpfc_cq_max_proc_limit_store
5121 * @dev: class device that is converted into a Scsi_host.
5122 * @attr: device attribute, not used.
5123 * @buf: string with the cq max processing limit of cqes
5124 * @count: unused variable.
5127 * If val is in a valid range, then set value on each cq
5130 * The length of the buf: if successful
5131 * -ERANGE: if val is not in the valid range
5132 * -EINVAL: if bad value format or intended mode is not supported.
5135 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
5136 const char *buf, size_t count)
5138 struct Scsi_Host *shost = class_to_shost(dev);
5139 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5140 struct lpfc_hba *phba = vport->phba;
5141 struct lpfc_queue *eq, *cq;
5145 /* cq_max_proc_limit is only valid for SLI4 */
5146 if (phba->sli_rev != LPFC_SLI_REV4)
5149 /* Sanity check on user data */
5150 if (!isdigit(buf[0]))
5152 if (kstrtoul(buf, 0, &val))
5155 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
5158 phba->cfg_cq_max_proc_limit = (uint32_t)val;
5160 /* set the values on the cq's */
5161 for (i = 0; i < phba->cfg_irq_chann; i++) {
5162 /* Get the EQ corresponding to the IRQ vector */
5163 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
5167 list_for_each_entry(cq, &eq->child_list, list)
5168 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
5176 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
5177 * itteration of CQ processing.
5179 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5180 module_param(lpfc_cq_max_proc_limit, int, 0644);
5181 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
5182 "Set the maximum number CQEs processed in an iteration of "
5184 lpfc_param_show(cq_max_proc_limit)
5187 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
5188 * single handler call which should request a polled completion rather
5189 * than re-enabling interrupts.
5191 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
5192 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
5193 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
5194 "CQE Processing Threshold to enable Polling");
5197 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
5198 * @phba: lpfc_hba pointer.
5202 * If val is in a valid range, then initialize the adapter's maximum
5206 * Always returns 0 for success, even if value not always set to
5207 * requested value. If value out of range or not supported, will fall
5211 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
5213 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5215 if (phba->sli_rev != LPFC_SLI_REV4)
5218 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
5219 phba->cfg_cq_max_proc_limit = val;
5223 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5224 "0371 lpfc_cq_max_proc_limit: %d out of range, using "
5226 phba->cfg_cq_max_proc_limit);
5231 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
5234 * lpfc_fcp_cpu_map_show - Display current driver CPU affinity
5235 * @dev: class converted to a Scsi_host structure.
5236 * @attr: device attribute, not used.
5237 * @buf: on return contains text describing the state of the link.
5239 * Returns: size of formatted string.
5242 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5245 struct Scsi_Host *shost = class_to_shost(dev);
5246 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5247 struct lpfc_hba *phba = vport->phba;
5248 struct lpfc_vector_map_info *cpup;
5251 if ((phba->sli_rev != LPFC_SLI_REV4) ||
5252 (phba->intr_type != MSIX))
5255 switch (phba->cfg_fcp_cpu_map) {
5257 len += scnprintf(buf + len, PAGE_SIZE-len,
5258 "fcp_cpu_map: No mapping (%d)\n",
5259 phba->cfg_fcp_cpu_map);
5262 len += scnprintf(buf + len, PAGE_SIZE-len,
5263 "fcp_cpu_map: HBA centric mapping (%d): "
5264 "%d of %d CPUs online from %d possible CPUs\n",
5265 phba->cfg_fcp_cpu_map, num_online_cpus(),
5267 phba->sli4_hba.num_possible_cpu);
5271 while (phba->sli4_hba.curr_disp_cpu <
5272 phba->sli4_hba.num_possible_cpu) {
5273 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5275 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5276 len += scnprintf(buf + len, PAGE_SIZE - len,
5277 "CPU %02d not present\n",
5278 phba->sli4_hba.curr_disp_cpu);
5279 else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
5280 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5282 buf + len, PAGE_SIZE - len,
5283 "CPU %02d hdwq None "
5284 "physid %d coreid %d ht %d ua %d\n",
5285 phba->sli4_hba.curr_disp_cpu,
5286 cpup->phys_id, cpup->core_id,
5287 (cpup->flag & LPFC_CPU_MAP_HYPER),
5288 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5291 buf + len, PAGE_SIZE - len,
5292 "CPU %02d EQ None hdwq %04d "
5293 "physid %d coreid %d ht %d ua %d\n",
5294 phba->sli4_hba.curr_disp_cpu,
5295 cpup->hdwq, cpup->phys_id,
5297 (cpup->flag & LPFC_CPU_MAP_HYPER),
5298 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5300 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5302 buf + len, PAGE_SIZE - len,
5303 "CPU %02d hdwq None "
5304 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5305 phba->sli4_hba.curr_disp_cpu,
5308 (cpup->flag & LPFC_CPU_MAP_HYPER),
5309 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5310 lpfc_get_irq(cpup->eq));
5313 buf + len, PAGE_SIZE - len,
5314 "CPU %02d EQ %04d hdwq %04d "
5315 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5316 phba->sli4_hba.curr_disp_cpu,
5317 cpup->eq, cpup->hdwq, cpup->phys_id,
5319 (cpup->flag & LPFC_CPU_MAP_HYPER),
5320 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5321 lpfc_get_irq(cpup->eq));
5324 phba->sli4_hba.curr_disp_cpu++;
5326 /* display max number of CPUs keeping some margin */
5327 if (phba->sli4_hba.curr_disp_cpu <
5328 phba->sli4_hba.num_possible_cpu &&
5329 (len >= (PAGE_SIZE - 64))) {
5330 len += scnprintf(buf + len,
5331 PAGE_SIZE - len, "more...\n");
5336 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
5337 phba->sli4_hba.curr_disp_cpu = 0;
5343 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5344 * @dev: class device that is converted into a Scsi_host.
5345 * @attr: device attribute, not used.
5346 * @buf: one or more lpfc_polling_flags values.
5350 * -EINVAL - Not implemented yet.
5353 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5354 const char *buf, size_t count)
5360 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5363 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5364 # 0 - Do not affinitze IRQ vectors
5365 # 1 - Affintize HBA vectors with respect to each HBA
5366 # (start with CPU0 for each HBA)
5367 # This also defines how Hardware Queues are mapped to specific CPUs.
5369 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5370 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5371 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5372 "Defines how to map CPUs to IRQ vectors per HBA");
5375 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5376 * @phba: lpfc_hba pointer.
5377 * @val: link speed value.
5380 * If val is in a valid range [0-2], then affinitze the adapter's
5384 * zero if val saved.
5385 * -EINVAL val out of range
5388 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5390 if (phba->sli_rev != LPFC_SLI_REV4) {
5391 phba->cfg_fcp_cpu_map = 0;
5395 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5396 phba->cfg_fcp_cpu_map = val;
5400 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5401 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5403 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5408 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5411 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5412 # Value range is [2,3]. Default value is 3.
5414 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5415 "Select Fibre Channel class of service for FCP sequences");
5418 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5419 # is [0,1]. Default value is 1.
5421 LPFC_VPORT_ATTR_RW(use_adisc, 1, 0, 1,
5422 "Use ADISC on rediscovery to authenticate FCP devices");
5425 # lpfc_first_burst_size: First burst size to use on the NPorts
5426 # that support first burst.
5427 # Value range is [0,65536]. Default value is 0.
5429 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5430 "First burst size for Targets that support first burst");
5433 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5434 * When the driver is configured as an NVME target, this value is
5435 * communicated to the NVME initiator in the PRLI response. It is
5436 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5437 * parameters are set and the target is sending the PRLI RSP.
5438 * Parameter supported on physical port only - no NPIV support.
5439 * Value range is [0,65536]. Default value is 0.
5441 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5442 "NVME Target mode first burst size in 512B increments.");
5445 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5446 * For the Initiator (I), enabling this parameter means that an NVMET
5447 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5448 * processed by the initiator for subsequent NVME FCP IO.
5449 * Currently, this feature is not supported on the NVME target
5450 * Value range is [0,1]. Default value is 0 (disabled).
5452 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5453 "Enable First Burst feature for NVME Initiator.");
5456 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5457 # depth. Default value is 0. When the value of this parameter is zero the
5458 # SCSI command completion time is not used for controlling I/O queue depth. When
5459 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5460 # to limit the I/O completion time to the parameter value.
5461 # The value is set in milliseconds.
5463 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5464 "Use command completion time to control queue depth");
5466 lpfc_vport_param_show(max_scsicmpl_time);
5468 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5470 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5471 struct lpfc_nodelist *ndlp, *next_ndlp;
5473 if (val == vport->cfg_max_scsicmpl_time)
5475 if ((val < 0) || (val > 60000))
5477 vport->cfg_max_scsicmpl_time = val;
5479 spin_lock_irq(shost->host_lock);
5480 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5481 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5483 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5485 spin_unlock_irq(shost->host_lock);
5488 lpfc_vport_param_store(max_scsicmpl_time);
5489 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5492 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5493 # range is [0,1]. Default value is 0.
5495 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5498 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5499 # range is [0,1]. Default value is 1.
5501 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5504 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5505 * range is [0,1]. Default value is 0.
5506 * For [0], FCP commands are issued to Work Queues based on upper layer
5507 * hardware queue index.
5508 * For [1], FCP commands are issued to a Work Queue associated with the
5511 * LPFC_FCP_SCHED_BY_HDWQ == 0
5512 * LPFC_FCP_SCHED_BY_CPU == 1
5514 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5515 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5516 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5517 * through WQs will be used.
5519 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5520 LPFC_FCP_SCHED_BY_HDWQ,
5521 LPFC_FCP_SCHED_BY_CPU,
5522 "Determine scheduling algorithm for "
5523 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5526 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5527 * range is [0,1]. Default value is 0.
5528 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5529 * For [1], GID_PT is used for NameServer queries after RSCN
5532 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5533 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5534 "Determine algorithm NameServer queries after RSCN "
5535 "[0] - GID_FT, [1] - GID_PT");
5538 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5539 # range is [0,1]. Default value is 0.
5540 # For [0], bus reset issues target reset to ALL devices
5541 # For [1], bus reset issues target reset to non-FCP2 devices
5543 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5544 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5548 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5549 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5550 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5551 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5552 # cr_delay is set to 0.
5554 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5555 "interrupt response is generated");
5557 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5558 "interrupt response is generated");
5561 # lpfc_multi_ring_support: Determines how many rings to spread available
5562 # cmd/rsp IOCB entries across.
5563 # Value range is [1,2]. Default value is 1.
5565 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5566 "SLI rings to spread IOCB entries across");
5569 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5570 # identifies what rctl value to configure the additional ring for.
5571 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5573 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5574 255, "Identifies RCTL for additional ring configuration");
5577 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5578 # identifies what type value to configure the additional ring for.
5579 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5581 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5582 255, "Identifies TYPE for additional ring configuration");
5585 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5586 # 0 = SmartSAN functionality disabled (default)
5587 # 1 = SmartSAN functionality enabled
5588 # This parameter will override the value of lpfc_fdmi_on module parameter.
5589 # Value range is [0,1]. Default value is 0.
5591 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5594 # lpfc_fdmi_on: Controls FDMI support.
5596 # 1 Traditional FDMI support (default)
5597 # Traditional FDMI support means the driver will assume FDMI-2 support;
5598 # however, if that fails, it will fallback to FDMI-1.
5599 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5600 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5602 # Value range [0,1]. Default value is 1.
5604 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5607 # Specifies the maximum number of ELS cmds we can have outstanding (for
5608 # discovery). Value range is [1,64]. Default value = 32.
5610 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5611 "during discovery");
5614 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5615 # will be scanned by the SCSI midlayer when sequential scanning is
5616 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5617 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5618 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5619 # above. The lpfc driver limits the default value to 255 for two reasons.
5620 # As it bounds the sequential scan loop, scanning for thousands of luns
5621 # on a target can take minutes of wall clock time. Additionally,
5622 # there are FC targets, such as JBODs, that only recognize 8-bits of
5623 # LUN ID. When they receive a value greater than 8 bits, they chop off
5624 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5625 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5626 # valid responses at each of the LUN IDs, to believe there are multiple
5627 # devices present, when in fact, there is only 1.
5628 # A customer that is aware of their target behaviors, and the results as
5629 # indicated above, is welcome to increase the lpfc_max_luns value.
5630 # As mentioned, this value is not used by the lpfc driver, only the
5632 # Value range is [0,65535]. Default value is 255.
5633 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5635 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5638 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5639 # Value range is [1,255], default value is 10.
5641 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5642 "Milliseconds driver will wait between polling FCP ring");
5645 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5646 # to complete in seconds. Value range is [5,180], default value is 60.
5648 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5649 "Maximum time to wait for task management commands to complete");
5651 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5652 # support this feature
5655 # 2 = MSI-X enabled (default)
5656 # Value range is [0,2]. Default value is 2.
5658 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5659 "MSI-X (2), if possible");
5662 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5664 * 0 = NVME OAS disabled
5665 * 1 = NVME OAS enabled
5667 * Value range is [0,1]. Default value is 0.
5669 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5670 "Use OAS bit on NVME IOs");
5673 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5675 * 0 = Put NVME Command in SGL
5676 * 1 = Embed NVME Command in WQE (unless G7)
5677 * 2 = Embed NVME Command in WQE (force)
5679 * Value range is [0,2]. Default value is 1.
5681 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5682 "Embed NVME Command in WQE");
5685 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5686 * the driver will advertise it supports to the SCSI layer.
5688 * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
5689 * 1,256 = Manually specify nr_hw_queue value to be advertised,
5691 * Value range is [0,256]. Default value is 8.
5693 LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5694 LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5695 "Set the number of SCSI Queues advertised");
5698 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5699 * will advertise it supports to the NVME and SCSI layers. This also
5700 * will map to the number of CQ/WQ pairs the driver will create.
5702 * The NVME Layer will try to create this many, plus 1 administrative
5703 * hardware queue. The administrative queue will always map to WQ 0
5704 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5706 * 0 = Configure the number of hdw queues to the number of active CPUs.
5707 * 1,256 = Manually specify how many hdw queues to use.
5709 * Value range is [0,256]. Default value is 0.
5711 LPFC_ATTR_R(hdw_queue,
5713 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5714 "Set the number of I/O Hardware Queues");
5716 #if IS_ENABLED(CONFIG_X86)
5718 * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
5720 * @phba: Pointer to HBA context object.
5723 lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)
5725 unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;
5726 const struct cpumask *sibling_mask;
5727 struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;
5729 cpumask_clear(aff_mask);
5731 if (phba->irq_chann_mode == NUMA_MODE) {
5732 /* Check if we're a NUMA architecture */
5733 numa_node = dev_to_node(&phba->pcidev->dev);
5734 if (numa_node == NUMA_NO_NODE) {
5735 phba->irq_chann_mode = NORMAL_MODE;
5740 for_each_possible_cpu(cpu) {
5741 switch (phba->irq_chann_mode) {
5743 if (cpu_to_node(cpu) == numa_node)
5744 cpumask_set_cpu(cpu, aff_mask);
5747 sibling_mask = topology_sibling_cpumask(cpu);
5748 first_cpu = cpumask_first(sibling_mask);
5749 if (first_cpu < nr_cpu_ids)
5750 cpumask_set_cpu(first_cpu, aff_mask);
5760 lpfc_assign_default_irq_chann(struct lpfc_hba *phba)
5762 #if IS_ENABLED(CONFIG_X86)
5763 switch (boot_cpu_data.x86_vendor) {
5764 case X86_VENDOR_AMD:
5765 /* If AMD architecture, then default is NUMA_MODE */
5766 phba->irq_chann_mode = NUMA_MODE;
5768 case X86_VENDOR_INTEL:
5769 /* If Intel architecture, then default is no hyperthread mode */
5770 phba->irq_chann_mode = NHT_MODE;
5773 phba->irq_chann_mode = NORMAL_MODE;
5776 lpfc_cpumask_irq_mode_init(phba);
5778 phba->irq_chann_mode = NORMAL_MODE;
5783 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5784 * for Hardware Queues to utilize. This also will map to the number
5785 * of EQ / MSI-X vectors the driver will create. This should never be
5786 * more than the number of Hardware Queues
5788 * 0 = Configure number of IRQ Channels to:
5789 * if AMD architecture, number of CPUs on HBA's NUMA node
5790 * if Intel architecture, number of physical CPUs.
5791 * otherwise, number of active CPUs.
5792 * [1,256] = Manually specify how many IRQ Channels to use.
5794 * Value range is [0,256]. Default value is [0].
5796 static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
5797 module_param(lpfc_irq_chann, uint, 0444);
5798 MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
5800 /* lpfc_irq_chann_init - Set the hba irq_chann initial value
5801 * @phba: lpfc_hba pointer.
5802 * @val: contains the initial value
5805 * Validates the initial value is within range and assigns it to the
5806 * adapter. If not in range, an error message is posted and the
5807 * default value is assigned.
5810 * zero if value is in range and is set
5811 * -EINVAL if value was out of range
5814 lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
5816 const struct cpumask *aff_mask;
5818 if (phba->cfg_use_msi != 2) {
5819 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5820 "8532 use_msi = %u ignoring cfg_irq_numa\n",
5822 phba->irq_chann_mode = NORMAL_MODE;
5823 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5827 /* Check if default setting was passed */
5828 if (val == LPFC_IRQ_CHANN_DEF &&
5829 phba->cfg_hdw_queue == LPFC_HBA_HDWQ_DEF &&
5830 phba->sli_rev == LPFC_SLI_REV4)
5831 lpfc_assign_default_irq_chann(phba);
5833 if (phba->irq_chann_mode != NORMAL_MODE) {
5834 aff_mask = &phba->sli4_hba.irq_aff_mask;
5836 if (cpumask_empty(aff_mask)) {
5837 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5838 "8533 Could not identify CPUS for "
5839 "mode %d, ignoring\n",
5840 phba->irq_chann_mode);
5841 phba->irq_chann_mode = NORMAL_MODE;
5842 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5844 phba->cfg_irq_chann = cpumask_weight(aff_mask);
5846 /* If no hyperthread mode, then set hdwq count to
5847 * aff_mask weight as well
5849 if (phba->irq_chann_mode == NHT_MODE)
5850 phba->cfg_hdw_queue = phba->cfg_irq_chann;
5852 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5853 "8543 lpfc_irq_chann set to %u "
5854 "(mode: %d)\n", phba->cfg_irq_chann,
5855 phba->irq_chann_mode);
5858 if (val > LPFC_IRQ_CHANN_MAX) {
5859 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5860 "8545 lpfc_irq_chann attribute cannot "
5861 "be set to %u, allowed range is "
5865 LPFC_IRQ_CHANN_MAX);
5866 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5869 if (phba->sli_rev == LPFC_SLI_REV4) {
5870 phba->cfg_irq_chann = val;
5872 phba->cfg_irq_chann = 2;
5873 phba->cfg_hdw_queue = 1;
5881 * lpfc_irq_chann_show - Display value of irq_chann
5882 * @dev: class converted to a Scsi_host structure.
5883 * @attr: device attribute, not used.
5884 * @buf: on return contains a string with the list sizes
5886 * Returns: size of formatted string.
5889 lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
5892 struct Scsi_Host *shost = class_to_shost(dev);
5893 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5894 struct lpfc_hba *phba = vport->phba;
5896 return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
5899 static DEVICE_ATTR_RO(lpfc_irq_chann);
5902 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5903 # 0 = HBA resets disabled
5904 # 1 = HBA resets enabled (default)
5905 # 2 = HBA reset via PCI bus reset enabled
5906 # Value range is [0,2]. Default value is 1.
5908 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5911 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5912 # 0 = HBA Heartbeat disabled
5913 # 1 = HBA Heartbeat enabled (default)
5914 # Value range is [0,1]. Default value is 1.
5916 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5919 # lpfc_EnableXLane: Enable Express Lane Feature
5920 # 0x0 Express Lane Feature disabled
5921 # 0x1 Express Lane Feature enabled
5922 # Value range is [0,1]. Default value is 0.
5924 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5927 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5928 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5929 # Value range is [0x0,0x7f]. Default value is 0
5931 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5934 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5935 # 0 = BlockGuard disabled (default)
5936 # 1 = BlockGuard enabled
5937 # Value range is [0,1]. Default value is 0.
5939 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5943 # - Bit mask of host protection capabilities used to register with the
5945 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5946 # - Allows you to ultimately specify which profiles to use
5947 # - Default will result in registering capabilities for all profiles.
5948 # - SHOST_DIF_TYPE1_PROTECTION 1
5949 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5950 # - SHOST_DIX_TYPE0_PROTECTION 8
5951 # HBA supports DIX Type 0: Host to HBA protection only
5952 # - SHOST_DIX_TYPE1_PROTECTION 16
5953 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5956 LPFC_ATTR(prot_mask,
5957 (SHOST_DIF_TYPE1_PROTECTION |
5958 SHOST_DIX_TYPE0_PROTECTION |
5959 SHOST_DIX_TYPE1_PROTECTION),
5961 (SHOST_DIF_TYPE1_PROTECTION |
5962 SHOST_DIX_TYPE0_PROTECTION |
5963 SHOST_DIX_TYPE1_PROTECTION),
5964 "T10-DIF host protection capabilities mask");
5968 # - Bit mask of protection guard types to register with the SCSI mid-layer
5969 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5970 # - Allows you to ultimately specify which profiles to use
5971 # - Default will result in registering capabilities for all guard types
5974 LPFC_ATTR(prot_guard,
5975 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5976 "T10-DIF host protection guard type");
5979 * Delay initial NPort discovery when Clean Address bit is cleared in
5980 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5981 * This parameter can have value 0 or 1.
5982 * When this parameter is set to 0, no delay is added to the initial
5984 * When this parameter is set to non-zero value, initial Nport discovery is
5985 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5986 * accept and FCID/Fabric name/Fabric portname is changed.
5987 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5988 * when Clean Address bit is cleared in FLOGI/FDISC
5989 * accept and FCID/Fabric name/Fabric portname is changed.
5990 * Default value is 0.
5992 LPFC_ATTR(delay_discovery, 0, 0, 1,
5993 "Delay NPort discovery when Clean Address bit is cleared.");
5996 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5997 * This value can be set to values between 64 and 4096. The default value
5998 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5999 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
6000 * Because of the additional overhead involved in setting up T10-DIF,
6001 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
6002 * and will be limited to 512 if BlockGuard is enabled under SLI3.
6004 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
6005 module_param(lpfc_sg_seg_cnt, uint, 0444);
6006 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
6009 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
6010 * configured for the adapter
6011 * @dev: class converted to a Scsi_host structure.
6012 * @attr: device attribute, not used.
6013 * @buf: on return contains a string with the list sizes
6015 * Returns: size of formatted string.
6018 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
6021 struct Scsi_Host *shost = class_to_shost(dev);
6022 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6023 struct lpfc_hba *phba = vport->phba;
6026 len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
6027 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
6029 len += scnprintf(buf + len, PAGE_SIZE, "Cfg: %d SCSI: %d NVME: %d\n",
6030 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
6031 phba->cfg_nvme_seg_cnt);
6035 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
6038 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
6039 * @phba: lpfc_hba pointer.
6040 * @val: contains the initial value
6043 * Validates the initial value is within range and assigns it to the
6044 * adapter. If not in range, an error message is posted and the
6045 * default value is assigned.
6048 * zero if value is in range and is set
6049 * -EINVAL if value was out of range
6052 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
6054 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
6055 phba->cfg_sg_seg_cnt = val;
6058 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6059 "0409 lpfc_sg_seg_cnt attribute cannot be set to %d, "
6060 "allowed range is [%d, %d]\n",
6061 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
6062 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
6067 * lpfc_enable_mds_diags: Enable MDS Diagnostics
6068 * 0 = MDS Diagnostics disabled (default)
6069 * 1 = MDS Diagnostics enabled
6070 * Value range is [0,1]. Default value is 0.
6072 LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
6075 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
6076 * 0 = Disable firmware logging (default)
6077 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
6078 * Value range [0..4]. Default value is 0
6080 LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
6081 lpfc_param_show(ras_fwlog_buffsize);
6084 lpfc_ras_fwlog_buffsize_set(struct lpfc_hba *phba, uint val)
6087 enum ras_state state;
6089 if (!lpfc_rangecheck(val, 0, 4))
6092 if (phba->cfg_ras_fwlog_buffsize == val)
6095 if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
6098 spin_lock_irq(&phba->hbalock);
6099 state = phba->ras_fwlog.state;
6100 spin_unlock_irq(&phba->hbalock);
6102 if (state == REG_INPROGRESS) {
6103 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
6104 "registration is in progress\n");
6108 /* For disable logging: stop the logs and free the DMA.
6109 * For ras_fwlog_buffsize size change we still need to free and
6110 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
6112 phba->cfg_ras_fwlog_buffsize = val;
6113 if (state == ACTIVE) {
6114 lpfc_ras_stop_fwlog(phba);
6115 lpfc_sli4_ras_dma_free(phba);
6118 lpfc_sli4_ras_init(phba);
6119 if (phba->ras_fwlog.ras_enabled)
6120 ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
6121 LPFC_RAS_ENABLE_LOGGING);
6125 lpfc_param_store(ras_fwlog_buffsize);
6126 static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
6129 * lpfc_ras_fwlog_level: Firmware logging verbosity level
6130 * Valid only if firmware logging is enabled
6131 * 0(Least Verbosity) 4 (most verbosity)
6132 * Value range is [0..4]. Default value is 0
6134 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
6137 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
6138 * Default function which has RAS support : 0
6139 * Value Range is [0..7].
6140 * FW logging is a global action and enablement is via a specific
6143 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
6146 * lpfc_enable_bbcr: Enable BB Credit Recovery
6147 * 0 = BB Credit Recovery disabled
6148 * 1 = BB Credit Recovery enabled (default)
6149 * Value range is [0,1]. Default value is 1.
6151 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
6153 /* Signaling module parameters */
6154 int lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
6155 module_param(lpfc_fabric_cgn_frequency, int, 0444);
6156 MODULE_PARM_DESC(lpfc_fabric_cgn_frequency, "Congestion signaling fabric freq");
6158 int lpfc_acqe_cgn_frequency = 10; /* 10 sec default */
6159 module_param(lpfc_acqe_cgn_frequency, int, 0444);
6160 MODULE_PARM_DESC(lpfc_acqe_cgn_frequency, "Congestion signaling ACQE freq");
6162 int lpfc_use_cgn_signal = 1; /* 0 - only use FPINs, 1 - Use signals if avail */
6163 module_param(lpfc_use_cgn_signal, int, 0444);
6164 MODULE_PARM_DESC(lpfc_use_cgn_signal, "Use Congestion signaling if available");
6167 * lpfc_enable_dpp: Enable DPP on G7
6168 * 0 = DPP on G7 disabled
6169 * 1 = DPP on G7 enabled (default)
6170 * Value range is [0,1]. Default value is 1.
6172 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
6175 * lpfc_enable_mi: Enable FDMI MIB
6177 * 1 = enabled (default)
6178 * Value range is [0,1].
6180 LPFC_ATTR_R(enable_mi, 1, 0, 1, "Enable MI");
6183 * lpfc_max_vmid: Maximum number of VMs to be tagged. This is valid only if
6184 * either vmid_app_header or vmid_priority_tagging is enabled.
6185 * 4 - 255 = vmid support enabled for 4-255 VMs
6186 * Value range is [4,255].
6188 LPFC_ATTR_RW(max_vmid, LPFC_MIN_VMID, LPFC_MIN_VMID, LPFC_MAX_VMID,
6189 "Maximum number of VMs supported");
6192 * lpfc_vmid_inactivity_timeout: Inactivity timeout duration in hours
6193 * 0 = Timeout is disabled
6194 * Value range is [0,24].
6196 LPFC_ATTR_RW(vmid_inactivity_timeout, 4, 0, 24,
6197 "Inactivity timeout in hours");
6200 * lpfc_vmid_app_header: Enable App Header VMID support
6201 * 0 = Support is disabled (default)
6202 * 1 = Support is enabled
6203 * Value range is [0,1].
6205 LPFC_ATTR_RW(vmid_app_header, LPFC_VMID_APP_HEADER_DISABLE,
6206 LPFC_VMID_APP_HEADER_DISABLE, LPFC_VMID_APP_HEADER_ENABLE,
6207 "Enable App Header VMID support");
6210 * lpfc_vmid_priority_tagging: Enable Priority Tagging VMID support
6211 * 0 = Support is disabled (default)
6212 * 1 = Allow supported targets only
6213 * 2 = Allow all targets
6214 * Value range is [0,2].
6216 LPFC_ATTR_RW(vmid_priority_tagging, LPFC_VMID_PRIO_TAG_DISABLE,
6217 LPFC_VMID_PRIO_TAG_DISABLE,
6218 LPFC_VMID_PRIO_TAG_ALL_TARGETS,
6219 "Enable Priority Tagging VMID support");
6221 struct device_attribute *lpfc_hba_attrs[] = {
6222 &dev_attr_nvme_info,
6223 &dev_attr_scsi_stat,
6225 &dev_attr_bg_guard_err,
6226 &dev_attr_bg_apptag_err,
6227 &dev_attr_bg_reftag_err,
6229 &dev_attr_serialnum,
6230 &dev_attr_modeldesc,
6231 &dev_attr_modelname,
6232 &dev_attr_programtype,
6236 &dev_attr_option_rom_version,
6237 &dev_attr_link_state,
6238 &dev_attr_num_discovered_ports,
6239 &dev_attr_menlo_mgmt_mode,
6240 &dev_attr_lpfc_drvr_version,
6241 &dev_attr_lpfc_enable_fip,
6242 &dev_attr_lpfc_temp_sensor,
6243 &dev_attr_lpfc_log_verbose,
6244 &dev_attr_lpfc_lun_queue_depth,
6245 &dev_attr_lpfc_tgt_queue_depth,
6246 &dev_attr_lpfc_hba_queue_depth,
6247 &dev_attr_lpfc_peer_port_login,
6248 &dev_attr_lpfc_nodev_tmo,
6249 &dev_attr_lpfc_devloss_tmo,
6250 &dev_attr_lpfc_enable_fc4_type,
6251 &dev_attr_lpfc_fcp_class,
6252 &dev_attr_lpfc_use_adisc,
6253 &dev_attr_lpfc_first_burst_size,
6254 &dev_attr_lpfc_ack0,
6255 &dev_attr_lpfc_xri_rebalancing,
6256 &dev_attr_lpfc_topology,
6257 &dev_attr_lpfc_scan_down,
6258 &dev_attr_lpfc_link_speed,
6259 &dev_attr_lpfc_fcp_io_sched,
6260 &dev_attr_lpfc_ns_query,
6261 &dev_attr_lpfc_fcp2_no_tgt_reset,
6262 &dev_attr_lpfc_cr_delay,
6263 &dev_attr_lpfc_cr_count,
6264 &dev_attr_lpfc_multi_ring_support,
6265 &dev_attr_lpfc_multi_ring_rctl,
6266 &dev_attr_lpfc_multi_ring_type,
6267 &dev_attr_lpfc_fdmi_on,
6268 &dev_attr_lpfc_enable_SmartSAN,
6269 &dev_attr_lpfc_max_luns,
6270 &dev_attr_lpfc_enable_npiv,
6271 &dev_attr_lpfc_fcf_failover_policy,
6272 &dev_attr_lpfc_enable_rrq,
6273 &dev_attr_lpfc_fcp_wait_abts_rsp,
6274 &dev_attr_nport_evt_cnt,
6275 &dev_attr_board_mode,
6282 &dev_attr_npiv_info,
6283 &dev_attr_issue_reset,
6284 &dev_attr_lpfc_poll,
6285 &dev_attr_lpfc_poll_tmo,
6286 &dev_attr_lpfc_task_mgmt_tmo,
6287 &dev_attr_lpfc_use_msi,
6288 &dev_attr_lpfc_nvme_oas,
6289 &dev_attr_lpfc_nvme_embed_cmd,
6290 &dev_attr_lpfc_fcp_imax,
6291 &dev_attr_lpfc_force_rscn,
6292 &dev_attr_lpfc_cq_poll_threshold,
6293 &dev_attr_lpfc_cq_max_proc_limit,
6294 &dev_attr_lpfc_fcp_cpu_map,
6295 &dev_attr_lpfc_fcp_mq_threshold,
6296 &dev_attr_lpfc_hdw_queue,
6297 &dev_attr_lpfc_irq_chann,
6298 &dev_attr_lpfc_suppress_rsp,
6299 &dev_attr_lpfc_nvmet_mrq,
6300 &dev_attr_lpfc_nvmet_mrq_post,
6301 &dev_attr_lpfc_nvme_enable_fb,
6302 &dev_attr_lpfc_nvmet_fb_size,
6303 &dev_attr_lpfc_enable_bg,
6304 &dev_attr_lpfc_soft_wwnn,
6305 &dev_attr_lpfc_soft_wwpn,
6306 &dev_attr_lpfc_soft_wwn_enable,
6307 &dev_attr_lpfc_enable_hba_reset,
6308 &dev_attr_lpfc_enable_hba_heartbeat,
6309 &dev_attr_lpfc_EnableXLane,
6310 &dev_attr_lpfc_XLanePriority,
6311 &dev_attr_lpfc_xlane_lun,
6312 &dev_attr_lpfc_xlane_tgt,
6313 &dev_attr_lpfc_xlane_vpt,
6314 &dev_attr_lpfc_xlane_lun_state,
6315 &dev_attr_lpfc_xlane_lun_status,
6316 &dev_attr_lpfc_xlane_priority,
6317 &dev_attr_lpfc_sg_seg_cnt,
6318 &dev_attr_lpfc_max_scsicmpl_time,
6319 &dev_attr_lpfc_stat_data_ctrl,
6320 &dev_attr_lpfc_aer_support,
6321 &dev_attr_lpfc_aer_state_cleanup,
6322 &dev_attr_lpfc_sriov_nr_virtfn,
6323 &dev_attr_lpfc_req_fw_upgrade,
6324 &dev_attr_lpfc_suppress_link_up,
6329 &dev_attr_txcmplq_hw,
6330 &dev_attr_lpfc_sriov_hw_max_virtfn,
6332 &dev_attr_lpfc_xlane_supported,
6333 &dev_attr_lpfc_enable_mds_diags,
6334 &dev_attr_lpfc_ras_fwlog_buffsize,
6335 &dev_attr_lpfc_ras_fwlog_level,
6336 &dev_attr_lpfc_ras_fwlog_func,
6337 &dev_attr_lpfc_enable_bbcr,
6338 &dev_attr_lpfc_enable_dpp,
6339 &dev_attr_lpfc_enable_mi,
6340 &dev_attr_lpfc_max_vmid,
6341 &dev_attr_lpfc_vmid_inactivity_timeout,
6342 &dev_attr_lpfc_vmid_app_header,
6343 &dev_attr_lpfc_vmid_priority_tagging,
6347 struct device_attribute *lpfc_vport_attrs[] = {
6349 &dev_attr_link_state,
6350 &dev_attr_num_discovered_ports,
6351 &dev_attr_lpfc_drvr_version,
6352 &dev_attr_lpfc_log_verbose,
6353 &dev_attr_lpfc_lun_queue_depth,
6354 &dev_attr_lpfc_tgt_queue_depth,
6355 &dev_attr_lpfc_nodev_tmo,
6356 &dev_attr_lpfc_devloss_tmo,
6357 &dev_attr_lpfc_hba_queue_depth,
6358 &dev_attr_lpfc_peer_port_login,
6359 &dev_attr_lpfc_restrict_login,
6360 &dev_attr_lpfc_fcp_class,
6361 &dev_attr_lpfc_use_adisc,
6362 &dev_attr_lpfc_first_burst_size,
6363 &dev_attr_lpfc_max_luns,
6364 &dev_attr_nport_evt_cnt,
6365 &dev_attr_npiv_info,
6366 &dev_attr_lpfc_enable_da_id,
6367 &dev_attr_lpfc_max_scsicmpl_time,
6368 &dev_attr_lpfc_stat_data_ctrl,
6369 &dev_attr_lpfc_static_vport,
6374 * sysfs_ctlreg_write - Write method for writing to ctlreg
6375 * @filp: open sysfs file
6376 * @kobj: kernel kobject that contains the kernel class device.
6377 * @bin_attr: kernel attributes passed to us.
6378 * @buf: contains the data to be written to the adapter IOREG space.
6379 * @off: offset into buffer to beginning of data.
6380 * @count: bytes to transfer.
6383 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6384 * Uses the adapter io control registers to send buf contents to the adapter.
6387 * -ERANGE off and count combo out of range
6388 * -EINVAL off, count or buff address invalid
6389 * -EPERM adapter is offline
6390 * value of count, buf contents written
6393 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6394 struct bin_attribute *bin_attr,
6395 char *buf, loff_t off, size_t count)
6398 struct device *dev = container_of(kobj, struct device, kobj);
6399 struct Scsi_Host *shost = class_to_shost(dev);
6400 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6401 struct lpfc_hba *phba = vport->phba;
6403 if (phba->sli_rev >= LPFC_SLI_REV4)
6406 if ((off + count) > FF_REG_AREA_SIZE)
6409 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6412 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6415 /* This is to protect HBA registers from accidental writes. */
6416 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6419 if (!(vport->fc_flag & FC_OFFLINE_MODE))
6422 spin_lock_irq(&phba->hbalock);
6423 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6424 buf_off += sizeof(uint32_t))
6425 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6426 phba->ctrl_regs_memmap_p + off + buf_off);
6428 spin_unlock_irq(&phba->hbalock);
6434 * sysfs_ctlreg_read - Read method for reading from ctlreg
6435 * @filp: open sysfs file
6436 * @kobj: kernel kobject that contains the kernel class device.
6437 * @bin_attr: kernel attributes passed to us.
6438 * @buf: if successful contains the data from the adapter IOREG space.
6439 * @off: offset into buffer to beginning of data.
6440 * @count: bytes to transfer.
6443 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6444 * Uses the adapter io control registers to read data into buf.
6447 * -ERANGE off and count combo out of range
6448 * -EINVAL off, count or buff address invalid
6449 * value of count, buf contents read
6452 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6453 struct bin_attribute *bin_attr,
6454 char *buf, loff_t off, size_t count)
6458 struct device *dev = container_of(kobj, struct device, kobj);
6459 struct Scsi_Host *shost = class_to_shost(dev);
6460 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6461 struct lpfc_hba *phba = vport->phba;
6463 if (phba->sli_rev >= LPFC_SLI_REV4)
6466 if (off > FF_REG_AREA_SIZE)
6469 if ((off + count) > FF_REG_AREA_SIZE)
6470 count = FF_REG_AREA_SIZE - off;
6472 if (count == 0) return 0;
6474 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6477 spin_lock_irq(&phba->hbalock);
6479 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6480 tmp_ptr = (uint32_t *)(buf + buf_off);
6481 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6484 spin_unlock_irq(&phba->hbalock);
6489 static struct bin_attribute sysfs_ctlreg_attr = {
6492 .mode = S_IRUSR | S_IWUSR,
6495 .read = sysfs_ctlreg_read,
6496 .write = sysfs_ctlreg_write,
6500 * sysfs_mbox_write - Write method for writing information via mbox
6501 * @filp: open sysfs file
6502 * @kobj: kernel kobject that contains the kernel class device.
6503 * @bin_attr: kernel attributes passed to us.
6504 * @buf: contains the data to be written to sysfs mbox.
6505 * @off: offset into buffer to beginning of data.
6506 * @count: bytes to transfer.
6509 * Deprecated function. All mailbox access from user space is performed via the
6513 * -EPERM operation not permitted
6516 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6517 struct bin_attribute *bin_attr,
6518 char *buf, loff_t off, size_t count)
6524 * sysfs_mbox_read - Read method for reading information via mbox
6525 * @filp: open sysfs file
6526 * @kobj: kernel kobject that contains the kernel class device.
6527 * @bin_attr: kernel attributes passed to us.
6528 * @buf: contains the data to be read from sysfs mbox.
6529 * @off: offset into buffer to beginning of data.
6530 * @count: bytes to transfer.
6533 * Deprecated function. All mailbox access from user space is performed via the
6537 * -EPERM operation not permitted
6540 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6541 struct bin_attribute *bin_attr,
6542 char *buf, loff_t off, size_t count)
6547 static struct bin_attribute sysfs_mbox_attr = {
6550 .mode = S_IRUSR | S_IWUSR,
6552 .size = MAILBOX_SYSFS_MAX,
6553 .read = sysfs_mbox_read,
6554 .write = sysfs_mbox_write,
6558 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6559 * @vport: address of lpfc vport structure.
6563 * error return code from sysfs_create_bin_file()
6566 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6568 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6571 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6572 &sysfs_drvr_stat_data_attr);
6574 /* Virtual ports do not need ctrl_reg and mbox */
6575 if (error || vport->port_type == LPFC_NPIV_PORT)
6578 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6579 &sysfs_ctlreg_attr);
6581 goto out_remove_stat_attr;
6583 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6586 goto out_remove_ctlreg_attr;
6589 out_remove_ctlreg_attr:
6590 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6591 out_remove_stat_attr:
6592 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6593 &sysfs_drvr_stat_data_attr);
6599 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6600 * @vport: address of lpfc vport structure.
6603 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6606 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6607 &sysfs_drvr_stat_data_attr);
6608 /* Virtual ports do not need ctrl_reg and mbox */
6609 if (vport->port_type == LPFC_NPIV_PORT)
6611 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6612 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6616 * Dynamic FC Host Attributes Support
6620 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6621 * @shost: kernel scsi host pointer.
6624 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6626 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6628 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6629 sizeof fc_host_symbolic_name(shost));
6633 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6634 * @shost: kernel scsi host pointer.
6637 lpfc_get_host_port_id(struct Scsi_Host *shost)
6639 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6641 /* note: fc_myDID already in cpu endianness */
6642 fc_host_port_id(shost) = vport->fc_myDID;
6646 * lpfc_get_host_port_type - Set the value of the scsi host port type
6647 * @shost: kernel scsi host pointer.
6650 lpfc_get_host_port_type(struct Scsi_Host *shost)
6652 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6653 struct lpfc_hba *phba = vport->phba;
6655 spin_lock_irq(shost->host_lock);
6657 if (vport->port_type == LPFC_NPIV_PORT) {
6658 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6659 } else if (lpfc_is_link_up(phba)) {
6660 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6661 if (vport->fc_flag & FC_PUBLIC_LOOP)
6662 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6664 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6666 if (vport->fc_flag & FC_FABRIC)
6667 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6669 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6672 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6674 spin_unlock_irq(shost->host_lock);
6678 * lpfc_get_host_port_state - Set the value of the scsi host port state
6679 * @shost: kernel scsi host pointer.
6682 lpfc_get_host_port_state(struct Scsi_Host *shost)
6684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6685 struct lpfc_hba *phba = vport->phba;
6687 spin_lock_irq(shost->host_lock);
6689 if (vport->fc_flag & FC_OFFLINE_MODE)
6690 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6692 switch (phba->link_state) {
6693 case LPFC_LINK_UNKNOWN:
6694 case LPFC_LINK_DOWN:
6695 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6699 case LPFC_HBA_READY:
6700 /* Links up, reports port state accordingly */
6701 if (vport->port_state < LPFC_VPORT_READY)
6702 fc_host_port_state(shost) =
6703 FC_PORTSTATE_BYPASSED;
6705 fc_host_port_state(shost) =
6706 FC_PORTSTATE_ONLINE;
6708 case LPFC_HBA_ERROR:
6709 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6712 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6717 spin_unlock_irq(shost->host_lock);
6721 * lpfc_get_host_speed - Set the value of the scsi host speed
6722 * @shost: kernel scsi host pointer.
6725 lpfc_get_host_speed(struct Scsi_Host *shost)
6727 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6728 struct lpfc_hba *phba = vport->phba;
6730 spin_lock_irq(shost->host_lock);
6732 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
6733 switch(phba->fc_linkspeed) {
6734 case LPFC_LINK_SPEED_1GHZ:
6735 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6737 case LPFC_LINK_SPEED_2GHZ:
6738 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6740 case LPFC_LINK_SPEED_4GHZ:
6741 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6743 case LPFC_LINK_SPEED_8GHZ:
6744 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6746 case LPFC_LINK_SPEED_10GHZ:
6747 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6749 case LPFC_LINK_SPEED_16GHZ:
6750 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6752 case LPFC_LINK_SPEED_32GHZ:
6753 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6755 case LPFC_LINK_SPEED_64GHZ:
6756 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6758 case LPFC_LINK_SPEED_128GHZ:
6759 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6761 case LPFC_LINK_SPEED_256GHZ:
6762 fc_host_speed(shost) = FC_PORTSPEED_256GBIT;
6765 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6768 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6769 switch (phba->fc_linkspeed) {
6770 case LPFC_ASYNC_LINK_SPEED_1GBPS:
6771 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6773 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6774 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6776 case LPFC_ASYNC_LINK_SPEED_20GBPS:
6777 fc_host_speed(shost) = FC_PORTSPEED_20GBIT;
6779 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6780 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6782 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6783 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6785 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6786 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6789 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6793 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6795 spin_unlock_irq(shost->host_lock);
6799 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6800 * @shost: kernel scsi host pointer.
6803 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6805 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6806 struct lpfc_hba *phba = vport->phba;
6809 spin_lock_irq(shost->host_lock);
6811 if ((vport->port_state > LPFC_FLOGI) &&
6812 ((vport->fc_flag & FC_FABRIC) ||
6813 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6814 (vport->fc_flag & FC_PUBLIC_LOOP))))
6815 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6817 /* fabric is local port if there is no F/FL_Port */
6820 spin_unlock_irq(shost->host_lock);
6822 fc_host_fabric_name(shost) = node_name;
6826 * lpfc_get_stats - Return statistical information about the adapter
6827 * @shost: kernel scsi host pointer.
6830 * NULL on error for link down, no mbox pool, sli2 active,
6831 * management not allowed, memory allocation error, or mbox error.
6835 * address of the adapter host statistics
6837 static struct fc_host_statistics *
6838 lpfc_get_stats(struct Scsi_Host *shost)
6840 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6841 struct lpfc_hba *phba = vport->phba;
6842 struct lpfc_sli *psli = &phba->sli;
6843 struct fc_host_statistics *hs = &phba->link_stats;
6844 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6845 LPFC_MBOXQ_t *pmboxq;
6850 * prevent udev from issuing mailbox commands until the port is
6853 if (phba->link_state < LPFC_LINK_DOWN ||
6854 !phba->mbox_mem_pool ||
6855 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6858 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6861 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6864 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6866 pmb = &pmboxq->u.mb;
6867 pmb->mbxCommand = MBX_READ_STATUS;
6868 pmb->mbxOwner = OWN_HOST;
6869 pmboxq->ctx_buf = NULL;
6870 pmboxq->vport = vport;
6872 if (vport->fc_flag & FC_OFFLINE_MODE) {
6873 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6874 if (rc != MBX_SUCCESS) {
6875 mempool_free(pmboxq, phba->mbox_mem_pool);
6879 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6880 if (rc != MBX_SUCCESS) {
6881 if (rc != MBX_TIMEOUT)
6882 mempool_free(pmboxq, phba->mbox_mem_pool);
6887 memset(hs, 0, sizeof (struct fc_host_statistics));
6889 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6891 * The MBX_READ_STATUS returns tx_k_bytes which has to
6892 * converted to words
6894 hs->tx_words = (uint64_t)
6895 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6897 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6898 hs->rx_words = (uint64_t)
6899 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6902 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6903 pmb->mbxCommand = MBX_READ_LNK_STAT;
6904 pmb->mbxOwner = OWN_HOST;
6905 pmboxq->ctx_buf = NULL;
6906 pmboxq->vport = vport;
6908 if (vport->fc_flag & FC_OFFLINE_MODE) {
6909 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6910 if (rc != MBX_SUCCESS) {
6911 mempool_free(pmboxq, phba->mbox_mem_pool);
6915 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6916 if (rc != MBX_SUCCESS) {
6917 if (rc != MBX_TIMEOUT)
6918 mempool_free(pmboxq, phba->mbox_mem_pool);
6923 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6924 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6925 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6926 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6927 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6928 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6929 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6931 hs->cn_sig_warn = atomic64_read(&phba->cgn_acqe_stat.warn);
6932 hs->cn_sig_alarm = atomic64_read(&phba->cgn_acqe_stat.alarm);
6934 hs->link_failure_count -= lso->link_failure_count;
6935 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6936 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6937 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6938 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6939 hs->invalid_crc_count -= lso->invalid_crc_count;
6940 hs->error_frames -= lso->error_frames;
6942 if (phba->hba_flag & HBA_FCOE_MODE) {
6944 hs->nos_count = (phba->link_events >> 1);
6945 hs->nos_count -= lso->link_events;
6946 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6947 hs->lip_count = (phba->fc_eventTag >> 1);
6948 hs->lip_count -= lso->link_events;
6952 hs->nos_count = (phba->fc_eventTag >> 1);
6953 hs->nos_count -= lso->link_events;
6956 hs->dumped_frames = -1;
6958 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6960 mempool_free(pmboxq, phba->mbox_mem_pool);
6966 * lpfc_reset_stats - Copy the adapter link stats information
6967 * @shost: kernel scsi host pointer.
6970 lpfc_reset_stats(struct Scsi_Host *shost)
6972 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6973 struct lpfc_hba *phba = vport->phba;
6974 struct lpfc_sli *psli = &phba->sli;
6975 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6976 LPFC_MBOXQ_t *pmboxq;
6980 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6983 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6986 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6988 pmb = &pmboxq->u.mb;
6989 pmb->mbxCommand = MBX_READ_STATUS;
6990 pmb->mbxOwner = OWN_HOST;
6991 pmb->un.varWords[0] = 0x1; /* reset request */
6992 pmboxq->ctx_buf = NULL;
6993 pmboxq->vport = vport;
6995 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6996 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6997 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6998 if (rc != MBX_SUCCESS) {
6999 mempool_free(pmboxq, phba->mbox_mem_pool);
7003 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
7004 if (rc != MBX_SUCCESS) {
7005 if (rc != MBX_TIMEOUT)
7006 mempool_free(pmboxq, phba->mbox_mem_pool);
7011 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
7012 pmb->mbxCommand = MBX_READ_LNK_STAT;
7013 pmb->mbxOwner = OWN_HOST;
7014 pmboxq->ctx_buf = NULL;
7015 pmboxq->vport = vport;
7017 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
7018 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
7019 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
7020 if (rc != MBX_SUCCESS) {
7021 mempool_free(pmboxq, phba->mbox_mem_pool);
7025 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
7026 if (rc != MBX_SUCCESS) {
7027 if (rc != MBX_TIMEOUT)
7028 mempool_free(pmboxq, phba->mbox_mem_pool);
7033 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
7034 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
7035 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
7036 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
7037 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
7038 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
7039 lso->error_frames = pmb->un.varRdLnk.crcCnt;
7040 if (phba->hba_flag & HBA_FCOE_MODE)
7041 lso->link_events = (phba->link_events >> 1);
7043 lso->link_events = (phba->fc_eventTag >> 1);
7045 atomic64_set(&phba->cgn_acqe_stat.warn, 0);
7046 atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
7048 memset(&shost_to_fc_host(shost)->fpin_stats, 0,
7049 sizeof(shost_to_fc_host(shost)->fpin_stats));
7051 psli->stats_start = ktime_get_seconds();
7053 mempool_free(pmboxq, phba->mbox_mem_pool);
7059 * The LPFC driver treats linkdown handling as target loss events so there
7060 * are no sysfs handlers for link_down_tmo.
7064 * lpfc_get_node_by_target - Return the nodelist for a target
7065 * @starget: kernel scsi target pointer.
7068 * address of the node list if found
7069 * NULL target not found
7071 static struct lpfc_nodelist *
7072 lpfc_get_node_by_target(struct scsi_target *starget)
7074 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
7075 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
7076 struct lpfc_nodelist *ndlp;
7078 spin_lock_irq(shost->host_lock);
7079 /* Search for this, mapped, target ID */
7080 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
7081 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
7082 starget->id == ndlp->nlp_sid) {
7083 spin_unlock_irq(shost->host_lock);
7087 spin_unlock_irq(shost->host_lock);
7092 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
7093 * @starget: kernel scsi target pointer.
7096 lpfc_get_starget_port_id(struct scsi_target *starget)
7098 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
7100 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
7104 * lpfc_get_starget_node_name - Set the target node name
7105 * @starget: kernel scsi target pointer.
7107 * Description: Set the target node name to the ndlp node name wwn or zero.
7110 lpfc_get_starget_node_name(struct scsi_target *starget)
7112 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
7114 fc_starget_node_name(starget) =
7115 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
7119 * lpfc_get_starget_port_name - Set the target port name
7120 * @starget: kernel scsi target pointer.
7122 * Description: set the target port name to the ndlp port name wwn or zero.
7125 lpfc_get_starget_port_name(struct scsi_target *starget)
7127 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
7129 fc_starget_port_name(starget) =
7130 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
7134 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
7135 * @rport: fc rport address.
7136 * @timeout: new value for dev loss tmo.
7139 * If timeout is non zero set the dev_loss_tmo to timeout, else set
7140 * dev_loss_tmo to one.
7143 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
7145 struct lpfc_rport_data *rdata = rport->dd_data;
7146 struct lpfc_nodelist *ndlp = rdata->pnode;
7147 #if (IS_ENABLED(CONFIG_NVME_FC))
7148 struct lpfc_nvme_rport *nrport = NULL;
7152 rport->dev_loss_tmo = timeout;
7154 rport->dev_loss_tmo = 1;
7157 dev_info(&rport->dev, "Cannot find remote node to "
7158 "set rport dev loss tmo, port_id x%x\n",
7163 #if (IS_ENABLED(CONFIG_NVME_FC))
7164 nrport = lpfc_ndlp_get_nrport(ndlp);
7166 if (nrport && nrport->remoteport)
7167 nvme_fc_set_remoteport_devloss(nrport->remoteport,
7168 rport->dev_loss_tmo);
7173 * lpfc_rport_show_function - Return rport target information
7176 * Macro that uses field to generate a function with the name lpfc_show_rport_
7178 * lpfc_show_rport_##field: returns the bytes formatted in buf
7179 * @cdev: class converted to an fc_rport.
7180 * @buf: on return contains the target_field or zero.
7182 * Returns: size of formatted string.
7184 #define lpfc_rport_show_function(field, format_string, sz, cast) \
7186 lpfc_show_rport_##field (struct device *dev, \
7187 struct device_attribute *attr, \
7190 struct fc_rport *rport = transport_class_to_rport(dev); \
7191 struct lpfc_rport_data *rdata = rport->hostdata; \
7192 return scnprintf(buf, sz, format_string, \
7193 (rdata->target) ? cast rdata->target->field : 0); \
7196 #define lpfc_rport_rd_attr(field, format_string, sz) \
7197 lpfc_rport_show_function(field, format_string, sz, ) \
7198 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
7201 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
7202 * @fc_vport: The fc_vport who's symbolic name has been changed.
7205 * This function is called by the transport after the @fc_vport's symbolic name
7206 * has been changed. This function re-registers the symbolic name with the
7207 * switch to propagate the change into the fabric if the vport is active.
7210 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
7212 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
7214 if (vport->port_state == LPFC_VPORT_READY)
7215 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
7219 * lpfc_hba_log_verbose_init - Set hba's log verbose level
7220 * @phba: Pointer to lpfc_hba struct.
7221 * @verbose: Verbose level to set.
7223 * This function is called by the lpfc_get_cfgparam() routine to set the
7224 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
7225 * log message according to the module's lpfc_log_verbose parameter setting
7226 * before hba port or vport created.
7229 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
7231 phba->cfg_log_verbose = verbose;
7234 struct fc_function_template lpfc_transport_functions = {
7235 /* fixed attributes the driver supports */
7236 .show_host_node_name = 1,
7237 .show_host_port_name = 1,
7238 .show_host_supported_classes = 1,
7239 .show_host_supported_fc4s = 1,
7240 .show_host_supported_speeds = 1,
7241 .show_host_maxframe_size = 1,
7243 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7244 .show_host_symbolic_name = 1,
7246 /* dynamic attributes the driver supports */
7247 .get_host_port_id = lpfc_get_host_port_id,
7248 .show_host_port_id = 1,
7250 .get_host_port_type = lpfc_get_host_port_type,
7251 .show_host_port_type = 1,
7253 .get_host_port_state = lpfc_get_host_port_state,
7254 .show_host_port_state = 1,
7256 /* active_fc4s is shown but doesn't change (thus no get function) */
7257 .show_host_active_fc4s = 1,
7259 .get_host_speed = lpfc_get_host_speed,
7260 .show_host_speed = 1,
7262 .get_host_fabric_name = lpfc_get_host_fabric_name,
7263 .show_host_fabric_name = 1,
7266 * The LPFC driver treats linkdown handling as target loss events
7267 * so there are no sysfs handlers for link_down_tmo.
7270 .get_fc_host_stats = lpfc_get_stats,
7271 .reset_fc_host_stats = lpfc_reset_stats,
7273 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7274 .show_rport_maxframe_size = 1,
7275 .show_rport_supported_classes = 1,
7277 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7278 .show_rport_dev_loss_tmo = 1,
7280 .get_starget_port_id = lpfc_get_starget_port_id,
7281 .show_starget_port_id = 1,
7283 .get_starget_node_name = lpfc_get_starget_node_name,
7284 .show_starget_node_name = 1,
7286 .get_starget_port_name = lpfc_get_starget_port_name,
7287 .show_starget_port_name = 1,
7289 .issue_fc_host_lip = lpfc_issue_lip,
7290 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7291 .terminate_rport_io = lpfc_terminate_rport_io,
7293 .dd_fcvport_size = sizeof(struct lpfc_vport *),
7295 .vport_disable = lpfc_vport_disable,
7297 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7299 .bsg_request = lpfc_bsg_request,
7300 .bsg_timeout = lpfc_bsg_timeout,
7303 struct fc_function_template lpfc_vport_transport_functions = {
7304 /* fixed attributes the driver supports */
7305 .show_host_node_name = 1,
7306 .show_host_port_name = 1,
7307 .show_host_supported_classes = 1,
7308 .show_host_supported_fc4s = 1,
7309 .show_host_supported_speeds = 1,
7310 .show_host_maxframe_size = 1,
7312 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7313 .show_host_symbolic_name = 1,
7315 /* dynamic attributes the driver supports */
7316 .get_host_port_id = lpfc_get_host_port_id,
7317 .show_host_port_id = 1,
7319 .get_host_port_type = lpfc_get_host_port_type,
7320 .show_host_port_type = 1,
7322 .get_host_port_state = lpfc_get_host_port_state,
7323 .show_host_port_state = 1,
7325 /* active_fc4s is shown but doesn't change (thus no get function) */
7326 .show_host_active_fc4s = 1,
7328 .get_host_speed = lpfc_get_host_speed,
7329 .show_host_speed = 1,
7331 .get_host_fabric_name = lpfc_get_host_fabric_name,
7332 .show_host_fabric_name = 1,
7335 * The LPFC driver treats linkdown handling as target loss events
7336 * so there are no sysfs handlers for link_down_tmo.
7339 .get_fc_host_stats = lpfc_get_stats,
7340 .reset_fc_host_stats = lpfc_reset_stats,
7342 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7343 .show_rport_maxframe_size = 1,
7344 .show_rport_supported_classes = 1,
7346 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7347 .show_rport_dev_loss_tmo = 1,
7349 .get_starget_port_id = lpfc_get_starget_port_id,
7350 .show_starget_port_id = 1,
7352 .get_starget_node_name = lpfc_get_starget_node_name,
7353 .show_starget_node_name = 1,
7355 .get_starget_port_name = lpfc_get_starget_port_name,
7356 .show_starget_port_name = 1,
7358 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7359 .terminate_rport_io = lpfc_terminate_rport_io,
7361 .vport_disable = lpfc_vport_disable,
7363 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7367 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7369 * @phba: lpfc_hba pointer.
7372 lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7374 /* If the adapter supports FCoE mode */
7375 switch (phba->pcidev->device) {
7376 case PCI_DEVICE_ID_SKYHAWK:
7377 case PCI_DEVICE_ID_SKYHAWK_VF:
7378 case PCI_DEVICE_ID_LANCER_FCOE:
7379 case PCI_DEVICE_ID_LANCER_FCOE_VF:
7380 case PCI_DEVICE_ID_ZEPHYR_DCSP:
7381 case PCI_DEVICE_ID_HORNET:
7382 case PCI_DEVICE_ID_TIGERSHARK:
7383 case PCI_DEVICE_ID_TOMCAT:
7384 phba->hba_flag |= HBA_FCOE_MODE;
7387 /* for others, clear the flag */
7388 phba->hba_flag &= ~HBA_FCOE_MODE;
7393 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7394 * @phba: lpfc_hba pointer.
7397 lpfc_get_cfgparam(struct lpfc_hba *phba)
7399 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7400 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
7401 lpfc_ns_query_init(phba, lpfc_ns_query);
7402 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7403 lpfc_cr_delay_init(phba, lpfc_cr_delay);
7404 lpfc_cr_count_init(phba, lpfc_cr_count);
7405 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
7406 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7407 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7408 lpfc_ack0_init(phba, lpfc_ack0);
7409 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
7410 lpfc_topology_init(phba, lpfc_topology);
7411 lpfc_link_speed_init(phba, lpfc_link_speed);
7412 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
7413 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
7414 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7415 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
7416 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
7417 lpfc_fcp_wait_abts_rsp_init(phba, lpfc_fcp_wait_abts_rsp);
7418 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7419 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
7420 lpfc_use_msi_init(phba, lpfc_use_msi);
7421 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
7422 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
7423 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7424 lpfc_force_rscn_init(phba, lpfc_force_rscn);
7425 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7426 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
7427 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
7428 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7429 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
7431 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7433 lpfc_max_vmid_init(phba, lpfc_max_vmid);
7434 lpfc_vmid_inactivity_timeout_init(phba, lpfc_vmid_inactivity_timeout);
7435 lpfc_vmid_app_header_init(phba, lpfc_vmid_app_header);
7436 lpfc_vmid_priority_tagging_init(phba, lpfc_vmid_priority_tagging);
7437 if (phba->sli_rev != LPFC_SLI_REV4)
7438 phba->cfg_EnableXLane = 0;
7439 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
7441 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7442 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7443 phba->cfg_oas_lun_state = 0;
7444 phba->cfg_oas_lun_status = 0;
7445 phba->cfg_oas_flags = 0;
7446 phba->cfg_oas_priority = 0;
7447 lpfc_enable_bg_init(phba, lpfc_enable_bg);
7448 lpfc_prot_mask_init(phba, lpfc_prot_mask);
7449 lpfc_prot_guard_init(phba, lpfc_prot_guard);
7450 if (phba->sli_rev == LPFC_SLI_REV4)
7453 phba->cfg_poll = lpfc_poll;
7455 /* Get the function mode */
7456 lpfc_get_hba_function_mode(phba);
7458 /* BlockGuard allowed for FC only. */
7459 if (phba->cfg_enable_bg && phba->hba_flag & HBA_FCOE_MODE) {
7460 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7461 "0581 BlockGuard feature not supported\n");
7462 /* If set, clear the BlockGuard support param */
7463 phba->cfg_enable_bg = 0;
7464 } else if (phba->cfg_enable_bg) {
7465 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
7468 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
7470 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
7471 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
7472 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
7474 /* Initialize first burst. Target vs Initiator are different. */
7475 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
7476 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
7477 lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
7478 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
7479 lpfc_irq_chann_init(phba, lpfc_irq_chann);
7480 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7481 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7482 lpfc_enable_mi_init(phba, lpfc_enable_mi);
7484 phba->cmf_active_mode = LPFC_CFG_OFF;
7485 if (lpfc_fabric_cgn_frequency > EDC_CG_SIGFREQ_CNT_MAX ||
7486 lpfc_fabric_cgn_frequency < EDC_CG_SIGFREQ_CNT_MIN)
7487 lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
7489 if (phba->sli_rev != LPFC_SLI_REV4) {
7490 /* NVME only supported on SLI4 */
7491 phba->nvmet_support = 0;
7492 phba->cfg_nvmet_mrq = 0;
7493 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7494 phba->cfg_enable_bbcr = 0;
7495 phba->cfg_xri_rebalancing = 0;
7497 /* We MUST have FCP support */
7498 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7499 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7502 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7504 phba->cfg_enable_pbde = 0;
7506 /* A value of 0 means use the number of CPUs found in the system */
7507 if (phba->cfg_hdw_queue == 0)
7508 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7509 if (phba->cfg_irq_chann == 0)
7510 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7511 if (phba->cfg_irq_chann > phba->cfg_hdw_queue &&
7512 phba->sli_rev == LPFC_SLI_REV4)
7513 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7515 phba->cfg_soft_wwnn = 0L;
7516 phba->cfg_soft_wwpn = 0L;
7517 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7518 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7519 lpfc_aer_support_init(phba, lpfc_aer_support);
7520 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7521 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7522 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7523 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7524 lpfc_sli_mode_init(phba, lpfc_sli_mode);
7525 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7526 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7527 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7528 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7534 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7535 * dependencies between protocols and roles.
7536 * @phba: lpfc_hba pointer.
7539 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7543 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu) {
7544 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7547 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu) {
7548 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7551 if (phba->cfg_irq_chann > phba->cfg_hdw_queue) {
7552 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7556 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7557 "2006 Reducing Queues - CPU limitation: "
7559 phba->cfg_irq_chann,
7560 phba->cfg_hdw_queue);
7562 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7563 phba->nvmet_support) {
7564 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7566 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7567 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7568 "NVME Target PRLI ACC enable_fb ",
7569 phba->cfg_nvme_enable_fb,
7570 phba->cfg_nvmet_fb_size,
7571 LPFC_NVMET_FB_SZ_MAX);
7573 if (phba->cfg_nvme_enable_fb == 0)
7574 phba->cfg_nvmet_fb_size = 0;
7576 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7577 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7580 if (!phba->cfg_nvmet_mrq)
7581 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7583 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7584 if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
7585 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7586 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7587 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7588 phba->cfg_nvmet_mrq);
7590 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7591 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7594 /* Not NVME Target mode. Turn off Target parameters. */
7595 phba->nvmet_support = 0;
7596 phba->cfg_nvmet_mrq = 0;
7597 phba->cfg_nvmet_fb_size = 0;
7602 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7603 * @vport: lpfc_vport pointer.
7606 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7608 lpfc_log_verbose_init(vport, lpfc_log_verbose);
7609 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7610 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7611 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7612 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7613 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7614 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7615 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7616 lpfc_use_adisc_init(vport, lpfc_use_adisc);
7617 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7618 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7619 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7620 lpfc_max_luns_init(vport, lpfc_max_luns);
7621 lpfc_scan_down_init(vport, lpfc_scan_down);
7622 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);