1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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
68 * Write key size should be multiple of 4. If write key is changed
69 * make sure that library write key is also changed.
71 #define LPFC_REG_WRITE_KEY_SIZE 4
72 #define LPFC_REG_WRITE_KEY "EMLX"
75 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
76 * @incr: integer to convert.
77 * @hdw: ascii string holding converted integer plus a string terminator.
80 * JEDEC Joint Electron Device Engineering Council.
81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
82 * character string. The string is then terminated with a NULL in byte 9.
83 * Hex 0-9 becomes ascii '0' to '9'.
84 * Hex a-f becomes ascii '=' to 'B' capital B.
87 * Coded for 32 bit integers only.
90 lpfc_jedec_to_ascii(int incr, char hdw[])
93 for (i = 0; i < 8; i++) {
96 hdw[7 - i] = 0x30 + j;
98 hdw[7 - i] = 0x61 + j - 10;
106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
107 * @dev: class unused variable.
108 * @attr: device attribute, not used.
109 * @buf: on return contains the module description text.
111 * Returns: size of formatted string.
114 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
126 * Returns: size of formatted string.
129 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
139 return snprintf(buf, PAGE_SIZE, "0\n");
143 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = shost_priv(shost);
148 struct lpfc_hba *phba = vport->phba;
149 struct lpfc_nvmet_tgtport *tgtp;
150 struct nvme_fc_local_port *localport;
151 struct lpfc_nodelist *ndlp;
152 struct nvme_fc_remote_port *nrport;
156 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
157 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
160 if (phba->nvmet_support) {
161 if (!phba->targetport) {
162 len = snprintf(buf, PAGE_SIZE,
163 "NVME Target: x%llx is not allocated\n",
164 wwn_to_u64(vport->fc_portname.u.wwn));
167 /* Port state is only one of two values for now. */
168 if (phba->targetport->port_id)
169 statep = "REGISTERED";
172 len += snprintf(buf + len, PAGE_SIZE - len,
173 "NVME Target: Enabled State %s\n",
175 len += snprintf(buf + len, PAGE_SIZE - len,
176 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
179 wwn_to_u64(vport->fc_portname.u.wwn),
180 wwn_to_u64(vport->fc_nodename.u.wwn),
181 phba->targetport->port_id);
183 len += snprintf(buf + len, PAGE_SIZE - len,
184 "\nNVME Target: Statistics\n");
185 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
186 len += snprintf(buf+len, PAGE_SIZE-len,
187 "LS: Rcv %08x Drop %08x Abort %08x\n",
188 atomic_read(&tgtp->rcv_ls_req_in),
189 atomic_read(&tgtp->rcv_ls_req_drop),
190 atomic_read(&tgtp->xmt_ls_abort));
191 if (atomic_read(&tgtp->rcv_ls_req_in) !=
192 atomic_read(&tgtp->rcv_ls_req_out)) {
193 len += snprintf(buf+len, PAGE_SIZE-len,
194 "Rcv LS: in %08x != out %08x\n",
195 atomic_read(&tgtp->rcv_ls_req_in),
196 atomic_read(&tgtp->rcv_ls_req_out));
199 len += snprintf(buf+len, PAGE_SIZE-len,
200 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
201 atomic_read(&tgtp->xmt_ls_rsp),
202 atomic_read(&tgtp->xmt_ls_drop),
203 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
204 atomic_read(&tgtp->xmt_ls_rsp_error));
206 len += snprintf(buf+len, PAGE_SIZE-len,
207 "FCP: Rcv %08x Release %08x Drop %08x\n",
208 atomic_read(&tgtp->rcv_fcp_cmd_in),
209 atomic_read(&tgtp->xmt_fcp_release),
210 atomic_read(&tgtp->rcv_fcp_cmd_drop));
212 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
213 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
214 len += snprintf(buf+len, PAGE_SIZE-len,
215 "Rcv FCP: in %08x != out %08x\n",
216 atomic_read(&tgtp->rcv_fcp_cmd_in),
217 atomic_read(&tgtp->rcv_fcp_cmd_out));
220 len += snprintf(buf+len, PAGE_SIZE-len,
221 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
223 atomic_read(&tgtp->xmt_fcp_read),
224 atomic_read(&tgtp->xmt_fcp_read_rsp),
225 atomic_read(&tgtp->xmt_fcp_write),
226 atomic_read(&tgtp->xmt_fcp_rsp),
227 atomic_read(&tgtp->xmt_fcp_drop));
229 len += snprintf(buf+len, PAGE_SIZE-len,
230 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
231 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
232 atomic_read(&tgtp->xmt_fcp_rsp_error),
233 atomic_read(&tgtp->xmt_fcp_rsp_drop));
235 len += snprintf(buf+len, PAGE_SIZE-len,
236 "ABORT: Xmt %08x Cmpl %08x\n",
237 atomic_read(&tgtp->xmt_fcp_abort),
238 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
240 len += snprintf(buf + len, PAGE_SIZE - len,
241 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
242 atomic_read(&tgtp->xmt_abort_sol),
243 atomic_read(&tgtp->xmt_abort_unsol),
244 atomic_read(&tgtp->xmt_abort_rsp),
245 atomic_read(&tgtp->xmt_abort_rsp_error));
247 len += snprintf(buf + len, PAGE_SIZE - len,
248 "IO_CTX: %08x outstanding %08x total %x",
249 phba->sli4_hba.nvmet_ctx_cnt,
250 phba->sli4_hba.nvmet_io_wait_cnt,
251 phba->sli4_hba.nvmet_io_wait_total);
253 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
257 localport = vport->localport;
259 len = snprintf(buf, PAGE_SIZE,
260 "NVME Initiator x%llx is not allocated\n",
261 wwn_to_u64(vport->fc_portname.u.wwn));
264 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
266 spin_lock_irq(shost->host_lock);
268 /* Port state is only one of two values for now. */
269 if (localport->port_id)
274 len += snprintf(buf + len, PAGE_SIZE - len,
275 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
278 wwn_to_u64(vport->fc_portname.u.wwn),
279 wwn_to_u64(vport->fc_nodename.u.wwn),
280 localport->port_id, statep);
282 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
286 /* local short-hand pointer. */
287 nrport = ndlp->nrport->remoteport;
289 /* Port state is only one of two values for now. */
290 switch (nrport->port_state) {
291 case FC_OBJSTATE_ONLINE:
294 case FC_OBJSTATE_UNKNOWN:
298 statep = "UNSUPPORTED";
302 /* Tab in to show lport ownership. */
303 len += snprintf(buf + len, PAGE_SIZE - len,
305 if (phba->brd_no >= 10)
306 len += snprintf(buf + len, PAGE_SIZE - len, " ");
308 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
310 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
312 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
315 /* An NVME rport can have multiple roles. */
316 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
317 len += snprintf(buf + len, PAGE_SIZE - len,
319 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
320 len += snprintf(buf + len, PAGE_SIZE - len,
322 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
323 len += snprintf(buf + len, PAGE_SIZE - len,
325 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
326 FC_PORT_ROLE_NVME_TARGET |
327 FC_PORT_ROLE_NVME_DISCOVERY))
328 len += snprintf(buf + len, PAGE_SIZE - len,
332 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
333 /* Terminate the string. */
334 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
336 spin_unlock_irq(shost->host_lock);
338 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
339 len += snprintf(buf+len, PAGE_SIZE-len,
340 "LS: Xmt %016llx Cmpl %016llx\n",
341 phba->fc4NvmeLsRequests,
342 phba->fc4NvmeLsCmpls);
344 len += snprintf(buf+len, PAGE_SIZE-len,
345 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
346 phba->fc4NvmeInputRequests,
347 phba->fc4NvmeOutputRequests,
348 phba->fc4NvmeControlRequests);
350 len += snprintf(buf+len, PAGE_SIZE-len,
351 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
357 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
360 struct Scsi_Host *shost = class_to_shost(dev);
361 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
362 struct lpfc_hba *phba = vport->phba;
364 if (phba->cfg_enable_bg)
365 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
366 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
368 return snprintf(buf, PAGE_SIZE,
369 "BlockGuard Not Supported\n");
371 return snprintf(buf, PAGE_SIZE,
372 "BlockGuard Disabled\n");
376 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
379 struct Scsi_Host *shost = class_to_shost(dev);
380 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
381 struct lpfc_hba *phba = vport->phba;
383 return snprintf(buf, PAGE_SIZE, "%llu\n",
384 (unsigned long long)phba->bg_guard_err_cnt);
388 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
391 struct Scsi_Host *shost = class_to_shost(dev);
392 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
393 struct lpfc_hba *phba = vport->phba;
395 return snprintf(buf, PAGE_SIZE, "%llu\n",
396 (unsigned long long)phba->bg_apptag_err_cnt);
400 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
403 struct Scsi_Host *shost = class_to_shost(dev);
404 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
405 struct lpfc_hba *phba = vport->phba;
407 return snprintf(buf, PAGE_SIZE, "%llu\n",
408 (unsigned long long)phba->bg_reftag_err_cnt);
412 * lpfc_info_show - Return some pci info about the host in ascii
413 * @dev: class converted to a Scsi_host structure.
414 * @attr: device attribute, not used.
415 * @buf: on return contains the formatted text from lpfc_info().
417 * Returns: size of formatted string.
420 lpfc_info_show(struct device *dev, struct device_attribute *attr,
423 struct Scsi_Host *host = class_to_shost(dev);
425 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
429 * lpfc_serialnum_show - Return the hba serial number in ascii
430 * @dev: class converted to a Scsi_host structure.
431 * @attr: device attribute, not used.
432 * @buf: on return contains the formatted text serial number.
434 * Returns: size of formatted string.
437 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
440 struct Scsi_Host *shost = class_to_shost(dev);
441 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
442 struct lpfc_hba *phba = vport->phba;
444 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
448 * lpfc_temp_sensor_show - Return the temperature sensor level
449 * @dev: class converted to a Scsi_host structure.
450 * @attr: device attribute, not used.
451 * @buf: on return contains the formatted support level.
454 * Returns a number indicating the temperature sensor level currently
455 * supported, zero or one in ascii.
457 * Returns: size of formatted string.
460 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
463 struct Scsi_Host *shost = class_to_shost(dev);
464 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
465 struct lpfc_hba *phba = vport->phba;
466 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
470 * lpfc_modeldesc_show - Return the model description of the hba
471 * @dev: class converted to a Scsi_host structure.
472 * @attr: device attribute, not used.
473 * @buf: on return contains the scsi vpd model description.
475 * Returns: size of formatted string.
478 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
481 struct Scsi_Host *shost = class_to_shost(dev);
482 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
483 struct lpfc_hba *phba = vport->phba;
485 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
489 * lpfc_modelname_show - Return the model name of the hba
490 * @dev: class converted to a Scsi_host structure.
491 * @attr: device attribute, not used.
492 * @buf: on return contains the scsi vpd model name.
494 * Returns: size of formatted string.
497 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
500 struct Scsi_Host *shost = class_to_shost(dev);
501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
502 struct lpfc_hba *phba = vport->phba;
504 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
508 * lpfc_programtype_show - Return the program type of the hba
509 * @dev: class converted to a Scsi_host structure.
510 * @attr: device attribute, not used.
511 * @buf: on return contains the scsi vpd program type.
513 * Returns: size of formatted string.
516 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
519 struct Scsi_Host *shost = class_to_shost(dev);
520 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
521 struct lpfc_hba *phba = vport->phba;
523 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
527 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
528 * @dev: class converted to a Scsi_host structure.
529 * @attr: device attribute, not used.
530 * @buf: on return contains the Menlo Maintenance sli flag.
532 * Returns: size of formatted string.
535 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
537 struct Scsi_Host *shost = class_to_shost(dev);
538 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
539 struct lpfc_hba *phba = vport->phba;
541 return snprintf(buf, PAGE_SIZE, "%d\n",
542 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
546 * lpfc_vportnum_show - Return the port number in ascii of the hba
547 * @dev: class converted to a Scsi_host structure.
548 * @attr: device attribute, not used.
549 * @buf: on return contains scsi vpd program type.
551 * Returns: size of formatted string.
554 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
557 struct Scsi_Host *shost = class_to_shost(dev);
558 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
559 struct lpfc_hba *phba = vport->phba;
561 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
565 * lpfc_fwrev_show - Return the firmware rev running in the hba
566 * @dev: class converted to a Scsi_host structure.
567 * @attr: device attribute, not used.
568 * @buf: on return contains the scsi vpd program type.
570 * Returns: size of formatted string.
573 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
576 struct Scsi_Host *shost = class_to_shost(dev);
577 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
578 struct lpfc_hba *phba = vport->phba;
581 char fwrev[FW_REV_STR_SIZE];
584 lpfc_decode_firmware_rev(phba, fwrev, 1);
585 if_type = phba->sli4_hba.pc_sli4_params.if_type;
586 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
588 if (phba->sli_rev < LPFC_SLI_REV4)
589 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
590 fwrev, phba->sli_rev);
592 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
593 fwrev, phba->sli_rev, if_type, sli_family);
599 * lpfc_hdw_show - Return the jedec information about the hba
600 * @dev: class converted to a Scsi_host structure.
601 * @attr: device attribute, not used.
602 * @buf: on return contains the scsi vpd program type.
604 * Returns: size of formatted string.
607 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
610 struct Scsi_Host *shost = class_to_shost(dev);
611 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
612 struct lpfc_hba *phba = vport->phba;
613 lpfc_vpd_t *vp = &phba->vpd;
615 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
616 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
620 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
621 * @dev: class converted to a Scsi_host structure.
622 * @attr: device attribute, not used.
623 * @buf: on return contains the ROM and FCode ascii strings.
625 * Returns: size of formatted string.
628 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
631 struct Scsi_Host *shost = class_to_shost(dev);
632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
633 struct lpfc_hba *phba = vport->phba;
634 char fwrev[FW_REV_STR_SIZE];
636 if (phba->sli_rev < LPFC_SLI_REV4)
637 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
639 lpfc_decode_firmware_rev(phba, fwrev, 1);
640 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
644 * lpfc_state_show - Return the link state of the port
645 * @dev: class converted to a Scsi_host structure.
646 * @attr: device attribute, not used.
647 * @buf: on return contains text describing the state of the link.
650 * The switch statement has no default so zero will be returned.
652 * Returns: size of formatted string.
655 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
658 struct Scsi_Host *shost = class_to_shost(dev);
659 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
660 struct lpfc_hba *phba = vport->phba;
663 switch (phba->link_state) {
664 case LPFC_LINK_UNKNOWN:
665 case LPFC_WARM_START:
666 case LPFC_INIT_START:
667 case LPFC_INIT_MBX_CMDS:
670 if (phba->hba_flag & LINK_DISABLED)
671 len += snprintf(buf + len, PAGE_SIZE-len,
672 "Link Down - User disabled\n");
674 len += snprintf(buf + len, PAGE_SIZE-len,
680 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
682 switch (vport->port_state) {
683 case LPFC_LOCAL_CFG_LINK:
684 len += snprintf(buf + len, PAGE_SIZE-len,
685 "Configuring Link\n");
689 case LPFC_FABRIC_CFG_LINK:
692 case LPFC_BUILD_DISC_LIST:
694 len += snprintf(buf + len, PAGE_SIZE - len,
697 case LPFC_VPORT_READY:
698 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
701 case LPFC_VPORT_FAILED:
702 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
705 case LPFC_VPORT_UNKNOWN:
706 len += snprintf(buf + len, PAGE_SIZE - len,
710 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
711 len += snprintf(buf + len, PAGE_SIZE-len,
712 " Menlo Maint Mode\n");
713 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
714 if (vport->fc_flag & FC_PUBLIC_LOOP)
715 len += snprintf(buf + len, PAGE_SIZE-len,
718 len += snprintf(buf + len, PAGE_SIZE-len,
721 if (vport->fc_flag & FC_FABRIC)
722 len += snprintf(buf + len, PAGE_SIZE-len,
725 len += snprintf(buf + len, PAGE_SIZE-len,
734 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
735 * @dev: class unused variable.
736 * @attr: device attribute, not used.
737 * @buf: on return contains the module description text.
739 * Returns: size of formatted string.
742 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
745 struct Scsi_Host *shost = class_to_shost(dev);
746 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
747 struct lpfc_hba *phba = vport->phba;
749 if (phba->sli_rev < LPFC_SLI_REV4)
750 return snprintf(buf, PAGE_SIZE, "fc\n");
752 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
753 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
754 return snprintf(buf, PAGE_SIZE, "fcoe\n");
755 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
756 return snprintf(buf, PAGE_SIZE, "fc\n");
758 return snprintf(buf, PAGE_SIZE, "unknown\n");
762 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
763 * (OAS) is supported.
764 * @dev: class unused variable.
765 * @attr: device attribute, not used.
766 * @buf: on return contains the module description text.
768 * Returns: size of formatted string.
771 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
774 struct Scsi_Host *shost = class_to_shost(dev);
775 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
776 struct lpfc_hba *phba = vport->phba;
778 return snprintf(buf, PAGE_SIZE, "%d\n",
779 phba->sli4_hba.pc_sli4_params.oas_supported);
783 * lpfc_link_state_store - Transition the link_state on an HBA port
784 * @dev: class device that is converted into a Scsi_host.
785 * @attr: device attribute, not used.
786 * @buf: one or more lpfc_polling_flags values.
790 * -EINVAL if the buffer is not "up" or "down"
791 * return from link state change function if non-zero
792 * length of the buf on success
795 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
796 const char *buf, size_t count)
798 struct Scsi_Host *shost = class_to_shost(dev);
799 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
800 struct lpfc_hba *phba = vport->phba;
802 int status = -EINVAL;
804 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
805 (phba->link_state == LPFC_LINK_DOWN))
806 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
807 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
808 (phba->link_state >= LPFC_LINK_UP))
809 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
818 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
819 * @dev: class device that is converted into a Scsi_host.
820 * @attr: device attribute, not used.
821 * @buf: on return contains the sum of fc mapped and unmapped.
824 * Returns the ascii text number of the sum of the fc mapped and unmapped
827 * Returns: size of formatted string.
830 lpfc_num_discovered_ports_show(struct device *dev,
831 struct device_attribute *attr, char *buf)
833 struct Scsi_Host *shost = class_to_shost(dev);
834 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
836 return snprintf(buf, PAGE_SIZE, "%d\n",
837 vport->fc_map_cnt + vport->fc_unmap_cnt);
841 * lpfc_issue_lip - Misnomer, name carried over from long ago
842 * @shost: Scsi_Host pointer.
845 * Bring the link down gracefully then re-init the link. The firmware will
846 * re-init the fiber channel interface as required. Does not issue a LIP.
849 * -EPERM port offline or management commands are being blocked
850 * -ENOMEM cannot allocate memory for the mailbox command
851 * -EIO error sending the mailbox command
855 lpfc_issue_lip(struct Scsi_Host *shost)
857 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
858 struct lpfc_hba *phba = vport->phba;
859 LPFC_MBOXQ_t *pmboxq;
860 int mbxstatus = MBXERR_ERROR;
862 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
863 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
866 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
871 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
872 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
873 pmboxq->u.mb.mbxOwner = OWN_HOST;
875 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
877 if ((mbxstatus == MBX_SUCCESS) &&
878 (pmboxq->u.mb.mbxStatus == 0 ||
879 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
880 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
881 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
882 phba->cfg_link_speed);
883 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
885 if ((mbxstatus == MBX_SUCCESS) &&
886 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
887 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
888 "2859 SLI authentication is required "
889 "for INIT_LINK but has not done yet\n");
892 lpfc_set_loopback_flag(phba);
893 if (mbxstatus != MBX_TIMEOUT)
894 mempool_free(pmboxq, phba->mbox_mem_pool);
896 if (mbxstatus == MBXERR_ERROR)
903 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
908 while (!list_empty(q)) {
909 spin_unlock_irq(lock);
911 if (cnt++ > 250) { /* 5 secs */
912 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
914 "Outstanding IO when ",
915 "bringing Adapter offline\n");
920 spin_unlock_irq(lock);
925 * lpfc_do_offline - Issues a mailbox command to bring the link down
926 * @phba: lpfc_hba pointer.
927 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
930 * Assumes any error from lpfc_do_offline() will be negative.
931 * Can wait up to 5 seconds for the port ring buffers count
932 * to reach zero, prints a warning if it is not zero and continues.
933 * lpfc_workq_post_event() returns a non-zero return code if call fails.
936 * -EIO error posting the event
940 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
942 struct completion online_compl;
943 struct lpfc_queue *qp = NULL;
944 struct lpfc_sli_ring *pring;
945 struct lpfc_sli *psli;
950 init_completion(&online_compl);
951 rc = lpfc_workq_post_event(phba, &status, &online_compl,
952 LPFC_EVT_OFFLINE_PREP);
956 wait_for_completion(&online_compl);
963 /* Wait a little for things to settle down, but not
964 * long enough for dev loss timeout to expire.
966 if (phba->sli_rev != LPFC_SLI_REV4) {
967 for (i = 0; i < psli->num_rings; i++) {
968 pring = &psli->sli3_ring[i];
969 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
974 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
978 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
984 init_completion(&online_compl);
985 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
989 wait_for_completion(&online_compl);
998 * lpfc_selective_reset - Offline then onlines the port
999 * @phba: lpfc_hba pointer.
1002 * If the port is configured to allow a reset then the hba is brought
1003 * offline then online.
1006 * Assumes any error from lpfc_do_offline() will be negative.
1007 * Do not make this function static.
1010 * lpfc_do_offline() return code if not zero
1011 * -EIO reset not configured or error posting the event
1015 lpfc_selective_reset(struct lpfc_hba *phba)
1017 struct completion online_compl;
1021 if (!phba->cfg_enable_hba_reset)
1024 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1025 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1031 init_completion(&online_compl);
1032 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1037 wait_for_completion(&online_compl);
1046 * lpfc_issue_reset - Selectively resets an adapter
1047 * @dev: class device that is converted into a Scsi_host.
1048 * @attr: device attribute, not used.
1049 * @buf: containing the string "selective".
1050 * @count: unused variable.
1053 * If the buf contains the string "selective" then lpfc_selective_reset()
1054 * is called to perform the reset.
1057 * Assumes any error from lpfc_selective_reset() will be negative.
1058 * If lpfc_selective_reset() returns zero then the length of the buffer
1059 * is returned which indicates success
1062 * -EINVAL if the buffer does not contain the string "selective"
1063 * length of buf if lpfc-selective_reset() if the call succeeds
1064 * return value of lpfc_selective_reset() if the call fails
1067 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1068 const char *buf, size_t count)
1070 struct Scsi_Host *shost = class_to_shost(dev);
1071 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1072 struct lpfc_hba *phba = vport->phba;
1073 int status = -EINVAL;
1075 if (!phba->cfg_enable_hba_reset)
1078 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1079 status = phba->lpfc_selective_reset(phba);
1088 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1089 * @phba: lpfc_hba pointer.
1092 * SLI4 interface type-2 device to wait on the sliport status register for
1093 * the readyness after performing a firmware reset.
1096 * zero for success, -EPERM when port does not have privilege to perform the
1097 * reset, -EIO when port timeout from recovering from the reset.
1100 * As the caller will interpret the return code by value, be careful in making
1101 * change or addition to return codes.
1104 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1106 struct lpfc_register portstat_reg = {0};
1110 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1111 &portstat_reg.word0);
1113 /* verify if privileged for the request operation */
1114 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1115 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1118 /* wait for the SLI port firmware ready after firmware reset */
1119 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1121 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1122 &portstat_reg.word0);
1123 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1125 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1127 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1132 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1139 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1140 * @phba: lpfc_hba pointer.
1143 * Request SLI4 interface type-2 device to perform a physical register set
1150 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1152 struct completion online_compl;
1153 struct pci_dev *pdev = phba->pcidev;
1154 uint32_t before_fc_flag;
1155 uint32_t sriov_nr_virtfn;
1157 int status = 0, rc = 0;
1158 int job_posted = 1, sriov_err;
1160 if (!phba->cfg_enable_hba_reset)
1163 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1164 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1165 LPFC_SLI_INTF_IF_TYPE_2))
1168 /* Keep state if we need to restore back */
1169 before_fc_flag = phba->pport->fc_flag;
1170 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1172 /* Disable SR-IOV virtual functions if enabled */
1173 if (phba->cfg_sriov_nr_virtfn) {
1174 pci_disable_sriov(pdev);
1175 phba->cfg_sriov_nr_virtfn = 0;
1178 if (opcode == LPFC_FW_DUMP)
1179 phba->hba_flag |= HBA_FW_DUMP_OP;
1181 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1184 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1188 /* wait for the device to be quiesced before firmware reset */
1191 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1192 LPFC_CTL_PDEV_CTL_OFFSET);
1194 if (opcode == LPFC_FW_DUMP)
1195 reg_val |= LPFC_FW_DUMP_REQUEST;
1196 else if (opcode == LPFC_FW_RESET)
1197 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1198 else if (opcode == LPFC_DV_RESET)
1199 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1201 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1202 LPFC_CTL_PDEV_CTL_OFFSET);
1204 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1206 /* delay driver action following IF_TYPE_2 reset */
1207 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1210 /* no privilege for reset */
1211 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1212 "3150 No privilege to perform the requested "
1213 "access: x%x\n", reg_val);
1214 } else if (rc == -EIO) {
1215 /* reset failed, there is nothing more we can do */
1216 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1217 "3153 Fail to perform the requested "
1218 "access: x%x\n", reg_val);
1222 /* keep the original port state */
1223 if (before_fc_flag & FC_OFFLINE_MODE)
1226 init_completion(&online_compl);
1227 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1232 wait_for_completion(&online_compl);
1235 /* in any case, restore the virtual functions enabled as before */
1236 if (sriov_nr_virtfn) {
1238 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1240 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1243 /* return proper error code */
1254 * lpfc_nport_evt_cnt_show - Return the number of nport events
1255 * @dev: class device that is converted into a Scsi_host.
1256 * @attr: device attribute, not used.
1257 * @buf: on return contains the ascii number of nport events.
1259 * Returns: size of formatted string.
1262 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1265 struct Scsi_Host *shost = class_to_shost(dev);
1266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1267 struct lpfc_hba *phba = vport->phba;
1269 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1273 * lpfc_board_mode_show - Return the state of the board
1274 * @dev: class device that is converted into a Scsi_host.
1275 * @attr: device attribute, not used.
1276 * @buf: on return contains the state of the adapter.
1278 * Returns: size of formatted string.
1281 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1284 struct Scsi_Host *shost = class_to_shost(dev);
1285 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1286 struct lpfc_hba *phba = vport->phba;
1289 if (phba->link_state == LPFC_HBA_ERROR)
1291 else if (phba->link_state == LPFC_WARM_START)
1292 state = "warm start";
1293 else if (phba->link_state == LPFC_INIT_START)
1298 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1302 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1303 * @dev: class device that is converted into a Scsi_host.
1304 * @attr: device attribute, not used.
1305 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1306 * @count: unused variable.
1309 * -EACCES if enable hba reset not enabled
1310 * -EINVAL if the buffer does not contain a valid string (see above)
1311 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1312 * buf length greater than zero indicates success
1315 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1316 const char *buf, size_t count)
1318 struct Scsi_Host *shost = class_to_shost(dev);
1319 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1320 struct lpfc_hba *phba = vport->phba;
1321 struct completion online_compl;
1322 char *board_mode_str = NULL;
1326 if (!phba->cfg_enable_hba_reset) {
1328 goto board_mode_out;
1331 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1332 "3050 lpfc_board_mode set to %s\n", buf);
1334 init_completion(&online_compl);
1336 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1337 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1341 goto board_mode_out;
1343 wait_for_completion(&online_compl);
1344 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1345 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1346 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1347 if (phba->sli_rev == LPFC_SLI_REV4)
1350 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1351 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1352 if (phba->sli_rev == LPFC_SLI_REV4)
1355 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1356 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1357 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1358 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1359 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1360 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1361 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1369 board_mode_str = strchr(buf, '\n');
1371 *board_mode_str = '\0';
1372 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1373 "3097 Failed \"%s\", status(%d), "
1375 buf, status, phba->pport->fc_flag);
1381 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1382 * @phba: pointer to the adapter structure.
1383 * @mxri: max xri count.
1384 * @axri: available xri count.
1385 * @mrpi: max rpi count.
1386 * @arpi: available rpi count.
1387 * @mvpi: max vpi count.
1388 * @avpi: available vpi count.
1391 * If an integer pointer for an count is not null then the value for the
1392 * count is returned.
1399 lpfc_get_hba_info(struct lpfc_hba *phba,
1400 uint32_t *mxri, uint32_t *axri,
1401 uint32_t *mrpi, uint32_t *arpi,
1402 uint32_t *mvpi, uint32_t *avpi)
1404 struct lpfc_mbx_read_config *rd_config;
1405 LPFC_MBOXQ_t *pmboxq;
1411 * prevent udev from issuing mailbox commands until the port is
1414 if (phba->link_state < LPFC_LINK_DOWN ||
1415 !phba->mbox_mem_pool ||
1416 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1419 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1422 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1425 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1427 pmb = &pmboxq->u.mb;
1428 pmb->mbxCommand = MBX_READ_CONFIG;
1429 pmb->mbxOwner = OWN_HOST;
1430 pmboxq->context1 = NULL;
1432 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1433 rc = MBX_NOT_FINISHED;
1435 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1437 if (rc != MBX_SUCCESS) {
1438 if (rc != MBX_TIMEOUT)
1439 mempool_free(pmboxq, phba->mbox_mem_pool);
1443 if (phba->sli_rev == LPFC_SLI_REV4) {
1444 rd_config = &pmboxq->u.mqe.un.rd_config;
1446 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1448 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1449 phba->sli4_hba.max_cfg_param.rpi_used;
1451 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1453 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1454 phba->sli4_hba.max_cfg_param.xri_used;
1456 /* Account for differences with SLI-3. Get vpi count from
1457 * mailbox data and subtract one for max vpi value.
1459 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1460 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1465 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1468 *mrpi = pmb->un.varRdConfig.max_rpi;
1470 *arpi = pmb->un.varRdConfig.avail_rpi;
1472 *mxri = pmb->un.varRdConfig.max_xri;
1474 *axri = pmb->un.varRdConfig.avail_xri;
1476 *mvpi = pmb->un.varRdConfig.max_vpi;
1478 *avpi = pmb->un.varRdConfig.avail_vpi;
1481 mempool_free(pmboxq, phba->mbox_mem_pool);
1486 * lpfc_max_rpi_show - Return maximum rpi
1487 * @dev: class device that is converted into a Scsi_host.
1488 * @attr: device attribute, not used.
1489 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1492 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1493 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1494 * to "Unknown" and the buffer length is returned, therefore the caller
1495 * must check for "Unknown" in the buffer to detect a failure.
1497 * Returns: size of formatted string.
1500 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1503 struct Scsi_Host *shost = class_to_shost(dev);
1504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1505 struct lpfc_hba *phba = vport->phba;
1508 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1509 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1510 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1514 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1515 * @dev: class device that is converted into a Scsi_host.
1516 * @attr: device attribute, not used.
1517 * @buf: containing the used rpi count in decimal or "Unknown".
1520 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1521 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1522 * to "Unknown" and the buffer length is returned, therefore the caller
1523 * must check for "Unknown" in the buffer to detect a failure.
1525 * Returns: size of formatted string.
1528 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1531 struct Scsi_Host *shost = class_to_shost(dev);
1532 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1533 struct lpfc_hba *phba = vport->phba;
1536 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1537 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1538 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1542 * lpfc_max_xri_show - Return maximum xri
1543 * @dev: class device that is converted into a Scsi_host.
1544 * @attr: device attribute, not used.
1545 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1548 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1549 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1550 * to "Unknown" and the buffer length is returned, therefore the caller
1551 * must check for "Unknown" in the buffer to detect a failure.
1553 * Returns: size of formatted string.
1556 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1559 struct Scsi_Host *shost = class_to_shost(dev);
1560 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1561 struct lpfc_hba *phba = vport->phba;
1564 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1565 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1566 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1570 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1571 * @dev: class device that is converted into a Scsi_host.
1572 * @attr: device attribute, not used.
1573 * @buf: on return contains the used xri count in decimal or "Unknown".
1576 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1577 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1578 * to "Unknown" and the buffer length is returned, therefore the caller
1579 * must check for "Unknown" in the buffer to detect a failure.
1581 * Returns: size of formatted string.
1584 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1587 struct Scsi_Host *shost = class_to_shost(dev);
1588 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1589 struct lpfc_hba *phba = vport->phba;
1592 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1593 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1594 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1598 * lpfc_max_vpi_show - Return maximum vpi
1599 * @dev: class device that is converted into a Scsi_host.
1600 * @attr: device attribute, not used.
1601 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1604 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1605 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1606 * to "Unknown" and the buffer length is returned, therefore the caller
1607 * must check for "Unknown" in the buffer to detect a failure.
1609 * Returns: size of formatted string.
1612 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1615 struct Scsi_Host *shost = class_to_shost(dev);
1616 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1617 struct lpfc_hba *phba = vport->phba;
1620 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1621 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1622 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1626 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1627 * @dev: class device that is converted into a Scsi_host.
1628 * @attr: device attribute, not used.
1629 * @buf: on return contains the used vpi count in decimal or "Unknown".
1632 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1633 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1634 * to "Unknown" and the buffer length is returned, therefore the caller
1635 * must check for "Unknown" in the buffer to detect a failure.
1637 * Returns: size of formatted string.
1640 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1643 struct Scsi_Host *shost = class_to_shost(dev);
1644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1645 struct lpfc_hba *phba = vport->phba;
1648 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1649 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1650 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1654 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1655 * @dev: class device that is converted into a Scsi_host.
1656 * @attr: device attribute, not used.
1657 * @buf: text that must be interpreted to determine if npiv is supported.
1660 * Buffer will contain text indicating npiv is not suppoerted on the port,
1661 * the port is an NPIV physical port, or it is an npiv virtual port with
1662 * the id of the vport.
1664 * Returns: size of formatted string.
1667 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1670 struct Scsi_Host *shost = class_to_shost(dev);
1671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1672 struct lpfc_hba *phba = vport->phba;
1674 if (!(phba->max_vpi))
1675 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1676 if (vport->port_type == LPFC_PHYSICAL_PORT)
1677 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1678 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1682 * lpfc_poll_show - Return text about poll support for the adapter
1683 * @dev: class device that is converted into a Scsi_host.
1684 * @attr: device attribute, not used.
1685 * @buf: on return contains the cfg_poll in hex.
1688 * cfg_poll should be a lpfc_polling_flags type.
1690 * Returns: size of formatted string.
1693 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1696 struct Scsi_Host *shost = class_to_shost(dev);
1697 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1698 struct lpfc_hba *phba = vport->phba;
1700 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1704 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1705 * @dev: class device that is converted into a Scsi_host.
1706 * @attr: device attribute, not used.
1707 * @buf: one or more lpfc_polling_flags values.
1711 * buf contents converted to integer and checked for a valid value.
1714 * -EINVAL if the buffer connot be converted or is out of range
1715 * length of the buf on success
1718 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1719 const char *buf, size_t count)
1721 struct Scsi_Host *shost = class_to_shost(dev);
1722 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1723 struct lpfc_hba *phba = vport->phba;
1728 if (!isdigit(buf[0]))
1731 if (sscanf(buf, "%i", &val) != 1)
1734 if ((val & 0x3) != val)
1737 if (phba->sli_rev == LPFC_SLI_REV4)
1740 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1741 "3051 lpfc_poll changed from %d to %d\n",
1742 phba->cfg_poll, val);
1744 spin_lock_irq(&phba->hbalock);
1746 old_val = phba->cfg_poll;
1748 if (val & ENABLE_FCP_RING_POLLING) {
1749 if ((val & DISABLE_FCP_RING_INT) &&
1750 !(old_val & DISABLE_FCP_RING_INT)) {
1751 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1752 spin_unlock_irq(&phba->hbalock);
1755 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1756 writel(creg_val, phba->HCregaddr);
1757 readl(phba->HCregaddr); /* flush */
1759 lpfc_poll_start_timer(phba);
1761 } else if (val != 0x0) {
1762 spin_unlock_irq(&phba->hbalock);
1766 if (!(val & DISABLE_FCP_RING_INT) &&
1767 (old_val & DISABLE_FCP_RING_INT))
1769 spin_unlock_irq(&phba->hbalock);
1770 del_timer(&phba->fcp_poll_timer);
1771 spin_lock_irq(&phba->hbalock);
1772 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1773 spin_unlock_irq(&phba->hbalock);
1776 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1777 writel(creg_val, phba->HCregaddr);
1778 readl(phba->HCregaddr); /* flush */
1781 phba->cfg_poll = val;
1783 spin_unlock_irq(&phba->hbalock);
1789 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1790 * @dev: class unused variable.
1791 * @attr: device attribute, not used.
1792 * @buf: on return contains the module description text.
1794 * Returns: size of formatted string.
1797 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1800 struct Scsi_Host *shost = class_to_shost(dev);
1801 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1802 struct lpfc_hba *phba = vport->phba;
1804 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1808 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1809 * @dev: class unused variable.
1810 * @attr: device attribute, not used.
1811 * @buf: on return contains the module description text.
1813 * Returns: size of formatted string.
1816 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1819 struct Scsi_Host *shost = class_to_shost(dev);
1820 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1821 struct lpfc_hba *phba = vport->phba;
1823 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1827 * lpfc_dss_show - Return the current state of dss and the configured state
1828 * @dev: class converted to a Scsi_host structure.
1829 * @attr: device attribute, not used.
1830 * @buf: on return contains the formatted text.
1832 * Returns: size of formatted string.
1835 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1838 struct Scsi_Host *shost = class_to_shost(dev);
1839 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1840 struct lpfc_hba *phba = vport->phba;
1842 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1843 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1844 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1849 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1850 * @dev: class converted to a Scsi_host structure.
1851 * @attr: device attribute, not used.
1852 * @buf: on return contains the formatted support level.
1855 * Returns the maximum number of virtual functions a physical function can
1856 * support, 0 will be returned if called on virtual function.
1858 * Returns: size of formatted string.
1861 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1862 struct device_attribute *attr,
1865 struct Scsi_Host *shost = class_to_shost(dev);
1866 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1867 struct lpfc_hba *phba = vport->phba;
1868 uint16_t max_nr_virtfn;
1870 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1871 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1874 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1876 return val >= min && val <= max;
1880 * lpfc_param_show - Return a cfg attribute value in decimal
1883 * Macro that given an attr e.g. hba_queue_depth expands
1884 * into a function with the name lpfc_hba_queue_depth_show.
1886 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1887 * @dev: class device that is converted into a Scsi_host.
1888 * @attr: device attribute, not used.
1889 * @buf: on return contains the attribute value in decimal.
1891 * Returns: size of formatted string.
1893 #define lpfc_param_show(attr) \
1895 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1898 struct Scsi_Host *shost = class_to_shost(dev);\
1899 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1900 struct lpfc_hba *phba = vport->phba;\
1901 return snprintf(buf, PAGE_SIZE, "%d\n",\
1906 * lpfc_param_hex_show - Return a cfg attribute value in hex
1909 * Macro that given an attr e.g. hba_queue_depth expands
1910 * into a function with the name lpfc_hba_queue_depth_show
1912 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1913 * @dev: class device that is converted into a Scsi_host.
1914 * @attr: device attribute, not used.
1915 * @buf: on return contains the attribute value in hexadecimal.
1917 * Returns: size of formatted string.
1919 #define lpfc_param_hex_show(attr) \
1921 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1924 struct Scsi_Host *shost = class_to_shost(dev);\
1925 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1926 struct lpfc_hba *phba = vport->phba;\
1928 val = phba->cfg_##attr;\
1929 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1934 * lpfc_param_init - Initializes a cfg attribute
1937 * Macro that given an attr e.g. hba_queue_depth expands
1938 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1939 * takes a default argument, a minimum and maximum argument.
1941 * lpfc_##attr##_init: Initializes an attribute.
1942 * @phba: pointer the the adapter structure.
1943 * @val: integer attribute value.
1945 * Validates the min and max values then sets the adapter config field
1946 * accordingly, or uses the default if out of range and prints an error message.
1950 * -EINVAL if default used
1952 #define lpfc_param_init(attr, default, minval, maxval) \
1954 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1956 if (lpfc_rangecheck(val, minval, maxval)) {\
1957 phba->cfg_##attr = val;\
1960 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1961 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1962 "allowed range is ["#minval", "#maxval"]\n", val); \
1963 phba->cfg_##attr = default;\
1968 * lpfc_param_set - Set a cfg attribute value
1971 * Macro that given an attr e.g. hba_queue_depth expands
1972 * into a function with the name lpfc_hba_queue_depth_set
1974 * lpfc_##attr##_set: Sets an attribute value.
1975 * @phba: pointer the the adapter structure.
1976 * @val: integer attribute value.
1979 * Validates the min and max values then sets the
1980 * adapter config field if in the valid range. prints error message
1981 * and does not set the parameter if invalid.
1985 * -EINVAL if val is invalid
1987 #define lpfc_param_set(attr, default, minval, maxval) \
1989 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1991 if (lpfc_rangecheck(val, minval, maxval)) {\
1992 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1993 "3052 lpfc_" #attr " changed from %d to %d\n", \
1994 phba->cfg_##attr, val); \
1995 phba->cfg_##attr = val;\
1998 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1999 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2000 "allowed range is ["#minval", "#maxval"]\n", val); \
2005 * lpfc_param_store - Set a vport attribute value
2008 * Macro that given an attr e.g. hba_queue_depth expands
2009 * into a function with the name lpfc_hba_queue_depth_store.
2011 * lpfc_##attr##_store: Set an sttribute value.
2012 * @dev: class device that is converted into a Scsi_host.
2013 * @attr: device attribute, not used.
2014 * @buf: contains the attribute value in ascii.
2018 * Convert the ascii text number to an integer, then
2019 * use the lpfc_##attr##_set function to set the value.
2022 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2023 * length of buffer upon success.
2025 #define lpfc_param_store(attr) \
2027 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2028 const char *buf, size_t count) \
2030 struct Scsi_Host *shost = class_to_shost(dev);\
2031 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2032 struct lpfc_hba *phba = vport->phba;\
2034 if (!isdigit(buf[0]))\
2036 if (sscanf(buf, "%i", &val) != 1)\
2038 if (lpfc_##attr##_set(phba, val) == 0) \
2039 return strlen(buf);\
2045 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2048 * Macro that given an attr e.g. hba_queue_depth expands
2049 * into a function with the name lpfc_hba_queue_depth_show
2051 * lpfc_##attr##_show: prints the attribute value in decimal.
2052 * @dev: class device that is converted into a Scsi_host.
2053 * @attr: device attribute, not used.
2054 * @buf: on return contains the attribute value in decimal.
2056 * Returns: length of formatted string.
2058 #define lpfc_vport_param_show(attr) \
2060 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2063 struct Scsi_Host *shost = class_to_shost(dev);\
2064 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2065 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2069 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2072 * Macro that given an attr e.g.
2073 * hba_queue_depth expands into a function with the name
2074 * lpfc_hba_queue_depth_show
2076 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2077 * @dev: class device that is converted into a Scsi_host.
2078 * @attr: device attribute, not used.
2079 * @buf: on return contains the attribute value in hexadecimal.
2081 * Returns: length of formatted string.
2083 #define lpfc_vport_param_hex_show(attr) \
2085 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2088 struct Scsi_Host *shost = class_to_shost(dev);\
2089 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2090 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2094 * lpfc_vport_param_init - Initialize a vport cfg attribute
2097 * Macro that given an attr e.g. hba_queue_depth expands
2098 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2099 * takes a default argument, a minimum and maximum argument.
2101 * lpfc_##attr##_init: validates the min and max values then sets the
2102 * adapter config field accordingly, or uses the default if out of range
2103 * and prints an error message.
2104 * @phba: pointer the the adapter structure.
2105 * @val: integer attribute value.
2109 * -EINVAL if default used
2111 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2113 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2115 if (lpfc_rangecheck(val, minval, maxval)) {\
2116 vport->cfg_##attr = val;\
2119 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2120 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2121 "allowed range is ["#minval", "#maxval"]\n", val); \
2122 vport->cfg_##attr = default;\
2127 * lpfc_vport_param_set - Set a vport cfg attribute
2130 * Macro that given an attr e.g. hba_queue_depth expands
2131 * into a function with the name lpfc_hba_queue_depth_set
2133 * lpfc_##attr##_set: validates the min and max values then sets the
2134 * adapter config field if in the valid range. prints error message
2135 * and does not set the parameter if invalid.
2136 * @phba: pointer the the adapter structure.
2137 * @val: integer attribute value.
2141 * -EINVAL if val is invalid
2143 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2145 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2147 if (lpfc_rangecheck(val, minval, maxval)) {\
2148 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2149 "3053 lpfc_" #attr \
2150 " changed from %d (x%x) to %d (x%x)\n", \
2151 vport->cfg_##attr, vport->cfg_##attr, \
2153 vport->cfg_##attr = val;\
2156 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2157 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2158 "allowed range is ["#minval", "#maxval"]\n", val); \
2163 * lpfc_vport_param_store - Set a vport attribute
2166 * Macro that given an attr e.g. hba_queue_depth
2167 * expands into a function with the name lpfc_hba_queue_depth_store
2169 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2170 * use the lpfc_##attr##_set function to set the value.
2171 * @cdev: class device that is converted into a Scsi_host.
2172 * @buf: contains the attribute value in decimal.
2176 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2177 * length of buffer upon success.
2179 #define lpfc_vport_param_store(attr) \
2181 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2182 const char *buf, size_t count) \
2184 struct Scsi_Host *shost = class_to_shost(dev);\
2185 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2187 if (!isdigit(buf[0]))\
2189 if (sscanf(buf, "%i", &val) != 1)\
2191 if (lpfc_##attr##_set(vport, val) == 0) \
2192 return strlen(buf);\
2198 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2199 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2200 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2201 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2202 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2203 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2204 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2205 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2206 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2207 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2208 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2209 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2210 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2211 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2212 lpfc_link_state_store);
2213 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2214 lpfc_option_rom_version_show, NULL);
2215 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2216 lpfc_num_discovered_ports_show, NULL);
2217 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2218 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2219 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2220 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2221 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2222 lpfc_board_mode_show, lpfc_board_mode_store);
2223 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2224 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2225 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2226 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2227 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2228 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2229 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2230 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2231 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2232 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2233 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2234 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2235 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2236 lpfc_sriov_hw_max_virtfn_show, NULL);
2237 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2238 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2241 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2244 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2246 * @cnt: Length of string.
2247 * @wwn: Array to receive converted wwn value.
2250 * -EINVAL if the buffer does not contain a valid wwn
2254 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2258 /* Count may include a LF at end of string */
2259 if (buf[cnt-1] == '\n')
2262 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2263 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2266 memset(wwn, 0, WWN_SZ);
2268 /* Validate and store the new name */
2269 for (i = 0, j = 0; i < 16; i++) {
2270 if ((*buf >= 'a') && (*buf <= 'f'))
2271 j = ((j << 4) | ((*buf++ - 'a') + 10));
2272 else if ((*buf >= 'A') && (*buf <= 'F'))
2273 j = ((j << 4) | ((*buf++ - 'A') + 10));
2274 else if ((*buf >= '0') && (*buf <= '9'))
2275 j = ((j << 4) | (*buf++ - '0'));
2279 wwn[i/2] = j & 0xff;
2286 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2287 * @dev: class device that is converted into a Scsi_host.
2288 * @attr: device attribute, not used.
2289 * @buf: containing the string lpfc_soft_wwn_key.
2290 * @count: must be size of lpfc_soft_wwn_key.
2293 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2294 * length of buf indicates success
2297 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2298 const char *buf, size_t count)
2300 struct Scsi_Host *shost = class_to_shost(dev);
2301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2302 struct lpfc_hba *phba = vport->phba;
2303 unsigned int cnt = count;
2304 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2305 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2308 * We're doing a simple sanity check for soft_wwpn setting.
2309 * We require that the user write a specific key to enable
2310 * the soft_wwpn attribute to be settable. Once the attribute
2311 * is written, the enable key resets. If further updates are
2312 * desired, the key must be written again to re-enable the
2315 * The "key" is not secret - it is a hardcoded string shown
2316 * here. The intent is to protect against the random user or
2317 * application that is just writing attributes.
2319 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2320 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2321 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2322 " be enabled: fawwpn is enabled\n");
2326 /* count may include a LF at end of string */
2327 if (buf[cnt-1] == '\n')
2330 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2331 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2334 phba->soft_wwn_enable = 1;
2336 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2337 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2339 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2340 " The soft_wwpn feature is not supported by Broadcom.");
2344 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2345 lpfc_soft_wwn_enable_store);
2348 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2349 * @dev: class device that is converted into a Scsi_host.
2350 * @attr: device attribute, not used.
2351 * @buf: on return contains the wwpn in hexadecimal.
2353 * Returns: size of formatted string.
2356 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2359 struct Scsi_Host *shost = class_to_shost(dev);
2360 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2361 struct lpfc_hba *phba = vport->phba;
2363 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2364 (unsigned long long)phba->cfg_soft_wwpn);
2368 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2369 * @dev class device that is converted into a Scsi_host.
2370 * @attr: device attribute, not used.
2371 * @buf: contains the wwpn in hexadecimal.
2372 * @count: number of wwpn bytes in buf
2375 * -EACCES hba reset not enabled, adapter over temp
2376 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2377 * -EIO error taking adapter offline or online
2378 * value of count on success
2381 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2382 const char *buf, size_t count)
2384 struct Scsi_Host *shost = class_to_shost(dev);
2385 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2386 struct lpfc_hba *phba = vport->phba;
2387 struct completion online_compl;
2388 int stat1 = 0, stat2 = 0;
2389 unsigned int cnt = count;
2393 if (!phba->cfg_enable_hba_reset)
2395 spin_lock_irq(&phba->hbalock);
2396 if (phba->over_temp_state == HBA_OVER_TEMP) {
2397 spin_unlock_irq(&phba->hbalock);
2400 spin_unlock_irq(&phba->hbalock);
2401 /* count may include a LF at end of string */
2402 if (buf[cnt-1] == '\n')
2405 if (!phba->soft_wwn_enable)
2408 /* lock setting wwpn, wwnn down */
2409 phba->soft_wwn_enable = 0;
2411 rc = lpfc_wwn_set(buf, cnt, wwpn);
2413 /* not able to set wwpn, unlock it */
2414 phba->soft_wwn_enable = 1;
2418 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2419 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2420 if (phba->cfg_soft_wwnn)
2421 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2423 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2424 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2426 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2428 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2429 "0463 lpfc_soft_wwpn attribute set failed to "
2430 "reinit adapter - %d\n", stat1);
2431 init_completion(&online_compl);
2432 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2437 wait_for_completion(&online_compl);
2439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2440 "0464 lpfc_soft_wwpn attribute set failed to "
2441 "reinit adapter - %d\n", stat2);
2442 return (stat1 || stat2) ? -EIO : count;
2444 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2445 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2448 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2449 * @dev: class device that is converted into a Scsi_host.
2450 * @attr: device attribute, not used.
2451 * @buf: on return contains the wwnn in hexadecimal.
2453 * Returns: size of formatted string.
2456 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2459 struct Scsi_Host *shost = class_to_shost(dev);
2460 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2461 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2462 (unsigned long long)phba->cfg_soft_wwnn);
2466 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2467 * @cdev: class device that is converted into a Scsi_host.
2468 * @buf: contains the ww node name in hexadecimal.
2469 * @count: number of wwnn bytes in buf.
2472 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2473 * value of count on success
2476 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2477 const char *buf, size_t count)
2479 struct Scsi_Host *shost = class_to_shost(dev);
2480 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2481 unsigned int cnt = count;
2485 /* count may include a LF at end of string */
2486 if (buf[cnt-1] == '\n')
2489 if (!phba->soft_wwn_enable)
2492 rc = lpfc_wwn_set(buf, cnt, wwnn);
2494 /* Allow wwnn to be set many times, as long as the enable
2495 * is set. However, once the wwpn is set, everything locks.
2500 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2502 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2503 "lpfc%d: soft_wwnn set. Value will take effect upon "
2504 "setting of the soft_wwpn\n", phba->brd_no);
2508 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2509 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2512 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2513 * Optimized Access Storage (OAS) operations.
2514 * @dev: class device that is converted into a Scsi_host.
2515 * @attr: device attribute, not used.
2516 * @buf: buffer for passing information.
2522 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2525 struct Scsi_Host *shost = class_to_shost(dev);
2526 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2528 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2529 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2533 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2534 * Optimized Access Storage (OAS) operations.
2535 * @dev: class device that is converted into a Scsi_host.
2536 * @attr: device attribute, not used.
2537 * @buf: buffer for passing information.
2538 * @count: Size of the data buffer.
2541 * -EINVAL count is invalid, invalid wwpn byte invalid
2542 * -EPERM oas is not supported by hba
2543 * value of count on success
2546 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2547 const char *buf, size_t count)
2549 struct Scsi_Host *shost = class_to_shost(dev);
2550 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2551 unsigned int cnt = count;
2552 uint8_t wwpn[WWN_SZ];
2558 /* count may include a LF at end of string */
2559 if (buf[cnt-1] == '\n')
2562 rc = lpfc_wwn_set(buf, cnt, wwpn);
2566 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2567 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2568 if (wwn_to_u64(wwpn) == 0)
2569 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2571 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2572 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2573 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2576 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2577 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2580 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2581 * Optimized Access Storage (OAS) operations.
2582 * @dev: class device that is converted into a Scsi_host.
2583 * @attr: device attribute, not used.
2584 * @buf: buffer for passing information.
2590 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2593 struct Scsi_Host *shost = class_to_shost(dev);
2594 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2596 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2600 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2601 * Optimized Access Storage (OAS) operations.
2602 * @dev: class device that is converted into a Scsi_host.
2603 * @attr: device attribute, not used.
2604 * @buf: buffer for passing information.
2605 * @count: Size of the data buffer.
2608 * -EINVAL count is invalid, invalid wwpn byte invalid
2609 * -EPERM oas is not supported by hba
2610 * value of count on success
2613 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2614 const char *buf, size_t count)
2616 struct Scsi_Host *shost = class_to_shost(dev);
2617 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2618 unsigned int cnt = count;
2625 /* count may include a LF at end of string */
2626 if (buf[cnt-1] == '\n')
2629 ret = kstrtoul(buf, 0, &val);
2630 if (ret || (val > 0x7f))
2634 phba->cfg_oas_priority = (uint8_t)val;
2636 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2639 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2640 lpfc_oas_priority_show, lpfc_oas_priority_store);
2643 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2644 * for Optimized Access Storage (OAS) operations.
2645 * @dev: class device that is converted into a Scsi_host.
2646 * @attr: device attribute, not used.
2647 * @buf: buffer for passing information.
2650 * value of count on success
2653 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2656 struct Scsi_Host *shost = class_to_shost(dev);
2657 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2659 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2660 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2664 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2665 * for Optimized Access Storage (OAS) operations.
2666 * @dev: class device that is converted into a Scsi_host.
2667 * @attr: device attribute, not used.
2668 * @buf: buffer for passing information.
2669 * @count: Size of the data buffer.
2672 * -EINVAL count is invalid, invalid wwpn byte invalid
2673 * -EPERM oas is not supported by hba
2674 * value of count on success
2677 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2678 const char *buf, size_t count)
2680 struct Scsi_Host *shost = class_to_shost(dev);
2681 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2682 unsigned int cnt = count;
2683 uint8_t wwpn[WWN_SZ];
2689 /* count may include a LF at end of string */
2690 if (buf[cnt-1] == '\n')
2693 rc = lpfc_wwn_set(buf, cnt, wwpn);
2697 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2698 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2699 if (wwn_to_u64(wwpn) == 0)
2700 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2702 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2703 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2704 if (phba->cfg_oas_priority == 0)
2705 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2706 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2709 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2710 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2713 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2714 * of whether luns will be enabled or disabled
2715 * for Optimized Access Storage (OAS) operations.
2716 * @dev: class device that is converted into a Scsi_host.
2717 * @attr: device attribute, not used.
2718 * @buf: buffer for passing information.
2721 * size of formatted string.
2724 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2727 struct Scsi_Host *shost = class_to_shost(dev);
2728 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2730 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2734 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2735 * of whether luns will be enabled or disabled
2736 * for Optimized Access Storage (OAS) operations.
2737 * @dev: class device that is converted into a Scsi_host.
2738 * @attr: device attribute, not used.
2739 * @buf: buffer for passing information.
2740 * @count: Size of the data buffer.
2743 * -EINVAL count is invalid, invalid wwpn byte invalid
2744 * -EPERM oas is not supported by hba
2745 * value of count on success
2748 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2749 const char *buf, size_t count)
2751 struct Scsi_Host *shost = class_to_shost(dev);
2752 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2758 if (!isdigit(buf[0]))
2761 if (sscanf(buf, "%i", &val) != 1)
2764 if ((val != 0) && (val != 1))
2767 phba->cfg_oas_lun_state = val;
2770 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2771 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2774 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2775 * Storage (OAS) lun returned by the
2776 * lpfc_oas_lun_show function.
2777 * @dev: class device that is converted into a Scsi_host.
2778 * @attr: device attribute, not used.
2779 * @buf: buffer for passing information.
2782 * size of formatted string.
2785 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2788 struct Scsi_Host *shost = class_to_shost(dev);
2789 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2791 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2794 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2796 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2797 lpfc_oas_lun_status_show, NULL);
2801 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2803 * @phba: lpfc_hba pointer.
2804 * @ndlp: pointer to fcp target node.
2805 * @lun: the fc lun for setting oas state.
2806 * @oas_state: the oas state to be set to the lun.
2810 * -EPERM OAS is not enabled or not supported by this port.
2814 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2815 uint8_t tgt_wwpn[], uint64_t lun,
2816 uint32_t oas_state, uint8_t pri)
2825 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2826 (struct lpfc_name *)tgt_wwpn,
2830 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2831 (struct lpfc_name *)tgt_wwpn, lun, pri);
2838 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2839 * Access Storage (OAS) operations.
2840 * @phba: lpfc_hba pointer.
2841 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2842 * @tgt_wwpn: wwpn of the target associated with the returned lun
2843 * @lun_status: status of the lun returned lun
2845 * Returns the first or next lun enabled for OAS operations for the vport/target
2846 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2847 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2850 * lun that is OAS enabled for the vport/target
2851 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2854 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2855 uint8_t tgt_wwpn[], uint32_t *lun_status,
2860 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2861 return NOT_OAS_ENABLED_LUN;
2862 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2863 phba->sli4_hba.oas_next_vpt_wwpn,
2864 (struct lpfc_name *)
2865 phba->sli4_hba.oas_next_tgt_wwpn,
2866 &phba->sli4_hba.oas_next_lun,
2867 (struct lpfc_name *)vpt_wwpn,
2868 (struct lpfc_name *)tgt_wwpn,
2869 &found_lun, lun_status, lun_pri))
2872 return NOT_OAS_ENABLED_LUN;
2876 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2877 * @phba: lpfc_hba pointer.
2878 * @vpt_wwpn: vport wwpn by reference.
2879 * @tgt_wwpn: target wwpn by reference.
2880 * @lun: the fc lun for setting oas state.
2881 * @oas_state: the oas state to be set to the oas_lun.
2883 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2884 * a lun for OAS operations.
2888 * -ENOMEM: failed to enable an lun for OAS operations
2889 * -EPERM: OAS is not enabled
2892 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2893 uint8_t tgt_wwpn[], uint64_t lun,
2894 uint32_t oas_state, uint8_t pri)
2899 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2905 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2906 * @dev: class device that is converted into a Scsi_host.
2907 * @attr: device attribute, not used.
2908 * @buf: buffer for passing information.
2910 * This routine returns a lun enabled for OAS each time the function
2914 * SUCCESS: size of formatted string.
2915 * -EFAULT: target or vport wwpn was not set properly.
2916 * -EPERM: oas is not enabled.
2919 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2922 struct Scsi_Host *shost = class_to_shost(dev);
2923 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2931 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2932 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2935 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2936 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2939 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2940 phba->cfg_oas_tgt_wwpn,
2941 &phba->cfg_oas_lun_status,
2942 &phba->cfg_oas_priority);
2943 if (oas_lun != NOT_OAS_ENABLED_LUN)
2944 phba->cfg_oas_flags |= OAS_LUN_VALID;
2946 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2952 * lpfc_oas_lun_store - Sets the OAS state for lun
2953 * @dev: class device that is converted into a Scsi_host.
2954 * @attr: device attribute, not used.
2955 * @buf: buffer for passing information.
2957 * This function sets the OAS state for lun. Before this function is called,
2958 * the vport wwpn, target wwpn, and oas state need to be set.
2961 * SUCCESS: size of formatted string.
2962 * -EFAULT: target or vport wwpn was not set properly.
2963 * -EPERM: oas is not enabled.
2964 * size of formatted string.
2967 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2968 const char *buf, size_t count)
2970 struct Scsi_Host *shost = class_to_shost(dev);
2971 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2979 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2982 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2985 if (!isdigit(buf[0]))
2988 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2991 pri = phba->cfg_oas_priority;
2993 pri = phba->cfg_XLanePriority;
2995 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2996 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2997 "priority 0x%x with oas state %d\n",
2998 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2999 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3000 pri, phba->cfg_oas_lun_state);
3002 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3003 phba->cfg_oas_tgt_wwpn, scsi_lun,
3004 phba->cfg_oas_lun_state, pri);
3010 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3011 lpfc_oas_lun_show, lpfc_oas_lun_store);
3013 int lpfc_enable_nvmet_cnt;
3014 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3015 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3016 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3017 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3018 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3020 static int lpfc_poll = 0;
3021 module_param(lpfc_poll, int, S_IRUGO);
3022 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3024 " 1 - poll with interrupts enabled"
3025 " 3 - poll and disable FCP ring interrupts");
3027 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3028 lpfc_poll_show, lpfc_poll_store);
3030 int lpfc_no_hba_reset_cnt;
3031 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3032 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3033 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3034 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3036 LPFC_ATTR(sli_mode, 0, 0, 3,
3037 "SLI mode selector:"
3038 " 0 - auto (SLI-3 if supported),"
3039 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3040 " 3 - select SLI-3");
3042 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3043 "Enable NPIV functionality");
3045 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3046 "FCF Fast failover=1 Priority failover=2");
3049 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3050 # 0x0 = disabled, XRI/OXID use not tracked.
3051 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3052 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3054 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3055 "Enable RRQ functionality");
3058 # lpfc_suppress_link_up: Bring link up at initialization
3059 # 0x0 = bring link up (issue MBX_INIT_LINK)
3060 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3061 # 0x2 = never bring up link
3062 # Default value is 0.
3064 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3065 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3066 "Suppress Link Up at initialization");
3068 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3076 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3078 struct Scsi_Host *shost = class_to_shost(dev);
3079 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3081 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3084 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3085 lpfc_iocb_hw_show, NULL);
3087 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3089 struct Scsi_Host *shost = class_to_shost(dev);
3090 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3091 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3093 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
3096 static DEVICE_ATTR(txq_hw, S_IRUGO,
3097 lpfc_txq_hw_show, NULL);
3099 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3102 struct Scsi_Host *shost = class_to_shost(dev);
3103 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3104 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3106 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
3109 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3110 lpfc_txcmplq_hw_show, NULL);
3112 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3113 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3116 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3117 # until the timer expires. Value range is [0,255]. Default value is 30.
3119 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3120 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3121 module_param(lpfc_nodev_tmo, int, 0);
3122 MODULE_PARM_DESC(lpfc_nodev_tmo,
3123 "Seconds driver will hold I/O waiting "
3124 "for a device to come back");
3127 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3128 * @dev: class converted to a Scsi_host structure.
3129 * @attr: device attribute, not used.
3130 * @buf: on return contains the dev loss timeout in decimal.
3132 * Returns: size of formatted string.
3135 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3138 struct Scsi_Host *shost = class_to_shost(dev);
3139 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3141 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3145 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3146 * @vport: lpfc vport structure pointer.
3147 * @val: contains the nodev timeout value.
3150 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3151 * a kernel error message is printed and zero is returned.
3152 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3153 * Otherwise nodev tmo is set to the default value.
3156 * zero if already set or if val is in range
3157 * -EINVAL val out of range
3160 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3162 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3163 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3164 if (val != LPFC_DEF_DEVLOSS_TMO)
3165 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3166 "0407 Ignoring lpfc_nodev_tmo module "
3167 "parameter because lpfc_devloss_tmo "
3172 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3173 vport->cfg_nodev_tmo = val;
3174 vport->cfg_devloss_tmo = val;
3177 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3178 "0400 lpfc_nodev_tmo attribute cannot be set to"
3179 " %d, allowed range is [%d, %d]\n",
3180 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3181 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3186 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3187 * @vport: lpfc vport structure pointer.
3190 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3193 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3195 struct Scsi_Host *shost;
3196 struct lpfc_nodelist *ndlp;
3198 shost = lpfc_shost_from_vport(vport);
3199 spin_lock_irq(shost->host_lock);
3200 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3201 if (!NLP_CHK_NODE_ACT(ndlp))
3204 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3206 spin_unlock_irq(shost->host_lock);
3210 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3211 * @vport: lpfc vport structure pointer.
3212 * @val: contains the tmo value.
3215 * If the devloss tmo is already set or the vport dev loss tmo has changed
3216 * then a kernel error message is printed and zero is returned.
3217 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3218 * Otherwise nodev tmo is set to the default value.
3221 * zero if already set or if val is in range
3222 * -EINVAL val out of range
3225 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3227 if (vport->dev_loss_tmo_changed ||
3228 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3229 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3230 "0401 Ignoring change to lpfc_nodev_tmo "
3231 "because lpfc_devloss_tmo is set.\n");
3234 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3235 vport->cfg_nodev_tmo = val;
3236 vport->cfg_devloss_tmo = val;
3238 * For compat: set the fc_host dev loss so new rports
3239 * will get the value.
3241 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3242 lpfc_update_rport_devloss_tmo(vport);
3245 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3246 "0403 lpfc_nodev_tmo attribute cannot be set to "
3247 "%d, allowed range is [%d, %d]\n",
3248 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3252 lpfc_vport_param_store(nodev_tmo)
3254 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3255 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3258 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3259 # disappear until the timer expires. Value range is [0,255]. Default
3262 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3263 MODULE_PARM_DESC(lpfc_devloss_tmo,
3264 "Seconds driver will hold I/O waiting "
3265 "for a device to come back");
3266 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3267 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3268 lpfc_vport_param_show(devloss_tmo)
3271 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3272 * @vport: lpfc vport structure pointer.
3273 * @val: contains the tmo value.
3276 * If val is in a valid range then set the vport nodev tmo,
3277 * devloss tmo, also set the vport dev loss tmo changed flag.
3278 * Else a kernel error message is printed.
3281 * zero if val is in range
3282 * -EINVAL val out of range
3285 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3287 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3288 vport->cfg_nodev_tmo = val;
3289 vport->cfg_devloss_tmo = val;
3290 vport->dev_loss_tmo_changed = 1;
3291 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3292 lpfc_update_rport_devloss_tmo(vport);
3296 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3297 "0404 lpfc_devloss_tmo attribute cannot be set to "
3298 "%d, allowed range is [%d, %d]\n",
3299 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3303 lpfc_vport_param_store(devloss_tmo)
3304 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3305 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3308 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3309 * lpfc_suppress_rsp = 0 Disable
3310 * lpfc_suppress_rsp = 1 Enable (default)
3313 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3314 "Enable suppress rsp feature is firmware supports it");
3317 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3318 * lpfc_nvmet_mrq = 1 use a single RQ pair
3319 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3322 LPFC_ATTR_R(nvmet_mrq,
3324 "Specify number of RQ pairs for processing NVMET cmds");
3327 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3328 * Supported Values: 1 - register just FCP
3329 * 3 - register both FCP and NVME
3330 * Supported values are [1,3]. Default value is 1
3332 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3333 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3334 "Define fc4 type to register with fabric.");
3337 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3338 * This parameter is only used if:
3339 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3340 * port is not configured for NVMET.
3342 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3343 * The remaining XRIs get split up based on lpfc_xri_split per port:
3345 * Supported Values are in percentages
3346 * the xri_split value is the percentage the SCSI port will get. The remaining
3347 * percentage will go to NVME.
3349 LPFC_ATTR_R(xri_split, 50, 10, 90,
3350 "Division of XRI resources between SCSI and NVME");
3353 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3354 # deluged with LOTS of information.
3355 # You can set a bit mask to record specific types of verbose messages:
3356 # See lpfc_logmsh.h for definitions.
3358 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3359 "Verbose logging bit-mask");
3362 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3363 # objects that have been registered with the nameserver after login.
3365 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3366 "Deregister nameserver objects before LOGO");
3369 # lun_queue_depth: This parameter is used to limit the number of outstanding
3370 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3371 # If this parameter value is greater than 1/8th the maximum number of exchanges
3372 # supported by the HBA port, then the lun queue depth will be reduced to
3373 # 1/8th the maximum number of exchanges.
3375 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3376 "Max number of FCP commands we can queue to a specific LUN");
3379 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3380 # commands per target port. Value range is [10,65535]. Default value is 65535.
3382 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3383 "Max number of FCP commands we can queue to a specific target port");
3386 # hba_queue_depth: This parameter is used to limit the number of outstanding
3387 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3388 # value is greater than the maximum number of exchanges supported by the HBA,
3389 # then maximum number of exchanges supported by the HBA is used to determine
3390 # the hba_queue_depth.
3392 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3393 "Max number of FCP commands we can queue to a lpfc HBA");
3396 # peer_port_login: This parameter allows/prevents logins
3397 # between peer ports hosted on the same physical port.
3398 # When this parameter is set 0 peer ports of same physical port
3399 # are not allowed to login to each other.
3400 # When this parameter is set 1 peer ports of same physical port
3401 # are allowed to login to each other.
3402 # Default value of this parameter is 0.
3404 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3405 "Allow peer ports on the same physical port to login to each "
3409 # restrict_login: This parameter allows/prevents logins
3410 # between Virtual Ports and remote initiators.
3411 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3412 # other initiators and will attempt to PLOGI all remote ports.
3413 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3414 # remote ports and will not attempt to PLOGI to other initiators.
3415 # This parameter does not restrict to the physical port.
3416 # This parameter does not restrict logins to Fabric resident remote ports.
3417 # Default value of this parameter is 1.
3419 static int lpfc_restrict_login = 1;
3420 module_param(lpfc_restrict_login, int, S_IRUGO);
3421 MODULE_PARM_DESC(lpfc_restrict_login,
3422 "Restrict virtual ports login to remote initiators.");
3423 lpfc_vport_param_show(restrict_login);
3426 * lpfc_restrict_login_init - Set the vport restrict login flag
3427 * @vport: lpfc vport structure pointer.
3428 * @val: contains the restrict login value.
3431 * If val is not in a valid range then log a kernel error message and set
3432 * the vport restrict login to one.
3433 * If the port type is physical clear the restrict login flag and return.
3434 * Else set the restrict login flag to val.
3437 * zero if val is in range
3438 * -EINVAL val out of range
3441 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3443 if (val < 0 || val > 1) {
3444 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3445 "0422 lpfc_restrict_login attribute cannot "
3446 "be set to %d, allowed range is [0, 1]\n",
3448 vport->cfg_restrict_login = 1;
3451 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3452 vport->cfg_restrict_login = 0;
3455 vport->cfg_restrict_login = val;
3460 * lpfc_restrict_login_set - Set the vport restrict login flag
3461 * @vport: lpfc vport structure pointer.
3462 * @val: contains the restrict login value.
3465 * If val is not in a valid range then log a kernel error message and set
3466 * the vport restrict login to one.
3467 * If the port type is physical and the val is not zero log a kernel
3468 * error message, clear the restrict login flag and return zero.
3469 * Else set the restrict login flag to val.
3472 * zero if val is in range
3473 * -EINVAL val out of range
3476 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3478 if (val < 0 || val > 1) {
3479 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3480 "0425 lpfc_restrict_login attribute cannot "
3481 "be set to %d, allowed range is [0, 1]\n",
3483 vport->cfg_restrict_login = 1;
3486 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3487 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3488 "0468 lpfc_restrict_login must be 0 for "
3489 "Physical ports.\n");
3490 vport->cfg_restrict_login = 0;
3493 vport->cfg_restrict_login = val;
3496 lpfc_vport_param_store(restrict_login);
3497 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3498 lpfc_restrict_login_show, lpfc_restrict_login_store);
3501 # Some disk devices have a "select ID" or "select Target" capability.
3502 # From a protocol standpoint "select ID" usually means select the
3503 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3504 # annex" which contains a table that maps a "select ID" (a number
3505 # between 0 and 7F) to an ALPA. By default, for compatibility with
3506 # older drivers, the lpfc driver scans this table from low ALPA to high
3509 # Turning on the scan-down variable (on = 1, off = 0) will
3510 # cause the lpfc driver to use an inverted table, effectively
3511 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3513 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3514 # and will not work across a fabric. Also this parameter will take
3515 # effect only in the case when ALPA map is not available.)
3517 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3518 "Start scanning for devices from highest ALPA to lowest");
3521 # lpfc_topology: link topology for init link
3522 # 0x0 = attempt loop mode then point-to-point
3523 # 0x01 = internal loopback mode
3524 # 0x02 = attempt point-to-point mode only
3525 # 0x04 = attempt loop mode only
3526 # 0x06 = attempt point-to-point mode then loop
3527 # Set point-to-point mode if you want to run as an N_Port.
3528 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3529 # Default value is 0.
3531 LPFC_ATTR(topology, 0, 0, 6,
3532 "Select Fibre Channel topology");
3535 * lpfc_topology_set - Set the adapters topology field
3536 * @phba: lpfc_hba pointer.
3537 * @val: topology value.
3540 * If val is in a valid range then set the adapter's topology field and
3541 * issue a lip; if the lip fails reset the topology to the old value.
3543 * If the value is not in range log a kernel error message and return an error.
3546 * zero if val is in range and lip okay
3547 * non-zero return value from lpfc_issue_lip()
3548 * -EINVAL val out of range
3551 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3552 const char *buf, size_t count)
3554 struct Scsi_Host *shost = class_to_shost(dev);
3555 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3556 struct lpfc_hba *phba = vport->phba;
3559 const char *val_buf = buf;
3563 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3565 val_buf = &buf[strlen("nolip ")];
3568 if (!isdigit(val_buf[0]))
3570 if (sscanf(val_buf, "%i", &val) != 1)
3573 if (val >= 0 && val <= 6) {
3574 prev_val = phba->cfg_topology;
3575 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3577 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3578 "3113 Loop mode not supported at speed %d\n",
3582 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3584 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3585 "3114 Loop mode not supported\n");
3588 phba->cfg_topology = val;
3592 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3593 "3054 lpfc_topology changed from %d to %d\n",
3595 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3596 phba->fc_topology_changed = 1;
3597 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3599 phba->cfg_topology = prev_val;
3604 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3605 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3606 "allowed range is [0, 6]\n",
3611 lpfc_param_show(topology)
3612 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3613 lpfc_topology_show, lpfc_topology_store);
3616 * lpfc_static_vport_show: Read callback function for
3617 * lpfc_static_vport sysfs file.
3618 * @dev: Pointer to class device object.
3619 * @attr: device attribute structure.
3620 * @buf: Data buffer.
3622 * This function is the read call back function for
3623 * lpfc_static_vport sysfs file. The lpfc_static_vport
3624 * sysfs file report the mageability of the vport.
3627 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3630 struct Scsi_Host *shost = class_to_shost(dev);
3631 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3632 if (vport->vport_flag & STATIC_VPORT)
3633 sprintf(buf, "1\n");
3635 sprintf(buf, "0\n");
3641 * Sysfs attribute to control the statistical data collection.
3643 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3644 lpfc_static_vport_show, NULL);
3647 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3648 * @dev: Pointer to class device.
3649 * @buf: Data buffer.
3650 * @count: Size of the data buffer.
3652 * This function get called when a user write to the lpfc_stat_data_ctrl
3653 * sysfs file. This function parse the command written to the sysfs file
3654 * and take appropriate action. These commands are used for controlling
3655 * driver statistical data collection.
3656 * Following are the command this function handles.
3658 * setbucket <bucket_type> <base> <step>
3659 * = Set the latency buckets.
3660 * destroybucket = destroy all the buckets.
3661 * start = start data collection
3662 * stop = stop data collection
3663 * reset = reset the collected data
3666 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3667 const char *buf, size_t count)
3669 struct Scsi_Host *shost = class_to_shost(dev);
3670 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3671 struct lpfc_hba *phba = vport->phba;
3672 #define LPFC_MAX_DATA_CTRL_LEN 1024
3673 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3675 char *str_ptr, *token;
3676 struct lpfc_vport **vports;
3677 struct Scsi_Host *v_shost;
3678 char *bucket_type_str, *base_str, *step_str;
3679 unsigned long base, step, bucket_type;
3681 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3682 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3685 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3686 str_ptr = &bucket_data[0];
3687 /* Ignore this token - this is command token */
3688 token = strsep(&str_ptr, "\t ");
3692 bucket_type_str = strsep(&str_ptr, "\t ");
3693 if (!bucket_type_str)
3696 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3697 bucket_type = LPFC_LINEAR_BUCKET;
3698 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3699 bucket_type = LPFC_POWER2_BUCKET;
3703 base_str = strsep(&str_ptr, "\t ");
3706 base = simple_strtoul(base_str, NULL, 0);
3708 step_str = strsep(&str_ptr, "\t ");
3711 step = simple_strtoul(step_str, NULL, 0);
3715 /* Block the data collection for every vport */
3716 vports = lpfc_create_vport_work_array(phba);
3720 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3721 v_shost = lpfc_shost_from_vport(vports[i]);
3722 spin_lock_irq(v_shost->host_lock);
3723 /* Block and reset data collection */
3724 vports[i]->stat_data_blocked = 1;
3725 if (vports[i]->stat_data_enabled)
3726 lpfc_vport_reset_stat_data(vports[i]);
3727 spin_unlock_irq(v_shost->host_lock);
3730 /* Set the bucket attributes */
3731 phba->bucket_type = bucket_type;
3732 phba->bucket_base = base;
3733 phba->bucket_step = step;
3735 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3736 v_shost = lpfc_shost_from_vport(vports[i]);
3738 /* Unblock data collection */
3739 spin_lock_irq(v_shost->host_lock);
3740 vports[i]->stat_data_blocked = 0;
3741 spin_unlock_irq(v_shost->host_lock);
3743 lpfc_destroy_vport_work_array(phba, vports);
3747 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3748 vports = lpfc_create_vport_work_array(phba);
3752 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3753 v_shost = lpfc_shost_from_vport(vports[i]);
3754 spin_lock_irq(shost->host_lock);
3755 vports[i]->stat_data_blocked = 1;
3756 lpfc_free_bucket(vport);
3757 vport->stat_data_enabled = 0;
3758 vports[i]->stat_data_blocked = 0;
3759 spin_unlock_irq(shost->host_lock);
3761 lpfc_destroy_vport_work_array(phba, vports);
3762 phba->bucket_type = LPFC_NO_BUCKET;
3763 phba->bucket_base = 0;
3764 phba->bucket_step = 0;
3768 if (!strncmp(buf, "start", strlen("start"))) {
3769 /* If no buckets configured return error */
3770 if (phba->bucket_type == LPFC_NO_BUCKET)
3772 spin_lock_irq(shost->host_lock);
3773 if (vport->stat_data_enabled) {
3774 spin_unlock_irq(shost->host_lock);
3777 lpfc_alloc_bucket(vport);
3778 vport->stat_data_enabled = 1;
3779 spin_unlock_irq(shost->host_lock);
3783 if (!strncmp(buf, "stop", strlen("stop"))) {
3784 spin_lock_irq(shost->host_lock);
3785 if (vport->stat_data_enabled == 0) {
3786 spin_unlock_irq(shost->host_lock);
3789 lpfc_free_bucket(vport);
3790 vport->stat_data_enabled = 0;
3791 spin_unlock_irq(shost->host_lock);
3795 if (!strncmp(buf, "reset", strlen("reset"))) {
3796 if ((phba->bucket_type == LPFC_NO_BUCKET)
3797 || !vport->stat_data_enabled)
3799 spin_lock_irq(shost->host_lock);
3800 vport->stat_data_blocked = 1;
3801 lpfc_vport_reset_stat_data(vport);
3802 vport->stat_data_blocked = 0;
3803 spin_unlock_irq(shost->host_lock);
3811 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3812 * @dev: Pointer to class device object.
3813 * @buf: Data buffer.
3815 * This function is the read call back function for
3816 * lpfc_stat_data_ctrl sysfs file. This function report the
3817 * current statistical data collection state.
3820 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3823 struct Scsi_Host *shost = class_to_shost(dev);
3824 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3825 struct lpfc_hba *phba = vport->phba;
3829 unsigned long bucket_value;
3831 switch (phba->bucket_type) {
3832 case LPFC_LINEAR_BUCKET:
3833 bucket_type = "linear";
3835 case LPFC_POWER2_BUCKET:
3836 bucket_type = "power2";
3839 bucket_type = "No Bucket";
3843 sprintf(&buf[index], "Statistical Data enabled :%d, "
3844 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3845 " Bucket step :%d\nLatency Ranges :",
3846 vport->stat_data_enabled, vport->stat_data_blocked,
3847 bucket_type, phba->bucket_base, phba->bucket_step);
3848 index = strlen(buf);
3849 if (phba->bucket_type != LPFC_NO_BUCKET) {
3850 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3851 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3852 bucket_value = phba->bucket_base +
3853 phba->bucket_step * i;
3855 bucket_value = phba->bucket_base +
3856 (1 << i) * phba->bucket_step;
3858 if (index + 10 > PAGE_SIZE)
3860 sprintf(&buf[index], "%08ld ", bucket_value);
3861 index = strlen(buf);
3864 sprintf(&buf[index], "\n");
3869 * Sysfs attribute to control the statistical data collection.
3871 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3872 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3875 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3879 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3882 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3883 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3884 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3888 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3890 * @kobj: Pointer to the kernel object
3891 * @bin_attr: Attribute object
3892 * @buff: Buffer pointer
3894 * @count: Buffer size
3896 * This function is the read call back function for lpfc_drvr_stat_data
3897 * sysfs file. This function export the statistical data to user
3901 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3902 struct bin_attribute *bin_attr,
3903 char *buf, loff_t off, size_t count)
3905 struct device *dev = container_of(kobj, struct device,
3907 struct Scsi_Host *shost = class_to_shost(dev);
3908 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3909 struct lpfc_hba *phba = vport->phba;
3910 int i = 0, index = 0;
3911 unsigned long nport_index;
3912 struct lpfc_nodelist *ndlp = NULL;
3913 nport_index = (unsigned long)off /
3914 MAX_STAT_DATA_SIZE_PER_TARGET;
3916 if (!vport->stat_data_enabled || vport->stat_data_blocked
3917 || (phba->bucket_type == LPFC_NO_BUCKET))
3920 spin_lock_irq(shost->host_lock);
3921 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3922 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3925 if (nport_index > 0) {
3930 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3934 if (!ndlp->lat_data)
3938 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3939 ndlp->nlp_portname.u.wwn[0],
3940 ndlp->nlp_portname.u.wwn[1],
3941 ndlp->nlp_portname.u.wwn[2],
3942 ndlp->nlp_portname.u.wwn[3],
3943 ndlp->nlp_portname.u.wwn[4],
3944 ndlp->nlp_portname.u.wwn[5],
3945 ndlp->nlp_portname.u.wwn[6],
3946 ndlp->nlp_portname.u.wwn[7]);
3948 index = strlen(buf);
3950 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3951 sprintf(&buf[index], "%010u,",
3952 ndlp->lat_data[i].cmd_count);
3953 index = strlen(buf);
3955 sprintf(&buf[index], "\n");
3956 index = strlen(buf);
3958 spin_unlock_irq(shost->host_lock);
3962 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3964 .name = "lpfc_drvr_stat_data",
3967 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3968 .read = sysfs_drvr_stat_data_read,
3973 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3975 # Value range is [0,16]. Default value is 0.
3978 * lpfc_link_speed_set - Set the adapters link speed
3979 * @phba: lpfc_hba pointer.
3980 * @val: link speed value.
3983 * If val is in a valid range then set the adapter's link speed field and
3984 * issue a lip; if the lip fails reset the link speed to the old value.
3987 * If the value is not in range log a kernel error message and return an error.
3990 * zero if val is in range and lip okay.
3991 * non-zero return value from lpfc_issue_lip()
3992 * -EINVAL val out of range
3995 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3996 const char *buf, size_t count)
3998 struct Scsi_Host *shost = class_to_shost(dev);
3999 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4000 struct lpfc_hba *phba = vport->phba;
4001 int val = LPFC_USER_LINK_SPEED_AUTO;
4003 const char *val_buf = buf;
4005 uint32_t prev_val, if_type;
4007 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4008 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4009 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4012 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4014 val_buf = &buf[strlen("nolip ")];
4017 if (!isdigit(val_buf[0]))
4019 if (sscanf(val_buf, "%i", &val) != 1)
4022 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4023 "3055 lpfc_link_speed changed from %d to %d %s\n",
4024 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4026 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4027 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4028 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4029 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4030 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4031 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4032 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
4033 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4034 "2879 lpfc_link_speed attribute cannot be set "
4035 "to %d. Speed is not supported by this port.\n",
4039 if (val == LPFC_USER_LINK_SPEED_16G &&
4040 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4041 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4042 "3112 lpfc_link_speed attribute cannot be set "
4043 "to %d. Speed is not supported in loop mode.\n",
4047 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4048 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4049 prev_val = phba->cfg_link_speed;
4050 phba->cfg_link_speed = val;
4054 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4056 phba->cfg_link_speed = prev_val;
4061 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4062 "0469 lpfc_link_speed attribute cannot be set to %d, "
4063 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
4067 static int lpfc_link_speed = 0;
4068 module_param(lpfc_link_speed, int, S_IRUGO);
4069 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4070 lpfc_param_show(link_speed)
4073 * lpfc_link_speed_init - Set the adapters link speed
4074 * @phba: lpfc_hba pointer.
4075 * @val: link speed value.
4078 * If val is in a valid range then set the adapter's link speed field.
4081 * If the value is not in range log a kernel error message, clear the link
4082 * speed and return an error.
4085 * zero if val saved.
4086 * -EINVAL val out of range
4089 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4091 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4093 "3111 lpfc_link_speed of %d cannot "
4094 "support loop mode, setting topology to default.\n",
4096 phba->cfg_topology = 0;
4098 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4099 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4100 phba->cfg_link_speed = val;
4103 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4104 "0405 lpfc_link_speed attribute cannot "
4105 "be set to %d, allowed values are "
4106 "["LPFC_LINK_SPEED_STRING"]\n", val);
4107 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4111 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
4112 lpfc_link_speed_show, lpfc_link_speed_store);
4115 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4116 # 0 = aer disabled or not supported
4117 # 1 = aer supported and enabled (default)
4118 # Value range is [0,1]. Default value is 1.
4120 LPFC_ATTR(aer_support, 1, 0, 1,
4121 "Enable PCIe device AER support");
4122 lpfc_param_show(aer_support)
4125 * lpfc_aer_support_store - Set the adapter for aer support
4127 * @dev: class device that is converted into a Scsi_host.
4128 * @attr: device attribute, not used.
4129 * @buf: containing enable or disable aer flag.
4130 * @count: unused variable.
4133 * If the val is 1 and currently the device's AER capability was not
4134 * enabled, invoke the kernel's enable AER helper routine, trying to
4135 * enable the device's AER capability. If the helper routine enabling
4136 * AER returns success, update the device's cfg_aer_support flag to
4137 * indicate AER is supported by the device; otherwise, if the device
4138 * AER capability is already enabled to support AER, then do nothing.
4140 * If the val is 0 and currently the device's AER support was enabled,
4141 * invoke the kernel's disable AER helper routine. After that, update
4142 * the device's cfg_aer_support flag to indicate AER is not supported
4143 * by the device; otherwise, if the device AER capability is already
4144 * disabled from supporting AER, then do nothing.
4147 * length of the buf on success if val is in range the intended mode
4149 * -EINVAL if val out of range or intended mode is not supported.
4152 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4153 const char *buf, size_t count)
4155 struct Scsi_Host *shost = class_to_shost(dev);
4156 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4157 struct lpfc_hba *phba = vport->phba;
4158 int val = 0, rc = -EINVAL;
4160 if (!isdigit(buf[0]))
4162 if (sscanf(buf, "%i", &val) != 1)
4167 if (phba->hba_flag & HBA_AER_ENABLED) {
4168 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4170 spin_lock_irq(&phba->hbalock);
4171 phba->hba_flag &= ~HBA_AER_ENABLED;
4172 spin_unlock_irq(&phba->hbalock);
4173 phba->cfg_aer_support = 0;
4178 phba->cfg_aer_support = 0;
4183 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4184 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4186 spin_lock_irq(&phba->hbalock);
4187 phba->hba_flag |= HBA_AER_ENABLED;
4188 spin_unlock_irq(&phba->hbalock);
4189 phba->cfg_aer_support = 1;
4194 phba->cfg_aer_support = 1;
4205 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4206 lpfc_aer_support_show, lpfc_aer_support_store);
4209 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4210 * @dev: class device that is converted into a Scsi_host.
4211 * @attr: device attribute, not used.
4212 * @buf: containing flag 1 for aer cleanup state.
4213 * @count: unused variable.
4216 * If the @buf contains 1 and the device currently has the AER support
4217 * enabled, then invokes the kernel AER helper routine
4218 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4219 * error status register.
4224 * -EINVAL if the buf does not contain the 1 or the device is not currently
4225 * enabled with the AER support.
4228 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4229 const char *buf, size_t count)
4231 struct Scsi_Host *shost = class_to_shost(dev);
4232 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4233 struct lpfc_hba *phba = vport->phba;
4236 if (!isdigit(buf[0]))
4238 if (sscanf(buf, "%i", &val) != 1)
4243 if (phba->hba_flag & HBA_AER_ENABLED)
4244 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4252 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4253 lpfc_aer_cleanup_state);
4256 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4258 * @dev: class device that is converted into a Scsi_host.
4259 * @attr: device attribute, not used.
4260 * @buf: containing the string the number of vfs to be enabled.
4261 * @count: unused variable.
4264 * When this api is called either through user sysfs, the driver shall
4265 * try to enable or disable SR-IOV virtual functions according to the
4268 * If zero virtual function has been enabled to the physical function,
4269 * the driver shall invoke the pci enable virtual function api trying
4270 * to enable the virtual functions. If the nr_vfn provided is greater
4271 * than the maximum supported, the maximum virtual function number will
4272 * be used for invoking the api; otherwise, the nr_vfn provided shall
4273 * be used for invoking the api. If the api call returned success, the
4274 * actual number of virtual functions enabled will be set to the driver
4275 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4276 * cfg_sriov_nr_virtfn remains zero.
4278 * If none-zero virtual functions have already been enabled to the
4279 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4280 * -EINVAL will be returned and the driver does nothing;
4282 * If the nr_vfn provided is zero and none-zero virtual functions have
4283 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4284 * disabling virtual function api shall be invoded to disable all the
4285 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4286 * zero. Otherwise, if zero virtual function has been enabled, do
4290 * length of the buf on success if val is in range the intended mode
4292 * -EINVAL if val out of range or intended mode is not supported.
4295 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4296 const char *buf, size_t count)
4298 struct Scsi_Host *shost = class_to_shost(dev);
4299 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4300 struct lpfc_hba *phba = vport->phba;
4301 struct pci_dev *pdev = phba->pcidev;
4302 int val = 0, rc = -EINVAL;
4304 /* Sanity check on user data */
4305 if (!isdigit(buf[0]))
4307 if (sscanf(buf, "%i", &val) != 1)
4312 /* Request disabling virtual functions */
4314 if (phba->cfg_sriov_nr_virtfn > 0) {
4315 pci_disable_sriov(pdev);
4316 phba->cfg_sriov_nr_virtfn = 0;
4321 /* Request enabling virtual functions */
4322 if (phba->cfg_sriov_nr_virtfn > 0) {
4323 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4324 "3018 There are %d virtual functions "
4325 "enabled on physical function.\n",
4326 phba->cfg_sriov_nr_virtfn);
4330 if (val <= LPFC_MAX_VFN_PER_PFN)
4331 phba->cfg_sriov_nr_virtfn = val;
4333 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4334 "3019 Enabling %d virtual functions is not "
4339 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4341 phba->cfg_sriov_nr_virtfn = 0;
4349 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4350 "Enable PCIe device SR-IOV virtual fn");
4352 lpfc_param_show(sriov_nr_virtfn)
4353 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4354 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4357 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4359 * @dev: class device that is converted into a Scsi_host.
4360 * @attr: device attribute, not used.
4361 * @buf: containing the string the number of vfs to be enabled.
4362 * @count: unused variable.
4367 * length of the buf on success if val is in range the intended mode
4369 * -EINVAL if val out of range or intended mode is not supported.
4372 lpfc_request_firmware_upgrade_store(struct device *dev,
4373 struct device_attribute *attr,
4374 const char *buf, size_t count)
4376 struct Scsi_Host *shost = class_to_shost(dev);
4377 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4378 struct lpfc_hba *phba = vport->phba;
4379 int val = 0, rc = -EINVAL;
4381 /* Sanity check on user data */
4382 if (!isdigit(buf[0]))
4384 if (sscanf(buf, "%i", &val) != 1)
4389 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4397 static int lpfc_req_fw_upgrade;
4398 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4399 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4400 lpfc_param_show(request_firmware_upgrade)
4403 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4404 * @phba: lpfc_hba pointer.
4408 * Set the initial Linux generic firmware upgrade enable or disable flag.
4411 * zero if val saved.
4412 * -EINVAL val out of range
4415 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4417 if (val >= 0 && val <= 1) {
4418 phba->cfg_request_firmware_upgrade = val;
4423 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4424 lpfc_request_firmware_upgrade_show,
4425 lpfc_request_firmware_upgrade_store);
4428 * lpfc_fcp_imax_store
4430 * @dev: class device that is converted into a Scsi_host.
4431 * @attr: device attribute, not used.
4432 * @buf: string with the number of fast-path FCP interrupts per second.
4433 * @count: unused variable.
4436 * If val is in a valid range [636,651042], then set the adapter's
4437 * maximum number of fast-path FCP interrupts per second.
4440 * length of the buf on success if val is in range the intended mode
4442 * -EINVAL if val out of range or intended mode is not supported.
4445 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4446 const char *buf, size_t count)
4448 struct Scsi_Host *shost = class_to_shost(dev);
4449 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4450 struct lpfc_hba *phba = vport->phba;
4453 /* fcp_imax is only valid for SLI4 */
4454 if (phba->sli_rev != LPFC_SLI_REV4)
4457 /* Sanity check on user data */
4458 if (!isdigit(buf[0]))
4460 if (sscanf(buf, "%i", &val) != 1)
4464 * Value range for the HBA is [5000,5000000]
4465 * The value for each EQ depends on how many EQs are configured.
4468 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4471 phba->cfg_fcp_imax = (uint32_t)val;
4473 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4474 lpfc_modify_hba_eq_delay(phba, i);
4480 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4483 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4485 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4486 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4487 MODULE_PARM_DESC(lpfc_fcp_imax,
4488 "Set the maximum number of FCP interrupts per second per HBA");
4489 lpfc_param_show(fcp_imax)
4492 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4493 * @phba: lpfc_hba pointer.
4494 * @val: link speed value.
4497 * If val is in a valid range [636,651042], then initialize the adapter's
4498 * maximum number of fast-path FCP interrupts per second.
4501 * zero if val saved.
4502 * -EINVAL val out of range
4505 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4507 if (phba->sli_rev != LPFC_SLI_REV4) {
4508 phba->cfg_fcp_imax = 0;
4512 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4514 phba->cfg_fcp_imax = val;
4518 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4519 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4521 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4526 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4527 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4530 * lpfc_state_show - Display current driver CPU affinity
4531 * @dev: class converted to a Scsi_host structure.
4532 * @attr: device attribute, not used.
4533 * @buf: on return contains text describing the state of the link.
4535 * Returns: size of formatted string.
4538 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4541 struct Scsi_Host *shost = class_to_shost(dev);
4542 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4543 struct lpfc_hba *phba = vport->phba;
4544 struct lpfc_vector_map_info *cpup;
4547 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4548 (phba->intr_type != MSIX))
4551 switch (phba->cfg_fcp_cpu_map) {
4553 len += snprintf(buf + len, PAGE_SIZE-len,
4554 "fcp_cpu_map: No mapping (%d)\n",
4555 phba->cfg_fcp_cpu_map);
4558 len += snprintf(buf + len, PAGE_SIZE-len,
4559 "fcp_cpu_map: HBA centric mapping (%d): "
4561 phba->cfg_fcp_cpu_map,
4562 phba->sli4_hba.num_online_cpu);
4565 len += snprintf(buf + len, PAGE_SIZE-len,
4566 "fcp_cpu_map: Driver centric mapping (%d): "
4568 phba->cfg_fcp_cpu_map,
4569 phba->sli4_hba.num_online_cpu);
4573 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4574 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4576 /* margin should fit in this and the truncated message */
4577 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4578 len += snprintf(buf + len, PAGE_SIZE-len,
4579 "CPU %02d io_chan %02d "
4580 "physid %d coreid %d\n",
4581 phba->sli4_hba.curr_disp_cpu,
4582 cpup->channel_id, cpup->phys_id,
4585 len += snprintf(buf + len, PAGE_SIZE-len,
4586 "CPU %02d io_chan %02d "
4587 "physid %d coreid %d IRQ %d\n",
4588 phba->sli4_hba.curr_disp_cpu,
4589 cpup->channel_id, cpup->phys_id,
4590 cpup->core_id, cpup->irq);
4592 phba->sli4_hba.curr_disp_cpu++;
4594 /* display max number of CPUs keeping some margin */
4595 if (phba->sli4_hba.curr_disp_cpu <
4596 phba->sli4_hba.num_present_cpu &&
4597 (len >= (PAGE_SIZE - 64))) {
4598 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4603 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4604 phba->sli4_hba.curr_disp_cpu = 0;
4610 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4611 * @dev: class device that is converted into a Scsi_host.
4612 * @attr: device attribute, not used.
4613 * @buf: one or more lpfc_polling_flags values.
4617 * -EINVAL - Not implemented yet.
4620 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4621 const char *buf, size_t count)
4623 int status = -EINVAL;
4628 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4631 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4632 # 0 - Do not affinitze IRQ vectors
4633 # 1 - Affintize HBA vectors with respect to each HBA
4634 # (start with CPU0 for each HBA)
4635 # 2 - Affintize HBA vectors with respect to the entire driver
4636 # (round robin thru all CPUs across all HBAs)
4638 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4639 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4640 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4641 "Defines how to map CPUs to IRQ vectors per HBA");
4644 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4645 * @phba: lpfc_hba pointer.
4646 * @val: link speed value.
4649 * If val is in a valid range [0-2], then affinitze the adapter's
4653 * zero if val saved.
4654 * -EINVAL val out of range
4657 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4659 if (phba->sli_rev != LPFC_SLI_REV4) {
4660 phba->cfg_fcp_cpu_map = 0;
4664 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4665 phba->cfg_fcp_cpu_map = val;
4669 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4670 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4672 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4677 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4678 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4681 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4682 # Value range is [2,3]. Default value is 3.
4684 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4685 "Select Fibre Channel class of service for FCP sequences");
4688 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4689 # is [0,1]. Default value is 0.
4691 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4692 "Use ADISC on rediscovery to authenticate FCP devices");
4695 # lpfc_first_burst_size: First burst size to use on the NPorts
4696 # that support first burst.
4697 # Value range is [0,65536]. Default value is 0.
4699 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4700 "First burst size for Targets that support first burst");
4703 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4704 * When the driver is configured as an NVME target, this value is
4705 * communicated to the NVME initiator in the PRLI response. It is
4706 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4707 * parameters are set and the target is sending the PRLI RSP.
4708 * Parameter supported on physical port only - no NPIV support.
4709 * Value range is [0,65536]. Default value is 0.
4711 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4712 "NVME Target mode first burst size in 512B increments.");
4715 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4716 * For the Initiator (I), enabling this parameter means that an NVMET
4717 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4718 * processed by the initiator for subsequent NVME FCP IO. For the target
4719 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4720 * driver parameter as the target function's first burst size returned to the
4721 * initiator in the target's NVME PRLI response. Parameter supported on physical
4722 * port only - no NPIV support.
4723 * Value range is [0,1]. Default value is 0 (disabled).
4725 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4726 "Enable First Burst feature on I and T functions.");
4729 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4730 # depth. Default value is 0. When the value of this parameter is zero the
4731 # SCSI command completion time is not used for controlling I/O queue depth. When
4732 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4733 # to limit the I/O completion time to the parameter value.
4734 # The value is set in milliseconds.
4736 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4737 "Use command completion time to control queue depth");
4739 lpfc_vport_param_show(max_scsicmpl_time);
4741 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4744 struct lpfc_nodelist *ndlp, *next_ndlp;
4746 if (val == vport->cfg_max_scsicmpl_time)
4748 if ((val < 0) || (val > 60000))
4750 vport->cfg_max_scsicmpl_time = val;
4752 spin_lock_irq(shost->host_lock);
4753 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4754 if (!NLP_CHK_NODE_ACT(ndlp))
4756 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4758 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4760 spin_unlock_irq(shost->host_lock);
4763 lpfc_vport_param_store(max_scsicmpl_time);
4764 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4765 lpfc_max_scsicmpl_time_show,
4766 lpfc_max_scsicmpl_time_store);
4769 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4770 # range is [0,1]. Default value is 0.
4772 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4775 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4776 * range is [0,1]. Default value is 0.
4777 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4778 * For [1], FCP commands are issued to a Work Queue associated with the
4781 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4782 * LPFC_FCP_SCHED_BY_CPU == 1
4784 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4785 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4786 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4787 * through WQs will be used.
4789 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4790 LPFC_FCP_SCHED_ROUND_ROBIN,
4791 LPFC_FCP_SCHED_BY_CPU,
4792 "Determine scheduling algorithm for "
4793 "issuing commands [0] - Round Robin, [1] - Current CPU");
4796 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4797 # range is [0,1]. Default value is 0.
4798 # For [0], bus reset issues target reset to ALL devices
4799 # For [1], bus reset issues target reset to non-FCP2 devices
4801 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4802 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4806 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4807 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4808 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4809 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4810 # cr_delay is set to 0.
4812 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4813 "interrupt response is generated");
4815 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4816 "interrupt response is generated");
4819 # lpfc_multi_ring_support: Determines how many rings to spread available
4820 # cmd/rsp IOCB entries across.
4821 # Value range is [1,2]. Default value is 1.
4823 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4824 "SLI rings to spread IOCB entries across");
4827 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4828 # identifies what rctl value to configure the additional ring for.
4829 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4831 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4832 255, "Identifies RCTL for additional ring configuration");
4835 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4836 # identifies what type value to configure the additional ring for.
4837 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4839 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4840 255, "Identifies TYPE for additional ring configuration");
4843 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4844 # 0 = SmartSAN functionality disabled (default)
4845 # 1 = SmartSAN functionality enabled
4846 # This parameter will override the value of lpfc_fdmi_on module parameter.
4847 # Value range is [0,1]. Default value is 0.
4849 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4852 # lpfc_fdmi_on: Controls FDMI support.
4853 # 0 No FDMI support (default)
4854 # 1 Traditional FDMI support
4855 # Traditional FDMI support means the driver will assume FDMI-2 support;
4856 # however, if that fails, it will fallback to FDMI-1.
4857 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4858 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4860 # Value range [0,1]. Default value is 0.
4862 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4865 # Specifies the maximum number of ELS cmds we can have outstanding (for
4866 # discovery). Value range is [1,64]. Default value = 32.
4868 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4869 "during discovery");
4872 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4873 # will be scanned by the SCSI midlayer when sequential scanning is
4874 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4875 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4876 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4877 # above. The lpfc driver limits the default value to 255 for two reasons.
4878 # As it bounds the sequential scan loop, scanning for thousands of luns
4879 # on a target can take minutes of wall clock time. Additionally,
4880 # there are FC targets, such as JBODs, that only recognize 8-bits of
4881 # LUN ID. When they receive a value greater than 8 bits, they chop off
4882 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4883 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4884 # valid responses at each of the LUN IDs, to believe there are multiple
4885 # devices present, when in fact, there is only 1.
4886 # A customer that is aware of their target behaviors, and the results as
4887 # indicated above, is welcome to increase the lpfc_max_luns value.
4888 # As mentioned, this value is not used by the lpfc driver, only the
4890 # Value range is [0,65535]. Default value is 255.
4891 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4893 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4896 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4897 # Value range is [1,255], default value is 10.
4899 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4900 "Milliseconds driver will wait between polling FCP ring");
4903 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4904 # to complete in seconds. Value range is [5,180], default value is 60.
4906 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4907 "Maximum time to wait for task management commands to complete");
4909 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4910 # support this feature
4913 # 2 = MSI-X enabled (default)
4914 # Value range is [0,2]. Default value is 2.
4916 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4917 "MSI-X (2), if possible");
4920 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4922 * 0 = NVME OAS disabled
4923 * 1 = NVME OAS enabled
4925 * Value range is [0,1]. Default value is 0.
4927 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4928 "Use OAS bit on NVME IOs");
4931 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4932 * will advertise it supports to the SCSI layer. This also will map to
4933 * the number of WQs the driver will create.
4935 * 0 = Configure the number of io channels to the number of active CPUs.
4936 * 1,32 = Manually specify how many io channels to use.
4938 * Value range is [0,32]. Default value is 4.
4940 LPFC_ATTR_R(fcp_io_channel,
4941 LPFC_FCP_IO_CHAN_DEF,
4942 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4943 "Set the number of FCP I/O channels");
4946 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4947 * will advertise it supports to the NVME layer. This also will map to
4948 * the number of WQs the driver will create.
4950 * This module parameter is valid when lpfc_enable_fc4_type is set
4953 * The NVME Layer will try to create this many, plus 1 administrative
4954 * hardware queue. The administrative queue will always map to WQ 0
4955 * A hardware IO queue maps (qidx) to a specific driver WQ.
4957 * 0 = Configure the number of io channels to the number of active CPUs.
4958 * 1,32 = Manually specify how many io channels to use.
4960 * Value range is [0,32]. Default value is 0.
4962 LPFC_ATTR_R(nvme_io_channel,
4963 LPFC_NVME_IO_CHAN_DEF,
4964 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4965 "Set the number of NVME I/O channels");
4968 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4969 # 0 = HBA resets disabled
4970 # 1 = HBA resets enabled (default)
4971 # Value range is [0,1]. Default value is 1.
4973 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
4976 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
4977 # 0 = HBA Heartbeat disabled
4978 # 1 = HBA Heartbeat enabled (default)
4979 # Value range is [0,1]. Default value is 1.
4981 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
4984 # lpfc_EnableXLane: Enable Express Lane Feature
4985 # 0x0 Express Lane Feature disabled
4986 # 0x1 Express Lane Feature enabled
4987 # Value range is [0,1]. Default value is 0.
4989 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4992 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4993 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4994 # Value range is [0x0,0x7f]. Default value is 0
4996 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
4999 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5000 # 0 = BlockGuard disabled (default)
5001 # 1 = BlockGuard enabled
5002 # Value range is [0,1]. Default value is 0.
5004 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5007 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5008 # 0 = disabled (default)
5010 # Value range is [0,1]. Default value is 0.
5012 # This feature in under investigation and may be supported in the future.
5014 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5018 # - Bit mask of host protection capabilities used to register with the
5020 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5021 # - Allows you to ultimately specify which profiles to use
5022 # - Default will result in registering capabilities for all profiles.
5023 # - SHOST_DIF_TYPE1_PROTECTION 1
5024 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5025 # - SHOST_DIX_TYPE0_PROTECTION 8
5026 # HBA supports DIX Type 0: Host to HBA protection only
5027 # - SHOST_DIX_TYPE1_PROTECTION 16
5028 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5031 LPFC_ATTR(prot_mask,
5032 (SHOST_DIF_TYPE1_PROTECTION |
5033 SHOST_DIX_TYPE0_PROTECTION |
5034 SHOST_DIX_TYPE1_PROTECTION),
5036 (SHOST_DIF_TYPE1_PROTECTION |
5037 SHOST_DIX_TYPE0_PROTECTION |
5038 SHOST_DIX_TYPE1_PROTECTION),
5039 "T10-DIF host protection capabilities mask");
5042 # lpfc_prot_guard: i
5043 # - Bit mask of protection guard types to register with the SCSI mid-layer
5044 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5045 # - Allows you to ultimately specify which profiles to use
5046 # - Default will result in registering capabilities for all guard types
5049 LPFC_ATTR(prot_guard,
5050 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5051 "T10-DIF host protection guard type");
5054 * Delay initial NPort discovery when Clean Address bit is cleared in
5055 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5056 * This parameter can have value 0 or 1.
5057 * When this parameter is set to 0, no delay is added to the initial
5059 * When this parameter is set to non-zero value, initial Nport discovery is
5060 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5061 * accept and FCID/Fabric name/Fabric portname is changed.
5062 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5063 * when Clean Address bit is cleared in FLOGI/FDISC
5064 * accept and FCID/Fabric name/Fabric portname is changed.
5065 * Default value is 0.
5067 LPFC_ATTR(delay_discovery, 0, 0, 1,
5068 "Delay NPort discovery when Clean Address bit is cleared.");
5071 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5072 * This value can be set to values between 64 and 4096. The default value is
5073 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5074 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5075 * Because of the additional overhead involved in setting up T10-DIF,
5076 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5077 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5079 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5080 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5083 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5084 * 0 = MDS Diagnostics disabled (default)
5085 * 1 = MDS Diagnostics enabled
5086 * Value range is [0,1]. Default value is 0.
5088 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5090 struct device_attribute *lpfc_hba_attrs[] = {
5091 &dev_attr_nvme_info,
5093 &dev_attr_bg_guard_err,
5094 &dev_attr_bg_apptag_err,
5095 &dev_attr_bg_reftag_err,
5097 &dev_attr_serialnum,
5098 &dev_attr_modeldesc,
5099 &dev_attr_modelname,
5100 &dev_attr_programtype,
5104 &dev_attr_option_rom_version,
5105 &dev_attr_link_state,
5106 &dev_attr_num_discovered_ports,
5107 &dev_attr_menlo_mgmt_mode,
5108 &dev_attr_lpfc_drvr_version,
5109 &dev_attr_lpfc_enable_fip,
5110 &dev_attr_lpfc_temp_sensor,
5111 &dev_attr_lpfc_log_verbose,
5112 &dev_attr_lpfc_lun_queue_depth,
5113 &dev_attr_lpfc_tgt_queue_depth,
5114 &dev_attr_lpfc_hba_queue_depth,
5115 &dev_attr_lpfc_peer_port_login,
5116 &dev_attr_lpfc_nodev_tmo,
5117 &dev_attr_lpfc_devloss_tmo,
5118 &dev_attr_lpfc_enable_fc4_type,
5119 &dev_attr_lpfc_xri_split,
5120 &dev_attr_lpfc_fcp_class,
5121 &dev_attr_lpfc_use_adisc,
5122 &dev_attr_lpfc_first_burst_size,
5123 &dev_attr_lpfc_ack0,
5124 &dev_attr_lpfc_topology,
5125 &dev_attr_lpfc_scan_down,
5126 &dev_attr_lpfc_link_speed,
5127 &dev_attr_lpfc_fcp_io_sched,
5128 &dev_attr_lpfc_fcp2_no_tgt_reset,
5129 &dev_attr_lpfc_cr_delay,
5130 &dev_attr_lpfc_cr_count,
5131 &dev_attr_lpfc_multi_ring_support,
5132 &dev_attr_lpfc_multi_ring_rctl,
5133 &dev_attr_lpfc_multi_ring_type,
5134 &dev_attr_lpfc_fdmi_on,
5135 &dev_attr_lpfc_enable_SmartSAN,
5136 &dev_attr_lpfc_max_luns,
5137 &dev_attr_lpfc_enable_npiv,
5138 &dev_attr_lpfc_fcf_failover_policy,
5139 &dev_attr_lpfc_enable_rrq,
5140 &dev_attr_nport_evt_cnt,
5141 &dev_attr_board_mode,
5148 &dev_attr_npiv_info,
5149 &dev_attr_issue_reset,
5150 &dev_attr_lpfc_poll,
5151 &dev_attr_lpfc_poll_tmo,
5152 &dev_attr_lpfc_task_mgmt_tmo,
5153 &dev_attr_lpfc_use_msi,
5154 &dev_attr_lpfc_nvme_oas,
5155 &dev_attr_lpfc_fcp_imax,
5156 &dev_attr_lpfc_fcp_cpu_map,
5157 &dev_attr_lpfc_fcp_io_channel,
5158 &dev_attr_lpfc_suppress_rsp,
5159 &dev_attr_lpfc_nvme_io_channel,
5160 &dev_attr_lpfc_nvmet_mrq,
5161 &dev_attr_lpfc_nvme_enable_fb,
5162 &dev_attr_lpfc_nvmet_fb_size,
5163 &dev_attr_lpfc_enable_bg,
5164 &dev_attr_lpfc_soft_wwnn,
5165 &dev_attr_lpfc_soft_wwpn,
5166 &dev_attr_lpfc_soft_wwn_enable,
5167 &dev_attr_lpfc_enable_hba_reset,
5168 &dev_attr_lpfc_enable_hba_heartbeat,
5169 &dev_attr_lpfc_EnableXLane,
5170 &dev_attr_lpfc_XLanePriority,
5171 &dev_attr_lpfc_xlane_lun,
5172 &dev_attr_lpfc_xlane_tgt,
5173 &dev_attr_lpfc_xlane_vpt,
5174 &dev_attr_lpfc_xlane_lun_state,
5175 &dev_attr_lpfc_xlane_lun_status,
5176 &dev_attr_lpfc_xlane_priority,
5177 &dev_attr_lpfc_sg_seg_cnt,
5178 &dev_attr_lpfc_max_scsicmpl_time,
5179 &dev_attr_lpfc_stat_data_ctrl,
5180 &dev_attr_lpfc_aer_support,
5181 &dev_attr_lpfc_aer_state_cleanup,
5182 &dev_attr_lpfc_sriov_nr_virtfn,
5183 &dev_attr_lpfc_req_fw_upgrade,
5184 &dev_attr_lpfc_suppress_link_up,
5185 &dev_attr_lpfc_iocb_cnt,
5188 &dev_attr_txcmplq_hw,
5189 &dev_attr_lpfc_fips_level,
5190 &dev_attr_lpfc_fips_rev,
5192 &dev_attr_lpfc_sriov_hw_max_virtfn,
5194 &dev_attr_lpfc_xlane_supported,
5195 &dev_attr_lpfc_enable_mds_diags,
5199 struct device_attribute *lpfc_vport_attrs[] = {
5201 &dev_attr_link_state,
5202 &dev_attr_num_discovered_ports,
5203 &dev_attr_lpfc_drvr_version,
5204 &dev_attr_lpfc_log_verbose,
5205 &dev_attr_lpfc_lun_queue_depth,
5206 &dev_attr_lpfc_tgt_queue_depth,
5207 &dev_attr_lpfc_nodev_tmo,
5208 &dev_attr_lpfc_devloss_tmo,
5209 &dev_attr_lpfc_hba_queue_depth,
5210 &dev_attr_lpfc_peer_port_login,
5211 &dev_attr_lpfc_restrict_login,
5212 &dev_attr_lpfc_fcp_class,
5213 &dev_attr_lpfc_use_adisc,
5214 &dev_attr_lpfc_first_burst_size,
5215 &dev_attr_lpfc_max_luns,
5216 &dev_attr_nport_evt_cnt,
5217 &dev_attr_npiv_info,
5218 &dev_attr_lpfc_enable_da_id,
5219 &dev_attr_lpfc_max_scsicmpl_time,
5220 &dev_attr_lpfc_stat_data_ctrl,
5221 &dev_attr_lpfc_static_vport,
5222 &dev_attr_lpfc_fips_level,
5223 &dev_attr_lpfc_fips_rev,
5228 * sysfs_ctlreg_write - Write method for writing to ctlreg
5229 * @filp: open sysfs file
5230 * @kobj: kernel kobject that contains the kernel class device.
5231 * @bin_attr: kernel attributes passed to us.
5232 * @buf: contains the data to be written to the adapter IOREG space.
5233 * @off: offset into buffer to beginning of data.
5234 * @count: bytes to transfer.
5237 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5238 * Uses the adapter io control registers to send buf contents to the adapter.
5241 * -ERANGE off and count combo out of range
5242 * -EINVAL off, count or buff address invalid
5243 * -EPERM adapter is offline
5244 * value of count, buf contents written
5247 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5248 struct bin_attribute *bin_attr,
5249 char *buf, loff_t off, size_t count)
5252 struct device *dev = container_of(kobj, struct device, kobj);
5253 struct Scsi_Host *shost = class_to_shost(dev);
5254 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5255 struct lpfc_hba *phba = vport->phba;
5257 if (phba->sli_rev >= LPFC_SLI_REV4)
5260 if ((off + count) > FF_REG_AREA_SIZE)
5263 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5266 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5269 /* This is to protect HBA registers from accidental writes. */
5270 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5273 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5276 spin_lock_irq(&phba->hbalock);
5277 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5278 buf_off += sizeof(uint32_t))
5279 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5280 phba->ctrl_regs_memmap_p + off + buf_off);
5282 spin_unlock_irq(&phba->hbalock);
5288 * sysfs_ctlreg_read - Read method for reading from ctlreg
5289 * @filp: open sysfs file
5290 * @kobj: kernel kobject that contains the kernel class device.
5291 * @bin_attr: kernel attributes passed to us.
5292 * @buf: if successful contains the data from the adapter IOREG space.
5293 * @off: offset into buffer to beginning of data.
5294 * @count: bytes to transfer.
5297 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5298 * Uses the adapter io control registers to read data into buf.
5301 * -ERANGE off and count combo out of range
5302 * -EINVAL off, count or buff address invalid
5303 * value of count, buf contents read
5306 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5307 struct bin_attribute *bin_attr,
5308 char *buf, loff_t off, size_t count)
5312 struct device *dev = container_of(kobj, struct device, kobj);
5313 struct Scsi_Host *shost = class_to_shost(dev);
5314 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5315 struct lpfc_hba *phba = vport->phba;
5317 if (phba->sli_rev >= LPFC_SLI_REV4)
5320 if (off > FF_REG_AREA_SIZE)
5323 if ((off + count) > FF_REG_AREA_SIZE)
5324 count = FF_REG_AREA_SIZE - off;
5326 if (count == 0) return 0;
5328 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5331 spin_lock_irq(&phba->hbalock);
5333 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5334 tmp_ptr = (uint32_t *)(buf + buf_off);
5335 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5338 spin_unlock_irq(&phba->hbalock);
5343 static struct bin_attribute sysfs_ctlreg_attr = {
5346 .mode = S_IRUSR | S_IWUSR,
5349 .read = sysfs_ctlreg_read,
5350 .write = sysfs_ctlreg_write,
5354 * sysfs_mbox_write - Write method for writing information via mbox
5355 * @filp: open sysfs file
5356 * @kobj: kernel kobject that contains the kernel class device.
5357 * @bin_attr: kernel attributes passed to us.
5358 * @buf: contains the data to be written to sysfs mbox.
5359 * @off: offset into buffer to beginning of data.
5360 * @count: bytes to transfer.
5363 * Deprecated function. All mailbox access from user space is performed via the
5367 * -EPERM operation not permitted
5370 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5371 struct bin_attribute *bin_attr,
5372 char *buf, loff_t off, size_t count)
5378 * sysfs_mbox_read - Read method for reading information via mbox
5379 * @filp: open sysfs file
5380 * @kobj: kernel kobject that contains the kernel class device.
5381 * @bin_attr: kernel attributes passed to us.
5382 * @buf: contains the data to be read from sysfs mbox.
5383 * @off: offset into buffer to beginning of data.
5384 * @count: bytes to transfer.
5387 * Deprecated function. All mailbox access from user space is performed via the
5391 * -EPERM operation not permitted
5394 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5395 struct bin_attribute *bin_attr,
5396 char *buf, loff_t off, size_t count)
5401 static struct bin_attribute sysfs_mbox_attr = {
5404 .mode = S_IRUSR | S_IWUSR,
5406 .size = MAILBOX_SYSFS_MAX,
5407 .read = sysfs_mbox_read,
5408 .write = sysfs_mbox_write,
5412 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5413 * @vport: address of lpfc vport structure.
5417 * error return code from sysfs_create_bin_file()
5420 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5422 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5425 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5426 &sysfs_drvr_stat_data_attr);
5428 /* Virtual ports do not need ctrl_reg and mbox */
5429 if (error || vport->port_type == LPFC_NPIV_PORT)
5432 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5433 &sysfs_ctlreg_attr);
5435 goto out_remove_stat_attr;
5437 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5440 goto out_remove_ctlreg_attr;
5443 out_remove_ctlreg_attr:
5444 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5445 out_remove_stat_attr:
5446 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5447 &sysfs_drvr_stat_data_attr);
5453 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5454 * @vport: address of lpfc vport structure.
5457 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5459 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5460 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5461 &sysfs_drvr_stat_data_attr);
5462 /* Virtual ports do not need ctrl_reg and mbox */
5463 if (vport->port_type == LPFC_NPIV_PORT)
5465 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5466 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5470 * Dynamic FC Host Attributes Support
5474 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5475 * @shost: kernel scsi host pointer.
5478 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5480 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5482 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5483 sizeof fc_host_symbolic_name(shost));
5487 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5488 * @shost: kernel scsi host pointer.
5491 lpfc_get_host_port_id(struct Scsi_Host *shost)
5493 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5495 /* note: fc_myDID already in cpu endianness */
5496 fc_host_port_id(shost) = vport->fc_myDID;
5500 * lpfc_get_host_port_type - Set the value of the scsi host port type
5501 * @shost: kernel scsi host pointer.
5504 lpfc_get_host_port_type(struct Scsi_Host *shost)
5506 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5507 struct lpfc_hba *phba = vport->phba;
5509 spin_lock_irq(shost->host_lock);
5511 if (vport->port_type == LPFC_NPIV_PORT) {
5512 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5513 } else if (lpfc_is_link_up(phba)) {
5514 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5515 if (vport->fc_flag & FC_PUBLIC_LOOP)
5516 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5518 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5520 if (vport->fc_flag & FC_FABRIC)
5521 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5523 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5526 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5528 spin_unlock_irq(shost->host_lock);
5532 * lpfc_get_host_port_state - Set the value of the scsi host port state
5533 * @shost: kernel scsi host pointer.
5536 lpfc_get_host_port_state(struct Scsi_Host *shost)
5538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5539 struct lpfc_hba *phba = vport->phba;
5541 spin_lock_irq(shost->host_lock);
5543 if (vport->fc_flag & FC_OFFLINE_MODE)
5544 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5546 switch (phba->link_state) {
5547 case LPFC_LINK_UNKNOWN:
5548 case LPFC_LINK_DOWN:
5549 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5553 case LPFC_HBA_READY:
5554 /* Links up, reports port state accordingly */
5555 if (vport->port_state < LPFC_VPORT_READY)
5556 fc_host_port_state(shost) =
5557 FC_PORTSTATE_BYPASSED;
5559 fc_host_port_state(shost) =
5560 FC_PORTSTATE_ONLINE;
5562 case LPFC_HBA_ERROR:
5563 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5566 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5571 spin_unlock_irq(shost->host_lock);
5575 * lpfc_get_host_speed - Set the value of the scsi host speed
5576 * @shost: kernel scsi host pointer.
5579 lpfc_get_host_speed(struct Scsi_Host *shost)
5581 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5582 struct lpfc_hba *phba = vport->phba;
5584 spin_lock_irq(shost->host_lock);
5586 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5587 switch(phba->fc_linkspeed) {
5588 case LPFC_LINK_SPEED_1GHZ:
5589 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5591 case LPFC_LINK_SPEED_2GHZ:
5592 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5594 case LPFC_LINK_SPEED_4GHZ:
5595 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5597 case LPFC_LINK_SPEED_8GHZ:
5598 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5600 case LPFC_LINK_SPEED_10GHZ:
5601 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5603 case LPFC_LINK_SPEED_16GHZ:
5604 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5606 case LPFC_LINK_SPEED_32GHZ:
5607 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5610 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5614 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5616 spin_unlock_irq(shost->host_lock);
5620 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5621 * @shost: kernel scsi host pointer.
5624 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5626 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5627 struct lpfc_hba *phba = vport->phba;
5630 spin_lock_irq(shost->host_lock);
5632 if ((vport->port_state > LPFC_FLOGI) &&
5633 ((vport->fc_flag & FC_FABRIC) ||
5634 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5635 (vport->fc_flag & FC_PUBLIC_LOOP))))
5636 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5638 /* fabric is local port if there is no F/FL_Port */
5641 spin_unlock_irq(shost->host_lock);
5643 fc_host_fabric_name(shost) = node_name;
5647 * lpfc_get_stats - Return statistical information about the adapter
5648 * @shost: kernel scsi host pointer.
5651 * NULL on error for link down, no mbox pool, sli2 active,
5652 * management not allowed, memory allocation error, or mbox error.
5656 * address of the adapter host statistics
5658 static struct fc_host_statistics *
5659 lpfc_get_stats(struct Scsi_Host *shost)
5661 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5662 struct lpfc_hba *phba = vport->phba;
5663 struct lpfc_sli *psli = &phba->sli;
5664 struct fc_host_statistics *hs = &phba->link_stats;
5665 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5666 LPFC_MBOXQ_t *pmboxq;
5668 unsigned long seconds;
5672 * prevent udev from issuing mailbox commands until the port is
5675 if (phba->link_state < LPFC_LINK_DOWN ||
5676 !phba->mbox_mem_pool ||
5677 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5680 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5683 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5686 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5688 pmb = &pmboxq->u.mb;
5689 pmb->mbxCommand = MBX_READ_STATUS;
5690 pmb->mbxOwner = OWN_HOST;
5691 pmboxq->context1 = NULL;
5692 pmboxq->vport = vport;
5694 if (vport->fc_flag & FC_OFFLINE_MODE)
5695 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5697 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5699 if (rc != MBX_SUCCESS) {
5700 if (rc != MBX_TIMEOUT)
5701 mempool_free(pmboxq, phba->mbox_mem_pool);
5705 memset(hs, 0, sizeof (struct fc_host_statistics));
5707 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5709 * The MBX_READ_STATUS returns tx_k_bytes which has to
5710 * converted to words
5712 hs->tx_words = (uint64_t)
5713 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5715 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5716 hs->rx_words = (uint64_t)
5717 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5720 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5721 pmb->mbxCommand = MBX_READ_LNK_STAT;
5722 pmb->mbxOwner = OWN_HOST;
5723 pmboxq->context1 = NULL;
5724 pmboxq->vport = vport;
5726 if (vport->fc_flag & FC_OFFLINE_MODE)
5727 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5729 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5731 if (rc != MBX_SUCCESS) {
5732 if (rc != MBX_TIMEOUT)
5733 mempool_free(pmboxq, phba->mbox_mem_pool);
5737 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5738 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5739 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5740 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5741 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5742 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5743 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5745 hs->link_failure_count -= lso->link_failure_count;
5746 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5747 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5748 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5749 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5750 hs->invalid_crc_count -= lso->invalid_crc_count;
5751 hs->error_frames -= lso->error_frames;
5753 if (phba->hba_flag & HBA_FCOE_MODE) {
5755 hs->nos_count = (phba->link_events >> 1);
5756 hs->nos_count -= lso->link_events;
5757 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5758 hs->lip_count = (phba->fc_eventTag >> 1);
5759 hs->lip_count -= lso->link_events;
5763 hs->nos_count = (phba->fc_eventTag >> 1);
5764 hs->nos_count -= lso->link_events;
5767 hs->dumped_frames = -1;
5769 seconds = get_seconds();
5770 if (seconds < psli->stats_start)
5771 hs->seconds_since_last_reset = seconds +
5772 ((unsigned long)-1 - psli->stats_start);
5774 hs->seconds_since_last_reset = seconds - psli->stats_start;
5776 mempool_free(pmboxq, phba->mbox_mem_pool);
5782 * lpfc_reset_stats - Copy the adapter link stats information
5783 * @shost: kernel scsi host pointer.
5786 lpfc_reset_stats(struct Scsi_Host *shost)
5788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5789 struct lpfc_hba *phba = vport->phba;
5790 struct lpfc_sli *psli = &phba->sli;
5791 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5792 LPFC_MBOXQ_t *pmboxq;
5796 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5799 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5802 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5804 pmb = &pmboxq->u.mb;
5805 pmb->mbxCommand = MBX_READ_STATUS;
5806 pmb->mbxOwner = OWN_HOST;
5807 pmb->un.varWords[0] = 0x1; /* reset request */
5808 pmboxq->context1 = NULL;
5809 pmboxq->vport = vport;
5811 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5812 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5813 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5815 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5817 if (rc != MBX_SUCCESS) {
5818 if (rc != MBX_TIMEOUT)
5819 mempool_free(pmboxq, phba->mbox_mem_pool);
5823 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5824 pmb->mbxCommand = MBX_READ_LNK_STAT;
5825 pmb->mbxOwner = OWN_HOST;
5826 pmboxq->context1 = NULL;
5827 pmboxq->vport = vport;
5829 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5830 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5831 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5833 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5835 if (rc != MBX_SUCCESS) {
5836 if (rc != MBX_TIMEOUT)
5837 mempool_free( pmboxq, phba->mbox_mem_pool);
5841 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5842 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5843 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5844 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5845 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5846 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5847 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5848 if (phba->hba_flag & HBA_FCOE_MODE)
5849 lso->link_events = (phba->link_events >> 1);
5851 lso->link_events = (phba->fc_eventTag >> 1);
5853 psli->stats_start = get_seconds();
5855 mempool_free(pmboxq, phba->mbox_mem_pool);
5861 * The LPFC driver treats linkdown handling as target loss events so there
5862 * are no sysfs handlers for link_down_tmo.
5866 * lpfc_get_node_by_target - Return the nodelist for a target
5867 * @starget: kernel scsi target pointer.
5870 * address of the node list if found
5871 * NULL target not found
5873 static struct lpfc_nodelist *
5874 lpfc_get_node_by_target(struct scsi_target *starget)
5876 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5877 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5878 struct lpfc_nodelist *ndlp;
5880 spin_lock_irq(shost->host_lock);
5881 /* Search for this, mapped, target ID */
5882 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5883 if (NLP_CHK_NODE_ACT(ndlp) &&
5884 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5885 starget->id == ndlp->nlp_sid) {
5886 spin_unlock_irq(shost->host_lock);
5890 spin_unlock_irq(shost->host_lock);
5895 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5896 * @starget: kernel scsi target pointer.
5899 lpfc_get_starget_port_id(struct scsi_target *starget)
5901 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5903 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5907 * lpfc_get_starget_node_name - Set the target node name
5908 * @starget: kernel scsi target pointer.
5910 * Description: Set the target node name to the ndlp node name wwn or zero.
5913 lpfc_get_starget_node_name(struct scsi_target *starget)
5915 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5917 fc_starget_node_name(starget) =
5918 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5922 * lpfc_get_starget_port_name - Set the target port name
5923 * @starget: kernel scsi target pointer.
5925 * Description: set the target port name to the ndlp port name wwn or zero.
5928 lpfc_get_starget_port_name(struct scsi_target *starget)
5930 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5932 fc_starget_port_name(starget) =
5933 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5937 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5938 * @rport: fc rport address.
5939 * @timeout: new value for dev loss tmo.
5942 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5943 * dev_loss_tmo to one.
5946 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5949 rport->dev_loss_tmo = timeout;
5951 rport->dev_loss_tmo = 1;
5955 * lpfc_rport_show_function - Return rport target information
5958 * Macro that uses field to generate a function with the name lpfc_show_rport_
5960 * lpfc_show_rport_##field: returns the bytes formatted in buf
5961 * @cdev: class converted to an fc_rport.
5962 * @buf: on return contains the target_field or zero.
5964 * Returns: size of formatted string.
5966 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5968 lpfc_show_rport_##field (struct device *dev, \
5969 struct device_attribute *attr, \
5972 struct fc_rport *rport = transport_class_to_rport(dev); \
5973 struct lpfc_rport_data *rdata = rport->hostdata; \
5974 return snprintf(buf, sz, format_string, \
5975 (rdata->target) ? cast rdata->target->field : 0); \
5978 #define lpfc_rport_rd_attr(field, format_string, sz) \
5979 lpfc_rport_show_function(field, format_string, sz, ) \
5980 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5983 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
5984 * @fc_vport: The fc_vport who's symbolic name has been changed.
5987 * This function is called by the transport after the @fc_vport's symbolic name
5988 * has been changed. This function re-registers the symbolic name with the
5989 * switch to propagate the change into the fabric if the vport is active.
5992 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5994 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5996 if (vport->port_state == LPFC_VPORT_READY)
5997 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6001 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6002 * @phba: Pointer to lpfc_hba struct.
6004 * This function is called by the lpfc_get_cfgparam() routine to set the
6005 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6006 * log message according to the module's lpfc_log_verbose parameter setting
6007 * before hba port or vport created.
6010 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6012 phba->cfg_log_verbose = verbose;
6015 struct fc_function_template lpfc_transport_functions = {
6016 /* fixed attributes the driver supports */
6017 .show_host_node_name = 1,
6018 .show_host_port_name = 1,
6019 .show_host_supported_classes = 1,
6020 .show_host_supported_fc4s = 1,
6021 .show_host_supported_speeds = 1,
6022 .show_host_maxframe_size = 1,
6024 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6025 .show_host_symbolic_name = 1,
6027 /* dynamic attributes the driver supports */
6028 .get_host_port_id = lpfc_get_host_port_id,
6029 .show_host_port_id = 1,
6031 .get_host_port_type = lpfc_get_host_port_type,
6032 .show_host_port_type = 1,
6034 .get_host_port_state = lpfc_get_host_port_state,
6035 .show_host_port_state = 1,
6037 /* active_fc4s is shown but doesn't change (thus no get function) */
6038 .show_host_active_fc4s = 1,
6040 .get_host_speed = lpfc_get_host_speed,
6041 .show_host_speed = 1,
6043 .get_host_fabric_name = lpfc_get_host_fabric_name,
6044 .show_host_fabric_name = 1,
6047 * The LPFC driver treats linkdown handling as target loss events
6048 * so there are no sysfs handlers for link_down_tmo.
6051 .get_fc_host_stats = lpfc_get_stats,
6052 .reset_fc_host_stats = lpfc_reset_stats,
6054 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6055 .show_rport_maxframe_size = 1,
6056 .show_rport_supported_classes = 1,
6058 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6059 .show_rport_dev_loss_tmo = 1,
6061 .get_starget_port_id = lpfc_get_starget_port_id,
6062 .show_starget_port_id = 1,
6064 .get_starget_node_name = lpfc_get_starget_node_name,
6065 .show_starget_node_name = 1,
6067 .get_starget_port_name = lpfc_get_starget_port_name,
6068 .show_starget_port_name = 1,
6070 .issue_fc_host_lip = lpfc_issue_lip,
6071 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6072 .terminate_rport_io = lpfc_terminate_rport_io,
6074 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6076 .vport_disable = lpfc_vport_disable,
6078 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6080 .bsg_request = lpfc_bsg_request,
6081 .bsg_timeout = lpfc_bsg_timeout,
6084 struct fc_function_template lpfc_vport_transport_functions = {
6085 /* fixed attributes the driver supports */
6086 .show_host_node_name = 1,
6087 .show_host_port_name = 1,
6088 .show_host_supported_classes = 1,
6089 .show_host_supported_fc4s = 1,
6090 .show_host_supported_speeds = 1,
6091 .show_host_maxframe_size = 1,
6093 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6094 .show_host_symbolic_name = 1,
6096 /* dynamic attributes the driver supports */
6097 .get_host_port_id = lpfc_get_host_port_id,
6098 .show_host_port_id = 1,
6100 .get_host_port_type = lpfc_get_host_port_type,
6101 .show_host_port_type = 1,
6103 .get_host_port_state = lpfc_get_host_port_state,
6104 .show_host_port_state = 1,
6106 /* active_fc4s is shown but doesn't change (thus no get function) */
6107 .show_host_active_fc4s = 1,
6109 .get_host_speed = lpfc_get_host_speed,
6110 .show_host_speed = 1,
6112 .get_host_fabric_name = lpfc_get_host_fabric_name,
6113 .show_host_fabric_name = 1,
6116 * The LPFC driver treats linkdown handling as target loss events
6117 * so there are no sysfs handlers for link_down_tmo.
6120 .get_fc_host_stats = lpfc_get_stats,
6121 .reset_fc_host_stats = lpfc_reset_stats,
6123 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6124 .show_rport_maxframe_size = 1,
6125 .show_rport_supported_classes = 1,
6127 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6128 .show_rport_dev_loss_tmo = 1,
6130 .get_starget_port_id = lpfc_get_starget_port_id,
6131 .show_starget_port_id = 1,
6133 .get_starget_node_name = lpfc_get_starget_node_name,
6134 .show_starget_node_name = 1,
6136 .get_starget_port_name = lpfc_get_starget_port_name,
6137 .show_starget_port_name = 1,
6139 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6140 .terminate_rport_io = lpfc_terminate_rport_io,
6142 .vport_disable = lpfc_vport_disable,
6144 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6148 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6149 * @phba: lpfc_hba pointer.
6152 lpfc_get_cfgparam(struct lpfc_hba *phba)
6154 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6155 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6156 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6157 lpfc_cr_count_init(phba, lpfc_cr_count);
6158 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6159 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6160 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6161 lpfc_ack0_init(phba, lpfc_ack0);
6162 lpfc_topology_init(phba, lpfc_topology);
6163 lpfc_link_speed_init(phba, lpfc_link_speed);
6164 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6165 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6166 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6167 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6168 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6169 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6170 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6171 lpfc_use_msi_init(phba, lpfc_use_msi);
6172 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6173 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6174 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6175 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6176 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6178 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6179 if (phba->sli_rev != LPFC_SLI_REV4)
6180 phba->cfg_EnableXLane = 0;
6181 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6183 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6184 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6185 phba->cfg_oas_lun_state = 0;
6186 phba->cfg_oas_lun_status = 0;
6187 phba->cfg_oas_flags = 0;
6188 phba->cfg_oas_priority = 0;
6189 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6190 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6191 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6192 if (phba->sli_rev == LPFC_SLI_REV4)
6195 phba->cfg_poll = lpfc_poll;
6196 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6198 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6199 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6201 /* Initialize first burst. Target vs Initiator are different. */
6202 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6203 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6204 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6205 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6207 if (phba->sli_rev != LPFC_SLI_REV4) {
6208 /* NVME only supported on SLI4 */
6209 phba->nvmet_support = 0;
6210 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6212 /* We MUST have FCP support */
6213 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6214 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6217 /* A value of 0 means use the number of CPUs found in the system */
6218 if (phba->cfg_fcp_io_channel == 0)
6219 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6220 if (phba->cfg_nvme_io_channel == 0)
6221 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6223 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6224 phba->cfg_fcp_io_channel = 0;
6226 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6227 phba->cfg_nvme_io_channel = 0;
6229 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6230 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6232 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6234 phba->cfg_soft_wwnn = 0L;
6235 phba->cfg_soft_wwpn = 0L;
6236 lpfc_xri_split_init(phba, lpfc_xri_split);
6237 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6238 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6239 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6240 lpfc_aer_support_init(phba, lpfc_aer_support);
6241 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6242 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6243 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6244 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6245 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6246 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6247 phba->cfg_enable_dss = 1;
6248 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6253 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6254 * dependencies between protocols and roles.
6255 * @phba: lpfc_hba pointer.
6258 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6260 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6261 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6263 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6264 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6266 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6267 phba->nvmet_support) {
6268 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6269 phba->cfg_fcp_io_channel = 0;
6271 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6272 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6273 "NVME Target PRLI ACC enable_fb ",
6274 phba->cfg_nvme_enable_fb,
6275 phba->cfg_nvmet_fb_size,
6276 LPFC_NVMET_FB_SZ_MAX);
6278 if (phba->cfg_nvme_enable_fb == 0)
6279 phba->cfg_nvmet_fb_size = 0;
6281 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6282 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6285 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6286 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6287 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6288 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6289 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6290 phba->cfg_nvmet_mrq);
6293 /* Not NVME Target mode. Turn off Target parameters. */
6294 phba->nvmet_support = 0;
6295 phba->cfg_nvmet_mrq = 0;
6296 phba->cfg_nvmet_fb_size = 0;
6299 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6300 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6302 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6306 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6307 * @vport: lpfc_vport pointer.
6310 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6312 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6313 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6314 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6315 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6316 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6317 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6318 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6319 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6320 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6321 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6322 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6323 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6324 lpfc_max_luns_init(vport, lpfc_max_luns);
6325 lpfc_scan_down_init(vport, lpfc_scan_down);
6326 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);