1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 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>
40 #include <linux/nvme-fc-driver.h>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_nvmet.h"
52 #include "lpfc_logmsg.h"
53 #include "lpfc_version.h"
54 #include "lpfc_compat.h"
55 #include "lpfc_crtn.h"
56 #include "lpfc_vport.h"
57 #include "lpfc_attr.h"
59 #define LPFC_DEF_DEVLOSS_TMO 30
60 #define LPFC_MIN_DEVLOSS_TMO 1
61 #define LPFC_MAX_DEVLOSS_TMO 255
63 #define LPFC_DEF_MRQ_POST 512
64 #define LPFC_MIN_MRQ_POST 512
65 #define LPFC_MAX_MRQ_POST 2048
67 #define LPFC_MAX_NVME_INFO_TMP_LEN 100
68 #define LPFC_NVME_INFO_MORE_STR "\nCould be more info...\n"
71 * Write key size should be multiple of 4. If write key is changed
72 * make sure that library write key is also changed.
74 #define LPFC_REG_WRITE_KEY_SIZE 4
75 #define LPFC_REG_WRITE_KEY "EMLX"
78 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
79 * @incr: integer to convert.
80 * @hdw: ascii string holding converted integer plus a string terminator.
83 * JEDEC Joint Electron Device Engineering Council.
84 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
85 * character string. The string is then terminated with a NULL in byte 9.
86 * Hex 0-9 becomes ascii '0' to '9'.
87 * Hex a-f becomes ascii '=' to 'B' capital B.
90 * Coded for 32 bit integers only.
93 lpfc_jedec_to_ascii(int incr, char hdw[])
96 for (i = 0; i < 8; i++) {
99 hdw[7 - i] = 0x30 + j;
101 hdw[7 - i] = 0x61 + j - 10;
109 * lpfc_drvr_version_show - Return the Emulex driver string with version number
110 * @dev: class unused variable.
111 * @attr: device attribute, not used.
112 * @buf: on return contains the module description text.
114 * Returns: size of formatted string.
117 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
120 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
124 * lpfc_enable_fip_show - Return the fip mode of the HBA
125 * @dev: class unused variable.
126 * @attr: device attribute, not used.
127 * @buf: on return contains the module description text.
129 * Returns: size of formatted string.
132 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
135 struct Scsi_Host *shost = class_to_shost(dev);
136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 struct lpfc_hba *phba = vport->phba;
139 if (phba->hba_flag & HBA_FIP_SUPPORT)
140 return snprintf(buf, PAGE_SIZE, "1\n");
142 return snprintf(buf, PAGE_SIZE, "0\n");
146 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
149 struct Scsi_Host *shost = class_to_shost(dev);
150 struct lpfc_vport *vport = shost_priv(shost);
151 struct lpfc_hba *phba = vport->phba;
152 struct lpfc_nvmet_tgtport *tgtp;
153 struct nvme_fc_local_port *localport;
154 struct lpfc_nvme_lport *lport;
155 struct lpfc_nvme_rport *rport;
156 struct lpfc_nodelist *ndlp;
157 struct nvme_fc_remote_port *nrport;
158 struct lpfc_nvme_ctrl_stat *cstat;
159 uint64_t data1, data2, data3;
160 uint64_t totin, totout, tot;
164 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
166 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
167 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
170 if (phba->nvmet_support) {
171 if (!phba->targetport) {
172 len = scnprintf(buf, PAGE_SIZE,
173 "NVME Target: x%llx is not allocated\n",
174 wwn_to_u64(vport->fc_portname.u.wwn));
177 /* Port state is only one of two values for now. */
178 if (phba->targetport->port_id)
179 statep = "REGISTERED";
182 scnprintf(tmp, sizeof(tmp),
183 "NVME Target Enabled State %s\n",
185 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
188 scnprintf(tmp, sizeof(tmp),
189 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
192 wwn_to_u64(vport->fc_portname.u.wwn),
193 wwn_to_u64(vport->fc_nodename.u.wwn),
194 phba->targetport->port_id);
195 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
198 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
202 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
203 scnprintf(tmp, sizeof(tmp),
204 "LS: Rcv %08x Drop %08x Abort %08x\n",
205 atomic_read(&tgtp->rcv_ls_req_in),
206 atomic_read(&tgtp->rcv_ls_req_drop),
207 atomic_read(&tgtp->xmt_ls_abort));
208 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
211 if (atomic_read(&tgtp->rcv_ls_req_in) !=
212 atomic_read(&tgtp->rcv_ls_req_out)) {
213 scnprintf(tmp, sizeof(tmp),
214 "Rcv LS: in %08x != out %08x\n",
215 atomic_read(&tgtp->rcv_ls_req_in),
216 atomic_read(&tgtp->rcv_ls_req_out));
217 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
221 scnprintf(tmp, sizeof(tmp),
222 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
223 atomic_read(&tgtp->xmt_ls_rsp),
224 atomic_read(&tgtp->xmt_ls_drop),
225 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
226 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
229 scnprintf(tmp, sizeof(tmp),
230 "LS: RSP Abort %08x xb %08x Err %08x\n",
231 atomic_read(&tgtp->xmt_ls_rsp_aborted),
232 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
233 atomic_read(&tgtp->xmt_ls_rsp_error));
234 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
237 scnprintf(tmp, sizeof(tmp),
238 "FCP: Rcv %08x Defer %08x Release %08x "
240 atomic_read(&tgtp->rcv_fcp_cmd_in),
241 atomic_read(&tgtp->rcv_fcp_cmd_defer),
242 atomic_read(&tgtp->xmt_fcp_release),
243 atomic_read(&tgtp->rcv_fcp_cmd_drop));
244 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
247 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
248 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
249 scnprintf(tmp, sizeof(tmp),
250 "Rcv FCP: in %08x != out %08x\n",
251 atomic_read(&tgtp->rcv_fcp_cmd_in),
252 atomic_read(&tgtp->rcv_fcp_cmd_out));
253 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
257 scnprintf(tmp, sizeof(tmp),
258 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
260 atomic_read(&tgtp->xmt_fcp_read),
261 atomic_read(&tgtp->xmt_fcp_read_rsp),
262 atomic_read(&tgtp->xmt_fcp_write),
263 atomic_read(&tgtp->xmt_fcp_rsp),
264 atomic_read(&tgtp->xmt_fcp_drop));
265 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
268 scnprintf(tmp, sizeof(tmp),
269 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
270 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
271 atomic_read(&tgtp->xmt_fcp_rsp_error),
272 atomic_read(&tgtp->xmt_fcp_rsp_drop));
273 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
276 scnprintf(tmp, sizeof(tmp),
277 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
278 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
279 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
280 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
281 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
284 scnprintf(tmp, sizeof(tmp),
285 "ABORT: Xmt %08x Cmpl %08x\n",
286 atomic_read(&tgtp->xmt_fcp_abort),
287 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
288 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
291 scnprintf(tmp, sizeof(tmp),
292 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
293 atomic_read(&tgtp->xmt_abort_sol),
294 atomic_read(&tgtp->xmt_abort_unsol),
295 atomic_read(&tgtp->xmt_abort_rsp),
296 atomic_read(&tgtp->xmt_abort_rsp_error));
297 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
300 scnprintf(tmp, sizeof(tmp),
301 "DELAY: ctx %08x fod %08x wqfull %08x\n",
302 atomic_read(&tgtp->defer_ctx),
303 atomic_read(&tgtp->defer_fod),
304 atomic_read(&tgtp->defer_wqfull));
305 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
308 /* Calculate outstanding IOs */
309 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
310 tot += atomic_read(&tgtp->xmt_fcp_release);
311 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
313 scnprintf(tmp, sizeof(tmp),
314 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
315 "CTX Outstanding %08llx\n\n",
316 phba->sli4_hba.nvmet_xri_cnt,
317 phba->sli4_hba.nvmet_io_wait_cnt,
318 phba->sli4_hba.nvmet_io_wait_total,
320 strlcat(buf, tmp, PAGE_SIZE);
324 localport = vport->localport;
326 len = scnprintf(buf, PAGE_SIZE,
327 "NVME Initiator x%llx is not allocated\n",
328 wwn_to_u64(vport->fc_portname.u.wwn));
331 lport = (struct lpfc_nvme_lport *)localport->private;
332 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
336 scnprintf(tmp, sizeof(tmp),
337 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
339 phba->sli4_hba.max_cfg_param.max_xri,
340 phba->sli4_hba.io_xri_max,
341 lpfc_sli4_get_els_iocb_cnt(phba));
342 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
345 /* Port state is only one of two values for now. */
346 if (localport->port_id)
351 scnprintf(tmp, sizeof(tmp),
352 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
355 wwn_to_u64(vport->fc_portname.u.wwn),
356 wwn_to_u64(vport->fc_nodename.u.wwn),
357 localport->port_id, statep);
358 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
361 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
363 spin_lock(&vport->phba->hbalock);
364 rport = lpfc_ndlp_get_nrport(ndlp);
366 nrport = rport->remoteport;
367 spin_unlock(&vport->phba->hbalock);
371 /* Port state is only one of two values for now. */
372 switch (nrport->port_state) {
373 case FC_OBJSTATE_ONLINE:
376 case FC_OBJSTATE_UNKNOWN:
380 statep = "UNSUPPORTED";
384 /* Tab in to show lport ownership. */
385 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
387 if (phba->brd_no >= 10) {
388 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
392 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
394 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
397 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
399 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
402 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
404 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
407 /* An NVME rport can have multiple roles. */
408 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
409 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
412 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
413 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
416 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
417 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
420 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
421 FC_PORT_ROLE_NVME_TARGET |
422 FC_PORT_ROLE_NVME_DISCOVERY)) {
423 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
425 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
429 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
430 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
438 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
441 scnprintf(tmp, sizeof(tmp),
442 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
443 atomic_read(&lport->fc4NvmeLsRequests),
444 atomic_read(&lport->fc4NvmeLsCmpls),
445 atomic_read(&lport->xmt_ls_abort));
446 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
449 scnprintf(tmp, sizeof(tmp),
450 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
451 atomic_read(&lport->xmt_ls_err),
452 atomic_read(&lport->cmpl_ls_xb),
453 atomic_read(&lport->cmpl_ls_err));
454 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
459 for (i = 0; i < phba->cfg_hdw_queue; i++) {
460 cstat = &lport->cstat[i];
461 tot = atomic_read(&cstat->fc4NvmeIoCmpls);
463 data1 = atomic_read(&cstat->fc4NvmeInputRequests);
464 data2 = atomic_read(&cstat->fc4NvmeOutputRequests);
465 data3 = atomic_read(&cstat->fc4NvmeControlRequests);
466 totout += (data1 + data2 + data3);
468 scnprintf(tmp, sizeof(tmp),
469 "Total FCP Cmpl %016llx Issue %016llx "
471 totin, totout, totout - totin);
472 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
475 scnprintf(tmp, sizeof(tmp),
476 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
477 "wqerr %08x err %08x\n",
478 atomic_read(&lport->xmt_fcp_abort),
479 atomic_read(&lport->xmt_fcp_noxri),
480 atomic_read(&lport->xmt_fcp_bad_ndlp),
481 atomic_read(&lport->xmt_fcp_qdepth),
482 atomic_read(&lport->xmt_fcp_err),
483 atomic_read(&lport->xmt_fcp_wqerr));
484 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
487 scnprintf(tmp, sizeof(tmp),
488 "FCP CMPL: xb %08x Err %08x\n",
489 atomic_read(&lport->cmpl_fcp_xb),
490 atomic_read(&lport->cmpl_fcp_err));
491 strlcat(buf, tmp, PAGE_SIZE);
494 len = strnlen(buf, PAGE_SIZE);
496 if (unlikely(len >= (PAGE_SIZE - 1))) {
497 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
498 "6314 Catching potential buffer "
499 "overflow > PAGE_SIZE = %lu bytes\n",
501 strlcpy(buf + PAGE_SIZE - 1 -
502 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1),
503 LPFC_NVME_INFO_MORE_STR,
504 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1)
512 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
515 struct Scsi_Host *shost = class_to_shost(dev);
516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
517 struct lpfc_hba *phba = vport->phba;
519 if (phba->cfg_enable_bg)
520 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
521 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
523 return snprintf(buf, PAGE_SIZE,
524 "BlockGuard Not Supported\n");
526 return snprintf(buf, PAGE_SIZE,
527 "BlockGuard Disabled\n");
531 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
534 struct Scsi_Host *shost = class_to_shost(dev);
535 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
536 struct lpfc_hba *phba = vport->phba;
538 return snprintf(buf, PAGE_SIZE, "%llu\n",
539 (unsigned long long)phba->bg_guard_err_cnt);
543 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
546 struct Scsi_Host *shost = class_to_shost(dev);
547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
548 struct lpfc_hba *phba = vport->phba;
550 return snprintf(buf, PAGE_SIZE, "%llu\n",
551 (unsigned long long)phba->bg_apptag_err_cnt);
555 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
558 struct Scsi_Host *shost = class_to_shost(dev);
559 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
560 struct lpfc_hba *phba = vport->phba;
562 return snprintf(buf, PAGE_SIZE, "%llu\n",
563 (unsigned long long)phba->bg_reftag_err_cnt);
567 * lpfc_info_show - Return some pci info about the host in ascii
568 * @dev: class converted to a Scsi_host structure.
569 * @attr: device attribute, not used.
570 * @buf: on return contains the formatted text from lpfc_info().
572 * Returns: size of formatted string.
575 lpfc_info_show(struct device *dev, struct device_attribute *attr,
578 struct Scsi_Host *host = class_to_shost(dev);
580 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
584 * lpfc_serialnum_show - Return the hba serial number in ascii
585 * @dev: class converted to a Scsi_host structure.
586 * @attr: device attribute, not used.
587 * @buf: on return contains the formatted text serial number.
589 * Returns: size of formatted string.
592 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
595 struct Scsi_Host *shost = class_to_shost(dev);
596 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
597 struct lpfc_hba *phba = vport->phba;
599 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
603 * lpfc_temp_sensor_show - Return the temperature sensor level
604 * @dev: class converted to a Scsi_host structure.
605 * @attr: device attribute, not used.
606 * @buf: on return contains the formatted support level.
609 * Returns a number indicating the temperature sensor level currently
610 * supported, zero or one in ascii.
612 * Returns: size of formatted string.
615 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
618 struct Scsi_Host *shost = class_to_shost(dev);
619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
620 struct lpfc_hba *phba = vport->phba;
621 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
625 * lpfc_modeldesc_show - Return the model description of the hba
626 * @dev: class converted to a Scsi_host structure.
627 * @attr: device attribute, not used.
628 * @buf: on return contains the scsi vpd model description.
630 * Returns: size of formatted string.
633 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
636 struct Scsi_Host *shost = class_to_shost(dev);
637 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
638 struct lpfc_hba *phba = vport->phba;
640 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
644 * lpfc_modelname_show - Return the model name of the hba
645 * @dev: class converted to a Scsi_host structure.
646 * @attr: device attribute, not used.
647 * @buf: on return contains the scsi vpd model name.
649 * Returns: size of formatted string.
652 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
655 struct Scsi_Host *shost = class_to_shost(dev);
656 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
657 struct lpfc_hba *phba = vport->phba;
659 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
663 * lpfc_programtype_show - Return the program type of the hba
664 * @dev: class converted to a Scsi_host structure.
665 * @attr: device attribute, not used.
666 * @buf: on return contains the scsi vpd program type.
668 * Returns: size of formatted string.
671 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
674 struct Scsi_Host *shost = class_to_shost(dev);
675 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
676 struct lpfc_hba *phba = vport->phba;
678 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
682 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
683 * @dev: class converted to a Scsi_host structure.
684 * @attr: device attribute, not used.
685 * @buf: on return contains the Menlo Maintenance sli flag.
687 * Returns: size of formatted string.
690 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
692 struct Scsi_Host *shost = class_to_shost(dev);
693 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
694 struct lpfc_hba *phba = vport->phba;
696 return snprintf(buf, PAGE_SIZE, "%d\n",
697 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
701 * lpfc_vportnum_show - Return the port number in ascii of the hba
702 * @dev: class converted to a Scsi_host structure.
703 * @attr: device attribute, not used.
704 * @buf: on return contains scsi vpd program type.
706 * Returns: size of formatted string.
709 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
712 struct Scsi_Host *shost = class_to_shost(dev);
713 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
714 struct lpfc_hba *phba = vport->phba;
716 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
720 * lpfc_fwrev_show - Return the firmware rev running in the hba
721 * @dev: class converted to a Scsi_host structure.
722 * @attr: device attribute, not used.
723 * @buf: on return contains the scsi vpd program type.
725 * Returns: size of formatted string.
728 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
731 struct Scsi_Host *shost = class_to_shost(dev);
732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
733 struct lpfc_hba *phba = vport->phba;
736 char fwrev[FW_REV_STR_SIZE];
739 lpfc_decode_firmware_rev(phba, fwrev, 1);
740 if_type = phba->sli4_hba.pc_sli4_params.if_type;
741 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
743 if (phba->sli_rev < LPFC_SLI_REV4)
744 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
745 fwrev, phba->sli_rev);
747 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
748 fwrev, phba->sli_rev, if_type, sli_family);
754 * lpfc_hdw_show - Return the jedec information about the hba
755 * @dev: class converted to a Scsi_host structure.
756 * @attr: device attribute, not used.
757 * @buf: on return contains the scsi vpd program type.
759 * Returns: size of formatted string.
762 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
765 struct Scsi_Host *shost = class_to_shost(dev);
766 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
767 struct lpfc_hba *phba = vport->phba;
768 lpfc_vpd_t *vp = &phba->vpd;
770 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
771 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
775 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
776 * @dev: class converted to a Scsi_host structure.
777 * @attr: device attribute, not used.
778 * @buf: on return contains the ROM and FCode ascii strings.
780 * Returns: size of formatted string.
783 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
786 struct Scsi_Host *shost = class_to_shost(dev);
787 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
788 struct lpfc_hba *phba = vport->phba;
789 char fwrev[FW_REV_STR_SIZE];
791 if (phba->sli_rev < LPFC_SLI_REV4)
792 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
794 lpfc_decode_firmware_rev(phba, fwrev, 1);
795 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
799 * lpfc_state_show - Return the link state of the port
800 * @dev: class converted to a Scsi_host structure.
801 * @attr: device attribute, not used.
802 * @buf: on return contains text describing the state of the link.
805 * The switch statement has no default so zero will be returned.
807 * Returns: size of formatted string.
810 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
813 struct Scsi_Host *shost = class_to_shost(dev);
814 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
815 struct lpfc_hba *phba = vport->phba;
818 switch (phba->link_state) {
819 case LPFC_LINK_UNKNOWN:
820 case LPFC_WARM_START:
821 case LPFC_INIT_START:
822 case LPFC_INIT_MBX_CMDS:
825 if (phba->hba_flag & LINK_DISABLED)
826 len += snprintf(buf + len, PAGE_SIZE-len,
827 "Link Down - User disabled\n");
829 len += snprintf(buf + len, PAGE_SIZE-len,
835 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
837 switch (vport->port_state) {
838 case LPFC_LOCAL_CFG_LINK:
839 len += snprintf(buf + len, PAGE_SIZE-len,
840 "Configuring Link\n");
844 case LPFC_FABRIC_CFG_LINK:
847 case LPFC_BUILD_DISC_LIST:
849 len += snprintf(buf + len, PAGE_SIZE - len,
852 case LPFC_VPORT_READY:
853 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
856 case LPFC_VPORT_FAILED:
857 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
860 case LPFC_VPORT_UNKNOWN:
861 len += snprintf(buf + len, PAGE_SIZE - len,
865 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
866 len += snprintf(buf + len, PAGE_SIZE-len,
867 " Menlo Maint Mode\n");
868 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
869 if (vport->fc_flag & FC_PUBLIC_LOOP)
870 len += snprintf(buf + len, PAGE_SIZE-len,
873 len += snprintf(buf + len, PAGE_SIZE-len,
876 if (vport->fc_flag & FC_FABRIC)
877 len += snprintf(buf + len, PAGE_SIZE-len,
880 len += snprintf(buf + len, PAGE_SIZE-len,
885 if ((phba->sli_rev == LPFC_SLI_REV4) &&
886 ((bf_get(lpfc_sli_intf_if_type,
887 &phba->sli4_hba.sli_intf) ==
888 LPFC_SLI_INTF_IF_TYPE_6))) {
889 struct lpfc_trunk_link link = phba->trunk_link;
891 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
892 len += snprintf(buf + len, PAGE_SIZE - len,
893 "Trunk port 0: Link %s %s\n",
894 (link.link0.state == LPFC_LINK_UP) ?
896 trunk_errmsg[link.link0.fault]);
898 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
899 len += snprintf(buf + len, PAGE_SIZE - len,
900 "Trunk port 1: Link %s %s\n",
901 (link.link1.state == LPFC_LINK_UP) ?
903 trunk_errmsg[link.link1.fault]);
905 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
906 len += snprintf(buf + len, PAGE_SIZE - len,
907 "Trunk port 2: Link %s %s\n",
908 (link.link2.state == LPFC_LINK_UP) ?
910 trunk_errmsg[link.link2.fault]);
912 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
913 len += snprintf(buf + len, PAGE_SIZE - len,
914 "Trunk port 3: Link %s %s\n",
915 (link.link3.state == LPFC_LINK_UP) ?
917 trunk_errmsg[link.link3.fault]);
925 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
926 * @dev: class unused variable.
927 * @attr: device attribute, not used.
928 * @buf: on return contains the module description text.
930 * Returns: size of formatted string.
933 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
936 struct Scsi_Host *shost = class_to_shost(dev);
937 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
938 struct lpfc_hba *phba = vport->phba;
940 if (phba->sli_rev < LPFC_SLI_REV4)
941 return snprintf(buf, PAGE_SIZE, "fc\n");
943 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
944 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
945 return snprintf(buf, PAGE_SIZE, "fcoe\n");
946 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
947 return snprintf(buf, PAGE_SIZE, "fc\n");
949 return snprintf(buf, PAGE_SIZE, "unknown\n");
953 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
954 * (OAS) is supported.
955 * @dev: class unused variable.
956 * @attr: device attribute, not used.
957 * @buf: on return contains the module description text.
959 * Returns: size of formatted string.
962 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
965 struct Scsi_Host *shost = class_to_shost(dev);
966 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
967 struct lpfc_hba *phba = vport->phba;
969 return snprintf(buf, PAGE_SIZE, "%d\n",
970 phba->sli4_hba.pc_sli4_params.oas_supported);
974 * lpfc_link_state_store - Transition the link_state on an HBA port
975 * @dev: class device that is converted into a Scsi_host.
976 * @attr: device attribute, not used.
977 * @buf: one or more lpfc_polling_flags values.
981 * -EINVAL if the buffer is not "up" or "down"
982 * return from link state change function if non-zero
983 * length of the buf on success
986 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
987 const char *buf, size_t count)
989 struct Scsi_Host *shost = class_to_shost(dev);
990 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
991 struct lpfc_hba *phba = vport->phba;
993 int status = -EINVAL;
995 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
996 (phba->link_state == LPFC_LINK_DOWN))
997 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
998 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
999 (phba->link_state >= LPFC_LINK_UP))
1000 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1009 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1010 * @dev: class device that is converted into a Scsi_host.
1011 * @attr: device attribute, not used.
1012 * @buf: on return contains the sum of fc mapped and unmapped.
1015 * Returns the ascii text number of the sum of the fc mapped and unmapped
1018 * Returns: size of formatted string.
1021 lpfc_num_discovered_ports_show(struct device *dev,
1022 struct device_attribute *attr, char *buf)
1024 struct Scsi_Host *shost = class_to_shost(dev);
1025 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1027 return snprintf(buf, PAGE_SIZE, "%d\n",
1028 vport->fc_map_cnt + vport->fc_unmap_cnt);
1032 * lpfc_issue_lip - Misnomer, name carried over from long ago
1033 * @shost: Scsi_Host pointer.
1036 * Bring the link down gracefully then re-init the link. The firmware will
1037 * re-init the fiber channel interface as required. Does not issue a LIP.
1040 * -EPERM port offline or management commands are being blocked
1041 * -ENOMEM cannot allocate memory for the mailbox command
1042 * -EIO error sending the mailbox command
1046 lpfc_issue_lip(struct Scsi_Host *shost)
1048 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1049 struct lpfc_hba *phba = vport->phba;
1050 LPFC_MBOXQ_t *pmboxq;
1051 int mbxstatus = MBXERR_ERROR;
1054 * If the link is offline, disabled or BLOCK_MGMT_IO
1055 * it doesn't make any sense to allow issue_lip
1057 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1058 (phba->hba_flag & LINK_DISABLED) ||
1059 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1062 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1067 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1068 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1069 pmboxq->u.mb.mbxOwner = OWN_HOST;
1071 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1073 if ((mbxstatus == MBX_SUCCESS) &&
1074 (pmboxq->u.mb.mbxStatus == 0 ||
1075 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1076 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1077 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1078 phba->cfg_link_speed);
1079 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1080 phba->fc_ratov * 2);
1081 if ((mbxstatus == MBX_SUCCESS) &&
1082 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1083 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1084 "2859 SLI authentication is required "
1085 "for INIT_LINK but has not done yet\n");
1088 lpfc_set_loopback_flag(phba);
1089 if (mbxstatus != MBX_TIMEOUT)
1090 mempool_free(pmboxq, phba->mbox_mem_pool);
1092 if (mbxstatus == MBXERR_ERROR)
1099 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1103 spin_lock_irq(lock);
1104 while (!list_empty(q)) {
1105 spin_unlock_irq(lock);
1107 if (cnt++ > 250) { /* 5 secs */
1108 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1110 "Outstanding IO when ",
1111 "bringing Adapter offline\n");
1114 spin_lock_irq(lock);
1116 spin_unlock_irq(lock);
1121 * lpfc_do_offline - Issues a mailbox command to bring the link down
1122 * @phba: lpfc_hba pointer.
1123 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1126 * Assumes any error from lpfc_do_offline() will be negative.
1127 * Can wait up to 5 seconds for the port ring buffers count
1128 * to reach zero, prints a warning if it is not zero and continues.
1129 * lpfc_workq_post_event() returns a non-zero return code if call fails.
1132 * -EIO error posting the event
1136 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1138 struct completion online_compl;
1139 struct lpfc_queue *qp = NULL;
1140 struct lpfc_sli_ring *pring;
1141 struct lpfc_sli *psli;
1146 init_completion(&online_compl);
1147 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1148 LPFC_EVT_OFFLINE_PREP);
1152 wait_for_completion(&online_compl);
1159 /* Wait a little for things to settle down, but not
1160 * long enough for dev loss timeout to expire.
1162 if (phba->sli_rev != LPFC_SLI_REV4) {
1163 for (i = 0; i < psli->num_rings; i++) {
1164 pring = &psli->sli3_ring[i];
1165 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1170 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1174 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1180 init_completion(&online_compl);
1181 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1185 wait_for_completion(&online_compl);
1194 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1195 * @phba: lpfc_hba pointer.
1198 * Issues a PCI secondary bus reset for the phba->pcidev.
1201 * First walks the bus_list to ensure only PCI devices with Emulex
1202 * vendor id, device ids that support hot reset, only one occurrence
1203 * of function 0, and all ports on the bus are in offline mode to ensure the
1204 * hot reset only affects one valid HBA.
1207 * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1208 * -ENODEV, NULL ptr to pcidev
1209 * -EBADSLT, detected invalid device
1210 * -EBUSY, port is not in offline state
1214 lpfc_reset_pci_bus(struct lpfc_hba *phba)
1216 struct pci_dev *pdev = phba->pcidev;
1217 struct Scsi_Host *shost = NULL;
1218 struct lpfc_hba *phba_other = NULL;
1219 struct pci_dev *ptr = NULL;
1222 if (phba->cfg_enable_hba_reset != 2)
1226 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1230 res = lpfc_check_pci_resettable(phba);
1234 /* Walk the list of devices on the pci_dev's bus */
1235 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1236 /* Check port is offline */
1237 shost = pci_get_drvdata(ptr);
1240 ((struct lpfc_vport *)shost->hostdata)->phba;
1241 if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1242 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1243 "8349 WWPN = 0x%02x%02x%02x%02x"
1244 "%02x%02x%02x%02x is not "
1246 phba_other->wwpn[0],
1247 phba_other->wwpn[1],
1248 phba_other->wwpn[2],
1249 phba_other->wwpn[3],
1250 phba_other->wwpn[4],
1251 phba_other->wwpn[5],
1252 phba_other->wwpn[6],
1253 phba_other->wwpn[7]);
1259 /* Issue PCI bus reset */
1260 res = pci_reset_bus(pdev);
1262 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1263 "8350 PCI reset bus failed: %d\n", res);
1270 * lpfc_selective_reset - Offline then onlines the port
1271 * @phba: lpfc_hba pointer.
1274 * If the port is configured to allow a reset then the hba is brought
1275 * offline then online.
1278 * Assumes any error from lpfc_do_offline() will be negative.
1279 * Do not make this function static.
1282 * lpfc_do_offline() return code if not zero
1283 * -EIO reset not configured or error posting the event
1287 lpfc_selective_reset(struct lpfc_hba *phba)
1289 struct completion online_compl;
1293 if (!phba->cfg_enable_hba_reset)
1296 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1297 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1303 init_completion(&online_compl);
1304 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1309 wait_for_completion(&online_compl);
1318 * lpfc_issue_reset - Selectively resets an adapter
1319 * @dev: class device that is converted into a Scsi_host.
1320 * @attr: device attribute, not used.
1321 * @buf: containing the string "selective".
1322 * @count: unused variable.
1325 * If the buf contains the string "selective" then lpfc_selective_reset()
1326 * is called to perform the reset.
1329 * Assumes any error from lpfc_selective_reset() will be negative.
1330 * If lpfc_selective_reset() returns zero then the length of the buffer
1331 * is returned which indicates success
1334 * -EINVAL if the buffer does not contain the string "selective"
1335 * length of buf if lpfc-selective_reset() if the call succeeds
1336 * return value of lpfc_selective_reset() if the call fails
1339 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1340 const char *buf, size_t count)
1342 struct Scsi_Host *shost = class_to_shost(dev);
1343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1344 struct lpfc_hba *phba = vport->phba;
1345 int status = -EINVAL;
1347 if (!phba->cfg_enable_hba_reset)
1350 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1351 status = phba->lpfc_selective_reset(phba);
1360 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1361 * @phba: lpfc_hba pointer.
1364 * SLI4 interface type-2 device to wait on the sliport status register for
1365 * the readyness after performing a firmware reset.
1368 * zero for success, -EPERM when port does not have privilege to perform the
1369 * reset, -EIO when port timeout from recovering from the reset.
1372 * As the caller will interpret the return code by value, be careful in making
1373 * change or addition to return codes.
1376 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1378 struct lpfc_register portstat_reg = {0};
1382 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1383 &portstat_reg.word0);
1385 /* verify if privileged for the request operation */
1386 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1387 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1390 /* wait for the SLI port firmware ready after firmware reset */
1391 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1393 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1394 &portstat_reg.word0);
1395 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1397 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1399 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1404 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1411 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1412 * @phba: lpfc_hba pointer.
1415 * Request SLI4 interface type-2 device to perform a physical register set
1422 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1424 struct completion online_compl;
1425 struct pci_dev *pdev = phba->pcidev;
1426 uint32_t before_fc_flag;
1427 uint32_t sriov_nr_virtfn;
1429 int status = 0, rc = 0;
1430 int job_posted = 1, sriov_err;
1432 if (!phba->cfg_enable_hba_reset)
1435 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1436 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1437 LPFC_SLI_INTF_IF_TYPE_2))
1440 /* Keep state if we need to restore back */
1441 before_fc_flag = phba->pport->fc_flag;
1442 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1444 /* Disable SR-IOV virtual functions if enabled */
1445 if (phba->cfg_sriov_nr_virtfn) {
1446 pci_disable_sriov(pdev);
1447 phba->cfg_sriov_nr_virtfn = 0;
1450 if (opcode == LPFC_FW_DUMP)
1451 phba->hba_flag |= HBA_FW_DUMP_OP;
1453 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1456 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1460 /* wait for the device to be quiesced before firmware reset */
1463 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1464 LPFC_CTL_PDEV_CTL_OFFSET);
1466 if (opcode == LPFC_FW_DUMP)
1467 reg_val |= LPFC_FW_DUMP_REQUEST;
1468 else if (opcode == LPFC_FW_RESET)
1469 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1470 else if (opcode == LPFC_DV_RESET)
1471 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1473 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1474 LPFC_CTL_PDEV_CTL_OFFSET);
1476 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1478 /* delay driver action following IF_TYPE_2 reset */
1479 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1482 /* no privilege for reset */
1483 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1484 "3150 No privilege to perform the requested "
1485 "access: x%x\n", reg_val);
1486 } else if (rc == -EIO) {
1487 /* reset failed, there is nothing more we can do */
1488 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1489 "3153 Fail to perform the requested "
1490 "access: x%x\n", reg_val);
1494 /* keep the original port state */
1495 if (before_fc_flag & FC_OFFLINE_MODE)
1498 init_completion(&online_compl);
1499 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1504 wait_for_completion(&online_compl);
1507 /* in any case, restore the virtual functions enabled as before */
1508 if (sriov_nr_virtfn) {
1510 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1512 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1515 /* return proper error code */
1526 * lpfc_nport_evt_cnt_show - Return the number of nport events
1527 * @dev: class device that is converted into a Scsi_host.
1528 * @attr: device attribute, not used.
1529 * @buf: on return contains the ascii number of nport events.
1531 * Returns: size of formatted string.
1534 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1537 struct Scsi_Host *shost = class_to_shost(dev);
1538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1539 struct lpfc_hba *phba = vport->phba;
1541 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1545 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1547 LPFC_MBOXQ_t *mbox = NULL;
1548 unsigned long val = 0;
1552 if (!strncmp("enable", buff_out,
1553 strlen("enable"))) {
1554 pval = buff_out + strlen("enable") + 1;
1555 rc = kstrtoul(pval, 0, &val);
1557 return rc; /* Invalid number */
1558 } else if (!strncmp("disable", buff_out,
1559 strlen("disable"))) {
1562 return -EINVAL; /* Invalid command */
1567 val = 0x0; /* Disable */
1570 val = 0x1; /* Enable two port trunk */
1573 val = 0x2; /* Enable four port trunk */
1579 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1580 "0070 Set trunk mode with val %ld ", val);
1582 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1586 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1587 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1588 12, LPFC_SLI4_MBX_EMBED);
1590 bf_set(lpfc_mbx_set_trunk_mode,
1591 &mbox->u.mqe.un.set_trunk_mode,
1593 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1595 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1596 "0071 Set trunk mode failed with status: %d",
1598 if (rc != MBX_TIMEOUT)
1599 mempool_free(mbox, phba->mbox_mem_pool);
1605 * lpfc_board_mode_show - Return the state of the board
1606 * @dev: class device that is converted into a Scsi_host.
1607 * @attr: device attribute, not used.
1608 * @buf: on return contains the state of the adapter.
1610 * Returns: size of formatted string.
1613 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1616 struct Scsi_Host *shost = class_to_shost(dev);
1617 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1618 struct lpfc_hba *phba = vport->phba;
1621 if (phba->link_state == LPFC_HBA_ERROR)
1623 else if (phba->link_state == LPFC_WARM_START)
1624 state = "warm start";
1625 else if (phba->link_state == LPFC_INIT_START)
1630 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1634 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1635 * @dev: class device that is converted into a Scsi_host.
1636 * @attr: device attribute, not used.
1637 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1638 * @count: unused variable.
1641 * -EACCES if enable hba reset not enabled
1642 * -EINVAL if the buffer does not contain a valid string (see above)
1643 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1644 * buf length greater than zero indicates success
1647 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1648 const char *buf, size_t count)
1650 struct Scsi_Host *shost = class_to_shost(dev);
1651 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1652 struct lpfc_hba *phba = vport->phba;
1653 struct completion online_compl;
1654 char *board_mode_str = NULL;
1658 if (!phba->cfg_enable_hba_reset) {
1660 goto board_mode_out;
1663 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1664 "3050 lpfc_board_mode set to %s\n", buf);
1666 init_completion(&online_compl);
1668 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1669 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1673 goto board_mode_out;
1675 wait_for_completion(&online_compl);
1678 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1679 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1680 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1681 if (phba->sli_rev == LPFC_SLI_REV4)
1684 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1685 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1686 if (phba->sli_rev == LPFC_SLI_REV4)
1689 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1690 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1691 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1692 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1693 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1694 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1695 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1696 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1698 status = lpfc_reset_pci_bus(phba);
1699 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1700 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
1708 board_mode_str = strchr(buf, '\n');
1710 *board_mode_str = '\0';
1711 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1712 "3097 Failed \"%s\", status(%d), "
1714 buf, status, phba->pport->fc_flag);
1720 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1721 * @phba: pointer to the adapter structure.
1722 * @mxri: max xri count.
1723 * @axri: available xri count.
1724 * @mrpi: max rpi count.
1725 * @arpi: available rpi count.
1726 * @mvpi: max vpi count.
1727 * @avpi: available vpi count.
1730 * If an integer pointer for an count is not null then the value for the
1731 * count is returned.
1738 lpfc_get_hba_info(struct lpfc_hba *phba,
1739 uint32_t *mxri, uint32_t *axri,
1740 uint32_t *mrpi, uint32_t *arpi,
1741 uint32_t *mvpi, uint32_t *avpi)
1743 struct lpfc_mbx_read_config *rd_config;
1744 LPFC_MBOXQ_t *pmboxq;
1750 * prevent udev from issuing mailbox commands until the port is
1753 if (phba->link_state < LPFC_LINK_DOWN ||
1754 !phba->mbox_mem_pool ||
1755 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1758 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1761 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1764 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1766 pmb = &pmboxq->u.mb;
1767 pmb->mbxCommand = MBX_READ_CONFIG;
1768 pmb->mbxOwner = OWN_HOST;
1769 pmboxq->ctx_buf = NULL;
1771 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1772 rc = MBX_NOT_FINISHED;
1774 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1776 if (rc != MBX_SUCCESS) {
1777 if (rc != MBX_TIMEOUT)
1778 mempool_free(pmboxq, phba->mbox_mem_pool);
1782 if (phba->sli_rev == LPFC_SLI_REV4) {
1783 rd_config = &pmboxq->u.mqe.un.rd_config;
1785 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1787 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1788 phba->sli4_hba.max_cfg_param.rpi_used;
1790 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1792 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1793 phba->sli4_hba.max_cfg_param.xri_used;
1795 /* Account for differences with SLI-3. Get vpi count from
1796 * mailbox data and subtract one for max vpi value.
1798 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1799 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1801 /* Limit the max we support */
1802 if (max_vpi > LPFC_MAX_VPI)
1803 max_vpi = LPFC_MAX_VPI;
1807 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1810 *mrpi = pmb->un.varRdConfig.max_rpi;
1812 *arpi = pmb->un.varRdConfig.avail_rpi;
1814 *mxri = pmb->un.varRdConfig.max_xri;
1816 *axri = pmb->un.varRdConfig.avail_xri;
1818 *mvpi = pmb->un.varRdConfig.max_vpi;
1820 /* avail_vpi is only valid if link is up and ready */
1821 if (phba->link_state == LPFC_HBA_READY)
1822 *avpi = pmb->un.varRdConfig.avail_vpi;
1824 *avpi = pmb->un.varRdConfig.max_vpi;
1828 mempool_free(pmboxq, phba->mbox_mem_pool);
1833 * lpfc_max_rpi_show - Return maximum rpi
1834 * @dev: class device that is converted into a Scsi_host.
1835 * @attr: device attribute, not used.
1836 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1839 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1840 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1841 * to "Unknown" and the buffer length is returned, therefore the caller
1842 * must check for "Unknown" in the buffer to detect a failure.
1844 * Returns: size of formatted string.
1847 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1850 struct Scsi_Host *shost = class_to_shost(dev);
1851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1852 struct lpfc_hba *phba = vport->phba;
1855 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1856 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1857 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1861 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1862 * @dev: class device that is converted into a Scsi_host.
1863 * @attr: device attribute, not used.
1864 * @buf: containing the used rpi count in decimal or "Unknown".
1867 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1868 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1869 * to "Unknown" and the buffer length is returned, therefore the caller
1870 * must check for "Unknown" in the buffer to detect a failure.
1872 * Returns: size of formatted string.
1875 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1878 struct Scsi_Host *shost = class_to_shost(dev);
1879 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1880 struct lpfc_hba *phba = vport->phba;
1883 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1884 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1885 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1889 * lpfc_max_xri_show - Return maximum xri
1890 * @dev: class device that is converted into a Scsi_host.
1891 * @attr: device attribute, not used.
1892 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1895 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1896 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1897 * to "Unknown" and the buffer length is returned, therefore the caller
1898 * must check for "Unknown" in the buffer to detect a failure.
1900 * Returns: size of formatted string.
1903 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1906 struct Scsi_Host *shost = class_to_shost(dev);
1907 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1908 struct lpfc_hba *phba = vport->phba;
1911 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1912 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1913 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1917 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1918 * @dev: class device that is converted into a Scsi_host.
1919 * @attr: device attribute, not used.
1920 * @buf: on return contains the used xri count in decimal or "Unknown".
1923 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1924 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1925 * to "Unknown" and the buffer length is returned, therefore the caller
1926 * must check for "Unknown" in the buffer to detect a failure.
1928 * Returns: size of formatted string.
1931 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1934 struct Scsi_Host *shost = class_to_shost(dev);
1935 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1936 struct lpfc_hba *phba = vport->phba;
1939 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1940 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1941 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1945 * lpfc_max_vpi_show - Return maximum vpi
1946 * @dev: class device that is converted into a Scsi_host.
1947 * @attr: device attribute, not used.
1948 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1951 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1952 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1953 * to "Unknown" and the buffer length is returned, therefore the caller
1954 * must check for "Unknown" in the buffer to detect a failure.
1956 * Returns: size of formatted string.
1959 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1962 struct Scsi_Host *shost = class_to_shost(dev);
1963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1964 struct lpfc_hba *phba = vport->phba;
1967 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1968 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1969 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1973 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1974 * @dev: class device that is converted into a Scsi_host.
1975 * @attr: device attribute, not used.
1976 * @buf: on return contains the used vpi count in decimal or "Unknown".
1979 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1980 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1981 * to "Unknown" and the buffer length is returned, therefore the caller
1982 * must check for "Unknown" in the buffer to detect a failure.
1984 * Returns: size of formatted string.
1987 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1990 struct Scsi_Host *shost = class_to_shost(dev);
1991 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1992 struct lpfc_hba *phba = vport->phba;
1995 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1996 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1997 return snprintf(buf, PAGE_SIZE, "Unknown\n");
2001 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2002 * @dev: class device that is converted into a Scsi_host.
2003 * @attr: device attribute, not used.
2004 * @buf: text that must be interpreted to determine if npiv is supported.
2007 * Buffer will contain text indicating npiv is not suppoerted on the port,
2008 * the port is an NPIV physical port, or it is an npiv virtual port with
2009 * the id of the vport.
2011 * Returns: size of formatted string.
2014 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2017 struct Scsi_Host *shost = class_to_shost(dev);
2018 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2019 struct lpfc_hba *phba = vport->phba;
2021 if (!(phba->max_vpi))
2022 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2023 if (vport->port_type == LPFC_PHYSICAL_PORT)
2024 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2025 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2029 * lpfc_poll_show - Return text about poll support for the adapter
2030 * @dev: class device that is converted into a Scsi_host.
2031 * @attr: device attribute, not used.
2032 * @buf: on return contains the cfg_poll in hex.
2035 * cfg_poll should be a lpfc_polling_flags type.
2037 * Returns: size of formatted string.
2040 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2043 struct Scsi_Host *shost = class_to_shost(dev);
2044 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2045 struct lpfc_hba *phba = vport->phba;
2047 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2051 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2052 * @dev: class device that is converted into a Scsi_host.
2053 * @attr: device attribute, not used.
2054 * @buf: one or more lpfc_polling_flags values.
2058 * buf contents converted to integer and checked for a valid value.
2061 * -EINVAL if the buffer connot be converted or is out of range
2062 * length of the buf on success
2065 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2066 const char *buf, size_t count)
2068 struct Scsi_Host *shost = class_to_shost(dev);
2069 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2070 struct lpfc_hba *phba = vport->phba;
2075 if (!isdigit(buf[0]))
2078 if (sscanf(buf, "%i", &val) != 1)
2081 if ((val & 0x3) != val)
2084 if (phba->sli_rev == LPFC_SLI_REV4)
2087 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2088 "3051 lpfc_poll changed from %d to %d\n",
2089 phba->cfg_poll, val);
2091 spin_lock_irq(&phba->hbalock);
2093 old_val = phba->cfg_poll;
2095 if (val & ENABLE_FCP_RING_POLLING) {
2096 if ((val & DISABLE_FCP_RING_INT) &&
2097 !(old_val & DISABLE_FCP_RING_INT)) {
2098 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2099 spin_unlock_irq(&phba->hbalock);
2102 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2103 writel(creg_val, phba->HCregaddr);
2104 readl(phba->HCregaddr); /* flush */
2106 lpfc_poll_start_timer(phba);
2108 } else if (val != 0x0) {
2109 spin_unlock_irq(&phba->hbalock);
2113 if (!(val & DISABLE_FCP_RING_INT) &&
2114 (old_val & DISABLE_FCP_RING_INT))
2116 spin_unlock_irq(&phba->hbalock);
2117 del_timer(&phba->fcp_poll_timer);
2118 spin_lock_irq(&phba->hbalock);
2119 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2120 spin_unlock_irq(&phba->hbalock);
2123 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2124 writel(creg_val, phba->HCregaddr);
2125 readl(phba->HCregaddr); /* flush */
2128 phba->cfg_poll = val;
2130 spin_unlock_irq(&phba->hbalock);
2136 * lpfc_fips_level_show - Return the current FIPS level for the HBA
2137 * @dev: class unused variable.
2138 * @attr: device attribute, not used.
2139 * @buf: on return contains the module description text.
2141 * Returns: size of formatted string.
2144 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
2147 struct Scsi_Host *shost = class_to_shost(dev);
2148 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2149 struct lpfc_hba *phba = vport->phba;
2151 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
2155 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
2156 * @dev: class unused variable.
2157 * @attr: device attribute, not used.
2158 * @buf: on return contains the module description text.
2160 * Returns: size of formatted string.
2163 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
2166 struct Scsi_Host *shost = class_to_shost(dev);
2167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2168 struct lpfc_hba *phba = vport->phba;
2170 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
2174 * lpfc_dss_show - Return the current state of dss and the configured state
2175 * @dev: class converted to a Scsi_host structure.
2176 * @attr: device attribute, not used.
2177 * @buf: on return contains the formatted text.
2179 * Returns: size of formatted string.
2182 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
2185 struct Scsi_Host *shost = class_to_shost(dev);
2186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2187 struct lpfc_hba *phba = vport->phba;
2189 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
2190 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
2191 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
2196 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2197 * @dev: class converted to a Scsi_host structure.
2198 * @attr: device attribute, not used.
2199 * @buf: on return contains the formatted support level.
2202 * Returns the maximum number of virtual functions a physical function can
2203 * support, 0 will be returned if called on virtual function.
2205 * Returns: size of formatted string.
2208 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2209 struct device_attribute *attr,
2212 struct Scsi_Host *shost = class_to_shost(dev);
2213 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2214 struct lpfc_hba *phba = vport->phba;
2215 uint16_t max_nr_virtfn;
2217 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2218 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2221 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2223 return val >= min && val <= max;
2227 * lpfc_enable_bbcr_set: Sets an attribute value.
2228 * @phba: pointer the the adapter structure.
2229 * @val: integer attribute value.
2232 * Validates the min and max values then sets the
2233 * adapter config field if in the valid range. prints error message
2234 * and does not set the parameter if invalid.
2238 * -EINVAL if val is invalid
2241 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2243 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2244 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2245 "3068 %s_enable_bbcr changed from %d to %d\n",
2246 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
2247 phba->cfg_enable_bbcr = val;
2250 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2251 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2252 LPFC_DRIVER_NAME, val);
2257 * lpfc_param_show - Return a cfg attribute value in decimal
2260 * Macro that given an attr e.g. hba_queue_depth expands
2261 * into a function with the name lpfc_hba_queue_depth_show.
2263 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2264 * @dev: class device that is converted into a Scsi_host.
2265 * @attr: device attribute, not used.
2266 * @buf: on return contains the attribute value in decimal.
2268 * Returns: size of formatted string.
2270 #define lpfc_param_show(attr) \
2272 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2275 struct Scsi_Host *shost = class_to_shost(dev);\
2276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2277 struct lpfc_hba *phba = vport->phba;\
2278 return snprintf(buf, PAGE_SIZE, "%d\n",\
2283 * lpfc_param_hex_show - Return a cfg attribute value in hex
2286 * Macro that given an attr e.g. hba_queue_depth expands
2287 * into a function with the name lpfc_hba_queue_depth_show
2289 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2290 * @dev: class device that is converted into a Scsi_host.
2291 * @attr: device attribute, not used.
2292 * @buf: on return contains the attribute value in hexadecimal.
2294 * Returns: size of formatted string.
2296 #define lpfc_param_hex_show(attr) \
2298 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2301 struct Scsi_Host *shost = class_to_shost(dev);\
2302 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2303 struct lpfc_hba *phba = vport->phba;\
2305 val = phba->cfg_##attr;\
2306 return snprintf(buf, PAGE_SIZE, "%#x\n",\
2311 * lpfc_param_init - Initializes a cfg attribute
2314 * Macro that given an attr e.g. hba_queue_depth expands
2315 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2316 * takes a default argument, a minimum and maximum argument.
2318 * lpfc_##attr##_init: Initializes an attribute.
2319 * @phba: pointer the the adapter structure.
2320 * @val: integer attribute value.
2322 * Validates the min and max values then sets the adapter config field
2323 * accordingly, or uses the default if out of range and prints an error message.
2327 * -EINVAL if default used
2329 #define lpfc_param_init(attr, default, minval, maxval) \
2331 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2333 if (lpfc_rangecheck(val, minval, maxval)) {\
2334 phba->cfg_##attr = val;\
2337 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2338 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2339 "allowed range is ["#minval", "#maxval"]\n", val); \
2340 phba->cfg_##attr = default;\
2345 * lpfc_param_set - Set a cfg attribute value
2348 * Macro that given an attr e.g. hba_queue_depth expands
2349 * into a function with the name lpfc_hba_queue_depth_set
2351 * lpfc_##attr##_set: Sets an attribute value.
2352 * @phba: pointer the the adapter structure.
2353 * @val: integer attribute value.
2356 * Validates the min and max values then sets the
2357 * adapter config field if in the valid range. prints error message
2358 * and does not set the parameter if invalid.
2362 * -EINVAL if val is invalid
2364 #define lpfc_param_set(attr, default, minval, maxval) \
2366 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2368 if (lpfc_rangecheck(val, minval, maxval)) {\
2369 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2370 "3052 lpfc_" #attr " changed from %d to %d\n", \
2371 phba->cfg_##attr, val); \
2372 phba->cfg_##attr = val;\
2375 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2376 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2377 "allowed range is ["#minval", "#maxval"]\n", val); \
2382 * lpfc_param_store - Set a vport attribute value
2385 * Macro that given an attr e.g. hba_queue_depth expands
2386 * into a function with the name lpfc_hba_queue_depth_store.
2388 * lpfc_##attr##_store: Set an sttribute value.
2389 * @dev: class device that is converted into a Scsi_host.
2390 * @attr: device attribute, not used.
2391 * @buf: contains the attribute value in ascii.
2395 * Convert the ascii text number to an integer, then
2396 * use the lpfc_##attr##_set function to set the value.
2399 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2400 * length of buffer upon success.
2402 #define lpfc_param_store(attr) \
2404 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2405 const char *buf, size_t count) \
2407 struct Scsi_Host *shost = class_to_shost(dev);\
2408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2409 struct lpfc_hba *phba = vport->phba;\
2411 if (!isdigit(buf[0]))\
2413 if (sscanf(buf, "%i", &val) != 1)\
2415 if (lpfc_##attr##_set(phba, val) == 0) \
2416 return strlen(buf);\
2422 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2425 * Macro that given an attr e.g. hba_queue_depth expands
2426 * into a function with the name lpfc_hba_queue_depth_show
2428 * lpfc_##attr##_show: prints the attribute value in decimal.
2429 * @dev: class device that is converted into a Scsi_host.
2430 * @attr: device attribute, not used.
2431 * @buf: on return contains the attribute value in decimal.
2433 * Returns: length of formatted string.
2435 #define lpfc_vport_param_show(attr) \
2437 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2440 struct Scsi_Host *shost = class_to_shost(dev);\
2441 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2442 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2446 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2449 * Macro that given an attr e.g.
2450 * hba_queue_depth expands into a function with the name
2451 * lpfc_hba_queue_depth_show
2453 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2454 * @dev: class device that is converted into a Scsi_host.
2455 * @attr: device attribute, not used.
2456 * @buf: on return contains the attribute value in hexadecimal.
2458 * Returns: length of formatted string.
2460 #define lpfc_vport_param_hex_show(attr) \
2462 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2465 struct Scsi_Host *shost = class_to_shost(dev);\
2466 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2467 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2471 * lpfc_vport_param_init - Initialize a vport cfg attribute
2474 * Macro that given an attr e.g. hba_queue_depth expands
2475 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2476 * takes a default argument, a minimum and maximum argument.
2478 * lpfc_##attr##_init: validates the min and max values then sets the
2479 * adapter config field accordingly, or uses the default if out of range
2480 * and prints an error message.
2481 * @phba: pointer the the adapter structure.
2482 * @val: integer attribute value.
2486 * -EINVAL if default used
2488 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2490 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2492 if (lpfc_rangecheck(val, minval, maxval)) {\
2493 vport->cfg_##attr = val;\
2496 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2497 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2498 "allowed range is ["#minval", "#maxval"]\n", val); \
2499 vport->cfg_##attr = default;\
2504 * lpfc_vport_param_set - Set a vport cfg attribute
2507 * Macro that given an attr e.g. hba_queue_depth expands
2508 * into a function with the name lpfc_hba_queue_depth_set
2510 * lpfc_##attr##_set: validates the min and max values then sets the
2511 * adapter config field if in the valid range. prints error message
2512 * and does not set the parameter if invalid.
2513 * @phba: pointer the the adapter structure.
2514 * @val: integer attribute value.
2518 * -EINVAL if val is invalid
2520 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2522 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2524 if (lpfc_rangecheck(val, minval, maxval)) {\
2525 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2526 "3053 lpfc_" #attr \
2527 " changed from %d (x%x) to %d (x%x)\n", \
2528 vport->cfg_##attr, vport->cfg_##attr, \
2530 vport->cfg_##attr = val;\
2533 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2534 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2535 "allowed range is ["#minval", "#maxval"]\n", val); \
2540 * lpfc_vport_param_store - Set a vport attribute
2543 * Macro that given an attr e.g. hba_queue_depth
2544 * expands into a function with the name lpfc_hba_queue_depth_store
2546 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2547 * use the lpfc_##attr##_set function to set the value.
2548 * @cdev: class device that is converted into a Scsi_host.
2549 * @buf: contains the attribute value in decimal.
2553 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2554 * length of buffer upon success.
2556 #define lpfc_vport_param_store(attr) \
2558 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2559 const char *buf, size_t count) \
2561 struct Scsi_Host *shost = class_to_shost(dev);\
2562 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2564 if (!isdigit(buf[0]))\
2566 if (sscanf(buf, "%i", &val) != 1)\
2568 if (lpfc_##attr##_set(vport, val) == 0) \
2569 return strlen(buf);\
2575 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2576 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2577 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2578 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2579 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2580 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2581 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2582 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2583 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2584 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2585 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2586 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2587 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2588 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2589 lpfc_link_state_store);
2590 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2591 lpfc_option_rom_version_show, NULL);
2592 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2593 lpfc_num_discovered_ports_show, NULL);
2594 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2595 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2596 static DEVICE_ATTR_RO(lpfc_drvr_version);
2597 static DEVICE_ATTR_RO(lpfc_enable_fip);
2598 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2599 lpfc_board_mode_show, lpfc_board_mode_store);
2600 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2601 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2602 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2603 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2604 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2605 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2606 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2607 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2608 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2609 static DEVICE_ATTR_RO(lpfc_fips_level);
2610 static DEVICE_ATTR_RO(lpfc_fips_rev);
2611 static DEVICE_ATTR_RO(lpfc_dss);
2612 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2613 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2614 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2617 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2620 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2622 * @cnt: Length of string.
2623 * @wwn: Array to receive converted wwn value.
2626 * -EINVAL if the buffer does not contain a valid wwn
2630 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2634 /* Count may include a LF at end of string */
2635 if (buf[cnt-1] == '\n')
2638 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2639 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2642 memset(wwn, 0, WWN_SZ);
2644 /* Validate and store the new name */
2645 for (i = 0, j = 0; i < 16; i++) {
2646 if ((*buf >= 'a') && (*buf <= 'f'))
2647 j = ((j << 4) | ((*buf++ - 'a') + 10));
2648 else if ((*buf >= 'A') && (*buf <= 'F'))
2649 j = ((j << 4) | ((*buf++ - 'A') + 10));
2650 else if ((*buf >= '0') && (*buf <= '9'))
2651 j = ((j << 4) | (*buf++ - '0'));
2655 wwn[i/2] = j & 0xff;
2662 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2663 * @dev: class device that is converted into a Scsi_host.
2664 * @attr: device attribute, not used.
2665 * @buf: containing the string lpfc_soft_wwn_key.
2666 * @count: must be size of lpfc_soft_wwn_key.
2669 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2670 * length of buf indicates success
2673 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2674 const char *buf, size_t count)
2676 struct Scsi_Host *shost = class_to_shost(dev);
2677 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2678 struct lpfc_hba *phba = vport->phba;
2679 unsigned int cnt = count;
2680 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2681 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2684 * We're doing a simple sanity check for soft_wwpn setting.
2685 * We require that the user write a specific key to enable
2686 * the soft_wwpn attribute to be settable. Once the attribute
2687 * is written, the enable key resets. If further updates are
2688 * desired, the key must be written again to re-enable the
2691 * The "key" is not secret - it is a hardcoded string shown
2692 * here. The intent is to protect against the random user or
2693 * application that is just writing attributes.
2695 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2696 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2697 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2698 " be enabled: fawwpn is enabled\n");
2702 /* count may include a LF at end of string */
2703 if (buf[cnt-1] == '\n')
2706 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2707 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2710 phba->soft_wwn_enable = 1;
2712 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2713 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2715 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2716 " The soft_wwpn feature is not supported by Broadcom.");
2720 static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
2723 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2724 * @dev: class device that is converted into a Scsi_host.
2725 * @attr: device attribute, not used.
2726 * @buf: on return contains the wwpn in hexadecimal.
2728 * Returns: size of formatted string.
2731 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2734 struct Scsi_Host *shost = class_to_shost(dev);
2735 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2736 struct lpfc_hba *phba = vport->phba;
2738 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2739 (unsigned long long)phba->cfg_soft_wwpn);
2743 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2744 * @dev class device that is converted into a Scsi_host.
2745 * @attr: device attribute, not used.
2746 * @buf: contains the wwpn in hexadecimal.
2747 * @count: number of wwpn bytes in buf
2750 * -EACCES hba reset not enabled, adapter over temp
2751 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2752 * -EIO error taking adapter offline or online
2753 * value of count on success
2756 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2757 const char *buf, size_t count)
2759 struct Scsi_Host *shost = class_to_shost(dev);
2760 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2761 struct lpfc_hba *phba = vport->phba;
2762 struct completion online_compl;
2763 int stat1 = 0, stat2 = 0;
2764 unsigned int cnt = count;
2768 if (!phba->cfg_enable_hba_reset)
2770 spin_lock_irq(&phba->hbalock);
2771 if (phba->over_temp_state == HBA_OVER_TEMP) {
2772 spin_unlock_irq(&phba->hbalock);
2775 spin_unlock_irq(&phba->hbalock);
2776 /* count may include a LF at end of string */
2777 if (buf[cnt-1] == '\n')
2780 if (!phba->soft_wwn_enable)
2783 /* lock setting wwpn, wwnn down */
2784 phba->soft_wwn_enable = 0;
2786 rc = lpfc_wwn_set(buf, cnt, wwpn);
2788 /* not able to set wwpn, unlock it */
2789 phba->soft_wwn_enable = 1;
2793 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2794 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2795 if (phba->cfg_soft_wwnn)
2796 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2798 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2799 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2801 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2803 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2804 "0463 lpfc_soft_wwpn attribute set failed to "
2805 "reinit adapter - %d\n", stat1);
2806 init_completion(&online_compl);
2807 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2812 wait_for_completion(&online_compl);
2814 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2815 "0464 lpfc_soft_wwpn attribute set failed to "
2816 "reinit adapter - %d\n", stat2);
2817 return (stat1 || stat2) ? -EIO : count;
2819 static DEVICE_ATTR_RW(lpfc_soft_wwpn);
2822 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2823 * @dev: class device that is converted into a Scsi_host.
2824 * @attr: device attribute, not used.
2825 * @buf: on return contains the wwnn in hexadecimal.
2827 * Returns: size of formatted string.
2830 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2833 struct Scsi_Host *shost = class_to_shost(dev);
2834 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2835 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2836 (unsigned long long)phba->cfg_soft_wwnn);
2840 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2841 * @cdev: class device that is converted into a Scsi_host.
2842 * @buf: contains the ww node name in hexadecimal.
2843 * @count: number of wwnn bytes in buf.
2846 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2847 * value of count on success
2850 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2851 const char *buf, size_t count)
2853 struct Scsi_Host *shost = class_to_shost(dev);
2854 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2855 unsigned int cnt = count;
2859 /* count may include a LF at end of string */
2860 if (buf[cnt-1] == '\n')
2863 if (!phba->soft_wwn_enable)
2866 rc = lpfc_wwn_set(buf, cnt, wwnn);
2868 /* Allow wwnn to be set many times, as long as the enable
2869 * is set. However, once the wwpn is set, everything locks.
2874 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2876 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2877 "lpfc%d: soft_wwnn set. Value will take effect upon "
2878 "setting of the soft_wwpn\n", phba->brd_no);
2882 static DEVICE_ATTR_RW(lpfc_soft_wwnn);
2885 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2886 * Optimized Access Storage (OAS) operations.
2887 * @dev: class device that is converted into a Scsi_host.
2888 * @attr: device attribute, not used.
2889 * @buf: buffer for passing information.
2895 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2898 struct Scsi_Host *shost = class_to_shost(dev);
2899 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2901 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2902 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2906 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2907 * Optimized Access Storage (OAS) operations.
2908 * @dev: class device that is converted into a Scsi_host.
2909 * @attr: device attribute, not used.
2910 * @buf: buffer for passing information.
2911 * @count: Size of the data buffer.
2914 * -EINVAL count is invalid, invalid wwpn byte invalid
2915 * -EPERM oas is not supported by hba
2916 * value of count on success
2919 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2920 const char *buf, size_t count)
2922 struct Scsi_Host *shost = class_to_shost(dev);
2923 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2924 unsigned int cnt = count;
2925 uint8_t wwpn[WWN_SZ];
2931 /* count may include a LF at end of string */
2932 if (buf[cnt-1] == '\n')
2935 rc = lpfc_wwn_set(buf, cnt, wwpn);
2939 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2940 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2941 if (wwn_to_u64(wwpn) == 0)
2942 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2944 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2945 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2946 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2949 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2950 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2953 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2954 * Optimized Access Storage (OAS) operations.
2955 * @dev: class device that is converted into a Scsi_host.
2956 * @attr: device attribute, not used.
2957 * @buf: buffer for passing information.
2963 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2966 struct Scsi_Host *shost = class_to_shost(dev);
2967 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2969 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2973 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2974 * Optimized Access Storage (OAS) operations.
2975 * @dev: class device that is converted into a Scsi_host.
2976 * @attr: device attribute, not used.
2977 * @buf: buffer for passing information.
2978 * @count: Size of the data buffer.
2981 * -EINVAL count is invalid, invalid wwpn byte invalid
2982 * -EPERM oas is not supported by hba
2983 * value of count on success
2986 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2987 const char *buf, size_t count)
2989 struct Scsi_Host *shost = class_to_shost(dev);
2990 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2991 unsigned int cnt = count;
2998 /* count may include a LF at end of string */
2999 if (buf[cnt-1] == '\n')
3002 ret = kstrtoul(buf, 0, &val);
3003 if (ret || (val > 0x7f))
3007 phba->cfg_oas_priority = (uint8_t)val;
3009 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3012 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3013 lpfc_oas_priority_show, lpfc_oas_priority_store);
3016 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3017 * for Optimized Access Storage (OAS) operations.
3018 * @dev: class device that is converted into a Scsi_host.
3019 * @attr: device attribute, not used.
3020 * @buf: buffer for passing information.
3023 * value of count on success
3026 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3029 struct Scsi_Host *shost = class_to_shost(dev);
3030 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3032 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
3033 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3037 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3038 * for Optimized Access Storage (OAS) operations.
3039 * @dev: class device that is converted into a Scsi_host.
3040 * @attr: device attribute, not used.
3041 * @buf: buffer for passing information.
3042 * @count: Size of the data buffer.
3045 * -EINVAL count is invalid, invalid wwpn byte invalid
3046 * -EPERM oas is not supported by hba
3047 * value of count on success
3050 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3051 const char *buf, size_t count)
3053 struct Scsi_Host *shost = class_to_shost(dev);
3054 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3055 unsigned int cnt = count;
3056 uint8_t wwpn[WWN_SZ];
3062 /* count may include a LF at end of string */
3063 if (buf[cnt-1] == '\n')
3066 rc = lpfc_wwn_set(buf, cnt, wwpn);
3070 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3071 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3072 if (wwn_to_u64(wwpn) == 0)
3073 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3075 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3076 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3077 if (phba->cfg_oas_priority == 0)
3078 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3079 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3082 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3083 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3086 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3087 * of whether luns will be enabled or disabled
3088 * for Optimized Access Storage (OAS) operations.
3089 * @dev: class device that is converted into a Scsi_host.
3090 * @attr: device attribute, not used.
3091 * @buf: buffer for passing information.
3094 * size of formatted string.
3097 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3100 struct Scsi_Host *shost = class_to_shost(dev);
3101 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3103 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3107 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3108 * of whether luns will be enabled or disabled
3109 * for Optimized Access Storage (OAS) operations.
3110 * @dev: class device that is converted into a Scsi_host.
3111 * @attr: device attribute, not used.
3112 * @buf: buffer for passing information.
3113 * @count: Size of the data buffer.
3116 * -EINVAL count is invalid, invalid wwpn byte invalid
3117 * -EPERM oas is not supported by hba
3118 * value of count on success
3121 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3122 const char *buf, size_t count)
3124 struct Scsi_Host *shost = class_to_shost(dev);
3125 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3131 if (!isdigit(buf[0]))
3134 if (sscanf(buf, "%i", &val) != 1)
3137 if ((val != 0) && (val != 1))
3140 phba->cfg_oas_lun_state = val;
3143 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3144 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3147 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3148 * Storage (OAS) lun returned by the
3149 * lpfc_oas_lun_show function.
3150 * @dev: class device that is converted into a Scsi_host.
3151 * @attr: device attribute, not used.
3152 * @buf: buffer for passing information.
3155 * size of formatted string.
3158 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3161 struct Scsi_Host *shost = class_to_shost(dev);
3162 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3164 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3167 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3169 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3170 lpfc_oas_lun_status_show, NULL);
3174 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3176 * @phba: lpfc_hba pointer.
3177 * @ndlp: pointer to fcp target node.
3178 * @lun: the fc lun for setting oas state.
3179 * @oas_state: the oas state to be set to the lun.
3183 * -EPERM OAS is not enabled or not supported by this port.
3187 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3188 uint8_t tgt_wwpn[], uint64_t lun,
3189 uint32_t oas_state, uint8_t pri)
3198 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3199 (struct lpfc_name *)tgt_wwpn,
3203 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3204 (struct lpfc_name *)tgt_wwpn, lun, pri);
3211 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3212 * Access Storage (OAS) operations.
3213 * @phba: lpfc_hba pointer.
3214 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3215 * @tgt_wwpn: wwpn of the target associated with the returned lun
3216 * @lun_status: status of the lun returned lun
3218 * Returns the first or next lun enabled for OAS operations for the vport/target
3219 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3220 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3223 * lun that is OAS enabled for the vport/target
3224 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3227 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3228 uint8_t tgt_wwpn[], uint32_t *lun_status,
3233 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3234 return NOT_OAS_ENABLED_LUN;
3235 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3236 phba->sli4_hba.oas_next_vpt_wwpn,
3237 (struct lpfc_name *)
3238 phba->sli4_hba.oas_next_tgt_wwpn,
3239 &phba->sli4_hba.oas_next_lun,
3240 (struct lpfc_name *)vpt_wwpn,
3241 (struct lpfc_name *)tgt_wwpn,
3242 &found_lun, lun_status, lun_pri))
3245 return NOT_OAS_ENABLED_LUN;
3249 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3250 * @phba: lpfc_hba pointer.
3251 * @vpt_wwpn: vport wwpn by reference.
3252 * @tgt_wwpn: target wwpn by reference.
3253 * @lun: the fc lun for setting oas state.
3254 * @oas_state: the oas state to be set to the oas_lun.
3256 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3257 * a lun for OAS operations.
3261 * -ENOMEM: failed to enable an lun for OAS operations
3262 * -EPERM: OAS is not enabled
3265 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3266 uint8_t tgt_wwpn[], uint64_t lun,
3267 uint32_t oas_state, uint8_t pri)
3272 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3278 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3279 * @dev: class device that is converted into a Scsi_host.
3280 * @attr: device attribute, not used.
3281 * @buf: buffer for passing information.
3283 * This routine returns a lun enabled for OAS each time the function
3287 * SUCCESS: size of formatted string.
3288 * -EFAULT: target or vport wwpn was not set properly.
3289 * -EPERM: oas is not enabled.
3292 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3295 struct Scsi_Host *shost = class_to_shost(dev);
3296 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3304 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3305 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3308 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3309 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3312 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3313 phba->cfg_oas_tgt_wwpn,
3314 &phba->cfg_oas_lun_status,
3315 &phba->cfg_oas_priority);
3316 if (oas_lun != NOT_OAS_ENABLED_LUN)
3317 phba->cfg_oas_flags |= OAS_LUN_VALID;
3319 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3325 * lpfc_oas_lun_store - Sets the OAS state for lun
3326 * @dev: class device that is converted into a Scsi_host.
3327 * @attr: device attribute, not used.
3328 * @buf: buffer for passing information.
3330 * This function sets the OAS state for lun. Before this function is called,
3331 * the vport wwpn, target wwpn, and oas state need to be set.
3334 * SUCCESS: size of formatted string.
3335 * -EFAULT: target or vport wwpn was not set properly.
3336 * -EPERM: oas is not enabled.
3337 * size of formatted string.
3340 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3341 const char *buf, size_t count)
3343 struct Scsi_Host *shost = class_to_shost(dev);
3344 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3352 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3355 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3358 if (!isdigit(buf[0]))
3361 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3364 pri = phba->cfg_oas_priority;
3366 pri = phba->cfg_XLanePriority;
3368 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3369 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3370 "priority 0x%x with oas state %d\n",
3371 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3372 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3373 pri, phba->cfg_oas_lun_state);
3375 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3376 phba->cfg_oas_tgt_wwpn, scsi_lun,
3377 phba->cfg_oas_lun_state, pri);
3383 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3384 lpfc_oas_lun_show, lpfc_oas_lun_store);
3386 int lpfc_enable_nvmet_cnt;
3387 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3388 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3389 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3390 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3391 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3393 static int lpfc_poll = 0;
3394 module_param(lpfc_poll, int, S_IRUGO);
3395 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3397 " 1 - poll with interrupts enabled"
3398 " 3 - poll and disable FCP ring interrupts");
3400 static DEVICE_ATTR_RW(lpfc_poll);
3402 int lpfc_no_hba_reset_cnt;
3403 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3404 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3405 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3406 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3408 LPFC_ATTR(sli_mode, 0, 0, 3,
3409 "SLI mode selector:"
3410 " 0 - auto (SLI-3 if supported),"
3411 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3412 " 3 - select SLI-3");
3414 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3415 "Enable NPIV functionality");
3417 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3418 "FCF Fast failover=1 Priority failover=2");
3421 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3422 # 0x0 = disabled, XRI/OXID use not tracked.
3423 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3424 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3426 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3427 "Enable RRQ functionality");
3430 # lpfc_suppress_link_up: Bring link up at initialization
3431 # 0x0 = bring link up (issue MBX_INIT_LINK)
3432 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3433 # 0x2 = never bring up link
3434 # Default value is 0.
3436 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3437 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3438 "Suppress Link Up at initialization");
3440 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3448 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3450 struct Scsi_Host *shost = class_to_shost(dev);
3451 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3453 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3456 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3457 lpfc_iocb_hw_show, NULL);
3459 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3461 struct Scsi_Host *shost = class_to_shost(dev);
3462 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3463 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3465 return snprintf(buf, PAGE_SIZE, "%d\n",
3466 pring ? pring->txq_max : 0);
3469 static DEVICE_ATTR(txq_hw, S_IRUGO,
3470 lpfc_txq_hw_show, NULL);
3472 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3475 struct Scsi_Host *shost = class_to_shost(dev);
3476 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3477 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3479 return snprintf(buf, PAGE_SIZE, "%d\n",
3480 pring ? pring->txcmplq_max : 0);
3483 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3484 lpfc_txcmplq_hw_show, NULL);
3486 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3487 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3490 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3491 # until the timer expires. Value range is [0,255]. Default value is 30.
3493 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3494 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3495 module_param(lpfc_nodev_tmo, int, 0);
3496 MODULE_PARM_DESC(lpfc_nodev_tmo,
3497 "Seconds driver will hold I/O waiting "
3498 "for a device to come back");
3501 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3502 * @dev: class converted to a Scsi_host structure.
3503 * @attr: device attribute, not used.
3504 * @buf: on return contains the dev loss timeout in decimal.
3506 * Returns: size of formatted string.
3509 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3512 struct Scsi_Host *shost = class_to_shost(dev);
3513 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3515 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3519 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3520 * @vport: lpfc vport structure pointer.
3521 * @val: contains the nodev timeout value.
3524 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3525 * a kernel error message is printed and zero is returned.
3526 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3527 * Otherwise nodev tmo is set to the default value.
3530 * zero if already set or if val is in range
3531 * -EINVAL val out of range
3534 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3536 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3537 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3538 if (val != LPFC_DEF_DEVLOSS_TMO)
3539 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3540 "0407 Ignoring lpfc_nodev_tmo module "
3541 "parameter because lpfc_devloss_tmo "
3546 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3547 vport->cfg_nodev_tmo = val;
3548 vport->cfg_devloss_tmo = val;
3551 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3552 "0400 lpfc_nodev_tmo attribute cannot be set to"
3553 " %d, allowed range is [%d, %d]\n",
3554 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3555 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3560 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3561 * @vport: lpfc vport structure pointer.
3564 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3567 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3569 struct Scsi_Host *shost;
3570 struct lpfc_nodelist *ndlp;
3571 #if (IS_ENABLED(CONFIG_NVME_FC))
3572 struct lpfc_nvme_rport *rport;
3573 struct nvme_fc_remote_port *remoteport = NULL;
3576 shost = lpfc_shost_from_vport(vport);
3577 spin_lock_irq(shost->host_lock);
3578 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3579 if (!NLP_CHK_NODE_ACT(ndlp))
3582 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3583 #if (IS_ENABLED(CONFIG_NVME_FC))
3584 spin_lock(&vport->phba->hbalock);
3585 rport = lpfc_ndlp_get_nrport(ndlp);
3587 remoteport = rport->remoteport;
3588 spin_unlock(&vport->phba->hbalock);
3590 nvme_fc_set_remoteport_devloss(rport->remoteport,
3591 vport->cfg_devloss_tmo);
3594 spin_unlock_irq(shost->host_lock);
3598 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3599 * @vport: lpfc vport structure pointer.
3600 * @val: contains the tmo value.
3603 * If the devloss tmo is already set or the vport dev loss tmo has changed
3604 * then a kernel error message is printed and zero is returned.
3605 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3606 * Otherwise nodev tmo is set to the default value.
3609 * zero if already set or if val is in range
3610 * -EINVAL val out of range
3613 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3615 if (vport->dev_loss_tmo_changed ||
3616 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3617 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3618 "0401 Ignoring change to lpfc_nodev_tmo "
3619 "because lpfc_devloss_tmo is set.\n");
3622 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3623 vport->cfg_nodev_tmo = val;
3624 vport->cfg_devloss_tmo = val;
3626 * For compat: set the fc_host dev loss so new rports
3627 * will get the value.
3629 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3630 lpfc_update_rport_devloss_tmo(vport);
3633 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3634 "0403 lpfc_nodev_tmo attribute cannot be set to "
3635 "%d, allowed range is [%d, %d]\n",
3636 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3640 lpfc_vport_param_store(nodev_tmo)
3642 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3645 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3646 # disappear until the timer expires. Value range is [0,255]. Default
3649 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3650 MODULE_PARM_DESC(lpfc_devloss_tmo,
3651 "Seconds driver will hold I/O waiting "
3652 "for a device to come back");
3653 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3654 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3655 lpfc_vport_param_show(devloss_tmo)
3658 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3659 * @vport: lpfc vport structure pointer.
3660 * @val: contains the tmo value.
3663 * If val is in a valid range then set the vport nodev tmo,
3664 * devloss tmo, also set the vport dev loss tmo changed flag.
3665 * Else a kernel error message is printed.
3668 * zero if val is in range
3669 * -EINVAL val out of range
3672 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3674 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3675 vport->cfg_nodev_tmo = val;
3676 vport->cfg_devloss_tmo = val;
3677 vport->dev_loss_tmo_changed = 1;
3678 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3679 lpfc_update_rport_devloss_tmo(vport);
3683 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3684 "0404 lpfc_devloss_tmo attribute cannot be set to "
3685 "%d, allowed range is [%d, %d]\n",
3686 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3690 lpfc_vport_param_store(devloss_tmo)
3691 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3694 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3695 * lpfc_suppress_rsp = 0 Disable
3696 * lpfc_suppress_rsp = 1 Enable (default)
3699 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3700 "Enable suppress rsp feature is firmware supports it");
3703 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3704 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3705 * lpfc_nvmet_mrq = 1 use a single RQ pair
3706 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3709 LPFC_ATTR_R(nvmet_mrq,
3710 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3711 "Specify number of RQ pairs for processing NVMET cmds");
3714 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3715 * to each NVMET RQ. Range 64 to 2048, default is 512.
3717 LPFC_ATTR_R(nvmet_mrq_post,
3718 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3719 LPFC_NVMET_RQE_DEF_COUNT,
3720 "Specify number of RQ buffers to initially post");
3723 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3724 * Supported Values: 1 - register just FCP
3725 * 3 - register both FCP and NVME
3726 * Supported values are [1,3]. Default value is 1
3728 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3729 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3730 "Enable FC4 Protocol support - FCP / NVME");
3733 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3734 # deluged with LOTS of information.
3735 # You can set a bit mask to record specific types of verbose messages:
3736 # See lpfc_logmsh.h for definitions.
3738 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3739 "Verbose logging bit-mask");
3742 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3743 # objects that have been registered with the nameserver after login.
3745 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3746 "Deregister nameserver objects before LOGO");
3749 # lun_queue_depth: This parameter is used to limit the number of outstanding
3750 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3751 # If this parameter value is greater than 1/8th the maximum number of exchanges
3752 # supported by the HBA port, then the lun queue depth will be reduced to
3753 # 1/8th the maximum number of exchanges.
3755 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3756 "Max number of FCP commands we can queue to a specific LUN");
3759 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3760 # commands per target port. Value range is [10,65535]. Default value is 65535.
3762 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3763 module_param(lpfc_tgt_queue_depth, uint, 0444);
3764 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3765 lpfc_vport_param_show(tgt_queue_depth);
3766 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3767 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3770 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3771 * @phba: pointer the the adapter structure.
3772 * @val: integer attribute value.
3774 * Description: Sets the parameter to the new value.
3778 * -EINVAL if val is invalid
3781 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3783 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3784 struct lpfc_nodelist *ndlp;
3786 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3789 if (val == vport->cfg_tgt_queue_depth)
3792 spin_lock_irq(shost->host_lock);
3793 vport->cfg_tgt_queue_depth = val;
3795 /* Next loop thru nodelist and change cmd_qdepth */
3796 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3797 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3799 spin_unlock_irq(shost->host_lock);
3803 lpfc_vport_param_store(tgt_queue_depth);
3804 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3807 # hba_queue_depth: This parameter is used to limit the number of outstanding
3808 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3809 # value is greater than the maximum number of exchanges supported by the HBA,
3810 # then maximum number of exchanges supported by the HBA is used to determine
3811 # the hba_queue_depth.
3813 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3814 "Max number of FCP commands we can queue to a lpfc HBA");
3817 # peer_port_login: This parameter allows/prevents logins
3818 # between peer ports hosted on the same physical port.
3819 # When this parameter is set 0 peer ports of same physical port
3820 # are not allowed to login to each other.
3821 # When this parameter is set 1 peer ports of same physical port
3822 # are allowed to login to each other.
3823 # Default value of this parameter is 0.
3825 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3826 "Allow peer ports on the same physical port to login to each "
3830 # restrict_login: This parameter allows/prevents logins
3831 # between Virtual Ports and remote initiators.
3832 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3833 # other initiators and will attempt to PLOGI all remote ports.
3834 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3835 # remote ports and will not attempt to PLOGI to other initiators.
3836 # This parameter does not restrict to the physical port.
3837 # This parameter does not restrict logins to Fabric resident remote ports.
3838 # Default value of this parameter is 1.
3840 static int lpfc_restrict_login = 1;
3841 module_param(lpfc_restrict_login, int, S_IRUGO);
3842 MODULE_PARM_DESC(lpfc_restrict_login,
3843 "Restrict virtual ports login to remote initiators.");
3844 lpfc_vport_param_show(restrict_login);
3847 * lpfc_restrict_login_init - Set the vport restrict login flag
3848 * @vport: lpfc vport structure pointer.
3849 * @val: contains the restrict login value.
3852 * If val is not in a valid range then log a kernel error message and set
3853 * the vport restrict login to one.
3854 * If the port type is physical clear the restrict login flag and return.
3855 * Else set the restrict login flag to val.
3858 * zero if val is in range
3859 * -EINVAL val out of range
3862 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3864 if (val < 0 || val > 1) {
3865 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3866 "0422 lpfc_restrict_login attribute cannot "
3867 "be set to %d, allowed range is [0, 1]\n",
3869 vport->cfg_restrict_login = 1;
3872 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3873 vport->cfg_restrict_login = 0;
3876 vport->cfg_restrict_login = val;
3881 * lpfc_restrict_login_set - Set the vport restrict login flag
3882 * @vport: lpfc vport structure pointer.
3883 * @val: contains the restrict login value.
3886 * If val is not in a valid range then log a kernel error message and set
3887 * the vport restrict login to one.
3888 * If the port type is physical and the val is not zero log a kernel
3889 * error message, clear the restrict login flag and return zero.
3890 * Else set the restrict login flag to val.
3893 * zero if val is in range
3894 * -EINVAL val out of range
3897 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3899 if (val < 0 || val > 1) {
3900 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3901 "0425 lpfc_restrict_login attribute cannot "
3902 "be set to %d, allowed range is [0, 1]\n",
3904 vport->cfg_restrict_login = 1;
3907 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3908 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3909 "0468 lpfc_restrict_login must be 0 for "
3910 "Physical ports.\n");
3911 vport->cfg_restrict_login = 0;
3914 vport->cfg_restrict_login = val;
3917 lpfc_vport_param_store(restrict_login);
3918 static DEVICE_ATTR_RW(lpfc_restrict_login);
3921 # Some disk devices have a "select ID" or "select Target" capability.
3922 # From a protocol standpoint "select ID" usually means select the
3923 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3924 # annex" which contains a table that maps a "select ID" (a number
3925 # between 0 and 7F) to an ALPA. By default, for compatibility with
3926 # older drivers, the lpfc driver scans this table from low ALPA to high
3929 # Turning on the scan-down variable (on = 1, off = 0) will
3930 # cause the lpfc driver to use an inverted table, effectively
3931 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3933 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3934 # and will not work across a fabric. Also this parameter will take
3935 # effect only in the case when ALPA map is not available.)
3937 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3938 "Start scanning for devices from highest ALPA to lowest");
3941 # lpfc_topology: link topology for init link
3942 # 0x0 = attempt loop mode then point-to-point
3943 # 0x01 = internal loopback mode
3944 # 0x02 = attempt point-to-point mode only
3945 # 0x04 = attempt loop mode only
3946 # 0x06 = attempt point-to-point mode then loop
3947 # Set point-to-point mode if you want to run as an N_Port.
3948 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3949 # Default value is 0.
3951 LPFC_ATTR(topology, 0, 0, 6,
3952 "Select Fibre Channel topology");
3955 * lpfc_topology_set - Set the adapters topology field
3956 * @phba: lpfc_hba pointer.
3957 * @val: topology value.
3960 * If val is in a valid range then set the adapter's topology field and
3961 * issue a lip; if the lip fails reset the topology to the old value.
3963 * If the value is not in range log a kernel error message and return an error.
3966 * zero if val is in range and lip okay
3967 * non-zero return value from lpfc_issue_lip()
3968 * -EINVAL val out of range
3971 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3972 const char *buf, size_t count)
3974 struct Scsi_Host *shost = class_to_shost(dev);
3975 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3976 struct lpfc_hba *phba = vport->phba;
3979 const char *val_buf = buf;
3983 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3985 val_buf = &buf[strlen("nolip ")];
3988 if (!isdigit(val_buf[0]))
3990 if (sscanf(val_buf, "%i", &val) != 1)
3993 if (val >= 0 && val <= 6) {
3994 prev_val = phba->cfg_topology;
3995 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3997 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3998 "3113 Loop mode not supported at speed %d\n",
4002 if ((phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
4003 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC) &&
4005 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4006 "3114 Loop mode not supported\n");
4009 phba->cfg_topology = val;
4013 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4014 "3054 lpfc_topology changed from %d to %d\n",
4016 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4017 phba->fc_topology_changed = 1;
4018 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4020 phba->cfg_topology = prev_val;
4025 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4026 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4027 "allowed range is [0, 6]\n",
4032 lpfc_param_show(topology)
4033 static DEVICE_ATTR_RW(lpfc_topology);
4036 * lpfc_static_vport_show: Read callback function for
4037 * lpfc_static_vport sysfs file.
4038 * @dev: Pointer to class device object.
4039 * @attr: device attribute structure.
4040 * @buf: Data buffer.
4042 * This function is the read call back function for
4043 * lpfc_static_vport sysfs file. The lpfc_static_vport
4044 * sysfs file report the mageability of the vport.
4047 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4050 struct Scsi_Host *shost = class_to_shost(dev);
4051 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4052 if (vport->vport_flag & STATIC_VPORT)
4053 sprintf(buf, "1\n");
4055 sprintf(buf, "0\n");
4061 * Sysfs attribute to control the statistical data collection.
4063 static DEVICE_ATTR_RO(lpfc_static_vport);
4066 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
4067 * @dev: Pointer to class device.
4068 * @buf: Data buffer.
4069 * @count: Size of the data buffer.
4071 * This function get called when a user write to the lpfc_stat_data_ctrl
4072 * sysfs file. This function parse the command written to the sysfs file
4073 * and take appropriate action. These commands are used for controlling
4074 * driver statistical data collection.
4075 * Following are the command this function handles.
4077 * setbucket <bucket_type> <base> <step>
4078 * = Set the latency buckets.
4079 * destroybucket = destroy all the buckets.
4080 * start = start data collection
4081 * stop = stop data collection
4082 * reset = reset the collected data
4085 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4086 const char *buf, size_t count)
4088 struct Scsi_Host *shost = class_to_shost(dev);
4089 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4090 struct lpfc_hba *phba = vport->phba;
4091 #define LPFC_MAX_DATA_CTRL_LEN 1024
4092 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4094 char *str_ptr, *token;
4095 struct lpfc_vport **vports;
4096 struct Scsi_Host *v_shost;
4097 char *bucket_type_str, *base_str, *step_str;
4098 unsigned long base, step, bucket_type;
4100 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
4101 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
4104 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
4105 str_ptr = &bucket_data[0];
4106 /* Ignore this token - this is command token */
4107 token = strsep(&str_ptr, "\t ");
4111 bucket_type_str = strsep(&str_ptr, "\t ");
4112 if (!bucket_type_str)
4115 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4116 bucket_type = LPFC_LINEAR_BUCKET;
4117 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4118 bucket_type = LPFC_POWER2_BUCKET;
4122 base_str = strsep(&str_ptr, "\t ");
4125 base = simple_strtoul(base_str, NULL, 0);
4127 step_str = strsep(&str_ptr, "\t ");
4130 step = simple_strtoul(step_str, NULL, 0);
4134 /* Block the data collection for every vport */
4135 vports = lpfc_create_vport_work_array(phba);
4139 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4140 v_shost = lpfc_shost_from_vport(vports[i]);
4141 spin_lock_irq(v_shost->host_lock);
4142 /* Block and reset data collection */
4143 vports[i]->stat_data_blocked = 1;
4144 if (vports[i]->stat_data_enabled)
4145 lpfc_vport_reset_stat_data(vports[i]);
4146 spin_unlock_irq(v_shost->host_lock);
4149 /* Set the bucket attributes */
4150 phba->bucket_type = bucket_type;
4151 phba->bucket_base = base;
4152 phba->bucket_step = step;
4154 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4155 v_shost = lpfc_shost_from_vport(vports[i]);
4157 /* Unblock data collection */
4158 spin_lock_irq(v_shost->host_lock);
4159 vports[i]->stat_data_blocked = 0;
4160 spin_unlock_irq(v_shost->host_lock);
4162 lpfc_destroy_vport_work_array(phba, vports);
4166 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4167 vports = lpfc_create_vport_work_array(phba);
4171 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4172 v_shost = lpfc_shost_from_vport(vports[i]);
4173 spin_lock_irq(shost->host_lock);
4174 vports[i]->stat_data_blocked = 1;
4175 lpfc_free_bucket(vport);
4176 vport->stat_data_enabled = 0;
4177 vports[i]->stat_data_blocked = 0;
4178 spin_unlock_irq(shost->host_lock);
4180 lpfc_destroy_vport_work_array(phba, vports);
4181 phba->bucket_type = LPFC_NO_BUCKET;
4182 phba->bucket_base = 0;
4183 phba->bucket_step = 0;
4187 if (!strncmp(buf, "start", strlen("start"))) {
4188 /* If no buckets configured return error */
4189 if (phba->bucket_type == LPFC_NO_BUCKET)
4191 spin_lock_irq(shost->host_lock);
4192 if (vport->stat_data_enabled) {
4193 spin_unlock_irq(shost->host_lock);
4196 lpfc_alloc_bucket(vport);
4197 vport->stat_data_enabled = 1;
4198 spin_unlock_irq(shost->host_lock);
4202 if (!strncmp(buf, "stop", strlen("stop"))) {
4203 spin_lock_irq(shost->host_lock);
4204 if (vport->stat_data_enabled == 0) {
4205 spin_unlock_irq(shost->host_lock);
4208 lpfc_free_bucket(vport);
4209 vport->stat_data_enabled = 0;
4210 spin_unlock_irq(shost->host_lock);
4214 if (!strncmp(buf, "reset", strlen("reset"))) {
4215 if ((phba->bucket_type == LPFC_NO_BUCKET)
4216 || !vport->stat_data_enabled)
4218 spin_lock_irq(shost->host_lock);
4219 vport->stat_data_blocked = 1;
4220 lpfc_vport_reset_stat_data(vport);
4221 vport->stat_data_blocked = 0;
4222 spin_unlock_irq(shost->host_lock);
4230 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
4231 * @dev: Pointer to class device object.
4232 * @buf: Data buffer.
4234 * This function is the read call back function for
4235 * lpfc_stat_data_ctrl sysfs file. This function report the
4236 * current statistical data collection state.
4239 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4242 struct Scsi_Host *shost = class_to_shost(dev);
4243 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4244 struct lpfc_hba *phba = vport->phba;
4248 unsigned long bucket_value;
4250 switch (phba->bucket_type) {
4251 case LPFC_LINEAR_BUCKET:
4252 bucket_type = "linear";
4254 case LPFC_POWER2_BUCKET:
4255 bucket_type = "power2";
4258 bucket_type = "No Bucket";
4262 sprintf(&buf[index], "Statistical Data enabled :%d, "
4263 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4264 " Bucket step :%d\nLatency Ranges :",
4265 vport->stat_data_enabled, vport->stat_data_blocked,
4266 bucket_type, phba->bucket_base, phba->bucket_step);
4267 index = strlen(buf);
4268 if (phba->bucket_type != LPFC_NO_BUCKET) {
4269 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4270 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4271 bucket_value = phba->bucket_base +
4272 phba->bucket_step * i;
4274 bucket_value = phba->bucket_base +
4275 (1 << i) * phba->bucket_step;
4277 if (index + 10 > PAGE_SIZE)
4279 sprintf(&buf[index], "%08ld ", bucket_value);
4280 index = strlen(buf);
4283 sprintf(&buf[index], "\n");
4288 * Sysfs attribute to control the statistical data collection.
4290 static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
4293 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4297 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4300 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4301 #define MAX_STAT_DATA_SIZE_PER_TARGET \
4302 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4306 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
4308 * @kobj: Pointer to the kernel object
4309 * @bin_attr: Attribute object
4310 * @buff: Buffer pointer
4312 * @count: Buffer size
4314 * This function is the read call back function for lpfc_drvr_stat_data
4315 * sysfs file. This function export the statistical data to user
4319 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4320 struct bin_attribute *bin_attr,
4321 char *buf, loff_t off, size_t count)
4323 struct device *dev = container_of(kobj, struct device,
4325 struct Scsi_Host *shost = class_to_shost(dev);
4326 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4327 struct lpfc_hba *phba = vport->phba;
4328 int i = 0, index = 0;
4329 unsigned long nport_index;
4330 struct lpfc_nodelist *ndlp = NULL;
4331 nport_index = (unsigned long)off /
4332 MAX_STAT_DATA_SIZE_PER_TARGET;
4334 if (!vport->stat_data_enabled || vport->stat_data_blocked
4335 || (phba->bucket_type == LPFC_NO_BUCKET))
4338 spin_lock_irq(shost->host_lock);
4339 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4340 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4343 if (nport_index > 0) {
4348 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4352 if (!ndlp->lat_data)
4356 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4357 ndlp->nlp_portname.u.wwn[0],
4358 ndlp->nlp_portname.u.wwn[1],
4359 ndlp->nlp_portname.u.wwn[2],
4360 ndlp->nlp_portname.u.wwn[3],
4361 ndlp->nlp_portname.u.wwn[4],
4362 ndlp->nlp_portname.u.wwn[5],
4363 ndlp->nlp_portname.u.wwn[6],
4364 ndlp->nlp_portname.u.wwn[7]);
4366 index = strlen(buf);
4368 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4369 sprintf(&buf[index], "%010u,",
4370 ndlp->lat_data[i].cmd_count);
4371 index = strlen(buf);
4373 sprintf(&buf[index], "\n");
4374 index = strlen(buf);
4376 spin_unlock_irq(shost->host_lock);
4380 static struct bin_attribute sysfs_drvr_stat_data_attr = {
4382 .name = "lpfc_drvr_stat_data",
4385 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4386 .read = sysfs_drvr_stat_data_read,
4391 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4393 # Value range is [0,16]. Default value is 0.
4396 * lpfc_link_speed_set - Set the adapters link speed
4397 * @phba: lpfc_hba pointer.
4398 * @val: link speed value.
4401 * If val is in a valid range then set the adapter's link speed field and
4402 * issue a lip; if the lip fails reset the link speed to the old value.
4405 * If the value is not in range log a kernel error message and return an error.
4408 * zero if val is in range and lip okay.
4409 * non-zero return value from lpfc_issue_lip()
4410 * -EINVAL val out of range
4413 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4414 const char *buf, size_t count)
4416 struct Scsi_Host *shost = class_to_shost(dev);
4417 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4418 struct lpfc_hba *phba = vport->phba;
4419 int val = LPFC_USER_LINK_SPEED_AUTO;
4421 const char *val_buf = buf;
4423 uint32_t prev_val, if_type;
4425 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4426 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4427 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4430 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4432 val_buf = &buf[strlen("nolip ")];
4435 if (!isdigit(val_buf[0]))
4437 if (sscanf(val_buf, "%i", &val) != 1)
4440 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4441 "3055 lpfc_link_speed changed from %d to %d %s\n",
4442 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4444 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4445 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4446 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4447 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4448 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4449 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4450 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4451 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4452 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4453 "2879 lpfc_link_speed attribute cannot be set "
4454 "to %d. Speed is not supported by this port.\n",
4458 if (val >= LPFC_USER_LINK_SPEED_16G &&
4459 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4460 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4461 "3112 lpfc_link_speed attribute cannot be set "
4462 "to %d. Speed is not supported in loop mode.\n",
4468 case LPFC_USER_LINK_SPEED_AUTO:
4469 case LPFC_USER_LINK_SPEED_1G:
4470 case LPFC_USER_LINK_SPEED_2G:
4471 case LPFC_USER_LINK_SPEED_4G:
4472 case LPFC_USER_LINK_SPEED_8G:
4473 case LPFC_USER_LINK_SPEED_16G:
4474 case LPFC_USER_LINK_SPEED_32G:
4475 case LPFC_USER_LINK_SPEED_64G:
4476 prev_val = phba->cfg_link_speed;
4477 phba->cfg_link_speed = val;
4481 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4483 phba->cfg_link_speed = prev_val;
4491 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4492 "0469 lpfc_link_speed attribute cannot be set to %d, "
4493 "allowed values are [%s]\n",
4494 val, LPFC_LINK_SPEED_STRING);
4499 static int lpfc_link_speed = 0;
4500 module_param(lpfc_link_speed, int, S_IRUGO);
4501 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4502 lpfc_param_show(link_speed)
4505 * lpfc_link_speed_init - Set the adapters link speed
4506 * @phba: lpfc_hba pointer.
4507 * @val: link speed value.
4510 * If val is in a valid range then set the adapter's link speed field.
4513 * If the value is not in range log a kernel error message, clear the link
4514 * speed and return an error.
4517 * zero if val saved.
4518 * -EINVAL val out of range
4521 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4523 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4524 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4525 "3111 lpfc_link_speed of %d cannot "
4526 "support loop mode, setting topology to default.\n",
4528 phba->cfg_topology = 0;
4532 case LPFC_USER_LINK_SPEED_AUTO:
4533 case LPFC_USER_LINK_SPEED_1G:
4534 case LPFC_USER_LINK_SPEED_2G:
4535 case LPFC_USER_LINK_SPEED_4G:
4536 case LPFC_USER_LINK_SPEED_8G:
4537 case LPFC_USER_LINK_SPEED_16G:
4538 case LPFC_USER_LINK_SPEED_32G:
4539 case LPFC_USER_LINK_SPEED_64G:
4540 phba->cfg_link_speed = val;
4543 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4544 "0405 lpfc_link_speed attribute cannot "
4545 "be set to %d, allowed values are "
4546 "["LPFC_LINK_SPEED_STRING"]\n", val);
4547 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4552 static DEVICE_ATTR_RW(lpfc_link_speed);
4555 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4556 # 0 = aer disabled or not supported
4557 # 1 = aer supported and enabled (default)
4558 # Value range is [0,1]. Default value is 1.
4560 LPFC_ATTR(aer_support, 1, 0, 1,
4561 "Enable PCIe device AER support");
4562 lpfc_param_show(aer_support)
4565 * lpfc_aer_support_store - Set the adapter for aer support
4567 * @dev: class device that is converted into a Scsi_host.
4568 * @attr: device attribute, not used.
4569 * @buf: containing enable or disable aer flag.
4570 * @count: unused variable.
4573 * If the val is 1 and currently the device's AER capability was not
4574 * enabled, invoke the kernel's enable AER helper routine, trying to
4575 * enable the device's AER capability. If the helper routine enabling
4576 * AER returns success, update the device's cfg_aer_support flag to
4577 * indicate AER is supported by the device; otherwise, if the device
4578 * AER capability is already enabled to support AER, then do nothing.
4580 * If the val is 0 and currently the device's AER support was enabled,
4581 * invoke the kernel's disable AER helper routine. After that, update
4582 * the device's cfg_aer_support flag to indicate AER is not supported
4583 * by the device; otherwise, if the device AER capability is already
4584 * disabled from supporting AER, then do nothing.
4587 * length of the buf on success if val is in range the intended mode
4589 * -EINVAL if val out of range or intended mode is not supported.
4592 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4593 const char *buf, size_t count)
4595 struct Scsi_Host *shost = class_to_shost(dev);
4596 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4597 struct lpfc_hba *phba = vport->phba;
4598 int val = 0, rc = -EINVAL;
4600 if (!isdigit(buf[0]))
4602 if (sscanf(buf, "%i", &val) != 1)
4607 if (phba->hba_flag & HBA_AER_ENABLED) {
4608 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4610 spin_lock_irq(&phba->hbalock);
4611 phba->hba_flag &= ~HBA_AER_ENABLED;
4612 spin_unlock_irq(&phba->hbalock);
4613 phba->cfg_aer_support = 0;
4618 phba->cfg_aer_support = 0;
4623 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4624 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4626 spin_lock_irq(&phba->hbalock);
4627 phba->hba_flag |= HBA_AER_ENABLED;
4628 spin_unlock_irq(&phba->hbalock);
4629 phba->cfg_aer_support = 1;
4634 phba->cfg_aer_support = 1;
4645 static DEVICE_ATTR_RW(lpfc_aer_support);
4648 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4649 * @dev: class device that is converted into a Scsi_host.
4650 * @attr: device attribute, not used.
4651 * @buf: containing flag 1 for aer cleanup state.
4652 * @count: unused variable.
4655 * If the @buf contains 1 and the device currently has the AER support
4656 * enabled, then invokes the kernel AER helper routine
4657 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4658 * error status register.
4663 * -EINVAL if the buf does not contain the 1 or the device is not currently
4664 * enabled with the AER support.
4667 lpfc_aer_cleanup_state(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;
4675 if (!isdigit(buf[0]))
4677 if (sscanf(buf, "%i", &val) != 1)
4682 if (phba->hba_flag & HBA_AER_ENABLED)
4683 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4691 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4692 lpfc_aer_cleanup_state);
4695 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4697 * @dev: class device that is converted into a Scsi_host.
4698 * @attr: device attribute, not used.
4699 * @buf: containing the string the number of vfs to be enabled.
4700 * @count: unused variable.
4703 * When this api is called either through user sysfs, the driver shall
4704 * try to enable or disable SR-IOV virtual functions according to the
4707 * If zero virtual function has been enabled to the physical function,
4708 * the driver shall invoke the pci enable virtual function api trying
4709 * to enable the virtual functions. If the nr_vfn provided is greater
4710 * than the maximum supported, the maximum virtual function number will
4711 * be used for invoking the api; otherwise, the nr_vfn provided shall
4712 * be used for invoking the api. If the api call returned success, the
4713 * actual number of virtual functions enabled will be set to the driver
4714 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4715 * cfg_sriov_nr_virtfn remains zero.
4717 * If none-zero virtual functions have already been enabled to the
4718 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4719 * -EINVAL will be returned and the driver does nothing;
4721 * If the nr_vfn provided is zero and none-zero virtual functions have
4722 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4723 * disabling virtual function api shall be invoded to disable all the
4724 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4725 * zero. Otherwise, if zero virtual function has been enabled, do
4729 * length of the buf on success if val is in range the intended mode
4731 * -EINVAL if val out of range or intended mode is not supported.
4734 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4735 const char *buf, size_t count)
4737 struct Scsi_Host *shost = class_to_shost(dev);
4738 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4739 struct lpfc_hba *phba = vport->phba;
4740 struct pci_dev *pdev = phba->pcidev;
4741 int val = 0, rc = -EINVAL;
4743 /* Sanity check on user data */
4744 if (!isdigit(buf[0]))
4746 if (sscanf(buf, "%i", &val) != 1)
4751 /* Request disabling virtual functions */
4753 if (phba->cfg_sriov_nr_virtfn > 0) {
4754 pci_disable_sriov(pdev);
4755 phba->cfg_sriov_nr_virtfn = 0;
4760 /* Request enabling virtual functions */
4761 if (phba->cfg_sriov_nr_virtfn > 0) {
4762 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4763 "3018 There are %d virtual functions "
4764 "enabled on physical function.\n",
4765 phba->cfg_sriov_nr_virtfn);
4769 if (val <= LPFC_MAX_VFN_PER_PFN)
4770 phba->cfg_sriov_nr_virtfn = val;
4772 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4773 "3019 Enabling %d virtual functions is not "
4778 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4780 phba->cfg_sriov_nr_virtfn = 0;
4788 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4789 "Enable PCIe device SR-IOV virtual fn");
4791 lpfc_param_show(sriov_nr_virtfn)
4792 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4795 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4797 * @dev: class device that is converted into a Scsi_host.
4798 * @attr: device attribute, not used.
4799 * @buf: containing the string the number of vfs to be enabled.
4800 * @count: unused variable.
4805 * length of the buf on success if val is in range the intended mode
4807 * -EINVAL if val out of range or intended mode is not supported.
4810 lpfc_request_firmware_upgrade_store(struct device *dev,
4811 struct device_attribute *attr,
4812 const char *buf, size_t count)
4814 struct Scsi_Host *shost = class_to_shost(dev);
4815 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4816 struct lpfc_hba *phba = vport->phba;
4817 int val = 0, rc = -EINVAL;
4819 /* Sanity check on user data */
4820 if (!isdigit(buf[0]))
4822 if (sscanf(buf, "%i", &val) != 1)
4827 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4835 static int lpfc_req_fw_upgrade;
4836 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4837 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4838 lpfc_param_show(request_firmware_upgrade)
4841 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4842 * @phba: lpfc_hba pointer.
4846 * Set the initial Linux generic firmware upgrade enable or disable flag.
4849 * zero if val saved.
4850 * -EINVAL val out of range
4853 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4855 if (val >= 0 && val <= 1) {
4856 phba->cfg_request_firmware_upgrade = val;
4861 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4862 lpfc_request_firmware_upgrade_show,
4863 lpfc_request_firmware_upgrade_store);
4866 * lpfc_fcp_imax_store
4868 * @dev: class device that is converted into a Scsi_host.
4869 * @attr: device attribute, not used.
4870 * @buf: string with the number of fast-path FCP interrupts per second.
4871 * @count: unused variable.
4874 * If val is in a valid range [636,651042], then set the adapter's
4875 * maximum number of fast-path FCP interrupts per second.
4878 * length of the buf on success if val is in range the intended mode
4880 * -EINVAL if val out of range or intended mode is not supported.
4883 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4884 const char *buf, size_t count)
4886 struct Scsi_Host *shost = class_to_shost(dev);
4887 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4888 struct lpfc_hba *phba = vport->phba;
4891 /* fcp_imax is only valid for SLI4 */
4892 if (phba->sli_rev != LPFC_SLI_REV4)
4895 /* Sanity check on user data */
4896 if (!isdigit(buf[0]))
4898 if (sscanf(buf, "%i", &val) != 1)
4902 * Value range for the HBA is [5000,5000000]
4903 * The value for each EQ depends on how many EQs are configured.
4906 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4909 phba->cfg_fcp_imax = (uint32_t)val;
4910 phba->initial_imax = phba->cfg_fcp_imax;
4912 for (i = 0; i < phba->cfg_hdw_queue; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4913 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4920 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4923 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4925 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4926 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4927 MODULE_PARM_DESC(lpfc_fcp_imax,
4928 "Set the maximum number of FCP interrupts per second per HBA");
4929 lpfc_param_show(fcp_imax)
4932 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4933 * @phba: lpfc_hba pointer.
4934 * @val: link speed value.
4937 * If val is in a valid range [636,651042], then initialize the adapter's
4938 * maximum number of fast-path FCP interrupts per second.
4941 * zero if val saved.
4942 * -EINVAL val out of range
4945 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4947 if (phba->sli_rev != LPFC_SLI_REV4) {
4948 phba->cfg_fcp_imax = 0;
4952 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4954 phba->cfg_fcp_imax = val;
4958 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4959 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4961 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4966 static DEVICE_ATTR_RW(lpfc_fcp_imax);
4969 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4970 * 0 No auto_imax support
4972 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4973 * the EQ Delay Multiplier, depending on the activity for that EQ.
4974 * Value range [0,1]. Default value is 1.
4976 LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4979 * lpfc_state_show - Display current driver CPU affinity
4980 * @dev: class converted to a Scsi_host structure.
4981 * @attr: device attribute, not used.
4982 * @buf: on return contains text describing the state of the link.
4984 * Returns: size of formatted string.
4987 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4990 struct Scsi_Host *shost = class_to_shost(dev);
4991 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4992 struct lpfc_hba *phba = vport->phba;
4993 struct lpfc_vector_map_info *cpup;
4996 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4997 (phba->intr_type != MSIX))
5000 switch (phba->cfg_fcp_cpu_map) {
5002 len += snprintf(buf + len, PAGE_SIZE-len,
5003 "fcp_cpu_map: No mapping (%d)\n",
5004 phba->cfg_fcp_cpu_map);
5007 len += snprintf(buf + len, PAGE_SIZE-len,
5008 "fcp_cpu_map: HBA centric mapping (%d): "
5010 phba->cfg_fcp_cpu_map,
5011 phba->sli4_hba.num_online_cpu);
5014 len += snprintf(buf + len, PAGE_SIZE-len,
5015 "fcp_cpu_map: Driver centric mapping (%d): "
5017 phba->cfg_fcp_cpu_map,
5018 phba->sli4_hba.num_online_cpu);
5022 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
5023 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5025 /* margin should fit in this and the truncated message */
5026 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
5027 len += snprintf(buf + len, PAGE_SIZE-len,
5028 "CPU %02d io_chan %02d "
5029 "physid %d coreid %d\n",
5030 phba->sli4_hba.curr_disp_cpu,
5031 cpup->channel_id, cpup->phys_id,
5034 len += snprintf(buf + len, PAGE_SIZE-len,
5035 "CPU %02d io_chan %02d "
5036 "physid %d coreid %d IRQ %d\n",
5037 phba->sli4_hba.curr_disp_cpu,
5038 cpup->channel_id, cpup->phys_id,
5039 cpup->core_id, cpup->irq);
5041 phba->sli4_hba.curr_disp_cpu++;
5043 /* display max number of CPUs keeping some margin */
5044 if (phba->sli4_hba.curr_disp_cpu <
5045 phba->sli4_hba.num_present_cpu &&
5046 (len >= (PAGE_SIZE - 64))) {
5047 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
5052 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
5053 phba->sli4_hba.curr_disp_cpu = 0;
5059 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5060 * @dev: class device that is converted into a Scsi_host.
5061 * @attr: device attribute, not used.
5062 * @buf: one or more lpfc_polling_flags values.
5066 * -EINVAL - Not implemented yet.
5069 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5070 const char *buf, size_t count)
5072 int status = -EINVAL;
5077 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5080 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
5081 # 0 - Do not affinitze IRQ vectors
5082 # 1 - Affintize HBA vectors with respect to each HBA
5083 # (start with CPU0 for each HBA)
5084 # 2 - Affintize HBA vectors with respect to the entire driver
5085 # (round robin thru all CPUs across all HBAs)
5087 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
5088 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5089 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5090 "Defines how to map CPUs to IRQ vectors per HBA");
5093 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5094 * @phba: lpfc_hba pointer.
5095 * @val: link speed value.
5098 * If val is in a valid range [0-2], then affinitze the adapter's
5102 * zero if val saved.
5103 * -EINVAL val out of range
5106 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5108 if (phba->sli_rev != LPFC_SLI_REV4) {
5109 phba->cfg_fcp_cpu_map = 0;
5113 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5114 phba->cfg_fcp_cpu_map = val;
5118 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5119 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5121 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
5126 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5129 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5130 # Value range is [2,3]. Default value is 3.
5132 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5133 "Select Fibre Channel class of service for FCP sequences");
5136 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5137 # is [0,1]. Default value is 0.
5139 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
5140 "Use ADISC on rediscovery to authenticate FCP devices");
5143 # lpfc_first_burst_size: First burst size to use on the NPorts
5144 # that support first burst.
5145 # Value range is [0,65536]. Default value is 0.
5147 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5148 "First burst size for Targets that support first burst");
5151 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5152 * When the driver is configured as an NVME target, this value is
5153 * communicated to the NVME initiator in the PRLI response. It is
5154 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5155 * parameters are set and the target is sending the PRLI RSP.
5156 * Parameter supported on physical port only - no NPIV support.
5157 * Value range is [0,65536]. Default value is 0.
5159 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5160 "NVME Target mode first burst size in 512B increments.");
5163 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5164 * For the Initiator (I), enabling this parameter means that an NVMET
5165 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5166 * processed by the initiator for subsequent NVME FCP IO. For the target
5167 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
5168 * driver parameter as the target function's first burst size returned to the
5169 * initiator in the target's NVME PRLI response. Parameter supported on physical
5170 * port only - no NPIV support.
5171 * Value range is [0,1]. Default value is 0 (disabled).
5173 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5174 "Enable First Burst feature on I and T functions.");
5177 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5178 # depth. Default value is 0. When the value of this parameter is zero the
5179 # SCSI command completion time is not used for controlling I/O queue depth. When
5180 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5181 # to limit the I/O completion time to the parameter value.
5182 # The value is set in milliseconds.
5184 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5185 "Use command completion time to control queue depth");
5187 lpfc_vport_param_show(max_scsicmpl_time);
5189 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5191 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5192 struct lpfc_nodelist *ndlp, *next_ndlp;
5194 if (val == vport->cfg_max_scsicmpl_time)
5196 if ((val < 0) || (val > 60000))
5198 vport->cfg_max_scsicmpl_time = val;
5200 spin_lock_irq(shost->host_lock);
5201 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5202 if (!NLP_CHK_NODE_ACT(ndlp))
5204 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5206 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5208 spin_unlock_irq(shost->host_lock);
5211 lpfc_vport_param_store(max_scsicmpl_time);
5212 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5215 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5216 # range is [0,1]. Default value is 0.
5218 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5221 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5222 * range is [0,1]. Default value is 0.
5223 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
5224 * For [1], FCP commands are issued to a Work Queue associated with the
5227 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
5228 * LPFC_FCP_SCHED_BY_CPU == 1
5230 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5231 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5232 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5233 * through WQs will be used.
5235 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
5236 LPFC_FCP_SCHED_ROUND_ROBIN,
5237 LPFC_FCP_SCHED_BY_CPU,
5238 "Determine scheduling algorithm for "
5239 "issuing commands [0] - Round Robin, [1] - Current CPU");
5242 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5243 * range is [0,1]. Default value is 0.
5244 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5245 * For [1], GID_PT is used for NameServer queries after RSCN
5248 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5249 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5250 "Determine algorithm NameServer queries after RSCN "
5251 "[0] - GID_FT, [1] - GID_PT");
5254 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5255 # range is [0,1]. Default value is 0.
5256 # For [0], bus reset issues target reset to ALL devices
5257 # For [1], bus reset issues target reset to non-FCP2 devices
5259 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5260 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5264 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5265 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5266 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5267 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5268 # cr_delay is set to 0.
5270 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5271 "interrupt response is generated");
5273 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5274 "interrupt response is generated");
5277 # lpfc_multi_ring_support: Determines how many rings to spread available
5278 # cmd/rsp IOCB entries across.
5279 # Value range is [1,2]. Default value is 1.
5281 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5282 "SLI rings to spread IOCB entries across");
5285 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5286 # identifies what rctl value to configure the additional ring for.
5287 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5289 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5290 255, "Identifies RCTL for additional ring configuration");
5293 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5294 # identifies what type value to configure the additional ring for.
5295 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5297 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5298 255, "Identifies TYPE for additional ring configuration");
5301 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5302 # 0 = SmartSAN functionality disabled (default)
5303 # 1 = SmartSAN functionality enabled
5304 # This parameter will override the value of lpfc_fdmi_on module parameter.
5305 # Value range is [0,1]. Default value is 0.
5307 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5310 # lpfc_fdmi_on: Controls FDMI support.
5312 # 1 Traditional FDMI support (default)
5313 # Traditional FDMI support means the driver will assume FDMI-2 support;
5314 # however, if that fails, it will fallback to FDMI-1.
5315 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5316 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5318 # Value range [0,1]. Default value is 1.
5320 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5323 # Specifies the maximum number of ELS cmds we can have outstanding (for
5324 # discovery). Value range is [1,64]. Default value = 32.
5326 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5327 "during discovery");
5330 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5331 # will be scanned by the SCSI midlayer when sequential scanning is
5332 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5333 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5334 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5335 # above. The lpfc driver limits the default value to 255 for two reasons.
5336 # As it bounds the sequential scan loop, scanning for thousands of luns
5337 # on a target can take minutes of wall clock time. Additionally,
5338 # there are FC targets, such as JBODs, that only recognize 8-bits of
5339 # LUN ID. When they receive a value greater than 8 bits, they chop off
5340 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5341 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5342 # valid responses at each of the LUN IDs, to believe there are multiple
5343 # devices present, when in fact, there is only 1.
5344 # A customer that is aware of their target behaviors, and the results as
5345 # indicated above, is welcome to increase the lpfc_max_luns value.
5346 # As mentioned, this value is not used by the lpfc driver, only the
5348 # Value range is [0,65535]. Default value is 255.
5349 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5351 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5354 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5355 # Value range is [1,255], default value is 10.
5357 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5358 "Milliseconds driver will wait between polling FCP ring");
5361 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5362 # to complete in seconds. Value range is [5,180], default value is 60.
5364 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5365 "Maximum time to wait for task management commands to complete");
5367 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5368 # support this feature
5371 # 2 = MSI-X enabled (default)
5372 # Value range is [0,2]. Default value is 2.
5374 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5375 "MSI-X (2), if possible");
5378 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5380 * 0 = NVME OAS disabled
5381 * 1 = NVME OAS enabled
5383 * Value range is [0,1]. Default value is 0.
5385 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5386 "Use OAS bit on NVME IOs");
5389 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5391 * 0 = Put NVME Command in SGL
5392 * 1 = Embed NVME Command in WQE (unless G7)
5393 * 2 = Embed NVME Command in WQE (force)
5395 * Value range is [0,2]. Default value is 1.
5397 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5398 "Embed NVME Command in WQE");
5401 * lpfc_hdw_queue: Set the number of IO channels the driver
5402 * will advertise it supports to the NVME and SCSI layers. This also
5403 * will map to the number of EQ/CQ/WQs the driver will create.
5405 * The NVME Layer will try to create this many, plus 1 administrative
5406 * hardware queue. The administrative queue will always map to WQ 0
5407 * A hardware IO queue maps (qidx) to a specific driver WQ.
5409 * 0 = Configure the number of hdw queues to the number of active CPUs.
5410 * 1,64 = Manually specify how many hdw queues to use.
5412 * Value range is [0,64]. Default value is 0.
5414 LPFC_ATTR_R(hdw_queue,
5416 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5417 "Set the number of I/O Hardware Queues");
5420 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5421 # 0 = HBA resets disabled
5422 # 1 = HBA resets enabled (default)
5423 # 2 = HBA reset via PCI bus reset enabled
5424 # Value range is [0,2]. Default value is 1.
5426 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5429 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5430 # 0 = HBA Heartbeat disabled
5431 # 1 = HBA Heartbeat enabled (default)
5432 # Value range is [0,1]. Default value is 1.
5434 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5437 # lpfc_EnableXLane: Enable Express Lane Feature
5438 # 0x0 Express Lane Feature disabled
5439 # 0x1 Express Lane Feature enabled
5440 # Value range is [0,1]. Default value is 0.
5442 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5445 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5446 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5447 # Value range is [0x0,0x7f]. Default value is 0
5449 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5452 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5453 # 0 = BlockGuard disabled (default)
5454 # 1 = BlockGuard enabled
5455 # Value range is [0,1]. Default value is 0.
5457 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5460 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5461 # 0 = disabled (default)
5463 # Value range is [0,1]. Default value is 0.
5465 # This feature in under investigation and may be supported in the future.
5467 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5471 # - Bit mask of host protection capabilities used to register with the
5473 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5474 # - Allows you to ultimately specify which profiles to use
5475 # - Default will result in registering capabilities for all profiles.
5476 # - SHOST_DIF_TYPE1_PROTECTION 1
5477 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5478 # - SHOST_DIX_TYPE0_PROTECTION 8
5479 # HBA supports DIX Type 0: Host to HBA protection only
5480 # - SHOST_DIX_TYPE1_PROTECTION 16
5481 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5484 LPFC_ATTR(prot_mask,
5485 (SHOST_DIF_TYPE1_PROTECTION |
5486 SHOST_DIX_TYPE0_PROTECTION |
5487 SHOST_DIX_TYPE1_PROTECTION),
5489 (SHOST_DIF_TYPE1_PROTECTION |
5490 SHOST_DIX_TYPE0_PROTECTION |
5491 SHOST_DIX_TYPE1_PROTECTION),
5492 "T10-DIF host protection capabilities mask");
5495 # lpfc_prot_guard: i
5496 # - Bit mask of protection guard types to register with the SCSI mid-layer
5497 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5498 # - Allows you to ultimately specify which profiles to use
5499 # - Default will result in registering capabilities for all guard types
5502 LPFC_ATTR(prot_guard,
5503 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5504 "T10-DIF host protection guard type");
5507 * Delay initial NPort discovery when Clean Address bit is cleared in
5508 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5509 * This parameter can have value 0 or 1.
5510 * When this parameter is set to 0, no delay is added to the initial
5512 * When this parameter is set to non-zero value, initial Nport discovery is
5513 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5514 * accept and FCID/Fabric name/Fabric portname is changed.
5515 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5516 * when Clean Address bit is cleared in FLOGI/FDISC
5517 * accept and FCID/Fabric name/Fabric portname is changed.
5518 * Default value is 0.
5520 LPFC_ATTR(delay_discovery, 0, 0, 1,
5521 "Delay NPort discovery when Clean Address bit is cleared.");
5524 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5525 * This value can be set to values between 64 and 4096. The default value
5526 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5527 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5528 * Because of the additional overhead involved in setting up T10-DIF,
5529 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5530 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5532 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5533 module_param(lpfc_sg_seg_cnt, uint, 0444);
5534 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5537 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5538 * configured for the adapter
5539 * @dev: class converted to a Scsi_host structure.
5540 * @attr: device attribute, not used.
5541 * @buf: on return contains a string with the list sizes
5543 * Returns: size of formatted string.
5546 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5549 struct Scsi_Host *shost = class_to_shost(dev);
5550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5551 struct lpfc_hba *phba = vport->phba;
5554 len = snprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
5555 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5557 len += snprintf(buf + len, PAGE_SIZE, "Cfg: %d SCSI: %d NVME: %d\n",
5558 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5559 phba->cfg_nvme_seg_cnt);
5563 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5566 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5567 * @phba: lpfc_hba pointer.
5568 * @val: contains the initial value
5571 * Validates the initial value is within range and assigns it to the
5572 * adapter. If not in range, an error message is posted and the
5573 * default value is assigned.
5576 * zero if value is in range and is set
5577 * -EINVAL if value was out of range
5580 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5582 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5583 phba->cfg_sg_seg_cnt = val;
5586 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5587 "0409 "LPFC_DRIVER_NAME"_sg_seg_cnt attribute cannot "
5588 "be set to %d, allowed range is [%d, %d]\n",
5589 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5590 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5595 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5596 * 0 = MDS Diagnostics disabled (default)
5597 * 1 = MDS Diagnostics enabled
5598 * Value range is [0,1]. Default value is 0.
5600 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5603 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5604 * 0 = Disable firmware logging (default)
5605 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
5606 * Value range [0..4]. Default value is 0
5608 LPFC_ATTR_RW(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5611 * lpfc_ras_fwlog_level: Firmware logging verbosity level
5612 * Valid only if firmware logging is enabled
5613 * 0(Least Verbosity) 4 (most verbosity)
5614 * Value range is [0..4]. Default value is 0
5616 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5619 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5620 * Default function which has RAS support : 0
5621 * Value Range is [0..7].
5622 * FW logging is a global action and enablement is via a specific
5625 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
5628 * lpfc_enable_bbcr: Enable BB Credit Recovery
5629 * 0 = BB Credit Recovery disabled
5630 * 1 = BB Credit Recovery enabled (default)
5631 * Value range is [0,1]. Default value is 1.
5633 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5636 * lpfc_enable_dpp: Enable DPP on G7
5637 * 0 = DPP on G7 disabled
5638 * 1 = DPP on G7 enabled (default)
5639 * Value range is [0,1]. Default value is 1.
5641 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5643 struct device_attribute *lpfc_hba_attrs[] = {
5644 &dev_attr_nvme_info,
5646 &dev_attr_bg_guard_err,
5647 &dev_attr_bg_apptag_err,
5648 &dev_attr_bg_reftag_err,
5650 &dev_attr_serialnum,
5651 &dev_attr_modeldesc,
5652 &dev_attr_modelname,
5653 &dev_attr_programtype,
5657 &dev_attr_option_rom_version,
5658 &dev_attr_link_state,
5659 &dev_attr_num_discovered_ports,
5660 &dev_attr_menlo_mgmt_mode,
5661 &dev_attr_lpfc_drvr_version,
5662 &dev_attr_lpfc_enable_fip,
5663 &dev_attr_lpfc_temp_sensor,
5664 &dev_attr_lpfc_log_verbose,
5665 &dev_attr_lpfc_lun_queue_depth,
5666 &dev_attr_lpfc_tgt_queue_depth,
5667 &dev_attr_lpfc_hba_queue_depth,
5668 &dev_attr_lpfc_peer_port_login,
5669 &dev_attr_lpfc_nodev_tmo,
5670 &dev_attr_lpfc_devloss_tmo,
5671 &dev_attr_lpfc_enable_fc4_type,
5672 &dev_attr_lpfc_fcp_class,
5673 &dev_attr_lpfc_use_adisc,
5674 &dev_attr_lpfc_first_burst_size,
5675 &dev_attr_lpfc_ack0,
5676 &dev_attr_lpfc_topology,
5677 &dev_attr_lpfc_scan_down,
5678 &dev_attr_lpfc_link_speed,
5679 &dev_attr_lpfc_fcp_io_sched,
5680 &dev_attr_lpfc_ns_query,
5681 &dev_attr_lpfc_fcp2_no_tgt_reset,
5682 &dev_attr_lpfc_cr_delay,
5683 &dev_attr_lpfc_cr_count,
5684 &dev_attr_lpfc_multi_ring_support,
5685 &dev_attr_lpfc_multi_ring_rctl,
5686 &dev_attr_lpfc_multi_ring_type,
5687 &dev_attr_lpfc_fdmi_on,
5688 &dev_attr_lpfc_enable_SmartSAN,
5689 &dev_attr_lpfc_max_luns,
5690 &dev_attr_lpfc_enable_npiv,
5691 &dev_attr_lpfc_fcf_failover_policy,
5692 &dev_attr_lpfc_enable_rrq,
5693 &dev_attr_nport_evt_cnt,
5694 &dev_attr_board_mode,
5701 &dev_attr_npiv_info,
5702 &dev_attr_issue_reset,
5703 &dev_attr_lpfc_poll,
5704 &dev_attr_lpfc_poll_tmo,
5705 &dev_attr_lpfc_task_mgmt_tmo,
5706 &dev_attr_lpfc_use_msi,
5707 &dev_attr_lpfc_nvme_oas,
5708 &dev_attr_lpfc_nvme_embed_cmd,
5709 &dev_attr_lpfc_auto_imax,
5710 &dev_attr_lpfc_fcp_imax,
5711 &dev_attr_lpfc_fcp_cpu_map,
5712 &dev_attr_lpfc_hdw_queue,
5713 &dev_attr_lpfc_suppress_rsp,
5714 &dev_attr_lpfc_nvmet_mrq,
5715 &dev_attr_lpfc_nvmet_mrq_post,
5716 &dev_attr_lpfc_nvme_enable_fb,
5717 &dev_attr_lpfc_nvmet_fb_size,
5718 &dev_attr_lpfc_enable_bg,
5719 &dev_attr_lpfc_soft_wwnn,
5720 &dev_attr_lpfc_soft_wwpn,
5721 &dev_attr_lpfc_soft_wwn_enable,
5722 &dev_attr_lpfc_enable_hba_reset,
5723 &dev_attr_lpfc_enable_hba_heartbeat,
5724 &dev_attr_lpfc_EnableXLane,
5725 &dev_attr_lpfc_XLanePriority,
5726 &dev_attr_lpfc_xlane_lun,
5727 &dev_attr_lpfc_xlane_tgt,
5728 &dev_attr_lpfc_xlane_vpt,
5729 &dev_attr_lpfc_xlane_lun_state,
5730 &dev_attr_lpfc_xlane_lun_status,
5731 &dev_attr_lpfc_xlane_priority,
5732 &dev_attr_lpfc_sg_seg_cnt,
5733 &dev_attr_lpfc_max_scsicmpl_time,
5734 &dev_attr_lpfc_stat_data_ctrl,
5735 &dev_attr_lpfc_aer_support,
5736 &dev_attr_lpfc_aer_state_cleanup,
5737 &dev_attr_lpfc_sriov_nr_virtfn,
5738 &dev_attr_lpfc_req_fw_upgrade,
5739 &dev_attr_lpfc_suppress_link_up,
5740 &dev_attr_lpfc_iocb_cnt,
5743 &dev_attr_txcmplq_hw,
5744 &dev_attr_lpfc_fips_level,
5745 &dev_attr_lpfc_fips_rev,
5747 &dev_attr_lpfc_sriov_hw_max_virtfn,
5749 &dev_attr_lpfc_xlane_supported,
5750 &dev_attr_lpfc_enable_mds_diags,
5751 &dev_attr_lpfc_ras_fwlog_buffsize,
5752 &dev_attr_lpfc_ras_fwlog_level,
5753 &dev_attr_lpfc_ras_fwlog_func,
5754 &dev_attr_lpfc_enable_bbcr,
5755 &dev_attr_lpfc_enable_dpp,
5759 struct device_attribute *lpfc_vport_attrs[] = {
5761 &dev_attr_link_state,
5762 &dev_attr_num_discovered_ports,
5763 &dev_attr_lpfc_drvr_version,
5764 &dev_attr_lpfc_log_verbose,
5765 &dev_attr_lpfc_lun_queue_depth,
5766 &dev_attr_lpfc_tgt_queue_depth,
5767 &dev_attr_lpfc_nodev_tmo,
5768 &dev_attr_lpfc_devloss_tmo,
5769 &dev_attr_lpfc_hba_queue_depth,
5770 &dev_attr_lpfc_peer_port_login,
5771 &dev_attr_lpfc_restrict_login,
5772 &dev_attr_lpfc_fcp_class,
5773 &dev_attr_lpfc_use_adisc,
5774 &dev_attr_lpfc_first_burst_size,
5775 &dev_attr_lpfc_max_luns,
5776 &dev_attr_nport_evt_cnt,
5777 &dev_attr_npiv_info,
5778 &dev_attr_lpfc_enable_da_id,
5779 &dev_attr_lpfc_max_scsicmpl_time,
5780 &dev_attr_lpfc_stat_data_ctrl,
5781 &dev_attr_lpfc_static_vport,
5782 &dev_attr_lpfc_fips_level,
5783 &dev_attr_lpfc_fips_rev,
5788 * sysfs_ctlreg_write - Write method for writing to ctlreg
5789 * @filp: open sysfs file
5790 * @kobj: kernel kobject that contains the kernel class device.
5791 * @bin_attr: kernel attributes passed to us.
5792 * @buf: contains the data to be written to the adapter IOREG space.
5793 * @off: offset into buffer to beginning of data.
5794 * @count: bytes to transfer.
5797 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5798 * Uses the adapter io control registers to send buf contents to the adapter.
5801 * -ERANGE off and count combo out of range
5802 * -EINVAL off, count or buff address invalid
5803 * -EPERM adapter is offline
5804 * value of count, buf contents written
5807 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5808 struct bin_attribute *bin_attr,
5809 char *buf, loff_t off, size_t count)
5812 struct device *dev = container_of(kobj, struct device, kobj);
5813 struct Scsi_Host *shost = class_to_shost(dev);
5814 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5815 struct lpfc_hba *phba = vport->phba;
5817 if (phba->sli_rev >= LPFC_SLI_REV4)
5820 if ((off + count) > FF_REG_AREA_SIZE)
5823 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5826 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5829 /* This is to protect HBA registers from accidental writes. */
5830 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5833 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5836 spin_lock_irq(&phba->hbalock);
5837 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5838 buf_off += sizeof(uint32_t))
5839 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5840 phba->ctrl_regs_memmap_p + off + buf_off);
5842 spin_unlock_irq(&phba->hbalock);
5848 * sysfs_ctlreg_read - Read method for reading from ctlreg
5849 * @filp: open sysfs file
5850 * @kobj: kernel kobject that contains the kernel class device.
5851 * @bin_attr: kernel attributes passed to us.
5852 * @buf: if successful contains the data from the adapter IOREG space.
5853 * @off: offset into buffer to beginning of data.
5854 * @count: bytes to transfer.
5857 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5858 * Uses the adapter io control registers to read data into buf.
5861 * -ERANGE off and count combo out of range
5862 * -EINVAL off, count or buff address invalid
5863 * value of count, buf contents read
5866 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5867 struct bin_attribute *bin_attr,
5868 char *buf, loff_t off, size_t count)
5872 struct device *dev = container_of(kobj, struct device, kobj);
5873 struct Scsi_Host *shost = class_to_shost(dev);
5874 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5875 struct lpfc_hba *phba = vport->phba;
5877 if (phba->sli_rev >= LPFC_SLI_REV4)
5880 if (off > FF_REG_AREA_SIZE)
5883 if ((off + count) > FF_REG_AREA_SIZE)
5884 count = FF_REG_AREA_SIZE - off;
5886 if (count == 0) return 0;
5888 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5891 spin_lock_irq(&phba->hbalock);
5893 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5894 tmp_ptr = (uint32_t *)(buf + buf_off);
5895 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5898 spin_unlock_irq(&phba->hbalock);
5903 static struct bin_attribute sysfs_ctlreg_attr = {
5906 .mode = S_IRUSR | S_IWUSR,
5909 .read = sysfs_ctlreg_read,
5910 .write = sysfs_ctlreg_write,
5914 * sysfs_mbox_write - Write method for writing information via mbox
5915 * @filp: open sysfs file
5916 * @kobj: kernel kobject that contains the kernel class device.
5917 * @bin_attr: kernel attributes passed to us.
5918 * @buf: contains the data to be written to sysfs mbox.
5919 * @off: offset into buffer to beginning of data.
5920 * @count: bytes to transfer.
5923 * Deprecated function. All mailbox access from user space is performed via the
5927 * -EPERM operation not permitted
5930 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5931 struct bin_attribute *bin_attr,
5932 char *buf, loff_t off, size_t count)
5938 * sysfs_mbox_read - Read method for reading information via mbox
5939 * @filp: open sysfs file
5940 * @kobj: kernel kobject that contains the kernel class device.
5941 * @bin_attr: kernel attributes passed to us.
5942 * @buf: contains the data to be read from sysfs mbox.
5943 * @off: offset into buffer to beginning of data.
5944 * @count: bytes to transfer.
5947 * Deprecated function. All mailbox access from user space is performed via the
5951 * -EPERM operation not permitted
5954 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5955 struct bin_attribute *bin_attr,
5956 char *buf, loff_t off, size_t count)
5961 static struct bin_attribute sysfs_mbox_attr = {
5964 .mode = S_IRUSR | S_IWUSR,
5966 .size = MAILBOX_SYSFS_MAX,
5967 .read = sysfs_mbox_read,
5968 .write = sysfs_mbox_write,
5972 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5973 * @vport: address of lpfc vport structure.
5977 * error return code from sysfs_create_bin_file()
5980 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5982 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5985 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5986 &sysfs_drvr_stat_data_attr);
5988 /* Virtual ports do not need ctrl_reg and mbox */
5989 if (error || vport->port_type == LPFC_NPIV_PORT)
5992 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5993 &sysfs_ctlreg_attr);
5995 goto out_remove_stat_attr;
5997 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6000 goto out_remove_ctlreg_attr;
6003 out_remove_ctlreg_attr:
6004 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6005 out_remove_stat_attr:
6006 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6007 &sysfs_drvr_stat_data_attr);
6013 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6014 * @vport: address of lpfc vport structure.
6017 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6019 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6020 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6021 &sysfs_drvr_stat_data_attr);
6022 /* Virtual ports do not need ctrl_reg and mbox */
6023 if (vport->port_type == LPFC_NPIV_PORT)
6025 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6026 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6030 * Dynamic FC Host Attributes Support
6034 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6035 * @shost: kernel scsi host pointer.
6038 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6040 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6042 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6043 sizeof fc_host_symbolic_name(shost));
6047 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6048 * @shost: kernel scsi host pointer.
6051 lpfc_get_host_port_id(struct Scsi_Host *shost)
6053 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6055 /* note: fc_myDID already in cpu endianness */
6056 fc_host_port_id(shost) = vport->fc_myDID;
6060 * lpfc_get_host_port_type - Set the value of the scsi host port type
6061 * @shost: kernel scsi host pointer.
6064 lpfc_get_host_port_type(struct Scsi_Host *shost)
6066 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6067 struct lpfc_hba *phba = vport->phba;
6069 spin_lock_irq(shost->host_lock);
6071 if (vport->port_type == LPFC_NPIV_PORT) {
6072 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6073 } else if (lpfc_is_link_up(phba)) {
6074 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6075 if (vport->fc_flag & FC_PUBLIC_LOOP)
6076 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6078 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6080 if (vport->fc_flag & FC_FABRIC)
6081 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6083 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6086 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6088 spin_unlock_irq(shost->host_lock);
6092 * lpfc_get_host_port_state - Set the value of the scsi host port state
6093 * @shost: kernel scsi host pointer.
6096 lpfc_get_host_port_state(struct Scsi_Host *shost)
6098 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6099 struct lpfc_hba *phba = vport->phba;
6101 spin_lock_irq(shost->host_lock);
6103 if (vport->fc_flag & FC_OFFLINE_MODE)
6104 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6106 switch (phba->link_state) {
6107 case LPFC_LINK_UNKNOWN:
6108 case LPFC_LINK_DOWN:
6109 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6113 case LPFC_HBA_READY:
6114 /* Links up, reports port state accordingly */
6115 if (vport->port_state < LPFC_VPORT_READY)
6116 fc_host_port_state(shost) =
6117 FC_PORTSTATE_BYPASSED;
6119 fc_host_port_state(shost) =
6120 FC_PORTSTATE_ONLINE;
6122 case LPFC_HBA_ERROR:
6123 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6126 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6131 spin_unlock_irq(shost->host_lock);
6135 * lpfc_get_host_speed - Set the value of the scsi host speed
6136 * @shost: kernel scsi host pointer.
6139 lpfc_get_host_speed(struct Scsi_Host *shost)
6141 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6142 struct lpfc_hba *phba = vport->phba;
6144 spin_lock_irq(shost->host_lock);
6146 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
6147 switch(phba->fc_linkspeed) {
6148 case LPFC_LINK_SPEED_1GHZ:
6149 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6151 case LPFC_LINK_SPEED_2GHZ:
6152 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6154 case LPFC_LINK_SPEED_4GHZ:
6155 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6157 case LPFC_LINK_SPEED_8GHZ:
6158 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6160 case LPFC_LINK_SPEED_10GHZ:
6161 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6163 case LPFC_LINK_SPEED_16GHZ:
6164 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6166 case LPFC_LINK_SPEED_32GHZ:
6167 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6169 case LPFC_LINK_SPEED_64GHZ:
6170 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6172 case LPFC_LINK_SPEED_128GHZ:
6173 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6176 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6179 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6180 switch (phba->fc_linkspeed) {
6181 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6182 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6184 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6185 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6187 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6188 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6190 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6191 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6194 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6198 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6200 spin_unlock_irq(shost->host_lock);
6204 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6205 * @shost: kernel scsi host pointer.
6208 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6211 struct lpfc_hba *phba = vport->phba;
6214 spin_lock_irq(shost->host_lock);
6216 if ((vport->port_state > LPFC_FLOGI) &&
6217 ((vport->fc_flag & FC_FABRIC) ||
6218 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6219 (vport->fc_flag & FC_PUBLIC_LOOP))))
6220 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6222 /* fabric is local port if there is no F/FL_Port */
6225 spin_unlock_irq(shost->host_lock);
6227 fc_host_fabric_name(shost) = node_name;
6231 * lpfc_get_stats - Return statistical information about the adapter
6232 * @shost: kernel scsi host pointer.
6235 * NULL on error for link down, no mbox pool, sli2 active,
6236 * management not allowed, memory allocation error, or mbox error.
6240 * address of the adapter host statistics
6242 static struct fc_host_statistics *
6243 lpfc_get_stats(struct Scsi_Host *shost)
6245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6246 struct lpfc_hba *phba = vport->phba;
6247 struct lpfc_sli *psli = &phba->sli;
6248 struct fc_host_statistics *hs = &phba->link_stats;
6249 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6250 LPFC_MBOXQ_t *pmboxq;
6255 * prevent udev from issuing mailbox commands until the port is
6258 if (phba->link_state < LPFC_LINK_DOWN ||
6259 !phba->mbox_mem_pool ||
6260 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6263 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6266 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6269 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6271 pmb = &pmboxq->u.mb;
6272 pmb->mbxCommand = MBX_READ_STATUS;
6273 pmb->mbxOwner = OWN_HOST;
6274 pmboxq->ctx_buf = NULL;
6275 pmboxq->vport = vport;
6277 if (vport->fc_flag & FC_OFFLINE_MODE)
6278 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6280 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6282 if (rc != MBX_SUCCESS) {
6283 if (rc != MBX_TIMEOUT)
6284 mempool_free(pmboxq, phba->mbox_mem_pool);
6288 memset(hs, 0, sizeof (struct fc_host_statistics));
6290 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6292 * The MBX_READ_STATUS returns tx_k_bytes which has to
6293 * converted to words
6295 hs->tx_words = (uint64_t)
6296 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6298 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6299 hs->rx_words = (uint64_t)
6300 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6303 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6304 pmb->mbxCommand = MBX_READ_LNK_STAT;
6305 pmb->mbxOwner = OWN_HOST;
6306 pmboxq->ctx_buf = NULL;
6307 pmboxq->vport = vport;
6309 if (vport->fc_flag & FC_OFFLINE_MODE)
6310 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6312 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6314 if (rc != MBX_SUCCESS) {
6315 if (rc != MBX_TIMEOUT)
6316 mempool_free(pmboxq, phba->mbox_mem_pool);
6320 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6321 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6322 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6323 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6324 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6325 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6326 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6328 hs->link_failure_count -= lso->link_failure_count;
6329 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6330 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6331 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6332 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6333 hs->invalid_crc_count -= lso->invalid_crc_count;
6334 hs->error_frames -= lso->error_frames;
6336 if (phba->hba_flag & HBA_FCOE_MODE) {
6338 hs->nos_count = (phba->link_events >> 1);
6339 hs->nos_count -= lso->link_events;
6340 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6341 hs->lip_count = (phba->fc_eventTag >> 1);
6342 hs->lip_count -= lso->link_events;
6346 hs->nos_count = (phba->fc_eventTag >> 1);
6347 hs->nos_count -= lso->link_events;
6350 hs->dumped_frames = -1;
6352 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6354 mempool_free(pmboxq, phba->mbox_mem_pool);
6360 * lpfc_reset_stats - Copy the adapter link stats information
6361 * @shost: kernel scsi host pointer.
6364 lpfc_reset_stats(struct Scsi_Host *shost)
6366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6367 struct lpfc_hba *phba = vport->phba;
6368 struct lpfc_sli *psli = &phba->sli;
6369 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6370 LPFC_MBOXQ_t *pmboxq;
6374 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6377 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6380 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6382 pmb = &pmboxq->u.mb;
6383 pmb->mbxCommand = MBX_READ_STATUS;
6384 pmb->mbxOwner = OWN_HOST;
6385 pmb->un.varWords[0] = 0x1; /* reset request */
6386 pmboxq->ctx_buf = NULL;
6387 pmboxq->vport = vport;
6389 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6390 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6391 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6393 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6395 if (rc != MBX_SUCCESS) {
6396 if (rc != MBX_TIMEOUT)
6397 mempool_free(pmboxq, phba->mbox_mem_pool);
6401 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6402 pmb->mbxCommand = MBX_READ_LNK_STAT;
6403 pmb->mbxOwner = OWN_HOST;
6404 pmboxq->ctx_buf = NULL;
6405 pmboxq->vport = vport;
6407 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6408 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6409 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6411 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6413 if (rc != MBX_SUCCESS) {
6414 if (rc != MBX_TIMEOUT)
6415 mempool_free( pmboxq, phba->mbox_mem_pool);
6419 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6420 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6421 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6422 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6423 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6424 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6425 lso->error_frames = pmb->un.varRdLnk.crcCnt;
6426 if (phba->hba_flag & HBA_FCOE_MODE)
6427 lso->link_events = (phba->link_events >> 1);
6429 lso->link_events = (phba->fc_eventTag >> 1);
6431 psli->stats_start = ktime_get_seconds();
6433 mempool_free(pmboxq, phba->mbox_mem_pool);
6439 * The LPFC driver treats linkdown handling as target loss events so there
6440 * are no sysfs handlers for link_down_tmo.
6444 * lpfc_get_node_by_target - Return the nodelist for a target
6445 * @starget: kernel scsi target pointer.
6448 * address of the node list if found
6449 * NULL target not found
6451 static struct lpfc_nodelist *
6452 lpfc_get_node_by_target(struct scsi_target *starget)
6454 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6455 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6456 struct lpfc_nodelist *ndlp;
6458 spin_lock_irq(shost->host_lock);
6459 /* Search for this, mapped, target ID */
6460 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6461 if (NLP_CHK_NODE_ACT(ndlp) &&
6462 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6463 starget->id == ndlp->nlp_sid) {
6464 spin_unlock_irq(shost->host_lock);
6468 spin_unlock_irq(shost->host_lock);
6473 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6474 * @starget: kernel scsi target pointer.
6477 lpfc_get_starget_port_id(struct scsi_target *starget)
6479 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6481 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6485 * lpfc_get_starget_node_name - Set the target node name
6486 * @starget: kernel scsi target pointer.
6488 * Description: Set the target node name to the ndlp node name wwn or zero.
6491 lpfc_get_starget_node_name(struct scsi_target *starget)
6493 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6495 fc_starget_node_name(starget) =
6496 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6500 * lpfc_get_starget_port_name - Set the target port name
6501 * @starget: kernel scsi target pointer.
6503 * Description: set the target port name to the ndlp port name wwn or zero.
6506 lpfc_get_starget_port_name(struct scsi_target *starget)
6508 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6510 fc_starget_port_name(starget) =
6511 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6515 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6516 * @rport: fc rport address.
6517 * @timeout: new value for dev loss tmo.
6520 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6521 * dev_loss_tmo to one.
6524 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6527 rport->dev_loss_tmo = timeout;
6529 rport->dev_loss_tmo = 1;
6533 * lpfc_rport_show_function - Return rport target information
6536 * Macro that uses field to generate a function with the name lpfc_show_rport_
6538 * lpfc_show_rport_##field: returns the bytes formatted in buf
6539 * @cdev: class converted to an fc_rport.
6540 * @buf: on return contains the target_field or zero.
6542 * Returns: size of formatted string.
6544 #define lpfc_rport_show_function(field, format_string, sz, cast) \
6546 lpfc_show_rport_##field (struct device *dev, \
6547 struct device_attribute *attr, \
6550 struct fc_rport *rport = transport_class_to_rport(dev); \
6551 struct lpfc_rport_data *rdata = rport->hostdata; \
6552 return snprintf(buf, sz, format_string, \
6553 (rdata->target) ? cast rdata->target->field : 0); \
6556 #define lpfc_rport_rd_attr(field, format_string, sz) \
6557 lpfc_rport_show_function(field, format_string, sz, ) \
6558 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6561 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6562 * @fc_vport: The fc_vport who's symbolic name has been changed.
6565 * This function is called by the transport after the @fc_vport's symbolic name
6566 * has been changed. This function re-registers the symbolic name with the
6567 * switch to propagate the change into the fabric if the vport is active.
6570 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6572 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6574 if (vport->port_state == LPFC_VPORT_READY)
6575 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6579 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6580 * @phba: Pointer to lpfc_hba struct.
6582 * This function is called by the lpfc_get_cfgparam() routine to set the
6583 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6584 * log message according to the module's lpfc_log_verbose parameter setting
6585 * before hba port or vport created.
6588 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6590 phba->cfg_log_verbose = verbose;
6593 struct fc_function_template lpfc_transport_functions = {
6594 /* fixed attributes the driver supports */
6595 .show_host_node_name = 1,
6596 .show_host_port_name = 1,
6597 .show_host_supported_classes = 1,
6598 .show_host_supported_fc4s = 1,
6599 .show_host_supported_speeds = 1,
6600 .show_host_maxframe_size = 1,
6602 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6603 .show_host_symbolic_name = 1,
6605 /* dynamic attributes the driver supports */
6606 .get_host_port_id = lpfc_get_host_port_id,
6607 .show_host_port_id = 1,
6609 .get_host_port_type = lpfc_get_host_port_type,
6610 .show_host_port_type = 1,
6612 .get_host_port_state = lpfc_get_host_port_state,
6613 .show_host_port_state = 1,
6615 /* active_fc4s is shown but doesn't change (thus no get function) */
6616 .show_host_active_fc4s = 1,
6618 .get_host_speed = lpfc_get_host_speed,
6619 .show_host_speed = 1,
6621 .get_host_fabric_name = lpfc_get_host_fabric_name,
6622 .show_host_fabric_name = 1,
6625 * The LPFC driver treats linkdown handling as target loss events
6626 * so there are no sysfs handlers for link_down_tmo.
6629 .get_fc_host_stats = lpfc_get_stats,
6630 .reset_fc_host_stats = lpfc_reset_stats,
6632 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6633 .show_rport_maxframe_size = 1,
6634 .show_rport_supported_classes = 1,
6636 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6637 .show_rport_dev_loss_tmo = 1,
6639 .get_starget_port_id = lpfc_get_starget_port_id,
6640 .show_starget_port_id = 1,
6642 .get_starget_node_name = lpfc_get_starget_node_name,
6643 .show_starget_node_name = 1,
6645 .get_starget_port_name = lpfc_get_starget_port_name,
6646 .show_starget_port_name = 1,
6648 .issue_fc_host_lip = lpfc_issue_lip,
6649 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6650 .terminate_rport_io = lpfc_terminate_rport_io,
6652 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6654 .vport_disable = lpfc_vport_disable,
6656 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6658 .bsg_request = lpfc_bsg_request,
6659 .bsg_timeout = lpfc_bsg_timeout,
6662 struct fc_function_template lpfc_vport_transport_functions = {
6663 /* fixed attributes the driver supports */
6664 .show_host_node_name = 1,
6665 .show_host_port_name = 1,
6666 .show_host_supported_classes = 1,
6667 .show_host_supported_fc4s = 1,
6668 .show_host_supported_speeds = 1,
6669 .show_host_maxframe_size = 1,
6671 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6672 .show_host_symbolic_name = 1,
6674 /* dynamic attributes the driver supports */
6675 .get_host_port_id = lpfc_get_host_port_id,
6676 .show_host_port_id = 1,
6678 .get_host_port_type = lpfc_get_host_port_type,
6679 .show_host_port_type = 1,
6681 .get_host_port_state = lpfc_get_host_port_state,
6682 .show_host_port_state = 1,
6684 /* active_fc4s is shown but doesn't change (thus no get function) */
6685 .show_host_active_fc4s = 1,
6687 .get_host_speed = lpfc_get_host_speed,
6688 .show_host_speed = 1,
6690 .get_host_fabric_name = lpfc_get_host_fabric_name,
6691 .show_host_fabric_name = 1,
6694 * The LPFC driver treats linkdown handling as target loss events
6695 * so there are no sysfs handlers for link_down_tmo.
6698 .get_fc_host_stats = lpfc_get_stats,
6699 .reset_fc_host_stats = lpfc_reset_stats,
6701 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6702 .show_rport_maxframe_size = 1,
6703 .show_rport_supported_classes = 1,
6705 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6706 .show_rport_dev_loss_tmo = 1,
6708 .get_starget_port_id = lpfc_get_starget_port_id,
6709 .show_starget_port_id = 1,
6711 .get_starget_node_name = lpfc_get_starget_node_name,
6712 .show_starget_node_name = 1,
6714 .get_starget_port_name = lpfc_get_starget_port_name,
6715 .show_starget_port_name = 1,
6717 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6718 .terminate_rport_io = lpfc_terminate_rport_io,
6720 .vport_disable = lpfc_vport_disable,
6722 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6726 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6727 * @phba: lpfc_hba pointer.
6730 lpfc_get_cfgparam(struct lpfc_hba *phba)
6732 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6733 lpfc_ns_query_init(phba, lpfc_ns_query);
6734 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6735 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6736 lpfc_cr_count_init(phba, lpfc_cr_count);
6737 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6738 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6739 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6740 lpfc_ack0_init(phba, lpfc_ack0);
6741 lpfc_topology_init(phba, lpfc_topology);
6742 lpfc_link_speed_init(phba, lpfc_link_speed);
6743 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6744 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6745 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6746 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6747 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6748 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6749 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6750 lpfc_use_msi_init(phba, lpfc_use_msi);
6751 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6752 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
6753 lpfc_auto_imax_init(phba, lpfc_auto_imax);
6754 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6755 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6756 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6757 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6759 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6760 if (phba->sli_rev != LPFC_SLI_REV4)
6761 phba->cfg_EnableXLane = 0;
6762 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6764 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6765 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6766 phba->cfg_oas_lun_state = 0;
6767 phba->cfg_oas_lun_status = 0;
6768 phba->cfg_oas_flags = 0;
6769 phba->cfg_oas_priority = 0;
6770 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6771 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6772 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6773 if (phba->sli_rev == LPFC_SLI_REV4)
6776 phba->cfg_poll = lpfc_poll;
6778 if (phba->cfg_enable_bg)
6779 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
6781 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6783 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6784 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6785 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
6787 /* Initialize first burst. Target vs Initiator are different. */
6788 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6789 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6790 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
6791 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
6792 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
6794 if (phba->sli_rev != LPFC_SLI_REV4) {
6795 /* NVME only supported on SLI4 */
6796 phba->nvmet_support = 0;
6797 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6798 phba->cfg_enable_bbcr = 0;
6800 /* We MUST have FCP support */
6801 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6802 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6805 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6806 phba->cfg_auto_imax = 0;
6807 phba->initial_imax = phba->cfg_fcp_imax;
6809 phba->cfg_enable_pbde = 0;
6811 /* A value of 0 means use the number of CPUs found in the system */
6812 if (phba->cfg_hdw_queue == 0)
6813 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
6815 phba->cfg_soft_wwnn = 0L;
6816 phba->cfg_soft_wwpn = 0L;
6817 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6818 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6819 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6820 lpfc_aer_support_init(phba, lpfc_aer_support);
6821 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6822 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6823 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6824 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6825 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6826 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6827 phba->cfg_enable_dss = 1;
6828 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6829 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
6830 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
6831 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
6834 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
6835 * accommodate 512K and 1M IOs in a single nvme buf and supply
6836 * enough NVME LS iocb buffers for larger connectivity counts.
6838 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6839 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
6840 phba->cfg_iocb_cnt = 5;
6847 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6848 * dependencies between protocols and roles.
6849 * @phba: lpfc_hba pointer.
6852 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6854 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu)
6855 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
6857 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6858 phba->nvmet_support) {
6859 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6861 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6862 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6863 "NVME Target PRLI ACC enable_fb ",
6864 phba->cfg_nvme_enable_fb,
6865 phba->cfg_nvmet_fb_size,
6866 LPFC_NVMET_FB_SZ_MAX);
6868 if (phba->cfg_nvme_enable_fb == 0)
6869 phba->cfg_nvmet_fb_size = 0;
6871 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6872 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6875 if (!phba->cfg_nvmet_mrq)
6876 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
6878 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6879 if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
6880 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
6881 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6882 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6883 phba->cfg_nvmet_mrq);
6885 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
6886 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
6889 /* Not NVME Target mode. Turn off Target parameters. */
6890 phba->nvmet_support = 0;
6891 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
6892 phba->cfg_nvmet_fb_size = 0;
6897 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6898 * @vport: lpfc_vport pointer.
6901 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6903 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6904 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6905 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6906 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6907 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6908 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6909 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6910 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6911 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6912 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6913 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6914 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6915 lpfc_max_luns_init(vport, lpfc_max_luns);
6916 lpfc_scan_down_init(vport, lpfc_scan_down);
6917 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);