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;
4484 phba->initial_imax = phba->cfg_fcp_imax;
4486 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4487 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4494 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4497 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4499 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4500 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4501 MODULE_PARM_DESC(lpfc_fcp_imax,
4502 "Set the maximum number of FCP interrupts per second per HBA");
4503 lpfc_param_show(fcp_imax)
4506 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4507 * @phba: lpfc_hba pointer.
4508 * @val: link speed value.
4511 * If val is in a valid range [636,651042], then initialize the adapter's
4512 * maximum number of fast-path FCP interrupts per second.
4515 * zero if val saved.
4516 * -EINVAL val out of range
4519 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4521 if (phba->sli_rev != LPFC_SLI_REV4) {
4522 phba->cfg_fcp_imax = 0;
4526 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4528 phba->cfg_fcp_imax = val;
4532 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4533 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4535 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4540 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4541 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4544 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4545 * 0 No auto_imax support
4547 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4548 * the EQ Delay Multiplier, depending on the activity for that EQ.
4549 * Value range [0,1]. Default value is 1.
4551 LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4554 * lpfc_state_show - Display current driver CPU affinity
4555 * @dev: class converted to a Scsi_host structure.
4556 * @attr: device attribute, not used.
4557 * @buf: on return contains text describing the state of the link.
4559 * Returns: size of formatted string.
4562 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4565 struct Scsi_Host *shost = class_to_shost(dev);
4566 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4567 struct lpfc_hba *phba = vport->phba;
4568 struct lpfc_vector_map_info *cpup;
4571 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4572 (phba->intr_type != MSIX))
4575 switch (phba->cfg_fcp_cpu_map) {
4577 len += snprintf(buf + len, PAGE_SIZE-len,
4578 "fcp_cpu_map: No mapping (%d)\n",
4579 phba->cfg_fcp_cpu_map);
4582 len += snprintf(buf + len, PAGE_SIZE-len,
4583 "fcp_cpu_map: HBA centric mapping (%d): "
4585 phba->cfg_fcp_cpu_map,
4586 phba->sli4_hba.num_online_cpu);
4589 len += snprintf(buf + len, PAGE_SIZE-len,
4590 "fcp_cpu_map: Driver centric mapping (%d): "
4592 phba->cfg_fcp_cpu_map,
4593 phba->sli4_hba.num_online_cpu);
4597 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4598 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4600 /* margin should fit in this and the truncated message */
4601 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4602 len += snprintf(buf + len, PAGE_SIZE-len,
4603 "CPU %02d io_chan %02d "
4604 "physid %d coreid %d\n",
4605 phba->sli4_hba.curr_disp_cpu,
4606 cpup->channel_id, cpup->phys_id,
4609 len += snprintf(buf + len, PAGE_SIZE-len,
4610 "CPU %02d io_chan %02d "
4611 "physid %d coreid %d IRQ %d\n",
4612 phba->sli4_hba.curr_disp_cpu,
4613 cpup->channel_id, cpup->phys_id,
4614 cpup->core_id, cpup->irq);
4616 phba->sli4_hba.curr_disp_cpu++;
4618 /* display max number of CPUs keeping some margin */
4619 if (phba->sli4_hba.curr_disp_cpu <
4620 phba->sli4_hba.num_present_cpu &&
4621 (len >= (PAGE_SIZE - 64))) {
4622 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4627 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4628 phba->sli4_hba.curr_disp_cpu = 0;
4634 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4635 * @dev: class device that is converted into a Scsi_host.
4636 * @attr: device attribute, not used.
4637 * @buf: one or more lpfc_polling_flags values.
4641 * -EINVAL - Not implemented yet.
4644 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4645 const char *buf, size_t count)
4647 int status = -EINVAL;
4652 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4655 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4656 # 0 - Do not affinitze IRQ vectors
4657 # 1 - Affintize HBA vectors with respect to each HBA
4658 # (start with CPU0 for each HBA)
4659 # 2 - Affintize HBA vectors with respect to the entire driver
4660 # (round robin thru all CPUs across all HBAs)
4662 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4663 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4664 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4665 "Defines how to map CPUs to IRQ vectors per HBA");
4668 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4669 * @phba: lpfc_hba pointer.
4670 * @val: link speed value.
4673 * If val is in a valid range [0-2], then affinitze the adapter's
4677 * zero if val saved.
4678 * -EINVAL val out of range
4681 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4683 if (phba->sli_rev != LPFC_SLI_REV4) {
4684 phba->cfg_fcp_cpu_map = 0;
4688 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4689 phba->cfg_fcp_cpu_map = val;
4693 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4694 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4696 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4701 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4702 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4705 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4706 # Value range is [2,3]. Default value is 3.
4708 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4709 "Select Fibre Channel class of service for FCP sequences");
4712 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4713 # is [0,1]. Default value is 0.
4715 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4716 "Use ADISC on rediscovery to authenticate FCP devices");
4719 # lpfc_first_burst_size: First burst size to use on the NPorts
4720 # that support first burst.
4721 # Value range is [0,65536]. Default value is 0.
4723 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4724 "First burst size for Targets that support first burst");
4727 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4728 * When the driver is configured as an NVME target, this value is
4729 * communicated to the NVME initiator in the PRLI response. It is
4730 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4731 * parameters are set and the target is sending the PRLI RSP.
4732 * Parameter supported on physical port only - no NPIV support.
4733 * Value range is [0,65536]. Default value is 0.
4735 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4736 "NVME Target mode first burst size in 512B increments.");
4739 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4740 * For the Initiator (I), enabling this parameter means that an NVMET
4741 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4742 * processed by the initiator for subsequent NVME FCP IO. For the target
4743 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4744 * driver parameter as the target function's first burst size returned to the
4745 * initiator in the target's NVME PRLI response. Parameter supported on physical
4746 * port only - no NPIV support.
4747 * Value range is [0,1]. Default value is 0 (disabled).
4749 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4750 "Enable First Burst feature on I and T functions.");
4753 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4754 # depth. Default value is 0. When the value of this parameter is zero the
4755 # SCSI command completion time is not used for controlling I/O queue depth. When
4756 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4757 # to limit the I/O completion time to the parameter value.
4758 # The value is set in milliseconds.
4760 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4761 "Use command completion time to control queue depth");
4763 lpfc_vport_param_show(max_scsicmpl_time);
4765 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4767 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4768 struct lpfc_nodelist *ndlp, *next_ndlp;
4770 if (val == vport->cfg_max_scsicmpl_time)
4772 if ((val < 0) || (val > 60000))
4774 vport->cfg_max_scsicmpl_time = val;
4776 spin_lock_irq(shost->host_lock);
4777 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4778 if (!NLP_CHK_NODE_ACT(ndlp))
4780 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4782 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4784 spin_unlock_irq(shost->host_lock);
4787 lpfc_vport_param_store(max_scsicmpl_time);
4788 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4789 lpfc_max_scsicmpl_time_show,
4790 lpfc_max_scsicmpl_time_store);
4793 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4794 # range is [0,1]. Default value is 0.
4796 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4799 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4800 * range is [0,1]. Default value is 0.
4801 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4802 * For [1], FCP commands are issued to a Work Queue associated with the
4805 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4806 * LPFC_FCP_SCHED_BY_CPU == 1
4808 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4809 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4810 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4811 * through WQs will be used.
4813 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4814 LPFC_FCP_SCHED_ROUND_ROBIN,
4815 LPFC_FCP_SCHED_BY_CPU,
4816 "Determine scheduling algorithm for "
4817 "issuing commands [0] - Round Robin, [1] - Current CPU");
4820 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4821 # range is [0,1]. Default value is 0.
4822 # For [0], bus reset issues target reset to ALL devices
4823 # For [1], bus reset issues target reset to non-FCP2 devices
4825 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4826 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4830 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4831 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4832 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4833 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4834 # cr_delay is set to 0.
4836 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4837 "interrupt response is generated");
4839 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4840 "interrupt response is generated");
4843 # lpfc_multi_ring_support: Determines how many rings to spread available
4844 # cmd/rsp IOCB entries across.
4845 # Value range is [1,2]. Default value is 1.
4847 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4848 "SLI rings to spread IOCB entries across");
4851 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4852 # identifies what rctl value to configure the additional ring for.
4853 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4855 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4856 255, "Identifies RCTL for additional ring configuration");
4859 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4860 # identifies what type value to configure the additional ring for.
4861 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4863 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4864 255, "Identifies TYPE for additional ring configuration");
4867 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4868 # 0 = SmartSAN functionality disabled (default)
4869 # 1 = SmartSAN functionality enabled
4870 # This parameter will override the value of lpfc_fdmi_on module parameter.
4871 # Value range is [0,1]. Default value is 0.
4873 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4876 # lpfc_fdmi_on: Controls FDMI support.
4877 # 0 No FDMI support (default)
4878 # 1 Traditional FDMI support
4879 # Traditional FDMI support means the driver will assume FDMI-2 support;
4880 # however, if that fails, it will fallback to FDMI-1.
4881 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4882 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4884 # Value range [0,1]. Default value is 0.
4886 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4889 # Specifies the maximum number of ELS cmds we can have outstanding (for
4890 # discovery). Value range is [1,64]. Default value = 32.
4892 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4893 "during discovery");
4896 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4897 # will be scanned by the SCSI midlayer when sequential scanning is
4898 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4899 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4900 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4901 # above. The lpfc driver limits the default value to 255 for two reasons.
4902 # As it bounds the sequential scan loop, scanning for thousands of luns
4903 # on a target can take minutes of wall clock time. Additionally,
4904 # there are FC targets, such as JBODs, that only recognize 8-bits of
4905 # LUN ID. When they receive a value greater than 8 bits, they chop off
4906 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4907 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4908 # valid responses at each of the LUN IDs, to believe there are multiple
4909 # devices present, when in fact, there is only 1.
4910 # A customer that is aware of their target behaviors, and the results as
4911 # indicated above, is welcome to increase the lpfc_max_luns value.
4912 # As mentioned, this value is not used by the lpfc driver, only the
4914 # Value range is [0,65535]. Default value is 255.
4915 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4917 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4920 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4921 # Value range is [1,255], default value is 10.
4923 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4924 "Milliseconds driver will wait between polling FCP ring");
4927 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4928 # to complete in seconds. Value range is [5,180], default value is 60.
4930 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4931 "Maximum time to wait for task management commands to complete");
4933 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4934 # support this feature
4937 # 2 = MSI-X enabled (default)
4938 # Value range is [0,2]. Default value is 2.
4940 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4941 "MSI-X (2), if possible");
4944 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4946 * 0 = NVME OAS disabled
4947 * 1 = NVME OAS enabled
4949 * Value range is [0,1]. Default value is 0.
4951 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4952 "Use OAS bit on NVME IOs");
4955 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4956 * will advertise it supports to the SCSI layer. This also will map to
4957 * the number of WQs the driver will create.
4959 * 0 = Configure the number of io channels to the number of active CPUs.
4960 * 1,32 = Manually specify how many io channels to use.
4962 * Value range is [0,32]. Default value is 4.
4964 LPFC_ATTR_R(fcp_io_channel,
4965 LPFC_FCP_IO_CHAN_DEF,
4966 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4967 "Set the number of FCP I/O channels");
4970 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4971 * will advertise it supports to the NVME layer. This also will map to
4972 * the number of WQs the driver will create.
4974 * This module parameter is valid when lpfc_enable_fc4_type is set
4977 * The NVME Layer will try to create this many, plus 1 administrative
4978 * hardware queue. The administrative queue will always map to WQ 0
4979 * A hardware IO queue maps (qidx) to a specific driver WQ.
4981 * 0 = Configure the number of io channels to the number of active CPUs.
4982 * 1,32 = Manually specify how many io channels to use.
4984 * Value range is [0,32]. Default value is 0.
4986 LPFC_ATTR_R(nvme_io_channel,
4987 LPFC_NVME_IO_CHAN_DEF,
4988 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4989 "Set the number of NVME I/O channels");
4992 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4993 # 0 = HBA resets disabled
4994 # 1 = HBA resets enabled (default)
4995 # Value range is [0,1]. Default value is 1.
4997 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
5000 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5001 # 0 = HBA Heartbeat disabled
5002 # 1 = HBA Heartbeat enabled (default)
5003 # Value range is [0,1]. Default value is 1.
5005 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5008 # lpfc_EnableXLane: Enable Express Lane Feature
5009 # 0x0 Express Lane Feature disabled
5010 # 0x1 Express Lane Feature enabled
5011 # Value range is [0,1]. Default value is 0.
5013 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5016 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5017 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5018 # Value range is [0x0,0x7f]. Default value is 0
5020 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5023 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5024 # 0 = BlockGuard disabled (default)
5025 # 1 = BlockGuard enabled
5026 # Value range is [0,1]. Default value is 0.
5028 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5031 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5032 # 0 = disabled (default)
5034 # Value range is [0,1]. Default value is 0.
5036 # This feature in under investigation and may be supported in the future.
5038 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5042 # - Bit mask of host protection capabilities used to register with the
5044 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5045 # - Allows you to ultimately specify which profiles to use
5046 # - Default will result in registering capabilities for all profiles.
5047 # - SHOST_DIF_TYPE1_PROTECTION 1
5048 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5049 # - SHOST_DIX_TYPE0_PROTECTION 8
5050 # HBA supports DIX Type 0: Host to HBA protection only
5051 # - SHOST_DIX_TYPE1_PROTECTION 16
5052 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5055 LPFC_ATTR(prot_mask,
5056 (SHOST_DIF_TYPE1_PROTECTION |
5057 SHOST_DIX_TYPE0_PROTECTION |
5058 SHOST_DIX_TYPE1_PROTECTION),
5060 (SHOST_DIF_TYPE1_PROTECTION |
5061 SHOST_DIX_TYPE0_PROTECTION |
5062 SHOST_DIX_TYPE1_PROTECTION),
5063 "T10-DIF host protection capabilities mask");
5066 # lpfc_prot_guard: i
5067 # - Bit mask of protection guard types to register with the SCSI mid-layer
5068 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5069 # - Allows you to ultimately specify which profiles to use
5070 # - Default will result in registering capabilities for all guard types
5073 LPFC_ATTR(prot_guard,
5074 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5075 "T10-DIF host protection guard type");
5078 * Delay initial NPort discovery when Clean Address bit is cleared in
5079 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5080 * This parameter can have value 0 or 1.
5081 * When this parameter is set to 0, no delay is added to the initial
5083 * When this parameter is set to non-zero value, initial Nport discovery is
5084 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5085 * accept and FCID/Fabric name/Fabric portname is changed.
5086 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5087 * when Clean Address bit is cleared in FLOGI/FDISC
5088 * accept and FCID/Fabric name/Fabric portname is changed.
5089 * Default value is 0.
5091 LPFC_ATTR(delay_discovery, 0, 0, 1,
5092 "Delay NPort discovery when Clean Address bit is cleared.");
5095 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5096 * This value can be set to values between 64 and 4096. The default value is
5097 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5098 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5099 * Because of the additional overhead involved in setting up T10-DIF,
5100 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5101 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5103 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5104 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5107 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5108 * 0 = MDS Diagnostics disabled (default)
5109 * 1 = MDS Diagnostics enabled
5110 * Value range is [0,1]. Default value is 0.
5112 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5114 struct device_attribute *lpfc_hba_attrs[] = {
5115 &dev_attr_nvme_info,
5117 &dev_attr_bg_guard_err,
5118 &dev_attr_bg_apptag_err,
5119 &dev_attr_bg_reftag_err,
5121 &dev_attr_serialnum,
5122 &dev_attr_modeldesc,
5123 &dev_attr_modelname,
5124 &dev_attr_programtype,
5128 &dev_attr_option_rom_version,
5129 &dev_attr_link_state,
5130 &dev_attr_num_discovered_ports,
5131 &dev_attr_menlo_mgmt_mode,
5132 &dev_attr_lpfc_drvr_version,
5133 &dev_attr_lpfc_enable_fip,
5134 &dev_attr_lpfc_temp_sensor,
5135 &dev_attr_lpfc_log_verbose,
5136 &dev_attr_lpfc_lun_queue_depth,
5137 &dev_attr_lpfc_tgt_queue_depth,
5138 &dev_attr_lpfc_hba_queue_depth,
5139 &dev_attr_lpfc_peer_port_login,
5140 &dev_attr_lpfc_nodev_tmo,
5141 &dev_attr_lpfc_devloss_tmo,
5142 &dev_attr_lpfc_enable_fc4_type,
5143 &dev_attr_lpfc_xri_split,
5144 &dev_attr_lpfc_fcp_class,
5145 &dev_attr_lpfc_use_adisc,
5146 &dev_attr_lpfc_first_burst_size,
5147 &dev_attr_lpfc_ack0,
5148 &dev_attr_lpfc_topology,
5149 &dev_attr_lpfc_scan_down,
5150 &dev_attr_lpfc_link_speed,
5151 &dev_attr_lpfc_fcp_io_sched,
5152 &dev_attr_lpfc_fcp2_no_tgt_reset,
5153 &dev_attr_lpfc_cr_delay,
5154 &dev_attr_lpfc_cr_count,
5155 &dev_attr_lpfc_multi_ring_support,
5156 &dev_attr_lpfc_multi_ring_rctl,
5157 &dev_attr_lpfc_multi_ring_type,
5158 &dev_attr_lpfc_fdmi_on,
5159 &dev_attr_lpfc_enable_SmartSAN,
5160 &dev_attr_lpfc_max_luns,
5161 &dev_attr_lpfc_enable_npiv,
5162 &dev_attr_lpfc_fcf_failover_policy,
5163 &dev_attr_lpfc_enable_rrq,
5164 &dev_attr_nport_evt_cnt,
5165 &dev_attr_board_mode,
5172 &dev_attr_npiv_info,
5173 &dev_attr_issue_reset,
5174 &dev_attr_lpfc_poll,
5175 &dev_attr_lpfc_poll_tmo,
5176 &dev_attr_lpfc_task_mgmt_tmo,
5177 &dev_attr_lpfc_use_msi,
5178 &dev_attr_lpfc_nvme_oas,
5179 &dev_attr_lpfc_auto_imax,
5180 &dev_attr_lpfc_fcp_imax,
5181 &dev_attr_lpfc_fcp_cpu_map,
5182 &dev_attr_lpfc_fcp_io_channel,
5183 &dev_attr_lpfc_suppress_rsp,
5184 &dev_attr_lpfc_nvme_io_channel,
5185 &dev_attr_lpfc_nvmet_mrq,
5186 &dev_attr_lpfc_nvme_enable_fb,
5187 &dev_attr_lpfc_nvmet_fb_size,
5188 &dev_attr_lpfc_enable_bg,
5189 &dev_attr_lpfc_soft_wwnn,
5190 &dev_attr_lpfc_soft_wwpn,
5191 &dev_attr_lpfc_soft_wwn_enable,
5192 &dev_attr_lpfc_enable_hba_reset,
5193 &dev_attr_lpfc_enable_hba_heartbeat,
5194 &dev_attr_lpfc_EnableXLane,
5195 &dev_attr_lpfc_XLanePriority,
5196 &dev_attr_lpfc_xlane_lun,
5197 &dev_attr_lpfc_xlane_tgt,
5198 &dev_attr_lpfc_xlane_vpt,
5199 &dev_attr_lpfc_xlane_lun_state,
5200 &dev_attr_lpfc_xlane_lun_status,
5201 &dev_attr_lpfc_xlane_priority,
5202 &dev_attr_lpfc_sg_seg_cnt,
5203 &dev_attr_lpfc_max_scsicmpl_time,
5204 &dev_attr_lpfc_stat_data_ctrl,
5205 &dev_attr_lpfc_aer_support,
5206 &dev_attr_lpfc_aer_state_cleanup,
5207 &dev_attr_lpfc_sriov_nr_virtfn,
5208 &dev_attr_lpfc_req_fw_upgrade,
5209 &dev_attr_lpfc_suppress_link_up,
5210 &dev_attr_lpfc_iocb_cnt,
5213 &dev_attr_txcmplq_hw,
5214 &dev_attr_lpfc_fips_level,
5215 &dev_attr_lpfc_fips_rev,
5217 &dev_attr_lpfc_sriov_hw_max_virtfn,
5219 &dev_attr_lpfc_xlane_supported,
5220 &dev_attr_lpfc_enable_mds_diags,
5224 struct device_attribute *lpfc_vport_attrs[] = {
5226 &dev_attr_link_state,
5227 &dev_attr_num_discovered_ports,
5228 &dev_attr_lpfc_drvr_version,
5229 &dev_attr_lpfc_log_verbose,
5230 &dev_attr_lpfc_lun_queue_depth,
5231 &dev_attr_lpfc_tgt_queue_depth,
5232 &dev_attr_lpfc_nodev_tmo,
5233 &dev_attr_lpfc_devloss_tmo,
5234 &dev_attr_lpfc_hba_queue_depth,
5235 &dev_attr_lpfc_peer_port_login,
5236 &dev_attr_lpfc_restrict_login,
5237 &dev_attr_lpfc_fcp_class,
5238 &dev_attr_lpfc_use_adisc,
5239 &dev_attr_lpfc_first_burst_size,
5240 &dev_attr_lpfc_max_luns,
5241 &dev_attr_nport_evt_cnt,
5242 &dev_attr_npiv_info,
5243 &dev_attr_lpfc_enable_da_id,
5244 &dev_attr_lpfc_max_scsicmpl_time,
5245 &dev_attr_lpfc_stat_data_ctrl,
5246 &dev_attr_lpfc_static_vport,
5247 &dev_attr_lpfc_fips_level,
5248 &dev_attr_lpfc_fips_rev,
5253 * sysfs_ctlreg_write - Write method for writing to ctlreg
5254 * @filp: open sysfs file
5255 * @kobj: kernel kobject that contains the kernel class device.
5256 * @bin_attr: kernel attributes passed to us.
5257 * @buf: contains the data to be written to the adapter IOREG space.
5258 * @off: offset into buffer to beginning of data.
5259 * @count: bytes to transfer.
5262 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5263 * Uses the adapter io control registers to send buf contents to the adapter.
5266 * -ERANGE off and count combo out of range
5267 * -EINVAL off, count or buff address invalid
5268 * -EPERM adapter is offline
5269 * value of count, buf contents written
5272 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5273 struct bin_attribute *bin_attr,
5274 char *buf, loff_t off, size_t count)
5277 struct device *dev = container_of(kobj, struct device, kobj);
5278 struct Scsi_Host *shost = class_to_shost(dev);
5279 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5280 struct lpfc_hba *phba = vport->phba;
5282 if (phba->sli_rev >= LPFC_SLI_REV4)
5285 if ((off + count) > FF_REG_AREA_SIZE)
5288 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5291 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5294 /* This is to protect HBA registers from accidental writes. */
5295 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5298 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5301 spin_lock_irq(&phba->hbalock);
5302 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5303 buf_off += sizeof(uint32_t))
5304 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5305 phba->ctrl_regs_memmap_p + off + buf_off);
5307 spin_unlock_irq(&phba->hbalock);
5313 * sysfs_ctlreg_read - Read method for reading from ctlreg
5314 * @filp: open sysfs file
5315 * @kobj: kernel kobject that contains the kernel class device.
5316 * @bin_attr: kernel attributes passed to us.
5317 * @buf: if successful contains the data from the adapter IOREG space.
5318 * @off: offset into buffer to beginning of data.
5319 * @count: bytes to transfer.
5322 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5323 * Uses the adapter io control registers to read data into buf.
5326 * -ERANGE off and count combo out of range
5327 * -EINVAL off, count or buff address invalid
5328 * value of count, buf contents read
5331 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5332 struct bin_attribute *bin_attr,
5333 char *buf, loff_t off, size_t count)
5337 struct device *dev = container_of(kobj, struct device, kobj);
5338 struct Scsi_Host *shost = class_to_shost(dev);
5339 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5340 struct lpfc_hba *phba = vport->phba;
5342 if (phba->sli_rev >= LPFC_SLI_REV4)
5345 if (off > FF_REG_AREA_SIZE)
5348 if ((off + count) > FF_REG_AREA_SIZE)
5349 count = FF_REG_AREA_SIZE - off;
5351 if (count == 0) return 0;
5353 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5356 spin_lock_irq(&phba->hbalock);
5358 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5359 tmp_ptr = (uint32_t *)(buf + buf_off);
5360 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5363 spin_unlock_irq(&phba->hbalock);
5368 static struct bin_attribute sysfs_ctlreg_attr = {
5371 .mode = S_IRUSR | S_IWUSR,
5374 .read = sysfs_ctlreg_read,
5375 .write = sysfs_ctlreg_write,
5379 * sysfs_mbox_write - Write method for writing information via mbox
5380 * @filp: open sysfs file
5381 * @kobj: kernel kobject that contains the kernel class device.
5382 * @bin_attr: kernel attributes passed to us.
5383 * @buf: contains the data to be written to sysfs mbox.
5384 * @off: offset into buffer to beginning of data.
5385 * @count: bytes to transfer.
5388 * Deprecated function. All mailbox access from user space is performed via the
5392 * -EPERM operation not permitted
5395 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5396 struct bin_attribute *bin_attr,
5397 char *buf, loff_t off, size_t count)
5403 * sysfs_mbox_read - Read method for reading information via mbox
5404 * @filp: open sysfs file
5405 * @kobj: kernel kobject that contains the kernel class device.
5406 * @bin_attr: kernel attributes passed to us.
5407 * @buf: contains the data to be read from sysfs mbox.
5408 * @off: offset into buffer to beginning of data.
5409 * @count: bytes to transfer.
5412 * Deprecated function. All mailbox access from user space is performed via the
5416 * -EPERM operation not permitted
5419 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5420 struct bin_attribute *bin_attr,
5421 char *buf, loff_t off, size_t count)
5426 static struct bin_attribute sysfs_mbox_attr = {
5429 .mode = S_IRUSR | S_IWUSR,
5431 .size = MAILBOX_SYSFS_MAX,
5432 .read = sysfs_mbox_read,
5433 .write = sysfs_mbox_write,
5437 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5438 * @vport: address of lpfc vport structure.
5442 * error return code from sysfs_create_bin_file()
5445 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5450 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5451 &sysfs_drvr_stat_data_attr);
5453 /* Virtual ports do not need ctrl_reg and mbox */
5454 if (error || vport->port_type == LPFC_NPIV_PORT)
5457 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5458 &sysfs_ctlreg_attr);
5460 goto out_remove_stat_attr;
5462 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5465 goto out_remove_ctlreg_attr;
5468 out_remove_ctlreg_attr:
5469 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5470 out_remove_stat_attr:
5471 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5472 &sysfs_drvr_stat_data_attr);
5478 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5479 * @vport: address of lpfc vport structure.
5482 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5484 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5485 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5486 &sysfs_drvr_stat_data_attr);
5487 /* Virtual ports do not need ctrl_reg and mbox */
5488 if (vport->port_type == LPFC_NPIV_PORT)
5490 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5491 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5495 * Dynamic FC Host Attributes Support
5499 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5500 * @shost: kernel scsi host pointer.
5503 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5505 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5507 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5508 sizeof fc_host_symbolic_name(shost));
5512 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5513 * @shost: kernel scsi host pointer.
5516 lpfc_get_host_port_id(struct Scsi_Host *shost)
5518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5520 /* note: fc_myDID already in cpu endianness */
5521 fc_host_port_id(shost) = vport->fc_myDID;
5525 * lpfc_get_host_port_type - Set the value of the scsi host port type
5526 * @shost: kernel scsi host pointer.
5529 lpfc_get_host_port_type(struct Scsi_Host *shost)
5531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5532 struct lpfc_hba *phba = vport->phba;
5534 spin_lock_irq(shost->host_lock);
5536 if (vport->port_type == LPFC_NPIV_PORT) {
5537 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5538 } else if (lpfc_is_link_up(phba)) {
5539 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5540 if (vport->fc_flag & FC_PUBLIC_LOOP)
5541 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5543 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5545 if (vport->fc_flag & FC_FABRIC)
5546 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5548 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5551 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5553 spin_unlock_irq(shost->host_lock);
5557 * lpfc_get_host_port_state - Set the value of the scsi host port state
5558 * @shost: kernel scsi host pointer.
5561 lpfc_get_host_port_state(struct Scsi_Host *shost)
5563 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5564 struct lpfc_hba *phba = vport->phba;
5566 spin_lock_irq(shost->host_lock);
5568 if (vport->fc_flag & FC_OFFLINE_MODE)
5569 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5571 switch (phba->link_state) {
5572 case LPFC_LINK_UNKNOWN:
5573 case LPFC_LINK_DOWN:
5574 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5578 case LPFC_HBA_READY:
5579 /* Links up, reports port state accordingly */
5580 if (vport->port_state < LPFC_VPORT_READY)
5581 fc_host_port_state(shost) =
5582 FC_PORTSTATE_BYPASSED;
5584 fc_host_port_state(shost) =
5585 FC_PORTSTATE_ONLINE;
5587 case LPFC_HBA_ERROR:
5588 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5591 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5596 spin_unlock_irq(shost->host_lock);
5600 * lpfc_get_host_speed - Set the value of the scsi host speed
5601 * @shost: kernel scsi host pointer.
5604 lpfc_get_host_speed(struct Scsi_Host *shost)
5606 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5607 struct lpfc_hba *phba = vport->phba;
5609 spin_lock_irq(shost->host_lock);
5611 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5612 switch(phba->fc_linkspeed) {
5613 case LPFC_LINK_SPEED_1GHZ:
5614 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5616 case LPFC_LINK_SPEED_2GHZ:
5617 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5619 case LPFC_LINK_SPEED_4GHZ:
5620 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5622 case LPFC_LINK_SPEED_8GHZ:
5623 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5625 case LPFC_LINK_SPEED_10GHZ:
5626 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5628 case LPFC_LINK_SPEED_16GHZ:
5629 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5631 case LPFC_LINK_SPEED_32GHZ:
5632 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5635 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5639 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5641 spin_unlock_irq(shost->host_lock);
5645 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5646 * @shost: kernel scsi host pointer.
5649 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5651 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5652 struct lpfc_hba *phba = vport->phba;
5655 spin_lock_irq(shost->host_lock);
5657 if ((vport->port_state > LPFC_FLOGI) &&
5658 ((vport->fc_flag & FC_FABRIC) ||
5659 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5660 (vport->fc_flag & FC_PUBLIC_LOOP))))
5661 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5663 /* fabric is local port if there is no F/FL_Port */
5666 spin_unlock_irq(shost->host_lock);
5668 fc_host_fabric_name(shost) = node_name;
5672 * lpfc_get_stats - Return statistical information about the adapter
5673 * @shost: kernel scsi host pointer.
5676 * NULL on error for link down, no mbox pool, sli2 active,
5677 * management not allowed, memory allocation error, or mbox error.
5681 * address of the adapter host statistics
5683 static struct fc_host_statistics *
5684 lpfc_get_stats(struct Scsi_Host *shost)
5686 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5687 struct lpfc_hba *phba = vport->phba;
5688 struct lpfc_sli *psli = &phba->sli;
5689 struct fc_host_statistics *hs = &phba->link_stats;
5690 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5691 LPFC_MBOXQ_t *pmboxq;
5693 unsigned long seconds;
5697 * prevent udev from issuing mailbox commands until the port is
5700 if (phba->link_state < LPFC_LINK_DOWN ||
5701 !phba->mbox_mem_pool ||
5702 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5705 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5708 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5711 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5713 pmb = &pmboxq->u.mb;
5714 pmb->mbxCommand = MBX_READ_STATUS;
5715 pmb->mbxOwner = OWN_HOST;
5716 pmboxq->context1 = NULL;
5717 pmboxq->vport = vport;
5719 if (vport->fc_flag & FC_OFFLINE_MODE)
5720 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5722 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5724 if (rc != MBX_SUCCESS) {
5725 if (rc != MBX_TIMEOUT)
5726 mempool_free(pmboxq, phba->mbox_mem_pool);
5730 memset(hs, 0, sizeof (struct fc_host_statistics));
5732 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5734 * The MBX_READ_STATUS returns tx_k_bytes which has to
5735 * converted to words
5737 hs->tx_words = (uint64_t)
5738 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5740 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5741 hs->rx_words = (uint64_t)
5742 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5745 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5746 pmb->mbxCommand = MBX_READ_LNK_STAT;
5747 pmb->mbxOwner = OWN_HOST;
5748 pmboxq->context1 = NULL;
5749 pmboxq->vport = vport;
5751 if (vport->fc_flag & FC_OFFLINE_MODE)
5752 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5754 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5756 if (rc != MBX_SUCCESS) {
5757 if (rc != MBX_TIMEOUT)
5758 mempool_free(pmboxq, phba->mbox_mem_pool);
5762 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5763 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5764 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5765 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5766 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5767 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5768 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5770 hs->link_failure_count -= lso->link_failure_count;
5771 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5772 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5773 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5774 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5775 hs->invalid_crc_count -= lso->invalid_crc_count;
5776 hs->error_frames -= lso->error_frames;
5778 if (phba->hba_flag & HBA_FCOE_MODE) {
5780 hs->nos_count = (phba->link_events >> 1);
5781 hs->nos_count -= lso->link_events;
5782 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5783 hs->lip_count = (phba->fc_eventTag >> 1);
5784 hs->lip_count -= lso->link_events;
5788 hs->nos_count = (phba->fc_eventTag >> 1);
5789 hs->nos_count -= lso->link_events;
5792 hs->dumped_frames = -1;
5794 seconds = get_seconds();
5795 if (seconds < psli->stats_start)
5796 hs->seconds_since_last_reset = seconds +
5797 ((unsigned long)-1 - psli->stats_start);
5799 hs->seconds_since_last_reset = seconds - psli->stats_start;
5801 mempool_free(pmboxq, phba->mbox_mem_pool);
5807 * lpfc_reset_stats - Copy the adapter link stats information
5808 * @shost: kernel scsi host pointer.
5811 lpfc_reset_stats(struct Scsi_Host *shost)
5813 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5814 struct lpfc_hba *phba = vport->phba;
5815 struct lpfc_sli *psli = &phba->sli;
5816 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5817 LPFC_MBOXQ_t *pmboxq;
5821 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5824 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5827 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5829 pmb = &pmboxq->u.mb;
5830 pmb->mbxCommand = MBX_READ_STATUS;
5831 pmb->mbxOwner = OWN_HOST;
5832 pmb->un.varWords[0] = 0x1; /* reset request */
5833 pmboxq->context1 = NULL;
5834 pmboxq->vport = vport;
5836 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5837 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5838 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5840 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5842 if (rc != MBX_SUCCESS) {
5843 if (rc != MBX_TIMEOUT)
5844 mempool_free(pmboxq, phba->mbox_mem_pool);
5848 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5849 pmb->mbxCommand = MBX_READ_LNK_STAT;
5850 pmb->mbxOwner = OWN_HOST;
5851 pmboxq->context1 = NULL;
5852 pmboxq->vport = vport;
5854 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5855 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5856 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5858 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5860 if (rc != MBX_SUCCESS) {
5861 if (rc != MBX_TIMEOUT)
5862 mempool_free( pmboxq, phba->mbox_mem_pool);
5866 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5867 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5868 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5869 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5870 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5871 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5872 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5873 if (phba->hba_flag & HBA_FCOE_MODE)
5874 lso->link_events = (phba->link_events >> 1);
5876 lso->link_events = (phba->fc_eventTag >> 1);
5878 psli->stats_start = get_seconds();
5880 mempool_free(pmboxq, phba->mbox_mem_pool);
5886 * The LPFC driver treats linkdown handling as target loss events so there
5887 * are no sysfs handlers for link_down_tmo.
5891 * lpfc_get_node_by_target - Return the nodelist for a target
5892 * @starget: kernel scsi target pointer.
5895 * address of the node list if found
5896 * NULL target not found
5898 static struct lpfc_nodelist *
5899 lpfc_get_node_by_target(struct scsi_target *starget)
5901 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5902 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5903 struct lpfc_nodelist *ndlp;
5905 spin_lock_irq(shost->host_lock);
5906 /* Search for this, mapped, target ID */
5907 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5908 if (NLP_CHK_NODE_ACT(ndlp) &&
5909 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5910 starget->id == ndlp->nlp_sid) {
5911 spin_unlock_irq(shost->host_lock);
5915 spin_unlock_irq(shost->host_lock);
5920 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5921 * @starget: kernel scsi target pointer.
5924 lpfc_get_starget_port_id(struct scsi_target *starget)
5926 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5928 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5932 * lpfc_get_starget_node_name - Set the target node name
5933 * @starget: kernel scsi target pointer.
5935 * Description: Set the target node name to the ndlp node name wwn or zero.
5938 lpfc_get_starget_node_name(struct scsi_target *starget)
5940 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5942 fc_starget_node_name(starget) =
5943 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5947 * lpfc_get_starget_port_name - Set the target port name
5948 * @starget: kernel scsi target pointer.
5950 * Description: set the target port name to the ndlp port name wwn or zero.
5953 lpfc_get_starget_port_name(struct scsi_target *starget)
5955 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5957 fc_starget_port_name(starget) =
5958 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5962 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5963 * @rport: fc rport address.
5964 * @timeout: new value for dev loss tmo.
5967 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5968 * dev_loss_tmo to one.
5971 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5974 rport->dev_loss_tmo = timeout;
5976 rport->dev_loss_tmo = 1;
5980 * lpfc_rport_show_function - Return rport target information
5983 * Macro that uses field to generate a function with the name lpfc_show_rport_
5985 * lpfc_show_rport_##field: returns the bytes formatted in buf
5986 * @cdev: class converted to an fc_rport.
5987 * @buf: on return contains the target_field or zero.
5989 * Returns: size of formatted string.
5991 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5993 lpfc_show_rport_##field (struct device *dev, \
5994 struct device_attribute *attr, \
5997 struct fc_rport *rport = transport_class_to_rport(dev); \
5998 struct lpfc_rport_data *rdata = rport->hostdata; \
5999 return snprintf(buf, sz, format_string, \
6000 (rdata->target) ? cast rdata->target->field : 0); \
6003 #define lpfc_rport_rd_attr(field, format_string, sz) \
6004 lpfc_rport_show_function(field, format_string, sz, ) \
6005 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6008 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6009 * @fc_vport: The fc_vport who's symbolic name has been changed.
6012 * This function is called by the transport after the @fc_vport's symbolic name
6013 * has been changed. This function re-registers the symbolic name with the
6014 * switch to propagate the change into the fabric if the vport is active.
6017 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6019 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6021 if (vport->port_state == LPFC_VPORT_READY)
6022 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6026 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6027 * @phba: Pointer to lpfc_hba struct.
6029 * This function is called by the lpfc_get_cfgparam() routine to set the
6030 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6031 * log message according to the module's lpfc_log_verbose parameter setting
6032 * before hba port or vport created.
6035 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6037 phba->cfg_log_verbose = verbose;
6040 struct fc_function_template lpfc_transport_functions = {
6041 /* fixed attributes the driver supports */
6042 .show_host_node_name = 1,
6043 .show_host_port_name = 1,
6044 .show_host_supported_classes = 1,
6045 .show_host_supported_fc4s = 1,
6046 .show_host_supported_speeds = 1,
6047 .show_host_maxframe_size = 1,
6049 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6050 .show_host_symbolic_name = 1,
6052 /* dynamic attributes the driver supports */
6053 .get_host_port_id = lpfc_get_host_port_id,
6054 .show_host_port_id = 1,
6056 .get_host_port_type = lpfc_get_host_port_type,
6057 .show_host_port_type = 1,
6059 .get_host_port_state = lpfc_get_host_port_state,
6060 .show_host_port_state = 1,
6062 /* active_fc4s is shown but doesn't change (thus no get function) */
6063 .show_host_active_fc4s = 1,
6065 .get_host_speed = lpfc_get_host_speed,
6066 .show_host_speed = 1,
6068 .get_host_fabric_name = lpfc_get_host_fabric_name,
6069 .show_host_fabric_name = 1,
6072 * The LPFC driver treats linkdown handling as target loss events
6073 * so there are no sysfs handlers for link_down_tmo.
6076 .get_fc_host_stats = lpfc_get_stats,
6077 .reset_fc_host_stats = lpfc_reset_stats,
6079 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6080 .show_rport_maxframe_size = 1,
6081 .show_rport_supported_classes = 1,
6083 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6084 .show_rport_dev_loss_tmo = 1,
6086 .get_starget_port_id = lpfc_get_starget_port_id,
6087 .show_starget_port_id = 1,
6089 .get_starget_node_name = lpfc_get_starget_node_name,
6090 .show_starget_node_name = 1,
6092 .get_starget_port_name = lpfc_get_starget_port_name,
6093 .show_starget_port_name = 1,
6095 .issue_fc_host_lip = lpfc_issue_lip,
6096 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6097 .terminate_rport_io = lpfc_terminate_rport_io,
6099 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6101 .vport_disable = lpfc_vport_disable,
6103 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6105 .bsg_request = lpfc_bsg_request,
6106 .bsg_timeout = lpfc_bsg_timeout,
6109 struct fc_function_template lpfc_vport_transport_functions = {
6110 /* fixed attributes the driver supports */
6111 .show_host_node_name = 1,
6112 .show_host_port_name = 1,
6113 .show_host_supported_classes = 1,
6114 .show_host_supported_fc4s = 1,
6115 .show_host_supported_speeds = 1,
6116 .show_host_maxframe_size = 1,
6118 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6119 .show_host_symbolic_name = 1,
6121 /* dynamic attributes the driver supports */
6122 .get_host_port_id = lpfc_get_host_port_id,
6123 .show_host_port_id = 1,
6125 .get_host_port_type = lpfc_get_host_port_type,
6126 .show_host_port_type = 1,
6128 .get_host_port_state = lpfc_get_host_port_state,
6129 .show_host_port_state = 1,
6131 /* active_fc4s is shown but doesn't change (thus no get function) */
6132 .show_host_active_fc4s = 1,
6134 .get_host_speed = lpfc_get_host_speed,
6135 .show_host_speed = 1,
6137 .get_host_fabric_name = lpfc_get_host_fabric_name,
6138 .show_host_fabric_name = 1,
6141 * The LPFC driver treats linkdown handling as target loss events
6142 * so there are no sysfs handlers for link_down_tmo.
6145 .get_fc_host_stats = lpfc_get_stats,
6146 .reset_fc_host_stats = lpfc_reset_stats,
6148 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6149 .show_rport_maxframe_size = 1,
6150 .show_rport_supported_classes = 1,
6152 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6153 .show_rport_dev_loss_tmo = 1,
6155 .get_starget_port_id = lpfc_get_starget_port_id,
6156 .show_starget_port_id = 1,
6158 .get_starget_node_name = lpfc_get_starget_node_name,
6159 .show_starget_node_name = 1,
6161 .get_starget_port_name = lpfc_get_starget_port_name,
6162 .show_starget_port_name = 1,
6164 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6165 .terminate_rport_io = lpfc_terminate_rport_io,
6167 .vport_disable = lpfc_vport_disable,
6169 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6173 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6174 * @phba: lpfc_hba pointer.
6177 lpfc_get_cfgparam(struct lpfc_hba *phba)
6179 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6180 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6181 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6182 lpfc_cr_count_init(phba, lpfc_cr_count);
6183 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6184 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6185 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6186 lpfc_ack0_init(phba, lpfc_ack0);
6187 lpfc_topology_init(phba, lpfc_topology);
6188 lpfc_link_speed_init(phba, lpfc_link_speed);
6189 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6190 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6191 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6192 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6193 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6194 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6195 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6196 lpfc_use_msi_init(phba, lpfc_use_msi);
6197 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6198 lpfc_auto_imax_init(phba, lpfc_auto_imax);
6199 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6200 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6201 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6202 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6204 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6205 if (phba->sli_rev != LPFC_SLI_REV4)
6206 phba->cfg_EnableXLane = 0;
6207 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6209 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6210 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6211 phba->cfg_oas_lun_state = 0;
6212 phba->cfg_oas_lun_status = 0;
6213 phba->cfg_oas_flags = 0;
6214 phba->cfg_oas_priority = 0;
6215 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6216 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6217 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6218 if (phba->sli_rev == LPFC_SLI_REV4)
6221 phba->cfg_poll = lpfc_poll;
6222 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6224 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6225 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6227 /* Initialize first burst. Target vs Initiator are different. */
6228 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6229 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6230 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6231 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6233 if (phba->sli_rev != LPFC_SLI_REV4) {
6234 /* NVME only supported on SLI4 */
6235 phba->nvmet_support = 0;
6236 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6238 /* We MUST have FCP support */
6239 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6240 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6243 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6244 phba->cfg_auto_imax = 0;
6245 phba->initial_imax = phba->cfg_fcp_imax;
6247 /* A value of 0 means use the number of CPUs found in the system */
6248 if (phba->cfg_fcp_io_channel == 0)
6249 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6250 if (phba->cfg_nvme_io_channel == 0)
6251 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6253 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6254 phba->cfg_fcp_io_channel = 0;
6256 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6257 phba->cfg_nvme_io_channel = 0;
6259 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6260 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6262 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6264 phba->cfg_soft_wwnn = 0L;
6265 phba->cfg_soft_wwpn = 0L;
6266 lpfc_xri_split_init(phba, lpfc_xri_split);
6267 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6268 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6269 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6270 lpfc_aer_support_init(phba, lpfc_aer_support);
6271 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6272 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6273 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6274 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6275 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6276 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6277 phba->cfg_enable_dss = 1;
6278 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6283 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6284 * dependencies between protocols and roles.
6285 * @phba: lpfc_hba pointer.
6288 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6290 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6291 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6293 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6294 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6296 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6297 phba->nvmet_support) {
6298 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6299 phba->cfg_fcp_io_channel = 0;
6301 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6302 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6303 "NVME Target PRLI ACC enable_fb ",
6304 phba->cfg_nvme_enable_fb,
6305 phba->cfg_nvmet_fb_size,
6306 LPFC_NVMET_FB_SZ_MAX);
6308 if (phba->cfg_nvme_enable_fb == 0)
6309 phba->cfg_nvmet_fb_size = 0;
6311 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6312 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6315 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6316 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6317 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6318 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6319 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6320 phba->cfg_nvmet_mrq);
6323 /* Not NVME Target mode. Turn off Target parameters. */
6324 phba->nvmet_support = 0;
6325 phba->cfg_nvmet_mrq = 0;
6326 phba->cfg_nvmet_fb_size = 0;
6329 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6330 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6332 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6336 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6337 * @vport: lpfc_vport pointer.
6340 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6342 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6343 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6344 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6345 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6346 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6347 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6348 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6349 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6350 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6351 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6352 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6353 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6354 lpfc_max_luns_init(vport, lpfc_max_luns);
6355 lpfc_scan_down_init(vport, lpfc_scan_down);
6356 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);