1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/ctype.h>
25 #include <linux/delay.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/aer.h>
30 #include <linux/gfp.h>
31 #include <linux/kernel.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_tcq.h>
37 #include <scsi/scsi_transport_fc.h>
38 #include <scsi/fc/fc_fs.h>
40 #include <linux/nvme-fc-driver.h>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_nvmet.h"
52 #include "lpfc_logmsg.h"
53 #include "lpfc_version.h"
54 #include "lpfc_compat.h"
55 #include "lpfc_crtn.h"
56 #include "lpfc_vport.h"
57 #include "lpfc_attr.h"
59 #define LPFC_DEF_DEVLOSS_TMO 30
60 #define LPFC_MIN_DEVLOSS_TMO 1
61 #define LPFC_MAX_DEVLOSS_TMO 255
63 #define LPFC_DEF_MRQ_POST 512
64 #define LPFC_MIN_MRQ_POST 512
65 #define LPFC_MAX_MRQ_POST 2048
68 * Write key size should be multiple of 4. If write key is changed
69 * make sure that library write key is also changed.
71 #define LPFC_REG_WRITE_KEY_SIZE 4
72 #define LPFC_REG_WRITE_KEY "EMLX"
75 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
76 * @incr: integer to convert.
77 * @hdw: ascii string holding converted integer plus a string terminator.
80 * JEDEC Joint Electron Device Engineering Council.
81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
82 * character string. The string is then terminated with a NULL in byte 9.
83 * Hex 0-9 becomes ascii '0' to '9'.
84 * Hex a-f becomes ascii '=' to 'B' capital B.
87 * Coded for 32 bit integers only.
90 lpfc_jedec_to_ascii(int incr, char hdw[])
93 for (i = 0; i < 8; i++) {
96 hdw[7 - i] = 0x30 + j;
98 hdw[7 - i] = 0x61 + j - 10;
106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
107 * @dev: class unused variable.
108 * @attr: device attribute, not used.
109 * @buf: on return contains the module description text.
111 * Returns: size of formatted string.
114 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
126 * Returns: size of formatted string.
129 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
139 return snprintf(buf, PAGE_SIZE, "0\n");
143 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = shost_priv(shost);
148 struct lpfc_hba *phba = vport->phba;
149 struct lpfc_nvmet_tgtport *tgtp;
150 struct nvme_fc_local_port *localport;
151 struct lpfc_nvme_lport *lport;
152 struct lpfc_nvme_rport *rport;
153 struct nvme_fc_remote_port *nrport;
157 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
158 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
161 if (phba->nvmet_support) {
162 if (!phba->targetport) {
163 len = snprintf(buf, PAGE_SIZE,
164 "NVME Target: x%llx is not allocated\n",
165 wwn_to_u64(vport->fc_portname.u.wwn));
168 /* Port state is only one of two values for now. */
169 if (phba->targetport->port_id)
170 statep = "REGISTERED";
173 len += snprintf(buf + len, PAGE_SIZE - len,
174 "NVME Target: Enabled State %s\n",
176 len += snprintf(buf + len, PAGE_SIZE - len,
177 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
180 wwn_to_u64(vport->fc_portname.u.wwn),
181 wwn_to_u64(vport->fc_nodename.u.wwn),
182 phba->targetport->port_id);
184 len += snprintf(buf + len, PAGE_SIZE - len,
185 "\nNVME Target: Statistics\n");
186 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
187 len += snprintf(buf+len, PAGE_SIZE-len,
188 "LS: Rcv %08x Drop %08x Abort %08x\n",
189 atomic_read(&tgtp->rcv_ls_req_in),
190 atomic_read(&tgtp->rcv_ls_req_drop),
191 atomic_read(&tgtp->xmt_ls_abort));
192 if (atomic_read(&tgtp->rcv_ls_req_in) !=
193 atomic_read(&tgtp->rcv_ls_req_out)) {
194 len += snprintf(buf+len, PAGE_SIZE-len,
195 "Rcv LS: in %08x != out %08x\n",
196 atomic_read(&tgtp->rcv_ls_req_in),
197 atomic_read(&tgtp->rcv_ls_req_out));
200 len += snprintf(buf+len, PAGE_SIZE-len,
201 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
202 atomic_read(&tgtp->xmt_ls_rsp),
203 atomic_read(&tgtp->xmt_ls_drop),
204 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
205 atomic_read(&tgtp->xmt_ls_rsp_error));
207 len += snprintf(buf+len, PAGE_SIZE-len,
208 "FCP: Rcv %08x Release %08x Drop %08x\n",
209 atomic_read(&tgtp->rcv_fcp_cmd_in),
210 atomic_read(&tgtp->xmt_fcp_release),
211 atomic_read(&tgtp->rcv_fcp_cmd_drop));
213 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
214 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
215 len += snprintf(buf+len, PAGE_SIZE-len,
216 "Rcv FCP: in %08x != out %08x\n",
217 atomic_read(&tgtp->rcv_fcp_cmd_in),
218 atomic_read(&tgtp->rcv_fcp_cmd_out));
221 len += snprintf(buf+len, PAGE_SIZE-len,
222 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
224 atomic_read(&tgtp->xmt_fcp_read),
225 atomic_read(&tgtp->xmt_fcp_read_rsp),
226 atomic_read(&tgtp->xmt_fcp_write),
227 atomic_read(&tgtp->xmt_fcp_rsp),
228 atomic_read(&tgtp->xmt_fcp_drop));
230 len += snprintf(buf+len, PAGE_SIZE-len,
231 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
232 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
233 atomic_read(&tgtp->xmt_fcp_rsp_error),
234 atomic_read(&tgtp->xmt_fcp_rsp_drop));
236 len += snprintf(buf+len, PAGE_SIZE-len,
237 "ABORT: Xmt %08x Cmpl %08x\n",
238 atomic_read(&tgtp->xmt_fcp_abort),
239 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
241 len += snprintf(buf + len, PAGE_SIZE - len,
242 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
243 atomic_read(&tgtp->xmt_abort_sol),
244 atomic_read(&tgtp->xmt_abort_unsol),
245 atomic_read(&tgtp->xmt_abort_rsp),
246 atomic_read(&tgtp->xmt_abort_rsp_error));
248 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
252 localport = vport->localport;
254 len = snprintf(buf, PAGE_SIZE,
255 "NVME Initiator x%llx is not allocated\n",
256 wwn_to_u64(vport->fc_portname.u.wwn));
259 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
261 spin_lock_irq(shost->host_lock);
262 lport = (struct lpfc_nvme_lport *)localport->private;
264 /* Port state is only one of two values for now. */
265 if (localport->port_id)
270 len += snprintf(buf + len, PAGE_SIZE - len,
271 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
274 wwn_to_u64(vport->fc_portname.u.wwn),
275 wwn_to_u64(vport->fc_nodename.u.wwn),
276 localport->port_id, statep);
278 list_for_each_entry(rport, &lport->rport_list, list) {
279 /* local short-hand pointer. */
280 nrport = rport->remoteport;
282 /* Port state is only one of two values for now. */
283 switch (nrport->port_state) {
284 case FC_OBJSTATE_ONLINE:
287 case FC_OBJSTATE_UNKNOWN:
291 statep = "UNSUPPORTED";
295 /* Tab in to show lport ownership. */
296 len += snprintf(buf + len, PAGE_SIZE - len,
298 if (phba->brd_no >= 10)
299 len += snprintf(buf + len, PAGE_SIZE - len, " ");
301 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
303 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
305 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
308 switch (nrport->port_role) {
309 case FC_PORT_ROLE_NVME_INITIATOR:
310 len += snprintf(buf + len, PAGE_SIZE - len,
313 case FC_PORT_ROLE_NVME_TARGET:
314 len += snprintf(buf + len, PAGE_SIZE - len,
317 case FC_PORT_ROLE_NVME_DISCOVERY:
318 len += snprintf(buf + len, PAGE_SIZE - len,
322 len += snprintf(buf + len, PAGE_SIZE - len,
327 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
328 /* Terminate the string. */
329 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
331 spin_unlock_irq(shost->host_lock);
333 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
334 len += snprintf(buf+len, PAGE_SIZE-len,
335 "LS: Xmt %016llx Cmpl %016llx\n",
336 phba->fc4NvmeLsRequests,
337 phba->fc4NvmeLsCmpls);
339 len += snprintf(buf+len, PAGE_SIZE-len,
340 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
341 phba->fc4NvmeInputRequests,
342 phba->fc4NvmeOutputRequests,
343 phba->fc4NvmeControlRequests);
345 len += snprintf(buf+len, PAGE_SIZE-len,
346 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
352 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
355 struct Scsi_Host *shost = class_to_shost(dev);
356 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
357 struct lpfc_hba *phba = vport->phba;
359 if (phba->cfg_enable_bg)
360 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
361 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
363 return snprintf(buf, PAGE_SIZE,
364 "BlockGuard Not Supported\n");
366 return snprintf(buf, PAGE_SIZE,
367 "BlockGuard Disabled\n");
371 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
374 struct Scsi_Host *shost = class_to_shost(dev);
375 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
376 struct lpfc_hba *phba = vport->phba;
378 return snprintf(buf, PAGE_SIZE, "%llu\n",
379 (unsigned long long)phba->bg_guard_err_cnt);
383 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
386 struct Scsi_Host *shost = class_to_shost(dev);
387 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
388 struct lpfc_hba *phba = vport->phba;
390 return snprintf(buf, PAGE_SIZE, "%llu\n",
391 (unsigned long long)phba->bg_apptag_err_cnt);
395 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
398 struct Scsi_Host *shost = class_to_shost(dev);
399 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
400 struct lpfc_hba *phba = vport->phba;
402 return snprintf(buf, PAGE_SIZE, "%llu\n",
403 (unsigned long long)phba->bg_reftag_err_cnt);
407 * lpfc_info_show - Return some pci info about the host in ascii
408 * @dev: class converted to a Scsi_host structure.
409 * @attr: device attribute, not used.
410 * @buf: on return contains the formatted text from lpfc_info().
412 * Returns: size of formatted string.
415 lpfc_info_show(struct device *dev, struct device_attribute *attr,
418 struct Scsi_Host *host = class_to_shost(dev);
420 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
424 * lpfc_serialnum_show - Return the hba serial number in ascii
425 * @dev: class converted to a Scsi_host structure.
426 * @attr: device attribute, not used.
427 * @buf: on return contains the formatted text serial number.
429 * Returns: size of formatted string.
432 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
435 struct Scsi_Host *shost = class_to_shost(dev);
436 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
437 struct lpfc_hba *phba = vport->phba;
439 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
443 * lpfc_temp_sensor_show - Return the temperature sensor level
444 * @dev: class converted to a Scsi_host structure.
445 * @attr: device attribute, not used.
446 * @buf: on return contains the formatted support level.
449 * Returns a number indicating the temperature sensor level currently
450 * supported, zero or one in ascii.
452 * Returns: size of formatted string.
455 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
458 struct Scsi_Host *shost = class_to_shost(dev);
459 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
460 struct lpfc_hba *phba = vport->phba;
461 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
465 * lpfc_modeldesc_show - Return the model description of the hba
466 * @dev: class converted to a Scsi_host structure.
467 * @attr: device attribute, not used.
468 * @buf: on return contains the scsi vpd model description.
470 * Returns: size of formatted string.
473 lpfc_modeldesc_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;
480 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
484 * lpfc_modelname_show - Return the model name of the hba
485 * @dev: class converted to a Scsi_host structure.
486 * @attr: device attribute, not used.
487 * @buf: on return contains the scsi vpd model name.
489 * Returns: size of formatted string.
492 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
495 struct Scsi_Host *shost = class_to_shost(dev);
496 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
497 struct lpfc_hba *phba = vport->phba;
499 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
503 * lpfc_programtype_show - Return the program type of the hba
504 * @dev: class converted to a Scsi_host structure.
505 * @attr: device attribute, not used.
506 * @buf: on return contains the scsi vpd program type.
508 * Returns: size of formatted string.
511 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
514 struct Scsi_Host *shost = class_to_shost(dev);
515 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
516 struct lpfc_hba *phba = vport->phba;
518 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
522 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
523 * @dev: class converted to a Scsi_host structure.
524 * @attr: device attribute, not used.
525 * @buf: on return contains the Menlo Maintenance sli flag.
527 * Returns: size of formatted string.
530 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
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, "%d\n",
537 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
541 * lpfc_vportnum_show - Return the port number in ascii of the hba
542 * @dev: class converted to a Scsi_host structure.
543 * @attr: device attribute, not used.
544 * @buf: on return contains scsi vpd program type.
546 * Returns: size of formatted string.
549 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
552 struct Scsi_Host *shost = class_to_shost(dev);
553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
554 struct lpfc_hba *phba = vport->phba;
556 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
560 * lpfc_fwrev_show - Return the firmware rev running in the hba
561 * @dev: class converted to a Scsi_host structure.
562 * @attr: device attribute, not used.
563 * @buf: on return contains the scsi vpd program type.
565 * Returns: size of formatted string.
568 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
571 struct Scsi_Host *shost = class_to_shost(dev);
572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
573 struct lpfc_hba *phba = vport->phba;
576 char fwrev[FW_REV_STR_SIZE];
579 lpfc_decode_firmware_rev(phba, fwrev, 1);
580 if_type = phba->sli4_hba.pc_sli4_params.if_type;
581 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
583 if (phba->sli_rev < LPFC_SLI_REV4)
584 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
585 fwrev, phba->sli_rev);
587 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
588 fwrev, phba->sli_rev, if_type, sli_family);
594 * lpfc_hdw_show - Return the jedec information about the hba
595 * @dev: class converted to a Scsi_host structure.
596 * @attr: device attribute, not used.
597 * @buf: on return contains the scsi vpd program type.
599 * Returns: size of formatted string.
602 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
605 struct Scsi_Host *shost = class_to_shost(dev);
606 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
607 struct lpfc_hba *phba = vport->phba;
608 lpfc_vpd_t *vp = &phba->vpd;
610 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
611 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
615 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
616 * @dev: class converted to a Scsi_host structure.
617 * @attr: device attribute, not used.
618 * @buf: on return contains the ROM and FCode ascii strings.
620 * Returns: size of formatted string.
623 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
626 struct Scsi_Host *shost = class_to_shost(dev);
627 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
628 struct lpfc_hba *phba = vport->phba;
629 char fwrev[FW_REV_STR_SIZE];
631 if (phba->sli_rev < LPFC_SLI_REV4)
632 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
634 lpfc_decode_firmware_rev(phba, fwrev, 1);
635 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
639 * lpfc_state_show - Return the link state of the port
640 * @dev: class converted to a Scsi_host structure.
641 * @attr: device attribute, not used.
642 * @buf: on return contains text describing the state of the link.
645 * The switch statement has no default so zero will be returned.
647 * Returns: size of formatted string.
650 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
653 struct Scsi_Host *shost = class_to_shost(dev);
654 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
655 struct lpfc_hba *phba = vport->phba;
658 switch (phba->link_state) {
659 case LPFC_LINK_UNKNOWN:
660 case LPFC_WARM_START:
661 case LPFC_INIT_START:
662 case LPFC_INIT_MBX_CMDS:
665 if (phba->hba_flag & LINK_DISABLED)
666 len += snprintf(buf + len, PAGE_SIZE-len,
667 "Link Down - User disabled\n");
669 len += snprintf(buf + len, PAGE_SIZE-len,
675 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
677 switch (vport->port_state) {
678 case LPFC_LOCAL_CFG_LINK:
679 len += snprintf(buf + len, PAGE_SIZE-len,
680 "Configuring Link\n");
684 case LPFC_FABRIC_CFG_LINK:
687 case LPFC_BUILD_DISC_LIST:
689 len += snprintf(buf + len, PAGE_SIZE - len,
692 case LPFC_VPORT_READY:
693 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
696 case LPFC_VPORT_FAILED:
697 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
700 case LPFC_VPORT_UNKNOWN:
701 len += snprintf(buf + len, PAGE_SIZE - len,
705 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
706 len += snprintf(buf + len, PAGE_SIZE-len,
707 " Menlo Maint Mode\n");
708 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
709 if (vport->fc_flag & FC_PUBLIC_LOOP)
710 len += snprintf(buf + len, PAGE_SIZE-len,
713 len += snprintf(buf + len, PAGE_SIZE-len,
716 if (vport->fc_flag & FC_FABRIC)
717 len += snprintf(buf + len, PAGE_SIZE-len,
720 len += snprintf(buf + len, PAGE_SIZE-len,
729 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
730 * @dev: class unused variable.
731 * @attr: device attribute, not used.
732 * @buf: on return contains the module description text.
734 * Returns: size of formatted string.
737 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
740 struct Scsi_Host *shost = class_to_shost(dev);
741 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
742 struct lpfc_hba *phba = vport->phba;
744 if (phba->sli_rev < LPFC_SLI_REV4)
745 return snprintf(buf, PAGE_SIZE, "fc\n");
747 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
748 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
749 return snprintf(buf, PAGE_SIZE, "fcoe\n");
750 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
751 return snprintf(buf, PAGE_SIZE, "fc\n");
753 return snprintf(buf, PAGE_SIZE, "unknown\n");
757 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
758 * (OAS) is supported.
759 * @dev: class unused variable.
760 * @attr: device attribute, not used.
761 * @buf: on return contains the module description text.
763 * Returns: size of formatted string.
766 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
769 struct Scsi_Host *shost = class_to_shost(dev);
770 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
771 struct lpfc_hba *phba = vport->phba;
773 return snprintf(buf, PAGE_SIZE, "%d\n",
774 phba->sli4_hba.pc_sli4_params.oas_supported);
778 * lpfc_link_state_store - Transition the link_state on an HBA port
779 * @dev: class device that is converted into a Scsi_host.
780 * @attr: device attribute, not used.
781 * @buf: one or more lpfc_polling_flags values.
785 * -EINVAL if the buffer is not "up" or "down"
786 * return from link state change function if non-zero
787 * length of the buf on success
790 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
791 const char *buf, size_t count)
793 struct Scsi_Host *shost = class_to_shost(dev);
794 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
795 struct lpfc_hba *phba = vport->phba;
797 int status = -EINVAL;
799 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
800 (phba->link_state == LPFC_LINK_DOWN))
801 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
802 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
803 (phba->link_state >= LPFC_LINK_UP))
804 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
813 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
814 * @dev: class device that is converted into a Scsi_host.
815 * @attr: device attribute, not used.
816 * @buf: on return contains the sum of fc mapped and unmapped.
819 * Returns the ascii text number of the sum of the fc mapped and unmapped
822 * Returns: size of formatted string.
825 lpfc_num_discovered_ports_show(struct device *dev,
826 struct device_attribute *attr, char *buf)
828 struct Scsi_Host *shost = class_to_shost(dev);
829 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
831 return snprintf(buf, PAGE_SIZE, "%d\n",
832 vport->fc_map_cnt + vport->fc_unmap_cnt);
836 * lpfc_issue_lip - Misnomer, name carried over from long ago
837 * @shost: Scsi_Host pointer.
840 * Bring the link down gracefully then re-init the link. The firmware will
841 * re-init the fiber channel interface as required. Does not issue a LIP.
844 * -EPERM port offline or management commands are being blocked
845 * -ENOMEM cannot allocate memory for the mailbox command
846 * -EIO error sending the mailbox command
850 lpfc_issue_lip(struct Scsi_Host *shost)
852 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
853 struct lpfc_hba *phba = vport->phba;
854 LPFC_MBOXQ_t *pmboxq;
855 int mbxstatus = MBXERR_ERROR;
857 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
858 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
861 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
866 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
867 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
868 pmboxq->u.mb.mbxOwner = OWN_HOST;
870 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
872 if ((mbxstatus == MBX_SUCCESS) &&
873 (pmboxq->u.mb.mbxStatus == 0 ||
874 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
875 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
876 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
877 phba->cfg_link_speed);
878 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
880 if ((mbxstatus == MBX_SUCCESS) &&
881 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
882 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
883 "2859 SLI authentication is required "
884 "for INIT_LINK but has not done yet\n");
887 lpfc_set_loopback_flag(phba);
888 if (mbxstatus != MBX_TIMEOUT)
889 mempool_free(pmboxq, phba->mbox_mem_pool);
891 if (mbxstatus == MBXERR_ERROR)
898 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
903 while (!list_empty(q)) {
904 spin_unlock_irq(lock);
906 if (cnt++ > 250) { /* 5 secs */
907 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
909 "Outstanding IO when ",
910 "bringing Adapter offline\n");
915 spin_unlock_irq(lock);
920 * lpfc_do_offline - Issues a mailbox command to bring the link down
921 * @phba: lpfc_hba pointer.
922 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
925 * Assumes any error from lpfc_do_offline() will be negative.
926 * Can wait up to 5 seconds for the port ring buffers count
927 * to reach zero, prints a warning if it is not zero and continues.
928 * lpfc_workq_post_event() returns a non-zero return code if call fails.
931 * -EIO error posting the event
935 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
937 struct completion online_compl;
938 struct lpfc_queue *qp = NULL;
939 struct lpfc_sli_ring *pring;
940 struct lpfc_sli *psli;
945 init_completion(&online_compl);
946 rc = lpfc_workq_post_event(phba, &status, &online_compl,
947 LPFC_EVT_OFFLINE_PREP);
951 wait_for_completion(&online_compl);
958 /* Wait a little for things to settle down, but not
959 * long enough for dev loss timeout to expire.
961 if (phba->sli_rev != LPFC_SLI_REV4) {
962 for (i = 0; i < psli->num_rings; i++) {
963 pring = &psli->sli3_ring[i];
964 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
969 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
973 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
979 init_completion(&online_compl);
980 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
984 wait_for_completion(&online_compl);
993 * lpfc_selective_reset - Offline then onlines the port
994 * @phba: lpfc_hba pointer.
997 * If the port is configured to allow a reset then the hba is brought
998 * offline then online.
1001 * Assumes any error from lpfc_do_offline() will be negative.
1002 * Do not make this function static.
1005 * lpfc_do_offline() return code if not zero
1006 * -EIO reset not configured or error posting the event
1010 lpfc_selective_reset(struct lpfc_hba *phba)
1012 struct completion online_compl;
1016 if (!phba->cfg_enable_hba_reset)
1019 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1020 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1026 init_completion(&online_compl);
1027 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1032 wait_for_completion(&online_compl);
1041 * lpfc_issue_reset - Selectively resets an adapter
1042 * @dev: class device that is converted into a Scsi_host.
1043 * @attr: device attribute, not used.
1044 * @buf: containing the string "selective".
1045 * @count: unused variable.
1048 * If the buf contains the string "selective" then lpfc_selective_reset()
1049 * is called to perform the reset.
1052 * Assumes any error from lpfc_selective_reset() will be negative.
1053 * If lpfc_selective_reset() returns zero then the length of the buffer
1054 * is returned which indicates success
1057 * -EINVAL if the buffer does not contain the string "selective"
1058 * length of buf if lpfc-selective_reset() if the call succeeds
1059 * return value of lpfc_selective_reset() if the call fails
1062 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1063 const char *buf, size_t count)
1065 struct Scsi_Host *shost = class_to_shost(dev);
1066 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1067 struct lpfc_hba *phba = vport->phba;
1068 int status = -EINVAL;
1070 if (!phba->cfg_enable_hba_reset)
1073 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1074 status = phba->lpfc_selective_reset(phba);
1083 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1084 * @phba: lpfc_hba pointer.
1087 * SLI4 interface type-2 device to wait on the sliport status register for
1088 * the readyness after performing a firmware reset.
1091 * zero for success, -EPERM when port does not have privilege to perform the
1092 * reset, -EIO when port timeout from recovering from the reset.
1095 * As the caller will interpret the return code by value, be careful in making
1096 * change or addition to return codes.
1099 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1101 struct lpfc_register portstat_reg = {0};
1105 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1106 &portstat_reg.word0);
1108 /* verify if privileged for the request operation */
1109 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1110 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1113 /* wait for the SLI port firmware ready after firmware reset */
1114 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1116 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1117 &portstat_reg.word0);
1118 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1120 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1122 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1127 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1134 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1135 * @phba: lpfc_hba pointer.
1138 * Request SLI4 interface type-2 device to perform a physical register set
1145 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1147 struct completion online_compl;
1148 struct pci_dev *pdev = phba->pcidev;
1149 uint32_t before_fc_flag;
1150 uint32_t sriov_nr_virtfn;
1152 int status = 0, rc = 0;
1153 int job_posted = 1, sriov_err;
1155 if (!phba->cfg_enable_hba_reset)
1158 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1159 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1160 LPFC_SLI_INTF_IF_TYPE_2))
1163 /* Keep state if we need to restore back */
1164 before_fc_flag = phba->pport->fc_flag;
1165 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1167 /* Disable SR-IOV virtual functions if enabled */
1168 if (phba->cfg_sriov_nr_virtfn) {
1169 pci_disable_sriov(pdev);
1170 phba->cfg_sriov_nr_virtfn = 0;
1173 if (opcode == LPFC_FW_DUMP)
1174 phba->hba_flag |= HBA_FW_DUMP_OP;
1176 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1179 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1183 /* wait for the device to be quiesced before firmware reset */
1186 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1187 LPFC_CTL_PDEV_CTL_OFFSET);
1189 if (opcode == LPFC_FW_DUMP)
1190 reg_val |= LPFC_FW_DUMP_REQUEST;
1191 else if (opcode == LPFC_FW_RESET)
1192 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1193 else if (opcode == LPFC_DV_RESET)
1194 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1196 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1197 LPFC_CTL_PDEV_CTL_OFFSET);
1199 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1201 /* delay driver action following IF_TYPE_2 reset */
1202 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1205 /* no privilege for reset */
1206 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1207 "3150 No privilege to perform the requested "
1208 "access: x%x\n", reg_val);
1209 } else if (rc == -EIO) {
1210 /* reset failed, there is nothing more we can do */
1211 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1212 "3153 Fail to perform the requested "
1213 "access: x%x\n", reg_val);
1217 /* keep the original port state */
1218 if (before_fc_flag & FC_OFFLINE_MODE)
1221 init_completion(&online_compl);
1222 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1227 wait_for_completion(&online_compl);
1230 /* in any case, restore the virtual functions enabled as before */
1231 if (sriov_nr_virtfn) {
1233 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1235 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1238 /* return proper error code */
1249 * lpfc_nport_evt_cnt_show - Return the number of nport events
1250 * @dev: class device that is converted into a Scsi_host.
1251 * @attr: device attribute, not used.
1252 * @buf: on return contains the ascii number of nport events.
1254 * Returns: size of formatted string.
1257 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1260 struct Scsi_Host *shost = class_to_shost(dev);
1261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1262 struct lpfc_hba *phba = vport->phba;
1264 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1268 * lpfc_board_mode_show - Return the state of the board
1269 * @dev: class device that is converted into a Scsi_host.
1270 * @attr: device attribute, not used.
1271 * @buf: on return contains the state of the adapter.
1273 * Returns: size of formatted string.
1276 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1279 struct Scsi_Host *shost = class_to_shost(dev);
1280 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1281 struct lpfc_hba *phba = vport->phba;
1284 if (phba->link_state == LPFC_HBA_ERROR)
1286 else if (phba->link_state == LPFC_WARM_START)
1287 state = "warm start";
1288 else if (phba->link_state == LPFC_INIT_START)
1293 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1297 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1298 * @dev: class device that is converted into a Scsi_host.
1299 * @attr: device attribute, not used.
1300 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1301 * @count: unused variable.
1304 * -EACCES if enable hba reset not enabled
1305 * -EINVAL if the buffer does not contain a valid string (see above)
1306 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1307 * buf length greater than zero indicates success
1310 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1311 const char *buf, size_t count)
1313 struct Scsi_Host *shost = class_to_shost(dev);
1314 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1315 struct lpfc_hba *phba = vport->phba;
1316 struct completion online_compl;
1317 char *board_mode_str = NULL;
1321 if (!phba->cfg_enable_hba_reset) {
1323 goto board_mode_out;
1326 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1327 "3050 lpfc_board_mode set to %s\n", buf);
1329 init_completion(&online_compl);
1331 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1332 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1336 goto board_mode_out;
1338 wait_for_completion(&online_compl);
1339 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1340 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1341 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1342 if (phba->sli_rev == LPFC_SLI_REV4)
1345 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1346 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1347 if (phba->sli_rev == LPFC_SLI_REV4)
1350 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1351 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1352 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1353 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1354 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1355 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1356 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1364 board_mode_str = strchr(buf, '\n');
1366 *board_mode_str = '\0';
1367 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1368 "3097 Failed \"%s\", status(%d), "
1370 buf, status, phba->pport->fc_flag);
1376 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1377 * @phba: pointer to the adapter structure.
1378 * @mxri: max xri count.
1379 * @axri: available xri count.
1380 * @mrpi: max rpi count.
1381 * @arpi: available rpi count.
1382 * @mvpi: max vpi count.
1383 * @avpi: available vpi count.
1386 * If an integer pointer for an count is not null then the value for the
1387 * count is returned.
1394 lpfc_get_hba_info(struct lpfc_hba *phba,
1395 uint32_t *mxri, uint32_t *axri,
1396 uint32_t *mrpi, uint32_t *arpi,
1397 uint32_t *mvpi, uint32_t *avpi)
1399 struct lpfc_mbx_read_config *rd_config;
1400 LPFC_MBOXQ_t *pmboxq;
1406 * prevent udev from issuing mailbox commands until the port is
1409 if (phba->link_state < LPFC_LINK_DOWN ||
1410 !phba->mbox_mem_pool ||
1411 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1414 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1417 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1420 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1422 pmb = &pmboxq->u.mb;
1423 pmb->mbxCommand = MBX_READ_CONFIG;
1424 pmb->mbxOwner = OWN_HOST;
1425 pmboxq->context1 = NULL;
1427 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1428 rc = MBX_NOT_FINISHED;
1430 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1432 if (rc != MBX_SUCCESS) {
1433 if (rc != MBX_TIMEOUT)
1434 mempool_free(pmboxq, phba->mbox_mem_pool);
1438 if (phba->sli_rev == LPFC_SLI_REV4) {
1439 rd_config = &pmboxq->u.mqe.un.rd_config;
1441 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1443 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1444 phba->sli4_hba.max_cfg_param.rpi_used;
1446 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1448 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1449 phba->sli4_hba.max_cfg_param.xri_used;
1451 /* Account for differences with SLI-3. Get vpi count from
1452 * mailbox data and subtract one for max vpi value.
1454 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1455 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1460 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1463 *mrpi = pmb->un.varRdConfig.max_rpi;
1465 *arpi = pmb->un.varRdConfig.avail_rpi;
1467 *mxri = pmb->un.varRdConfig.max_xri;
1469 *axri = pmb->un.varRdConfig.avail_xri;
1471 *mvpi = pmb->un.varRdConfig.max_vpi;
1473 *avpi = pmb->un.varRdConfig.avail_vpi;
1476 mempool_free(pmboxq, phba->mbox_mem_pool);
1481 * lpfc_max_rpi_show - Return maximum rpi
1482 * @dev: class device that is converted into a Scsi_host.
1483 * @attr: device attribute, not used.
1484 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1487 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1488 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1489 * to "Unknown" and the buffer length is returned, therefore the caller
1490 * must check for "Unknown" in the buffer to detect a failure.
1492 * Returns: size of formatted string.
1495 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1498 struct Scsi_Host *shost = class_to_shost(dev);
1499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1500 struct lpfc_hba *phba = vport->phba;
1503 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1504 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1505 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1509 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1510 * @dev: class device that is converted into a Scsi_host.
1511 * @attr: device attribute, not used.
1512 * @buf: containing the used rpi count in decimal or "Unknown".
1515 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1516 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1517 * to "Unknown" and the buffer length is returned, therefore the caller
1518 * must check for "Unknown" in the buffer to detect a failure.
1520 * Returns: size of formatted string.
1523 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1526 struct Scsi_Host *shost = class_to_shost(dev);
1527 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1528 struct lpfc_hba *phba = vport->phba;
1531 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1532 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1533 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1537 * lpfc_max_xri_show - Return maximum xri
1538 * @dev: class device that is converted into a Scsi_host.
1539 * @attr: device attribute, not used.
1540 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1543 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1544 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1545 * to "Unknown" and the buffer length is returned, therefore the caller
1546 * must check for "Unknown" in the buffer to detect a failure.
1548 * Returns: size of formatted string.
1551 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1554 struct Scsi_Host *shost = class_to_shost(dev);
1555 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1556 struct lpfc_hba *phba = vport->phba;
1559 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1560 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1561 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1565 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1566 * @dev: class device that is converted into a Scsi_host.
1567 * @attr: device attribute, not used.
1568 * @buf: on return contains the used xri count in decimal or "Unknown".
1571 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1572 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1573 * to "Unknown" and the buffer length is returned, therefore the caller
1574 * must check for "Unknown" in the buffer to detect a failure.
1576 * Returns: size of formatted string.
1579 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1582 struct Scsi_Host *shost = class_to_shost(dev);
1583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1584 struct lpfc_hba *phba = vport->phba;
1587 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1588 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1589 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1593 * lpfc_max_vpi_show - Return maximum vpi
1594 * @dev: class device that is converted into a Scsi_host.
1595 * @attr: device attribute, not used.
1596 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1599 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1600 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1601 * to "Unknown" and the buffer length is returned, therefore the caller
1602 * must check for "Unknown" in the buffer to detect a failure.
1604 * Returns: size of formatted string.
1607 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1610 struct Scsi_Host *shost = class_to_shost(dev);
1611 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1612 struct lpfc_hba *phba = vport->phba;
1615 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1616 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1617 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1621 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1622 * @dev: class device that is converted into a Scsi_host.
1623 * @attr: device attribute, not used.
1624 * @buf: on return contains the used vpi count in decimal or "Unknown".
1627 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1628 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1629 * to "Unknown" and the buffer length is returned, therefore the caller
1630 * must check for "Unknown" in the buffer to detect a failure.
1632 * Returns: size of formatted string.
1635 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1638 struct Scsi_Host *shost = class_to_shost(dev);
1639 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1640 struct lpfc_hba *phba = vport->phba;
1643 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1644 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1645 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1649 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1650 * @dev: class device that is converted into a Scsi_host.
1651 * @attr: device attribute, not used.
1652 * @buf: text that must be interpreted to determine if npiv is supported.
1655 * Buffer will contain text indicating npiv is not suppoerted on the port,
1656 * the port is an NPIV physical port, or it is an npiv virtual port with
1657 * the id of the vport.
1659 * Returns: size of formatted string.
1662 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1665 struct Scsi_Host *shost = class_to_shost(dev);
1666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1667 struct lpfc_hba *phba = vport->phba;
1669 if (!(phba->max_vpi))
1670 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1671 if (vport->port_type == LPFC_PHYSICAL_PORT)
1672 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1673 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1677 * lpfc_poll_show - Return text about poll support for the adapter
1678 * @dev: class device that is converted into a Scsi_host.
1679 * @attr: device attribute, not used.
1680 * @buf: on return contains the cfg_poll in hex.
1683 * cfg_poll should be a lpfc_polling_flags type.
1685 * Returns: size of formatted string.
1688 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1691 struct Scsi_Host *shost = class_to_shost(dev);
1692 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1693 struct lpfc_hba *phba = vport->phba;
1695 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1699 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1700 * @dev: class device that is converted into a Scsi_host.
1701 * @attr: device attribute, not used.
1702 * @buf: one or more lpfc_polling_flags values.
1706 * buf contents converted to integer and checked for a valid value.
1709 * -EINVAL if the buffer connot be converted or is out of range
1710 * length of the buf on success
1713 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1714 const char *buf, size_t count)
1716 struct Scsi_Host *shost = class_to_shost(dev);
1717 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1718 struct lpfc_hba *phba = vport->phba;
1723 if (!isdigit(buf[0]))
1726 if (sscanf(buf, "%i", &val) != 1)
1729 if ((val & 0x3) != val)
1732 if (phba->sli_rev == LPFC_SLI_REV4)
1735 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1736 "3051 lpfc_poll changed from %d to %d\n",
1737 phba->cfg_poll, val);
1739 spin_lock_irq(&phba->hbalock);
1741 old_val = phba->cfg_poll;
1743 if (val & ENABLE_FCP_RING_POLLING) {
1744 if ((val & DISABLE_FCP_RING_INT) &&
1745 !(old_val & DISABLE_FCP_RING_INT)) {
1746 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1747 spin_unlock_irq(&phba->hbalock);
1750 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1751 writel(creg_val, phba->HCregaddr);
1752 readl(phba->HCregaddr); /* flush */
1754 lpfc_poll_start_timer(phba);
1756 } else if (val != 0x0) {
1757 spin_unlock_irq(&phba->hbalock);
1761 if (!(val & DISABLE_FCP_RING_INT) &&
1762 (old_val & DISABLE_FCP_RING_INT))
1764 spin_unlock_irq(&phba->hbalock);
1765 del_timer(&phba->fcp_poll_timer);
1766 spin_lock_irq(&phba->hbalock);
1767 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1768 spin_unlock_irq(&phba->hbalock);
1771 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1772 writel(creg_val, phba->HCregaddr);
1773 readl(phba->HCregaddr); /* flush */
1776 phba->cfg_poll = val;
1778 spin_unlock_irq(&phba->hbalock);
1784 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1785 * @dev: class unused variable.
1786 * @attr: device attribute, not used.
1787 * @buf: on return contains the module description text.
1789 * Returns: size of formatted string.
1792 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1795 struct Scsi_Host *shost = class_to_shost(dev);
1796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1797 struct lpfc_hba *phba = vport->phba;
1799 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1803 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1804 * @dev: class unused variable.
1805 * @attr: device attribute, not used.
1806 * @buf: on return contains the module description text.
1808 * Returns: size of formatted string.
1811 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1814 struct Scsi_Host *shost = class_to_shost(dev);
1815 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1816 struct lpfc_hba *phba = vport->phba;
1818 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1822 * lpfc_dss_show - Return the current state of dss and the configured state
1823 * @dev: class converted to a Scsi_host structure.
1824 * @attr: device attribute, not used.
1825 * @buf: on return contains the formatted text.
1827 * Returns: size of formatted string.
1830 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1833 struct Scsi_Host *shost = class_to_shost(dev);
1834 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1835 struct lpfc_hba *phba = vport->phba;
1837 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1838 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1839 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1844 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1845 * @dev: class converted to a Scsi_host structure.
1846 * @attr: device attribute, not used.
1847 * @buf: on return contains the formatted support level.
1850 * Returns the maximum number of virtual functions a physical function can
1851 * support, 0 will be returned if called on virtual function.
1853 * Returns: size of formatted string.
1856 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1857 struct device_attribute *attr,
1860 struct Scsi_Host *shost = class_to_shost(dev);
1861 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1862 struct lpfc_hba *phba = vport->phba;
1863 uint16_t max_nr_virtfn;
1865 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1866 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1869 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1871 return val >= min && val <= max;
1875 * lpfc_param_show - Return a cfg attribute value in decimal
1878 * Macro that given an attr e.g. hba_queue_depth expands
1879 * into a function with the name lpfc_hba_queue_depth_show.
1881 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1882 * @dev: class device that is converted into a Scsi_host.
1883 * @attr: device attribute, not used.
1884 * @buf: on return contains the attribute value in decimal.
1886 * Returns: size of formatted string.
1888 #define lpfc_param_show(attr) \
1890 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1893 struct Scsi_Host *shost = class_to_shost(dev);\
1894 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1895 struct lpfc_hba *phba = vport->phba;\
1896 return snprintf(buf, PAGE_SIZE, "%d\n",\
1901 * lpfc_param_hex_show - Return a cfg attribute value in hex
1904 * Macro that given an attr e.g. hba_queue_depth expands
1905 * into a function with the name lpfc_hba_queue_depth_show
1907 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1908 * @dev: class device that is converted into a Scsi_host.
1909 * @attr: device attribute, not used.
1910 * @buf: on return contains the attribute value in hexadecimal.
1912 * Returns: size of formatted string.
1914 #define lpfc_param_hex_show(attr) \
1916 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1919 struct Scsi_Host *shost = class_to_shost(dev);\
1920 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1921 struct lpfc_hba *phba = vport->phba;\
1923 val = phba->cfg_##attr;\
1924 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1929 * lpfc_param_init - Initializes a cfg attribute
1932 * Macro that given an attr e.g. hba_queue_depth expands
1933 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1934 * takes a default argument, a minimum and maximum argument.
1936 * lpfc_##attr##_init: Initializes an attribute.
1937 * @phba: pointer the the adapter structure.
1938 * @val: integer attribute value.
1940 * Validates the min and max values then sets the adapter config field
1941 * accordingly, or uses the default if out of range and prints an error message.
1945 * -EINVAL if default used
1947 #define lpfc_param_init(attr, default, minval, maxval) \
1949 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1951 if (lpfc_rangecheck(val, minval, maxval)) {\
1952 phba->cfg_##attr = val;\
1955 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1956 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1957 "allowed range is ["#minval", "#maxval"]\n", val); \
1958 phba->cfg_##attr = default;\
1963 * lpfc_param_set - Set a cfg attribute value
1966 * Macro that given an attr e.g. hba_queue_depth expands
1967 * into a function with the name lpfc_hba_queue_depth_set
1969 * lpfc_##attr##_set: Sets an attribute value.
1970 * @phba: pointer the the adapter structure.
1971 * @val: integer attribute value.
1974 * Validates the min and max values then sets the
1975 * adapter config field if in the valid range. prints error message
1976 * and does not set the parameter if invalid.
1980 * -EINVAL if val is invalid
1982 #define lpfc_param_set(attr, default, minval, maxval) \
1984 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1986 if (lpfc_rangecheck(val, minval, maxval)) {\
1987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1988 "3052 lpfc_" #attr " changed from %d to %d\n", \
1989 phba->cfg_##attr, val); \
1990 phba->cfg_##attr = val;\
1993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1994 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1995 "allowed range is ["#minval", "#maxval"]\n", val); \
2000 * lpfc_param_store - Set a vport attribute value
2003 * Macro that given an attr e.g. hba_queue_depth expands
2004 * into a function with the name lpfc_hba_queue_depth_store.
2006 * lpfc_##attr##_store: Set an sttribute value.
2007 * @dev: class device that is converted into a Scsi_host.
2008 * @attr: device attribute, not used.
2009 * @buf: contains the attribute value in ascii.
2013 * Convert the ascii text number to an integer, then
2014 * use the lpfc_##attr##_set function to set the value.
2017 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2018 * length of buffer upon success.
2020 #define lpfc_param_store(attr) \
2022 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2023 const char *buf, size_t count) \
2025 struct Scsi_Host *shost = class_to_shost(dev);\
2026 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2027 struct lpfc_hba *phba = vport->phba;\
2029 if (!isdigit(buf[0]))\
2031 if (sscanf(buf, "%i", &val) != 1)\
2033 if (lpfc_##attr##_set(phba, val) == 0) \
2034 return strlen(buf);\
2040 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2043 * Macro that given an attr e.g. hba_queue_depth expands
2044 * into a function with the name lpfc_hba_queue_depth_show
2046 * lpfc_##attr##_show: prints the attribute value in decimal.
2047 * @dev: class device that is converted into a Scsi_host.
2048 * @attr: device attribute, not used.
2049 * @buf: on return contains the attribute value in decimal.
2051 * Returns: length of formatted string.
2053 #define lpfc_vport_param_show(attr) \
2055 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2058 struct Scsi_Host *shost = class_to_shost(dev);\
2059 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2060 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2064 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2067 * Macro that given an attr e.g.
2068 * hba_queue_depth expands into a function with the name
2069 * lpfc_hba_queue_depth_show
2071 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2072 * @dev: class device that is converted into a Scsi_host.
2073 * @attr: device attribute, not used.
2074 * @buf: on return contains the attribute value in hexadecimal.
2076 * Returns: length of formatted string.
2078 #define lpfc_vport_param_hex_show(attr) \
2080 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2083 struct Scsi_Host *shost = class_to_shost(dev);\
2084 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2085 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2089 * lpfc_vport_param_init - Initialize a vport cfg attribute
2092 * Macro that given an attr e.g. hba_queue_depth expands
2093 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2094 * takes a default argument, a minimum and maximum argument.
2096 * lpfc_##attr##_init: validates the min and max values then sets the
2097 * adapter config field accordingly, or uses the default if out of range
2098 * and prints an error message.
2099 * @phba: pointer the the adapter structure.
2100 * @val: integer attribute value.
2104 * -EINVAL if default used
2106 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2108 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2110 if (lpfc_rangecheck(val, minval, maxval)) {\
2111 vport->cfg_##attr = val;\
2114 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2115 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2116 "allowed range is ["#minval", "#maxval"]\n", val); \
2117 vport->cfg_##attr = default;\
2122 * lpfc_vport_param_set - Set a vport cfg attribute
2125 * Macro that given an attr e.g. hba_queue_depth expands
2126 * into a function with the name lpfc_hba_queue_depth_set
2128 * lpfc_##attr##_set: validates the min and max values then sets the
2129 * adapter config field if in the valid range. prints error message
2130 * and does not set the parameter if invalid.
2131 * @phba: pointer the the adapter structure.
2132 * @val: integer attribute value.
2136 * -EINVAL if val is invalid
2138 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2140 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2142 if (lpfc_rangecheck(val, minval, maxval)) {\
2143 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2144 "3053 lpfc_" #attr \
2145 " changed from %d (x%x) to %d (x%x)\n", \
2146 vport->cfg_##attr, vport->cfg_##attr, \
2148 vport->cfg_##attr = val;\
2151 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2152 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2153 "allowed range is ["#minval", "#maxval"]\n", val); \
2158 * lpfc_vport_param_store - Set a vport attribute
2161 * Macro that given an attr e.g. hba_queue_depth
2162 * expands into a function with the name lpfc_hba_queue_depth_store
2164 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2165 * use the lpfc_##attr##_set function to set the value.
2166 * @cdev: class device that is converted into a Scsi_host.
2167 * @buf: contains the attribute value in decimal.
2171 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2172 * length of buffer upon success.
2174 #define lpfc_vport_param_store(attr) \
2176 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2177 const char *buf, size_t count) \
2179 struct Scsi_Host *shost = class_to_shost(dev);\
2180 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2182 if (!isdigit(buf[0]))\
2184 if (sscanf(buf, "%i", &val) != 1)\
2186 if (lpfc_##attr##_set(vport, val) == 0) \
2187 return strlen(buf);\
2193 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2194 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2195 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2196 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2197 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2198 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2199 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2200 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2201 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2202 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2203 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2204 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2205 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2206 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2207 lpfc_link_state_store);
2208 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2209 lpfc_option_rom_version_show, NULL);
2210 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2211 lpfc_num_discovered_ports_show, NULL);
2212 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2213 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2214 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2215 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2216 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2217 lpfc_board_mode_show, lpfc_board_mode_store);
2218 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2219 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2220 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2221 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2222 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2223 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2224 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2225 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2226 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2227 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2228 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2229 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2230 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2231 lpfc_sriov_hw_max_virtfn_show, NULL);
2232 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2233 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2236 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2239 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2241 * @cnt: Length of string.
2242 * @wwn: Array to receive converted wwn value.
2245 * -EINVAL if the buffer does not contain a valid wwn
2249 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2253 /* Count may include a LF at end of string */
2254 if (buf[cnt-1] == '\n')
2257 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2258 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2261 memset(wwn, 0, WWN_SZ);
2263 /* Validate and store the new name */
2264 for (i = 0, j = 0; i < 16; i++) {
2265 if ((*buf >= 'a') && (*buf <= 'f'))
2266 j = ((j << 4) | ((*buf++ - 'a') + 10));
2267 else if ((*buf >= 'A') && (*buf <= 'F'))
2268 j = ((j << 4) | ((*buf++ - 'A') + 10));
2269 else if ((*buf >= '0') && (*buf <= '9'))
2270 j = ((j << 4) | (*buf++ - '0'));
2274 wwn[i/2] = j & 0xff;
2281 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2282 * @dev: class device that is converted into a Scsi_host.
2283 * @attr: device attribute, not used.
2284 * @buf: containing the string lpfc_soft_wwn_key.
2285 * @count: must be size of lpfc_soft_wwn_key.
2288 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2289 * length of buf indicates success
2292 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2293 const char *buf, size_t count)
2295 struct Scsi_Host *shost = class_to_shost(dev);
2296 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2297 struct lpfc_hba *phba = vport->phba;
2298 unsigned int cnt = count;
2299 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2300 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2303 * We're doing a simple sanity check for soft_wwpn setting.
2304 * We require that the user write a specific key to enable
2305 * the soft_wwpn attribute to be settable. Once the attribute
2306 * is written, the enable key resets. If further updates are
2307 * desired, the key must be written again to re-enable the
2310 * The "key" is not secret - it is a hardcoded string shown
2311 * here. The intent is to protect against the random user or
2312 * application that is just writing attributes.
2314 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2316 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2317 " be enabled: fawwpn is enabled\n");
2321 /* count may include a LF at end of string */
2322 if (buf[cnt-1] == '\n')
2325 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2326 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2329 phba->soft_wwn_enable = 1;
2331 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2332 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2334 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2335 " The soft_wwpn feature is not supported by Broadcom.");
2339 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2340 lpfc_soft_wwn_enable_store);
2343 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2344 * @dev: class device that is converted into a Scsi_host.
2345 * @attr: device attribute, not used.
2346 * @buf: on return contains the wwpn in hexadecimal.
2348 * Returns: size of formatted string.
2351 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2354 struct Scsi_Host *shost = class_to_shost(dev);
2355 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2356 struct lpfc_hba *phba = vport->phba;
2358 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2359 (unsigned long long)phba->cfg_soft_wwpn);
2363 * lpfc_soft_wwpn_store - Set the 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: contains the wwpn in hexadecimal.
2367 * @count: number of wwpn bytes in buf
2370 * -EACCES hba reset not enabled, adapter over temp
2371 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2372 * -EIO error taking adapter offline or online
2373 * value of count on success
2376 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2377 const char *buf, size_t count)
2379 struct Scsi_Host *shost = class_to_shost(dev);
2380 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2381 struct lpfc_hba *phba = vport->phba;
2382 struct completion online_compl;
2383 int stat1 = 0, stat2 = 0;
2384 unsigned int cnt = count;
2388 if (!phba->cfg_enable_hba_reset)
2390 spin_lock_irq(&phba->hbalock);
2391 if (phba->over_temp_state == HBA_OVER_TEMP) {
2392 spin_unlock_irq(&phba->hbalock);
2395 spin_unlock_irq(&phba->hbalock);
2396 /* count may include a LF at end of string */
2397 if (buf[cnt-1] == '\n')
2400 if (!phba->soft_wwn_enable)
2403 /* lock setting wwpn, wwnn down */
2404 phba->soft_wwn_enable = 0;
2406 rc = lpfc_wwn_set(buf, cnt, wwpn);
2408 /* not able to set wwpn, unlock it */
2409 phba->soft_wwn_enable = 1;
2413 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2414 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2415 if (phba->cfg_soft_wwnn)
2416 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2418 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2419 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2421 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2423 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2424 "0463 lpfc_soft_wwpn attribute set failed to "
2425 "reinit adapter - %d\n", stat1);
2426 init_completion(&online_compl);
2427 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2432 wait_for_completion(&online_compl);
2434 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2435 "0464 lpfc_soft_wwpn attribute set failed to "
2436 "reinit adapter - %d\n", stat2);
2437 return (stat1 || stat2) ? -EIO : count;
2439 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2440 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2443 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2444 * @dev: class device that is converted into a Scsi_host.
2445 * @attr: device attribute, not used.
2446 * @buf: on return contains the wwnn in hexadecimal.
2448 * Returns: size of formatted string.
2451 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2454 struct Scsi_Host *shost = class_to_shost(dev);
2455 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2456 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2457 (unsigned long long)phba->cfg_soft_wwnn);
2461 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2462 * @cdev: class device that is converted into a Scsi_host.
2463 * @buf: contains the ww node name in hexadecimal.
2464 * @count: number of wwnn bytes in buf.
2467 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2468 * value of count on success
2471 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2472 const char *buf, size_t count)
2474 struct Scsi_Host *shost = class_to_shost(dev);
2475 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2476 unsigned int cnt = count;
2480 /* count may include a LF at end of string */
2481 if (buf[cnt-1] == '\n')
2484 if (!phba->soft_wwn_enable)
2487 rc = lpfc_wwn_set(buf, cnt, wwnn);
2489 /* Allow wwnn to be set many times, as long as the enable
2490 * is set. However, once the wwpn is set, everything locks.
2495 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2497 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2498 "lpfc%d: soft_wwnn set. Value will take effect upon "
2499 "setting of the soft_wwpn\n", phba->brd_no);
2503 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2504 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2507 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2508 * Optimized Access Storage (OAS) operations.
2509 * @dev: class device that is converted into a Scsi_host.
2510 * @attr: device attribute, not used.
2511 * @buf: buffer for passing information.
2517 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2520 struct Scsi_Host *shost = class_to_shost(dev);
2521 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2523 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2524 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2528 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2529 * Optimized Access Storage (OAS) operations.
2530 * @dev: class device that is converted into a Scsi_host.
2531 * @attr: device attribute, not used.
2532 * @buf: buffer for passing information.
2533 * @count: Size of the data buffer.
2536 * -EINVAL count is invalid, invalid wwpn byte invalid
2537 * -EPERM oas is not supported by hba
2538 * value of count on success
2541 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2542 const char *buf, size_t count)
2544 struct Scsi_Host *shost = class_to_shost(dev);
2545 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2546 unsigned int cnt = count;
2547 uint8_t wwpn[WWN_SZ];
2553 /* count may include a LF at end of string */
2554 if (buf[cnt-1] == '\n')
2557 rc = lpfc_wwn_set(buf, cnt, wwpn);
2561 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2562 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2563 if (wwn_to_u64(wwpn) == 0)
2564 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2566 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2567 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2568 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2571 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2572 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2575 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2576 * Optimized Access Storage (OAS) operations.
2577 * @dev: class device that is converted into a Scsi_host.
2578 * @attr: device attribute, not used.
2579 * @buf: buffer for passing information.
2585 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2588 struct Scsi_Host *shost = class_to_shost(dev);
2589 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2591 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2595 * lpfc_oas_priority_store - Store 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.
2600 * @count: Size of the data buffer.
2603 * -EINVAL count is invalid, invalid wwpn byte invalid
2604 * -EPERM oas is not supported by hba
2605 * value of count on success
2608 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2609 const char *buf, size_t count)
2611 struct Scsi_Host *shost = class_to_shost(dev);
2612 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2613 unsigned int cnt = count;
2620 /* count may include a LF at end of string */
2621 if (buf[cnt-1] == '\n')
2624 ret = kstrtoul(buf, 0, &val);
2625 if (ret || (val > 0x7f))
2629 phba->cfg_oas_priority = (uint8_t)val;
2631 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2634 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2635 lpfc_oas_priority_show, lpfc_oas_priority_store);
2638 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2639 * for Optimized Access Storage (OAS) operations.
2640 * @dev: class device that is converted into a Scsi_host.
2641 * @attr: device attribute, not used.
2642 * @buf: buffer for passing information.
2645 * value of count on success
2648 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2651 struct Scsi_Host *shost = class_to_shost(dev);
2652 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2654 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2655 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2659 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2660 * for Optimized Access Storage (OAS) operations.
2661 * @dev: class device that is converted into a Scsi_host.
2662 * @attr: device attribute, not used.
2663 * @buf: buffer for passing information.
2664 * @count: Size of the data buffer.
2667 * -EINVAL count is invalid, invalid wwpn byte invalid
2668 * -EPERM oas is not supported by hba
2669 * value of count on success
2672 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2673 const char *buf, size_t count)
2675 struct Scsi_Host *shost = class_to_shost(dev);
2676 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2677 unsigned int cnt = count;
2678 uint8_t wwpn[WWN_SZ];
2684 /* count may include a LF at end of string */
2685 if (buf[cnt-1] == '\n')
2688 rc = lpfc_wwn_set(buf, cnt, wwpn);
2692 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2693 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2694 if (wwn_to_u64(wwpn) == 0)
2695 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2697 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2698 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2699 if (phba->cfg_oas_priority == 0)
2700 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2701 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2704 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2705 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2708 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2709 * of whether luns will be enabled or disabled
2710 * for Optimized Access Storage (OAS) operations.
2711 * @dev: class device that is converted into a Scsi_host.
2712 * @attr: device attribute, not used.
2713 * @buf: buffer for passing information.
2716 * size of formatted string.
2719 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2722 struct Scsi_Host *shost = class_to_shost(dev);
2723 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2725 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2729 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2730 * of whether luns will be enabled or disabled
2731 * for Optimized Access Storage (OAS) operations.
2732 * @dev: class device that is converted into a Scsi_host.
2733 * @attr: device attribute, not used.
2734 * @buf: buffer for passing information.
2735 * @count: Size of the data buffer.
2738 * -EINVAL count is invalid, invalid wwpn byte invalid
2739 * -EPERM oas is not supported by hba
2740 * value of count on success
2743 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2744 const char *buf, size_t count)
2746 struct Scsi_Host *shost = class_to_shost(dev);
2747 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2753 if (!isdigit(buf[0]))
2756 if (sscanf(buf, "%i", &val) != 1)
2759 if ((val != 0) && (val != 1))
2762 phba->cfg_oas_lun_state = val;
2765 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2766 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2769 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2770 * Storage (OAS) lun returned by the
2771 * lpfc_oas_lun_show function.
2772 * @dev: class device that is converted into a Scsi_host.
2773 * @attr: device attribute, not used.
2774 * @buf: buffer for passing information.
2777 * size of formatted string.
2780 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2783 struct Scsi_Host *shost = class_to_shost(dev);
2784 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2786 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2789 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2791 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2792 lpfc_oas_lun_status_show, NULL);
2796 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2798 * @phba: lpfc_hba pointer.
2799 * @ndlp: pointer to fcp target node.
2800 * @lun: the fc lun for setting oas state.
2801 * @oas_state: the oas state to be set to the lun.
2805 * -EPERM OAS is not enabled or not supported by this port.
2809 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2810 uint8_t tgt_wwpn[], uint64_t lun,
2811 uint32_t oas_state, uint8_t pri)
2820 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2821 (struct lpfc_name *)tgt_wwpn,
2825 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2826 (struct lpfc_name *)tgt_wwpn, lun, pri);
2833 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2834 * Access Storage (OAS) operations.
2835 * @phba: lpfc_hba pointer.
2836 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2837 * @tgt_wwpn: wwpn of the target associated with the returned lun
2838 * @lun_status: status of the lun returned lun
2840 * Returns the first or next lun enabled for OAS operations for the vport/target
2841 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2842 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2845 * lun that is OAS enabled for the vport/target
2846 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2849 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2850 uint8_t tgt_wwpn[], uint32_t *lun_status,
2855 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2856 return NOT_OAS_ENABLED_LUN;
2857 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2858 phba->sli4_hba.oas_next_vpt_wwpn,
2859 (struct lpfc_name *)
2860 phba->sli4_hba.oas_next_tgt_wwpn,
2861 &phba->sli4_hba.oas_next_lun,
2862 (struct lpfc_name *)vpt_wwpn,
2863 (struct lpfc_name *)tgt_wwpn,
2864 &found_lun, lun_status, lun_pri))
2867 return NOT_OAS_ENABLED_LUN;
2871 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2872 * @phba: lpfc_hba pointer.
2873 * @vpt_wwpn: vport wwpn by reference.
2874 * @tgt_wwpn: target wwpn by reference.
2875 * @lun: the fc lun for setting oas state.
2876 * @oas_state: the oas state to be set to the oas_lun.
2878 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2879 * a lun for OAS operations.
2883 * -ENOMEM: failed to enable an lun for OAS operations
2884 * -EPERM: OAS is not enabled
2887 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2888 uint8_t tgt_wwpn[], uint64_t lun,
2889 uint32_t oas_state, uint8_t pri)
2894 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2900 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2901 * @dev: class device that is converted into a Scsi_host.
2902 * @attr: device attribute, not used.
2903 * @buf: buffer for passing information.
2905 * This routine returns a lun enabled for OAS each time the function
2909 * SUCCESS: size of formatted string.
2910 * -EFAULT: target or vport wwpn was not set properly.
2911 * -EPERM: oas is not enabled.
2914 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2917 struct Scsi_Host *shost = class_to_shost(dev);
2918 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2926 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2927 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2930 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2931 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2934 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2935 phba->cfg_oas_tgt_wwpn,
2936 &phba->cfg_oas_lun_status,
2937 &phba->cfg_oas_priority);
2938 if (oas_lun != NOT_OAS_ENABLED_LUN)
2939 phba->cfg_oas_flags |= OAS_LUN_VALID;
2941 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2947 * lpfc_oas_lun_store - Sets the OAS state for lun
2948 * @dev: class device that is converted into a Scsi_host.
2949 * @attr: device attribute, not used.
2950 * @buf: buffer for passing information.
2952 * This function sets the OAS state for lun. Before this function is called,
2953 * the vport wwpn, target wwpn, and oas state need to be set.
2956 * SUCCESS: size of formatted string.
2957 * -EFAULT: target or vport wwpn was not set properly.
2958 * -EPERM: oas is not enabled.
2959 * size of formatted string.
2962 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2963 const char *buf, size_t count)
2965 struct Scsi_Host *shost = class_to_shost(dev);
2966 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2974 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2977 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2980 if (!isdigit(buf[0]))
2983 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2986 pri = phba->cfg_oas_priority;
2988 pri = phba->cfg_XLanePriority;
2990 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2991 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2992 "priority 0x%x with oas state %d\n",
2993 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2994 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
2995 pri, phba->cfg_oas_lun_state);
2997 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
2998 phba->cfg_oas_tgt_wwpn, scsi_lun,
2999 phba->cfg_oas_lun_state, pri);
3005 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3006 lpfc_oas_lun_show, lpfc_oas_lun_store);
3008 int lpfc_enable_nvmet_cnt;
3009 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3010 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3011 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3012 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3013 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3015 static int lpfc_poll = 0;
3016 module_param(lpfc_poll, int, S_IRUGO);
3017 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3019 " 1 - poll with interrupts enabled"
3020 " 3 - poll and disable FCP ring interrupts");
3022 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3023 lpfc_poll_show, lpfc_poll_store);
3025 int lpfc_no_hba_reset_cnt;
3026 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3027 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3028 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3029 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3031 LPFC_ATTR(sli_mode, 0, 0, 3,
3032 "SLI mode selector:"
3033 " 0 - auto (SLI-3 if supported),"
3034 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3035 " 3 - select SLI-3");
3037 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3038 "Enable NPIV functionality");
3040 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3041 "FCF Fast failover=1 Priority failover=2");
3044 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3045 # 0x0 = disabled, XRI/OXID use not tracked.
3046 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3047 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3049 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3050 "Enable RRQ functionality");
3053 # lpfc_suppress_link_up: Bring link up at initialization
3054 # 0x0 = bring link up (issue MBX_INIT_LINK)
3055 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3056 # 0x2 = never bring up link
3057 # Default value is 0.
3059 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3060 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3061 "Suppress Link Up at initialization");
3063 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3071 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3073 struct Scsi_Host *shost = class_to_shost(dev);
3074 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3076 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3079 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3080 lpfc_iocb_hw_show, NULL);
3082 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3084 struct Scsi_Host *shost = class_to_shost(dev);
3085 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3086 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3088 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
3091 static DEVICE_ATTR(txq_hw, S_IRUGO,
3092 lpfc_txq_hw_show, NULL);
3094 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3097 struct Scsi_Host *shost = class_to_shost(dev);
3098 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3099 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3101 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
3104 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3105 lpfc_txcmplq_hw_show, NULL);
3107 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3108 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3111 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3112 # until the timer expires. Value range is [0,255]. Default value is 30.
3114 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3115 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3116 module_param(lpfc_nodev_tmo, int, 0);
3117 MODULE_PARM_DESC(lpfc_nodev_tmo,
3118 "Seconds driver will hold I/O waiting "
3119 "for a device to come back");
3122 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3123 * @dev: class converted to a Scsi_host structure.
3124 * @attr: device attribute, not used.
3125 * @buf: on return contains the dev loss timeout in decimal.
3127 * Returns: size of formatted string.
3130 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3133 struct Scsi_Host *shost = class_to_shost(dev);
3134 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3136 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3140 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3141 * @vport: lpfc vport structure pointer.
3142 * @val: contains the nodev timeout value.
3145 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3146 * a kernel error message is printed and zero is returned.
3147 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3148 * Otherwise nodev tmo is set to the default value.
3151 * zero if already set or if val is in range
3152 * -EINVAL val out of range
3155 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3157 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3158 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3159 if (val != LPFC_DEF_DEVLOSS_TMO)
3160 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3161 "0407 Ignoring lpfc_nodev_tmo module "
3162 "parameter because lpfc_devloss_tmo "
3167 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3168 vport->cfg_nodev_tmo = val;
3169 vport->cfg_devloss_tmo = val;
3172 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3173 "0400 lpfc_nodev_tmo attribute cannot be set to"
3174 " %d, allowed range is [%d, %d]\n",
3175 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3176 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3181 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3182 * @vport: lpfc vport structure pointer.
3185 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3188 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3190 struct Scsi_Host *shost;
3191 struct lpfc_nodelist *ndlp;
3193 shost = lpfc_shost_from_vport(vport);
3194 spin_lock_irq(shost->host_lock);
3195 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3196 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
3197 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3198 spin_unlock_irq(shost->host_lock);
3202 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3203 * @vport: lpfc vport structure pointer.
3204 * @val: contains the tmo value.
3207 * If the devloss tmo is already set or the vport dev loss tmo has changed
3208 * then a kernel error message is printed and zero is returned.
3209 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3210 * Otherwise nodev tmo is set to the default value.
3213 * zero if already set or if val is in range
3214 * -EINVAL val out of range
3217 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3219 if (vport->dev_loss_tmo_changed ||
3220 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3221 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3222 "0401 Ignoring change to lpfc_nodev_tmo "
3223 "because lpfc_devloss_tmo is set.\n");
3226 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3227 vport->cfg_nodev_tmo = val;
3228 vport->cfg_devloss_tmo = val;
3230 * For compat: set the fc_host dev loss so new rports
3231 * will get the value.
3233 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3234 lpfc_update_rport_devloss_tmo(vport);
3237 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3238 "0403 lpfc_nodev_tmo attribute cannot be set to "
3239 "%d, allowed range is [%d, %d]\n",
3240 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3244 lpfc_vport_param_store(nodev_tmo)
3246 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3247 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3250 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3251 # disappear until the timer expires. Value range is [0,255]. Default
3254 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3255 MODULE_PARM_DESC(lpfc_devloss_tmo,
3256 "Seconds driver will hold I/O waiting "
3257 "for a device to come back");
3258 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3259 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3260 lpfc_vport_param_show(devloss_tmo)
3263 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3264 * @vport: lpfc vport structure pointer.
3265 * @val: contains the tmo value.
3268 * If val is in a valid range then set the vport nodev tmo,
3269 * devloss tmo, also set the vport dev loss tmo changed flag.
3270 * Else a kernel error message is printed.
3273 * zero if val is in range
3274 * -EINVAL val out of range
3277 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3279 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3280 vport->cfg_nodev_tmo = val;
3281 vport->cfg_devloss_tmo = val;
3282 vport->dev_loss_tmo_changed = 1;
3283 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3284 lpfc_update_rport_devloss_tmo(vport);
3288 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3289 "0404 lpfc_devloss_tmo attribute cannot be set to "
3290 "%d, allowed range is [%d, %d]\n",
3291 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3295 lpfc_vport_param_store(devloss_tmo)
3296 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3297 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3300 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3301 * lpfc_suppress_rsp = 0 Disable
3302 * lpfc_suppress_rsp = 1 Enable (default)
3305 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3306 "Enable suppress rsp feature is firmware supports it");
3309 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3310 * lpfc_nvmet_mrq = 1 use a single RQ pair
3311 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3314 LPFC_ATTR_R(nvmet_mrq,
3316 "Specify number of RQ pairs for processing NVMET cmds");
3319 * lpfc_nvmet_mrq_post: Specify number buffers to post on every MRQ
3322 LPFC_ATTR_R(nvmet_mrq_post, LPFC_DEF_MRQ_POST,
3323 LPFC_MIN_MRQ_POST, LPFC_MAX_MRQ_POST,
3324 "Specify number of buffers to post on every MRQ");
3327 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3328 * Supported Values: 1 - register just FCP
3329 * 3 - register both FCP and NVME
3330 * Supported values are [1,3]. Default value is 1
3332 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3333 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3334 "Define fc4 type to register with fabric.");
3337 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3338 * This parameter is only used if:
3339 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3340 * port is not configured for NVMET.
3342 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3343 * The remaining XRIs get split up based on lpfc_xri_split per port:
3345 * Supported Values are in percentages
3346 * the xri_split value is the percentage the SCSI port will get. The remaining
3347 * percentage will go to NVME.
3349 LPFC_ATTR_R(xri_split, 50, 10, 90,
3350 "Division of XRI resources between SCSI and NVME");
3353 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3354 # deluged with LOTS of information.
3355 # You can set a bit mask to record specific types of verbose messages:
3356 # See lpfc_logmsh.h for definitions.
3358 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3359 "Verbose logging bit-mask");
3362 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3363 # objects that have been registered with the nameserver after login.
3365 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3366 "Deregister nameserver objects before LOGO");
3369 # lun_queue_depth: This parameter is used to limit the number of outstanding
3370 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3371 # If this parameter value is greater than 1/8th the maximum number of exchanges
3372 # supported by the HBA port, then the lun queue depth will be reduced to
3373 # 1/8th the maximum number of exchanges.
3375 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3376 "Max number of FCP commands we can queue to a specific LUN");
3379 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3380 # commands per target port. Value range is [10,65535]. Default value is 65535.
3382 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3383 "Max number of FCP commands we can queue to a specific target port");
3386 # hba_queue_depth: This parameter is used to limit the number of outstanding
3387 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3388 # value is greater than the maximum number of exchanges supported by the HBA,
3389 # then maximum number of exchanges supported by the HBA is used to determine
3390 # the hba_queue_depth.
3392 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3393 "Max number of FCP commands we can queue to a lpfc HBA");
3396 # peer_port_login: This parameter allows/prevents logins
3397 # between peer ports hosted on the same physical port.
3398 # When this parameter is set 0 peer ports of same physical port
3399 # are not allowed to login to each other.
3400 # When this parameter is set 1 peer ports of same physical port
3401 # are allowed to login to each other.
3402 # Default value of this parameter is 0.
3404 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3405 "Allow peer ports on the same physical port to login to each "
3409 # restrict_login: This parameter allows/prevents logins
3410 # between Virtual Ports and remote initiators.
3411 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3412 # other initiators and will attempt to PLOGI all remote ports.
3413 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3414 # remote ports and will not attempt to PLOGI to other initiators.
3415 # This parameter does not restrict to the physical port.
3416 # This parameter does not restrict logins to Fabric resident remote ports.
3417 # Default value of this parameter is 1.
3419 static int lpfc_restrict_login = 1;
3420 module_param(lpfc_restrict_login, int, S_IRUGO);
3421 MODULE_PARM_DESC(lpfc_restrict_login,
3422 "Restrict virtual ports login to remote initiators.");
3423 lpfc_vport_param_show(restrict_login);
3426 * lpfc_restrict_login_init - Set the vport restrict login flag
3427 * @vport: lpfc vport structure pointer.
3428 * @val: contains the restrict login value.
3431 * If val is not in a valid range then log a kernel error message and set
3432 * the vport restrict login to one.
3433 * If the port type is physical clear the restrict login flag and return.
3434 * Else set the restrict login flag to val.
3437 * zero if val is in range
3438 * -EINVAL val out of range
3441 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3443 if (val < 0 || val > 1) {
3444 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3445 "0422 lpfc_restrict_login attribute cannot "
3446 "be set to %d, allowed range is [0, 1]\n",
3448 vport->cfg_restrict_login = 1;
3451 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3452 vport->cfg_restrict_login = 0;
3455 vport->cfg_restrict_login = val;
3460 * lpfc_restrict_login_set - Set the vport restrict login flag
3461 * @vport: lpfc vport structure pointer.
3462 * @val: contains the restrict login value.
3465 * If val is not in a valid range then log a kernel error message and set
3466 * the vport restrict login to one.
3467 * If the port type is physical and the val is not zero log a kernel
3468 * error message, clear the restrict login flag and return zero.
3469 * Else set the restrict login flag to val.
3472 * zero if val is in range
3473 * -EINVAL val out of range
3476 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3478 if (val < 0 || val > 1) {
3479 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3480 "0425 lpfc_restrict_login attribute cannot "
3481 "be set to %d, allowed range is [0, 1]\n",
3483 vport->cfg_restrict_login = 1;
3486 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3487 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3488 "0468 lpfc_restrict_login must be 0 for "
3489 "Physical ports.\n");
3490 vport->cfg_restrict_login = 0;
3493 vport->cfg_restrict_login = val;
3496 lpfc_vport_param_store(restrict_login);
3497 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3498 lpfc_restrict_login_show, lpfc_restrict_login_store);
3501 # Some disk devices have a "select ID" or "select Target" capability.
3502 # From a protocol standpoint "select ID" usually means select the
3503 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3504 # annex" which contains a table that maps a "select ID" (a number
3505 # between 0 and 7F) to an ALPA. By default, for compatibility with
3506 # older drivers, the lpfc driver scans this table from low ALPA to high
3509 # Turning on the scan-down variable (on = 1, off = 0) will
3510 # cause the lpfc driver to use an inverted table, effectively
3511 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3513 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3514 # and will not work across a fabric. Also this parameter will take
3515 # effect only in the case when ALPA map is not available.)
3517 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3518 "Start scanning for devices from highest ALPA to lowest");
3521 # lpfc_topology: link topology for init link
3522 # 0x0 = attempt loop mode then point-to-point
3523 # 0x01 = internal loopback mode
3524 # 0x02 = attempt point-to-point mode only
3525 # 0x04 = attempt loop mode only
3526 # 0x06 = attempt point-to-point mode then loop
3527 # Set point-to-point mode if you want to run as an N_Port.
3528 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3529 # Default value is 0.
3531 LPFC_ATTR(topology, 0, 0, 6,
3532 "Select Fibre Channel topology");
3535 * lpfc_topology_set - Set the adapters topology field
3536 * @phba: lpfc_hba pointer.
3537 * @val: topology value.
3540 * If val is in a valid range then set the adapter's topology field and
3541 * issue a lip; if the lip fails reset the topology to the old value.
3543 * If the value is not in range log a kernel error message and return an error.
3546 * zero if val is in range and lip okay
3547 * non-zero return value from lpfc_issue_lip()
3548 * -EINVAL val out of range
3551 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3552 const char *buf, size_t count)
3554 struct Scsi_Host *shost = class_to_shost(dev);
3555 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3556 struct lpfc_hba *phba = vport->phba;
3559 const char *val_buf = buf;
3563 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3565 val_buf = &buf[strlen("nolip ")];
3568 if (!isdigit(val_buf[0]))
3570 if (sscanf(val_buf, "%i", &val) != 1)
3573 if (val >= 0 && val <= 6) {
3574 prev_val = phba->cfg_topology;
3575 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3577 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3578 "3113 Loop mode not supported at speed %d\n",
3582 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3584 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3585 "3114 Loop mode not supported\n");
3588 phba->cfg_topology = val;
3592 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3593 "3054 lpfc_topology changed from %d to %d\n",
3595 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3596 phba->fc_topology_changed = 1;
3597 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3599 phba->cfg_topology = prev_val;
3604 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3605 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3606 "allowed range is [0, 6]\n",
3611 lpfc_param_show(topology)
3612 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3613 lpfc_topology_show, lpfc_topology_store);
3616 * lpfc_static_vport_show: Read callback function for
3617 * lpfc_static_vport sysfs file.
3618 * @dev: Pointer to class device object.
3619 * @attr: device attribute structure.
3620 * @buf: Data buffer.
3622 * This function is the read call back function for
3623 * lpfc_static_vport sysfs file. The lpfc_static_vport
3624 * sysfs file report the mageability of the vport.
3627 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3630 struct Scsi_Host *shost = class_to_shost(dev);
3631 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3632 if (vport->vport_flag & STATIC_VPORT)
3633 sprintf(buf, "1\n");
3635 sprintf(buf, "0\n");
3641 * Sysfs attribute to control the statistical data collection.
3643 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3644 lpfc_static_vport_show, NULL);
3647 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3648 * @dev: Pointer to class device.
3649 * @buf: Data buffer.
3650 * @count: Size of the data buffer.
3652 * This function get called when a user write to the lpfc_stat_data_ctrl
3653 * sysfs file. This function parse the command written to the sysfs file
3654 * and take appropriate action. These commands are used for controlling
3655 * driver statistical data collection.
3656 * Following are the command this function handles.
3658 * setbucket <bucket_type> <base> <step>
3659 * = Set the latency buckets.
3660 * destroybucket = destroy all the buckets.
3661 * start = start data collection
3662 * stop = stop data collection
3663 * reset = reset the collected data
3666 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3667 const char *buf, size_t count)
3669 struct Scsi_Host *shost = class_to_shost(dev);
3670 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3671 struct lpfc_hba *phba = vport->phba;
3672 #define LPFC_MAX_DATA_CTRL_LEN 1024
3673 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3675 char *str_ptr, *token;
3676 struct lpfc_vport **vports;
3677 struct Scsi_Host *v_shost;
3678 char *bucket_type_str, *base_str, *step_str;
3679 unsigned long base, step, bucket_type;
3681 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3682 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3685 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3686 str_ptr = &bucket_data[0];
3687 /* Ignore this token - this is command token */
3688 token = strsep(&str_ptr, "\t ");
3692 bucket_type_str = strsep(&str_ptr, "\t ");
3693 if (!bucket_type_str)
3696 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3697 bucket_type = LPFC_LINEAR_BUCKET;
3698 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3699 bucket_type = LPFC_POWER2_BUCKET;
3703 base_str = strsep(&str_ptr, "\t ");
3706 base = simple_strtoul(base_str, NULL, 0);
3708 step_str = strsep(&str_ptr, "\t ");
3711 step = simple_strtoul(step_str, NULL, 0);
3715 /* Block the data collection for every vport */
3716 vports = lpfc_create_vport_work_array(phba);
3720 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3721 v_shost = lpfc_shost_from_vport(vports[i]);
3722 spin_lock_irq(v_shost->host_lock);
3723 /* Block and reset data collection */
3724 vports[i]->stat_data_blocked = 1;
3725 if (vports[i]->stat_data_enabled)
3726 lpfc_vport_reset_stat_data(vports[i]);
3727 spin_unlock_irq(v_shost->host_lock);
3730 /* Set the bucket attributes */
3731 phba->bucket_type = bucket_type;
3732 phba->bucket_base = base;
3733 phba->bucket_step = step;
3735 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3736 v_shost = lpfc_shost_from_vport(vports[i]);
3738 /* Unblock data collection */
3739 spin_lock_irq(v_shost->host_lock);
3740 vports[i]->stat_data_blocked = 0;
3741 spin_unlock_irq(v_shost->host_lock);
3743 lpfc_destroy_vport_work_array(phba, vports);
3747 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3748 vports = lpfc_create_vport_work_array(phba);
3752 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3753 v_shost = lpfc_shost_from_vport(vports[i]);
3754 spin_lock_irq(shost->host_lock);
3755 vports[i]->stat_data_blocked = 1;
3756 lpfc_free_bucket(vport);
3757 vport->stat_data_enabled = 0;
3758 vports[i]->stat_data_blocked = 0;
3759 spin_unlock_irq(shost->host_lock);
3761 lpfc_destroy_vport_work_array(phba, vports);
3762 phba->bucket_type = LPFC_NO_BUCKET;
3763 phba->bucket_base = 0;
3764 phba->bucket_step = 0;
3768 if (!strncmp(buf, "start", strlen("start"))) {
3769 /* If no buckets configured return error */
3770 if (phba->bucket_type == LPFC_NO_BUCKET)
3772 spin_lock_irq(shost->host_lock);
3773 if (vport->stat_data_enabled) {
3774 spin_unlock_irq(shost->host_lock);
3777 lpfc_alloc_bucket(vport);
3778 vport->stat_data_enabled = 1;
3779 spin_unlock_irq(shost->host_lock);
3783 if (!strncmp(buf, "stop", strlen("stop"))) {
3784 spin_lock_irq(shost->host_lock);
3785 if (vport->stat_data_enabled == 0) {
3786 spin_unlock_irq(shost->host_lock);
3789 lpfc_free_bucket(vport);
3790 vport->stat_data_enabled = 0;
3791 spin_unlock_irq(shost->host_lock);
3795 if (!strncmp(buf, "reset", strlen("reset"))) {
3796 if ((phba->bucket_type == LPFC_NO_BUCKET)
3797 || !vport->stat_data_enabled)
3799 spin_lock_irq(shost->host_lock);
3800 vport->stat_data_blocked = 1;
3801 lpfc_vport_reset_stat_data(vport);
3802 vport->stat_data_blocked = 0;
3803 spin_unlock_irq(shost->host_lock);
3811 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3812 * @dev: Pointer to class device object.
3813 * @buf: Data buffer.
3815 * This function is the read call back function for
3816 * lpfc_stat_data_ctrl sysfs file. This function report the
3817 * current statistical data collection state.
3820 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3823 struct Scsi_Host *shost = class_to_shost(dev);
3824 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3825 struct lpfc_hba *phba = vport->phba;
3829 unsigned long bucket_value;
3831 switch (phba->bucket_type) {
3832 case LPFC_LINEAR_BUCKET:
3833 bucket_type = "linear";
3835 case LPFC_POWER2_BUCKET:
3836 bucket_type = "power2";
3839 bucket_type = "No Bucket";
3843 sprintf(&buf[index], "Statistical Data enabled :%d, "
3844 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3845 " Bucket step :%d\nLatency Ranges :",
3846 vport->stat_data_enabled, vport->stat_data_blocked,
3847 bucket_type, phba->bucket_base, phba->bucket_step);
3848 index = strlen(buf);
3849 if (phba->bucket_type != LPFC_NO_BUCKET) {
3850 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3851 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3852 bucket_value = phba->bucket_base +
3853 phba->bucket_step * i;
3855 bucket_value = phba->bucket_base +
3856 (1 << i) * phba->bucket_step;
3858 if (index + 10 > PAGE_SIZE)
3860 sprintf(&buf[index], "%08ld ", bucket_value);
3861 index = strlen(buf);
3864 sprintf(&buf[index], "\n");
3869 * Sysfs attribute to control the statistical data collection.
3871 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3872 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3875 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3879 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3882 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3883 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3884 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3888 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3890 * @kobj: Pointer to the kernel object
3891 * @bin_attr: Attribute object
3892 * @buff: Buffer pointer
3894 * @count: Buffer size
3896 * This function is the read call back function for lpfc_drvr_stat_data
3897 * sysfs file. This function export the statistical data to user
3901 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3902 struct bin_attribute *bin_attr,
3903 char *buf, loff_t off, size_t count)
3905 struct device *dev = container_of(kobj, struct device,
3907 struct Scsi_Host *shost = class_to_shost(dev);
3908 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3909 struct lpfc_hba *phba = vport->phba;
3910 int i = 0, index = 0;
3911 unsigned long nport_index;
3912 struct lpfc_nodelist *ndlp = NULL;
3913 nport_index = (unsigned long)off /
3914 MAX_STAT_DATA_SIZE_PER_TARGET;
3916 if (!vport->stat_data_enabled || vport->stat_data_blocked
3917 || (phba->bucket_type == LPFC_NO_BUCKET))
3920 spin_lock_irq(shost->host_lock);
3921 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3922 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3925 if (nport_index > 0) {
3930 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3934 if (!ndlp->lat_data)
3938 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3939 ndlp->nlp_portname.u.wwn[0],
3940 ndlp->nlp_portname.u.wwn[1],
3941 ndlp->nlp_portname.u.wwn[2],
3942 ndlp->nlp_portname.u.wwn[3],
3943 ndlp->nlp_portname.u.wwn[4],
3944 ndlp->nlp_portname.u.wwn[5],
3945 ndlp->nlp_portname.u.wwn[6],
3946 ndlp->nlp_portname.u.wwn[7]);
3948 index = strlen(buf);
3950 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3951 sprintf(&buf[index], "%010u,",
3952 ndlp->lat_data[i].cmd_count);
3953 index = strlen(buf);
3955 sprintf(&buf[index], "\n");
3956 index = strlen(buf);
3958 spin_unlock_irq(shost->host_lock);
3962 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3964 .name = "lpfc_drvr_stat_data",
3967 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3968 .read = sysfs_drvr_stat_data_read,
3973 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3975 # Value range is [0,16]. Default value is 0.
3978 * lpfc_link_speed_set - Set the adapters link speed
3979 * @phba: lpfc_hba pointer.
3980 * @val: link speed value.
3983 * If val is in a valid range then set the adapter's link speed field and
3984 * issue a lip; if the lip fails reset the link speed to the old value.
3987 * If the value is not in range log a kernel error message and return an error.
3990 * zero if val is in range and lip okay.
3991 * non-zero return value from lpfc_issue_lip()
3992 * -EINVAL val out of range
3995 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3996 const char *buf, size_t count)
3998 struct Scsi_Host *shost = class_to_shost(dev);
3999 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4000 struct lpfc_hba *phba = vport->phba;
4001 int val = LPFC_USER_LINK_SPEED_AUTO;
4003 const char *val_buf = buf;
4005 uint32_t prev_val, if_type;
4007 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4008 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4009 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4012 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4014 val_buf = &buf[strlen("nolip ")];
4017 if (!isdigit(val_buf[0]))
4019 if (sscanf(val_buf, "%i", &val) != 1)
4022 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4023 "3055 lpfc_link_speed changed from %d to %d %s\n",
4024 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4026 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4027 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4028 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4029 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4030 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4031 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4032 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
4033 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4034 "2879 lpfc_link_speed attribute cannot be set "
4035 "to %d. Speed is not supported by this port.\n",
4039 if (val == LPFC_USER_LINK_SPEED_16G &&
4040 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4041 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4042 "3112 lpfc_link_speed attribute cannot be set "
4043 "to %d. Speed is not supported in loop mode.\n",
4047 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4048 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4049 prev_val = phba->cfg_link_speed;
4050 phba->cfg_link_speed = val;
4054 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4056 phba->cfg_link_speed = prev_val;
4061 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4062 "0469 lpfc_link_speed attribute cannot be set to %d, "
4063 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
4067 static int lpfc_link_speed = 0;
4068 module_param(lpfc_link_speed, int, S_IRUGO);
4069 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4070 lpfc_param_show(link_speed)
4073 * lpfc_link_speed_init - Set the adapters link speed
4074 * @phba: lpfc_hba pointer.
4075 * @val: link speed value.
4078 * If val is in a valid range then set the adapter's link speed field.
4081 * If the value is not in range log a kernel error message, clear the link
4082 * speed and return an error.
4085 * zero if val saved.
4086 * -EINVAL val out of range
4089 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4091 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4093 "3111 lpfc_link_speed of %d cannot "
4094 "support loop mode, setting topology to default.\n",
4096 phba->cfg_topology = 0;
4098 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4099 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4100 phba->cfg_link_speed = val;
4103 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4104 "0405 lpfc_link_speed attribute cannot "
4105 "be set to %d, allowed values are "
4106 "["LPFC_LINK_SPEED_STRING"]\n", val);
4107 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4111 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
4112 lpfc_link_speed_show, lpfc_link_speed_store);
4115 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4116 # 0 = aer disabled or not supported
4117 # 1 = aer supported and enabled (default)
4118 # Value range is [0,1]. Default value is 1.
4120 LPFC_ATTR(aer_support, 1, 0, 1,
4121 "Enable PCIe device AER support");
4122 lpfc_param_show(aer_support)
4125 * lpfc_aer_support_store - Set the adapter for aer support
4127 * @dev: class device that is converted into a Scsi_host.
4128 * @attr: device attribute, not used.
4129 * @buf: containing enable or disable aer flag.
4130 * @count: unused variable.
4133 * If the val is 1 and currently the device's AER capability was not
4134 * enabled, invoke the kernel's enable AER helper routine, trying to
4135 * enable the device's AER capability. If the helper routine enabling
4136 * AER returns success, update the device's cfg_aer_support flag to
4137 * indicate AER is supported by the device; otherwise, if the device
4138 * AER capability is already enabled to support AER, then do nothing.
4140 * If the val is 0 and currently the device's AER support was enabled,
4141 * invoke the kernel's disable AER helper routine. After that, update
4142 * the device's cfg_aer_support flag to indicate AER is not supported
4143 * by the device; otherwise, if the device AER capability is already
4144 * disabled from supporting AER, then do nothing.
4147 * length of the buf on success if val is in range the intended mode
4149 * -EINVAL if val out of range or intended mode is not supported.
4152 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4153 const char *buf, size_t count)
4155 struct Scsi_Host *shost = class_to_shost(dev);
4156 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4157 struct lpfc_hba *phba = vport->phba;
4158 int val = 0, rc = -EINVAL;
4160 if (!isdigit(buf[0]))
4162 if (sscanf(buf, "%i", &val) != 1)
4167 if (phba->hba_flag & HBA_AER_ENABLED) {
4168 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4170 spin_lock_irq(&phba->hbalock);
4171 phba->hba_flag &= ~HBA_AER_ENABLED;
4172 spin_unlock_irq(&phba->hbalock);
4173 phba->cfg_aer_support = 0;
4178 phba->cfg_aer_support = 0;
4183 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4184 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4186 spin_lock_irq(&phba->hbalock);
4187 phba->hba_flag |= HBA_AER_ENABLED;
4188 spin_unlock_irq(&phba->hbalock);
4189 phba->cfg_aer_support = 1;
4194 phba->cfg_aer_support = 1;
4205 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4206 lpfc_aer_support_show, lpfc_aer_support_store);
4209 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4210 * @dev: class device that is converted into a Scsi_host.
4211 * @attr: device attribute, not used.
4212 * @buf: containing flag 1 for aer cleanup state.
4213 * @count: unused variable.
4216 * If the @buf contains 1 and the device currently has the AER support
4217 * enabled, then invokes the kernel AER helper routine
4218 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4219 * error status register.
4224 * -EINVAL if the buf does not contain the 1 or the device is not currently
4225 * enabled with the AER support.
4228 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4229 const char *buf, size_t count)
4231 struct Scsi_Host *shost = class_to_shost(dev);
4232 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4233 struct lpfc_hba *phba = vport->phba;
4236 if (!isdigit(buf[0]))
4238 if (sscanf(buf, "%i", &val) != 1)
4243 if (phba->hba_flag & HBA_AER_ENABLED)
4244 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4252 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4253 lpfc_aer_cleanup_state);
4256 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4258 * @dev: class device that is converted into a Scsi_host.
4259 * @attr: device attribute, not used.
4260 * @buf: containing the string the number of vfs to be enabled.
4261 * @count: unused variable.
4264 * When this api is called either through user sysfs, the driver shall
4265 * try to enable or disable SR-IOV virtual functions according to the
4268 * If zero virtual function has been enabled to the physical function,
4269 * the driver shall invoke the pci enable virtual function api trying
4270 * to enable the virtual functions. If the nr_vfn provided is greater
4271 * than the maximum supported, the maximum virtual function number will
4272 * be used for invoking the api; otherwise, the nr_vfn provided shall
4273 * be used for invoking the api. If the api call returned success, the
4274 * actual number of virtual functions enabled will be set to the driver
4275 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4276 * cfg_sriov_nr_virtfn remains zero.
4278 * If none-zero virtual functions have already been enabled to the
4279 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4280 * -EINVAL will be returned and the driver does nothing;
4282 * If the nr_vfn provided is zero and none-zero virtual functions have
4283 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4284 * disabling virtual function api shall be invoded to disable all the
4285 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4286 * zero. Otherwise, if zero virtual function has been enabled, do
4290 * length of the buf on success if val is in range the intended mode
4292 * -EINVAL if val out of range or intended mode is not supported.
4295 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4296 const char *buf, size_t count)
4298 struct Scsi_Host *shost = class_to_shost(dev);
4299 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4300 struct lpfc_hba *phba = vport->phba;
4301 struct pci_dev *pdev = phba->pcidev;
4302 int val = 0, rc = -EINVAL;
4304 /* Sanity check on user data */
4305 if (!isdigit(buf[0]))
4307 if (sscanf(buf, "%i", &val) != 1)
4312 /* Request disabling virtual functions */
4314 if (phba->cfg_sriov_nr_virtfn > 0) {
4315 pci_disable_sriov(pdev);
4316 phba->cfg_sriov_nr_virtfn = 0;
4321 /* Request enabling virtual functions */
4322 if (phba->cfg_sriov_nr_virtfn > 0) {
4323 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4324 "3018 There are %d virtual functions "
4325 "enabled on physical function.\n",
4326 phba->cfg_sriov_nr_virtfn);
4330 if (val <= LPFC_MAX_VFN_PER_PFN)
4331 phba->cfg_sriov_nr_virtfn = val;
4333 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4334 "3019 Enabling %d virtual functions is not "
4339 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4341 phba->cfg_sriov_nr_virtfn = 0;
4349 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4350 "Enable PCIe device SR-IOV virtual fn");
4352 lpfc_param_show(sriov_nr_virtfn)
4353 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4354 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4357 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4359 * @dev: class device that is converted into a Scsi_host.
4360 * @attr: device attribute, not used.
4361 * @buf: containing the string the number of vfs to be enabled.
4362 * @count: unused variable.
4367 * length of the buf on success if val is in range the intended mode
4369 * -EINVAL if val out of range or intended mode is not supported.
4372 lpfc_request_firmware_upgrade_store(struct device *dev,
4373 struct device_attribute *attr,
4374 const char *buf, size_t count)
4376 struct Scsi_Host *shost = class_to_shost(dev);
4377 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4378 struct lpfc_hba *phba = vport->phba;
4379 int val = 0, rc = -EINVAL;
4381 /* Sanity check on user data */
4382 if (!isdigit(buf[0]))
4384 if (sscanf(buf, "%i", &val) != 1)
4389 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4397 static int lpfc_req_fw_upgrade;
4398 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4399 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4400 lpfc_param_show(request_firmware_upgrade)
4403 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4404 * @phba: lpfc_hba pointer.
4408 * Set the initial Linux generic firmware upgrade enable or disable flag.
4411 * zero if val saved.
4412 * -EINVAL val out of range
4415 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4417 if (val >= 0 && val <= 1) {
4418 phba->cfg_request_firmware_upgrade = val;
4423 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4424 lpfc_request_firmware_upgrade_show,
4425 lpfc_request_firmware_upgrade_store);
4428 * lpfc_fcp_imax_store
4430 * @dev: class device that is converted into a Scsi_host.
4431 * @attr: device attribute, not used.
4432 * @buf: string with the number of fast-path FCP interrupts per second.
4433 * @count: unused variable.
4436 * If val is in a valid range [636,651042], then set the adapter's
4437 * maximum number of fast-path FCP interrupts per second.
4440 * length of the buf on success if val is in range the intended mode
4442 * -EINVAL if val out of range or intended mode is not supported.
4445 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4446 const char *buf, size_t count)
4448 struct Scsi_Host *shost = class_to_shost(dev);
4449 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4450 struct lpfc_hba *phba = vport->phba;
4453 /* fcp_imax is only valid for SLI4 */
4454 if (phba->sli_rev != LPFC_SLI_REV4)
4457 /* Sanity check on user data */
4458 if (!isdigit(buf[0]))
4460 if (sscanf(buf, "%i", &val) != 1)
4464 * Value range for the HBA is [5000,5000000]
4465 * The value for each EQ depends on how many EQs are configured.
4468 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4471 phba->cfg_fcp_imax = (uint32_t)val;
4473 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4474 lpfc_modify_hba_eq_delay(phba, i);
4480 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4483 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4485 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4486 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4487 MODULE_PARM_DESC(lpfc_fcp_imax,
4488 "Set the maximum number of FCP interrupts per second per HBA");
4489 lpfc_param_show(fcp_imax)
4492 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4493 * @phba: lpfc_hba pointer.
4494 * @val: link speed value.
4497 * If val is in a valid range [636,651042], then initialize the adapter's
4498 * maximum number of fast-path FCP interrupts per second.
4501 * zero if val saved.
4502 * -EINVAL val out of range
4505 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4507 if (phba->sli_rev != LPFC_SLI_REV4) {
4508 phba->cfg_fcp_imax = 0;
4512 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4514 phba->cfg_fcp_imax = val;
4518 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4519 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4521 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4526 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4527 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4530 * lpfc_state_show - Display current driver CPU affinity
4531 * @dev: class converted to a Scsi_host structure.
4532 * @attr: device attribute, not used.
4533 * @buf: on return contains text describing the state of the link.
4535 * Returns: size of formatted string.
4538 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4541 struct Scsi_Host *shost = class_to_shost(dev);
4542 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4543 struct lpfc_hba *phba = vport->phba;
4544 struct lpfc_vector_map_info *cpup;
4547 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4548 (phba->intr_type != MSIX))
4551 switch (phba->cfg_fcp_cpu_map) {
4553 len += snprintf(buf + len, PAGE_SIZE-len,
4554 "fcp_cpu_map: No mapping (%d)\n",
4555 phba->cfg_fcp_cpu_map);
4558 len += snprintf(buf + len, PAGE_SIZE-len,
4559 "fcp_cpu_map: HBA centric mapping (%d): "
4561 phba->cfg_fcp_cpu_map,
4562 phba->sli4_hba.num_online_cpu);
4565 len += snprintf(buf + len, PAGE_SIZE-len,
4566 "fcp_cpu_map: Driver centric mapping (%d): "
4568 phba->cfg_fcp_cpu_map,
4569 phba->sli4_hba.num_online_cpu);
4573 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4574 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4576 /* margin should fit in this and the truncated message */
4577 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4578 len += snprintf(buf + len, PAGE_SIZE-len,
4579 "CPU %02d io_chan %02d "
4580 "physid %d coreid %d\n",
4581 phba->sli4_hba.curr_disp_cpu,
4582 cpup->channel_id, cpup->phys_id,
4585 len += snprintf(buf + len, PAGE_SIZE-len,
4586 "CPU %02d io_chan %02d "
4587 "physid %d coreid %d IRQ %d\n",
4588 phba->sli4_hba.curr_disp_cpu,
4589 cpup->channel_id, cpup->phys_id,
4590 cpup->core_id, cpup->irq);
4592 phba->sli4_hba.curr_disp_cpu++;
4594 /* display max number of CPUs keeping some margin */
4595 if (phba->sli4_hba.curr_disp_cpu <
4596 phba->sli4_hba.num_present_cpu &&
4597 (len >= (PAGE_SIZE - 64))) {
4598 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4603 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4604 phba->sli4_hba.curr_disp_cpu = 0;
4610 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4611 * @dev: class device that is converted into a Scsi_host.
4612 * @attr: device attribute, not used.
4613 * @buf: one or more lpfc_polling_flags values.
4617 * -EINVAL - Not implemented yet.
4620 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4621 const char *buf, size_t count)
4623 int status = -EINVAL;
4628 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4631 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4632 # 0 - Do not affinitze IRQ vectors
4633 # 1 - Affintize HBA vectors with respect to each HBA
4634 # (start with CPU0 for each HBA)
4635 # 2 - Affintize HBA vectors with respect to the entire driver
4636 # (round robin thru all CPUs across all HBAs)
4638 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4639 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4640 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4641 "Defines how to map CPUs to IRQ vectors per HBA");
4644 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4645 * @phba: lpfc_hba pointer.
4646 * @val: link speed value.
4649 * If val is in a valid range [0-2], then affinitze the adapter's
4653 * zero if val saved.
4654 * -EINVAL val out of range
4657 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4659 if (phba->sli_rev != LPFC_SLI_REV4) {
4660 phba->cfg_fcp_cpu_map = 0;
4664 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4665 phba->cfg_fcp_cpu_map = val;
4669 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4670 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4672 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4677 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4678 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4681 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4682 # Value range is [2,3]. Default value is 3.
4684 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4685 "Select Fibre Channel class of service for FCP sequences");
4688 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4689 # is [0,1]. Default value is 0.
4691 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4692 "Use ADISC on rediscovery to authenticate FCP devices");
4695 # lpfc_first_burst_size: First burst size to use on the NPorts
4696 # that support first burst.
4697 # Value range is [0,65536]. Default value is 0.
4699 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4700 "First burst size for Targets that support first burst");
4703 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4704 * When the driver is configured as an NVME target, this value is
4705 * communicated to the NVME initiator in the PRLI response. It is
4706 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4707 * parameters are set and the target is sending the PRLI RSP.
4708 * Parameter supported on physical port only - no NPIV support.
4709 * Value range is [0,65536]. Default value is 0.
4711 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4712 "NVME Target mode first burst size in 512B increments.");
4715 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4716 * For the Initiator (I), enabling this parameter means that an NVMET
4717 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4718 * processed by the initiator for subsequent NVME FCP IO. For the target
4719 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4720 * driver parameter as the target function's first burst size returned to the
4721 * initiator in the target's NVME PRLI response. Parameter supported on physical
4722 * port only - no NPIV support.
4723 * Value range is [0,1]. Default value is 0 (disabled).
4725 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4726 "Enable First Burst feature on I and T functions.");
4729 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4730 # depth. Default value is 0. When the value of this parameter is zero the
4731 # SCSI command completion time is not used for controlling I/O queue depth. When
4732 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4733 # to limit the I/O completion time to the parameter value.
4734 # The value is set in milliseconds.
4736 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4737 "Use command completion time to control queue depth");
4739 lpfc_vport_param_show(max_scsicmpl_time);
4741 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4744 struct lpfc_nodelist *ndlp, *next_ndlp;
4746 if (val == vport->cfg_max_scsicmpl_time)
4748 if ((val < 0) || (val > 60000))
4750 vport->cfg_max_scsicmpl_time = val;
4752 spin_lock_irq(shost->host_lock);
4753 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4754 if (!NLP_CHK_NODE_ACT(ndlp))
4756 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4758 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4760 spin_unlock_irq(shost->host_lock);
4763 lpfc_vport_param_store(max_scsicmpl_time);
4764 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4765 lpfc_max_scsicmpl_time_show,
4766 lpfc_max_scsicmpl_time_store);
4769 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4770 # range is [0,1]. Default value is 0.
4772 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4775 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4776 * range is [0,1]. Default value is 0.
4777 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4778 * For [1], FCP commands are issued to a Work Queue associated with the
4781 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4782 * LPFC_FCP_SCHED_BY_CPU == 1
4784 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4785 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4786 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4787 * through WQs will be used.
4789 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4790 LPFC_FCP_SCHED_ROUND_ROBIN,
4791 LPFC_FCP_SCHED_BY_CPU,
4792 "Determine scheduling algorithm for "
4793 "issuing commands [0] - Round Robin, [1] - Current CPU");
4796 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4797 # range is [0,1]. Default value is 0.
4798 # For [0], bus reset issues target reset to ALL devices
4799 # For [1], bus reset issues target reset to non-FCP2 devices
4801 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4802 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4806 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4807 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4808 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4809 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4810 # cr_delay is set to 0.
4812 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4813 "interrupt response is generated");
4815 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4816 "interrupt response is generated");
4819 # lpfc_multi_ring_support: Determines how many rings to spread available
4820 # cmd/rsp IOCB entries across.
4821 # Value range is [1,2]. Default value is 1.
4823 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4824 "SLI rings to spread IOCB entries across");
4827 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4828 # identifies what rctl value to configure the additional ring for.
4829 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4831 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4832 255, "Identifies RCTL for additional ring configuration");
4835 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4836 # identifies what type value to configure the additional ring for.
4837 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4839 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4840 255, "Identifies TYPE for additional ring configuration");
4843 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4844 # 0 = SmartSAN functionality disabled (default)
4845 # 1 = SmartSAN functionality enabled
4846 # This parameter will override the value of lpfc_fdmi_on module parameter.
4847 # Value range is [0,1]. Default value is 0.
4849 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4852 # lpfc_fdmi_on: Controls FDMI support.
4853 # 0 No FDMI support (default)
4854 # 1 Traditional FDMI support
4855 # Traditional FDMI support means the driver will assume FDMI-2 support;
4856 # however, if that fails, it will fallback to FDMI-1.
4857 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4858 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4860 # Value range [0,1]. Default value is 0.
4862 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4865 # Specifies the maximum number of ELS cmds we can have outstanding (for
4866 # discovery). Value range is [1,64]. Default value = 32.
4868 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4869 "during discovery");
4872 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4873 # will be scanned by the SCSI midlayer when sequential scanning is
4874 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4875 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4876 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4877 # above. The lpfc driver limits the default value to 255 for two reasons.
4878 # As it bounds the sequential scan loop, scanning for thousands of luns
4879 # on a target can take minutes of wall clock time. Additionally,
4880 # there are FC targets, such as JBODs, that only recognize 8-bits of
4881 # LUN ID. When they receive a value greater than 8 bits, they chop off
4882 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4883 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4884 # valid responses at each of the LUN IDs, to believe there are multiple
4885 # devices present, when in fact, there is only 1.
4886 # A customer that is aware of their target behaviors, and the results as
4887 # indicated above, is welcome to increase the lpfc_max_luns value.
4888 # As mentioned, this value is not used by the lpfc driver, only the
4890 # Value range is [0,65535]. Default value is 255.
4891 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4893 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4896 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4897 # Value range is [1,255], default value is 10.
4899 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4900 "Milliseconds driver will wait between polling FCP ring");
4903 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4904 # to complete in seconds. Value range is [5,180], default value is 60.
4906 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4907 "Maximum time to wait for task management commands to complete");
4909 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4910 # support this feature
4913 # 2 = MSI-X enabled (default)
4914 # Value range is [0,2]. Default value is 2.
4916 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4917 "MSI-X (2), if possible");
4920 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4922 * 0 = NVME OAS disabled
4923 * 1 = NVME OAS enabled
4925 * Value range is [0,1]. Default value is 0.
4927 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4928 "Use OAS bit on NVME IOs");
4931 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4932 * will advertise it supports to the SCSI layer. This also will map to
4933 * the number of WQs the driver will create.
4935 * 0 = Configure the number of io channels to the number of active CPUs.
4936 * 1,32 = Manually specify how many io channels to use.
4938 * Value range is [0,32]. Default value is 4.
4940 LPFC_ATTR_R(fcp_io_channel,
4941 LPFC_FCP_IO_CHAN_DEF,
4942 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4943 "Set the number of FCP I/O channels");
4946 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4947 * will advertise it supports to the NVME layer. This also will map to
4948 * the number of WQs the driver will create.
4950 * This module parameter is valid when lpfc_enable_fc4_type is set
4953 * The NVME Layer will try to create this many, plus 1 administrative
4954 * hardware queue. The administrative queue will always map to WQ 0
4955 * A hardware IO queue maps (qidx) to a specific driver WQ.
4957 * 0 = Configure the number of io channels to the number of active CPUs.
4958 * 1,32 = Manually specify how many io channels to use.
4960 * Value range is [0,32]. Default value is 0.
4962 LPFC_ATTR_R(nvme_io_channel,
4963 LPFC_NVME_IO_CHAN_DEF,
4964 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4965 "Set the number of NVME I/O channels");
4968 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4969 # 0 = HBA resets disabled
4970 # 1 = HBA resets enabled (default)
4971 # Value range is [0,1]. Default value is 1.
4973 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
4976 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
4977 # 0 = HBA Heartbeat disabled
4978 # 1 = HBA Heartbeat enabled (default)
4979 # Value range is [0,1]. Default value is 1.
4981 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
4984 # lpfc_EnableXLane: Enable Express Lane Feature
4985 # 0x0 Express Lane Feature disabled
4986 # 0x1 Express Lane Feature enabled
4987 # Value range is [0,1]. Default value is 0.
4989 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4992 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4993 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4994 # Value range is [0x0,0x7f]. Default value is 0
4996 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
4999 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5000 # 0 = BlockGuard disabled (default)
5001 # 1 = BlockGuard enabled
5002 # Value range is [0,1]. Default value is 0.
5004 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5007 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5008 # 0 = disabled (default)
5010 # Value range is [0,1]. Default value is 0.
5012 # This feature in under investigation and may be supported in the future.
5014 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5018 # - Bit mask of host protection capabilities used to register with the
5020 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5021 # - Allows you to ultimately specify which profiles to use
5022 # - Default will result in registering capabilities for all profiles.
5023 # - SHOST_DIF_TYPE1_PROTECTION 1
5024 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5025 # - SHOST_DIX_TYPE0_PROTECTION 8
5026 # HBA supports DIX Type 0: Host to HBA protection only
5027 # - SHOST_DIX_TYPE1_PROTECTION 16
5028 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5031 LPFC_ATTR(prot_mask,
5032 (SHOST_DIF_TYPE1_PROTECTION |
5033 SHOST_DIX_TYPE0_PROTECTION |
5034 SHOST_DIX_TYPE1_PROTECTION),
5036 (SHOST_DIF_TYPE1_PROTECTION |
5037 SHOST_DIX_TYPE0_PROTECTION |
5038 SHOST_DIX_TYPE1_PROTECTION),
5039 "T10-DIF host protection capabilities mask");
5042 # lpfc_prot_guard: i
5043 # - Bit mask of protection guard types to register with the SCSI mid-layer
5044 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5045 # - Allows you to ultimately specify which profiles to use
5046 # - Default will result in registering capabilities for all guard types
5049 LPFC_ATTR(prot_guard,
5050 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5051 "T10-DIF host protection guard type");
5054 * Delay initial NPort discovery when Clean Address bit is cleared in
5055 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5056 * This parameter can have value 0 or 1.
5057 * When this parameter is set to 0, no delay is added to the initial
5059 * When this parameter is set to non-zero value, initial Nport discovery is
5060 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5061 * accept and FCID/Fabric name/Fabric portname is changed.
5062 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5063 * when Clean Address bit is cleared in FLOGI/FDISC
5064 * accept and FCID/Fabric name/Fabric portname is changed.
5065 * Default value is 0.
5067 LPFC_ATTR(delay_discovery, 0, 0, 1,
5068 "Delay NPort discovery when Clean Address bit is cleared.");
5071 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5072 * This value can be set to values between 64 and 4096. The default value is
5073 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5074 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5075 * Because of the additional overhead involved in setting up T10-DIF,
5076 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5077 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5079 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5080 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5083 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5084 * 0 = MDS Diagnostics disabled (default)
5085 * 1 = MDS Diagnostics enabled
5086 * Value range is [0,1]. Default value is 0.
5088 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5090 struct device_attribute *lpfc_hba_attrs[] = {
5091 &dev_attr_nvme_info,
5093 &dev_attr_bg_guard_err,
5094 &dev_attr_bg_apptag_err,
5095 &dev_attr_bg_reftag_err,
5097 &dev_attr_serialnum,
5098 &dev_attr_modeldesc,
5099 &dev_attr_modelname,
5100 &dev_attr_programtype,
5104 &dev_attr_option_rom_version,
5105 &dev_attr_link_state,
5106 &dev_attr_num_discovered_ports,
5107 &dev_attr_menlo_mgmt_mode,
5108 &dev_attr_lpfc_drvr_version,
5109 &dev_attr_lpfc_enable_fip,
5110 &dev_attr_lpfc_temp_sensor,
5111 &dev_attr_lpfc_log_verbose,
5112 &dev_attr_lpfc_lun_queue_depth,
5113 &dev_attr_lpfc_tgt_queue_depth,
5114 &dev_attr_lpfc_hba_queue_depth,
5115 &dev_attr_lpfc_peer_port_login,
5116 &dev_attr_lpfc_nodev_tmo,
5117 &dev_attr_lpfc_devloss_tmo,
5118 &dev_attr_lpfc_enable_fc4_type,
5119 &dev_attr_lpfc_xri_split,
5120 &dev_attr_lpfc_fcp_class,
5121 &dev_attr_lpfc_use_adisc,
5122 &dev_attr_lpfc_first_burst_size,
5123 &dev_attr_lpfc_ack0,
5124 &dev_attr_lpfc_topology,
5125 &dev_attr_lpfc_scan_down,
5126 &dev_attr_lpfc_link_speed,
5127 &dev_attr_lpfc_fcp_io_sched,
5128 &dev_attr_lpfc_fcp2_no_tgt_reset,
5129 &dev_attr_lpfc_cr_delay,
5130 &dev_attr_lpfc_cr_count,
5131 &dev_attr_lpfc_multi_ring_support,
5132 &dev_attr_lpfc_multi_ring_rctl,
5133 &dev_attr_lpfc_multi_ring_type,
5134 &dev_attr_lpfc_fdmi_on,
5135 &dev_attr_lpfc_enable_SmartSAN,
5136 &dev_attr_lpfc_max_luns,
5137 &dev_attr_lpfc_enable_npiv,
5138 &dev_attr_lpfc_fcf_failover_policy,
5139 &dev_attr_lpfc_enable_rrq,
5140 &dev_attr_nport_evt_cnt,
5141 &dev_attr_board_mode,
5148 &dev_attr_npiv_info,
5149 &dev_attr_issue_reset,
5150 &dev_attr_lpfc_poll,
5151 &dev_attr_lpfc_poll_tmo,
5152 &dev_attr_lpfc_task_mgmt_tmo,
5153 &dev_attr_lpfc_use_msi,
5154 &dev_attr_lpfc_nvme_oas,
5155 &dev_attr_lpfc_fcp_imax,
5156 &dev_attr_lpfc_fcp_cpu_map,
5157 &dev_attr_lpfc_fcp_io_channel,
5158 &dev_attr_lpfc_suppress_rsp,
5159 &dev_attr_lpfc_nvme_io_channel,
5160 &dev_attr_lpfc_nvmet_mrq,
5161 &dev_attr_lpfc_nvmet_mrq_post,
5162 &dev_attr_lpfc_nvme_enable_fb,
5163 &dev_attr_lpfc_nvmet_fb_size,
5164 &dev_attr_lpfc_enable_bg,
5165 &dev_attr_lpfc_soft_wwnn,
5166 &dev_attr_lpfc_soft_wwpn,
5167 &dev_attr_lpfc_soft_wwn_enable,
5168 &dev_attr_lpfc_enable_hba_reset,
5169 &dev_attr_lpfc_enable_hba_heartbeat,
5170 &dev_attr_lpfc_EnableXLane,
5171 &dev_attr_lpfc_XLanePriority,
5172 &dev_attr_lpfc_xlane_lun,
5173 &dev_attr_lpfc_xlane_tgt,
5174 &dev_attr_lpfc_xlane_vpt,
5175 &dev_attr_lpfc_xlane_lun_state,
5176 &dev_attr_lpfc_xlane_lun_status,
5177 &dev_attr_lpfc_xlane_priority,
5178 &dev_attr_lpfc_sg_seg_cnt,
5179 &dev_attr_lpfc_max_scsicmpl_time,
5180 &dev_attr_lpfc_stat_data_ctrl,
5181 &dev_attr_lpfc_aer_support,
5182 &dev_attr_lpfc_aer_state_cleanup,
5183 &dev_attr_lpfc_sriov_nr_virtfn,
5184 &dev_attr_lpfc_req_fw_upgrade,
5185 &dev_attr_lpfc_suppress_link_up,
5186 &dev_attr_lpfc_iocb_cnt,
5189 &dev_attr_txcmplq_hw,
5190 &dev_attr_lpfc_fips_level,
5191 &dev_attr_lpfc_fips_rev,
5193 &dev_attr_lpfc_sriov_hw_max_virtfn,
5195 &dev_attr_lpfc_xlane_supported,
5196 &dev_attr_lpfc_enable_mds_diags,
5200 struct device_attribute *lpfc_vport_attrs[] = {
5202 &dev_attr_link_state,
5203 &dev_attr_num_discovered_ports,
5204 &dev_attr_lpfc_drvr_version,
5205 &dev_attr_lpfc_log_verbose,
5206 &dev_attr_lpfc_lun_queue_depth,
5207 &dev_attr_lpfc_tgt_queue_depth,
5208 &dev_attr_lpfc_nodev_tmo,
5209 &dev_attr_lpfc_devloss_tmo,
5210 &dev_attr_lpfc_hba_queue_depth,
5211 &dev_attr_lpfc_peer_port_login,
5212 &dev_attr_lpfc_restrict_login,
5213 &dev_attr_lpfc_fcp_class,
5214 &dev_attr_lpfc_use_adisc,
5215 &dev_attr_lpfc_first_burst_size,
5216 &dev_attr_lpfc_max_luns,
5217 &dev_attr_nport_evt_cnt,
5218 &dev_attr_npiv_info,
5219 &dev_attr_lpfc_enable_da_id,
5220 &dev_attr_lpfc_max_scsicmpl_time,
5221 &dev_attr_lpfc_stat_data_ctrl,
5222 &dev_attr_lpfc_static_vport,
5223 &dev_attr_lpfc_fips_level,
5224 &dev_attr_lpfc_fips_rev,
5229 * sysfs_ctlreg_write - Write method for writing to ctlreg
5230 * @filp: open sysfs file
5231 * @kobj: kernel kobject that contains the kernel class device.
5232 * @bin_attr: kernel attributes passed to us.
5233 * @buf: contains the data to be written to the adapter IOREG space.
5234 * @off: offset into buffer to beginning of data.
5235 * @count: bytes to transfer.
5238 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5239 * Uses the adapter io control registers to send buf contents to the adapter.
5242 * -ERANGE off and count combo out of range
5243 * -EINVAL off, count or buff address invalid
5244 * -EPERM adapter is offline
5245 * value of count, buf contents written
5248 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5249 struct bin_attribute *bin_attr,
5250 char *buf, loff_t off, size_t count)
5253 struct device *dev = container_of(kobj, struct device, kobj);
5254 struct Scsi_Host *shost = class_to_shost(dev);
5255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5256 struct lpfc_hba *phba = vport->phba;
5258 if (phba->sli_rev >= LPFC_SLI_REV4)
5261 if ((off + count) > FF_REG_AREA_SIZE)
5264 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5267 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5270 /* This is to protect HBA registers from accidental writes. */
5271 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5274 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5277 spin_lock_irq(&phba->hbalock);
5278 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5279 buf_off += sizeof(uint32_t))
5280 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5281 phba->ctrl_regs_memmap_p + off + buf_off);
5283 spin_unlock_irq(&phba->hbalock);
5289 * sysfs_ctlreg_read - Read method for reading from ctlreg
5290 * @filp: open sysfs file
5291 * @kobj: kernel kobject that contains the kernel class device.
5292 * @bin_attr: kernel attributes passed to us.
5293 * @buf: if successful contains the data from the adapter IOREG space.
5294 * @off: offset into buffer to beginning of data.
5295 * @count: bytes to transfer.
5298 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5299 * Uses the adapter io control registers to read data into buf.
5302 * -ERANGE off and count combo out of range
5303 * -EINVAL off, count or buff address invalid
5304 * value of count, buf contents read
5307 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5308 struct bin_attribute *bin_attr,
5309 char *buf, loff_t off, size_t count)
5313 struct device *dev = container_of(kobj, struct device, kobj);
5314 struct Scsi_Host *shost = class_to_shost(dev);
5315 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5316 struct lpfc_hba *phba = vport->phba;
5318 if (phba->sli_rev >= LPFC_SLI_REV4)
5321 if (off > FF_REG_AREA_SIZE)
5324 if ((off + count) > FF_REG_AREA_SIZE)
5325 count = FF_REG_AREA_SIZE - off;
5327 if (count == 0) return 0;
5329 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5332 spin_lock_irq(&phba->hbalock);
5334 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5335 tmp_ptr = (uint32_t *)(buf + buf_off);
5336 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5339 spin_unlock_irq(&phba->hbalock);
5344 static struct bin_attribute sysfs_ctlreg_attr = {
5347 .mode = S_IRUSR | S_IWUSR,
5350 .read = sysfs_ctlreg_read,
5351 .write = sysfs_ctlreg_write,
5355 * sysfs_mbox_write - Write method for writing information via mbox
5356 * @filp: open sysfs file
5357 * @kobj: kernel kobject that contains the kernel class device.
5358 * @bin_attr: kernel attributes passed to us.
5359 * @buf: contains the data to be written to sysfs mbox.
5360 * @off: offset into buffer to beginning of data.
5361 * @count: bytes to transfer.
5364 * Deprecated function. All mailbox access from user space is performed via the
5368 * -EPERM operation not permitted
5371 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5372 struct bin_attribute *bin_attr,
5373 char *buf, loff_t off, size_t count)
5379 * sysfs_mbox_read - Read method for reading information via mbox
5380 * @filp: open sysfs file
5381 * @kobj: kernel kobject that contains the kernel class device.
5382 * @bin_attr: kernel attributes passed to us.
5383 * @buf: contains the data to be read from sysfs mbox.
5384 * @off: offset into buffer to beginning of data.
5385 * @count: bytes to transfer.
5388 * Deprecated function. All mailbox access from user space is performed via the
5392 * -EPERM operation not permitted
5395 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5396 struct bin_attribute *bin_attr,
5397 char *buf, loff_t off, size_t count)
5402 static struct bin_attribute sysfs_mbox_attr = {
5405 .mode = S_IRUSR | S_IWUSR,
5407 .size = MAILBOX_SYSFS_MAX,
5408 .read = sysfs_mbox_read,
5409 .write = sysfs_mbox_write,
5413 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5414 * @vport: address of lpfc vport structure.
5418 * error return code from sysfs_create_bin_file()
5421 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5423 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5426 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5427 &sysfs_drvr_stat_data_attr);
5429 /* Virtual ports do not need ctrl_reg and mbox */
5430 if (error || vport->port_type == LPFC_NPIV_PORT)
5433 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5434 &sysfs_ctlreg_attr);
5436 goto out_remove_stat_attr;
5438 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5441 goto out_remove_ctlreg_attr;
5444 out_remove_ctlreg_attr:
5445 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5446 out_remove_stat_attr:
5447 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5448 &sysfs_drvr_stat_data_attr);
5454 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5455 * @vport: address of lpfc vport structure.
5458 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5460 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5461 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5462 &sysfs_drvr_stat_data_attr);
5463 /* Virtual ports do not need ctrl_reg and mbox */
5464 if (vport->port_type == LPFC_NPIV_PORT)
5466 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5467 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5471 * Dynamic FC Host Attributes Support
5475 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5476 * @shost: kernel scsi host pointer.
5479 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5481 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5483 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5484 sizeof fc_host_symbolic_name(shost));
5488 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5489 * @shost: kernel scsi host pointer.
5492 lpfc_get_host_port_id(struct Scsi_Host *shost)
5494 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5496 /* note: fc_myDID already in cpu endianness */
5497 fc_host_port_id(shost) = vport->fc_myDID;
5501 * lpfc_get_host_port_type - Set the value of the scsi host port type
5502 * @shost: kernel scsi host pointer.
5505 lpfc_get_host_port_type(struct Scsi_Host *shost)
5507 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5508 struct lpfc_hba *phba = vport->phba;
5510 spin_lock_irq(shost->host_lock);
5512 if (vport->port_type == LPFC_NPIV_PORT) {
5513 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5514 } else if (lpfc_is_link_up(phba)) {
5515 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5516 if (vport->fc_flag & FC_PUBLIC_LOOP)
5517 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5519 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5521 if (vport->fc_flag & FC_FABRIC)
5522 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5524 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5527 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5529 spin_unlock_irq(shost->host_lock);
5533 * lpfc_get_host_port_state - Set the value of the scsi host port state
5534 * @shost: kernel scsi host pointer.
5537 lpfc_get_host_port_state(struct Scsi_Host *shost)
5539 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5540 struct lpfc_hba *phba = vport->phba;
5542 spin_lock_irq(shost->host_lock);
5544 if (vport->fc_flag & FC_OFFLINE_MODE)
5545 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5547 switch (phba->link_state) {
5548 case LPFC_LINK_UNKNOWN:
5549 case LPFC_LINK_DOWN:
5550 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5554 case LPFC_HBA_READY:
5555 /* Links up, reports port state accordingly */
5556 if (vport->port_state < LPFC_VPORT_READY)
5557 fc_host_port_state(shost) =
5558 FC_PORTSTATE_BYPASSED;
5560 fc_host_port_state(shost) =
5561 FC_PORTSTATE_ONLINE;
5563 case LPFC_HBA_ERROR:
5564 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5567 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5572 spin_unlock_irq(shost->host_lock);
5576 * lpfc_get_host_speed - Set the value of the scsi host speed
5577 * @shost: kernel scsi host pointer.
5580 lpfc_get_host_speed(struct Scsi_Host *shost)
5582 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5583 struct lpfc_hba *phba = vport->phba;
5585 spin_lock_irq(shost->host_lock);
5587 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5588 switch(phba->fc_linkspeed) {
5589 case LPFC_LINK_SPEED_1GHZ:
5590 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5592 case LPFC_LINK_SPEED_2GHZ:
5593 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5595 case LPFC_LINK_SPEED_4GHZ:
5596 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5598 case LPFC_LINK_SPEED_8GHZ:
5599 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5601 case LPFC_LINK_SPEED_10GHZ:
5602 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5604 case LPFC_LINK_SPEED_16GHZ:
5605 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5607 case LPFC_LINK_SPEED_32GHZ:
5608 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5611 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5615 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5617 spin_unlock_irq(shost->host_lock);
5621 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5622 * @shost: kernel scsi host pointer.
5625 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5627 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5628 struct lpfc_hba *phba = vport->phba;
5631 spin_lock_irq(shost->host_lock);
5633 if ((vport->port_state > LPFC_FLOGI) &&
5634 ((vport->fc_flag & FC_FABRIC) ||
5635 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5636 (vport->fc_flag & FC_PUBLIC_LOOP))))
5637 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5639 /* fabric is local port if there is no F/FL_Port */
5642 spin_unlock_irq(shost->host_lock);
5644 fc_host_fabric_name(shost) = node_name;
5648 * lpfc_get_stats - Return statistical information about the adapter
5649 * @shost: kernel scsi host pointer.
5652 * NULL on error for link down, no mbox pool, sli2 active,
5653 * management not allowed, memory allocation error, or mbox error.
5657 * address of the adapter host statistics
5659 static struct fc_host_statistics *
5660 lpfc_get_stats(struct Scsi_Host *shost)
5662 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5663 struct lpfc_hba *phba = vport->phba;
5664 struct lpfc_sli *psli = &phba->sli;
5665 struct fc_host_statistics *hs = &phba->link_stats;
5666 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5667 LPFC_MBOXQ_t *pmboxq;
5669 unsigned long seconds;
5673 * prevent udev from issuing mailbox commands until the port is
5676 if (phba->link_state < LPFC_LINK_DOWN ||
5677 !phba->mbox_mem_pool ||
5678 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5681 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5684 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5687 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5689 pmb = &pmboxq->u.mb;
5690 pmb->mbxCommand = MBX_READ_STATUS;
5691 pmb->mbxOwner = OWN_HOST;
5692 pmboxq->context1 = NULL;
5693 pmboxq->vport = vport;
5695 if (vport->fc_flag & FC_OFFLINE_MODE)
5696 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5698 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5700 if (rc != MBX_SUCCESS) {
5701 if (rc != MBX_TIMEOUT)
5702 mempool_free(pmboxq, phba->mbox_mem_pool);
5706 memset(hs, 0, sizeof (struct fc_host_statistics));
5708 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5710 * The MBX_READ_STATUS returns tx_k_bytes which has to
5711 * converted to words
5713 hs->tx_words = (uint64_t)
5714 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5716 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5717 hs->rx_words = (uint64_t)
5718 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5721 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5722 pmb->mbxCommand = MBX_READ_LNK_STAT;
5723 pmb->mbxOwner = OWN_HOST;
5724 pmboxq->context1 = NULL;
5725 pmboxq->vport = vport;
5727 if (vport->fc_flag & FC_OFFLINE_MODE)
5728 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5730 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5732 if (rc != MBX_SUCCESS) {
5733 if (rc != MBX_TIMEOUT)
5734 mempool_free(pmboxq, phba->mbox_mem_pool);
5738 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5739 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5740 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5741 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5742 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5743 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5744 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5746 hs->link_failure_count -= lso->link_failure_count;
5747 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5748 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5749 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5750 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5751 hs->invalid_crc_count -= lso->invalid_crc_count;
5752 hs->error_frames -= lso->error_frames;
5754 if (phba->hba_flag & HBA_FCOE_MODE) {
5756 hs->nos_count = (phba->link_events >> 1);
5757 hs->nos_count -= lso->link_events;
5758 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5759 hs->lip_count = (phba->fc_eventTag >> 1);
5760 hs->lip_count -= lso->link_events;
5764 hs->nos_count = (phba->fc_eventTag >> 1);
5765 hs->nos_count -= lso->link_events;
5768 hs->dumped_frames = -1;
5770 seconds = get_seconds();
5771 if (seconds < psli->stats_start)
5772 hs->seconds_since_last_reset = seconds +
5773 ((unsigned long)-1 - psli->stats_start);
5775 hs->seconds_since_last_reset = seconds - psli->stats_start;
5777 mempool_free(pmboxq, phba->mbox_mem_pool);
5783 * lpfc_reset_stats - Copy the adapter link stats information
5784 * @shost: kernel scsi host pointer.
5787 lpfc_reset_stats(struct Scsi_Host *shost)
5789 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5790 struct lpfc_hba *phba = vport->phba;
5791 struct lpfc_sli *psli = &phba->sli;
5792 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5793 LPFC_MBOXQ_t *pmboxq;
5797 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5800 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5803 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5805 pmb = &pmboxq->u.mb;
5806 pmb->mbxCommand = MBX_READ_STATUS;
5807 pmb->mbxOwner = OWN_HOST;
5808 pmb->un.varWords[0] = 0x1; /* reset request */
5809 pmboxq->context1 = NULL;
5810 pmboxq->vport = vport;
5812 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5813 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5814 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5816 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5818 if (rc != MBX_SUCCESS) {
5819 if (rc != MBX_TIMEOUT)
5820 mempool_free(pmboxq, phba->mbox_mem_pool);
5824 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5825 pmb->mbxCommand = MBX_READ_LNK_STAT;
5826 pmb->mbxOwner = OWN_HOST;
5827 pmboxq->context1 = NULL;
5828 pmboxq->vport = vport;
5830 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5831 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5832 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5834 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5836 if (rc != MBX_SUCCESS) {
5837 if (rc != MBX_TIMEOUT)
5838 mempool_free( pmboxq, phba->mbox_mem_pool);
5842 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5843 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5844 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5845 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5846 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5847 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5848 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5849 if (phba->hba_flag & HBA_FCOE_MODE)
5850 lso->link_events = (phba->link_events >> 1);
5852 lso->link_events = (phba->fc_eventTag >> 1);
5854 psli->stats_start = get_seconds();
5856 mempool_free(pmboxq, phba->mbox_mem_pool);
5862 * The LPFC driver treats linkdown handling as target loss events so there
5863 * are no sysfs handlers for link_down_tmo.
5867 * lpfc_get_node_by_target - Return the nodelist for a target
5868 * @starget: kernel scsi target pointer.
5871 * address of the node list if found
5872 * NULL target not found
5874 static struct lpfc_nodelist *
5875 lpfc_get_node_by_target(struct scsi_target *starget)
5877 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5878 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5879 struct lpfc_nodelist *ndlp;
5881 spin_lock_irq(shost->host_lock);
5882 /* Search for this, mapped, target ID */
5883 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5884 if (NLP_CHK_NODE_ACT(ndlp) &&
5885 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5886 starget->id == ndlp->nlp_sid) {
5887 spin_unlock_irq(shost->host_lock);
5891 spin_unlock_irq(shost->host_lock);
5896 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5897 * @starget: kernel scsi target pointer.
5900 lpfc_get_starget_port_id(struct scsi_target *starget)
5902 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5904 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5908 * lpfc_get_starget_node_name - Set the target node name
5909 * @starget: kernel scsi target pointer.
5911 * Description: Set the target node name to the ndlp node name wwn or zero.
5914 lpfc_get_starget_node_name(struct scsi_target *starget)
5916 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5918 fc_starget_node_name(starget) =
5919 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5923 * lpfc_get_starget_port_name - Set the target port name
5924 * @starget: kernel scsi target pointer.
5926 * Description: set the target port name to the ndlp port name wwn or zero.
5929 lpfc_get_starget_port_name(struct scsi_target *starget)
5931 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5933 fc_starget_port_name(starget) =
5934 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5938 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5939 * @rport: fc rport address.
5940 * @timeout: new value for dev loss tmo.
5943 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5944 * dev_loss_tmo to one.
5947 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5950 rport->dev_loss_tmo = timeout;
5952 rport->dev_loss_tmo = 1;
5956 * lpfc_rport_show_function - Return rport target information
5959 * Macro that uses field to generate a function with the name lpfc_show_rport_
5961 * lpfc_show_rport_##field: returns the bytes formatted in buf
5962 * @cdev: class converted to an fc_rport.
5963 * @buf: on return contains the target_field or zero.
5965 * Returns: size of formatted string.
5967 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5969 lpfc_show_rport_##field (struct device *dev, \
5970 struct device_attribute *attr, \
5973 struct fc_rport *rport = transport_class_to_rport(dev); \
5974 struct lpfc_rport_data *rdata = rport->hostdata; \
5975 return snprintf(buf, sz, format_string, \
5976 (rdata->target) ? cast rdata->target->field : 0); \
5979 #define lpfc_rport_rd_attr(field, format_string, sz) \
5980 lpfc_rport_show_function(field, format_string, sz, ) \
5981 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5984 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
5985 * @fc_vport: The fc_vport who's symbolic name has been changed.
5988 * This function is called by the transport after the @fc_vport's symbolic name
5989 * has been changed. This function re-registers the symbolic name with the
5990 * switch to propagate the change into the fabric if the vport is active.
5993 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5995 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5997 if (vport->port_state == LPFC_VPORT_READY)
5998 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6002 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6003 * @phba: Pointer to lpfc_hba struct.
6005 * This function is called by the lpfc_get_cfgparam() routine to set the
6006 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6007 * log message according to the module's lpfc_log_verbose parameter setting
6008 * before hba port or vport created.
6011 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6013 phba->cfg_log_verbose = verbose;
6016 struct fc_function_template lpfc_transport_functions = {
6017 /* fixed attributes the driver supports */
6018 .show_host_node_name = 1,
6019 .show_host_port_name = 1,
6020 .show_host_supported_classes = 1,
6021 .show_host_supported_fc4s = 1,
6022 .show_host_supported_speeds = 1,
6023 .show_host_maxframe_size = 1,
6025 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6026 .show_host_symbolic_name = 1,
6028 /* dynamic attributes the driver supports */
6029 .get_host_port_id = lpfc_get_host_port_id,
6030 .show_host_port_id = 1,
6032 .get_host_port_type = lpfc_get_host_port_type,
6033 .show_host_port_type = 1,
6035 .get_host_port_state = lpfc_get_host_port_state,
6036 .show_host_port_state = 1,
6038 /* active_fc4s is shown but doesn't change (thus no get function) */
6039 .show_host_active_fc4s = 1,
6041 .get_host_speed = lpfc_get_host_speed,
6042 .show_host_speed = 1,
6044 .get_host_fabric_name = lpfc_get_host_fabric_name,
6045 .show_host_fabric_name = 1,
6048 * The LPFC driver treats linkdown handling as target loss events
6049 * so there are no sysfs handlers for link_down_tmo.
6052 .get_fc_host_stats = lpfc_get_stats,
6053 .reset_fc_host_stats = lpfc_reset_stats,
6055 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6056 .show_rport_maxframe_size = 1,
6057 .show_rport_supported_classes = 1,
6059 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6060 .show_rport_dev_loss_tmo = 1,
6062 .get_starget_port_id = lpfc_get_starget_port_id,
6063 .show_starget_port_id = 1,
6065 .get_starget_node_name = lpfc_get_starget_node_name,
6066 .show_starget_node_name = 1,
6068 .get_starget_port_name = lpfc_get_starget_port_name,
6069 .show_starget_port_name = 1,
6071 .issue_fc_host_lip = lpfc_issue_lip,
6072 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6073 .terminate_rport_io = lpfc_terminate_rport_io,
6075 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6077 .vport_disable = lpfc_vport_disable,
6079 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6081 .bsg_request = lpfc_bsg_request,
6082 .bsg_timeout = lpfc_bsg_timeout,
6085 struct fc_function_template lpfc_vport_transport_functions = {
6086 /* fixed attributes the driver supports */
6087 .show_host_node_name = 1,
6088 .show_host_port_name = 1,
6089 .show_host_supported_classes = 1,
6090 .show_host_supported_fc4s = 1,
6091 .show_host_supported_speeds = 1,
6092 .show_host_maxframe_size = 1,
6094 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6095 .show_host_symbolic_name = 1,
6097 /* dynamic attributes the driver supports */
6098 .get_host_port_id = lpfc_get_host_port_id,
6099 .show_host_port_id = 1,
6101 .get_host_port_type = lpfc_get_host_port_type,
6102 .show_host_port_type = 1,
6104 .get_host_port_state = lpfc_get_host_port_state,
6105 .show_host_port_state = 1,
6107 /* active_fc4s is shown but doesn't change (thus no get function) */
6108 .show_host_active_fc4s = 1,
6110 .get_host_speed = lpfc_get_host_speed,
6111 .show_host_speed = 1,
6113 .get_host_fabric_name = lpfc_get_host_fabric_name,
6114 .show_host_fabric_name = 1,
6117 * The LPFC driver treats linkdown handling as target loss events
6118 * so there are no sysfs handlers for link_down_tmo.
6121 .get_fc_host_stats = lpfc_get_stats,
6122 .reset_fc_host_stats = lpfc_reset_stats,
6124 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6125 .show_rport_maxframe_size = 1,
6126 .show_rport_supported_classes = 1,
6128 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6129 .show_rport_dev_loss_tmo = 1,
6131 .get_starget_port_id = lpfc_get_starget_port_id,
6132 .show_starget_port_id = 1,
6134 .get_starget_node_name = lpfc_get_starget_node_name,
6135 .show_starget_node_name = 1,
6137 .get_starget_port_name = lpfc_get_starget_port_name,
6138 .show_starget_port_name = 1,
6140 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6141 .terminate_rport_io = lpfc_terminate_rport_io,
6143 .vport_disable = lpfc_vport_disable,
6145 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6149 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6150 * @phba: lpfc_hba pointer.
6153 lpfc_get_cfgparam(struct lpfc_hba *phba)
6155 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6156 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6157 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6158 lpfc_cr_count_init(phba, lpfc_cr_count);
6159 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6160 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6161 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6162 lpfc_ack0_init(phba, lpfc_ack0);
6163 lpfc_topology_init(phba, lpfc_topology);
6164 lpfc_link_speed_init(phba, lpfc_link_speed);
6165 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6166 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6167 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6168 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6169 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6170 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6171 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6172 lpfc_use_msi_init(phba, lpfc_use_msi);
6173 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6174 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6175 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6176 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6177 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6179 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6180 if (phba->sli_rev != LPFC_SLI_REV4)
6181 phba->cfg_EnableXLane = 0;
6182 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6184 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6185 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6186 phba->cfg_oas_lun_state = 0;
6187 phba->cfg_oas_lun_status = 0;
6188 phba->cfg_oas_flags = 0;
6189 phba->cfg_oas_priority = 0;
6190 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6191 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6192 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6193 if (phba->sli_rev == LPFC_SLI_REV4)
6196 phba->cfg_poll = lpfc_poll;
6197 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6199 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6200 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6201 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
6203 /* Initialize first burst. Target vs Initiator are different. */
6204 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6205 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6206 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6207 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6209 if (phba->sli_rev != LPFC_SLI_REV4) {
6210 /* NVME only supported on SLI4 */
6211 phba->nvmet_support = 0;
6212 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6214 /* We MUST have FCP support */
6215 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6216 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6219 /* A value of 0 means use the number of CPUs found in the system */
6220 if (phba->cfg_fcp_io_channel == 0)
6221 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6222 if (phba->cfg_nvme_io_channel == 0)
6223 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6225 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6226 phba->cfg_fcp_io_channel = 0;
6228 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6229 phba->cfg_nvme_io_channel = 0;
6231 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6232 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6234 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6236 phba->cfg_soft_wwnn = 0L;
6237 phba->cfg_soft_wwpn = 0L;
6238 lpfc_xri_split_init(phba, lpfc_xri_split);
6239 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6240 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6241 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6242 lpfc_aer_support_init(phba, lpfc_aer_support);
6243 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6244 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6245 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6246 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6247 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6248 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6249 phba->cfg_enable_dss = 1;
6250 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6255 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6256 * dependencies between protocols and roles.
6257 * @phba: lpfc_hba pointer.
6260 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6262 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6263 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6265 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6266 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6268 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6269 phba->nvmet_support) {
6270 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6271 phba->cfg_fcp_io_channel = 0;
6273 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6274 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6275 "NVME Target PRLI ACC enable_fb ",
6276 phba->cfg_nvme_enable_fb,
6277 phba->cfg_nvmet_fb_size,
6278 LPFC_NVMET_FB_SZ_MAX);
6280 if (phba->cfg_nvme_enable_fb == 0)
6281 phba->cfg_nvmet_fb_size = 0;
6283 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6284 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6287 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6288 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6289 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6290 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6291 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6292 phba->cfg_nvmet_mrq);
6295 /* Not NVME Target mode. Turn off Target parameters. */
6296 phba->nvmet_support = 0;
6297 phba->cfg_nvmet_mrq = 0;
6298 phba->cfg_nvmet_mrq_post = 0;
6299 phba->cfg_nvmet_fb_size = 0;
6302 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6303 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6305 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6309 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6310 * @vport: lpfc_vport pointer.
6313 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6315 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6316 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6317 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6318 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6319 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6320 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6321 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6322 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6323 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6324 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6325 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6326 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6327 lpfc_max_luns_init(vport, lpfc_max_luns);
6328 lpfc_scan_down_init(vport, lpfc_scan_down);
6329 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);