1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/ctype.h>
25 #include <linux/delay.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/aer.h>
30 #include <linux/gfp.h>
31 #include <linux/kernel.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_tcq.h>
37 #include <scsi/scsi_transport_fc.h>
38 #include <scsi/fc/fc_fs.h>
40 #include <linux/nvme-fc-driver.h>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_nvmet.h"
52 #include "lpfc_logmsg.h"
53 #include "lpfc_version.h"
54 #include "lpfc_compat.h"
55 #include "lpfc_crtn.h"
56 #include "lpfc_vport.h"
57 #include "lpfc_attr.h"
59 #define LPFC_DEF_DEVLOSS_TMO 30
60 #define LPFC_MIN_DEVLOSS_TMO 1
61 #define LPFC_MAX_DEVLOSS_TMO 255
63 #define LPFC_DEF_MRQ_POST 512
64 #define LPFC_MIN_MRQ_POST 512
65 #define LPFC_MAX_MRQ_POST 2048
68 * Write key size should be multiple of 4. If write key is changed
69 * make sure that library write key is also changed.
71 #define LPFC_REG_WRITE_KEY_SIZE 4
72 #define LPFC_REG_WRITE_KEY "EMLX"
75 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
76 * @incr: integer to convert.
77 * @hdw: ascii string holding converted integer plus a string terminator.
80 * JEDEC Joint Electron Device Engineering Council.
81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
82 * character string. The string is then terminated with a NULL in byte 9.
83 * Hex 0-9 becomes ascii '0' to '9'.
84 * Hex a-f becomes ascii '=' to 'B' capital B.
87 * Coded for 32 bit integers only.
90 lpfc_jedec_to_ascii(int incr, char hdw[])
93 for (i = 0; i < 8; i++) {
96 hdw[7 - i] = 0x30 + j;
98 hdw[7 - i] = 0x61 + j - 10;
106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
107 * @dev: class unused variable.
108 * @attr: device attribute, not used.
109 * @buf: on return contains the module description text.
111 * Returns: size of formatted string.
114 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
126 * Returns: size of formatted string.
129 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
139 return snprintf(buf, PAGE_SIZE, "0\n");
143 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = shost_priv(shost);
148 struct lpfc_hba *phba = vport->phba;
149 struct lpfc_nvmet_tgtport *tgtp;
150 struct nvme_fc_local_port *localport;
151 struct lpfc_nodelist *ndlp;
152 struct nvme_fc_remote_port *nrport;
153 uint64_t data1, data2, data3, tot;
157 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
158 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
161 if (phba->nvmet_support) {
162 if (!phba->targetport) {
163 len = snprintf(buf, PAGE_SIZE,
164 "NVME Target: x%llx is not allocated\n",
165 wwn_to_u64(vport->fc_portname.u.wwn));
168 /* Port state is only one of two values for now. */
169 if (phba->targetport->port_id)
170 statep = "REGISTERED";
173 len += snprintf(buf + len, PAGE_SIZE - len,
174 "NVME Target Enabled State %s\n",
176 len += snprintf(buf + len, PAGE_SIZE - len,
177 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
180 wwn_to_u64(vport->fc_portname.u.wwn),
181 wwn_to_u64(vport->fc_nodename.u.wwn),
182 phba->targetport->port_id);
184 len += snprintf(buf + len, PAGE_SIZE - len,
185 "\nNVME Target: Statistics\n");
186 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
187 len += snprintf(buf+len, PAGE_SIZE-len,
188 "LS: Rcv %08x Drop %08x Abort %08x\n",
189 atomic_read(&tgtp->rcv_ls_req_in),
190 atomic_read(&tgtp->rcv_ls_req_drop),
191 atomic_read(&tgtp->xmt_ls_abort));
192 if (atomic_read(&tgtp->rcv_ls_req_in) !=
193 atomic_read(&tgtp->rcv_ls_req_out)) {
194 len += snprintf(buf+len, PAGE_SIZE-len,
195 "Rcv LS: in %08x != out %08x\n",
196 atomic_read(&tgtp->rcv_ls_req_in),
197 atomic_read(&tgtp->rcv_ls_req_out));
200 len += snprintf(buf+len, PAGE_SIZE-len,
201 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
202 atomic_read(&tgtp->xmt_ls_rsp),
203 atomic_read(&tgtp->xmt_ls_drop),
204 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
205 atomic_read(&tgtp->xmt_ls_rsp_error));
207 len += snprintf(buf+len, PAGE_SIZE-len,
208 "FCP: Rcv %08x Defer %08x Release %08x "
210 atomic_read(&tgtp->rcv_fcp_cmd_in),
211 atomic_read(&tgtp->rcv_fcp_cmd_defer),
212 atomic_read(&tgtp->xmt_fcp_release),
213 atomic_read(&tgtp->rcv_fcp_cmd_drop));
215 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
216 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
217 len += snprintf(buf+len, PAGE_SIZE-len,
218 "Rcv FCP: in %08x != out %08x\n",
219 atomic_read(&tgtp->rcv_fcp_cmd_in),
220 atomic_read(&tgtp->rcv_fcp_cmd_out));
223 len += snprintf(buf+len, PAGE_SIZE-len,
224 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
226 atomic_read(&tgtp->xmt_fcp_read),
227 atomic_read(&tgtp->xmt_fcp_read_rsp),
228 atomic_read(&tgtp->xmt_fcp_write),
229 atomic_read(&tgtp->xmt_fcp_rsp),
230 atomic_read(&tgtp->xmt_fcp_drop));
232 len += snprintf(buf+len, PAGE_SIZE-len,
233 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
234 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
235 atomic_read(&tgtp->xmt_fcp_rsp_error),
236 atomic_read(&tgtp->xmt_fcp_rsp_drop));
238 len += snprintf(buf+len, PAGE_SIZE-len,
239 "ABORT: Xmt %08x Cmpl %08x\n",
240 atomic_read(&tgtp->xmt_fcp_abort),
241 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
243 len += snprintf(buf + len, PAGE_SIZE - len,
244 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
245 atomic_read(&tgtp->xmt_abort_sol),
246 atomic_read(&tgtp->xmt_abort_unsol),
247 atomic_read(&tgtp->xmt_abort_rsp),
248 atomic_read(&tgtp->xmt_abort_rsp_error));
250 /* Calculate outstanding IOs */
251 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
252 tot += atomic_read(&tgtp->xmt_fcp_release);
253 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
255 len += snprintf(buf + len, PAGE_SIZE - len,
256 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
257 "CTX Outstanding %08llx\n",
258 phba->sli4_hba.nvmet_xri_cnt,
259 phba->sli4_hba.nvmet_io_wait_cnt,
260 phba->sli4_hba.nvmet_io_wait_total,
263 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
267 localport = vport->localport;
269 len = snprintf(buf, PAGE_SIZE,
270 "NVME Initiator x%llx is not allocated\n",
271 wwn_to_u64(vport->fc_portname.u.wwn));
274 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
276 spin_lock_irq(shost->host_lock);
278 /* Port state is only one of two values for now. */
279 if (localport->port_id)
284 len += snprintf(buf + len, PAGE_SIZE - len,
285 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
288 wwn_to_u64(vport->fc_portname.u.wwn),
289 wwn_to_u64(vport->fc_nodename.u.wwn),
290 localport->port_id, statep);
292 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
296 /* local short-hand pointer. */
297 nrport = ndlp->nrport->remoteport;
299 /* Port state is only one of two values for now. */
300 switch (nrport->port_state) {
301 case FC_OBJSTATE_ONLINE:
304 case FC_OBJSTATE_UNKNOWN:
308 statep = "UNSUPPORTED";
312 /* Tab in to show lport ownership. */
313 len += snprintf(buf + len, PAGE_SIZE - len,
315 if (phba->brd_no >= 10)
316 len += snprintf(buf + len, PAGE_SIZE - len, " ");
318 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
320 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
322 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
325 /* An NVME rport can have multiple roles. */
326 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
327 len += snprintf(buf + len, PAGE_SIZE - len,
329 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
330 len += snprintf(buf + len, PAGE_SIZE - len,
332 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
333 len += snprintf(buf + len, PAGE_SIZE - len,
335 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
336 FC_PORT_ROLE_NVME_TARGET |
337 FC_PORT_ROLE_NVME_DISCOVERY))
338 len += snprintf(buf + len, PAGE_SIZE - len,
342 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
343 /* Terminate the string. */
344 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
346 spin_unlock_irq(shost->host_lock);
348 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
349 len += snprintf(buf+len, PAGE_SIZE-len,
350 "LS: Xmt %016x Cmpl %016x\n",
351 atomic_read(&phba->fc4NvmeLsRequests),
352 atomic_read(&phba->fc4NvmeLsCmpls));
354 tot = atomic_read(&phba->fc4NvmeIoCmpls);
355 data1 = atomic_read(&phba->fc4NvmeInputRequests);
356 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
357 data3 = atomic_read(&phba->fc4NvmeControlRequests);
358 len += snprintf(buf+len, PAGE_SIZE-len,
359 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
360 data1, data2, data3);
362 len += snprintf(buf+len, PAGE_SIZE-len,
363 " Cmpl %016llx Outstanding %016llx\n",
364 tot, (data1 + data2 + data3) - tot);
369 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
372 struct Scsi_Host *shost = class_to_shost(dev);
373 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
374 struct lpfc_hba *phba = vport->phba;
376 if (phba->cfg_enable_bg)
377 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
378 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
380 return snprintf(buf, PAGE_SIZE,
381 "BlockGuard Not Supported\n");
383 return snprintf(buf, PAGE_SIZE,
384 "BlockGuard Disabled\n");
388 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
391 struct Scsi_Host *shost = class_to_shost(dev);
392 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
393 struct lpfc_hba *phba = vport->phba;
395 return snprintf(buf, PAGE_SIZE, "%llu\n",
396 (unsigned long long)phba->bg_guard_err_cnt);
400 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
403 struct Scsi_Host *shost = class_to_shost(dev);
404 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
405 struct lpfc_hba *phba = vport->phba;
407 return snprintf(buf, PAGE_SIZE, "%llu\n",
408 (unsigned long long)phba->bg_apptag_err_cnt);
412 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
415 struct Scsi_Host *shost = class_to_shost(dev);
416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
419 return snprintf(buf, PAGE_SIZE, "%llu\n",
420 (unsigned long long)phba->bg_reftag_err_cnt);
424 * lpfc_info_show - Return some pci info about the host in ascii
425 * @dev: class converted to a Scsi_host structure.
426 * @attr: device attribute, not used.
427 * @buf: on return contains the formatted text from lpfc_info().
429 * Returns: size of formatted string.
432 lpfc_info_show(struct device *dev, struct device_attribute *attr,
435 struct Scsi_Host *host = class_to_shost(dev);
437 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
441 * lpfc_serialnum_show - Return the hba serial number in ascii
442 * @dev: class converted to a Scsi_host structure.
443 * @attr: device attribute, not used.
444 * @buf: on return contains the formatted text serial number.
446 * Returns: size of formatted string.
449 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
452 struct Scsi_Host *shost = class_to_shost(dev);
453 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
454 struct lpfc_hba *phba = vport->phba;
456 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
460 * lpfc_temp_sensor_show - Return the temperature sensor level
461 * @dev: class converted to a Scsi_host structure.
462 * @attr: device attribute, not used.
463 * @buf: on return contains the formatted support level.
466 * Returns a number indicating the temperature sensor level currently
467 * supported, zero or one in ascii.
469 * Returns: size of formatted string.
472 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
475 struct Scsi_Host *shost = class_to_shost(dev);
476 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
477 struct lpfc_hba *phba = vport->phba;
478 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
482 * lpfc_modeldesc_show - Return the model description of the hba
483 * @dev: class converted to a Scsi_host structure.
484 * @attr: device attribute, not used.
485 * @buf: on return contains the scsi vpd model description.
487 * Returns: size of formatted string.
490 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
493 struct Scsi_Host *shost = class_to_shost(dev);
494 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
495 struct lpfc_hba *phba = vport->phba;
497 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
501 * lpfc_modelname_show - Return the model name of the hba
502 * @dev: class converted to a Scsi_host structure.
503 * @attr: device attribute, not used.
504 * @buf: on return contains the scsi vpd model name.
506 * Returns: size of formatted string.
509 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
512 struct Scsi_Host *shost = class_to_shost(dev);
513 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
514 struct lpfc_hba *phba = vport->phba;
516 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
520 * lpfc_programtype_show - Return the program type of the hba
521 * @dev: class converted to a Scsi_host structure.
522 * @attr: device attribute, not used.
523 * @buf: on return contains the scsi vpd program type.
525 * Returns: size of formatted string.
528 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
531 struct Scsi_Host *shost = class_to_shost(dev);
532 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
533 struct lpfc_hba *phba = vport->phba;
535 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
539 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
540 * @dev: class converted to a Scsi_host structure.
541 * @attr: device attribute, not used.
542 * @buf: on return contains the Menlo Maintenance sli flag.
544 * Returns: size of formatted string.
547 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
549 struct Scsi_Host *shost = class_to_shost(dev);
550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
551 struct lpfc_hba *phba = vport->phba;
553 return snprintf(buf, PAGE_SIZE, "%d\n",
554 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
558 * lpfc_vportnum_show - Return the port number in ascii of the hba
559 * @dev: class converted to a Scsi_host structure.
560 * @attr: device attribute, not used.
561 * @buf: on return contains scsi vpd program type.
563 * Returns: size of formatted string.
566 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
569 struct Scsi_Host *shost = class_to_shost(dev);
570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
571 struct lpfc_hba *phba = vport->phba;
573 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
577 * lpfc_fwrev_show - Return the firmware rev running in the hba
578 * @dev: class converted to a Scsi_host structure.
579 * @attr: device attribute, not used.
580 * @buf: on return contains the scsi vpd program type.
582 * Returns: size of formatted string.
585 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
588 struct Scsi_Host *shost = class_to_shost(dev);
589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
590 struct lpfc_hba *phba = vport->phba;
593 char fwrev[FW_REV_STR_SIZE];
596 lpfc_decode_firmware_rev(phba, fwrev, 1);
597 if_type = phba->sli4_hba.pc_sli4_params.if_type;
598 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
600 if (phba->sli_rev < LPFC_SLI_REV4)
601 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
602 fwrev, phba->sli_rev);
604 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
605 fwrev, phba->sli_rev, if_type, sli_family);
611 * lpfc_hdw_show - Return the jedec information about the hba
612 * @dev: class converted to a Scsi_host structure.
613 * @attr: device attribute, not used.
614 * @buf: on return contains the scsi vpd program type.
616 * Returns: size of formatted string.
619 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
622 struct Scsi_Host *shost = class_to_shost(dev);
623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
624 struct lpfc_hba *phba = vport->phba;
625 lpfc_vpd_t *vp = &phba->vpd;
627 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
628 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
632 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
633 * @dev: class converted to a Scsi_host structure.
634 * @attr: device attribute, not used.
635 * @buf: on return contains the ROM and FCode ascii strings.
637 * Returns: size of formatted string.
640 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
643 struct Scsi_Host *shost = class_to_shost(dev);
644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
645 struct lpfc_hba *phba = vport->phba;
646 char fwrev[FW_REV_STR_SIZE];
648 if (phba->sli_rev < LPFC_SLI_REV4)
649 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
651 lpfc_decode_firmware_rev(phba, fwrev, 1);
652 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
656 * lpfc_state_show - Return the link state of the port
657 * @dev: class converted to a Scsi_host structure.
658 * @attr: device attribute, not used.
659 * @buf: on return contains text describing the state of the link.
662 * The switch statement has no default so zero will be returned.
664 * Returns: size of formatted string.
667 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
670 struct Scsi_Host *shost = class_to_shost(dev);
671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
672 struct lpfc_hba *phba = vport->phba;
675 switch (phba->link_state) {
676 case LPFC_LINK_UNKNOWN:
677 case LPFC_WARM_START:
678 case LPFC_INIT_START:
679 case LPFC_INIT_MBX_CMDS:
682 if (phba->hba_flag & LINK_DISABLED)
683 len += snprintf(buf + len, PAGE_SIZE-len,
684 "Link Down - User disabled\n");
686 len += snprintf(buf + len, PAGE_SIZE-len,
692 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
694 switch (vport->port_state) {
695 case LPFC_LOCAL_CFG_LINK:
696 len += snprintf(buf + len, PAGE_SIZE-len,
697 "Configuring Link\n");
701 case LPFC_FABRIC_CFG_LINK:
704 case LPFC_BUILD_DISC_LIST:
706 len += snprintf(buf + len, PAGE_SIZE - len,
709 case LPFC_VPORT_READY:
710 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
713 case LPFC_VPORT_FAILED:
714 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
717 case LPFC_VPORT_UNKNOWN:
718 len += snprintf(buf + len, PAGE_SIZE - len,
722 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
723 len += snprintf(buf + len, PAGE_SIZE-len,
724 " Menlo Maint Mode\n");
725 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
726 if (vport->fc_flag & FC_PUBLIC_LOOP)
727 len += snprintf(buf + len, PAGE_SIZE-len,
730 len += snprintf(buf + len, PAGE_SIZE-len,
733 if (vport->fc_flag & FC_FABRIC)
734 len += snprintf(buf + len, PAGE_SIZE-len,
737 len += snprintf(buf + len, PAGE_SIZE-len,
746 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
747 * @dev: class unused variable.
748 * @attr: device attribute, not used.
749 * @buf: on return contains the module description text.
751 * Returns: size of formatted string.
754 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
757 struct Scsi_Host *shost = class_to_shost(dev);
758 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
759 struct lpfc_hba *phba = vport->phba;
761 if (phba->sli_rev < LPFC_SLI_REV4)
762 return snprintf(buf, PAGE_SIZE, "fc\n");
764 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
765 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
766 return snprintf(buf, PAGE_SIZE, "fcoe\n");
767 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
768 return snprintf(buf, PAGE_SIZE, "fc\n");
770 return snprintf(buf, PAGE_SIZE, "unknown\n");
774 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
775 * (OAS) is supported.
776 * @dev: class unused variable.
777 * @attr: device attribute, not used.
778 * @buf: on return contains the module description text.
780 * Returns: size of formatted string.
783 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
786 struct Scsi_Host *shost = class_to_shost(dev);
787 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
788 struct lpfc_hba *phba = vport->phba;
790 return snprintf(buf, PAGE_SIZE, "%d\n",
791 phba->sli4_hba.pc_sli4_params.oas_supported);
795 * lpfc_link_state_store - Transition the link_state on an HBA port
796 * @dev: class device that is converted into a Scsi_host.
797 * @attr: device attribute, not used.
798 * @buf: one or more lpfc_polling_flags values.
802 * -EINVAL if the buffer is not "up" or "down"
803 * return from link state change function if non-zero
804 * length of the buf on success
807 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
808 const char *buf, size_t count)
810 struct Scsi_Host *shost = class_to_shost(dev);
811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
812 struct lpfc_hba *phba = vport->phba;
814 int status = -EINVAL;
816 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
817 (phba->link_state == LPFC_LINK_DOWN))
818 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
819 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
820 (phba->link_state >= LPFC_LINK_UP))
821 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
830 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
831 * @dev: class device that is converted into a Scsi_host.
832 * @attr: device attribute, not used.
833 * @buf: on return contains the sum of fc mapped and unmapped.
836 * Returns the ascii text number of the sum of the fc mapped and unmapped
839 * Returns: size of formatted string.
842 lpfc_num_discovered_ports_show(struct device *dev,
843 struct device_attribute *attr, char *buf)
845 struct Scsi_Host *shost = class_to_shost(dev);
846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
848 return snprintf(buf, PAGE_SIZE, "%d\n",
849 vport->fc_map_cnt + vport->fc_unmap_cnt);
853 * lpfc_issue_lip - Misnomer, name carried over from long ago
854 * @shost: Scsi_Host pointer.
857 * Bring the link down gracefully then re-init the link. The firmware will
858 * re-init the fiber channel interface as required. Does not issue a LIP.
861 * -EPERM port offline or management commands are being blocked
862 * -ENOMEM cannot allocate memory for the mailbox command
863 * -EIO error sending the mailbox command
867 lpfc_issue_lip(struct Scsi_Host *shost)
869 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
870 struct lpfc_hba *phba = vport->phba;
871 LPFC_MBOXQ_t *pmboxq;
872 int mbxstatus = MBXERR_ERROR;
875 * If the link is offline, disabled or BLOCK_MGMT_IO
876 * it doesn't make any sense to allow issue_lip
878 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
879 (phba->hba_flag & LINK_DISABLED) ||
880 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
883 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
888 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
889 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
890 pmboxq->u.mb.mbxOwner = OWN_HOST;
892 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
894 if ((mbxstatus == MBX_SUCCESS) &&
895 (pmboxq->u.mb.mbxStatus == 0 ||
896 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
897 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
898 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
899 phba->cfg_link_speed);
900 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
902 if ((mbxstatus == MBX_SUCCESS) &&
903 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
904 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
905 "2859 SLI authentication is required "
906 "for INIT_LINK but has not done yet\n");
909 lpfc_set_loopback_flag(phba);
910 if (mbxstatus != MBX_TIMEOUT)
911 mempool_free(pmboxq, phba->mbox_mem_pool);
913 if (mbxstatus == MBXERR_ERROR)
920 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
925 while (!list_empty(q)) {
926 spin_unlock_irq(lock);
928 if (cnt++ > 250) { /* 5 secs */
929 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
931 "Outstanding IO when ",
932 "bringing Adapter offline\n");
937 spin_unlock_irq(lock);
942 * lpfc_do_offline - Issues a mailbox command to bring the link down
943 * @phba: lpfc_hba pointer.
944 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
947 * Assumes any error from lpfc_do_offline() will be negative.
948 * Can wait up to 5 seconds for the port ring buffers count
949 * to reach zero, prints a warning if it is not zero and continues.
950 * lpfc_workq_post_event() returns a non-zero return code if call fails.
953 * -EIO error posting the event
957 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
959 struct completion online_compl;
960 struct lpfc_queue *qp = NULL;
961 struct lpfc_sli_ring *pring;
962 struct lpfc_sli *psli;
967 init_completion(&online_compl);
968 rc = lpfc_workq_post_event(phba, &status, &online_compl,
969 LPFC_EVT_OFFLINE_PREP);
973 wait_for_completion(&online_compl);
980 /* Wait a little for things to settle down, but not
981 * long enough for dev loss timeout to expire.
983 if (phba->sli_rev != LPFC_SLI_REV4) {
984 for (i = 0; i < psli->num_rings; i++) {
985 pring = &psli->sli3_ring[i];
986 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
991 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
995 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1001 init_completion(&online_compl);
1002 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1006 wait_for_completion(&online_compl);
1015 * lpfc_selective_reset - Offline then onlines the port
1016 * @phba: lpfc_hba pointer.
1019 * If the port is configured to allow a reset then the hba is brought
1020 * offline then online.
1023 * Assumes any error from lpfc_do_offline() will be negative.
1024 * Do not make this function static.
1027 * lpfc_do_offline() return code if not zero
1028 * -EIO reset not configured or error posting the event
1032 lpfc_selective_reset(struct lpfc_hba *phba)
1034 struct completion online_compl;
1038 if (!phba->cfg_enable_hba_reset)
1041 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1042 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1048 init_completion(&online_compl);
1049 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1054 wait_for_completion(&online_compl);
1063 * lpfc_issue_reset - Selectively resets an adapter
1064 * @dev: class device that is converted into a Scsi_host.
1065 * @attr: device attribute, not used.
1066 * @buf: containing the string "selective".
1067 * @count: unused variable.
1070 * If the buf contains the string "selective" then lpfc_selective_reset()
1071 * is called to perform the reset.
1074 * Assumes any error from lpfc_selective_reset() will be negative.
1075 * If lpfc_selective_reset() returns zero then the length of the buffer
1076 * is returned which indicates success
1079 * -EINVAL if the buffer does not contain the string "selective"
1080 * length of buf if lpfc-selective_reset() if the call succeeds
1081 * return value of lpfc_selective_reset() if the call fails
1084 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1085 const char *buf, size_t count)
1087 struct Scsi_Host *shost = class_to_shost(dev);
1088 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1089 struct lpfc_hba *phba = vport->phba;
1090 int status = -EINVAL;
1092 if (!phba->cfg_enable_hba_reset)
1095 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1096 status = phba->lpfc_selective_reset(phba);
1105 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1106 * @phba: lpfc_hba pointer.
1109 * SLI4 interface type-2 device to wait on the sliport status register for
1110 * the readyness after performing a firmware reset.
1113 * zero for success, -EPERM when port does not have privilege to perform the
1114 * reset, -EIO when port timeout from recovering from the reset.
1117 * As the caller will interpret the return code by value, be careful in making
1118 * change or addition to return codes.
1121 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1123 struct lpfc_register portstat_reg = {0};
1127 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1128 &portstat_reg.word0);
1130 /* verify if privileged for the request operation */
1131 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1132 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1135 /* wait for the SLI port firmware ready after firmware reset */
1136 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1138 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1139 &portstat_reg.word0);
1140 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1142 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1144 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1149 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1156 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1157 * @phba: lpfc_hba pointer.
1160 * Request SLI4 interface type-2 device to perform a physical register set
1167 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1169 struct completion online_compl;
1170 struct pci_dev *pdev = phba->pcidev;
1171 uint32_t before_fc_flag;
1172 uint32_t sriov_nr_virtfn;
1174 int status = 0, rc = 0;
1175 int job_posted = 1, sriov_err;
1177 if (!phba->cfg_enable_hba_reset)
1180 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1181 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1182 LPFC_SLI_INTF_IF_TYPE_2))
1185 /* Keep state if we need to restore back */
1186 before_fc_flag = phba->pport->fc_flag;
1187 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1189 /* Disable SR-IOV virtual functions if enabled */
1190 if (phba->cfg_sriov_nr_virtfn) {
1191 pci_disable_sriov(pdev);
1192 phba->cfg_sriov_nr_virtfn = 0;
1195 if (opcode == LPFC_FW_DUMP)
1196 phba->hba_flag |= HBA_FW_DUMP_OP;
1198 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1201 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1205 /* wait for the device to be quiesced before firmware reset */
1208 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1209 LPFC_CTL_PDEV_CTL_OFFSET);
1211 if (opcode == LPFC_FW_DUMP)
1212 reg_val |= LPFC_FW_DUMP_REQUEST;
1213 else if (opcode == LPFC_FW_RESET)
1214 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1215 else if (opcode == LPFC_DV_RESET)
1216 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1218 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1219 LPFC_CTL_PDEV_CTL_OFFSET);
1221 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1223 /* delay driver action following IF_TYPE_2 reset */
1224 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1227 /* no privilege for reset */
1228 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1229 "3150 No privilege to perform the requested "
1230 "access: x%x\n", reg_val);
1231 } else if (rc == -EIO) {
1232 /* reset failed, there is nothing more we can do */
1233 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1234 "3153 Fail to perform the requested "
1235 "access: x%x\n", reg_val);
1239 /* keep the original port state */
1240 if (before_fc_flag & FC_OFFLINE_MODE)
1243 init_completion(&online_compl);
1244 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1249 wait_for_completion(&online_compl);
1252 /* in any case, restore the virtual functions enabled as before */
1253 if (sriov_nr_virtfn) {
1255 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1257 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1260 /* return proper error code */
1271 * lpfc_nport_evt_cnt_show - Return the number of nport events
1272 * @dev: class device that is converted into a Scsi_host.
1273 * @attr: device attribute, not used.
1274 * @buf: on return contains the ascii number of nport events.
1276 * Returns: size of formatted string.
1279 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1282 struct Scsi_Host *shost = class_to_shost(dev);
1283 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1284 struct lpfc_hba *phba = vport->phba;
1286 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1290 * lpfc_board_mode_show - Return the state of the board
1291 * @dev: class device that is converted into a Scsi_host.
1292 * @attr: device attribute, not used.
1293 * @buf: on return contains the state of the adapter.
1295 * Returns: size of formatted string.
1298 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1301 struct Scsi_Host *shost = class_to_shost(dev);
1302 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1303 struct lpfc_hba *phba = vport->phba;
1306 if (phba->link_state == LPFC_HBA_ERROR)
1308 else if (phba->link_state == LPFC_WARM_START)
1309 state = "warm start";
1310 else if (phba->link_state == LPFC_INIT_START)
1315 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1319 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1320 * @dev: class device that is converted into a Scsi_host.
1321 * @attr: device attribute, not used.
1322 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1323 * @count: unused variable.
1326 * -EACCES if enable hba reset not enabled
1327 * -EINVAL if the buffer does not contain a valid string (see above)
1328 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1329 * buf length greater than zero indicates success
1332 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1333 const char *buf, size_t count)
1335 struct Scsi_Host *shost = class_to_shost(dev);
1336 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1337 struct lpfc_hba *phba = vport->phba;
1338 struct completion online_compl;
1339 char *board_mode_str = NULL;
1343 if (!phba->cfg_enable_hba_reset) {
1345 goto board_mode_out;
1348 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1349 "3050 lpfc_board_mode set to %s\n", buf);
1351 init_completion(&online_compl);
1353 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1354 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1358 goto board_mode_out;
1360 wait_for_completion(&online_compl);
1363 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1364 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1365 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1366 if (phba->sli_rev == LPFC_SLI_REV4)
1369 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1370 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1371 if (phba->sli_rev == LPFC_SLI_REV4)
1374 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1375 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1376 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1377 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1378 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1379 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1380 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1388 board_mode_str = strchr(buf, '\n');
1390 *board_mode_str = '\0';
1391 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1392 "3097 Failed \"%s\", status(%d), "
1394 buf, status, phba->pport->fc_flag);
1400 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1401 * @phba: pointer to the adapter structure.
1402 * @mxri: max xri count.
1403 * @axri: available xri count.
1404 * @mrpi: max rpi count.
1405 * @arpi: available rpi count.
1406 * @mvpi: max vpi count.
1407 * @avpi: available vpi count.
1410 * If an integer pointer for an count is not null then the value for the
1411 * count is returned.
1418 lpfc_get_hba_info(struct lpfc_hba *phba,
1419 uint32_t *mxri, uint32_t *axri,
1420 uint32_t *mrpi, uint32_t *arpi,
1421 uint32_t *mvpi, uint32_t *avpi)
1423 struct lpfc_mbx_read_config *rd_config;
1424 LPFC_MBOXQ_t *pmboxq;
1430 * prevent udev from issuing mailbox commands until the port is
1433 if (phba->link_state < LPFC_LINK_DOWN ||
1434 !phba->mbox_mem_pool ||
1435 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1438 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1441 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1444 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1446 pmb = &pmboxq->u.mb;
1447 pmb->mbxCommand = MBX_READ_CONFIG;
1448 pmb->mbxOwner = OWN_HOST;
1449 pmboxq->context1 = NULL;
1451 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1452 rc = MBX_NOT_FINISHED;
1454 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1456 if (rc != MBX_SUCCESS) {
1457 if (rc != MBX_TIMEOUT)
1458 mempool_free(pmboxq, phba->mbox_mem_pool);
1462 if (phba->sli_rev == LPFC_SLI_REV4) {
1463 rd_config = &pmboxq->u.mqe.un.rd_config;
1465 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1467 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1468 phba->sli4_hba.max_cfg_param.rpi_used;
1470 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1472 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1473 phba->sli4_hba.max_cfg_param.xri_used;
1475 /* Account for differences with SLI-3. Get vpi count from
1476 * mailbox data and subtract one for max vpi value.
1478 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1479 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1481 /* Limit the max we support */
1482 if (max_vpi > LPFC_MAX_VPI)
1483 max_vpi = LPFC_MAX_VPI;
1487 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1490 *mrpi = pmb->un.varRdConfig.max_rpi;
1492 *arpi = pmb->un.varRdConfig.avail_rpi;
1494 *mxri = pmb->un.varRdConfig.max_xri;
1496 *axri = pmb->un.varRdConfig.avail_xri;
1498 *mvpi = pmb->un.varRdConfig.max_vpi;
1500 /* avail_vpi is only valid if link is up and ready */
1501 if (phba->link_state == LPFC_HBA_READY)
1502 *avpi = pmb->un.varRdConfig.avail_vpi;
1504 *avpi = pmb->un.varRdConfig.max_vpi;
1508 mempool_free(pmboxq, phba->mbox_mem_pool);
1513 * lpfc_max_rpi_show - Return maximum rpi
1514 * @dev: class device that is converted into a Scsi_host.
1515 * @attr: device attribute, not used.
1516 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1519 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1520 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1521 * to "Unknown" and the buffer length is returned, therefore the caller
1522 * must check for "Unknown" in the buffer to detect a failure.
1524 * Returns: size of formatted string.
1527 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1530 struct Scsi_Host *shost = class_to_shost(dev);
1531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1532 struct lpfc_hba *phba = vport->phba;
1535 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1536 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1537 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1541 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1542 * @dev: class device that is converted into a Scsi_host.
1543 * @attr: device attribute, not used.
1544 * @buf: containing the used rpi count in decimal or "Unknown".
1547 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1548 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1549 * to "Unknown" and the buffer length is returned, therefore the caller
1550 * must check for "Unknown" in the buffer to detect a failure.
1552 * Returns: size of formatted string.
1555 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1558 struct Scsi_Host *shost = class_to_shost(dev);
1559 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1560 struct lpfc_hba *phba = vport->phba;
1563 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1564 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1565 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1569 * lpfc_max_xri_show - Return maximum xri
1570 * @dev: class device that is converted into a Scsi_host.
1571 * @attr: device attribute, not used.
1572 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1575 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1576 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1577 * to "Unknown" and the buffer length is returned, therefore the caller
1578 * must check for "Unknown" in the buffer to detect a failure.
1580 * Returns: size of formatted string.
1583 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1586 struct Scsi_Host *shost = class_to_shost(dev);
1587 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1588 struct lpfc_hba *phba = vport->phba;
1591 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1592 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1593 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1597 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1598 * @dev: class device that is converted into a Scsi_host.
1599 * @attr: device attribute, not used.
1600 * @buf: on return contains the used xri count in decimal or "Unknown".
1603 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1604 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1605 * to "Unknown" and the buffer length is returned, therefore the caller
1606 * must check for "Unknown" in the buffer to detect a failure.
1608 * Returns: size of formatted string.
1611 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1614 struct Scsi_Host *shost = class_to_shost(dev);
1615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1616 struct lpfc_hba *phba = vport->phba;
1619 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1620 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1621 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1625 * lpfc_max_vpi_show - Return maximum vpi
1626 * @dev: class device that is converted into a Scsi_host.
1627 * @attr: device attribute, not used.
1628 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1631 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1632 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1633 * to "Unknown" and the buffer length is returned, therefore the caller
1634 * must check for "Unknown" in the buffer to detect a failure.
1636 * Returns: size of formatted string.
1639 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1642 struct Scsi_Host *shost = class_to_shost(dev);
1643 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1644 struct lpfc_hba *phba = vport->phba;
1647 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1648 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1649 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1653 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1654 * @dev: class device that is converted into a Scsi_host.
1655 * @attr: device attribute, not used.
1656 * @buf: on return contains the used vpi count in decimal or "Unknown".
1659 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1660 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1661 * to "Unknown" and the buffer length is returned, therefore the caller
1662 * must check for "Unknown" in the buffer to detect a failure.
1664 * Returns: size of formatted string.
1667 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1670 struct Scsi_Host *shost = class_to_shost(dev);
1671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1672 struct lpfc_hba *phba = vport->phba;
1675 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1676 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1677 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1681 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1682 * @dev: class device that is converted into a Scsi_host.
1683 * @attr: device attribute, not used.
1684 * @buf: text that must be interpreted to determine if npiv is supported.
1687 * Buffer will contain text indicating npiv is not suppoerted on the port,
1688 * the port is an NPIV physical port, or it is an npiv virtual port with
1689 * the id of the vport.
1691 * Returns: size of formatted string.
1694 lpfc_npiv_info_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 if (!(phba->max_vpi))
1702 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1703 if (vport->port_type == LPFC_PHYSICAL_PORT)
1704 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1705 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1709 * lpfc_poll_show - Return text about poll support for the adapter
1710 * @dev: class device that is converted into a Scsi_host.
1711 * @attr: device attribute, not used.
1712 * @buf: on return contains the cfg_poll in hex.
1715 * cfg_poll should be a lpfc_polling_flags type.
1717 * Returns: size of formatted string.
1720 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1723 struct Scsi_Host *shost = class_to_shost(dev);
1724 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1725 struct lpfc_hba *phba = vport->phba;
1727 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1731 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1732 * @dev: class device that is converted into a Scsi_host.
1733 * @attr: device attribute, not used.
1734 * @buf: one or more lpfc_polling_flags values.
1738 * buf contents converted to integer and checked for a valid value.
1741 * -EINVAL if the buffer connot be converted or is out of range
1742 * length of the buf on success
1745 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1746 const char *buf, size_t count)
1748 struct Scsi_Host *shost = class_to_shost(dev);
1749 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1750 struct lpfc_hba *phba = vport->phba;
1755 if (!isdigit(buf[0]))
1758 if (sscanf(buf, "%i", &val) != 1)
1761 if ((val & 0x3) != val)
1764 if (phba->sli_rev == LPFC_SLI_REV4)
1767 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1768 "3051 lpfc_poll changed from %d to %d\n",
1769 phba->cfg_poll, val);
1771 spin_lock_irq(&phba->hbalock);
1773 old_val = phba->cfg_poll;
1775 if (val & ENABLE_FCP_RING_POLLING) {
1776 if ((val & DISABLE_FCP_RING_INT) &&
1777 !(old_val & DISABLE_FCP_RING_INT)) {
1778 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1779 spin_unlock_irq(&phba->hbalock);
1782 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1783 writel(creg_val, phba->HCregaddr);
1784 readl(phba->HCregaddr); /* flush */
1786 lpfc_poll_start_timer(phba);
1788 } else if (val != 0x0) {
1789 spin_unlock_irq(&phba->hbalock);
1793 if (!(val & DISABLE_FCP_RING_INT) &&
1794 (old_val & DISABLE_FCP_RING_INT))
1796 spin_unlock_irq(&phba->hbalock);
1797 del_timer(&phba->fcp_poll_timer);
1798 spin_lock_irq(&phba->hbalock);
1799 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1800 spin_unlock_irq(&phba->hbalock);
1803 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1804 writel(creg_val, phba->HCregaddr);
1805 readl(phba->HCregaddr); /* flush */
1808 phba->cfg_poll = val;
1810 spin_unlock_irq(&phba->hbalock);
1816 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1817 * @dev: class unused variable.
1818 * @attr: device attribute, not used.
1819 * @buf: on return contains the module description text.
1821 * Returns: size of formatted string.
1824 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1827 struct Scsi_Host *shost = class_to_shost(dev);
1828 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1829 struct lpfc_hba *phba = vport->phba;
1831 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1835 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1836 * @dev: class unused variable.
1837 * @attr: device attribute, not used.
1838 * @buf: on return contains the module description text.
1840 * Returns: size of formatted string.
1843 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1846 struct Scsi_Host *shost = class_to_shost(dev);
1847 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1848 struct lpfc_hba *phba = vport->phba;
1850 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1854 * lpfc_dss_show - Return the current state of dss and the configured state
1855 * @dev: class converted to a Scsi_host structure.
1856 * @attr: device attribute, not used.
1857 * @buf: on return contains the formatted text.
1859 * Returns: size of formatted string.
1862 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1865 struct Scsi_Host *shost = class_to_shost(dev);
1866 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1867 struct lpfc_hba *phba = vport->phba;
1869 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1870 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1871 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1876 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1877 * @dev: class converted to a Scsi_host structure.
1878 * @attr: device attribute, not used.
1879 * @buf: on return contains the formatted support level.
1882 * Returns the maximum number of virtual functions a physical function can
1883 * support, 0 will be returned if called on virtual function.
1885 * Returns: size of formatted string.
1888 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1889 struct device_attribute *attr,
1892 struct Scsi_Host *shost = class_to_shost(dev);
1893 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1894 struct lpfc_hba *phba = vport->phba;
1895 uint16_t max_nr_virtfn;
1897 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1898 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1901 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1903 return val >= min && val <= max;
1907 * lpfc_enable_bbcr_set: Sets an attribute value.
1908 * @phba: pointer the the adapter structure.
1909 * @val: integer attribute value.
1912 * Validates the min and max values then sets the
1913 * adapter config field if in the valid range. prints error message
1914 * and does not set the parameter if invalid.
1918 * -EINVAL if val is invalid
1921 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
1923 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
1924 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1925 "3068 %s_enable_bbcr changed from %d to %d\n",
1926 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
1927 phba->cfg_enable_bbcr = val;
1930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1931 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
1932 LPFC_DRIVER_NAME, val);
1937 * lpfc_param_show - Return a cfg attribute value in decimal
1940 * Macro that given an attr e.g. hba_queue_depth expands
1941 * into a function with the name lpfc_hba_queue_depth_show.
1943 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1944 * @dev: class device that is converted into a Scsi_host.
1945 * @attr: device attribute, not used.
1946 * @buf: on return contains the attribute value in decimal.
1948 * Returns: size of formatted string.
1950 #define lpfc_param_show(attr) \
1952 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1955 struct Scsi_Host *shost = class_to_shost(dev);\
1956 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1957 struct lpfc_hba *phba = vport->phba;\
1958 return snprintf(buf, PAGE_SIZE, "%d\n",\
1963 * lpfc_param_hex_show - Return a cfg attribute value in hex
1966 * Macro that given an attr e.g. hba_queue_depth expands
1967 * into a function with the name lpfc_hba_queue_depth_show
1969 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1970 * @dev: class device that is converted into a Scsi_host.
1971 * @attr: device attribute, not used.
1972 * @buf: on return contains the attribute value in hexadecimal.
1974 * Returns: size of formatted string.
1976 #define lpfc_param_hex_show(attr) \
1978 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1981 struct Scsi_Host *shost = class_to_shost(dev);\
1982 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1983 struct lpfc_hba *phba = vport->phba;\
1985 val = phba->cfg_##attr;\
1986 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1991 * lpfc_param_init - Initializes a cfg attribute
1994 * Macro that given an attr e.g. hba_queue_depth expands
1995 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1996 * takes a default argument, a minimum and maximum argument.
1998 * lpfc_##attr##_init: Initializes an attribute.
1999 * @phba: pointer the the adapter structure.
2000 * @val: integer attribute value.
2002 * Validates the min and max values then sets the adapter config field
2003 * accordingly, or uses the default if out of range and prints an error message.
2007 * -EINVAL if default used
2009 #define lpfc_param_init(attr, default, minval, maxval) \
2011 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2013 if (lpfc_rangecheck(val, minval, maxval)) {\
2014 phba->cfg_##attr = val;\
2017 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2018 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2019 "allowed range is ["#minval", "#maxval"]\n", val); \
2020 phba->cfg_##attr = default;\
2025 * lpfc_param_set - Set a cfg attribute value
2028 * Macro that given an attr e.g. hba_queue_depth expands
2029 * into a function with the name lpfc_hba_queue_depth_set
2031 * lpfc_##attr##_set: Sets an attribute value.
2032 * @phba: pointer the the adapter structure.
2033 * @val: integer attribute value.
2036 * Validates the min and max values then sets the
2037 * adapter config field if in the valid range. prints error message
2038 * and does not set the parameter if invalid.
2042 * -EINVAL if val is invalid
2044 #define lpfc_param_set(attr, default, minval, maxval) \
2046 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2048 if (lpfc_rangecheck(val, minval, maxval)) {\
2049 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2050 "3052 lpfc_" #attr " changed from %d to %d\n", \
2051 phba->cfg_##attr, val); \
2052 phba->cfg_##attr = val;\
2055 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2056 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2057 "allowed range is ["#minval", "#maxval"]\n", val); \
2062 * lpfc_param_store - Set a vport attribute value
2065 * Macro that given an attr e.g. hba_queue_depth expands
2066 * into a function with the name lpfc_hba_queue_depth_store.
2068 * lpfc_##attr##_store: Set an sttribute value.
2069 * @dev: class device that is converted into a Scsi_host.
2070 * @attr: device attribute, not used.
2071 * @buf: contains the attribute value in ascii.
2075 * Convert the ascii text number to an integer, then
2076 * use the lpfc_##attr##_set function to set the value.
2079 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2080 * length of buffer upon success.
2082 #define lpfc_param_store(attr) \
2084 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2085 const char *buf, size_t count) \
2087 struct Scsi_Host *shost = class_to_shost(dev);\
2088 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2089 struct lpfc_hba *phba = vport->phba;\
2091 if (!isdigit(buf[0]))\
2093 if (sscanf(buf, "%i", &val) != 1)\
2095 if (lpfc_##attr##_set(phba, val) == 0) \
2096 return strlen(buf);\
2102 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2105 * Macro that given an attr e.g. hba_queue_depth expands
2106 * into a function with the name lpfc_hba_queue_depth_show
2108 * lpfc_##attr##_show: prints the attribute value in decimal.
2109 * @dev: class device that is converted into a Scsi_host.
2110 * @attr: device attribute, not used.
2111 * @buf: on return contains the attribute value in decimal.
2113 * Returns: length of formatted string.
2115 #define lpfc_vport_param_show(attr) \
2117 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2120 struct Scsi_Host *shost = class_to_shost(dev);\
2121 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2122 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2126 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2129 * Macro that given an attr e.g.
2130 * hba_queue_depth expands into a function with the name
2131 * lpfc_hba_queue_depth_show
2133 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2134 * @dev: class device that is converted into a Scsi_host.
2135 * @attr: device attribute, not used.
2136 * @buf: on return contains the attribute value in hexadecimal.
2138 * Returns: length of formatted string.
2140 #define lpfc_vport_param_hex_show(attr) \
2142 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2145 struct Scsi_Host *shost = class_to_shost(dev);\
2146 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2147 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2151 * lpfc_vport_param_init - Initialize a vport cfg attribute
2154 * Macro that given an attr e.g. hba_queue_depth expands
2155 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2156 * takes a default argument, a minimum and maximum argument.
2158 * lpfc_##attr##_init: validates the min and max values then sets the
2159 * adapter config field accordingly, or uses the default if out of range
2160 * and prints an error message.
2161 * @phba: pointer the the adapter structure.
2162 * @val: integer attribute value.
2166 * -EINVAL if default used
2168 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2170 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2172 if (lpfc_rangecheck(val, minval, maxval)) {\
2173 vport->cfg_##attr = val;\
2176 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2177 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2178 "allowed range is ["#minval", "#maxval"]\n", val); \
2179 vport->cfg_##attr = default;\
2184 * lpfc_vport_param_set - Set a vport cfg attribute
2187 * Macro that given an attr e.g. hba_queue_depth expands
2188 * into a function with the name lpfc_hba_queue_depth_set
2190 * lpfc_##attr##_set: validates the min and max values then sets the
2191 * adapter config field if in the valid range. prints error message
2192 * and does not set the parameter if invalid.
2193 * @phba: pointer the the adapter structure.
2194 * @val: integer attribute value.
2198 * -EINVAL if val is invalid
2200 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2202 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2204 if (lpfc_rangecheck(val, minval, maxval)) {\
2205 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2206 "3053 lpfc_" #attr \
2207 " changed from %d (x%x) to %d (x%x)\n", \
2208 vport->cfg_##attr, vport->cfg_##attr, \
2210 vport->cfg_##attr = val;\
2213 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2214 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2215 "allowed range is ["#minval", "#maxval"]\n", val); \
2220 * lpfc_vport_param_store - Set a vport attribute
2223 * Macro that given an attr e.g. hba_queue_depth
2224 * expands into a function with the name lpfc_hba_queue_depth_store
2226 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2227 * use the lpfc_##attr##_set function to set the value.
2228 * @cdev: class device that is converted into a Scsi_host.
2229 * @buf: contains the attribute value in decimal.
2233 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2234 * length of buffer upon success.
2236 #define lpfc_vport_param_store(attr) \
2238 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2239 const char *buf, size_t count) \
2241 struct Scsi_Host *shost = class_to_shost(dev);\
2242 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2244 if (!isdigit(buf[0]))\
2246 if (sscanf(buf, "%i", &val) != 1)\
2248 if (lpfc_##attr##_set(vport, val) == 0) \
2249 return strlen(buf);\
2255 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2256 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2257 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2258 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2259 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2260 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2261 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2262 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2263 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2264 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2265 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2266 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2267 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2268 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2269 lpfc_link_state_store);
2270 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2271 lpfc_option_rom_version_show, NULL);
2272 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2273 lpfc_num_discovered_ports_show, NULL);
2274 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2275 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2276 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2277 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2278 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2279 lpfc_board_mode_show, lpfc_board_mode_store);
2280 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2281 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2282 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2283 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2284 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2285 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2286 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2287 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2288 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2289 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2290 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2291 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2292 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2293 lpfc_sriov_hw_max_virtfn_show, NULL);
2294 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2295 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2298 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2301 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2303 * @cnt: Length of string.
2304 * @wwn: Array to receive converted wwn value.
2307 * -EINVAL if the buffer does not contain a valid wwn
2311 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2315 /* Count may include a LF at end of string */
2316 if (buf[cnt-1] == '\n')
2319 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2320 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2323 memset(wwn, 0, WWN_SZ);
2325 /* Validate and store the new name */
2326 for (i = 0, j = 0; i < 16; i++) {
2327 if ((*buf >= 'a') && (*buf <= 'f'))
2328 j = ((j << 4) | ((*buf++ - 'a') + 10));
2329 else if ((*buf >= 'A') && (*buf <= 'F'))
2330 j = ((j << 4) | ((*buf++ - 'A') + 10));
2331 else if ((*buf >= '0') && (*buf <= '9'))
2332 j = ((j << 4) | (*buf++ - '0'));
2336 wwn[i/2] = j & 0xff;
2343 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2344 * @dev: class device that is converted into a Scsi_host.
2345 * @attr: device attribute, not used.
2346 * @buf: containing the string lpfc_soft_wwn_key.
2347 * @count: must be size of lpfc_soft_wwn_key.
2350 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2351 * length of buf indicates success
2354 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2355 const char *buf, size_t count)
2357 struct Scsi_Host *shost = class_to_shost(dev);
2358 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2359 struct lpfc_hba *phba = vport->phba;
2360 unsigned int cnt = count;
2361 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2362 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2365 * We're doing a simple sanity check for soft_wwpn setting.
2366 * We require that the user write a specific key to enable
2367 * the soft_wwpn attribute to be settable. Once the attribute
2368 * is written, the enable key resets. If further updates are
2369 * desired, the key must be written again to re-enable the
2372 * The "key" is not secret - it is a hardcoded string shown
2373 * here. The intent is to protect against the random user or
2374 * application that is just writing attributes.
2376 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2378 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2379 " be enabled: fawwpn is enabled\n");
2383 /* count may include a LF at end of string */
2384 if (buf[cnt-1] == '\n')
2387 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2388 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2391 phba->soft_wwn_enable = 1;
2393 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2394 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2396 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2397 " The soft_wwpn feature is not supported by Broadcom.");
2401 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2402 lpfc_soft_wwn_enable_store);
2405 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2406 * @dev: class device that is converted into a Scsi_host.
2407 * @attr: device attribute, not used.
2408 * @buf: on return contains the wwpn in hexadecimal.
2410 * Returns: size of formatted string.
2413 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2416 struct Scsi_Host *shost = class_to_shost(dev);
2417 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2418 struct lpfc_hba *phba = vport->phba;
2420 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2421 (unsigned long long)phba->cfg_soft_wwpn);
2425 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2426 * @dev class device that is converted into a Scsi_host.
2427 * @attr: device attribute, not used.
2428 * @buf: contains the wwpn in hexadecimal.
2429 * @count: number of wwpn bytes in buf
2432 * -EACCES hba reset not enabled, adapter over temp
2433 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2434 * -EIO error taking adapter offline or online
2435 * value of count on success
2438 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2439 const char *buf, size_t count)
2441 struct Scsi_Host *shost = class_to_shost(dev);
2442 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2443 struct lpfc_hba *phba = vport->phba;
2444 struct completion online_compl;
2445 int stat1 = 0, stat2 = 0;
2446 unsigned int cnt = count;
2450 if (!phba->cfg_enable_hba_reset)
2452 spin_lock_irq(&phba->hbalock);
2453 if (phba->over_temp_state == HBA_OVER_TEMP) {
2454 spin_unlock_irq(&phba->hbalock);
2457 spin_unlock_irq(&phba->hbalock);
2458 /* count may include a LF at end of string */
2459 if (buf[cnt-1] == '\n')
2462 if (!phba->soft_wwn_enable)
2465 /* lock setting wwpn, wwnn down */
2466 phba->soft_wwn_enable = 0;
2468 rc = lpfc_wwn_set(buf, cnt, wwpn);
2470 /* not able to set wwpn, unlock it */
2471 phba->soft_wwn_enable = 1;
2475 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2476 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2477 if (phba->cfg_soft_wwnn)
2478 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2480 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2481 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2483 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2485 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2486 "0463 lpfc_soft_wwpn attribute set failed to "
2487 "reinit adapter - %d\n", stat1);
2488 init_completion(&online_compl);
2489 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2494 wait_for_completion(&online_compl);
2496 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2497 "0464 lpfc_soft_wwpn attribute set failed to "
2498 "reinit adapter - %d\n", stat2);
2499 return (stat1 || stat2) ? -EIO : count;
2501 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2502 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2505 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2506 * @dev: class device that is converted into a Scsi_host.
2507 * @attr: device attribute, not used.
2508 * @buf: on return contains the wwnn in hexadecimal.
2510 * Returns: size of formatted string.
2513 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2516 struct Scsi_Host *shost = class_to_shost(dev);
2517 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2518 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2519 (unsigned long long)phba->cfg_soft_wwnn);
2523 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2524 * @cdev: class device that is converted into a Scsi_host.
2525 * @buf: contains the ww node name in hexadecimal.
2526 * @count: number of wwnn bytes in buf.
2529 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2530 * value of count on success
2533 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2534 const char *buf, size_t count)
2536 struct Scsi_Host *shost = class_to_shost(dev);
2537 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2538 unsigned int cnt = count;
2542 /* count may include a LF at end of string */
2543 if (buf[cnt-1] == '\n')
2546 if (!phba->soft_wwn_enable)
2549 rc = lpfc_wwn_set(buf, cnt, wwnn);
2551 /* Allow wwnn to be set many times, as long as the enable
2552 * is set. However, once the wwpn is set, everything locks.
2557 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2559 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2560 "lpfc%d: soft_wwnn set. Value will take effect upon "
2561 "setting of the soft_wwpn\n", phba->brd_no);
2565 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2566 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2569 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2570 * Optimized Access Storage (OAS) operations.
2571 * @dev: class device that is converted into a Scsi_host.
2572 * @attr: device attribute, not used.
2573 * @buf: buffer for passing information.
2579 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2582 struct Scsi_Host *shost = class_to_shost(dev);
2583 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2585 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2586 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2590 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2591 * Optimized Access Storage (OAS) operations.
2592 * @dev: class device that is converted into a Scsi_host.
2593 * @attr: device attribute, not used.
2594 * @buf: buffer for passing information.
2595 * @count: Size of the data buffer.
2598 * -EINVAL count is invalid, invalid wwpn byte invalid
2599 * -EPERM oas is not supported by hba
2600 * value of count on success
2603 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2604 const char *buf, size_t count)
2606 struct Scsi_Host *shost = class_to_shost(dev);
2607 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2608 unsigned int cnt = count;
2609 uint8_t wwpn[WWN_SZ];
2615 /* count may include a LF at end of string */
2616 if (buf[cnt-1] == '\n')
2619 rc = lpfc_wwn_set(buf, cnt, wwpn);
2623 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2624 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2625 if (wwn_to_u64(wwpn) == 0)
2626 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2628 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2629 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2630 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2633 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2634 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2637 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2638 * Optimized Access Storage (OAS) operations.
2639 * @dev: class device that is converted into a Scsi_host.
2640 * @attr: device attribute, not used.
2641 * @buf: buffer for passing information.
2647 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2650 struct Scsi_Host *shost = class_to_shost(dev);
2651 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2653 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2657 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2658 * Optimized Access Storage (OAS) operations.
2659 * @dev: class device that is converted into a Scsi_host.
2660 * @attr: device attribute, not used.
2661 * @buf: buffer for passing information.
2662 * @count: Size of the data buffer.
2665 * -EINVAL count is invalid, invalid wwpn byte invalid
2666 * -EPERM oas is not supported by hba
2667 * value of count on success
2670 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2671 const char *buf, size_t count)
2673 struct Scsi_Host *shost = class_to_shost(dev);
2674 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2675 unsigned int cnt = count;
2682 /* count may include a LF at end of string */
2683 if (buf[cnt-1] == '\n')
2686 ret = kstrtoul(buf, 0, &val);
2687 if (ret || (val > 0x7f))
2691 phba->cfg_oas_priority = (uint8_t)val;
2693 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2696 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2697 lpfc_oas_priority_show, lpfc_oas_priority_store);
2700 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2701 * for Optimized Access Storage (OAS) operations.
2702 * @dev: class device that is converted into a Scsi_host.
2703 * @attr: device attribute, not used.
2704 * @buf: buffer for passing information.
2707 * value of count on success
2710 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2713 struct Scsi_Host *shost = class_to_shost(dev);
2714 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2716 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2717 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2721 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2722 * for Optimized Access Storage (OAS) operations.
2723 * @dev: class device that is converted into a Scsi_host.
2724 * @attr: device attribute, not used.
2725 * @buf: buffer for passing information.
2726 * @count: Size of the data buffer.
2729 * -EINVAL count is invalid, invalid wwpn byte invalid
2730 * -EPERM oas is not supported by hba
2731 * value of count on success
2734 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2735 const char *buf, size_t count)
2737 struct Scsi_Host *shost = class_to_shost(dev);
2738 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2739 unsigned int cnt = count;
2740 uint8_t wwpn[WWN_SZ];
2746 /* count may include a LF at end of string */
2747 if (buf[cnt-1] == '\n')
2750 rc = lpfc_wwn_set(buf, cnt, wwpn);
2754 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2755 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2756 if (wwn_to_u64(wwpn) == 0)
2757 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2759 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2760 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2761 if (phba->cfg_oas_priority == 0)
2762 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2763 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2766 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2767 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2770 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2771 * of whether luns will be enabled or disabled
2772 * for Optimized Access Storage (OAS) operations.
2773 * @dev: class device that is converted into a Scsi_host.
2774 * @attr: device attribute, not used.
2775 * @buf: buffer for passing information.
2778 * size of formatted string.
2781 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2784 struct Scsi_Host *shost = class_to_shost(dev);
2785 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2787 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2791 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2792 * of whether luns will be enabled or disabled
2793 * for Optimized Access Storage (OAS) operations.
2794 * @dev: class device that is converted into a Scsi_host.
2795 * @attr: device attribute, not used.
2796 * @buf: buffer for passing information.
2797 * @count: Size of the data buffer.
2800 * -EINVAL count is invalid, invalid wwpn byte invalid
2801 * -EPERM oas is not supported by hba
2802 * value of count on success
2805 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2806 const char *buf, size_t count)
2808 struct Scsi_Host *shost = class_to_shost(dev);
2809 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2815 if (!isdigit(buf[0]))
2818 if (sscanf(buf, "%i", &val) != 1)
2821 if ((val != 0) && (val != 1))
2824 phba->cfg_oas_lun_state = val;
2827 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2828 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2831 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2832 * Storage (OAS) lun returned by the
2833 * lpfc_oas_lun_show function.
2834 * @dev: class device that is converted into a Scsi_host.
2835 * @attr: device attribute, not used.
2836 * @buf: buffer for passing information.
2839 * size of formatted string.
2842 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2845 struct Scsi_Host *shost = class_to_shost(dev);
2846 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2848 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2851 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2853 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2854 lpfc_oas_lun_status_show, NULL);
2858 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2860 * @phba: lpfc_hba pointer.
2861 * @ndlp: pointer to fcp target node.
2862 * @lun: the fc lun for setting oas state.
2863 * @oas_state: the oas state to be set to the lun.
2867 * -EPERM OAS is not enabled or not supported by this port.
2871 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2872 uint8_t tgt_wwpn[], uint64_t lun,
2873 uint32_t oas_state, uint8_t pri)
2882 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2883 (struct lpfc_name *)tgt_wwpn,
2887 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2888 (struct lpfc_name *)tgt_wwpn, lun, pri);
2895 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2896 * Access Storage (OAS) operations.
2897 * @phba: lpfc_hba pointer.
2898 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2899 * @tgt_wwpn: wwpn of the target associated with the returned lun
2900 * @lun_status: status of the lun returned lun
2902 * Returns the first or next lun enabled for OAS operations for the vport/target
2903 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2904 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2907 * lun that is OAS enabled for the vport/target
2908 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2911 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2912 uint8_t tgt_wwpn[], uint32_t *lun_status,
2917 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2918 return NOT_OAS_ENABLED_LUN;
2919 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2920 phba->sli4_hba.oas_next_vpt_wwpn,
2921 (struct lpfc_name *)
2922 phba->sli4_hba.oas_next_tgt_wwpn,
2923 &phba->sli4_hba.oas_next_lun,
2924 (struct lpfc_name *)vpt_wwpn,
2925 (struct lpfc_name *)tgt_wwpn,
2926 &found_lun, lun_status, lun_pri))
2929 return NOT_OAS_ENABLED_LUN;
2933 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2934 * @phba: lpfc_hba pointer.
2935 * @vpt_wwpn: vport wwpn by reference.
2936 * @tgt_wwpn: target wwpn by reference.
2937 * @lun: the fc lun for setting oas state.
2938 * @oas_state: the oas state to be set to the oas_lun.
2940 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2941 * a lun for OAS operations.
2945 * -ENOMEM: failed to enable an lun for OAS operations
2946 * -EPERM: OAS is not enabled
2949 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2950 uint8_t tgt_wwpn[], uint64_t lun,
2951 uint32_t oas_state, uint8_t pri)
2956 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2962 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2963 * @dev: class device that is converted into a Scsi_host.
2964 * @attr: device attribute, not used.
2965 * @buf: buffer for passing information.
2967 * This routine returns a lun enabled for OAS each time the function
2971 * SUCCESS: size of formatted string.
2972 * -EFAULT: target or vport wwpn was not set properly.
2973 * -EPERM: oas is not enabled.
2976 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2979 struct Scsi_Host *shost = class_to_shost(dev);
2980 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2988 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2989 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2992 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2993 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2996 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2997 phba->cfg_oas_tgt_wwpn,
2998 &phba->cfg_oas_lun_status,
2999 &phba->cfg_oas_priority);
3000 if (oas_lun != NOT_OAS_ENABLED_LUN)
3001 phba->cfg_oas_flags |= OAS_LUN_VALID;
3003 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3009 * lpfc_oas_lun_store - Sets the OAS state for lun
3010 * @dev: class device that is converted into a Scsi_host.
3011 * @attr: device attribute, not used.
3012 * @buf: buffer for passing information.
3014 * This function sets the OAS state for lun. Before this function is called,
3015 * the vport wwpn, target wwpn, and oas state need to be set.
3018 * SUCCESS: size of formatted string.
3019 * -EFAULT: target or vport wwpn was not set properly.
3020 * -EPERM: oas is not enabled.
3021 * size of formatted string.
3024 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3025 const char *buf, size_t count)
3027 struct Scsi_Host *shost = class_to_shost(dev);
3028 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3036 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3039 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3042 if (!isdigit(buf[0]))
3045 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3048 pri = phba->cfg_oas_priority;
3050 pri = phba->cfg_XLanePriority;
3052 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3053 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3054 "priority 0x%x with oas state %d\n",
3055 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3056 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3057 pri, phba->cfg_oas_lun_state);
3059 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3060 phba->cfg_oas_tgt_wwpn, scsi_lun,
3061 phba->cfg_oas_lun_state, pri);
3067 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3068 lpfc_oas_lun_show, lpfc_oas_lun_store);
3070 int lpfc_enable_nvmet_cnt;
3071 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3072 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3073 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3074 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3075 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3077 static int lpfc_poll = 0;
3078 module_param(lpfc_poll, int, S_IRUGO);
3079 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3081 " 1 - poll with interrupts enabled"
3082 " 3 - poll and disable FCP ring interrupts");
3084 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3085 lpfc_poll_show, lpfc_poll_store);
3087 int lpfc_no_hba_reset_cnt;
3088 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3089 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3090 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3091 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3093 LPFC_ATTR(sli_mode, 0, 0, 3,
3094 "SLI mode selector:"
3095 " 0 - auto (SLI-3 if supported),"
3096 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3097 " 3 - select SLI-3");
3099 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3100 "Enable NPIV functionality");
3102 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3103 "FCF Fast failover=1 Priority failover=2");
3106 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3107 # 0x0 = disabled, XRI/OXID use not tracked.
3108 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3109 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3111 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3112 "Enable RRQ functionality");
3115 # lpfc_suppress_link_up: Bring link up at initialization
3116 # 0x0 = bring link up (issue MBX_INIT_LINK)
3117 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3118 # 0x2 = never bring up link
3119 # Default value is 0.
3121 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3122 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3123 "Suppress Link Up at initialization");
3125 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3133 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3135 struct Scsi_Host *shost = class_to_shost(dev);
3136 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3138 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3141 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3142 lpfc_iocb_hw_show, NULL);
3144 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3146 struct Scsi_Host *shost = class_to_shost(dev);
3147 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3148 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3150 return snprintf(buf, PAGE_SIZE, "%d\n",
3151 pring ? pring->txq_max : 0);
3154 static DEVICE_ATTR(txq_hw, S_IRUGO,
3155 lpfc_txq_hw_show, NULL);
3157 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3160 struct Scsi_Host *shost = class_to_shost(dev);
3161 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3162 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3164 return snprintf(buf, PAGE_SIZE, "%d\n",
3165 pring ? pring->txcmplq_max : 0);
3168 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3169 lpfc_txcmplq_hw_show, NULL);
3171 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3172 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3175 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3176 # until the timer expires. Value range is [0,255]. Default value is 30.
3178 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3179 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3180 module_param(lpfc_nodev_tmo, int, 0);
3181 MODULE_PARM_DESC(lpfc_nodev_tmo,
3182 "Seconds driver will hold I/O waiting "
3183 "for a device to come back");
3186 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3187 * @dev: class converted to a Scsi_host structure.
3188 * @attr: device attribute, not used.
3189 * @buf: on return contains the dev loss timeout in decimal.
3191 * Returns: size of formatted string.
3194 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3197 struct Scsi_Host *shost = class_to_shost(dev);
3198 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3200 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3204 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3205 * @vport: lpfc vport structure pointer.
3206 * @val: contains the nodev timeout value.
3209 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3210 * a kernel error message is printed and zero is returned.
3211 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3212 * Otherwise nodev tmo is set to the default value.
3215 * zero if already set or if val is in range
3216 * -EINVAL val out of range
3219 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3221 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3222 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3223 if (val != LPFC_DEF_DEVLOSS_TMO)
3224 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3225 "0407 Ignoring lpfc_nodev_tmo module "
3226 "parameter because lpfc_devloss_tmo "
3231 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3232 vport->cfg_nodev_tmo = val;
3233 vport->cfg_devloss_tmo = val;
3236 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3237 "0400 lpfc_nodev_tmo attribute cannot be set to"
3238 " %d, allowed range is [%d, %d]\n",
3239 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3240 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3245 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3246 * @vport: lpfc vport structure pointer.
3249 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3252 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3254 struct Scsi_Host *shost;
3255 struct lpfc_nodelist *ndlp;
3257 shost = lpfc_shost_from_vport(vport);
3258 spin_lock_irq(shost->host_lock);
3259 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3260 if (!NLP_CHK_NODE_ACT(ndlp))
3263 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3265 spin_unlock_irq(shost->host_lock);
3269 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3270 * @vport: lpfc vport structure pointer.
3271 * @val: contains the tmo value.
3274 * If the devloss tmo is already set or the vport dev loss tmo has changed
3275 * then a kernel error message is printed and zero is returned.
3276 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3277 * Otherwise nodev tmo is set to the default value.
3280 * zero if already set or if val is in range
3281 * -EINVAL val out of range
3284 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3286 if (vport->dev_loss_tmo_changed ||
3287 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3288 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3289 "0401 Ignoring change to lpfc_nodev_tmo "
3290 "because lpfc_devloss_tmo is set.\n");
3293 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3294 vport->cfg_nodev_tmo = val;
3295 vport->cfg_devloss_tmo = val;
3297 * For compat: set the fc_host dev loss so new rports
3298 * will get the value.
3300 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3301 lpfc_update_rport_devloss_tmo(vport);
3304 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3305 "0403 lpfc_nodev_tmo attribute cannot be set to "
3306 "%d, allowed range is [%d, %d]\n",
3307 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3311 lpfc_vport_param_store(nodev_tmo)
3313 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3314 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3317 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3318 # disappear until the timer expires. Value range is [0,255]. Default
3321 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3322 MODULE_PARM_DESC(lpfc_devloss_tmo,
3323 "Seconds driver will hold I/O waiting "
3324 "for a device to come back");
3325 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3326 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3327 lpfc_vport_param_show(devloss_tmo)
3330 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3331 * @vport: lpfc vport structure pointer.
3332 * @val: contains the tmo value.
3335 * If val is in a valid range then set the vport nodev tmo,
3336 * devloss tmo, also set the vport dev loss tmo changed flag.
3337 * Else a kernel error message is printed.
3340 * zero if val is in range
3341 * -EINVAL val out of range
3344 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3346 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3347 vport->cfg_nodev_tmo = val;
3348 vport->cfg_devloss_tmo = val;
3349 vport->dev_loss_tmo_changed = 1;
3350 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3351 lpfc_update_rport_devloss_tmo(vport);
3355 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3356 "0404 lpfc_devloss_tmo attribute cannot be set to "
3357 "%d, allowed range is [%d, %d]\n",
3358 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3362 lpfc_vport_param_store(devloss_tmo)
3363 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3364 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3367 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3368 * lpfc_suppress_rsp = 0 Disable
3369 * lpfc_suppress_rsp = 1 Enable (default)
3372 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3373 "Enable suppress rsp feature is firmware supports it");
3376 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3377 * lpfc_nvmet_mrq = 1 use a single RQ pair
3378 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3381 LPFC_ATTR_R(nvmet_mrq,
3383 "Specify number of RQ pairs for processing NVMET cmds");
3386 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3387 * Supported Values: 1 - register just FCP
3388 * 3 - register both FCP and NVME
3389 * Supported values are [1,3]. Default value is 1
3391 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3392 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3393 "Define fc4 type to register with fabric.");
3396 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3397 * This parameter is only used if:
3398 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3399 * port is not configured for NVMET.
3401 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3402 * The remaining XRIs get split up based on lpfc_xri_split per port:
3404 * Supported Values are in percentages
3405 * the xri_split value is the percentage the SCSI port will get. The remaining
3406 * percentage will go to NVME.
3408 LPFC_ATTR_R(xri_split, 50, 10, 90,
3409 "Division of XRI resources between SCSI and NVME");
3412 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3413 # deluged with LOTS of information.
3414 # You can set a bit mask to record specific types of verbose messages:
3415 # See lpfc_logmsh.h for definitions.
3417 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3418 "Verbose logging bit-mask");
3421 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3422 # objects that have been registered with the nameserver after login.
3424 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3425 "Deregister nameserver objects before LOGO");
3428 # lun_queue_depth: This parameter is used to limit the number of outstanding
3429 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3430 # If this parameter value is greater than 1/8th the maximum number of exchanges
3431 # supported by the HBA port, then the lun queue depth will be reduced to
3432 # 1/8th the maximum number of exchanges.
3434 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3435 "Max number of FCP commands we can queue to a specific LUN");
3438 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3439 # commands per target port. Value range is [10,65535]. Default value is 65535.
3441 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3442 "Max number of FCP commands we can queue to a specific target port");
3445 # hba_queue_depth: This parameter is used to limit the number of outstanding
3446 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3447 # value is greater than the maximum number of exchanges supported by the HBA,
3448 # then maximum number of exchanges supported by the HBA is used to determine
3449 # the hba_queue_depth.
3451 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3452 "Max number of FCP commands we can queue to a lpfc HBA");
3455 # peer_port_login: This parameter allows/prevents logins
3456 # between peer ports hosted on the same physical port.
3457 # When this parameter is set 0 peer ports of same physical port
3458 # are not allowed to login to each other.
3459 # When this parameter is set 1 peer ports of same physical port
3460 # are allowed to login to each other.
3461 # Default value of this parameter is 0.
3463 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3464 "Allow peer ports on the same physical port to login to each "
3468 # restrict_login: This parameter allows/prevents logins
3469 # between Virtual Ports and remote initiators.
3470 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3471 # other initiators and will attempt to PLOGI all remote ports.
3472 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3473 # remote ports and will not attempt to PLOGI to other initiators.
3474 # This parameter does not restrict to the physical port.
3475 # This parameter does not restrict logins to Fabric resident remote ports.
3476 # Default value of this parameter is 1.
3478 static int lpfc_restrict_login = 1;
3479 module_param(lpfc_restrict_login, int, S_IRUGO);
3480 MODULE_PARM_DESC(lpfc_restrict_login,
3481 "Restrict virtual ports login to remote initiators.");
3482 lpfc_vport_param_show(restrict_login);
3485 * lpfc_restrict_login_init - Set the vport restrict login flag
3486 * @vport: lpfc vport structure pointer.
3487 * @val: contains the restrict login value.
3490 * If val is not in a valid range then log a kernel error message and set
3491 * the vport restrict login to one.
3492 * If the port type is physical clear the restrict login flag and return.
3493 * Else set the restrict login flag to val.
3496 * zero if val is in range
3497 * -EINVAL val out of range
3500 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3502 if (val < 0 || val > 1) {
3503 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3504 "0422 lpfc_restrict_login attribute cannot "
3505 "be set to %d, allowed range is [0, 1]\n",
3507 vport->cfg_restrict_login = 1;
3510 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3511 vport->cfg_restrict_login = 0;
3514 vport->cfg_restrict_login = val;
3519 * lpfc_restrict_login_set - Set the vport restrict login flag
3520 * @vport: lpfc vport structure pointer.
3521 * @val: contains the restrict login value.
3524 * If val is not in a valid range then log a kernel error message and set
3525 * the vport restrict login to one.
3526 * If the port type is physical and the val is not zero log a kernel
3527 * error message, clear the restrict login flag and return zero.
3528 * Else set the restrict login flag to val.
3531 * zero if val is in range
3532 * -EINVAL val out of range
3535 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3537 if (val < 0 || val > 1) {
3538 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3539 "0425 lpfc_restrict_login attribute cannot "
3540 "be set to %d, allowed range is [0, 1]\n",
3542 vport->cfg_restrict_login = 1;
3545 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3546 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3547 "0468 lpfc_restrict_login must be 0 for "
3548 "Physical ports.\n");
3549 vport->cfg_restrict_login = 0;
3552 vport->cfg_restrict_login = val;
3555 lpfc_vport_param_store(restrict_login);
3556 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3557 lpfc_restrict_login_show, lpfc_restrict_login_store);
3560 # Some disk devices have a "select ID" or "select Target" capability.
3561 # From a protocol standpoint "select ID" usually means select the
3562 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3563 # annex" which contains a table that maps a "select ID" (a number
3564 # between 0 and 7F) to an ALPA. By default, for compatibility with
3565 # older drivers, the lpfc driver scans this table from low ALPA to high
3568 # Turning on the scan-down variable (on = 1, off = 0) will
3569 # cause the lpfc driver to use an inverted table, effectively
3570 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3572 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3573 # and will not work across a fabric. Also this parameter will take
3574 # effect only in the case when ALPA map is not available.)
3576 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3577 "Start scanning for devices from highest ALPA to lowest");
3580 # lpfc_topology: link topology for init link
3581 # 0x0 = attempt loop mode then point-to-point
3582 # 0x01 = internal loopback mode
3583 # 0x02 = attempt point-to-point mode only
3584 # 0x04 = attempt loop mode only
3585 # 0x06 = attempt point-to-point mode then loop
3586 # Set point-to-point mode if you want to run as an N_Port.
3587 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3588 # Default value is 0.
3590 LPFC_ATTR(topology, 0, 0, 6,
3591 "Select Fibre Channel topology");
3594 * lpfc_topology_set - Set the adapters topology field
3595 * @phba: lpfc_hba pointer.
3596 * @val: topology value.
3599 * If val is in a valid range then set the adapter's topology field and
3600 * issue a lip; if the lip fails reset the topology to the old value.
3602 * If the value is not in range log a kernel error message and return an error.
3605 * zero if val is in range and lip okay
3606 * non-zero return value from lpfc_issue_lip()
3607 * -EINVAL val out of range
3610 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3611 const char *buf, size_t count)
3613 struct Scsi_Host *shost = class_to_shost(dev);
3614 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3615 struct lpfc_hba *phba = vport->phba;
3618 const char *val_buf = buf;
3622 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3624 val_buf = &buf[strlen("nolip ")];
3627 if (!isdigit(val_buf[0]))
3629 if (sscanf(val_buf, "%i", &val) != 1)
3632 if (val >= 0 && val <= 6) {
3633 prev_val = phba->cfg_topology;
3634 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3636 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3637 "3113 Loop mode not supported at speed %d\n",
3641 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3643 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3644 "3114 Loop mode not supported\n");
3647 phba->cfg_topology = val;
3651 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3652 "3054 lpfc_topology changed from %d to %d\n",
3654 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3655 phba->fc_topology_changed = 1;
3656 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3658 phba->cfg_topology = prev_val;
3663 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3664 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3665 "allowed range is [0, 6]\n",
3670 lpfc_param_show(topology)
3671 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3672 lpfc_topology_show, lpfc_topology_store);
3675 * lpfc_static_vport_show: Read callback function for
3676 * lpfc_static_vport sysfs file.
3677 * @dev: Pointer to class device object.
3678 * @attr: device attribute structure.
3679 * @buf: Data buffer.
3681 * This function is the read call back function for
3682 * lpfc_static_vport sysfs file. The lpfc_static_vport
3683 * sysfs file report the mageability of the vport.
3686 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3689 struct Scsi_Host *shost = class_to_shost(dev);
3690 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3691 if (vport->vport_flag & STATIC_VPORT)
3692 sprintf(buf, "1\n");
3694 sprintf(buf, "0\n");
3700 * Sysfs attribute to control the statistical data collection.
3702 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3703 lpfc_static_vport_show, NULL);
3706 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3707 * @dev: Pointer to class device.
3708 * @buf: Data buffer.
3709 * @count: Size of the data buffer.
3711 * This function get called when a user write to the lpfc_stat_data_ctrl
3712 * sysfs file. This function parse the command written to the sysfs file
3713 * and take appropriate action. These commands are used for controlling
3714 * driver statistical data collection.
3715 * Following are the command this function handles.
3717 * setbucket <bucket_type> <base> <step>
3718 * = Set the latency buckets.
3719 * destroybucket = destroy all the buckets.
3720 * start = start data collection
3721 * stop = stop data collection
3722 * reset = reset the collected data
3725 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3726 const char *buf, size_t count)
3728 struct Scsi_Host *shost = class_to_shost(dev);
3729 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3730 struct lpfc_hba *phba = vport->phba;
3731 #define LPFC_MAX_DATA_CTRL_LEN 1024
3732 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3734 char *str_ptr, *token;
3735 struct lpfc_vport **vports;
3736 struct Scsi_Host *v_shost;
3737 char *bucket_type_str, *base_str, *step_str;
3738 unsigned long base, step, bucket_type;
3740 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3741 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3744 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3745 str_ptr = &bucket_data[0];
3746 /* Ignore this token - this is command token */
3747 token = strsep(&str_ptr, "\t ");
3751 bucket_type_str = strsep(&str_ptr, "\t ");
3752 if (!bucket_type_str)
3755 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3756 bucket_type = LPFC_LINEAR_BUCKET;
3757 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3758 bucket_type = LPFC_POWER2_BUCKET;
3762 base_str = strsep(&str_ptr, "\t ");
3765 base = simple_strtoul(base_str, NULL, 0);
3767 step_str = strsep(&str_ptr, "\t ");
3770 step = simple_strtoul(step_str, NULL, 0);
3774 /* Block the data collection for every vport */
3775 vports = lpfc_create_vport_work_array(phba);
3779 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3780 v_shost = lpfc_shost_from_vport(vports[i]);
3781 spin_lock_irq(v_shost->host_lock);
3782 /* Block and reset data collection */
3783 vports[i]->stat_data_blocked = 1;
3784 if (vports[i]->stat_data_enabled)
3785 lpfc_vport_reset_stat_data(vports[i]);
3786 spin_unlock_irq(v_shost->host_lock);
3789 /* Set the bucket attributes */
3790 phba->bucket_type = bucket_type;
3791 phba->bucket_base = base;
3792 phba->bucket_step = step;
3794 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3795 v_shost = lpfc_shost_from_vport(vports[i]);
3797 /* Unblock data collection */
3798 spin_lock_irq(v_shost->host_lock);
3799 vports[i]->stat_data_blocked = 0;
3800 spin_unlock_irq(v_shost->host_lock);
3802 lpfc_destroy_vport_work_array(phba, vports);
3806 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3807 vports = lpfc_create_vport_work_array(phba);
3811 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3812 v_shost = lpfc_shost_from_vport(vports[i]);
3813 spin_lock_irq(shost->host_lock);
3814 vports[i]->stat_data_blocked = 1;
3815 lpfc_free_bucket(vport);
3816 vport->stat_data_enabled = 0;
3817 vports[i]->stat_data_blocked = 0;
3818 spin_unlock_irq(shost->host_lock);
3820 lpfc_destroy_vport_work_array(phba, vports);
3821 phba->bucket_type = LPFC_NO_BUCKET;
3822 phba->bucket_base = 0;
3823 phba->bucket_step = 0;
3827 if (!strncmp(buf, "start", strlen("start"))) {
3828 /* If no buckets configured return error */
3829 if (phba->bucket_type == LPFC_NO_BUCKET)
3831 spin_lock_irq(shost->host_lock);
3832 if (vport->stat_data_enabled) {
3833 spin_unlock_irq(shost->host_lock);
3836 lpfc_alloc_bucket(vport);
3837 vport->stat_data_enabled = 1;
3838 spin_unlock_irq(shost->host_lock);
3842 if (!strncmp(buf, "stop", strlen("stop"))) {
3843 spin_lock_irq(shost->host_lock);
3844 if (vport->stat_data_enabled == 0) {
3845 spin_unlock_irq(shost->host_lock);
3848 lpfc_free_bucket(vport);
3849 vport->stat_data_enabled = 0;
3850 spin_unlock_irq(shost->host_lock);
3854 if (!strncmp(buf, "reset", strlen("reset"))) {
3855 if ((phba->bucket_type == LPFC_NO_BUCKET)
3856 || !vport->stat_data_enabled)
3858 spin_lock_irq(shost->host_lock);
3859 vport->stat_data_blocked = 1;
3860 lpfc_vport_reset_stat_data(vport);
3861 vport->stat_data_blocked = 0;
3862 spin_unlock_irq(shost->host_lock);
3870 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3871 * @dev: Pointer to class device object.
3872 * @buf: Data buffer.
3874 * This function is the read call back function for
3875 * lpfc_stat_data_ctrl sysfs file. This function report the
3876 * current statistical data collection state.
3879 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3882 struct Scsi_Host *shost = class_to_shost(dev);
3883 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3884 struct lpfc_hba *phba = vport->phba;
3888 unsigned long bucket_value;
3890 switch (phba->bucket_type) {
3891 case LPFC_LINEAR_BUCKET:
3892 bucket_type = "linear";
3894 case LPFC_POWER2_BUCKET:
3895 bucket_type = "power2";
3898 bucket_type = "No Bucket";
3902 sprintf(&buf[index], "Statistical Data enabled :%d, "
3903 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3904 " Bucket step :%d\nLatency Ranges :",
3905 vport->stat_data_enabled, vport->stat_data_blocked,
3906 bucket_type, phba->bucket_base, phba->bucket_step);
3907 index = strlen(buf);
3908 if (phba->bucket_type != LPFC_NO_BUCKET) {
3909 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3910 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3911 bucket_value = phba->bucket_base +
3912 phba->bucket_step * i;
3914 bucket_value = phba->bucket_base +
3915 (1 << i) * phba->bucket_step;
3917 if (index + 10 > PAGE_SIZE)
3919 sprintf(&buf[index], "%08ld ", bucket_value);
3920 index = strlen(buf);
3923 sprintf(&buf[index], "\n");
3928 * Sysfs attribute to control the statistical data collection.
3930 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3931 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3934 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3938 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3941 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3942 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3943 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3947 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3949 * @kobj: Pointer to the kernel object
3950 * @bin_attr: Attribute object
3951 * @buff: Buffer pointer
3953 * @count: Buffer size
3955 * This function is the read call back function for lpfc_drvr_stat_data
3956 * sysfs file. This function export the statistical data to user
3960 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3961 struct bin_attribute *bin_attr,
3962 char *buf, loff_t off, size_t count)
3964 struct device *dev = container_of(kobj, struct device,
3966 struct Scsi_Host *shost = class_to_shost(dev);
3967 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3968 struct lpfc_hba *phba = vport->phba;
3969 int i = 0, index = 0;
3970 unsigned long nport_index;
3971 struct lpfc_nodelist *ndlp = NULL;
3972 nport_index = (unsigned long)off /
3973 MAX_STAT_DATA_SIZE_PER_TARGET;
3975 if (!vport->stat_data_enabled || vport->stat_data_blocked
3976 || (phba->bucket_type == LPFC_NO_BUCKET))
3979 spin_lock_irq(shost->host_lock);
3980 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3981 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3984 if (nport_index > 0) {
3989 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3993 if (!ndlp->lat_data)
3997 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3998 ndlp->nlp_portname.u.wwn[0],
3999 ndlp->nlp_portname.u.wwn[1],
4000 ndlp->nlp_portname.u.wwn[2],
4001 ndlp->nlp_portname.u.wwn[3],
4002 ndlp->nlp_portname.u.wwn[4],
4003 ndlp->nlp_portname.u.wwn[5],
4004 ndlp->nlp_portname.u.wwn[6],
4005 ndlp->nlp_portname.u.wwn[7]);
4007 index = strlen(buf);
4009 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4010 sprintf(&buf[index], "%010u,",
4011 ndlp->lat_data[i].cmd_count);
4012 index = strlen(buf);
4014 sprintf(&buf[index], "\n");
4015 index = strlen(buf);
4017 spin_unlock_irq(shost->host_lock);
4021 static struct bin_attribute sysfs_drvr_stat_data_attr = {
4023 .name = "lpfc_drvr_stat_data",
4026 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4027 .read = sysfs_drvr_stat_data_read,
4032 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4034 # Value range is [0,16]. Default value is 0.
4037 * lpfc_link_speed_set - Set the adapters link speed
4038 * @phba: lpfc_hba pointer.
4039 * @val: link speed value.
4042 * If val is in a valid range then set the adapter's link speed field and
4043 * issue a lip; if the lip fails reset the link speed to the old value.
4046 * If the value is not in range log a kernel error message and return an error.
4049 * zero if val is in range and lip okay.
4050 * non-zero return value from lpfc_issue_lip()
4051 * -EINVAL val out of range
4054 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4055 const char *buf, size_t count)
4057 struct Scsi_Host *shost = class_to_shost(dev);
4058 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4059 struct lpfc_hba *phba = vport->phba;
4060 int val = LPFC_USER_LINK_SPEED_AUTO;
4062 const char *val_buf = buf;
4064 uint32_t prev_val, if_type;
4066 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4067 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4068 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4071 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4073 val_buf = &buf[strlen("nolip ")];
4076 if (!isdigit(val_buf[0]))
4078 if (sscanf(val_buf, "%i", &val) != 1)
4081 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4082 "3055 lpfc_link_speed changed from %d to %d %s\n",
4083 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4085 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4086 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4087 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4088 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4089 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4090 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4091 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
4092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4093 "2879 lpfc_link_speed attribute cannot be set "
4094 "to %d. Speed is not supported by this port.\n",
4098 if (val == LPFC_USER_LINK_SPEED_16G &&
4099 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4100 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4101 "3112 lpfc_link_speed attribute cannot be set "
4102 "to %d. Speed is not supported in loop mode.\n",
4106 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4107 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4108 prev_val = phba->cfg_link_speed;
4109 phba->cfg_link_speed = val;
4113 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4115 phba->cfg_link_speed = prev_val;
4120 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4121 "0469 lpfc_link_speed attribute cannot be set to %d, "
4122 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
4126 static int lpfc_link_speed = 0;
4127 module_param(lpfc_link_speed, int, S_IRUGO);
4128 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4129 lpfc_param_show(link_speed)
4132 * lpfc_link_speed_init - Set the adapters link speed
4133 * @phba: lpfc_hba pointer.
4134 * @val: link speed value.
4137 * If val is in a valid range then set the adapter's link speed field.
4140 * If the value is not in range log a kernel error message, clear the link
4141 * speed and return an error.
4144 * zero if val saved.
4145 * -EINVAL val out of range
4148 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4150 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4152 "3111 lpfc_link_speed of %d cannot "
4153 "support loop mode, setting topology to default.\n",
4155 phba->cfg_topology = 0;
4157 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4158 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4159 phba->cfg_link_speed = val;
4162 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4163 "0405 lpfc_link_speed attribute cannot "
4164 "be set to %d, allowed values are "
4165 "["LPFC_LINK_SPEED_STRING"]\n", val);
4166 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4170 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
4171 lpfc_link_speed_show, lpfc_link_speed_store);
4174 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4175 # 0 = aer disabled or not supported
4176 # 1 = aer supported and enabled (default)
4177 # Value range is [0,1]. Default value is 1.
4179 LPFC_ATTR(aer_support, 1, 0, 1,
4180 "Enable PCIe device AER support");
4181 lpfc_param_show(aer_support)
4184 * lpfc_aer_support_store - Set the adapter for aer support
4186 * @dev: class device that is converted into a Scsi_host.
4187 * @attr: device attribute, not used.
4188 * @buf: containing enable or disable aer flag.
4189 * @count: unused variable.
4192 * If the val is 1 and currently the device's AER capability was not
4193 * enabled, invoke the kernel's enable AER helper routine, trying to
4194 * enable the device's AER capability. If the helper routine enabling
4195 * AER returns success, update the device's cfg_aer_support flag to
4196 * indicate AER is supported by the device; otherwise, if the device
4197 * AER capability is already enabled to support AER, then do nothing.
4199 * If the val is 0 and currently the device's AER support was enabled,
4200 * invoke the kernel's disable AER helper routine. After that, update
4201 * the device's cfg_aer_support flag to indicate AER is not supported
4202 * by the device; otherwise, if the device AER capability is already
4203 * disabled from supporting AER, then do nothing.
4206 * length of the buf on success if val is in range the intended mode
4208 * -EINVAL if val out of range or intended mode is not supported.
4211 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4212 const char *buf, size_t count)
4214 struct Scsi_Host *shost = class_to_shost(dev);
4215 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4216 struct lpfc_hba *phba = vport->phba;
4217 int val = 0, rc = -EINVAL;
4219 if (!isdigit(buf[0]))
4221 if (sscanf(buf, "%i", &val) != 1)
4226 if (phba->hba_flag & HBA_AER_ENABLED) {
4227 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4229 spin_lock_irq(&phba->hbalock);
4230 phba->hba_flag &= ~HBA_AER_ENABLED;
4231 spin_unlock_irq(&phba->hbalock);
4232 phba->cfg_aer_support = 0;
4237 phba->cfg_aer_support = 0;
4242 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4243 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4245 spin_lock_irq(&phba->hbalock);
4246 phba->hba_flag |= HBA_AER_ENABLED;
4247 spin_unlock_irq(&phba->hbalock);
4248 phba->cfg_aer_support = 1;
4253 phba->cfg_aer_support = 1;
4264 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4265 lpfc_aer_support_show, lpfc_aer_support_store);
4268 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4269 * @dev: class device that is converted into a Scsi_host.
4270 * @attr: device attribute, not used.
4271 * @buf: containing flag 1 for aer cleanup state.
4272 * @count: unused variable.
4275 * If the @buf contains 1 and the device currently has the AER support
4276 * enabled, then invokes the kernel AER helper routine
4277 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4278 * error status register.
4283 * -EINVAL if the buf does not contain the 1 or the device is not currently
4284 * enabled with the AER support.
4287 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4288 const char *buf, size_t count)
4290 struct Scsi_Host *shost = class_to_shost(dev);
4291 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4292 struct lpfc_hba *phba = vport->phba;
4295 if (!isdigit(buf[0]))
4297 if (sscanf(buf, "%i", &val) != 1)
4302 if (phba->hba_flag & HBA_AER_ENABLED)
4303 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4311 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4312 lpfc_aer_cleanup_state);
4315 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4317 * @dev: class device that is converted into a Scsi_host.
4318 * @attr: device attribute, not used.
4319 * @buf: containing the string the number of vfs to be enabled.
4320 * @count: unused variable.
4323 * When this api is called either through user sysfs, the driver shall
4324 * try to enable or disable SR-IOV virtual functions according to the
4327 * If zero virtual function has been enabled to the physical function,
4328 * the driver shall invoke the pci enable virtual function api trying
4329 * to enable the virtual functions. If the nr_vfn provided is greater
4330 * than the maximum supported, the maximum virtual function number will
4331 * be used for invoking the api; otherwise, the nr_vfn provided shall
4332 * be used for invoking the api. If the api call returned success, the
4333 * actual number of virtual functions enabled will be set to the driver
4334 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4335 * cfg_sriov_nr_virtfn remains zero.
4337 * If none-zero virtual functions have already been enabled to the
4338 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4339 * -EINVAL will be returned and the driver does nothing;
4341 * If the nr_vfn provided is zero and none-zero virtual functions have
4342 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4343 * disabling virtual function api shall be invoded to disable all the
4344 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4345 * zero. Otherwise, if zero virtual function has been enabled, do
4349 * length of the buf on success if val is in range the intended mode
4351 * -EINVAL if val out of range or intended mode is not supported.
4354 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4355 const char *buf, size_t count)
4357 struct Scsi_Host *shost = class_to_shost(dev);
4358 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4359 struct lpfc_hba *phba = vport->phba;
4360 struct pci_dev *pdev = phba->pcidev;
4361 int val = 0, rc = -EINVAL;
4363 /* Sanity check on user data */
4364 if (!isdigit(buf[0]))
4366 if (sscanf(buf, "%i", &val) != 1)
4371 /* Request disabling virtual functions */
4373 if (phba->cfg_sriov_nr_virtfn > 0) {
4374 pci_disable_sriov(pdev);
4375 phba->cfg_sriov_nr_virtfn = 0;
4380 /* Request enabling virtual functions */
4381 if (phba->cfg_sriov_nr_virtfn > 0) {
4382 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4383 "3018 There are %d virtual functions "
4384 "enabled on physical function.\n",
4385 phba->cfg_sriov_nr_virtfn);
4389 if (val <= LPFC_MAX_VFN_PER_PFN)
4390 phba->cfg_sriov_nr_virtfn = val;
4392 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4393 "3019 Enabling %d virtual functions is not "
4398 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4400 phba->cfg_sriov_nr_virtfn = 0;
4408 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4409 "Enable PCIe device SR-IOV virtual fn");
4411 lpfc_param_show(sriov_nr_virtfn)
4412 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4413 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4416 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4418 * @dev: class device that is converted into a Scsi_host.
4419 * @attr: device attribute, not used.
4420 * @buf: containing the string the number of vfs to be enabled.
4421 * @count: unused variable.
4426 * length of the buf on success if val is in range the intended mode
4428 * -EINVAL if val out of range or intended mode is not supported.
4431 lpfc_request_firmware_upgrade_store(struct device *dev,
4432 struct device_attribute *attr,
4433 const char *buf, size_t count)
4435 struct Scsi_Host *shost = class_to_shost(dev);
4436 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4437 struct lpfc_hba *phba = vport->phba;
4438 int val = 0, rc = -EINVAL;
4440 /* Sanity check on user data */
4441 if (!isdigit(buf[0]))
4443 if (sscanf(buf, "%i", &val) != 1)
4448 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4456 static int lpfc_req_fw_upgrade;
4457 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4458 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4459 lpfc_param_show(request_firmware_upgrade)
4462 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4463 * @phba: lpfc_hba pointer.
4467 * Set the initial Linux generic firmware upgrade enable or disable flag.
4470 * zero if val saved.
4471 * -EINVAL val out of range
4474 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4476 if (val >= 0 && val <= 1) {
4477 phba->cfg_request_firmware_upgrade = val;
4482 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4483 lpfc_request_firmware_upgrade_show,
4484 lpfc_request_firmware_upgrade_store);
4487 * lpfc_fcp_imax_store
4489 * @dev: class device that is converted into a Scsi_host.
4490 * @attr: device attribute, not used.
4491 * @buf: string with the number of fast-path FCP interrupts per second.
4492 * @count: unused variable.
4495 * If val is in a valid range [636,651042], then set the adapter's
4496 * maximum number of fast-path FCP interrupts per second.
4499 * length of the buf on success if val is in range the intended mode
4501 * -EINVAL if val out of range or intended mode is not supported.
4504 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4505 const char *buf, size_t count)
4507 struct Scsi_Host *shost = class_to_shost(dev);
4508 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4509 struct lpfc_hba *phba = vport->phba;
4512 /* fcp_imax is only valid for SLI4 */
4513 if (phba->sli_rev != LPFC_SLI_REV4)
4516 /* Sanity check on user data */
4517 if (!isdigit(buf[0]))
4519 if (sscanf(buf, "%i", &val) != 1)
4523 * Value range for the HBA is [5000,5000000]
4524 * The value for each EQ depends on how many EQs are configured.
4527 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4530 phba->cfg_fcp_imax = (uint32_t)val;
4531 phba->initial_imax = phba->cfg_fcp_imax;
4533 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4534 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4541 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4544 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4546 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4547 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4548 MODULE_PARM_DESC(lpfc_fcp_imax,
4549 "Set the maximum number of FCP interrupts per second per HBA");
4550 lpfc_param_show(fcp_imax)
4553 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4554 * @phba: lpfc_hba pointer.
4555 * @val: link speed value.
4558 * If val is in a valid range [636,651042], then initialize the adapter's
4559 * maximum number of fast-path FCP interrupts per second.
4562 * zero if val saved.
4563 * -EINVAL val out of range
4566 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4568 if (phba->sli_rev != LPFC_SLI_REV4) {
4569 phba->cfg_fcp_imax = 0;
4573 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4575 phba->cfg_fcp_imax = val;
4579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4580 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4582 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4587 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4588 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4591 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4592 * 0 No auto_imax support
4594 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4595 * the EQ Delay Multiplier, depending on the activity for that EQ.
4596 * Value range [0,1]. Default value is 1.
4598 LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4601 * lpfc_state_show - Display current driver CPU affinity
4602 * @dev: class converted to a Scsi_host structure.
4603 * @attr: device attribute, not used.
4604 * @buf: on return contains text describing the state of the link.
4606 * Returns: size of formatted string.
4609 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4612 struct Scsi_Host *shost = class_to_shost(dev);
4613 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4614 struct lpfc_hba *phba = vport->phba;
4615 struct lpfc_vector_map_info *cpup;
4618 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4619 (phba->intr_type != MSIX))
4622 switch (phba->cfg_fcp_cpu_map) {
4624 len += snprintf(buf + len, PAGE_SIZE-len,
4625 "fcp_cpu_map: No mapping (%d)\n",
4626 phba->cfg_fcp_cpu_map);
4629 len += snprintf(buf + len, PAGE_SIZE-len,
4630 "fcp_cpu_map: HBA centric mapping (%d): "
4632 phba->cfg_fcp_cpu_map,
4633 phba->sli4_hba.num_online_cpu);
4636 len += snprintf(buf + len, PAGE_SIZE-len,
4637 "fcp_cpu_map: Driver centric mapping (%d): "
4639 phba->cfg_fcp_cpu_map,
4640 phba->sli4_hba.num_online_cpu);
4644 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4645 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4647 /* margin should fit in this and the truncated message */
4648 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4649 len += snprintf(buf + len, PAGE_SIZE-len,
4650 "CPU %02d io_chan %02d "
4651 "physid %d coreid %d\n",
4652 phba->sli4_hba.curr_disp_cpu,
4653 cpup->channel_id, cpup->phys_id,
4656 len += snprintf(buf + len, PAGE_SIZE-len,
4657 "CPU %02d io_chan %02d "
4658 "physid %d coreid %d IRQ %d\n",
4659 phba->sli4_hba.curr_disp_cpu,
4660 cpup->channel_id, cpup->phys_id,
4661 cpup->core_id, cpup->irq);
4663 phba->sli4_hba.curr_disp_cpu++;
4665 /* display max number of CPUs keeping some margin */
4666 if (phba->sli4_hba.curr_disp_cpu <
4667 phba->sli4_hba.num_present_cpu &&
4668 (len >= (PAGE_SIZE - 64))) {
4669 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4674 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4675 phba->sli4_hba.curr_disp_cpu = 0;
4681 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4682 * @dev: class device that is converted into a Scsi_host.
4683 * @attr: device attribute, not used.
4684 * @buf: one or more lpfc_polling_flags values.
4688 * -EINVAL - Not implemented yet.
4691 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4692 const char *buf, size_t count)
4694 int status = -EINVAL;
4699 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4702 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4703 # 0 - Do not affinitze IRQ vectors
4704 # 1 - Affintize HBA vectors with respect to each HBA
4705 # (start with CPU0 for each HBA)
4706 # 2 - Affintize HBA vectors with respect to the entire driver
4707 # (round robin thru all CPUs across all HBAs)
4709 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4710 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4711 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4712 "Defines how to map CPUs to IRQ vectors per HBA");
4715 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4716 * @phba: lpfc_hba pointer.
4717 * @val: link speed value.
4720 * If val is in a valid range [0-2], then affinitze the adapter's
4724 * zero if val saved.
4725 * -EINVAL val out of range
4728 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4730 if (phba->sli_rev != LPFC_SLI_REV4) {
4731 phba->cfg_fcp_cpu_map = 0;
4735 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4736 phba->cfg_fcp_cpu_map = val;
4740 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4741 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4743 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4748 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4749 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4752 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4753 # Value range is [2,3]. Default value is 3.
4755 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4756 "Select Fibre Channel class of service for FCP sequences");
4759 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4760 # is [0,1]. Default value is 0.
4762 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4763 "Use ADISC on rediscovery to authenticate FCP devices");
4766 # lpfc_first_burst_size: First burst size to use on the NPorts
4767 # that support first burst.
4768 # Value range is [0,65536]. Default value is 0.
4770 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4771 "First burst size for Targets that support first burst");
4774 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4775 * When the driver is configured as an NVME target, this value is
4776 * communicated to the NVME initiator in the PRLI response. It is
4777 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4778 * parameters are set and the target is sending the PRLI RSP.
4779 * Parameter supported on physical port only - no NPIV support.
4780 * Value range is [0,65536]. Default value is 0.
4782 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4783 "NVME Target mode first burst size in 512B increments.");
4786 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4787 * For the Initiator (I), enabling this parameter means that an NVMET
4788 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4789 * processed by the initiator for subsequent NVME FCP IO. For the target
4790 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4791 * driver parameter as the target function's first burst size returned to the
4792 * initiator in the target's NVME PRLI response. Parameter supported on physical
4793 * port only - no NPIV support.
4794 * Value range is [0,1]. Default value is 0 (disabled).
4796 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4797 "Enable First Burst feature on I and T functions.");
4800 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4801 # depth. Default value is 0. When the value of this parameter is zero the
4802 # SCSI command completion time is not used for controlling I/O queue depth. When
4803 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4804 # to limit the I/O completion time to the parameter value.
4805 # The value is set in milliseconds.
4807 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4808 "Use command completion time to control queue depth");
4810 lpfc_vport_param_show(max_scsicmpl_time);
4812 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4814 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4815 struct lpfc_nodelist *ndlp, *next_ndlp;
4817 if (val == vport->cfg_max_scsicmpl_time)
4819 if ((val < 0) || (val > 60000))
4821 vport->cfg_max_scsicmpl_time = val;
4823 spin_lock_irq(shost->host_lock);
4824 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4825 if (!NLP_CHK_NODE_ACT(ndlp))
4827 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4829 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4831 spin_unlock_irq(shost->host_lock);
4834 lpfc_vport_param_store(max_scsicmpl_time);
4835 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4836 lpfc_max_scsicmpl_time_show,
4837 lpfc_max_scsicmpl_time_store);
4840 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4841 # range is [0,1]. Default value is 0.
4843 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4846 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4847 * range is [0,1]. Default value is 0.
4848 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4849 * For [1], FCP commands are issued to a Work Queue associated with the
4852 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4853 * LPFC_FCP_SCHED_BY_CPU == 1
4855 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4856 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4857 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4858 * through WQs will be used.
4860 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4861 LPFC_FCP_SCHED_ROUND_ROBIN,
4862 LPFC_FCP_SCHED_BY_CPU,
4863 "Determine scheduling algorithm for "
4864 "issuing commands [0] - Round Robin, [1] - Current CPU");
4867 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4868 # range is [0,1]. Default value is 0.
4869 # For [0], bus reset issues target reset to ALL devices
4870 # For [1], bus reset issues target reset to non-FCP2 devices
4872 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4873 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4877 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4878 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4879 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4880 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4881 # cr_delay is set to 0.
4883 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4884 "interrupt response is generated");
4886 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4887 "interrupt response is generated");
4890 # lpfc_multi_ring_support: Determines how many rings to spread available
4891 # cmd/rsp IOCB entries across.
4892 # Value range is [1,2]. Default value is 1.
4894 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4895 "SLI rings to spread IOCB entries across");
4898 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4899 # identifies what rctl value to configure the additional ring for.
4900 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4902 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4903 255, "Identifies RCTL for additional ring configuration");
4906 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4907 # identifies what type value to configure the additional ring for.
4908 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4910 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4911 255, "Identifies TYPE for additional ring configuration");
4914 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4915 # 0 = SmartSAN functionality disabled (default)
4916 # 1 = SmartSAN functionality enabled
4917 # This parameter will override the value of lpfc_fdmi_on module parameter.
4918 # Value range is [0,1]. Default value is 0.
4920 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4923 # lpfc_fdmi_on: Controls FDMI support.
4924 # 0 No FDMI support (default)
4925 # 1 Traditional FDMI support
4926 # Traditional FDMI support means the driver will assume FDMI-2 support;
4927 # however, if that fails, it will fallback to FDMI-1.
4928 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4929 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4931 # Value range [0,1]. Default value is 0.
4933 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4936 # Specifies the maximum number of ELS cmds we can have outstanding (for
4937 # discovery). Value range is [1,64]. Default value = 32.
4939 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4940 "during discovery");
4943 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4944 # will be scanned by the SCSI midlayer when sequential scanning is
4945 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4946 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4947 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4948 # above. The lpfc driver limits the default value to 255 for two reasons.
4949 # As it bounds the sequential scan loop, scanning for thousands of luns
4950 # on a target can take minutes of wall clock time. Additionally,
4951 # there are FC targets, such as JBODs, that only recognize 8-bits of
4952 # LUN ID. When they receive a value greater than 8 bits, they chop off
4953 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4954 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4955 # valid responses at each of the LUN IDs, to believe there are multiple
4956 # devices present, when in fact, there is only 1.
4957 # A customer that is aware of their target behaviors, and the results as
4958 # indicated above, is welcome to increase the lpfc_max_luns value.
4959 # As mentioned, this value is not used by the lpfc driver, only the
4961 # Value range is [0,65535]. Default value is 255.
4962 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4964 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4967 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4968 # Value range is [1,255], default value is 10.
4970 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4971 "Milliseconds driver will wait between polling FCP ring");
4974 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4975 # to complete in seconds. Value range is [5,180], default value is 60.
4977 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4978 "Maximum time to wait for task management commands to complete");
4980 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4981 # support this feature
4984 # 2 = MSI-X enabled (default)
4985 # Value range is [0,2]. Default value is 2.
4987 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4988 "MSI-X (2), if possible");
4991 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4993 * 0 = NVME OAS disabled
4994 * 1 = NVME OAS enabled
4996 * Value range is [0,1]. Default value is 0.
4998 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4999 "Use OAS bit on NVME IOs");
5002 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
5003 * will advertise it supports to the SCSI layer. This also will map to
5004 * the number of WQs the driver will create.
5006 * 0 = Configure the number of io channels to the number of active CPUs.
5007 * 1,32 = Manually specify how many io channels to use.
5009 * Value range is [0,32]. Default value is 4.
5011 LPFC_ATTR_R(fcp_io_channel,
5012 LPFC_FCP_IO_CHAN_DEF,
5013 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5014 "Set the number of FCP I/O channels");
5017 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
5018 * will advertise it supports to the NVME layer. This also will map to
5019 * the number of WQs the driver will create.
5021 * This module parameter is valid when lpfc_enable_fc4_type is set
5024 * The NVME Layer will try to create this many, plus 1 administrative
5025 * hardware queue. The administrative queue will always map to WQ 0
5026 * A hardware IO queue maps (qidx) to a specific driver WQ.
5028 * 0 = Configure the number of io channels to the number of active CPUs.
5029 * 1,32 = Manually specify how many io channels to use.
5031 * Value range is [0,32]. Default value is 0.
5033 LPFC_ATTR_R(nvme_io_channel,
5034 LPFC_NVME_IO_CHAN_DEF,
5035 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5036 "Set the number of NVME I/O channels");
5039 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5040 # 0 = HBA resets disabled
5041 # 1 = HBA resets enabled (default)
5042 # Value range is [0,1]. Default value is 1.
5044 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
5047 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5048 # 0 = HBA Heartbeat disabled
5049 # 1 = HBA Heartbeat enabled (default)
5050 # Value range is [0,1]. Default value is 1.
5052 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5055 # lpfc_EnableXLane: Enable Express Lane Feature
5056 # 0x0 Express Lane Feature disabled
5057 # 0x1 Express Lane Feature enabled
5058 # Value range is [0,1]. Default value is 0.
5060 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5063 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5064 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5065 # Value range is [0x0,0x7f]. Default value is 0
5067 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5070 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5071 # 0 = BlockGuard disabled (default)
5072 # 1 = BlockGuard enabled
5073 # Value range is [0,1]. Default value is 0.
5075 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5078 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5079 # 0 = disabled (default)
5081 # Value range is [0,1]. Default value is 0.
5083 # This feature in under investigation and may be supported in the future.
5085 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5089 # - Bit mask of host protection capabilities used to register with the
5091 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5092 # - Allows you to ultimately specify which profiles to use
5093 # - Default will result in registering capabilities for all profiles.
5094 # - SHOST_DIF_TYPE1_PROTECTION 1
5095 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5096 # - SHOST_DIX_TYPE0_PROTECTION 8
5097 # HBA supports DIX Type 0: Host to HBA protection only
5098 # - SHOST_DIX_TYPE1_PROTECTION 16
5099 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5102 LPFC_ATTR(prot_mask,
5103 (SHOST_DIF_TYPE1_PROTECTION |
5104 SHOST_DIX_TYPE0_PROTECTION |
5105 SHOST_DIX_TYPE1_PROTECTION),
5107 (SHOST_DIF_TYPE1_PROTECTION |
5108 SHOST_DIX_TYPE0_PROTECTION |
5109 SHOST_DIX_TYPE1_PROTECTION),
5110 "T10-DIF host protection capabilities mask");
5113 # lpfc_prot_guard: i
5114 # - Bit mask of protection guard types to register with the SCSI mid-layer
5115 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5116 # - Allows you to ultimately specify which profiles to use
5117 # - Default will result in registering capabilities for all guard types
5120 LPFC_ATTR(prot_guard,
5121 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5122 "T10-DIF host protection guard type");
5125 * Delay initial NPort discovery when Clean Address bit is cleared in
5126 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5127 * This parameter can have value 0 or 1.
5128 * When this parameter is set to 0, no delay is added to the initial
5130 * When this parameter is set to non-zero value, initial Nport discovery is
5131 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5132 * accept and FCID/Fabric name/Fabric portname is changed.
5133 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5134 * when Clean Address bit is cleared in FLOGI/FDISC
5135 * accept and FCID/Fabric name/Fabric portname is changed.
5136 * Default value is 0.
5138 LPFC_ATTR(delay_discovery, 0, 0, 1,
5139 "Delay NPort discovery when Clean Address bit is cleared.");
5142 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5143 * This value can be set to values between 64 and 4096. The default value is
5144 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5145 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5146 * Because of the additional overhead involved in setting up T10-DIF,
5147 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5148 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5150 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5151 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5154 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5155 * 0 = MDS Diagnostics disabled (default)
5156 * 1 = MDS Diagnostics enabled
5157 * Value range is [0,1]. Default value is 0.
5159 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5162 * lpfc_enable_bbcr: Enable BB Credit Recovery
5163 * 0 = BB Credit Recovery disabled
5164 * 1 = BB Credit Recovery enabled (default)
5165 * Value range is [0,1]. Default value is 1.
5167 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5169 struct device_attribute *lpfc_hba_attrs[] = {
5170 &dev_attr_nvme_info,
5172 &dev_attr_bg_guard_err,
5173 &dev_attr_bg_apptag_err,
5174 &dev_attr_bg_reftag_err,
5176 &dev_attr_serialnum,
5177 &dev_attr_modeldesc,
5178 &dev_attr_modelname,
5179 &dev_attr_programtype,
5183 &dev_attr_option_rom_version,
5184 &dev_attr_link_state,
5185 &dev_attr_num_discovered_ports,
5186 &dev_attr_menlo_mgmt_mode,
5187 &dev_attr_lpfc_drvr_version,
5188 &dev_attr_lpfc_enable_fip,
5189 &dev_attr_lpfc_temp_sensor,
5190 &dev_attr_lpfc_log_verbose,
5191 &dev_attr_lpfc_lun_queue_depth,
5192 &dev_attr_lpfc_tgt_queue_depth,
5193 &dev_attr_lpfc_hba_queue_depth,
5194 &dev_attr_lpfc_peer_port_login,
5195 &dev_attr_lpfc_nodev_tmo,
5196 &dev_attr_lpfc_devloss_tmo,
5197 &dev_attr_lpfc_enable_fc4_type,
5198 &dev_attr_lpfc_xri_split,
5199 &dev_attr_lpfc_fcp_class,
5200 &dev_attr_lpfc_use_adisc,
5201 &dev_attr_lpfc_first_burst_size,
5202 &dev_attr_lpfc_ack0,
5203 &dev_attr_lpfc_topology,
5204 &dev_attr_lpfc_scan_down,
5205 &dev_attr_lpfc_link_speed,
5206 &dev_attr_lpfc_fcp_io_sched,
5207 &dev_attr_lpfc_fcp2_no_tgt_reset,
5208 &dev_attr_lpfc_cr_delay,
5209 &dev_attr_lpfc_cr_count,
5210 &dev_attr_lpfc_multi_ring_support,
5211 &dev_attr_lpfc_multi_ring_rctl,
5212 &dev_attr_lpfc_multi_ring_type,
5213 &dev_attr_lpfc_fdmi_on,
5214 &dev_attr_lpfc_enable_SmartSAN,
5215 &dev_attr_lpfc_max_luns,
5216 &dev_attr_lpfc_enable_npiv,
5217 &dev_attr_lpfc_fcf_failover_policy,
5218 &dev_attr_lpfc_enable_rrq,
5219 &dev_attr_nport_evt_cnt,
5220 &dev_attr_board_mode,
5227 &dev_attr_npiv_info,
5228 &dev_attr_issue_reset,
5229 &dev_attr_lpfc_poll,
5230 &dev_attr_lpfc_poll_tmo,
5231 &dev_attr_lpfc_task_mgmt_tmo,
5232 &dev_attr_lpfc_use_msi,
5233 &dev_attr_lpfc_nvme_oas,
5234 &dev_attr_lpfc_auto_imax,
5235 &dev_attr_lpfc_fcp_imax,
5236 &dev_attr_lpfc_fcp_cpu_map,
5237 &dev_attr_lpfc_fcp_io_channel,
5238 &dev_attr_lpfc_suppress_rsp,
5239 &dev_attr_lpfc_nvme_io_channel,
5240 &dev_attr_lpfc_nvmet_mrq,
5241 &dev_attr_lpfc_nvme_enable_fb,
5242 &dev_attr_lpfc_nvmet_fb_size,
5243 &dev_attr_lpfc_enable_bg,
5244 &dev_attr_lpfc_soft_wwnn,
5245 &dev_attr_lpfc_soft_wwpn,
5246 &dev_attr_lpfc_soft_wwn_enable,
5247 &dev_attr_lpfc_enable_hba_reset,
5248 &dev_attr_lpfc_enable_hba_heartbeat,
5249 &dev_attr_lpfc_EnableXLane,
5250 &dev_attr_lpfc_XLanePriority,
5251 &dev_attr_lpfc_xlane_lun,
5252 &dev_attr_lpfc_xlane_tgt,
5253 &dev_attr_lpfc_xlane_vpt,
5254 &dev_attr_lpfc_xlane_lun_state,
5255 &dev_attr_lpfc_xlane_lun_status,
5256 &dev_attr_lpfc_xlane_priority,
5257 &dev_attr_lpfc_sg_seg_cnt,
5258 &dev_attr_lpfc_max_scsicmpl_time,
5259 &dev_attr_lpfc_stat_data_ctrl,
5260 &dev_attr_lpfc_aer_support,
5261 &dev_attr_lpfc_aer_state_cleanup,
5262 &dev_attr_lpfc_sriov_nr_virtfn,
5263 &dev_attr_lpfc_req_fw_upgrade,
5264 &dev_attr_lpfc_suppress_link_up,
5265 &dev_attr_lpfc_iocb_cnt,
5268 &dev_attr_txcmplq_hw,
5269 &dev_attr_lpfc_fips_level,
5270 &dev_attr_lpfc_fips_rev,
5272 &dev_attr_lpfc_sriov_hw_max_virtfn,
5274 &dev_attr_lpfc_xlane_supported,
5275 &dev_attr_lpfc_enable_mds_diags,
5276 &dev_attr_lpfc_enable_bbcr,
5280 struct device_attribute *lpfc_vport_attrs[] = {
5282 &dev_attr_link_state,
5283 &dev_attr_num_discovered_ports,
5284 &dev_attr_lpfc_drvr_version,
5285 &dev_attr_lpfc_log_verbose,
5286 &dev_attr_lpfc_lun_queue_depth,
5287 &dev_attr_lpfc_tgt_queue_depth,
5288 &dev_attr_lpfc_nodev_tmo,
5289 &dev_attr_lpfc_devloss_tmo,
5290 &dev_attr_lpfc_hba_queue_depth,
5291 &dev_attr_lpfc_peer_port_login,
5292 &dev_attr_lpfc_restrict_login,
5293 &dev_attr_lpfc_fcp_class,
5294 &dev_attr_lpfc_use_adisc,
5295 &dev_attr_lpfc_first_burst_size,
5296 &dev_attr_lpfc_max_luns,
5297 &dev_attr_nport_evt_cnt,
5298 &dev_attr_npiv_info,
5299 &dev_attr_lpfc_enable_da_id,
5300 &dev_attr_lpfc_max_scsicmpl_time,
5301 &dev_attr_lpfc_stat_data_ctrl,
5302 &dev_attr_lpfc_static_vport,
5303 &dev_attr_lpfc_fips_level,
5304 &dev_attr_lpfc_fips_rev,
5309 * sysfs_ctlreg_write - Write method for writing to ctlreg
5310 * @filp: open sysfs file
5311 * @kobj: kernel kobject that contains the kernel class device.
5312 * @bin_attr: kernel attributes passed to us.
5313 * @buf: contains the data to be written to the adapter IOREG space.
5314 * @off: offset into buffer to beginning of data.
5315 * @count: bytes to transfer.
5318 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5319 * Uses the adapter io control registers to send buf contents to the adapter.
5322 * -ERANGE off and count combo out of range
5323 * -EINVAL off, count or buff address invalid
5324 * -EPERM adapter is offline
5325 * value of count, buf contents written
5328 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5329 struct bin_attribute *bin_attr,
5330 char *buf, loff_t off, size_t count)
5333 struct device *dev = container_of(kobj, struct device, kobj);
5334 struct Scsi_Host *shost = class_to_shost(dev);
5335 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5336 struct lpfc_hba *phba = vport->phba;
5338 if (phba->sli_rev >= LPFC_SLI_REV4)
5341 if ((off + count) > FF_REG_AREA_SIZE)
5344 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5347 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5350 /* This is to protect HBA registers from accidental writes. */
5351 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5354 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5357 spin_lock_irq(&phba->hbalock);
5358 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5359 buf_off += sizeof(uint32_t))
5360 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5361 phba->ctrl_regs_memmap_p + off + buf_off);
5363 spin_unlock_irq(&phba->hbalock);
5369 * sysfs_ctlreg_read - Read method for reading from ctlreg
5370 * @filp: open sysfs file
5371 * @kobj: kernel kobject that contains the kernel class device.
5372 * @bin_attr: kernel attributes passed to us.
5373 * @buf: if successful contains the data from the adapter IOREG space.
5374 * @off: offset into buffer to beginning of data.
5375 * @count: bytes to transfer.
5378 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5379 * Uses the adapter io control registers to read data into buf.
5382 * -ERANGE off and count combo out of range
5383 * -EINVAL off, count or buff address invalid
5384 * value of count, buf contents read
5387 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5388 struct bin_attribute *bin_attr,
5389 char *buf, loff_t off, size_t count)
5393 struct device *dev = container_of(kobj, struct device, kobj);
5394 struct Scsi_Host *shost = class_to_shost(dev);
5395 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5396 struct lpfc_hba *phba = vport->phba;
5398 if (phba->sli_rev >= LPFC_SLI_REV4)
5401 if (off > FF_REG_AREA_SIZE)
5404 if ((off + count) > FF_REG_AREA_SIZE)
5405 count = FF_REG_AREA_SIZE - off;
5407 if (count == 0) return 0;
5409 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5412 spin_lock_irq(&phba->hbalock);
5414 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5415 tmp_ptr = (uint32_t *)(buf + buf_off);
5416 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5419 spin_unlock_irq(&phba->hbalock);
5424 static struct bin_attribute sysfs_ctlreg_attr = {
5427 .mode = S_IRUSR | S_IWUSR,
5430 .read = sysfs_ctlreg_read,
5431 .write = sysfs_ctlreg_write,
5435 * sysfs_mbox_write - Write method for writing information via mbox
5436 * @filp: open sysfs file
5437 * @kobj: kernel kobject that contains the kernel class device.
5438 * @bin_attr: kernel attributes passed to us.
5439 * @buf: contains the data to be written to sysfs mbox.
5440 * @off: offset into buffer to beginning of data.
5441 * @count: bytes to transfer.
5444 * Deprecated function. All mailbox access from user space is performed via the
5448 * -EPERM operation not permitted
5451 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5452 struct bin_attribute *bin_attr,
5453 char *buf, loff_t off, size_t count)
5459 * sysfs_mbox_read - Read method for reading information via mbox
5460 * @filp: open sysfs file
5461 * @kobj: kernel kobject that contains the kernel class device.
5462 * @bin_attr: kernel attributes passed to us.
5463 * @buf: contains the data to be read from sysfs mbox.
5464 * @off: offset into buffer to beginning of data.
5465 * @count: bytes to transfer.
5468 * Deprecated function. All mailbox access from user space is performed via the
5472 * -EPERM operation not permitted
5475 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5476 struct bin_attribute *bin_attr,
5477 char *buf, loff_t off, size_t count)
5482 static struct bin_attribute sysfs_mbox_attr = {
5485 .mode = S_IRUSR | S_IWUSR,
5487 .size = MAILBOX_SYSFS_MAX,
5488 .read = sysfs_mbox_read,
5489 .write = sysfs_mbox_write,
5493 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5494 * @vport: address of lpfc vport structure.
5498 * error return code from sysfs_create_bin_file()
5501 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5506 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5507 &sysfs_drvr_stat_data_attr);
5509 /* Virtual ports do not need ctrl_reg and mbox */
5510 if (error || vport->port_type == LPFC_NPIV_PORT)
5513 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5514 &sysfs_ctlreg_attr);
5516 goto out_remove_stat_attr;
5518 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5521 goto out_remove_ctlreg_attr;
5524 out_remove_ctlreg_attr:
5525 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5526 out_remove_stat_attr:
5527 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5528 &sysfs_drvr_stat_data_attr);
5534 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5535 * @vport: address of lpfc vport structure.
5538 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5540 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5541 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5542 &sysfs_drvr_stat_data_attr);
5543 /* Virtual ports do not need ctrl_reg and mbox */
5544 if (vport->port_type == LPFC_NPIV_PORT)
5546 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5547 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5551 * Dynamic FC Host Attributes Support
5555 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5556 * @shost: kernel scsi host pointer.
5559 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5561 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5563 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5564 sizeof fc_host_symbolic_name(shost));
5568 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5569 * @shost: kernel scsi host pointer.
5572 lpfc_get_host_port_id(struct Scsi_Host *shost)
5574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5576 /* note: fc_myDID already in cpu endianness */
5577 fc_host_port_id(shost) = vport->fc_myDID;
5581 * lpfc_get_host_port_type - Set the value of the scsi host port type
5582 * @shost: kernel scsi host pointer.
5585 lpfc_get_host_port_type(struct Scsi_Host *shost)
5587 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5588 struct lpfc_hba *phba = vport->phba;
5590 spin_lock_irq(shost->host_lock);
5592 if (vport->port_type == LPFC_NPIV_PORT) {
5593 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5594 } else if (lpfc_is_link_up(phba)) {
5595 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5596 if (vport->fc_flag & FC_PUBLIC_LOOP)
5597 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5599 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5601 if (vport->fc_flag & FC_FABRIC)
5602 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5604 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5607 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5609 spin_unlock_irq(shost->host_lock);
5613 * lpfc_get_host_port_state - Set the value of the scsi host port state
5614 * @shost: kernel scsi host pointer.
5617 lpfc_get_host_port_state(struct Scsi_Host *shost)
5619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5620 struct lpfc_hba *phba = vport->phba;
5622 spin_lock_irq(shost->host_lock);
5624 if (vport->fc_flag & FC_OFFLINE_MODE)
5625 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5627 switch (phba->link_state) {
5628 case LPFC_LINK_UNKNOWN:
5629 case LPFC_LINK_DOWN:
5630 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5634 case LPFC_HBA_READY:
5635 /* Links up, reports port state accordingly */
5636 if (vport->port_state < LPFC_VPORT_READY)
5637 fc_host_port_state(shost) =
5638 FC_PORTSTATE_BYPASSED;
5640 fc_host_port_state(shost) =
5641 FC_PORTSTATE_ONLINE;
5643 case LPFC_HBA_ERROR:
5644 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5647 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5652 spin_unlock_irq(shost->host_lock);
5656 * lpfc_get_host_speed - Set the value of the scsi host speed
5657 * @shost: kernel scsi host pointer.
5660 lpfc_get_host_speed(struct Scsi_Host *shost)
5662 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5663 struct lpfc_hba *phba = vport->phba;
5665 spin_lock_irq(shost->host_lock);
5667 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5668 switch(phba->fc_linkspeed) {
5669 case LPFC_LINK_SPEED_1GHZ:
5670 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5672 case LPFC_LINK_SPEED_2GHZ:
5673 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5675 case LPFC_LINK_SPEED_4GHZ:
5676 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5678 case LPFC_LINK_SPEED_8GHZ:
5679 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5681 case LPFC_LINK_SPEED_10GHZ:
5682 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5684 case LPFC_LINK_SPEED_16GHZ:
5685 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5687 case LPFC_LINK_SPEED_32GHZ:
5688 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5691 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5695 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5697 spin_unlock_irq(shost->host_lock);
5701 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5702 * @shost: kernel scsi host pointer.
5705 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5707 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5708 struct lpfc_hba *phba = vport->phba;
5711 spin_lock_irq(shost->host_lock);
5713 if ((vport->port_state > LPFC_FLOGI) &&
5714 ((vport->fc_flag & FC_FABRIC) ||
5715 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5716 (vport->fc_flag & FC_PUBLIC_LOOP))))
5717 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5719 /* fabric is local port if there is no F/FL_Port */
5722 spin_unlock_irq(shost->host_lock);
5724 fc_host_fabric_name(shost) = node_name;
5728 * lpfc_get_stats - Return statistical information about the adapter
5729 * @shost: kernel scsi host pointer.
5732 * NULL on error for link down, no mbox pool, sli2 active,
5733 * management not allowed, memory allocation error, or mbox error.
5737 * address of the adapter host statistics
5739 static struct fc_host_statistics *
5740 lpfc_get_stats(struct Scsi_Host *shost)
5742 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5743 struct lpfc_hba *phba = vport->phba;
5744 struct lpfc_sli *psli = &phba->sli;
5745 struct fc_host_statistics *hs = &phba->link_stats;
5746 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5747 LPFC_MBOXQ_t *pmboxq;
5749 unsigned long seconds;
5753 * prevent udev from issuing mailbox commands until the port is
5756 if (phba->link_state < LPFC_LINK_DOWN ||
5757 !phba->mbox_mem_pool ||
5758 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5761 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5764 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5767 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5769 pmb = &pmboxq->u.mb;
5770 pmb->mbxCommand = MBX_READ_STATUS;
5771 pmb->mbxOwner = OWN_HOST;
5772 pmboxq->context1 = NULL;
5773 pmboxq->vport = vport;
5775 if (vport->fc_flag & FC_OFFLINE_MODE)
5776 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5778 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5780 if (rc != MBX_SUCCESS) {
5781 if (rc != MBX_TIMEOUT)
5782 mempool_free(pmboxq, phba->mbox_mem_pool);
5786 memset(hs, 0, sizeof (struct fc_host_statistics));
5788 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5790 * The MBX_READ_STATUS returns tx_k_bytes which has to
5791 * converted to words
5793 hs->tx_words = (uint64_t)
5794 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5796 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5797 hs->rx_words = (uint64_t)
5798 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5801 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5802 pmb->mbxCommand = MBX_READ_LNK_STAT;
5803 pmb->mbxOwner = OWN_HOST;
5804 pmboxq->context1 = NULL;
5805 pmboxq->vport = vport;
5807 if (vport->fc_flag & FC_OFFLINE_MODE)
5808 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5810 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5812 if (rc != MBX_SUCCESS) {
5813 if (rc != MBX_TIMEOUT)
5814 mempool_free(pmboxq, phba->mbox_mem_pool);
5818 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5819 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5820 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5821 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5822 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5823 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5824 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5826 hs->link_failure_count -= lso->link_failure_count;
5827 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5828 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5829 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5830 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5831 hs->invalid_crc_count -= lso->invalid_crc_count;
5832 hs->error_frames -= lso->error_frames;
5834 if (phba->hba_flag & HBA_FCOE_MODE) {
5836 hs->nos_count = (phba->link_events >> 1);
5837 hs->nos_count -= lso->link_events;
5838 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5839 hs->lip_count = (phba->fc_eventTag >> 1);
5840 hs->lip_count -= lso->link_events;
5844 hs->nos_count = (phba->fc_eventTag >> 1);
5845 hs->nos_count -= lso->link_events;
5848 hs->dumped_frames = -1;
5850 seconds = get_seconds();
5851 if (seconds < psli->stats_start)
5852 hs->seconds_since_last_reset = seconds +
5853 ((unsigned long)-1 - psli->stats_start);
5855 hs->seconds_since_last_reset = seconds - psli->stats_start;
5857 mempool_free(pmboxq, phba->mbox_mem_pool);
5863 * lpfc_reset_stats - Copy the adapter link stats information
5864 * @shost: kernel scsi host pointer.
5867 lpfc_reset_stats(struct Scsi_Host *shost)
5869 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5870 struct lpfc_hba *phba = vport->phba;
5871 struct lpfc_sli *psli = &phba->sli;
5872 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5873 LPFC_MBOXQ_t *pmboxq;
5877 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5880 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5883 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5885 pmb = &pmboxq->u.mb;
5886 pmb->mbxCommand = MBX_READ_STATUS;
5887 pmb->mbxOwner = OWN_HOST;
5888 pmb->un.varWords[0] = 0x1; /* reset request */
5889 pmboxq->context1 = NULL;
5890 pmboxq->vport = vport;
5892 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5893 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5894 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5896 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5898 if (rc != MBX_SUCCESS) {
5899 if (rc != MBX_TIMEOUT)
5900 mempool_free(pmboxq, phba->mbox_mem_pool);
5904 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5905 pmb->mbxCommand = MBX_READ_LNK_STAT;
5906 pmb->mbxOwner = OWN_HOST;
5907 pmboxq->context1 = NULL;
5908 pmboxq->vport = vport;
5910 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5911 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5912 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5914 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5916 if (rc != MBX_SUCCESS) {
5917 if (rc != MBX_TIMEOUT)
5918 mempool_free( pmboxq, phba->mbox_mem_pool);
5922 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5923 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5924 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5925 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5926 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5927 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5928 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5929 if (phba->hba_flag & HBA_FCOE_MODE)
5930 lso->link_events = (phba->link_events >> 1);
5932 lso->link_events = (phba->fc_eventTag >> 1);
5934 psli->stats_start = get_seconds();
5936 mempool_free(pmboxq, phba->mbox_mem_pool);
5942 * The LPFC driver treats linkdown handling as target loss events so there
5943 * are no sysfs handlers for link_down_tmo.
5947 * lpfc_get_node_by_target - Return the nodelist for a target
5948 * @starget: kernel scsi target pointer.
5951 * address of the node list if found
5952 * NULL target not found
5954 static struct lpfc_nodelist *
5955 lpfc_get_node_by_target(struct scsi_target *starget)
5957 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5958 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5959 struct lpfc_nodelist *ndlp;
5961 spin_lock_irq(shost->host_lock);
5962 /* Search for this, mapped, target ID */
5963 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5964 if (NLP_CHK_NODE_ACT(ndlp) &&
5965 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5966 starget->id == ndlp->nlp_sid) {
5967 spin_unlock_irq(shost->host_lock);
5971 spin_unlock_irq(shost->host_lock);
5976 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5977 * @starget: kernel scsi target pointer.
5980 lpfc_get_starget_port_id(struct scsi_target *starget)
5982 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5984 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5988 * lpfc_get_starget_node_name - Set the target node name
5989 * @starget: kernel scsi target pointer.
5991 * Description: Set the target node name to the ndlp node name wwn or zero.
5994 lpfc_get_starget_node_name(struct scsi_target *starget)
5996 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5998 fc_starget_node_name(starget) =
5999 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6003 * lpfc_get_starget_port_name - Set the target port name
6004 * @starget: kernel scsi target pointer.
6006 * Description: set the target port name to the ndlp port name wwn or zero.
6009 lpfc_get_starget_port_name(struct scsi_target *starget)
6011 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6013 fc_starget_port_name(starget) =
6014 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6018 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6019 * @rport: fc rport address.
6020 * @timeout: new value for dev loss tmo.
6023 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6024 * dev_loss_tmo to one.
6027 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6030 rport->dev_loss_tmo = timeout;
6032 rport->dev_loss_tmo = 1;
6036 * lpfc_rport_show_function - Return rport target information
6039 * Macro that uses field to generate a function with the name lpfc_show_rport_
6041 * lpfc_show_rport_##field: returns the bytes formatted in buf
6042 * @cdev: class converted to an fc_rport.
6043 * @buf: on return contains the target_field or zero.
6045 * Returns: size of formatted string.
6047 #define lpfc_rport_show_function(field, format_string, sz, cast) \
6049 lpfc_show_rport_##field (struct device *dev, \
6050 struct device_attribute *attr, \
6053 struct fc_rport *rport = transport_class_to_rport(dev); \
6054 struct lpfc_rport_data *rdata = rport->hostdata; \
6055 return snprintf(buf, sz, format_string, \
6056 (rdata->target) ? cast rdata->target->field : 0); \
6059 #define lpfc_rport_rd_attr(field, format_string, sz) \
6060 lpfc_rport_show_function(field, format_string, sz, ) \
6061 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6064 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6065 * @fc_vport: The fc_vport who's symbolic name has been changed.
6068 * This function is called by the transport after the @fc_vport's symbolic name
6069 * has been changed. This function re-registers the symbolic name with the
6070 * switch to propagate the change into the fabric if the vport is active.
6073 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6075 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6077 if (vport->port_state == LPFC_VPORT_READY)
6078 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6082 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6083 * @phba: Pointer to lpfc_hba struct.
6085 * This function is called by the lpfc_get_cfgparam() routine to set the
6086 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6087 * log message according to the module's lpfc_log_verbose parameter setting
6088 * before hba port or vport created.
6091 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6093 phba->cfg_log_verbose = verbose;
6096 struct fc_function_template lpfc_transport_functions = {
6097 /* fixed attributes the driver supports */
6098 .show_host_node_name = 1,
6099 .show_host_port_name = 1,
6100 .show_host_supported_classes = 1,
6101 .show_host_supported_fc4s = 1,
6102 .show_host_supported_speeds = 1,
6103 .show_host_maxframe_size = 1,
6105 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6106 .show_host_symbolic_name = 1,
6108 /* dynamic attributes the driver supports */
6109 .get_host_port_id = lpfc_get_host_port_id,
6110 .show_host_port_id = 1,
6112 .get_host_port_type = lpfc_get_host_port_type,
6113 .show_host_port_type = 1,
6115 .get_host_port_state = lpfc_get_host_port_state,
6116 .show_host_port_state = 1,
6118 /* active_fc4s is shown but doesn't change (thus no get function) */
6119 .show_host_active_fc4s = 1,
6121 .get_host_speed = lpfc_get_host_speed,
6122 .show_host_speed = 1,
6124 .get_host_fabric_name = lpfc_get_host_fabric_name,
6125 .show_host_fabric_name = 1,
6128 * The LPFC driver treats linkdown handling as target loss events
6129 * so there are no sysfs handlers for link_down_tmo.
6132 .get_fc_host_stats = lpfc_get_stats,
6133 .reset_fc_host_stats = lpfc_reset_stats,
6135 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6136 .show_rport_maxframe_size = 1,
6137 .show_rport_supported_classes = 1,
6139 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6140 .show_rport_dev_loss_tmo = 1,
6142 .get_starget_port_id = lpfc_get_starget_port_id,
6143 .show_starget_port_id = 1,
6145 .get_starget_node_name = lpfc_get_starget_node_name,
6146 .show_starget_node_name = 1,
6148 .get_starget_port_name = lpfc_get_starget_port_name,
6149 .show_starget_port_name = 1,
6151 .issue_fc_host_lip = lpfc_issue_lip,
6152 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6153 .terminate_rport_io = lpfc_terminate_rport_io,
6155 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6157 .vport_disable = lpfc_vport_disable,
6159 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6161 .bsg_request = lpfc_bsg_request,
6162 .bsg_timeout = lpfc_bsg_timeout,
6165 struct fc_function_template lpfc_vport_transport_functions = {
6166 /* fixed attributes the driver supports */
6167 .show_host_node_name = 1,
6168 .show_host_port_name = 1,
6169 .show_host_supported_classes = 1,
6170 .show_host_supported_fc4s = 1,
6171 .show_host_supported_speeds = 1,
6172 .show_host_maxframe_size = 1,
6174 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6175 .show_host_symbolic_name = 1,
6177 /* dynamic attributes the driver supports */
6178 .get_host_port_id = lpfc_get_host_port_id,
6179 .show_host_port_id = 1,
6181 .get_host_port_type = lpfc_get_host_port_type,
6182 .show_host_port_type = 1,
6184 .get_host_port_state = lpfc_get_host_port_state,
6185 .show_host_port_state = 1,
6187 /* active_fc4s is shown but doesn't change (thus no get function) */
6188 .show_host_active_fc4s = 1,
6190 .get_host_speed = lpfc_get_host_speed,
6191 .show_host_speed = 1,
6193 .get_host_fabric_name = lpfc_get_host_fabric_name,
6194 .show_host_fabric_name = 1,
6197 * The LPFC driver treats linkdown handling as target loss events
6198 * so there are no sysfs handlers for link_down_tmo.
6201 .get_fc_host_stats = lpfc_get_stats,
6202 .reset_fc_host_stats = lpfc_reset_stats,
6204 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6205 .show_rport_maxframe_size = 1,
6206 .show_rport_supported_classes = 1,
6208 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6209 .show_rport_dev_loss_tmo = 1,
6211 .get_starget_port_id = lpfc_get_starget_port_id,
6212 .show_starget_port_id = 1,
6214 .get_starget_node_name = lpfc_get_starget_node_name,
6215 .show_starget_node_name = 1,
6217 .get_starget_port_name = lpfc_get_starget_port_name,
6218 .show_starget_port_name = 1,
6220 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6221 .terminate_rport_io = lpfc_terminate_rport_io,
6223 .vport_disable = lpfc_vport_disable,
6225 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6229 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6230 * @phba: lpfc_hba pointer.
6233 lpfc_get_cfgparam(struct lpfc_hba *phba)
6235 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6236 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6237 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6238 lpfc_cr_count_init(phba, lpfc_cr_count);
6239 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6240 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6241 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6242 lpfc_ack0_init(phba, lpfc_ack0);
6243 lpfc_topology_init(phba, lpfc_topology);
6244 lpfc_link_speed_init(phba, lpfc_link_speed);
6245 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6246 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6247 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6248 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6249 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6250 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6251 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6252 lpfc_use_msi_init(phba, lpfc_use_msi);
6253 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6254 lpfc_auto_imax_init(phba, lpfc_auto_imax);
6255 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6256 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6257 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6258 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6260 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6261 if (phba->sli_rev != LPFC_SLI_REV4)
6262 phba->cfg_EnableXLane = 0;
6263 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6265 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6266 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6267 phba->cfg_oas_lun_state = 0;
6268 phba->cfg_oas_lun_status = 0;
6269 phba->cfg_oas_flags = 0;
6270 phba->cfg_oas_priority = 0;
6271 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6272 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6273 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6274 if (phba->sli_rev == LPFC_SLI_REV4)
6277 phba->cfg_poll = lpfc_poll;
6278 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6280 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6281 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6283 /* Initialize first burst. Target vs Initiator are different. */
6284 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6285 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6286 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6287 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6288 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
6290 if (phba->sli_rev != LPFC_SLI_REV4) {
6291 /* NVME only supported on SLI4 */
6292 phba->nvmet_support = 0;
6293 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6294 phba->cfg_enable_bbcr = 0;
6296 /* We MUST have FCP support */
6297 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6298 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6301 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6302 phba->cfg_auto_imax = 0;
6303 phba->initial_imax = phba->cfg_fcp_imax;
6305 /* A value of 0 means use the number of CPUs found in the system */
6306 if (phba->cfg_fcp_io_channel == 0)
6307 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6308 if (phba->cfg_nvme_io_channel == 0)
6309 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6311 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6312 phba->cfg_fcp_io_channel = 0;
6314 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6315 phba->cfg_nvme_io_channel = 0;
6317 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6318 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6320 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6322 phba->cfg_soft_wwnn = 0L;
6323 phba->cfg_soft_wwpn = 0L;
6324 lpfc_xri_split_init(phba, lpfc_xri_split);
6325 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6326 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6327 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6328 lpfc_aer_support_init(phba, lpfc_aer_support);
6329 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6330 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6331 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6332 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6333 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6334 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6335 phba->cfg_enable_dss = 1;
6336 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6341 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6342 * dependencies between protocols and roles.
6343 * @phba: lpfc_hba pointer.
6346 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6348 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6349 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6351 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6352 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6354 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6355 phba->nvmet_support) {
6356 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6357 phba->cfg_fcp_io_channel = 0;
6359 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6360 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6361 "NVME Target PRLI ACC enable_fb ",
6362 phba->cfg_nvme_enable_fb,
6363 phba->cfg_nvmet_fb_size,
6364 LPFC_NVMET_FB_SZ_MAX);
6366 if (phba->cfg_nvme_enable_fb == 0)
6367 phba->cfg_nvmet_fb_size = 0;
6369 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6370 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6373 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6374 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6375 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6376 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6377 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6378 phba->cfg_nvmet_mrq);
6381 /* Not NVME Target mode. Turn off Target parameters. */
6382 phba->nvmet_support = 0;
6383 phba->cfg_nvmet_mrq = 0;
6384 phba->cfg_nvmet_fb_size = 0;
6387 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6388 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6390 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6394 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6395 * @vport: lpfc_vport pointer.
6398 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6400 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6401 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6402 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6403 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6404 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6405 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6406 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6407 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6408 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6409 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6410 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6411 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6412 lpfc_max_luns_init(vport, lpfc_max_luns);
6413 lpfc_scan_down_init(vport, lpfc_scan_down);
6414 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);