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);
1356 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1357 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1358 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1359 if (phba->sli_rev == LPFC_SLI_REV4)
1362 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1363 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1364 if (phba->sli_rev == LPFC_SLI_REV4)
1367 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1368 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1369 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1370 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1371 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1372 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1373 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1381 board_mode_str = strchr(buf, '\n');
1383 *board_mode_str = '\0';
1384 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1385 "3097 Failed \"%s\", status(%d), "
1387 buf, status, phba->pport->fc_flag);
1393 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1394 * @phba: pointer to the adapter structure.
1395 * @mxri: max xri count.
1396 * @axri: available xri count.
1397 * @mrpi: max rpi count.
1398 * @arpi: available rpi count.
1399 * @mvpi: max vpi count.
1400 * @avpi: available vpi count.
1403 * If an integer pointer for an count is not null then the value for the
1404 * count is returned.
1411 lpfc_get_hba_info(struct lpfc_hba *phba,
1412 uint32_t *mxri, uint32_t *axri,
1413 uint32_t *mrpi, uint32_t *arpi,
1414 uint32_t *mvpi, uint32_t *avpi)
1416 struct lpfc_mbx_read_config *rd_config;
1417 LPFC_MBOXQ_t *pmboxq;
1423 * prevent udev from issuing mailbox commands until the port is
1426 if (phba->link_state < LPFC_LINK_DOWN ||
1427 !phba->mbox_mem_pool ||
1428 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1431 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1434 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1437 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1439 pmb = &pmboxq->u.mb;
1440 pmb->mbxCommand = MBX_READ_CONFIG;
1441 pmb->mbxOwner = OWN_HOST;
1442 pmboxq->context1 = NULL;
1444 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1445 rc = MBX_NOT_FINISHED;
1447 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1449 if (rc != MBX_SUCCESS) {
1450 if (rc != MBX_TIMEOUT)
1451 mempool_free(pmboxq, phba->mbox_mem_pool);
1455 if (phba->sli_rev == LPFC_SLI_REV4) {
1456 rd_config = &pmboxq->u.mqe.un.rd_config;
1458 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1460 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1461 phba->sli4_hba.max_cfg_param.rpi_used;
1463 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1465 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1466 phba->sli4_hba.max_cfg_param.xri_used;
1468 /* Account for differences with SLI-3. Get vpi count from
1469 * mailbox data and subtract one for max vpi value.
1471 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1472 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1477 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1480 *mrpi = pmb->un.varRdConfig.max_rpi;
1482 *arpi = pmb->un.varRdConfig.avail_rpi;
1484 *mxri = pmb->un.varRdConfig.max_xri;
1486 *axri = pmb->un.varRdConfig.avail_xri;
1488 *mvpi = pmb->un.varRdConfig.max_vpi;
1490 *avpi = pmb->un.varRdConfig.avail_vpi;
1493 mempool_free(pmboxq, phba->mbox_mem_pool);
1498 * lpfc_max_rpi_show - Return maximum rpi
1499 * @dev: class device that is converted into a Scsi_host.
1500 * @attr: device attribute, not used.
1501 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1504 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1505 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1506 * to "Unknown" and the buffer length is returned, therefore the caller
1507 * must check for "Unknown" in the buffer to detect a failure.
1509 * Returns: size of formatted string.
1512 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1515 struct Scsi_Host *shost = class_to_shost(dev);
1516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1517 struct lpfc_hba *phba = vport->phba;
1520 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1521 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1522 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1526 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1527 * @dev: class device that is converted into a Scsi_host.
1528 * @attr: device attribute, not used.
1529 * @buf: containing the used rpi count in decimal or "Unknown".
1532 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1533 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1534 * to "Unknown" and the buffer length is returned, therefore the caller
1535 * must check for "Unknown" in the buffer to detect a failure.
1537 * Returns: size of formatted string.
1540 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1543 struct Scsi_Host *shost = class_to_shost(dev);
1544 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1545 struct lpfc_hba *phba = vport->phba;
1548 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1549 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1550 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1554 * lpfc_max_xri_show - Return maximum xri
1555 * @dev: class device that is converted into a Scsi_host.
1556 * @attr: device attribute, not used.
1557 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1560 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1561 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1562 * to "Unknown" and the buffer length is returned, therefore the caller
1563 * must check for "Unknown" in the buffer to detect a failure.
1565 * Returns: size of formatted string.
1568 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1571 struct Scsi_Host *shost = class_to_shost(dev);
1572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1573 struct lpfc_hba *phba = vport->phba;
1576 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1577 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1578 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1582 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1583 * @dev: class device that is converted into a Scsi_host.
1584 * @attr: device attribute, not used.
1585 * @buf: on return contains the used xri count in decimal or "Unknown".
1588 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1589 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1590 * to "Unknown" and the buffer length is returned, therefore the caller
1591 * must check for "Unknown" in the buffer to detect a failure.
1593 * Returns: size of formatted string.
1596 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1599 struct Scsi_Host *shost = class_to_shost(dev);
1600 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1601 struct lpfc_hba *phba = vport->phba;
1604 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1605 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1606 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1610 * lpfc_max_vpi_show - Return maximum vpi
1611 * @dev: class device that is converted into a Scsi_host.
1612 * @attr: device attribute, not used.
1613 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1616 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1617 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1618 * to "Unknown" and the buffer length is returned, therefore the caller
1619 * must check for "Unknown" in the buffer to detect a failure.
1621 * Returns: size of formatted string.
1624 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1627 struct Scsi_Host *shost = class_to_shost(dev);
1628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1629 struct lpfc_hba *phba = vport->phba;
1632 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1633 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1634 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1638 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1639 * @dev: class device that is converted into a Scsi_host.
1640 * @attr: device attribute, not used.
1641 * @buf: on return contains the used vpi count in decimal or "Unknown".
1644 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1645 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1646 * to "Unknown" and the buffer length is returned, therefore the caller
1647 * must check for "Unknown" in the buffer to detect a failure.
1649 * Returns: size of formatted string.
1652 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1655 struct Scsi_Host *shost = class_to_shost(dev);
1656 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1657 struct lpfc_hba *phba = vport->phba;
1660 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1661 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1662 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1666 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1667 * @dev: class device that is converted into a Scsi_host.
1668 * @attr: device attribute, not used.
1669 * @buf: text that must be interpreted to determine if npiv is supported.
1672 * Buffer will contain text indicating npiv is not suppoerted on the port,
1673 * the port is an NPIV physical port, or it is an npiv virtual port with
1674 * the id of the vport.
1676 * Returns: size of formatted string.
1679 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1682 struct Scsi_Host *shost = class_to_shost(dev);
1683 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1684 struct lpfc_hba *phba = vport->phba;
1686 if (!(phba->max_vpi))
1687 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1688 if (vport->port_type == LPFC_PHYSICAL_PORT)
1689 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1690 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1694 * lpfc_poll_show - Return text about poll support for the adapter
1695 * @dev: class device that is converted into a Scsi_host.
1696 * @attr: device attribute, not used.
1697 * @buf: on return contains the cfg_poll in hex.
1700 * cfg_poll should be a lpfc_polling_flags type.
1702 * Returns: size of formatted string.
1705 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1708 struct Scsi_Host *shost = class_to_shost(dev);
1709 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1710 struct lpfc_hba *phba = vport->phba;
1712 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1716 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1717 * @dev: class device that is converted into a Scsi_host.
1718 * @attr: device attribute, not used.
1719 * @buf: one or more lpfc_polling_flags values.
1723 * buf contents converted to integer and checked for a valid value.
1726 * -EINVAL if the buffer connot be converted or is out of range
1727 * length of the buf on success
1730 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1731 const char *buf, size_t count)
1733 struct Scsi_Host *shost = class_to_shost(dev);
1734 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1735 struct lpfc_hba *phba = vport->phba;
1740 if (!isdigit(buf[0]))
1743 if (sscanf(buf, "%i", &val) != 1)
1746 if ((val & 0x3) != val)
1749 if (phba->sli_rev == LPFC_SLI_REV4)
1752 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1753 "3051 lpfc_poll changed from %d to %d\n",
1754 phba->cfg_poll, val);
1756 spin_lock_irq(&phba->hbalock);
1758 old_val = phba->cfg_poll;
1760 if (val & ENABLE_FCP_RING_POLLING) {
1761 if ((val & DISABLE_FCP_RING_INT) &&
1762 !(old_val & DISABLE_FCP_RING_INT)) {
1763 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1764 spin_unlock_irq(&phba->hbalock);
1767 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1768 writel(creg_val, phba->HCregaddr);
1769 readl(phba->HCregaddr); /* flush */
1771 lpfc_poll_start_timer(phba);
1773 } else if (val != 0x0) {
1774 spin_unlock_irq(&phba->hbalock);
1778 if (!(val & DISABLE_FCP_RING_INT) &&
1779 (old_val & DISABLE_FCP_RING_INT))
1781 spin_unlock_irq(&phba->hbalock);
1782 del_timer(&phba->fcp_poll_timer);
1783 spin_lock_irq(&phba->hbalock);
1784 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1785 spin_unlock_irq(&phba->hbalock);
1788 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1789 writel(creg_val, phba->HCregaddr);
1790 readl(phba->HCregaddr); /* flush */
1793 phba->cfg_poll = val;
1795 spin_unlock_irq(&phba->hbalock);
1801 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1802 * @dev: class unused variable.
1803 * @attr: device attribute, not used.
1804 * @buf: on return contains the module description text.
1806 * Returns: size of formatted string.
1809 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1812 struct Scsi_Host *shost = class_to_shost(dev);
1813 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1814 struct lpfc_hba *phba = vport->phba;
1816 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1820 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1821 * @dev: class unused variable.
1822 * @attr: device attribute, not used.
1823 * @buf: on return contains the module description text.
1825 * Returns: size of formatted string.
1828 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1831 struct Scsi_Host *shost = class_to_shost(dev);
1832 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1833 struct lpfc_hba *phba = vport->phba;
1835 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1839 * lpfc_dss_show - Return the current state of dss and the configured state
1840 * @dev: class converted to a Scsi_host structure.
1841 * @attr: device attribute, not used.
1842 * @buf: on return contains the formatted text.
1844 * Returns: size of formatted string.
1847 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1850 struct Scsi_Host *shost = class_to_shost(dev);
1851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1852 struct lpfc_hba *phba = vport->phba;
1854 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1855 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1856 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1861 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1862 * @dev: class converted to a Scsi_host structure.
1863 * @attr: device attribute, not used.
1864 * @buf: on return contains the formatted support level.
1867 * Returns the maximum number of virtual functions a physical function can
1868 * support, 0 will be returned if called on virtual function.
1870 * Returns: size of formatted string.
1873 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1874 struct device_attribute *attr,
1877 struct Scsi_Host *shost = class_to_shost(dev);
1878 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1879 struct lpfc_hba *phba = vport->phba;
1880 uint16_t max_nr_virtfn;
1882 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1883 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1886 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1888 return val >= min && val <= max;
1892 * lpfc_param_show - Return a cfg attribute value in decimal
1895 * Macro that given an attr e.g. hba_queue_depth expands
1896 * into a function with the name lpfc_hba_queue_depth_show.
1898 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1899 * @dev: class device that is converted into a Scsi_host.
1900 * @attr: device attribute, not used.
1901 * @buf: on return contains the attribute value in decimal.
1903 * Returns: size of formatted string.
1905 #define lpfc_param_show(attr) \
1907 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1910 struct Scsi_Host *shost = class_to_shost(dev);\
1911 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1912 struct lpfc_hba *phba = vport->phba;\
1913 return snprintf(buf, PAGE_SIZE, "%d\n",\
1918 * lpfc_param_hex_show - Return a cfg attribute value in hex
1921 * Macro that given an attr e.g. hba_queue_depth expands
1922 * into a function with the name lpfc_hba_queue_depth_show
1924 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1925 * @dev: class device that is converted into a Scsi_host.
1926 * @attr: device attribute, not used.
1927 * @buf: on return contains the attribute value in hexadecimal.
1929 * Returns: size of formatted string.
1931 #define lpfc_param_hex_show(attr) \
1933 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1936 struct Scsi_Host *shost = class_to_shost(dev);\
1937 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1938 struct lpfc_hba *phba = vport->phba;\
1940 val = phba->cfg_##attr;\
1941 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1946 * lpfc_param_init - Initializes a cfg attribute
1949 * Macro that given an attr e.g. hba_queue_depth expands
1950 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1951 * takes a default argument, a minimum and maximum argument.
1953 * lpfc_##attr##_init: Initializes an attribute.
1954 * @phba: pointer the the adapter structure.
1955 * @val: integer attribute value.
1957 * Validates the min and max values then sets the adapter config field
1958 * accordingly, or uses the default if out of range and prints an error message.
1962 * -EINVAL if default used
1964 #define lpfc_param_init(attr, default, minval, maxval) \
1966 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1968 if (lpfc_rangecheck(val, minval, maxval)) {\
1969 phba->cfg_##attr = val;\
1972 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1973 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1974 "allowed range is ["#minval", "#maxval"]\n", val); \
1975 phba->cfg_##attr = default;\
1980 * lpfc_param_set - Set a cfg attribute value
1983 * Macro that given an attr e.g. hba_queue_depth expands
1984 * into a function with the name lpfc_hba_queue_depth_set
1986 * lpfc_##attr##_set: Sets an attribute value.
1987 * @phba: pointer the the adapter structure.
1988 * @val: integer attribute value.
1991 * Validates the min and max values then sets the
1992 * adapter config field if in the valid range. prints error message
1993 * and does not set the parameter if invalid.
1997 * -EINVAL if val is invalid
1999 #define lpfc_param_set(attr, default, minval, maxval) \
2001 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2003 if (lpfc_rangecheck(val, minval, maxval)) {\
2004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2005 "3052 lpfc_" #attr " changed from %d to %d\n", \
2006 phba->cfg_##attr, val); \
2007 phba->cfg_##attr = val;\
2010 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2011 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2012 "allowed range is ["#minval", "#maxval"]\n", val); \
2017 * lpfc_param_store - Set a vport attribute value
2020 * Macro that given an attr e.g. hba_queue_depth expands
2021 * into a function with the name lpfc_hba_queue_depth_store.
2023 * lpfc_##attr##_store: Set an sttribute value.
2024 * @dev: class device that is converted into a Scsi_host.
2025 * @attr: device attribute, not used.
2026 * @buf: contains the attribute value in ascii.
2030 * Convert the ascii text number to an integer, then
2031 * use the lpfc_##attr##_set function to set the value.
2034 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2035 * length of buffer upon success.
2037 #define lpfc_param_store(attr) \
2039 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2040 const char *buf, size_t count) \
2042 struct Scsi_Host *shost = class_to_shost(dev);\
2043 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2044 struct lpfc_hba *phba = vport->phba;\
2046 if (!isdigit(buf[0]))\
2048 if (sscanf(buf, "%i", &val) != 1)\
2050 if (lpfc_##attr##_set(phba, val) == 0) \
2051 return strlen(buf);\
2057 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2060 * Macro that given an attr e.g. hba_queue_depth expands
2061 * into a function with the name lpfc_hba_queue_depth_show
2063 * lpfc_##attr##_show: prints the attribute value in decimal.
2064 * @dev: class device that is converted into a Scsi_host.
2065 * @attr: device attribute, not used.
2066 * @buf: on return contains the attribute value in decimal.
2068 * Returns: length of formatted string.
2070 #define lpfc_vport_param_show(attr) \
2072 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2075 struct Scsi_Host *shost = class_to_shost(dev);\
2076 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2077 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2081 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2084 * Macro that given an attr e.g.
2085 * hba_queue_depth expands into a function with the name
2086 * lpfc_hba_queue_depth_show
2088 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2089 * @dev: class device that is converted into a Scsi_host.
2090 * @attr: device attribute, not used.
2091 * @buf: on return contains the attribute value in hexadecimal.
2093 * Returns: length of formatted string.
2095 #define lpfc_vport_param_hex_show(attr) \
2097 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2100 struct Scsi_Host *shost = class_to_shost(dev);\
2101 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2102 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2106 * lpfc_vport_param_init - Initialize a vport cfg attribute
2109 * Macro that given an attr e.g. hba_queue_depth expands
2110 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2111 * takes a default argument, a minimum and maximum argument.
2113 * lpfc_##attr##_init: validates the min and max values then sets the
2114 * adapter config field accordingly, or uses the default if out of range
2115 * and prints an error message.
2116 * @phba: pointer the the adapter structure.
2117 * @val: integer attribute value.
2121 * -EINVAL if default used
2123 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2125 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2127 if (lpfc_rangecheck(val, minval, maxval)) {\
2128 vport->cfg_##attr = val;\
2131 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2132 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2133 "allowed range is ["#minval", "#maxval"]\n", val); \
2134 vport->cfg_##attr = default;\
2139 * lpfc_vport_param_set - Set a vport cfg attribute
2142 * Macro that given an attr e.g. hba_queue_depth expands
2143 * into a function with the name lpfc_hba_queue_depth_set
2145 * lpfc_##attr##_set: validates the min and max values then sets the
2146 * adapter config field if in the valid range. prints error message
2147 * and does not set the parameter if invalid.
2148 * @phba: pointer the the adapter structure.
2149 * @val: integer attribute value.
2153 * -EINVAL if val is invalid
2155 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2157 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2159 if (lpfc_rangecheck(val, minval, maxval)) {\
2160 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2161 "3053 lpfc_" #attr \
2162 " changed from %d (x%x) to %d (x%x)\n", \
2163 vport->cfg_##attr, vport->cfg_##attr, \
2165 vport->cfg_##attr = val;\
2168 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2169 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2170 "allowed range is ["#minval", "#maxval"]\n", val); \
2175 * lpfc_vport_param_store - Set a vport attribute
2178 * Macro that given an attr e.g. hba_queue_depth
2179 * expands into a function with the name lpfc_hba_queue_depth_store
2181 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2182 * use the lpfc_##attr##_set function to set the value.
2183 * @cdev: class device that is converted into a Scsi_host.
2184 * @buf: contains the attribute value in decimal.
2188 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2189 * length of buffer upon success.
2191 #define lpfc_vport_param_store(attr) \
2193 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2194 const char *buf, size_t count) \
2196 struct Scsi_Host *shost = class_to_shost(dev);\
2197 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2199 if (!isdigit(buf[0]))\
2201 if (sscanf(buf, "%i", &val) != 1)\
2203 if (lpfc_##attr##_set(vport, val) == 0) \
2204 return strlen(buf);\
2210 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2211 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2212 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2213 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2214 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2215 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2216 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2217 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2218 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2219 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2220 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2221 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2222 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2223 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2224 lpfc_link_state_store);
2225 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2226 lpfc_option_rom_version_show, NULL);
2227 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2228 lpfc_num_discovered_ports_show, NULL);
2229 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2230 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2231 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2232 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2233 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2234 lpfc_board_mode_show, lpfc_board_mode_store);
2235 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2236 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2237 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2238 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2239 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2240 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2241 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2242 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2243 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2244 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2245 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2246 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2247 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2248 lpfc_sriov_hw_max_virtfn_show, NULL);
2249 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2250 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2253 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2256 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2258 * @cnt: Length of string.
2259 * @wwn: Array to receive converted wwn value.
2262 * -EINVAL if the buffer does not contain a valid wwn
2266 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2270 /* Count may include a LF at end of string */
2271 if (buf[cnt-1] == '\n')
2274 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2275 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2278 memset(wwn, 0, WWN_SZ);
2280 /* Validate and store the new name */
2281 for (i = 0, j = 0; i < 16; i++) {
2282 if ((*buf >= 'a') && (*buf <= 'f'))
2283 j = ((j << 4) | ((*buf++ - 'a') + 10));
2284 else if ((*buf >= 'A') && (*buf <= 'F'))
2285 j = ((j << 4) | ((*buf++ - 'A') + 10));
2286 else if ((*buf >= '0') && (*buf <= '9'))
2287 j = ((j << 4) | (*buf++ - '0'));
2291 wwn[i/2] = j & 0xff;
2298 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2299 * @dev: class device that is converted into a Scsi_host.
2300 * @attr: device attribute, not used.
2301 * @buf: containing the string lpfc_soft_wwn_key.
2302 * @count: must be size of lpfc_soft_wwn_key.
2305 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2306 * length of buf indicates success
2309 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2310 const char *buf, size_t count)
2312 struct Scsi_Host *shost = class_to_shost(dev);
2313 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2314 struct lpfc_hba *phba = vport->phba;
2315 unsigned int cnt = count;
2316 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2317 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2320 * We're doing a simple sanity check for soft_wwpn setting.
2321 * We require that the user write a specific key to enable
2322 * the soft_wwpn attribute to be settable. Once the attribute
2323 * is written, the enable key resets. If further updates are
2324 * desired, the key must be written again to re-enable the
2327 * The "key" is not secret - it is a hardcoded string shown
2328 * here. The intent is to protect against the random user or
2329 * application that is just writing attributes.
2331 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2332 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2333 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2334 " be enabled: fawwpn is enabled\n");
2338 /* count may include a LF at end of string */
2339 if (buf[cnt-1] == '\n')
2342 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2343 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2346 phba->soft_wwn_enable = 1;
2348 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2349 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2351 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2352 " The soft_wwpn feature is not supported by Broadcom.");
2356 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2357 lpfc_soft_wwn_enable_store);
2360 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2361 * @dev: class device that is converted into a Scsi_host.
2362 * @attr: device attribute, not used.
2363 * @buf: on return contains the wwpn in hexadecimal.
2365 * Returns: size of formatted string.
2368 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2371 struct Scsi_Host *shost = class_to_shost(dev);
2372 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2373 struct lpfc_hba *phba = vport->phba;
2375 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2376 (unsigned long long)phba->cfg_soft_wwpn);
2380 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2381 * @dev class device that is converted into a Scsi_host.
2382 * @attr: device attribute, not used.
2383 * @buf: contains the wwpn in hexadecimal.
2384 * @count: number of wwpn bytes in buf
2387 * -EACCES hba reset not enabled, adapter over temp
2388 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2389 * -EIO error taking adapter offline or online
2390 * value of count on success
2393 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2394 const char *buf, size_t count)
2396 struct Scsi_Host *shost = class_to_shost(dev);
2397 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2398 struct lpfc_hba *phba = vport->phba;
2399 struct completion online_compl;
2400 int stat1 = 0, stat2 = 0;
2401 unsigned int cnt = count;
2405 if (!phba->cfg_enable_hba_reset)
2407 spin_lock_irq(&phba->hbalock);
2408 if (phba->over_temp_state == HBA_OVER_TEMP) {
2409 spin_unlock_irq(&phba->hbalock);
2412 spin_unlock_irq(&phba->hbalock);
2413 /* count may include a LF at end of string */
2414 if (buf[cnt-1] == '\n')
2417 if (!phba->soft_wwn_enable)
2420 /* lock setting wwpn, wwnn down */
2421 phba->soft_wwn_enable = 0;
2423 rc = lpfc_wwn_set(buf, cnt, wwpn);
2425 /* not able to set wwpn, unlock it */
2426 phba->soft_wwn_enable = 1;
2430 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2431 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2432 if (phba->cfg_soft_wwnn)
2433 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2435 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2436 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2438 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2441 "0463 lpfc_soft_wwpn attribute set failed to "
2442 "reinit adapter - %d\n", stat1);
2443 init_completion(&online_compl);
2444 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2449 wait_for_completion(&online_compl);
2451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2452 "0464 lpfc_soft_wwpn attribute set failed to "
2453 "reinit adapter - %d\n", stat2);
2454 return (stat1 || stat2) ? -EIO : count;
2456 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2457 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2460 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2461 * @dev: class device that is converted into a Scsi_host.
2462 * @attr: device attribute, not used.
2463 * @buf: on return contains the wwnn in hexadecimal.
2465 * Returns: size of formatted string.
2468 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2471 struct Scsi_Host *shost = class_to_shost(dev);
2472 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2473 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2474 (unsigned long long)phba->cfg_soft_wwnn);
2478 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2479 * @cdev: class device that is converted into a Scsi_host.
2480 * @buf: contains the ww node name in hexadecimal.
2481 * @count: number of wwnn bytes in buf.
2484 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2485 * value of count on success
2488 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2489 const char *buf, size_t count)
2491 struct Scsi_Host *shost = class_to_shost(dev);
2492 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2493 unsigned int cnt = count;
2497 /* count may include a LF at end of string */
2498 if (buf[cnt-1] == '\n')
2501 if (!phba->soft_wwn_enable)
2504 rc = lpfc_wwn_set(buf, cnt, wwnn);
2506 /* Allow wwnn to be set many times, as long as the enable
2507 * is set. However, once the wwpn is set, everything locks.
2512 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2514 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2515 "lpfc%d: soft_wwnn set. Value will take effect upon "
2516 "setting of the soft_wwpn\n", phba->brd_no);
2520 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2521 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2524 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2525 * Optimized Access Storage (OAS) operations.
2526 * @dev: class device that is converted into a Scsi_host.
2527 * @attr: device attribute, not used.
2528 * @buf: buffer for passing information.
2534 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2537 struct Scsi_Host *shost = class_to_shost(dev);
2538 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2540 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2541 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2545 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2546 * Optimized Access Storage (OAS) operations.
2547 * @dev: class device that is converted into a Scsi_host.
2548 * @attr: device attribute, not used.
2549 * @buf: buffer for passing information.
2550 * @count: Size of the data buffer.
2553 * -EINVAL count is invalid, invalid wwpn byte invalid
2554 * -EPERM oas is not supported by hba
2555 * value of count on success
2558 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2559 const char *buf, size_t count)
2561 struct Scsi_Host *shost = class_to_shost(dev);
2562 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2563 unsigned int cnt = count;
2564 uint8_t wwpn[WWN_SZ];
2570 /* count may include a LF at end of string */
2571 if (buf[cnt-1] == '\n')
2574 rc = lpfc_wwn_set(buf, cnt, wwpn);
2578 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2579 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2580 if (wwn_to_u64(wwpn) == 0)
2581 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2583 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2584 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2585 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2588 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2589 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2592 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2593 * Optimized Access Storage (OAS) operations.
2594 * @dev: class device that is converted into a Scsi_host.
2595 * @attr: device attribute, not used.
2596 * @buf: buffer for passing information.
2602 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2605 struct Scsi_Host *shost = class_to_shost(dev);
2606 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2608 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2612 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2613 * Optimized Access Storage (OAS) operations.
2614 * @dev: class device that is converted into a Scsi_host.
2615 * @attr: device attribute, not used.
2616 * @buf: buffer for passing information.
2617 * @count: Size of the data buffer.
2620 * -EINVAL count is invalid, invalid wwpn byte invalid
2621 * -EPERM oas is not supported by hba
2622 * value of count on success
2625 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2626 const char *buf, size_t count)
2628 struct Scsi_Host *shost = class_to_shost(dev);
2629 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2630 unsigned int cnt = count;
2637 /* count may include a LF at end of string */
2638 if (buf[cnt-1] == '\n')
2641 ret = kstrtoul(buf, 0, &val);
2642 if (ret || (val > 0x7f))
2646 phba->cfg_oas_priority = (uint8_t)val;
2648 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2651 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2652 lpfc_oas_priority_show, lpfc_oas_priority_store);
2655 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2656 * for Optimized Access Storage (OAS) operations.
2657 * @dev: class device that is converted into a Scsi_host.
2658 * @attr: device attribute, not used.
2659 * @buf: buffer for passing information.
2662 * value of count on success
2665 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2668 struct Scsi_Host *shost = class_to_shost(dev);
2669 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2671 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2672 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2676 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2677 * for Optimized Access Storage (OAS) operations.
2678 * @dev: class device that is converted into a Scsi_host.
2679 * @attr: device attribute, not used.
2680 * @buf: buffer for passing information.
2681 * @count: Size of the data buffer.
2684 * -EINVAL count is invalid, invalid wwpn byte invalid
2685 * -EPERM oas is not supported by hba
2686 * value of count on success
2689 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2690 const char *buf, size_t count)
2692 struct Scsi_Host *shost = class_to_shost(dev);
2693 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2694 unsigned int cnt = count;
2695 uint8_t wwpn[WWN_SZ];
2701 /* count may include a LF at end of string */
2702 if (buf[cnt-1] == '\n')
2705 rc = lpfc_wwn_set(buf, cnt, wwpn);
2709 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2710 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2711 if (wwn_to_u64(wwpn) == 0)
2712 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2714 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2715 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2716 if (phba->cfg_oas_priority == 0)
2717 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2718 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2721 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2722 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2725 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2726 * of whether luns will be enabled or disabled
2727 * for Optimized Access Storage (OAS) operations.
2728 * @dev: class device that is converted into a Scsi_host.
2729 * @attr: device attribute, not used.
2730 * @buf: buffer for passing information.
2733 * size of formatted string.
2736 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2739 struct Scsi_Host *shost = class_to_shost(dev);
2740 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2742 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2746 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2747 * of whether luns will be enabled or disabled
2748 * for Optimized Access Storage (OAS) operations.
2749 * @dev: class device that is converted into a Scsi_host.
2750 * @attr: device attribute, not used.
2751 * @buf: buffer for passing information.
2752 * @count: Size of the data buffer.
2755 * -EINVAL count is invalid, invalid wwpn byte invalid
2756 * -EPERM oas is not supported by hba
2757 * value of count on success
2760 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2761 const char *buf, size_t count)
2763 struct Scsi_Host *shost = class_to_shost(dev);
2764 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2770 if (!isdigit(buf[0]))
2773 if (sscanf(buf, "%i", &val) != 1)
2776 if ((val != 0) && (val != 1))
2779 phba->cfg_oas_lun_state = val;
2782 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2783 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2786 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2787 * Storage (OAS) lun returned by the
2788 * lpfc_oas_lun_show function.
2789 * @dev: class device that is converted into a Scsi_host.
2790 * @attr: device attribute, not used.
2791 * @buf: buffer for passing information.
2794 * size of formatted string.
2797 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2800 struct Scsi_Host *shost = class_to_shost(dev);
2801 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2803 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2806 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2808 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2809 lpfc_oas_lun_status_show, NULL);
2813 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2815 * @phba: lpfc_hba pointer.
2816 * @ndlp: pointer to fcp target node.
2817 * @lun: the fc lun for setting oas state.
2818 * @oas_state: the oas state to be set to the lun.
2822 * -EPERM OAS is not enabled or not supported by this port.
2826 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2827 uint8_t tgt_wwpn[], uint64_t lun,
2828 uint32_t oas_state, uint8_t pri)
2837 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2838 (struct lpfc_name *)tgt_wwpn,
2842 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2843 (struct lpfc_name *)tgt_wwpn, lun, pri);
2850 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2851 * Access Storage (OAS) operations.
2852 * @phba: lpfc_hba pointer.
2853 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2854 * @tgt_wwpn: wwpn of the target associated with the returned lun
2855 * @lun_status: status of the lun returned lun
2857 * Returns the first or next lun enabled for OAS operations for the vport/target
2858 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2859 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2862 * lun that is OAS enabled for the vport/target
2863 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2866 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2867 uint8_t tgt_wwpn[], uint32_t *lun_status,
2872 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2873 return NOT_OAS_ENABLED_LUN;
2874 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2875 phba->sli4_hba.oas_next_vpt_wwpn,
2876 (struct lpfc_name *)
2877 phba->sli4_hba.oas_next_tgt_wwpn,
2878 &phba->sli4_hba.oas_next_lun,
2879 (struct lpfc_name *)vpt_wwpn,
2880 (struct lpfc_name *)tgt_wwpn,
2881 &found_lun, lun_status, lun_pri))
2884 return NOT_OAS_ENABLED_LUN;
2888 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2889 * @phba: lpfc_hba pointer.
2890 * @vpt_wwpn: vport wwpn by reference.
2891 * @tgt_wwpn: target wwpn by reference.
2892 * @lun: the fc lun for setting oas state.
2893 * @oas_state: the oas state to be set to the oas_lun.
2895 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2896 * a lun for OAS operations.
2900 * -ENOMEM: failed to enable an lun for OAS operations
2901 * -EPERM: OAS is not enabled
2904 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2905 uint8_t tgt_wwpn[], uint64_t lun,
2906 uint32_t oas_state, uint8_t pri)
2911 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2917 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2918 * @dev: class device that is converted into a Scsi_host.
2919 * @attr: device attribute, not used.
2920 * @buf: buffer for passing information.
2922 * This routine returns a lun enabled for OAS each time the function
2926 * SUCCESS: size of formatted string.
2927 * -EFAULT: target or vport wwpn was not set properly.
2928 * -EPERM: oas is not enabled.
2931 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2934 struct Scsi_Host *shost = class_to_shost(dev);
2935 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2943 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2944 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2947 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2948 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2951 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2952 phba->cfg_oas_tgt_wwpn,
2953 &phba->cfg_oas_lun_status,
2954 &phba->cfg_oas_priority);
2955 if (oas_lun != NOT_OAS_ENABLED_LUN)
2956 phba->cfg_oas_flags |= OAS_LUN_VALID;
2958 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2964 * lpfc_oas_lun_store - Sets the OAS state for lun
2965 * @dev: class device that is converted into a Scsi_host.
2966 * @attr: device attribute, not used.
2967 * @buf: buffer for passing information.
2969 * This function sets the OAS state for lun. Before this function is called,
2970 * the vport wwpn, target wwpn, and oas state need to be set.
2973 * SUCCESS: size of formatted string.
2974 * -EFAULT: target or vport wwpn was not set properly.
2975 * -EPERM: oas is not enabled.
2976 * size of formatted string.
2979 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2980 const char *buf, size_t count)
2982 struct Scsi_Host *shost = class_to_shost(dev);
2983 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2991 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2994 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2997 if (!isdigit(buf[0]))
3000 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3003 pri = phba->cfg_oas_priority;
3005 pri = phba->cfg_XLanePriority;
3007 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3008 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3009 "priority 0x%x with oas state %d\n",
3010 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3011 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3012 pri, phba->cfg_oas_lun_state);
3014 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3015 phba->cfg_oas_tgt_wwpn, scsi_lun,
3016 phba->cfg_oas_lun_state, pri);
3022 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3023 lpfc_oas_lun_show, lpfc_oas_lun_store);
3025 int lpfc_enable_nvmet_cnt;
3026 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3027 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3028 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3029 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3030 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3032 static int lpfc_poll = 0;
3033 module_param(lpfc_poll, int, S_IRUGO);
3034 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3036 " 1 - poll with interrupts enabled"
3037 " 3 - poll and disable FCP ring interrupts");
3039 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3040 lpfc_poll_show, lpfc_poll_store);
3042 int lpfc_no_hba_reset_cnt;
3043 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3044 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3045 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3046 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3048 LPFC_ATTR(sli_mode, 0, 0, 3,
3049 "SLI mode selector:"
3050 " 0 - auto (SLI-3 if supported),"
3051 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3052 " 3 - select SLI-3");
3054 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3055 "Enable NPIV functionality");
3057 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3058 "FCF Fast failover=1 Priority failover=2");
3061 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3062 # 0x0 = disabled, XRI/OXID use not tracked.
3063 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3064 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3066 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3067 "Enable RRQ functionality");
3070 # lpfc_suppress_link_up: Bring link up at initialization
3071 # 0x0 = bring link up (issue MBX_INIT_LINK)
3072 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3073 # 0x2 = never bring up link
3074 # Default value is 0.
3076 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3077 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3078 "Suppress Link Up at initialization");
3080 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3088 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3090 struct Scsi_Host *shost = class_to_shost(dev);
3091 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3093 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3096 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3097 lpfc_iocb_hw_show, NULL);
3099 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3101 struct Scsi_Host *shost = class_to_shost(dev);
3102 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3103 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3105 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
3108 static DEVICE_ATTR(txq_hw, S_IRUGO,
3109 lpfc_txq_hw_show, NULL);
3111 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3114 struct Scsi_Host *shost = class_to_shost(dev);
3115 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3116 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3118 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
3121 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3122 lpfc_txcmplq_hw_show, NULL);
3124 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3125 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3128 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3129 # until the timer expires. Value range is [0,255]. Default value is 30.
3131 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3132 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3133 module_param(lpfc_nodev_tmo, int, 0);
3134 MODULE_PARM_DESC(lpfc_nodev_tmo,
3135 "Seconds driver will hold I/O waiting "
3136 "for a device to come back");
3139 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3140 * @dev: class converted to a Scsi_host structure.
3141 * @attr: device attribute, not used.
3142 * @buf: on return contains the dev loss timeout in decimal.
3144 * Returns: size of formatted string.
3147 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3150 struct Scsi_Host *shost = class_to_shost(dev);
3151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3153 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3157 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3158 * @vport: lpfc vport structure pointer.
3159 * @val: contains the nodev timeout value.
3162 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3163 * a kernel error message is printed and zero is returned.
3164 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3165 * Otherwise nodev tmo is set to the default value.
3168 * zero if already set or if val is in range
3169 * -EINVAL val out of range
3172 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3174 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3175 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3176 if (val != LPFC_DEF_DEVLOSS_TMO)
3177 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3178 "0407 Ignoring lpfc_nodev_tmo module "
3179 "parameter because lpfc_devloss_tmo "
3184 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3185 vport->cfg_nodev_tmo = val;
3186 vport->cfg_devloss_tmo = val;
3189 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3190 "0400 lpfc_nodev_tmo attribute cannot be set to"
3191 " %d, allowed range is [%d, %d]\n",
3192 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3193 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3198 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3199 * @vport: lpfc vport structure pointer.
3202 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3205 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3207 struct Scsi_Host *shost;
3208 struct lpfc_nodelist *ndlp;
3210 shost = lpfc_shost_from_vport(vport);
3211 spin_lock_irq(shost->host_lock);
3212 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3213 if (!NLP_CHK_NODE_ACT(ndlp))
3216 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3218 spin_unlock_irq(shost->host_lock);
3222 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3223 * @vport: lpfc vport structure pointer.
3224 * @val: contains the tmo value.
3227 * If the devloss tmo is already set or the vport dev loss tmo has changed
3228 * then a kernel error message is printed and zero is returned.
3229 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3230 * Otherwise nodev tmo is set to the default value.
3233 * zero if already set or if val is in range
3234 * -EINVAL val out of range
3237 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3239 if (vport->dev_loss_tmo_changed ||
3240 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3241 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3242 "0401 Ignoring change to lpfc_nodev_tmo "
3243 "because lpfc_devloss_tmo is set.\n");
3246 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3247 vport->cfg_nodev_tmo = val;
3248 vport->cfg_devloss_tmo = val;
3250 * For compat: set the fc_host dev loss so new rports
3251 * will get the value.
3253 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3254 lpfc_update_rport_devloss_tmo(vport);
3257 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3258 "0403 lpfc_nodev_tmo attribute cannot be set to "
3259 "%d, allowed range is [%d, %d]\n",
3260 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3264 lpfc_vport_param_store(nodev_tmo)
3266 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3267 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3270 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3271 # disappear until the timer expires. Value range is [0,255]. Default
3274 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3275 MODULE_PARM_DESC(lpfc_devloss_tmo,
3276 "Seconds driver will hold I/O waiting "
3277 "for a device to come back");
3278 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3279 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3280 lpfc_vport_param_show(devloss_tmo)
3283 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3284 * @vport: lpfc vport structure pointer.
3285 * @val: contains the tmo value.
3288 * If val is in a valid range then set the vport nodev tmo,
3289 * devloss tmo, also set the vport dev loss tmo changed flag.
3290 * Else a kernel error message is printed.
3293 * zero if val is in range
3294 * -EINVAL val out of range
3297 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3299 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3300 vport->cfg_nodev_tmo = val;
3301 vport->cfg_devloss_tmo = val;
3302 vport->dev_loss_tmo_changed = 1;
3303 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3304 lpfc_update_rport_devloss_tmo(vport);
3308 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3309 "0404 lpfc_devloss_tmo attribute cannot be set to "
3310 "%d, allowed range is [%d, %d]\n",
3311 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3315 lpfc_vport_param_store(devloss_tmo)
3316 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3317 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3320 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3321 * lpfc_suppress_rsp = 0 Disable
3322 * lpfc_suppress_rsp = 1 Enable (default)
3325 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3326 "Enable suppress rsp feature is firmware supports it");
3329 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3330 * lpfc_nvmet_mrq = 1 use a single RQ pair
3331 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3334 LPFC_ATTR_R(nvmet_mrq,
3336 "Specify number of RQ pairs for processing NVMET cmds");
3339 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3340 * Supported Values: 1 - register just FCP
3341 * 3 - register both FCP and NVME
3342 * Supported values are [1,3]. Default value is 1
3344 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3345 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3346 "Define fc4 type to register with fabric.");
3349 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3350 * This parameter is only used if:
3351 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3352 * port is not configured for NVMET.
3354 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3355 * The remaining XRIs get split up based on lpfc_xri_split per port:
3357 * Supported Values are in percentages
3358 * the xri_split value is the percentage the SCSI port will get. The remaining
3359 * percentage will go to NVME.
3361 LPFC_ATTR_R(xri_split, 50, 10, 90,
3362 "Division of XRI resources between SCSI and NVME");
3365 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3366 # deluged with LOTS of information.
3367 # You can set a bit mask to record specific types of verbose messages:
3368 # See lpfc_logmsh.h for definitions.
3370 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3371 "Verbose logging bit-mask");
3374 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3375 # objects that have been registered with the nameserver after login.
3377 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3378 "Deregister nameserver objects before LOGO");
3381 # lun_queue_depth: This parameter is used to limit the number of outstanding
3382 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3383 # If this parameter value is greater than 1/8th the maximum number of exchanges
3384 # supported by the HBA port, then the lun queue depth will be reduced to
3385 # 1/8th the maximum number of exchanges.
3387 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3388 "Max number of FCP commands we can queue to a specific LUN");
3391 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3392 # commands per target port. Value range is [10,65535]. Default value is 65535.
3394 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3395 "Max number of FCP commands we can queue to a specific target port");
3398 # hba_queue_depth: This parameter is used to limit the number of outstanding
3399 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3400 # value is greater than the maximum number of exchanges supported by the HBA,
3401 # then maximum number of exchanges supported by the HBA is used to determine
3402 # the hba_queue_depth.
3404 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3405 "Max number of FCP commands we can queue to a lpfc HBA");
3408 # peer_port_login: This parameter allows/prevents logins
3409 # between peer ports hosted on the same physical port.
3410 # When this parameter is set 0 peer ports of same physical port
3411 # are not allowed to login to each other.
3412 # When this parameter is set 1 peer ports of same physical port
3413 # are allowed to login to each other.
3414 # Default value of this parameter is 0.
3416 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3417 "Allow peer ports on the same physical port to login to each "
3421 # restrict_login: This parameter allows/prevents logins
3422 # between Virtual Ports and remote initiators.
3423 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3424 # other initiators and will attempt to PLOGI all remote ports.
3425 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3426 # remote ports and will not attempt to PLOGI to other initiators.
3427 # This parameter does not restrict to the physical port.
3428 # This parameter does not restrict logins to Fabric resident remote ports.
3429 # Default value of this parameter is 1.
3431 static int lpfc_restrict_login = 1;
3432 module_param(lpfc_restrict_login, int, S_IRUGO);
3433 MODULE_PARM_DESC(lpfc_restrict_login,
3434 "Restrict virtual ports login to remote initiators.");
3435 lpfc_vport_param_show(restrict_login);
3438 * lpfc_restrict_login_init - Set the vport restrict login flag
3439 * @vport: lpfc vport structure pointer.
3440 * @val: contains the restrict login value.
3443 * If val is not in a valid range then log a kernel error message and set
3444 * the vport restrict login to one.
3445 * If the port type is physical clear the restrict login flag and return.
3446 * Else set the restrict login flag to val.
3449 * zero if val is in range
3450 * -EINVAL val out of range
3453 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3455 if (val < 0 || val > 1) {
3456 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3457 "0422 lpfc_restrict_login attribute cannot "
3458 "be set to %d, allowed range is [0, 1]\n",
3460 vport->cfg_restrict_login = 1;
3463 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3464 vport->cfg_restrict_login = 0;
3467 vport->cfg_restrict_login = val;
3472 * lpfc_restrict_login_set - Set the vport restrict login flag
3473 * @vport: lpfc vport structure pointer.
3474 * @val: contains the restrict login value.
3477 * If val is not in a valid range then log a kernel error message and set
3478 * the vport restrict login to one.
3479 * If the port type is physical and the val is not zero log a kernel
3480 * error message, clear the restrict login flag and return zero.
3481 * Else set the restrict login flag to val.
3484 * zero if val is in range
3485 * -EINVAL val out of range
3488 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3490 if (val < 0 || val > 1) {
3491 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3492 "0425 lpfc_restrict_login attribute cannot "
3493 "be set to %d, allowed range is [0, 1]\n",
3495 vport->cfg_restrict_login = 1;
3498 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3499 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3500 "0468 lpfc_restrict_login must be 0 for "
3501 "Physical ports.\n");
3502 vport->cfg_restrict_login = 0;
3505 vport->cfg_restrict_login = val;
3508 lpfc_vport_param_store(restrict_login);
3509 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3510 lpfc_restrict_login_show, lpfc_restrict_login_store);
3513 # Some disk devices have a "select ID" or "select Target" capability.
3514 # From a protocol standpoint "select ID" usually means select the
3515 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3516 # annex" which contains a table that maps a "select ID" (a number
3517 # between 0 and 7F) to an ALPA. By default, for compatibility with
3518 # older drivers, the lpfc driver scans this table from low ALPA to high
3521 # Turning on the scan-down variable (on = 1, off = 0) will
3522 # cause the lpfc driver to use an inverted table, effectively
3523 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3525 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3526 # and will not work across a fabric. Also this parameter will take
3527 # effect only in the case when ALPA map is not available.)
3529 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3530 "Start scanning for devices from highest ALPA to lowest");
3533 # lpfc_topology: link topology for init link
3534 # 0x0 = attempt loop mode then point-to-point
3535 # 0x01 = internal loopback mode
3536 # 0x02 = attempt point-to-point mode only
3537 # 0x04 = attempt loop mode only
3538 # 0x06 = attempt point-to-point mode then loop
3539 # Set point-to-point mode if you want to run as an N_Port.
3540 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3541 # Default value is 0.
3543 LPFC_ATTR(topology, 0, 0, 6,
3544 "Select Fibre Channel topology");
3547 * lpfc_topology_set - Set the adapters topology field
3548 * @phba: lpfc_hba pointer.
3549 * @val: topology value.
3552 * If val is in a valid range then set the adapter's topology field and
3553 * issue a lip; if the lip fails reset the topology to the old value.
3555 * If the value is not in range log a kernel error message and return an error.
3558 * zero if val is in range and lip okay
3559 * non-zero return value from lpfc_issue_lip()
3560 * -EINVAL val out of range
3563 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3564 const char *buf, size_t count)
3566 struct Scsi_Host *shost = class_to_shost(dev);
3567 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3568 struct lpfc_hba *phba = vport->phba;
3571 const char *val_buf = buf;
3575 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3577 val_buf = &buf[strlen("nolip ")];
3580 if (!isdigit(val_buf[0]))
3582 if (sscanf(val_buf, "%i", &val) != 1)
3585 if (val >= 0 && val <= 6) {
3586 prev_val = phba->cfg_topology;
3587 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3589 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3590 "3113 Loop mode not supported at speed %d\n",
3594 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3596 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3597 "3114 Loop mode not supported\n");
3600 phba->cfg_topology = val;
3604 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3605 "3054 lpfc_topology changed from %d to %d\n",
3607 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3608 phba->fc_topology_changed = 1;
3609 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3611 phba->cfg_topology = prev_val;
3616 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3617 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3618 "allowed range is [0, 6]\n",
3623 lpfc_param_show(topology)
3624 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3625 lpfc_topology_show, lpfc_topology_store);
3628 * lpfc_static_vport_show: Read callback function for
3629 * lpfc_static_vport sysfs file.
3630 * @dev: Pointer to class device object.
3631 * @attr: device attribute structure.
3632 * @buf: Data buffer.
3634 * This function is the read call back function for
3635 * lpfc_static_vport sysfs file. The lpfc_static_vport
3636 * sysfs file report the mageability of the vport.
3639 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3642 struct Scsi_Host *shost = class_to_shost(dev);
3643 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3644 if (vport->vport_flag & STATIC_VPORT)
3645 sprintf(buf, "1\n");
3647 sprintf(buf, "0\n");
3653 * Sysfs attribute to control the statistical data collection.
3655 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3656 lpfc_static_vport_show, NULL);
3659 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3660 * @dev: Pointer to class device.
3661 * @buf: Data buffer.
3662 * @count: Size of the data buffer.
3664 * This function get called when a user write to the lpfc_stat_data_ctrl
3665 * sysfs file. This function parse the command written to the sysfs file
3666 * and take appropriate action. These commands are used for controlling
3667 * driver statistical data collection.
3668 * Following are the command this function handles.
3670 * setbucket <bucket_type> <base> <step>
3671 * = Set the latency buckets.
3672 * destroybucket = destroy all the buckets.
3673 * start = start data collection
3674 * stop = stop data collection
3675 * reset = reset the collected data
3678 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3679 const char *buf, size_t count)
3681 struct Scsi_Host *shost = class_to_shost(dev);
3682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3683 struct lpfc_hba *phba = vport->phba;
3684 #define LPFC_MAX_DATA_CTRL_LEN 1024
3685 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3687 char *str_ptr, *token;
3688 struct lpfc_vport **vports;
3689 struct Scsi_Host *v_shost;
3690 char *bucket_type_str, *base_str, *step_str;
3691 unsigned long base, step, bucket_type;
3693 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3694 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3697 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3698 str_ptr = &bucket_data[0];
3699 /* Ignore this token - this is command token */
3700 token = strsep(&str_ptr, "\t ");
3704 bucket_type_str = strsep(&str_ptr, "\t ");
3705 if (!bucket_type_str)
3708 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3709 bucket_type = LPFC_LINEAR_BUCKET;
3710 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3711 bucket_type = LPFC_POWER2_BUCKET;
3715 base_str = strsep(&str_ptr, "\t ");
3718 base = simple_strtoul(base_str, NULL, 0);
3720 step_str = strsep(&str_ptr, "\t ");
3723 step = simple_strtoul(step_str, NULL, 0);
3727 /* Block the data collection for every vport */
3728 vports = lpfc_create_vport_work_array(phba);
3732 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3733 v_shost = lpfc_shost_from_vport(vports[i]);
3734 spin_lock_irq(v_shost->host_lock);
3735 /* Block and reset data collection */
3736 vports[i]->stat_data_blocked = 1;
3737 if (vports[i]->stat_data_enabled)
3738 lpfc_vport_reset_stat_data(vports[i]);
3739 spin_unlock_irq(v_shost->host_lock);
3742 /* Set the bucket attributes */
3743 phba->bucket_type = bucket_type;
3744 phba->bucket_base = base;
3745 phba->bucket_step = step;
3747 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3748 v_shost = lpfc_shost_from_vport(vports[i]);
3750 /* Unblock data collection */
3751 spin_lock_irq(v_shost->host_lock);
3752 vports[i]->stat_data_blocked = 0;
3753 spin_unlock_irq(v_shost->host_lock);
3755 lpfc_destroy_vport_work_array(phba, vports);
3759 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3760 vports = lpfc_create_vport_work_array(phba);
3764 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3765 v_shost = lpfc_shost_from_vport(vports[i]);
3766 spin_lock_irq(shost->host_lock);
3767 vports[i]->stat_data_blocked = 1;
3768 lpfc_free_bucket(vport);
3769 vport->stat_data_enabled = 0;
3770 vports[i]->stat_data_blocked = 0;
3771 spin_unlock_irq(shost->host_lock);
3773 lpfc_destroy_vport_work_array(phba, vports);
3774 phba->bucket_type = LPFC_NO_BUCKET;
3775 phba->bucket_base = 0;
3776 phba->bucket_step = 0;
3780 if (!strncmp(buf, "start", strlen("start"))) {
3781 /* If no buckets configured return error */
3782 if (phba->bucket_type == LPFC_NO_BUCKET)
3784 spin_lock_irq(shost->host_lock);
3785 if (vport->stat_data_enabled) {
3786 spin_unlock_irq(shost->host_lock);
3789 lpfc_alloc_bucket(vport);
3790 vport->stat_data_enabled = 1;
3791 spin_unlock_irq(shost->host_lock);
3795 if (!strncmp(buf, "stop", strlen("stop"))) {
3796 spin_lock_irq(shost->host_lock);
3797 if (vport->stat_data_enabled == 0) {
3798 spin_unlock_irq(shost->host_lock);
3801 lpfc_free_bucket(vport);
3802 vport->stat_data_enabled = 0;
3803 spin_unlock_irq(shost->host_lock);
3807 if (!strncmp(buf, "reset", strlen("reset"))) {
3808 if ((phba->bucket_type == LPFC_NO_BUCKET)
3809 || !vport->stat_data_enabled)
3811 spin_lock_irq(shost->host_lock);
3812 vport->stat_data_blocked = 1;
3813 lpfc_vport_reset_stat_data(vport);
3814 vport->stat_data_blocked = 0;
3815 spin_unlock_irq(shost->host_lock);
3823 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3824 * @dev: Pointer to class device object.
3825 * @buf: Data buffer.
3827 * This function is the read call back function for
3828 * lpfc_stat_data_ctrl sysfs file. This function report the
3829 * current statistical data collection state.
3832 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3835 struct Scsi_Host *shost = class_to_shost(dev);
3836 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3837 struct lpfc_hba *phba = vport->phba;
3841 unsigned long bucket_value;
3843 switch (phba->bucket_type) {
3844 case LPFC_LINEAR_BUCKET:
3845 bucket_type = "linear";
3847 case LPFC_POWER2_BUCKET:
3848 bucket_type = "power2";
3851 bucket_type = "No Bucket";
3855 sprintf(&buf[index], "Statistical Data enabled :%d, "
3856 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3857 " Bucket step :%d\nLatency Ranges :",
3858 vport->stat_data_enabled, vport->stat_data_blocked,
3859 bucket_type, phba->bucket_base, phba->bucket_step);
3860 index = strlen(buf);
3861 if (phba->bucket_type != LPFC_NO_BUCKET) {
3862 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3863 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3864 bucket_value = phba->bucket_base +
3865 phba->bucket_step * i;
3867 bucket_value = phba->bucket_base +
3868 (1 << i) * phba->bucket_step;
3870 if (index + 10 > PAGE_SIZE)
3872 sprintf(&buf[index], "%08ld ", bucket_value);
3873 index = strlen(buf);
3876 sprintf(&buf[index], "\n");
3881 * Sysfs attribute to control the statistical data collection.
3883 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3884 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3887 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3891 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3894 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3895 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3896 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3900 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3902 * @kobj: Pointer to the kernel object
3903 * @bin_attr: Attribute object
3904 * @buff: Buffer pointer
3906 * @count: Buffer size
3908 * This function is the read call back function for lpfc_drvr_stat_data
3909 * sysfs file. This function export the statistical data to user
3913 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3914 struct bin_attribute *bin_attr,
3915 char *buf, loff_t off, size_t count)
3917 struct device *dev = container_of(kobj, struct device,
3919 struct Scsi_Host *shost = class_to_shost(dev);
3920 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3921 struct lpfc_hba *phba = vport->phba;
3922 int i = 0, index = 0;
3923 unsigned long nport_index;
3924 struct lpfc_nodelist *ndlp = NULL;
3925 nport_index = (unsigned long)off /
3926 MAX_STAT_DATA_SIZE_PER_TARGET;
3928 if (!vport->stat_data_enabled || vport->stat_data_blocked
3929 || (phba->bucket_type == LPFC_NO_BUCKET))
3932 spin_lock_irq(shost->host_lock);
3933 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3934 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3937 if (nport_index > 0) {
3942 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3946 if (!ndlp->lat_data)
3950 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3951 ndlp->nlp_portname.u.wwn[0],
3952 ndlp->nlp_portname.u.wwn[1],
3953 ndlp->nlp_portname.u.wwn[2],
3954 ndlp->nlp_portname.u.wwn[3],
3955 ndlp->nlp_portname.u.wwn[4],
3956 ndlp->nlp_portname.u.wwn[5],
3957 ndlp->nlp_portname.u.wwn[6],
3958 ndlp->nlp_portname.u.wwn[7]);
3960 index = strlen(buf);
3962 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3963 sprintf(&buf[index], "%010u,",
3964 ndlp->lat_data[i].cmd_count);
3965 index = strlen(buf);
3967 sprintf(&buf[index], "\n");
3968 index = strlen(buf);
3970 spin_unlock_irq(shost->host_lock);
3974 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3976 .name = "lpfc_drvr_stat_data",
3979 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3980 .read = sysfs_drvr_stat_data_read,
3985 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3987 # Value range is [0,16]. Default value is 0.
3990 * lpfc_link_speed_set - Set the adapters link speed
3991 * @phba: lpfc_hba pointer.
3992 * @val: link speed value.
3995 * If val is in a valid range then set the adapter's link speed field and
3996 * issue a lip; if the lip fails reset the link speed to the old value.
3999 * If the value is not in range log a kernel error message and return an error.
4002 * zero if val is in range and lip okay.
4003 * non-zero return value from lpfc_issue_lip()
4004 * -EINVAL val out of range
4007 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4008 const char *buf, size_t count)
4010 struct Scsi_Host *shost = class_to_shost(dev);
4011 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4012 struct lpfc_hba *phba = vport->phba;
4013 int val = LPFC_USER_LINK_SPEED_AUTO;
4015 const char *val_buf = buf;
4017 uint32_t prev_val, if_type;
4019 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4020 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4021 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4024 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4026 val_buf = &buf[strlen("nolip ")];
4029 if (!isdigit(val_buf[0]))
4031 if (sscanf(val_buf, "%i", &val) != 1)
4034 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4035 "3055 lpfc_link_speed changed from %d to %d %s\n",
4036 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4038 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4039 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4040 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4041 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4042 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4043 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4044 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
4045 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4046 "2879 lpfc_link_speed attribute cannot be set "
4047 "to %d. Speed is not supported by this port.\n",
4051 if (val == LPFC_USER_LINK_SPEED_16G &&
4052 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4053 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4054 "3112 lpfc_link_speed attribute cannot be set "
4055 "to %d. Speed is not supported in loop mode.\n",
4059 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4060 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4061 prev_val = phba->cfg_link_speed;
4062 phba->cfg_link_speed = val;
4066 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4068 phba->cfg_link_speed = prev_val;
4073 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4074 "0469 lpfc_link_speed attribute cannot be set to %d, "
4075 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
4079 static int lpfc_link_speed = 0;
4080 module_param(lpfc_link_speed, int, S_IRUGO);
4081 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4082 lpfc_param_show(link_speed)
4085 * lpfc_link_speed_init - Set the adapters link speed
4086 * @phba: lpfc_hba pointer.
4087 * @val: link speed value.
4090 * If val is in a valid range then set the adapter's link speed field.
4093 * If the value is not in range log a kernel error message, clear the link
4094 * speed and return an error.
4097 * zero if val saved.
4098 * -EINVAL val out of range
4101 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4103 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4104 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4105 "3111 lpfc_link_speed of %d cannot "
4106 "support loop mode, setting topology to default.\n",
4108 phba->cfg_topology = 0;
4110 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4111 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4112 phba->cfg_link_speed = val;
4115 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4116 "0405 lpfc_link_speed attribute cannot "
4117 "be set to %d, allowed values are "
4118 "["LPFC_LINK_SPEED_STRING"]\n", val);
4119 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4123 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
4124 lpfc_link_speed_show, lpfc_link_speed_store);
4127 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4128 # 0 = aer disabled or not supported
4129 # 1 = aer supported and enabled (default)
4130 # Value range is [0,1]. Default value is 1.
4132 LPFC_ATTR(aer_support, 1, 0, 1,
4133 "Enable PCIe device AER support");
4134 lpfc_param_show(aer_support)
4137 * lpfc_aer_support_store - Set the adapter for aer support
4139 * @dev: class device that is converted into a Scsi_host.
4140 * @attr: device attribute, not used.
4141 * @buf: containing enable or disable aer flag.
4142 * @count: unused variable.
4145 * If the val is 1 and currently the device's AER capability was not
4146 * enabled, invoke the kernel's enable AER helper routine, trying to
4147 * enable the device's AER capability. If the helper routine enabling
4148 * AER returns success, update the device's cfg_aer_support flag to
4149 * indicate AER is supported by the device; otherwise, if the device
4150 * AER capability is already enabled to support AER, then do nothing.
4152 * If the val is 0 and currently the device's AER support was enabled,
4153 * invoke the kernel's disable AER helper routine. After that, update
4154 * the device's cfg_aer_support flag to indicate AER is not supported
4155 * by the device; otherwise, if the device AER capability is already
4156 * disabled from supporting AER, then do nothing.
4159 * length of the buf on success if val is in range the intended mode
4161 * -EINVAL if val out of range or intended mode is not supported.
4164 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4165 const char *buf, size_t count)
4167 struct Scsi_Host *shost = class_to_shost(dev);
4168 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4169 struct lpfc_hba *phba = vport->phba;
4170 int val = 0, rc = -EINVAL;
4172 if (!isdigit(buf[0]))
4174 if (sscanf(buf, "%i", &val) != 1)
4179 if (phba->hba_flag & HBA_AER_ENABLED) {
4180 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4182 spin_lock_irq(&phba->hbalock);
4183 phba->hba_flag &= ~HBA_AER_ENABLED;
4184 spin_unlock_irq(&phba->hbalock);
4185 phba->cfg_aer_support = 0;
4190 phba->cfg_aer_support = 0;
4195 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4196 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4198 spin_lock_irq(&phba->hbalock);
4199 phba->hba_flag |= HBA_AER_ENABLED;
4200 spin_unlock_irq(&phba->hbalock);
4201 phba->cfg_aer_support = 1;
4206 phba->cfg_aer_support = 1;
4217 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4218 lpfc_aer_support_show, lpfc_aer_support_store);
4221 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4222 * @dev: class device that is converted into a Scsi_host.
4223 * @attr: device attribute, not used.
4224 * @buf: containing flag 1 for aer cleanup state.
4225 * @count: unused variable.
4228 * If the @buf contains 1 and the device currently has the AER support
4229 * enabled, then invokes the kernel AER helper routine
4230 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4231 * error status register.
4236 * -EINVAL if the buf does not contain the 1 or the device is not currently
4237 * enabled with the AER support.
4240 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4241 const char *buf, size_t count)
4243 struct Scsi_Host *shost = class_to_shost(dev);
4244 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4245 struct lpfc_hba *phba = vport->phba;
4248 if (!isdigit(buf[0]))
4250 if (sscanf(buf, "%i", &val) != 1)
4255 if (phba->hba_flag & HBA_AER_ENABLED)
4256 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4264 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4265 lpfc_aer_cleanup_state);
4268 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4270 * @dev: class device that is converted into a Scsi_host.
4271 * @attr: device attribute, not used.
4272 * @buf: containing the string the number of vfs to be enabled.
4273 * @count: unused variable.
4276 * When this api is called either through user sysfs, the driver shall
4277 * try to enable or disable SR-IOV virtual functions according to the
4280 * If zero virtual function has been enabled to the physical function,
4281 * the driver shall invoke the pci enable virtual function api trying
4282 * to enable the virtual functions. If the nr_vfn provided is greater
4283 * than the maximum supported, the maximum virtual function number will
4284 * be used for invoking the api; otherwise, the nr_vfn provided shall
4285 * be used for invoking the api. If the api call returned success, the
4286 * actual number of virtual functions enabled will be set to the driver
4287 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4288 * cfg_sriov_nr_virtfn remains zero.
4290 * If none-zero virtual functions have already been enabled to the
4291 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4292 * -EINVAL will be returned and the driver does nothing;
4294 * If the nr_vfn provided is zero and none-zero virtual functions have
4295 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4296 * disabling virtual function api shall be invoded to disable all the
4297 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4298 * zero. Otherwise, if zero virtual function has been enabled, do
4302 * length of the buf on success if val is in range the intended mode
4304 * -EINVAL if val out of range or intended mode is not supported.
4307 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4308 const char *buf, size_t count)
4310 struct Scsi_Host *shost = class_to_shost(dev);
4311 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4312 struct lpfc_hba *phba = vport->phba;
4313 struct pci_dev *pdev = phba->pcidev;
4314 int val = 0, rc = -EINVAL;
4316 /* Sanity check on user data */
4317 if (!isdigit(buf[0]))
4319 if (sscanf(buf, "%i", &val) != 1)
4324 /* Request disabling virtual functions */
4326 if (phba->cfg_sriov_nr_virtfn > 0) {
4327 pci_disable_sriov(pdev);
4328 phba->cfg_sriov_nr_virtfn = 0;
4333 /* Request enabling virtual functions */
4334 if (phba->cfg_sriov_nr_virtfn > 0) {
4335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4336 "3018 There are %d virtual functions "
4337 "enabled on physical function.\n",
4338 phba->cfg_sriov_nr_virtfn);
4342 if (val <= LPFC_MAX_VFN_PER_PFN)
4343 phba->cfg_sriov_nr_virtfn = val;
4345 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4346 "3019 Enabling %d virtual functions is not "
4351 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4353 phba->cfg_sriov_nr_virtfn = 0;
4361 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4362 "Enable PCIe device SR-IOV virtual fn");
4364 lpfc_param_show(sriov_nr_virtfn)
4365 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4366 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4369 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4371 * @dev: class device that is converted into a Scsi_host.
4372 * @attr: device attribute, not used.
4373 * @buf: containing the string the number of vfs to be enabled.
4374 * @count: unused variable.
4379 * length of the buf on success if val is in range the intended mode
4381 * -EINVAL if val out of range or intended mode is not supported.
4384 lpfc_request_firmware_upgrade_store(struct device *dev,
4385 struct device_attribute *attr,
4386 const char *buf, size_t count)
4388 struct Scsi_Host *shost = class_to_shost(dev);
4389 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4390 struct lpfc_hba *phba = vport->phba;
4391 int val = 0, rc = -EINVAL;
4393 /* Sanity check on user data */
4394 if (!isdigit(buf[0]))
4396 if (sscanf(buf, "%i", &val) != 1)
4401 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4409 static int lpfc_req_fw_upgrade;
4410 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4411 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4412 lpfc_param_show(request_firmware_upgrade)
4415 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4416 * @phba: lpfc_hba pointer.
4420 * Set the initial Linux generic firmware upgrade enable or disable flag.
4423 * zero if val saved.
4424 * -EINVAL val out of range
4427 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4429 if (val >= 0 && val <= 1) {
4430 phba->cfg_request_firmware_upgrade = val;
4435 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4436 lpfc_request_firmware_upgrade_show,
4437 lpfc_request_firmware_upgrade_store);
4440 * lpfc_fcp_imax_store
4442 * @dev: class device that is converted into a Scsi_host.
4443 * @attr: device attribute, not used.
4444 * @buf: string with the number of fast-path FCP interrupts per second.
4445 * @count: unused variable.
4448 * If val is in a valid range [636,651042], then set the adapter's
4449 * maximum number of fast-path FCP interrupts per second.
4452 * length of the buf on success if val is in range the intended mode
4454 * -EINVAL if val out of range or intended mode is not supported.
4457 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4458 const char *buf, size_t count)
4460 struct Scsi_Host *shost = class_to_shost(dev);
4461 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4462 struct lpfc_hba *phba = vport->phba;
4465 /* fcp_imax is only valid for SLI4 */
4466 if (phba->sli_rev != LPFC_SLI_REV4)
4469 /* Sanity check on user data */
4470 if (!isdigit(buf[0]))
4472 if (sscanf(buf, "%i", &val) != 1)
4476 * Value range for the HBA is [5000,5000000]
4477 * The value for each EQ depends on how many EQs are configured.
4480 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4483 phba->cfg_fcp_imax = (uint32_t)val;
4485 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4486 lpfc_modify_hba_eq_delay(phba, i);
4492 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4495 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4497 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4498 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4499 MODULE_PARM_DESC(lpfc_fcp_imax,
4500 "Set the maximum number of FCP interrupts per second per HBA");
4501 lpfc_param_show(fcp_imax)
4504 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4505 * @phba: lpfc_hba pointer.
4506 * @val: link speed value.
4509 * If val is in a valid range [636,651042], then initialize the adapter's
4510 * maximum number of fast-path FCP interrupts per second.
4513 * zero if val saved.
4514 * -EINVAL val out of range
4517 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4519 if (phba->sli_rev != LPFC_SLI_REV4) {
4520 phba->cfg_fcp_imax = 0;
4524 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4526 phba->cfg_fcp_imax = val;
4530 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4531 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4533 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4538 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4539 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4542 * lpfc_state_show - Display current driver CPU affinity
4543 * @dev: class converted to a Scsi_host structure.
4544 * @attr: device attribute, not used.
4545 * @buf: on return contains text describing the state of the link.
4547 * Returns: size of formatted string.
4550 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4553 struct Scsi_Host *shost = class_to_shost(dev);
4554 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4555 struct lpfc_hba *phba = vport->phba;
4556 struct lpfc_vector_map_info *cpup;
4559 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4560 (phba->intr_type != MSIX))
4563 switch (phba->cfg_fcp_cpu_map) {
4565 len += snprintf(buf + len, PAGE_SIZE-len,
4566 "fcp_cpu_map: No mapping (%d)\n",
4567 phba->cfg_fcp_cpu_map);
4570 len += snprintf(buf + len, PAGE_SIZE-len,
4571 "fcp_cpu_map: HBA centric mapping (%d): "
4573 phba->cfg_fcp_cpu_map,
4574 phba->sli4_hba.num_online_cpu);
4577 len += snprintf(buf + len, PAGE_SIZE-len,
4578 "fcp_cpu_map: Driver centric mapping (%d): "
4580 phba->cfg_fcp_cpu_map,
4581 phba->sli4_hba.num_online_cpu);
4585 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4586 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4588 /* margin should fit in this and the truncated message */
4589 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4590 len += snprintf(buf + len, PAGE_SIZE-len,
4591 "CPU %02d io_chan %02d "
4592 "physid %d coreid %d\n",
4593 phba->sli4_hba.curr_disp_cpu,
4594 cpup->channel_id, cpup->phys_id,
4597 len += snprintf(buf + len, PAGE_SIZE-len,
4598 "CPU %02d io_chan %02d "
4599 "physid %d coreid %d IRQ %d\n",
4600 phba->sli4_hba.curr_disp_cpu,
4601 cpup->channel_id, cpup->phys_id,
4602 cpup->core_id, cpup->irq);
4604 phba->sli4_hba.curr_disp_cpu++;
4606 /* display max number of CPUs keeping some margin */
4607 if (phba->sli4_hba.curr_disp_cpu <
4608 phba->sli4_hba.num_present_cpu &&
4609 (len >= (PAGE_SIZE - 64))) {
4610 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4615 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4616 phba->sli4_hba.curr_disp_cpu = 0;
4622 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4623 * @dev: class device that is converted into a Scsi_host.
4624 * @attr: device attribute, not used.
4625 * @buf: one or more lpfc_polling_flags values.
4629 * -EINVAL - Not implemented yet.
4632 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4633 const char *buf, size_t count)
4635 int status = -EINVAL;
4640 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4643 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4644 # 0 - Do not affinitze IRQ vectors
4645 # 1 - Affintize HBA vectors with respect to each HBA
4646 # (start with CPU0 for each HBA)
4647 # 2 - Affintize HBA vectors with respect to the entire driver
4648 # (round robin thru all CPUs across all HBAs)
4650 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4651 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4652 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4653 "Defines how to map CPUs to IRQ vectors per HBA");
4656 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4657 * @phba: lpfc_hba pointer.
4658 * @val: link speed value.
4661 * If val is in a valid range [0-2], then affinitze the adapter's
4665 * zero if val saved.
4666 * -EINVAL val out of range
4669 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4671 if (phba->sli_rev != LPFC_SLI_REV4) {
4672 phba->cfg_fcp_cpu_map = 0;
4676 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4677 phba->cfg_fcp_cpu_map = val;
4681 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4682 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4684 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4689 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4690 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4693 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4694 # Value range is [2,3]. Default value is 3.
4696 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4697 "Select Fibre Channel class of service for FCP sequences");
4700 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4701 # is [0,1]. Default value is 0.
4703 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4704 "Use ADISC on rediscovery to authenticate FCP devices");
4707 # lpfc_first_burst_size: First burst size to use on the NPorts
4708 # that support first burst.
4709 # Value range is [0,65536]. Default value is 0.
4711 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4712 "First burst size for Targets that support first burst");
4715 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4716 * When the driver is configured as an NVME target, this value is
4717 * communicated to the NVME initiator in the PRLI response. It is
4718 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4719 * parameters are set and the target is sending the PRLI RSP.
4720 * Parameter supported on physical port only - no NPIV support.
4721 * Value range is [0,65536]. Default value is 0.
4723 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4724 "NVME Target mode first burst size in 512B increments.");
4727 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4728 * For the Initiator (I), enabling this parameter means that an NVMET
4729 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4730 * processed by the initiator for subsequent NVME FCP IO. For the target
4731 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4732 * driver parameter as the target function's first burst size returned to the
4733 * initiator in the target's NVME PRLI response. Parameter supported on physical
4734 * port only - no NPIV support.
4735 * Value range is [0,1]. Default value is 0 (disabled).
4737 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4738 "Enable First Burst feature on I and T functions.");
4741 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4742 # depth. Default value is 0. When the value of this parameter is zero the
4743 # SCSI command completion time is not used for controlling I/O queue depth. When
4744 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4745 # to limit the I/O completion time to the parameter value.
4746 # The value is set in milliseconds.
4748 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4749 "Use command completion time to control queue depth");
4751 lpfc_vport_param_show(max_scsicmpl_time);
4753 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4755 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4756 struct lpfc_nodelist *ndlp, *next_ndlp;
4758 if (val == vport->cfg_max_scsicmpl_time)
4760 if ((val < 0) || (val > 60000))
4762 vport->cfg_max_scsicmpl_time = val;
4764 spin_lock_irq(shost->host_lock);
4765 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4766 if (!NLP_CHK_NODE_ACT(ndlp))
4768 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4770 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4772 spin_unlock_irq(shost->host_lock);
4775 lpfc_vport_param_store(max_scsicmpl_time);
4776 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4777 lpfc_max_scsicmpl_time_show,
4778 lpfc_max_scsicmpl_time_store);
4781 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4782 # range is [0,1]. Default value is 0.
4784 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4787 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4788 * range is [0,1]. Default value is 0.
4789 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4790 * For [1], FCP commands are issued to a Work Queue associated with the
4793 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4794 * LPFC_FCP_SCHED_BY_CPU == 1
4796 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4797 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4798 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4799 * through WQs will be used.
4801 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4802 LPFC_FCP_SCHED_ROUND_ROBIN,
4803 LPFC_FCP_SCHED_BY_CPU,
4804 "Determine scheduling algorithm for "
4805 "issuing commands [0] - Round Robin, [1] - Current CPU");
4808 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4809 # range is [0,1]. Default value is 0.
4810 # For [0], bus reset issues target reset to ALL devices
4811 # For [1], bus reset issues target reset to non-FCP2 devices
4813 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4814 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4818 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4819 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4820 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4821 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4822 # cr_delay is set to 0.
4824 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4825 "interrupt response is generated");
4827 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4828 "interrupt response is generated");
4831 # lpfc_multi_ring_support: Determines how many rings to spread available
4832 # cmd/rsp IOCB entries across.
4833 # Value range is [1,2]. Default value is 1.
4835 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4836 "SLI rings to spread IOCB entries across");
4839 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4840 # identifies what rctl value to configure the additional ring for.
4841 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4843 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4844 255, "Identifies RCTL for additional ring configuration");
4847 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4848 # identifies what type value to configure the additional ring for.
4849 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4851 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4852 255, "Identifies TYPE for additional ring configuration");
4855 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4856 # 0 = SmartSAN functionality disabled (default)
4857 # 1 = SmartSAN functionality enabled
4858 # This parameter will override the value of lpfc_fdmi_on module parameter.
4859 # Value range is [0,1]. Default value is 0.
4861 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4864 # lpfc_fdmi_on: Controls FDMI support.
4865 # 0 No FDMI support (default)
4866 # 1 Traditional FDMI support
4867 # Traditional FDMI support means the driver will assume FDMI-2 support;
4868 # however, if that fails, it will fallback to FDMI-1.
4869 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4870 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4872 # Value range [0,1]. Default value is 0.
4874 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4877 # Specifies the maximum number of ELS cmds we can have outstanding (for
4878 # discovery). Value range is [1,64]. Default value = 32.
4880 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4881 "during discovery");
4884 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4885 # will be scanned by the SCSI midlayer when sequential scanning is
4886 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4887 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4888 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4889 # above. The lpfc driver limits the default value to 255 for two reasons.
4890 # As it bounds the sequential scan loop, scanning for thousands of luns
4891 # on a target can take minutes of wall clock time. Additionally,
4892 # there are FC targets, such as JBODs, that only recognize 8-bits of
4893 # LUN ID. When they receive a value greater than 8 bits, they chop off
4894 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4895 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4896 # valid responses at each of the LUN IDs, to believe there are multiple
4897 # devices present, when in fact, there is only 1.
4898 # A customer that is aware of their target behaviors, and the results as
4899 # indicated above, is welcome to increase the lpfc_max_luns value.
4900 # As mentioned, this value is not used by the lpfc driver, only the
4902 # Value range is [0,65535]. Default value is 255.
4903 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4905 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4908 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4909 # Value range is [1,255], default value is 10.
4911 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4912 "Milliseconds driver will wait between polling FCP ring");
4915 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4916 # to complete in seconds. Value range is [5,180], default value is 60.
4918 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4919 "Maximum time to wait for task management commands to complete");
4921 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4922 # support this feature
4925 # 2 = MSI-X enabled (default)
4926 # Value range is [0,2]. Default value is 2.
4928 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4929 "MSI-X (2), if possible");
4932 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4934 * 0 = NVME OAS disabled
4935 * 1 = NVME OAS enabled
4937 * Value range is [0,1]. Default value is 0.
4939 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4940 "Use OAS bit on NVME IOs");
4943 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4944 * will advertise it supports to the SCSI layer. This also will map to
4945 * the number of WQs the driver will create.
4947 * 0 = Configure the number of io channels to the number of active CPUs.
4948 * 1,32 = Manually specify how many io channels to use.
4950 * Value range is [0,32]. Default value is 4.
4952 LPFC_ATTR_R(fcp_io_channel,
4953 LPFC_FCP_IO_CHAN_DEF,
4954 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4955 "Set the number of FCP I/O channels");
4958 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4959 * will advertise it supports to the NVME layer. This also will map to
4960 * the number of WQs the driver will create.
4962 * This module parameter is valid when lpfc_enable_fc4_type is set
4965 * The NVME Layer will try to create this many, plus 1 administrative
4966 * hardware queue. The administrative queue will always map to WQ 0
4967 * A hardware IO queue maps (qidx) to a specific driver WQ.
4969 * 0 = Configure the number of io channels to the number of active CPUs.
4970 * 1,32 = Manually specify how many io channels to use.
4972 * Value range is [0,32]. Default value is 0.
4974 LPFC_ATTR_R(nvme_io_channel,
4975 LPFC_NVME_IO_CHAN_DEF,
4976 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4977 "Set the number of NVME I/O channels");
4980 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4981 # 0 = HBA resets disabled
4982 # 1 = HBA resets enabled (default)
4983 # Value range is [0,1]. Default value is 1.
4985 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
4988 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
4989 # 0 = HBA Heartbeat disabled
4990 # 1 = HBA Heartbeat enabled (default)
4991 # Value range is [0,1]. Default value is 1.
4993 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
4996 # lpfc_EnableXLane: Enable Express Lane Feature
4997 # 0x0 Express Lane Feature disabled
4998 # 0x1 Express Lane Feature enabled
4999 # Value range is [0,1]. Default value is 0.
5001 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5004 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5005 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5006 # Value range is [0x0,0x7f]. Default value is 0
5008 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5011 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5012 # 0 = BlockGuard disabled (default)
5013 # 1 = BlockGuard enabled
5014 # Value range is [0,1]. Default value is 0.
5016 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5019 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5020 # 0 = disabled (default)
5022 # Value range is [0,1]. Default value is 0.
5024 # This feature in under investigation and may be supported in the future.
5026 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5030 # - Bit mask of host protection capabilities used to register with the
5032 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5033 # - Allows you to ultimately specify which profiles to use
5034 # - Default will result in registering capabilities for all profiles.
5035 # - SHOST_DIF_TYPE1_PROTECTION 1
5036 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5037 # - SHOST_DIX_TYPE0_PROTECTION 8
5038 # HBA supports DIX Type 0: Host to HBA protection only
5039 # - SHOST_DIX_TYPE1_PROTECTION 16
5040 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5043 LPFC_ATTR(prot_mask,
5044 (SHOST_DIF_TYPE1_PROTECTION |
5045 SHOST_DIX_TYPE0_PROTECTION |
5046 SHOST_DIX_TYPE1_PROTECTION),
5048 (SHOST_DIF_TYPE1_PROTECTION |
5049 SHOST_DIX_TYPE0_PROTECTION |
5050 SHOST_DIX_TYPE1_PROTECTION),
5051 "T10-DIF host protection capabilities mask");
5054 # lpfc_prot_guard: i
5055 # - Bit mask of protection guard types to register with the SCSI mid-layer
5056 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5057 # - Allows you to ultimately specify which profiles to use
5058 # - Default will result in registering capabilities for all guard types
5061 LPFC_ATTR(prot_guard,
5062 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5063 "T10-DIF host protection guard type");
5066 * Delay initial NPort discovery when Clean Address bit is cleared in
5067 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5068 * This parameter can have value 0 or 1.
5069 * When this parameter is set to 0, no delay is added to the initial
5071 * When this parameter is set to non-zero value, initial Nport discovery is
5072 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5073 * accept and FCID/Fabric name/Fabric portname is changed.
5074 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5075 * when Clean Address bit is cleared in FLOGI/FDISC
5076 * accept and FCID/Fabric name/Fabric portname is changed.
5077 * Default value is 0.
5079 LPFC_ATTR(delay_discovery, 0, 0, 1,
5080 "Delay NPort discovery when Clean Address bit is cleared.");
5083 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5084 * This value can be set to values between 64 and 4096. The default value is
5085 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5086 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5087 * Because of the additional overhead involved in setting up T10-DIF,
5088 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5089 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5091 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5092 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5095 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5096 * 0 = MDS Diagnostics disabled (default)
5097 * 1 = MDS Diagnostics enabled
5098 * Value range is [0,1]. Default value is 0.
5100 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5102 struct device_attribute *lpfc_hba_attrs[] = {
5103 &dev_attr_nvme_info,
5105 &dev_attr_bg_guard_err,
5106 &dev_attr_bg_apptag_err,
5107 &dev_attr_bg_reftag_err,
5109 &dev_attr_serialnum,
5110 &dev_attr_modeldesc,
5111 &dev_attr_modelname,
5112 &dev_attr_programtype,
5116 &dev_attr_option_rom_version,
5117 &dev_attr_link_state,
5118 &dev_attr_num_discovered_ports,
5119 &dev_attr_menlo_mgmt_mode,
5120 &dev_attr_lpfc_drvr_version,
5121 &dev_attr_lpfc_enable_fip,
5122 &dev_attr_lpfc_temp_sensor,
5123 &dev_attr_lpfc_log_verbose,
5124 &dev_attr_lpfc_lun_queue_depth,
5125 &dev_attr_lpfc_tgt_queue_depth,
5126 &dev_attr_lpfc_hba_queue_depth,
5127 &dev_attr_lpfc_peer_port_login,
5128 &dev_attr_lpfc_nodev_tmo,
5129 &dev_attr_lpfc_devloss_tmo,
5130 &dev_attr_lpfc_enable_fc4_type,
5131 &dev_attr_lpfc_xri_split,
5132 &dev_attr_lpfc_fcp_class,
5133 &dev_attr_lpfc_use_adisc,
5134 &dev_attr_lpfc_first_burst_size,
5135 &dev_attr_lpfc_ack0,
5136 &dev_attr_lpfc_topology,
5137 &dev_attr_lpfc_scan_down,
5138 &dev_attr_lpfc_link_speed,
5139 &dev_attr_lpfc_fcp_io_sched,
5140 &dev_attr_lpfc_fcp2_no_tgt_reset,
5141 &dev_attr_lpfc_cr_delay,
5142 &dev_attr_lpfc_cr_count,
5143 &dev_attr_lpfc_multi_ring_support,
5144 &dev_attr_lpfc_multi_ring_rctl,
5145 &dev_attr_lpfc_multi_ring_type,
5146 &dev_attr_lpfc_fdmi_on,
5147 &dev_attr_lpfc_enable_SmartSAN,
5148 &dev_attr_lpfc_max_luns,
5149 &dev_attr_lpfc_enable_npiv,
5150 &dev_attr_lpfc_fcf_failover_policy,
5151 &dev_attr_lpfc_enable_rrq,
5152 &dev_attr_nport_evt_cnt,
5153 &dev_attr_board_mode,
5160 &dev_attr_npiv_info,
5161 &dev_attr_issue_reset,
5162 &dev_attr_lpfc_poll,
5163 &dev_attr_lpfc_poll_tmo,
5164 &dev_attr_lpfc_task_mgmt_tmo,
5165 &dev_attr_lpfc_use_msi,
5166 &dev_attr_lpfc_nvme_oas,
5167 &dev_attr_lpfc_fcp_imax,
5168 &dev_attr_lpfc_fcp_cpu_map,
5169 &dev_attr_lpfc_fcp_io_channel,
5170 &dev_attr_lpfc_suppress_rsp,
5171 &dev_attr_lpfc_nvme_io_channel,
5172 &dev_attr_lpfc_nvmet_mrq,
5173 &dev_attr_lpfc_nvme_enable_fb,
5174 &dev_attr_lpfc_nvmet_fb_size,
5175 &dev_attr_lpfc_enable_bg,
5176 &dev_attr_lpfc_soft_wwnn,
5177 &dev_attr_lpfc_soft_wwpn,
5178 &dev_attr_lpfc_soft_wwn_enable,
5179 &dev_attr_lpfc_enable_hba_reset,
5180 &dev_attr_lpfc_enable_hba_heartbeat,
5181 &dev_attr_lpfc_EnableXLane,
5182 &dev_attr_lpfc_XLanePriority,
5183 &dev_attr_lpfc_xlane_lun,
5184 &dev_attr_lpfc_xlane_tgt,
5185 &dev_attr_lpfc_xlane_vpt,
5186 &dev_attr_lpfc_xlane_lun_state,
5187 &dev_attr_lpfc_xlane_lun_status,
5188 &dev_attr_lpfc_xlane_priority,
5189 &dev_attr_lpfc_sg_seg_cnt,
5190 &dev_attr_lpfc_max_scsicmpl_time,
5191 &dev_attr_lpfc_stat_data_ctrl,
5192 &dev_attr_lpfc_aer_support,
5193 &dev_attr_lpfc_aer_state_cleanup,
5194 &dev_attr_lpfc_sriov_nr_virtfn,
5195 &dev_attr_lpfc_req_fw_upgrade,
5196 &dev_attr_lpfc_suppress_link_up,
5197 &dev_attr_lpfc_iocb_cnt,
5200 &dev_attr_txcmplq_hw,
5201 &dev_attr_lpfc_fips_level,
5202 &dev_attr_lpfc_fips_rev,
5204 &dev_attr_lpfc_sriov_hw_max_virtfn,
5206 &dev_attr_lpfc_xlane_supported,
5207 &dev_attr_lpfc_enable_mds_diags,
5211 struct device_attribute *lpfc_vport_attrs[] = {
5213 &dev_attr_link_state,
5214 &dev_attr_num_discovered_ports,
5215 &dev_attr_lpfc_drvr_version,
5216 &dev_attr_lpfc_log_verbose,
5217 &dev_attr_lpfc_lun_queue_depth,
5218 &dev_attr_lpfc_tgt_queue_depth,
5219 &dev_attr_lpfc_nodev_tmo,
5220 &dev_attr_lpfc_devloss_tmo,
5221 &dev_attr_lpfc_hba_queue_depth,
5222 &dev_attr_lpfc_peer_port_login,
5223 &dev_attr_lpfc_restrict_login,
5224 &dev_attr_lpfc_fcp_class,
5225 &dev_attr_lpfc_use_adisc,
5226 &dev_attr_lpfc_first_burst_size,
5227 &dev_attr_lpfc_max_luns,
5228 &dev_attr_nport_evt_cnt,
5229 &dev_attr_npiv_info,
5230 &dev_attr_lpfc_enable_da_id,
5231 &dev_attr_lpfc_max_scsicmpl_time,
5232 &dev_attr_lpfc_stat_data_ctrl,
5233 &dev_attr_lpfc_static_vport,
5234 &dev_attr_lpfc_fips_level,
5235 &dev_attr_lpfc_fips_rev,
5240 * sysfs_ctlreg_write - Write method for writing to ctlreg
5241 * @filp: open sysfs file
5242 * @kobj: kernel kobject that contains the kernel class device.
5243 * @bin_attr: kernel attributes passed to us.
5244 * @buf: contains the data to be written to the adapter IOREG space.
5245 * @off: offset into buffer to beginning of data.
5246 * @count: bytes to transfer.
5249 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5250 * Uses the adapter io control registers to send buf contents to the adapter.
5253 * -ERANGE off and count combo out of range
5254 * -EINVAL off, count or buff address invalid
5255 * -EPERM adapter is offline
5256 * value of count, buf contents written
5259 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5260 struct bin_attribute *bin_attr,
5261 char *buf, loff_t off, size_t count)
5264 struct device *dev = container_of(kobj, struct device, kobj);
5265 struct Scsi_Host *shost = class_to_shost(dev);
5266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5267 struct lpfc_hba *phba = vport->phba;
5269 if (phba->sli_rev >= LPFC_SLI_REV4)
5272 if ((off + count) > FF_REG_AREA_SIZE)
5275 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5278 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5281 /* This is to protect HBA registers from accidental writes. */
5282 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5285 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5288 spin_lock_irq(&phba->hbalock);
5289 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5290 buf_off += sizeof(uint32_t))
5291 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5292 phba->ctrl_regs_memmap_p + off + buf_off);
5294 spin_unlock_irq(&phba->hbalock);
5300 * sysfs_ctlreg_read - Read method for reading from ctlreg
5301 * @filp: open sysfs file
5302 * @kobj: kernel kobject that contains the kernel class device.
5303 * @bin_attr: kernel attributes passed to us.
5304 * @buf: if successful contains the data from the adapter IOREG space.
5305 * @off: offset into buffer to beginning of data.
5306 * @count: bytes to transfer.
5309 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5310 * Uses the adapter io control registers to read data into buf.
5313 * -ERANGE off and count combo out of range
5314 * -EINVAL off, count or buff address invalid
5315 * value of count, buf contents read
5318 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5319 struct bin_attribute *bin_attr,
5320 char *buf, loff_t off, size_t count)
5324 struct device *dev = container_of(kobj, struct device, kobj);
5325 struct Scsi_Host *shost = class_to_shost(dev);
5326 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5327 struct lpfc_hba *phba = vport->phba;
5329 if (phba->sli_rev >= LPFC_SLI_REV4)
5332 if (off > FF_REG_AREA_SIZE)
5335 if ((off + count) > FF_REG_AREA_SIZE)
5336 count = FF_REG_AREA_SIZE - off;
5338 if (count == 0) return 0;
5340 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5343 spin_lock_irq(&phba->hbalock);
5345 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5346 tmp_ptr = (uint32_t *)(buf + buf_off);
5347 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5350 spin_unlock_irq(&phba->hbalock);
5355 static struct bin_attribute sysfs_ctlreg_attr = {
5358 .mode = S_IRUSR | S_IWUSR,
5361 .read = sysfs_ctlreg_read,
5362 .write = sysfs_ctlreg_write,
5366 * sysfs_mbox_write - Write method for writing information via mbox
5367 * @filp: open sysfs file
5368 * @kobj: kernel kobject that contains the kernel class device.
5369 * @bin_attr: kernel attributes passed to us.
5370 * @buf: contains the data to be written to sysfs mbox.
5371 * @off: offset into buffer to beginning of data.
5372 * @count: bytes to transfer.
5375 * Deprecated function. All mailbox access from user space is performed via the
5379 * -EPERM operation not permitted
5382 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5383 struct bin_attribute *bin_attr,
5384 char *buf, loff_t off, size_t count)
5390 * sysfs_mbox_read - Read method for reading information via mbox
5391 * @filp: open sysfs file
5392 * @kobj: kernel kobject that contains the kernel class device.
5393 * @bin_attr: kernel attributes passed to us.
5394 * @buf: contains the data to be read from sysfs mbox.
5395 * @off: offset into buffer to beginning of data.
5396 * @count: bytes to transfer.
5399 * Deprecated function. All mailbox access from user space is performed via the
5403 * -EPERM operation not permitted
5406 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5407 struct bin_attribute *bin_attr,
5408 char *buf, loff_t off, size_t count)
5413 static struct bin_attribute sysfs_mbox_attr = {
5416 .mode = S_IRUSR | S_IWUSR,
5418 .size = MAILBOX_SYSFS_MAX,
5419 .read = sysfs_mbox_read,
5420 .write = sysfs_mbox_write,
5424 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5425 * @vport: address of lpfc vport structure.
5429 * error return code from sysfs_create_bin_file()
5432 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5434 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5437 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5438 &sysfs_drvr_stat_data_attr);
5440 /* Virtual ports do not need ctrl_reg and mbox */
5441 if (error || vport->port_type == LPFC_NPIV_PORT)
5444 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5445 &sysfs_ctlreg_attr);
5447 goto out_remove_stat_attr;
5449 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5452 goto out_remove_ctlreg_attr;
5455 out_remove_ctlreg_attr:
5456 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5457 out_remove_stat_attr:
5458 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5459 &sysfs_drvr_stat_data_attr);
5465 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5466 * @vport: address of lpfc vport structure.
5469 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5471 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5472 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5473 &sysfs_drvr_stat_data_attr);
5474 /* Virtual ports do not need ctrl_reg and mbox */
5475 if (vport->port_type == LPFC_NPIV_PORT)
5477 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5478 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5482 * Dynamic FC Host Attributes Support
5486 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5487 * @shost: kernel scsi host pointer.
5490 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5492 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5494 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5495 sizeof fc_host_symbolic_name(shost));
5499 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5500 * @shost: kernel scsi host pointer.
5503 lpfc_get_host_port_id(struct Scsi_Host *shost)
5505 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5507 /* note: fc_myDID already in cpu endianness */
5508 fc_host_port_id(shost) = vport->fc_myDID;
5512 * lpfc_get_host_port_type - Set the value of the scsi host port type
5513 * @shost: kernel scsi host pointer.
5516 lpfc_get_host_port_type(struct Scsi_Host *shost)
5518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5519 struct lpfc_hba *phba = vport->phba;
5521 spin_lock_irq(shost->host_lock);
5523 if (vport->port_type == LPFC_NPIV_PORT) {
5524 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5525 } else if (lpfc_is_link_up(phba)) {
5526 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5527 if (vport->fc_flag & FC_PUBLIC_LOOP)
5528 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5530 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5532 if (vport->fc_flag & FC_FABRIC)
5533 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5535 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5538 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5540 spin_unlock_irq(shost->host_lock);
5544 * lpfc_get_host_port_state - Set the value of the scsi host port state
5545 * @shost: kernel scsi host pointer.
5548 lpfc_get_host_port_state(struct Scsi_Host *shost)
5550 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5551 struct lpfc_hba *phba = vport->phba;
5553 spin_lock_irq(shost->host_lock);
5555 if (vport->fc_flag & FC_OFFLINE_MODE)
5556 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5558 switch (phba->link_state) {
5559 case LPFC_LINK_UNKNOWN:
5560 case LPFC_LINK_DOWN:
5561 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5565 case LPFC_HBA_READY:
5566 /* Links up, reports port state accordingly */
5567 if (vport->port_state < LPFC_VPORT_READY)
5568 fc_host_port_state(shost) =
5569 FC_PORTSTATE_BYPASSED;
5571 fc_host_port_state(shost) =
5572 FC_PORTSTATE_ONLINE;
5574 case LPFC_HBA_ERROR:
5575 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5578 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5583 spin_unlock_irq(shost->host_lock);
5587 * lpfc_get_host_speed - Set the value of the scsi host speed
5588 * @shost: kernel scsi host pointer.
5591 lpfc_get_host_speed(struct Scsi_Host *shost)
5593 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5594 struct lpfc_hba *phba = vport->phba;
5596 spin_lock_irq(shost->host_lock);
5598 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5599 switch(phba->fc_linkspeed) {
5600 case LPFC_LINK_SPEED_1GHZ:
5601 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5603 case LPFC_LINK_SPEED_2GHZ:
5604 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5606 case LPFC_LINK_SPEED_4GHZ:
5607 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5609 case LPFC_LINK_SPEED_8GHZ:
5610 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5612 case LPFC_LINK_SPEED_10GHZ:
5613 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5615 case LPFC_LINK_SPEED_16GHZ:
5616 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5618 case LPFC_LINK_SPEED_32GHZ:
5619 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5622 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5626 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5628 spin_unlock_irq(shost->host_lock);
5632 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5633 * @shost: kernel scsi host pointer.
5636 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5638 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5639 struct lpfc_hba *phba = vport->phba;
5642 spin_lock_irq(shost->host_lock);
5644 if ((vport->port_state > LPFC_FLOGI) &&
5645 ((vport->fc_flag & FC_FABRIC) ||
5646 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5647 (vport->fc_flag & FC_PUBLIC_LOOP))))
5648 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5650 /* fabric is local port if there is no F/FL_Port */
5653 spin_unlock_irq(shost->host_lock);
5655 fc_host_fabric_name(shost) = node_name;
5659 * lpfc_get_stats - Return statistical information about the adapter
5660 * @shost: kernel scsi host pointer.
5663 * NULL on error for link down, no mbox pool, sli2 active,
5664 * management not allowed, memory allocation error, or mbox error.
5668 * address of the adapter host statistics
5670 static struct fc_host_statistics *
5671 lpfc_get_stats(struct Scsi_Host *shost)
5673 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5674 struct lpfc_hba *phba = vport->phba;
5675 struct lpfc_sli *psli = &phba->sli;
5676 struct fc_host_statistics *hs = &phba->link_stats;
5677 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5678 LPFC_MBOXQ_t *pmboxq;
5680 unsigned long seconds;
5684 * prevent udev from issuing mailbox commands until the port is
5687 if (phba->link_state < LPFC_LINK_DOWN ||
5688 !phba->mbox_mem_pool ||
5689 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5692 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5695 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5698 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5700 pmb = &pmboxq->u.mb;
5701 pmb->mbxCommand = MBX_READ_STATUS;
5702 pmb->mbxOwner = OWN_HOST;
5703 pmboxq->context1 = NULL;
5704 pmboxq->vport = vport;
5706 if (vport->fc_flag & FC_OFFLINE_MODE)
5707 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5709 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5711 if (rc != MBX_SUCCESS) {
5712 if (rc != MBX_TIMEOUT)
5713 mempool_free(pmboxq, phba->mbox_mem_pool);
5717 memset(hs, 0, sizeof (struct fc_host_statistics));
5719 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5721 * The MBX_READ_STATUS returns tx_k_bytes which has to
5722 * converted to words
5724 hs->tx_words = (uint64_t)
5725 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5727 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5728 hs->rx_words = (uint64_t)
5729 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5732 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5733 pmb->mbxCommand = MBX_READ_LNK_STAT;
5734 pmb->mbxOwner = OWN_HOST;
5735 pmboxq->context1 = NULL;
5736 pmboxq->vport = vport;
5738 if (vport->fc_flag & FC_OFFLINE_MODE)
5739 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5741 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5743 if (rc != MBX_SUCCESS) {
5744 if (rc != MBX_TIMEOUT)
5745 mempool_free(pmboxq, phba->mbox_mem_pool);
5749 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5750 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5751 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5752 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5753 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5754 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5755 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5757 hs->link_failure_count -= lso->link_failure_count;
5758 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5759 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5760 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5761 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5762 hs->invalid_crc_count -= lso->invalid_crc_count;
5763 hs->error_frames -= lso->error_frames;
5765 if (phba->hba_flag & HBA_FCOE_MODE) {
5767 hs->nos_count = (phba->link_events >> 1);
5768 hs->nos_count -= lso->link_events;
5769 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5770 hs->lip_count = (phba->fc_eventTag >> 1);
5771 hs->lip_count -= lso->link_events;
5775 hs->nos_count = (phba->fc_eventTag >> 1);
5776 hs->nos_count -= lso->link_events;
5779 hs->dumped_frames = -1;
5781 seconds = get_seconds();
5782 if (seconds < psli->stats_start)
5783 hs->seconds_since_last_reset = seconds +
5784 ((unsigned long)-1 - psli->stats_start);
5786 hs->seconds_since_last_reset = seconds - psli->stats_start;
5788 mempool_free(pmboxq, phba->mbox_mem_pool);
5794 * lpfc_reset_stats - Copy the adapter link stats information
5795 * @shost: kernel scsi host pointer.
5798 lpfc_reset_stats(struct Scsi_Host *shost)
5800 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5801 struct lpfc_hba *phba = vport->phba;
5802 struct lpfc_sli *psli = &phba->sli;
5803 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5804 LPFC_MBOXQ_t *pmboxq;
5808 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5811 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5814 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5816 pmb = &pmboxq->u.mb;
5817 pmb->mbxCommand = MBX_READ_STATUS;
5818 pmb->mbxOwner = OWN_HOST;
5819 pmb->un.varWords[0] = 0x1; /* reset request */
5820 pmboxq->context1 = NULL;
5821 pmboxq->vport = vport;
5823 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5824 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5825 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5827 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5829 if (rc != MBX_SUCCESS) {
5830 if (rc != MBX_TIMEOUT)
5831 mempool_free(pmboxq, phba->mbox_mem_pool);
5835 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5836 pmb->mbxCommand = MBX_READ_LNK_STAT;
5837 pmb->mbxOwner = OWN_HOST;
5838 pmboxq->context1 = NULL;
5839 pmboxq->vport = vport;
5841 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5842 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5843 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5845 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5847 if (rc != MBX_SUCCESS) {
5848 if (rc != MBX_TIMEOUT)
5849 mempool_free( pmboxq, phba->mbox_mem_pool);
5853 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5854 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5855 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5856 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5857 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5858 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5859 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5860 if (phba->hba_flag & HBA_FCOE_MODE)
5861 lso->link_events = (phba->link_events >> 1);
5863 lso->link_events = (phba->fc_eventTag >> 1);
5865 psli->stats_start = get_seconds();
5867 mempool_free(pmboxq, phba->mbox_mem_pool);
5873 * The LPFC driver treats linkdown handling as target loss events so there
5874 * are no sysfs handlers for link_down_tmo.
5878 * lpfc_get_node_by_target - Return the nodelist for a target
5879 * @starget: kernel scsi target pointer.
5882 * address of the node list if found
5883 * NULL target not found
5885 static struct lpfc_nodelist *
5886 lpfc_get_node_by_target(struct scsi_target *starget)
5888 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5889 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5890 struct lpfc_nodelist *ndlp;
5892 spin_lock_irq(shost->host_lock);
5893 /* Search for this, mapped, target ID */
5894 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5895 if (NLP_CHK_NODE_ACT(ndlp) &&
5896 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5897 starget->id == ndlp->nlp_sid) {
5898 spin_unlock_irq(shost->host_lock);
5902 spin_unlock_irq(shost->host_lock);
5907 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5908 * @starget: kernel scsi target pointer.
5911 lpfc_get_starget_port_id(struct scsi_target *starget)
5913 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5915 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5919 * lpfc_get_starget_node_name - Set the target node name
5920 * @starget: kernel scsi target pointer.
5922 * Description: Set the target node name to the ndlp node name wwn or zero.
5925 lpfc_get_starget_node_name(struct scsi_target *starget)
5927 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5929 fc_starget_node_name(starget) =
5930 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5934 * lpfc_get_starget_port_name - Set the target port name
5935 * @starget: kernel scsi target pointer.
5937 * Description: set the target port name to the ndlp port name wwn or zero.
5940 lpfc_get_starget_port_name(struct scsi_target *starget)
5942 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5944 fc_starget_port_name(starget) =
5945 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5949 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5950 * @rport: fc rport address.
5951 * @timeout: new value for dev loss tmo.
5954 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5955 * dev_loss_tmo to one.
5958 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5961 rport->dev_loss_tmo = timeout;
5963 rport->dev_loss_tmo = 1;
5967 * lpfc_rport_show_function - Return rport target information
5970 * Macro that uses field to generate a function with the name lpfc_show_rport_
5972 * lpfc_show_rport_##field: returns the bytes formatted in buf
5973 * @cdev: class converted to an fc_rport.
5974 * @buf: on return contains the target_field or zero.
5976 * Returns: size of formatted string.
5978 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5980 lpfc_show_rport_##field (struct device *dev, \
5981 struct device_attribute *attr, \
5984 struct fc_rport *rport = transport_class_to_rport(dev); \
5985 struct lpfc_rport_data *rdata = rport->hostdata; \
5986 return snprintf(buf, sz, format_string, \
5987 (rdata->target) ? cast rdata->target->field : 0); \
5990 #define lpfc_rport_rd_attr(field, format_string, sz) \
5991 lpfc_rport_show_function(field, format_string, sz, ) \
5992 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5995 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
5996 * @fc_vport: The fc_vport who's symbolic name has been changed.
5999 * This function is called by the transport after the @fc_vport's symbolic name
6000 * has been changed. This function re-registers the symbolic name with the
6001 * switch to propagate the change into the fabric if the vport is active.
6004 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6006 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6008 if (vport->port_state == LPFC_VPORT_READY)
6009 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6013 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6014 * @phba: Pointer to lpfc_hba struct.
6016 * This function is called by the lpfc_get_cfgparam() routine to set the
6017 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6018 * log message according to the module's lpfc_log_verbose parameter setting
6019 * before hba port or vport created.
6022 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6024 phba->cfg_log_verbose = verbose;
6027 struct fc_function_template lpfc_transport_functions = {
6028 /* fixed attributes the driver supports */
6029 .show_host_node_name = 1,
6030 .show_host_port_name = 1,
6031 .show_host_supported_classes = 1,
6032 .show_host_supported_fc4s = 1,
6033 .show_host_supported_speeds = 1,
6034 .show_host_maxframe_size = 1,
6036 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6037 .show_host_symbolic_name = 1,
6039 /* dynamic attributes the driver supports */
6040 .get_host_port_id = lpfc_get_host_port_id,
6041 .show_host_port_id = 1,
6043 .get_host_port_type = lpfc_get_host_port_type,
6044 .show_host_port_type = 1,
6046 .get_host_port_state = lpfc_get_host_port_state,
6047 .show_host_port_state = 1,
6049 /* active_fc4s is shown but doesn't change (thus no get function) */
6050 .show_host_active_fc4s = 1,
6052 .get_host_speed = lpfc_get_host_speed,
6053 .show_host_speed = 1,
6055 .get_host_fabric_name = lpfc_get_host_fabric_name,
6056 .show_host_fabric_name = 1,
6059 * The LPFC driver treats linkdown handling as target loss events
6060 * so there are no sysfs handlers for link_down_tmo.
6063 .get_fc_host_stats = lpfc_get_stats,
6064 .reset_fc_host_stats = lpfc_reset_stats,
6066 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6067 .show_rport_maxframe_size = 1,
6068 .show_rport_supported_classes = 1,
6070 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6071 .show_rport_dev_loss_tmo = 1,
6073 .get_starget_port_id = lpfc_get_starget_port_id,
6074 .show_starget_port_id = 1,
6076 .get_starget_node_name = lpfc_get_starget_node_name,
6077 .show_starget_node_name = 1,
6079 .get_starget_port_name = lpfc_get_starget_port_name,
6080 .show_starget_port_name = 1,
6082 .issue_fc_host_lip = lpfc_issue_lip,
6083 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6084 .terminate_rport_io = lpfc_terminate_rport_io,
6086 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6088 .vport_disable = lpfc_vport_disable,
6090 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6092 .bsg_request = lpfc_bsg_request,
6093 .bsg_timeout = lpfc_bsg_timeout,
6096 struct fc_function_template lpfc_vport_transport_functions = {
6097 /* fixed attributes the driver supports */
6098 .show_host_node_name = 1,
6099 .show_host_port_name = 1,
6100 .show_host_supported_classes = 1,
6101 .show_host_supported_fc4s = 1,
6102 .show_host_supported_speeds = 1,
6103 .show_host_maxframe_size = 1,
6105 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6106 .show_host_symbolic_name = 1,
6108 /* dynamic attributes the driver supports */
6109 .get_host_port_id = lpfc_get_host_port_id,
6110 .show_host_port_id = 1,
6112 .get_host_port_type = lpfc_get_host_port_type,
6113 .show_host_port_type = 1,
6115 .get_host_port_state = lpfc_get_host_port_state,
6116 .show_host_port_state = 1,
6118 /* active_fc4s is shown but doesn't change (thus no get function) */
6119 .show_host_active_fc4s = 1,
6121 .get_host_speed = lpfc_get_host_speed,
6122 .show_host_speed = 1,
6124 .get_host_fabric_name = lpfc_get_host_fabric_name,
6125 .show_host_fabric_name = 1,
6128 * The LPFC driver treats linkdown handling as target loss events
6129 * so there are no sysfs handlers for link_down_tmo.
6132 .get_fc_host_stats = lpfc_get_stats,
6133 .reset_fc_host_stats = lpfc_reset_stats,
6135 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6136 .show_rport_maxframe_size = 1,
6137 .show_rport_supported_classes = 1,
6139 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6140 .show_rport_dev_loss_tmo = 1,
6142 .get_starget_port_id = lpfc_get_starget_port_id,
6143 .show_starget_port_id = 1,
6145 .get_starget_node_name = lpfc_get_starget_node_name,
6146 .show_starget_node_name = 1,
6148 .get_starget_port_name = lpfc_get_starget_port_name,
6149 .show_starget_port_name = 1,
6151 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6152 .terminate_rport_io = lpfc_terminate_rport_io,
6154 .vport_disable = lpfc_vport_disable,
6156 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6160 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6161 * @phba: lpfc_hba pointer.
6164 lpfc_get_cfgparam(struct lpfc_hba *phba)
6166 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6167 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6168 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6169 lpfc_cr_count_init(phba, lpfc_cr_count);
6170 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6171 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6172 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6173 lpfc_ack0_init(phba, lpfc_ack0);
6174 lpfc_topology_init(phba, lpfc_topology);
6175 lpfc_link_speed_init(phba, lpfc_link_speed);
6176 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6177 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6178 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6179 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6180 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6181 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6182 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6183 lpfc_use_msi_init(phba, lpfc_use_msi);
6184 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6185 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6186 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6187 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6188 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6190 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6191 if (phba->sli_rev != LPFC_SLI_REV4)
6192 phba->cfg_EnableXLane = 0;
6193 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6195 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6196 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6197 phba->cfg_oas_lun_state = 0;
6198 phba->cfg_oas_lun_status = 0;
6199 phba->cfg_oas_flags = 0;
6200 phba->cfg_oas_priority = 0;
6201 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6202 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6203 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6204 if (phba->sli_rev == LPFC_SLI_REV4)
6207 phba->cfg_poll = lpfc_poll;
6208 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6210 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6211 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6213 /* Initialize first burst. Target vs Initiator are different. */
6214 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6215 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6216 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6217 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6219 if (phba->sli_rev != LPFC_SLI_REV4) {
6220 /* NVME only supported on SLI4 */
6221 phba->nvmet_support = 0;
6222 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6224 /* We MUST have FCP support */
6225 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6226 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6229 /* A value of 0 means use the number of CPUs found in the system */
6230 if (phba->cfg_fcp_io_channel == 0)
6231 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6232 if (phba->cfg_nvme_io_channel == 0)
6233 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6235 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6236 phba->cfg_fcp_io_channel = 0;
6238 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6239 phba->cfg_nvme_io_channel = 0;
6241 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6242 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6244 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6246 phba->cfg_soft_wwnn = 0L;
6247 phba->cfg_soft_wwpn = 0L;
6248 lpfc_xri_split_init(phba, lpfc_xri_split);
6249 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6250 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6251 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6252 lpfc_aer_support_init(phba, lpfc_aer_support);
6253 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6254 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6255 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6256 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6257 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6258 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6259 phba->cfg_enable_dss = 1;
6260 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6265 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6266 * dependencies between protocols and roles.
6267 * @phba: lpfc_hba pointer.
6270 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6272 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6273 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6275 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6276 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6278 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6279 phba->nvmet_support) {
6280 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6281 phba->cfg_fcp_io_channel = 0;
6283 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6284 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6285 "NVME Target PRLI ACC enable_fb ",
6286 phba->cfg_nvme_enable_fb,
6287 phba->cfg_nvmet_fb_size,
6288 LPFC_NVMET_FB_SZ_MAX);
6290 if (phba->cfg_nvme_enable_fb == 0)
6291 phba->cfg_nvmet_fb_size = 0;
6293 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6294 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6297 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6298 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6299 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6300 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6301 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6302 phba->cfg_nvmet_mrq);
6305 /* Not NVME Target mode. Turn off Target parameters. */
6306 phba->nvmet_support = 0;
6307 phba->cfg_nvmet_mrq = 0;
6308 phba->cfg_nvmet_fb_size = 0;
6311 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6312 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6314 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6318 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6319 * @vport: lpfc_vport pointer.
6322 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6324 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6325 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6326 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6327 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6328 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6329 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6330 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6331 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6332 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6333 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6334 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6335 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6336 lpfc_max_luns_init(vport, lpfc_max_luns);
6337 lpfc_scan_down_init(vport, lpfc_scan_down);
6338 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);