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 256
64 #define LPFC_MIN_MRQ_POST 32
65 #define LPFC_MAX_MRQ_POST 512
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_nvme_lport *lport;
152 struct lpfc_nvme_rport *rport;
153 struct nvme_fc_remote_port *nrport;
157 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
158 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
161 if (phba->nvmet_support) {
162 if (!phba->targetport) {
163 len = snprintf(buf, PAGE_SIZE,
164 "NVME Target: x%llx is not allocated\n",
165 wwn_to_u64(vport->fc_portname.u.wwn));
168 /* Port state is only one of two values for now. */
169 if (phba->targetport->port_id)
170 statep = "REGISTERED";
173 len += snprintf(buf + len, PAGE_SIZE - len,
174 "NVME Target: Enabled State %s\n",
176 len += snprintf(buf + len, PAGE_SIZE - len,
177 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
180 wwn_to_u64(vport->fc_portname.u.wwn),
181 wwn_to_u64(vport->fc_nodename.u.wwn),
182 phba->targetport->port_id);
184 len += snprintf(buf + len, PAGE_SIZE,
185 "\nNVME Target: Statistics\n");
186 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
187 len += snprintf(buf+len, PAGE_SIZE-len,
188 "LS: Rcv %08x Drop %08x Abort %08x\n",
189 atomic_read(&tgtp->rcv_ls_req_in),
190 atomic_read(&tgtp->rcv_ls_req_drop),
191 atomic_read(&tgtp->xmt_ls_abort));
192 if (atomic_read(&tgtp->rcv_ls_req_in) !=
193 atomic_read(&tgtp->rcv_ls_req_out)) {
194 len += snprintf(buf+len, PAGE_SIZE-len,
195 "Rcv LS: in %08x != out %08x\n",
196 atomic_read(&tgtp->rcv_ls_req_in),
197 atomic_read(&tgtp->rcv_ls_req_out));
200 len += snprintf(buf+len, PAGE_SIZE-len,
201 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
202 atomic_read(&tgtp->xmt_ls_rsp),
203 atomic_read(&tgtp->xmt_ls_drop),
204 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
205 atomic_read(&tgtp->xmt_ls_rsp_error));
207 len += snprintf(buf+len, PAGE_SIZE-len,
208 "FCP: Rcv %08x Drop %08x\n",
209 atomic_read(&tgtp->rcv_fcp_cmd_in),
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\n",
222 atomic_read(&tgtp->xmt_fcp_read),
223 atomic_read(&tgtp->xmt_fcp_read_rsp),
224 atomic_read(&tgtp->xmt_fcp_write),
225 atomic_read(&tgtp->xmt_fcp_rsp));
227 len += snprintf(buf+len, PAGE_SIZE-len,
228 "FCP Rsp: abort %08x drop %08x\n",
229 atomic_read(&tgtp->xmt_fcp_abort),
230 atomic_read(&tgtp->xmt_fcp_drop));
232 len += snprintf(buf+len, PAGE_SIZE-len,
233 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
234 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
235 atomic_read(&tgtp->xmt_fcp_rsp_error),
236 atomic_read(&tgtp->xmt_fcp_rsp_drop));
238 len += snprintf(buf+len, PAGE_SIZE-len,
239 "ABORT: Xmt %08x Err %08x Cmpl %08x",
240 atomic_read(&tgtp->xmt_abort_rsp),
241 atomic_read(&tgtp->xmt_abort_rsp_error),
242 atomic_read(&tgtp->xmt_abort_cmpl));
244 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
248 localport = vport->localport;
250 len = snprintf(buf, PAGE_SIZE,
251 "NVME Initiator x%llx is not allocated\n",
252 wwn_to_u64(vport->fc_portname.u.wwn));
255 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
257 spin_lock_irq(shost->host_lock);
258 lport = (struct lpfc_nvme_lport *)localport->private;
260 /* Port state is only one of two values for now. */
261 if (localport->port_id)
266 len += snprintf(buf + len, PAGE_SIZE - len,
267 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
270 wwn_to_u64(vport->fc_portname.u.wwn),
271 wwn_to_u64(vport->fc_nodename.u.wwn),
272 localport->port_id, statep);
274 list_for_each_entry(rport, &lport->rport_list, list) {
275 /* local short-hand pointer. */
276 nrport = rport->remoteport;
278 /* Port state is only one of two values for now. */
279 switch (nrport->port_state) {
280 case FC_OBJSTATE_ONLINE:
283 case FC_OBJSTATE_UNKNOWN:
287 statep = "UNSUPPORTED";
291 /* Tab in to show lport ownership. */
292 len += snprintf(buf + len, PAGE_SIZE - len,
294 if (phba->brd_no >= 10)
295 len += snprintf(buf + len, PAGE_SIZE - len, " ");
297 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
299 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
301 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
304 switch (nrport->port_role) {
305 case FC_PORT_ROLE_NVME_INITIATOR:
306 len += snprintf(buf + len, PAGE_SIZE - len,
309 case FC_PORT_ROLE_NVME_TARGET:
310 len += snprintf(buf + len, PAGE_SIZE - len,
313 case FC_PORT_ROLE_NVME_DISCOVERY:
314 len += snprintf(buf + len, PAGE_SIZE - len,
318 len += snprintf(buf + len, PAGE_SIZE - len,
323 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
324 /* Terminate the string. */
325 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
327 spin_unlock_irq(shost->host_lock);
329 len += snprintf(buf + len, PAGE_SIZE, "\nNVME Statistics\n");
330 len += snprintf(buf+len, PAGE_SIZE-len,
331 "LS: Xmt %016llx Cmpl %016llx\n",
332 phba->fc4NvmeLsRequests,
333 phba->fc4NvmeLsCmpls);
335 len += snprintf(buf+len, PAGE_SIZE-len,
336 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
337 phba->fc4NvmeInputRequests,
338 phba->fc4NvmeOutputRequests,
339 phba->fc4NvmeControlRequests);
341 len += snprintf(buf+len, PAGE_SIZE-len,
342 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
348 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
351 struct Scsi_Host *shost = class_to_shost(dev);
352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353 struct lpfc_hba *phba = vport->phba;
355 if (phba->cfg_enable_bg)
356 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
357 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
359 return snprintf(buf, PAGE_SIZE,
360 "BlockGuard Not Supported\n");
362 return snprintf(buf, PAGE_SIZE,
363 "BlockGuard Disabled\n");
367 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
370 struct Scsi_Host *shost = class_to_shost(dev);
371 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
372 struct lpfc_hba *phba = vport->phba;
374 return snprintf(buf, PAGE_SIZE, "%llu\n",
375 (unsigned long long)phba->bg_guard_err_cnt);
379 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
382 struct Scsi_Host *shost = class_to_shost(dev);
383 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
384 struct lpfc_hba *phba = vport->phba;
386 return snprintf(buf, PAGE_SIZE, "%llu\n",
387 (unsigned long long)phba->bg_apptag_err_cnt);
391 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
394 struct Scsi_Host *shost = class_to_shost(dev);
395 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
396 struct lpfc_hba *phba = vport->phba;
398 return snprintf(buf, PAGE_SIZE, "%llu\n",
399 (unsigned long long)phba->bg_reftag_err_cnt);
403 * lpfc_info_show - Return some pci info about the host in ascii
404 * @dev: class converted to a Scsi_host structure.
405 * @attr: device attribute, not used.
406 * @buf: on return contains the formatted text from lpfc_info().
408 * Returns: size of formatted string.
411 lpfc_info_show(struct device *dev, struct device_attribute *attr,
414 struct Scsi_Host *host = class_to_shost(dev);
416 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
420 * lpfc_serialnum_show - Return the hba serial number in ascii
421 * @dev: class converted to a Scsi_host structure.
422 * @attr: device attribute, not used.
423 * @buf: on return contains the formatted text serial number.
425 * Returns: size of formatted string.
428 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
431 struct Scsi_Host *shost = class_to_shost(dev);
432 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
433 struct lpfc_hba *phba = vport->phba;
435 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
439 * lpfc_temp_sensor_show - Return the temperature sensor level
440 * @dev: class converted to a Scsi_host structure.
441 * @attr: device attribute, not used.
442 * @buf: on return contains the formatted support level.
445 * Returns a number indicating the temperature sensor level currently
446 * supported, zero or one in ascii.
448 * Returns: size of formatted string.
451 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
454 struct Scsi_Host *shost = class_to_shost(dev);
455 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
456 struct lpfc_hba *phba = vport->phba;
457 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
461 * lpfc_modeldesc_show - Return the model description of the hba
462 * @dev: class converted to a Scsi_host structure.
463 * @attr: device attribute, not used.
464 * @buf: on return contains the scsi vpd model description.
466 * Returns: size of formatted string.
469 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
472 struct Scsi_Host *shost = class_to_shost(dev);
473 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
474 struct lpfc_hba *phba = vport->phba;
476 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
480 * lpfc_modelname_show - Return the model name of the hba
481 * @dev: class converted to a Scsi_host structure.
482 * @attr: device attribute, not used.
483 * @buf: on return contains the scsi vpd model name.
485 * Returns: size of formatted string.
488 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
491 struct Scsi_Host *shost = class_to_shost(dev);
492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
493 struct lpfc_hba *phba = vport->phba;
495 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
499 * lpfc_programtype_show - Return the program type of the hba
500 * @dev: class converted to a Scsi_host structure.
501 * @attr: device attribute, not used.
502 * @buf: on return contains the scsi vpd program type.
504 * Returns: size of formatted string.
507 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
510 struct Scsi_Host *shost = class_to_shost(dev);
511 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
512 struct lpfc_hba *phba = vport->phba;
514 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
518 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
519 * @dev: class converted to a Scsi_host structure.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the Menlo Maintenance sli flag.
523 * Returns: size of formatted string.
526 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
528 struct Scsi_Host *shost = class_to_shost(dev);
529 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
530 struct lpfc_hba *phba = vport->phba;
532 return snprintf(buf, PAGE_SIZE, "%d\n",
533 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
537 * lpfc_vportnum_show - Return the port number in ascii of the hba
538 * @dev: class converted to a Scsi_host structure.
539 * @attr: device attribute, not used.
540 * @buf: on return contains scsi vpd program type.
542 * Returns: size of formatted string.
545 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
548 struct Scsi_Host *shost = class_to_shost(dev);
549 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
550 struct lpfc_hba *phba = vport->phba;
552 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
556 * lpfc_fwrev_show - Return the firmware rev running in the hba
557 * @dev: class converted to a Scsi_host structure.
558 * @attr: device attribute, not used.
559 * @buf: on return contains the scsi vpd program type.
561 * Returns: size of formatted string.
564 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
567 struct Scsi_Host *shost = class_to_shost(dev);
568 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
569 struct lpfc_hba *phba = vport->phba;
572 char fwrev[FW_REV_STR_SIZE];
575 lpfc_decode_firmware_rev(phba, fwrev, 1);
576 if_type = phba->sli4_hba.pc_sli4_params.if_type;
577 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
579 if (phba->sli_rev < LPFC_SLI_REV4)
580 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
581 fwrev, phba->sli_rev);
583 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
584 fwrev, phba->sli_rev, if_type, sli_family);
590 * lpfc_hdw_show - Return the jedec information about the hba
591 * @dev: class converted to a Scsi_host structure.
592 * @attr: device attribute, not used.
593 * @buf: on return contains the scsi vpd program type.
595 * Returns: size of formatted string.
598 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
601 struct Scsi_Host *shost = class_to_shost(dev);
602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
603 struct lpfc_hba *phba = vport->phba;
604 lpfc_vpd_t *vp = &phba->vpd;
606 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
607 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
611 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
612 * @dev: class converted to a Scsi_host structure.
613 * @attr: device attribute, not used.
614 * @buf: on return contains the ROM and FCode ascii strings.
616 * Returns: size of formatted string.
619 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
622 struct Scsi_Host *shost = class_to_shost(dev);
623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
624 struct lpfc_hba *phba = vport->phba;
625 char fwrev[FW_REV_STR_SIZE];
627 if (phba->sli_rev < LPFC_SLI_REV4)
628 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
630 lpfc_decode_firmware_rev(phba, fwrev, 1);
631 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
635 * lpfc_state_show - Return the link state of the port
636 * @dev: class converted to a Scsi_host structure.
637 * @attr: device attribute, not used.
638 * @buf: on return contains text describing the state of the link.
641 * The switch statement has no default so zero will be returned.
643 * Returns: size of formatted string.
646 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
649 struct Scsi_Host *shost = class_to_shost(dev);
650 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
651 struct lpfc_hba *phba = vport->phba;
654 switch (phba->link_state) {
655 case LPFC_LINK_UNKNOWN:
656 case LPFC_WARM_START:
657 case LPFC_INIT_START:
658 case LPFC_INIT_MBX_CMDS:
661 if (phba->hba_flag & LINK_DISABLED)
662 len += snprintf(buf + len, PAGE_SIZE-len,
663 "Link Down - User disabled\n");
665 len += snprintf(buf + len, PAGE_SIZE-len,
671 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
673 switch (vport->port_state) {
674 case LPFC_LOCAL_CFG_LINK:
675 len += snprintf(buf + len, PAGE_SIZE-len,
676 "Configuring Link\n");
680 case LPFC_FABRIC_CFG_LINK:
683 case LPFC_BUILD_DISC_LIST:
685 len += snprintf(buf + len, PAGE_SIZE - len,
688 case LPFC_VPORT_READY:
689 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
692 case LPFC_VPORT_FAILED:
693 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
696 case LPFC_VPORT_UNKNOWN:
697 len += snprintf(buf + len, PAGE_SIZE - len,
701 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
702 len += snprintf(buf + len, PAGE_SIZE-len,
703 " Menlo Maint Mode\n");
704 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
705 if (vport->fc_flag & FC_PUBLIC_LOOP)
706 len += snprintf(buf + len, PAGE_SIZE-len,
709 len += snprintf(buf + len, PAGE_SIZE-len,
712 if (vport->fc_flag & FC_FABRIC)
713 len += snprintf(buf + len, PAGE_SIZE-len,
716 len += snprintf(buf + len, PAGE_SIZE-len,
725 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
726 * @dev: class unused variable.
727 * @attr: device attribute, not used.
728 * @buf: on return contains the module description text.
730 * Returns: size of formatted string.
733 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
736 struct Scsi_Host *shost = class_to_shost(dev);
737 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
738 struct lpfc_hba *phba = vport->phba;
740 if (phba->sli_rev < LPFC_SLI_REV4)
741 return snprintf(buf, PAGE_SIZE, "fc\n");
743 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
744 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
745 return snprintf(buf, PAGE_SIZE, "fcoe\n");
746 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
747 return snprintf(buf, PAGE_SIZE, "fc\n");
749 return snprintf(buf, PAGE_SIZE, "unknown\n");
753 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
754 * (OAS) is supported.
755 * @dev: class unused variable.
756 * @attr: device attribute, not used.
757 * @buf: on return contains the module description text.
759 * Returns: size of formatted string.
762 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
765 struct Scsi_Host *shost = class_to_shost(dev);
766 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
767 struct lpfc_hba *phba = vport->phba;
769 return snprintf(buf, PAGE_SIZE, "%d\n",
770 phba->sli4_hba.pc_sli4_params.oas_supported);
774 * lpfc_link_state_store - Transition the link_state on an HBA port
775 * @dev: class device that is converted into a Scsi_host.
776 * @attr: device attribute, not used.
777 * @buf: one or more lpfc_polling_flags values.
781 * -EINVAL if the buffer is not "up" or "down"
782 * return from link state change function if non-zero
783 * length of the buf on success
786 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
787 const char *buf, size_t count)
789 struct Scsi_Host *shost = class_to_shost(dev);
790 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
791 struct lpfc_hba *phba = vport->phba;
793 int status = -EINVAL;
795 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
796 (phba->link_state == LPFC_LINK_DOWN))
797 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
798 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
799 (phba->link_state >= LPFC_LINK_UP))
800 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
809 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
810 * @dev: class device that is converted into a Scsi_host.
811 * @attr: device attribute, not used.
812 * @buf: on return contains the sum of fc mapped and unmapped.
815 * Returns the ascii text number of the sum of the fc mapped and unmapped
818 * Returns: size of formatted string.
821 lpfc_num_discovered_ports_show(struct device *dev,
822 struct device_attribute *attr, char *buf)
824 struct Scsi_Host *shost = class_to_shost(dev);
825 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
827 return snprintf(buf, PAGE_SIZE, "%d\n",
828 vport->fc_map_cnt + vport->fc_unmap_cnt);
832 * lpfc_issue_lip - Misnomer, name carried over from long ago
833 * @shost: Scsi_Host pointer.
836 * Bring the link down gracefully then re-init the link. The firmware will
837 * re-init the fiber channel interface as required. Does not issue a LIP.
840 * -EPERM port offline or management commands are being blocked
841 * -ENOMEM cannot allocate memory for the mailbox command
842 * -EIO error sending the mailbox command
846 lpfc_issue_lip(struct Scsi_Host *shost)
848 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
849 struct lpfc_hba *phba = vport->phba;
850 LPFC_MBOXQ_t *pmboxq;
851 int mbxstatus = MBXERR_ERROR;
853 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
854 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
857 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
862 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
863 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
864 pmboxq->u.mb.mbxOwner = OWN_HOST;
866 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
868 if ((mbxstatus == MBX_SUCCESS) &&
869 (pmboxq->u.mb.mbxStatus == 0 ||
870 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
871 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
872 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
873 phba->cfg_link_speed);
874 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
876 if ((mbxstatus == MBX_SUCCESS) &&
877 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
878 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
879 "2859 SLI authentication is required "
880 "for INIT_LINK but has not done yet\n");
883 lpfc_set_loopback_flag(phba);
884 if (mbxstatus != MBX_TIMEOUT)
885 mempool_free(pmboxq, phba->mbox_mem_pool);
887 if (mbxstatus == MBXERR_ERROR)
894 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
899 while (!list_empty(q)) {
900 spin_unlock_irq(lock);
902 if (cnt++ > 250) { /* 5 secs */
903 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
905 "Outstanding IO when ",
906 "bringing Adapter offline\n");
911 spin_unlock_irq(lock);
916 * lpfc_do_offline - Issues a mailbox command to bring the link down
917 * @phba: lpfc_hba pointer.
918 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
921 * Assumes any error from lpfc_do_offline() will be negative.
922 * Can wait up to 5 seconds for the port ring buffers count
923 * to reach zero, prints a warning if it is not zero and continues.
924 * lpfc_workq_post_event() returns a non-zero return code if call fails.
927 * -EIO error posting the event
931 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
933 struct completion online_compl;
934 struct lpfc_queue *qp = NULL;
935 struct lpfc_sli_ring *pring;
936 struct lpfc_sli *psli;
941 init_completion(&online_compl);
942 rc = lpfc_workq_post_event(phba, &status, &online_compl,
943 LPFC_EVT_OFFLINE_PREP);
947 wait_for_completion(&online_compl);
954 /* Wait a little for things to settle down, but not
955 * long enough for dev loss timeout to expire.
957 if (phba->sli_rev != LPFC_SLI_REV4) {
958 for (i = 0; i < psli->num_rings; i++) {
959 pring = &psli->sli3_ring[i];
960 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
965 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
969 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
975 init_completion(&online_compl);
976 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
980 wait_for_completion(&online_compl);
989 * lpfc_selective_reset - Offline then onlines the port
990 * @phba: lpfc_hba pointer.
993 * If the port is configured to allow a reset then the hba is brought
994 * offline then online.
997 * Assumes any error from lpfc_do_offline() will be negative.
998 * Do not make this function static.
1001 * lpfc_do_offline() return code if not zero
1002 * -EIO reset not configured or error posting the event
1006 lpfc_selective_reset(struct lpfc_hba *phba)
1008 struct completion online_compl;
1012 if (!phba->cfg_enable_hba_reset)
1015 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1016 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1022 init_completion(&online_compl);
1023 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1028 wait_for_completion(&online_compl);
1037 * lpfc_issue_reset - Selectively resets an adapter
1038 * @dev: class device that is converted into a Scsi_host.
1039 * @attr: device attribute, not used.
1040 * @buf: containing the string "selective".
1041 * @count: unused variable.
1044 * If the buf contains the string "selective" then lpfc_selective_reset()
1045 * is called to perform the reset.
1048 * Assumes any error from lpfc_selective_reset() will be negative.
1049 * If lpfc_selective_reset() returns zero then the length of the buffer
1050 * is returned which indicates success
1053 * -EINVAL if the buffer does not contain the string "selective"
1054 * length of buf if lpfc-selective_reset() if the call succeeds
1055 * return value of lpfc_selective_reset() if the call fails
1058 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1059 const char *buf, size_t count)
1061 struct Scsi_Host *shost = class_to_shost(dev);
1062 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1063 struct lpfc_hba *phba = vport->phba;
1064 int status = -EINVAL;
1066 if (!phba->cfg_enable_hba_reset)
1069 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1070 status = phba->lpfc_selective_reset(phba);
1079 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1080 * @phba: lpfc_hba pointer.
1083 * SLI4 interface type-2 device to wait on the sliport status register for
1084 * the readyness after performing a firmware reset.
1087 * zero for success, -EPERM when port does not have privilege to perform the
1088 * reset, -EIO when port timeout from recovering from the reset.
1091 * As the caller will interpret the return code by value, be careful in making
1092 * change or addition to return codes.
1095 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1097 struct lpfc_register portstat_reg = {0};
1101 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1102 &portstat_reg.word0);
1104 /* verify if privileged for the request operation */
1105 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1106 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1109 /* wait for the SLI port firmware ready after firmware reset */
1110 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1112 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1113 &portstat_reg.word0);
1114 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1116 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1118 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1123 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1130 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1131 * @phba: lpfc_hba pointer.
1134 * Request SLI4 interface type-2 device to perform a physical register set
1141 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1143 struct completion online_compl;
1144 struct pci_dev *pdev = phba->pcidev;
1145 uint32_t before_fc_flag;
1146 uint32_t sriov_nr_virtfn;
1148 int status = 0, rc = 0;
1149 int job_posted = 1, sriov_err;
1151 if (!phba->cfg_enable_hba_reset)
1154 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1155 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1156 LPFC_SLI_INTF_IF_TYPE_2))
1159 /* Keep state if we need to restore back */
1160 before_fc_flag = phba->pport->fc_flag;
1161 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1163 /* Disable SR-IOV virtual functions if enabled */
1164 if (phba->cfg_sriov_nr_virtfn) {
1165 pci_disable_sriov(pdev);
1166 phba->cfg_sriov_nr_virtfn = 0;
1169 if (opcode == LPFC_FW_DUMP)
1170 phba->hba_flag |= HBA_FW_DUMP_OP;
1172 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1175 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1179 /* wait for the device to be quiesced before firmware reset */
1182 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1183 LPFC_CTL_PDEV_CTL_OFFSET);
1185 if (opcode == LPFC_FW_DUMP)
1186 reg_val |= LPFC_FW_DUMP_REQUEST;
1187 else if (opcode == LPFC_FW_RESET)
1188 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1189 else if (opcode == LPFC_DV_RESET)
1190 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1192 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1193 LPFC_CTL_PDEV_CTL_OFFSET);
1195 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1197 /* delay driver action following IF_TYPE_2 reset */
1198 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1201 /* no privilege for reset */
1202 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1203 "3150 No privilege to perform the requested "
1204 "access: x%x\n", reg_val);
1205 } else if (rc == -EIO) {
1206 /* reset failed, there is nothing more we can do */
1207 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1208 "3153 Fail to perform the requested "
1209 "access: x%x\n", reg_val);
1213 /* keep the original port state */
1214 if (before_fc_flag & FC_OFFLINE_MODE)
1217 init_completion(&online_compl);
1218 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1223 wait_for_completion(&online_compl);
1226 /* in any case, restore the virtual functions enabled as before */
1227 if (sriov_nr_virtfn) {
1229 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1231 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1234 /* return proper error code */
1245 * lpfc_nport_evt_cnt_show - Return the number of nport events
1246 * @dev: class device that is converted into a Scsi_host.
1247 * @attr: device attribute, not used.
1248 * @buf: on return contains the ascii number of nport events.
1250 * Returns: size of formatted string.
1253 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1256 struct Scsi_Host *shost = class_to_shost(dev);
1257 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1258 struct lpfc_hba *phba = vport->phba;
1260 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1264 * lpfc_board_mode_show - Return the state of the board
1265 * @dev: class device that is converted into a Scsi_host.
1266 * @attr: device attribute, not used.
1267 * @buf: on return contains the state of the adapter.
1269 * Returns: size of formatted string.
1272 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1275 struct Scsi_Host *shost = class_to_shost(dev);
1276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1277 struct lpfc_hba *phba = vport->phba;
1280 if (phba->link_state == LPFC_HBA_ERROR)
1282 else if (phba->link_state == LPFC_WARM_START)
1283 state = "warm start";
1284 else if (phba->link_state == LPFC_INIT_START)
1289 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1293 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1294 * @dev: class device that is converted into a Scsi_host.
1295 * @attr: device attribute, not used.
1296 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1297 * @count: unused variable.
1300 * -EACCES if enable hba reset not enabled
1301 * -EINVAL if the buffer does not contain a valid string (see above)
1302 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1303 * buf length greater than zero indicates success
1306 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1307 const char *buf, size_t count)
1309 struct Scsi_Host *shost = class_to_shost(dev);
1310 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1311 struct lpfc_hba *phba = vport->phba;
1312 struct completion online_compl;
1313 char *board_mode_str = NULL;
1317 if (!phba->cfg_enable_hba_reset) {
1319 goto board_mode_out;
1322 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1323 "3050 lpfc_board_mode set to %s\n", buf);
1325 init_completion(&online_compl);
1327 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1328 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1332 goto board_mode_out;
1334 wait_for_completion(&online_compl);
1335 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1336 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1337 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1338 if (phba->sli_rev == LPFC_SLI_REV4)
1341 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1342 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1343 if (phba->sli_rev == LPFC_SLI_REV4)
1346 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1347 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1348 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1349 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1350 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1351 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1352 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1360 board_mode_str = strchr(buf, '\n');
1362 *board_mode_str = '\0';
1363 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1364 "3097 Failed \"%s\", status(%d), "
1366 buf, status, phba->pport->fc_flag);
1372 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1373 * @phba: pointer to the adapter structure.
1374 * @mxri: max xri count.
1375 * @axri: available xri count.
1376 * @mrpi: max rpi count.
1377 * @arpi: available rpi count.
1378 * @mvpi: max vpi count.
1379 * @avpi: available vpi count.
1382 * If an integer pointer for an count is not null then the value for the
1383 * count is returned.
1390 lpfc_get_hba_info(struct lpfc_hba *phba,
1391 uint32_t *mxri, uint32_t *axri,
1392 uint32_t *mrpi, uint32_t *arpi,
1393 uint32_t *mvpi, uint32_t *avpi)
1395 struct lpfc_mbx_read_config *rd_config;
1396 LPFC_MBOXQ_t *pmboxq;
1402 * prevent udev from issuing mailbox commands until the port is
1405 if (phba->link_state < LPFC_LINK_DOWN ||
1406 !phba->mbox_mem_pool ||
1407 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1410 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1413 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1416 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1418 pmb = &pmboxq->u.mb;
1419 pmb->mbxCommand = MBX_READ_CONFIG;
1420 pmb->mbxOwner = OWN_HOST;
1421 pmboxq->context1 = NULL;
1423 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1424 rc = MBX_NOT_FINISHED;
1426 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1428 if (rc != MBX_SUCCESS) {
1429 if (rc != MBX_TIMEOUT)
1430 mempool_free(pmboxq, phba->mbox_mem_pool);
1434 if (phba->sli_rev == LPFC_SLI_REV4) {
1435 rd_config = &pmboxq->u.mqe.un.rd_config;
1437 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1439 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1440 phba->sli4_hba.max_cfg_param.rpi_used;
1442 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1444 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1445 phba->sli4_hba.max_cfg_param.xri_used;
1447 /* Account for differences with SLI-3. Get vpi count from
1448 * mailbox data and subtract one for max vpi value.
1450 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1451 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1456 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1459 *mrpi = pmb->un.varRdConfig.max_rpi;
1461 *arpi = pmb->un.varRdConfig.avail_rpi;
1463 *mxri = pmb->un.varRdConfig.max_xri;
1465 *axri = pmb->un.varRdConfig.avail_xri;
1467 *mvpi = pmb->un.varRdConfig.max_vpi;
1469 *avpi = pmb->un.varRdConfig.avail_vpi;
1472 mempool_free(pmboxq, phba->mbox_mem_pool);
1477 * lpfc_max_rpi_show - Return maximum rpi
1478 * @dev: class device that is converted into a Scsi_host.
1479 * @attr: device attribute, not used.
1480 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1483 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1484 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1485 * to "Unknown" and the buffer length is returned, therefore the caller
1486 * must check for "Unknown" in the buffer to detect a failure.
1488 * Returns: size of formatted string.
1491 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1494 struct Scsi_Host *shost = class_to_shost(dev);
1495 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1496 struct lpfc_hba *phba = vport->phba;
1499 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1500 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1501 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1505 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1506 * @dev: class device that is converted into a Scsi_host.
1507 * @attr: device attribute, not used.
1508 * @buf: containing the used rpi count in decimal or "Unknown".
1511 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1512 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1513 * to "Unknown" and the buffer length is returned, therefore the caller
1514 * must check for "Unknown" in the buffer to detect a failure.
1516 * Returns: size of formatted string.
1519 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1522 struct Scsi_Host *shost = class_to_shost(dev);
1523 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1524 struct lpfc_hba *phba = vport->phba;
1527 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1528 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1529 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1533 * lpfc_max_xri_show - Return maximum xri
1534 * @dev: class device that is converted into a Scsi_host.
1535 * @attr: device attribute, not used.
1536 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1539 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1540 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1541 * to "Unknown" and the buffer length is returned, therefore the caller
1542 * must check for "Unknown" in the buffer to detect a failure.
1544 * Returns: size of formatted string.
1547 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1550 struct Scsi_Host *shost = class_to_shost(dev);
1551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1552 struct lpfc_hba *phba = vport->phba;
1555 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1556 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1557 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1561 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1562 * @dev: class device that is converted into a Scsi_host.
1563 * @attr: device attribute, not used.
1564 * @buf: on return contains the used xri count in decimal or "Unknown".
1567 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1568 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1569 * to "Unknown" and the buffer length is returned, therefore the caller
1570 * must check for "Unknown" in the buffer to detect a failure.
1572 * Returns: size of formatted string.
1575 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1578 struct Scsi_Host *shost = class_to_shost(dev);
1579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1580 struct lpfc_hba *phba = vport->phba;
1583 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1584 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1585 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1589 * lpfc_max_vpi_show - Return maximum vpi
1590 * @dev: class device that is converted into a Scsi_host.
1591 * @attr: device attribute, not used.
1592 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1595 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1596 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1597 * to "Unknown" and the buffer length is returned, therefore the caller
1598 * must check for "Unknown" in the buffer to detect a failure.
1600 * Returns: size of formatted string.
1603 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1606 struct Scsi_Host *shost = class_to_shost(dev);
1607 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1608 struct lpfc_hba *phba = vport->phba;
1611 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1612 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1613 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1617 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1618 * @dev: class device that is converted into a Scsi_host.
1619 * @attr: device attribute, not used.
1620 * @buf: on return contains the used vpi count in decimal or "Unknown".
1623 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1624 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1625 * to "Unknown" and the buffer length is returned, therefore the caller
1626 * must check for "Unknown" in the buffer to detect a failure.
1628 * Returns: size of formatted string.
1631 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1634 struct Scsi_Host *shost = class_to_shost(dev);
1635 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1636 struct lpfc_hba *phba = vport->phba;
1639 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1640 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1641 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1645 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1646 * @dev: class device that is converted into a Scsi_host.
1647 * @attr: device attribute, not used.
1648 * @buf: text that must be interpreted to determine if npiv is supported.
1651 * Buffer will contain text indicating npiv is not suppoerted on the port,
1652 * the port is an NPIV physical port, or it is an npiv virtual port with
1653 * the id of the vport.
1655 * Returns: size of formatted string.
1658 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1661 struct Scsi_Host *shost = class_to_shost(dev);
1662 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1663 struct lpfc_hba *phba = vport->phba;
1665 if (!(phba->max_vpi))
1666 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1667 if (vport->port_type == LPFC_PHYSICAL_PORT)
1668 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1669 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1673 * lpfc_poll_show - Return text about poll support for the adapter
1674 * @dev: class device that is converted into a Scsi_host.
1675 * @attr: device attribute, not used.
1676 * @buf: on return contains the cfg_poll in hex.
1679 * cfg_poll should be a lpfc_polling_flags type.
1681 * Returns: size of formatted string.
1684 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1687 struct Scsi_Host *shost = class_to_shost(dev);
1688 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1689 struct lpfc_hba *phba = vport->phba;
1691 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1695 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1696 * @dev: class device that is converted into a Scsi_host.
1697 * @attr: device attribute, not used.
1698 * @buf: one or more lpfc_polling_flags values.
1702 * buf contents converted to integer and checked for a valid value.
1705 * -EINVAL if the buffer connot be converted or is out of range
1706 * length of the buf on success
1709 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1710 const char *buf, size_t count)
1712 struct Scsi_Host *shost = class_to_shost(dev);
1713 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1714 struct lpfc_hba *phba = vport->phba;
1719 if (!isdigit(buf[0]))
1722 if (sscanf(buf, "%i", &val) != 1)
1725 if ((val & 0x3) != val)
1728 if (phba->sli_rev == LPFC_SLI_REV4)
1731 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1732 "3051 lpfc_poll changed from %d to %d\n",
1733 phba->cfg_poll, val);
1735 spin_lock_irq(&phba->hbalock);
1737 old_val = phba->cfg_poll;
1739 if (val & ENABLE_FCP_RING_POLLING) {
1740 if ((val & DISABLE_FCP_RING_INT) &&
1741 !(old_val & DISABLE_FCP_RING_INT)) {
1742 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1743 spin_unlock_irq(&phba->hbalock);
1746 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1747 writel(creg_val, phba->HCregaddr);
1748 readl(phba->HCregaddr); /* flush */
1750 lpfc_poll_start_timer(phba);
1752 } else if (val != 0x0) {
1753 spin_unlock_irq(&phba->hbalock);
1757 if (!(val & DISABLE_FCP_RING_INT) &&
1758 (old_val & DISABLE_FCP_RING_INT))
1760 spin_unlock_irq(&phba->hbalock);
1761 del_timer(&phba->fcp_poll_timer);
1762 spin_lock_irq(&phba->hbalock);
1763 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1764 spin_unlock_irq(&phba->hbalock);
1767 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1768 writel(creg_val, phba->HCregaddr);
1769 readl(phba->HCregaddr); /* flush */
1772 phba->cfg_poll = val;
1774 spin_unlock_irq(&phba->hbalock);
1780 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1781 * @dev: class unused variable.
1782 * @attr: device attribute, not used.
1783 * @buf: on return contains the module description text.
1785 * Returns: size of formatted string.
1788 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1791 struct Scsi_Host *shost = class_to_shost(dev);
1792 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1793 struct lpfc_hba *phba = vport->phba;
1795 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1799 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1800 * @dev: class unused variable.
1801 * @attr: device attribute, not used.
1802 * @buf: on return contains the module description text.
1804 * Returns: size of formatted string.
1807 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1810 struct Scsi_Host *shost = class_to_shost(dev);
1811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1812 struct lpfc_hba *phba = vport->phba;
1814 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1818 * lpfc_dss_show - Return the current state of dss and the configured state
1819 * @dev: class converted to a Scsi_host structure.
1820 * @attr: device attribute, not used.
1821 * @buf: on return contains the formatted text.
1823 * Returns: size of formatted string.
1826 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1829 struct Scsi_Host *shost = class_to_shost(dev);
1830 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1831 struct lpfc_hba *phba = vport->phba;
1833 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1834 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1835 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1840 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1841 * @dev: class converted to a Scsi_host structure.
1842 * @attr: device attribute, not used.
1843 * @buf: on return contains the formatted support level.
1846 * Returns the maximum number of virtual functions a physical function can
1847 * support, 0 will be returned if called on virtual function.
1849 * Returns: size of formatted string.
1852 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1853 struct device_attribute *attr,
1856 struct Scsi_Host *shost = class_to_shost(dev);
1857 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1858 struct lpfc_hba *phba = vport->phba;
1859 uint16_t max_nr_virtfn;
1861 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1862 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1865 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1867 return val >= min && val <= max;
1871 * lpfc_param_show - Return a cfg attribute value in decimal
1874 * Macro that given an attr e.g. hba_queue_depth expands
1875 * into a function with the name lpfc_hba_queue_depth_show.
1877 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1878 * @dev: class device that is converted into a Scsi_host.
1879 * @attr: device attribute, not used.
1880 * @buf: on return contains the attribute value in decimal.
1882 * Returns: size of formatted string.
1884 #define lpfc_param_show(attr) \
1886 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1889 struct Scsi_Host *shost = class_to_shost(dev);\
1890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1891 struct lpfc_hba *phba = vport->phba;\
1892 return snprintf(buf, PAGE_SIZE, "%d\n",\
1897 * lpfc_param_hex_show - Return a cfg attribute value in hex
1900 * Macro that given an attr e.g. hba_queue_depth expands
1901 * into a function with the name lpfc_hba_queue_depth_show
1903 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1904 * @dev: class device that is converted into a Scsi_host.
1905 * @attr: device attribute, not used.
1906 * @buf: on return contains the attribute value in hexadecimal.
1908 * Returns: size of formatted string.
1910 #define lpfc_param_hex_show(attr) \
1912 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1915 struct Scsi_Host *shost = class_to_shost(dev);\
1916 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1917 struct lpfc_hba *phba = vport->phba;\
1919 val = phba->cfg_##attr;\
1920 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1925 * lpfc_param_init - Initializes a cfg attribute
1928 * Macro that given an attr e.g. hba_queue_depth expands
1929 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1930 * takes a default argument, a minimum and maximum argument.
1932 * lpfc_##attr##_init: Initializes an attribute.
1933 * @phba: pointer the the adapter structure.
1934 * @val: integer attribute value.
1936 * Validates the min and max values then sets the adapter config field
1937 * accordingly, or uses the default if out of range and prints an error message.
1941 * -EINVAL if default used
1943 #define lpfc_param_init(attr, default, minval, maxval) \
1945 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1947 if (lpfc_rangecheck(val, minval, maxval)) {\
1948 phba->cfg_##attr = val;\
1951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1952 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1953 "allowed range is ["#minval", "#maxval"]\n", val); \
1954 phba->cfg_##attr = default;\
1959 * lpfc_param_set - Set a cfg attribute value
1962 * Macro that given an attr e.g. hba_queue_depth expands
1963 * into a function with the name lpfc_hba_queue_depth_set
1965 * lpfc_##attr##_set: Sets an attribute value.
1966 * @phba: pointer the the adapter structure.
1967 * @val: integer attribute value.
1970 * Validates the min and max values then sets the
1971 * adapter config field if in the valid range. prints error message
1972 * and does not set the parameter if invalid.
1976 * -EINVAL if val is invalid
1978 #define lpfc_param_set(attr, default, minval, maxval) \
1980 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1982 if (lpfc_rangecheck(val, minval, maxval)) {\
1983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1984 "3052 lpfc_" #attr " changed from %d to %d\n", \
1985 phba->cfg_##attr, val); \
1986 phba->cfg_##attr = val;\
1989 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1990 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1991 "allowed range is ["#minval", "#maxval"]\n", val); \
1996 * lpfc_param_store - Set a vport attribute value
1999 * Macro that given an attr e.g. hba_queue_depth expands
2000 * into a function with the name lpfc_hba_queue_depth_store.
2002 * lpfc_##attr##_store: Set an sttribute value.
2003 * @dev: class device that is converted into a Scsi_host.
2004 * @attr: device attribute, not used.
2005 * @buf: contains the attribute value in ascii.
2009 * Convert the ascii text number to an integer, then
2010 * use the lpfc_##attr##_set function to set the value.
2013 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2014 * length of buffer upon success.
2016 #define lpfc_param_store(attr) \
2018 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2019 const char *buf, size_t count) \
2021 struct Scsi_Host *shost = class_to_shost(dev);\
2022 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2023 struct lpfc_hba *phba = vport->phba;\
2025 if (!isdigit(buf[0]))\
2027 if (sscanf(buf, "%i", &val) != 1)\
2029 if (lpfc_##attr##_set(phba, val) == 0) \
2030 return strlen(buf);\
2036 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2039 * Macro that given an attr e.g. hba_queue_depth expands
2040 * into a function with the name lpfc_hba_queue_depth_show
2042 * lpfc_##attr##_show: prints the attribute value in decimal.
2043 * @dev: class device that is converted into a Scsi_host.
2044 * @attr: device attribute, not used.
2045 * @buf: on return contains the attribute value in decimal.
2047 * Returns: length of formatted string.
2049 #define lpfc_vport_param_show(attr) \
2051 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2054 struct Scsi_Host *shost = class_to_shost(dev);\
2055 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2056 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2060 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2063 * Macro that given an attr e.g.
2064 * hba_queue_depth expands into a function with the name
2065 * lpfc_hba_queue_depth_show
2067 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2068 * @dev: class device that is converted into a Scsi_host.
2069 * @attr: device attribute, not used.
2070 * @buf: on return contains the attribute value in hexadecimal.
2072 * Returns: length of formatted string.
2074 #define lpfc_vport_param_hex_show(attr) \
2076 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2079 struct Scsi_Host *shost = class_to_shost(dev);\
2080 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2081 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2085 * lpfc_vport_param_init - Initialize a vport cfg attribute
2088 * Macro that given an attr e.g. hba_queue_depth expands
2089 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2090 * takes a default argument, a minimum and maximum argument.
2092 * lpfc_##attr##_init: validates the min and max values then sets the
2093 * adapter config field accordingly, or uses the default if out of range
2094 * and prints an error message.
2095 * @phba: pointer the the adapter structure.
2096 * @val: integer attribute value.
2100 * -EINVAL if default used
2102 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2104 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2106 if (lpfc_rangecheck(val, minval, maxval)) {\
2107 vport->cfg_##attr = val;\
2110 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2111 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2112 "allowed range is ["#minval", "#maxval"]\n", val); \
2113 vport->cfg_##attr = default;\
2118 * lpfc_vport_param_set - Set a vport cfg attribute
2121 * Macro that given an attr e.g. hba_queue_depth expands
2122 * into a function with the name lpfc_hba_queue_depth_set
2124 * lpfc_##attr##_set: validates the min and max values then sets the
2125 * adapter config field if in the valid range. prints error message
2126 * and does not set the parameter if invalid.
2127 * @phba: pointer the the adapter structure.
2128 * @val: integer attribute value.
2132 * -EINVAL if val is invalid
2134 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2136 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2138 if (lpfc_rangecheck(val, minval, maxval)) {\
2139 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2140 "3053 lpfc_" #attr \
2141 " changed from %d (x%x) to %d (x%x)\n", \
2142 vport->cfg_##attr, vport->cfg_##attr, \
2144 vport->cfg_##attr = val;\
2147 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2148 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2149 "allowed range is ["#minval", "#maxval"]\n", val); \
2154 * lpfc_vport_param_store - Set a vport attribute
2157 * Macro that given an attr e.g. hba_queue_depth
2158 * expands into a function with the name lpfc_hba_queue_depth_store
2160 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2161 * use the lpfc_##attr##_set function to set the value.
2162 * @cdev: class device that is converted into a Scsi_host.
2163 * @buf: contains the attribute value in decimal.
2167 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2168 * length of buffer upon success.
2170 #define lpfc_vport_param_store(attr) \
2172 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2173 const char *buf, size_t count) \
2175 struct Scsi_Host *shost = class_to_shost(dev);\
2176 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2178 if (!isdigit(buf[0]))\
2180 if (sscanf(buf, "%i", &val) != 1)\
2182 if (lpfc_##attr##_set(vport, val) == 0) \
2183 return strlen(buf);\
2189 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2190 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2191 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2192 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2193 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2194 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2195 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2196 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2197 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2198 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2199 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2200 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2201 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2202 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2203 lpfc_link_state_store);
2204 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2205 lpfc_option_rom_version_show, NULL);
2206 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2207 lpfc_num_discovered_ports_show, NULL);
2208 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2209 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2210 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2211 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2212 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2213 lpfc_board_mode_show, lpfc_board_mode_store);
2214 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2215 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2216 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2217 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2218 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2219 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2220 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2221 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2222 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2223 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2224 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2225 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2226 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2227 lpfc_sriov_hw_max_virtfn_show, NULL);
2228 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2229 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2232 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2235 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2237 * @cnt: Length of string.
2238 * @wwn: Array to receive converted wwn value.
2241 * -EINVAL if the buffer does not contain a valid wwn
2245 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2249 /* Count may include a LF at end of string */
2250 if (buf[cnt-1] == '\n')
2253 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2254 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2257 memset(wwn, 0, WWN_SZ);
2259 /* Validate and store the new name */
2260 for (i = 0, j = 0; i < 16; i++) {
2261 if ((*buf >= 'a') && (*buf <= 'f'))
2262 j = ((j << 4) | ((*buf++ - 'a') + 10));
2263 else if ((*buf >= 'A') && (*buf <= 'F'))
2264 j = ((j << 4) | ((*buf++ - 'A') + 10));
2265 else if ((*buf >= '0') && (*buf <= '9'))
2266 j = ((j << 4) | (*buf++ - '0'));
2270 wwn[i/2] = j & 0xff;
2277 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2278 * @dev: class device that is converted into a Scsi_host.
2279 * @attr: device attribute, not used.
2280 * @buf: containing the string lpfc_soft_wwn_key.
2281 * @count: must be size of lpfc_soft_wwn_key.
2284 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2285 * length of buf indicates success
2288 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2289 const char *buf, size_t count)
2291 struct Scsi_Host *shost = class_to_shost(dev);
2292 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2293 struct lpfc_hba *phba = vport->phba;
2294 unsigned int cnt = count;
2297 * We're doing a simple sanity check for soft_wwpn setting.
2298 * We require that the user write a specific key to enable
2299 * the soft_wwpn attribute to be settable. Once the attribute
2300 * is written, the enable key resets. If further updates are
2301 * desired, the key must be written again to re-enable the
2304 * The "key" is not secret - it is a hardcoded string shown
2305 * here. The intent is to protect against the random user or
2306 * application that is just writing attributes.
2309 /* count may include a LF at end of string */
2310 if (buf[cnt-1] == '\n')
2313 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2314 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2317 phba->soft_wwn_enable = 1;
2319 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2320 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2322 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2323 " The soft_wwpn feature is not supported by Broadcom.");
2327 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2328 lpfc_soft_wwn_enable_store);
2331 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2332 * @dev: class device that is converted into a Scsi_host.
2333 * @attr: device attribute, not used.
2334 * @buf: on return contains the wwpn in hexadecimal.
2336 * Returns: size of formatted string.
2339 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2342 struct Scsi_Host *shost = class_to_shost(dev);
2343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2344 struct lpfc_hba *phba = vport->phba;
2346 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2347 (unsigned long long)phba->cfg_soft_wwpn);
2351 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2352 * @dev class device that is converted into a Scsi_host.
2353 * @attr: device attribute, not used.
2354 * @buf: contains the wwpn in hexadecimal.
2355 * @count: number of wwpn bytes in buf
2358 * -EACCES hba reset not enabled, adapter over temp
2359 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2360 * -EIO error taking adapter offline or online
2361 * value of count on success
2364 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2365 const char *buf, size_t count)
2367 struct Scsi_Host *shost = class_to_shost(dev);
2368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2369 struct lpfc_hba *phba = vport->phba;
2370 struct completion online_compl;
2371 int stat1 = 0, stat2 = 0;
2372 unsigned int cnt = count;
2376 if (!phba->cfg_enable_hba_reset)
2378 spin_lock_irq(&phba->hbalock);
2379 if (phba->over_temp_state == HBA_OVER_TEMP) {
2380 spin_unlock_irq(&phba->hbalock);
2383 spin_unlock_irq(&phba->hbalock);
2384 /* count may include a LF at end of string */
2385 if (buf[cnt-1] == '\n')
2388 if (!phba->soft_wwn_enable)
2391 /* lock setting wwpn, wwnn down */
2392 phba->soft_wwn_enable = 0;
2394 rc = lpfc_wwn_set(buf, cnt, wwpn);
2396 /* not able to set wwpn, unlock it */
2397 phba->soft_wwn_enable = 1;
2401 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2402 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2403 if (phba->cfg_soft_wwnn)
2404 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2406 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2407 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2409 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2411 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2412 "0463 lpfc_soft_wwpn attribute set failed to "
2413 "reinit adapter - %d\n", stat1);
2414 init_completion(&online_compl);
2415 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2420 wait_for_completion(&online_compl);
2422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2423 "0464 lpfc_soft_wwpn attribute set failed to "
2424 "reinit adapter - %d\n", stat2);
2425 return (stat1 || stat2) ? -EIO : count;
2427 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2428 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2431 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2432 * @dev: class device that is converted into a Scsi_host.
2433 * @attr: device attribute, not used.
2434 * @buf: on return contains the wwnn in hexadecimal.
2436 * Returns: size of formatted string.
2439 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2442 struct Scsi_Host *shost = class_to_shost(dev);
2443 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2444 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2445 (unsigned long long)phba->cfg_soft_wwnn);
2449 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2450 * @cdev: class device that is converted into a Scsi_host.
2451 * @buf: contains the ww node name in hexadecimal.
2452 * @count: number of wwnn bytes in buf.
2455 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2456 * value of count on success
2459 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2460 const char *buf, size_t count)
2462 struct Scsi_Host *shost = class_to_shost(dev);
2463 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2464 unsigned int cnt = count;
2468 /* count may include a LF at end of string */
2469 if (buf[cnt-1] == '\n')
2472 if (!phba->soft_wwn_enable)
2475 rc = lpfc_wwn_set(buf, cnt, wwnn);
2477 /* Allow wwnn to be set many times, as long as the enable
2478 * is set. However, once the wwpn is set, everything locks.
2483 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2485 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2486 "lpfc%d: soft_wwnn set. Value will take effect upon "
2487 "setting of the soft_wwpn\n", phba->brd_no);
2491 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2492 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2495 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2496 * Optimized Access Storage (OAS) operations.
2497 * @dev: class device that is converted into a Scsi_host.
2498 * @attr: device attribute, not used.
2499 * @buf: buffer for passing information.
2505 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2508 struct Scsi_Host *shost = class_to_shost(dev);
2509 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2511 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2512 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2516 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2517 * Optimized Access Storage (OAS) operations.
2518 * @dev: class device that is converted into a Scsi_host.
2519 * @attr: device attribute, not used.
2520 * @buf: buffer for passing information.
2521 * @count: Size of the data buffer.
2524 * -EINVAL count is invalid, invalid wwpn byte invalid
2525 * -EPERM oas is not supported by hba
2526 * value of count on success
2529 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2530 const char *buf, size_t count)
2532 struct Scsi_Host *shost = class_to_shost(dev);
2533 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2534 unsigned int cnt = count;
2535 uint8_t wwpn[WWN_SZ];
2541 /* count may include a LF at end of string */
2542 if (buf[cnt-1] == '\n')
2545 rc = lpfc_wwn_set(buf, cnt, wwpn);
2549 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2550 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2551 if (wwn_to_u64(wwpn) == 0)
2552 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2554 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2555 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2556 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2559 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2560 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2563 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2564 * Optimized Access Storage (OAS) operations.
2565 * @dev: class device that is converted into a Scsi_host.
2566 * @attr: device attribute, not used.
2567 * @buf: buffer for passing information.
2573 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2576 struct Scsi_Host *shost = class_to_shost(dev);
2577 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2579 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2583 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2584 * Optimized Access Storage (OAS) operations.
2585 * @dev: class device that is converted into a Scsi_host.
2586 * @attr: device attribute, not used.
2587 * @buf: buffer for passing information.
2588 * @count: Size of the data buffer.
2591 * -EINVAL count is invalid, invalid wwpn byte invalid
2592 * -EPERM oas is not supported by hba
2593 * value of count on success
2596 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2597 const char *buf, size_t count)
2599 struct Scsi_Host *shost = class_to_shost(dev);
2600 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2601 unsigned int cnt = count;
2608 /* count may include a LF at end of string */
2609 if (buf[cnt-1] == '\n')
2612 ret = kstrtoul(buf, 0, &val);
2613 if (ret || (val > 0x7f))
2617 phba->cfg_oas_priority = (uint8_t)val;
2619 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2622 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2623 lpfc_oas_priority_show, lpfc_oas_priority_store);
2626 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2627 * for Optimized Access Storage (OAS) operations.
2628 * @dev: class device that is converted into a Scsi_host.
2629 * @attr: device attribute, not used.
2630 * @buf: buffer for passing information.
2633 * value of count on success
2636 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2639 struct Scsi_Host *shost = class_to_shost(dev);
2640 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2642 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2643 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2647 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2648 * for Optimized Access Storage (OAS) operations.
2649 * @dev: class device that is converted into a Scsi_host.
2650 * @attr: device attribute, not used.
2651 * @buf: buffer for passing information.
2652 * @count: Size of the data buffer.
2655 * -EINVAL count is invalid, invalid wwpn byte invalid
2656 * -EPERM oas is not supported by hba
2657 * value of count on success
2660 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2661 const char *buf, size_t count)
2663 struct Scsi_Host *shost = class_to_shost(dev);
2664 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2665 unsigned int cnt = count;
2666 uint8_t wwpn[WWN_SZ];
2672 /* count may include a LF at end of string */
2673 if (buf[cnt-1] == '\n')
2676 rc = lpfc_wwn_set(buf, cnt, wwpn);
2680 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2681 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2682 if (wwn_to_u64(wwpn) == 0)
2683 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2685 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2686 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2687 if (phba->cfg_oas_priority == 0)
2688 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2689 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2692 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2693 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2696 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2697 * of whether luns will be enabled or disabled
2698 * for Optimized Access Storage (OAS) operations.
2699 * @dev: class device that is converted into a Scsi_host.
2700 * @attr: device attribute, not used.
2701 * @buf: buffer for passing information.
2704 * size of formatted string.
2707 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2710 struct Scsi_Host *shost = class_to_shost(dev);
2711 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2713 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2717 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2718 * of whether luns will be enabled or disabled
2719 * for Optimized Access Storage (OAS) operations.
2720 * @dev: class device that is converted into a Scsi_host.
2721 * @attr: device attribute, not used.
2722 * @buf: buffer for passing information.
2723 * @count: Size of the data buffer.
2726 * -EINVAL count is invalid, invalid wwpn byte invalid
2727 * -EPERM oas is not supported by hba
2728 * value of count on success
2731 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2732 const char *buf, size_t count)
2734 struct Scsi_Host *shost = class_to_shost(dev);
2735 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2741 if (!isdigit(buf[0]))
2744 if (sscanf(buf, "%i", &val) != 1)
2747 if ((val != 0) && (val != 1))
2750 phba->cfg_oas_lun_state = val;
2753 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2754 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2757 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2758 * Storage (OAS) lun returned by the
2759 * lpfc_oas_lun_show function.
2760 * @dev: class device that is converted into a Scsi_host.
2761 * @attr: device attribute, not used.
2762 * @buf: buffer for passing information.
2765 * size of formatted string.
2768 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2771 struct Scsi_Host *shost = class_to_shost(dev);
2772 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2774 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2777 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2779 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2780 lpfc_oas_lun_status_show, NULL);
2784 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2786 * @phba: lpfc_hba pointer.
2787 * @ndlp: pointer to fcp target node.
2788 * @lun: the fc lun for setting oas state.
2789 * @oas_state: the oas state to be set to the lun.
2793 * -EPERM OAS is not enabled or not supported by this port.
2797 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2798 uint8_t tgt_wwpn[], uint64_t lun,
2799 uint32_t oas_state, uint8_t pri)
2808 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2809 (struct lpfc_name *)tgt_wwpn,
2813 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2814 (struct lpfc_name *)tgt_wwpn, lun, pri);
2821 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2822 * Access Storage (OAS) operations.
2823 * @phba: lpfc_hba pointer.
2824 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2825 * @tgt_wwpn: wwpn of the target associated with the returned lun
2826 * @lun_status: status of the lun returned lun
2828 * Returns the first or next lun enabled for OAS operations for the vport/target
2829 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2830 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2833 * lun that is OAS enabled for the vport/target
2834 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2837 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2838 uint8_t tgt_wwpn[], uint32_t *lun_status,
2843 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2844 return NOT_OAS_ENABLED_LUN;
2845 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2846 phba->sli4_hba.oas_next_vpt_wwpn,
2847 (struct lpfc_name *)
2848 phba->sli4_hba.oas_next_tgt_wwpn,
2849 &phba->sli4_hba.oas_next_lun,
2850 (struct lpfc_name *)vpt_wwpn,
2851 (struct lpfc_name *)tgt_wwpn,
2852 &found_lun, lun_status, lun_pri))
2855 return NOT_OAS_ENABLED_LUN;
2859 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2860 * @phba: lpfc_hba pointer.
2861 * @vpt_wwpn: vport wwpn by reference.
2862 * @tgt_wwpn: target wwpn by reference.
2863 * @lun: the fc lun for setting oas state.
2864 * @oas_state: the oas state to be set to the oas_lun.
2866 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2867 * a lun for OAS operations.
2871 * -ENOMEM: failed to enable an lun for OAS operations
2872 * -EPERM: OAS is not enabled
2875 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2876 uint8_t tgt_wwpn[], uint64_t lun,
2877 uint32_t oas_state, uint8_t pri)
2882 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2888 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2889 * @dev: class device that is converted into a Scsi_host.
2890 * @attr: device attribute, not used.
2891 * @buf: buffer for passing information.
2893 * This routine returns a lun enabled for OAS each time the function
2897 * SUCCESS: size of formatted string.
2898 * -EFAULT: target or vport wwpn was not set properly.
2899 * -EPERM: oas is not enabled.
2902 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2905 struct Scsi_Host *shost = class_to_shost(dev);
2906 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2914 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2915 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2918 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2919 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2922 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2923 phba->cfg_oas_tgt_wwpn,
2924 &phba->cfg_oas_lun_status,
2925 &phba->cfg_oas_priority);
2926 if (oas_lun != NOT_OAS_ENABLED_LUN)
2927 phba->cfg_oas_flags |= OAS_LUN_VALID;
2929 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2935 * lpfc_oas_lun_store - Sets the OAS state for lun
2936 * @dev: class device that is converted into a Scsi_host.
2937 * @attr: device attribute, not used.
2938 * @buf: buffer for passing information.
2940 * This function sets the OAS state for lun. Before this function is called,
2941 * the vport wwpn, target wwpn, and oas state need to be set.
2944 * SUCCESS: size of formatted string.
2945 * -EFAULT: target or vport wwpn was not set properly.
2946 * -EPERM: oas is not enabled.
2947 * size of formatted string.
2950 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2951 const char *buf, size_t count)
2953 struct Scsi_Host *shost = class_to_shost(dev);
2954 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2962 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2965 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2968 if (!isdigit(buf[0]))
2971 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2974 pri = phba->cfg_oas_priority;
2976 pri = phba->cfg_XLanePriority;
2978 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2979 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2980 "priority 0x%x with oas state %d\n",
2981 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2982 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
2983 pri, phba->cfg_oas_lun_state);
2985 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
2986 phba->cfg_oas_tgt_wwpn, scsi_lun,
2987 phba->cfg_oas_lun_state, pri);
2993 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2994 lpfc_oas_lun_show, lpfc_oas_lun_store);
2996 int lpfc_enable_nvmet_cnt;
2997 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
2998 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2999 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3000 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3001 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3003 static int lpfc_poll = 0;
3004 module_param(lpfc_poll, int, S_IRUGO);
3005 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3007 " 1 - poll with interrupts enabled"
3008 " 3 - poll and disable FCP ring interrupts");
3010 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3011 lpfc_poll_show, lpfc_poll_store);
3013 LPFC_ATTR(sli_mode, 0, 0, 3,
3014 "SLI mode selector:"
3015 " 0 - auto (SLI-3 if supported),"
3016 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3017 " 3 - select SLI-3");
3019 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3020 "Enable NPIV functionality");
3022 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3023 "FCF Fast failover=1 Priority failover=2");
3026 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3027 # 0x0 = disabled, XRI/OXID use not tracked.
3028 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3029 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3031 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3032 "Enable RRQ functionality");
3035 # lpfc_suppress_link_up: Bring link up at initialization
3036 # 0x0 = bring link up (issue MBX_INIT_LINK)
3037 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3038 # 0x2 = never bring up link
3039 # Default value is 0.
3041 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3042 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3043 "Suppress Link Up at initialization");
3045 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3053 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3055 struct Scsi_Host *shost = class_to_shost(dev);
3056 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3058 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3061 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3062 lpfc_iocb_hw_show, NULL);
3064 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3066 struct Scsi_Host *shost = class_to_shost(dev);
3067 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3068 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3070 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
3073 static DEVICE_ATTR(txq_hw, S_IRUGO,
3074 lpfc_txq_hw_show, NULL);
3076 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3079 struct Scsi_Host *shost = class_to_shost(dev);
3080 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3081 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3083 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
3086 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3087 lpfc_txcmplq_hw_show, NULL);
3089 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3090 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3093 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3094 # until the timer expires. Value range is [0,255]. Default value is 30.
3096 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3097 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3098 module_param(lpfc_nodev_tmo, int, 0);
3099 MODULE_PARM_DESC(lpfc_nodev_tmo,
3100 "Seconds driver will hold I/O waiting "
3101 "for a device to come back");
3104 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3105 * @dev: class converted to a Scsi_host structure.
3106 * @attr: device attribute, not used.
3107 * @buf: on return contains the dev loss timeout in decimal.
3109 * Returns: size of formatted string.
3112 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3115 struct Scsi_Host *shost = class_to_shost(dev);
3116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3118 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3122 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3123 * @vport: lpfc vport structure pointer.
3124 * @val: contains the nodev timeout value.
3127 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3128 * a kernel error message is printed and zero is returned.
3129 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3130 * Otherwise nodev tmo is set to the default value.
3133 * zero if already set or if val is in range
3134 * -EINVAL val out of range
3137 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3139 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3140 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3141 if (val != LPFC_DEF_DEVLOSS_TMO)
3142 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3143 "0407 Ignoring lpfc_nodev_tmo module "
3144 "parameter because lpfc_devloss_tmo "
3149 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3150 vport->cfg_nodev_tmo = val;
3151 vport->cfg_devloss_tmo = val;
3154 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3155 "0400 lpfc_nodev_tmo attribute cannot be set to"
3156 " %d, allowed range is [%d, %d]\n",
3157 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3158 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3163 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3164 * @vport: lpfc vport structure pointer.
3167 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3170 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3172 struct Scsi_Host *shost;
3173 struct lpfc_nodelist *ndlp;
3175 shost = lpfc_shost_from_vport(vport);
3176 spin_lock_irq(shost->host_lock);
3177 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3178 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
3179 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3180 spin_unlock_irq(shost->host_lock);
3184 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3185 * @vport: lpfc vport structure pointer.
3186 * @val: contains the tmo value.
3189 * If the devloss tmo is already set or the vport dev loss tmo has changed
3190 * then a kernel error message is printed and zero is returned.
3191 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3192 * Otherwise nodev tmo is set to the default value.
3195 * zero if already set or if val is in range
3196 * -EINVAL val out of range
3199 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3201 if (vport->dev_loss_tmo_changed ||
3202 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3203 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3204 "0401 Ignoring change to lpfc_nodev_tmo "
3205 "because lpfc_devloss_tmo is set.\n");
3208 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3209 vport->cfg_nodev_tmo = val;
3210 vport->cfg_devloss_tmo = val;
3212 * For compat: set the fc_host dev loss so new rports
3213 * will get the value.
3215 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3216 lpfc_update_rport_devloss_tmo(vport);
3219 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3220 "0403 lpfc_nodev_tmo attribute cannot be set to "
3221 "%d, allowed range is [%d, %d]\n",
3222 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3226 lpfc_vport_param_store(nodev_tmo)
3228 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3229 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3232 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3233 # disappear until the timer expires. Value range is [0,255]. Default
3236 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3237 MODULE_PARM_DESC(lpfc_devloss_tmo,
3238 "Seconds driver will hold I/O waiting "
3239 "for a device to come back");
3240 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3241 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3242 lpfc_vport_param_show(devloss_tmo)
3245 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3246 * @vport: lpfc vport structure pointer.
3247 * @val: contains the tmo value.
3250 * If val is in a valid range then set the vport nodev tmo,
3251 * devloss tmo, also set the vport dev loss tmo changed flag.
3252 * Else a kernel error message is printed.
3255 * zero if val is in range
3256 * -EINVAL val out of range
3259 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3261 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3262 vport->cfg_nodev_tmo = val;
3263 vport->cfg_devloss_tmo = val;
3264 vport->dev_loss_tmo_changed = 1;
3265 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3266 lpfc_update_rport_devloss_tmo(vport);
3270 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3271 "0404 lpfc_devloss_tmo attribute cannot be set to "
3272 "%d, allowed range is [%d, %d]\n",
3273 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3277 lpfc_vport_param_store(devloss_tmo)
3278 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3279 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3282 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3283 * lpfc_suppress_rsp = 0 Disable
3284 * lpfc_suppress_rsp = 1 Enable (default)
3287 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3288 "Enable suppress rsp feature is firmware supports it");
3291 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3292 * lpfc_nvmet_mrq = 1 use a single RQ pair
3293 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3296 LPFC_ATTR_R(nvmet_mrq,
3298 "Specify number of RQ pairs for processing NVMET cmds");
3301 * lpfc_nvmet_mrq_post: Specify number buffers to post on every MRQ
3304 LPFC_ATTR_R(nvmet_mrq_post, LPFC_DEF_MRQ_POST,
3305 LPFC_MIN_MRQ_POST, LPFC_MAX_MRQ_POST,
3306 "Specify number of buffers to post on every MRQ");
3309 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3310 * Supported Values: 1 - register just FCP
3311 * 3 - register both FCP and NVME
3312 * Supported values are [1,3]. Default value is 3
3314 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3315 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3316 "Define fc4 type to register with fabric.");
3319 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3320 * This parameter is only used if:
3321 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3322 * port is not configured for NVMET.
3324 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3325 * The remaining XRIs get split up based on lpfc_xri_split per port:
3327 * Supported Values are in percentages
3328 * the xri_split value is the percentage the SCSI port will get. The remaining
3329 * percentage will go to NVME.
3331 LPFC_ATTR_R(xri_split, 50, 10, 90,
3332 "Division of XRI resources between SCSI and NVME");
3335 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3336 # deluged with LOTS of information.
3337 # You can set a bit mask to record specific types of verbose messages:
3338 # See lpfc_logmsh.h for definitions.
3340 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3341 "Verbose logging bit-mask");
3344 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3345 # objects that have been registered with the nameserver after login.
3347 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3348 "Deregister nameserver objects before LOGO");
3351 # lun_queue_depth: This parameter is used to limit the number of outstanding
3352 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3353 # If this parameter value is greater than 1/8th the maximum number of exchanges
3354 # supported by the HBA port, then the lun queue depth will be reduced to
3355 # 1/8th the maximum number of exchanges.
3357 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3358 "Max number of FCP commands we can queue to a specific LUN");
3361 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3362 # commands per target port. Value range is [10,65535]. Default value is 65535.
3364 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3365 "Max number of FCP commands we can queue to a specific target port");
3368 # hba_queue_depth: This parameter is used to limit the number of outstanding
3369 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3370 # value is greater than the maximum number of exchanges supported by the HBA,
3371 # then maximum number of exchanges supported by the HBA is used to determine
3372 # the hba_queue_depth.
3374 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3375 "Max number of FCP commands we can queue to a lpfc HBA");
3378 # peer_port_login: This parameter allows/prevents logins
3379 # between peer ports hosted on the same physical port.
3380 # When this parameter is set 0 peer ports of same physical port
3381 # are not allowed to login to each other.
3382 # When this parameter is set 1 peer ports of same physical port
3383 # are allowed to login to each other.
3384 # Default value of this parameter is 0.
3386 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3387 "Allow peer ports on the same physical port to login to each "
3391 # restrict_login: This parameter allows/prevents logins
3392 # between Virtual Ports and remote initiators.
3393 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3394 # other initiators and will attempt to PLOGI all remote ports.
3395 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3396 # remote ports and will not attempt to PLOGI to other initiators.
3397 # This parameter does not restrict to the physical port.
3398 # This parameter does not restrict logins to Fabric resident remote ports.
3399 # Default value of this parameter is 1.
3401 static int lpfc_restrict_login = 1;
3402 module_param(lpfc_restrict_login, int, S_IRUGO);
3403 MODULE_PARM_DESC(lpfc_restrict_login,
3404 "Restrict virtual ports login to remote initiators.");
3405 lpfc_vport_param_show(restrict_login);
3408 * lpfc_restrict_login_init - Set the vport restrict login flag
3409 * @vport: lpfc vport structure pointer.
3410 * @val: contains the restrict login value.
3413 * If val is not in a valid range then log a kernel error message and set
3414 * the vport restrict login to one.
3415 * If the port type is physical clear the restrict login flag and return.
3416 * Else set the restrict login flag to val.
3419 * zero if val is in range
3420 * -EINVAL val out of range
3423 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3425 if (val < 0 || val > 1) {
3426 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3427 "0422 lpfc_restrict_login attribute cannot "
3428 "be set to %d, allowed range is [0, 1]\n",
3430 vport->cfg_restrict_login = 1;
3433 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3434 vport->cfg_restrict_login = 0;
3437 vport->cfg_restrict_login = val;
3442 * lpfc_restrict_login_set - Set the vport restrict login flag
3443 * @vport: lpfc vport structure pointer.
3444 * @val: contains the restrict login value.
3447 * If val is not in a valid range then log a kernel error message and set
3448 * the vport restrict login to one.
3449 * If the port type is physical and the val is not zero log a kernel
3450 * error message, clear the restrict login flag and return zero.
3451 * Else set the restrict login flag to val.
3454 * zero if val is in range
3455 * -EINVAL val out of range
3458 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3460 if (val < 0 || val > 1) {
3461 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3462 "0425 lpfc_restrict_login attribute cannot "
3463 "be set to %d, allowed range is [0, 1]\n",
3465 vport->cfg_restrict_login = 1;
3468 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3469 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3470 "0468 lpfc_restrict_login must be 0 for "
3471 "Physical ports.\n");
3472 vport->cfg_restrict_login = 0;
3475 vport->cfg_restrict_login = val;
3478 lpfc_vport_param_store(restrict_login);
3479 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3480 lpfc_restrict_login_show, lpfc_restrict_login_store);
3483 # Some disk devices have a "select ID" or "select Target" capability.
3484 # From a protocol standpoint "select ID" usually means select the
3485 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3486 # annex" which contains a table that maps a "select ID" (a number
3487 # between 0 and 7F) to an ALPA. By default, for compatibility with
3488 # older drivers, the lpfc driver scans this table from low ALPA to high
3491 # Turning on the scan-down variable (on = 1, off = 0) will
3492 # cause the lpfc driver to use an inverted table, effectively
3493 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3495 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3496 # and will not work across a fabric. Also this parameter will take
3497 # effect only in the case when ALPA map is not available.)
3499 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3500 "Start scanning for devices from highest ALPA to lowest");
3503 # lpfc_topology: link topology for init link
3504 # 0x0 = attempt loop mode then point-to-point
3505 # 0x01 = internal loopback mode
3506 # 0x02 = attempt point-to-point mode only
3507 # 0x04 = attempt loop mode only
3508 # 0x06 = attempt point-to-point mode then loop
3509 # Set point-to-point mode if you want to run as an N_Port.
3510 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3511 # Default value is 0.
3513 LPFC_ATTR(topology, 0, 0, 6,
3514 "Select Fibre Channel topology");
3517 * lpfc_topology_set - Set the adapters topology field
3518 * @phba: lpfc_hba pointer.
3519 * @val: topology value.
3522 * If val is in a valid range then set the adapter's topology field and
3523 * issue a lip; if the lip fails reset the topology to the old value.
3525 * If the value is not in range log a kernel error message and return an error.
3528 * zero if val is in range and lip okay
3529 * non-zero return value from lpfc_issue_lip()
3530 * -EINVAL val out of range
3533 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3534 const char *buf, size_t count)
3536 struct Scsi_Host *shost = class_to_shost(dev);
3537 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3538 struct lpfc_hba *phba = vport->phba;
3541 const char *val_buf = buf;
3545 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3547 val_buf = &buf[strlen("nolip ")];
3550 if (!isdigit(val_buf[0]))
3552 if (sscanf(val_buf, "%i", &val) != 1)
3555 if (val >= 0 && val <= 6) {
3556 prev_val = phba->cfg_topology;
3557 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3559 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3560 "3113 Loop mode not supported at speed %d\n",
3564 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3566 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3567 "3114 Loop mode not supported\n");
3570 phba->cfg_topology = val;
3574 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3575 "3054 lpfc_topology changed from %d to %d\n",
3577 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3578 phba->fc_topology_changed = 1;
3579 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3581 phba->cfg_topology = prev_val;
3586 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3587 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3588 "allowed range is [0, 6]\n",
3593 lpfc_param_show(topology)
3594 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3595 lpfc_topology_show, lpfc_topology_store);
3598 * lpfc_static_vport_show: Read callback function for
3599 * lpfc_static_vport sysfs file.
3600 * @dev: Pointer to class device object.
3601 * @attr: device attribute structure.
3602 * @buf: Data buffer.
3604 * This function is the read call back function for
3605 * lpfc_static_vport sysfs file. The lpfc_static_vport
3606 * sysfs file report the mageability of the vport.
3609 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3612 struct Scsi_Host *shost = class_to_shost(dev);
3613 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3614 if (vport->vport_flag & STATIC_VPORT)
3615 sprintf(buf, "1\n");
3617 sprintf(buf, "0\n");
3623 * Sysfs attribute to control the statistical data collection.
3625 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3626 lpfc_static_vport_show, NULL);
3629 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3630 * @dev: Pointer to class device.
3631 * @buf: Data buffer.
3632 * @count: Size of the data buffer.
3634 * This function get called when a user write to the lpfc_stat_data_ctrl
3635 * sysfs file. This function parse the command written to the sysfs file
3636 * and take appropriate action. These commands are used for controlling
3637 * driver statistical data collection.
3638 * Following are the command this function handles.
3640 * setbucket <bucket_type> <base> <step>
3641 * = Set the latency buckets.
3642 * destroybucket = destroy all the buckets.
3643 * start = start data collection
3644 * stop = stop data collection
3645 * reset = reset the collected data
3648 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3649 const char *buf, size_t count)
3651 struct Scsi_Host *shost = class_to_shost(dev);
3652 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3653 struct lpfc_hba *phba = vport->phba;
3654 #define LPFC_MAX_DATA_CTRL_LEN 1024
3655 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3657 char *str_ptr, *token;
3658 struct lpfc_vport **vports;
3659 struct Scsi_Host *v_shost;
3660 char *bucket_type_str, *base_str, *step_str;
3661 unsigned long base, step, bucket_type;
3663 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3664 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3667 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3668 str_ptr = &bucket_data[0];
3669 /* Ignore this token - this is command token */
3670 token = strsep(&str_ptr, "\t ");
3674 bucket_type_str = strsep(&str_ptr, "\t ");
3675 if (!bucket_type_str)
3678 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3679 bucket_type = LPFC_LINEAR_BUCKET;
3680 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3681 bucket_type = LPFC_POWER2_BUCKET;
3685 base_str = strsep(&str_ptr, "\t ");
3688 base = simple_strtoul(base_str, NULL, 0);
3690 step_str = strsep(&str_ptr, "\t ");
3693 step = simple_strtoul(step_str, NULL, 0);
3697 /* Block the data collection for every vport */
3698 vports = lpfc_create_vport_work_array(phba);
3702 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3703 v_shost = lpfc_shost_from_vport(vports[i]);
3704 spin_lock_irq(v_shost->host_lock);
3705 /* Block and reset data collection */
3706 vports[i]->stat_data_blocked = 1;
3707 if (vports[i]->stat_data_enabled)
3708 lpfc_vport_reset_stat_data(vports[i]);
3709 spin_unlock_irq(v_shost->host_lock);
3712 /* Set the bucket attributes */
3713 phba->bucket_type = bucket_type;
3714 phba->bucket_base = base;
3715 phba->bucket_step = step;
3717 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3718 v_shost = lpfc_shost_from_vport(vports[i]);
3720 /* Unblock data collection */
3721 spin_lock_irq(v_shost->host_lock);
3722 vports[i]->stat_data_blocked = 0;
3723 spin_unlock_irq(v_shost->host_lock);
3725 lpfc_destroy_vport_work_array(phba, vports);
3729 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3730 vports = lpfc_create_vport_work_array(phba);
3734 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3735 v_shost = lpfc_shost_from_vport(vports[i]);
3736 spin_lock_irq(shost->host_lock);
3737 vports[i]->stat_data_blocked = 1;
3738 lpfc_free_bucket(vport);
3739 vport->stat_data_enabled = 0;
3740 vports[i]->stat_data_blocked = 0;
3741 spin_unlock_irq(shost->host_lock);
3743 lpfc_destroy_vport_work_array(phba, vports);
3744 phba->bucket_type = LPFC_NO_BUCKET;
3745 phba->bucket_base = 0;
3746 phba->bucket_step = 0;
3750 if (!strncmp(buf, "start", strlen("start"))) {
3751 /* If no buckets configured return error */
3752 if (phba->bucket_type == LPFC_NO_BUCKET)
3754 spin_lock_irq(shost->host_lock);
3755 if (vport->stat_data_enabled) {
3756 spin_unlock_irq(shost->host_lock);
3759 lpfc_alloc_bucket(vport);
3760 vport->stat_data_enabled = 1;
3761 spin_unlock_irq(shost->host_lock);
3765 if (!strncmp(buf, "stop", strlen("stop"))) {
3766 spin_lock_irq(shost->host_lock);
3767 if (vport->stat_data_enabled == 0) {
3768 spin_unlock_irq(shost->host_lock);
3771 lpfc_free_bucket(vport);
3772 vport->stat_data_enabled = 0;
3773 spin_unlock_irq(shost->host_lock);
3777 if (!strncmp(buf, "reset", strlen("reset"))) {
3778 if ((phba->bucket_type == LPFC_NO_BUCKET)
3779 || !vport->stat_data_enabled)
3781 spin_lock_irq(shost->host_lock);
3782 vport->stat_data_blocked = 1;
3783 lpfc_vport_reset_stat_data(vport);
3784 vport->stat_data_blocked = 0;
3785 spin_unlock_irq(shost->host_lock);
3793 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3794 * @dev: Pointer to class device object.
3795 * @buf: Data buffer.
3797 * This function is the read call back function for
3798 * lpfc_stat_data_ctrl sysfs file. This function report the
3799 * current statistical data collection state.
3802 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3805 struct Scsi_Host *shost = class_to_shost(dev);
3806 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3807 struct lpfc_hba *phba = vport->phba;
3811 unsigned long bucket_value;
3813 switch (phba->bucket_type) {
3814 case LPFC_LINEAR_BUCKET:
3815 bucket_type = "linear";
3817 case LPFC_POWER2_BUCKET:
3818 bucket_type = "power2";
3821 bucket_type = "No Bucket";
3825 sprintf(&buf[index], "Statistical Data enabled :%d, "
3826 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3827 " Bucket step :%d\nLatency Ranges :",
3828 vport->stat_data_enabled, vport->stat_data_blocked,
3829 bucket_type, phba->bucket_base, phba->bucket_step);
3830 index = strlen(buf);
3831 if (phba->bucket_type != LPFC_NO_BUCKET) {
3832 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3833 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3834 bucket_value = phba->bucket_base +
3835 phba->bucket_step * i;
3837 bucket_value = phba->bucket_base +
3838 (1 << i) * phba->bucket_step;
3840 if (index + 10 > PAGE_SIZE)
3842 sprintf(&buf[index], "%08ld ", bucket_value);
3843 index = strlen(buf);
3846 sprintf(&buf[index], "\n");
3851 * Sysfs attribute to control the statistical data collection.
3853 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3854 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3857 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3861 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3864 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3865 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3866 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3870 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3872 * @kobj: Pointer to the kernel object
3873 * @bin_attr: Attribute object
3874 * @buff: Buffer pointer
3876 * @count: Buffer size
3878 * This function is the read call back function for lpfc_drvr_stat_data
3879 * sysfs file. This function export the statistical data to user
3883 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3884 struct bin_attribute *bin_attr,
3885 char *buf, loff_t off, size_t count)
3887 struct device *dev = container_of(kobj, struct device,
3889 struct Scsi_Host *shost = class_to_shost(dev);
3890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3891 struct lpfc_hba *phba = vport->phba;
3892 int i = 0, index = 0;
3893 unsigned long nport_index;
3894 struct lpfc_nodelist *ndlp = NULL;
3895 nport_index = (unsigned long)off /
3896 MAX_STAT_DATA_SIZE_PER_TARGET;
3898 if (!vport->stat_data_enabled || vport->stat_data_blocked
3899 || (phba->bucket_type == LPFC_NO_BUCKET))
3902 spin_lock_irq(shost->host_lock);
3903 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3904 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3907 if (nport_index > 0) {
3912 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3916 if (!ndlp->lat_data)
3920 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3921 ndlp->nlp_portname.u.wwn[0],
3922 ndlp->nlp_portname.u.wwn[1],
3923 ndlp->nlp_portname.u.wwn[2],
3924 ndlp->nlp_portname.u.wwn[3],
3925 ndlp->nlp_portname.u.wwn[4],
3926 ndlp->nlp_portname.u.wwn[5],
3927 ndlp->nlp_portname.u.wwn[6],
3928 ndlp->nlp_portname.u.wwn[7]);
3930 index = strlen(buf);
3932 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3933 sprintf(&buf[index], "%010u,",
3934 ndlp->lat_data[i].cmd_count);
3935 index = strlen(buf);
3937 sprintf(&buf[index], "\n");
3938 index = strlen(buf);
3940 spin_unlock_irq(shost->host_lock);
3944 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3946 .name = "lpfc_drvr_stat_data",
3949 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3950 .read = sysfs_drvr_stat_data_read,
3955 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3957 # Value range is [0,16]. Default value is 0.
3960 * lpfc_link_speed_set - Set the adapters link speed
3961 * @phba: lpfc_hba pointer.
3962 * @val: link speed value.
3965 * If val is in a valid range then set the adapter's link speed field and
3966 * issue a lip; if the lip fails reset the link speed to the old value.
3969 * If the value is not in range log a kernel error message and return an error.
3972 * zero if val is in range and lip okay.
3973 * non-zero return value from lpfc_issue_lip()
3974 * -EINVAL val out of range
3977 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3978 const char *buf, size_t count)
3980 struct Scsi_Host *shost = class_to_shost(dev);
3981 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3982 struct lpfc_hba *phba = vport->phba;
3983 int val = LPFC_USER_LINK_SPEED_AUTO;
3985 const char *val_buf = buf;
3987 uint32_t prev_val, if_type;
3989 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3990 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
3991 phba->hba_flag & HBA_FORCED_LINK_SPEED)
3994 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3996 val_buf = &buf[strlen("nolip ")];
3999 if (!isdigit(val_buf[0]))
4001 if (sscanf(val_buf, "%i", &val) != 1)
4004 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4005 "3055 lpfc_link_speed changed from %d to %d %s\n",
4006 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4008 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4009 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4010 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4011 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4012 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4013 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4014 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
4015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4016 "2879 lpfc_link_speed attribute cannot be set "
4017 "to %d. Speed is not supported by this port.\n",
4021 if (val == LPFC_USER_LINK_SPEED_16G &&
4022 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4023 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4024 "3112 lpfc_link_speed attribute cannot be set "
4025 "to %d. Speed is not supported in loop mode.\n",
4029 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4030 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4031 prev_val = phba->cfg_link_speed;
4032 phba->cfg_link_speed = val;
4036 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4038 phba->cfg_link_speed = prev_val;
4043 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4044 "0469 lpfc_link_speed attribute cannot be set to %d, "
4045 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
4049 static int lpfc_link_speed = 0;
4050 module_param(lpfc_link_speed, int, S_IRUGO);
4051 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4052 lpfc_param_show(link_speed)
4055 * lpfc_link_speed_init - Set the adapters link speed
4056 * @phba: lpfc_hba pointer.
4057 * @val: link speed value.
4060 * If val is in a valid range then set the adapter's link speed field.
4063 * If the value is not in range log a kernel error message, clear the link
4064 * speed and return an error.
4067 * zero if val saved.
4068 * -EINVAL val out of range
4071 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4073 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4074 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4075 "3111 lpfc_link_speed of %d cannot "
4076 "support loop mode, setting topology to default.\n",
4078 phba->cfg_topology = 0;
4080 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4081 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4082 phba->cfg_link_speed = val;
4085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4086 "0405 lpfc_link_speed attribute cannot "
4087 "be set to %d, allowed values are "
4088 "["LPFC_LINK_SPEED_STRING"]\n", val);
4089 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4093 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
4094 lpfc_link_speed_show, lpfc_link_speed_store);
4097 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4098 # 0 = aer disabled or not supported
4099 # 1 = aer supported and enabled (default)
4100 # Value range is [0,1]. Default value is 1.
4102 LPFC_ATTR(aer_support, 1, 0, 1,
4103 "Enable PCIe device AER support");
4104 lpfc_param_show(aer_support)
4107 * lpfc_aer_support_store - Set the adapter for aer support
4109 * @dev: class device that is converted into a Scsi_host.
4110 * @attr: device attribute, not used.
4111 * @buf: containing enable or disable aer flag.
4112 * @count: unused variable.
4115 * If the val is 1 and currently the device's AER capability was not
4116 * enabled, invoke the kernel's enable AER helper routine, trying to
4117 * enable the device's AER capability. If the helper routine enabling
4118 * AER returns success, update the device's cfg_aer_support flag to
4119 * indicate AER is supported by the device; otherwise, if the device
4120 * AER capability is already enabled to support AER, then do nothing.
4122 * If the val is 0 and currently the device's AER support was enabled,
4123 * invoke the kernel's disable AER helper routine. After that, update
4124 * the device's cfg_aer_support flag to indicate AER is not supported
4125 * by the device; otherwise, if the device AER capability is already
4126 * disabled from supporting AER, then do nothing.
4129 * length of the buf on success if val is in range the intended mode
4131 * -EINVAL if val out of range or intended mode is not supported.
4134 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4135 const char *buf, size_t count)
4137 struct Scsi_Host *shost = class_to_shost(dev);
4138 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4139 struct lpfc_hba *phba = vport->phba;
4140 int val = 0, rc = -EINVAL;
4142 if (!isdigit(buf[0]))
4144 if (sscanf(buf, "%i", &val) != 1)
4149 if (phba->hba_flag & HBA_AER_ENABLED) {
4150 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4152 spin_lock_irq(&phba->hbalock);
4153 phba->hba_flag &= ~HBA_AER_ENABLED;
4154 spin_unlock_irq(&phba->hbalock);
4155 phba->cfg_aer_support = 0;
4160 phba->cfg_aer_support = 0;
4165 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4166 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4168 spin_lock_irq(&phba->hbalock);
4169 phba->hba_flag |= HBA_AER_ENABLED;
4170 spin_unlock_irq(&phba->hbalock);
4171 phba->cfg_aer_support = 1;
4176 phba->cfg_aer_support = 1;
4187 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4188 lpfc_aer_support_show, lpfc_aer_support_store);
4191 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4192 * @dev: class device that is converted into a Scsi_host.
4193 * @attr: device attribute, not used.
4194 * @buf: containing flag 1 for aer cleanup state.
4195 * @count: unused variable.
4198 * If the @buf contains 1 and the device currently has the AER support
4199 * enabled, then invokes the kernel AER helper routine
4200 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4201 * error status register.
4206 * -EINVAL if the buf does not contain the 1 or the device is not currently
4207 * enabled with the AER support.
4210 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4211 const char *buf, size_t count)
4213 struct Scsi_Host *shost = class_to_shost(dev);
4214 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4215 struct lpfc_hba *phba = vport->phba;
4218 if (!isdigit(buf[0]))
4220 if (sscanf(buf, "%i", &val) != 1)
4225 if (phba->hba_flag & HBA_AER_ENABLED)
4226 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4234 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4235 lpfc_aer_cleanup_state);
4238 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4240 * @dev: class device that is converted into a Scsi_host.
4241 * @attr: device attribute, not used.
4242 * @buf: containing the string the number of vfs to be enabled.
4243 * @count: unused variable.
4246 * When this api is called either through user sysfs, the driver shall
4247 * try to enable or disable SR-IOV virtual functions according to the
4250 * If zero virtual function has been enabled to the physical function,
4251 * the driver shall invoke the pci enable virtual function api trying
4252 * to enable the virtual functions. If the nr_vfn provided is greater
4253 * than the maximum supported, the maximum virtual function number will
4254 * be used for invoking the api; otherwise, the nr_vfn provided shall
4255 * be used for invoking the api. If the api call returned success, the
4256 * actual number of virtual functions enabled will be set to the driver
4257 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4258 * cfg_sriov_nr_virtfn remains zero.
4260 * If none-zero virtual functions have already been enabled to the
4261 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4262 * -EINVAL will be returned and the driver does nothing;
4264 * If the nr_vfn provided is zero and none-zero virtual functions have
4265 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4266 * disabling virtual function api shall be invoded to disable all the
4267 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4268 * zero. Otherwise, if zero virtual function has been enabled, do
4272 * length of the buf on success if val is in range the intended mode
4274 * -EINVAL if val out of range or intended mode is not supported.
4277 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4278 const char *buf, size_t count)
4280 struct Scsi_Host *shost = class_to_shost(dev);
4281 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4282 struct lpfc_hba *phba = vport->phba;
4283 struct pci_dev *pdev = phba->pcidev;
4284 int val = 0, rc = -EINVAL;
4286 /* Sanity check on user data */
4287 if (!isdigit(buf[0]))
4289 if (sscanf(buf, "%i", &val) != 1)
4294 /* Request disabling virtual functions */
4296 if (phba->cfg_sriov_nr_virtfn > 0) {
4297 pci_disable_sriov(pdev);
4298 phba->cfg_sriov_nr_virtfn = 0;
4303 /* Request enabling virtual functions */
4304 if (phba->cfg_sriov_nr_virtfn > 0) {
4305 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4306 "3018 There are %d virtual functions "
4307 "enabled on physical function.\n",
4308 phba->cfg_sriov_nr_virtfn);
4312 if (val <= LPFC_MAX_VFN_PER_PFN)
4313 phba->cfg_sriov_nr_virtfn = val;
4315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4316 "3019 Enabling %d virtual functions is not "
4321 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4323 phba->cfg_sriov_nr_virtfn = 0;
4331 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4332 "Enable PCIe device SR-IOV virtual fn");
4334 lpfc_param_show(sriov_nr_virtfn)
4335 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4336 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4339 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4341 * @dev: class device that is converted into a Scsi_host.
4342 * @attr: device attribute, not used.
4343 * @buf: containing the string the number of vfs to be enabled.
4344 * @count: unused variable.
4349 * length of the buf on success if val is in range the intended mode
4351 * -EINVAL if val out of range or intended mode is not supported.
4354 lpfc_request_firmware_upgrade_store(struct device *dev,
4355 struct device_attribute *attr,
4356 const char *buf, size_t count)
4358 struct Scsi_Host *shost = class_to_shost(dev);
4359 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4360 struct lpfc_hba *phba = vport->phba;
4361 int val = 0, rc = -EINVAL;
4363 /* Sanity check on user data */
4364 if (!isdigit(buf[0]))
4366 if (sscanf(buf, "%i", &val) != 1)
4371 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4379 static int lpfc_req_fw_upgrade;
4380 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4381 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4382 lpfc_param_show(request_firmware_upgrade)
4385 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4386 * @phba: lpfc_hba pointer.
4390 * Set the initial Linux generic firmware upgrade enable or disable flag.
4393 * zero if val saved.
4394 * -EINVAL val out of range
4397 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4399 if (val >= 0 && val <= 1) {
4400 phba->cfg_request_firmware_upgrade = val;
4405 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4406 lpfc_request_firmware_upgrade_show,
4407 lpfc_request_firmware_upgrade_store);
4410 * lpfc_fcp_imax_store
4412 * @dev: class device that is converted into a Scsi_host.
4413 * @attr: device attribute, not used.
4414 * @buf: string with the number of fast-path FCP interrupts per second.
4415 * @count: unused variable.
4418 * If val is in a valid range [636,651042], then set the adapter's
4419 * maximum number of fast-path FCP interrupts per second.
4422 * length of the buf on success if val is in range the intended mode
4424 * -EINVAL if val out of range or intended mode is not supported.
4427 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4428 const char *buf, size_t count)
4430 struct Scsi_Host *shost = class_to_shost(dev);
4431 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4432 struct lpfc_hba *phba = vport->phba;
4435 /* fcp_imax is only valid for SLI4 */
4436 if (phba->sli_rev != LPFC_SLI_REV4)
4439 /* Sanity check on user data */
4440 if (!isdigit(buf[0]))
4442 if (sscanf(buf, "%i", &val) != 1)
4446 * Value range for the HBA is [5000,5000000]
4447 * The value for each EQ depends on how many EQs are configured.
4450 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4453 phba->cfg_fcp_imax = (uint32_t)val;
4454 for (i = 0; i < phba->io_channel_irqs; i++)
4455 lpfc_modify_hba_eq_delay(phba, i);
4461 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4464 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4466 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4467 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4468 MODULE_PARM_DESC(lpfc_fcp_imax,
4469 "Set the maximum number of FCP interrupts per second per HBA");
4470 lpfc_param_show(fcp_imax)
4473 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4474 * @phba: lpfc_hba pointer.
4475 * @val: link speed value.
4478 * If val is in a valid range [636,651042], then initialize the adapter's
4479 * maximum number of fast-path FCP interrupts per second.
4482 * zero if val saved.
4483 * -EINVAL val out of range
4486 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4488 if (phba->sli_rev != LPFC_SLI_REV4) {
4489 phba->cfg_fcp_imax = 0;
4493 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4495 phba->cfg_fcp_imax = val;
4499 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4500 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4502 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4507 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4508 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4511 * lpfc_state_show - Display current driver CPU affinity
4512 * @dev: class converted to a Scsi_host structure.
4513 * @attr: device attribute, not used.
4514 * @buf: on return contains text describing the state of the link.
4516 * Returns: size of formatted string.
4519 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4522 struct Scsi_Host *shost = class_to_shost(dev);
4523 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4524 struct lpfc_hba *phba = vport->phba;
4525 struct lpfc_vector_map_info *cpup;
4528 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4529 (phba->intr_type != MSIX))
4532 switch (phba->cfg_fcp_cpu_map) {
4534 len += snprintf(buf + len, PAGE_SIZE-len,
4535 "fcp_cpu_map: No mapping (%d)\n",
4536 phba->cfg_fcp_cpu_map);
4539 len += snprintf(buf + len, PAGE_SIZE-len,
4540 "fcp_cpu_map: HBA centric mapping (%d): "
4542 phba->cfg_fcp_cpu_map,
4543 phba->sli4_hba.num_online_cpu);
4546 len += snprintf(buf + len, PAGE_SIZE-len,
4547 "fcp_cpu_map: Driver centric mapping (%d): "
4549 phba->cfg_fcp_cpu_map,
4550 phba->sli4_hba.num_online_cpu);
4554 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4555 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4557 /* margin should fit in this and the truncated message */
4558 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4559 len += snprintf(buf + len, PAGE_SIZE-len,
4560 "CPU %02d io_chan %02d "
4561 "physid %d coreid %d\n",
4562 phba->sli4_hba.curr_disp_cpu,
4563 cpup->channel_id, cpup->phys_id,
4566 len += snprintf(buf + len, PAGE_SIZE-len,
4567 "CPU %02d io_chan %02d "
4568 "physid %d coreid %d IRQ %d\n",
4569 phba->sli4_hba.curr_disp_cpu,
4570 cpup->channel_id, cpup->phys_id,
4571 cpup->core_id, cpup->irq);
4573 phba->sli4_hba.curr_disp_cpu++;
4575 /* display max number of CPUs keeping some margin */
4576 if (phba->sli4_hba.curr_disp_cpu <
4577 phba->sli4_hba.num_present_cpu &&
4578 (len >= (PAGE_SIZE - 64))) {
4579 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4584 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4585 phba->sli4_hba.curr_disp_cpu = 0;
4591 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4592 * @dev: class device that is converted into a Scsi_host.
4593 * @attr: device attribute, not used.
4594 * @buf: one or more lpfc_polling_flags values.
4598 * -EINVAL - Not implemented yet.
4601 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4602 const char *buf, size_t count)
4604 int status = -EINVAL;
4609 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4612 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4613 # 0 - Do not affinitze IRQ vectors
4614 # 1 - Affintize HBA vectors with respect to each HBA
4615 # (start with CPU0 for each HBA)
4616 # 2 - Affintize HBA vectors with respect to the entire driver
4617 # (round robin thru all CPUs across all HBAs)
4619 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4620 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4621 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4622 "Defines how to map CPUs to IRQ vectors per HBA");
4625 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4626 * @phba: lpfc_hba pointer.
4627 * @val: link speed value.
4630 * If val is in a valid range [0-2], then affinitze the adapter's
4634 * zero if val saved.
4635 * -EINVAL val out of range
4638 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4640 if (phba->sli_rev != LPFC_SLI_REV4) {
4641 phba->cfg_fcp_cpu_map = 0;
4645 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4646 phba->cfg_fcp_cpu_map = val;
4650 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4651 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4653 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4658 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4659 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4662 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4663 # Value range is [2,3]. Default value is 3.
4665 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4666 "Select Fibre Channel class of service for FCP sequences");
4669 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4670 # is [0,1]. Default value is 0.
4672 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4673 "Use ADISC on rediscovery to authenticate FCP devices");
4676 # lpfc_first_burst_size: First burst size to use on the NPorts
4677 # that support first burst.
4678 # Value range is [0,65536]. Default value is 0.
4680 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4681 "First burst size for Targets that support first burst");
4684 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4685 * When the driver is configured as an NVME target, this value is
4686 * communicated to the NVME initiator in the PRLI response. It is
4687 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4688 * parameters are set and the target is sending the PRLI RSP.
4689 * Parameter supported on physical port only - no NPIV support.
4690 * Value range is [0,65536]. Default value is 0.
4692 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4693 "NVME Target mode first burst size in 512B increments.");
4696 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4697 * For the Initiator (I), enabling this parameter means that an NVMET
4698 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4699 * processed by the initiator for subsequent NVME FCP IO. For the target
4700 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4701 * driver parameter as the target function's first burst size returned to the
4702 * initiator in the target's NVME PRLI response. Parameter supported on physical
4703 * port only - no NPIV support.
4704 * Value range is [0,1]. Default value is 0 (disabled).
4706 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4707 "Enable First Burst feature on I and T functions.");
4710 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4711 # depth. Default value is 0. When the value of this parameter is zero the
4712 # SCSI command completion time is not used for controlling I/O queue depth. When
4713 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4714 # to limit the I/O completion time to the parameter value.
4715 # The value is set in milliseconds.
4717 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4718 "Use command completion time to control queue depth");
4720 lpfc_vport_param_show(max_scsicmpl_time);
4722 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4725 struct lpfc_nodelist *ndlp, *next_ndlp;
4727 if (val == vport->cfg_max_scsicmpl_time)
4729 if ((val < 0) || (val > 60000))
4731 vport->cfg_max_scsicmpl_time = val;
4733 spin_lock_irq(shost->host_lock);
4734 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4735 if (!NLP_CHK_NODE_ACT(ndlp))
4737 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4739 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4741 spin_unlock_irq(shost->host_lock);
4744 lpfc_vport_param_store(max_scsicmpl_time);
4745 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4746 lpfc_max_scsicmpl_time_show,
4747 lpfc_max_scsicmpl_time_store);
4750 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4751 # range is [0,1]. Default value is 0.
4753 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4756 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4757 * range is [0,1]. Default value is 0.
4758 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4759 * For [1], FCP commands are issued to a Work Queue associated with the
4762 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4763 * LPFC_FCP_SCHED_BY_CPU == 1
4765 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4766 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4767 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4768 * through WQs will be used.
4770 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4771 LPFC_FCP_SCHED_ROUND_ROBIN,
4772 LPFC_FCP_SCHED_BY_CPU,
4773 "Determine scheduling algorithm for "
4774 "issuing commands [0] - Round Robin, [1] - Current CPU");
4777 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4778 # range is [0,1]. Default value is 0.
4779 # For [0], bus reset issues target reset to ALL devices
4780 # For [1], bus reset issues target reset to non-FCP2 devices
4782 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4783 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4787 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4788 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4789 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4790 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4791 # cr_delay is set to 0.
4793 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4794 "interrupt response is generated");
4796 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4797 "interrupt response is generated");
4800 # lpfc_multi_ring_support: Determines how many rings to spread available
4801 # cmd/rsp IOCB entries across.
4802 # Value range is [1,2]. Default value is 1.
4804 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4805 "SLI rings to spread IOCB entries across");
4808 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4809 # identifies what rctl value to configure the additional ring for.
4810 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4812 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4813 255, "Identifies RCTL for additional ring configuration");
4816 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4817 # identifies what type value to configure the additional ring for.
4818 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4820 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4821 255, "Identifies TYPE for additional ring configuration");
4824 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4825 # 0 = SmartSAN functionality disabled (default)
4826 # 1 = SmartSAN functionality enabled
4827 # This parameter will override the value of lpfc_fdmi_on module parameter.
4828 # Value range is [0,1]. Default value is 0.
4830 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4833 # lpfc_fdmi_on: Controls FDMI support.
4834 # 0 No FDMI support (default)
4835 # 1 Traditional FDMI support
4836 # Traditional FDMI support means the driver will assume FDMI-2 support;
4837 # however, if that fails, it will fallback to FDMI-1.
4838 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4839 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4841 # Value range [0,1]. Default value is 0.
4843 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4846 # Specifies the maximum number of ELS cmds we can have outstanding (for
4847 # discovery). Value range is [1,64]. Default value = 32.
4849 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4850 "during discovery");
4853 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4854 # will be scanned by the SCSI midlayer when sequential scanning is
4855 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4856 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4857 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4858 # above. The lpfc driver limits the default value to 255 for two reasons.
4859 # As it bounds the sequential scan loop, scanning for thousands of luns
4860 # on a target can take minutes of wall clock time. Additionally,
4861 # there are FC targets, such as JBODs, that only recognize 8-bits of
4862 # LUN ID. When they receive a value greater than 8 bits, they chop off
4863 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4864 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4865 # valid responses at each of the LUN IDs, to believe there are multiple
4866 # devices present, when in fact, there is only 1.
4867 # A customer that is aware of their target behaviors, and the results as
4868 # indicated above, is welcome to increase the lpfc_max_luns value.
4869 # As mentioned, this value is not used by the lpfc driver, only the
4871 # Value range is [0,65535]. Default value is 255.
4872 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4874 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4877 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4878 # Value range is [1,255], default value is 10.
4880 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4881 "Milliseconds driver will wait between polling FCP ring");
4884 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4885 # to complete in seconds. Value range is [5,180], default value is 60.
4887 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4888 "Maximum time to wait for task management commands to complete");
4890 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4891 # support this feature
4894 # 2 = MSI-X enabled (default)
4895 # Value range is [0,2]. Default value is 2.
4897 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4898 "MSI-X (2), if possible");
4901 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4903 * 0 = NVME OAS disabled
4904 * 1 = NVME OAS enabled
4906 * Value range is [0,1]. Default value is 0.
4908 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4909 "Use OAS bit on NVME IOs");
4912 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4913 * will advertise it supports to the SCSI layer. This also will map to
4914 * the number of WQs the driver will create.
4916 * 0 = Configure the number of io channels to the number of active CPUs.
4917 * 1,32 = Manually specify how many io channels to use.
4919 * Value range is [0,32]. Default value is 4.
4921 LPFC_ATTR_R(fcp_io_channel,
4922 LPFC_FCP_IO_CHAN_DEF,
4923 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4924 "Set the number of FCP I/O channels");
4927 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4928 * will advertise it supports to the NVME layer. This also will map to
4929 * the number of WQs the driver will create.
4931 * This module parameter is valid when lpfc_enable_fc4_type is set
4934 * The NVME Layer will try to create this many, plus 1 administrative
4935 * hardware queue. The administrative queue will always map to WQ 0
4936 * A hardware IO queue maps (qidx) to a specific driver WQ.
4938 * 0 = Configure the number of io channels to the number of active CPUs.
4939 * 1,32 = Manually specify how many io channels to use.
4941 * Value range is [0,32]. Default value is 0.
4943 LPFC_ATTR_R(nvme_io_channel,
4944 LPFC_NVME_IO_CHAN_DEF,
4945 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4946 "Set the number of NVME I/O channels");
4949 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4950 # 0 = HBA resets disabled
4951 # 1 = HBA resets enabled (default)
4952 # Value range is [0,1]. Default value is 1.
4954 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
4957 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
4958 # 0 = HBA Heartbeat disabled
4959 # 1 = HBA Heartbeat enabled (default)
4960 # Value range is [0,1]. Default value is 1.
4962 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
4965 # lpfc_EnableXLane: Enable Express Lane Feature
4966 # 0x0 Express Lane Feature disabled
4967 # 0x1 Express Lane Feature enabled
4968 # Value range is [0,1]. Default value is 0.
4970 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4973 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4974 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4975 # Value range is [0x0,0x7f]. Default value is 0
4977 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
4980 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4981 # 0 = BlockGuard disabled (default)
4982 # 1 = BlockGuard enabled
4983 # Value range is [0,1]. Default value is 0.
4985 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4988 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4989 # 0 = disabled (default)
4991 # Value range is [0,1]. Default value is 0.
4993 # This feature in under investigation and may be supported in the future.
4995 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4999 # - Bit mask of host protection capabilities used to register with the
5001 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5002 # - Allows you to ultimately specify which profiles to use
5003 # - Default will result in registering capabilities for all profiles.
5004 # - SHOST_DIF_TYPE1_PROTECTION 1
5005 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5006 # - SHOST_DIX_TYPE0_PROTECTION 8
5007 # HBA supports DIX Type 0: Host to HBA protection only
5008 # - SHOST_DIX_TYPE1_PROTECTION 16
5009 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5012 LPFC_ATTR(prot_mask,
5013 (SHOST_DIF_TYPE1_PROTECTION |
5014 SHOST_DIX_TYPE0_PROTECTION |
5015 SHOST_DIX_TYPE1_PROTECTION),
5017 (SHOST_DIF_TYPE1_PROTECTION |
5018 SHOST_DIX_TYPE0_PROTECTION |
5019 SHOST_DIX_TYPE1_PROTECTION),
5020 "T10-DIF host protection capabilities mask");
5023 # lpfc_prot_guard: i
5024 # - Bit mask of protection guard types to register with the SCSI mid-layer
5025 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5026 # - Allows you to ultimately specify which profiles to use
5027 # - Default will result in registering capabilities for all guard types
5030 LPFC_ATTR(prot_guard,
5031 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5032 "T10-DIF host protection guard type");
5035 * Delay initial NPort discovery when Clean Address bit is cleared in
5036 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5037 * This parameter can have value 0 or 1.
5038 * When this parameter is set to 0, no delay is added to the initial
5040 * When this parameter is set to non-zero value, initial Nport discovery is
5041 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5042 * accept and FCID/Fabric name/Fabric portname is changed.
5043 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5044 * when Clean Address bit is cleared in FLOGI/FDISC
5045 * accept and FCID/Fabric name/Fabric portname is changed.
5046 * Default value is 0.
5048 LPFC_ATTR(delay_discovery, 0, 0, 1,
5049 "Delay NPort discovery when Clean Address bit is cleared.");
5052 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5053 * This value can be set to values between 64 and 4096. The default value is
5054 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5055 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5056 * Because of the additional overhead involved in setting up T10-DIF,
5057 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5058 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5060 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5061 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5064 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5065 * 0 = MDS Diagnostics disabled (default)
5066 * 1 = MDS Diagnostics enabled
5067 * Value range is [0,1]. Default value is 0.
5069 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5071 struct device_attribute *lpfc_hba_attrs[] = {
5072 &dev_attr_nvme_info,
5074 &dev_attr_bg_guard_err,
5075 &dev_attr_bg_apptag_err,
5076 &dev_attr_bg_reftag_err,
5078 &dev_attr_serialnum,
5079 &dev_attr_modeldesc,
5080 &dev_attr_modelname,
5081 &dev_attr_programtype,
5085 &dev_attr_option_rom_version,
5086 &dev_attr_link_state,
5087 &dev_attr_num_discovered_ports,
5088 &dev_attr_menlo_mgmt_mode,
5089 &dev_attr_lpfc_drvr_version,
5090 &dev_attr_lpfc_enable_fip,
5091 &dev_attr_lpfc_temp_sensor,
5092 &dev_attr_lpfc_log_verbose,
5093 &dev_attr_lpfc_lun_queue_depth,
5094 &dev_attr_lpfc_tgt_queue_depth,
5095 &dev_attr_lpfc_hba_queue_depth,
5096 &dev_attr_lpfc_peer_port_login,
5097 &dev_attr_lpfc_nodev_tmo,
5098 &dev_attr_lpfc_devloss_tmo,
5099 &dev_attr_lpfc_enable_fc4_type,
5100 &dev_attr_lpfc_xri_split,
5101 &dev_attr_lpfc_fcp_class,
5102 &dev_attr_lpfc_use_adisc,
5103 &dev_attr_lpfc_first_burst_size,
5104 &dev_attr_lpfc_ack0,
5105 &dev_attr_lpfc_topology,
5106 &dev_attr_lpfc_scan_down,
5107 &dev_attr_lpfc_link_speed,
5108 &dev_attr_lpfc_fcp_io_sched,
5109 &dev_attr_lpfc_fcp2_no_tgt_reset,
5110 &dev_attr_lpfc_cr_delay,
5111 &dev_attr_lpfc_cr_count,
5112 &dev_attr_lpfc_multi_ring_support,
5113 &dev_attr_lpfc_multi_ring_rctl,
5114 &dev_attr_lpfc_multi_ring_type,
5115 &dev_attr_lpfc_fdmi_on,
5116 &dev_attr_lpfc_enable_SmartSAN,
5117 &dev_attr_lpfc_max_luns,
5118 &dev_attr_lpfc_enable_npiv,
5119 &dev_attr_lpfc_fcf_failover_policy,
5120 &dev_attr_lpfc_enable_rrq,
5121 &dev_attr_nport_evt_cnt,
5122 &dev_attr_board_mode,
5129 &dev_attr_npiv_info,
5130 &dev_attr_issue_reset,
5131 &dev_attr_lpfc_poll,
5132 &dev_attr_lpfc_poll_tmo,
5133 &dev_attr_lpfc_task_mgmt_tmo,
5134 &dev_attr_lpfc_use_msi,
5135 &dev_attr_lpfc_nvme_oas,
5136 &dev_attr_lpfc_fcp_imax,
5137 &dev_attr_lpfc_fcp_cpu_map,
5138 &dev_attr_lpfc_fcp_io_channel,
5139 &dev_attr_lpfc_suppress_rsp,
5140 &dev_attr_lpfc_nvme_io_channel,
5141 &dev_attr_lpfc_nvmet_mrq,
5142 &dev_attr_lpfc_nvmet_mrq_post,
5143 &dev_attr_lpfc_nvme_enable_fb,
5144 &dev_attr_lpfc_nvmet_fb_size,
5145 &dev_attr_lpfc_enable_bg,
5146 &dev_attr_lpfc_soft_wwnn,
5147 &dev_attr_lpfc_soft_wwpn,
5148 &dev_attr_lpfc_soft_wwn_enable,
5149 &dev_attr_lpfc_enable_hba_reset,
5150 &dev_attr_lpfc_enable_hba_heartbeat,
5151 &dev_attr_lpfc_EnableXLane,
5152 &dev_attr_lpfc_XLanePriority,
5153 &dev_attr_lpfc_xlane_lun,
5154 &dev_attr_lpfc_xlane_tgt,
5155 &dev_attr_lpfc_xlane_vpt,
5156 &dev_attr_lpfc_xlane_lun_state,
5157 &dev_attr_lpfc_xlane_lun_status,
5158 &dev_attr_lpfc_xlane_priority,
5159 &dev_attr_lpfc_sg_seg_cnt,
5160 &dev_attr_lpfc_max_scsicmpl_time,
5161 &dev_attr_lpfc_stat_data_ctrl,
5162 &dev_attr_lpfc_aer_support,
5163 &dev_attr_lpfc_aer_state_cleanup,
5164 &dev_attr_lpfc_sriov_nr_virtfn,
5165 &dev_attr_lpfc_req_fw_upgrade,
5166 &dev_attr_lpfc_suppress_link_up,
5167 &dev_attr_lpfc_iocb_cnt,
5170 &dev_attr_txcmplq_hw,
5171 &dev_attr_lpfc_fips_level,
5172 &dev_attr_lpfc_fips_rev,
5174 &dev_attr_lpfc_sriov_hw_max_virtfn,
5176 &dev_attr_lpfc_xlane_supported,
5177 &dev_attr_lpfc_enable_mds_diags,
5181 struct device_attribute *lpfc_vport_attrs[] = {
5183 &dev_attr_link_state,
5184 &dev_attr_num_discovered_ports,
5185 &dev_attr_lpfc_drvr_version,
5186 &dev_attr_lpfc_log_verbose,
5187 &dev_attr_lpfc_lun_queue_depth,
5188 &dev_attr_lpfc_tgt_queue_depth,
5189 &dev_attr_lpfc_nodev_tmo,
5190 &dev_attr_lpfc_devloss_tmo,
5191 &dev_attr_lpfc_hba_queue_depth,
5192 &dev_attr_lpfc_peer_port_login,
5193 &dev_attr_lpfc_restrict_login,
5194 &dev_attr_lpfc_fcp_class,
5195 &dev_attr_lpfc_use_adisc,
5196 &dev_attr_lpfc_first_burst_size,
5197 &dev_attr_lpfc_max_luns,
5198 &dev_attr_nport_evt_cnt,
5199 &dev_attr_npiv_info,
5200 &dev_attr_lpfc_enable_da_id,
5201 &dev_attr_lpfc_max_scsicmpl_time,
5202 &dev_attr_lpfc_stat_data_ctrl,
5203 &dev_attr_lpfc_static_vport,
5204 &dev_attr_lpfc_fips_level,
5205 &dev_attr_lpfc_fips_rev,
5210 * sysfs_ctlreg_write - Write method for writing to ctlreg
5211 * @filp: open sysfs file
5212 * @kobj: kernel kobject that contains the kernel class device.
5213 * @bin_attr: kernel attributes passed to us.
5214 * @buf: contains the data to be written to the adapter IOREG space.
5215 * @off: offset into buffer to beginning of data.
5216 * @count: bytes to transfer.
5219 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5220 * Uses the adapter io control registers to send buf contents to the adapter.
5223 * -ERANGE off and count combo out of range
5224 * -EINVAL off, count or buff address invalid
5225 * -EPERM adapter is offline
5226 * value of count, buf contents written
5229 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5230 struct bin_attribute *bin_attr,
5231 char *buf, loff_t off, size_t count)
5234 struct device *dev = container_of(kobj, struct device, kobj);
5235 struct Scsi_Host *shost = class_to_shost(dev);
5236 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5237 struct lpfc_hba *phba = vport->phba;
5239 if (phba->sli_rev >= LPFC_SLI_REV4)
5242 if ((off + count) > FF_REG_AREA_SIZE)
5245 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5248 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5251 /* This is to protect HBA registers from accidental writes. */
5252 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5255 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5258 spin_lock_irq(&phba->hbalock);
5259 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5260 buf_off += sizeof(uint32_t))
5261 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5262 phba->ctrl_regs_memmap_p + off + buf_off);
5264 spin_unlock_irq(&phba->hbalock);
5270 * sysfs_ctlreg_read - Read method for reading from ctlreg
5271 * @filp: open sysfs file
5272 * @kobj: kernel kobject that contains the kernel class device.
5273 * @bin_attr: kernel attributes passed to us.
5274 * @buf: if successful contains the data from the adapter IOREG space.
5275 * @off: offset into buffer to beginning of data.
5276 * @count: bytes to transfer.
5279 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5280 * Uses the adapter io control registers to read data into buf.
5283 * -ERANGE off and count combo out of range
5284 * -EINVAL off, count or buff address invalid
5285 * value of count, buf contents read
5288 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5289 struct bin_attribute *bin_attr,
5290 char *buf, loff_t off, size_t count)
5294 struct device *dev = container_of(kobj, struct device, kobj);
5295 struct Scsi_Host *shost = class_to_shost(dev);
5296 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5297 struct lpfc_hba *phba = vport->phba;
5299 if (phba->sli_rev >= LPFC_SLI_REV4)
5302 if (off > FF_REG_AREA_SIZE)
5305 if ((off + count) > FF_REG_AREA_SIZE)
5306 count = FF_REG_AREA_SIZE - off;
5308 if (count == 0) return 0;
5310 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5313 spin_lock_irq(&phba->hbalock);
5315 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5316 tmp_ptr = (uint32_t *)(buf + buf_off);
5317 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5320 spin_unlock_irq(&phba->hbalock);
5325 static struct bin_attribute sysfs_ctlreg_attr = {
5328 .mode = S_IRUSR | S_IWUSR,
5331 .read = sysfs_ctlreg_read,
5332 .write = sysfs_ctlreg_write,
5336 * sysfs_mbox_write - Write method for writing information via mbox
5337 * @filp: open sysfs file
5338 * @kobj: kernel kobject that contains the kernel class device.
5339 * @bin_attr: kernel attributes passed to us.
5340 * @buf: contains the data to be written to sysfs mbox.
5341 * @off: offset into buffer to beginning of data.
5342 * @count: bytes to transfer.
5345 * Deprecated function. All mailbox access from user space is performed via the
5349 * -EPERM operation not permitted
5352 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5353 struct bin_attribute *bin_attr,
5354 char *buf, loff_t off, size_t count)
5360 * sysfs_mbox_read - Read method for reading information via mbox
5361 * @filp: open sysfs file
5362 * @kobj: kernel kobject that contains the kernel class device.
5363 * @bin_attr: kernel attributes passed to us.
5364 * @buf: contains the data to be read from sysfs mbox.
5365 * @off: offset into buffer to beginning of data.
5366 * @count: bytes to transfer.
5369 * Deprecated function. All mailbox access from user space is performed via the
5373 * -EPERM operation not permitted
5376 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5377 struct bin_attribute *bin_attr,
5378 char *buf, loff_t off, size_t count)
5383 static struct bin_attribute sysfs_mbox_attr = {
5386 .mode = S_IRUSR | S_IWUSR,
5388 .size = MAILBOX_SYSFS_MAX,
5389 .read = sysfs_mbox_read,
5390 .write = sysfs_mbox_write,
5394 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5395 * @vport: address of lpfc vport structure.
5399 * error return code from sysfs_create_bin_file()
5402 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5404 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5407 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5408 &sysfs_drvr_stat_data_attr);
5410 /* Virtual ports do not need ctrl_reg and mbox */
5411 if (error || vport->port_type == LPFC_NPIV_PORT)
5414 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5415 &sysfs_ctlreg_attr);
5417 goto out_remove_stat_attr;
5419 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5422 goto out_remove_ctlreg_attr;
5425 out_remove_ctlreg_attr:
5426 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5427 out_remove_stat_attr:
5428 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5429 &sysfs_drvr_stat_data_attr);
5435 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5436 * @vport: address of lpfc vport structure.
5439 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5442 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5443 &sysfs_drvr_stat_data_attr);
5444 /* Virtual ports do not need ctrl_reg and mbox */
5445 if (vport->port_type == LPFC_NPIV_PORT)
5447 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5448 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5452 * Dynamic FC Host Attributes Support
5456 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5457 * @shost: kernel scsi host pointer.
5460 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5462 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5464 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5465 sizeof fc_host_symbolic_name(shost));
5469 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5470 * @shost: kernel scsi host pointer.
5473 lpfc_get_host_port_id(struct Scsi_Host *shost)
5475 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5477 /* note: fc_myDID already in cpu endianness */
5478 fc_host_port_id(shost) = vport->fc_myDID;
5482 * lpfc_get_host_port_type - Set the value of the scsi host port type
5483 * @shost: kernel scsi host pointer.
5486 lpfc_get_host_port_type(struct Scsi_Host *shost)
5488 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5489 struct lpfc_hba *phba = vport->phba;
5491 spin_lock_irq(shost->host_lock);
5493 if (vport->port_type == LPFC_NPIV_PORT) {
5494 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5495 } else if (lpfc_is_link_up(phba)) {
5496 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5497 if (vport->fc_flag & FC_PUBLIC_LOOP)
5498 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5500 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5502 if (vport->fc_flag & FC_FABRIC)
5503 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5505 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5508 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5510 spin_unlock_irq(shost->host_lock);
5514 * lpfc_get_host_port_state - Set the value of the scsi host port state
5515 * @shost: kernel scsi host pointer.
5518 lpfc_get_host_port_state(struct Scsi_Host *shost)
5520 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5521 struct lpfc_hba *phba = vport->phba;
5523 spin_lock_irq(shost->host_lock);
5525 if (vport->fc_flag & FC_OFFLINE_MODE)
5526 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5528 switch (phba->link_state) {
5529 case LPFC_LINK_UNKNOWN:
5530 case LPFC_LINK_DOWN:
5531 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5535 case LPFC_HBA_READY:
5536 /* Links up, reports port state accordingly */
5537 if (vport->port_state < LPFC_VPORT_READY)
5538 fc_host_port_state(shost) =
5539 FC_PORTSTATE_BYPASSED;
5541 fc_host_port_state(shost) =
5542 FC_PORTSTATE_ONLINE;
5544 case LPFC_HBA_ERROR:
5545 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5548 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5553 spin_unlock_irq(shost->host_lock);
5557 * lpfc_get_host_speed - Set the value of the scsi host speed
5558 * @shost: kernel scsi host pointer.
5561 lpfc_get_host_speed(struct Scsi_Host *shost)
5563 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5564 struct lpfc_hba *phba = vport->phba;
5566 spin_lock_irq(shost->host_lock);
5568 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5569 switch(phba->fc_linkspeed) {
5570 case LPFC_LINK_SPEED_1GHZ:
5571 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5573 case LPFC_LINK_SPEED_2GHZ:
5574 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5576 case LPFC_LINK_SPEED_4GHZ:
5577 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5579 case LPFC_LINK_SPEED_8GHZ:
5580 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5582 case LPFC_LINK_SPEED_10GHZ:
5583 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5585 case LPFC_LINK_SPEED_16GHZ:
5586 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5588 case LPFC_LINK_SPEED_32GHZ:
5589 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5592 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5596 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5598 spin_unlock_irq(shost->host_lock);
5602 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5603 * @shost: kernel scsi host pointer.
5606 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5608 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5609 struct lpfc_hba *phba = vport->phba;
5612 spin_lock_irq(shost->host_lock);
5614 if ((vport->port_state > LPFC_FLOGI) &&
5615 ((vport->fc_flag & FC_FABRIC) ||
5616 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5617 (vport->fc_flag & FC_PUBLIC_LOOP))))
5618 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5620 /* fabric is local port if there is no F/FL_Port */
5623 spin_unlock_irq(shost->host_lock);
5625 fc_host_fabric_name(shost) = node_name;
5629 * lpfc_get_stats - Return statistical information about the adapter
5630 * @shost: kernel scsi host pointer.
5633 * NULL on error for link down, no mbox pool, sli2 active,
5634 * management not allowed, memory allocation error, or mbox error.
5638 * address of the adapter host statistics
5640 static struct fc_host_statistics *
5641 lpfc_get_stats(struct Scsi_Host *shost)
5643 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5644 struct lpfc_hba *phba = vport->phba;
5645 struct lpfc_sli *psli = &phba->sli;
5646 struct fc_host_statistics *hs = &phba->link_stats;
5647 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5648 LPFC_MBOXQ_t *pmboxq;
5650 unsigned long seconds;
5654 * prevent udev from issuing mailbox commands until the port is
5657 if (phba->link_state < LPFC_LINK_DOWN ||
5658 !phba->mbox_mem_pool ||
5659 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5662 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5665 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5668 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5670 pmb = &pmboxq->u.mb;
5671 pmb->mbxCommand = MBX_READ_STATUS;
5672 pmb->mbxOwner = OWN_HOST;
5673 pmboxq->context1 = NULL;
5674 pmboxq->vport = vport;
5676 if (vport->fc_flag & FC_OFFLINE_MODE)
5677 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5679 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5681 if (rc != MBX_SUCCESS) {
5682 if (rc != MBX_TIMEOUT)
5683 mempool_free(pmboxq, phba->mbox_mem_pool);
5687 memset(hs, 0, sizeof (struct fc_host_statistics));
5689 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5691 * The MBX_READ_STATUS returns tx_k_bytes which has to
5692 * converted to words
5694 hs->tx_words = (uint64_t)
5695 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5697 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5698 hs->rx_words = (uint64_t)
5699 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5702 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5703 pmb->mbxCommand = MBX_READ_LNK_STAT;
5704 pmb->mbxOwner = OWN_HOST;
5705 pmboxq->context1 = NULL;
5706 pmboxq->vport = vport;
5708 if (vport->fc_flag & FC_OFFLINE_MODE)
5709 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5711 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5713 if (rc != MBX_SUCCESS) {
5714 if (rc != MBX_TIMEOUT)
5715 mempool_free(pmboxq, phba->mbox_mem_pool);
5719 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5720 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5721 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5722 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5723 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5724 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5725 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5727 hs->link_failure_count -= lso->link_failure_count;
5728 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5729 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5730 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5731 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5732 hs->invalid_crc_count -= lso->invalid_crc_count;
5733 hs->error_frames -= lso->error_frames;
5735 if (phba->hba_flag & HBA_FCOE_MODE) {
5737 hs->nos_count = (phba->link_events >> 1);
5738 hs->nos_count -= lso->link_events;
5739 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5740 hs->lip_count = (phba->fc_eventTag >> 1);
5741 hs->lip_count -= lso->link_events;
5745 hs->nos_count = (phba->fc_eventTag >> 1);
5746 hs->nos_count -= lso->link_events;
5749 hs->dumped_frames = -1;
5751 seconds = get_seconds();
5752 if (seconds < psli->stats_start)
5753 hs->seconds_since_last_reset = seconds +
5754 ((unsigned long)-1 - psli->stats_start);
5756 hs->seconds_since_last_reset = seconds - psli->stats_start;
5758 mempool_free(pmboxq, phba->mbox_mem_pool);
5764 * lpfc_reset_stats - Copy the adapter link stats information
5765 * @shost: kernel scsi host pointer.
5768 lpfc_reset_stats(struct Scsi_Host *shost)
5770 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5771 struct lpfc_hba *phba = vport->phba;
5772 struct lpfc_sli *psli = &phba->sli;
5773 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5774 LPFC_MBOXQ_t *pmboxq;
5778 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5781 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5784 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5786 pmb = &pmboxq->u.mb;
5787 pmb->mbxCommand = MBX_READ_STATUS;
5788 pmb->mbxOwner = OWN_HOST;
5789 pmb->un.varWords[0] = 0x1; /* reset request */
5790 pmboxq->context1 = NULL;
5791 pmboxq->vport = vport;
5793 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5794 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5795 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5797 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5799 if (rc != MBX_SUCCESS) {
5800 if (rc != MBX_TIMEOUT)
5801 mempool_free(pmboxq, phba->mbox_mem_pool);
5805 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5806 pmb->mbxCommand = MBX_READ_LNK_STAT;
5807 pmb->mbxOwner = OWN_HOST;
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 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5824 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5825 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5826 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5827 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5828 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5829 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5830 if (phba->hba_flag & HBA_FCOE_MODE)
5831 lso->link_events = (phba->link_events >> 1);
5833 lso->link_events = (phba->fc_eventTag >> 1);
5835 psli->stats_start = get_seconds();
5837 mempool_free(pmboxq, phba->mbox_mem_pool);
5843 * The LPFC driver treats linkdown handling as target loss events so there
5844 * are no sysfs handlers for link_down_tmo.
5848 * lpfc_get_node_by_target - Return the nodelist for a target
5849 * @starget: kernel scsi target pointer.
5852 * address of the node list if found
5853 * NULL target not found
5855 static struct lpfc_nodelist *
5856 lpfc_get_node_by_target(struct scsi_target *starget)
5858 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5859 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5860 struct lpfc_nodelist *ndlp;
5862 spin_lock_irq(shost->host_lock);
5863 /* Search for this, mapped, target ID */
5864 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5865 if (NLP_CHK_NODE_ACT(ndlp) &&
5866 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5867 starget->id == ndlp->nlp_sid) {
5868 spin_unlock_irq(shost->host_lock);
5872 spin_unlock_irq(shost->host_lock);
5877 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5878 * @starget: kernel scsi target pointer.
5881 lpfc_get_starget_port_id(struct scsi_target *starget)
5883 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5885 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5889 * lpfc_get_starget_node_name - Set the target node name
5890 * @starget: kernel scsi target pointer.
5892 * Description: Set the target node name to the ndlp node name wwn or zero.
5895 lpfc_get_starget_node_name(struct scsi_target *starget)
5897 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5899 fc_starget_node_name(starget) =
5900 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5904 * lpfc_get_starget_port_name - Set the target port name
5905 * @starget: kernel scsi target pointer.
5907 * Description: set the target port name to the ndlp port name wwn or zero.
5910 lpfc_get_starget_port_name(struct scsi_target *starget)
5912 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5914 fc_starget_port_name(starget) =
5915 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5919 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5920 * @rport: fc rport address.
5921 * @timeout: new value for dev loss tmo.
5924 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5925 * dev_loss_tmo to one.
5928 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5931 rport->dev_loss_tmo = timeout;
5933 rport->dev_loss_tmo = 1;
5937 * lpfc_rport_show_function - Return rport target information
5940 * Macro that uses field to generate a function with the name lpfc_show_rport_
5942 * lpfc_show_rport_##field: returns the bytes formatted in buf
5943 * @cdev: class converted to an fc_rport.
5944 * @buf: on return contains the target_field or zero.
5946 * Returns: size of formatted string.
5948 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5950 lpfc_show_rport_##field (struct device *dev, \
5951 struct device_attribute *attr, \
5954 struct fc_rport *rport = transport_class_to_rport(dev); \
5955 struct lpfc_rport_data *rdata = rport->hostdata; \
5956 return snprintf(buf, sz, format_string, \
5957 (rdata->target) ? cast rdata->target->field : 0); \
5960 #define lpfc_rport_rd_attr(field, format_string, sz) \
5961 lpfc_rport_show_function(field, format_string, sz, ) \
5962 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5965 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
5966 * @fc_vport: The fc_vport who's symbolic name has been changed.
5969 * This function is called by the transport after the @fc_vport's symbolic name
5970 * has been changed. This function re-registers the symbolic name with the
5971 * switch to propagate the change into the fabric if the vport is active.
5974 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5976 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5978 if (vport->port_state == LPFC_VPORT_READY)
5979 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5983 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5984 * @phba: Pointer to lpfc_hba struct.
5986 * This function is called by the lpfc_get_cfgparam() routine to set the
5987 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
5988 * log message according to the module's lpfc_log_verbose parameter setting
5989 * before hba port or vport created.
5992 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5994 phba->cfg_log_verbose = verbose;
5997 struct fc_function_template lpfc_transport_functions = {
5998 /* fixed attributes the driver supports */
5999 .show_host_node_name = 1,
6000 .show_host_port_name = 1,
6001 .show_host_supported_classes = 1,
6002 .show_host_supported_fc4s = 1,
6003 .show_host_supported_speeds = 1,
6004 .show_host_maxframe_size = 1,
6006 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6007 .show_host_symbolic_name = 1,
6009 /* dynamic attributes the driver supports */
6010 .get_host_port_id = lpfc_get_host_port_id,
6011 .show_host_port_id = 1,
6013 .get_host_port_type = lpfc_get_host_port_type,
6014 .show_host_port_type = 1,
6016 .get_host_port_state = lpfc_get_host_port_state,
6017 .show_host_port_state = 1,
6019 /* active_fc4s is shown but doesn't change (thus no get function) */
6020 .show_host_active_fc4s = 1,
6022 .get_host_speed = lpfc_get_host_speed,
6023 .show_host_speed = 1,
6025 .get_host_fabric_name = lpfc_get_host_fabric_name,
6026 .show_host_fabric_name = 1,
6029 * The LPFC driver treats linkdown handling as target loss events
6030 * so there are no sysfs handlers for link_down_tmo.
6033 .get_fc_host_stats = lpfc_get_stats,
6034 .reset_fc_host_stats = lpfc_reset_stats,
6036 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6037 .show_rport_maxframe_size = 1,
6038 .show_rport_supported_classes = 1,
6040 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6041 .show_rport_dev_loss_tmo = 1,
6043 .get_starget_port_id = lpfc_get_starget_port_id,
6044 .show_starget_port_id = 1,
6046 .get_starget_node_name = lpfc_get_starget_node_name,
6047 .show_starget_node_name = 1,
6049 .get_starget_port_name = lpfc_get_starget_port_name,
6050 .show_starget_port_name = 1,
6052 .issue_fc_host_lip = lpfc_issue_lip,
6053 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6054 .terminate_rport_io = lpfc_terminate_rport_io,
6056 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6058 .vport_disable = lpfc_vport_disable,
6060 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6062 .bsg_request = lpfc_bsg_request,
6063 .bsg_timeout = lpfc_bsg_timeout,
6066 struct fc_function_template lpfc_vport_transport_functions = {
6067 /* fixed attributes the driver supports */
6068 .show_host_node_name = 1,
6069 .show_host_port_name = 1,
6070 .show_host_supported_classes = 1,
6071 .show_host_supported_fc4s = 1,
6072 .show_host_supported_speeds = 1,
6073 .show_host_maxframe_size = 1,
6075 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6076 .show_host_symbolic_name = 1,
6078 /* dynamic attributes the driver supports */
6079 .get_host_port_id = lpfc_get_host_port_id,
6080 .show_host_port_id = 1,
6082 .get_host_port_type = lpfc_get_host_port_type,
6083 .show_host_port_type = 1,
6085 .get_host_port_state = lpfc_get_host_port_state,
6086 .show_host_port_state = 1,
6088 /* active_fc4s is shown but doesn't change (thus no get function) */
6089 .show_host_active_fc4s = 1,
6091 .get_host_speed = lpfc_get_host_speed,
6092 .show_host_speed = 1,
6094 .get_host_fabric_name = lpfc_get_host_fabric_name,
6095 .show_host_fabric_name = 1,
6098 * The LPFC driver treats linkdown handling as target loss events
6099 * so there are no sysfs handlers for link_down_tmo.
6102 .get_fc_host_stats = lpfc_get_stats,
6103 .reset_fc_host_stats = lpfc_reset_stats,
6105 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6106 .show_rport_maxframe_size = 1,
6107 .show_rport_supported_classes = 1,
6109 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6110 .show_rport_dev_loss_tmo = 1,
6112 .get_starget_port_id = lpfc_get_starget_port_id,
6113 .show_starget_port_id = 1,
6115 .get_starget_node_name = lpfc_get_starget_node_name,
6116 .show_starget_node_name = 1,
6118 .get_starget_port_name = lpfc_get_starget_port_name,
6119 .show_starget_port_name = 1,
6121 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6122 .terminate_rport_io = lpfc_terminate_rport_io,
6124 .vport_disable = lpfc_vport_disable,
6126 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6130 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6131 * @phba: lpfc_hba pointer.
6134 lpfc_get_cfgparam(struct lpfc_hba *phba)
6136 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6137 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6138 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6139 lpfc_cr_count_init(phba, lpfc_cr_count);
6140 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6141 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6142 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6143 lpfc_ack0_init(phba, lpfc_ack0);
6144 lpfc_topology_init(phba, lpfc_topology);
6145 lpfc_link_speed_init(phba, lpfc_link_speed);
6146 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6147 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6148 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6149 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6150 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6151 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6152 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6153 lpfc_use_msi_init(phba, lpfc_use_msi);
6154 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6155 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6156 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6157 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6158 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6160 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6161 if (phba->sli_rev != LPFC_SLI_REV4)
6162 phba->cfg_EnableXLane = 0;
6163 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6165 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6166 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6167 phba->cfg_oas_lun_state = 0;
6168 phba->cfg_oas_lun_status = 0;
6169 phba->cfg_oas_flags = 0;
6170 phba->cfg_oas_priority = 0;
6171 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6172 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6173 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6174 if (phba->sli_rev == LPFC_SLI_REV4)
6177 phba->cfg_poll = lpfc_poll;
6178 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6180 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6181 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6182 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
6184 /* Initialize first burst. Target vs Initiator are different. */
6185 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6186 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6187 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6188 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6190 if (phba->sli_rev != LPFC_SLI_REV4) {
6191 /* NVME only supported on SLI4 */
6192 phba->nvmet_support = 0;
6193 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6195 /* We MUST have FCP support */
6196 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6197 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6200 /* A value of 0 means use the number of CPUs found in the system */
6201 if (phba->cfg_fcp_io_channel == 0)
6202 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6203 if (phba->cfg_nvme_io_channel == 0)
6204 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6206 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6207 phba->cfg_fcp_io_channel = 0;
6209 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6210 phba->cfg_nvme_io_channel = 0;
6212 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6213 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6215 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6217 phba->cfg_soft_wwnn = 0L;
6218 phba->cfg_soft_wwpn = 0L;
6219 lpfc_xri_split_init(phba, lpfc_xri_split);
6220 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6221 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6222 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6223 lpfc_aer_support_init(phba, lpfc_aer_support);
6224 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6225 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6226 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6227 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6228 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6229 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6230 phba->cfg_enable_dss = 1;
6231 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6236 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6237 * dependencies between protocols and roles.
6238 * @phba: lpfc_hba pointer.
6241 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6243 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6244 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6246 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6247 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6249 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6250 phba->nvmet_support) {
6251 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6252 phba->cfg_fcp_io_channel = 0;
6254 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6255 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6256 "NVME Target PRLI ACC enable_fb ",
6257 phba->cfg_nvme_enable_fb,
6258 phba->cfg_nvmet_fb_size,
6259 LPFC_NVMET_FB_SZ_MAX);
6261 if (phba->cfg_nvme_enable_fb == 0)
6262 phba->cfg_nvmet_fb_size = 0;
6264 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6265 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6268 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6269 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6270 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6271 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6272 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6273 phba->cfg_nvmet_mrq);
6276 /* Not NVME Target mode. Turn off Target parameters. */
6277 phba->nvmet_support = 0;
6278 phba->cfg_nvmet_mrq = 0;
6279 phba->cfg_nvmet_mrq_post = 0;
6280 phba->cfg_nvmet_fb_size = 0;
6283 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6284 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6286 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6290 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6291 * @vport: lpfc_vport pointer.
6294 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6296 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6297 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6298 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6299 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6300 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6301 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6302 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6303 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6304 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6305 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6306 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6307 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6308 lpfc_max_luns_init(vport, lpfc_max_luns);
6309 lpfc_scan_down_init(vport, lpfc_scan_down);
6310 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);