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_nvme_lport *lport;
152 struct lpfc_nvme_rport *rport;
153 struct nvme_fc_remote_port *nrport;
157 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
158 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
161 if (phba->nvmet_support) {
162 if (!phba->targetport) {
163 len = snprintf(buf, PAGE_SIZE,
164 "NVME Target: x%llx is not allocated\n",
165 wwn_to_u64(vport->fc_portname.u.wwn));
168 /* Port state is only one of two values for now. */
169 if (phba->targetport->port_id)
170 statep = "REGISTERED";
173 len += snprintf(buf + len, PAGE_SIZE - len,
174 "NVME Target: Enabled State %s\n",
176 len += snprintf(buf + len, PAGE_SIZE - len,
177 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
180 wwn_to_u64(vport->fc_portname.u.wwn),
181 wwn_to_u64(vport->fc_nodename.u.wwn),
182 phba->targetport->port_id);
184 len += snprintf(buf + len, PAGE_SIZE - 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 len += snprintf(buf + len, PAGE_SIZE - len,
249 "IO_CTX: %08x outstanding %08x total %x",
250 phba->sli4_hba.nvmet_ctx_cnt,
251 phba->sli4_hba.nvmet_io_wait_cnt,
252 phba->sli4_hba.nvmet_io_wait_total);
254 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
258 localport = vport->localport;
260 len = snprintf(buf, PAGE_SIZE,
261 "NVME Initiator x%llx is not allocated\n",
262 wwn_to_u64(vport->fc_portname.u.wwn));
265 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
267 spin_lock_irq(shost->host_lock);
268 lport = (struct lpfc_nvme_lport *)localport->private;
270 /* Port state is only one of two values for now. */
271 if (localport->port_id)
276 len += snprintf(buf + len, PAGE_SIZE - len,
277 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
280 wwn_to_u64(vport->fc_portname.u.wwn),
281 wwn_to_u64(vport->fc_nodename.u.wwn),
282 localport->port_id, statep);
284 list_for_each_entry(rport, &lport->rport_list, list) {
285 /* local short-hand pointer. */
286 nrport = rport->remoteport;
288 /* Port state is only one of two values for now. */
289 switch (nrport->port_state) {
290 case FC_OBJSTATE_ONLINE:
293 case FC_OBJSTATE_UNKNOWN:
297 statep = "UNSUPPORTED";
301 /* Tab in to show lport ownership. */
302 len += snprintf(buf + len, PAGE_SIZE - len,
304 if (phba->brd_no >= 10)
305 len += snprintf(buf + len, PAGE_SIZE - len, " ");
307 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
309 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
311 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
314 switch (nrport->port_role) {
315 case FC_PORT_ROLE_NVME_INITIATOR:
316 len += snprintf(buf + len, PAGE_SIZE - len,
319 case FC_PORT_ROLE_NVME_TARGET:
320 len += snprintf(buf + len, PAGE_SIZE - len,
323 case FC_PORT_ROLE_NVME_DISCOVERY:
324 len += snprintf(buf + len, PAGE_SIZE - len,
328 len += snprintf(buf + len, PAGE_SIZE - len,
333 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
334 /* Terminate the string. */
335 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
337 spin_unlock_irq(shost->host_lock);
339 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
340 len += snprintf(buf+len, PAGE_SIZE-len,
341 "LS: Xmt %016llx Cmpl %016llx\n",
342 phba->fc4NvmeLsRequests,
343 phba->fc4NvmeLsCmpls);
345 len += snprintf(buf+len, PAGE_SIZE-len,
346 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
347 phba->fc4NvmeInputRequests,
348 phba->fc4NvmeOutputRequests,
349 phba->fc4NvmeControlRequests);
351 len += snprintf(buf+len, PAGE_SIZE-len,
352 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
358 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
361 struct Scsi_Host *shost = class_to_shost(dev);
362 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
363 struct lpfc_hba *phba = vport->phba;
365 if (phba->cfg_enable_bg)
366 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
367 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
369 return snprintf(buf, PAGE_SIZE,
370 "BlockGuard Not Supported\n");
372 return snprintf(buf, PAGE_SIZE,
373 "BlockGuard Disabled\n");
377 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
380 struct Scsi_Host *shost = class_to_shost(dev);
381 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
382 struct lpfc_hba *phba = vport->phba;
384 return snprintf(buf, PAGE_SIZE, "%llu\n",
385 (unsigned long long)phba->bg_guard_err_cnt);
389 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
392 struct Scsi_Host *shost = class_to_shost(dev);
393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394 struct lpfc_hba *phba = vport->phba;
396 return snprintf(buf, PAGE_SIZE, "%llu\n",
397 (unsigned long long)phba->bg_apptag_err_cnt);
401 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
404 struct Scsi_Host *shost = class_to_shost(dev);
405 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
406 struct lpfc_hba *phba = vport->phba;
408 return snprintf(buf, PAGE_SIZE, "%llu\n",
409 (unsigned long long)phba->bg_reftag_err_cnt);
413 * lpfc_info_show - Return some pci info about the host in ascii
414 * @dev: class converted to a Scsi_host structure.
415 * @attr: device attribute, not used.
416 * @buf: on return contains the formatted text from lpfc_info().
418 * Returns: size of formatted string.
421 lpfc_info_show(struct device *dev, struct device_attribute *attr,
424 struct Scsi_Host *host = class_to_shost(dev);
426 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
430 * lpfc_serialnum_show - Return the hba serial number in ascii
431 * @dev: class converted to a Scsi_host structure.
432 * @attr: device attribute, not used.
433 * @buf: on return contains the formatted text serial number.
435 * Returns: size of formatted string.
438 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
441 struct Scsi_Host *shost = class_to_shost(dev);
442 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
443 struct lpfc_hba *phba = vport->phba;
445 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
449 * lpfc_temp_sensor_show - Return the temperature sensor level
450 * @dev: class converted to a Scsi_host structure.
451 * @attr: device attribute, not used.
452 * @buf: on return contains the formatted support level.
455 * Returns a number indicating the temperature sensor level currently
456 * supported, zero or one in ascii.
458 * Returns: size of formatted string.
461 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
464 struct Scsi_Host *shost = class_to_shost(dev);
465 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
466 struct lpfc_hba *phba = vport->phba;
467 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
471 * lpfc_modeldesc_show - Return the model description of the hba
472 * @dev: class converted to a Scsi_host structure.
473 * @attr: device attribute, not used.
474 * @buf: on return contains the scsi vpd model description.
476 * Returns: size of formatted string.
479 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
482 struct Scsi_Host *shost = class_to_shost(dev);
483 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
484 struct lpfc_hba *phba = vport->phba;
486 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
490 * lpfc_modelname_show - Return the model name of the hba
491 * @dev: class converted to a Scsi_host structure.
492 * @attr: device attribute, not used.
493 * @buf: on return contains the scsi vpd model name.
495 * Returns: size of formatted string.
498 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
501 struct Scsi_Host *shost = class_to_shost(dev);
502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
503 struct lpfc_hba *phba = vport->phba;
505 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
509 * lpfc_programtype_show - Return the program type of the hba
510 * @dev: class converted to a Scsi_host structure.
511 * @attr: device attribute, not used.
512 * @buf: on return contains the scsi vpd program type.
514 * Returns: size of formatted string.
517 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
520 struct Scsi_Host *shost = class_to_shost(dev);
521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
522 struct lpfc_hba *phba = vport->phba;
524 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
528 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
529 * @dev: class converted to a Scsi_host structure.
530 * @attr: device attribute, not used.
531 * @buf: on return contains the Menlo Maintenance sli flag.
533 * Returns: size of formatted string.
536 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
538 struct Scsi_Host *shost = class_to_shost(dev);
539 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
540 struct lpfc_hba *phba = vport->phba;
542 return snprintf(buf, PAGE_SIZE, "%d\n",
543 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
547 * lpfc_vportnum_show - Return the port number in ascii of the hba
548 * @dev: class converted to a Scsi_host structure.
549 * @attr: device attribute, not used.
550 * @buf: on return contains scsi vpd program type.
552 * Returns: size of formatted string.
555 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
558 struct Scsi_Host *shost = class_to_shost(dev);
559 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
560 struct lpfc_hba *phba = vport->phba;
562 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
566 * lpfc_fwrev_show - Return the firmware rev running in the hba
567 * @dev: class converted to a Scsi_host structure.
568 * @attr: device attribute, not used.
569 * @buf: on return contains the scsi vpd program type.
571 * Returns: size of formatted string.
574 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
577 struct Scsi_Host *shost = class_to_shost(dev);
578 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
579 struct lpfc_hba *phba = vport->phba;
582 char fwrev[FW_REV_STR_SIZE];
585 lpfc_decode_firmware_rev(phba, fwrev, 1);
586 if_type = phba->sli4_hba.pc_sli4_params.if_type;
587 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
589 if (phba->sli_rev < LPFC_SLI_REV4)
590 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
591 fwrev, phba->sli_rev);
593 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
594 fwrev, phba->sli_rev, if_type, sli_family);
600 * lpfc_hdw_show - Return the jedec information about the hba
601 * @dev: class converted to a Scsi_host structure.
602 * @attr: device attribute, not used.
603 * @buf: on return contains the scsi vpd program type.
605 * Returns: size of formatted string.
608 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
611 struct Scsi_Host *shost = class_to_shost(dev);
612 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
613 struct lpfc_hba *phba = vport->phba;
614 lpfc_vpd_t *vp = &phba->vpd;
616 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
617 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
621 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
622 * @dev: class converted to a Scsi_host structure.
623 * @attr: device attribute, not used.
624 * @buf: on return contains the ROM and FCode ascii strings.
626 * Returns: size of formatted string.
629 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
632 struct Scsi_Host *shost = class_to_shost(dev);
633 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
634 struct lpfc_hba *phba = vport->phba;
635 char fwrev[FW_REV_STR_SIZE];
637 if (phba->sli_rev < LPFC_SLI_REV4)
638 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
640 lpfc_decode_firmware_rev(phba, fwrev, 1);
641 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
645 * lpfc_state_show - Return the link state of the port
646 * @dev: class converted to a Scsi_host structure.
647 * @attr: device attribute, not used.
648 * @buf: on return contains text describing the state of the link.
651 * The switch statement has no default so zero will be returned.
653 * Returns: size of formatted string.
656 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
659 struct Scsi_Host *shost = class_to_shost(dev);
660 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
661 struct lpfc_hba *phba = vport->phba;
664 switch (phba->link_state) {
665 case LPFC_LINK_UNKNOWN:
666 case LPFC_WARM_START:
667 case LPFC_INIT_START:
668 case LPFC_INIT_MBX_CMDS:
671 if (phba->hba_flag & LINK_DISABLED)
672 len += snprintf(buf + len, PAGE_SIZE-len,
673 "Link Down - User disabled\n");
675 len += snprintf(buf + len, PAGE_SIZE-len,
681 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
683 switch (vport->port_state) {
684 case LPFC_LOCAL_CFG_LINK:
685 len += snprintf(buf + len, PAGE_SIZE-len,
686 "Configuring Link\n");
690 case LPFC_FABRIC_CFG_LINK:
693 case LPFC_BUILD_DISC_LIST:
695 len += snprintf(buf + len, PAGE_SIZE - len,
698 case LPFC_VPORT_READY:
699 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
702 case LPFC_VPORT_FAILED:
703 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
706 case LPFC_VPORT_UNKNOWN:
707 len += snprintf(buf + len, PAGE_SIZE - len,
711 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
712 len += snprintf(buf + len, PAGE_SIZE-len,
713 " Menlo Maint Mode\n");
714 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
715 if (vport->fc_flag & FC_PUBLIC_LOOP)
716 len += snprintf(buf + len, PAGE_SIZE-len,
719 len += snprintf(buf + len, PAGE_SIZE-len,
722 if (vport->fc_flag & FC_FABRIC)
723 len += snprintf(buf + len, PAGE_SIZE-len,
726 len += snprintf(buf + len, PAGE_SIZE-len,
735 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
736 * @dev: class unused variable.
737 * @attr: device attribute, not used.
738 * @buf: on return contains the module description text.
740 * Returns: size of formatted string.
743 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
746 struct Scsi_Host *shost = class_to_shost(dev);
747 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
748 struct lpfc_hba *phba = vport->phba;
750 if (phba->sli_rev < LPFC_SLI_REV4)
751 return snprintf(buf, PAGE_SIZE, "fc\n");
753 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
754 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
755 return snprintf(buf, PAGE_SIZE, "fcoe\n");
756 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
757 return snprintf(buf, PAGE_SIZE, "fc\n");
759 return snprintf(buf, PAGE_SIZE, "unknown\n");
763 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
764 * (OAS) is supported.
765 * @dev: class unused variable.
766 * @attr: device attribute, not used.
767 * @buf: on return contains the module description text.
769 * Returns: size of formatted string.
772 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
775 struct Scsi_Host *shost = class_to_shost(dev);
776 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
777 struct lpfc_hba *phba = vport->phba;
779 return snprintf(buf, PAGE_SIZE, "%d\n",
780 phba->sli4_hba.pc_sli4_params.oas_supported);
784 * lpfc_link_state_store - Transition the link_state on an HBA port
785 * @dev: class device that is converted into a Scsi_host.
786 * @attr: device attribute, not used.
787 * @buf: one or more lpfc_polling_flags values.
791 * -EINVAL if the buffer is not "up" or "down"
792 * return from link state change function if non-zero
793 * length of the buf on success
796 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
797 const char *buf, size_t count)
799 struct Scsi_Host *shost = class_to_shost(dev);
800 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
801 struct lpfc_hba *phba = vport->phba;
803 int status = -EINVAL;
805 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
806 (phba->link_state == LPFC_LINK_DOWN))
807 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
808 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
809 (phba->link_state >= LPFC_LINK_UP))
810 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
819 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
820 * @dev: class device that is converted into a Scsi_host.
821 * @attr: device attribute, not used.
822 * @buf: on return contains the sum of fc mapped and unmapped.
825 * Returns the ascii text number of the sum of the fc mapped and unmapped
828 * Returns: size of formatted string.
831 lpfc_num_discovered_ports_show(struct device *dev,
832 struct device_attribute *attr, char *buf)
834 struct Scsi_Host *shost = class_to_shost(dev);
835 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
837 return snprintf(buf, PAGE_SIZE, "%d\n",
838 vport->fc_map_cnt + vport->fc_unmap_cnt);
842 * lpfc_issue_lip - Misnomer, name carried over from long ago
843 * @shost: Scsi_Host pointer.
846 * Bring the link down gracefully then re-init the link. The firmware will
847 * re-init the fiber channel interface as required. Does not issue a LIP.
850 * -EPERM port offline or management commands are being blocked
851 * -ENOMEM cannot allocate memory for the mailbox command
852 * -EIO error sending the mailbox command
856 lpfc_issue_lip(struct Scsi_Host *shost)
858 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
859 struct lpfc_hba *phba = vport->phba;
860 LPFC_MBOXQ_t *pmboxq;
861 int mbxstatus = MBXERR_ERROR;
863 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
864 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
867 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
872 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
873 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
874 pmboxq->u.mb.mbxOwner = OWN_HOST;
876 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
878 if ((mbxstatus == MBX_SUCCESS) &&
879 (pmboxq->u.mb.mbxStatus == 0 ||
880 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
881 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
882 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
883 phba->cfg_link_speed);
884 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
886 if ((mbxstatus == MBX_SUCCESS) &&
887 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
888 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
889 "2859 SLI authentication is required "
890 "for INIT_LINK but has not done yet\n");
893 lpfc_set_loopback_flag(phba);
894 if (mbxstatus != MBX_TIMEOUT)
895 mempool_free(pmboxq, phba->mbox_mem_pool);
897 if (mbxstatus == MBXERR_ERROR)
904 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
909 while (!list_empty(q)) {
910 spin_unlock_irq(lock);
912 if (cnt++ > 250) { /* 5 secs */
913 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
915 "Outstanding IO when ",
916 "bringing Adapter offline\n");
921 spin_unlock_irq(lock);
926 * lpfc_do_offline - Issues a mailbox command to bring the link down
927 * @phba: lpfc_hba pointer.
928 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
931 * Assumes any error from lpfc_do_offline() will be negative.
932 * Can wait up to 5 seconds for the port ring buffers count
933 * to reach zero, prints a warning if it is not zero and continues.
934 * lpfc_workq_post_event() returns a non-zero return code if call fails.
937 * -EIO error posting the event
941 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
943 struct completion online_compl;
944 struct lpfc_queue *qp = NULL;
945 struct lpfc_sli_ring *pring;
946 struct lpfc_sli *psli;
951 init_completion(&online_compl);
952 rc = lpfc_workq_post_event(phba, &status, &online_compl,
953 LPFC_EVT_OFFLINE_PREP);
957 wait_for_completion(&online_compl);
964 /* Wait a little for things to settle down, but not
965 * long enough for dev loss timeout to expire.
967 if (phba->sli_rev != LPFC_SLI_REV4) {
968 for (i = 0; i < psli->num_rings; i++) {
969 pring = &psli->sli3_ring[i];
970 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
975 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
979 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
985 init_completion(&online_compl);
986 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
990 wait_for_completion(&online_compl);
999 * lpfc_selective_reset - Offline then onlines the port
1000 * @phba: lpfc_hba pointer.
1003 * If the port is configured to allow a reset then the hba is brought
1004 * offline then online.
1007 * Assumes any error from lpfc_do_offline() will be negative.
1008 * Do not make this function static.
1011 * lpfc_do_offline() return code if not zero
1012 * -EIO reset not configured or error posting the event
1016 lpfc_selective_reset(struct lpfc_hba *phba)
1018 struct completion online_compl;
1022 if (!phba->cfg_enable_hba_reset)
1025 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1026 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1032 init_completion(&online_compl);
1033 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1038 wait_for_completion(&online_compl);
1047 * lpfc_issue_reset - Selectively resets an adapter
1048 * @dev: class device that is converted into a Scsi_host.
1049 * @attr: device attribute, not used.
1050 * @buf: containing the string "selective".
1051 * @count: unused variable.
1054 * If the buf contains the string "selective" then lpfc_selective_reset()
1055 * is called to perform the reset.
1058 * Assumes any error from lpfc_selective_reset() will be negative.
1059 * If lpfc_selective_reset() returns zero then the length of the buffer
1060 * is returned which indicates success
1063 * -EINVAL if the buffer does not contain the string "selective"
1064 * length of buf if lpfc-selective_reset() if the call succeeds
1065 * return value of lpfc_selective_reset() if the call fails
1068 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1069 const char *buf, size_t count)
1071 struct Scsi_Host *shost = class_to_shost(dev);
1072 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1073 struct lpfc_hba *phba = vport->phba;
1074 int status = -EINVAL;
1076 if (!phba->cfg_enable_hba_reset)
1079 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1080 status = phba->lpfc_selective_reset(phba);
1089 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1090 * @phba: lpfc_hba pointer.
1093 * SLI4 interface type-2 device to wait on the sliport status register for
1094 * the readyness after performing a firmware reset.
1097 * zero for success, -EPERM when port does not have privilege to perform the
1098 * reset, -EIO when port timeout from recovering from the reset.
1101 * As the caller will interpret the return code by value, be careful in making
1102 * change or addition to return codes.
1105 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1107 struct lpfc_register portstat_reg = {0};
1111 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1112 &portstat_reg.word0);
1114 /* verify if privileged for the request operation */
1115 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1116 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1119 /* wait for the SLI port firmware ready after firmware reset */
1120 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1122 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1123 &portstat_reg.word0);
1124 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1126 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1128 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1133 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1140 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1141 * @phba: lpfc_hba pointer.
1144 * Request SLI4 interface type-2 device to perform a physical register set
1151 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1153 struct completion online_compl;
1154 struct pci_dev *pdev = phba->pcidev;
1155 uint32_t before_fc_flag;
1156 uint32_t sriov_nr_virtfn;
1158 int status = 0, rc = 0;
1159 int job_posted = 1, sriov_err;
1161 if (!phba->cfg_enable_hba_reset)
1164 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1165 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1166 LPFC_SLI_INTF_IF_TYPE_2))
1169 /* Keep state if we need to restore back */
1170 before_fc_flag = phba->pport->fc_flag;
1171 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1173 /* Disable SR-IOV virtual functions if enabled */
1174 if (phba->cfg_sriov_nr_virtfn) {
1175 pci_disable_sriov(pdev);
1176 phba->cfg_sriov_nr_virtfn = 0;
1179 if (opcode == LPFC_FW_DUMP)
1180 phba->hba_flag |= HBA_FW_DUMP_OP;
1182 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1185 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1189 /* wait for the device to be quiesced before firmware reset */
1192 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1193 LPFC_CTL_PDEV_CTL_OFFSET);
1195 if (opcode == LPFC_FW_DUMP)
1196 reg_val |= LPFC_FW_DUMP_REQUEST;
1197 else if (opcode == LPFC_FW_RESET)
1198 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1199 else if (opcode == LPFC_DV_RESET)
1200 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1202 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1203 LPFC_CTL_PDEV_CTL_OFFSET);
1205 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1207 /* delay driver action following IF_TYPE_2 reset */
1208 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1211 /* no privilege for reset */
1212 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1213 "3150 No privilege to perform the requested "
1214 "access: x%x\n", reg_val);
1215 } else if (rc == -EIO) {
1216 /* reset failed, there is nothing more we can do */
1217 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1218 "3153 Fail to perform the requested "
1219 "access: x%x\n", reg_val);
1223 /* keep the original port state */
1224 if (before_fc_flag & FC_OFFLINE_MODE)
1227 init_completion(&online_compl);
1228 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1233 wait_for_completion(&online_compl);
1236 /* in any case, restore the virtual functions enabled as before */
1237 if (sriov_nr_virtfn) {
1239 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1241 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1244 /* return proper error code */
1255 * lpfc_nport_evt_cnt_show - Return the number of nport events
1256 * @dev: class device that is converted into a Scsi_host.
1257 * @attr: device attribute, not used.
1258 * @buf: on return contains the ascii number of nport events.
1260 * Returns: size of formatted string.
1263 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1266 struct Scsi_Host *shost = class_to_shost(dev);
1267 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1268 struct lpfc_hba *phba = vport->phba;
1270 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1274 * lpfc_board_mode_show - Return the state of the board
1275 * @dev: class device that is converted into a Scsi_host.
1276 * @attr: device attribute, not used.
1277 * @buf: on return contains the state of the adapter.
1279 * Returns: size of formatted string.
1282 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1285 struct Scsi_Host *shost = class_to_shost(dev);
1286 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1287 struct lpfc_hba *phba = vport->phba;
1290 if (phba->link_state == LPFC_HBA_ERROR)
1292 else if (phba->link_state == LPFC_WARM_START)
1293 state = "warm start";
1294 else if (phba->link_state == LPFC_INIT_START)
1299 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1303 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1304 * @dev: class device that is converted into a Scsi_host.
1305 * @attr: device attribute, not used.
1306 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1307 * @count: unused variable.
1310 * -EACCES if enable hba reset not enabled
1311 * -EINVAL if the buffer does not contain a valid string (see above)
1312 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1313 * buf length greater than zero indicates success
1316 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1317 const char *buf, size_t count)
1319 struct Scsi_Host *shost = class_to_shost(dev);
1320 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1321 struct lpfc_hba *phba = vport->phba;
1322 struct completion online_compl;
1323 char *board_mode_str = NULL;
1327 if (!phba->cfg_enable_hba_reset) {
1329 goto board_mode_out;
1332 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1333 "3050 lpfc_board_mode set to %s\n", buf);
1335 init_completion(&online_compl);
1337 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1338 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1342 goto board_mode_out;
1344 wait_for_completion(&online_compl);
1345 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1346 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1347 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1348 if (phba->sli_rev == LPFC_SLI_REV4)
1351 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1352 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1353 if (phba->sli_rev == LPFC_SLI_REV4)
1356 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1357 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1358 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1359 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1360 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1361 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1362 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1370 board_mode_str = strchr(buf, '\n');
1372 *board_mode_str = '\0';
1373 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1374 "3097 Failed \"%s\", status(%d), "
1376 buf, status, phba->pport->fc_flag);
1382 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1383 * @phba: pointer to the adapter structure.
1384 * @mxri: max xri count.
1385 * @axri: available xri count.
1386 * @mrpi: max rpi count.
1387 * @arpi: available rpi count.
1388 * @mvpi: max vpi count.
1389 * @avpi: available vpi count.
1392 * If an integer pointer for an count is not null then the value for the
1393 * count is returned.
1400 lpfc_get_hba_info(struct lpfc_hba *phba,
1401 uint32_t *mxri, uint32_t *axri,
1402 uint32_t *mrpi, uint32_t *arpi,
1403 uint32_t *mvpi, uint32_t *avpi)
1405 struct lpfc_mbx_read_config *rd_config;
1406 LPFC_MBOXQ_t *pmboxq;
1412 * prevent udev from issuing mailbox commands until the port is
1415 if (phba->link_state < LPFC_LINK_DOWN ||
1416 !phba->mbox_mem_pool ||
1417 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1420 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1423 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1426 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1428 pmb = &pmboxq->u.mb;
1429 pmb->mbxCommand = MBX_READ_CONFIG;
1430 pmb->mbxOwner = OWN_HOST;
1431 pmboxq->context1 = NULL;
1433 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1434 rc = MBX_NOT_FINISHED;
1436 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1438 if (rc != MBX_SUCCESS) {
1439 if (rc != MBX_TIMEOUT)
1440 mempool_free(pmboxq, phba->mbox_mem_pool);
1444 if (phba->sli_rev == LPFC_SLI_REV4) {
1445 rd_config = &pmboxq->u.mqe.un.rd_config;
1447 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1449 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1450 phba->sli4_hba.max_cfg_param.rpi_used;
1452 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1454 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1455 phba->sli4_hba.max_cfg_param.xri_used;
1457 /* Account for differences with SLI-3. Get vpi count from
1458 * mailbox data and subtract one for max vpi value.
1460 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1461 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1466 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1469 *mrpi = pmb->un.varRdConfig.max_rpi;
1471 *arpi = pmb->un.varRdConfig.avail_rpi;
1473 *mxri = pmb->un.varRdConfig.max_xri;
1475 *axri = pmb->un.varRdConfig.avail_xri;
1477 *mvpi = pmb->un.varRdConfig.max_vpi;
1479 *avpi = pmb->un.varRdConfig.avail_vpi;
1482 mempool_free(pmboxq, phba->mbox_mem_pool);
1487 * lpfc_max_rpi_show - Return maximum rpi
1488 * @dev: class device that is converted into a Scsi_host.
1489 * @attr: device attribute, not used.
1490 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1493 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1494 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1495 * to "Unknown" and the buffer length is returned, therefore the caller
1496 * must check for "Unknown" in the buffer to detect a failure.
1498 * Returns: size of formatted string.
1501 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1504 struct Scsi_Host *shost = class_to_shost(dev);
1505 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1506 struct lpfc_hba *phba = vport->phba;
1509 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1510 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1511 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1515 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1516 * @dev: class device that is converted into a Scsi_host.
1517 * @attr: device attribute, not used.
1518 * @buf: containing the used rpi count in decimal or "Unknown".
1521 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1522 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1523 * to "Unknown" and the buffer length is returned, therefore the caller
1524 * must check for "Unknown" in the buffer to detect a failure.
1526 * Returns: size of formatted string.
1529 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1532 struct Scsi_Host *shost = class_to_shost(dev);
1533 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1534 struct lpfc_hba *phba = vport->phba;
1537 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1538 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1539 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1543 * lpfc_max_xri_show - Return maximum xri
1544 * @dev: class device that is converted into a Scsi_host.
1545 * @attr: device attribute, not used.
1546 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1549 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1550 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1551 * to "Unknown" and the buffer length is returned, therefore the caller
1552 * must check for "Unknown" in the buffer to detect a failure.
1554 * Returns: size of formatted string.
1557 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1560 struct Scsi_Host *shost = class_to_shost(dev);
1561 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1562 struct lpfc_hba *phba = vport->phba;
1565 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1566 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1567 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1571 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1572 * @dev: class device that is converted into a Scsi_host.
1573 * @attr: device attribute, not used.
1574 * @buf: on return contains the used xri count in decimal or "Unknown".
1577 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1578 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1579 * to "Unknown" and the buffer length is returned, therefore the caller
1580 * must check for "Unknown" in the buffer to detect a failure.
1582 * Returns: size of formatted string.
1585 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1588 struct Scsi_Host *shost = class_to_shost(dev);
1589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1590 struct lpfc_hba *phba = vport->phba;
1593 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1594 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1595 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1599 * lpfc_max_vpi_show - Return maximum vpi
1600 * @dev: class device that is converted into a Scsi_host.
1601 * @attr: device attribute, not used.
1602 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1605 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1606 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1607 * to "Unknown" and the buffer length is returned, therefore the caller
1608 * must check for "Unknown" in the buffer to detect a failure.
1610 * Returns: size of formatted string.
1613 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1616 struct Scsi_Host *shost = class_to_shost(dev);
1617 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1618 struct lpfc_hba *phba = vport->phba;
1621 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1622 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1623 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1627 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1628 * @dev: class device that is converted into a Scsi_host.
1629 * @attr: device attribute, not used.
1630 * @buf: on return contains the used vpi count in decimal or "Unknown".
1633 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1634 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1635 * to "Unknown" and the buffer length is returned, therefore the caller
1636 * must check for "Unknown" in the buffer to detect a failure.
1638 * Returns: size of formatted string.
1641 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1644 struct Scsi_Host *shost = class_to_shost(dev);
1645 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1646 struct lpfc_hba *phba = vport->phba;
1649 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1650 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1651 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1655 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1656 * @dev: class device that is converted into a Scsi_host.
1657 * @attr: device attribute, not used.
1658 * @buf: text that must be interpreted to determine if npiv is supported.
1661 * Buffer will contain text indicating npiv is not suppoerted on the port,
1662 * the port is an NPIV physical port, or it is an npiv virtual port with
1663 * the id of the vport.
1665 * Returns: size of formatted string.
1668 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1671 struct Scsi_Host *shost = class_to_shost(dev);
1672 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1673 struct lpfc_hba *phba = vport->phba;
1675 if (!(phba->max_vpi))
1676 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1677 if (vport->port_type == LPFC_PHYSICAL_PORT)
1678 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1679 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1683 * lpfc_poll_show - Return text about poll support for the adapter
1684 * @dev: class device that is converted into a Scsi_host.
1685 * @attr: device attribute, not used.
1686 * @buf: on return contains the cfg_poll in hex.
1689 * cfg_poll should be a lpfc_polling_flags type.
1691 * Returns: size of formatted string.
1694 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1697 struct Scsi_Host *shost = class_to_shost(dev);
1698 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1699 struct lpfc_hba *phba = vport->phba;
1701 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1705 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1706 * @dev: class device that is converted into a Scsi_host.
1707 * @attr: device attribute, not used.
1708 * @buf: one or more lpfc_polling_flags values.
1712 * buf contents converted to integer and checked for a valid value.
1715 * -EINVAL if the buffer connot be converted or is out of range
1716 * length of the buf on success
1719 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1720 const char *buf, size_t count)
1722 struct Scsi_Host *shost = class_to_shost(dev);
1723 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1724 struct lpfc_hba *phba = vport->phba;
1729 if (!isdigit(buf[0]))
1732 if (sscanf(buf, "%i", &val) != 1)
1735 if ((val & 0x3) != val)
1738 if (phba->sli_rev == LPFC_SLI_REV4)
1741 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1742 "3051 lpfc_poll changed from %d to %d\n",
1743 phba->cfg_poll, val);
1745 spin_lock_irq(&phba->hbalock);
1747 old_val = phba->cfg_poll;
1749 if (val & ENABLE_FCP_RING_POLLING) {
1750 if ((val & DISABLE_FCP_RING_INT) &&
1751 !(old_val & DISABLE_FCP_RING_INT)) {
1752 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1753 spin_unlock_irq(&phba->hbalock);
1756 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1757 writel(creg_val, phba->HCregaddr);
1758 readl(phba->HCregaddr); /* flush */
1760 lpfc_poll_start_timer(phba);
1762 } else if (val != 0x0) {
1763 spin_unlock_irq(&phba->hbalock);
1767 if (!(val & DISABLE_FCP_RING_INT) &&
1768 (old_val & DISABLE_FCP_RING_INT))
1770 spin_unlock_irq(&phba->hbalock);
1771 del_timer(&phba->fcp_poll_timer);
1772 spin_lock_irq(&phba->hbalock);
1773 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1774 spin_unlock_irq(&phba->hbalock);
1777 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1778 writel(creg_val, phba->HCregaddr);
1779 readl(phba->HCregaddr); /* flush */
1782 phba->cfg_poll = val;
1784 spin_unlock_irq(&phba->hbalock);
1790 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1791 * @dev: class unused variable.
1792 * @attr: device attribute, not used.
1793 * @buf: on return contains the module description text.
1795 * Returns: size of formatted string.
1798 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1801 struct Scsi_Host *shost = class_to_shost(dev);
1802 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1803 struct lpfc_hba *phba = vport->phba;
1805 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1809 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1810 * @dev: class unused variable.
1811 * @attr: device attribute, not used.
1812 * @buf: on return contains the module description text.
1814 * Returns: size of formatted string.
1817 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1820 struct Scsi_Host *shost = class_to_shost(dev);
1821 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1822 struct lpfc_hba *phba = vport->phba;
1824 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1828 * lpfc_dss_show - Return the current state of dss and the configured state
1829 * @dev: class converted to a Scsi_host structure.
1830 * @attr: device attribute, not used.
1831 * @buf: on return contains the formatted text.
1833 * Returns: size of formatted string.
1836 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1839 struct Scsi_Host *shost = class_to_shost(dev);
1840 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1841 struct lpfc_hba *phba = vport->phba;
1843 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1844 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1845 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1850 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1851 * @dev: class converted to a Scsi_host structure.
1852 * @attr: device attribute, not used.
1853 * @buf: on return contains the formatted support level.
1856 * Returns the maximum number of virtual functions a physical function can
1857 * support, 0 will be returned if called on virtual function.
1859 * Returns: size of formatted string.
1862 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1863 struct device_attribute *attr,
1866 struct Scsi_Host *shost = class_to_shost(dev);
1867 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1868 struct lpfc_hba *phba = vport->phba;
1869 uint16_t max_nr_virtfn;
1871 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1872 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1875 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1877 return val >= min && val <= max;
1881 * lpfc_param_show - Return a cfg attribute value in decimal
1884 * Macro that given an attr e.g. hba_queue_depth expands
1885 * into a function with the name lpfc_hba_queue_depth_show.
1887 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1888 * @dev: class device that is converted into a Scsi_host.
1889 * @attr: device attribute, not used.
1890 * @buf: on return contains the attribute value in decimal.
1892 * Returns: size of formatted string.
1894 #define lpfc_param_show(attr) \
1896 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1899 struct Scsi_Host *shost = class_to_shost(dev);\
1900 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1901 struct lpfc_hba *phba = vport->phba;\
1902 return snprintf(buf, PAGE_SIZE, "%d\n",\
1907 * lpfc_param_hex_show - Return a cfg attribute value in hex
1910 * Macro that given an attr e.g. hba_queue_depth expands
1911 * into a function with the name lpfc_hba_queue_depth_show
1913 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1914 * @dev: class device that is converted into a Scsi_host.
1915 * @attr: device attribute, not used.
1916 * @buf: on return contains the attribute value in hexadecimal.
1918 * Returns: size of formatted string.
1920 #define lpfc_param_hex_show(attr) \
1922 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1925 struct Scsi_Host *shost = class_to_shost(dev);\
1926 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1927 struct lpfc_hba *phba = vport->phba;\
1929 val = phba->cfg_##attr;\
1930 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1935 * lpfc_param_init - Initializes a cfg attribute
1938 * Macro that given an attr e.g. hba_queue_depth expands
1939 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1940 * takes a default argument, a minimum and maximum argument.
1942 * lpfc_##attr##_init: Initializes an attribute.
1943 * @phba: pointer the the adapter structure.
1944 * @val: integer attribute value.
1946 * Validates the min and max values then sets the adapter config field
1947 * accordingly, or uses the default if out of range and prints an error message.
1951 * -EINVAL if default used
1953 #define lpfc_param_init(attr, default, minval, maxval) \
1955 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1957 if (lpfc_rangecheck(val, minval, maxval)) {\
1958 phba->cfg_##attr = val;\
1961 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1962 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1963 "allowed range is ["#minval", "#maxval"]\n", val); \
1964 phba->cfg_##attr = default;\
1969 * lpfc_param_set - Set a cfg attribute value
1972 * Macro that given an attr e.g. hba_queue_depth expands
1973 * into a function with the name lpfc_hba_queue_depth_set
1975 * lpfc_##attr##_set: Sets an attribute value.
1976 * @phba: pointer the the adapter structure.
1977 * @val: integer attribute value.
1980 * Validates the min and max values then sets the
1981 * adapter config field if in the valid range. prints error message
1982 * and does not set the parameter if invalid.
1986 * -EINVAL if val is invalid
1988 #define lpfc_param_set(attr, default, minval, maxval) \
1990 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1992 if (lpfc_rangecheck(val, minval, maxval)) {\
1993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1994 "3052 lpfc_" #attr " changed from %d to %d\n", \
1995 phba->cfg_##attr, val); \
1996 phba->cfg_##attr = val;\
1999 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2000 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2001 "allowed range is ["#minval", "#maxval"]\n", val); \
2006 * lpfc_param_store - Set a vport attribute value
2009 * Macro that given an attr e.g. hba_queue_depth expands
2010 * into a function with the name lpfc_hba_queue_depth_store.
2012 * lpfc_##attr##_store: Set an sttribute value.
2013 * @dev: class device that is converted into a Scsi_host.
2014 * @attr: device attribute, not used.
2015 * @buf: contains the attribute value in ascii.
2019 * Convert the ascii text number to an integer, then
2020 * use the lpfc_##attr##_set function to set the value.
2023 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2024 * length of buffer upon success.
2026 #define lpfc_param_store(attr) \
2028 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2029 const char *buf, size_t count) \
2031 struct Scsi_Host *shost = class_to_shost(dev);\
2032 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2033 struct lpfc_hba *phba = vport->phba;\
2035 if (!isdigit(buf[0]))\
2037 if (sscanf(buf, "%i", &val) != 1)\
2039 if (lpfc_##attr##_set(phba, val) == 0) \
2040 return strlen(buf);\
2046 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2049 * Macro that given an attr e.g. hba_queue_depth expands
2050 * into a function with the name lpfc_hba_queue_depth_show
2052 * lpfc_##attr##_show: prints the attribute value in decimal.
2053 * @dev: class device that is converted into a Scsi_host.
2054 * @attr: device attribute, not used.
2055 * @buf: on return contains the attribute value in decimal.
2057 * Returns: length of formatted string.
2059 #define lpfc_vport_param_show(attr) \
2061 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2064 struct Scsi_Host *shost = class_to_shost(dev);\
2065 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2066 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2070 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2073 * Macro that given an attr e.g.
2074 * hba_queue_depth expands into a function with the name
2075 * lpfc_hba_queue_depth_show
2077 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2078 * @dev: class device that is converted into a Scsi_host.
2079 * @attr: device attribute, not used.
2080 * @buf: on return contains the attribute value in hexadecimal.
2082 * Returns: length of formatted string.
2084 #define lpfc_vport_param_hex_show(attr) \
2086 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2089 struct Scsi_Host *shost = class_to_shost(dev);\
2090 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2091 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2095 * lpfc_vport_param_init - Initialize a vport cfg attribute
2098 * Macro that given an attr e.g. hba_queue_depth expands
2099 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2100 * takes a default argument, a minimum and maximum argument.
2102 * lpfc_##attr##_init: validates the min and max values then sets the
2103 * adapter config field accordingly, or uses the default if out of range
2104 * and prints an error message.
2105 * @phba: pointer the the adapter structure.
2106 * @val: integer attribute value.
2110 * -EINVAL if default used
2112 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2114 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2116 if (lpfc_rangecheck(val, minval, maxval)) {\
2117 vport->cfg_##attr = val;\
2120 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2121 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2122 "allowed range is ["#minval", "#maxval"]\n", val); \
2123 vport->cfg_##attr = default;\
2128 * lpfc_vport_param_set - Set a vport cfg attribute
2131 * Macro that given an attr e.g. hba_queue_depth expands
2132 * into a function with the name lpfc_hba_queue_depth_set
2134 * lpfc_##attr##_set: validates the min and max values then sets the
2135 * adapter config field if in the valid range. prints error message
2136 * and does not set the parameter if invalid.
2137 * @phba: pointer the the adapter structure.
2138 * @val: integer attribute value.
2142 * -EINVAL if val is invalid
2144 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2146 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2148 if (lpfc_rangecheck(val, minval, maxval)) {\
2149 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2150 "3053 lpfc_" #attr \
2151 " changed from %d (x%x) to %d (x%x)\n", \
2152 vport->cfg_##attr, vport->cfg_##attr, \
2154 vport->cfg_##attr = val;\
2157 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2158 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2159 "allowed range is ["#minval", "#maxval"]\n", val); \
2164 * lpfc_vport_param_store - Set a vport attribute
2167 * Macro that given an attr e.g. hba_queue_depth
2168 * expands into a function with the name lpfc_hba_queue_depth_store
2170 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2171 * use the lpfc_##attr##_set function to set the value.
2172 * @cdev: class device that is converted into a Scsi_host.
2173 * @buf: contains the attribute value in decimal.
2177 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2178 * length of buffer upon success.
2180 #define lpfc_vport_param_store(attr) \
2182 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2183 const char *buf, size_t count) \
2185 struct Scsi_Host *shost = class_to_shost(dev);\
2186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2188 if (!isdigit(buf[0]))\
2190 if (sscanf(buf, "%i", &val) != 1)\
2192 if (lpfc_##attr##_set(vport, val) == 0) \
2193 return strlen(buf);\
2199 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2200 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2201 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2202 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2203 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2204 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2205 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2206 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2207 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2208 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2209 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2210 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2211 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2212 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2213 lpfc_link_state_store);
2214 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2215 lpfc_option_rom_version_show, NULL);
2216 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2217 lpfc_num_discovered_ports_show, NULL);
2218 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2219 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2220 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2221 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2222 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2223 lpfc_board_mode_show, lpfc_board_mode_store);
2224 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2225 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2226 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2227 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2228 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2229 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2230 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2231 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2232 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2233 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2234 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2235 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2236 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2237 lpfc_sriov_hw_max_virtfn_show, NULL);
2238 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2239 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2242 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2245 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2247 * @cnt: Length of string.
2248 * @wwn: Array to receive converted wwn value.
2251 * -EINVAL if the buffer does not contain a valid wwn
2255 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2259 /* Count may include a LF at end of string */
2260 if (buf[cnt-1] == '\n')
2263 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2264 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2267 memset(wwn, 0, WWN_SZ);
2269 /* Validate and store the new name */
2270 for (i = 0, j = 0; i < 16; i++) {
2271 if ((*buf >= 'a') && (*buf <= 'f'))
2272 j = ((j << 4) | ((*buf++ - 'a') + 10));
2273 else if ((*buf >= 'A') && (*buf <= 'F'))
2274 j = ((j << 4) | ((*buf++ - 'A') + 10));
2275 else if ((*buf >= '0') && (*buf <= '9'))
2276 j = ((j << 4) | (*buf++ - '0'));
2280 wwn[i/2] = j & 0xff;
2287 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2288 * @dev: class device that is converted into a Scsi_host.
2289 * @attr: device attribute, not used.
2290 * @buf: containing the string lpfc_soft_wwn_key.
2291 * @count: must be size of lpfc_soft_wwn_key.
2294 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2295 * length of buf indicates success
2298 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2299 const char *buf, size_t count)
2301 struct Scsi_Host *shost = class_to_shost(dev);
2302 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2303 struct lpfc_hba *phba = vport->phba;
2304 unsigned int cnt = count;
2305 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2306 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2309 * We're doing a simple sanity check for soft_wwpn setting.
2310 * We require that the user write a specific key to enable
2311 * the soft_wwpn attribute to be settable. Once the attribute
2312 * is written, the enable key resets. If further updates are
2313 * desired, the key must be written again to re-enable the
2316 * The "key" is not secret - it is a hardcoded string shown
2317 * here. The intent is to protect against the random user or
2318 * application that is just writing attributes.
2320 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2322 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2323 " be enabled: fawwpn is enabled\n");
2327 /* count may include a LF at end of string */
2328 if (buf[cnt-1] == '\n')
2331 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2332 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2335 phba->soft_wwn_enable = 1;
2337 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2338 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2340 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2341 " The soft_wwpn feature is not supported by Broadcom.");
2345 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2346 lpfc_soft_wwn_enable_store);
2349 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2350 * @dev: class device that is converted into a Scsi_host.
2351 * @attr: device attribute, not used.
2352 * @buf: on return contains the wwpn in hexadecimal.
2354 * Returns: size of formatted string.
2357 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2360 struct Scsi_Host *shost = class_to_shost(dev);
2361 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2362 struct lpfc_hba *phba = vport->phba;
2364 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2365 (unsigned long long)phba->cfg_soft_wwpn);
2369 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2370 * @dev class device that is converted into a Scsi_host.
2371 * @attr: device attribute, not used.
2372 * @buf: contains the wwpn in hexadecimal.
2373 * @count: number of wwpn bytes in buf
2376 * -EACCES hba reset not enabled, adapter over temp
2377 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2378 * -EIO error taking adapter offline or online
2379 * value of count on success
2382 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2383 const char *buf, size_t count)
2385 struct Scsi_Host *shost = class_to_shost(dev);
2386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2387 struct lpfc_hba *phba = vport->phba;
2388 struct completion online_compl;
2389 int stat1 = 0, stat2 = 0;
2390 unsigned int cnt = count;
2394 if (!phba->cfg_enable_hba_reset)
2396 spin_lock_irq(&phba->hbalock);
2397 if (phba->over_temp_state == HBA_OVER_TEMP) {
2398 spin_unlock_irq(&phba->hbalock);
2401 spin_unlock_irq(&phba->hbalock);
2402 /* count may include a LF at end of string */
2403 if (buf[cnt-1] == '\n')
2406 if (!phba->soft_wwn_enable)
2409 /* lock setting wwpn, wwnn down */
2410 phba->soft_wwn_enable = 0;
2412 rc = lpfc_wwn_set(buf, cnt, wwpn);
2414 /* not able to set wwpn, unlock it */
2415 phba->soft_wwn_enable = 1;
2419 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2420 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2421 if (phba->cfg_soft_wwnn)
2422 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2424 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2425 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2427 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2429 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2430 "0463 lpfc_soft_wwpn attribute set failed to "
2431 "reinit adapter - %d\n", stat1);
2432 init_completion(&online_compl);
2433 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2438 wait_for_completion(&online_compl);
2440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2441 "0464 lpfc_soft_wwpn attribute set failed to "
2442 "reinit adapter - %d\n", stat2);
2443 return (stat1 || stat2) ? -EIO : count;
2445 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2446 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2449 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2450 * @dev: class device that is converted into a Scsi_host.
2451 * @attr: device attribute, not used.
2452 * @buf: on return contains the wwnn in hexadecimal.
2454 * Returns: size of formatted string.
2457 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2460 struct Scsi_Host *shost = class_to_shost(dev);
2461 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2462 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2463 (unsigned long long)phba->cfg_soft_wwnn);
2467 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2468 * @cdev: class device that is converted into a Scsi_host.
2469 * @buf: contains the ww node name in hexadecimal.
2470 * @count: number of wwnn bytes in buf.
2473 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2474 * value of count on success
2477 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2478 const char *buf, size_t count)
2480 struct Scsi_Host *shost = class_to_shost(dev);
2481 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2482 unsigned int cnt = count;
2486 /* count may include a LF at end of string */
2487 if (buf[cnt-1] == '\n')
2490 if (!phba->soft_wwn_enable)
2493 rc = lpfc_wwn_set(buf, cnt, wwnn);
2495 /* Allow wwnn to be set many times, as long as the enable
2496 * is set. However, once the wwpn is set, everything locks.
2501 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2503 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2504 "lpfc%d: soft_wwnn set. Value will take effect upon "
2505 "setting of the soft_wwpn\n", phba->brd_no);
2509 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2510 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2513 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2514 * Optimized Access Storage (OAS) operations.
2515 * @dev: class device that is converted into a Scsi_host.
2516 * @attr: device attribute, not used.
2517 * @buf: buffer for passing information.
2523 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2526 struct Scsi_Host *shost = class_to_shost(dev);
2527 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2529 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2530 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2534 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2535 * Optimized Access Storage (OAS) operations.
2536 * @dev: class device that is converted into a Scsi_host.
2537 * @attr: device attribute, not used.
2538 * @buf: buffer for passing information.
2539 * @count: Size of the data buffer.
2542 * -EINVAL count is invalid, invalid wwpn byte invalid
2543 * -EPERM oas is not supported by hba
2544 * value of count on success
2547 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2548 const char *buf, size_t count)
2550 struct Scsi_Host *shost = class_to_shost(dev);
2551 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2552 unsigned int cnt = count;
2553 uint8_t wwpn[WWN_SZ];
2559 /* count may include a LF at end of string */
2560 if (buf[cnt-1] == '\n')
2563 rc = lpfc_wwn_set(buf, cnt, wwpn);
2567 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2568 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2569 if (wwn_to_u64(wwpn) == 0)
2570 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2572 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2573 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2574 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2577 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2578 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2581 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2582 * Optimized Access Storage (OAS) operations.
2583 * @dev: class device that is converted into a Scsi_host.
2584 * @attr: device attribute, not used.
2585 * @buf: buffer for passing information.
2591 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2594 struct Scsi_Host *shost = class_to_shost(dev);
2595 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2597 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2601 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2602 * Optimized Access Storage (OAS) operations.
2603 * @dev: class device that is converted into a Scsi_host.
2604 * @attr: device attribute, not used.
2605 * @buf: buffer for passing information.
2606 * @count: Size of the data buffer.
2609 * -EINVAL count is invalid, invalid wwpn byte invalid
2610 * -EPERM oas is not supported by hba
2611 * value of count on success
2614 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2615 const char *buf, size_t count)
2617 struct Scsi_Host *shost = class_to_shost(dev);
2618 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2619 unsigned int cnt = count;
2626 /* count may include a LF at end of string */
2627 if (buf[cnt-1] == '\n')
2630 ret = kstrtoul(buf, 0, &val);
2631 if (ret || (val > 0x7f))
2635 phba->cfg_oas_priority = (uint8_t)val;
2637 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2640 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2641 lpfc_oas_priority_show, lpfc_oas_priority_store);
2644 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2645 * for Optimized Access Storage (OAS) operations.
2646 * @dev: class device that is converted into a Scsi_host.
2647 * @attr: device attribute, not used.
2648 * @buf: buffer for passing information.
2651 * value of count on success
2654 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2657 struct Scsi_Host *shost = class_to_shost(dev);
2658 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2660 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2661 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2665 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2666 * for Optimized Access Storage (OAS) operations.
2667 * @dev: class device that is converted into a Scsi_host.
2668 * @attr: device attribute, not used.
2669 * @buf: buffer for passing information.
2670 * @count: Size of the data buffer.
2673 * -EINVAL count is invalid, invalid wwpn byte invalid
2674 * -EPERM oas is not supported by hba
2675 * value of count on success
2678 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2679 const char *buf, size_t count)
2681 struct Scsi_Host *shost = class_to_shost(dev);
2682 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2683 unsigned int cnt = count;
2684 uint8_t wwpn[WWN_SZ];
2690 /* count may include a LF at end of string */
2691 if (buf[cnt-1] == '\n')
2694 rc = lpfc_wwn_set(buf, cnt, wwpn);
2698 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2699 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2700 if (wwn_to_u64(wwpn) == 0)
2701 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2703 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2704 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2705 if (phba->cfg_oas_priority == 0)
2706 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2707 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2710 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2711 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2714 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2715 * of whether luns will be enabled or disabled
2716 * for Optimized Access Storage (OAS) operations.
2717 * @dev: class device that is converted into a Scsi_host.
2718 * @attr: device attribute, not used.
2719 * @buf: buffer for passing information.
2722 * size of formatted string.
2725 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2728 struct Scsi_Host *shost = class_to_shost(dev);
2729 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2731 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2735 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2736 * of whether luns will be enabled or disabled
2737 * for Optimized Access Storage (OAS) operations.
2738 * @dev: class device that is converted into a Scsi_host.
2739 * @attr: device attribute, not used.
2740 * @buf: buffer for passing information.
2741 * @count: Size of the data buffer.
2744 * -EINVAL count is invalid, invalid wwpn byte invalid
2745 * -EPERM oas is not supported by hba
2746 * value of count on success
2749 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2750 const char *buf, size_t count)
2752 struct Scsi_Host *shost = class_to_shost(dev);
2753 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2759 if (!isdigit(buf[0]))
2762 if (sscanf(buf, "%i", &val) != 1)
2765 if ((val != 0) && (val != 1))
2768 phba->cfg_oas_lun_state = val;
2771 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2772 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2775 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2776 * Storage (OAS) lun returned by the
2777 * lpfc_oas_lun_show function.
2778 * @dev: class device that is converted into a Scsi_host.
2779 * @attr: device attribute, not used.
2780 * @buf: buffer for passing information.
2783 * size of formatted string.
2786 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2789 struct Scsi_Host *shost = class_to_shost(dev);
2790 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2792 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2795 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2797 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2798 lpfc_oas_lun_status_show, NULL);
2802 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2804 * @phba: lpfc_hba pointer.
2805 * @ndlp: pointer to fcp target node.
2806 * @lun: the fc lun for setting oas state.
2807 * @oas_state: the oas state to be set to the lun.
2811 * -EPERM OAS is not enabled or not supported by this port.
2815 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2816 uint8_t tgt_wwpn[], uint64_t lun,
2817 uint32_t oas_state, uint8_t pri)
2826 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2827 (struct lpfc_name *)tgt_wwpn,
2831 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2832 (struct lpfc_name *)tgt_wwpn, lun, pri);
2839 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2840 * Access Storage (OAS) operations.
2841 * @phba: lpfc_hba pointer.
2842 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2843 * @tgt_wwpn: wwpn of the target associated with the returned lun
2844 * @lun_status: status of the lun returned lun
2846 * Returns the first or next lun enabled for OAS operations for the vport/target
2847 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2848 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2851 * lun that is OAS enabled for the vport/target
2852 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2855 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2856 uint8_t tgt_wwpn[], uint32_t *lun_status,
2861 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2862 return NOT_OAS_ENABLED_LUN;
2863 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2864 phba->sli4_hba.oas_next_vpt_wwpn,
2865 (struct lpfc_name *)
2866 phba->sli4_hba.oas_next_tgt_wwpn,
2867 &phba->sli4_hba.oas_next_lun,
2868 (struct lpfc_name *)vpt_wwpn,
2869 (struct lpfc_name *)tgt_wwpn,
2870 &found_lun, lun_status, lun_pri))
2873 return NOT_OAS_ENABLED_LUN;
2877 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2878 * @phba: lpfc_hba pointer.
2879 * @vpt_wwpn: vport wwpn by reference.
2880 * @tgt_wwpn: target wwpn by reference.
2881 * @lun: the fc lun for setting oas state.
2882 * @oas_state: the oas state to be set to the oas_lun.
2884 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2885 * a lun for OAS operations.
2889 * -ENOMEM: failed to enable an lun for OAS operations
2890 * -EPERM: OAS is not enabled
2893 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2894 uint8_t tgt_wwpn[], uint64_t lun,
2895 uint32_t oas_state, uint8_t pri)
2900 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2906 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2907 * @dev: class device that is converted into a Scsi_host.
2908 * @attr: device attribute, not used.
2909 * @buf: buffer for passing information.
2911 * This routine returns a lun enabled for OAS each time the function
2915 * SUCCESS: size of formatted string.
2916 * -EFAULT: target or vport wwpn was not set properly.
2917 * -EPERM: oas is not enabled.
2920 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2923 struct Scsi_Host *shost = class_to_shost(dev);
2924 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2932 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2933 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2936 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2937 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2940 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2941 phba->cfg_oas_tgt_wwpn,
2942 &phba->cfg_oas_lun_status,
2943 &phba->cfg_oas_priority);
2944 if (oas_lun != NOT_OAS_ENABLED_LUN)
2945 phba->cfg_oas_flags |= OAS_LUN_VALID;
2947 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2953 * lpfc_oas_lun_store - Sets the OAS state for lun
2954 * @dev: class device that is converted into a Scsi_host.
2955 * @attr: device attribute, not used.
2956 * @buf: buffer for passing information.
2958 * This function sets the OAS state for lun. Before this function is called,
2959 * the vport wwpn, target wwpn, and oas state need to be set.
2962 * SUCCESS: size of formatted string.
2963 * -EFAULT: target or vport wwpn was not set properly.
2964 * -EPERM: oas is not enabled.
2965 * size of formatted string.
2968 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2969 const char *buf, size_t count)
2971 struct Scsi_Host *shost = class_to_shost(dev);
2972 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2980 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2983 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2986 if (!isdigit(buf[0]))
2989 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2992 pri = phba->cfg_oas_priority;
2994 pri = phba->cfg_XLanePriority;
2996 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2997 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2998 "priority 0x%x with oas state %d\n",
2999 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3000 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3001 pri, phba->cfg_oas_lun_state);
3003 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3004 phba->cfg_oas_tgt_wwpn, scsi_lun,
3005 phba->cfg_oas_lun_state, pri);
3011 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3012 lpfc_oas_lun_show, lpfc_oas_lun_store);
3014 int lpfc_enable_nvmet_cnt;
3015 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3016 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3017 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3018 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3019 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3021 static int lpfc_poll = 0;
3022 module_param(lpfc_poll, int, S_IRUGO);
3023 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3025 " 1 - poll with interrupts enabled"
3026 " 3 - poll and disable FCP ring interrupts");
3028 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3029 lpfc_poll_show, lpfc_poll_store);
3031 int lpfc_no_hba_reset_cnt;
3032 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3033 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3034 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3035 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3037 LPFC_ATTR(sli_mode, 0, 0, 3,
3038 "SLI mode selector:"
3039 " 0 - auto (SLI-3 if supported),"
3040 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3041 " 3 - select SLI-3");
3043 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3044 "Enable NPIV functionality");
3046 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3047 "FCF Fast failover=1 Priority failover=2");
3050 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3051 # 0x0 = disabled, XRI/OXID use not tracked.
3052 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3053 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3055 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3056 "Enable RRQ functionality");
3059 # lpfc_suppress_link_up: Bring link up at initialization
3060 # 0x0 = bring link up (issue MBX_INIT_LINK)
3061 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3062 # 0x2 = never bring up link
3063 # Default value is 0.
3065 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3066 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3067 "Suppress Link Up at initialization");
3069 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3077 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3079 struct Scsi_Host *shost = class_to_shost(dev);
3080 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3082 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3085 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3086 lpfc_iocb_hw_show, NULL);
3088 lpfc_txq_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;
3092 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3094 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
3097 static DEVICE_ATTR(txq_hw, S_IRUGO,
3098 lpfc_txq_hw_show, NULL);
3100 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3103 struct Scsi_Host *shost = class_to_shost(dev);
3104 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3105 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3107 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
3110 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3111 lpfc_txcmplq_hw_show, NULL);
3113 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3114 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3117 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3118 # until the timer expires. Value range is [0,255]. Default value is 30.
3120 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3121 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3122 module_param(lpfc_nodev_tmo, int, 0);
3123 MODULE_PARM_DESC(lpfc_nodev_tmo,
3124 "Seconds driver will hold I/O waiting "
3125 "for a device to come back");
3128 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3129 * @dev: class converted to a Scsi_host structure.
3130 * @attr: device attribute, not used.
3131 * @buf: on return contains the dev loss timeout in decimal.
3133 * Returns: size of formatted string.
3136 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3139 struct Scsi_Host *shost = class_to_shost(dev);
3140 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3142 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3146 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3147 * @vport: lpfc vport structure pointer.
3148 * @val: contains the nodev timeout value.
3151 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3152 * a kernel error message is printed and zero is returned.
3153 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3154 * Otherwise nodev tmo is set to the default value.
3157 * zero if already set or if val is in range
3158 * -EINVAL val out of range
3161 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3163 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3164 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3165 if (val != LPFC_DEF_DEVLOSS_TMO)
3166 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3167 "0407 Ignoring lpfc_nodev_tmo module "
3168 "parameter because lpfc_devloss_tmo "
3173 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3174 vport->cfg_nodev_tmo = val;
3175 vport->cfg_devloss_tmo = val;
3178 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3179 "0400 lpfc_nodev_tmo attribute cannot be set to"
3180 " %d, allowed range is [%d, %d]\n",
3181 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3182 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3187 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3188 * @vport: lpfc vport structure pointer.
3191 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3194 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3196 struct Scsi_Host *shost;
3197 struct lpfc_nodelist *ndlp;
3199 shost = lpfc_shost_from_vport(vport);
3200 spin_lock_irq(shost->host_lock);
3201 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3202 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
3203 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3204 spin_unlock_irq(shost->host_lock);
3208 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3209 * @vport: lpfc vport structure pointer.
3210 * @val: contains the tmo value.
3213 * If the devloss tmo is already set or the vport dev loss tmo has changed
3214 * then a kernel error message is printed and zero is returned.
3215 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3216 * Otherwise nodev tmo is set to the default value.
3219 * zero if already set or if val is in range
3220 * -EINVAL val out of range
3223 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3225 if (vport->dev_loss_tmo_changed ||
3226 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3227 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3228 "0401 Ignoring change to lpfc_nodev_tmo "
3229 "because lpfc_devloss_tmo is set.\n");
3232 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3233 vport->cfg_nodev_tmo = val;
3234 vport->cfg_devloss_tmo = val;
3236 * For compat: set the fc_host dev loss so new rports
3237 * will get the value.
3239 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3240 lpfc_update_rport_devloss_tmo(vport);
3243 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3244 "0403 lpfc_nodev_tmo attribute cannot be set to "
3245 "%d, allowed range is [%d, %d]\n",
3246 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3250 lpfc_vport_param_store(nodev_tmo)
3252 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3253 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3256 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3257 # disappear until the timer expires. Value range is [0,255]. Default
3260 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3261 MODULE_PARM_DESC(lpfc_devloss_tmo,
3262 "Seconds driver will hold I/O waiting "
3263 "for a device to come back");
3264 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3265 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3266 lpfc_vport_param_show(devloss_tmo)
3269 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3270 * @vport: lpfc vport structure pointer.
3271 * @val: contains the tmo value.
3274 * If val is in a valid range then set the vport nodev tmo,
3275 * devloss tmo, also set the vport dev loss tmo changed flag.
3276 * Else a kernel error message is printed.
3279 * zero if val is in range
3280 * -EINVAL val out of range
3283 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3285 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3286 vport->cfg_nodev_tmo = val;
3287 vport->cfg_devloss_tmo = val;
3288 vport->dev_loss_tmo_changed = 1;
3289 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3290 lpfc_update_rport_devloss_tmo(vport);
3294 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3295 "0404 lpfc_devloss_tmo attribute cannot be set to "
3296 "%d, allowed range is [%d, %d]\n",
3297 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3301 lpfc_vport_param_store(devloss_tmo)
3302 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3303 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3306 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3307 * lpfc_suppress_rsp = 0 Disable
3308 * lpfc_suppress_rsp = 1 Enable (default)
3311 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3312 "Enable suppress rsp feature is firmware supports it");
3315 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3316 * lpfc_nvmet_mrq = 1 use a single RQ pair
3317 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3320 LPFC_ATTR_R(nvmet_mrq,
3322 "Specify number of RQ pairs for processing NVMET cmds");
3325 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3326 * Supported Values: 1 - register just FCP
3327 * 3 - register both FCP and NVME
3328 * Supported values are [1,3]. Default value is 1
3330 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3331 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3332 "Define fc4 type to register with fabric.");
3335 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3336 * This parameter is only used if:
3337 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3338 * port is not configured for NVMET.
3340 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3341 * The remaining XRIs get split up based on lpfc_xri_split per port:
3343 * Supported Values are in percentages
3344 * the xri_split value is the percentage the SCSI port will get. The remaining
3345 * percentage will go to NVME.
3347 LPFC_ATTR_R(xri_split, 50, 10, 90,
3348 "Division of XRI resources between SCSI and NVME");
3351 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3352 # deluged with LOTS of information.
3353 # You can set a bit mask to record specific types of verbose messages:
3354 # See lpfc_logmsh.h for definitions.
3356 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3357 "Verbose logging bit-mask");
3360 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3361 # objects that have been registered with the nameserver after login.
3363 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3364 "Deregister nameserver objects before LOGO");
3367 # lun_queue_depth: This parameter is used to limit the number of outstanding
3368 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3369 # If this parameter value is greater than 1/8th the maximum number of exchanges
3370 # supported by the HBA port, then the lun queue depth will be reduced to
3371 # 1/8th the maximum number of exchanges.
3373 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3374 "Max number of FCP commands we can queue to a specific LUN");
3377 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3378 # commands per target port. Value range is [10,65535]. Default value is 65535.
3380 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3381 "Max number of FCP commands we can queue to a specific target port");
3384 # hba_queue_depth: This parameter is used to limit the number of outstanding
3385 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3386 # value is greater than the maximum number of exchanges supported by the HBA,
3387 # then maximum number of exchanges supported by the HBA is used to determine
3388 # the hba_queue_depth.
3390 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3391 "Max number of FCP commands we can queue to a lpfc HBA");
3394 # peer_port_login: This parameter allows/prevents logins
3395 # between peer ports hosted on the same physical port.
3396 # When this parameter is set 0 peer ports of same physical port
3397 # are not allowed to login to each other.
3398 # When this parameter is set 1 peer ports of same physical port
3399 # are allowed to login to each other.
3400 # Default value of this parameter is 0.
3402 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3403 "Allow peer ports on the same physical port to login to each "
3407 # restrict_login: This parameter allows/prevents logins
3408 # between Virtual Ports and remote initiators.
3409 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3410 # other initiators and will attempt to PLOGI all remote ports.
3411 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3412 # remote ports and will not attempt to PLOGI to other initiators.
3413 # This parameter does not restrict to the physical port.
3414 # This parameter does not restrict logins to Fabric resident remote ports.
3415 # Default value of this parameter is 1.
3417 static int lpfc_restrict_login = 1;
3418 module_param(lpfc_restrict_login, int, S_IRUGO);
3419 MODULE_PARM_DESC(lpfc_restrict_login,
3420 "Restrict virtual ports login to remote initiators.");
3421 lpfc_vport_param_show(restrict_login);
3424 * lpfc_restrict_login_init - Set the vport restrict login flag
3425 * @vport: lpfc vport structure pointer.
3426 * @val: contains the restrict login value.
3429 * If val is not in a valid range then log a kernel error message and set
3430 * the vport restrict login to one.
3431 * If the port type is physical clear the restrict login flag and return.
3432 * Else set the restrict login flag to val.
3435 * zero if val is in range
3436 * -EINVAL val out of range
3439 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3441 if (val < 0 || val > 1) {
3442 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3443 "0422 lpfc_restrict_login attribute cannot "
3444 "be set to %d, allowed range is [0, 1]\n",
3446 vport->cfg_restrict_login = 1;
3449 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3450 vport->cfg_restrict_login = 0;
3453 vport->cfg_restrict_login = val;
3458 * lpfc_restrict_login_set - Set the vport restrict login flag
3459 * @vport: lpfc vport structure pointer.
3460 * @val: contains the restrict login value.
3463 * If val is not in a valid range then log a kernel error message and set
3464 * the vport restrict login to one.
3465 * If the port type is physical and the val is not zero log a kernel
3466 * error message, clear the restrict login flag and return zero.
3467 * Else set the restrict login flag to val.
3470 * zero if val is in range
3471 * -EINVAL val out of range
3474 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3476 if (val < 0 || val > 1) {
3477 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3478 "0425 lpfc_restrict_login attribute cannot "
3479 "be set to %d, allowed range is [0, 1]\n",
3481 vport->cfg_restrict_login = 1;
3484 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3485 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3486 "0468 lpfc_restrict_login must be 0 for "
3487 "Physical ports.\n");
3488 vport->cfg_restrict_login = 0;
3491 vport->cfg_restrict_login = val;
3494 lpfc_vport_param_store(restrict_login);
3495 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3496 lpfc_restrict_login_show, lpfc_restrict_login_store);
3499 # Some disk devices have a "select ID" or "select Target" capability.
3500 # From a protocol standpoint "select ID" usually means select the
3501 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3502 # annex" which contains a table that maps a "select ID" (a number
3503 # between 0 and 7F) to an ALPA. By default, for compatibility with
3504 # older drivers, the lpfc driver scans this table from low ALPA to high
3507 # Turning on the scan-down variable (on = 1, off = 0) will
3508 # cause the lpfc driver to use an inverted table, effectively
3509 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3511 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3512 # and will not work across a fabric. Also this parameter will take
3513 # effect only in the case when ALPA map is not available.)
3515 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3516 "Start scanning for devices from highest ALPA to lowest");
3519 # lpfc_topology: link topology for init link
3520 # 0x0 = attempt loop mode then point-to-point
3521 # 0x01 = internal loopback mode
3522 # 0x02 = attempt point-to-point mode only
3523 # 0x04 = attempt loop mode only
3524 # 0x06 = attempt point-to-point mode then loop
3525 # Set point-to-point mode if you want to run as an N_Port.
3526 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3527 # Default value is 0.
3529 LPFC_ATTR(topology, 0, 0, 6,
3530 "Select Fibre Channel topology");
3533 * lpfc_topology_set - Set the adapters topology field
3534 * @phba: lpfc_hba pointer.
3535 * @val: topology value.
3538 * If val is in a valid range then set the adapter's topology field and
3539 * issue a lip; if the lip fails reset the topology to the old value.
3541 * If the value is not in range log a kernel error message and return an error.
3544 * zero if val is in range and lip okay
3545 * non-zero return value from lpfc_issue_lip()
3546 * -EINVAL val out of range
3549 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3550 const char *buf, size_t count)
3552 struct Scsi_Host *shost = class_to_shost(dev);
3553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3554 struct lpfc_hba *phba = vport->phba;
3557 const char *val_buf = buf;
3561 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3563 val_buf = &buf[strlen("nolip ")];
3566 if (!isdigit(val_buf[0]))
3568 if (sscanf(val_buf, "%i", &val) != 1)
3571 if (val >= 0 && val <= 6) {
3572 prev_val = phba->cfg_topology;
3573 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3575 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3576 "3113 Loop mode not supported at speed %d\n",
3580 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3582 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3583 "3114 Loop mode not supported\n");
3586 phba->cfg_topology = val;
3590 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3591 "3054 lpfc_topology changed from %d to %d\n",
3593 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3594 phba->fc_topology_changed = 1;
3595 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3597 phba->cfg_topology = prev_val;
3602 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3603 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3604 "allowed range is [0, 6]\n",
3609 lpfc_param_show(topology)
3610 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3611 lpfc_topology_show, lpfc_topology_store);
3614 * lpfc_static_vport_show: Read callback function for
3615 * lpfc_static_vport sysfs file.
3616 * @dev: Pointer to class device object.
3617 * @attr: device attribute structure.
3618 * @buf: Data buffer.
3620 * This function is the read call back function for
3621 * lpfc_static_vport sysfs file. The lpfc_static_vport
3622 * sysfs file report the mageability of the vport.
3625 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3628 struct Scsi_Host *shost = class_to_shost(dev);
3629 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3630 if (vport->vport_flag & STATIC_VPORT)
3631 sprintf(buf, "1\n");
3633 sprintf(buf, "0\n");
3639 * Sysfs attribute to control the statistical data collection.
3641 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3642 lpfc_static_vport_show, NULL);
3645 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3646 * @dev: Pointer to class device.
3647 * @buf: Data buffer.
3648 * @count: Size of the data buffer.
3650 * This function get called when a user write to the lpfc_stat_data_ctrl
3651 * sysfs file. This function parse the command written to the sysfs file
3652 * and take appropriate action. These commands are used for controlling
3653 * driver statistical data collection.
3654 * Following are the command this function handles.
3656 * setbucket <bucket_type> <base> <step>
3657 * = Set the latency buckets.
3658 * destroybucket = destroy all the buckets.
3659 * start = start data collection
3660 * stop = stop data collection
3661 * reset = reset the collected data
3664 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3665 const char *buf, size_t count)
3667 struct Scsi_Host *shost = class_to_shost(dev);
3668 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3669 struct lpfc_hba *phba = vport->phba;
3670 #define LPFC_MAX_DATA_CTRL_LEN 1024
3671 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3673 char *str_ptr, *token;
3674 struct lpfc_vport **vports;
3675 struct Scsi_Host *v_shost;
3676 char *bucket_type_str, *base_str, *step_str;
3677 unsigned long base, step, bucket_type;
3679 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3680 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3683 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3684 str_ptr = &bucket_data[0];
3685 /* Ignore this token - this is command token */
3686 token = strsep(&str_ptr, "\t ");
3690 bucket_type_str = strsep(&str_ptr, "\t ");
3691 if (!bucket_type_str)
3694 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3695 bucket_type = LPFC_LINEAR_BUCKET;
3696 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3697 bucket_type = LPFC_POWER2_BUCKET;
3701 base_str = strsep(&str_ptr, "\t ");
3704 base = simple_strtoul(base_str, NULL, 0);
3706 step_str = strsep(&str_ptr, "\t ");
3709 step = simple_strtoul(step_str, NULL, 0);
3713 /* Block the data collection for every vport */
3714 vports = lpfc_create_vport_work_array(phba);
3718 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3719 v_shost = lpfc_shost_from_vport(vports[i]);
3720 spin_lock_irq(v_shost->host_lock);
3721 /* Block and reset data collection */
3722 vports[i]->stat_data_blocked = 1;
3723 if (vports[i]->stat_data_enabled)
3724 lpfc_vport_reset_stat_data(vports[i]);
3725 spin_unlock_irq(v_shost->host_lock);
3728 /* Set the bucket attributes */
3729 phba->bucket_type = bucket_type;
3730 phba->bucket_base = base;
3731 phba->bucket_step = step;
3733 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3734 v_shost = lpfc_shost_from_vport(vports[i]);
3736 /* Unblock data collection */
3737 spin_lock_irq(v_shost->host_lock);
3738 vports[i]->stat_data_blocked = 0;
3739 spin_unlock_irq(v_shost->host_lock);
3741 lpfc_destroy_vport_work_array(phba, vports);
3745 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3746 vports = lpfc_create_vport_work_array(phba);
3750 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3751 v_shost = lpfc_shost_from_vport(vports[i]);
3752 spin_lock_irq(shost->host_lock);
3753 vports[i]->stat_data_blocked = 1;
3754 lpfc_free_bucket(vport);
3755 vport->stat_data_enabled = 0;
3756 vports[i]->stat_data_blocked = 0;
3757 spin_unlock_irq(shost->host_lock);
3759 lpfc_destroy_vport_work_array(phba, vports);
3760 phba->bucket_type = LPFC_NO_BUCKET;
3761 phba->bucket_base = 0;
3762 phba->bucket_step = 0;
3766 if (!strncmp(buf, "start", strlen("start"))) {
3767 /* If no buckets configured return error */
3768 if (phba->bucket_type == LPFC_NO_BUCKET)
3770 spin_lock_irq(shost->host_lock);
3771 if (vport->stat_data_enabled) {
3772 spin_unlock_irq(shost->host_lock);
3775 lpfc_alloc_bucket(vport);
3776 vport->stat_data_enabled = 1;
3777 spin_unlock_irq(shost->host_lock);
3781 if (!strncmp(buf, "stop", strlen("stop"))) {
3782 spin_lock_irq(shost->host_lock);
3783 if (vport->stat_data_enabled == 0) {
3784 spin_unlock_irq(shost->host_lock);
3787 lpfc_free_bucket(vport);
3788 vport->stat_data_enabled = 0;
3789 spin_unlock_irq(shost->host_lock);
3793 if (!strncmp(buf, "reset", strlen("reset"))) {
3794 if ((phba->bucket_type == LPFC_NO_BUCKET)
3795 || !vport->stat_data_enabled)
3797 spin_lock_irq(shost->host_lock);
3798 vport->stat_data_blocked = 1;
3799 lpfc_vport_reset_stat_data(vport);
3800 vport->stat_data_blocked = 0;
3801 spin_unlock_irq(shost->host_lock);
3809 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3810 * @dev: Pointer to class device object.
3811 * @buf: Data buffer.
3813 * This function is the read call back function for
3814 * lpfc_stat_data_ctrl sysfs file. This function report the
3815 * current statistical data collection state.
3818 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3821 struct Scsi_Host *shost = class_to_shost(dev);
3822 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3823 struct lpfc_hba *phba = vport->phba;
3827 unsigned long bucket_value;
3829 switch (phba->bucket_type) {
3830 case LPFC_LINEAR_BUCKET:
3831 bucket_type = "linear";
3833 case LPFC_POWER2_BUCKET:
3834 bucket_type = "power2";
3837 bucket_type = "No Bucket";
3841 sprintf(&buf[index], "Statistical Data enabled :%d, "
3842 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3843 " Bucket step :%d\nLatency Ranges :",
3844 vport->stat_data_enabled, vport->stat_data_blocked,
3845 bucket_type, phba->bucket_base, phba->bucket_step);
3846 index = strlen(buf);
3847 if (phba->bucket_type != LPFC_NO_BUCKET) {
3848 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3849 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3850 bucket_value = phba->bucket_base +
3851 phba->bucket_step * i;
3853 bucket_value = phba->bucket_base +
3854 (1 << i) * phba->bucket_step;
3856 if (index + 10 > PAGE_SIZE)
3858 sprintf(&buf[index], "%08ld ", bucket_value);
3859 index = strlen(buf);
3862 sprintf(&buf[index], "\n");
3867 * Sysfs attribute to control the statistical data collection.
3869 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3870 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3873 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3877 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3880 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3881 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3882 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3886 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3888 * @kobj: Pointer to the kernel object
3889 * @bin_attr: Attribute object
3890 * @buff: Buffer pointer
3892 * @count: Buffer size
3894 * This function is the read call back function for lpfc_drvr_stat_data
3895 * sysfs file. This function export the statistical data to user
3899 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3900 struct bin_attribute *bin_attr,
3901 char *buf, loff_t off, size_t count)
3903 struct device *dev = container_of(kobj, struct device,
3905 struct Scsi_Host *shost = class_to_shost(dev);
3906 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3907 struct lpfc_hba *phba = vport->phba;
3908 int i = 0, index = 0;
3909 unsigned long nport_index;
3910 struct lpfc_nodelist *ndlp = NULL;
3911 nport_index = (unsigned long)off /
3912 MAX_STAT_DATA_SIZE_PER_TARGET;
3914 if (!vport->stat_data_enabled || vport->stat_data_blocked
3915 || (phba->bucket_type == LPFC_NO_BUCKET))
3918 spin_lock_irq(shost->host_lock);
3919 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3920 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3923 if (nport_index > 0) {
3928 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3932 if (!ndlp->lat_data)
3936 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3937 ndlp->nlp_portname.u.wwn[0],
3938 ndlp->nlp_portname.u.wwn[1],
3939 ndlp->nlp_portname.u.wwn[2],
3940 ndlp->nlp_portname.u.wwn[3],
3941 ndlp->nlp_portname.u.wwn[4],
3942 ndlp->nlp_portname.u.wwn[5],
3943 ndlp->nlp_portname.u.wwn[6],
3944 ndlp->nlp_portname.u.wwn[7]);
3946 index = strlen(buf);
3948 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3949 sprintf(&buf[index], "%010u,",
3950 ndlp->lat_data[i].cmd_count);
3951 index = strlen(buf);
3953 sprintf(&buf[index], "\n");
3954 index = strlen(buf);
3956 spin_unlock_irq(shost->host_lock);
3960 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3962 .name = "lpfc_drvr_stat_data",
3965 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3966 .read = sysfs_drvr_stat_data_read,
3971 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3973 # Value range is [0,16]. Default value is 0.
3976 * lpfc_link_speed_set - Set the adapters link speed
3977 * @phba: lpfc_hba pointer.
3978 * @val: link speed value.
3981 * If val is in a valid range then set the adapter's link speed field and
3982 * issue a lip; if the lip fails reset the link speed to the old value.
3985 * If the value is not in range log a kernel error message and return an error.
3988 * zero if val is in range and lip okay.
3989 * non-zero return value from lpfc_issue_lip()
3990 * -EINVAL val out of range
3993 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3994 const char *buf, size_t count)
3996 struct Scsi_Host *shost = class_to_shost(dev);
3997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3998 struct lpfc_hba *phba = vport->phba;
3999 int val = LPFC_USER_LINK_SPEED_AUTO;
4001 const char *val_buf = buf;
4003 uint32_t prev_val, if_type;
4005 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4006 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4007 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4010 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4012 val_buf = &buf[strlen("nolip ")];
4015 if (!isdigit(val_buf[0]))
4017 if (sscanf(val_buf, "%i", &val) != 1)
4020 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4021 "3055 lpfc_link_speed changed from %d to %d %s\n",
4022 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4024 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4025 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4026 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4027 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4028 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4029 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4030 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
4031 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4032 "2879 lpfc_link_speed attribute cannot be set "
4033 "to %d. Speed is not supported by this port.\n",
4037 if (val == LPFC_USER_LINK_SPEED_16G &&
4038 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4039 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4040 "3112 lpfc_link_speed attribute cannot be set "
4041 "to %d. Speed is not supported in loop mode.\n",
4045 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4046 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4047 prev_val = phba->cfg_link_speed;
4048 phba->cfg_link_speed = val;
4052 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4054 phba->cfg_link_speed = prev_val;
4059 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4060 "0469 lpfc_link_speed attribute cannot be set to %d, "
4061 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
4065 static int lpfc_link_speed = 0;
4066 module_param(lpfc_link_speed, int, S_IRUGO);
4067 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4068 lpfc_param_show(link_speed)
4071 * lpfc_link_speed_init - Set the adapters link speed
4072 * @phba: lpfc_hba pointer.
4073 * @val: link speed value.
4076 * If val is in a valid range then set the adapter's link speed field.
4079 * If the value is not in range log a kernel error message, clear the link
4080 * speed and return an error.
4083 * zero if val saved.
4084 * -EINVAL val out of range
4087 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4089 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4090 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4091 "3111 lpfc_link_speed of %d cannot "
4092 "support loop mode, setting topology to default.\n",
4094 phba->cfg_topology = 0;
4096 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4097 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4098 phba->cfg_link_speed = val;
4101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4102 "0405 lpfc_link_speed attribute cannot "
4103 "be set to %d, allowed values are "
4104 "["LPFC_LINK_SPEED_STRING"]\n", val);
4105 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4109 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
4110 lpfc_link_speed_show, lpfc_link_speed_store);
4113 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4114 # 0 = aer disabled or not supported
4115 # 1 = aer supported and enabled (default)
4116 # Value range is [0,1]. Default value is 1.
4118 LPFC_ATTR(aer_support, 1, 0, 1,
4119 "Enable PCIe device AER support");
4120 lpfc_param_show(aer_support)
4123 * lpfc_aer_support_store - Set the adapter for aer support
4125 * @dev: class device that is converted into a Scsi_host.
4126 * @attr: device attribute, not used.
4127 * @buf: containing enable or disable aer flag.
4128 * @count: unused variable.
4131 * If the val is 1 and currently the device's AER capability was not
4132 * enabled, invoke the kernel's enable AER helper routine, trying to
4133 * enable the device's AER capability. If the helper routine enabling
4134 * AER returns success, update the device's cfg_aer_support flag to
4135 * indicate AER is supported by the device; otherwise, if the device
4136 * AER capability is already enabled to support AER, then do nothing.
4138 * If the val is 0 and currently the device's AER support was enabled,
4139 * invoke the kernel's disable AER helper routine. After that, update
4140 * the device's cfg_aer_support flag to indicate AER is not supported
4141 * by the device; otherwise, if the device AER capability is already
4142 * disabled from supporting AER, then do nothing.
4145 * length of the buf on success if val is in range the intended mode
4147 * -EINVAL if val out of range or intended mode is not supported.
4150 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4151 const char *buf, size_t count)
4153 struct Scsi_Host *shost = class_to_shost(dev);
4154 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4155 struct lpfc_hba *phba = vport->phba;
4156 int val = 0, rc = -EINVAL;
4158 if (!isdigit(buf[0]))
4160 if (sscanf(buf, "%i", &val) != 1)
4165 if (phba->hba_flag & HBA_AER_ENABLED) {
4166 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4168 spin_lock_irq(&phba->hbalock);
4169 phba->hba_flag &= ~HBA_AER_ENABLED;
4170 spin_unlock_irq(&phba->hbalock);
4171 phba->cfg_aer_support = 0;
4176 phba->cfg_aer_support = 0;
4181 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4182 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4184 spin_lock_irq(&phba->hbalock);
4185 phba->hba_flag |= HBA_AER_ENABLED;
4186 spin_unlock_irq(&phba->hbalock);
4187 phba->cfg_aer_support = 1;
4192 phba->cfg_aer_support = 1;
4203 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4204 lpfc_aer_support_show, lpfc_aer_support_store);
4207 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4208 * @dev: class device that is converted into a Scsi_host.
4209 * @attr: device attribute, not used.
4210 * @buf: containing flag 1 for aer cleanup state.
4211 * @count: unused variable.
4214 * If the @buf contains 1 and the device currently has the AER support
4215 * enabled, then invokes the kernel AER helper routine
4216 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4217 * error status register.
4222 * -EINVAL if the buf does not contain the 1 or the device is not currently
4223 * enabled with the AER support.
4226 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4227 const char *buf, size_t count)
4229 struct Scsi_Host *shost = class_to_shost(dev);
4230 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4231 struct lpfc_hba *phba = vport->phba;
4234 if (!isdigit(buf[0]))
4236 if (sscanf(buf, "%i", &val) != 1)
4241 if (phba->hba_flag & HBA_AER_ENABLED)
4242 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4250 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4251 lpfc_aer_cleanup_state);
4254 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4256 * @dev: class device that is converted into a Scsi_host.
4257 * @attr: device attribute, not used.
4258 * @buf: containing the string the number of vfs to be enabled.
4259 * @count: unused variable.
4262 * When this api is called either through user sysfs, the driver shall
4263 * try to enable or disable SR-IOV virtual functions according to the
4266 * If zero virtual function has been enabled to the physical function,
4267 * the driver shall invoke the pci enable virtual function api trying
4268 * to enable the virtual functions. If the nr_vfn provided is greater
4269 * than the maximum supported, the maximum virtual function number will
4270 * be used for invoking the api; otherwise, the nr_vfn provided shall
4271 * be used for invoking the api. If the api call returned success, the
4272 * actual number of virtual functions enabled will be set to the driver
4273 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4274 * cfg_sriov_nr_virtfn remains zero.
4276 * If none-zero virtual functions have already been enabled to the
4277 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4278 * -EINVAL will be returned and the driver does nothing;
4280 * If the nr_vfn provided is zero and none-zero virtual functions have
4281 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4282 * disabling virtual function api shall be invoded to disable all the
4283 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4284 * zero. Otherwise, if zero virtual function has been enabled, do
4288 * length of the buf on success if val is in range the intended mode
4290 * -EINVAL if val out of range or intended mode is not supported.
4293 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4294 const char *buf, size_t count)
4296 struct Scsi_Host *shost = class_to_shost(dev);
4297 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4298 struct lpfc_hba *phba = vport->phba;
4299 struct pci_dev *pdev = phba->pcidev;
4300 int val = 0, rc = -EINVAL;
4302 /* Sanity check on user data */
4303 if (!isdigit(buf[0]))
4305 if (sscanf(buf, "%i", &val) != 1)
4310 /* Request disabling virtual functions */
4312 if (phba->cfg_sriov_nr_virtfn > 0) {
4313 pci_disable_sriov(pdev);
4314 phba->cfg_sriov_nr_virtfn = 0;
4319 /* Request enabling virtual functions */
4320 if (phba->cfg_sriov_nr_virtfn > 0) {
4321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4322 "3018 There are %d virtual functions "
4323 "enabled on physical function.\n",
4324 phba->cfg_sriov_nr_virtfn);
4328 if (val <= LPFC_MAX_VFN_PER_PFN)
4329 phba->cfg_sriov_nr_virtfn = val;
4331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4332 "3019 Enabling %d virtual functions is not "
4337 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4339 phba->cfg_sriov_nr_virtfn = 0;
4347 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4348 "Enable PCIe device SR-IOV virtual fn");
4350 lpfc_param_show(sriov_nr_virtfn)
4351 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4352 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4355 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4357 * @dev: class device that is converted into a Scsi_host.
4358 * @attr: device attribute, not used.
4359 * @buf: containing the string the number of vfs to be enabled.
4360 * @count: unused variable.
4365 * length of the buf on success if val is in range the intended mode
4367 * -EINVAL if val out of range or intended mode is not supported.
4370 lpfc_request_firmware_upgrade_store(struct device *dev,
4371 struct device_attribute *attr,
4372 const char *buf, size_t count)
4374 struct Scsi_Host *shost = class_to_shost(dev);
4375 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4376 struct lpfc_hba *phba = vport->phba;
4377 int val = 0, rc = -EINVAL;
4379 /* Sanity check on user data */
4380 if (!isdigit(buf[0]))
4382 if (sscanf(buf, "%i", &val) != 1)
4387 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4395 static int lpfc_req_fw_upgrade;
4396 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4397 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4398 lpfc_param_show(request_firmware_upgrade)
4401 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4402 * @phba: lpfc_hba pointer.
4406 * Set the initial Linux generic firmware upgrade enable or disable flag.
4409 * zero if val saved.
4410 * -EINVAL val out of range
4413 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4415 if (val >= 0 && val <= 1) {
4416 phba->cfg_request_firmware_upgrade = val;
4421 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4422 lpfc_request_firmware_upgrade_show,
4423 lpfc_request_firmware_upgrade_store);
4426 * lpfc_fcp_imax_store
4428 * @dev: class device that is converted into a Scsi_host.
4429 * @attr: device attribute, not used.
4430 * @buf: string with the number of fast-path FCP interrupts per second.
4431 * @count: unused variable.
4434 * If val is in a valid range [636,651042], then set the adapter's
4435 * maximum number of fast-path FCP interrupts per second.
4438 * length of the buf on success if val is in range the intended mode
4440 * -EINVAL if val out of range or intended mode is not supported.
4443 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4444 const char *buf, size_t count)
4446 struct Scsi_Host *shost = class_to_shost(dev);
4447 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4448 struct lpfc_hba *phba = vport->phba;
4451 /* fcp_imax is only valid for SLI4 */
4452 if (phba->sli_rev != LPFC_SLI_REV4)
4455 /* Sanity check on user data */
4456 if (!isdigit(buf[0]))
4458 if (sscanf(buf, "%i", &val) != 1)
4462 * Value range for the HBA is [5000,5000000]
4463 * The value for each EQ depends on how many EQs are configured.
4466 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4469 phba->cfg_fcp_imax = (uint32_t)val;
4471 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4472 lpfc_modify_hba_eq_delay(phba, i);
4478 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4481 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4483 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4484 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4485 MODULE_PARM_DESC(lpfc_fcp_imax,
4486 "Set the maximum number of FCP interrupts per second per HBA");
4487 lpfc_param_show(fcp_imax)
4490 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4491 * @phba: lpfc_hba pointer.
4492 * @val: link speed value.
4495 * If val is in a valid range [636,651042], then initialize the adapter's
4496 * maximum number of fast-path FCP interrupts per second.
4499 * zero if val saved.
4500 * -EINVAL val out of range
4503 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4505 if (phba->sli_rev != LPFC_SLI_REV4) {
4506 phba->cfg_fcp_imax = 0;
4510 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4512 phba->cfg_fcp_imax = val;
4516 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4517 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4519 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4524 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4525 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4528 * lpfc_state_show - Display current driver CPU affinity
4529 * @dev: class converted to a Scsi_host structure.
4530 * @attr: device attribute, not used.
4531 * @buf: on return contains text describing the state of the link.
4533 * Returns: size of formatted string.
4536 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4539 struct Scsi_Host *shost = class_to_shost(dev);
4540 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4541 struct lpfc_hba *phba = vport->phba;
4542 struct lpfc_vector_map_info *cpup;
4545 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4546 (phba->intr_type != MSIX))
4549 switch (phba->cfg_fcp_cpu_map) {
4551 len += snprintf(buf + len, PAGE_SIZE-len,
4552 "fcp_cpu_map: No mapping (%d)\n",
4553 phba->cfg_fcp_cpu_map);
4556 len += snprintf(buf + len, PAGE_SIZE-len,
4557 "fcp_cpu_map: HBA centric mapping (%d): "
4559 phba->cfg_fcp_cpu_map,
4560 phba->sli4_hba.num_online_cpu);
4563 len += snprintf(buf + len, PAGE_SIZE-len,
4564 "fcp_cpu_map: Driver centric mapping (%d): "
4566 phba->cfg_fcp_cpu_map,
4567 phba->sli4_hba.num_online_cpu);
4571 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4572 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4574 /* margin should fit in this and the truncated message */
4575 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4576 len += snprintf(buf + len, PAGE_SIZE-len,
4577 "CPU %02d io_chan %02d "
4578 "physid %d coreid %d\n",
4579 phba->sli4_hba.curr_disp_cpu,
4580 cpup->channel_id, cpup->phys_id,
4583 len += snprintf(buf + len, PAGE_SIZE-len,
4584 "CPU %02d io_chan %02d "
4585 "physid %d coreid %d IRQ %d\n",
4586 phba->sli4_hba.curr_disp_cpu,
4587 cpup->channel_id, cpup->phys_id,
4588 cpup->core_id, cpup->irq);
4590 phba->sli4_hba.curr_disp_cpu++;
4592 /* display max number of CPUs keeping some margin */
4593 if (phba->sli4_hba.curr_disp_cpu <
4594 phba->sli4_hba.num_present_cpu &&
4595 (len >= (PAGE_SIZE - 64))) {
4596 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4601 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4602 phba->sli4_hba.curr_disp_cpu = 0;
4608 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4609 * @dev: class device that is converted into a Scsi_host.
4610 * @attr: device attribute, not used.
4611 * @buf: one or more lpfc_polling_flags values.
4615 * -EINVAL - Not implemented yet.
4618 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4619 const char *buf, size_t count)
4621 int status = -EINVAL;
4626 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4629 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4630 # 0 - Do not affinitze IRQ vectors
4631 # 1 - Affintize HBA vectors with respect to each HBA
4632 # (start with CPU0 for each HBA)
4633 # 2 - Affintize HBA vectors with respect to the entire driver
4634 # (round robin thru all CPUs across all HBAs)
4636 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4637 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4638 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4639 "Defines how to map CPUs to IRQ vectors per HBA");
4642 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4643 * @phba: lpfc_hba pointer.
4644 * @val: link speed value.
4647 * If val is in a valid range [0-2], then affinitze the adapter's
4651 * zero if val saved.
4652 * -EINVAL val out of range
4655 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4657 if (phba->sli_rev != LPFC_SLI_REV4) {
4658 phba->cfg_fcp_cpu_map = 0;
4662 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4663 phba->cfg_fcp_cpu_map = val;
4667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4668 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4670 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4675 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4676 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4679 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4680 # Value range is [2,3]. Default value is 3.
4682 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4683 "Select Fibre Channel class of service for FCP sequences");
4686 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4687 # is [0,1]. Default value is 0.
4689 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4690 "Use ADISC on rediscovery to authenticate FCP devices");
4693 # lpfc_first_burst_size: First burst size to use on the NPorts
4694 # that support first burst.
4695 # Value range is [0,65536]. Default value is 0.
4697 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4698 "First burst size for Targets that support first burst");
4701 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4702 * When the driver is configured as an NVME target, this value is
4703 * communicated to the NVME initiator in the PRLI response. It is
4704 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4705 * parameters are set and the target is sending the PRLI RSP.
4706 * Parameter supported on physical port only - no NPIV support.
4707 * Value range is [0,65536]. Default value is 0.
4709 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4710 "NVME Target mode first burst size in 512B increments.");
4713 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4714 * For the Initiator (I), enabling this parameter means that an NVMET
4715 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4716 * processed by the initiator for subsequent NVME FCP IO. For the target
4717 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4718 * driver parameter as the target function's first burst size returned to the
4719 * initiator in the target's NVME PRLI response. Parameter supported on physical
4720 * port only - no NPIV support.
4721 * Value range is [0,1]. Default value is 0 (disabled).
4723 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4724 "Enable First Burst feature on I and T functions.");
4727 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4728 # depth. Default value is 0. When the value of this parameter is zero the
4729 # SCSI command completion time is not used for controlling I/O queue depth. When
4730 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4731 # to limit the I/O completion time to the parameter value.
4732 # The value is set in milliseconds.
4734 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4735 "Use command completion time to control queue depth");
4737 lpfc_vport_param_show(max_scsicmpl_time);
4739 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4742 struct lpfc_nodelist *ndlp, *next_ndlp;
4744 if (val == vport->cfg_max_scsicmpl_time)
4746 if ((val < 0) || (val > 60000))
4748 vport->cfg_max_scsicmpl_time = val;
4750 spin_lock_irq(shost->host_lock);
4751 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4752 if (!NLP_CHK_NODE_ACT(ndlp))
4754 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4756 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4758 spin_unlock_irq(shost->host_lock);
4761 lpfc_vport_param_store(max_scsicmpl_time);
4762 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4763 lpfc_max_scsicmpl_time_show,
4764 lpfc_max_scsicmpl_time_store);
4767 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4768 # range is [0,1]. Default value is 0.
4770 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4773 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4774 * range is [0,1]. Default value is 0.
4775 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4776 * For [1], FCP commands are issued to a Work Queue associated with the
4779 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4780 * LPFC_FCP_SCHED_BY_CPU == 1
4782 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4783 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4784 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4785 * through WQs will be used.
4787 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4788 LPFC_FCP_SCHED_ROUND_ROBIN,
4789 LPFC_FCP_SCHED_BY_CPU,
4790 "Determine scheduling algorithm for "
4791 "issuing commands [0] - Round Robin, [1] - Current CPU");
4794 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4795 # range is [0,1]. Default value is 0.
4796 # For [0], bus reset issues target reset to ALL devices
4797 # For [1], bus reset issues target reset to non-FCP2 devices
4799 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4800 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4804 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4805 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4806 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4807 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4808 # cr_delay is set to 0.
4810 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4811 "interrupt response is generated");
4813 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4814 "interrupt response is generated");
4817 # lpfc_multi_ring_support: Determines how many rings to spread available
4818 # cmd/rsp IOCB entries across.
4819 # Value range is [1,2]. Default value is 1.
4821 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4822 "SLI rings to spread IOCB entries across");
4825 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4826 # identifies what rctl value to configure the additional ring for.
4827 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4829 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4830 255, "Identifies RCTL for additional ring configuration");
4833 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4834 # identifies what type value to configure the additional ring for.
4835 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4837 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4838 255, "Identifies TYPE for additional ring configuration");
4841 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4842 # 0 = SmartSAN functionality disabled (default)
4843 # 1 = SmartSAN functionality enabled
4844 # This parameter will override the value of lpfc_fdmi_on module parameter.
4845 # Value range is [0,1]. Default value is 0.
4847 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4850 # lpfc_fdmi_on: Controls FDMI support.
4851 # 0 No FDMI support (default)
4852 # 1 Traditional FDMI support
4853 # Traditional FDMI support means the driver will assume FDMI-2 support;
4854 # however, if that fails, it will fallback to FDMI-1.
4855 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4856 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4858 # Value range [0,1]. Default value is 0.
4860 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4863 # Specifies the maximum number of ELS cmds we can have outstanding (for
4864 # discovery). Value range is [1,64]. Default value = 32.
4866 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4867 "during discovery");
4870 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4871 # will be scanned by the SCSI midlayer when sequential scanning is
4872 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4873 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4874 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4875 # above. The lpfc driver limits the default value to 255 for two reasons.
4876 # As it bounds the sequential scan loop, scanning for thousands of luns
4877 # on a target can take minutes of wall clock time. Additionally,
4878 # there are FC targets, such as JBODs, that only recognize 8-bits of
4879 # LUN ID. When they receive a value greater than 8 bits, they chop off
4880 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4881 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4882 # valid responses at each of the LUN IDs, to believe there are multiple
4883 # devices present, when in fact, there is only 1.
4884 # A customer that is aware of their target behaviors, and the results as
4885 # indicated above, is welcome to increase the lpfc_max_luns value.
4886 # As mentioned, this value is not used by the lpfc driver, only the
4888 # Value range is [0,65535]. Default value is 255.
4889 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4891 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4894 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4895 # Value range is [1,255], default value is 10.
4897 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4898 "Milliseconds driver will wait between polling FCP ring");
4901 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4902 # to complete in seconds. Value range is [5,180], default value is 60.
4904 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4905 "Maximum time to wait for task management commands to complete");
4907 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4908 # support this feature
4911 # 2 = MSI-X enabled (default)
4912 # Value range is [0,2]. Default value is 2.
4914 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4915 "MSI-X (2), if possible");
4918 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4920 * 0 = NVME OAS disabled
4921 * 1 = NVME OAS enabled
4923 * Value range is [0,1]. Default value is 0.
4925 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4926 "Use OAS bit on NVME IOs");
4929 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4930 * will advertise it supports to the SCSI layer. This also will map to
4931 * the number of WQs the driver will create.
4933 * 0 = Configure the number of io channels to the number of active CPUs.
4934 * 1,32 = Manually specify how many io channels to use.
4936 * Value range is [0,32]. Default value is 4.
4938 LPFC_ATTR_R(fcp_io_channel,
4939 LPFC_FCP_IO_CHAN_DEF,
4940 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4941 "Set the number of FCP I/O channels");
4944 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4945 * will advertise it supports to the NVME layer. This also will map to
4946 * the number of WQs the driver will create.
4948 * This module parameter is valid when lpfc_enable_fc4_type is set
4951 * The NVME Layer will try to create this many, plus 1 administrative
4952 * hardware queue. The administrative queue will always map to WQ 0
4953 * A hardware IO queue maps (qidx) to a specific driver WQ.
4955 * 0 = Configure the number of io channels to the number of active CPUs.
4956 * 1,32 = Manually specify how many io channels to use.
4958 * Value range is [0,32]. Default value is 0.
4960 LPFC_ATTR_R(nvme_io_channel,
4961 LPFC_NVME_IO_CHAN_DEF,
4962 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4963 "Set the number of NVME I/O channels");
4966 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4967 # 0 = HBA resets disabled
4968 # 1 = HBA resets enabled (default)
4969 # Value range is [0,1]. Default value is 1.
4971 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
4974 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
4975 # 0 = HBA Heartbeat disabled
4976 # 1 = HBA Heartbeat enabled (default)
4977 # Value range is [0,1]. Default value is 1.
4979 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
4982 # lpfc_EnableXLane: Enable Express Lane Feature
4983 # 0x0 Express Lane Feature disabled
4984 # 0x1 Express Lane Feature enabled
4985 # Value range is [0,1]. Default value is 0.
4987 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4990 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4991 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4992 # Value range is [0x0,0x7f]. Default value is 0
4994 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
4997 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4998 # 0 = BlockGuard disabled (default)
4999 # 1 = BlockGuard enabled
5000 # Value range is [0,1]. Default value is 0.
5002 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5005 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5006 # 0 = disabled (default)
5008 # Value range is [0,1]. Default value is 0.
5010 # This feature in under investigation and may be supported in the future.
5012 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5016 # - Bit mask of host protection capabilities used to register with the
5018 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5019 # - Allows you to ultimately specify which profiles to use
5020 # - Default will result in registering capabilities for all profiles.
5021 # - SHOST_DIF_TYPE1_PROTECTION 1
5022 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5023 # - SHOST_DIX_TYPE0_PROTECTION 8
5024 # HBA supports DIX Type 0: Host to HBA protection only
5025 # - SHOST_DIX_TYPE1_PROTECTION 16
5026 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5029 LPFC_ATTR(prot_mask,
5030 (SHOST_DIF_TYPE1_PROTECTION |
5031 SHOST_DIX_TYPE0_PROTECTION |
5032 SHOST_DIX_TYPE1_PROTECTION),
5034 (SHOST_DIF_TYPE1_PROTECTION |
5035 SHOST_DIX_TYPE0_PROTECTION |
5036 SHOST_DIX_TYPE1_PROTECTION),
5037 "T10-DIF host protection capabilities mask");
5040 # lpfc_prot_guard: i
5041 # - Bit mask of protection guard types to register with the SCSI mid-layer
5042 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5043 # - Allows you to ultimately specify which profiles to use
5044 # - Default will result in registering capabilities for all guard types
5047 LPFC_ATTR(prot_guard,
5048 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5049 "T10-DIF host protection guard type");
5052 * Delay initial NPort discovery when Clean Address bit is cleared in
5053 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5054 * This parameter can have value 0 or 1.
5055 * When this parameter is set to 0, no delay is added to the initial
5057 * When this parameter is set to non-zero value, initial Nport discovery is
5058 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5059 * accept and FCID/Fabric name/Fabric portname is changed.
5060 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5061 * when Clean Address bit is cleared in FLOGI/FDISC
5062 * accept and FCID/Fabric name/Fabric portname is changed.
5063 * Default value is 0.
5065 LPFC_ATTR(delay_discovery, 0, 0, 1,
5066 "Delay NPort discovery when Clean Address bit is cleared.");
5069 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5070 * This value can be set to values between 64 and 4096. The default value is
5071 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5072 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5073 * Because of the additional overhead involved in setting up T10-DIF,
5074 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5075 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5077 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5078 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5081 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5082 * 0 = MDS Diagnostics disabled (default)
5083 * 1 = MDS Diagnostics enabled
5084 * Value range is [0,1]. Default value is 0.
5086 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5088 struct device_attribute *lpfc_hba_attrs[] = {
5089 &dev_attr_nvme_info,
5091 &dev_attr_bg_guard_err,
5092 &dev_attr_bg_apptag_err,
5093 &dev_attr_bg_reftag_err,
5095 &dev_attr_serialnum,
5096 &dev_attr_modeldesc,
5097 &dev_attr_modelname,
5098 &dev_attr_programtype,
5102 &dev_attr_option_rom_version,
5103 &dev_attr_link_state,
5104 &dev_attr_num_discovered_ports,
5105 &dev_attr_menlo_mgmt_mode,
5106 &dev_attr_lpfc_drvr_version,
5107 &dev_attr_lpfc_enable_fip,
5108 &dev_attr_lpfc_temp_sensor,
5109 &dev_attr_lpfc_log_verbose,
5110 &dev_attr_lpfc_lun_queue_depth,
5111 &dev_attr_lpfc_tgt_queue_depth,
5112 &dev_attr_lpfc_hba_queue_depth,
5113 &dev_attr_lpfc_peer_port_login,
5114 &dev_attr_lpfc_nodev_tmo,
5115 &dev_attr_lpfc_devloss_tmo,
5116 &dev_attr_lpfc_enable_fc4_type,
5117 &dev_attr_lpfc_xri_split,
5118 &dev_attr_lpfc_fcp_class,
5119 &dev_attr_lpfc_use_adisc,
5120 &dev_attr_lpfc_first_burst_size,
5121 &dev_attr_lpfc_ack0,
5122 &dev_attr_lpfc_topology,
5123 &dev_attr_lpfc_scan_down,
5124 &dev_attr_lpfc_link_speed,
5125 &dev_attr_lpfc_fcp_io_sched,
5126 &dev_attr_lpfc_fcp2_no_tgt_reset,
5127 &dev_attr_lpfc_cr_delay,
5128 &dev_attr_lpfc_cr_count,
5129 &dev_attr_lpfc_multi_ring_support,
5130 &dev_attr_lpfc_multi_ring_rctl,
5131 &dev_attr_lpfc_multi_ring_type,
5132 &dev_attr_lpfc_fdmi_on,
5133 &dev_attr_lpfc_enable_SmartSAN,
5134 &dev_attr_lpfc_max_luns,
5135 &dev_attr_lpfc_enable_npiv,
5136 &dev_attr_lpfc_fcf_failover_policy,
5137 &dev_attr_lpfc_enable_rrq,
5138 &dev_attr_nport_evt_cnt,
5139 &dev_attr_board_mode,
5146 &dev_attr_npiv_info,
5147 &dev_attr_issue_reset,
5148 &dev_attr_lpfc_poll,
5149 &dev_attr_lpfc_poll_tmo,
5150 &dev_attr_lpfc_task_mgmt_tmo,
5151 &dev_attr_lpfc_use_msi,
5152 &dev_attr_lpfc_nvme_oas,
5153 &dev_attr_lpfc_fcp_imax,
5154 &dev_attr_lpfc_fcp_cpu_map,
5155 &dev_attr_lpfc_fcp_io_channel,
5156 &dev_attr_lpfc_suppress_rsp,
5157 &dev_attr_lpfc_nvme_io_channel,
5158 &dev_attr_lpfc_nvmet_mrq,
5159 &dev_attr_lpfc_nvme_enable_fb,
5160 &dev_attr_lpfc_nvmet_fb_size,
5161 &dev_attr_lpfc_enable_bg,
5162 &dev_attr_lpfc_soft_wwnn,
5163 &dev_attr_lpfc_soft_wwpn,
5164 &dev_attr_lpfc_soft_wwn_enable,
5165 &dev_attr_lpfc_enable_hba_reset,
5166 &dev_attr_lpfc_enable_hba_heartbeat,
5167 &dev_attr_lpfc_EnableXLane,
5168 &dev_attr_lpfc_XLanePriority,
5169 &dev_attr_lpfc_xlane_lun,
5170 &dev_attr_lpfc_xlane_tgt,
5171 &dev_attr_lpfc_xlane_vpt,
5172 &dev_attr_lpfc_xlane_lun_state,
5173 &dev_attr_lpfc_xlane_lun_status,
5174 &dev_attr_lpfc_xlane_priority,
5175 &dev_attr_lpfc_sg_seg_cnt,
5176 &dev_attr_lpfc_max_scsicmpl_time,
5177 &dev_attr_lpfc_stat_data_ctrl,
5178 &dev_attr_lpfc_aer_support,
5179 &dev_attr_lpfc_aer_state_cleanup,
5180 &dev_attr_lpfc_sriov_nr_virtfn,
5181 &dev_attr_lpfc_req_fw_upgrade,
5182 &dev_attr_lpfc_suppress_link_up,
5183 &dev_attr_lpfc_iocb_cnt,
5186 &dev_attr_txcmplq_hw,
5187 &dev_attr_lpfc_fips_level,
5188 &dev_attr_lpfc_fips_rev,
5190 &dev_attr_lpfc_sriov_hw_max_virtfn,
5192 &dev_attr_lpfc_xlane_supported,
5193 &dev_attr_lpfc_enable_mds_diags,
5197 struct device_attribute *lpfc_vport_attrs[] = {
5199 &dev_attr_link_state,
5200 &dev_attr_num_discovered_ports,
5201 &dev_attr_lpfc_drvr_version,
5202 &dev_attr_lpfc_log_verbose,
5203 &dev_attr_lpfc_lun_queue_depth,
5204 &dev_attr_lpfc_tgt_queue_depth,
5205 &dev_attr_lpfc_nodev_tmo,
5206 &dev_attr_lpfc_devloss_tmo,
5207 &dev_attr_lpfc_hba_queue_depth,
5208 &dev_attr_lpfc_peer_port_login,
5209 &dev_attr_lpfc_restrict_login,
5210 &dev_attr_lpfc_fcp_class,
5211 &dev_attr_lpfc_use_adisc,
5212 &dev_attr_lpfc_first_burst_size,
5213 &dev_attr_lpfc_max_luns,
5214 &dev_attr_nport_evt_cnt,
5215 &dev_attr_npiv_info,
5216 &dev_attr_lpfc_enable_da_id,
5217 &dev_attr_lpfc_max_scsicmpl_time,
5218 &dev_attr_lpfc_stat_data_ctrl,
5219 &dev_attr_lpfc_static_vport,
5220 &dev_attr_lpfc_fips_level,
5221 &dev_attr_lpfc_fips_rev,
5226 * sysfs_ctlreg_write - Write method for writing to ctlreg
5227 * @filp: open sysfs file
5228 * @kobj: kernel kobject that contains the kernel class device.
5229 * @bin_attr: kernel attributes passed to us.
5230 * @buf: contains the data to be written to the adapter IOREG space.
5231 * @off: offset into buffer to beginning of data.
5232 * @count: bytes to transfer.
5235 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5236 * Uses the adapter io control registers to send buf contents to the adapter.
5239 * -ERANGE off and count combo out of range
5240 * -EINVAL off, count or buff address invalid
5241 * -EPERM adapter is offline
5242 * value of count, buf contents written
5245 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5246 struct bin_attribute *bin_attr,
5247 char *buf, loff_t off, size_t count)
5250 struct device *dev = container_of(kobj, struct device, kobj);
5251 struct Scsi_Host *shost = class_to_shost(dev);
5252 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5253 struct lpfc_hba *phba = vport->phba;
5255 if (phba->sli_rev >= LPFC_SLI_REV4)
5258 if ((off + count) > FF_REG_AREA_SIZE)
5261 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5264 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5267 /* This is to protect HBA registers from accidental writes. */
5268 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5271 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5274 spin_lock_irq(&phba->hbalock);
5275 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5276 buf_off += sizeof(uint32_t))
5277 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5278 phba->ctrl_regs_memmap_p + off + buf_off);
5280 spin_unlock_irq(&phba->hbalock);
5286 * sysfs_ctlreg_read - Read method for reading from ctlreg
5287 * @filp: open sysfs file
5288 * @kobj: kernel kobject that contains the kernel class device.
5289 * @bin_attr: kernel attributes passed to us.
5290 * @buf: if successful contains the data from the adapter IOREG space.
5291 * @off: offset into buffer to beginning of data.
5292 * @count: bytes to transfer.
5295 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5296 * Uses the adapter io control registers to read data into buf.
5299 * -ERANGE off and count combo out of range
5300 * -EINVAL off, count or buff address invalid
5301 * value of count, buf contents read
5304 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5305 struct bin_attribute *bin_attr,
5306 char *buf, loff_t off, size_t count)
5310 struct device *dev = container_of(kobj, struct device, kobj);
5311 struct Scsi_Host *shost = class_to_shost(dev);
5312 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5313 struct lpfc_hba *phba = vport->phba;
5315 if (phba->sli_rev >= LPFC_SLI_REV4)
5318 if (off > FF_REG_AREA_SIZE)
5321 if ((off + count) > FF_REG_AREA_SIZE)
5322 count = FF_REG_AREA_SIZE - off;
5324 if (count == 0) return 0;
5326 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5329 spin_lock_irq(&phba->hbalock);
5331 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5332 tmp_ptr = (uint32_t *)(buf + buf_off);
5333 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5336 spin_unlock_irq(&phba->hbalock);
5341 static struct bin_attribute sysfs_ctlreg_attr = {
5344 .mode = S_IRUSR | S_IWUSR,
5347 .read = sysfs_ctlreg_read,
5348 .write = sysfs_ctlreg_write,
5352 * sysfs_mbox_write - Write method for writing information via mbox
5353 * @filp: open sysfs file
5354 * @kobj: kernel kobject that contains the kernel class device.
5355 * @bin_attr: kernel attributes passed to us.
5356 * @buf: contains the data to be written to sysfs mbox.
5357 * @off: offset into buffer to beginning of data.
5358 * @count: bytes to transfer.
5361 * Deprecated function. All mailbox access from user space is performed via the
5365 * -EPERM operation not permitted
5368 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5369 struct bin_attribute *bin_attr,
5370 char *buf, loff_t off, size_t count)
5376 * sysfs_mbox_read - Read method for reading information via mbox
5377 * @filp: open sysfs file
5378 * @kobj: kernel kobject that contains the kernel class device.
5379 * @bin_attr: kernel attributes passed to us.
5380 * @buf: contains the data to be read from sysfs mbox.
5381 * @off: offset into buffer to beginning of data.
5382 * @count: bytes to transfer.
5385 * Deprecated function. All mailbox access from user space is performed via the
5389 * -EPERM operation not permitted
5392 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5393 struct bin_attribute *bin_attr,
5394 char *buf, loff_t off, size_t count)
5399 static struct bin_attribute sysfs_mbox_attr = {
5402 .mode = S_IRUSR | S_IWUSR,
5404 .size = MAILBOX_SYSFS_MAX,
5405 .read = sysfs_mbox_read,
5406 .write = sysfs_mbox_write,
5410 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5411 * @vport: address of lpfc vport structure.
5415 * error return code from sysfs_create_bin_file()
5418 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5423 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5424 &sysfs_drvr_stat_data_attr);
5426 /* Virtual ports do not need ctrl_reg and mbox */
5427 if (error || vport->port_type == LPFC_NPIV_PORT)
5430 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5431 &sysfs_ctlreg_attr);
5433 goto out_remove_stat_attr;
5435 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5438 goto out_remove_ctlreg_attr;
5441 out_remove_ctlreg_attr:
5442 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5443 out_remove_stat_attr:
5444 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5445 &sysfs_drvr_stat_data_attr);
5451 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5452 * @vport: address of lpfc vport structure.
5455 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5457 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5458 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5459 &sysfs_drvr_stat_data_attr);
5460 /* Virtual ports do not need ctrl_reg and mbox */
5461 if (vport->port_type == LPFC_NPIV_PORT)
5463 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5464 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5468 * Dynamic FC Host Attributes Support
5472 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5473 * @shost: kernel scsi host pointer.
5476 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5478 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5480 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5481 sizeof fc_host_symbolic_name(shost));
5485 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5486 * @shost: kernel scsi host pointer.
5489 lpfc_get_host_port_id(struct Scsi_Host *shost)
5491 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5493 /* note: fc_myDID already in cpu endianness */
5494 fc_host_port_id(shost) = vport->fc_myDID;
5498 * lpfc_get_host_port_type - Set the value of the scsi host port type
5499 * @shost: kernel scsi host pointer.
5502 lpfc_get_host_port_type(struct Scsi_Host *shost)
5504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5505 struct lpfc_hba *phba = vport->phba;
5507 spin_lock_irq(shost->host_lock);
5509 if (vport->port_type == LPFC_NPIV_PORT) {
5510 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5511 } else if (lpfc_is_link_up(phba)) {
5512 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5513 if (vport->fc_flag & FC_PUBLIC_LOOP)
5514 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5516 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5518 if (vport->fc_flag & FC_FABRIC)
5519 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5521 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5524 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5526 spin_unlock_irq(shost->host_lock);
5530 * lpfc_get_host_port_state - Set the value of the scsi host port state
5531 * @shost: kernel scsi host pointer.
5534 lpfc_get_host_port_state(struct Scsi_Host *shost)
5536 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5537 struct lpfc_hba *phba = vport->phba;
5539 spin_lock_irq(shost->host_lock);
5541 if (vport->fc_flag & FC_OFFLINE_MODE)
5542 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5544 switch (phba->link_state) {
5545 case LPFC_LINK_UNKNOWN:
5546 case LPFC_LINK_DOWN:
5547 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5551 case LPFC_HBA_READY:
5552 /* Links up, reports port state accordingly */
5553 if (vport->port_state < LPFC_VPORT_READY)
5554 fc_host_port_state(shost) =
5555 FC_PORTSTATE_BYPASSED;
5557 fc_host_port_state(shost) =
5558 FC_PORTSTATE_ONLINE;
5560 case LPFC_HBA_ERROR:
5561 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5564 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5569 spin_unlock_irq(shost->host_lock);
5573 * lpfc_get_host_speed - Set the value of the scsi host speed
5574 * @shost: kernel scsi host pointer.
5577 lpfc_get_host_speed(struct Scsi_Host *shost)
5579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5580 struct lpfc_hba *phba = vport->phba;
5582 spin_lock_irq(shost->host_lock);
5584 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5585 switch(phba->fc_linkspeed) {
5586 case LPFC_LINK_SPEED_1GHZ:
5587 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5589 case LPFC_LINK_SPEED_2GHZ:
5590 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5592 case LPFC_LINK_SPEED_4GHZ:
5593 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5595 case LPFC_LINK_SPEED_8GHZ:
5596 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5598 case LPFC_LINK_SPEED_10GHZ:
5599 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5601 case LPFC_LINK_SPEED_16GHZ:
5602 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5604 case LPFC_LINK_SPEED_32GHZ:
5605 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5608 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5612 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5614 spin_unlock_irq(shost->host_lock);
5618 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5619 * @shost: kernel scsi host pointer.
5622 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5624 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5625 struct lpfc_hba *phba = vport->phba;
5628 spin_lock_irq(shost->host_lock);
5630 if ((vport->port_state > LPFC_FLOGI) &&
5631 ((vport->fc_flag & FC_FABRIC) ||
5632 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5633 (vport->fc_flag & FC_PUBLIC_LOOP))))
5634 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5636 /* fabric is local port if there is no F/FL_Port */
5639 spin_unlock_irq(shost->host_lock);
5641 fc_host_fabric_name(shost) = node_name;
5645 * lpfc_get_stats - Return statistical information about the adapter
5646 * @shost: kernel scsi host pointer.
5649 * NULL on error for link down, no mbox pool, sli2 active,
5650 * management not allowed, memory allocation error, or mbox error.
5654 * address of the adapter host statistics
5656 static struct fc_host_statistics *
5657 lpfc_get_stats(struct Scsi_Host *shost)
5659 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5660 struct lpfc_hba *phba = vport->phba;
5661 struct lpfc_sli *psli = &phba->sli;
5662 struct fc_host_statistics *hs = &phba->link_stats;
5663 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5664 LPFC_MBOXQ_t *pmboxq;
5666 unsigned long seconds;
5670 * prevent udev from issuing mailbox commands until the port is
5673 if (phba->link_state < LPFC_LINK_DOWN ||
5674 !phba->mbox_mem_pool ||
5675 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5678 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5681 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5684 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5686 pmb = &pmboxq->u.mb;
5687 pmb->mbxCommand = MBX_READ_STATUS;
5688 pmb->mbxOwner = OWN_HOST;
5689 pmboxq->context1 = NULL;
5690 pmboxq->vport = vport;
5692 if (vport->fc_flag & FC_OFFLINE_MODE)
5693 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5695 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5697 if (rc != MBX_SUCCESS) {
5698 if (rc != MBX_TIMEOUT)
5699 mempool_free(pmboxq, phba->mbox_mem_pool);
5703 memset(hs, 0, sizeof (struct fc_host_statistics));
5705 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5707 * The MBX_READ_STATUS returns tx_k_bytes which has to
5708 * converted to words
5710 hs->tx_words = (uint64_t)
5711 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5713 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5714 hs->rx_words = (uint64_t)
5715 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5718 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5719 pmb->mbxCommand = MBX_READ_LNK_STAT;
5720 pmb->mbxOwner = OWN_HOST;
5721 pmboxq->context1 = NULL;
5722 pmboxq->vport = vport;
5724 if (vport->fc_flag & FC_OFFLINE_MODE)
5725 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5727 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5729 if (rc != MBX_SUCCESS) {
5730 if (rc != MBX_TIMEOUT)
5731 mempool_free(pmboxq, phba->mbox_mem_pool);
5735 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5736 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5737 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5738 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5739 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5740 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5741 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5743 hs->link_failure_count -= lso->link_failure_count;
5744 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5745 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5746 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5747 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5748 hs->invalid_crc_count -= lso->invalid_crc_count;
5749 hs->error_frames -= lso->error_frames;
5751 if (phba->hba_flag & HBA_FCOE_MODE) {
5753 hs->nos_count = (phba->link_events >> 1);
5754 hs->nos_count -= lso->link_events;
5755 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5756 hs->lip_count = (phba->fc_eventTag >> 1);
5757 hs->lip_count -= lso->link_events;
5761 hs->nos_count = (phba->fc_eventTag >> 1);
5762 hs->nos_count -= lso->link_events;
5765 hs->dumped_frames = -1;
5767 seconds = get_seconds();
5768 if (seconds < psli->stats_start)
5769 hs->seconds_since_last_reset = seconds +
5770 ((unsigned long)-1 - psli->stats_start);
5772 hs->seconds_since_last_reset = seconds - psli->stats_start;
5774 mempool_free(pmboxq, phba->mbox_mem_pool);
5780 * lpfc_reset_stats - Copy the adapter link stats information
5781 * @shost: kernel scsi host pointer.
5784 lpfc_reset_stats(struct Scsi_Host *shost)
5786 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5787 struct lpfc_hba *phba = vport->phba;
5788 struct lpfc_sli *psli = &phba->sli;
5789 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5790 LPFC_MBOXQ_t *pmboxq;
5794 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5797 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5800 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5802 pmb = &pmboxq->u.mb;
5803 pmb->mbxCommand = MBX_READ_STATUS;
5804 pmb->mbxOwner = OWN_HOST;
5805 pmb->un.varWords[0] = 0x1; /* reset request */
5806 pmboxq->context1 = NULL;
5807 pmboxq->vport = vport;
5809 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5810 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5811 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5813 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5815 if (rc != MBX_SUCCESS) {
5816 if (rc != MBX_TIMEOUT)
5817 mempool_free(pmboxq, phba->mbox_mem_pool);
5821 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5822 pmb->mbxCommand = MBX_READ_LNK_STAT;
5823 pmb->mbxOwner = OWN_HOST;
5824 pmboxq->context1 = NULL;
5825 pmboxq->vport = vport;
5827 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5828 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5829 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5831 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5833 if (rc != MBX_SUCCESS) {
5834 if (rc != MBX_TIMEOUT)
5835 mempool_free( pmboxq, phba->mbox_mem_pool);
5839 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5840 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5841 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5842 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5843 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5844 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5845 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5846 if (phba->hba_flag & HBA_FCOE_MODE)
5847 lso->link_events = (phba->link_events >> 1);
5849 lso->link_events = (phba->fc_eventTag >> 1);
5851 psli->stats_start = get_seconds();
5853 mempool_free(pmboxq, phba->mbox_mem_pool);
5859 * The LPFC driver treats linkdown handling as target loss events so there
5860 * are no sysfs handlers for link_down_tmo.
5864 * lpfc_get_node_by_target - Return the nodelist for a target
5865 * @starget: kernel scsi target pointer.
5868 * address of the node list if found
5869 * NULL target not found
5871 static struct lpfc_nodelist *
5872 lpfc_get_node_by_target(struct scsi_target *starget)
5874 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5875 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5876 struct lpfc_nodelist *ndlp;
5878 spin_lock_irq(shost->host_lock);
5879 /* Search for this, mapped, target ID */
5880 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5881 if (NLP_CHK_NODE_ACT(ndlp) &&
5882 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5883 starget->id == ndlp->nlp_sid) {
5884 spin_unlock_irq(shost->host_lock);
5888 spin_unlock_irq(shost->host_lock);
5893 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5894 * @starget: kernel scsi target pointer.
5897 lpfc_get_starget_port_id(struct scsi_target *starget)
5899 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5901 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5905 * lpfc_get_starget_node_name - Set the target node name
5906 * @starget: kernel scsi target pointer.
5908 * Description: Set the target node name to the ndlp node name wwn or zero.
5911 lpfc_get_starget_node_name(struct scsi_target *starget)
5913 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5915 fc_starget_node_name(starget) =
5916 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5920 * lpfc_get_starget_port_name - Set the target port name
5921 * @starget: kernel scsi target pointer.
5923 * Description: set the target port name to the ndlp port name wwn or zero.
5926 lpfc_get_starget_port_name(struct scsi_target *starget)
5928 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5930 fc_starget_port_name(starget) =
5931 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5935 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5936 * @rport: fc rport address.
5937 * @timeout: new value for dev loss tmo.
5940 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5941 * dev_loss_tmo to one.
5944 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5947 rport->dev_loss_tmo = timeout;
5949 rport->dev_loss_tmo = 1;
5953 * lpfc_rport_show_function - Return rport target information
5956 * Macro that uses field to generate a function with the name lpfc_show_rport_
5958 * lpfc_show_rport_##field: returns the bytes formatted in buf
5959 * @cdev: class converted to an fc_rport.
5960 * @buf: on return contains the target_field or zero.
5962 * Returns: size of formatted string.
5964 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5966 lpfc_show_rport_##field (struct device *dev, \
5967 struct device_attribute *attr, \
5970 struct fc_rport *rport = transport_class_to_rport(dev); \
5971 struct lpfc_rport_data *rdata = rport->hostdata; \
5972 return snprintf(buf, sz, format_string, \
5973 (rdata->target) ? cast rdata->target->field : 0); \
5976 #define lpfc_rport_rd_attr(field, format_string, sz) \
5977 lpfc_rport_show_function(field, format_string, sz, ) \
5978 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5981 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
5982 * @fc_vport: The fc_vport who's symbolic name has been changed.
5985 * This function is called by the transport after the @fc_vport's symbolic name
5986 * has been changed. This function re-registers the symbolic name with the
5987 * switch to propagate the change into the fabric if the vport is active.
5990 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5992 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5994 if (vport->port_state == LPFC_VPORT_READY)
5995 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5999 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6000 * @phba: Pointer to lpfc_hba struct.
6002 * This function is called by the lpfc_get_cfgparam() routine to set the
6003 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6004 * log message according to the module's lpfc_log_verbose parameter setting
6005 * before hba port or vport created.
6008 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6010 phba->cfg_log_verbose = verbose;
6013 struct fc_function_template lpfc_transport_functions = {
6014 /* fixed attributes the driver supports */
6015 .show_host_node_name = 1,
6016 .show_host_port_name = 1,
6017 .show_host_supported_classes = 1,
6018 .show_host_supported_fc4s = 1,
6019 .show_host_supported_speeds = 1,
6020 .show_host_maxframe_size = 1,
6022 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6023 .show_host_symbolic_name = 1,
6025 /* dynamic attributes the driver supports */
6026 .get_host_port_id = lpfc_get_host_port_id,
6027 .show_host_port_id = 1,
6029 .get_host_port_type = lpfc_get_host_port_type,
6030 .show_host_port_type = 1,
6032 .get_host_port_state = lpfc_get_host_port_state,
6033 .show_host_port_state = 1,
6035 /* active_fc4s is shown but doesn't change (thus no get function) */
6036 .show_host_active_fc4s = 1,
6038 .get_host_speed = lpfc_get_host_speed,
6039 .show_host_speed = 1,
6041 .get_host_fabric_name = lpfc_get_host_fabric_name,
6042 .show_host_fabric_name = 1,
6045 * The LPFC driver treats linkdown handling as target loss events
6046 * so there are no sysfs handlers for link_down_tmo.
6049 .get_fc_host_stats = lpfc_get_stats,
6050 .reset_fc_host_stats = lpfc_reset_stats,
6052 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6053 .show_rport_maxframe_size = 1,
6054 .show_rport_supported_classes = 1,
6056 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6057 .show_rport_dev_loss_tmo = 1,
6059 .get_starget_port_id = lpfc_get_starget_port_id,
6060 .show_starget_port_id = 1,
6062 .get_starget_node_name = lpfc_get_starget_node_name,
6063 .show_starget_node_name = 1,
6065 .get_starget_port_name = lpfc_get_starget_port_name,
6066 .show_starget_port_name = 1,
6068 .issue_fc_host_lip = lpfc_issue_lip,
6069 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6070 .terminate_rport_io = lpfc_terminate_rport_io,
6072 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6074 .vport_disable = lpfc_vport_disable,
6076 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6078 .bsg_request = lpfc_bsg_request,
6079 .bsg_timeout = lpfc_bsg_timeout,
6082 struct fc_function_template lpfc_vport_transport_functions = {
6083 /* fixed attributes the driver supports */
6084 .show_host_node_name = 1,
6085 .show_host_port_name = 1,
6086 .show_host_supported_classes = 1,
6087 .show_host_supported_fc4s = 1,
6088 .show_host_supported_speeds = 1,
6089 .show_host_maxframe_size = 1,
6091 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6092 .show_host_symbolic_name = 1,
6094 /* dynamic attributes the driver supports */
6095 .get_host_port_id = lpfc_get_host_port_id,
6096 .show_host_port_id = 1,
6098 .get_host_port_type = lpfc_get_host_port_type,
6099 .show_host_port_type = 1,
6101 .get_host_port_state = lpfc_get_host_port_state,
6102 .show_host_port_state = 1,
6104 /* active_fc4s is shown but doesn't change (thus no get function) */
6105 .show_host_active_fc4s = 1,
6107 .get_host_speed = lpfc_get_host_speed,
6108 .show_host_speed = 1,
6110 .get_host_fabric_name = lpfc_get_host_fabric_name,
6111 .show_host_fabric_name = 1,
6114 * The LPFC driver treats linkdown handling as target loss events
6115 * so there are no sysfs handlers for link_down_tmo.
6118 .get_fc_host_stats = lpfc_get_stats,
6119 .reset_fc_host_stats = lpfc_reset_stats,
6121 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6122 .show_rport_maxframe_size = 1,
6123 .show_rport_supported_classes = 1,
6125 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6126 .show_rport_dev_loss_tmo = 1,
6128 .get_starget_port_id = lpfc_get_starget_port_id,
6129 .show_starget_port_id = 1,
6131 .get_starget_node_name = lpfc_get_starget_node_name,
6132 .show_starget_node_name = 1,
6134 .get_starget_port_name = lpfc_get_starget_port_name,
6135 .show_starget_port_name = 1,
6137 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6138 .terminate_rport_io = lpfc_terminate_rport_io,
6140 .vport_disable = lpfc_vport_disable,
6142 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6146 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6147 * @phba: lpfc_hba pointer.
6150 lpfc_get_cfgparam(struct lpfc_hba *phba)
6152 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6153 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6154 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6155 lpfc_cr_count_init(phba, lpfc_cr_count);
6156 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6157 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6158 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6159 lpfc_ack0_init(phba, lpfc_ack0);
6160 lpfc_topology_init(phba, lpfc_topology);
6161 lpfc_link_speed_init(phba, lpfc_link_speed);
6162 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6163 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6164 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6165 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6166 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6167 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6168 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6169 lpfc_use_msi_init(phba, lpfc_use_msi);
6170 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6171 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6172 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6173 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6174 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6176 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6177 if (phba->sli_rev != LPFC_SLI_REV4)
6178 phba->cfg_EnableXLane = 0;
6179 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6181 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6182 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6183 phba->cfg_oas_lun_state = 0;
6184 phba->cfg_oas_lun_status = 0;
6185 phba->cfg_oas_flags = 0;
6186 phba->cfg_oas_priority = 0;
6187 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6188 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6189 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6190 if (phba->sli_rev == LPFC_SLI_REV4)
6193 phba->cfg_poll = lpfc_poll;
6194 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6196 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6197 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6199 /* Initialize first burst. Target vs Initiator are different. */
6200 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6201 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6202 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6203 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6205 if (phba->sli_rev != LPFC_SLI_REV4) {
6206 /* NVME only supported on SLI4 */
6207 phba->nvmet_support = 0;
6208 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6210 /* We MUST have FCP support */
6211 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6212 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6215 /* A value of 0 means use the number of CPUs found in the system */
6216 if (phba->cfg_fcp_io_channel == 0)
6217 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6218 if (phba->cfg_nvme_io_channel == 0)
6219 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6221 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6222 phba->cfg_fcp_io_channel = 0;
6224 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6225 phba->cfg_nvme_io_channel = 0;
6227 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6228 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6230 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6232 phba->cfg_soft_wwnn = 0L;
6233 phba->cfg_soft_wwpn = 0L;
6234 lpfc_xri_split_init(phba, lpfc_xri_split);
6235 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6236 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6237 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6238 lpfc_aer_support_init(phba, lpfc_aer_support);
6239 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6240 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6241 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6242 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6243 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6244 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6245 phba->cfg_enable_dss = 1;
6246 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6251 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6252 * dependencies between protocols and roles.
6253 * @phba: lpfc_hba pointer.
6256 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6258 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6259 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6261 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6262 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6264 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6265 phba->nvmet_support) {
6266 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6267 phba->cfg_fcp_io_channel = 0;
6269 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6270 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6271 "NVME Target PRLI ACC enable_fb ",
6272 phba->cfg_nvme_enable_fb,
6273 phba->cfg_nvmet_fb_size,
6274 LPFC_NVMET_FB_SZ_MAX);
6276 if (phba->cfg_nvme_enable_fb == 0)
6277 phba->cfg_nvmet_fb_size = 0;
6279 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6280 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6283 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6284 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6285 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6286 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6287 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6288 phba->cfg_nvmet_mrq);
6291 /* Not NVME Target mode. Turn off Target parameters. */
6292 phba->nvmet_support = 0;
6293 phba->cfg_nvmet_mrq = 0;
6294 phba->cfg_nvmet_fb_size = 0;
6297 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6298 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6300 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6304 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6305 * @vport: lpfc_vport pointer.
6308 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6310 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6311 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6312 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6313 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6314 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6315 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6316 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6317 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6318 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6319 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6320 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6321 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6322 lpfc_max_luns_init(vport, lpfc_max_luns);
6323 lpfc_scan_down_init(vport, lpfc_scan_down);
6324 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);