1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/ctype.h>
25 #include <linux/delay.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/aer.h>
30 #include <linux/gfp.h>
31 #include <linux/kernel.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_tcq.h>
37 #include <scsi/scsi_transport_fc.h>
38 #include <scsi/fc/fc_fs.h>
40 #include <linux/nvme-fc-driver.h>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_nvmet.h"
52 #include "lpfc_logmsg.h"
53 #include "lpfc_version.h"
54 #include "lpfc_compat.h"
55 #include "lpfc_crtn.h"
56 #include "lpfc_vport.h"
57 #include "lpfc_attr.h"
59 #define LPFC_DEF_DEVLOSS_TMO 30
60 #define LPFC_MIN_DEVLOSS_TMO 1
61 #define LPFC_MAX_DEVLOSS_TMO 255
63 #define LPFC_DEF_MRQ_POST 512
64 #define LPFC_MIN_MRQ_POST 512
65 #define LPFC_MAX_MRQ_POST 2048
68 * Write key size should be multiple of 4. If write key is changed
69 * make sure that library write key is also changed.
71 #define LPFC_REG_WRITE_KEY_SIZE 4
72 #define LPFC_REG_WRITE_KEY "EMLX"
75 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
76 * @incr: integer to convert.
77 * @hdw: ascii string holding converted integer plus a string terminator.
80 * JEDEC Joint Electron Device Engineering Council.
81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
82 * character string. The string is then terminated with a NULL in byte 9.
83 * Hex 0-9 becomes ascii '0' to '9'.
84 * Hex a-f becomes ascii '=' to 'B' capital B.
87 * Coded for 32 bit integers only.
90 lpfc_jedec_to_ascii(int incr, char hdw[])
93 for (i = 0; i < 8; i++) {
96 hdw[7 - i] = 0x30 + j;
98 hdw[7 - i] = 0x61 + j - 10;
106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
107 * @dev: class unused variable.
108 * @attr: device attribute, not used.
109 * @buf: on return contains the module description text.
111 * Returns: size of formatted string.
114 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
126 * Returns: size of formatted string.
129 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
139 return snprintf(buf, PAGE_SIZE, "0\n");
143 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = shost_priv(shost);
148 struct lpfc_hba *phba = vport->phba;
149 struct lpfc_nvmet_tgtport *tgtp;
150 struct nvme_fc_local_port *localport;
151 struct lpfc_nodelist *ndlp;
152 struct nvme_fc_remote_port *nrport;
153 uint64_t data1, data2, data3, tot;
157 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
158 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
161 if (phba->nvmet_support) {
162 if (!phba->targetport) {
163 len = snprintf(buf, PAGE_SIZE,
164 "NVME Target: x%llx is not allocated\n",
165 wwn_to_u64(vport->fc_portname.u.wwn));
168 /* Port state is only one of two values for now. */
169 if (phba->targetport->port_id)
170 statep = "REGISTERED";
173 len += snprintf(buf + len, PAGE_SIZE - len,
174 "NVME Target Enabled State %s\n",
176 len += snprintf(buf + len, PAGE_SIZE - len,
177 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
180 wwn_to_u64(vport->fc_portname.u.wwn),
181 wwn_to_u64(vport->fc_nodename.u.wwn),
182 phba->targetport->port_id);
184 len += snprintf(buf + len, PAGE_SIZE - len,
185 "\nNVME Target: Statistics\n");
186 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
187 len += snprintf(buf+len, PAGE_SIZE-len,
188 "LS: Rcv %08x Drop %08x Abort %08x\n",
189 atomic_read(&tgtp->rcv_ls_req_in),
190 atomic_read(&tgtp->rcv_ls_req_drop),
191 atomic_read(&tgtp->xmt_ls_abort));
192 if (atomic_read(&tgtp->rcv_ls_req_in) !=
193 atomic_read(&tgtp->rcv_ls_req_out)) {
194 len += snprintf(buf+len, PAGE_SIZE-len,
195 "Rcv LS: in %08x != out %08x\n",
196 atomic_read(&tgtp->rcv_ls_req_in),
197 atomic_read(&tgtp->rcv_ls_req_out));
200 len += snprintf(buf+len, PAGE_SIZE-len,
201 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
202 atomic_read(&tgtp->xmt_ls_rsp),
203 atomic_read(&tgtp->xmt_ls_drop),
204 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
205 atomic_read(&tgtp->xmt_ls_rsp_error));
207 len += snprintf(buf+len, PAGE_SIZE-len,
208 "FCP: Rcv %08x Release %08x Drop %08x\n",
209 atomic_read(&tgtp->rcv_fcp_cmd_in),
210 atomic_read(&tgtp->xmt_fcp_release),
211 atomic_read(&tgtp->rcv_fcp_cmd_drop));
213 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
214 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
215 len += snprintf(buf+len, PAGE_SIZE-len,
216 "Rcv FCP: in %08x != out %08x\n",
217 atomic_read(&tgtp->rcv_fcp_cmd_in),
218 atomic_read(&tgtp->rcv_fcp_cmd_out));
221 len += snprintf(buf+len, PAGE_SIZE-len,
222 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
224 atomic_read(&tgtp->xmt_fcp_read),
225 atomic_read(&tgtp->xmt_fcp_read_rsp),
226 atomic_read(&tgtp->xmt_fcp_write),
227 atomic_read(&tgtp->xmt_fcp_rsp),
228 atomic_read(&tgtp->xmt_fcp_drop));
230 len += snprintf(buf+len, PAGE_SIZE-len,
231 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
232 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
233 atomic_read(&tgtp->xmt_fcp_rsp_error),
234 atomic_read(&tgtp->xmt_fcp_rsp_drop));
236 len += snprintf(buf+len, PAGE_SIZE-len,
237 "ABORT: Xmt %08x Cmpl %08x\n",
238 atomic_read(&tgtp->xmt_fcp_abort),
239 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
241 len += snprintf(buf + len, PAGE_SIZE - len,
242 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
243 atomic_read(&tgtp->xmt_abort_sol),
244 atomic_read(&tgtp->xmt_abort_unsol),
245 atomic_read(&tgtp->xmt_abort_rsp),
246 atomic_read(&tgtp->xmt_abort_rsp_error));
248 spin_lock(&phba->sli4_hba.nvmet_ctx_get_lock);
249 spin_lock(&phba->sli4_hba.nvmet_ctx_put_lock);
250 tot = phba->sli4_hba.nvmet_xri_cnt -
251 (phba->sli4_hba.nvmet_ctx_get_cnt +
252 phba->sli4_hba.nvmet_ctx_put_cnt);
253 spin_unlock(&phba->sli4_hba.nvmet_ctx_put_lock);
254 spin_unlock(&phba->sli4_hba.nvmet_ctx_get_lock);
256 len += snprintf(buf + len, PAGE_SIZE - len,
257 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
258 "CTX Outstanding %08llx\n",
259 phba->sli4_hba.nvmet_xri_cnt,
260 phba->sli4_hba.nvmet_io_wait_cnt,
261 phba->sli4_hba.nvmet_io_wait_total,
264 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
268 localport = vport->localport;
270 len = snprintf(buf, PAGE_SIZE,
271 "NVME Initiator x%llx is not allocated\n",
272 wwn_to_u64(vport->fc_portname.u.wwn));
275 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
277 spin_lock_irq(shost->host_lock);
279 /* Port state is only one of two values for now. */
280 if (localport->port_id)
285 len += snprintf(buf + len, PAGE_SIZE - len,
286 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
289 wwn_to_u64(vport->fc_portname.u.wwn),
290 wwn_to_u64(vport->fc_nodename.u.wwn),
291 localport->port_id, statep);
293 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
297 /* local short-hand pointer. */
298 nrport = ndlp->nrport->remoteport;
300 /* Port state is only one of two values for now. */
301 switch (nrport->port_state) {
302 case FC_OBJSTATE_ONLINE:
305 case FC_OBJSTATE_UNKNOWN:
309 statep = "UNSUPPORTED";
313 /* Tab in to show lport ownership. */
314 len += snprintf(buf + len, PAGE_SIZE - len,
316 if (phba->brd_no >= 10)
317 len += snprintf(buf + len, PAGE_SIZE - len, " ");
319 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
321 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
323 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
326 /* An NVME rport can have multiple roles. */
327 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
328 len += snprintf(buf + len, PAGE_SIZE - len,
330 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
331 len += snprintf(buf + len, PAGE_SIZE - len,
333 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
334 len += snprintf(buf + len, PAGE_SIZE - len,
336 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
337 FC_PORT_ROLE_NVME_TARGET |
338 FC_PORT_ROLE_NVME_DISCOVERY))
339 len += snprintf(buf + len, PAGE_SIZE - len,
343 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
344 /* Terminate the string. */
345 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
347 spin_unlock_irq(shost->host_lock);
349 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
350 len += snprintf(buf+len, PAGE_SIZE-len,
351 "LS: Xmt %016x Cmpl %016x\n",
352 atomic_read(&phba->fc4NvmeLsRequests),
353 atomic_read(&phba->fc4NvmeLsCmpls));
355 tot = atomic_read(&phba->fc4NvmeIoCmpls);
356 data1 = atomic_read(&phba->fc4NvmeInputRequests);
357 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
358 data3 = atomic_read(&phba->fc4NvmeControlRequests);
359 len += snprintf(buf+len, PAGE_SIZE-len,
360 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
361 data1, data2, data3);
363 len += snprintf(buf+len, PAGE_SIZE-len,
364 " Cmpl %016llx Outstanding %016llx\n",
365 tot, (data1 + data2 + data3) - tot);
370 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
373 struct Scsi_Host *shost = class_to_shost(dev);
374 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
375 struct lpfc_hba *phba = vport->phba;
377 if (phba->cfg_enable_bg)
378 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
379 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
381 return snprintf(buf, PAGE_SIZE,
382 "BlockGuard Not Supported\n");
384 return snprintf(buf, PAGE_SIZE,
385 "BlockGuard Disabled\n");
389 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
392 struct Scsi_Host *shost = class_to_shost(dev);
393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394 struct lpfc_hba *phba = vport->phba;
396 return snprintf(buf, PAGE_SIZE, "%llu\n",
397 (unsigned long long)phba->bg_guard_err_cnt);
401 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
404 struct Scsi_Host *shost = class_to_shost(dev);
405 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
406 struct lpfc_hba *phba = vport->phba;
408 return snprintf(buf, PAGE_SIZE, "%llu\n",
409 (unsigned long long)phba->bg_apptag_err_cnt);
413 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
416 struct Scsi_Host *shost = class_to_shost(dev);
417 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
418 struct lpfc_hba *phba = vport->phba;
420 return snprintf(buf, PAGE_SIZE, "%llu\n",
421 (unsigned long long)phba->bg_reftag_err_cnt);
425 * lpfc_info_show - Return some pci info about the host in ascii
426 * @dev: class converted to a Scsi_host structure.
427 * @attr: device attribute, not used.
428 * @buf: on return contains the formatted text from lpfc_info().
430 * Returns: size of formatted string.
433 lpfc_info_show(struct device *dev, struct device_attribute *attr,
436 struct Scsi_Host *host = class_to_shost(dev);
438 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
442 * lpfc_serialnum_show - Return the hba serial number in ascii
443 * @dev: class converted to a Scsi_host structure.
444 * @attr: device attribute, not used.
445 * @buf: on return contains the formatted text serial number.
447 * Returns: size of formatted string.
450 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
453 struct Scsi_Host *shost = class_to_shost(dev);
454 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
455 struct lpfc_hba *phba = vport->phba;
457 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
461 * lpfc_temp_sensor_show - Return the temperature sensor level
462 * @dev: class converted to a Scsi_host structure.
463 * @attr: device attribute, not used.
464 * @buf: on return contains the formatted support level.
467 * Returns a number indicating the temperature sensor level currently
468 * supported, zero or one in ascii.
470 * Returns: size of formatted string.
473 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
476 struct Scsi_Host *shost = class_to_shost(dev);
477 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
478 struct lpfc_hba *phba = vport->phba;
479 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
483 * lpfc_modeldesc_show - Return the model description of the hba
484 * @dev: class converted to a Scsi_host structure.
485 * @attr: device attribute, not used.
486 * @buf: on return contains the scsi vpd model description.
488 * Returns: size of formatted string.
491 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
494 struct Scsi_Host *shost = class_to_shost(dev);
495 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
496 struct lpfc_hba *phba = vport->phba;
498 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
502 * lpfc_modelname_show - Return the model name of the hba
503 * @dev: class converted to a Scsi_host structure.
504 * @attr: device attribute, not used.
505 * @buf: on return contains the scsi vpd model name.
507 * Returns: size of formatted string.
510 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
513 struct Scsi_Host *shost = class_to_shost(dev);
514 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
515 struct lpfc_hba *phba = vport->phba;
517 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
521 * lpfc_programtype_show - Return the program type of the hba
522 * @dev: class converted to a Scsi_host structure.
523 * @attr: device attribute, not used.
524 * @buf: on return contains the scsi vpd program type.
526 * Returns: size of formatted string.
529 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
532 struct Scsi_Host *shost = class_to_shost(dev);
533 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
534 struct lpfc_hba *phba = vport->phba;
536 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
540 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
541 * @dev: class converted to a Scsi_host structure.
542 * @attr: device attribute, not used.
543 * @buf: on return contains the Menlo Maintenance sli flag.
545 * Returns: size of formatted string.
548 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
550 struct Scsi_Host *shost = class_to_shost(dev);
551 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
552 struct lpfc_hba *phba = vport->phba;
554 return snprintf(buf, PAGE_SIZE, "%d\n",
555 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
559 * lpfc_vportnum_show - Return the port number in ascii of the hba
560 * @dev: class converted to a Scsi_host structure.
561 * @attr: device attribute, not used.
562 * @buf: on return contains scsi vpd program type.
564 * Returns: size of formatted string.
567 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
570 struct Scsi_Host *shost = class_to_shost(dev);
571 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
572 struct lpfc_hba *phba = vport->phba;
574 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
578 * lpfc_fwrev_show - Return the firmware rev running in the hba
579 * @dev: class converted to a Scsi_host structure.
580 * @attr: device attribute, not used.
581 * @buf: on return contains the scsi vpd program type.
583 * Returns: size of formatted string.
586 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
589 struct Scsi_Host *shost = class_to_shost(dev);
590 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
591 struct lpfc_hba *phba = vport->phba;
594 char fwrev[FW_REV_STR_SIZE];
597 lpfc_decode_firmware_rev(phba, fwrev, 1);
598 if_type = phba->sli4_hba.pc_sli4_params.if_type;
599 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
601 if (phba->sli_rev < LPFC_SLI_REV4)
602 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
603 fwrev, phba->sli_rev);
605 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
606 fwrev, phba->sli_rev, if_type, sli_family);
612 * lpfc_hdw_show - Return the jedec information about the hba
613 * @dev: class converted to a Scsi_host structure.
614 * @attr: device attribute, not used.
615 * @buf: on return contains the scsi vpd program type.
617 * Returns: size of formatted string.
620 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
623 struct Scsi_Host *shost = class_to_shost(dev);
624 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
625 struct lpfc_hba *phba = vport->phba;
626 lpfc_vpd_t *vp = &phba->vpd;
628 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
629 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
633 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
634 * @dev: class converted to a Scsi_host structure.
635 * @attr: device attribute, not used.
636 * @buf: on return contains the ROM and FCode ascii strings.
638 * Returns: size of formatted string.
641 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
644 struct Scsi_Host *shost = class_to_shost(dev);
645 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
646 struct lpfc_hba *phba = vport->phba;
647 char fwrev[FW_REV_STR_SIZE];
649 if (phba->sli_rev < LPFC_SLI_REV4)
650 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
652 lpfc_decode_firmware_rev(phba, fwrev, 1);
653 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
657 * lpfc_state_show - Return the link state of the port
658 * @dev: class converted to a Scsi_host structure.
659 * @attr: device attribute, not used.
660 * @buf: on return contains text describing the state of the link.
663 * The switch statement has no default so zero will be returned.
665 * Returns: size of formatted string.
668 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
671 struct Scsi_Host *shost = class_to_shost(dev);
672 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
673 struct lpfc_hba *phba = vport->phba;
676 switch (phba->link_state) {
677 case LPFC_LINK_UNKNOWN:
678 case LPFC_WARM_START:
679 case LPFC_INIT_START:
680 case LPFC_INIT_MBX_CMDS:
683 if (phba->hba_flag & LINK_DISABLED)
684 len += snprintf(buf + len, PAGE_SIZE-len,
685 "Link Down - User disabled\n");
687 len += snprintf(buf + len, PAGE_SIZE-len,
693 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
695 switch (vport->port_state) {
696 case LPFC_LOCAL_CFG_LINK:
697 len += snprintf(buf + len, PAGE_SIZE-len,
698 "Configuring Link\n");
702 case LPFC_FABRIC_CFG_LINK:
705 case LPFC_BUILD_DISC_LIST:
707 len += snprintf(buf + len, PAGE_SIZE - len,
710 case LPFC_VPORT_READY:
711 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
714 case LPFC_VPORT_FAILED:
715 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
718 case LPFC_VPORT_UNKNOWN:
719 len += snprintf(buf + len, PAGE_SIZE - len,
723 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
724 len += snprintf(buf + len, PAGE_SIZE-len,
725 " Menlo Maint Mode\n");
726 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
727 if (vport->fc_flag & FC_PUBLIC_LOOP)
728 len += snprintf(buf + len, PAGE_SIZE-len,
731 len += snprintf(buf + len, PAGE_SIZE-len,
734 if (vport->fc_flag & FC_FABRIC)
735 len += snprintf(buf + len, PAGE_SIZE-len,
738 len += snprintf(buf + len, PAGE_SIZE-len,
747 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
748 * @dev: class unused variable.
749 * @attr: device attribute, not used.
750 * @buf: on return contains the module description text.
752 * Returns: size of formatted string.
755 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
758 struct Scsi_Host *shost = class_to_shost(dev);
759 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
760 struct lpfc_hba *phba = vport->phba;
762 if (phba->sli_rev < LPFC_SLI_REV4)
763 return snprintf(buf, PAGE_SIZE, "fc\n");
765 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
766 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
767 return snprintf(buf, PAGE_SIZE, "fcoe\n");
768 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
769 return snprintf(buf, PAGE_SIZE, "fc\n");
771 return snprintf(buf, PAGE_SIZE, "unknown\n");
775 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
776 * (OAS) is supported.
777 * @dev: class unused variable.
778 * @attr: device attribute, not used.
779 * @buf: on return contains the module description text.
781 * Returns: size of formatted string.
784 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
787 struct Scsi_Host *shost = class_to_shost(dev);
788 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
789 struct lpfc_hba *phba = vport->phba;
791 return snprintf(buf, PAGE_SIZE, "%d\n",
792 phba->sli4_hba.pc_sli4_params.oas_supported);
796 * lpfc_link_state_store - Transition the link_state on an HBA port
797 * @dev: class device that is converted into a Scsi_host.
798 * @attr: device attribute, not used.
799 * @buf: one or more lpfc_polling_flags values.
803 * -EINVAL if the buffer is not "up" or "down"
804 * return from link state change function if non-zero
805 * length of the buf on success
808 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
809 const char *buf, size_t count)
811 struct Scsi_Host *shost = class_to_shost(dev);
812 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
813 struct lpfc_hba *phba = vport->phba;
815 int status = -EINVAL;
817 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
818 (phba->link_state == LPFC_LINK_DOWN))
819 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
820 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
821 (phba->link_state >= LPFC_LINK_UP))
822 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
831 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
832 * @dev: class device that is converted into a Scsi_host.
833 * @attr: device attribute, not used.
834 * @buf: on return contains the sum of fc mapped and unmapped.
837 * Returns the ascii text number of the sum of the fc mapped and unmapped
840 * Returns: size of formatted string.
843 lpfc_num_discovered_ports_show(struct device *dev,
844 struct device_attribute *attr, char *buf)
846 struct Scsi_Host *shost = class_to_shost(dev);
847 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
849 return snprintf(buf, PAGE_SIZE, "%d\n",
850 vport->fc_map_cnt + vport->fc_unmap_cnt);
854 * lpfc_issue_lip - Misnomer, name carried over from long ago
855 * @shost: Scsi_Host pointer.
858 * Bring the link down gracefully then re-init the link. The firmware will
859 * re-init the fiber channel interface as required. Does not issue a LIP.
862 * -EPERM port offline or management commands are being blocked
863 * -ENOMEM cannot allocate memory for the mailbox command
864 * -EIO error sending the mailbox command
868 lpfc_issue_lip(struct Scsi_Host *shost)
870 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
871 struct lpfc_hba *phba = vport->phba;
872 LPFC_MBOXQ_t *pmboxq;
873 int mbxstatus = MBXERR_ERROR;
875 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
876 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
879 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
884 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
885 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
886 pmboxq->u.mb.mbxOwner = OWN_HOST;
888 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
890 if ((mbxstatus == MBX_SUCCESS) &&
891 (pmboxq->u.mb.mbxStatus == 0 ||
892 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
893 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
894 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
895 phba->cfg_link_speed);
896 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
898 if ((mbxstatus == MBX_SUCCESS) &&
899 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
900 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
901 "2859 SLI authentication is required "
902 "for INIT_LINK but has not done yet\n");
905 lpfc_set_loopback_flag(phba);
906 if (mbxstatus != MBX_TIMEOUT)
907 mempool_free(pmboxq, phba->mbox_mem_pool);
909 if (mbxstatus == MBXERR_ERROR)
916 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
921 while (!list_empty(q)) {
922 spin_unlock_irq(lock);
924 if (cnt++ > 250) { /* 5 secs */
925 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
927 "Outstanding IO when ",
928 "bringing Adapter offline\n");
933 spin_unlock_irq(lock);
938 * lpfc_do_offline - Issues a mailbox command to bring the link down
939 * @phba: lpfc_hba pointer.
940 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
943 * Assumes any error from lpfc_do_offline() will be negative.
944 * Can wait up to 5 seconds for the port ring buffers count
945 * to reach zero, prints a warning if it is not zero and continues.
946 * lpfc_workq_post_event() returns a non-zero return code if call fails.
949 * -EIO error posting the event
953 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
955 struct completion online_compl;
956 struct lpfc_queue *qp = NULL;
957 struct lpfc_sli_ring *pring;
958 struct lpfc_sli *psli;
963 init_completion(&online_compl);
964 rc = lpfc_workq_post_event(phba, &status, &online_compl,
965 LPFC_EVT_OFFLINE_PREP);
969 wait_for_completion(&online_compl);
976 /* Wait a little for things to settle down, but not
977 * long enough for dev loss timeout to expire.
979 if (phba->sli_rev != LPFC_SLI_REV4) {
980 for (i = 0; i < psli->num_rings; i++) {
981 pring = &psli->sli3_ring[i];
982 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
987 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
991 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
997 init_completion(&online_compl);
998 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1002 wait_for_completion(&online_compl);
1011 * lpfc_selective_reset - Offline then onlines the port
1012 * @phba: lpfc_hba pointer.
1015 * If the port is configured to allow a reset then the hba is brought
1016 * offline then online.
1019 * Assumes any error from lpfc_do_offline() will be negative.
1020 * Do not make this function static.
1023 * lpfc_do_offline() return code if not zero
1024 * -EIO reset not configured or error posting the event
1028 lpfc_selective_reset(struct lpfc_hba *phba)
1030 struct completion online_compl;
1034 if (!phba->cfg_enable_hba_reset)
1037 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1038 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1044 init_completion(&online_compl);
1045 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1050 wait_for_completion(&online_compl);
1059 * lpfc_issue_reset - Selectively resets an adapter
1060 * @dev: class device that is converted into a Scsi_host.
1061 * @attr: device attribute, not used.
1062 * @buf: containing the string "selective".
1063 * @count: unused variable.
1066 * If the buf contains the string "selective" then lpfc_selective_reset()
1067 * is called to perform the reset.
1070 * Assumes any error from lpfc_selective_reset() will be negative.
1071 * If lpfc_selective_reset() returns zero then the length of the buffer
1072 * is returned which indicates success
1075 * -EINVAL if the buffer does not contain the string "selective"
1076 * length of buf if lpfc-selective_reset() if the call succeeds
1077 * return value of lpfc_selective_reset() if the call fails
1080 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1081 const char *buf, size_t count)
1083 struct Scsi_Host *shost = class_to_shost(dev);
1084 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1085 struct lpfc_hba *phba = vport->phba;
1086 int status = -EINVAL;
1088 if (!phba->cfg_enable_hba_reset)
1091 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1092 status = phba->lpfc_selective_reset(phba);
1101 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1102 * @phba: lpfc_hba pointer.
1105 * SLI4 interface type-2 device to wait on the sliport status register for
1106 * the readyness after performing a firmware reset.
1109 * zero for success, -EPERM when port does not have privilege to perform the
1110 * reset, -EIO when port timeout from recovering from the reset.
1113 * As the caller will interpret the return code by value, be careful in making
1114 * change or addition to return codes.
1117 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1119 struct lpfc_register portstat_reg = {0};
1123 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1124 &portstat_reg.word0);
1126 /* verify if privileged for the request operation */
1127 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1128 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1131 /* wait for the SLI port firmware ready after firmware reset */
1132 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1134 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1135 &portstat_reg.word0);
1136 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1138 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1140 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1145 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1152 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1153 * @phba: lpfc_hba pointer.
1156 * Request SLI4 interface type-2 device to perform a physical register set
1163 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1165 struct completion online_compl;
1166 struct pci_dev *pdev = phba->pcidev;
1167 uint32_t before_fc_flag;
1168 uint32_t sriov_nr_virtfn;
1170 int status = 0, rc = 0;
1171 int job_posted = 1, sriov_err;
1173 if (!phba->cfg_enable_hba_reset)
1176 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1177 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1178 LPFC_SLI_INTF_IF_TYPE_2))
1181 /* Keep state if we need to restore back */
1182 before_fc_flag = phba->pport->fc_flag;
1183 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1185 /* Disable SR-IOV virtual functions if enabled */
1186 if (phba->cfg_sriov_nr_virtfn) {
1187 pci_disable_sriov(pdev);
1188 phba->cfg_sriov_nr_virtfn = 0;
1191 if (opcode == LPFC_FW_DUMP)
1192 phba->hba_flag |= HBA_FW_DUMP_OP;
1194 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1197 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1201 /* wait for the device to be quiesced before firmware reset */
1204 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1205 LPFC_CTL_PDEV_CTL_OFFSET);
1207 if (opcode == LPFC_FW_DUMP)
1208 reg_val |= LPFC_FW_DUMP_REQUEST;
1209 else if (opcode == LPFC_FW_RESET)
1210 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1211 else if (opcode == LPFC_DV_RESET)
1212 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1214 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1215 LPFC_CTL_PDEV_CTL_OFFSET);
1217 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1219 /* delay driver action following IF_TYPE_2 reset */
1220 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1223 /* no privilege for reset */
1224 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1225 "3150 No privilege to perform the requested "
1226 "access: x%x\n", reg_val);
1227 } else if (rc == -EIO) {
1228 /* reset failed, there is nothing more we can do */
1229 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1230 "3153 Fail to perform the requested "
1231 "access: x%x\n", reg_val);
1235 /* keep the original port state */
1236 if (before_fc_flag & FC_OFFLINE_MODE)
1239 init_completion(&online_compl);
1240 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1245 wait_for_completion(&online_compl);
1248 /* in any case, restore the virtual functions enabled as before */
1249 if (sriov_nr_virtfn) {
1251 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1253 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1256 /* return proper error code */
1267 * lpfc_nport_evt_cnt_show - Return the number of nport events
1268 * @dev: class device that is converted into a Scsi_host.
1269 * @attr: device attribute, not used.
1270 * @buf: on return contains the ascii number of nport events.
1272 * Returns: size of formatted string.
1275 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1278 struct Scsi_Host *shost = class_to_shost(dev);
1279 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1280 struct lpfc_hba *phba = vport->phba;
1282 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1286 * lpfc_board_mode_show - Return the state of the board
1287 * @dev: class device that is converted into a Scsi_host.
1288 * @attr: device attribute, not used.
1289 * @buf: on return contains the state of the adapter.
1291 * Returns: size of formatted string.
1294 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1297 struct Scsi_Host *shost = class_to_shost(dev);
1298 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1299 struct lpfc_hba *phba = vport->phba;
1302 if (phba->link_state == LPFC_HBA_ERROR)
1304 else if (phba->link_state == LPFC_WARM_START)
1305 state = "warm start";
1306 else if (phba->link_state == LPFC_INIT_START)
1311 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1315 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1316 * @dev: class device that is converted into a Scsi_host.
1317 * @attr: device attribute, not used.
1318 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1319 * @count: unused variable.
1322 * -EACCES if enable hba reset not enabled
1323 * -EINVAL if the buffer does not contain a valid string (see above)
1324 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1325 * buf length greater than zero indicates success
1328 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1329 const char *buf, size_t count)
1331 struct Scsi_Host *shost = class_to_shost(dev);
1332 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1333 struct lpfc_hba *phba = vport->phba;
1334 struct completion online_compl;
1335 char *board_mode_str = NULL;
1339 if (!phba->cfg_enable_hba_reset) {
1341 goto board_mode_out;
1344 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1345 "3050 lpfc_board_mode set to %s\n", buf);
1347 init_completion(&online_compl);
1349 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1350 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1354 goto board_mode_out;
1356 wait_for_completion(&online_compl);
1359 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1360 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1361 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1362 if (phba->sli_rev == LPFC_SLI_REV4)
1365 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1366 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1367 if (phba->sli_rev == LPFC_SLI_REV4)
1370 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1371 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1372 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1373 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1374 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1375 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1376 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1384 board_mode_str = strchr(buf, '\n');
1386 *board_mode_str = '\0';
1387 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1388 "3097 Failed \"%s\", status(%d), "
1390 buf, status, phba->pport->fc_flag);
1396 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1397 * @phba: pointer to the adapter structure.
1398 * @mxri: max xri count.
1399 * @axri: available xri count.
1400 * @mrpi: max rpi count.
1401 * @arpi: available rpi count.
1402 * @mvpi: max vpi count.
1403 * @avpi: available vpi count.
1406 * If an integer pointer for an count is not null then the value for the
1407 * count is returned.
1414 lpfc_get_hba_info(struct lpfc_hba *phba,
1415 uint32_t *mxri, uint32_t *axri,
1416 uint32_t *mrpi, uint32_t *arpi,
1417 uint32_t *mvpi, uint32_t *avpi)
1419 struct lpfc_mbx_read_config *rd_config;
1420 LPFC_MBOXQ_t *pmboxq;
1426 * prevent udev from issuing mailbox commands until the port is
1429 if (phba->link_state < LPFC_LINK_DOWN ||
1430 !phba->mbox_mem_pool ||
1431 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1434 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1437 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1440 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1442 pmb = &pmboxq->u.mb;
1443 pmb->mbxCommand = MBX_READ_CONFIG;
1444 pmb->mbxOwner = OWN_HOST;
1445 pmboxq->context1 = NULL;
1447 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1448 rc = MBX_NOT_FINISHED;
1450 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1452 if (rc != MBX_SUCCESS) {
1453 if (rc != MBX_TIMEOUT)
1454 mempool_free(pmboxq, phba->mbox_mem_pool);
1458 if (phba->sli_rev == LPFC_SLI_REV4) {
1459 rd_config = &pmboxq->u.mqe.un.rd_config;
1461 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1463 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1464 phba->sli4_hba.max_cfg_param.rpi_used;
1466 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1468 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1469 phba->sli4_hba.max_cfg_param.xri_used;
1471 /* Account for differences with SLI-3. Get vpi count from
1472 * mailbox data and subtract one for max vpi value.
1474 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1475 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1480 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1483 *mrpi = pmb->un.varRdConfig.max_rpi;
1485 *arpi = pmb->un.varRdConfig.avail_rpi;
1487 *mxri = pmb->un.varRdConfig.max_xri;
1489 *axri = pmb->un.varRdConfig.avail_xri;
1491 *mvpi = pmb->un.varRdConfig.max_vpi;
1493 *avpi = pmb->un.varRdConfig.avail_vpi;
1496 mempool_free(pmboxq, phba->mbox_mem_pool);
1501 * lpfc_max_rpi_show - Return maximum rpi
1502 * @dev: class device that is converted into a Scsi_host.
1503 * @attr: device attribute, not used.
1504 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1507 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1508 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1509 * to "Unknown" and the buffer length is returned, therefore the caller
1510 * must check for "Unknown" in the buffer to detect a failure.
1512 * Returns: size of formatted string.
1515 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1518 struct Scsi_Host *shost = class_to_shost(dev);
1519 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1520 struct lpfc_hba *phba = vport->phba;
1523 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1524 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1525 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1529 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1530 * @dev: class device that is converted into a Scsi_host.
1531 * @attr: device attribute, not used.
1532 * @buf: containing the used rpi count in decimal or "Unknown".
1535 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1536 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1537 * to "Unknown" and the buffer length is returned, therefore the caller
1538 * must check for "Unknown" in the buffer to detect a failure.
1540 * Returns: size of formatted string.
1543 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1546 struct Scsi_Host *shost = class_to_shost(dev);
1547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1548 struct lpfc_hba *phba = vport->phba;
1551 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1552 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1553 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1557 * lpfc_max_xri_show - Return maximum xri
1558 * @dev: class device that is converted into a Scsi_host.
1559 * @attr: device attribute, not used.
1560 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1563 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1564 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1565 * to "Unknown" and the buffer length is returned, therefore the caller
1566 * must check for "Unknown" in the buffer to detect a failure.
1568 * Returns: size of formatted string.
1571 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1574 struct Scsi_Host *shost = class_to_shost(dev);
1575 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1576 struct lpfc_hba *phba = vport->phba;
1579 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1580 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1581 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1585 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1586 * @dev: class device that is converted into a Scsi_host.
1587 * @attr: device attribute, not used.
1588 * @buf: on return contains the used xri count in decimal or "Unknown".
1591 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1592 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1593 * to "Unknown" and the buffer length is returned, therefore the caller
1594 * must check for "Unknown" in the buffer to detect a failure.
1596 * Returns: size of formatted string.
1599 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1602 struct Scsi_Host *shost = class_to_shost(dev);
1603 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1604 struct lpfc_hba *phba = vport->phba;
1607 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1608 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1609 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1613 * lpfc_max_vpi_show - Return maximum vpi
1614 * @dev: class device that is converted into a Scsi_host.
1615 * @attr: device attribute, not used.
1616 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1619 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1620 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1621 * to "Unknown" and the buffer length is returned, therefore the caller
1622 * must check for "Unknown" in the buffer to detect a failure.
1624 * Returns: size of formatted string.
1627 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1630 struct Scsi_Host *shost = class_to_shost(dev);
1631 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1632 struct lpfc_hba *phba = vport->phba;
1635 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1636 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1637 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1641 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1642 * @dev: class device that is converted into a Scsi_host.
1643 * @attr: device attribute, not used.
1644 * @buf: on return contains the used vpi count in decimal or "Unknown".
1647 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1648 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1649 * to "Unknown" and the buffer length is returned, therefore the caller
1650 * must check for "Unknown" in the buffer to detect a failure.
1652 * Returns: size of formatted string.
1655 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1658 struct Scsi_Host *shost = class_to_shost(dev);
1659 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1660 struct lpfc_hba *phba = vport->phba;
1663 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1664 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1665 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1669 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1670 * @dev: class device that is converted into a Scsi_host.
1671 * @attr: device attribute, not used.
1672 * @buf: text that must be interpreted to determine if npiv is supported.
1675 * Buffer will contain text indicating npiv is not suppoerted on the port,
1676 * the port is an NPIV physical port, or it is an npiv virtual port with
1677 * the id of the vport.
1679 * Returns: size of formatted string.
1682 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1685 struct Scsi_Host *shost = class_to_shost(dev);
1686 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1687 struct lpfc_hba *phba = vport->phba;
1689 if (!(phba->max_vpi))
1690 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1691 if (vport->port_type == LPFC_PHYSICAL_PORT)
1692 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1693 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1697 * lpfc_poll_show - Return text about poll support for the adapter
1698 * @dev: class device that is converted into a Scsi_host.
1699 * @attr: device attribute, not used.
1700 * @buf: on return contains the cfg_poll in hex.
1703 * cfg_poll should be a lpfc_polling_flags type.
1705 * Returns: size of formatted string.
1708 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1711 struct Scsi_Host *shost = class_to_shost(dev);
1712 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1713 struct lpfc_hba *phba = vport->phba;
1715 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1719 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1720 * @dev: class device that is converted into a Scsi_host.
1721 * @attr: device attribute, not used.
1722 * @buf: one or more lpfc_polling_flags values.
1726 * buf contents converted to integer and checked for a valid value.
1729 * -EINVAL if the buffer connot be converted or is out of range
1730 * length of the buf on success
1733 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1734 const char *buf, size_t count)
1736 struct Scsi_Host *shost = class_to_shost(dev);
1737 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1738 struct lpfc_hba *phba = vport->phba;
1743 if (!isdigit(buf[0]))
1746 if (sscanf(buf, "%i", &val) != 1)
1749 if ((val & 0x3) != val)
1752 if (phba->sli_rev == LPFC_SLI_REV4)
1755 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1756 "3051 lpfc_poll changed from %d to %d\n",
1757 phba->cfg_poll, val);
1759 spin_lock_irq(&phba->hbalock);
1761 old_val = phba->cfg_poll;
1763 if (val & ENABLE_FCP_RING_POLLING) {
1764 if ((val & DISABLE_FCP_RING_INT) &&
1765 !(old_val & DISABLE_FCP_RING_INT)) {
1766 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1767 spin_unlock_irq(&phba->hbalock);
1770 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1771 writel(creg_val, phba->HCregaddr);
1772 readl(phba->HCregaddr); /* flush */
1774 lpfc_poll_start_timer(phba);
1776 } else if (val != 0x0) {
1777 spin_unlock_irq(&phba->hbalock);
1781 if (!(val & DISABLE_FCP_RING_INT) &&
1782 (old_val & DISABLE_FCP_RING_INT))
1784 spin_unlock_irq(&phba->hbalock);
1785 del_timer(&phba->fcp_poll_timer);
1786 spin_lock_irq(&phba->hbalock);
1787 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1788 spin_unlock_irq(&phba->hbalock);
1791 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1792 writel(creg_val, phba->HCregaddr);
1793 readl(phba->HCregaddr); /* flush */
1796 phba->cfg_poll = val;
1798 spin_unlock_irq(&phba->hbalock);
1804 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1805 * @dev: class unused variable.
1806 * @attr: device attribute, not used.
1807 * @buf: on return contains the module description text.
1809 * Returns: size of formatted string.
1812 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1815 struct Scsi_Host *shost = class_to_shost(dev);
1816 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1817 struct lpfc_hba *phba = vport->phba;
1819 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1823 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1824 * @dev: class unused variable.
1825 * @attr: device attribute, not used.
1826 * @buf: on return contains the module description text.
1828 * Returns: size of formatted string.
1831 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1834 struct Scsi_Host *shost = class_to_shost(dev);
1835 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1836 struct lpfc_hba *phba = vport->phba;
1838 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1842 * lpfc_dss_show - Return the current state of dss and the configured state
1843 * @dev: class converted to a Scsi_host structure.
1844 * @attr: device attribute, not used.
1845 * @buf: on return contains the formatted text.
1847 * Returns: size of formatted string.
1850 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1853 struct Scsi_Host *shost = class_to_shost(dev);
1854 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1855 struct lpfc_hba *phba = vport->phba;
1857 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1858 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1859 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1864 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1865 * @dev: class converted to a Scsi_host structure.
1866 * @attr: device attribute, not used.
1867 * @buf: on return contains the formatted support level.
1870 * Returns the maximum number of virtual functions a physical function can
1871 * support, 0 will be returned if called on virtual function.
1873 * Returns: size of formatted string.
1876 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1877 struct device_attribute *attr,
1880 struct Scsi_Host *shost = class_to_shost(dev);
1881 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1882 struct lpfc_hba *phba = vport->phba;
1883 uint16_t max_nr_virtfn;
1885 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1886 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1889 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1891 return val >= min && val <= max;
1895 * lpfc_param_show - Return a cfg attribute value in decimal
1898 * Macro that given an attr e.g. hba_queue_depth expands
1899 * into a function with the name lpfc_hba_queue_depth_show.
1901 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1902 * @dev: class device that is converted into a Scsi_host.
1903 * @attr: device attribute, not used.
1904 * @buf: on return contains the attribute value in decimal.
1906 * Returns: size of formatted string.
1908 #define lpfc_param_show(attr) \
1910 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1913 struct Scsi_Host *shost = class_to_shost(dev);\
1914 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1915 struct lpfc_hba *phba = vport->phba;\
1916 return snprintf(buf, PAGE_SIZE, "%d\n",\
1921 * lpfc_param_hex_show - Return a cfg attribute value in hex
1924 * Macro that given an attr e.g. hba_queue_depth expands
1925 * into a function with the name lpfc_hba_queue_depth_show
1927 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1928 * @dev: class device that is converted into a Scsi_host.
1929 * @attr: device attribute, not used.
1930 * @buf: on return contains the attribute value in hexadecimal.
1932 * Returns: size of formatted string.
1934 #define lpfc_param_hex_show(attr) \
1936 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1939 struct Scsi_Host *shost = class_to_shost(dev);\
1940 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1941 struct lpfc_hba *phba = vport->phba;\
1943 val = phba->cfg_##attr;\
1944 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1949 * lpfc_param_init - Initializes a cfg attribute
1952 * Macro that given an attr e.g. hba_queue_depth expands
1953 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1954 * takes a default argument, a minimum and maximum argument.
1956 * lpfc_##attr##_init: Initializes an attribute.
1957 * @phba: pointer the the adapter structure.
1958 * @val: integer attribute value.
1960 * Validates the min and max values then sets the adapter config field
1961 * accordingly, or uses the default if out of range and prints an error message.
1965 * -EINVAL if default used
1967 #define lpfc_param_init(attr, default, minval, maxval) \
1969 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1971 if (lpfc_rangecheck(val, minval, maxval)) {\
1972 phba->cfg_##attr = val;\
1975 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1976 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1977 "allowed range is ["#minval", "#maxval"]\n", val); \
1978 phba->cfg_##attr = default;\
1983 * lpfc_param_set - Set a cfg attribute value
1986 * Macro that given an attr e.g. hba_queue_depth expands
1987 * into a function with the name lpfc_hba_queue_depth_set
1989 * lpfc_##attr##_set: Sets an attribute value.
1990 * @phba: pointer the the adapter structure.
1991 * @val: integer attribute value.
1994 * Validates the min and max values then sets the
1995 * adapter config field if in the valid range. prints error message
1996 * and does not set the parameter if invalid.
2000 * -EINVAL if val is invalid
2002 #define lpfc_param_set(attr, default, minval, maxval) \
2004 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2006 if (lpfc_rangecheck(val, minval, maxval)) {\
2007 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2008 "3052 lpfc_" #attr " changed from %d to %d\n", \
2009 phba->cfg_##attr, val); \
2010 phba->cfg_##attr = val;\
2013 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2014 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2015 "allowed range is ["#minval", "#maxval"]\n", val); \
2020 * lpfc_param_store - Set a vport attribute value
2023 * Macro that given an attr e.g. hba_queue_depth expands
2024 * into a function with the name lpfc_hba_queue_depth_store.
2026 * lpfc_##attr##_store: Set an sttribute value.
2027 * @dev: class device that is converted into a Scsi_host.
2028 * @attr: device attribute, not used.
2029 * @buf: contains the attribute value in ascii.
2033 * Convert the ascii text number to an integer, then
2034 * use the lpfc_##attr##_set function to set the value.
2037 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2038 * length of buffer upon success.
2040 #define lpfc_param_store(attr) \
2042 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2043 const char *buf, size_t count) \
2045 struct Scsi_Host *shost = class_to_shost(dev);\
2046 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2047 struct lpfc_hba *phba = vport->phba;\
2049 if (!isdigit(buf[0]))\
2051 if (sscanf(buf, "%i", &val) != 1)\
2053 if (lpfc_##attr##_set(phba, val) == 0) \
2054 return strlen(buf);\
2060 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2063 * Macro that given an attr e.g. hba_queue_depth expands
2064 * into a function with the name lpfc_hba_queue_depth_show
2066 * lpfc_##attr##_show: prints the attribute value in decimal.
2067 * @dev: class device that is converted into a Scsi_host.
2068 * @attr: device attribute, not used.
2069 * @buf: on return contains the attribute value in decimal.
2071 * Returns: length of formatted string.
2073 #define lpfc_vport_param_show(attr) \
2075 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2078 struct Scsi_Host *shost = class_to_shost(dev);\
2079 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2080 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2084 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2087 * Macro that given an attr e.g.
2088 * hba_queue_depth expands into a function with the name
2089 * lpfc_hba_queue_depth_show
2091 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2092 * @dev: class device that is converted into a Scsi_host.
2093 * @attr: device attribute, not used.
2094 * @buf: on return contains the attribute value in hexadecimal.
2096 * Returns: length of formatted string.
2098 #define lpfc_vport_param_hex_show(attr) \
2100 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2103 struct Scsi_Host *shost = class_to_shost(dev);\
2104 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2105 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2109 * lpfc_vport_param_init - Initialize a vport cfg attribute
2112 * Macro that given an attr e.g. hba_queue_depth expands
2113 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2114 * takes a default argument, a minimum and maximum argument.
2116 * lpfc_##attr##_init: validates the min and max values then sets the
2117 * adapter config field accordingly, or uses the default if out of range
2118 * and prints an error message.
2119 * @phba: pointer the the adapter structure.
2120 * @val: integer attribute value.
2124 * -EINVAL if default used
2126 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2128 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2130 if (lpfc_rangecheck(val, minval, maxval)) {\
2131 vport->cfg_##attr = val;\
2134 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2135 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2136 "allowed range is ["#minval", "#maxval"]\n", val); \
2137 vport->cfg_##attr = default;\
2142 * lpfc_vport_param_set - Set a vport cfg attribute
2145 * Macro that given an attr e.g. hba_queue_depth expands
2146 * into a function with the name lpfc_hba_queue_depth_set
2148 * lpfc_##attr##_set: validates the min and max values then sets the
2149 * adapter config field if in the valid range. prints error message
2150 * and does not set the parameter if invalid.
2151 * @phba: pointer the the adapter structure.
2152 * @val: integer attribute value.
2156 * -EINVAL if val is invalid
2158 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2160 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2162 if (lpfc_rangecheck(val, minval, maxval)) {\
2163 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2164 "3053 lpfc_" #attr \
2165 " changed from %d (x%x) to %d (x%x)\n", \
2166 vport->cfg_##attr, vport->cfg_##attr, \
2168 vport->cfg_##attr = val;\
2171 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2172 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2173 "allowed range is ["#minval", "#maxval"]\n", val); \
2178 * lpfc_vport_param_store - Set a vport attribute
2181 * Macro that given an attr e.g. hba_queue_depth
2182 * expands into a function with the name lpfc_hba_queue_depth_store
2184 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2185 * use the lpfc_##attr##_set function to set the value.
2186 * @cdev: class device that is converted into a Scsi_host.
2187 * @buf: contains the attribute value in decimal.
2191 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2192 * length of buffer upon success.
2194 #define lpfc_vport_param_store(attr) \
2196 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2197 const char *buf, size_t count) \
2199 struct Scsi_Host *shost = class_to_shost(dev);\
2200 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2202 if (!isdigit(buf[0]))\
2204 if (sscanf(buf, "%i", &val) != 1)\
2206 if (lpfc_##attr##_set(vport, val) == 0) \
2207 return strlen(buf);\
2213 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2214 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2215 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2216 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2217 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2218 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2219 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2220 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2221 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2222 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2223 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2224 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2225 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2226 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2227 lpfc_link_state_store);
2228 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2229 lpfc_option_rom_version_show, NULL);
2230 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2231 lpfc_num_discovered_ports_show, NULL);
2232 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2233 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2234 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2235 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2236 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2237 lpfc_board_mode_show, lpfc_board_mode_store);
2238 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2239 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2240 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2241 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2242 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2243 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2244 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2245 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2246 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2247 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2248 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2249 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2250 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2251 lpfc_sriov_hw_max_virtfn_show, NULL);
2252 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2253 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2256 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2259 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2261 * @cnt: Length of string.
2262 * @wwn: Array to receive converted wwn value.
2265 * -EINVAL if the buffer does not contain a valid wwn
2269 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2273 /* Count may include a LF at end of string */
2274 if (buf[cnt-1] == '\n')
2277 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2278 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2281 memset(wwn, 0, WWN_SZ);
2283 /* Validate and store the new name */
2284 for (i = 0, j = 0; i < 16; i++) {
2285 if ((*buf >= 'a') && (*buf <= 'f'))
2286 j = ((j << 4) | ((*buf++ - 'a') + 10));
2287 else if ((*buf >= 'A') && (*buf <= 'F'))
2288 j = ((j << 4) | ((*buf++ - 'A') + 10));
2289 else if ((*buf >= '0') && (*buf <= '9'))
2290 j = ((j << 4) | (*buf++ - '0'));
2294 wwn[i/2] = j & 0xff;
2301 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2302 * @dev: class device that is converted into a Scsi_host.
2303 * @attr: device attribute, not used.
2304 * @buf: containing the string lpfc_soft_wwn_key.
2305 * @count: must be size of lpfc_soft_wwn_key.
2308 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2309 * length of buf indicates success
2312 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2313 const char *buf, size_t count)
2315 struct Scsi_Host *shost = class_to_shost(dev);
2316 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2317 struct lpfc_hba *phba = vport->phba;
2318 unsigned int cnt = count;
2319 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2320 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2323 * We're doing a simple sanity check for soft_wwpn setting.
2324 * We require that the user write a specific key to enable
2325 * the soft_wwpn attribute to be settable. Once the attribute
2326 * is written, the enable key resets. If further updates are
2327 * desired, the key must be written again to re-enable the
2330 * The "key" is not secret - it is a hardcoded string shown
2331 * here. The intent is to protect against the random user or
2332 * application that is just writing attributes.
2334 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2336 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2337 " be enabled: fawwpn is enabled\n");
2341 /* count may include a LF at end of string */
2342 if (buf[cnt-1] == '\n')
2345 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2346 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2349 phba->soft_wwn_enable = 1;
2351 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2352 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2354 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2355 " The soft_wwpn feature is not supported by Broadcom.");
2359 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2360 lpfc_soft_wwn_enable_store);
2363 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2364 * @dev: class device that is converted into a Scsi_host.
2365 * @attr: device attribute, not used.
2366 * @buf: on return contains the wwpn in hexadecimal.
2368 * Returns: size of formatted string.
2371 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2374 struct Scsi_Host *shost = class_to_shost(dev);
2375 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2376 struct lpfc_hba *phba = vport->phba;
2378 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2379 (unsigned long long)phba->cfg_soft_wwpn);
2383 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2384 * @dev class device that is converted into a Scsi_host.
2385 * @attr: device attribute, not used.
2386 * @buf: contains the wwpn in hexadecimal.
2387 * @count: number of wwpn bytes in buf
2390 * -EACCES hba reset not enabled, adapter over temp
2391 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2392 * -EIO error taking adapter offline or online
2393 * value of count on success
2396 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2397 const char *buf, size_t count)
2399 struct Scsi_Host *shost = class_to_shost(dev);
2400 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2401 struct lpfc_hba *phba = vport->phba;
2402 struct completion online_compl;
2403 int stat1 = 0, stat2 = 0;
2404 unsigned int cnt = count;
2408 if (!phba->cfg_enable_hba_reset)
2410 spin_lock_irq(&phba->hbalock);
2411 if (phba->over_temp_state == HBA_OVER_TEMP) {
2412 spin_unlock_irq(&phba->hbalock);
2415 spin_unlock_irq(&phba->hbalock);
2416 /* count may include a LF at end of string */
2417 if (buf[cnt-1] == '\n')
2420 if (!phba->soft_wwn_enable)
2423 /* lock setting wwpn, wwnn down */
2424 phba->soft_wwn_enable = 0;
2426 rc = lpfc_wwn_set(buf, cnt, wwpn);
2428 /* not able to set wwpn, unlock it */
2429 phba->soft_wwn_enable = 1;
2433 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2434 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2435 if (phba->cfg_soft_wwnn)
2436 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2438 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2439 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2441 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2443 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2444 "0463 lpfc_soft_wwpn attribute set failed to "
2445 "reinit adapter - %d\n", stat1);
2446 init_completion(&online_compl);
2447 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2452 wait_for_completion(&online_compl);
2454 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2455 "0464 lpfc_soft_wwpn attribute set failed to "
2456 "reinit adapter - %d\n", stat2);
2457 return (stat1 || stat2) ? -EIO : count;
2459 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2460 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2463 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2464 * @dev: class device that is converted into a Scsi_host.
2465 * @attr: device attribute, not used.
2466 * @buf: on return contains the wwnn in hexadecimal.
2468 * Returns: size of formatted string.
2471 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2474 struct Scsi_Host *shost = class_to_shost(dev);
2475 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2476 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2477 (unsigned long long)phba->cfg_soft_wwnn);
2481 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2482 * @cdev: class device that is converted into a Scsi_host.
2483 * @buf: contains the ww node name in hexadecimal.
2484 * @count: number of wwnn bytes in buf.
2487 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2488 * value of count on success
2491 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2492 const char *buf, size_t count)
2494 struct Scsi_Host *shost = class_to_shost(dev);
2495 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2496 unsigned int cnt = count;
2500 /* count may include a LF at end of string */
2501 if (buf[cnt-1] == '\n')
2504 if (!phba->soft_wwn_enable)
2507 rc = lpfc_wwn_set(buf, cnt, wwnn);
2509 /* Allow wwnn to be set many times, as long as the enable
2510 * is set. However, once the wwpn is set, everything locks.
2515 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2517 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2518 "lpfc%d: soft_wwnn set. Value will take effect upon "
2519 "setting of the soft_wwpn\n", phba->brd_no);
2523 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2524 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2527 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2528 * Optimized Access Storage (OAS) operations.
2529 * @dev: class device that is converted into a Scsi_host.
2530 * @attr: device attribute, not used.
2531 * @buf: buffer for passing information.
2537 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2540 struct Scsi_Host *shost = class_to_shost(dev);
2541 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2543 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2544 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2548 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2549 * Optimized Access Storage (OAS) operations.
2550 * @dev: class device that is converted into a Scsi_host.
2551 * @attr: device attribute, not used.
2552 * @buf: buffer for passing information.
2553 * @count: Size of the data buffer.
2556 * -EINVAL count is invalid, invalid wwpn byte invalid
2557 * -EPERM oas is not supported by hba
2558 * value of count on success
2561 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2562 const char *buf, size_t count)
2564 struct Scsi_Host *shost = class_to_shost(dev);
2565 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2566 unsigned int cnt = count;
2567 uint8_t wwpn[WWN_SZ];
2573 /* count may include a LF at end of string */
2574 if (buf[cnt-1] == '\n')
2577 rc = lpfc_wwn_set(buf, cnt, wwpn);
2581 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2582 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2583 if (wwn_to_u64(wwpn) == 0)
2584 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2586 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2587 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2588 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2591 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2592 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2595 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2596 * Optimized Access Storage (OAS) operations.
2597 * @dev: class device that is converted into a Scsi_host.
2598 * @attr: device attribute, not used.
2599 * @buf: buffer for passing information.
2605 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2608 struct Scsi_Host *shost = class_to_shost(dev);
2609 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2611 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2615 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2616 * Optimized Access Storage (OAS) operations.
2617 * @dev: class device that is converted into a Scsi_host.
2618 * @attr: device attribute, not used.
2619 * @buf: buffer for passing information.
2620 * @count: Size of the data buffer.
2623 * -EINVAL count is invalid, invalid wwpn byte invalid
2624 * -EPERM oas is not supported by hba
2625 * value of count on success
2628 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2629 const char *buf, size_t count)
2631 struct Scsi_Host *shost = class_to_shost(dev);
2632 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2633 unsigned int cnt = count;
2640 /* count may include a LF at end of string */
2641 if (buf[cnt-1] == '\n')
2644 ret = kstrtoul(buf, 0, &val);
2645 if (ret || (val > 0x7f))
2649 phba->cfg_oas_priority = (uint8_t)val;
2651 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2654 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2655 lpfc_oas_priority_show, lpfc_oas_priority_store);
2658 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2659 * for Optimized Access Storage (OAS) operations.
2660 * @dev: class device that is converted into a Scsi_host.
2661 * @attr: device attribute, not used.
2662 * @buf: buffer for passing information.
2665 * value of count on success
2668 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2671 struct Scsi_Host *shost = class_to_shost(dev);
2672 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2674 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2675 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2679 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2680 * for Optimized Access Storage (OAS) operations.
2681 * @dev: class device that is converted into a Scsi_host.
2682 * @attr: device attribute, not used.
2683 * @buf: buffer for passing information.
2684 * @count: Size of the data buffer.
2687 * -EINVAL count is invalid, invalid wwpn byte invalid
2688 * -EPERM oas is not supported by hba
2689 * value of count on success
2692 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2693 const char *buf, size_t count)
2695 struct Scsi_Host *shost = class_to_shost(dev);
2696 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2697 unsigned int cnt = count;
2698 uint8_t wwpn[WWN_SZ];
2704 /* count may include a LF at end of string */
2705 if (buf[cnt-1] == '\n')
2708 rc = lpfc_wwn_set(buf, cnt, wwpn);
2712 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2713 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2714 if (wwn_to_u64(wwpn) == 0)
2715 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2717 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2718 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2719 if (phba->cfg_oas_priority == 0)
2720 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2721 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2724 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2725 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2728 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2729 * of whether luns will be enabled or disabled
2730 * for Optimized Access Storage (OAS) operations.
2731 * @dev: class device that is converted into a Scsi_host.
2732 * @attr: device attribute, not used.
2733 * @buf: buffer for passing information.
2736 * size of formatted string.
2739 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2742 struct Scsi_Host *shost = class_to_shost(dev);
2743 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2745 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2749 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2750 * of whether luns will be enabled or disabled
2751 * for Optimized Access Storage (OAS) operations.
2752 * @dev: class device that is converted into a Scsi_host.
2753 * @attr: device attribute, not used.
2754 * @buf: buffer for passing information.
2755 * @count: Size of the data buffer.
2758 * -EINVAL count is invalid, invalid wwpn byte invalid
2759 * -EPERM oas is not supported by hba
2760 * value of count on success
2763 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2764 const char *buf, size_t count)
2766 struct Scsi_Host *shost = class_to_shost(dev);
2767 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2773 if (!isdigit(buf[0]))
2776 if (sscanf(buf, "%i", &val) != 1)
2779 if ((val != 0) && (val != 1))
2782 phba->cfg_oas_lun_state = val;
2785 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2786 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2789 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2790 * Storage (OAS) lun returned by the
2791 * lpfc_oas_lun_show function.
2792 * @dev: class device that is converted into a Scsi_host.
2793 * @attr: device attribute, not used.
2794 * @buf: buffer for passing information.
2797 * size of formatted string.
2800 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2803 struct Scsi_Host *shost = class_to_shost(dev);
2804 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2806 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2809 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2811 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2812 lpfc_oas_lun_status_show, NULL);
2816 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2818 * @phba: lpfc_hba pointer.
2819 * @ndlp: pointer to fcp target node.
2820 * @lun: the fc lun for setting oas state.
2821 * @oas_state: the oas state to be set to the lun.
2825 * -EPERM OAS is not enabled or not supported by this port.
2829 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2830 uint8_t tgt_wwpn[], uint64_t lun,
2831 uint32_t oas_state, uint8_t pri)
2840 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2841 (struct lpfc_name *)tgt_wwpn,
2845 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2846 (struct lpfc_name *)tgt_wwpn, lun, pri);
2853 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2854 * Access Storage (OAS) operations.
2855 * @phba: lpfc_hba pointer.
2856 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2857 * @tgt_wwpn: wwpn of the target associated with the returned lun
2858 * @lun_status: status of the lun returned lun
2860 * Returns the first or next lun enabled for OAS operations for the vport/target
2861 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2862 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2865 * lun that is OAS enabled for the vport/target
2866 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2869 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2870 uint8_t tgt_wwpn[], uint32_t *lun_status,
2875 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2876 return NOT_OAS_ENABLED_LUN;
2877 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2878 phba->sli4_hba.oas_next_vpt_wwpn,
2879 (struct lpfc_name *)
2880 phba->sli4_hba.oas_next_tgt_wwpn,
2881 &phba->sli4_hba.oas_next_lun,
2882 (struct lpfc_name *)vpt_wwpn,
2883 (struct lpfc_name *)tgt_wwpn,
2884 &found_lun, lun_status, lun_pri))
2887 return NOT_OAS_ENABLED_LUN;
2891 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2892 * @phba: lpfc_hba pointer.
2893 * @vpt_wwpn: vport wwpn by reference.
2894 * @tgt_wwpn: target wwpn by reference.
2895 * @lun: the fc lun for setting oas state.
2896 * @oas_state: the oas state to be set to the oas_lun.
2898 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2899 * a lun for OAS operations.
2903 * -ENOMEM: failed to enable an lun for OAS operations
2904 * -EPERM: OAS is not enabled
2907 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2908 uint8_t tgt_wwpn[], uint64_t lun,
2909 uint32_t oas_state, uint8_t pri)
2914 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2920 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2921 * @dev: class device that is converted into a Scsi_host.
2922 * @attr: device attribute, not used.
2923 * @buf: buffer for passing information.
2925 * This routine returns a lun enabled for OAS each time the function
2929 * SUCCESS: size of formatted string.
2930 * -EFAULT: target or vport wwpn was not set properly.
2931 * -EPERM: oas is not enabled.
2934 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2937 struct Scsi_Host *shost = class_to_shost(dev);
2938 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2946 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2947 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2950 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2951 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2954 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2955 phba->cfg_oas_tgt_wwpn,
2956 &phba->cfg_oas_lun_status,
2957 &phba->cfg_oas_priority);
2958 if (oas_lun != NOT_OAS_ENABLED_LUN)
2959 phba->cfg_oas_flags |= OAS_LUN_VALID;
2961 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2967 * lpfc_oas_lun_store - Sets the OAS state for lun
2968 * @dev: class device that is converted into a Scsi_host.
2969 * @attr: device attribute, not used.
2970 * @buf: buffer for passing information.
2972 * This function sets the OAS state for lun. Before this function is called,
2973 * the vport wwpn, target wwpn, and oas state need to be set.
2976 * SUCCESS: size of formatted string.
2977 * -EFAULT: target or vport wwpn was not set properly.
2978 * -EPERM: oas is not enabled.
2979 * size of formatted string.
2982 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2983 const char *buf, size_t count)
2985 struct Scsi_Host *shost = class_to_shost(dev);
2986 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2994 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2997 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3000 if (!isdigit(buf[0]))
3003 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3006 pri = phba->cfg_oas_priority;
3008 pri = phba->cfg_XLanePriority;
3010 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3011 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3012 "priority 0x%x with oas state %d\n",
3013 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3014 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3015 pri, phba->cfg_oas_lun_state);
3017 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3018 phba->cfg_oas_tgt_wwpn, scsi_lun,
3019 phba->cfg_oas_lun_state, pri);
3025 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3026 lpfc_oas_lun_show, lpfc_oas_lun_store);
3028 int lpfc_enable_nvmet_cnt;
3029 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3030 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3031 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3032 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3033 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3035 static int lpfc_poll = 0;
3036 module_param(lpfc_poll, int, S_IRUGO);
3037 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3039 " 1 - poll with interrupts enabled"
3040 " 3 - poll and disable FCP ring interrupts");
3042 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3043 lpfc_poll_show, lpfc_poll_store);
3045 int lpfc_no_hba_reset_cnt;
3046 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3047 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3048 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3049 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3051 LPFC_ATTR(sli_mode, 0, 0, 3,
3052 "SLI mode selector:"
3053 " 0 - auto (SLI-3 if supported),"
3054 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3055 " 3 - select SLI-3");
3057 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3058 "Enable NPIV functionality");
3060 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3061 "FCF Fast failover=1 Priority failover=2");
3064 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3065 # 0x0 = disabled, XRI/OXID use not tracked.
3066 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3067 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3069 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3070 "Enable RRQ functionality");
3073 # lpfc_suppress_link_up: Bring link up at initialization
3074 # 0x0 = bring link up (issue MBX_INIT_LINK)
3075 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3076 # 0x2 = never bring up link
3077 # Default value is 0.
3079 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3080 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3081 "Suppress Link Up at initialization");
3083 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3091 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3093 struct Scsi_Host *shost = class_to_shost(dev);
3094 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3096 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3099 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3100 lpfc_iocb_hw_show, NULL);
3102 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3104 struct Scsi_Host *shost = class_to_shost(dev);
3105 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3106 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3108 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
3111 static DEVICE_ATTR(txq_hw, S_IRUGO,
3112 lpfc_txq_hw_show, NULL);
3114 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3117 struct Scsi_Host *shost = class_to_shost(dev);
3118 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3119 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3121 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
3124 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3125 lpfc_txcmplq_hw_show, NULL);
3127 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3128 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3131 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3132 # until the timer expires. Value range is [0,255]. Default value is 30.
3134 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3135 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3136 module_param(lpfc_nodev_tmo, int, 0);
3137 MODULE_PARM_DESC(lpfc_nodev_tmo,
3138 "Seconds driver will hold I/O waiting "
3139 "for a device to come back");
3142 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3143 * @dev: class converted to a Scsi_host structure.
3144 * @attr: device attribute, not used.
3145 * @buf: on return contains the dev loss timeout in decimal.
3147 * Returns: size of formatted string.
3150 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3153 struct Scsi_Host *shost = class_to_shost(dev);
3154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3156 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3160 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3161 * @vport: lpfc vport structure pointer.
3162 * @val: contains the nodev timeout value.
3165 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3166 * a kernel error message is printed and zero is returned.
3167 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3168 * Otherwise nodev tmo is set to the default value.
3171 * zero if already set or if val is in range
3172 * -EINVAL val out of range
3175 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3177 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3178 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3179 if (val != LPFC_DEF_DEVLOSS_TMO)
3180 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3181 "0407 Ignoring lpfc_nodev_tmo module "
3182 "parameter because lpfc_devloss_tmo "
3187 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3188 vport->cfg_nodev_tmo = val;
3189 vport->cfg_devloss_tmo = val;
3192 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3193 "0400 lpfc_nodev_tmo attribute cannot be set to"
3194 " %d, allowed range is [%d, %d]\n",
3195 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3196 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3201 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3202 * @vport: lpfc vport structure pointer.
3205 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3208 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3210 struct Scsi_Host *shost;
3211 struct lpfc_nodelist *ndlp;
3213 shost = lpfc_shost_from_vport(vport);
3214 spin_lock_irq(shost->host_lock);
3215 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3216 if (!NLP_CHK_NODE_ACT(ndlp))
3219 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3221 spin_unlock_irq(shost->host_lock);
3225 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3226 * @vport: lpfc vport structure pointer.
3227 * @val: contains the tmo value.
3230 * If the devloss tmo is already set or the vport dev loss tmo has changed
3231 * then a kernel error message is printed and zero is returned.
3232 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3233 * Otherwise nodev tmo is set to the default value.
3236 * zero if already set or if val is in range
3237 * -EINVAL val out of range
3240 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3242 if (vport->dev_loss_tmo_changed ||
3243 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3244 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3245 "0401 Ignoring change to lpfc_nodev_tmo "
3246 "because lpfc_devloss_tmo is set.\n");
3249 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3250 vport->cfg_nodev_tmo = val;
3251 vport->cfg_devloss_tmo = val;
3253 * For compat: set the fc_host dev loss so new rports
3254 * will get the value.
3256 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3257 lpfc_update_rport_devloss_tmo(vport);
3260 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3261 "0403 lpfc_nodev_tmo attribute cannot be set to "
3262 "%d, allowed range is [%d, %d]\n",
3263 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3267 lpfc_vport_param_store(nodev_tmo)
3269 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3270 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3273 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3274 # disappear until the timer expires. Value range is [0,255]. Default
3277 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3278 MODULE_PARM_DESC(lpfc_devloss_tmo,
3279 "Seconds driver will hold I/O waiting "
3280 "for a device to come back");
3281 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3282 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3283 lpfc_vport_param_show(devloss_tmo)
3286 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3287 * @vport: lpfc vport structure pointer.
3288 * @val: contains the tmo value.
3291 * If val is in a valid range then set the vport nodev tmo,
3292 * devloss tmo, also set the vport dev loss tmo changed flag.
3293 * Else a kernel error message is printed.
3296 * zero if val is in range
3297 * -EINVAL val out of range
3300 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3302 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3303 vport->cfg_nodev_tmo = val;
3304 vport->cfg_devloss_tmo = val;
3305 vport->dev_loss_tmo_changed = 1;
3306 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3307 lpfc_update_rport_devloss_tmo(vport);
3311 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3312 "0404 lpfc_devloss_tmo attribute cannot be set to "
3313 "%d, allowed range is [%d, %d]\n",
3314 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3318 lpfc_vport_param_store(devloss_tmo)
3319 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3320 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3323 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3324 * lpfc_suppress_rsp = 0 Disable
3325 * lpfc_suppress_rsp = 1 Enable (default)
3328 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3329 "Enable suppress rsp feature is firmware supports it");
3332 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3333 * lpfc_nvmet_mrq = 1 use a single RQ pair
3334 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3337 LPFC_ATTR_R(nvmet_mrq,
3339 "Specify number of RQ pairs for processing NVMET cmds");
3342 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3343 * Supported Values: 1 - register just FCP
3344 * 3 - register both FCP and NVME
3345 * Supported values are [1,3]. Default value is 1
3347 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3348 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3349 "Define fc4 type to register with fabric.");
3352 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3353 * This parameter is only used if:
3354 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3355 * port is not configured for NVMET.
3357 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3358 * The remaining XRIs get split up based on lpfc_xri_split per port:
3360 * Supported Values are in percentages
3361 * the xri_split value is the percentage the SCSI port will get. The remaining
3362 * percentage will go to NVME.
3364 LPFC_ATTR_R(xri_split, 50, 10, 90,
3365 "Division of XRI resources between SCSI and NVME");
3368 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3369 # deluged with LOTS of information.
3370 # You can set a bit mask to record specific types of verbose messages:
3371 # See lpfc_logmsh.h for definitions.
3373 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3374 "Verbose logging bit-mask");
3377 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3378 # objects that have been registered with the nameserver after login.
3380 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3381 "Deregister nameserver objects before LOGO");
3384 # lun_queue_depth: This parameter is used to limit the number of outstanding
3385 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3386 # If this parameter value is greater than 1/8th the maximum number of exchanges
3387 # supported by the HBA port, then the lun queue depth will be reduced to
3388 # 1/8th the maximum number of exchanges.
3390 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3391 "Max number of FCP commands we can queue to a specific LUN");
3394 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3395 # commands per target port. Value range is [10,65535]. Default value is 65535.
3397 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3398 "Max number of FCP commands we can queue to a specific target port");
3401 # hba_queue_depth: This parameter is used to limit the number of outstanding
3402 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3403 # value is greater than the maximum number of exchanges supported by the HBA,
3404 # then maximum number of exchanges supported by the HBA is used to determine
3405 # the hba_queue_depth.
3407 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3408 "Max number of FCP commands we can queue to a lpfc HBA");
3411 # peer_port_login: This parameter allows/prevents logins
3412 # between peer ports hosted on the same physical port.
3413 # When this parameter is set 0 peer ports of same physical port
3414 # are not allowed to login to each other.
3415 # When this parameter is set 1 peer ports of same physical port
3416 # are allowed to login to each other.
3417 # Default value of this parameter is 0.
3419 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3420 "Allow peer ports on the same physical port to login to each "
3424 # restrict_login: This parameter allows/prevents logins
3425 # between Virtual Ports and remote initiators.
3426 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3427 # other initiators and will attempt to PLOGI all remote ports.
3428 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3429 # remote ports and will not attempt to PLOGI to other initiators.
3430 # This parameter does not restrict to the physical port.
3431 # This parameter does not restrict logins to Fabric resident remote ports.
3432 # Default value of this parameter is 1.
3434 static int lpfc_restrict_login = 1;
3435 module_param(lpfc_restrict_login, int, S_IRUGO);
3436 MODULE_PARM_DESC(lpfc_restrict_login,
3437 "Restrict virtual ports login to remote initiators.");
3438 lpfc_vport_param_show(restrict_login);
3441 * lpfc_restrict_login_init - Set the vport restrict login flag
3442 * @vport: lpfc vport structure pointer.
3443 * @val: contains the restrict login value.
3446 * If val is not in a valid range then log a kernel error message and set
3447 * the vport restrict login to one.
3448 * If the port type is physical clear the restrict login flag and return.
3449 * Else set the restrict login flag to val.
3452 * zero if val is in range
3453 * -EINVAL val out of range
3456 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3458 if (val < 0 || val > 1) {
3459 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3460 "0422 lpfc_restrict_login attribute cannot "
3461 "be set to %d, allowed range is [0, 1]\n",
3463 vport->cfg_restrict_login = 1;
3466 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3467 vport->cfg_restrict_login = 0;
3470 vport->cfg_restrict_login = val;
3475 * lpfc_restrict_login_set - Set the vport restrict login flag
3476 * @vport: lpfc vport structure pointer.
3477 * @val: contains the restrict login value.
3480 * If val is not in a valid range then log a kernel error message and set
3481 * the vport restrict login to one.
3482 * If the port type is physical and the val is not zero log a kernel
3483 * error message, clear the restrict login flag and return zero.
3484 * Else set the restrict login flag to val.
3487 * zero if val is in range
3488 * -EINVAL val out of range
3491 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3493 if (val < 0 || val > 1) {
3494 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3495 "0425 lpfc_restrict_login attribute cannot "
3496 "be set to %d, allowed range is [0, 1]\n",
3498 vport->cfg_restrict_login = 1;
3501 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3502 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3503 "0468 lpfc_restrict_login must be 0 for "
3504 "Physical ports.\n");
3505 vport->cfg_restrict_login = 0;
3508 vport->cfg_restrict_login = val;
3511 lpfc_vport_param_store(restrict_login);
3512 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3513 lpfc_restrict_login_show, lpfc_restrict_login_store);
3516 # Some disk devices have a "select ID" or "select Target" capability.
3517 # From a protocol standpoint "select ID" usually means select the
3518 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3519 # annex" which contains a table that maps a "select ID" (a number
3520 # between 0 and 7F) to an ALPA. By default, for compatibility with
3521 # older drivers, the lpfc driver scans this table from low ALPA to high
3524 # Turning on the scan-down variable (on = 1, off = 0) will
3525 # cause the lpfc driver to use an inverted table, effectively
3526 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3528 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3529 # and will not work across a fabric. Also this parameter will take
3530 # effect only in the case when ALPA map is not available.)
3532 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3533 "Start scanning for devices from highest ALPA to lowest");
3536 # lpfc_topology: link topology for init link
3537 # 0x0 = attempt loop mode then point-to-point
3538 # 0x01 = internal loopback mode
3539 # 0x02 = attempt point-to-point mode only
3540 # 0x04 = attempt loop mode only
3541 # 0x06 = attempt point-to-point mode then loop
3542 # Set point-to-point mode if you want to run as an N_Port.
3543 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3544 # Default value is 0.
3546 LPFC_ATTR(topology, 0, 0, 6,
3547 "Select Fibre Channel topology");
3550 * lpfc_topology_set - Set the adapters topology field
3551 * @phba: lpfc_hba pointer.
3552 * @val: topology value.
3555 * If val is in a valid range then set the adapter's topology field and
3556 * issue a lip; if the lip fails reset the topology to the old value.
3558 * If the value is not in range log a kernel error message and return an error.
3561 * zero if val is in range and lip okay
3562 * non-zero return value from lpfc_issue_lip()
3563 * -EINVAL val out of range
3566 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3567 const char *buf, size_t count)
3569 struct Scsi_Host *shost = class_to_shost(dev);
3570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3571 struct lpfc_hba *phba = vport->phba;
3574 const char *val_buf = buf;
3578 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3580 val_buf = &buf[strlen("nolip ")];
3583 if (!isdigit(val_buf[0]))
3585 if (sscanf(val_buf, "%i", &val) != 1)
3588 if (val >= 0 && val <= 6) {
3589 prev_val = phba->cfg_topology;
3590 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3592 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3593 "3113 Loop mode not supported at speed %d\n",
3597 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3599 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3600 "3114 Loop mode not supported\n");
3603 phba->cfg_topology = val;
3607 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3608 "3054 lpfc_topology changed from %d to %d\n",
3610 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3611 phba->fc_topology_changed = 1;
3612 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3614 phba->cfg_topology = prev_val;
3619 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3620 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3621 "allowed range is [0, 6]\n",
3626 lpfc_param_show(topology)
3627 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3628 lpfc_topology_show, lpfc_topology_store);
3631 * lpfc_static_vport_show: Read callback function for
3632 * lpfc_static_vport sysfs file.
3633 * @dev: Pointer to class device object.
3634 * @attr: device attribute structure.
3635 * @buf: Data buffer.
3637 * This function is the read call back function for
3638 * lpfc_static_vport sysfs file. The lpfc_static_vport
3639 * sysfs file report the mageability of the vport.
3642 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3645 struct Scsi_Host *shost = class_to_shost(dev);
3646 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3647 if (vport->vport_flag & STATIC_VPORT)
3648 sprintf(buf, "1\n");
3650 sprintf(buf, "0\n");
3656 * Sysfs attribute to control the statistical data collection.
3658 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3659 lpfc_static_vport_show, NULL);
3662 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3663 * @dev: Pointer to class device.
3664 * @buf: Data buffer.
3665 * @count: Size of the data buffer.
3667 * This function get called when a user write to the lpfc_stat_data_ctrl
3668 * sysfs file. This function parse the command written to the sysfs file
3669 * and take appropriate action. These commands are used for controlling
3670 * driver statistical data collection.
3671 * Following are the command this function handles.
3673 * setbucket <bucket_type> <base> <step>
3674 * = Set the latency buckets.
3675 * destroybucket = destroy all the buckets.
3676 * start = start data collection
3677 * stop = stop data collection
3678 * reset = reset the collected data
3681 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3682 const char *buf, size_t count)
3684 struct Scsi_Host *shost = class_to_shost(dev);
3685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3686 struct lpfc_hba *phba = vport->phba;
3687 #define LPFC_MAX_DATA_CTRL_LEN 1024
3688 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3690 char *str_ptr, *token;
3691 struct lpfc_vport **vports;
3692 struct Scsi_Host *v_shost;
3693 char *bucket_type_str, *base_str, *step_str;
3694 unsigned long base, step, bucket_type;
3696 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3697 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3700 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3701 str_ptr = &bucket_data[0];
3702 /* Ignore this token - this is command token */
3703 token = strsep(&str_ptr, "\t ");
3707 bucket_type_str = strsep(&str_ptr, "\t ");
3708 if (!bucket_type_str)
3711 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3712 bucket_type = LPFC_LINEAR_BUCKET;
3713 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3714 bucket_type = LPFC_POWER2_BUCKET;
3718 base_str = strsep(&str_ptr, "\t ");
3721 base = simple_strtoul(base_str, NULL, 0);
3723 step_str = strsep(&str_ptr, "\t ");
3726 step = simple_strtoul(step_str, NULL, 0);
3730 /* Block the data collection for every vport */
3731 vports = lpfc_create_vport_work_array(phba);
3735 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3736 v_shost = lpfc_shost_from_vport(vports[i]);
3737 spin_lock_irq(v_shost->host_lock);
3738 /* Block and reset data collection */
3739 vports[i]->stat_data_blocked = 1;
3740 if (vports[i]->stat_data_enabled)
3741 lpfc_vport_reset_stat_data(vports[i]);
3742 spin_unlock_irq(v_shost->host_lock);
3745 /* Set the bucket attributes */
3746 phba->bucket_type = bucket_type;
3747 phba->bucket_base = base;
3748 phba->bucket_step = step;
3750 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3751 v_shost = lpfc_shost_from_vport(vports[i]);
3753 /* Unblock data collection */
3754 spin_lock_irq(v_shost->host_lock);
3755 vports[i]->stat_data_blocked = 0;
3756 spin_unlock_irq(v_shost->host_lock);
3758 lpfc_destroy_vport_work_array(phba, vports);
3762 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3763 vports = lpfc_create_vport_work_array(phba);
3767 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3768 v_shost = lpfc_shost_from_vport(vports[i]);
3769 spin_lock_irq(shost->host_lock);
3770 vports[i]->stat_data_blocked = 1;
3771 lpfc_free_bucket(vport);
3772 vport->stat_data_enabled = 0;
3773 vports[i]->stat_data_blocked = 0;
3774 spin_unlock_irq(shost->host_lock);
3776 lpfc_destroy_vport_work_array(phba, vports);
3777 phba->bucket_type = LPFC_NO_BUCKET;
3778 phba->bucket_base = 0;
3779 phba->bucket_step = 0;
3783 if (!strncmp(buf, "start", strlen("start"))) {
3784 /* If no buckets configured return error */
3785 if (phba->bucket_type == LPFC_NO_BUCKET)
3787 spin_lock_irq(shost->host_lock);
3788 if (vport->stat_data_enabled) {
3789 spin_unlock_irq(shost->host_lock);
3792 lpfc_alloc_bucket(vport);
3793 vport->stat_data_enabled = 1;
3794 spin_unlock_irq(shost->host_lock);
3798 if (!strncmp(buf, "stop", strlen("stop"))) {
3799 spin_lock_irq(shost->host_lock);
3800 if (vport->stat_data_enabled == 0) {
3801 spin_unlock_irq(shost->host_lock);
3804 lpfc_free_bucket(vport);
3805 vport->stat_data_enabled = 0;
3806 spin_unlock_irq(shost->host_lock);
3810 if (!strncmp(buf, "reset", strlen("reset"))) {
3811 if ((phba->bucket_type == LPFC_NO_BUCKET)
3812 || !vport->stat_data_enabled)
3814 spin_lock_irq(shost->host_lock);
3815 vport->stat_data_blocked = 1;
3816 lpfc_vport_reset_stat_data(vport);
3817 vport->stat_data_blocked = 0;
3818 spin_unlock_irq(shost->host_lock);
3826 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3827 * @dev: Pointer to class device object.
3828 * @buf: Data buffer.
3830 * This function is the read call back function for
3831 * lpfc_stat_data_ctrl sysfs file. This function report the
3832 * current statistical data collection state.
3835 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3838 struct Scsi_Host *shost = class_to_shost(dev);
3839 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3840 struct lpfc_hba *phba = vport->phba;
3844 unsigned long bucket_value;
3846 switch (phba->bucket_type) {
3847 case LPFC_LINEAR_BUCKET:
3848 bucket_type = "linear";
3850 case LPFC_POWER2_BUCKET:
3851 bucket_type = "power2";
3854 bucket_type = "No Bucket";
3858 sprintf(&buf[index], "Statistical Data enabled :%d, "
3859 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3860 " Bucket step :%d\nLatency Ranges :",
3861 vport->stat_data_enabled, vport->stat_data_blocked,
3862 bucket_type, phba->bucket_base, phba->bucket_step);
3863 index = strlen(buf);
3864 if (phba->bucket_type != LPFC_NO_BUCKET) {
3865 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3866 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3867 bucket_value = phba->bucket_base +
3868 phba->bucket_step * i;
3870 bucket_value = phba->bucket_base +
3871 (1 << i) * phba->bucket_step;
3873 if (index + 10 > PAGE_SIZE)
3875 sprintf(&buf[index], "%08ld ", bucket_value);
3876 index = strlen(buf);
3879 sprintf(&buf[index], "\n");
3884 * Sysfs attribute to control the statistical data collection.
3886 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3887 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3890 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3894 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3897 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3898 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3899 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3903 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3905 * @kobj: Pointer to the kernel object
3906 * @bin_attr: Attribute object
3907 * @buff: Buffer pointer
3909 * @count: Buffer size
3911 * This function is the read call back function for lpfc_drvr_stat_data
3912 * sysfs file. This function export the statistical data to user
3916 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3917 struct bin_attribute *bin_attr,
3918 char *buf, loff_t off, size_t count)
3920 struct device *dev = container_of(kobj, struct device,
3922 struct Scsi_Host *shost = class_to_shost(dev);
3923 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3924 struct lpfc_hba *phba = vport->phba;
3925 int i = 0, index = 0;
3926 unsigned long nport_index;
3927 struct lpfc_nodelist *ndlp = NULL;
3928 nport_index = (unsigned long)off /
3929 MAX_STAT_DATA_SIZE_PER_TARGET;
3931 if (!vport->stat_data_enabled || vport->stat_data_blocked
3932 || (phba->bucket_type == LPFC_NO_BUCKET))
3935 spin_lock_irq(shost->host_lock);
3936 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3937 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3940 if (nport_index > 0) {
3945 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3949 if (!ndlp->lat_data)
3953 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3954 ndlp->nlp_portname.u.wwn[0],
3955 ndlp->nlp_portname.u.wwn[1],
3956 ndlp->nlp_portname.u.wwn[2],
3957 ndlp->nlp_portname.u.wwn[3],
3958 ndlp->nlp_portname.u.wwn[4],
3959 ndlp->nlp_portname.u.wwn[5],
3960 ndlp->nlp_portname.u.wwn[6],
3961 ndlp->nlp_portname.u.wwn[7]);
3963 index = strlen(buf);
3965 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3966 sprintf(&buf[index], "%010u,",
3967 ndlp->lat_data[i].cmd_count);
3968 index = strlen(buf);
3970 sprintf(&buf[index], "\n");
3971 index = strlen(buf);
3973 spin_unlock_irq(shost->host_lock);
3977 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3979 .name = "lpfc_drvr_stat_data",
3982 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3983 .read = sysfs_drvr_stat_data_read,
3988 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3990 # Value range is [0,16]. Default value is 0.
3993 * lpfc_link_speed_set - Set the adapters link speed
3994 * @phba: lpfc_hba pointer.
3995 * @val: link speed value.
3998 * If val is in a valid range then set the adapter's link speed field and
3999 * issue a lip; if the lip fails reset the link speed to the old value.
4002 * If the value is not in range log a kernel error message and return an error.
4005 * zero if val is in range and lip okay.
4006 * non-zero return value from lpfc_issue_lip()
4007 * -EINVAL val out of range
4010 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4011 const char *buf, size_t count)
4013 struct Scsi_Host *shost = class_to_shost(dev);
4014 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4015 struct lpfc_hba *phba = vport->phba;
4016 int val = LPFC_USER_LINK_SPEED_AUTO;
4018 const char *val_buf = buf;
4020 uint32_t prev_val, if_type;
4022 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4023 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4024 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4027 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4029 val_buf = &buf[strlen("nolip ")];
4032 if (!isdigit(val_buf[0]))
4034 if (sscanf(val_buf, "%i", &val) != 1)
4037 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4038 "3055 lpfc_link_speed changed from %d to %d %s\n",
4039 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4041 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4042 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4043 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4044 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4045 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4046 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4047 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
4048 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4049 "2879 lpfc_link_speed attribute cannot be set "
4050 "to %d. Speed is not supported by this port.\n",
4054 if (val == LPFC_USER_LINK_SPEED_16G &&
4055 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4056 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4057 "3112 lpfc_link_speed attribute cannot be set "
4058 "to %d. Speed is not supported in loop mode.\n",
4062 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4063 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4064 prev_val = phba->cfg_link_speed;
4065 phba->cfg_link_speed = val;
4069 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4071 phba->cfg_link_speed = prev_val;
4076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4077 "0469 lpfc_link_speed attribute cannot be set to %d, "
4078 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
4082 static int lpfc_link_speed = 0;
4083 module_param(lpfc_link_speed, int, S_IRUGO);
4084 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4085 lpfc_param_show(link_speed)
4088 * lpfc_link_speed_init - Set the adapters link speed
4089 * @phba: lpfc_hba pointer.
4090 * @val: link speed value.
4093 * If val is in a valid range then set the adapter's link speed field.
4096 * If the value is not in range log a kernel error message, clear the link
4097 * speed and return an error.
4100 * zero if val saved.
4101 * -EINVAL val out of range
4104 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4106 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4107 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4108 "3111 lpfc_link_speed of %d cannot "
4109 "support loop mode, setting topology to default.\n",
4111 phba->cfg_topology = 0;
4113 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4114 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4115 phba->cfg_link_speed = val;
4118 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4119 "0405 lpfc_link_speed attribute cannot "
4120 "be set to %d, allowed values are "
4121 "["LPFC_LINK_SPEED_STRING"]\n", val);
4122 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4126 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
4127 lpfc_link_speed_show, lpfc_link_speed_store);
4130 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4131 # 0 = aer disabled or not supported
4132 # 1 = aer supported and enabled (default)
4133 # Value range is [0,1]. Default value is 1.
4135 LPFC_ATTR(aer_support, 1, 0, 1,
4136 "Enable PCIe device AER support");
4137 lpfc_param_show(aer_support)
4140 * lpfc_aer_support_store - Set the adapter for aer support
4142 * @dev: class device that is converted into a Scsi_host.
4143 * @attr: device attribute, not used.
4144 * @buf: containing enable or disable aer flag.
4145 * @count: unused variable.
4148 * If the val is 1 and currently the device's AER capability was not
4149 * enabled, invoke the kernel's enable AER helper routine, trying to
4150 * enable the device's AER capability. If the helper routine enabling
4151 * AER returns success, update the device's cfg_aer_support flag to
4152 * indicate AER is supported by the device; otherwise, if the device
4153 * AER capability is already enabled to support AER, then do nothing.
4155 * If the val is 0 and currently the device's AER support was enabled,
4156 * invoke the kernel's disable AER helper routine. After that, update
4157 * the device's cfg_aer_support flag to indicate AER is not supported
4158 * by the device; otherwise, if the device AER capability is already
4159 * disabled from supporting AER, then do nothing.
4162 * length of the buf on success if val is in range the intended mode
4164 * -EINVAL if val out of range or intended mode is not supported.
4167 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4168 const char *buf, size_t count)
4170 struct Scsi_Host *shost = class_to_shost(dev);
4171 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4172 struct lpfc_hba *phba = vport->phba;
4173 int val = 0, rc = -EINVAL;
4175 if (!isdigit(buf[0]))
4177 if (sscanf(buf, "%i", &val) != 1)
4182 if (phba->hba_flag & HBA_AER_ENABLED) {
4183 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4185 spin_lock_irq(&phba->hbalock);
4186 phba->hba_flag &= ~HBA_AER_ENABLED;
4187 spin_unlock_irq(&phba->hbalock);
4188 phba->cfg_aer_support = 0;
4193 phba->cfg_aer_support = 0;
4198 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4199 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4201 spin_lock_irq(&phba->hbalock);
4202 phba->hba_flag |= HBA_AER_ENABLED;
4203 spin_unlock_irq(&phba->hbalock);
4204 phba->cfg_aer_support = 1;
4209 phba->cfg_aer_support = 1;
4220 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4221 lpfc_aer_support_show, lpfc_aer_support_store);
4224 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4225 * @dev: class device that is converted into a Scsi_host.
4226 * @attr: device attribute, not used.
4227 * @buf: containing flag 1 for aer cleanup state.
4228 * @count: unused variable.
4231 * If the @buf contains 1 and the device currently has the AER support
4232 * enabled, then invokes the kernel AER helper routine
4233 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4234 * error status register.
4239 * -EINVAL if the buf does not contain the 1 or the device is not currently
4240 * enabled with the AER support.
4243 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4244 const char *buf, size_t count)
4246 struct Scsi_Host *shost = class_to_shost(dev);
4247 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4248 struct lpfc_hba *phba = vport->phba;
4251 if (!isdigit(buf[0]))
4253 if (sscanf(buf, "%i", &val) != 1)
4258 if (phba->hba_flag & HBA_AER_ENABLED)
4259 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4267 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4268 lpfc_aer_cleanup_state);
4271 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4273 * @dev: class device that is converted into a Scsi_host.
4274 * @attr: device attribute, not used.
4275 * @buf: containing the string the number of vfs to be enabled.
4276 * @count: unused variable.
4279 * When this api is called either through user sysfs, the driver shall
4280 * try to enable or disable SR-IOV virtual functions according to the
4283 * If zero virtual function has been enabled to the physical function,
4284 * the driver shall invoke the pci enable virtual function api trying
4285 * to enable the virtual functions. If the nr_vfn provided is greater
4286 * than the maximum supported, the maximum virtual function number will
4287 * be used for invoking the api; otherwise, the nr_vfn provided shall
4288 * be used for invoking the api. If the api call returned success, the
4289 * actual number of virtual functions enabled will be set to the driver
4290 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4291 * cfg_sriov_nr_virtfn remains zero.
4293 * If none-zero virtual functions have already been enabled to the
4294 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4295 * -EINVAL will be returned and the driver does nothing;
4297 * If the nr_vfn provided is zero and none-zero virtual functions have
4298 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4299 * disabling virtual function api shall be invoded to disable all the
4300 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4301 * zero. Otherwise, if zero virtual function has been enabled, do
4305 * length of the buf on success if val is in range the intended mode
4307 * -EINVAL if val out of range or intended mode is not supported.
4310 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4311 const char *buf, size_t count)
4313 struct Scsi_Host *shost = class_to_shost(dev);
4314 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4315 struct lpfc_hba *phba = vport->phba;
4316 struct pci_dev *pdev = phba->pcidev;
4317 int val = 0, rc = -EINVAL;
4319 /* Sanity check on user data */
4320 if (!isdigit(buf[0]))
4322 if (sscanf(buf, "%i", &val) != 1)
4327 /* Request disabling virtual functions */
4329 if (phba->cfg_sriov_nr_virtfn > 0) {
4330 pci_disable_sriov(pdev);
4331 phba->cfg_sriov_nr_virtfn = 0;
4336 /* Request enabling virtual functions */
4337 if (phba->cfg_sriov_nr_virtfn > 0) {
4338 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4339 "3018 There are %d virtual functions "
4340 "enabled on physical function.\n",
4341 phba->cfg_sriov_nr_virtfn);
4345 if (val <= LPFC_MAX_VFN_PER_PFN)
4346 phba->cfg_sriov_nr_virtfn = val;
4348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4349 "3019 Enabling %d virtual functions is not "
4354 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4356 phba->cfg_sriov_nr_virtfn = 0;
4364 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4365 "Enable PCIe device SR-IOV virtual fn");
4367 lpfc_param_show(sriov_nr_virtfn)
4368 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4369 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4372 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4374 * @dev: class device that is converted into a Scsi_host.
4375 * @attr: device attribute, not used.
4376 * @buf: containing the string the number of vfs to be enabled.
4377 * @count: unused variable.
4382 * length of the buf on success if val is in range the intended mode
4384 * -EINVAL if val out of range or intended mode is not supported.
4387 lpfc_request_firmware_upgrade_store(struct device *dev,
4388 struct device_attribute *attr,
4389 const char *buf, size_t count)
4391 struct Scsi_Host *shost = class_to_shost(dev);
4392 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4393 struct lpfc_hba *phba = vport->phba;
4394 int val = 0, rc = -EINVAL;
4396 /* Sanity check on user data */
4397 if (!isdigit(buf[0]))
4399 if (sscanf(buf, "%i", &val) != 1)
4404 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4412 static int lpfc_req_fw_upgrade;
4413 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4414 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4415 lpfc_param_show(request_firmware_upgrade)
4418 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4419 * @phba: lpfc_hba pointer.
4423 * Set the initial Linux generic firmware upgrade enable or disable flag.
4426 * zero if val saved.
4427 * -EINVAL val out of range
4430 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4432 if (val >= 0 && val <= 1) {
4433 phba->cfg_request_firmware_upgrade = val;
4438 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4439 lpfc_request_firmware_upgrade_show,
4440 lpfc_request_firmware_upgrade_store);
4443 * lpfc_fcp_imax_store
4445 * @dev: class device that is converted into a Scsi_host.
4446 * @attr: device attribute, not used.
4447 * @buf: string with the number of fast-path FCP interrupts per second.
4448 * @count: unused variable.
4451 * If val is in a valid range [636,651042], then set the adapter's
4452 * maximum number of fast-path FCP interrupts per second.
4455 * length of the buf on success if val is in range the intended mode
4457 * -EINVAL if val out of range or intended mode is not supported.
4460 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4461 const char *buf, size_t count)
4463 struct Scsi_Host *shost = class_to_shost(dev);
4464 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4465 struct lpfc_hba *phba = vport->phba;
4468 /* fcp_imax is only valid for SLI4 */
4469 if (phba->sli_rev != LPFC_SLI_REV4)
4472 /* Sanity check on user data */
4473 if (!isdigit(buf[0]))
4475 if (sscanf(buf, "%i", &val) != 1)
4479 * Value range for the HBA is [5000,5000000]
4480 * The value for each EQ depends on how many EQs are configured.
4483 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4486 phba->cfg_fcp_imax = (uint32_t)val;
4487 phba->initial_imax = phba->cfg_fcp_imax;
4489 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4490 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4497 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4500 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4502 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4503 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4504 MODULE_PARM_DESC(lpfc_fcp_imax,
4505 "Set the maximum number of FCP interrupts per second per HBA");
4506 lpfc_param_show(fcp_imax)
4509 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4510 * @phba: lpfc_hba pointer.
4511 * @val: link speed value.
4514 * If val is in a valid range [636,651042], then initialize the adapter's
4515 * maximum number of fast-path FCP interrupts per second.
4518 * zero if val saved.
4519 * -EINVAL val out of range
4522 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4524 if (phba->sli_rev != LPFC_SLI_REV4) {
4525 phba->cfg_fcp_imax = 0;
4529 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4531 phba->cfg_fcp_imax = val;
4535 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4536 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4538 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4543 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4544 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4547 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4548 * 0 No auto_imax support
4550 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4551 * the EQ Delay Multiplier, depending on the activity for that EQ.
4552 * Value range [0,1]. Default value is 1.
4554 LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4557 * lpfc_state_show - Display current driver CPU affinity
4558 * @dev: class converted to a Scsi_host structure.
4559 * @attr: device attribute, not used.
4560 * @buf: on return contains text describing the state of the link.
4562 * Returns: size of formatted string.
4565 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4568 struct Scsi_Host *shost = class_to_shost(dev);
4569 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4570 struct lpfc_hba *phba = vport->phba;
4571 struct lpfc_vector_map_info *cpup;
4574 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4575 (phba->intr_type != MSIX))
4578 switch (phba->cfg_fcp_cpu_map) {
4580 len += snprintf(buf + len, PAGE_SIZE-len,
4581 "fcp_cpu_map: No mapping (%d)\n",
4582 phba->cfg_fcp_cpu_map);
4585 len += snprintf(buf + len, PAGE_SIZE-len,
4586 "fcp_cpu_map: HBA centric mapping (%d): "
4588 phba->cfg_fcp_cpu_map,
4589 phba->sli4_hba.num_online_cpu);
4592 len += snprintf(buf + len, PAGE_SIZE-len,
4593 "fcp_cpu_map: Driver centric mapping (%d): "
4595 phba->cfg_fcp_cpu_map,
4596 phba->sli4_hba.num_online_cpu);
4600 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4601 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4603 /* margin should fit in this and the truncated message */
4604 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4605 len += snprintf(buf + len, PAGE_SIZE-len,
4606 "CPU %02d io_chan %02d "
4607 "physid %d coreid %d\n",
4608 phba->sli4_hba.curr_disp_cpu,
4609 cpup->channel_id, cpup->phys_id,
4612 len += snprintf(buf + len, PAGE_SIZE-len,
4613 "CPU %02d io_chan %02d "
4614 "physid %d coreid %d IRQ %d\n",
4615 phba->sli4_hba.curr_disp_cpu,
4616 cpup->channel_id, cpup->phys_id,
4617 cpup->core_id, cpup->irq);
4619 phba->sli4_hba.curr_disp_cpu++;
4621 /* display max number of CPUs keeping some margin */
4622 if (phba->sli4_hba.curr_disp_cpu <
4623 phba->sli4_hba.num_present_cpu &&
4624 (len >= (PAGE_SIZE - 64))) {
4625 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4630 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4631 phba->sli4_hba.curr_disp_cpu = 0;
4637 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4638 * @dev: class device that is converted into a Scsi_host.
4639 * @attr: device attribute, not used.
4640 * @buf: one or more lpfc_polling_flags values.
4644 * -EINVAL - Not implemented yet.
4647 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4648 const char *buf, size_t count)
4650 int status = -EINVAL;
4655 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4658 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4659 # 0 - Do not affinitze IRQ vectors
4660 # 1 - Affintize HBA vectors with respect to each HBA
4661 # (start with CPU0 for each HBA)
4662 # 2 - Affintize HBA vectors with respect to the entire driver
4663 # (round robin thru all CPUs across all HBAs)
4665 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4666 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4667 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4668 "Defines how to map CPUs to IRQ vectors per HBA");
4671 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4672 * @phba: lpfc_hba pointer.
4673 * @val: link speed value.
4676 * If val is in a valid range [0-2], then affinitze the adapter's
4680 * zero if val saved.
4681 * -EINVAL val out of range
4684 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4686 if (phba->sli_rev != LPFC_SLI_REV4) {
4687 phba->cfg_fcp_cpu_map = 0;
4691 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4692 phba->cfg_fcp_cpu_map = val;
4696 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4697 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4699 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4704 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4705 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4708 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4709 # Value range is [2,3]. Default value is 3.
4711 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4712 "Select Fibre Channel class of service for FCP sequences");
4715 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4716 # is [0,1]. Default value is 0.
4718 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4719 "Use ADISC on rediscovery to authenticate FCP devices");
4722 # lpfc_first_burst_size: First burst size to use on the NPorts
4723 # that support first burst.
4724 # Value range is [0,65536]. Default value is 0.
4726 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4727 "First burst size for Targets that support first burst");
4730 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4731 * When the driver is configured as an NVME target, this value is
4732 * communicated to the NVME initiator in the PRLI response. It is
4733 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4734 * parameters are set and the target is sending the PRLI RSP.
4735 * Parameter supported on physical port only - no NPIV support.
4736 * Value range is [0,65536]. Default value is 0.
4738 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4739 "NVME Target mode first burst size in 512B increments.");
4742 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4743 * For the Initiator (I), enabling this parameter means that an NVMET
4744 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4745 * processed by the initiator for subsequent NVME FCP IO. For the target
4746 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4747 * driver parameter as the target function's first burst size returned to the
4748 * initiator in the target's NVME PRLI response. Parameter supported on physical
4749 * port only - no NPIV support.
4750 * Value range is [0,1]. Default value is 0 (disabled).
4752 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4753 "Enable First Burst feature on I and T functions.");
4756 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4757 # depth. Default value is 0. When the value of this parameter is zero the
4758 # SCSI command completion time is not used for controlling I/O queue depth. When
4759 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4760 # to limit the I/O completion time to the parameter value.
4761 # The value is set in milliseconds.
4763 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4764 "Use command completion time to control queue depth");
4766 lpfc_vport_param_show(max_scsicmpl_time);
4768 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4771 struct lpfc_nodelist *ndlp, *next_ndlp;
4773 if (val == vport->cfg_max_scsicmpl_time)
4775 if ((val < 0) || (val > 60000))
4777 vport->cfg_max_scsicmpl_time = val;
4779 spin_lock_irq(shost->host_lock);
4780 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4781 if (!NLP_CHK_NODE_ACT(ndlp))
4783 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4785 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4787 spin_unlock_irq(shost->host_lock);
4790 lpfc_vport_param_store(max_scsicmpl_time);
4791 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4792 lpfc_max_scsicmpl_time_show,
4793 lpfc_max_scsicmpl_time_store);
4796 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4797 # range is [0,1]. Default value is 0.
4799 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4802 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4803 * range is [0,1]. Default value is 0.
4804 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4805 * For [1], FCP commands are issued to a Work Queue associated with the
4808 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4809 * LPFC_FCP_SCHED_BY_CPU == 1
4811 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4812 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4813 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4814 * through WQs will be used.
4816 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4817 LPFC_FCP_SCHED_ROUND_ROBIN,
4818 LPFC_FCP_SCHED_BY_CPU,
4819 "Determine scheduling algorithm for "
4820 "issuing commands [0] - Round Robin, [1] - Current CPU");
4823 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4824 # range is [0,1]. Default value is 0.
4825 # For [0], bus reset issues target reset to ALL devices
4826 # For [1], bus reset issues target reset to non-FCP2 devices
4828 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4829 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4833 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4834 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4835 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4836 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4837 # cr_delay is set to 0.
4839 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4840 "interrupt response is generated");
4842 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4843 "interrupt response is generated");
4846 # lpfc_multi_ring_support: Determines how many rings to spread available
4847 # cmd/rsp IOCB entries across.
4848 # Value range is [1,2]. Default value is 1.
4850 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4851 "SLI rings to spread IOCB entries across");
4854 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4855 # identifies what rctl value to configure the additional ring for.
4856 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4858 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4859 255, "Identifies RCTL for additional ring configuration");
4862 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4863 # identifies what type value to configure the additional ring for.
4864 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4866 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4867 255, "Identifies TYPE for additional ring configuration");
4870 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4871 # 0 = SmartSAN functionality disabled (default)
4872 # 1 = SmartSAN functionality enabled
4873 # This parameter will override the value of lpfc_fdmi_on module parameter.
4874 # Value range is [0,1]. Default value is 0.
4876 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4879 # lpfc_fdmi_on: Controls FDMI support.
4880 # 0 No FDMI support (default)
4881 # 1 Traditional FDMI support
4882 # Traditional FDMI support means the driver will assume FDMI-2 support;
4883 # however, if that fails, it will fallback to FDMI-1.
4884 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4885 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4887 # Value range [0,1]. Default value is 0.
4889 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4892 # Specifies the maximum number of ELS cmds we can have outstanding (for
4893 # discovery). Value range is [1,64]. Default value = 32.
4895 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4896 "during discovery");
4899 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4900 # will be scanned by the SCSI midlayer when sequential scanning is
4901 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4902 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4903 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4904 # above. The lpfc driver limits the default value to 255 for two reasons.
4905 # As it bounds the sequential scan loop, scanning for thousands of luns
4906 # on a target can take minutes of wall clock time. Additionally,
4907 # there are FC targets, such as JBODs, that only recognize 8-bits of
4908 # LUN ID. When they receive a value greater than 8 bits, they chop off
4909 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4910 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4911 # valid responses at each of the LUN IDs, to believe there are multiple
4912 # devices present, when in fact, there is only 1.
4913 # A customer that is aware of their target behaviors, and the results as
4914 # indicated above, is welcome to increase the lpfc_max_luns value.
4915 # As mentioned, this value is not used by the lpfc driver, only the
4917 # Value range is [0,65535]. Default value is 255.
4918 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4920 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4923 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4924 # Value range is [1,255], default value is 10.
4926 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4927 "Milliseconds driver will wait between polling FCP ring");
4930 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4931 # to complete in seconds. Value range is [5,180], default value is 60.
4933 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4934 "Maximum time to wait for task management commands to complete");
4936 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4937 # support this feature
4940 # 2 = MSI-X enabled (default)
4941 # Value range is [0,2]. Default value is 2.
4943 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4944 "MSI-X (2), if possible");
4947 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4949 * 0 = NVME OAS disabled
4950 * 1 = NVME OAS enabled
4952 * Value range is [0,1]. Default value is 0.
4954 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4955 "Use OAS bit on NVME IOs");
4958 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4959 * will advertise it supports to the SCSI layer. This also will map to
4960 * the number of WQs the driver will create.
4962 * 0 = Configure the number of io channels to the number of active CPUs.
4963 * 1,32 = Manually specify how many io channels to use.
4965 * Value range is [0,32]. Default value is 4.
4967 LPFC_ATTR_R(fcp_io_channel,
4968 LPFC_FCP_IO_CHAN_DEF,
4969 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4970 "Set the number of FCP I/O channels");
4973 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4974 * will advertise it supports to the NVME layer. This also will map to
4975 * the number of WQs the driver will create.
4977 * This module parameter is valid when lpfc_enable_fc4_type is set
4980 * The NVME Layer will try to create this many, plus 1 administrative
4981 * hardware queue. The administrative queue will always map to WQ 0
4982 * A hardware IO queue maps (qidx) to a specific driver WQ.
4984 * 0 = Configure the number of io channels to the number of active CPUs.
4985 * 1,32 = Manually specify how many io channels to use.
4987 * Value range is [0,32]. Default value is 0.
4989 LPFC_ATTR_R(nvme_io_channel,
4990 LPFC_NVME_IO_CHAN_DEF,
4991 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4992 "Set the number of NVME I/O channels");
4995 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4996 # 0 = HBA resets disabled
4997 # 1 = HBA resets enabled (default)
4998 # Value range is [0,1]. Default value is 1.
5000 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
5003 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5004 # 0 = HBA Heartbeat disabled
5005 # 1 = HBA Heartbeat enabled (default)
5006 # Value range is [0,1]. Default value is 1.
5008 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5011 # lpfc_EnableXLane: Enable Express Lane Feature
5012 # 0x0 Express Lane Feature disabled
5013 # 0x1 Express Lane Feature enabled
5014 # Value range is [0,1]. Default value is 0.
5016 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5019 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5020 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5021 # Value range is [0x0,0x7f]. Default value is 0
5023 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5026 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5027 # 0 = BlockGuard disabled (default)
5028 # 1 = BlockGuard enabled
5029 # Value range is [0,1]. Default value is 0.
5031 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5034 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5035 # 0 = disabled (default)
5037 # Value range is [0,1]. Default value is 0.
5039 # This feature in under investigation and may be supported in the future.
5041 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5045 # - Bit mask of host protection capabilities used to register with the
5047 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5048 # - Allows you to ultimately specify which profiles to use
5049 # - Default will result in registering capabilities for all profiles.
5050 # - SHOST_DIF_TYPE1_PROTECTION 1
5051 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5052 # - SHOST_DIX_TYPE0_PROTECTION 8
5053 # HBA supports DIX Type 0: Host to HBA protection only
5054 # - SHOST_DIX_TYPE1_PROTECTION 16
5055 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5058 LPFC_ATTR(prot_mask,
5059 (SHOST_DIF_TYPE1_PROTECTION |
5060 SHOST_DIX_TYPE0_PROTECTION |
5061 SHOST_DIX_TYPE1_PROTECTION),
5063 (SHOST_DIF_TYPE1_PROTECTION |
5064 SHOST_DIX_TYPE0_PROTECTION |
5065 SHOST_DIX_TYPE1_PROTECTION),
5066 "T10-DIF host protection capabilities mask");
5069 # lpfc_prot_guard: i
5070 # - Bit mask of protection guard types to register with the SCSI mid-layer
5071 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5072 # - Allows you to ultimately specify which profiles to use
5073 # - Default will result in registering capabilities for all guard types
5076 LPFC_ATTR(prot_guard,
5077 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5078 "T10-DIF host protection guard type");
5081 * Delay initial NPort discovery when Clean Address bit is cleared in
5082 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5083 * This parameter can have value 0 or 1.
5084 * When this parameter is set to 0, no delay is added to the initial
5086 * When this parameter is set to non-zero value, initial Nport discovery is
5087 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5088 * accept and FCID/Fabric name/Fabric portname is changed.
5089 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5090 * when Clean Address bit is cleared in FLOGI/FDISC
5091 * accept and FCID/Fabric name/Fabric portname is changed.
5092 * Default value is 0.
5094 LPFC_ATTR(delay_discovery, 0, 0, 1,
5095 "Delay NPort discovery when Clean Address bit is cleared.");
5098 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5099 * This value can be set to values between 64 and 4096. The default value is
5100 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5101 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5102 * Because of the additional overhead involved in setting up T10-DIF,
5103 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5104 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5106 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5107 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5110 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5111 * 0 = MDS Diagnostics disabled (default)
5112 * 1 = MDS Diagnostics enabled
5113 * Value range is [0,1]. Default value is 0.
5115 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5117 struct device_attribute *lpfc_hba_attrs[] = {
5118 &dev_attr_nvme_info,
5120 &dev_attr_bg_guard_err,
5121 &dev_attr_bg_apptag_err,
5122 &dev_attr_bg_reftag_err,
5124 &dev_attr_serialnum,
5125 &dev_attr_modeldesc,
5126 &dev_attr_modelname,
5127 &dev_attr_programtype,
5131 &dev_attr_option_rom_version,
5132 &dev_attr_link_state,
5133 &dev_attr_num_discovered_ports,
5134 &dev_attr_menlo_mgmt_mode,
5135 &dev_attr_lpfc_drvr_version,
5136 &dev_attr_lpfc_enable_fip,
5137 &dev_attr_lpfc_temp_sensor,
5138 &dev_attr_lpfc_log_verbose,
5139 &dev_attr_lpfc_lun_queue_depth,
5140 &dev_attr_lpfc_tgt_queue_depth,
5141 &dev_attr_lpfc_hba_queue_depth,
5142 &dev_attr_lpfc_peer_port_login,
5143 &dev_attr_lpfc_nodev_tmo,
5144 &dev_attr_lpfc_devloss_tmo,
5145 &dev_attr_lpfc_enable_fc4_type,
5146 &dev_attr_lpfc_xri_split,
5147 &dev_attr_lpfc_fcp_class,
5148 &dev_attr_lpfc_use_adisc,
5149 &dev_attr_lpfc_first_burst_size,
5150 &dev_attr_lpfc_ack0,
5151 &dev_attr_lpfc_topology,
5152 &dev_attr_lpfc_scan_down,
5153 &dev_attr_lpfc_link_speed,
5154 &dev_attr_lpfc_fcp_io_sched,
5155 &dev_attr_lpfc_fcp2_no_tgt_reset,
5156 &dev_attr_lpfc_cr_delay,
5157 &dev_attr_lpfc_cr_count,
5158 &dev_attr_lpfc_multi_ring_support,
5159 &dev_attr_lpfc_multi_ring_rctl,
5160 &dev_attr_lpfc_multi_ring_type,
5161 &dev_attr_lpfc_fdmi_on,
5162 &dev_attr_lpfc_enable_SmartSAN,
5163 &dev_attr_lpfc_max_luns,
5164 &dev_attr_lpfc_enable_npiv,
5165 &dev_attr_lpfc_fcf_failover_policy,
5166 &dev_attr_lpfc_enable_rrq,
5167 &dev_attr_nport_evt_cnt,
5168 &dev_attr_board_mode,
5175 &dev_attr_npiv_info,
5176 &dev_attr_issue_reset,
5177 &dev_attr_lpfc_poll,
5178 &dev_attr_lpfc_poll_tmo,
5179 &dev_attr_lpfc_task_mgmt_tmo,
5180 &dev_attr_lpfc_use_msi,
5181 &dev_attr_lpfc_nvme_oas,
5182 &dev_attr_lpfc_auto_imax,
5183 &dev_attr_lpfc_fcp_imax,
5184 &dev_attr_lpfc_fcp_cpu_map,
5185 &dev_attr_lpfc_fcp_io_channel,
5186 &dev_attr_lpfc_suppress_rsp,
5187 &dev_attr_lpfc_nvme_io_channel,
5188 &dev_attr_lpfc_nvmet_mrq,
5189 &dev_attr_lpfc_nvme_enable_fb,
5190 &dev_attr_lpfc_nvmet_fb_size,
5191 &dev_attr_lpfc_enable_bg,
5192 &dev_attr_lpfc_soft_wwnn,
5193 &dev_attr_lpfc_soft_wwpn,
5194 &dev_attr_lpfc_soft_wwn_enable,
5195 &dev_attr_lpfc_enable_hba_reset,
5196 &dev_attr_lpfc_enable_hba_heartbeat,
5197 &dev_attr_lpfc_EnableXLane,
5198 &dev_attr_lpfc_XLanePriority,
5199 &dev_attr_lpfc_xlane_lun,
5200 &dev_attr_lpfc_xlane_tgt,
5201 &dev_attr_lpfc_xlane_vpt,
5202 &dev_attr_lpfc_xlane_lun_state,
5203 &dev_attr_lpfc_xlane_lun_status,
5204 &dev_attr_lpfc_xlane_priority,
5205 &dev_attr_lpfc_sg_seg_cnt,
5206 &dev_attr_lpfc_max_scsicmpl_time,
5207 &dev_attr_lpfc_stat_data_ctrl,
5208 &dev_attr_lpfc_aer_support,
5209 &dev_attr_lpfc_aer_state_cleanup,
5210 &dev_attr_lpfc_sriov_nr_virtfn,
5211 &dev_attr_lpfc_req_fw_upgrade,
5212 &dev_attr_lpfc_suppress_link_up,
5213 &dev_attr_lpfc_iocb_cnt,
5216 &dev_attr_txcmplq_hw,
5217 &dev_attr_lpfc_fips_level,
5218 &dev_attr_lpfc_fips_rev,
5220 &dev_attr_lpfc_sriov_hw_max_virtfn,
5222 &dev_attr_lpfc_xlane_supported,
5223 &dev_attr_lpfc_enable_mds_diags,
5227 struct device_attribute *lpfc_vport_attrs[] = {
5229 &dev_attr_link_state,
5230 &dev_attr_num_discovered_ports,
5231 &dev_attr_lpfc_drvr_version,
5232 &dev_attr_lpfc_log_verbose,
5233 &dev_attr_lpfc_lun_queue_depth,
5234 &dev_attr_lpfc_tgt_queue_depth,
5235 &dev_attr_lpfc_nodev_tmo,
5236 &dev_attr_lpfc_devloss_tmo,
5237 &dev_attr_lpfc_hba_queue_depth,
5238 &dev_attr_lpfc_peer_port_login,
5239 &dev_attr_lpfc_restrict_login,
5240 &dev_attr_lpfc_fcp_class,
5241 &dev_attr_lpfc_use_adisc,
5242 &dev_attr_lpfc_first_burst_size,
5243 &dev_attr_lpfc_max_luns,
5244 &dev_attr_nport_evt_cnt,
5245 &dev_attr_npiv_info,
5246 &dev_attr_lpfc_enable_da_id,
5247 &dev_attr_lpfc_max_scsicmpl_time,
5248 &dev_attr_lpfc_stat_data_ctrl,
5249 &dev_attr_lpfc_static_vport,
5250 &dev_attr_lpfc_fips_level,
5251 &dev_attr_lpfc_fips_rev,
5256 * sysfs_ctlreg_write - Write method for writing to ctlreg
5257 * @filp: open sysfs file
5258 * @kobj: kernel kobject that contains the kernel class device.
5259 * @bin_attr: kernel attributes passed to us.
5260 * @buf: contains the data to be written to the adapter IOREG space.
5261 * @off: offset into buffer to beginning of data.
5262 * @count: bytes to transfer.
5265 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5266 * Uses the adapter io control registers to send buf contents to the adapter.
5269 * -ERANGE off and count combo out of range
5270 * -EINVAL off, count or buff address invalid
5271 * -EPERM adapter is offline
5272 * value of count, buf contents written
5275 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5276 struct bin_attribute *bin_attr,
5277 char *buf, loff_t off, size_t count)
5280 struct device *dev = container_of(kobj, struct device, kobj);
5281 struct Scsi_Host *shost = class_to_shost(dev);
5282 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5283 struct lpfc_hba *phba = vport->phba;
5285 if (phba->sli_rev >= LPFC_SLI_REV4)
5288 if ((off + count) > FF_REG_AREA_SIZE)
5291 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5294 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5297 /* This is to protect HBA registers from accidental writes. */
5298 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5301 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5304 spin_lock_irq(&phba->hbalock);
5305 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5306 buf_off += sizeof(uint32_t))
5307 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5308 phba->ctrl_regs_memmap_p + off + buf_off);
5310 spin_unlock_irq(&phba->hbalock);
5316 * sysfs_ctlreg_read - Read method for reading from ctlreg
5317 * @filp: open sysfs file
5318 * @kobj: kernel kobject that contains the kernel class device.
5319 * @bin_attr: kernel attributes passed to us.
5320 * @buf: if successful contains the data from the adapter IOREG space.
5321 * @off: offset into buffer to beginning of data.
5322 * @count: bytes to transfer.
5325 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5326 * Uses the adapter io control registers to read data into buf.
5329 * -ERANGE off and count combo out of range
5330 * -EINVAL off, count or buff address invalid
5331 * value of count, buf contents read
5334 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5335 struct bin_attribute *bin_attr,
5336 char *buf, loff_t off, size_t count)
5340 struct device *dev = container_of(kobj, struct device, kobj);
5341 struct Scsi_Host *shost = class_to_shost(dev);
5342 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5343 struct lpfc_hba *phba = vport->phba;
5345 if (phba->sli_rev >= LPFC_SLI_REV4)
5348 if (off > FF_REG_AREA_SIZE)
5351 if ((off + count) > FF_REG_AREA_SIZE)
5352 count = FF_REG_AREA_SIZE - off;
5354 if (count == 0) return 0;
5356 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5359 spin_lock_irq(&phba->hbalock);
5361 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5362 tmp_ptr = (uint32_t *)(buf + buf_off);
5363 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5366 spin_unlock_irq(&phba->hbalock);
5371 static struct bin_attribute sysfs_ctlreg_attr = {
5374 .mode = S_IRUSR | S_IWUSR,
5377 .read = sysfs_ctlreg_read,
5378 .write = sysfs_ctlreg_write,
5382 * sysfs_mbox_write - Write method for writing information via mbox
5383 * @filp: open sysfs file
5384 * @kobj: kernel kobject that contains the kernel class device.
5385 * @bin_attr: kernel attributes passed to us.
5386 * @buf: contains the data to be written to sysfs mbox.
5387 * @off: offset into buffer to beginning of data.
5388 * @count: bytes to transfer.
5391 * Deprecated function. All mailbox access from user space is performed via the
5395 * -EPERM operation not permitted
5398 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5399 struct bin_attribute *bin_attr,
5400 char *buf, loff_t off, size_t count)
5406 * sysfs_mbox_read - Read method for reading information via mbox
5407 * @filp: open sysfs file
5408 * @kobj: kernel kobject that contains the kernel class device.
5409 * @bin_attr: kernel attributes passed to us.
5410 * @buf: contains the data to be read from sysfs mbox.
5411 * @off: offset into buffer to beginning of data.
5412 * @count: bytes to transfer.
5415 * Deprecated function. All mailbox access from user space is performed via the
5419 * -EPERM operation not permitted
5422 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5423 struct bin_attribute *bin_attr,
5424 char *buf, loff_t off, size_t count)
5429 static struct bin_attribute sysfs_mbox_attr = {
5432 .mode = S_IRUSR | S_IWUSR,
5434 .size = MAILBOX_SYSFS_MAX,
5435 .read = sysfs_mbox_read,
5436 .write = sysfs_mbox_write,
5440 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5441 * @vport: address of lpfc vport structure.
5445 * error return code from sysfs_create_bin_file()
5448 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5450 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5453 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5454 &sysfs_drvr_stat_data_attr);
5456 /* Virtual ports do not need ctrl_reg and mbox */
5457 if (error || vport->port_type == LPFC_NPIV_PORT)
5460 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5461 &sysfs_ctlreg_attr);
5463 goto out_remove_stat_attr;
5465 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5468 goto out_remove_ctlreg_attr;
5471 out_remove_ctlreg_attr:
5472 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5473 out_remove_stat_attr:
5474 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5475 &sysfs_drvr_stat_data_attr);
5481 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5482 * @vport: address of lpfc vport structure.
5485 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5488 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5489 &sysfs_drvr_stat_data_attr);
5490 /* Virtual ports do not need ctrl_reg and mbox */
5491 if (vport->port_type == LPFC_NPIV_PORT)
5493 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5494 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5498 * Dynamic FC Host Attributes Support
5502 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5503 * @shost: kernel scsi host pointer.
5506 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5508 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5510 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5511 sizeof fc_host_symbolic_name(shost));
5515 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5516 * @shost: kernel scsi host pointer.
5519 lpfc_get_host_port_id(struct Scsi_Host *shost)
5521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5523 /* note: fc_myDID already in cpu endianness */
5524 fc_host_port_id(shost) = vport->fc_myDID;
5528 * lpfc_get_host_port_type - Set the value of the scsi host port type
5529 * @shost: kernel scsi host pointer.
5532 lpfc_get_host_port_type(struct Scsi_Host *shost)
5534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5535 struct lpfc_hba *phba = vport->phba;
5537 spin_lock_irq(shost->host_lock);
5539 if (vport->port_type == LPFC_NPIV_PORT) {
5540 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5541 } else if (lpfc_is_link_up(phba)) {
5542 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5543 if (vport->fc_flag & FC_PUBLIC_LOOP)
5544 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5546 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5548 if (vport->fc_flag & FC_FABRIC)
5549 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5551 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5554 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5556 spin_unlock_irq(shost->host_lock);
5560 * lpfc_get_host_port_state - Set the value of the scsi host port state
5561 * @shost: kernel scsi host pointer.
5564 lpfc_get_host_port_state(struct Scsi_Host *shost)
5566 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5567 struct lpfc_hba *phba = vport->phba;
5569 spin_lock_irq(shost->host_lock);
5571 if (vport->fc_flag & FC_OFFLINE_MODE)
5572 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5574 switch (phba->link_state) {
5575 case LPFC_LINK_UNKNOWN:
5576 case LPFC_LINK_DOWN:
5577 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5581 case LPFC_HBA_READY:
5582 /* Links up, reports port state accordingly */
5583 if (vport->port_state < LPFC_VPORT_READY)
5584 fc_host_port_state(shost) =
5585 FC_PORTSTATE_BYPASSED;
5587 fc_host_port_state(shost) =
5588 FC_PORTSTATE_ONLINE;
5590 case LPFC_HBA_ERROR:
5591 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5594 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5599 spin_unlock_irq(shost->host_lock);
5603 * lpfc_get_host_speed - Set the value of the scsi host speed
5604 * @shost: kernel scsi host pointer.
5607 lpfc_get_host_speed(struct Scsi_Host *shost)
5609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5610 struct lpfc_hba *phba = vport->phba;
5612 spin_lock_irq(shost->host_lock);
5614 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5615 switch(phba->fc_linkspeed) {
5616 case LPFC_LINK_SPEED_1GHZ:
5617 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5619 case LPFC_LINK_SPEED_2GHZ:
5620 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5622 case LPFC_LINK_SPEED_4GHZ:
5623 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5625 case LPFC_LINK_SPEED_8GHZ:
5626 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5628 case LPFC_LINK_SPEED_10GHZ:
5629 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5631 case LPFC_LINK_SPEED_16GHZ:
5632 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5634 case LPFC_LINK_SPEED_32GHZ:
5635 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5638 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5642 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5644 spin_unlock_irq(shost->host_lock);
5648 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5649 * @shost: kernel scsi host pointer.
5652 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5654 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5655 struct lpfc_hba *phba = vport->phba;
5658 spin_lock_irq(shost->host_lock);
5660 if ((vport->port_state > LPFC_FLOGI) &&
5661 ((vport->fc_flag & FC_FABRIC) ||
5662 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5663 (vport->fc_flag & FC_PUBLIC_LOOP))))
5664 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5666 /* fabric is local port if there is no F/FL_Port */
5669 spin_unlock_irq(shost->host_lock);
5671 fc_host_fabric_name(shost) = node_name;
5675 * lpfc_get_stats - Return statistical information about the adapter
5676 * @shost: kernel scsi host pointer.
5679 * NULL on error for link down, no mbox pool, sli2 active,
5680 * management not allowed, memory allocation error, or mbox error.
5684 * address of the adapter host statistics
5686 static struct fc_host_statistics *
5687 lpfc_get_stats(struct Scsi_Host *shost)
5689 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5690 struct lpfc_hba *phba = vport->phba;
5691 struct lpfc_sli *psli = &phba->sli;
5692 struct fc_host_statistics *hs = &phba->link_stats;
5693 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5694 LPFC_MBOXQ_t *pmboxq;
5696 unsigned long seconds;
5700 * prevent udev from issuing mailbox commands until the port is
5703 if (phba->link_state < LPFC_LINK_DOWN ||
5704 !phba->mbox_mem_pool ||
5705 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5708 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5711 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5714 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5716 pmb = &pmboxq->u.mb;
5717 pmb->mbxCommand = MBX_READ_STATUS;
5718 pmb->mbxOwner = OWN_HOST;
5719 pmboxq->context1 = NULL;
5720 pmboxq->vport = vport;
5722 if (vport->fc_flag & FC_OFFLINE_MODE)
5723 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5725 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5727 if (rc != MBX_SUCCESS) {
5728 if (rc != MBX_TIMEOUT)
5729 mempool_free(pmboxq, phba->mbox_mem_pool);
5733 memset(hs, 0, sizeof (struct fc_host_statistics));
5735 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5737 * The MBX_READ_STATUS returns tx_k_bytes which has to
5738 * converted to words
5740 hs->tx_words = (uint64_t)
5741 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5743 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5744 hs->rx_words = (uint64_t)
5745 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5748 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5749 pmb->mbxCommand = MBX_READ_LNK_STAT;
5750 pmb->mbxOwner = OWN_HOST;
5751 pmboxq->context1 = NULL;
5752 pmboxq->vport = vport;
5754 if (vport->fc_flag & FC_OFFLINE_MODE)
5755 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5757 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5759 if (rc != MBX_SUCCESS) {
5760 if (rc != MBX_TIMEOUT)
5761 mempool_free(pmboxq, phba->mbox_mem_pool);
5765 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5766 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5767 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5768 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5769 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5770 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5771 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5773 hs->link_failure_count -= lso->link_failure_count;
5774 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5775 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5776 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5777 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5778 hs->invalid_crc_count -= lso->invalid_crc_count;
5779 hs->error_frames -= lso->error_frames;
5781 if (phba->hba_flag & HBA_FCOE_MODE) {
5783 hs->nos_count = (phba->link_events >> 1);
5784 hs->nos_count -= lso->link_events;
5785 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5786 hs->lip_count = (phba->fc_eventTag >> 1);
5787 hs->lip_count -= lso->link_events;
5791 hs->nos_count = (phba->fc_eventTag >> 1);
5792 hs->nos_count -= lso->link_events;
5795 hs->dumped_frames = -1;
5797 seconds = get_seconds();
5798 if (seconds < psli->stats_start)
5799 hs->seconds_since_last_reset = seconds +
5800 ((unsigned long)-1 - psli->stats_start);
5802 hs->seconds_since_last_reset = seconds - psli->stats_start;
5804 mempool_free(pmboxq, phba->mbox_mem_pool);
5810 * lpfc_reset_stats - Copy the adapter link stats information
5811 * @shost: kernel scsi host pointer.
5814 lpfc_reset_stats(struct Scsi_Host *shost)
5816 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5817 struct lpfc_hba *phba = vport->phba;
5818 struct lpfc_sli *psli = &phba->sli;
5819 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5820 LPFC_MBOXQ_t *pmboxq;
5824 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5827 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5830 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5832 pmb = &pmboxq->u.mb;
5833 pmb->mbxCommand = MBX_READ_STATUS;
5834 pmb->mbxOwner = OWN_HOST;
5835 pmb->un.varWords[0] = 0x1; /* reset request */
5836 pmboxq->context1 = NULL;
5837 pmboxq->vport = vport;
5839 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5840 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5841 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5843 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5845 if (rc != MBX_SUCCESS) {
5846 if (rc != MBX_TIMEOUT)
5847 mempool_free(pmboxq, phba->mbox_mem_pool);
5851 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5852 pmb->mbxCommand = MBX_READ_LNK_STAT;
5853 pmb->mbxOwner = OWN_HOST;
5854 pmboxq->context1 = NULL;
5855 pmboxq->vport = vport;
5857 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5858 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5859 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5861 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5863 if (rc != MBX_SUCCESS) {
5864 if (rc != MBX_TIMEOUT)
5865 mempool_free( pmboxq, phba->mbox_mem_pool);
5869 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5870 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5871 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5872 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5873 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5874 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5875 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5876 if (phba->hba_flag & HBA_FCOE_MODE)
5877 lso->link_events = (phba->link_events >> 1);
5879 lso->link_events = (phba->fc_eventTag >> 1);
5881 psli->stats_start = get_seconds();
5883 mempool_free(pmboxq, phba->mbox_mem_pool);
5889 * The LPFC driver treats linkdown handling as target loss events so there
5890 * are no sysfs handlers for link_down_tmo.
5894 * lpfc_get_node_by_target - Return the nodelist for a target
5895 * @starget: kernel scsi target pointer.
5898 * address of the node list if found
5899 * NULL target not found
5901 static struct lpfc_nodelist *
5902 lpfc_get_node_by_target(struct scsi_target *starget)
5904 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5905 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5906 struct lpfc_nodelist *ndlp;
5908 spin_lock_irq(shost->host_lock);
5909 /* Search for this, mapped, target ID */
5910 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5911 if (NLP_CHK_NODE_ACT(ndlp) &&
5912 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5913 starget->id == ndlp->nlp_sid) {
5914 spin_unlock_irq(shost->host_lock);
5918 spin_unlock_irq(shost->host_lock);
5923 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5924 * @starget: kernel scsi target pointer.
5927 lpfc_get_starget_port_id(struct scsi_target *starget)
5929 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5931 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5935 * lpfc_get_starget_node_name - Set the target node name
5936 * @starget: kernel scsi target pointer.
5938 * Description: Set the target node name to the ndlp node name wwn or zero.
5941 lpfc_get_starget_node_name(struct scsi_target *starget)
5943 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5945 fc_starget_node_name(starget) =
5946 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5950 * lpfc_get_starget_port_name - Set the target port name
5951 * @starget: kernel scsi target pointer.
5953 * Description: set the target port name to the ndlp port name wwn or zero.
5956 lpfc_get_starget_port_name(struct scsi_target *starget)
5958 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5960 fc_starget_port_name(starget) =
5961 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5965 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5966 * @rport: fc rport address.
5967 * @timeout: new value for dev loss tmo.
5970 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5971 * dev_loss_tmo to one.
5974 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5977 rport->dev_loss_tmo = timeout;
5979 rport->dev_loss_tmo = 1;
5983 * lpfc_rport_show_function - Return rport target information
5986 * Macro that uses field to generate a function with the name lpfc_show_rport_
5988 * lpfc_show_rport_##field: returns the bytes formatted in buf
5989 * @cdev: class converted to an fc_rport.
5990 * @buf: on return contains the target_field or zero.
5992 * Returns: size of formatted string.
5994 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5996 lpfc_show_rport_##field (struct device *dev, \
5997 struct device_attribute *attr, \
6000 struct fc_rport *rport = transport_class_to_rport(dev); \
6001 struct lpfc_rport_data *rdata = rport->hostdata; \
6002 return snprintf(buf, sz, format_string, \
6003 (rdata->target) ? cast rdata->target->field : 0); \
6006 #define lpfc_rport_rd_attr(field, format_string, sz) \
6007 lpfc_rport_show_function(field, format_string, sz, ) \
6008 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6011 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6012 * @fc_vport: The fc_vport who's symbolic name has been changed.
6015 * This function is called by the transport after the @fc_vport's symbolic name
6016 * has been changed. This function re-registers the symbolic name with the
6017 * switch to propagate the change into the fabric if the vport is active.
6020 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6022 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6024 if (vport->port_state == LPFC_VPORT_READY)
6025 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6029 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6030 * @phba: Pointer to lpfc_hba struct.
6032 * This function is called by the lpfc_get_cfgparam() routine to set the
6033 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6034 * log message according to the module's lpfc_log_verbose parameter setting
6035 * before hba port or vport created.
6038 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6040 phba->cfg_log_verbose = verbose;
6043 struct fc_function_template lpfc_transport_functions = {
6044 /* fixed attributes the driver supports */
6045 .show_host_node_name = 1,
6046 .show_host_port_name = 1,
6047 .show_host_supported_classes = 1,
6048 .show_host_supported_fc4s = 1,
6049 .show_host_supported_speeds = 1,
6050 .show_host_maxframe_size = 1,
6052 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6053 .show_host_symbolic_name = 1,
6055 /* dynamic attributes the driver supports */
6056 .get_host_port_id = lpfc_get_host_port_id,
6057 .show_host_port_id = 1,
6059 .get_host_port_type = lpfc_get_host_port_type,
6060 .show_host_port_type = 1,
6062 .get_host_port_state = lpfc_get_host_port_state,
6063 .show_host_port_state = 1,
6065 /* active_fc4s is shown but doesn't change (thus no get function) */
6066 .show_host_active_fc4s = 1,
6068 .get_host_speed = lpfc_get_host_speed,
6069 .show_host_speed = 1,
6071 .get_host_fabric_name = lpfc_get_host_fabric_name,
6072 .show_host_fabric_name = 1,
6075 * The LPFC driver treats linkdown handling as target loss events
6076 * so there are no sysfs handlers for link_down_tmo.
6079 .get_fc_host_stats = lpfc_get_stats,
6080 .reset_fc_host_stats = lpfc_reset_stats,
6082 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6083 .show_rport_maxframe_size = 1,
6084 .show_rport_supported_classes = 1,
6086 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6087 .show_rport_dev_loss_tmo = 1,
6089 .get_starget_port_id = lpfc_get_starget_port_id,
6090 .show_starget_port_id = 1,
6092 .get_starget_node_name = lpfc_get_starget_node_name,
6093 .show_starget_node_name = 1,
6095 .get_starget_port_name = lpfc_get_starget_port_name,
6096 .show_starget_port_name = 1,
6098 .issue_fc_host_lip = lpfc_issue_lip,
6099 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6100 .terminate_rport_io = lpfc_terminate_rport_io,
6102 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6104 .vport_disable = lpfc_vport_disable,
6106 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6108 .bsg_request = lpfc_bsg_request,
6109 .bsg_timeout = lpfc_bsg_timeout,
6112 struct fc_function_template lpfc_vport_transport_functions = {
6113 /* fixed attributes the driver supports */
6114 .show_host_node_name = 1,
6115 .show_host_port_name = 1,
6116 .show_host_supported_classes = 1,
6117 .show_host_supported_fc4s = 1,
6118 .show_host_supported_speeds = 1,
6119 .show_host_maxframe_size = 1,
6121 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6122 .show_host_symbolic_name = 1,
6124 /* dynamic attributes the driver supports */
6125 .get_host_port_id = lpfc_get_host_port_id,
6126 .show_host_port_id = 1,
6128 .get_host_port_type = lpfc_get_host_port_type,
6129 .show_host_port_type = 1,
6131 .get_host_port_state = lpfc_get_host_port_state,
6132 .show_host_port_state = 1,
6134 /* active_fc4s is shown but doesn't change (thus no get function) */
6135 .show_host_active_fc4s = 1,
6137 .get_host_speed = lpfc_get_host_speed,
6138 .show_host_speed = 1,
6140 .get_host_fabric_name = lpfc_get_host_fabric_name,
6141 .show_host_fabric_name = 1,
6144 * The LPFC driver treats linkdown handling as target loss events
6145 * so there are no sysfs handlers for link_down_tmo.
6148 .get_fc_host_stats = lpfc_get_stats,
6149 .reset_fc_host_stats = lpfc_reset_stats,
6151 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6152 .show_rport_maxframe_size = 1,
6153 .show_rport_supported_classes = 1,
6155 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6156 .show_rport_dev_loss_tmo = 1,
6158 .get_starget_port_id = lpfc_get_starget_port_id,
6159 .show_starget_port_id = 1,
6161 .get_starget_node_name = lpfc_get_starget_node_name,
6162 .show_starget_node_name = 1,
6164 .get_starget_port_name = lpfc_get_starget_port_name,
6165 .show_starget_port_name = 1,
6167 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6168 .terminate_rport_io = lpfc_terminate_rport_io,
6170 .vport_disable = lpfc_vport_disable,
6172 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6176 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6177 * @phba: lpfc_hba pointer.
6180 lpfc_get_cfgparam(struct lpfc_hba *phba)
6182 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6183 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6184 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6185 lpfc_cr_count_init(phba, lpfc_cr_count);
6186 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6187 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6188 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6189 lpfc_ack0_init(phba, lpfc_ack0);
6190 lpfc_topology_init(phba, lpfc_topology);
6191 lpfc_link_speed_init(phba, lpfc_link_speed);
6192 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6193 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6194 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6195 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6196 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6197 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6198 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6199 lpfc_use_msi_init(phba, lpfc_use_msi);
6200 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6201 lpfc_auto_imax_init(phba, lpfc_auto_imax);
6202 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6203 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6204 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6205 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6207 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6208 if (phba->sli_rev != LPFC_SLI_REV4)
6209 phba->cfg_EnableXLane = 0;
6210 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6212 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6213 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6214 phba->cfg_oas_lun_state = 0;
6215 phba->cfg_oas_lun_status = 0;
6216 phba->cfg_oas_flags = 0;
6217 phba->cfg_oas_priority = 0;
6218 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6219 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6220 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6221 if (phba->sli_rev == LPFC_SLI_REV4)
6224 phba->cfg_poll = lpfc_poll;
6225 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6227 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6228 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6230 /* Initialize first burst. Target vs Initiator are different. */
6231 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6232 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6233 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6234 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6236 if (phba->sli_rev != LPFC_SLI_REV4) {
6237 /* NVME only supported on SLI4 */
6238 phba->nvmet_support = 0;
6239 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6241 /* We MUST have FCP support */
6242 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6243 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6246 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6247 phba->cfg_auto_imax = 0;
6248 phba->initial_imax = phba->cfg_fcp_imax;
6250 /* A value of 0 means use the number of CPUs found in the system */
6251 if (phba->cfg_fcp_io_channel == 0)
6252 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6253 if (phba->cfg_nvme_io_channel == 0)
6254 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6256 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6257 phba->cfg_fcp_io_channel = 0;
6259 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6260 phba->cfg_nvme_io_channel = 0;
6262 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6263 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6265 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6267 phba->cfg_soft_wwnn = 0L;
6268 phba->cfg_soft_wwpn = 0L;
6269 lpfc_xri_split_init(phba, lpfc_xri_split);
6270 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6271 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6272 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6273 lpfc_aer_support_init(phba, lpfc_aer_support);
6274 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6275 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6276 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6277 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6278 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6279 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6280 phba->cfg_enable_dss = 1;
6281 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6286 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6287 * dependencies between protocols and roles.
6288 * @phba: lpfc_hba pointer.
6291 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6293 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6294 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6296 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6297 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6299 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6300 phba->nvmet_support) {
6301 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6302 phba->cfg_fcp_io_channel = 0;
6304 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6305 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6306 "NVME Target PRLI ACC enable_fb ",
6307 phba->cfg_nvme_enable_fb,
6308 phba->cfg_nvmet_fb_size,
6309 LPFC_NVMET_FB_SZ_MAX);
6311 if (phba->cfg_nvme_enable_fb == 0)
6312 phba->cfg_nvmet_fb_size = 0;
6314 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6315 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6318 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6319 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6320 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6321 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6322 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6323 phba->cfg_nvmet_mrq);
6326 /* Not NVME Target mode. Turn off Target parameters. */
6327 phba->nvmet_support = 0;
6328 phba->cfg_nvmet_mrq = 0;
6329 phba->cfg_nvmet_fb_size = 0;
6332 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6333 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6335 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6339 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6340 * @vport: lpfc_vport pointer.
6343 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6345 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6346 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6347 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6348 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6349 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6350 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6351 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6352 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6353 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6354 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6355 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6356 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6357 lpfc_max_luns_init(vport, lpfc_max_luns);
6358 lpfc_scan_down_init(vport, lpfc_scan_down);
6359 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);