1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/ctype.h>
25 #include <linux/delay.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/aer.h>
30 #include <linux/gfp.h>
31 #include <linux/kernel.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_tcq.h>
37 #include <scsi/scsi_transport_fc.h>
38 #include <scsi/fc/fc_fs.h>
40 #include <linux/nvme-fc-driver.h>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_nvmet.h"
52 #include "lpfc_logmsg.h"
53 #include "lpfc_version.h"
54 #include "lpfc_compat.h"
55 #include "lpfc_crtn.h"
56 #include "lpfc_vport.h"
57 #include "lpfc_attr.h"
59 #define LPFC_DEF_DEVLOSS_TMO 30
60 #define LPFC_MIN_DEVLOSS_TMO 1
61 #define LPFC_MAX_DEVLOSS_TMO 255
63 #define LPFC_DEF_MRQ_POST 512
64 #define LPFC_MIN_MRQ_POST 512
65 #define LPFC_MAX_MRQ_POST 2048
68 * Write key size should be multiple of 4. If write key is changed
69 * make sure that library write key is also changed.
71 #define LPFC_REG_WRITE_KEY_SIZE 4
72 #define LPFC_REG_WRITE_KEY "EMLX"
75 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
76 * @incr: integer to convert.
77 * @hdw: ascii string holding converted integer plus a string terminator.
80 * JEDEC Joint Electron Device Engineering Council.
81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
82 * character string. The string is then terminated with a NULL in byte 9.
83 * Hex 0-9 becomes ascii '0' to '9'.
84 * Hex a-f becomes ascii '=' to 'B' capital B.
87 * Coded for 32 bit integers only.
90 lpfc_jedec_to_ascii(int incr, char hdw[])
93 for (i = 0; i < 8; i++) {
96 hdw[7 - i] = 0x30 + j;
98 hdw[7 - i] = 0x61 + j - 10;
106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
107 * @dev: class unused variable.
108 * @attr: device attribute, not used.
109 * @buf: on return contains the module description text.
111 * Returns: size of formatted string.
114 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
126 * Returns: size of formatted string.
129 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
139 return snprintf(buf, PAGE_SIZE, "0\n");
143 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = shost_priv(shost);
148 struct lpfc_hba *phba = vport->phba;
149 struct lpfc_nvmet_tgtport *tgtp;
150 struct nvme_fc_local_port *localport;
151 struct lpfc_nodelist *ndlp;
152 struct nvme_fc_remote_port *nrport;
153 uint64_t data1, data2, data3, tot;
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 - len,
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 Release %08x Drop %08x\n",
209 atomic_read(&tgtp->rcv_fcp_cmd_in),
210 atomic_read(&tgtp->xmt_fcp_release),
211 atomic_read(&tgtp->rcv_fcp_cmd_drop));
213 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
214 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
215 len += snprintf(buf+len, PAGE_SIZE-len,
216 "Rcv FCP: in %08x != out %08x\n",
217 atomic_read(&tgtp->rcv_fcp_cmd_in),
218 atomic_read(&tgtp->rcv_fcp_cmd_out));
221 len += snprintf(buf+len, PAGE_SIZE-len,
222 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
224 atomic_read(&tgtp->xmt_fcp_read),
225 atomic_read(&tgtp->xmt_fcp_read_rsp),
226 atomic_read(&tgtp->xmt_fcp_write),
227 atomic_read(&tgtp->xmt_fcp_rsp),
228 atomic_read(&tgtp->xmt_fcp_drop));
230 len += snprintf(buf+len, PAGE_SIZE-len,
231 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
232 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
233 atomic_read(&tgtp->xmt_fcp_rsp_error),
234 atomic_read(&tgtp->xmt_fcp_rsp_drop));
236 len += snprintf(buf+len, PAGE_SIZE-len,
237 "ABORT: Xmt %08x Cmpl %08x\n",
238 atomic_read(&tgtp->xmt_fcp_abort),
239 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
241 len += snprintf(buf + len, PAGE_SIZE - len,
242 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
243 atomic_read(&tgtp->xmt_abort_sol),
244 atomic_read(&tgtp->xmt_abort_unsol),
245 atomic_read(&tgtp->xmt_abort_rsp),
246 atomic_read(&tgtp->xmt_abort_rsp_error));
248 spin_lock(&phba->sli4_hba.nvmet_io_lock);
249 tot = phba->sli4_hba.nvmet_xri_cnt -
250 phba->sli4_hba.nvmet_ctx_cnt;
251 spin_unlock(&phba->sli4_hba.nvmet_io_lock);
253 len += snprintf(buf + len, PAGE_SIZE - len,
254 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
255 "CTX Outstanding %08llx\n",
256 phba->sli4_hba.nvmet_ctx_cnt,
257 phba->sli4_hba.nvmet_io_wait_cnt,
258 phba->sli4_hba.nvmet_io_wait_total,
261 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
265 localport = vport->localport;
267 len = snprintf(buf, PAGE_SIZE,
268 "NVME Initiator x%llx is not allocated\n",
269 wwn_to_u64(vport->fc_portname.u.wwn));
272 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
274 spin_lock_irq(shost->host_lock);
276 /* Port state is only one of two values for now. */
277 if (localport->port_id)
282 len += snprintf(buf + len, PAGE_SIZE - len,
283 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
286 wwn_to_u64(vport->fc_portname.u.wwn),
287 wwn_to_u64(vport->fc_nodename.u.wwn),
288 localport->port_id, statep);
290 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
294 /* local short-hand pointer. */
295 nrport = ndlp->nrport->remoteport;
297 /* Port state is only one of two values for now. */
298 switch (nrport->port_state) {
299 case FC_OBJSTATE_ONLINE:
302 case FC_OBJSTATE_UNKNOWN:
306 statep = "UNSUPPORTED";
310 /* Tab in to show lport ownership. */
311 len += snprintf(buf + len, PAGE_SIZE - len,
313 if (phba->brd_no >= 10)
314 len += snprintf(buf + len, PAGE_SIZE - len, " ");
316 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
318 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
320 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
323 /* An NVME rport can have multiple roles. */
324 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
325 len += snprintf(buf + len, PAGE_SIZE - len,
327 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
328 len += snprintf(buf + len, PAGE_SIZE - len,
330 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
331 len += snprintf(buf + len, PAGE_SIZE - len,
333 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
334 FC_PORT_ROLE_NVME_TARGET |
335 FC_PORT_ROLE_NVME_DISCOVERY))
336 len += snprintf(buf + len, PAGE_SIZE - len,
340 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
341 /* Terminate the string. */
342 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
344 spin_unlock_irq(shost->host_lock);
346 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
347 len += snprintf(buf+len, PAGE_SIZE-len,
348 "LS: Xmt %016x Cmpl %016x\n",
349 atomic_read(&phba->fc4NvmeLsRequests),
350 atomic_read(&phba->fc4NvmeLsCmpls));
352 tot = atomic_read(&phba->fc4NvmeIoCmpls);
353 data1 = atomic_read(&phba->fc4NvmeInputRequests);
354 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
355 data3 = atomic_read(&phba->fc4NvmeControlRequests);
356 len += snprintf(buf+len, PAGE_SIZE-len,
357 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
358 data1, data2, data3);
360 len += snprintf(buf+len, PAGE_SIZE-len,
361 " Cmpl %016llx Outstanding %016llx\n",
362 tot, (data1 + data2 + data3) - tot);
367 lpfc_bg_info_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 if (phba->cfg_enable_bg)
375 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
376 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
378 return snprintf(buf, PAGE_SIZE,
379 "BlockGuard Not Supported\n");
381 return snprintf(buf, PAGE_SIZE,
382 "BlockGuard Disabled\n");
386 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
389 struct Scsi_Host *shost = class_to_shost(dev);
390 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
391 struct lpfc_hba *phba = vport->phba;
393 return snprintf(buf, PAGE_SIZE, "%llu\n",
394 (unsigned long long)phba->bg_guard_err_cnt);
398 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
401 struct Scsi_Host *shost = class_to_shost(dev);
402 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
403 struct lpfc_hba *phba = vport->phba;
405 return snprintf(buf, PAGE_SIZE, "%llu\n",
406 (unsigned long long)phba->bg_apptag_err_cnt);
410 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
413 struct Scsi_Host *shost = class_to_shost(dev);
414 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
415 struct lpfc_hba *phba = vport->phba;
417 return snprintf(buf, PAGE_SIZE, "%llu\n",
418 (unsigned long long)phba->bg_reftag_err_cnt);
422 * lpfc_info_show - Return some pci info about the host in ascii
423 * @dev: class converted to a Scsi_host structure.
424 * @attr: device attribute, not used.
425 * @buf: on return contains the formatted text from lpfc_info().
427 * Returns: size of formatted string.
430 lpfc_info_show(struct device *dev, struct device_attribute *attr,
433 struct Scsi_Host *host = class_to_shost(dev);
435 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
439 * lpfc_serialnum_show - Return the hba serial number in ascii
440 * @dev: class converted to a Scsi_host structure.
441 * @attr: device attribute, not used.
442 * @buf: on return contains the formatted text serial number.
444 * Returns: size of formatted string.
447 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
450 struct Scsi_Host *shost = class_to_shost(dev);
451 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
452 struct lpfc_hba *phba = vport->phba;
454 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
458 * lpfc_temp_sensor_show - Return the temperature sensor level
459 * @dev: class converted to a Scsi_host structure.
460 * @attr: device attribute, not used.
461 * @buf: on return contains the formatted support level.
464 * Returns a number indicating the temperature sensor level currently
465 * supported, zero or one in ascii.
467 * Returns: size of formatted string.
470 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
473 struct Scsi_Host *shost = class_to_shost(dev);
474 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
475 struct lpfc_hba *phba = vport->phba;
476 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
480 * lpfc_modeldesc_show - Return the model description 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 description.
485 * Returns: size of formatted string.
488 lpfc_modeldesc_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->ModelDesc);
499 * lpfc_modelname_show - Return the model name 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 model name.
504 * Returns: size of formatted string.
507 lpfc_modelname_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->ModelName);
518 * lpfc_programtype_show - Return the program type of the hba
519 * @dev: class converted to a Scsi_host structure.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the scsi vpd program type.
523 * Returns: size of formatted string.
526 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
529 struct Scsi_Host *shost = class_to_shost(dev);
530 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
531 struct lpfc_hba *phba = vport->phba;
533 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
537 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
538 * @dev: class converted to a Scsi_host structure.
539 * @attr: device attribute, not used.
540 * @buf: on return contains the Menlo Maintenance sli flag.
542 * Returns: size of formatted string.
545 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
547 struct Scsi_Host *shost = class_to_shost(dev);
548 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
549 struct lpfc_hba *phba = vport->phba;
551 return snprintf(buf, PAGE_SIZE, "%d\n",
552 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
556 * lpfc_vportnum_show - Return the port number in ascii of the hba
557 * @dev: class converted to a Scsi_host structure.
558 * @attr: device attribute, not used.
559 * @buf: on return contains scsi vpd program type.
561 * Returns: size of formatted string.
564 lpfc_vportnum_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;
571 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
575 * lpfc_fwrev_show - Return the firmware rev running in the hba
576 * @dev: class converted to a Scsi_host structure.
577 * @attr: device attribute, not used.
578 * @buf: on return contains the scsi vpd program type.
580 * Returns: size of formatted string.
583 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
586 struct Scsi_Host *shost = class_to_shost(dev);
587 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
588 struct lpfc_hba *phba = vport->phba;
591 char fwrev[FW_REV_STR_SIZE];
594 lpfc_decode_firmware_rev(phba, fwrev, 1);
595 if_type = phba->sli4_hba.pc_sli4_params.if_type;
596 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
598 if (phba->sli_rev < LPFC_SLI_REV4)
599 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
600 fwrev, phba->sli_rev);
602 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
603 fwrev, phba->sli_rev, if_type, sli_family);
609 * lpfc_hdw_show - Return the jedec information about the hba
610 * @dev: class converted to a Scsi_host structure.
611 * @attr: device attribute, not used.
612 * @buf: on return contains the scsi vpd program type.
614 * Returns: size of formatted string.
617 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
620 struct Scsi_Host *shost = class_to_shost(dev);
621 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
622 struct lpfc_hba *phba = vport->phba;
623 lpfc_vpd_t *vp = &phba->vpd;
625 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
626 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
630 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
631 * @dev: class converted to a Scsi_host structure.
632 * @attr: device attribute, not used.
633 * @buf: on return contains the ROM and FCode ascii strings.
635 * Returns: size of formatted string.
638 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
641 struct Scsi_Host *shost = class_to_shost(dev);
642 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
643 struct lpfc_hba *phba = vport->phba;
644 char fwrev[FW_REV_STR_SIZE];
646 if (phba->sli_rev < LPFC_SLI_REV4)
647 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
649 lpfc_decode_firmware_rev(phba, fwrev, 1);
650 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
654 * lpfc_state_show - Return the link state of the port
655 * @dev: class converted to a Scsi_host structure.
656 * @attr: device attribute, not used.
657 * @buf: on return contains text describing the state of the link.
660 * The switch statement has no default so zero will be returned.
662 * Returns: size of formatted string.
665 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
668 struct Scsi_Host *shost = class_to_shost(dev);
669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
670 struct lpfc_hba *phba = vport->phba;
673 switch (phba->link_state) {
674 case LPFC_LINK_UNKNOWN:
675 case LPFC_WARM_START:
676 case LPFC_INIT_START:
677 case LPFC_INIT_MBX_CMDS:
680 if (phba->hba_flag & LINK_DISABLED)
681 len += snprintf(buf + len, PAGE_SIZE-len,
682 "Link Down - User disabled\n");
684 len += snprintf(buf + len, PAGE_SIZE-len,
690 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
692 switch (vport->port_state) {
693 case LPFC_LOCAL_CFG_LINK:
694 len += snprintf(buf + len, PAGE_SIZE-len,
695 "Configuring Link\n");
699 case LPFC_FABRIC_CFG_LINK:
702 case LPFC_BUILD_DISC_LIST:
704 len += snprintf(buf + len, PAGE_SIZE - len,
707 case LPFC_VPORT_READY:
708 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
711 case LPFC_VPORT_FAILED:
712 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
715 case LPFC_VPORT_UNKNOWN:
716 len += snprintf(buf + len, PAGE_SIZE - len,
720 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
721 len += snprintf(buf + len, PAGE_SIZE-len,
722 " Menlo Maint Mode\n");
723 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
724 if (vport->fc_flag & FC_PUBLIC_LOOP)
725 len += snprintf(buf + len, PAGE_SIZE-len,
728 len += snprintf(buf + len, PAGE_SIZE-len,
731 if (vport->fc_flag & FC_FABRIC)
732 len += snprintf(buf + len, PAGE_SIZE-len,
735 len += snprintf(buf + len, PAGE_SIZE-len,
744 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
745 * @dev: class unused variable.
746 * @attr: device attribute, not used.
747 * @buf: on return contains the module description text.
749 * Returns: size of formatted string.
752 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
755 struct Scsi_Host *shost = class_to_shost(dev);
756 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
757 struct lpfc_hba *phba = vport->phba;
759 if (phba->sli_rev < LPFC_SLI_REV4)
760 return snprintf(buf, PAGE_SIZE, "fc\n");
762 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
763 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
764 return snprintf(buf, PAGE_SIZE, "fcoe\n");
765 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
766 return snprintf(buf, PAGE_SIZE, "fc\n");
768 return snprintf(buf, PAGE_SIZE, "unknown\n");
772 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
773 * (OAS) is supported.
774 * @dev: class unused variable.
775 * @attr: device attribute, not used.
776 * @buf: on return contains the module description text.
778 * Returns: size of formatted string.
781 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
784 struct Scsi_Host *shost = class_to_shost(dev);
785 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
786 struct lpfc_hba *phba = vport->phba;
788 return snprintf(buf, PAGE_SIZE, "%d\n",
789 phba->sli4_hba.pc_sli4_params.oas_supported);
793 * lpfc_link_state_store - Transition the link_state on an HBA port
794 * @dev: class device that is converted into a Scsi_host.
795 * @attr: device attribute, not used.
796 * @buf: one or more lpfc_polling_flags values.
800 * -EINVAL if the buffer is not "up" or "down"
801 * return from link state change function if non-zero
802 * length of the buf on success
805 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
806 const char *buf, size_t count)
808 struct Scsi_Host *shost = class_to_shost(dev);
809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
810 struct lpfc_hba *phba = vport->phba;
812 int status = -EINVAL;
814 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
815 (phba->link_state == LPFC_LINK_DOWN))
816 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
817 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
818 (phba->link_state >= LPFC_LINK_UP))
819 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
828 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
829 * @dev: class device that is converted into a Scsi_host.
830 * @attr: device attribute, not used.
831 * @buf: on return contains the sum of fc mapped and unmapped.
834 * Returns the ascii text number of the sum of the fc mapped and unmapped
837 * Returns: size of formatted string.
840 lpfc_num_discovered_ports_show(struct device *dev,
841 struct device_attribute *attr, char *buf)
843 struct Scsi_Host *shost = class_to_shost(dev);
844 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
846 return snprintf(buf, PAGE_SIZE, "%d\n",
847 vport->fc_map_cnt + vport->fc_unmap_cnt);
851 * lpfc_issue_lip - Misnomer, name carried over from long ago
852 * @shost: Scsi_Host pointer.
855 * Bring the link down gracefully then re-init the link. The firmware will
856 * re-init the fiber channel interface as required. Does not issue a LIP.
859 * -EPERM port offline or management commands are being blocked
860 * -ENOMEM cannot allocate memory for the mailbox command
861 * -EIO error sending the mailbox command
865 lpfc_issue_lip(struct Scsi_Host *shost)
867 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
868 struct lpfc_hba *phba = vport->phba;
869 LPFC_MBOXQ_t *pmboxq;
870 int mbxstatus = MBXERR_ERROR;
872 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
873 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
876 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
881 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
882 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
883 pmboxq->u.mb.mbxOwner = OWN_HOST;
885 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
887 if ((mbxstatus == MBX_SUCCESS) &&
888 (pmboxq->u.mb.mbxStatus == 0 ||
889 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
890 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
891 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
892 phba->cfg_link_speed);
893 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
895 if ((mbxstatus == MBX_SUCCESS) &&
896 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
897 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
898 "2859 SLI authentication is required "
899 "for INIT_LINK but has not done yet\n");
902 lpfc_set_loopback_flag(phba);
903 if (mbxstatus != MBX_TIMEOUT)
904 mempool_free(pmboxq, phba->mbox_mem_pool);
906 if (mbxstatus == MBXERR_ERROR)
913 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
918 while (!list_empty(q)) {
919 spin_unlock_irq(lock);
921 if (cnt++ > 250) { /* 5 secs */
922 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
924 "Outstanding IO when ",
925 "bringing Adapter offline\n");
930 spin_unlock_irq(lock);
935 * lpfc_do_offline - Issues a mailbox command to bring the link down
936 * @phba: lpfc_hba pointer.
937 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
940 * Assumes any error from lpfc_do_offline() will be negative.
941 * Can wait up to 5 seconds for the port ring buffers count
942 * to reach zero, prints a warning if it is not zero and continues.
943 * lpfc_workq_post_event() returns a non-zero return code if call fails.
946 * -EIO error posting the event
950 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
952 struct completion online_compl;
953 struct lpfc_queue *qp = NULL;
954 struct lpfc_sli_ring *pring;
955 struct lpfc_sli *psli;
960 init_completion(&online_compl);
961 rc = lpfc_workq_post_event(phba, &status, &online_compl,
962 LPFC_EVT_OFFLINE_PREP);
966 wait_for_completion(&online_compl);
973 /* Wait a little for things to settle down, but not
974 * long enough for dev loss timeout to expire.
976 if (phba->sli_rev != LPFC_SLI_REV4) {
977 for (i = 0; i < psli->num_rings; i++) {
978 pring = &psli->sli3_ring[i];
979 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
984 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
988 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
994 init_completion(&online_compl);
995 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
999 wait_for_completion(&online_compl);
1008 * lpfc_selective_reset - Offline then onlines the port
1009 * @phba: lpfc_hba pointer.
1012 * If the port is configured to allow a reset then the hba is brought
1013 * offline then online.
1016 * Assumes any error from lpfc_do_offline() will be negative.
1017 * Do not make this function static.
1020 * lpfc_do_offline() return code if not zero
1021 * -EIO reset not configured or error posting the event
1025 lpfc_selective_reset(struct lpfc_hba *phba)
1027 struct completion online_compl;
1031 if (!phba->cfg_enable_hba_reset)
1034 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1035 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1041 init_completion(&online_compl);
1042 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1047 wait_for_completion(&online_compl);
1056 * lpfc_issue_reset - Selectively resets an adapter
1057 * @dev: class device that is converted into a Scsi_host.
1058 * @attr: device attribute, not used.
1059 * @buf: containing the string "selective".
1060 * @count: unused variable.
1063 * If the buf contains the string "selective" then lpfc_selective_reset()
1064 * is called to perform the reset.
1067 * Assumes any error from lpfc_selective_reset() will be negative.
1068 * If lpfc_selective_reset() returns zero then the length of the buffer
1069 * is returned which indicates success
1072 * -EINVAL if the buffer does not contain the string "selective"
1073 * length of buf if lpfc-selective_reset() if the call succeeds
1074 * return value of lpfc_selective_reset() if the call fails
1077 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1078 const char *buf, size_t count)
1080 struct Scsi_Host *shost = class_to_shost(dev);
1081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1082 struct lpfc_hba *phba = vport->phba;
1083 int status = -EINVAL;
1085 if (!phba->cfg_enable_hba_reset)
1088 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1089 status = phba->lpfc_selective_reset(phba);
1098 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1099 * @phba: lpfc_hba pointer.
1102 * SLI4 interface type-2 device to wait on the sliport status register for
1103 * the readyness after performing a firmware reset.
1106 * zero for success, -EPERM when port does not have privilege to perform the
1107 * reset, -EIO when port timeout from recovering from the reset.
1110 * As the caller will interpret the return code by value, be careful in making
1111 * change or addition to return codes.
1114 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1116 struct lpfc_register portstat_reg = {0};
1120 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1121 &portstat_reg.word0);
1123 /* verify if privileged for the request operation */
1124 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1125 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1128 /* wait for the SLI port firmware ready after firmware reset */
1129 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1131 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1132 &portstat_reg.word0);
1133 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1135 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1137 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1142 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1149 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1150 * @phba: lpfc_hba pointer.
1153 * Request SLI4 interface type-2 device to perform a physical register set
1160 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1162 struct completion online_compl;
1163 struct pci_dev *pdev = phba->pcidev;
1164 uint32_t before_fc_flag;
1165 uint32_t sriov_nr_virtfn;
1167 int status = 0, rc = 0;
1168 int job_posted = 1, sriov_err;
1170 if (!phba->cfg_enable_hba_reset)
1173 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1174 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1175 LPFC_SLI_INTF_IF_TYPE_2))
1178 /* Keep state if we need to restore back */
1179 before_fc_flag = phba->pport->fc_flag;
1180 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1182 /* Disable SR-IOV virtual functions if enabled */
1183 if (phba->cfg_sriov_nr_virtfn) {
1184 pci_disable_sriov(pdev);
1185 phba->cfg_sriov_nr_virtfn = 0;
1188 if (opcode == LPFC_FW_DUMP)
1189 phba->hba_flag |= HBA_FW_DUMP_OP;
1191 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1194 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1198 /* wait for the device to be quiesced before firmware reset */
1201 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1202 LPFC_CTL_PDEV_CTL_OFFSET);
1204 if (opcode == LPFC_FW_DUMP)
1205 reg_val |= LPFC_FW_DUMP_REQUEST;
1206 else if (opcode == LPFC_FW_RESET)
1207 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1208 else if (opcode == LPFC_DV_RESET)
1209 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1211 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1212 LPFC_CTL_PDEV_CTL_OFFSET);
1214 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1216 /* delay driver action following IF_TYPE_2 reset */
1217 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1220 /* no privilege for reset */
1221 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1222 "3150 No privilege to perform the requested "
1223 "access: x%x\n", reg_val);
1224 } else if (rc == -EIO) {
1225 /* reset failed, there is nothing more we can do */
1226 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1227 "3153 Fail to perform the requested "
1228 "access: x%x\n", reg_val);
1232 /* keep the original port state */
1233 if (before_fc_flag & FC_OFFLINE_MODE)
1236 init_completion(&online_compl);
1237 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1242 wait_for_completion(&online_compl);
1245 /* in any case, restore the virtual functions enabled as before */
1246 if (sriov_nr_virtfn) {
1248 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1250 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1253 /* return proper error code */
1264 * lpfc_nport_evt_cnt_show - Return the number of nport events
1265 * @dev: class device that is converted into a Scsi_host.
1266 * @attr: device attribute, not used.
1267 * @buf: on return contains the ascii number of nport events.
1269 * Returns: size of formatted string.
1272 lpfc_nport_evt_cnt_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;
1279 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1283 * lpfc_board_mode_show - Return the state of the board
1284 * @dev: class device that is converted into a Scsi_host.
1285 * @attr: device attribute, not used.
1286 * @buf: on return contains the state of the adapter.
1288 * Returns: size of formatted string.
1291 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1294 struct Scsi_Host *shost = class_to_shost(dev);
1295 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1296 struct lpfc_hba *phba = vport->phba;
1299 if (phba->link_state == LPFC_HBA_ERROR)
1301 else if (phba->link_state == LPFC_WARM_START)
1302 state = "warm start";
1303 else if (phba->link_state == LPFC_INIT_START)
1308 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1312 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1313 * @dev: class device that is converted into a Scsi_host.
1314 * @attr: device attribute, not used.
1315 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1316 * @count: unused variable.
1319 * -EACCES if enable hba reset not enabled
1320 * -EINVAL if the buffer does not contain a valid string (see above)
1321 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1322 * buf length greater than zero indicates success
1325 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1326 const char *buf, size_t count)
1328 struct Scsi_Host *shost = class_to_shost(dev);
1329 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1330 struct lpfc_hba *phba = vport->phba;
1331 struct completion online_compl;
1332 char *board_mode_str = NULL;
1336 if (!phba->cfg_enable_hba_reset) {
1338 goto board_mode_out;
1341 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1342 "3050 lpfc_board_mode set to %s\n", buf);
1344 init_completion(&online_compl);
1346 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1347 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1351 goto board_mode_out;
1353 wait_for_completion(&online_compl);
1354 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1355 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1356 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1357 if (phba->sli_rev == LPFC_SLI_REV4)
1360 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1361 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1362 if (phba->sli_rev == LPFC_SLI_REV4)
1365 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1366 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1367 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1368 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1369 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1370 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1371 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1379 board_mode_str = strchr(buf, '\n');
1381 *board_mode_str = '\0';
1382 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1383 "3097 Failed \"%s\", status(%d), "
1385 buf, status, phba->pport->fc_flag);
1391 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1392 * @phba: pointer to the adapter structure.
1393 * @mxri: max xri count.
1394 * @axri: available xri count.
1395 * @mrpi: max rpi count.
1396 * @arpi: available rpi count.
1397 * @mvpi: max vpi count.
1398 * @avpi: available vpi count.
1401 * If an integer pointer for an count is not null then the value for the
1402 * count is returned.
1409 lpfc_get_hba_info(struct lpfc_hba *phba,
1410 uint32_t *mxri, uint32_t *axri,
1411 uint32_t *mrpi, uint32_t *arpi,
1412 uint32_t *mvpi, uint32_t *avpi)
1414 struct lpfc_mbx_read_config *rd_config;
1415 LPFC_MBOXQ_t *pmboxq;
1421 * prevent udev from issuing mailbox commands until the port is
1424 if (phba->link_state < LPFC_LINK_DOWN ||
1425 !phba->mbox_mem_pool ||
1426 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1429 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1432 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1435 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1437 pmb = &pmboxq->u.mb;
1438 pmb->mbxCommand = MBX_READ_CONFIG;
1439 pmb->mbxOwner = OWN_HOST;
1440 pmboxq->context1 = NULL;
1442 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1443 rc = MBX_NOT_FINISHED;
1445 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1447 if (rc != MBX_SUCCESS) {
1448 if (rc != MBX_TIMEOUT)
1449 mempool_free(pmboxq, phba->mbox_mem_pool);
1453 if (phba->sli_rev == LPFC_SLI_REV4) {
1454 rd_config = &pmboxq->u.mqe.un.rd_config;
1456 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1458 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1459 phba->sli4_hba.max_cfg_param.rpi_used;
1461 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1463 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1464 phba->sli4_hba.max_cfg_param.xri_used;
1466 /* Account for differences with SLI-3. Get vpi count from
1467 * mailbox data and subtract one for max vpi value.
1469 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1470 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1475 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1478 *mrpi = pmb->un.varRdConfig.max_rpi;
1480 *arpi = pmb->un.varRdConfig.avail_rpi;
1482 *mxri = pmb->un.varRdConfig.max_xri;
1484 *axri = pmb->un.varRdConfig.avail_xri;
1486 *mvpi = pmb->un.varRdConfig.max_vpi;
1488 *avpi = pmb->un.varRdConfig.avail_vpi;
1491 mempool_free(pmboxq, phba->mbox_mem_pool);
1496 * lpfc_max_rpi_show - Return maximum rpi
1497 * @dev: class device that is converted into a Scsi_host.
1498 * @attr: device attribute, not used.
1499 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1502 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1503 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1504 * to "Unknown" and the buffer length is returned, therefore the caller
1505 * must check for "Unknown" in the buffer to detect a failure.
1507 * Returns: size of formatted string.
1510 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1513 struct Scsi_Host *shost = class_to_shost(dev);
1514 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1515 struct lpfc_hba *phba = vport->phba;
1518 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1519 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1520 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1524 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1525 * @dev: class device that is converted into a Scsi_host.
1526 * @attr: device attribute, not used.
1527 * @buf: containing the used rpi count in decimal or "Unknown".
1530 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1531 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1532 * to "Unknown" and the buffer length is returned, therefore the caller
1533 * must check for "Unknown" in the buffer to detect a failure.
1535 * Returns: size of formatted string.
1538 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1541 struct Scsi_Host *shost = class_to_shost(dev);
1542 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1543 struct lpfc_hba *phba = vport->phba;
1546 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1547 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1548 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1552 * lpfc_max_xri_show - Return maximum xri
1553 * @dev: class device that is converted into a Scsi_host.
1554 * @attr: device attribute, not used.
1555 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1558 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1559 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1560 * to "Unknown" and the buffer length is returned, therefore the caller
1561 * must check for "Unknown" in the buffer to detect a failure.
1563 * Returns: size of formatted string.
1566 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1569 struct Scsi_Host *shost = class_to_shost(dev);
1570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1571 struct lpfc_hba *phba = vport->phba;
1574 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1575 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1576 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1580 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1581 * @dev: class device that is converted into a Scsi_host.
1582 * @attr: device attribute, not used.
1583 * @buf: on return contains the used xri count in decimal or "Unknown".
1586 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1587 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1588 * to "Unknown" and the buffer length is returned, therefore the caller
1589 * must check for "Unknown" in the buffer to detect a failure.
1591 * Returns: size of formatted string.
1594 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1597 struct Scsi_Host *shost = class_to_shost(dev);
1598 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1599 struct lpfc_hba *phba = vport->phba;
1602 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1603 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1604 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1608 * lpfc_max_vpi_show - Return maximum vpi
1609 * @dev: class device that is converted into a Scsi_host.
1610 * @attr: device attribute, not used.
1611 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1614 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1615 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1616 * to "Unknown" and the buffer length is returned, therefore the caller
1617 * must check for "Unknown" in the buffer to detect a failure.
1619 * Returns: size of formatted string.
1622 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1625 struct Scsi_Host *shost = class_to_shost(dev);
1626 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1627 struct lpfc_hba *phba = vport->phba;
1630 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1631 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1632 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1636 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1637 * @dev: class device that is converted into a Scsi_host.
1638 * @attr: device attribute, not used.
1639 * @buf: on return contains the used vpi count in decimal or "Unknown".
1642 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1643 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1644 * to "Unknown" and the buffer length is returned, therefore the caller
1645 * must check for "Unknown" in the buffer to detect a failure.
1647 * Returns: size of formatted string.
1650 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1653 struct Scsi_Host *shost = class_to_shost(dev);
1654 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1655 struct lpfc_hba *phba = vport->phba;
1658 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1659 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1660 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1664 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1665 * @dev: class device that is converted into a Scsi_host.
1666 * @attr: device attribute, not used.
1667 * @buf: text that must be interpreted to determine if npiv is supported.
1670 * Buffer will contain text indicating npiv is not suppoerted on the port,
1671 * the port is an NPIV physical port, or it is an npiv virtual port with
1672 * the id of the vport.
1674 * Returns: size of formatted string.
1677 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1680 struct Scsi_Host *shost = class_to_shost(dev);
1681 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1682 struct lpfc_hba *phba = vport->phba;
1684 if (!(phba->max_vpi))
1685 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1686 if (vport->port_type == LPFC_PHYSICAL_PORT)
1687 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1688 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1692 * lpfc_poll_show - Return text about poll support for the adapter
1693 * @dev: class device that is converted into a Scsi_host.
1694 * @attr: device attribute, not used.
1695 * @buf: on return contains the cfg_poll in hex.
1698 * cfg_poll should be a lpfc_polling_flags type.
1700 * Returns: size of formatted string.
1703 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1706 struct Scsi_Host *shost = class_to_shost(dev);
1707 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1708 struct lpfc_hba *phba = vport->phba;
1710 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1714 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1715 * @dev: class device that is converted into a Scsi_host.
1716 * @attr: device attribute, not used.
1717 * @buf: one or more lpfc_polling_flags values.
1721 * buf contents converted to integer and checked for a valid value.
1724 * -EINVAL if the buffer connot be converted or is out of range
1725 * length of the buf on success
1728 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1729 const char *buf, size_t count)
1731 struct Scsi_Host *shost = class_to_shost(dev);
1732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1733 struct lpfc_hba *phba = vport->phba;
1738 if (!isdigit(buf[0]))
1741 if (sscanf(buf, "%i", &val) != 1)
1744 if ((val & 0x3) != val)
1747 if (phba->sli_rev == LPFC_SLI_REV4)
1750 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1751 "3051 lpfc_poll changed from %d to %d\n",
1752 phba->cfg_poll, val);
1754 spin_lock_irq(&phba->hbalock);
1756 old_val = phba->cfg_poll;
1758 if (val & ENABLE_FCP_RING_POLLING) {
1759 if ((val & DISABLE_FCP_RING_INT) &&
1760 !(old_val & DISABLE_FCP_RING_INT)) {
1761 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1762 spin_unlock_irq(&phba->hbalock);
1765 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1766 writel(creg_val, phba->HCregaddr);
1767 readl(phba->HCregaddr); /* flush */
1769 lpfc_poll_start_timer(phba);
1771 } else if (val != 0x0) {
1772 spin_unlock_irq(&phba->hbalock);
1776 if (!(val & DISABLE_FCP_RING_INT) &&
1777 (old_val & DISABLE_FCP_RING_INT))
1779 spin_unlock_irq(&phba->hbalock);
1780 del_timer(&phba->fcp_poll_timer);
1781 spin_lock_irq(&phba->hbalock);
1782 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1783 spin_unlock_irq(&phba->hbalock);
1786 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1787 writel(creg_val, phba->HCregaddr);
1788 readl(phba->HCregaddr); /* flush */
1791 phba->cfg_poll = val;
1793 spin_unlock_irq(&phba->hbalock);
1799 * lpfc_fips_level_show - Return the current FIPS level 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_level_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_level);
1818 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1819 * @dev: class unused variable.
1820 * @attr: device attribute, not used.
1821 * @buf: on return contains the module description text.
1823 * Returns: size of formatted string.
1826 lpfc_fips_rev_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, "%d\n", phba->fips_spec_rev);
1837 * lpfc_dss_show - Return the current state of dss and the configured state
1838 * @dev: class converted to a Scsi_host structure.
1839 * @attr: device attribute, not used.
1840 * @buf: on return contains the formatted text.
1842 * Returns: size of formatted string.
1845 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1848 struct Scsi_Host *shost = class_to_shost(dev);
1849 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1850 struct lpfc_hba *phba = vport->phba;
1852 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1853 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1854 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1859 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1860 * @dev: class converted to a Scsi_host structure.
1861 * @attr: device attribute, not used.
1862 * @buf: on return contains the formatted support level.
1865 * Returns the maximum number of virtual functions a physical function can
1866 * support, 0 will be returned if called on virtual function.
1868 * Returns: size of formatted string.
1871 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1872 struct device_attribute *attr,
1875 struct Scsi_Host *shost = class_to_shost(dev);
1876 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1877 struct lpfc_hba *phba = vport->phba;
1878 uint16_t max_nr_virtfn;
1880 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1881 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1884 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1886 return val >= min && val <= max;
1890 * lpfc_param_show - Return a cfg attribute value in decimal
1893 * Macro that given an attr e.g. hba_queue_depth expands
1894 * into a function with the name lpfc_hba_queue_depth_show.
1896 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1897 * @dev: class device that is converted into a Scsi_host.
1898 * @attr: device attribute, not used.
1899 * @buf: on return contains the attribute value in decimal.
1901 * Returns: size of formatted string.
1903 #define lpfc_param_show(attr) \
1905 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1908 struct Scsi_Host *shost = class_to_shost(dev);\
1909 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1910 struct lpfc_hba *phba = vport->phba;\
1911 return snprintf(buf, PAGE_SIZE, "%d\n",\
1916 * lpfc_param_hex_show - Return a cfg attribute value in hex
1919 * Macro that given an attr e.g. hba_queue_depth expands
1920 * into a function with the name lpfc_hba_queue_depth_show
1922 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1923 * @dev: class device that is converted into a Scsi_host.
1924 * @attr: device attribute, not used.
1925 * @buf: on return contains the attribute value in hexadecimal.
1927 * Returns: size of formatted string.
1929 #define lpfc_param_hex_show(attr) \
1931 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1934 struct Scsi_Host *shost = class_to_shost(dev);\
1935 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1936 struct lpfc_hba *phba = vport->phba;\
1938 val = phba->cfg_##attr;\
1939 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1944 * lpfc_param_init - Initializes a cfg attribute
1947 * Macro that given an attr e.g. hba_queue_depth expands
1948 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1949 * takes a default argument, a minimum and maximum argument.
1951 * lpfc_##attr##_init: Initializes an attribute.
1952 * @phba: pointer the the adapter structure.
1953 * @val: integer attribute value.
1955 * Validates the min and max values then sets the adapter config field
1956 * accordingly, or uses the default if out of range and prints an error message.
1960 * -EINVAL if default used
1962 #define lpfc_param_init(attr, default, minval, maxval) \
1964 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1966 if (lpfc_rangecheck(val, minval, maxval)) {\
1967 phba->cfg_##attr = val;\
1970 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1971 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1972 "allowed range is ["#minval", "#maxval"]\n", val); \
1973 phba->cfg_##attr = default;\
1978 * lpfc_param_set - Set a cfg attribute value
1981 * Macro that given an attr e.g. hba_queue_depth expands
1982 * into a function with the name lpfc_hba_queue_depth_set
1984 * lpfc_##attr##_set: Sets an attribute value.
1985 * @phba: pointer the the adapter structure.
1986 * @val: integer attribute value.
1989 * Validates the min and max values then sets the
1990 * adapter config field if in the valid range. prints error message
1991 * and does not set the parameter if invalid.
1995 * -EINVAL if val is invalid
1997 #define lpfc_param_set(attr, default, minval, maxval) \
1999 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2001 if (lpfc_rangecheck(val, minval, maxval)) {\
2002 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2003 "3052 lpfc_" #attr " changed from %d to %d\n", \
2004 phba->cfg_##attr, val); \
2005 phba->cfg_##attr = val;\
2008 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2009 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2010 "allowed range is ["#minval", "#maxval"]\n", val); \
2015 * lpfc_param_store - Set a vport attribute value
2018 * Macro that given an attr e.g. hba_queue_depth expands
2019 * into a function with the name lpfc_hba_queue_depth_store.
2021 * lpfc_##attr##_store: Set an sttribute value.
2022 * @dev: class device that is converted into a Scsi_host.
2023 * @attr: device attribute, not used.
2024 * @buf: contains the attribute value in ascii.
2028 * Convert the ascii text number to an integer, then
2029 * use the lpfc_##attr##_set function to set the value.
2032 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2033 * length of buffer upon success.
2035 #define lpfc_param_store(attr) \
2037 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2038 const char *buf, size_t count) \
2040 struct Scsi_Host *shost = class_to_shost(dev);\
2041 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2042 struct lpfc_hba *phba = vport->phba;\
2044 if (!isdigit(buf[0]))\
2046 if (sscanf(buf, "%i", &val) != 1)\
2048 if (lpfc_##attr##_set(phba, val) == 0) \
2049 return strlen(buf);\
2055 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2058 * Macro that given an attr e.g. hba_queue_depth expands
2059 * into a function with the name lpfc_hba_queue_depth_show
2061 * lpfc_##attr##_show: prints the attribute value in decimal.
2062 * @dev: class device that is converted into a Scsi_host.
2063 * @attr: device attribute, not used.
2064 * @buf: on return contains the attribute value in decimal.
2066 * Returns: length of formatted string.
2068 #define lpfc_vport_param_show(attr) \
2070 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2073 struct Scsi_Host *shost = class_to_shost(dev);\
2074 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2075 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2079 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2082 * Macro that given an attr e.g.
2083 * hba_queue_depth expands into a function with the name
2084 * lpfc_hba_queue_depth_show
2086 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2087 * @dev: class device that is converted into a Scsi_host.
2088 * @attr: device attribute, not used.
2089 * @buf: on return contains the attribute value in hexadecimal.
2091 * Returns: length of formatted string.
2093 #define lpfc_vport_param_hex_show(attr) \
2095 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2098 struct Scsi_Host *shost = class_to_shost(dev);\
2099 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2100 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2104 * lpfc_vport_param_init - Initialize a vport cfg attribute
2107 * Macro that given an attr e.g. hba_queue_depth expands
2108 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2109 * takes a default argument, a minimum and maximum argument.
2111 * lpfc_##attr##_init: validates the min and max values then sets the
2112 * adapter config field accordingly, or uses the default if out of range
2113 * and prints an error message.
2114 * @phba: pointer the the adapter structure.
2115 * @val: integer attribute value.
2119 * -EINVAL if default used
2121 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2123 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2125 if (lpfc_rangecheck(val, minval, maxval)) {\
2126 vport->cfg_##attr = val;\
2129 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2130 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2131 "allowed range is ["#minval", "#maxval"]\n", val); \
2132 vport->cfg_##attr = default;\
2137 * lpfc_vport_param_set - Set a vport cfg attribute
2140 * Macro that given an attr e.g. hba_queue_depth expands
2141 * into a function with the name lpfc_hba_queue_depth_set
2143 * lpfc_##attr##_set: validates the min and max values then sets the
2144 * adapter config field if in the valid range. prints error message
2145 * and does not set the parameter if invalid.
2146 * @phba: pointer the the adapter structure.
2147 * @val: integer attribute value.
2151 * -EINVAL if val is invalid
2153 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2155 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2157 if (lpfc_rangecheck(val, minval, maxval)) {\
2158 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2159 "3053 lpfc_" #attr \
2160 " changed from %d (x%x) to %d (x%x)\n", \
2161 vport->cfg_##attr, vport->cfg_##attr, \
2163 vport->cfg_##attr = val;\
2166 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2167 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2168 "allowed range is ["#minval", "#maxval"]\n", val); \
2173 * lpfc_vport_param_store - Set a vport attribute
2176 * Macro that given an attr e.g. hba_queue_depth
2177 * expands into a function with the name lpfc_hba_queue_depth_store
2179 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2180 * use the lpfc_##attr##_set function to set the value.
2181 * @cdev: class device that is converted into a Scsi_host.
2182 * @buf: contains the attribute value in decimal.
2186 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2187 * length of buffer upon success.
2189 #define lpfc_vport_param_store(attr) \
2191 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2192 const char *buf, size_t count) \
2194 struct Scsi_Host *shost = class_to_shost(dev);\
2195 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2197 if (!isdigit(buf[0]))\
2199 if (sscanf(buf, "%i", &val) != 1)\
2201 if (lpfc_##attr##_set(vport, val) == 0) \
2202 return strlen(buf);\
2208 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2209 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2210 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2211 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2212 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2213 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2214 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2215 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2216 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2217 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2218 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2219 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2220 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2221 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2222 lpfc_link_state_store);
2223 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2224 lpfc_option_rom_version_show, NULL);
2225 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2226 lpfc_num_discovered_ports_show, NULL);
2227 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2228 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2229 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2230 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2231 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2232 lpfc_board_mode_show, lpfc_board_mode_store);
2233 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2234 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2235 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2236 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2237 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2238 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2239 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2240 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2241 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2242 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2243 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2244 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2245 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2246 lpfc_sriov_hw_max_virtfn_show, NULL);
2247 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2248 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2251 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2254 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2256 * @cnt: Length of string.
2257 * @wwn: Array to receive converted wwn value.
2260 * -EINVAL if the buffer does not contain a valid wwn
2264 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2268 /* Count may include a LF at end of string */
2269 if (buf[cnt-1] == '\n')
2272 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2273 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2276 memset(wwn, 0, WWN_SZ);
2278 /* Validate and store the new name */
2279 for (i = 0, j = 0; i < 16; i++) {
2280 if ((*buf >= 'a') && (*buf <= 'f'))
2281 j = ((j << 4) | ((*buf++ - 'a') + 10));
2282 else if ((*buf >= 'A') && (*buf <= 'F'))
2283 j = ((j << 4) | ((*buf++ - 'A') + 10));
2284 else if ((*buf >= '0') && (*buf <= '9'))
2285 j = ((j << 4) | (*buf++ - '0'));
2289 wwn[i/2] = j & 0xff;
2296 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2297 * @dev: class device that is converted into a Scsi_host.
2298 * @attr: device attribute, not used.
2299 * @buf: containing the string lpfc_soft_wwn_key.
2300 * @count: must be size of lpfc_soft_wwn_key.
2303 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2304 * length of buf indicates success
2307 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2308 const char *buf, size_t count)
2310 struct Scsi_Host *shost = class_to_shost(dev);
2311 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2312 struct lpfc_hba *phba = vport->phba;
2313 unsigned int cnt = count;
2314 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2315 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2318 * We're doing a simple sanity check for soft_wwpn setting.
2319 * We require that the user write a specific key to enable
2320 * the soft_wwpn attribute to be settable. Once the attribute
2321 * is written, the enable key resets. If further updates are
2322 * desired, the key must be written again to re-enable the
2325 * The "key" is not secret - it is a hardcoded string shown
2326 * here. The intent is to protect against the random user or
2327 * application that is just writing attributes.
2329 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2330 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2331 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2332 " be enabled: fawwpn is enabled\n");
2336 /* count may include a LF at end of string */
2337 if (buf[cnt-1] == '\n')
2340 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2341 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2344 phba->soft_wwn_enable = 1;
2346 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2347 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2349 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2350 " The soft_wwpn feature is not supported by Broadcom.");
2354 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2355 lpfc_soft_wwn_enable_store);
2358 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2359 * @dev: class device that is converted into a Scsi_host.
2360 * @attr: device attribute, not used.
2361 * @buf: on return contains the wwpn in hexadecimal.
2363 * Returns: size of formatted string.
2366 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2369 struct Scsi_Host *shost = class_to_shost(dev);
2370 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2371 struct lpfc_hba *phba = vport->phba;
2373 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2374 (unsigned long long)phba->cfg_soft_wwpn);
2378 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2379 * @dev class device that is converted into a Scsi_host.
2380 * @attr: device attribute, not used.
2381 * @buf: contains the wwpn in hexadecimal.
2382 * @count: number of wwpn bytes in buf
2385 * -EACCES hba reset not enabled, adapter over temp
2386 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2387 * -EIO error taking adapter offline or online
2388 * value of count on success
2391 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2392 const char *buf, size_t count)
2394 struct Scsi_Host *shost = class_to_shost(dev);
2395 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2396 struct lpfc_hba *phba = vport->phba;
2397 struct completion online_compl;
2398 int stat1 = 0, stat2 = 0;
2399 unsigned int cnt = count;
2403 if (!phba->cfg_enable_hba_reset)
2405 spin_lock_irq(&phba->hbalock);
2406 if (phba->over_temp_state == HBA_OVER_TEMP) {
2407 spin_unlock_irq(&phba->hbalock);
2410 spin_unlock_irq(&phba->hbalock);
2411 /* count may include a LF at end of string */
2412 if (buf[cnt-1] == '\n')
2415 if (!phba->soft_wwn_enable)
2418 /* lock setting wwpn, wwnn down */
2419 phba->soft_wwn_enable = 0;
2421 rc = lpfc_wwn_set(buf, cnt, wwpn);
2423 /* not able to set wwpn, unlock it */
2424 phba->soft_wwn_enable = 1;
2428 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2429 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2430 if (phba->cfg_soft_wwnn)
2431 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2433 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2434 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2436 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2438 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2439 "0463 lpfc_soft_wwpn attribute set failed to "
2440 "reinit adapter - %d\n", stat1);
2441 init_completion(&online_compl);
2442 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2447 wait_for_completion(&online_compl);
2449 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2450 "0464 lpfc_soft_wwpn attribute set failed to "
2451 "reinit adapter - %d\n", stat2);
2452 return (stat1 || stat2) ? -EIO : count;
2454 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2455 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2458 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2459 * @dev: class device that is converted into a Scsi_host.
2460 * @attr: device attribute, not used.
2461 * @buf: on return contains the wwnn in hexadecimal.
2463 * Returns: size of formatted string.
2466 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2469 struct Scsi_Host *shost = class_to_shost(dev);
2470 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2471 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2472 (unsigned long long)phba->cfg_soft_wwnn);
2476 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2477 * @cdev: class device that is converted into a Scsi_host.
2478 * @buf: contains the ww node name in hexadecimal.
2479 * @count: number of wwnn bytes in buf.
2482 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2483 * value of count on success
2486 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2487 const char *buf, size_t count)
2489 struct Scsi_Host *shost = class_to_shost(dev);
2490 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2491 unsigned int cnt = count;
2495 /* count may include a LF at end of string */
2496 if (buf[cnt-1] == '\n')
2499 if (!phba->soft_wwn_enable)
2502 rc = lpfc_wwn_set(buf, cnt, wwnn);
2504 /* Allow wwnn to be set many times, as long as the enable
2505 * is set. However, once the wwpn is set, everything locks.
2510 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2512 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2513 "lpfc%d: soft_wwnn set. Value will take effect upon "
2514 "setting of the soft_wwpn\n", phba->brd_no);
2518 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2519 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2522 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2523 * Optimized Access Storage (OAS) operations.
2524 * @dev: class device that is converted into a Scsi_host.
2525 * @attr: device attribute, not used.
2526 * @buf: buffer for passing information.
2532 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2535 struct Scsi_Host *shost = class_to_shost(dev);
2536 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2538 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2539 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2543 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2544 * Optimized Access Storage (OAS) operations.
2545 * @dev: class device that is converted into a Scsi_host.
2546 * @attr: device attribute, not used.
2547 * @buf: buffer for passing information.
2548 * @count: Size of the data buffer.
2551 * -EINVAL count is invalid, invalid wwpn byte invalid
2552 * -EPERM oas is not supported by hba
2553 * value of count on success
2556 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2557 const char *buf, size_t count)
2559 struct Scsi_Host *shost = class_to_shost(dev);
2560 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2561 unsigned int cnt = count;
2562 uint8_t wwpn[WWN_SZ];
2568 /* count may include a LF at end of string */
2569 if (buf[cnt-1] == '\n')
2572 rc = lpfc_wwn_set(buf, cnt, wwpn);
2576 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2577 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2578 if (wwn_to_u64(wwpn) == 0)
2579 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2581 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2582 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2583 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2586 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2587 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2590 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2591 * Optimized Access Storage (OAS) operations.
2592 * @dev: class device that is converted into a Scsi_host.
2593 * @attr: device attribute, not used.
2594 * @buf: buffer for passing information.
2600 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2603 struct Scsi_Host *shost = class_to_shost(dev);
2604 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2606 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2610 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2611 * Optimized Access Storage (OAS) operations.
2612 * @dev: class device that is converted into a Scsi_host.
2613 * @attr: device attribute, not used.
2614 * @buf: buffer for passing information.
2615 * @count: Size of the data buffer.
2618 * -EINVAL count is invalid, invalid wwpn byte invalid
2619 * -EPERM oas is not supported by hba
2620 * value of count on success
2623 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2624 const char *buf, size_t count)
2626 struct Scsi_Host *shost = class_to_shost(dev);
2627 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2628 unsigned int cnt = count;
2635 /* count may include a LF at end of string */
2636 if (buf[cnt-1] == '\n')
2639 ret = kstrtoul(buf, 0, &val);
2640 if (ret || (val > 0x7f))
2644 phba->cfg_oas_priority = (uint8_t)val;
2646 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2649 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2650 lpfc_oas_priority_show, lpfc_oas_priority_store);
2653 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2654 * for Optimized Access Storage (OAS) operations.
2655 * @dev: class device that is converted into a Scsi_host.
2656 * @attr: device attribute, not used.
2657 * @buf: buffer for passing information.
2660 * value of count on success
2663 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2666 struct Scsi_Host *shost = class_to_shost(dev);
2667 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2669 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2670 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2674 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2675 * for Optimized Access Storage (OAS) operations.
2676 * @dev: class device that is converted into a Scsi_host.
2677 * @attr: device attribute, not used.
2678 * @buf: buffer for passing information.
2679 * @count: Size of the data buffer.
2682 * -EINVAL count is invalid, invalid wwpn byte invalid
2683 * -EPERM oas is not supported by hba
2684 * value of count on success
2687 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2688 const char *buf, size_t count)
2690 struct Scsi_Host *shost = class_to_shost(dev);
2691 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2692 unsigned int cnt = count;
2693 uint8_t wwpn[WWN_SZ];
2699 /* count may include a LF at end of string */
2700 if (buf[cnt-1] == '\n')
2703 rc = lpfc_wwn_set(buf, cnt, wwpn);
2707 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2708 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2709 if (wwn_to_u64(wwpn) == 0)
2710 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2712 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2713 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2714 if (phba->cfg_oas_priority == 0)
2715 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2716 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2719 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2720 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2723 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2724 * of whether luns will be enabled or disabled
2725 * for Optimized Access Storage (OAS) operations.
2726 * @dev: class device that is converted into a Scsi_host.
2727 * @attr: device attribute, not used.
2728 * @buf: buffer for passing information.
2731 * size of formatted string.
2734 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2737 struct Scsi_Host *shost = class_to_shost(dev);
2738 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2740 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2744 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2745 * of whether luns will be enabled or disabled
2746 * for Optimized Access Storage (OAS) operations.
2747 * @dev: class device that is converted into a Scsi_host.
2748 * @attr: device attribute, not used.
2749 * @buf: buffer for passing information.
2750 * @count: Size of the data buffer.
2753 * -EINVAL count is invalid, invalid wwpn byte invalid
2754 * -EPERM oas is not supported by hba
2755 * value of count on success
2758 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2759 const char *buf, size_t count)
2761 struct Scsi_Host *shost = class_to_shost(dev);
2762 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2768 if (!isdigit(buf[0]))
2771 if (sscanf(buf, "%i", &val) != 1)
2774 if ((val != 0) && (val != 1))
2777 phba->cfg_oas_lun_state = val;
2780 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2781 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2784 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2785 * Storage (OAS) lun returned by the
2786 * lpfc_oas_lun_show function.
2787 * @dev: class device that is converted into a Scsi_host.
2788 * @attr: device attribute, not used.
2789 * @buf: buffer for passing information.
2792 * size of formatted string.
2795 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2798 struct Scsi_Host *shost = class_to_shost(dev);
2799 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2801 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2804 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2806 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2807 lpfc_oas_lun_status_show, NULL);
2811 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2813 * @phba: lpfc_hba pointer.
2814 * @ndlp: pointer to fcp target node.
2815 * @lun: the fc lun for setting oas state.
2816 * @oas_state: the oas state to be set to the lun.
2820 * -EPERM OAS is not enabled or not supported by this port.
2824 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2825 uint8_t tgt_wwpn[], uint64_t lun,
2826 uint32_t oas_state, uint8_t pri)
2835 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2836 (struct lpfc_name *)tgt_wwpn,
2840 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2841 (struct lpfc_name *)tgt_wwpn, lun, pri);
2848 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2849 * Access Storage (OAS) operations.
2850 * @phba: lpfc_hba pointer.
2851 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2852 * @tgt_wwpn: wwpn of the target associated with the returned lun
2853 * @lun_status: status of the lun returned lun
2855 * Returns the first or next lun enabled for OAS operations for the vport/target
2856 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2857 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2860 * lun that is OAS enabled for the vport/target
2861 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2864 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2865 uint8_t tgt_wwpn[], uint32_t *lun_status,
2870 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2871 return NOT_OAS_ENABLED_LUN;
2872 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2873 phba->sli4_hba.oas_next_vpt_wwpn,
2874 (struct lpfc_name *)
2875 phba->sli4_hba.oas_next_tgt_wwpn,
2876 &phba->sli4_hba.oas_next_lun,
2877 (struct lpfc_name *)vpt_wwpn,
2878 (struct lpfc_name *)tgt_wwpn,
2879 &found_lun, lun_status, lun_pri))
2882 return NOT_OAS_ENABLED_LUN;
2886 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2887 * @phba: lpfc_hba pointer.
2888 * @vpt_wwpn: vport wwpn by reference.
2889 * @tgt_wwpn: target wwpn by reference.
2890 * @lun: the fc lun for setting oas state.
2891 * @oas_state: the oas state to be set to the oas_lun.
2893 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2894 * a lun for OAS operations.
2898 * -ENOMEM: failed to enable an lun for OAS operations
2899 * -EPERM: OAS is not enabled
2902 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2903 uint8_t tgt_wwpn[], uint64_t lun,
2904 uint32_t oas_state, uint8_t pri)
2909 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2915 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2916 * @dev: class device that is converted into a Scsi_host.
2917 * @attr: device attribute, not used.
2918 * @buf: buffer for passing information.
2920 * This routine returns a lun enabled for OAS each time the function
2924 * SUCCESS: size of formatted string.
2925 * -EFAULT: target or vport wwpn was not set properly.
2926 * -EPERM: oas is not enabled.
2929 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2932 struct Scsi_Host *shost = class_to_shost(dev);
2933 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2941 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2942 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2945 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2946 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2949 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2950 phba->cfg_oas_tgt_wwpn,
2951 &phba->cfg_oas_lun_status,
2952 &phba->cfg_oas_priority);
2953 if (oas_lun != NOT_OAS_ENABLED_LUN)
2954 phba->cfg_oas_flags |= OAS_LUN_VALID;
2956 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2962 * lpfc_oas_lun_store - Sets the OAS state for lun
2963 * @dev: class device that is converted into a Scsi_host.
2964 * @attr: device attribute, not used.
2965 * @buf: buffer for passing information.
2967 * This function sets the OAS state for lun. Before this function is called,
2968 * the vport wwpn, target wwpn, and oas state need to be set.
2971 * SUCCESS: size of formatted string.
2972 * -EFAULT: target or vport wwpn was not set properly.
2973 * -EPERM: oas is not enabled.
2974 * size of formatted string.
2977 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2978 const char *buf, size_t count)
2980 struct Scsi_Host *shost = class_to_shost(dev);
2981 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2989 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2992 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2995 if (!isdigit(buf[0]))
2998 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3001 pri = phba->cfg_oas_priority;
3003 pri = phba->cfg_XLanePriority;
3005 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3006 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3007 "priority 0x%x with oas state %d\n",
3008 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3009 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3010 pri, phba->cfg_oas_lun_state);
3012 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3013 phba->cfg_oas_tgt_wwpn, scsi_lun,
3014 phba->cfg_oas_lun_state, pri);
3020 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3021 lpfc_oas_lun_show, lpfc_oas_lun_store);
3023 int lpfc_enable_nvmet_cnt;
3024 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3025 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3026 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3027 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3028 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3030 static int lpfc_poll = 0;
3031 module_param(lpfc_poll, int, S_IRUGO);
3032 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3034 " 1 - poll with interrupts enabled"
3035 " 3 - poll and disable FCP ring interrupts");
3037 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3038 lpfc_poll_show, lpfc_poll_store);
3040 int lpfc_no_hba_reset_cnt;
3041 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3042 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3043 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3044 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3046 LPFC_ATTR(sli_mode, 0, 0, 3,
3047 "SLI mode selector:"
3048 " 0 - auto (SLI-3 if supported),"
3049 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3050 " 3 - select SLI-3");
3052 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3053 "Enable NPIV functionality");
3055 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3056 "FCF Fast failover=1 Priority failover=2");
3059 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3060 # 0x0 = disabled, XRI/OXID use not tracked.
3061 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3062 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3064 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3065 "Enable RRQ functionality");
3068 # lpfc_suppress_link_up: Bring link up at initialization
3069 # 0x0 = bring link up (issue MBX_INIT_LINK)
3070 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3071 # 0x2 = never bring up link
3072 # Default value is 0.
3074 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3075 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3076 "Suppress Link Up at initialization");
3078 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3086 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3088 struct Scsi_Host *shost = class_to_shost(dev);
3089 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3091 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3094 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3095 lpfc_iocb_hw_show, NULL);
3097 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3099 struct Scsi_Host *shost = class_to_shost(dev);
3100 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3101 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3103 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
3106 static DEVICE_ATTR(txq_hw, S_IRUGO,
3107 lpfc_txq_hw_show, NULL);
3109 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3112 struct Scsi_Host *shost = class_to_shost(dev);
3113 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3114 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3116 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
3119 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3120 lpfc_txcmplq_hw_show, NULL);
3122 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3123 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3126 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3127 # until the timer expires. Value range is [0,255]. Default value is 30.
3129 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3130 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3131 module_param(lpfc_nodev_tmo, int, 0);
3132 MODULE_PARM_DESC(lpfc_nodev_tmo,
3133 "Seconds driver will hold I/O waiting "
3134 "for a device to come back");
3137 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3138 * @dev: class converted to a Scsi_host structure.
3139 * @attr: device attribute, not used.
3140 * @buf: on return contains the dev loss timeout in decimal.
3142 * Returns: size of formatted string.
3145 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3148 struct Scsi_Host *shost = class_to_shost(dev);
3149 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3151 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3155 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3156 * @vport: lpfc vport structure pointer.
3157 * @val: contains the nodev timeout value.
3160 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3161 * a kernel error message is printed and zero is returned.
3162 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3163 * Otherwise nodev tmo is set to the default value.
3166 * zero if already set or if val is in range
3167 * -EINVAL val out of range
3170 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3172 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3173 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3174 if (val != LPFC_DEF_DEVLOSS_TMO)
3175 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3176 "0407 Ignoring lpfc_nodev_tmo module "
3177 "parameter because lpfc_devloss_tmo "
3182 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3183 vport->cfg_nodev_tmo = val;
3184 vport->cfg_devloss_tmo = val;
3187 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3188 "0400 lpfc_nodev_tmo attribute cannot be set to"
3189 " %d, allowed range is [%d, %d]\n",
3190 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3191 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3196 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3197 * @vport: lpfc vport structure pointer.
3200 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3203 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3205 struct Scsi_Host *shost;
3206 struct lpfc_nodelist *ndlp;
3208 shost = lpfc_shost_from_vport(vport);
3209 spin_lock_irq(shost->host_lock);
3210 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3211 if (!NLP_CHK_NODE_ACT(ndlp))
3214 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3216 spin_unlock_irq(shost->host_lock);
3220 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3221 * @vport: lpfc vport structure pointer.
3222 * @val: contains the tmo value.
3225 * If the devloss tmo is already set or the vport dev loss tmo has changed
3226 * then a kernel error message is printed and zero is returned.
3227 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3228 * Otherwise nodev tmo is set to the default value.
3231 * zero if already set or if val is in range
3232 * -EINVAL val out of range
3235 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3237 if (vport->dev_loss_tmo_changed ||
3238 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3239 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3240 "0401 Ignoring change to lpfc_nodev_tmo "
3241 "because lpfc_devloss_tmo is set.\n");
3244 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3245 vport->cfg_nodev_tmo = val;
3246 vport->cfg_devloss_tmo = val;
3248 * For compat: set the fc_host dev loss so new rports
3249 * will get the value.
3251 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3252 lpfc_update_rport_devloss_tmo(vport);
3255 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3256 "0403 lpfc_nodev_tmo attribute cannot be set to "
3257 "%d, allowed range is [%d, %d]\n",
3258 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3262 lpfc_vport_param_store(nodev_tmo)
3264 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3265 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3268 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3269 # disappear until the timer expires. Value range is [0,255]. Default
3272 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3273 MODULE_PARM_DESC(lpfc_devloss_tmo,
3274 "Seconds driver will hold I/O waiting "
3275 "for a device to come back");
3276 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3277 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3278 lpfc_vport_param_show(devloss_tmo)
3281 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3282 * @vport: lpfc vport structure pointer.
3283 * @val: contains the tmo value.
3286 * If val is in a valid range then set the vport nodev tmo,
3287 * devloss tmo, also set the vport dev loss tmo changed flag.
3288 * Else a kernel error message is printed.
3291 * zero if val is in range
3292 * -EINVAL val out of range
3295 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3297 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3298 vport->cfg_nodev_tmo = val;
3299 vport->cfg_devloss_tmo = val;
3300 vport->dev_loss_tmo_changed = 1;
3301 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3302 lpfc_update_rport_devloss_tmo(vport);
3306 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3307 "0404 lpfc_devloss_tmo attribute cannot be set to "
3308 "%d, allowed range is [%d, %d]\n",
3309 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3313 lpfc_vport_param_store(devloss_tmo)
3314 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3315 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3318 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3319 * lpfc_suppress_rsp = 0 Disable
3320 * lpfc_suppress_rsp = 1 Enable (default)
3323 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3324 "Enable suppress rsp feature is firmware supports it");
3327 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3328 * lpfc_nvmet_mrq = 1 use a single RQ pair
3329 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3332 LPFC_ATTR_R(nvmet_mrq,
3334 "Specify number of RQ pairs for processing NVMET cmds");
3337 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3338 * Supported Values: 1 - register just FCP
3339 * 3 - register both FCP and NVME
3340 * Supported values are [1,3]. Default value is 1
3342 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3343 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3344 "Define fc4 type to register with fabric.");
3347 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3348 * This parameter is only used if:
3349 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3350 * port is not configured for NVMET.
3352 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3353 * The remaining XRIs get split up based on lpfc_xri_split per port:
3355 * Supported Values are in percentages
3356 * the xri_split value is the percentage the SCSI port will get. The remaining
3357 * percentage will go to NVME.
3359 LPFC_ATTR_R(xri_split, 50, 10, 90,
3360 "Division of XRI resources between SCSI and NVME");
3363 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3364 # deluged with LOTS of information.
3365 # You can set a bit mask to record specific types of verbose messages:
3366 # See lpfc_logmsh.h for definitions.
3368 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3369 "Verbose logging bit-mask");
3372 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3373 # objects that have been registered with the nameserver after login.
3375 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3376 "Deregister nameserver objects before LOGO");
3379 # lun_queue_depth: This parameter is used to limit the number of outstanding
3380 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3381 # If this parameter value is greater than 1/8th the maximum number of exchanges
3382 # supported by the HBA port, then the lun queue depth will be reduced to
3383 # 1/8th the maximum number of exchanges.
3385 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3386 "Max number of FCP commands we can queue to a specific LUN");
3389 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3390 # commands per target port. Value range is [10,65535]. Default value is 65535.
3392 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3393 "Max number of FCP commands we can queue to a specific target port");
3396 # hba_queue_depth: This parameter is used to limit the number of outstanding
3397 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3398 # value is greater than the maximum number of exchanges supported by the HBA,
3399 # then maximum number of exchanges supported by the HBA is used to determine
3400 # the hba_queue_depth.
3402 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3403 "Max number of FCP commands we can queue to a lpfc HBA");
3406 # peer_port_login: This parameter allows/prevents logins
3407 # between peer ports hosted on the same physical port.
3408 # When this parameter is set 0 peer ports of same physical port
3409 # are not allowed to login to each other.
3410 # When this parameter is set 1 peer ports of same physical port
3411 # are allowed to login to each other.
3412 # Default value of this parameter is 0.
3414 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3415 "Allow peer ports on the same physical port to login to each "
3419 # restrict_login: This parameter allows/prevents logins
3420 # between Virtual Ports and remote initiators.
3421 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3422 # other initiators and will attempt to PLOGI all remote ports.
3423 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3424 # remote ports and will not attempt to PLOGI to other initiators.
3425 # This parameter does not restrict to the physical port.
3426 # This parameter does not restrict logins to Fabric resident remote ports.
3427 # Default value of this parameter is 1.
3429 static int lpfc_restrict_login = 1;
3430 module_param(lpfc_restrict_login, int, S_IRUGO);
3431 MODULE_PARM_DESC(lpfc_restrict_login,
3432 "Restrict virtual ports login to remote initiators.");
3433 lpfc_vport_param_show(restrict_login);
3436 * lpfc_restrict_login_init - Set the vport restrict login flag
3437 * @vport: lpfc vport structure pointer.
3438 * @val: contains the restrict login value.
3441 * If val is not in a valid range then log a kernel error message and set
3442 * the vport restrict login to one.
3443 * If the port type is physical clear the restrict login flag and return.
3444 * Else set the restrict login flag to val.
3447 * zero if val is in range
3448 * -EINVAL val out of range
3451 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3453 if (val < 0 || val > 1) {
3454 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3455 "0422 lpfc_restrict_login attribute cannot "
3456 "be set to %d, allowed range is [0, 1]\n",
3458 vport->cfg_restrict_login = 1;
3461 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3462 vport->cfg_restrict_login = 0;
3465 vport->cfg_restrict_login = val;
3470 * lpfc_restrict_login_set - Set the vport restrict login flag
3471 * @vport: lpfc vport structure pointer.
3472 * @val: contains the restrict login value.
3475 * If val is not in a valid range then log a kernel error message and set
3476 * the vport restrict login to one.
3477 * If the port type is physical and the val is not zero log a kernel
3478 * error message, clear the restrict login flag and return zero.
3479 * Else set the restrict login flag to val.
3482 * zero if val is in range
3483 * -EINVAL val out of range
3486 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3488 if (val < 0 || val > 1) {
3489 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3490 "0425 lpfc_restrict_login attribute cannot "
3491 "be set to %d, allowed range is [0, 1]\n",
3493 vport->cfg_restrict_login = 1;
3496 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3497 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3498 "0468 lpfc_restrict_login must be 0 for "
3499 "Physical ports.\n");
3500 vport->cfg_restrict_login = 0;
3503 vport->cfg_restrict_login = val;
3506 lpfc_vport_param_store(restrict_login);
3507 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3508 lpfc_restrict_login_show, lpfc_restrict_login_store);
3511 # Some disk devices have a "select ID" or "select Target" capability.
3512 # From a protocol standpoint "select ID" usually means select the
3513 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3514 # annex" which contains a table that maps a "select ID" (a number
3515 # between 0 and 7F) to an ALPA. By default, for compatibility with
3516 # older drivers, the lpfc driver scans this table from low ALPA to high
3519 # Turning on the scan-down variable (on = 1, off = 0) will
3520 # cause the lpfc driver to use an inverted table, effectively
3521 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3523 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3524 # and will not work across a fabric. Also this parameter will take
3525 # effect only in the case when ALPA map is not available.)
3527 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3528 "Start scanning for devices from highest ALPA to lowest");
3531 # lpfc_topology: link topology for init link
3532 # 0x0 = attempt loop mode then point-to-point
3533 # 0x01 = internal loopback mode
3534 # 0x02 = attempt point-to-point mode only
3535 # 0x04 = attempt loop mode only
3536 # 0x06 = attempt point-to-point mode then loop
3537 # Set point-to-point mode if you want to run as an N_Port.
3538 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3539 # Default value is 0.
3541 LPFC_ATTR(topology, 0, 0, 6,
3542 "Select Fibre Channel topology");
3545 * lpfc_topology_set - Set the adapters topology field
3546 * @phba: lpfc_hba pointer.
3547 * @val: topology value.
3550 * If val is in a valid range then set the adapter's topology field and
3551 * issue a lip; if the lip fails reset the topology to the old value.
3553 * If the value is not in range log a kernel error message and return an error.
3556 * zero if val is in range and lip okay
3557 * non-zero return value from lpfc_issue_lip()
3558 * -EINVAL val out of range
3561 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3562 const char *buf, size_t count)
3564 struct Scsi_Host *shost = class_to_shost(dev);
3565 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3566 struct lpfc_hba *phba = vport->phba;
3569 const char *val_buf = buf;
3573 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3575 val_buf = &buf[strlen("nolip ")];
3578 if (!isdigit(val_buf[0]))
3580 if (sscanf(val_buf, "%i", &val) != 1)
3583 if (val >= 0 && val <= 6) {
3584 prev_val = phba->cfg_topology;
3585 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3587 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3588 "3113 Loop mode not supported at speed %d\n",
3592 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3594 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3595 "3114 Loop mode not supported\n");
3598 phba->cfg_topology = val;
3602 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3603 "3054 lpfc_topology changed from %d to %d\n",
3605 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3606 phba->fc_topology_changed = 1;
3607 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3609 phba->cfg_topology = prev_val;
3614 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3615 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3616 "allowed range is [0, 6]\n",
3621 lpfc_param_show(topology)
3622 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3623 lpfc_topology_show, lpfc_topology_store);
3626 * lpfc_static_vport_show: Read callback function for
3627 * lpfc_static_vport sysfs file.
3628 * @dev: Pointer to class device object.
3629 * @attr: device attribute structure.
3630 * @buf: Data buffer.
3632 * This function is the read call back function for
3633 * lpfc_static_vport sysfs file. The lpfc_static_vport
3634 * sysfs file report the mageability of the vport.
3637 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3640 struct Scsi_Host *shost = class_to_shost(dev);
3641 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3642 if (vport->vport_flag & STATIC_VPORT)
3643 sprintf(buf, "1\n");
3645 sprintf(buf, "0\n");
3651 * Sysfs attribute to control the statistical data collection.
3653 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3654 lpfc_static_vport_show, NULL);
3657 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3658 * @dev: Pointer to class device.
3659 * @buf: Data buffer.
3660 * @count: Size of the data buffer.
3662 * This function get called when a user write to the lpfc_stat_data_ctrl
3663 * sysfs file. This function parse the command written to the sysfs file
3664 * and take appropriate action. These commands are used for controlling
3665 * driver statistical data collection.
3666 * Following are the command this function handles.
3668 * setbucket <bucket_type> <base> <step>
3669 * = Set the latency buckets.
3670 * destroybucket = destroy all the buckets.
3671 * start = start data collection
3672 * stop = stop data collection
3673 * reset = reset the collected data
3676 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3677 const char *buf, size_t count)
3679 struct Scsi_Host *shost = class_to_shost(dev);
3680 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3681 struct lpfc_hba *phba = vport->phba;
3682 #define LPFC_MAX_DATA_CTRL_LEN 1024
3683 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3685 char *str_ptr, *token;
3686 struct lpfc_vport **vports;
3687 struct Scsi_Host *v_shost;
3688 char *bucket_type_str, *base_str, *step_str;
3689 unsigned long base, step, bucket_type;
3691 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3692 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3695 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3696 str_ptr = &bucket_data[0];
3697 /* Ignore this token - this is command token */
3698 token = strsep(&str_ptr, "\t ");
3702 bucket_type_str = strsep(&str_ptr, "\t ");
3703 if (!bucket_type_str)
3706 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3707 bucket_type = LPFC_LINEAR_BUCKET;
3708 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3709 bucket_type = LPFC_POWER2_BUCKET;
3713 base_str = strsep(&str_ptr, "\t ");
3716 base = simple_strtoul(base_str, NULL, 0);
3718 step_str = strsep(&str_ptr, "\t ");
3721 step = simple_strtoul(step_str, NULL, 0);
3725 /* Block the data collection for every vport */
3726 vports = lpfc_create_vport_work_array(phba);
3730 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3731 v_shost = lpfc_shost_from_vport(vports[i]);
3732 spin_lock_irq(v_shost->host_lock);
3733 /* Block and reset data collection */
3734 vports[i]->stat_data_blocked = 1;
3735 if (vports[i]->stat_data_enabled)
3736 lpfc_vport_reset_stat_data(vports[i]);
3737 spin_unlock_irq(v_shost->host_lock);
3740 /* Set the bucket attributes */
3741 phba->bucket_type = bucket_type;
3742 phba->bucket_base = base;
3743 phba->bucket_step = step;
3745 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3746 v_shost = lpfc_shost_from_vport(vports[i]);
3748 /* Unblock data collection */
3749 spin_lock_irq(v_shost->host_lock);
3750 vports[i]->stat_data_blocked = 0;
3751 spin_unlock_irq(v_shost->host_lock);
3753 lpfc_destroy_vport_work_array(phba, vports);
3757 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3758 vports = lpfc_create_vport_work_array(phba);
3762 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3763 v_shost = lpfc_shost_from_vport(vports[i]);
3764 spin_lock_irq(shost->host_lock);
3765 vports[i]->stat_data_blocked = 1;
3766 lpfc_free_bucket(vport);
3767 vport->stat_data_enabled = 0;
3768 vports[i]->stat_data_blocked = 0;
3769 spin_unlock_irq(shost->host_lock);
3771 lpfc_destroy_vport_work_array(phba, vports);
3772 phba->bucket_type = LPFC_NO_BUCKET;
3773 phba->bucket_base = 0;
3774 phba->bucket_step = 0;
3778 if (!strncmp(buf, "start", strlen("start"))) {
3779 /* If no buckets configured return error */
3780 if (phba->bucket_type == LPFC_NO_BUCKET)
3782 spin_lock_irq(shost->host_lock);
3783 if (vport->stat_data_enabled) {
3784 spin_unlock_irq(shost->host_lock);
3787 lpfc_alloc_bucket(vport);
3788 vport->stat_data_enabled = 1;
3789 spin_unlock_irq(shost->host_lock);
3793 if (!strncmp(buf, "stop", strlen("stop"))) {
3794 spin_lock_irq(shost->host_lock);
3795 if (vport->stat_data_enabled == 0) {
3796 spin_unlock_irq(shost->host_lock);
3799 lpfc_free_bucket(vport);
3800 vport->stat_data_enabled = 0;
3801 spin_unlock_irq(shost->host_lock);
3805 if (!strncmp(buf, "reset", strlen("reset"))) {
3806 if ((phba->bucket_type == LPFC_NO_BUCKET)
3807 || !vport->stat_data_enabled)
3809 spin_lock_irq(shost->host_lock);
3810 vport->stat_data_blocked = 1;
3811 lpfc_vport_reset_stat_data(vport);
3812 vport->stat_data_blocked = 0;
3813 spin_unlock_irq(shost->host_lock);
3821 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3822 * @dev: Pointer to class device object.
3823 * @buf: Data buffer.
3825 * This function is the read call back function for
3826 * lpfc_stat_data_ctrl sysfs file. This function report the
3827 * current statistical data collection state.
3830 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3833 struct Scsi_Host *shost = class_to_shost(dev);
3834 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3835 struct lpfc_hba *phba = vport->phba;
3839 unsigned long bucket_value;
3841 switch (phba->bucket_type) {
3842 case LPFC_LINEAR_BUCKET:
3843 bucket_type = "linear";
3845 case LPFC_POWER2_BUCKET:
3846 bucket_type = "power2";
3849 bucket_type = "No Bucket";
3853 sprintf(&buf[index], "Statistical Data enabled :%d, "
3854 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3855 " Bucket step :%d\nLatency Ranges :",
3856 vport->stat_data_enabled, vport->stat_data_blocked,
3857 bucket_type, phba->bucket_base, phba->bucket_step);
3858 index = strlen(buf);
3859 if (phba->bucket_type != LPFC_NO_BUCKET) {
3860 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3861 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3862 bucket_value = phba->bucket_base +
3863 phba->bucket_step * i;
3865 bucket_value = phba->bucket_base +
3866 (1 << i) * phba->bucket_step;
3868 if (index + 10 > PAGE_SIZE)
3870 sprintf(&buf[index], "%08ld ", bucket_value);
3871 index = strlen(buf);
3874 sprintf(&buf[index], "\n");
3879 * Sysfs attribute to control the statistical data collection.
3881 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3882 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3885 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3889 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3892 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3893 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3894 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3898 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3900 * @kobj: Pointer to the kernel object
3901 * @bin_attr: Attribute object
3902 * @buff: Buffer pointer
3904 * @count: Buffer size
3906 * This function is the read call back function for lpfc_drvr_stat_data
3907 * sysfs file. This function export the statistical data to user
3911 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3912 struct bin_attribute *bin_attr,
3913 char *buf, loff_t off, size_t count)
3915 struct device *dev = container_of(kobj, struct device,
3917 struct Scsi_Host *shost = class_to_shost(dev);
3918 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3919 struct lpfc_hba *phba = vport->phba;
3920 int i = 0, index = 0;
3921 unsigned long nport_index;
3922 struct lpfc_nodelist *ndlp = NULL;
3923 nport_index = (unsigned long)off /
3924 MAX_STAT_DATA_SIZE_PER_TARGET;
3926 if (!vport->stat_data_enabled || vport->stat_data_blocked
3927 || (phba->bucket_type == LPFC_NO_BUCKET))
3930 spin_lock_irq(shost->host_lock);
3931 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3932 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3935 if (nport_index > 0) {
3940 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3944 if (!ndlp->lat_data)
3948 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3949 ndlp->nlp_portname.u.wwn[0],
3950 ndlp->nlp_portname.u.wwn[1],
3951 ndlp->nlp_portname.u.wwn[2],
3952 ndlp->nlp_portname.u.wwn[3],
3953 ndlp->nlp_portname.u.wwn[4],
3954 ndlp->nlp_portname.u.wwn[5],
3955 ndlp->nlp_portname.u.wwn[6],
3956 ndlp->nlp_portname.u.wwn[7]);
3958 index = strlen(buf);
3960 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3961 sprintf(&buf[index], "%010u,",
3962 ndlp->lat_data[i].cmd_count);
3963 index = strlen(buf);
3965 sprintf(&buf[index], "\n");
3966 index = strlen(buf);
3968 spin_unlock_irq(shost->host_lock);
3972 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3974 .name = "lpfc_drvr_stat_data",
3977 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3978 .read = sysfs_drvr_stat_data_read,
3983 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3985 # Value range is [0,16]. Default value is 0.
3988 * lpfc_link_speed_set - Set the adapters link speed
3989 * @phba: lpfc_hba pointer.
3990 * @val: link speed value.
3993 * If val is in a valid range then set the adapter's link speed field and
3994 * issue a lip; if the lip fails reset the link speed to the old value.
3997 * If the value is not in range log a kernel error message and return an error.
4000 * zero if val is in range and lip okay.
4001 * non-zero return value from lpfc_issue_lip()
4002 * -EINVAL val out of range
4005 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4006 const char *buf, size_t count)
4008 struct Scsi_Host *shost = class_to_shost(dev);
4009 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4010 struct lpfc_hba *phba = vport->phba;
4011 int val = LPFC_USER_LINK_SPEED_AUTO;
4013 const char *val_buf = buf;
4015 uint32_t prev_val, if_type;
4017 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4018 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4019 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4022 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4024 val_buf = &buf[strlen("nolip ")];
4027 if (!isdigit(val_buf[0]))
4029 if (sscanf(val_buf, "%i", &val) != 1)
4032 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4033 "3055 lpfc_link_speed changed from %d to %d %s\n",
4034 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4036 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4037 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4038 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4039 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4040 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4041 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4042 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
4043 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4044 "2879 lpfc_link_speed attribute cannot be set "
4045 "to %d. Speed is not supported by this port.\n",
4049 if (val == LPFC_USER_LINK_SPEED_16G &&
4050 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4051 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4052 "3112 lpfc_link_speed attribute cannot be set "
4053 "to %d. Speed is not supported in loop mode.\n",
4057 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4058 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4059 prev_val = phba->cfg_link_speed;
4060 phba->cfg_link_speed = val;
4064 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4066 phba->cfg_link_speed = prev_val;
4071 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4072 "0469 lpfc_link_speed attribute cannot be set to %d, "
4073 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
4077 static int lpfc_link_speed = 0;
4078 module_param(lpfc_link_speed, int, S_IRUGO);
4079 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4080 lpfc_param_show(link_speed)
4083 * lpfc_link_speed_init - Set the adapters link speed
4084 * @phba: lpfc_hba pointer.
4085 * @val: link speed value.
4088 * If val is in a valid range then set the adapter's link speed field.
4091 * If the value is not in range log a kernel error message, clear the link
4092 * speed and return an error.
4095 * zero if val saved.
4096 * -EINVAL val out of range
4099 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4101 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4102 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4103 "3111 lpfc_link_speed of %d cannot "
4104 "support loop mode, setting topology to default.\n",
4106 phba->cfg_topology = 0;
4108 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4109 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4110 phba->cfg_link_speed = val;
4113 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4114 "0405 lpfc_link_speed attribute cannot "
4115 "be set to %d, allowed values are "
4116 "["LPFC_LINK_SPEED_STRING"]\n", val);
4117 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4121 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
4122 lpfc_link_speed_show, lpfc_link_speed_store);
4125 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4126 # 0 = aer disabled or not supported
4127 # 1 = aer supported and enabled (default)
4128 # Value range is [0,1]. Default value is 1.
4130 LPFC_ATTR(aer_support, 1, 0, 1,
4131 "Enable PCIe device AER support");
4132 lpfc_param_show(aer_support)
4135 * lpfc_aer_support_store - Set the adapter for aer support
4137 * @dev: class device that is converted into a Scsi_host.
4138 * @attr: device attribute, not used.
4139 * @buf: containing enable or disable aer flag.
4140 * @count: unused variable.
4143 * If the val is 1 and currently the device's AER capability was not
4144 * enabled, invoke the kernel's enable AER helper routine, trying to
4145 * enable the device's AER capability. If the helper routine enabling
4146 * AER returns success, update the device's cfg_aer_support flag to
4147 * indicate AER is supported by the device; otherwise, if the device
4148 * AER capability is already enabled to support AER, then do nothing.
4150 * If the val is 0 and currently the device's AER support was enabled,
4151 * invoke the kernel's disable AER helper routine. After that, update
4152 * the device's cfg_aer_support flag to indicate AER is not supported
4153 * by the device; otherwise, if the device AER capability is already
4154 * disabled from supporting AER, then do nothing.
4157 * length of the buf on success if val is in range the intended mode
4159 * -EINVAL if val out of range or intended mode is not supported.
4162 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4163 const char *buf, size_t count)
4165 struct Scsi_Host *shost = class_to_shost(dev);
4166 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4167 struct lpfc_hba *phba = vport->phba;
4168 int val = 0, rc = -EINVAL;
4170 if (!isdigit(buf[0]))
4172 if (sscanf(buf, "%i", &val) != 1)
4177 if (phba->hba_flag & HBA_AER_ENABLED) {
4178 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4180 spin_lock_irq(&phba->hbalock);
4181 phba->hba_flag &= ~HBA_AER_ENABLED;
4182 spin_unlock_irq(&phba->hbalock);
4183 phba->cfg_aer_support = 0;
4188 phba->cfg_aer_support = 0;
4193 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4194 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4196 spin_lock_irq(&phba->hbalock);
4197 phba->hba_flag |= HBA_AER_ENABLED;
4198 spin_unlock_irq(&phba->hbalock);
4199 phba->cfg_aer_support = 1;
4204 phba->cfg_aer_support = 1;
4215 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4216 lpfc_aer_support_show, lpfc_aer_support_store);
4219 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4220 * @dev: class device that is converted into a Scsi_host.
4221 * @attr: device attribute, not used.
4222 * @buf: containing flag 1 for aer cleanup state.
4223 * @count: unused variable.
4226 * If the @buf contains 1 and the device currently has the AER support
4227 * enabled, then invokes the kernel AER helper routine
4228 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4229 * error status register.
4234 * -EINVAL if the buf does not contain the 1 or the device is not currently
4235 * enabled with the AER support.
4238 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4239 const char *buf, size_t count)
4241 struct Scsi_Host *shost = class_to_shost(dev);
4242 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4243 struct lpfc_hba *phba = vport->phba;
4246 if (!isdigit(buf[0]))
4248 if (sscanf(buf, "%i", &val) != 1)
4253 if (phba->hba_flag & HBA_AER_ENABLED)
4254 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4262 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4263 lpfc_aer_cleanup_state);
4266 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4268 * @dev: class device that is converted into a Scsi_host.
4269 * @attr: device attribute, not used.
4270 * @buf: containing the string the number of vfs to be enabled.
4271 * @count: unused variable.
4274 * When this api is called either through user sysfs, the driver shall
4275 * try to enable or disable SR-IOV virtual functions according to the
4278 * If zero virtual function has been enabled to the physical function,
4279 * the driver shall invoke the pci enable virtual function api trying
4280 * to enable the virtual functions. If the nr_vfn provided is greater
4281 * than the maximum supported, the maximum virtual function number will
4282 * be used for invoking the api; otherwise, the nr_vfn provided shall
4283 * be used for invoking the api. If the api call returned success, the
4284 * actual number of virtual functions enabled will be set to the driver
4285 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4286 * cfg_sriov_nr_virtfn remains zero.
4288 * If none-zero virtual functions have already been enabled to the
4289 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4290 * -EINVAL will be returned and the driver does nothing;
4292 * If the nr_vfn provided is zero and none-zero virtual functions have
4293 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4294 * disabling virtual function api shall be invoded to disable all the
4295 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4296 * zero. Otherwise, if zero virtual function has been enabled, do
4300 * length of the buf on success if val is in range the intended mode
4302 * -EINVAL if val out of range or intended mode is not supported.
4305 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4306 const char *buf, size_t count)
4308 struct Scsi_Host *shost = class_to_shost(dev);
4309 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4310 struct lpfc_hba *phba = vport->phba;
4311 struct pci_dev *pdev = phba->pcidev;
4312 int val = 0, rc = -EINVAL;
4314 /* Sanity check on user data */
4315 if (!isdigit(buf[0]))
4317 if (sscanf(buf, "%i", &val) != 1)
4322 /* Request disabling virtual functions */
4324 if (phba->cfg_sriov_nr_virtfn > 0) {
4325 pci_disable_sriov(pdev);
4326 phba->cfg_sriov_nr_virtfn = 0;
4331 /* Request enabling virtual functions */
4332 if (phba->cfg_sriov_nr_virtfn > 0) {
4333 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4334 "3018 There are %d virtual functions "
4335 "enabled on physical function.\n",
4336 phba->cfg_sriov_nr_virtfn);
4340 if (val <= LPFC_MAX_VFN_PER_PFN)
4341 phba->cfg_sriov_nr_virtfn = val;
4343 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4344 "3019 Enabling %d virtual functions is not "
4349 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4351 phba->cfg_sriov_nr_virtfn = 0;
4359 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4360 "Enable PCIe device SR-IOV virtual fn");
4362 lpfc_param_show(sriov_nr_virtfn)
4363 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4364 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4367 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4369 * @dev: class device that is converted into a Scsi_host.
4370 * @attr: device attribute, not used.
4371 * @buf: containing the string the number of vfs to be enabled.
4372 * @count: unused variable.
4377 * length of the buf on success if val is in range the intended mode
4379 * -EINVAL if val out of range or intended mode is not supported.
4382 lpfc_request_firmware_upgrade_store(struct device *dev,
4383 struct device_attribute *attr,
4384 const char *buf, size_t count)
4386 struct Scsi_Host *shost = class_to_shost(dev);
4387 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4388 struct lpfc_hba *phba = vport->phba;
4389 int val = 0, rc = -EINVAL;
4391 /* Sanity check on user data */
4392 if (!isdigit(buf[0]))
4394 if (sscanf(buf, "%i", &val) != 1)
4399 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4407 static int lpfc_req_fw_upgrade;
4408 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4409 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4410 lpfc_param_show(request_firmware_upgrade)
4413 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4414 * @phba: lpfc_hba pointer.
4418 * Set the initial Linux generic firmware upgrade enable or disable flag.
4421 * zero if val saved.
4422 * -EINVAL val out of range
4425 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4427 if (val >= 0 && val <= 1) {
4428 phba->cfg_request_firmware_upgrade = val;
4433 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4434 lpfc_request_firmware_upgrade_show,
4435 lpfc_request_firmware_upgrade_store);
4438 * lpfc_fcp_imax_store
4440 * @dev: class device that is converted into a Scsi_host.
4441 * @attr: device attribute, not used.
4442 * @buf: string with the number of fast-path FCP interrupts per second.
4443 * @count: unused variable.
4446 * If val is in a valid range [636,651042], then set the adapter's
4447 * maximum number of fast-path FCP interrupts per second.
4450 * length of the buf on success if val is in range the intended mode
4452 * -EINVAL if val out of range or intended mode is not supported.
4455 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4456 const char *buf, size_t count)
4458 struct Scsi_Host *shost = class_to_shost(dev);
4459 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4460 struct lpfc_hba *phba = vport->phba;
4463 /* fcp_imax is only valid for SLI4 */
4464 if (phba->sli_rev != LPFC_SLI_REV4)
4467 /* Sanity check on user data */
4468 if (!isdigit(buf[0]))
4470 if (sscanf(buf, "%i", &val) != 1)
4474 * Value range for the HBA is [5000,5000000]
4475 * The value for each EQ depends on how many EQs are configured.
4478 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4481 phba->cfg_fcp_imax = (uint32_t)val;
4483 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4484 lpfc_modify_hba_eq_delay(phba, i);
4490 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4493 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4495 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4496 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4497 MODULE_PARM_DESC(lpfc_fcp_imax,
4498 "Set the maximum number of FCP interrupts per second per HBA");
4499 lpfc_param_show(fcp_imax)
4502 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4503 * @phba: lpfc_hba pointer.
4504 * @val: link speed value.
4507 * If val is in a valid range [636,651042], then initialize the adapter's
4508 * maximum number of fast-path FCP interrupts per second.
4511 * zero if val saved.
4512 * -EINVAL val out of range
4515 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4517 if (phba->sli_rev != LPFC_SLI_REV4) {
4518 phba->cfg_fcp_imax = 0;
4522 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4524 phba->cfg_fcp_imax = val;
4528 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4529 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4531 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4536 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4537 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4540 * lpfc_state_show - Display current driver CPU affinity
4541 * @dev: class converted to a Scsi_host structure.
4542 * @attr: device attribute, not used.
4543 * @buf: on return contains text describing the state of the link.
4545 * Returns: size of formatted string.
4548 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4551 struct Scsi_Host *shost = class_to_shost(dev);
4552 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4553 struct lpfc_hba *phba = vport->phba;
4554 struct lpfc_vector_map_info *cpup;
4557 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4558 (phba->intr_type != MSIX))
4561 switch (phba->cfg_fcp_cpu_map) {
4563 len += snprintf(buf + len, PAGE_SIZE-len,
4564 "fcp_cpu_map: No mapping (%d)\n",
4565 phba->cfg_fcp_cpu_map);
4568 len += snprintf(buf + len, PAGE_SIZE-len,
4569 "fcp_cpu_map: HBA centric mapping (%d): "
4571 phba->cfg_fcp_cpu_map,
4572 phba->sli4_hba.num_online_cpu);
4575 len += snprintf(buf + len, PAGE_SIZE-len,
4576 "fcp_cpu_map: Driver centric mapping (%d): "
4578 phba->cfg_fcp_cpu_map,
4579 phba->sli4_hba.num_online_cpu);
4583 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4584 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4586 /* margin should fit in this and the truncated message */
4587 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4588 len += snprintf(buf + len, PAGE_SIZE-len,
4589 "CPU %02d io_chan %02d "
4590 "physid %d coreid %d\n",
4591 phba->sli4_hba.curr_disp_cpu,
4592 cpup->channel_id, cpup->phys_id,
4595 len += snprintf(buf + len, PAGE_SIZE-len,
4596 "CPU %02d io_chan %02d "
4597 "physid %d coreid %d IRQ %d\n",
4598 phba->sli4_hba.curr_disp_cpu,
4599 cpup->channel_id, cpup->phys_id,
4600 cpup->core_id, cpup->irq);
4602 phba->sli4_hba.curr_disp_cpu++;
4604 /* display max number of CPUs keeping some margin */
4605 if (phba->sli4_hba.curr_disp_cpu <
4606 phba->sli4_hba.num_present_cpu &&
4607 (len >= (PAGE_SIZE - 64))) {
4608 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4613 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4614 phba->sli4_hba.curr_disp_cpu = 0;
4620 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4621 * @dev: class device that is converted into a Scsi_host.
4622 * @attr: device attribute, not used.
4623 * @buf: one or more lpfc_polling_flags values.
4627 * -EINVAL - Not implemented yet.
4630 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4631 const char *buf, size_t count)
4633 int status = -EINVAL;
4638 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4641 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4642 # 0 - Do not affinitze IRQ vectors
4643 # 1 - Affintize HBA vectors with respect to each HBA
4644 # (start with CPU0 for each HBA)
4645 # 2 - Affintize HBA vectors with respect to the entire driver
4646 # (round robin thru all CPUs across all HBAs)
4648 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4649 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4650 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4651 "Defines how to map CPUs to IRQ vectors per HBA");
4654 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4655 * @phba: lpfc_hba pointer.
4656 * @val: link speed value.
4659 * If val is in a valid range [0-2], then affinitze the adapter's
4663 * zero if val saved.
4664 * -EINVAL val out of range
4667 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4669 if (phba->sli_rev != LPFC_SLI_REV4) {
4670 phba->cfg_fcp_cpu_map = 0;
4674 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4675 phba->cfg_fcp_cpu_map = val;
4679 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4680 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4682 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4687 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4688 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4691 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4692 # Value range is [2,3]. Default value is 3.
4694 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4695 "Select Fibre Channel class of service for FCP sequences");
4698 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4699 # is [0,1]. Default value is 0.
4701 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4702 "Use ADISC on rediscovery to authenticate FCP devices");
4705 # lpfc_first_burst_size: First burst size to use on the NPorts
4706 # that support first burst.
4707 # Value range is [0,65536]. Default value is 0.
4709 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4710 "First burst size for Targets that support first burst");
4713 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4714 * When the driver is configured as an NVME target, this value is
4715 * communicated to the NVME initiator in the PRLI response. It is
4716 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4717 * parameters are set and the target is sending the PRLI RSP.
4718 * Parameter supported on physical port only - no NPIV support.
4719 * Value range is [0,65536]. Default value is 0.
4721 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4722 "NVME Target mode first burst size in 512B increments.");
4725 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4726 * For the Initiator (I), enabling this parameter means that an NVMET
4727 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4728 * processed by the initiator for subsequent NVME FCP IO. For the target
4729 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4730 * driver parameter as the target function's first burst size returned to the
4731 * initiator in the target's NVME PRLI response. Parameter supported on physical
4732 * port only - no NPIV support.
4733 * Value range is [0,1]. Default value is 0 (disabled).
4735 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4736 "Enable First Burst feature on I and T functions.");
4739 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4740 # depth. Default value is 0. When the value of this parameter is zero the
4741 # SCSI command completion time is not used for controlling I/O queue depth. When
4742 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4743 # to limit the I/O completion time to the parameter value.
4744 # The value is set in milliseconds.
4746 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4747 "Use command completion time to control queue depth");
4749 lpfc_vport_param_show(max_scsicmpl_time);
4751 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4753 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4754 struct lpfc_nodelist *ndlp, *next_ndlp;
4756 if (val == vport->cfg_max_scsicmpl_time)
4758 if ((val < 0) || (val > 60000))
4760 vport->cfg_max_scsicmpl_time = val;
4762 spin_lock_irq(shost->host_lock);
4763 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4764 if (!NLP_CHK_NODE_ACT(ndlp))
4766 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4768 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4770 spin_unlock_irq(shost->host_lock);
4773 lpfc_vport_param_store(max_scsicmpl_time);
4774 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4775 lpfc_max_scsicmpl_time_show,
4776 lpfc_max_scsicmpl_time_store);
4779 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4780 # range is [0,1]. Default value is 0.
4782 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4785 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4786 * range is [0,1]. Default value is 0.
4787 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4788 * For [1], FCP commands are issued to a Work Queue associated with the
4791 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4792 * LPFC_FCP_SCHED_BY_CPU == 1
4794 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4795 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4796 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4797 * through WQs will be used.
4799 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4800 LPFC_FCP_SCHED_ROUND_ROBIN,
4801 LPFC_FCP_SCHED_BY_CPU,
4802 "Determine scheduling algorithm for "
4803 "issuing commands [0] - Round Robin, [1] - Current CPU");
4806 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4807 # range is [0,1]. Default value is 0.
4808 # For [0], bus reset issues target reset to ALL devices
4809 # For [1], bus reset issues target reset to non-FCP2 devices
4811 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4812 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4816 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4817 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4818 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4819 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4820 # cr_delay is set to 0.
4822 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4823 "interrupt response is generated");
4825 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4826 "interrupt response is generated");
4829 # lpfc_multi_ring_support: Determines how many rings to spread available
4830 # cmd/rsp IOCB entries across.
4831 # Value range is [1,2]. Default value is 1.
4833 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4834 "SLI rings to spread IOCB entries across");
4837 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4838 # identifies what rctl value to configure the additional ring for.
4839 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4841 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4842 255, "Identifies RCTL for additional ring configuration");
4845 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4846 # identifies what type value to configure the additional ring for.
4847 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4849 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4850 255, "Identifies TYPE for additional ring configuration");
4853 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4854 # 0 = SmartSAN functionality disabled (default)
4855 # 1 = SmartSAN functionality enabled
4856 # This parameter will override the value of lpfc_fdmi_on module parameter.
4857 # Value range is [0,1]. Default value is 0.
4859 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4862 # lpfc_fdmi_on: Controls FDMI support.
4863 # 0 No FDMI support (default)
4864 # 1 Traditional FDMI support
4865 # Traditional FDMI support means the driver will assume FDMI-2 support;
4866 # however, if that fails, it will fallback to FDMI-1.
4867 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4868 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4870 # Value range [0,1]. Default value is 0.
4872 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4875 # Specifies the maximum number of ELS cmds we can have outstanding (for
4876 # discovery). Value range is [1,64]. Default value = 32.
4878 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4879 "during discovery");
4882 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4883 # will be scanned by the SCSI midlayer when sequential scanning is
4884 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4885 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4886 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4887 # above. The lpfc driver limits the default value to 255 for two reasons.
4888 # As it bounds the sequential scan loop, scanning for thousands of luns
4889 # on a target can take minutes of wall clock time. Additionally,
4890 # there are FC targets, such as JBODs, that only recognize 8-bits of
4891 # LUN ID. When they receive a value greater than 8 bits, they chop off
4892 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4893 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4894 # valid responses at each of the LUN IDs, to believe there are multiple
4895 # devices present, when in fact, there is only 1.
4896 # A customer that is aware of their target behaviors, and the results as
4897 # indicated above, is welcome to increase the lpfc_max_luns value.
4898 # As mentioned, this value is not used by the lpfc driver, only the
4900 # Value range is [0,65535]. Default value is 255.
4901 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4903 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4906 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4907 # Value range is [1,255], default value is 10.
4909 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4910 "Milliseconds driver will wait between polling FCP ring");
4913 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4914 # to complete in seconds. Value range is [5,180], default value is 60.
4916 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4917 "Maximum time to wait for task management commands to complete");
4919 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4920 # support this feature
4923 # 2 = MSI-X enabled (default)
4924 # Value range is [0,2]. Default value is 2.
4926 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4927 "MSI-X (2), if possible");
4930 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4932 * 0 = NVME OAS disabled
4933 * 1 = NVME OAS enabled
4935 * Value range is [0,1]. Default value is 0.
4937 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4938 "Use OAS bit on NVME IOs");
4941 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4942 * will advertise it supports to the SCSI layer. This also will map to
4943 * the number of WQs the driver will create.
4945 * 0 = Configure the number of io channels to the number of active CPUs.
4946 * 1,32 = Manually specify how many io channels to use.
4948 * Value range is [0,32]. Default value is 4.
4950 LPFC_ATTR_R(fcp_io_channel,
4951 LPFC_FCP_IO_CHAN_DEF,
4952 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4953 "Set the number of FCP I/O channels");
4956 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4957 * will advertise it supports to the NVME layer. This also will map to
4958 * the number of WQs the driver will create.
4960 * This module parameter is valid when lpfc_enable_fc4_type is set
4963 * The NVME Layer will try to create this many, plus 1 administrative
4964 * hardware queue. The administrative queue will always map to WQ 0
4965 * A hardware IO queue maps (qidx) to a specific driver WQ.
4967 * 0 = Configure the number of io channels to the number of active CPUs.
4968 * 1,32 = Manually specify how many io channels to use.
4970 * Value range is [0,32]. Default value is 0.
4972 LPFC_ATTR_R(nvme_io_channel,
4973 LPFC_NVME_IO_CHAN_DEF,
4974 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4975 "Set the number of NVME I/O channels");
4978 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4979 # 0 = HBA resets disabled
4980 # 1 = HBA resets enabled (default)
4981 # Value range is [0,1]. Default value is 1.
4983 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
4986 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
4987 # 0 = HBA Heartbeat disabled
4988 # 1 = HBA Heartbeat enabled (default)
4989 # Value range is [0,1]. Default value is 1.
4991 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
4994 # lpfc_EnableXLane: Enable Express Lane Feature
4995 # 0x0 Express Lane Feature disabled
4996 # 0x1 Express Lane Feature enabled
4997 # Value range is [0,1]. Default value is 0.
4999 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5002 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5003 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5004 # Value range is [0x0,0x7f]. Default value is 0
5006 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5009 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5010 # 0 = BlockGuard disabled (default)
5011 # 1 = BlockGuard enabled
5012 # Value range is [0,1]. Default value is 0.
5014 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5017 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5018 # 0 = disabled (default)
5020 # Value range is [0,1]. Default value is 0.
5022 # This feature in under investigation and may be supported in the future.
5024 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5028 # - Bit mask of host protection capabilities used to register with the
5030 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5031 # - Allows you to ultimately specify which profiles to use
5032 # - Default will result in registering capabilities for all profiles.
5033 # - SHOST_DIF_TYPE1_PROTECTION 1
5034 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5035 # - SHOST_DIX_TYPE0_PROTECTION 8
5036 # HBA supports DIX Type 0: Host to HBA protection only
5037 # - SHOST_DIX_TYPE1_PROTECTION 16
5038 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5041 LPFC_ATTR(prot_mask,
5042 (SHOST_DIF_TYPE1_PROTECTION |
5043 SHOST_DIX_TYPE0_PROTECTION |
5044 SHOST_DIX_TYPE1_PROTECTION),
5046 (SHOST_DIF_TYPE1_PROTECTION |
5047 SHOST_DIX_TYPE0_PROTECTION |
5048 SHOST_DIX_TYPE1_PROTECTION),
5049 "T10-DIF host protection capabilities mask");
5052 # lpfc_prot_guard: i
5053 # - Bit mask of protection guard types to register with the SCSI mid-layer
5054 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5055 # - Allows you to ultimately specify which profiles to use
5056 # - Default will result in registering capabilities for all guard types
5059 LPFC_ATTR(prot_guard,
5060 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5061 "T10-DIF host protection guard type");
5064 * Delay initial NPort discovery when Clean Address bit is cleared in
5065 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5066 * This parameter can have value 0 or 1.
5067 * When this parameter is set to 0, no delay is added to the initial
5069 * When this parameter is set to non-zero value, initial Nport discovery is
5070 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5071 * accept and FCID/Fabric name/Fabric portname is changed.
5072 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5073 * when Clean Address bit is cleared in FLOGI/FDISC
5074 * accept and FCID/Fabric name/Fabric portname is changed.
5075 * Default value is 0.
5077 LPFC_ATTR(delay_discovery, 0, 0, 1,
5078 "Delay NPort discovery when Clean Address bit is cleared.");
5081 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5082 * This value can be set to values between 64 and 4096. The default value is
5083 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5084 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5085 * Because of the additional overhead involved in setting up T10-DIF,
5086 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5087 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5089 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5090 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5093 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5094 * 0 = MDS Diagnostics disabled (default)
5095 * 1 = MDS Diagnostics enabled
5096 * Value range is [0,1]. Default value is 0.
5098 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5100 struct device_attribute *lpfc_hba_attrs[] = {
5101 &dev_attr_nvme_info,
5103 &dev_attr_bg_guard_err,
5104 &dev_attr_bg_apptag_err,
5105 &dev_attr_bg_reftag_err,
5107 &dev_attr_serialnum,
5108 &dev_attr_modeldesc,
5109 &dev_attr_modelname,
5110 &dev_attr_programtype,
5114 &dev_attr_option_rom_version,
5115 &dev_attr_link_state,
5116 &dev_attr_num_discovered_ports,
5117 &dev_attr_menlo_mgmt_mode,
5118 &dev_attr_lpfc_drvr_version,
5119 &dev_attr_lpfc_enable_fip,
5120 &dev_attr_lpfc_temp_sensor,
5121 &dev_attr_lpfc_log_verbose,
5122 &dev_attr_lpfc_lun_queue_depth,
5123 &dev_attr_lpfc_tgt_queue_depth,
5124 &dev_attr_lpfc_hba_queue_depth,
5125 &dev_attr_lpfc_peer_port_login,
5126 &dev_attr_lpfc_nodev_tmo,
5127 &dev_attr_lpfc_devloss_tmo,
5128 &dev_attr_lpfc_enable_fc4_type,
5129 &dev_attr_lpfc_xri_split,
5130 &dev_attr_lpfc_fcp_class,
5131 &dev_attr_lpfc_use_adisc,
5132 &dev_attr_lpfc_first_burst_size,
5133 &dev_attr_lpfc_ack0,
5134 &dev_attr_lpfc_topology,
5135 &dev_attr_lpfc_scan_down,
5136 &dev_attr_lpfc_link_speed,
5137 &dev_attr_lpfc_fcp_io_sched,
5138 &dev_attr_lpfc_fcp2_no_tgt_reset,
5139 &dev_attr_lpfc_cr_delay,
5140 &dev_attr_lpfc_cr_count,
5141 &dev_attr_lpfc_multi_ring_support,
5142 &dev_attr_lpfc_multi_ring_rctl,
5143 &dev_attr_lpfc_multi_ring_type,
5144 &dev_attr_lpfc_fdmi_on,
5145 &dev_attr_lpfc_enable_SmartSAN,
5146 &dev_attr_lpfc_max_luns,
5147 &dev_attr_lpfc_enable_npiv,
5148 &dev_attr_lpfc_fcf_failover_policy,
5149 &dev_attr_lpfc_enable_rrq,
5150 &dev_attr_nport_evt_cnt,
5151 &dev_attr_board_mode,
5158 &dev_attr_npiv_info,
5159 &dev_attr_issue_reset,
5160 &dev_attr_lpfc_poll,
5161 &dev_attr_lpfc_poll_tmo,
5162 &dev_attr_lpfc_task_mgmt_tmo,
5163 &dev_attr_lpfc_use_msi,
5164 &dev_attr_lpfc_nvme_oas,
5165 &dev_attr_lpfc_fcp_imax,
5166 &dev_attr_lpfc_fcp_cpu_map,
5167 &dev_attr_lpfc_fcp_io_channel,
5168 &dev_attr_lpfc_suppress_rsp,
5169 &dev_attr_lpfc_nvme_io_channel,
5170 &dev_attr_lpfc_nvmet_mrq,
5171 &dev_attr_lpfc_nvme_enable_fb,
5172 &dev_attr_lpfc_nvmet_fb_size,
5173 &dev_attr_lpfc_enable_bg,
5174 &dev_attr_lpfc_soft_wwnn,
5175 &dev_attr_lpfc_soft_wwpn,
5176 &dev_attr_lpfc_soft_wwn_enable,
5177 &dev_attr_lpfc_enable_hba_reset,
5178 &dev_attr_lpfc_enable_hba_heartbeat,
5179 &dev_attr_lpfc_EnableXLane,
5180 &dev_attr_lpfc_XLanePriority,
5181 &dev_attr_lpfc_xlane_lun,
5182 &dev_attr_lpfc_xlane_tgt,
5183 &dev_attr_lpfc_xlane_vpt,
5184 &dev_attr_lpfc_xlane_lun_state,
5185 &dev_attr_lpfc_xlane_lun_status,
5186 &dev_attr_lpfc_xlane_priority,
5187 &dev_attr_lpfc_sg_seg_cnt,
5188 &dev_attr_lpfc_max_scsicmpl_time,
5189 &dev_attr_lpfc_stat_data_ctrl,
5190 &dev_attr_lpfc_aer_support,
5191 &dev_attr_lpfc_aer_state_cleanup,
5192 &dev_attr_lpfc_sriov_nr_virtfn,
5193 &dev_attr_lpfc_req_fw_upgrade,
5194 &dev_attr_lpfc_suppress_link_up,
5195 &dev_attr_lpfc_iocb_cnt,
5198 &dev_attr_txcmplq_hw,
5199 &dev_attr_lpfc_fips_level,
5200 &dev_attr_lpfc_fips_rev,
5202 &dev_attr_lpfc_sriov_hw_max_virtfn,
5204 &dev_attr_lpfc_xlane_supported,
5205 &dev_attr_lpfc_enable_mds_diags,
5209 struct device_attribute *lpfc_vport_attrs[] = {
5211 &dev_attr_link_state,
5212 &dev_attr_num_discovered_ports,
5213 &dev_attr_lpfc_drvr_version,
5214 &dev_attr_lpfc_log_verbose,
5215 &dev_attr_lpfc_lun_queue_depth,
5216 &dev_attr_lpfc_tgt_queue_depth,
5217 &dev_attr_lpfc_nodev_tmo,
5218 &dev_attr_lpfc_devloss_tmo,
5219 &dev_attr_lpfc_hba_queue_depth,
5220 &dev_attr_lpfc_peer_port_login,
5221 &dev_attr_lpfc_restrict_login,
5222 &dev_attr_lpfc_fcp_class,
5223 &dev_attr_lpfc_use_adisc,
5224 &dev_attr_lpfc_first_burst_size,
5225 &dev_attr_lpfc_max_luns,
5226 &dev_attr_nport_evt_cnt,
5227 &dev_attr_npiv_info,
5228 &dev_attr_lpfc_enable_da_id,
5229 &dev_attr_lpfc_max_scsicmpl_time,
5230 &dev_attr_lpfc_stat_data_ctrl,
5231 &dev_attr_lpfc_static_vport,
5232 &dev_attr_lpfc_fips_level,
5233 &dev_attr_lpfc_fips_rev,
5238 * sysfs_ctlreg_write - Write method for writing to ctlreg
5239 * @filp: open sysfs file
5240 * @kobj: kernel kobject that contains the kernel class device.
5241 * @bin_attr: kernel attributes passed to us.
5242 * @buf: contains the data to be written to the adapter IOREG space.
5243 * @off: offset into buffer to beginning of data.
5244 * @count: bytes to transfer.
5247 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5248 * Uses the adapter io control registers to send buf contents to the adapter.
5251 * -ERANGE off and count combo out of range
5252 * -EINVAL off, count or buff address invalid
5253 * -EPERM adapter is offline
5254 * value of count, buf contents written
5257 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5258 struct bin_attribute *bin_attr,
5259 char *buf, loff_t off, size_t count)
5262 struct device *dev = container_of(kobj, struct device, kobj);
5263 struct Scsi_Host *shost = class_to_shost(dev);
5264 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5265 struct lpfc_hba *phba = vport->phba;
5267 if (phba->sli_rev >= LPFC_SLI_REV4)
5270 if ((off + count) > FF_REG_AREA_SIZE)
5273 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5276 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5279 /* This is to protect HBA registers from accidental writes. */
5280 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5283 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5286 spin_lock_irq(&phba->hbalock);
5287 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5288 buf_off += sizeof(uint32_t))
5289 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5290 phba->ctrl_regs_memmap_p + off + buf_off);
5292 spin_unlock_irq(&phba->hbalock);
5298 * sysfs_ctlreg_read - Read method for reading from ctlreg
5299 * @filp: open sysfs file
5300 * @kobj: kernel kobject that contains the kernel class device.
5301 * @bin_attr: kernel attributes passed to us.
5302 * @buf: if successful contains the data from the adapter IOREG space.
5303 * @off: offset into buffer to beginning of data.
5304 * @count: bytes to transfer.
5307 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5308 * Uses the adapter io control registers to read data into buf.
5311 * -ERANGE off and count combo out of range
5312 * -EINVAL off, count or buff address invalid
5313 * value of count, buf contents read
5316 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5317 struct bin_attribute *bin_attr,
5318 char *buf, loff_t off, size_t count)
5322 struct device *dev = container_of(kobj, struct device, kobj);
5323 struct Scsi_Host *shost = class_to_shost(dev);
5324 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5325 struct lpfc_hba *phba = vport->phba;
5327 if (phba->sli_rev >= LPFC_SLI_REV4)
5330 if (off > FF_REG_AREA_SIZE)
5333 if ((off + count) > FF_REG_AREA_SIZE)
5334 count = FF_REG_AREA_SIZE - off;
5336 if (count == 0) return 0;
5338 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5341 spin_lock_irq(&phba->hbalock);
5343 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5344 tmp_ptr = (uint32_t *)(buf + buf_off);
5345 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5348 spin_unlock_irq(&phba->hbalock);
5353 static struct bin_attribute sysfs_ctlreg_attr = {
5356 .mode = S_IRUSR | S_IWUSR,
5359 .read = sysfs_ctlreg_read,
5360 .write = sysfs_ctlreg_write,
5364 * sysfs_mbox_write - Write method for writing information via mbox
5365 * @filp: open sysfs file
5366 * @kobj: kernel kobject that contains the kernel class device.
5367 * @bin_attr: kernel attributes passed to us.
5368 * @buf: contains the data to be written to sysfs mbox.
5369 * @off: offset into buffer to beginning of data.
5370 * @count: bytes to transfer.
5373 * Deprecated function. All mailbox access from user space is performed via the
5377 * -EPERM operation not permitted
5380 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5381 struct bin_attribute *bin_attr,
5382 char *buf, loff_t off, size_t count)
5388 * sysfs_mbox_read - Read method for reading information via mbox
5389 * @filp: open sysfs file
5390 * @kobj: kernel kobject that contains the kernel class device.
5391 * @bin_attr: kernel attributes passed to us.
5392 * @buf: contains the data to be read from sysfs mbox.
5393 * @off: offset into buffer to beginning of data.
5394 * @count: bytes to transfer.
5397 * Deprecated function. All mailbox access from user space is performed via the
5401 * -EPERM operation not permitted
5404 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5405 struct bin_attribute *bin_attr,
5406 char *buf, loff_t off, size_t count)
5411 static struct bin_attribute sysfs_mbox_attr = {
5414 .mode = S_IRUSR | S_IWUSR,
5416 .size = MAILBOX_SYSFS_MAX,
5417 .read = sysfs_mbox_read,
5418 .write = sysfs_mbox_write,
5422 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5423 * @vport: address of lpfc vport structure.
5427 * error return code from sysfs_create_bin_file()
5430 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5432 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5435 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5436 &sysfs_drvr_stat_data_attr);
5438 /* Virtual ports do not need ctrl_reg and mbox */
5439 if (error || vport->port_type == LPFC_NPIV_PORT)
5442 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5443 &sysfs_ctlreg_attr);
5445 goto out_remove_stat_attr;
5447 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5450 goto out_remove_ctlreg_attr;
5453 out_remove_ctlreg_attr:
5454 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5455 out_remove_stat_attr:
5456 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5457 &sysfs_drvr_stat_data_attr);
5463 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5464 * @vport: address of lpfc vport structure.
5467 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5469 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5470 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5471 &sysfs_drvr_stat_data_attr);
5472 /* Virtual ports do not need ctrl_reg and mbox */
5473 if (vport->port_type == LPFC_NPIV_PORT)
5475 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5476 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5480 * Dynamic FC Host Attributes Support
5484 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5485 * @shost: kernel scsi host pointer.
5488 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5490 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5492 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5493 sizeof fc_host_symbolic_name(shost));
5497 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5498 * @shost: kernel scsi host pointer.
5501 lpfc_get_host_port_id(struct Scsi_Host *shost)
5503 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5505 /* note: fc_myDID already in cpu endianness */
5506 fc_host_port_id(shost) = vport->fc_myDID;
5510 * lpfc_get_host_port_type - Set the value of the scsi host port type
5511 * @shost: kernel scsi host pointer.
5514 lpfc_get_host_port_type(struct Scsi_Host *shost)
5516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5517 struct lpfc_hba *phba = vport->phba;
5519 spin_lock_irq(shost->host_lock);
5521 if (vport->port_type == LPFC_NPIV_PORT) {
5522 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5523 } else if (lpfc_is_link_up(phba)) {
5524 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5525 if (vport->fc_flag & FC_PUBLIC_LOOP)
5526 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5528 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5530 if (vport->fc_flag & FC_FABRIC)
5531 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5533 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5536 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5538 spin_unlock_irq(shost->host_lock);
5542 * lpfc_get_host_port_state - Set the value of the scsi host port state
5543 * @shost: kernel scsi host pointer.
5546 lpfc_get_host_port_state(struct Scsi_Host *shost)
5548 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5549 struct lpfc_hba *phba = vport->phba;
5551 spin_lock_irq(shost->host_lock);
5553 if (vport->fc_flag & FC_OFFLINE_MODE)
5554 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5556 switch (phba->link_state) {
5557 case LPFC_LINK_UNKNOWN:
5558 case LPFC_LINK_DOWN:
5559 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5563 case LPFC_HBA_READY:
5564 /* Links up, reports port state accordingly */
5565 if (vport->port_state < LPFC_VPORT_READY)
5566 fc_host_port_state(shost) =
5567 FC_PORTSTATE_BYPASSED;
5569 fc_host_port_state(shost) =
5570 FC_PORTSTATE_ONLINE;
5572 case LPFC_HBA_ERROR:
5573 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5576 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5581 spin_unlock_irq(shost->host_lock);
5585 * lpfc_get_host_speed - Set the value of the scsi host speed
5586 * @shost: kernel scsi host pointer.
5589 lpfc_get_host_speed(struct Scsi_Host *shost)
5591 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5592 struct lpfc_hba *phba = vport->phba;
5594 spin_lock_irq(shost->host_lock);
5596 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5597 switch(phba->fc_linkspeed) {
5598 case LPFC_LINK_SPEED_1GHZ:
5599 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5601 case LPFC_LINK_SPEED_2GHZ:
5602 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5604 case LPFC_LINK_SPEED_4GHZ:
5605 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5607 case LPFC_LINK_SPEED_8GHZ:
5608 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5610 case LPFC_LINK_SPEED_10GHZ:
5611 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5613 case LPFC_LINK_SPEED_16GHZ:
5614 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5616 case LPFC_LINK_SPEED_32GHZ:
5617 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5620 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5624 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5626 spin_unlock_irq(shost->host_lock);
5630 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5631 * @shost: kernel scsi host pointer.
5634 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5636 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5637 struct lpfc_hba *phba = vport->phba;
5640 spin_lock_irq(shost->host_lock);
5642 if ((vport->port_state > LPFC_FLOGI) &&
5643 ((vport->fc_flag & FC_FABRIC) ||
5644 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5645 (vport->fc_flag & FC_PUBLIC_LOOP))))
5646 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5648 /* fabric is local port if there is no F/FL_Port */
5651 spin_unlock_irq(shost->host_lock);
5653 fc_host_fabric_name(shost) = node_name;
5657 * lpfc_get_stats - Return statistical information about the adapter
5658 * @shost: kernel scsi host pointer.
5661 * NULL on error for link down, no mbox pool, sli2 active,
5662 * management not allowed, memory allocation error, or mbox error.
5666 * address of the adapter host statistics
5668 static struct fc_host_statistics *
5669 lpfc_get_stats(struct Scsi_Host *shost)
5671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5672 struct lpfc_hba *phba = vport->phba;
5673 struct lpfc_sli *psli = &phba->sli;
5674 struct fc_host_statistics *hs = &phba->link_stats;
5675 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5676 LPFC_MBOXQ_t *pmboxq;
5678 unsigned long seconds;
5682 * prevent udev from issuing mailbox commands until the port is
5685 if (phba->link_state < LPFC_LINK_DOWN ||
5686 !phba->mbox_mem_pool ||
5687 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5690 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5693 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5696 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5698 pmb = &pmboxq->u.mb;
5699 pmb->mbxCommand = MBX_READ_STATUS;
5700 pmb->mbxOwner = OWN_HOST;
5701 pmboxq->context1 = NULL;
5702 pmboxq->vport = vport;
5704 if (vport->fc_flag & FC_OFFLINE_MODE)
5705 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5707 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5709 if (rc != MBX_SUCCESS) {
5710 if (rc != MBX_TIMEOUT)
5711 mempool_free(pmboxq, phba->mbox_mem_pool);
5715 memset(hs, 0, sizeof (struct fc_host_statistics));
5717 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5719 * The MBX_READ_STATUS returns tx_k_bytes which has to
5720 * converted to words
5722 hs->tx_words = (uint64_t)
5723 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5725 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5726 hs->rx_words = (uint64_t)
5727 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5730 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5731 pmb->mbxCommand = MBX_READ_LNK_STAT;
5732 pmb->mbxOwner = OWN_HOST;
5733 pmboxq->context1 = NULL;
5734 pmboxq->vport = vport;
5736 if (vport->fc_flag & FC_OFFLINE_MODE)
5737 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5739 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5741 if (rc != MBX_SUCCESS) {
5742 if (rc != MBX_TIMEOUT)
5743 mempool_free(pmboxq, phba->mbox_mem_pool);
5747 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5748 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5749 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5750 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5751 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5752 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5753 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5755 hs->link_failure_count -= lso->link_failure_count;
5756 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5757 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5758 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5759 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5760 hs->invalid_crc_count -= lso->invalid_crc_count;
5761 hs->error_frames -= lso->error_frames;
5763 if (phba->hba_flag & HBA_FCOE_MODE) {
5765 hs->nos_count = (phba->link_events >> 1);
5766 hs->nos_count -= lso->link_events;
5767 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5768 hs->lip_count = (phba->fc_eventTag >> 1);
5769 hs->lip_count -= lso->link_events;
5773 hs->nos_count = (phba->fc_eventTag >> 1);
5774 hs->nos_count -= lso->link_events;
5777 hs->dumped_frames = -1;
5779 seconds = get_seconds();
5780 if (seconds < psli->stats_start)
5781 hs->seconds_since_last_reset = seconds +
5782 ((unsigned long)-1 - psli->stats_start);
5784 hs->seconds_since_last_reset = seconds - psli->stats_start;
5786 mempool_free(pmboxq, phba->mbox_mem_pool);
5792 * lpfc_reset_stats - Copy the adapter link stats information
5793 * @shost: kernel scsi host pointer.
5796 lpfc_reset_stats(struct Scsi_Host *shost)
5798 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5799 struct lpfc_hba *phba = vport->phba;
5800 struct lpfc_sli *psli = &phba->sli;
5801 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5802 LPFC_MBOXQ_t *pmboxq;
5806 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5809 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5812 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5814 pmb = &pmboxq->u.mb;
5815 pmb->mbxCommand = MBX_READ_STATUS;
5816 pmb->mbxOwner = OWN_HOST;
5817 pmb->un.varWords[0] = 0x1; /* reset request */
5818 pmboxq->context1 = NULL;
5819 pmboxq->vport = vport;
5821 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5822 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5823 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5825 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5827 if (rc != MBX_SUCCESS) {
5828 if (rc != MBX_TIMEOUT)
5829 mempool_free(pmboxq, phba->mbox_mem_pool);
5833 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5834 pmb->mbxCommand = MBX_READ_LNK_STAT;
5835 pmb->mbxOwner = OWN_HOST;
5836 pmboxq->context1 = NULL;
5837 pmboxq->vport = vport;
5839 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5840 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5841 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5843 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5845 if (rc != MBX_SUCCESS) {
5846 if (rc != MBX_TIMEOUT)
5847 mempool_free( pmboxq, phba->mbox_mem_pool);
5851 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5852 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5853 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5854 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5855 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5856 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5857 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5858 if (phba->hba_flag & HBA_FCOE_MODE)
5859 lso->link_events = (phba->link_events >> 1);
5861 lso->link_events = (phba->fc_eventTag >> 1);
5863 psli->stats_start = get_seconds();
5865 mempool_free(pmboxq, phba->mbox_mem_pool);
5871 * The LPFC driver treats linkdown handling as target loss events so there
5872 * are no sysfs handlers for link_down_tmo.
5876 * lpfc_get_node_by_target - Return the nodelist for a target
5877 * @starget: kernel scsi target pointer.
5880 * address of the node list if found
5881 * NULL target not found
5883 static struct lpfc_nodelist *
5884 lpfc_get_node_by_target(struct scsi_target *starget)
5886 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5887 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5888 struct lpfc_nodelist *ndlp;
5890 spin_lock_irq(shost->host_lock);
5891 /* Search for this, mapped, target ID */
5892 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5893 if (NLP_CHK_NODE_ACT(ndlp) &&
5894 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5895 starget->id == ndlp->nlp_sid) {
5896 spin_unlock_irq(shost->host_lock);
5900 spin_unlock_irq(shost->host_lock);
5905 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5906 * @starget: kernel scsi target pointer.
5909 lpfc_get_starget_port_id(struct scsi_target *starget)
5911 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5913 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5917 * lpfc_get_starget_node_name - Set the target node name
5918 * @starget: kernel scsi target pointer.
5920 * Description: Set the target node name to the ndlp node name wwn or zero.
5923 lpfc_get_starget_node_name(struct scsi_target *starget)
5925 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5927 fc_starget_node_name(starget) =
5928 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5932 * lpfc_get_starget_port_name - Set the target port name
5933 * @starget: kernel scsi target pointer.
5935 * Description: set the target port name to the ndlp port name wwn or zero.
5938 lpfc_get_starget_port_name(struct scsi_target *starget)
5940 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5942 fc_starget_port_name(starget) =
5943 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5947 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5948 * @rport: fc rport address.
5949 * @timeout: new value for dev loss tmo.
5952 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5953 * dev_loss_tmo to one.
5956 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5959 rport->dev_loss_tmo = timeout;
5961 rport->dev_loss_tmo = 1;
5965 * lpfc_rport_show_function - Return rport target information
5968 * Macro that uses field to generate a function with the name lpfc_show_rport_
5970 * lpfc_show_rport_##field: returns the bytes formatted in buf
5971 * @cdev: class converted to an fc_rport.
5972 * @buf: on return contains the target_field or zero.
5974 * Returns: size of formatted string.
5976 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5978 lpfc_show_rport_##field (struct device *dev, \
5979 struct device_attribute *attr, \
5982 struct fc_rport *rport = transport_class_to_rport(dev); \
5983 struct lpfc_rport_data *rdata = rport->hostdata; \
5984 return snprintf(buf, sz, format_string, \
5985 (rdata->target) ? cast rdata->target->field : 0); \
5988 #define lpfc_rport_rd_attr(field, format_string, sz) \
5989 lpfc_rport_show_function(field, format_string, sz, ) \
5990 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5993 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
5994 * @fc_vport: The fc_vport who's symbolic name has been changed.
5997 * This function is called by the transport after the @fc_vport's symbolic name
5998 * has been changed. This function re-registers the symbolic name with the
5999 * switch to propagate the change into the fabric if the vport is active.
6002 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6004 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6006 if (vport->port_state == LPFC_VPORT_READY)
6007 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6011 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6012 * @phba: Pointer to lpfc_hba struct.
6014 * This function is called by the lpfc_get_cfgparam() routine to set the
6015 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6016 * log message according to the module's lpfc_log_verbose parameter setting
6017 * before hba port or vport created.
6020 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6022 phba->cfg_log_verbose = verbose;
6025 struct fc_function_template lpfc_transport_functions = {
6026 /* fixed attributes the driver supports */
6027 .show_host_node_name = 1,
6028 .show_host_port_name = 1,
6029 .show_host_supported_classes = 1,
6030 .show_host_supported_fc4s = 1,
6031 .show_host_supported_speeds = 1,
6032 .show_host_maxframe_size = 1,
6034 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6035 .show_host_symbolic_name = 1,
6037 /* dynamic attributes the driver supports */
6038 .get_host_port_id = lpfc_get_host_port_id,
6039 .show_host_port_id = 1,
6041 .get_host_port_type = lpfc_get_host_port_type,
6042 .show_host_port_type = 1,
6044 .get_host_port_state = lpfc_get_host_port_state,
6045 .show_host_port_state = 1,
6047 /* active_fc4s is shown but doesn't change (thus no get function) */
6048 .show_host_active_fc4s = 1,
6050 .get_host_speed = lpfc_get_host_speed,
6051 .show_host_speed = 1,
6053 .get_host_fabric_name = lpfc_get_host_fabric_name,
6054 .show_host_fabric_name = 1,
6057 * The LPFC driver treats linkdown handling as target loss events
6058 * so there are no sysfs handlers for link_down_tmo.
6061 .get_fc_host_stats = lpfc_get_stats,
6062 .reset_fc_host_stats = lpfc_reset_stats,
6064 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6065 .show_rport_maxframe_size = 1,
6066 .show_rport_supported_classes = 1,
6068 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6069 .show_rport_dev_loss_tmo = 1,
6071 .get_starget_port_id = lpfc_get_starget_port_id,
6072 .show_starget_port_id = 1,
6074 .get_starget_node_name = lpfc_get_starget_node_name,
6075 .show_starget_node_name = 1,
6077 .get_starget_port_name = lpfc_get_starget_port_name,
6078 .show_starget_port_name = 1,
6080 .issue_fc_host_lip = lpfc_issue_lip,
6081 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6082 .terminate_rport_io = lpfc_terminate_rport_io,
6084 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6086 .vport_disable = lpfc_vport_disable,
6088 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6090 .bsg_request = lpfc_bsg_request,
6091 .bsg_timeout = lpfc_bsg_timeout,
6094 struct fc_function_template lpfc_vport_transport_functions = {
6095 /* fixed attributes the driver supports */
6096 .show_host_node_name = 1,
6097 .show_host_port_name = 1,
6098 .show_host_supported_classes = 1,
6099 .show_host_supported_fc4s = 1,
6100 .show_host_supported_speeds = 1,
6101 .show_host_maxframe_size = 1,
6103 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6104 .show_host_symbolic_name = 1,
6106 /* dynamic attributes the driver supports */
6107 .get_host_port_id = lpfc_get_host_port_id,
6108 .show_host_port_id = 1,
6110 .get_host_port_type = lpfc_get_host_port_type,
6111 .show_host_port_type = 1,
6113 .get_host_port_state = lpfc_get_host_port_state,
6114 .show_host_port_state = 1,
6116 /* active_fc4s is shown but doesn't change (thus no get function) */
6117 .show_host_active_fc4s = 1,
6119 .get_host_speed = lpfc_get_host_speed,
6120 .show_host_speed = 1,
6122 .get_host_fabric_name = lpfc_get_host_fabric_name,
6123 .show_host_fabric_name = 1,
6126 * The LPFC driver treats linkdown handling as target loss events
6127 * so there are no sysfs handlers for link_down_tmo.
6130 .get_fc_host_stats = lpfc_get_stats,
6131 .reset_fc_host_stats = lpfc_reset_stats,
6133 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6134 .show_rport_maxframe_size = 1,
6135 .show_rport_supported_classes = 1,
6137 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6138 .show_rport_dev_loss_tmo = 1,
6140 .get_starget_port_id = lpfc_get_starget_port_id,
6141 .show_starget_port_id = 1,
6143 .get_starget_node_name = lpfc_get_starget_node_name,
6144 .show_starget_node_name = 1,
6146 .get_starget_port_name = lpfc_get_starget_port_name,
6147 .show_starget_port_name = 1,
6149 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6150 .terminate_rport_io = lpfc_terminate_rport_io,
6152 .vport_disable = lpfc_vport_disable,
6154 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6158 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6159 * @phba: lpfc_hba pointer.
6162 lpfc_get_cfgparam(struct lpfc_hba *phba)
6164 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6165 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6166 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6167 lpfc_cr_count_init(phba, lpfc_cr_count);
6168 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6169 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6170 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6171 lpfc_ack0_init(phba, lpfc_ack0);
6172 lpfc_topology_init(phba, lpfc_topology);
6173 lpfc_link_speed_init(phba, lpfc_link_speed);
6174 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6175 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6176 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6177 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6178 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6179 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6180 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6181 lpfc_use_msi_init(phba, lpfc_use_msi);
6182 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6183 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6184 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6185 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6186 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6188 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6189 if (phba->sli_rev != LPFC_SLI_REV4)
6190 phba->cfg_EnableXLane = 0;
6191 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6193 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6194 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6195 phba->cfg_oas_lun_state = 0;
6196 phba->cfg_oas_lun_status = 0;
6197 phba->cfg_oas_flags = 0;
6198 phba->cfg_oas_priority = 0;
6199 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6200 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6201 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6202 if (phba->sli_rev == LPFC_SLI_REV4)
6205 phba->cfg_poll = lpfc_poll;
6206 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6208 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6209 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6211 /* Initialize first burst. Target vs Initiator are different. */
6212 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6213 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6214 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6215 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6217 if (phba->sli_rev != LPFC_SLI_REV4) {
6218 /* NVME only supported on SLI4 */
6219 phba->nvmet_support = 0;
6220 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6222 /* We MUST have FCP support */
6223 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6224 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6227 /* A value of 0 means use the number of CPUs found in the system */
6228 if (phba->cfg_fcp_io_channel == 0)
6229 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6230 if (phba->cfg_nvme_io_channel == 0)
6231 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6233 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6234 phba->cfg_fcp_io_channel = 0;
6236 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6237 phba->cfg_nvme_io_channel = 0;
6239 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6240 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6242 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6244 phba->cfg_soft_wwnn = 0L;
6245 phba->cfg_soft_wwpn = 0L;
6246 lpfc_xri_split_init(phba, lpfc_xri_split);
6247 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6248 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6249 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6250 lpfc_aer_support_init(phba, lpfc_aer_support);
6251 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6252 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6253 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6254 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6255 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6256 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6257 phba->cfg_enable_dss = 1;
6258 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6263 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6264 * dependencies between protocols and roles.
6265 * @phba: lpfc_hba pointer.
6268 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6270 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6271 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6273 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6274 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6276 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6277 phba->nvmet_support) {
6278 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6279 phba->cfg_fcp_io_channel = 0;
6281 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6282 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6283 "NVME Target PRLI ACC enable_fb ",
6284 phba->cfg_nvme_enable_fb,
6285 phba->cfg_nvmet_fb_size,
6286 LPFC_NVMET_FB_SZ_MAX);
6288 if (phba->cfg_nvme_enable_fb == 0)
6289 phba->cfg_nvmet_fb_size = 0;
6291 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6292 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6295 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6296 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6297 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6298 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6299 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6300 phba->cfg_nvmet_mrq);
6303 /* Not NVME Target mode. Turn off Target parameters. */
6304 phba->nvmet_support = 0;
6305 phba->cfg_nvmet_mrq = 0;
6306 phba->cfg_nvmet_fb_size = 0;
6309 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6310 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6312 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6316 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6317 * @vport: lpfc_vport pointer.
6320 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6322 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6323 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6324 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6325 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6326 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6327 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6328 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6329 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6330 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6331 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6332 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6333 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6334 lpfc_max_luns_init(vport, lpfc_max_luns);
6335 lpfc_scan_down_init(vport, lpfc_scan_down);
6336 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);