1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. 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 lpfc_nodelist *ndlp;
154 struct nvme_fc_remote_port *nrport;
155 struct lpfc_fc4_ctrl_stat *cstat;
156 uint64_t data1, data2, data3;
157 uint64_t totin, totout, tot;
161 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
163 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
164 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
167 if (phba->nvmet_support) {
168 if (!phba->targetport) {
169 len = scnprintf(buf, PAGE_SIZE,
170 "NVME Target: x%llx is not allocated\n",
171 wwn_to_u64(vport->fc_portname.u.wwn));
174 /* Port state is only one of two values for now. */
175 if (phba->targetport->port_id)
176 statep = "REGISTERED";
179 scnprintf(tmp, sizeof(tmp),
180 "NVME Target Enabled State %s\n",
182 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
185 scnprintf(tmp, sizeof(tmp),
186 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
189 wwn_to_u64(vport->fc_portname.u.wwn),
190 wwn_to_u64(vport->fc_nodename.u.wwn),
191 phba->targetport->port_id);
192 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
195 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
199 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
200 scnprintf(tmp, sizeof(tmp),
201 "LS: Rcv %08x Drop %08x Abort %08x\n",
202 atomic_read(&tgtp->rcv_ls_req_in),
203 atomic_read(&tgtp->rcv_ls_req_drop),
204 atomic_read(&tgtp->xmt_ls_abort));
205 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
208 if (atomic_read(&tgtp->rcv_ls_req_in) !=
209 atomic_read(&tgtp->rcv_ls_req_out)) {
210 scnprintf(tmp, sizeof(tmp),
211 "Rcv LS: in %08x != out %08x\n",
212 atomic_read(&tgtp->rcv_ls_req_in),
213 atomic_read(&tgtp->rcv_ls_req_out));
214 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
218 scnprintf(tmp, sizeof(tmp),
219 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
220 atomic_read(&tgtp->xmt_ls_rsp),
221 atomic_read(&tgtp->xmt_ls_drop),
222 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
223 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
226 scnprintf(tmp, sizeof(tmp),
227 "LS: RSP Abort %08x xb %08x Err %08x\n",
228 atomic_read(&tgtp->xmt_ls_rsp_aborted),
229 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
230 atomic_read(&tgtp->xmt_ls_rsp_error));
231 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
234 scnprintf(tmp, sizeof(tmp),
235 "FCP: Rcv %08x Defer %08x Release %08x "
237 atomic_read(&tgtp->rcv_fcp_cmd_in),
238 atomic_read(&tgtp->rcv_fcp_cmd_defer),
239 atomic_read(&tgtp->xmt_fcp_release),
240 atomic_read(&tgtp->rcv_fcp_cmd_drop));
241 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
244 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
245 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
246 scnprintf(tmp, sizeof(tmp),
247 "Rcv FCP: in %08x != out %08x\n",
248 atomic_read(&tgtp->rcv_fcp_cmd_in),
249 atomic_read(&tgtp->rcv_fcp_cmd_out));
250 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
254 scnprintf(tmp, sizeof(tmp),
255 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
257 atomic_read(&tgtp->xmt_fcp_read),
258 atomic_read(&tgtp->xmt_fcp_read_rsp),
259 atomic_read(&tgtp->xmt_fcp_write),
260 atomic_read(&tgtp->xmt_fcp_rsp),
261 atomic_read(&tgtp->xmt_fcp_drop));
262 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
265 scnprintf(tmp, sizeof(tmp),
266 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
267 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
268 atomic_read(&tgtp->xmt_fcp_rsp_error),
269 atomic_read(&tgtp->xmt_fcp_rsp_drop));
270 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
273 scnprintf(tmp, sizeof(tmp),
274 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
275 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
276 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
277 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
278 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
281 scnprintf(tmp, sizeof(tmp),
282 "ABORT: Xmt %08x Cmpl %08x\n",
283 atomic_read(&tgtp->xmt_fcp_abort),
284 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
285 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
288 scnprintf(tmp, sizeof(tmp),
289 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
290 atomic_read(&tgtp->xmt_abort_sol),
291 atomic_read(&tgtp->xmt_abort_unsol),
292 atomic_read(&tgtp->xmt_abort_rsp),
293 atomic_read(&tgtp->xmt_abort_rsp_error));
294 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
297 scnprintf(tmp, sizeof(tmp),
298 "DELAY: ctx %08x fod %08x wqfull %08x\n",
299 atomic_read(&tgtp->defer_ctx),
300 atomic_read(&tgtp->defer_fod),
301 atomic_read(&tgtp->defer_wqfull));
302 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
305 /* Calculate outstanding IOs */
306 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
307 tot += atomic_read(&tgtp->xmt_fcp_release);
308 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
310 scnprintf(tmp, sizeof(tmp),
311 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
312 "CTX Outstanding %08llx\n\n",
313 phba->sli4_hba.nvmet_xri_cnt,
314 phba->sli4_hba.nvmet_io_wait_cnt,
315 phba->sli4_hba.nvmet_io_wait_total,
317 strlcat(buf, tmp, PAGE_SIZE);
321 localport = vport->localport;
323 len = scnprintf(buf, PAGE_SIZE,
324 "NVME Initiator x%llx is not allocated\n",
325 wwn_to_u64(vport->fc_portname.u.wwn));
328 lport = (struct lpfc_nvme_lport *)localport->private;
329 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
333 scnprintf(tmp, sizeof(tmp),
334 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
336 phba->sli4_hba.max_cfg_param.max_xri,
337 phba->sli4_hba.io_xri_max,
338 lpfc_sli4_get_els_iocb_cnt(phba));
339 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
342 /* Port state is only one of two values for now. */
343 if (localport->port_id)
348 scnprintf(tmp, sizeof(tmp),
349 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
352 wwn_to_u64(vport->fc_portname.u.wwn),
353 wwn_to_u64(vport->fc_nodename.u.wwn),
354 localport->port_id, statep);
355 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
358 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
360 spin_lock(&vport->phba->hbalock);
361 rport = lpfc_ndlp_get_nrport(ndlp);
363 nrport = rport->remoteport;
364 spin_unlock(&vport->phba->hbalock);
368 /* Port state is only one of two values for now. */
369 switch (nrport->port_state) {
370 case FC_OBJSTATE_ONLINE:
373 case FC_OBJSTATE_UNKNOWN:
377 statep = "UNSUPPORTED";
381 /* Tab in to show lport ownership. */
382 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
384 if (phba->brd_no >= 10) {
385 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
389 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
391 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
394 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
396 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
399 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
401 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
404 /* An NVME rport can have multiple roles. */
405 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
406 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
409 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
410 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
413 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
414 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
417 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
418 FC_PORT_ROLE_NVME_TARGET |
419 FC_PORT_ROLE_NVME_DISCOVERY)) {
420 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
422 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
426 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
427 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
435 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
438 scnprintf(tmp, sizeof(tmp),
439 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
440 atomic_read(&lport->fc4NvmeLsRequests),
441 atomic_read(&lport->fc4NvmeLsCmpls),
442 atomic_read(&lport->xmt_ls_abort));
443 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
446 scnprintf(tmp, sizeof(tmp),
447 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
448 atomic_read(&lport->xmt_ls_err),
449 atomic_read(&lport->cmpl_ls_xb),
450 atomic_read(&lport->cmpl_ls_err));
451 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
456 for (i = 0; i < phba->cfg_hdw_queue; i++) {
457 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
458 tot = cstat->io_cmpls;
460 data1 = cstat->input_requests;
461 data2 = cstat->output_requests;
462 data3 = cstat->control_requests;
463 totout += (data1 + data2 + data3);
465 scnprintf(tmp, sizeof(tmp),
466 "Total FCP Cmpl %016llx Issue %016llx "
468 totin, totout, totout - totin);
469 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
472 scnprintf(tmp, sizeof(tmp),
473 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
474 "wqerr %08x err %08x\n",
475 atomic_read(&lport->xmt_fcp_abort),
476 atomic_read(&lport->xmt_fcp_noxri),
477 atomic_read(&lport->xmt_fcp_bad_ndlp),
478 atomic_read(&lport->xmt_fcp_qdepth),
479 atomic_read(&lport->xmt_fcp_err),
480 atomic_read(&lport->xmt_fcp_wqerr));
481 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
484 scnprintf(tmp, sizeof(tmp),
485 "FCP CMPL: xb %08x Err %08x\n",
486 atomic_read(&lport->cmpl_fcp_xb),
487 atomic_read(&lport->cmpl_fcp_err));
488 strlcat(buf, tmp, PAGE_SIZE);
491 len = strnlen(buf, PAGE_SIZE);
493 if (unlikely(len >= (PAGE_SIZE - 1))) {
494 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
495 "6314 Catching potential buffer "
496 "overflow > PAGE_SIZE = %lu bytes\n",
498 strlcpy(buf + PAGE_SIZE - 1 -
499 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1),
500 LPFC_NVME_INFO_MORE_STR,
501 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1)
509 lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
512 struct Scsi_Host *shost = class_to_shost(dev);
513 struct lpfc_vport *vport = shost_priv(shost);
514 struct lpfc_hba *phba = vport->phba;
516 struct lpfc_fc4_ctrl_stat *cstat;
517 u64 data1, data2, data3;
518 u64 tot, totin, totout;
520 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
522 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
523 (phba->sli_rev != LPFC_SLI_REV4))
526 scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
530 for (i = 0; i < phba->cfg_hdw_queue; i++) {
531 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
532 tot = cstat->io_cmpls;
534 data1 = cstat->input_requests;
535 data2 = cstat->output_requests;
536 data3 = cstat->control_requests;
537 totout += (data1 + data2 + data3);
539 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
540 "IO %016llx ", i, data1, data2, data3);
541 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
544 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
545 tot, ((data1 + data2 + data3) - tot));
546 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
549 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
550 "OutIO %016llx\n", totin, totout, totout - totin);
551 strlcat(buf, tmp, PAGE_SIZE);
554 len = strnlen(buf, PAGE_SIZE);
560 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
563 struct Scsi_Host *shost = class_to_shost(dev);
564 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
565 struct lpfc_hba *phba = vport->phba;
567 if (phba->cfg_enable_bg)
568 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
569 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
571 return snprintf(buf, PAGE_SIZE,
572 "BlockGuard Not Supported\n");
574 return snprintf(buf, PAGE_SIZE,
575 "BlockGuard Disabled\n");
579 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
582 struct Scsi_Host *shost = class_to_shost(dev);
583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584 struct lpfc_hba *phba = vport->phba;
586 return snprintf(buf, PAGE_SIZE, "%llu\n",
587 (unsigned long long)phba->bg_guard_err_cnt);
591 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
594 struct Scsi_Host *shost = class_to_shost(dev);
595 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
596 struct lpfc_hba *phba = vport->phba;
598 return snprintf(buf, PAGE_SIZE, "%llu\n",
599 (unsigned long long)phba->bg_apptag_err_cnt);
603 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
606 struct Scsi_Host *shost = class_to_shost(dev);
607 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
608 struct lpfc_hba *phba = vport->phba;
610 return snprintf(buf, PAGE_SIZE, "%llu\n",
611 (unsigned long long)phba->bg_reftag_err_cnt);
615 * lpfc_info_show - Return some pci info about the host in ascii
616 * @dev: class converted to a Scsi_host structure.
617 * @attr: device attribute, not used.
618 * @buf: on return contains the formatted text from lpfc_info().
620 * Returns: size of formatted string.
623 lpfc_info_show(struct device *dev, struct device_attribute *attr,
626 struct Scsi_Host *host = class_to_shost(dev);
628 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
632 * lpfc_serialnum_show - Return the hba serial number in ascii
633 * @dev: class converted to a Scsi_host structure.
634 * @attr: device attribute, not used.
635 * @buf: on return contains the formatted text serial number.
637 * Returns: size of formatted string.
640 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
643 struct Scsi_Host *shost = class_to_shost(dev);
644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
645 struct lpfc_hba *phba = vport->phba;
647 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
651 * lpfc_temp_sensor_show - Return the temperature sensor level
652 * @dev: class converted to a Scsi_host structure.
653 * @attr: device attribute, not used.
654 * @buf: on return contains the formatted support level.
657 * Returns a number indicating the temperature sensor level currently
658 * supported, zero or one in ascii.
660 * Returns: size of formatted string.
663 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
666 struct Scsi_Host *shost = class_to_shost(dev);
667 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
668 struct lpfc_hba *phba = vport->phba;
669 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
673 * lpfc_modeldesc_show - Return the model description of the hba
674 * @dev: class converted to a Scsi_host structure.
675 * @attr: device attribute, not used.
676 * @buf: on return contains the scsi vpd model description.
678 * Returns: size of formatted string.
681 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
684 struct Scsi_Host *shost = class_to_shost(dev);
685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
686 struct lpfc_hba *phba = vport->phba;
688 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
692 * lpfc_modelname_show - Return the model name of the hba
693 * @dev: class converted to a Scsi_host structure.
694 * @attr: device attribute, not used.
695 * @buf: on return contains the scsi vpd model name.
697 * Returns: size of formatted string.
700 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
703 struct Scsi_Host *shost = class_to_shost(dev);
704 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
705 struct lpfc_hba *phba = vport->phba;
707 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
711 * lpfc_programtype_show - Return the program type of the hba
712 * @dev: class converted to a Scsi_host structure.
713 * @attr: device attribute, not used.
714 * @buf: on return contains the scsi vpd program type.
716 * Returns: size of formatted string.
719 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
722 struct Scsi_Host *shost = class_to_shost(dev);
723 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
724 struct lpfc_hba *phba = vport->phba;
726 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
730 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
731 * @dev: class converted to a Scsi_host structure.
732 * @attr: device attribute, not used.
733 * @buf: on return contains the Menlo Maintenance sli flag.
735 * Returns: size of formatted string.
738 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
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 return snprintf(buf, PAGE_SIZE, "%d\n",
745 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
749 * lpfc_vportnum_show - Return the port number in ascii of the hba
750 * @dev: class converted to a Scsi_host structure.
751 * @attr: device attribute, not used.
752 * @buf: on return contains scsi vpd program type.
754 * Returns: size of formatted string.
757 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
760 struct Scsi_Host *shost = class_to_shost(dev);
761 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
762 struct lpfc_hba *phba = vport->phba;
764 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
768 * lpfc_fwrev_show - Return the firmware rev running in the hba
769 * @dev: class converted to a Scsi_host structure.
770 * @attr: device attribute, not used.
771 * @buf: on return contains the scsi vpd program type.
773 * Returns: size of formatted string.
776 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
779 struct Scsi_Host *shost = class_to_shost(dev);
780 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
781 struct lpfc_hba *phba = vport->phba;
784 char fwrev[FW_REV_STR_SIZE];
787 lpfc_decode_firmware_rev(phba, fwrev, 1);
788 if_type = phba->sli4_hba.pc_sli4_params.if_type;
789 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
791 if (phba->sli_rev < LPFC_SLI_REV4)
792 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
793 fwrev, phba->sli_rev);
795 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
796 fwrev, phba->sli_rev, if_type, sli_family);
802 * lpfc_hdw_show - Return the jedec information about the hba
803 * @dev: class converted to a Scsi_host structure.
804 * @attr: device attribute, not used.
805 * @buf: on return contains the scsi vpd program type.
807 * Returns: size of formatted string.
810 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
813 struct Scsi_Host *shost = class_to_shost(dev);
814 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
815 struct lpfc_hba *phba = vport->phba;
816 lpfc_vpd_t *vp = &phba->vpd;
818 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
819 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
823 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
824 * @dev: class converted to a Scsi_host structure.
825 * @attr: device attribute, not used.
826 * @buf: on return contains the ROM and FCode ascii strings.
828 * Returns: size of formatted string.
831 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
834 struct Scsi_Host *shost = class_to_shost(dev);
835 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
836 struct lpfc_hba *phba = vport->phba;
837 char fwrev[FW_REV_STR_SIZE];
839 if (phba->sli_rev < LPFC_SLI_REV4)
840 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
842 lpfc_decode_firmware_rev(phba, fwrev, 1);
843 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
847 * lpfc_state_show - Return the link state of the port
848 * @dev: class converted to a Scsi_host structure.
849 * @attr: device attribute, not used.
850 * @buf: on return contains text describing the state of the link.
853 * The switch statement has no default so zero will be returned.
855 * Returns: size of formatted string.
858 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
861 struct Scsi_Host *shost = class_to_shost(dev);
862 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
863 struct lpfc_hba *phba = vport->phba;
866 switch (phba->link_state) {
867 case LPFC_LINK_UNKNOWN:
868 case LPFC_WARM_START:
869 case LPFC_INIT_START:
870 case LPFC_INIT_MBX_CMDS:
873 if (phba->hba_flag & LINK_DISABLED)
874 len += snprintf(buf + len, PAGE_SIZE-len,
875 "Link Down - User disabled\n");
877 len += snprintf(buf + len, PAGE_SIZE-len,
883 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
885 switch (vport->port_state) {
886 case LPFC_LOCAL_CFG_LINK:
887 len += snprintf(buf + len, PAGE_SIZE-len,
888 "Configuring Link\n");
892 case LPFC_FABRIC_CFG_LINK:
895 case LPFC_BUILD_DISC_LIST:
897 len += snprintf(buf + len, PAGE_SIZE - len,
900 case LPFC_VPORT_READY:
901 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
904 case LPFC_VPORT_FAILED:
905 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
908 case LPFC_VPORT_UNKNOWN:
909 len += snprintf(buf + len, PAGE_SIZE - len,
913 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
914 len += snprintf(buf + len, PAGE_SIZE-len,
915 " Menlo Maint Mode\n");
916 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
917 if (vport->fc_flag & FC_PUBLIC_LOOP)
918 len += snprintf(buf + len, PAGE_SIZE-len,
921 len += snprintf(buf + len, PAGE_SIZE-len,
924 if (vport->fc_flag & FC_FABRIC)
925 len += snprintf(buf + len, PAGE_SIZE-len,
928 len += snprintf(buf + len, PAGE_SIZE-len,
933 if ((phba->sli_rev == LPFC_SLI_REV4) &&
934 ((bf_get(lpfc_sli_intf_if_type,
935 &phba->sli4_hba.sli_intf) ==
936 LPFC_SLI_INTF_IF_TYPE_6))) {
937 struct lpfc_trunk_link link = phba->trunk_link;
939 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
940 len += snprintf(buf + len, PAGE_SIZE - len,
941 "Trunk port 0: Link %s %s\n",
942 (link.link0.state == LPFC_LINK_UP) ?
944 trunk_errmsg[link.link0.fault]);
946 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
947 len += snprintf(buf + len, PAGE_SIZE - len,
948 "Trunk port 1: Link %s %s\n",
949 (link.link1.state == LPFC_LINK_UP) ?
951 trunk_errmsg[link.link1.fault]);
953 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
954 len += snprintf(buf + len, PAGE_SIZE - len,
955 "Trunk port 2: Link %s %s\n",
956 (link.link2.state == LPFC_LINK_UP) ?
958 trunk_errmsg[link.link2.fault]);
960 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
961 len += snprintf(buf + len, PAGE_SIZE - len,
962 "Trunk port 3: Link %s %s\n",
963 (link.link3.state == LPFC_LINK_UP) ?
965 trunk_errmsg[link.link3.fault]);
973 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
974 * @dev: class unused variable.
975 * @attr: device attribute, not used.
976 * @buf: on return contains the module description text.
978 * Returns: size of formatted string.
981 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
984 struct Scsi_Host *shost = class_to_shost(dev);
985 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
986 struct lpfc_hba *phba = vport->phba;
988 if (phba->sli_rev < LPFC_SLI_REV4)
989 return snprintf(buf, PAGE_SIZE, "fc\n");
991 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
992 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
993 return snprintf(buf, PAGE_SIZE, "fcoe\n");
994 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
995 return snprintf(buf, PAGE_SIZE, "fc\n");
997 return snprintf(buf, PAGE_SIZE, "unknown\n");
1001 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1002 * (OAS) is supported.
1003 * @dev: class unused variable.
1004 * @attr: device attribute, not used.
1005 * @buf: on return contains the module description text.
1007 * Returns: size of formatted string.
1010 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1013 struct Scsi_Host *shost = class_to_shost(dev);
1014 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1015 struct lpfc_hba *phba = vport->phba;
1017 return snprintf(buf, PAGE_SIZE, "%d\n",
1018 phba->sli4_hba.pc_sli4_params.oas_supported);
1022 * lpfc_link_state_store - Transition the link_state on an HBA port
1023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: one or more lpfc_polling_flags values.
1029 * -EINVAL if the buffer is not "up" or "down"
1030 * return from link state change function if non-zero
1031 * length of the buf on success
1034 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1035 const char *buf, size_t count)
1037 struct Scsi_Host *shost = class_to_shost(dev);
1038 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1039 struct lpfc_hba *phba = vport->phba;
1041 int status = -EINVAL;
1043 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1044 (phba->link_state == LPFC_LINK_DOWN))
1045 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
1046 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1047 (phba->link_state >= LPFC_LINK_UP))
1048 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1057 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1058 * @dev: class device that is converted into a Scsi_host.
1059 * @attr: device attribute, not used.
1060 * @buf: on return contains the sum of fc mapped and unmapped.
1063 * Returns the ascii text number of the sum of the fc mapped and unmapped
1066 * Returns: size of formatted string.
1069 lpfc_num_discovered_ports_show(struct device *dev,
1070 struct device_attribute *attr, char *buf)
1072 struct Scsi_Host *shost = class_to_shost(dev);
1073 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1075 return snprintf(buf, PAGE_SIZE, "%d\n",
1076 vport->fc_map_cnt + vport->fc_unmap_cnt);
1080 * lpfc_issue_lip - Misnomer, name carried over from long ago
1081 * @shost: Scsi_Host pointer.
1084 * Bring the link down gracefully then re-init the link. The firmware will
1085 * re-init the fiber channel interface as required. Does not issue a LIP.
1088 * -EPERM port offline or management commands are being blocked
1089 * -ENOMEM cannot allocate memory for the mailbox command
1090 * -EIO error sending the mailbox command
1094 lpfc_issue_lip(struct Scsi_Host *shost)
1096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1097 struct lpfc_hba *phba = vport->phba;
1098 LPFC_MBOXQ_t *pmboxq;
1099 int mbxstatus = MBXERR_ERROR;
1102 * If the link is offline, disabled or BLOCK_MGMT_IO
1103 * it doesn't make any sense to allow issue_lip
1105 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1106 (phba->hba_flag & LINK_DISABLED) ||
1107 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1110 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1115 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1116 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1117 pmboxq->u.mb.mbxOwner = OWN_HOST;
1119 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1121 if ((mbxstatus == MBX_SUCCESS) &&
1122 (pmboxq->u.mb.mbxStatus == 0 ||
1123 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1124 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1125 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1126 phba->cfg_link_speed);
1127 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1128 phba->fc_ratov * 2);
1129 if ((mbxstatus == MBX_SUCCESS) &&
1130 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1131 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1132 "2859 SLI authentication is required "
1133 "for INIT_LINK but has not done yet\n");
1136 lpfc_set_loopback_flag(phba);
1137 if (mbxstatus != MBX_TIMEOUT)
1138 mempool_free(pmboxq, phba->mbox_mem_pool);
1140 if (mbxstatus == MBXERR_ERROR)
1147 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1151 spin_lock_irq(lock);
1152 while (!list_empty(q)) {
1153 spin_unlock_irq(lock);
1155 if (cnt++ > 250) { /* 5 secs */
1156 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1158 "Outstanding IO when ",
1159 "bringing Adapter offline\n");
1162 spin_lock_irq(lock);
1164 spin_unlock_irq(lock);
1169 * lpfc_do_offline - Issues a mailbox command to bring the link down
1170 * @phba: lpfc_hba pointer.
1171 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1174 * Assumes any error from lpfc_do_offline() will be negative.
1175 * Can wait up to 5 seconds for the port ring buffers count
1176 * to reach zero, prints a warning if it is not zero and continues.
1177 * lpfc_workq_post_event() returns a non-zero return code if call fails.
1180 * -EIO error posting the event
1184 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1186 struct completion online_compl;
1187 struct lpfc_queue *qp = NULL;
1188 struct lpfc_sli_ring *pring;
1189 struct lpfc_sli *psli;
1194 init_completion(&online_compl);
1195 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1196 LPFC_EVT_OFFLINE_PREP);
1200 wait_for_completion(&online_compl);
1207 /* Wait a little for things to settle down, but not
1208 * long enough for dev loss timeout to expire.
1210 if (phba->sli_rev != LPFC_SLI_REV4) {
1211 for (i = 0; i < psli->num_rings; i++) {
1212 pring = &psli->sli3_ring[i];
1213 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1218 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1222 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1228 init_completion(&online_compl);
1229 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1233 wait_for_completion(&online_compl);
1242 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1243 * @phba: lpfc_hba pointer.
1246 * Issues a PCI secondary bus reset for the phba->pcidev.
1249 * First walks the bus_list to ensure only PCI devices with Emulex
1250 * vendor id, device ids that support hot reset, only one occurrence
1251 * of function 0, and all ports on the bus are in offline mode to ensure the
1252 * hot reset only affects one valid HBA.
1255 * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1256 * -ENODEV, NULL ptr to pcidev
1257 * -EBADSLT, detected invalid device
1258 * -EBUSY, port is not in offline state
1262 lpfc_reset_pci_bus(struct lpfc_hba *phba)
1264 struct pci_dev *pdev = phba->pcidev;
1265 struct Scsi_Host *shost = NULL;
1266 struct lpfc_hba *phba_other = NULL;
1267 struct pci_dev *ptr = NULL;
1270 if (phba->cfg_enable_hba_reset != 2)
1274 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1278 res = lpfc_check_pci_resettable(phba);
1282 /* Walk the list of devices on the pci_dev's bus */
1283 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1284 /* Check port is offline */
1285 shost = pci_get_drvdata(ptr);
1288 ((struct lpfc_vport *)shost->hostdata)->phba;
1289 if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1290 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1291 "8349 WWPN = 0x%02x%02x%02x%02x"
1292 "%02x%02x%02x%02x is not "
1294 phba_other->wwpn[0],
1295 phba_other->wwpn[1],
1296 phba_other->wwpn[2],
1297 phba_other->wwpn[3],
1298 phba_other->wwpn[4],
1299 phba_other->wwpn[5],
1300 phba_other->wwpn[6],
1301 phba_other->wwpn[7]);
1307 /* Issue PCI bus reset */
1308 res = pci_reset_bus(pdev);
1310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1311 "8350 PCI reset bus failed: %d\n", res);
1318 * lpfc_selective_reset - Offline then onlines the port
1319 * @phba: lpfc_hba pointer.
1322 * If the port is configured to allow a reset then the hba is brought
1323 * offline then online.
1326 * Assumes any error from lpfc_do_offline() will be negative.
1327 * Do not make this function static.
1330 * lpfc_do_offline() return code if not zero
1331 * -EIO reset not configured or error posting the event
1335 lpfc_selective_reset(struct lpfc_hba *phba)
1337 struct completion online_compl;
1341 if (!phba->cfg_enable_hba_reset)
1344 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1345 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1351 init_completion(&online_compl);
1352 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1357 wait_for_completion(&online_compl);
1366 * lpfc_issue_reset - Selectively resets an adapter
1367 * @dev: class device that is converted into a Scsi_host.
1368 * @attr: device attribute, not used.
1369 * @buf: containing the string "selective".
1370 * @count: unused variable.
1373 * If the buf contains the string "selective" then lpfc_selective_reset()
1374 * is called to perform the reset.
1377 * Assumes any error from lpfc_selective_reset() will be negative.
1378 * If lpfc_selective_reset() returns zero then the length of the buffer
1379 * is returned which indicates success
1382 * -EINVAL if the buffer does not contain the string "selective"
1383 * length of buf if lpfc-selective_reset() if the call succeeds
1384 * return value of lpfc_selective_reset() if the call fails
1387 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1388 const char *buf, size_t count)
1390 struct Scsi_Host *shost = class_to_shost(dev);
1391 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1392 struct lpfc_hba *phba = vport->phba;
1393 int status = -EINVAL;
1395 if (!phba->cfg_enable_hba_reset)
1398 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1399 status = phba->lpfc_selective_reset(phba);
1408 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1409 * @phba: lpfc_hba pointer.
1412 * SLI4 interface type-2 device to wait on the sliport status register for
1413 * the readyness after performing a firmware reset.
1416 * zero for success, -EPERM when port does not have privilege to perform the
1417 * reset, -EIO when port timeout from recovering from the reset.
1420 * As the caller will interpret the return code by value, be careful in making
1421 * change or addition to return codes.
1424 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1426 struct lpfc_register portstat_reg = {0};
1430 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1431 &portstat_reg.word0);
1433 /* verify if privileged for the request operation */
1434 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1435 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1438 /* wait for the SLI port firmware ready after firmware reset */
1439 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1441 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1442 &portstat_reg.word0);
1443 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1445 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1447 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1452 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1459 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1460 * @phba: lpfc_hba pointer.
1463 * Request SLI4 interface type-2 device to perform a physical register set
1470 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1472 struct completion online_compl;
1473 struct pci_dev *pdev = phba->pcidev;
1474 uint32_t before_fc_flag;
1475 uint32_t sriov_nr_virtfn;
1477 int status = 0, rc = 0;
1478 int job_posted = 1, sriov_err;
1480 if (!phba->cfg_enable_hba_reset)
1483 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1484 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1485 LPFC_SLI_INTF_IF_TYPE_2))
1488 /* Keep state if we need to restore back */
1489 before_fc_flag = phba->pport->fc_flag;
1490 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1492 /* Disable SR-IOV virtual functions if enabled */
1493 if (phba->cfg_sriov_nr_virtfn) {
1494 pci_disable_sriov(pdev);
1495 phba->cfg_sriov_nr_virtfn = 0;
1498 if (opcode == LPFC_FW_DUMP)
1499 phba->hba_flag |= HBA_FW_DUMP_OP;
1501 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1504 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1508 /* wait for the device to be quiesced before firmware reset */
1511 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1512 LPFC_CTL_PDEV_CTL_OFFSET);
1514 if (opcode == LPFC_FW_DUMP)
1515 reg_val |= LPFC_FW_DUMP_REQUEST;
1516 else if (opcode == LPFC_FW_RESET)
1517 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1518 else if (opcode == LPFC_DV_RESET)
1519 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1521 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1522 LPFC_CTL_PDEV_CTL_OFFSET);
1524 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1526 /* delay driver action following IF_TYPE_2 reset */
1527 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1530 /* no privilege for reset */
1531 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1532 "3150 No privilege to perform the requested "
1533 "access: x%x\n", reg_val);
1534 } else if (rc == -EIO) {
1535 /* reset failed, there is nothing more we can do */
1536 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1537 "3153 Fail to perform the requested "
1538 "access: x%x\n", reg_val);
1542 /* keep the original port state */
1543 if (before_fc_flag & FC_OFFLINE_MODE)
1546 init_completion(&online_compl);
1547 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1552 wait_for_completion(&online_compl);
1555 /* in any case, restore the virtual functions enabled as before */
1556 if (sriov_nr_virtfn) {
1558 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1560 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1563 /* return proper error code */
1574 * lpfc_nport_evt_cnt_show - Return the number of nport events
1575 * @dev: class device that is converted into a Scsi_host.
1576 * @attr: device attribute, not used.
1577 * @buf: on return contains the ascii number of nport events.
1579 * Returns: size of formatted string.
1582 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1585 struct Scsi_Host *shost = class_to_shost(dev);
1586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1587 struct lpfc_hba *phba = vport->phba;
1589 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1593 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1595 LPFC_MBOXQ_t *mbox = NULL;
1596 unsigned long val = 0;
1600 if (!strncmp("enable", buff_out,
1601 strlen("enable"))) {
1602 pval = buff_out + strlen("enable") + 1;
1603 rc = kstrtoul(pval, 0, &val);
1605 return rc; /* Invalid number */
1606 } else if (!strncmp("disable", buff_out,
1607 strlen("disable"))) {
1610 return -EINVAL; /* Invalid command */
1615 val = 0x0; /* Disable */
1618 val = 0x1; /* Enable two port trunk */
1621 val = 0x2; /* Enable four port trunk */
1627 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1628 "0070 Set trunk mode with val %ld ", val);
1630 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1634 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1635 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1636 12, LPFC_SLI4_MBX_EMBED);
1638 bf_set(lpfc_mbx_set_trunk_mode,
1639 &mbox->u.mqe.un.set_trunk_mode,
1641 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1643 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1644 "0071 Set trunk mode failed with status: %d",
1646 if (rc != MBX_TIMEOUT)
1647 mempool_free(mbox, phba->mbox_mem_pool);
1653 * lpfc_board_mode_show - Return the state of the board
1654 * @dev: class device that is converted into a Scsi_host.
1655 * @attr: device attribute, not used.
1656 * @buf: on return contains the state of the adapter.
1658 * Returns: size of formatted string.
1661 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1664 struct Scsi_Host *shost = class_to_shost(dev);
1665 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1666 struct lpfc_hba *phba = vport->phba;
1669 if (phba->link_state == LPFC_HBA_ERROR)
1671 else if (phba->link_state == LPFC_WARM_START)
1672 state = "warm start";
1673 else if (phba->link_state == LPFC_INIT_START)
1678 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1682 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1683 * @dev: class device that is converted into a Scsi_host.
1684 * @attr: device attribute, not used.
1685 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1686 * @count: unused variable.
1689 * -EACCES if enable hba reset not enabled
1690 * -EINVAL if the buffer does not contain a valid string (see above)
1691 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1692 * buf length greater than zero indicates success
1695 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1696 const char *buf, size_t count)
1698 struct Scsi_Host *shost = class_to_shost(dev);
1699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1700 struct lpfc_hba *phba = vport->phba;
1701 struct completion online_compl;
1702 char *board_mode_str = NULL;
1706 if (!phba->cfg_enable_hba_reset) {
1708 goto board_mode_out;
1711 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1712 "3050 lpfc_board_mode set to %s\n", buf);
1714 init_completion(&online_compl);
1716 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1717 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1721 goto board_mode_out;
1723 wait_for_completion(&online_compl);
1726 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1727 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1728 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1729 if (phba->sli_rev == LPFC_SLI_REV4)
1732 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1733 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1734 if (phba->sli_rev == LPFC_SLI_REV4)
1737 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1738 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1739 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1740 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1741 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1742 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1743 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1744 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1746 status = lpfc_reset_pci_bus(phba);
1747 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1748 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
1756 board_mode_str = strchr(buf, '\n');
1758 *board_mode_str = '\0';
1759 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1760 "3097 Failed \"%s\", status(%d), "
1762 buf, status, phba->pport->fc_flag);
1768 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1769 * @phba: pointer to the adapter structure.
1770 * @mxri: max xri count.
1771 * @axri: available xri count.
1772 * @mrpi: max rpi count.
1773 * @arpi: available rpi count.
1774 * @mvpi: max vpi count.
1775 * @avpi: available vpi count.
1778 * If an integer pointer for an count is not null then the value for the
1779 * count is returned.
1786 lpfc_get_hba_info(struct lpfc_hba *phba,
1787 uint32_t *mxri, uint32_t *axri,
1788 uint32_t *mrpi, uint32_t *arpi,
1789 uint32_t *mvpi, uint32_t *avpi)
1791 struct lpfc_mbx_read_config *rd_config;
1792 LPFC_MBOXQ_t *pmboxq;
1798 * prevent udev from issuing mailbox commands until the port is
1801 if (phba->link_state < LPFC_LINK_DOWN ||
1802 !phba->mbox_mem_pool ||
1803 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1806 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1809 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1812 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1814 pmb = &pmboxq->u.mb;
1815 pmb->mbxCommand = MBX_READ_CONFIG;
1816 pmb->mbxOwner = OWN_HOST;
1817 pmboxq->ctx_buf = NULL;
1819 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1820 rc = MBX_NOT_FINISHED;
1822 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1824 if (rc != MBX_SUCCESS) {
1825 if (rc != MBX_TIMEOUT)
1826 mempool_free(pmboxq, phba->mbox_mem_pool);
1830 if (phba->sli_rev == LPFC_SLI_REV4) {
1831 rd_config = &pmboxq->u.mqe.un.rd_config;
1833 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1835 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1836 phba->sli4_hba.max_cfg_param.rpi_used;
1838 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1840 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1841 phba->sli4_hba.max_cfg_param.xri_used;
1843 /* Account for differences with SLI-3. Get vpi count from
1844 * mailbox data and subtract one for max vpi value.
1846 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1847 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1849 /* Limit the max we support */
1850 if (max_vpi > LPFC_MAX_VPI)
1851 max_vpi = LPFC_MAX_VPI;
1855 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1858 *mrpi = pmb->un.varRdConfig.max_rpi;
1860 *arpi = pmb->un.varRdConfig.avail_rpi;
1862 *mxri = pmb->un.varRdConfig.max_xri;
1864 *axri = pmb->un.varRdConfig.avail_xri;
1866 *mvpi = pmb->un.varRdConfig.max_vpi;
1868 /* avail_vpi is only valid if link is up and ready */
1869 if (phba->link_state == LPFC_HBA_READY)
1870 *avpi = pmb->un.varRdConfig.avail_vpi;
1872 *avpi = pmb->un.varRdConfig.max_vpi;
1876 mempool_free(pmboxq, phba->mbox_mem_pool);
1881 * lpfc_max_rpi_show - Return maximum rpi
1882 * @dev: class device that is converted into a Scsi_host.
1883 * @attr: device attribute, not used.
1884 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1887 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1888 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1889 * to "Unknown" and the buffer length is returned, therefore the caller
1890 * must check for "Unknown" in the buffer to detect a failure.
1892 * Returns: size of formatted string.
1895 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1898 struct Scsi_Host *shost = class_to_shost(dev);
1899 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1900 struct lpfc_hba *phba = vport->phba;
1903 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1904 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1905 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1909 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1910 * @dev: class device that is converted into a Scsi_host.
1911 * @attr: device attribute, not used.
1912 * @buf: containing the used rpi count in decimal or "Unknown".
1915 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1916 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1917 * to "Unknown" and the buffer length is returned, therefore the caller
1918 * must check for "Unknown" in the buffer to detect a failure.
1920 * Returns: size of formatted string.
1923 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1926 struct Scsi_Host *shost = class_to_shost(dev);
1927 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1928 struct lpfc_hba *phba = vport->phba;
1931 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1932 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1933 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1937 * lpfc_max_xri_show - Return maximum xri
1938 * @dev: class device that is converted into a Scsi_host.
1939 * @attr: device attribute, not used.
1940 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1943 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1944 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1945 * to "Unknown" and the buffer length is returned, therefore the caller
1946 * must check for "Unknown" in the buffer to detect a failure.
1948 * Returns: size of formatted string.
1951 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1954 struct Scsi_Host *shost = class_to_shost(dev);
1955 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1956 struct lpfc_hba *phba = vport->phba;
1959 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1960 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1961 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1965 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1966 * @dev: class device that is converted into a Scsi_host.
1967 * @attr: device attribute, not used.
1968 * @buf: on return contains the used xri count in decimal or "Unknown".
1971 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1972 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1973 * to "Unknown" and the buffer length is returned, therefore the caller
1974 * must check for "Unknown" in the buffer to detect a failure.
1976 * Returns: size of formatted string.
1979 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1982 struct Scsi_Host *shost = class_to_shost(dev);
1983 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1984 struct lpfc_hba *phba = vport->phba;
1987 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1988 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1989 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1993 * lpfc_max_vpi_show - Return maximum vpi
1994 * @dev: class device that is converted into a Scsi_host.
1995 * @attr: device attribute, not used.
1996 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1999 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2000 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2001 * to "Unknown" and the buffer length is returned, therefore the caller
2002 * must check for "Unknown" in the buffer to detect a failure.
2004 * Returns: size of formatted string.
2007 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2010 struct Scsi_Host *shost = class_to_shost(dev);
2011 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2012 struct lpfc_hba *phba = vport->phba;
2015 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2016 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
2017 return snprintf(buf, PAGE_SIZE, "Unknown\n");
2021 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2022 * @dev: class device that is converted into a Scsi_host.
2023 * @attr: device attribute, not used.
2024 * @buf: on return contains the used vpi count in decimal or "Unknown".
2027 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2028 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2029 * to "Unknown" and the buffer length is returned, therefore the caller
2030 * must check for "Unknown" in the buffer to detect a failure.
2032 * Returns: size of formatted string.
2035 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2038 struct Scsi_Host *shost = class_to_shost(dev);
2039 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2040 struct lpfc_hba *phba = vport->phba;
2043 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2044 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2045 return snprintf(buf, PAGE_SIZE, "Unknown\n");
2049 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2050 * @dev: class device that is converted into a Scsi_host.
2051 * @attr: device attribute, not used.
2052 * @buf: text that must be interpreted to determine if npiv is supported.
2055 * Buffer will contain text indicating npiv is not suppoerted on the port,
2056 * the port is an NPIV physical port, or it is an npiv virtual port with
2057 * the id of the vport.
2059 * Returns: size of formatted string.
2062 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2065 struct Scsi_Host *shost = class_to_shost(dev);
2066 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2067 struct lpfc_hba *phba = vport->phba;
2069 if (!(phba->max_vpi))
2070 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2071 if (vport->port_type == LPFC_PHYSICAL_PORT)
2072 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2073 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2077 * lpfc_poll_show - Return text about poll support for the adapter
2078 * @dev: class device that is converted into a Scsi_host.
2079 * @attr: device attribute, not used.
2080 * @buf: on return contains the cfg_poll in hex.
2083 * cfg_poll should be a lpfc_polling_flags type.
2085 * Returns: size of formatted string.
2088 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2091 struct Scsi_Host *shost = class_to_shost(dev);
2092 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2093 struct lpfc_hba *phba = vport->phba;
2095 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2099 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2100 * @dev: class device that is converted into a Scsi_host.
2101 * @attr: device attribute, not used.
2102 * @buf: one or more lpfc_polling_flags values.
2106 * buf contents converted to integer and checked for a valid value.
2109 * -EINVAL if the buffer connot be converted or is out of range
2110 * length of the buf on success
2113 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2114 const char *buf, size_t count)
2116 struct Scsi_Host *shost = class_to_shost(dev);
2117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2118 struct lpfc_hba *phba = vport->phba;
2123 if (!isdigit(buf[0]))
2126 if (sscanf(buf, "%i", &val) != 1)
2129 if ((val & 0x3) != val)
2132 if (phba->sli_rev == LPFC_SLI_REV4)
2135 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2136 "3051 lpfc_poll changed from %d to %d\n",
2137 phba->cfg_poll, val);
2139 spin_lock_irq(&phba->hbalock);
2141 old_val = phba->cfg_poll;
2143 if (val & ENABLE_FCP_RING_POLLING) {
2144 if ((val & DISABLE_FCP_RING_INT) &&
2145 !(old_val & DISABLE_FCP_RING_INT)) {
2146 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2147 spin_unlock_irq(&phba->hbalock);
2150 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2151 writel(creg_val, phba->HCregaddr);
2152 readl(phba->HCregaddr); /* flush */
2154 lpfc_poll_start_timer(phba);
2156 } else if (val != 0x0) {
2157 spin_unlock_irq(&phba->hbalock);
2161 if (!(val & DISABLE_FCP_RING_INT) &&
2162 (old_val & DISABLE_FCP_RING_INT))
2164 spin_unlock_irq(&phba->hbalock);
2165 del_timer(&phba->fcp_poll_timer);
2166 spin_lock_irq(&phba->hbalock);
2167 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2168 spin_unlock_irq(&phba->hbalock);
2171 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2172 writel(creg_val, phba->HCregaddr);
2173 readl(phba->HCregaddr); /* flush */
2176 phba->cfg_poll = val;
2178 spin_unlock_irq(&phba->hbalock);
2184 * lpfc_fips_level_show - Return the current FIPS level for the HBA
2185 * @dev: class unused variable.
2186 * @attr: device attribute, not used.
2187 * @buf: on return contains the module description text.
2189 * Returns: size of formatted string.
2192 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
2195 struct Scsi_Host *shost = class_to_shost(dev);
2196 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2197 struct lpfc_hba *phba = vport->phba;
2199 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
2203 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
2204 * @dev: class unused variable.
2205 * @attr: device attribute, not used.
2206 * @buf: on return contains the module description text.
2208 * Returns: size of formatted string.
2211 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
2214 struct Scsi_Host *shost = class_to_shost(dev);
2215 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2216 struct lpfc_hba *phba = vport->phba;
2218 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
2222 * lpfc_dss_show - Return the current state of dss and the configured state
2223 * @dev: class converted to a Scsi_host structure.
2224 * @attr: device attribute, not used.
2225 * @buf: on return contains the formatted text.
2227 * Returns: size of formatted string.
2230 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
2233 struct Scsi_Host *shost = class_to_shost(dev);
2234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2235 struct lpfc_hba *phba = vport->phba;
2237 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
2238 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
2239 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
2244 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2245 * @dev: class converted to a Scsi_host structure.
2246 * @attr: device attribute, not used.
2247 * @buf: on return contains the formatted support level.
2250 * Returns the maximum number of virtual functions a physical function can
2251 * support, 0 will be returned if called on virtual function.
2253 * Returns: size of formatted string.
2256 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2257 struct device_attribute *attr,
2260 struct Scsi_Host *shost = class_to_shost(dev);
2261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2262 struct lpfc_hba *phba = vport->phba;
2263 uint16_t max_nr_virtfn;
2265 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2266 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2269 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2271 return val >= min && val <= max;
2275 * lpfc_enable_bbcr_set: Sets an attribute value.
2276 * @phba: pointer the the adapter structure.
2277 * @val: integer attribute value.
2280 * Validates the min and max values then sets the
2281 * adapter config field if in the valid range. prints error message
2282 * and does not set the parameter if invalid.
2286 * -EINVAL if val is invalid
2289 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2291 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2292 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2293 "3068 %s_enable_bbcr changed from %d to %d\n",
2294 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
2295 phba->cfg_enable_bbcr = val;
2298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2299 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2300 LPFC_DRIVER_NAME, val);
2305 * lpfc_param_show - Return a cfg attribute value in decimal
2308 * Macro that given an attr e.g. hba_queue_depth expands
2309 * into a function with the name lpfc_hba_queue_depth_show.
2311 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2312 * @dev: class device that is converted into a Scsi_host.
2313 * @attr: device attribute, not used.
2314 * @buf: on return contains the attribute value in decimal.
2316 * Returns: size of formatted string.
2318 #define lpfc_param_show(attr) \
2320 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2323 struct Scsi_Host *shost = class_to_shost(dev);\
2324 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2325 struct lpfc_hba *phba = vport->phba;\
2326 return snprintf(buf, PAGE_SIZE, "%d\n",\
2331 * lpfc_param_hex_show - Return a cfg attribute value in hex
2334 * Macro that given an attr e.g. hba_queue_depth expands
2335 * into a function with the name lpfc_hba_queue_depth_show
2337 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2338 * @dev: class device that is converted into a Scsi_host.
2339 * @attr: device attribute, not used.
2340 * @buf: on return contains the attribute value in hexadecimal.
2342 * Returns: size of formatted string.
2344 #define lpfc_param_hex_show(attr) \
2346 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2349 struct Scsi_Host *shost = class_to_shost(dev);\
2350 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2351 struct lpfc_hba *phba = vport->phba;\
2353 val = phba->cfg_##attr;\
2354 return snprintf(buf, PAGE_SIZE, "%#x\n",\
2359 * lpfc_param_init - Initializes a cfg attribute
2362 * Macro that given an attr e.g. hba_queue_depth expands
2363 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2364 * takes a default argument, a minimum and maximum argument.
2366 * lpfc_##attr##_init: Initializes an attribute.
2367 * @phba: pointer the the adapter structure.
2368 * @val: integer attribute value.
2370 * Validates the min and max values then sets the adapter config field
2371 * accordingly, or uses the default if out of range and prints an error message.
2375 * -EINVAL if default used
2377 #define lpfc_param_init(attr, default, minval, maxval) \
2379 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2381 if (lpfc_rangecheck(val, minval, maxval)) {\
2382 phba->cfg_##attr = val;\
2385 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2386 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2387 "allowed range is ["#minval", "#maxval"]\n", val); \
2388 phba->cfg_##attr = default;\
2393 * lpfc_param_set - Set a cfg attribute value
2396 * Macro that given an attr e.g. hba_queue_depth expands
2397 * into a function with the name lpfc_hba_queue_depth_set
2399 * lpfc_##attr##_set: Sets an attribute value.
2400 * @phba: pointer the the adapter structure.
2401 * @val: integer attribute value.
2404 * Validates the min and max values then sets the
2405 * adapter config field if in the valid range. prints error message
2406 * and does not set the parameter if invalid.
2410 * -EINVAL if val is invalid
2412 #define lpfc_param_set(attr, default, minval, maxval) \
2414 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2416 if (lpfc_rangecheck(val, minval, maxval)) {\
2417 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2418 "3052 lpfc_" #attr " changed from %d to %d\n", \
2419 phba->cfg_##attr, val); \
2420 phba->cfg_##attr = val;\
2423 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2424 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2425 "allowed range is ["#minval", "#maxval"]\n", val); \
2430 * lpfc_param_store - Set a vport attribute value
2433 * Macro that given an attr e.g. hba_queue_depth expands
2434 * into a function with the name lpfc_hba_queue_depth_store.
2436 * lpfc_##attr##_store: Set an sttribute value.
2437 * @dev: class device that is converted into a Scsi_host.
2438 * @attr: device attribute, not used.
2439 * @buf: contains the attribute value in ascii.
2443 * Convert the ascii text number to an integer, then
2444 * use the lpfc_##attr##_set function to set the value.
2447 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2448 * length of buffer upon success.
2450 #define lpfc_param_store(attr) \
2452 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2453 const char *buf, size_t count) \
2455 struct Scsi_Host *shost = class_to_shost(dev);\
2456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2457 struct lpfc_hba *phba = vport->phba;\
2459 if (!isdigit(buf[0]))\
2461 if (sscanf(buf, "%i", &val) != 1)\
2463 if (lpfc_##attr##_set(phba, val) == 0) \
2464 return strlen(buf);\
2470 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2473 * Macro that given an attr e.g. hba_queue_depth expands
2474 * into a function with the name lpfc_hba_queue_depth_show
2476 * lpfc_##attr##_show: prints the attribute value in decimal.
2477 * @dev: class device that is converted into a Scsi_host.
2478 * @attr: device attribute, not used.
2479 * @buf: on return contains the attribute value in decimal.
2481 * Returns: length of formatted string.
2483 #define lpfc_vport_param_show(attr) \
2485 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2488 struct Scsi_Host *shost = class_to_shost(dev);\
2489 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2490 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2494 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2497 * Macro that given an attr e.g.
2498 * hba_queue_depth expands into a function with the name
2499 * lpfc_hba_queue_depth_show
2501 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2502 * @dev: class device that is converted into a Scsi_host.
2503 * @attr: device attribute, not used.
2504 * @buf: on return contains the attribute value in hexadecimal.
2506 * Returns: length of formatted string.
2508 #define lpfc_vport_param_hex_show(attr) \
2510 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2513 struct Scsi_Host *shost = class_to_shost(dev);\
2514 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2515 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2519 * lpfc_vport_param_init - Initialize a vport cfg attribute
2522 * Macro that given an attr e.g. hba_queue_depth expands
2523 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2524 * takes a default argument, a minimum and maximum argument.
2526 * lpfc_##attr##_init: validates the min and max values then sets the
2527 * adapter config field accordingly, or uses the default if out of range
2528 * and prints an error message.
2529 * @phba: pointer the the adapter structure.
2530 * @val: integer attribute value.
2534 * -EINVAL if default used
2536 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2538 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2540 if (lpfc_rangecheck(val, minval, maxval)) {\
2541 vport->cfg_##attr = val;\
2544 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2545 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2546 "allowed range is ["#minval", "#maxval"]\n", val); \
2547 vport->cfg_##attr = default;\
2552 * lpfc_vport_param_set - Set a vport cfg attribute
2555 * Macro that given an attr e.g. hba_queue_depth expands
2556 * into a function with the name lpfc_hba_queue_depth_set
2558 * lpfc_##attr##_set: validates the min and max values then sets the
2559 * adapter config field if in the valid range. prints error message
2560 * and does not set the parameter if invalid.
2561 * @phba: pointer the the adapter structure.
2562 * @val: integer attribute value.
2566 * -EINVAL if val is invalid
2568 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2570 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2572 if (lpfc_rangecheck(val, minval, maxval)) {\
2573 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2574 "3053 lpfc_" #attr \
2575 " changed from %d (x%x) to %d (x%x)\n", \
2576 vport->cfg_##attr, vport->cfg_##attr, \
2578 vport->cfg_##attr = val;\
2581 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2582 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2583 "allowed range is ["#minval", "#maxval"]\n", val); \
2588 * lpfc_vport_param_store - Set a vport attribute
2591 * Macro that given an attr e.g. hba_queue_depth
2592 * expands into a function with the name lpfc_hba_queue_depth_store
2594 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2595 * use the lpfc_##attr##_set function to set the value.
2596 * @cdev: class device that is converted into a Scsi_host.
2597 * @buf: contains the attribute value in decimal.
2601 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2602 * length of buffer upon success.
2604 #define lpfc_vport_param_store(attr) \
2606 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2607 const char *buf, size_t count) \
2609 struct Scsi_Host *shost = class_to_shost(dev);\
2610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2612 if (!isdigit(buf[0]))\
2614 if (sscanf(buf, "%i", &val) != 1)\
2616 if (lpfc_##attr##_set(vport, val) == 0) \
2617 return strlen(buf);\
2623 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2624 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2625 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2626 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2627 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2628 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2629 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2630 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2631 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2632 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2633 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2634 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2635 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2636 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2637 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2638 lpfc_link_state_store);
2639 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2640 lpfc_option_rom_version_show, NULL);
2641 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2642 lpfc_num_discovered_ports_show, NULL);
2643 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2644 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2645 static DEVICE_ATTR_RO(lpfc_drvr_version);
2646 static DEVICE_ATTR_RO(lpfc_enable_fip);
2647 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2648 lpfc_board_mode_show, lpfc_board_mode_store);
2649 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2650 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2651 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2652 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2653 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2654 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2655 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2656 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2657 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2658 static DEVICE_ATTR_RO(lpfc_fips_level);
2659 static DEVICE_ATTR_RO(lpfc_fips_rev);
2660 static DEVICE_ATTR_RO(lpfc_dss);
2661 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2662 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2663 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2666 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2669 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2671 * @cnt: Length of string.
2672 * @wwn: Array to receive converted wwn value.
2675 * -EINVAL if the buffer does not contain a valid wwn
2679 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2683 /* Count may include a LF at end of string */
2684 if (buf[cnt-1] == '\n')
2687 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2688 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2691 memset(wwn, 0, WWN_SZ);
2693 /* Validate and store the new name */
2694 for (i = 0, j = 0; i < 16; i++) {
2695 if ((*buf >= 'a') && (*buf <= 'f'))
2696 j = ((j << 4) | ((*buf++ - 'a') + 10));
2697 else if ((*buf >= 'A') && (*buf <= 'F'))
2698 j = ((j << 4) | ((*buf++ - 'A') + 10));
2699 else if ((*buf >= '0') && (*buf <= '9'))
2700 j = ((j << 4) | (*buf++ - '0'));
2704 wwn[i/2] = j & 0xff;
2711 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2712 * @dev: class device that is converted into a Scsi_host.
2713 * @attr: device attribute, not used.
2714 * @buf: containing the string lpfc_soft_wwn_key.
2715 * @count: must be size of lpfc_soft_wwn_key.
2718 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2719 * length of buf indicates success
2722 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2723 const char *buf, size_t count)
2725 struct Scsi_Host *shost = class_to_shost(dev);
2726 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2727 struct lpfc_hba *phba = vport->phba;
2728 unsigned int cnt = count;
2729 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2730 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2733 * We're doing a simple sanity check for soft_wwpn setting.
2734 * We require that the user write a specific key to enable
2735 * the soft_wwpn attribute to be settable. Once the attribute
2736 * is written, the enable key resets. If further updates are
2737 * desired, the key must be written again to re-enable the
2740 * The "key" is not secret - it is a hardcoded string shown
2741 * here. The intent is to protect against the random user or
2742 * application that is just writing attributes.
2744 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2745 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2746 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2747 " be enabled: fawwpn is enabled\n");
2751 /* count may include a LF at end of string */
2752 if (buf[cnt-1] == '\n')
2755 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2756 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2759 phba->soft_wwn_enable = 1;
2761 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2762 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2764 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2765 " The soft_wwpn feature is not supported by Broadcom.");
2769 static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
2772 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2773 * @dev: class device that is converted into a Scsi_host.
2774 * @attr: device attribute, not used.
2775 * @buf: on return contains the wwpn in hexadecimal.
2777 * Returns: size of formatted string.
2780 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2783 struct Scsi_Host *shost = class_to_shost(dev);
2784 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2785 struct lpfc_hba *phba = vport->phba;
2787 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2788 (unsigned long long)phba->cfg_soft_wwpn);
2792 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2793 * @dev class device that is converted into a Scsi_host.
2794 * @attr: device attribute, not used.
2795 * @buf: contains the wwpn in hexadecimal.
2796 * @count: number of wwpn bytes in buf
2799 * -EACCES hba reset not enabled, adapter over temp
2800 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2801 * -EIO error taking adapter offline or online
2802 * value of count on success
2805 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2806 const char *buf, size_t count)
2808 struct Scsi_Host *shost = class_to_shost(dev);
2809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2810 struct lpfc_hba *phba = vport->phba;
2811 struct completion online_compl;
2812 int stat1 = 0, stat2 = 0;
2813 unsigned int cnt = count;
2817 if (!phba->cfg_enable_hba_reset)
2819 spin_lock_irq(&phba->hbalock);
2820 if (phba->over_temp_state == HBA_OVER_TEMP) {
2821 spin_unlock_irq(&phba->hbalock);
2824 spin_unlock_irq(&phba->hbalock);
2825 /* count may include a LF at end of string */
2826 if (buf[cnt-1] == '\n')
2829 if (!phba->soft_wwn_enable)
2832 /* lock setting wwpn, wwnn down */
2833 phba->soft_wwn_enable = 0;
2835 rc = lpfc_wwn_set(buf, cnt, wwpn);
2837 /* not able to set wwpn, unlock it */
2838 phba->soft_wwn_enable = 1;
2842 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2843 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2844 if (phba->cfg_soft_wwnn)
2845 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2847 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2848 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2850 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2853 "0463 lpfc_soft_wwpn attribute set failed to "
2854 "reinit adapter - %d\n", stat1);
2855 init_completion(&online_compl);
2856 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2861 wait_for_completion(&online_compl);
2863 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2864 "0464 lpfc_soft_wwpn attribute set failed to "
2865 "reinit adapter - %d\n", stat2);
2866 return (stat1 || stat2) ? -EIO : count;
2868 static DEVICE_ATTR_RW(lpfc_soft_wwpn);
2871 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2872 * @dev: class device that is converted into a Scsi_host.
2873 * @attr: device attribute, not used.
2874 * @buf: on return contains the wwnn in hexadecimal.
2876 * Returns: size of formatted string.
2879 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2882 struct Scsi_Host *shost = class_to_shost(dev);
2883 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2884 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2885 (unsigned long long)phba->cfg_soft_wwnn);
2889 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2890 * @cdev: class device that is converted into a Scsi_host.
2891 * @buf: contains the ww node name in hexadecimal.
2892 * @count: number of wwnn bytes in buf.
2895 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2896 * value of count on success
2899 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2900 const char *buf, size_t count)
2902 struct Scsi_Host *shost = class_to_shost(dev);
2903 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2904 unsigned int cnt = count;
2908 /* count may include a LF at end of string */
2909 if (buf[cnt-1] == '\n')
2912 if (!phba->soft_wwn_enable)
2915 rc = lpfc_wwn_set(buf, cnt, wwnn);
2917 /* Allow wwnn to be set many times, as long as the enable
2918 * is set. However, once the wwpn is set, everything locks.
2923 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2925 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2926 "lpfc%d: soft_wwnn set. Value will take effect upon "
2927 "setting of the soft_wwpn\n", phba->brd_no);
2931 static DEVICE_ATTR_RW(lpfc_soft_wwnn);
2934 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2935 * Optimized Access Storage (OAS) operations.
2936 * @dev: class device that is converted into a Scsi_host.
2937 * @attr: device attribute, not used.
2938 * @buf: buffer for passing information.
2944 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2947 struct Scsi_Host *shost = class_to_shost(dev);
2948 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2950 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2951 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2955 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2956 * Optimized Access Storage (OAS) operations.
2957 * @dev: class device that is converted into a Scsi_host.
2958 * @attr: device attribute, not used.
2959 * @buf: buffer for passing information.
2960 * @count: Size of the data buffer.
2963 * -EINVAL count is invalid, invalid wwpn byte invalid
2964 * -EPERM oas is not supported by hba
2965 * value of count on success
2968 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2969 const char *buf, size_t count)
2971 struct Scsi_Host *shost = class_to_shost(dev);
2972 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2973 unsigned int cnt = count;
2974 uint8_t wwpn[WWN_SZ];
2980 /* count may include a LF at end of string */
2981 if (buf[cnt-1] == '\n')
2984 rc = lpfc_wwn_set(buf, cnt, wwpn);
2988 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2989 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2990 if (wwn_to_u64(wwpn) == 0)
2991 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2993 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2994 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2995 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2998 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2999 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
3002 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
3003 * Optimized Access Storage (OAS) operations.
3004 * @dev: class device that is converted into a Scsi_host.
3005 * @attr: device attribute, not used.
3006 * @buf: buffer for passing information.
3012 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3015 struct Scsi_Host *shost = class_to_shost(dev);
3016 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3018 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3022 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3023 * Optimized Access Storage (OAS) operations.
3024 * @dev: class device that is converted into a Scsi_host.
3025 * @attr: device attribute, not used.
3026 * @buf: buffer for passing information.
3027 * @count: Size of the data buffer.
3030 * -EINVAL count is invalid, invalid wwpn byte invalid
3031 * -EPERM oas is not supported by hba
3032 * value of count on success
3035 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3036 const char *buf, size_t count)
3038 struct Scsi_Host *shost = class_to_shost(dev);
3039 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3040 unsigned int cnt = count;
3047 /* count may include a LF at end of string */
3048 if (buf[cnt-1] == '\n')
3051 ret = kstrtoul(buf, 0, &val);
3052 if (ret || (val > 0x7f))
3056 phba->cfg_oas_priority = (uint8_t)val;
3058 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3061 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3062 lpfc_oas_priority_show, lpfc_oas_priority_store);
3065 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3066 * for Optimized Access Storage (OAS) operations.
3067 * @dev: class device that is converted into a Scsi_host.
3068 * @attr: device attribute, not used.
3069 * @buf: buffer for passing information.
3072 * value of count on success
3075 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3078 struct Scsi_Host *shost = class_to_shost(dev);
3079 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3081 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
3082 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3086 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3087 * for Optimized Access Storage (OAS) operations.
3088 * @dev: class device that is converted into a Scsi_host.
3089 * @attr: device attribute, not used.
3090 * @buf: buffer for passing information.
3091 * @count: Size of the data buffer.
3094 * -EINVAL count is invalid, invalid wwpn byte invalid
3095 * -EPERM oas is not supported by hba
3096 * value of count on success
3099 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3100 const char *buf, size_t count)
3102 struct Scsi_Host *shost = class_to_shost(dev);
3103 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3104 unsigned int cnt = count;
3105 uint8_t wwpn[WWN_SZ];
3111 /* count may include a LF at end of string */
3112 if (buf[cnt-1] == '\n')
3115 rc = lpfc_wwn_set(buf, cnt, wwpn);
3119 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3120 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3121 if (wwn_to_u64(wwpn) == 0)
3122 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3124 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3125 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3126 if (phba->cfg_oas_priority == 0)
3127 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3128 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3131 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3132 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3135 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3136 * of whether luns will be enabled or disabled
3137 * for Optimized Access Storage (OAS) operations.
3138 * @dev: class device that is converted into a Scsi_host.
3139 * @attr: device attribute, not used.
3140 * @buf: buffer for passing information.
3143 * size of formatted string.
3146 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3149 struct Scsi_Host *shost = class_to_shost(dev);
3150 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3152 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3156 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3157 * of whether luns will be enabled or disabled
3158 * for Optimized Access Storage (OAS) operations.
3159 * @dev: class device that is converted into a Scsi_host.
3160 * @attr: device attribute, not used.
3161 * @buf: buffer for passing information.
3162 * @count: Size of the data buffer.
3165 * -EINVAL count is invalid, invalid wwpn byte invalid
3166 * -EPERM oas is not supported by hba
3167 * value of count on success
3170 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3171 const char *buf, size_t count)
3173 struct Scsi_Host *shost = class_to_shost(dev);
3174 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3180 if (!isdigit(buf[0]))
3183 if (sscanf(buf, "%i", &val) != 1)
3186 if ((val != 0) && (val != 1))
3189 phba->cfg_oas_lun_state = val;
3192 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3193 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3196 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3197 * Storage (OAS) lun returned by the
3198 * lpfc_oas_lun_show function.
3199 * @dev: class device that is converted into a Scsi_host.
3200 * @attr: device attribute, not used.
3201 * @buf: buffer for passing information.
3204 * size of formatted string.
3207 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3210 struct Scsi_Host *shost = class_to_shost(dev);
3211 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3213 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3216 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3218 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3219 lpfc_oas_lun_status_show, NULL);
3223 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3225 * @phba: lpfc_hba pointer.
3226 * @ndlp: pointer to fcp target node.
3227 * @lun: the fc lun for setting oas state.
3228 * @oas_state: the oas state to be set to the lun.
3232 * -EPERM OAS is not enabled or not supported by this port.
3236 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3237 uint8_t tgt_wwpn[], uint64_t lun,
3238 uint32_t oas_state, uint8_t pri)
3247 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3248 (struct lpfc_name *)tgt_wwpn,
3252 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3253 (struct lpfc_name *)tgt_wwpn, lun, pri);
3260 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3261 * Access Storage (OAS) operations.
3262 * @phba: lpfc_hba pointer.
3263 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3264 * @tgt_wwpn: wwpn of the target associated with the returned lun
3265 * @lun_status: status of the lun returned lun
3267 * Returns the first or next lun enabled for OAS operations for the vport/target
3268 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3269 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3272 * lun that is OAS enabled for the vport/target
3273 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3276 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3277 uint8_t tgt_wwpn[], uint32_t *lun_status,
3282 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3283 return NOT_OAS_ENABLED_LUN;
3284 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3285 phba->sli4_hba.oas_next_vpt_wwpn,
3286 (struct lpfc_name *)
3287 phba->sli4_hba.oas_next_tgt_wwpn,
3288 &phba->sli4_hba.oas_next_lun,
3289 (struct lpfc_name *)vpt_wwpn,
3290 (struct lpfc_name *)tgt_wwpn,
3291 &found_lun, lun_status, lun_pri))
3294 return NOT_OAS_ENABLED_LUN;
3298 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3299 * @phba: lpfc_hba pointer.
3300 * @vpt_wwpn: vport wwpn by reference.
3301 * @tgt_wwpn: target wwpn by reference.
3302 * @lun: the fc lun for setting oas state.
3303 * @oas_state: the oas state to be set to the oas_lun.
3305 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3306 * a lun for OAS operations.
3310 * -ENOMEM: failed to enable an lun for OAS operations
3311 * -EPERM: OAS is not enabled
3314 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3315 uint8_t tgt_wwpn[], uint64_t lun,
3316 uint32_t oas_state, uint8_t pri)
3321 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3327 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3328 * @dev: class device that is converted into a Scsi_host.
3329 * @attr: device attribute, not used.
3330 * @buf: buffer for passing information.
3332 * This routine returns a lun enabled for OAS each time the function
3336 * SUCCESS: size of formatted string.
3337 * -EFAULT: target or vport wwpn was not set properly.
3338 * -EPERM: oas is not enabled.
3341 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3344 struct Scsi_Host *shost = class_to_shost(dev);
3345 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3353 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3354 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3357 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3358 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3361 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3362 phba->cfg_oas_tgt_wwpn,
3363 &phba->cfg_oas_lun_status,
3364 &phba->cfg_oas_priority);
3365 if (oas_lun != NOT_OAS_ENABLED_LUN)
3366 phba->cfg_oas_flags |= OAS_LUN_VALID;
3368 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3374 * lpfc_oas_lun_store - Sets the OAS state for lun
3375 * @dev: class device that is converted into a Scsi_host.
3376 * @attr: device attribute, not used.
3377 * @buf: buffer for passing information.
3379 * This function sets the OAS state for lun. Before this function is called,
3380 * the vport wwpn, target wwpn, and oas state need to be set.
3383 * SUCCESS: size of formatted string.
3384 * -EFAULT: target or vport wwpn was not set properly.
3385 * -EPERM: oas is not enabled.
3386 * size of formatted string.
3389 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3390 const char *buf, size_t count)
3392 struct Scsi_Host *shost = class_to_shost(dev);
3393 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3401 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3404 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3407 if (!isdigit(buf[0]))
3410 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3413 pri = phba->cfg_oas_priority;
3415 pri = phba->cfg_XLanePriority;
3417 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3418 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3419 "priority 0x%x with oas state %d\n",
3420 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3421 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3422 pri, phba->cfg_oas_lun_state);
3424 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3425 phba->cfg_oas_tgt_wwpn, scsi_lun,
3426 phba->cfg_oas_lun_state, pri);
3432 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3433 lpfc_oas_lun_show, lpfc_oas_lun_store);
3435 int lpfc_enable_nvmet_cnt;
3436 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3437 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3438 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3439 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3440 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3442 static int lpfc_poll = 0;
3443 module_param(lpfc_poll, int, S_IRUGO);
3444 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3446 " 1 - poll with interrupts enabled"
3447 " 3 - poll and disable FCP ring interrupts");
3449 static DEVICE_ATTR_RW(lpfc_poll);
3451 int lpfc_no_hba_reset_cnt;
3452 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3453 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3454 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3455 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3457 LPFC_ATTR(sli_mode, 0, 0, 3,
3458 "SLI mode selector:"
3459 " 0 - auto (SLI-3 if supported),"
3460 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3461 " 3 - select SLI-3");
3463 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3464 "Enable NPIV functionality");
3466 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3467 "FCF Fast failover=1 Priority failover=2");
3470 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3471 # 0x0 = disabled, XRI/OXID use not tracked.
3472 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3473 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3475 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3476 "Enable RRQ functionality");
3479 # lpfc_suppress_link_up: Bring link up at initialization
3480 # 0x0 = bring link up (issue MBX_INIT_LINK)
3481 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3482 # 0x2 = never bring up link
3483 # Default value is 0.
3485 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3486 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3487 "Suppress Link Up at initialization");
3489 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3497 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3499 struct Scsi_Host *shost = class_to_shost(dev);
3500 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3502 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3505 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3506 lpfc_iocb_hw_show, NULL);
3508 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3510 struct Scsi_Host *shost = class_to_shost(dev);
3511 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3512 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3514 return snprintf(buf, PAGE_SIZE, "%d\n",
3515 pring ? pring->txq_max : 0);
3518 static DEVICE_ATTR(txq_hw, S_IRUGO,
3519 lpfc_txq_hw_show, NULL);
3521 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3524 struct Scsi_Host *shost = class_to_shost(dev);
3525 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3526 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3528 return snprintf(buf, PAGE_SIZE, "%d\n",
3529 pring ? pring->txcmplq_max : 0);
3532 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3533 lpfc_txcmplq_hw_show, NULL);
3535 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3536 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3539 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3540 # until the timer expires. Value range is [0,255]. Default value is 30.
3542 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3543 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3544 module_param(lpfc_nodev_tmo, int, 0);
3545 MODULE_PARM_DESC(lpfc_nodev_tmo,
3546 "Seconds driver will hold I/O waiting "
3547 "for a device to come back");
3550 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3551 * @dev: class converted to a Scsi_host structure.
3552 * @attr: device attribute, not used.
3553 * @buf: on return contains the dev loss timeout in decimal.
3555 * Returns: size of formatted string.
3558 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3561 struct Scsi_Host *shost = class_to_shost(dev);
3562 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3564 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3568 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3569 * @vport: lpfc vport structure pointer.
3570 * @val: contains the nodev timeout value.
3573 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3574 * a kernel error message is printed and zero is returned.
3575 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3576 * Otherwise nodev tmo is set to the default value.
3579 * zero if already set or if val is in range
3580 * -EINVAL val out of range
3583 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3585 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3586 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3587 if (val != LPFC_DEF_DEVLOSS_TMO)
3588 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3589 "0407 Ignoring lpfc_nodev_tmo module "
3590 "parameter because lpfc_devloss_tmo "
3595 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3596 vport->cfg_nodev_tmo = val;
3597 vport->cfg_devloss_tmo = val;
3600 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3601 "0400 lpfc_nodev_tmo attribute cannot be set to"
3602 " %d, allowed range is [%d, %d]\n",
3603 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3604 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3609 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3610 * @vport: lpfc vport structure pointer.
3613 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3616 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3618 struct Scsi_Host *shost;
3619 struct lpfc_nodelist *ndlp;
3620 #if (IS_ENABLED(CONFIG_NVME_FC))
3621 struct lpfc_nvme_rport *rport;
3622 struct nvme_fc_remote_port *remoteport = NULL;
3625 shost = lpfc_shost_from_vport(vport);
3626 spin_lock_irq(shost->host_lock);
3627 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3628 if (!NLP_CHK_NODE_ACT(ndlp))
3631 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3632 #if (IS_ENABLED(CONFIG_NVME_FC))
3633 spin_lock(&vport->phba->hbalock);
3634 rport = lpfc_ndlp_get_nrport(ndlp);
3636 remoteport = rport->remoteport;
3637 spin_unlock(&vport->phba->hbalock);
3639 nvme_fc_set_remoteport_devloss(rport->remoteport,
3640 vport->cfg_devloss_tmo);
3643 spin_unlock_irq(shost->host_lock);
3647 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3648 * @vport: lpfc vport structure pointer.
3649 * @val: contains the tmo value.
3652 * If the devloss tmo is already set or the vport dev loss tmo has changed
3653 * then a kernel error message is printed and zero is returned.
3654 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3655 * Otherwise nodev tmo is set to the default value.
3658 * zero if already set or if val is in range
3659 * -EINVAL val out of range
3662 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3664 if (vport->dev_loss_tmo_changed ||
3665 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3666 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3667 "0401 Ignoring change to lpfc_nodev_tmo "
3668 "because lpfc_devloss_tmo is set.\n");
3671 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3672 vport->cfg_nodev_tmo = val;
3673 vport->cfg_devloss_tmo = val;
3675 * For compat: set the fc_host dev loss so new rports
3676 * will get the value.
3678 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3679 lpfc_update_rport_devloss_tmo(vport);
3682 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3683 "0403 lpfc_nodev_tmo attribute cannot be set to "
3684 "%d, allowed range is [%d, %d]\n",
3685 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3689 lpfc_vport_param_store(nodev_tmo)
3691 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3694 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3695 # disappear until the timer expires. Value range is [0,255]. Default
3698 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3699 MODULE_PARM_DESC(lpfc_devloss_tmo,
3700 "Seconds driver will hold I/O waiting "
3701 "for a device to come back");
3702 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3703 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3704 lpfc_vport_param_show(devloss_tmo)
3707 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3708 * @vport: lpfc vport structure pointer.
3709 * @val: contains the tmo value.
3712 * If val is in a valid range then set the vport nodev tmo,
3713 * devloss tmo, also set the vport dev loss tmo changed flag.
3714 * Else a kernel error message is printed.
3717 * zero if val is in range
3718 * -EINVAL val out of range
3721 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3723 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3724 vport->cfg_nodev_tmo = val;
3725 vport->cfg_devloss_tmo = val;
3726 vport->dev_loss_tmo_changed = 1;
3727 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3728 lpfc_update_rport_devloss_tmo(vport);
3732 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3733 "0404 lpfc_devloss_tmo attribute cannot be set to "
3734 "%d, allowed range is [%d, %d]\n",
3735 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3739 lpfc_vport_param_store(devloss_tmo)
3740 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3743 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3744 * lpfc_suppress_rsp = 0 Disable
3745 * lpfc_suppress_rsp = 1 Enable (default)
3748 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3749 "Enable suppress rsp feature is firmware supports it");
3752 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3753 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3754 * lpfc_nvmet_mrq = 1 use a single RQ pair
3755 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3758 LPFC_ATTR_R(nvmet_mrq,
3759 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3760 "Specify number of RQ pairs for processing NVMET cmds");
3763 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3764 * to each NVMET RQ. Range 64 to 2048, default is 512.
3766 LPFC_ATTR_R(nvmet_mrq_post,
3767 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3768 LPFC_NVMET_RQE_DEF_COUNT,
3769 "Specify number of RQ buffers to initially post");
3772 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3773 * Supported Values: 1 - register just FCP
3774 * 3 - register both FCP and NVME
3775 * Supported values are [1,3]. Default value is 3
3777 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3778 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3779 "Enable FC4 Protocol support - FCP / NVME");
3782 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3783 # deluged with LOTS of information.
3784 # You can set a bit mask to record specific types of verbose messages:
3785 # See lpfc_logmsh.h for definitions.
3787 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3788 "Verbose logging bit-mask");
3791 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3792 # objects that have been registered with the nameserver after login.
3794 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3795 "Deregister nameserver objects before LOGO");
3798 # lun_queue_depth: This parameter is used to limit the number of outstanding
3799 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3800 # If this parameter value is greater than 1/8th the maximum number of exchanges
3801 # supported by the HBA port, then the lun queue depth will be reduced to
3802 # 1/8th the maximum number of exchanges.
3804 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3805 "Max number of FCP commands we can queue to a specific LUN");
3808 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3809 # commands per target port. Value range is [10,65535]. Default value is 65535.
3811 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3812 module_param(lpfc_tgt_queue_depth, uint, 0444);
3813 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3814 lpfc_vport_param_show(tgt_queue_depth);
3815 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3816 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3819 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3820 * @phba: pointer the the adapter structure.
3821 * @val: integer attribute value.
3823 * Description: Sets the parameter to the new value.
3827 * -EINVAL if val is invalid
3830 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3832 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3833 struct lpfc_nodelist *ndlp;
3835 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3838 if (val == vport->cfg_tgt_queue_depth)
3841 spin_lock_irq(shost->host_lock);
3842 vport->cfg_tgt_queue_depth = val;
3844 /* Next loop thru nodelist and change cmd_qdepth */
3845 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3846 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3848 spin_unlock_irq(shost->host_lock);
3852 lpfc_vport_param_store(tgt_queue_depth);
3853 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3856 # hba_queue_depth: This parameter is used to limit the number of outstanding
3857 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3858 # value is greater than the maximum number of exchanges supported by the HBA,
3859 # then maximum number of exchanges supported by the HBA is used to determine
3860 # the hba_queue_depth.
3862 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3863 "Max number of FCP commands we can queue to a lpfc HBA");
3866 # peer_port_login: This parameter allows/prevents logins
3867 # between peer ports hosted on the same physical port.
3868 # When this parameter is set 0 peer ports of same physical port
3869 # are not allowed to login to each other.
3870 # When this parameter is set 1 peer ports of same physical port
3871 # are allowed to login to each other.
3872 # Default value of this parameter is 0.
3874 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3875 "Allow peer ports on the same physical port to login to each "
3879 # restrict_login: This parameter allows/prevents logins
3880 # between Virtual Ports and remote initiators.
3881 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3882 # other initiators and will attempt to PLOGI all remote ports.
3883 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3884 # remote ports and will not attempt to PLOGI to other initiators.
3885 # This parameter does not restrict to the physical port.
3886 # This parameter does not restrict logins to Fabric resident remote ports.
3887 # Default value of this parameter is 1.
3889 static int lpfc_restrict_login = 1;
3890 module_param(lpfc_restrict_login, int, S_IRUGO);
3891 MODULE_PARM_DESC(lpfc_restrict_login,
3892 "Restrict virtual ports login to remote initiators.");
3893 lpfc_vport_param_show(restrict_login);
3896 * lpfc_restrict_login_init - Set the vport restrict login flag
3897 * @vport: lpfc vport structure pointer.
3898 * @val: contains the restrict login value.
3901 * If val is not in a valid range then log a kernel error message and set
3902 * the vport restrict login to one.
3903 * If the port type is physical clear the restrict login flag and return.
3904 * Else set the restrict login flag to val.
3907 * zero if val is in range
3908 * -EINVAL val out of range
3911 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3913 if (val < 0 || val > 1) {
3914 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3915 "0422 lpfc_restrict_login attribute cannot "
3916 "be set to %d, allowed range is [0, 1]\n",
3918 vport->cfg_restrict_login = 1;
3921 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3922 vport->cfg_restrict_login = 0;
3925 vport->cfg_restrict_login = val;
3930 * lpfc_restrict_login_set - Set the vport restrict login flag
3931 * @vport: lpfc vport structure pointer.
3932 * @val: contains the restrict login value.
3935 * If val is not in a valid range then log a kernel error message and set
3936 * the vport restrict login to one.
3937 * If the port type is physical and the val is not zero log a kernel
3938 * error message, clear the restrict login flag and return zero.
3939 * Else set the restrict login flag to val.
3942 * zero if val is in range
3943 * -EINVAL val out of range
3946 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3948 if (val < 0 || val > 1) {
3949 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3950 "0425 lpfc_restrict_login attribute cannot "
3951 "be set to %d, allowed range is [0, 1]\n",
3953 vport->cfg_restrict_login = 1;
3956 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3957 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3958 "0468 lpfc_restrict_login must be 0 for "
3959 "Physical ports.\n");
3960 vport->cfg_restrict_login = 0;
3963 vport->cfg_restrict_login = val;
3966 lpfc_vport_param_store(restrict_login);
3967 static DEVICE_ATTR_RW(lpfc_restrict_login);
3970 # Some disk devices have a "select ID" or "select Target" capability.
3971 # From a protocol standpoint "select ID" usually means select the
3972 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3973 # annex" which contains a table that maps a "select ID" (a number
3974 # between 0 and 7F) to an ALPA. By default, for compatibility with
3975 # older drivers, the lpfc driver scans this table from low ALPA to high
3978 # Turning on the scan-down variable (on = 1, off = 0) will
3979 # cause the lpfc driver to use an inverted table, effectively
3980 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3982 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3983 # and will not work across a fabric. Also this parameter will take
3984 # effect only in the case when ALPA map is not available.)
3986 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3987 "Start scanning for devices from highest ALPA to lowest");
3990 # lpfc_topology: link topology for init link
3991 # 0x0 = attempt loop mode then point-to-point
3992 # 0x01 = internal loopback mode
3993 # 0x02 = attempt point-to-point mode only
3994 # 0x04 = attempt loop mode only
3995 # 0x06 = attempt point-to-point mode then loop
3996 # Set point-to-point mode if you want to run as an N_Port.
3997 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3998 # Default value is 0.
4000 LPFC_ATTR(topology, 0, 0, 6,
4001 "Select Fibre Channel topology");
4004 * lpfc_topology_set - Set the adapters topology field
4005 * @phba: lpfc_hba pointer.
4006 * @val: topology value.
4009 * If val is in a valid range then set the adapter's topology field and
4010 * issue a lip; if the lip fails reset the topology to the old value.
4012 * If the value is not in range log a kernel error message and return an error.
4015 * zero if val is in range and lip okay
4016 * non-zero return value from lpfc_issue_lip()
4017 * -EINVAL val out of range
4020 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4021 const char *buf, size_t count)
4023 struct Scsi_Host *shost = class_to_shost(dev);
4024 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4025 struct lpfc_hba *phba = vport->phba;
4028 const char *val_buf = buf;
4032 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4034 val_buf = &buf[strlen("nolip ")];
4037 if (!isdigit(val_buf[0]))
4039 if (sscanf(val_buf, "%i", &val) != 1)
4042 if (val >= 0 && val <= 6) {
4043 prev_val = phba->cfg_topology;
4044 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4046 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4047 "3113 Loop mode not supported at speed %d\n",
4051 if ((phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
4052 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC) &&
4054 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4055 "3114 Loop mode not supported\n");
4058 phba->cfg_topology = val;
4062 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4063 "3054 lpfc_topology changed from %d to %d\n",
4065 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4066 phba->fc_topology_changed = 1;
4067 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4069 phba->cfg_topology = prev_val;
4074 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4075 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4076 "allowed range is [0, 6]\n",
4081 lpfc_param_show(topology)
4082 static DEVICE_ATTR_RW(lpfc_topology);
4085 * lpfc_static_vport_show: Read callback function for
4086 * lpfc_static_vport sysfs file.
4087 * @dev: Pointer to class device object.
4088 * @attr: device attribute structure.
4089 * @buf: Data buffer.
4091 * This function is the read call back function for
4092 * lpfc_static_vport sysfs file. The lpfc_static_vport
4093 * sysfs file report the mageability of the vport.
4096 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4099 struct Scsi_Host *shost = class_to_shost(dev);
4100 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4101 if (vport->vport_flag & STATIC_VPORT)
4102 sprintf(buf, "1\n");
4104 sprintf(buf, "0\n");
4110 * Sysfs attribute to control the statistical data collection.
4112 static DEVICE_ATTR_RO(lpfc_static_vport);
4115 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
4116 * @dev: Pointer to class device.
4117 * @buf: Data buffer.
4118 * @count: Size of the data buffer.
4120 * This function get called when a user write to the lpfc_stat_data_ctrl
4121 * sysfs file. This function parse the command written to the sysfs file
4122 * and take appropriate action. These commands are used for controlling
4123 * driver statistical data collection.
4124 * Following are the command this function handles.
4126 * setbucket <bucket_type> <base> <step>
4127 * = Set the latency buckets.
4128 * destroybucket = destroy all the buckets.
4129 * start = start data collection
4130 * stop = stop data collection
4131 * reset = reset the collected data
4134 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4135 const char *buf, size_t count)
4137 struct Scsi_Host *shost = class_to_shost(dev);
4138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4139 struct lpfc_hba *phba = vport->phba;
4140 #define LPFC_MAX_DATA_CTRL_LEN 1024
4141 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4143 char *str_ptr, *token;
4144 struct lpfc_vport **vports;
4145 struct Scsi_Host *v_shost;
4146 char *bucket_type_str, *base_str, *step_str;
4147 unsigned long base, step, bucket_type;
4149 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
4150 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
4153 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
4154 str_ptr = &bucket_data[0];
4155 /* Ignore this token - this is command token */
4156 token = strsep(&str_ptr, "\t ");
4160 bucket_type_str = strsep(&str_ptr, "\t ");
4161 if (!bucket_type_str)
4164 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4165 bucket_type = LPFC_LINEAR_BUCKET;
4166 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4167 bucket_type = LPFC_POWER2_BUCKET;
4171 base_str = strsep(&str_ptr, "\t ");
4174 base = simple_strtoul(base_str, NULL, 0);
4176 step_str = strsep(&str_ptr, "\t ");
4179 step = simple_strtoul(step_str, NULL, 0);
4183 /* Block the data collection for every vport */
4184 vports = lpfc_create_vport_work_array(phba);
4188 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4189 v_shost = lpfc_shost_from_vport(vports[i]);
4190 spin_lock_irq(v_shost->host_lock);
4191 /* Block and reset data collection */
4192 vports[i]->stat_data_blocked = 1;
4193 if (vports[i]->stat_data_enabled)
4194 lpfc_vport_reset_stat_data(vports[i]);
4195 spin_unlock_irq(v_shost->host_lock);
4198 /* Set the bucket attributes */
4199 phba->bucket_type = bucket_type;
4200 phba->bucket_base = base;
4201 phba->bucket_step = step;
4203 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4204 v_shost = lpfc_shost_from_vport(vports[i]);
4206 /* Unblock data collection */
4207 spin_lock_irq(v_shost->host_lock);
4208 vports[i]->stat_data_blocked = 0;
4209 spin_unlock_irq(v_shost->host_lock);
4211 lpfc_destroy_vport_work_array(phba, vports);
4215 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4216 vports = lpfc_create_vport_work_array(phba);
4220 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4221 v_shost = lpfc_shost_from_vport(vports[i]);
4222 spin_lock_irq(shost->host_lock);
4223 vports[i]->stat_data_blocked = 1;
4224 lpfc_free_bucket(vport);
4225 vport->stat_data_enabled = 0;
4226 vports[i]->stat_data_blocked = 0;
4227 spin_unlock_irq(shost->host_lock);
4229 lpfc_destroy_vport_work_array(phba, vports);
4230 phba->bucket_type = LPFC_NO_BUCKET;
4231 phba->bucket_base = 0;
4232 phba->bucket_step = 0;
4236 if (!strncmp(buf, "start", strlen("start"))) {
4237 /* If no buckets configured return error */
4238 if (phba->bucket_type == LPFC_NO_BUCKET)
4240 spin_lock_irq(shost->host_lock);
4241 if (vport->stat_data_enabled) {
4242 spin_unlock_irq(shost->host_lock);
4245 lpfc_alloc_bucket(vport);
4246 vport->stat_data_enabled = 1;
4247 spin_unlock_irq(shost->host_lock);
4251 if (!strncmp(buf, "stop", strlen("stop"))) {
4252 spin_lock_irq(shost->host_lock);
4253 if (vport->stat_data_enabled == 0) {
4254 spin_unlock_irq(shost->host_lock);
4257 lpfc_free_bucket(vport);
4258 vport->stat_data_enabled = 0;
4259 spin_unlock_irq(shost->host_lock);
4263 if (!strncmp(buf, "reset", strlen("reset"))) {
4264 if ((phba->bucket_type == LPFC_NO_BUCKET)
4265 || !vport->stat_data_enabled)
4267 spin_lock_irq(shost->host_lock);
4268 vport->stat_data_blocked = 1;
4269 lpfc_vport_reset_stat_data(vport);
4270 vport->stat_data_blocked = 0;
4271 spin_unlock_irq(shost->host_lock);
4279 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
4280 * @dev: Pointer to class device object.
4281 * @buf: Data buffer.
4283 * This function is the read call back function for
4284 * lpfc_stat_data_ctrl sysfs file. This function report the
4285 * current statistical data collection state.
4288 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4291 struct Scsi_Host *shost = class_to_shost(dev);
4292 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4293 struct lpfc_hba *phba = vport->phba;
4297 unsigned long bucket_value;
4299 switch (phba->bucket_type) {
4300 case LPFC_LINEAR_BUCKET:
4301 bucket_type = "linear";
4303 case LPFC_POWER2_BUCKET:
4304 bucket_type = "power2";
4307 bucket_type = "No Bucket";
4311 sprintf(&buf[index], "Statistical Data enabled :%d, "
4312 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4313 " Bucket step :%d\nLatency Ranges :",
4314 vport->stat_data_enabled, vport->stat_data_blocked,
4315 bucket_type, phba->bucket_base, phba->bucket_step);
4316 index = strlen(buf);
4317 if (phba->bucket_type != LPFC_NO_BUCKET) {
4318 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4319 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4320 bucket_value = phba->bucket_base +
4321 phba->bucket_step * i;
4323 bucket_value = phba->bucket_base +
4324 (1 << i) * phba->bucket_step;
4326 if (index + 10 > PAGE_SIZE)
4328 sprintf(&buf[index], "%08ld ", bucket_value);
4329 index = strlen(buf);
4332 sprintf(&buf[index], "\n");
4337 * Sysfs attribute to control the statistical data collection.
4339 static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
4342 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4346 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4349 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4350 #define MAX_STAT_DATA_SIZE_PER_TARGET \
4351 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4355 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
4357 * @kobj: Pointer to the kernel object
4358 * @bin_attr: Attribute object
4359 * @buff: Buffer pointer
4361 * @count: Buffer size
4363 * This function is the read call back function for lpfc_drvr_stat_data
4364 * sysfs file. This function export the statistical data to user
4368 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4369 struct bin_attribute *bin_attr,
4370 char *buf, loff_t off, size_t count)
4372 struct device *dev = container_of(kobj, struct device,
4374 struct Scsi_Host *shost = class_to_shost(dev);
4375 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4376 struct lpfc_hba *phba = vport->phba;
4377 int i = 0, index = 0;
4378 unsigned long nport_index;
4379 struct lpfc_nodelist *ndlp = NULL;
4380 nport_index = (unsigned long)off /
4381 MAX_STAT_DATA_SIZE_PER_TARGET;
4383 if (!vport->stat_data_enabled || vport->stat_data_blocked
4384 || (phba->bucket_type == LPFC_NO_BUCKET))
4387 spin_lock_irq(shost->host_lock);
4388 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4389 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4392 if (nport_index > 0) {
4397 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4401 if (!ndlp->lat_data)
4405 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4406 ndlp->nlp_portname.u.wwn[0],
4407 ndlp->nlp_portname.u.wwn[1],
4408 ndlp->nlp_portname.u.wwn[2],
4409 ndlp->nlp_portname.u.wwn[3],
4410 ndlp->nlp_portname.u.wwn[4],
4411 ndlp->nlp_portname.u.wwn[5],
4412 ndlp->nlp_portname.u.wwn[6],
4413 ndlp->nlp_portname.u.wwn[7]);
4415 index = strlen(buf);
4417 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4418 sprintf(&buf[index], "%010u,",
4419 ndlp->lat_data[i].cmd_count);
4420 index = strlen(buf);
4422 sprintf(&buf[index], "\n");
4423 index = strlen(buf);
4425 spin_unlock_irq(shost->host_lock);
4429 static struct bin_attribute sysfs_drvr_stat_data_attr = {
4431 .name = "lpfc_drvr_stat_data",
4434 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4435 .read = sysfs_drvr_stat_data_read,
4440 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4442 # Value range is [0,16]. Default value is 0.
4445 * lpfc_link_speed_set - Set the adapters link speed
4446 * @phba: lpfc_hba pointer.
4447 * @val: link speed value.
4450 * If val is in a valid range then set the adapter's link speed field and
4451 * issue a lip; if the lip fails reset the link speed to the old value.
4454 * If the value is not in range log a kernel error message and return an error.
4457 * zero if val is in range and lip okay.
4458 * non-zero return value from lpfc_issue_lip()
4459 * -EINVAL val out of range
4462 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4463 const char *buf, size_t count)
4465 struct Scsi_Host *shost = class_to_shost(dev);
4466 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4467 struct lpfc_hba *phba = vport->phba;
4468 int val = LPFC_USER_LINK_SPEED_AUTO;
4470 const char *val_buf = buf;
4472 uint32_t prev_val, if_type;
4474 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4475 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4476 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4479 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4481 val_buf = &buf[strlen("nolip ")];
4484 if (!isdigit(val_buf[0]))
4486 if (sscanf(val_buf, "%i", &val) != 1)
4489 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4490 "3055 lpfc_link_speed changed from %d to %d %s\n",
4491 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4493 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4494 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4495 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4496 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4497 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4498 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4499 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4500 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4501 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4502 "2879 lpfc_link_speed attribute cannot be set "
4503 "to %d. Speed is not supported by this port.\n",
4507 if (val >= LPFC_USER_LINK_SPEED_16G &&
4508 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4509 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4510 "3112 lpfc_link_speed attribute cannot be set "
4511 "to %d. Speed is not supported in loop mode.\n",
4517 case LPFC_USER_LINK_SPEED_AUTO:
4518 case LPFC_USER_LINK_SPEED_1G:
4519 case LPFC_USER_LINK_SPEED_2G:
4520 case LPFC_USER_LINK_SPEED_4G:
4521 case LPFC_USER_LINK_SPEED_8G:
4522 case LPFC_USER_LINK_SPEED_16G:
4523 case LPFC_USER_LINK_SPEED_32G:
4524 case LPFC_USER_LINK_SPEED_64G:
4525 prev_val = phba->cfg_link_speed;
4526 phba->cfg_link_speed = val;
4530 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4532 phba->cfg_link_speed = prev_val;
4540 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4541 "0469 lpfc_link_speed attribute cannot be set to %d, "
4542 "allowed values are [%s]\n",
4543 val, LPFC_LINK_SPEED_STRING);
4548 static int lpfc_link_speed = 0;
4549 module_param(lpfc_link_speed, int, S_IRUGO);
4550 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4551 lpfc_param_show(link_speed)
4554 * lpfc_link_speed_init - Set the adapters link speed
4555 * @phba: lpfc_hba pointer.
4556 * @val: link speed value.
4559 * If val is in a valid range then set the adapter's link speed field.
4562 * If the value is not in range log a kernel error message, clear the link
4563 * speed and return an error.
4566 * zero if val saved.
4567 * -EINVAL val out of range
4570 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4572 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4573 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4574 "3111 lpfc_link_speed of %d cannot "
4575 "support loop mode, setting topology to default.\n",
4577 phba->cfg_topology = 0;
4581 case LPFC_USER_LINK_SPEED_AUTO:
4582 case LPFC_USER_LINK_SPEED_1G:
4583 case LPFC_USER_LINK_SPEED_2G:
4584 case LPFC_USER_LINK_SPEED_4G:
4585 case LPFC_USER_LINK_SPEED_8G:
4586 case LPFC_USER_LINK_SPEED_16G:
4587 case LPFC_USER_LINK_SPEED_32G:
4588 case LPFC_USER_LINK_SPEED_64G:
4589 phba->cfg_link_speed = val;
4592 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4593 "0405 lpfc_link_speed attribute cannot "
4594 "be set to %d, allowed values are "
4595 "["LPFC_LINK_SPEED_STRING"]\n", val);
4596 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4601 static DEVICE_ATTR_RW(lpfc_link_speed);
4604 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4605 # 0 = aer disabled or not supported
4606 # 1 = aer supported and enabled (default)
4607 # Value range is [0,1]. Default value is 1.
4609 LPFC_ATTR(aer_support, 1, 0, 1,
4610 "Enable PCIe device AER support");
4611 lpfc_param_show(aer_support)
4614 * lpfc_aer_support_store - Set the adapter for aer support
4616 * @dev: class device that is converted into a Scsi_host.
4617 * @attr: device attribute, not used.
4618 * @buf: containing enable or disable aer flag.
4619 * @count: unused variable.
4622 * If the val is 1 and currently the device's AER capability was not
4623 * enabled, invoke the kernel's enable AER helper routine, trying to
4624 * enable the device's AER capability. If the helper routine enabling
4625 * AER returns success, update the device's cfg_aer_support flag to
4626 * indicate AER is supported by the device; otherwise, if the device
4627 * AER capability is already enabled to support AER, then do nothing.
4629 * If the val is 0 and currently the device's AER support was enabled,
4630 * invoke the kernel's disable AER helper routine. After that, update
4631 * the device's cfg_aer_support flag to indicate AER is not supported
4632 * by the device; otherwise, if the device AER capability is already
4633 * disabled from supporting AER, then do nothing.
4636 * length of the buf on success if val is in range the intended mode
4638 * -EINVAL if val out of range or intended mode is not supported.
4641 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4642 const char *buf, size_t count)
4644 struct Scsi_Host *shost = class_to_shost(dev);
4645 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4646 struct lpfc_hba *phba = vport->phba;
4647 int val = 0, rc = -EINVAL;
4649 if (!isdigit(buf[0]))
4651 if (sscanf(buf, "%i", &val) != 1)
4656 if (phba->hba_flag & HBA_AER_ENABLED) {
4657 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4659 spin_lock_irq(&phba->hbalock);
4660 phba->hba_flag &= ~HBA_AER_ENABLED;
4661 spin_unlock_irq(&phba->hbalock);
4662 phba->cfg_aer_support = 0;
4667 phba->cfg_aer_support = 0;
4672 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4673 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4675 spin_lock_irq(&phba->hbalock);
4676 phba->hba_flag |= HBA_AER_ENABLED;
4677 spin_unlock_irq(&phba->hbalock);
4678 phba->cfg_aer_support = 1;
4683 phba->cfg_aer_support = 1;
4694 static DEVICE_ATTR_RW(lpfc_aer_support);
4697 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4698 * @dev: class device that is converted into a Scsi_host.
4699 * @attr: device attribute, not used.
4700 * @buf: containing flag 1 for aer cleanup state.
4701 * @count: unused variable.
4704 * If the @buf contains 1 and the device currently has the AER support
4705 * enabled, then invokes the kernel AER helper routine
4706 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4707 * error status register.
4712 * -EINVAL if the buf does not contain the 1 or the device is not currently
4713 * enabled with the AER support.
4716 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4717 const char *buf, size_t count)
4719 struct Scsi_Host *shost = class_to_shost(dev);
4720 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4721 struct lpfc_hba *phba = vport->phba;
4724 if (!isdigit(buf[0]))
4726 if (sscanf(buf, "%i", &val) != 1)
4731 if (phba->hba_flag & HBA_AER_ENABLED)
4732 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4740 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4741 lpfc_aer_cleanup_state);
4744 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4746 * @dev: class device that is converted into a Scsi_host.
4747 * @attr: device attribute, not used.
4748 * @buf: containing the string the number of vfs to be enabled.
4749 * @count: unused variable.
4752 * When this api is called either through user sysfs, the driver shall
4753 * try to enable or disable SR-IOV virtual functions according to the
4756 * If zero virtual function has been enabled to the physical function,
4757 * the driver shall invoke the pci enable virtual function api trying
4758 * to enable the virtual functions. If the nr_vfn provided is greater
4759 * than the maximum supported, the maximum virtual function number will
4760 * be used for invoking the api; otherwise, the nr_vfn provided shall
4761 * be used for invoking the api. If the api call returned success, the
4762 * actual number of virtual functions enabled will be set to the driver
4763 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4764 * cfg_sriov_nr_virtfn remains zero.
4766 * If none-zero virtual functions have already been enabled to the
4767 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4768 * -EINVAL will be returned and the driver does nothing;
4770 * If the nr_vfn provided is zero and none-zero virtual functions have
4771 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4772 * disabling virtual function api shall be invoded to disable all the
4773 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4774 * zero. Otherwise, if zero virtual function has been enabled, do
4778 * length of the buf on success if val is in range the intended mode
4780 * -EINVAL if val out of range or intended mode is not supported.
4783 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4784 const char *buf, size_t count)
4786 struct Scsi_Host *shost = class_to_shost(dev);
4787 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4788 struct lpfc_hba *phba = vport->phba;
4789 struct pci_dev *pdev = phba->pcidev;
4790 int val = 0, rc = -EINVAL;
4792 /* Sanity check on user data */
4793 if (!isdigit(buf[0]))
4795 if (sscanf(buf, "%i", &val) != 1)
4800 /* Request disabling virtual functions */
4802 if (phba->cfg_sriov_nr_virtfn > 0) {
4803 pci_disable_sriov(pdev);
4804 phba->cfg_sriov_nr_virtfn = 0;
4809 /* Request enabling virtual functions */
4810 if (phba->cfg_sriov_nr_virtfn > 0) {
4811 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4812 "3018 There are %d virtual functions "
4813 "enabled on physical function.\n",
4814 phba->cfg_sriov_nr_virtfn);
4818 if (val <= LPFC_MAX_VFN_PER_PFN)
4819 phba->cfg_sriov_nr_virtfn = val;
4821 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4822 "3019 Enabling %d virtual functions is not "
4827 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4829 phba->cfg_sriov_nr_virtfn = 0;
4837 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4838 "Enable PCIe device SR-IOV virtual fn");
4840 lpfc_param_show(sriov_nr_virtfn)
4841 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4844 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4846 * @dev: class device that is converted into a Scsi_host.
4847 * @attr: device attribute, not used.
4848 * @buf: containing the string the number of vfs to be enabled.
4849 * @count: unused variable.
4854 * length of the buf on success if val is in range the intended mode
4856 * -EINVAL if val out of range or intended mode is not supported.
4859 lpfc_request_firmware_upgrade_store(struct device *dev,
4860 struct device_attribute *attr,
4861 const char *buf, size_t count)
4863 struct Scsi_Host *shost = class_to_shost(dev);
4864 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4865 struct lpfc_hba *phba = vport->phba;
4866 int val = 0, rc = -EINVAL;
4868 /* Sanity check on user data */
4869 if (!isdigit(buf[0]))
4871 if (sscanf(buf, "%i", &val) != 1)
4876 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4884 static int lpfc_req_fw_upgrade;
4885 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4886 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4887 lpfc_param_show(request_firmware_upgrade)
4890 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4891 * @phba: lpfc_hba pointer.
4895 * Set the initial Linux generic firmware upgrade enable or disable flag.
4898 * zero if val saved.
4899 * -EINVAL val out of range
4902 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4904 if (val >= 0 && val <= 1) {
4905 phba->cfg_request_firmware_upgrade = val;
4910 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4911 lpfc_request_firmware_upgrade_show,
4912 lpfc_request_firmware_upgrade_store);
4915 * lpfc_fcp_imax_store
4917 * @dev: class device that is converted into a Scsi_host.
4918 * @attr: device attribute, not used.
4919 * @buf: string with the number of fast-path FCP interrupts per second.
4920 * @count: unused variable.
4923 * If val is in a valid range [636,651042], then set the adapter's
4924 * maximum number of fast-path FCP interrupts per second.
4927 * length of the buf on success if val is in range the intended mode
4929 * -EINVAL if val out of range or intended mode is not supported.
4932 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4933 const char *buf, size_t count)
4935 struct Scsi_Host *shost = class_to_shost(dev);
4936 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4937 struct lpfc_hba *phba = vport->phba;
4938 struct lpfc_eq_intr_info *eqi;
4942 /* fcp_imax is only valid for SLI4 */
4943 if (phba->sli_rev != LPFC_SLI_REV4)
4946 /* Sanity check on user data */
4947 if (!isdigit(buf[0]))
4949 if (sscanf(buf, "%i", &val) != 1)
4953 * Value range for the HBA is [5000,5000000]
4954 * The value for each EQ depends on how many EQs are configured.
4957 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4960 phba->cfg_auto_imax = (val) ? 0 : 1;
4961 if (phba->cfg_fcp_imax && !val) {
4962 queue_delayed_work(phba->wq, &phba->eq_delay_work,
4963 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
4965 for_each_present_cpu(i) {
4966 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
4971 phba->cfg_fcp_imax = (uint32_t)val;
4973 if (phba->cfg_fcp_imax)
4974 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
4978 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4979 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4986 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4989 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4991 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4992 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4993 MODULE_PARM_DESC(lpfc_fcp_imax,
4994 "Set the maximum number of FCP interrupts per second per HBA");
4995 lpfc_param_show(fcp_imax)
4998 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4999 * @phba: lpfc_hba pointer.
5000 * @val: link speed value.
5003 * If val is in a valid range [636,651042], then initialize the adapter's
5004 * maximum number of fast-path FCP interrupts per second.
5007 * zero if val saved.
5008 * -EINVAL val out of range
5011 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
5013 if (phba->sli_rev != LPFC_SLI_REV4) {
5014 phba->cfg_fcp_imax = 0;
5018 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
5020 phba->cfg_fcp_imax = val;
5024 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5025 "3016 lpfc_fcp_imax: %d out of range, using default\n",
5027 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
5032 static DEVICE_ATTR_RW(lpfc_fcp_imax);
5035 * lpfc_cq_max_proc_limit_store
5037 * @dev: class device that is converted into a Scsi_host.
5038 * @attr: device attribute, not used.
5039 * @buf: string with the cq max processing limit of cqes
5040 * @count: unused variable.
5043 * If val is in a valid range, then set value on each cq
5046 * The length of the buf: if successful
5047 * -ERANGE: if val is not in the valid range
5048 * -EINVAL: if bad value format or intended mode is not supported.
5051 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
5052 const char *buf, size_t count)
5054 struct Scsi_Host *shost = class_to_shost(dev);
5055 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5056 struct lpfc_hba *phba = vport->phba;
5057 struct lpfc_queue *eq, *cq;
5061 /* cq_max_proc_limit is only valid for SLI4 */
5062 if (phba->sli_rev != LPFC_SLI_REV4)
5065 /* Sanity check on user data */
5066 if (!isdigit(buf[0]))
5068 if (kstrtoul(buf, 0, &val))
5071 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
5074 phba->cfg_cq_max_proc_limit = (uint32_t)val;
5076 /* set the values on the cq's */
5077 for (i = 0; i < phba->cfg_irq_chann; i++) {
5078 eq = phba->sli4_hba.hdwq[i].hba_eq;
5082 list_for_each_entry(cq, &eq->child_list, list)
5083 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
5091 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
5092 * itteration of CQ processing.
5094 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5095 module_param(lpfc_cq_max_proc_limit, int, 0644);
5096 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
5097 "Set the maximum number CQEs processed in an iteration of "
5099 lpfc_param_show(cq_max_proc_limit)
5102 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
5103 * single handler call which should request a polled completion rather
5104 * than re-enabling interrupts.
5106 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
5107 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
5108 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
5109 "CQE Processing Threshold to enable Polling");
5112 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
5113 * @phba: lpfc_hba pointer.
5117 * If val is in a valid range, then initialize the adapter's maximum
5121 * Always returns 0 for success, even if value not always set to
5122 * requested value. If value out of range or not supported, will fall
5126 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
5128 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5130 if (phba->sli_rev != LPFC_SLI_REV4)
5133 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
5134 phba->cfg_cq_max_proc_limit = val;
5138 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5139 "0371 "LPFC_DRIVER_NAME"_cq_max_proc_limit: "
5140 "%d out of range, using default\n",
5141 phba->cfg_cq_max_proc_limit);
5146 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
5149 * lpfc_state_show - Display current driver CPU affinity
5150 * @dev: class converted to a Scsi_host structure.
5151 * @attr: device attribute, not used.
5152 * @buf: on return contains text describing the state of the link.
5154 * Returns: size of formatted string.
5157 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5160 struct Scsi_Host *shost = class_to_shost(dev);
5161 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5162 struct lpfc_hba *phba = vport->phba;
5163 struct lpfc_vector_map_info *cpup;
5166 if ((phba->sli_rev != LPFC_SLI_REV4) ||
5167 (phba->intr_type != MSIX))
5170 switch (phba->cfg_fcp_cpu_map) {
5172 len += snprintf(buf + len, PAGE_SIZE-len,
5173 "fcp_cpu_map: No mapping (%d)\n",
5174 phba->cfg_fcp_cpu_map);
5177 len += snprintf(buf + len, PAGE_SIZE-len,
5178 "fcp_cpu_map: HBA centric mapping (%d): "
5179 "%d of %d CPUs online from %d possible CPUs\n",
5180 phba->cfg_fcp_cpu_map, num_online_cpus(),
5182 phba->sli4_hba.num_possible_cpu);
5186 while (phba->sli4_hba.curr_disp_cpu <
5187 phba->sli4_hba.num_possible_cpu) {
5188 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5190 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5191 len += snprintf(buf + len, PAGE_SIZE - len,
5192 "CPU %02d not present\n",
5193 phba->sli4_hba.curr_disp_cpu);
5194 else if (cpup->irq == LPFC_VECTOR_MAP_EMPTY) {
5195 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5197 buf + len, PAGE_SIZE - len,
5198 "CPU %02d hdwq None "
5199 "physid %d coreid %d ht %d\n",
5200 phba->sli4_hba.curr_disp_cpu,
5202 cpup->core_id, cpup->hyper);
5205 buf + len, PAGE_SIZE - len,
5206 "CPU %02d EQ %04d hdwq %04d "
5207 "physid %d coreid %d ht %d\n",
5208 phba->sli4_hba.curr_disp_cpu,
5209 cpup->eq, cpup->hdwq, cpup->phys_id,
5210 cpup->core_id, cpup->hyper);
5212 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5214 buf + len, PAGE_SIZE - len,
5215 "CPU %02d hdwq None "
5216 "physid %d coreid %d ht %d IRQ %d\n",
5217 phba->sli4_hba.curr_disp_cpu,
5219 cpup->core_id, cpup->hyper, cpup->irq);
5222 buf + len, PAGE_SIZE - len,
5223 "CPU %02d EQ %04d hdwq %04d "
5224 "physid %d coreid %d ht %d IRQ %d\n",
5225 phba->sli4_hba.curr_disp_cpu,
5226 cpup->eq, cpup->hdwq, cpup->phys_id,
5227 cpup->core_id, cpup->hyper, cpup->irq);
5230 phba->sli4_hba.curr_disp_cpu++;
5232 /* display max number of CPUs keeping some margin */
5233 if (phba->sli4_hba.curr_disp_cpu <
5234 phba->sli4_hba.num_possible_cpu &&
5235 (len >= (PAGE_SIZE - 64))) {
5236 len += snprintf(buf + len,
5237 PAGE_SIZE - len, "more...\n");
5242 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
5243 phba->sli4_hba.curr_disp_cpu = 0;
5249 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5250 * @dev: class device that is converted into a Scsi_host.
5251 * @attr: device attribute, not used.
5252 * @buf: one or more lpfc_polling_flags values.
5256 * -EINVAL - Not implemented yet.
5259 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5260 const char *buf, size_t count)
5262 int status = -EINVAL;
5267 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5270 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5271 # 0 - Do not affinitze IRQ vectors
5272 # 1 - Affintize HBA vectors with respect to each HBA
5273 # (start with CPU0 for each HBA)
5274 # This also defines how Hardware Queues are mapped to specific CPUs.
5276 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5277 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5278 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5279 "Defines how to map CPUs to IRQ vectors per HBA");
5282 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5283 * @phba: lpfc_hba pointer.
5284 * @val: link speed value.
5287 * If val is in a valid range [0-2], then affinitze the adapter's
5291 * zero if val saved.
5292 * -EINVAL val out of range
5295 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5297 if (phba->sli_rev != LPFC_SLI_REV4) {
5298 phba->cfg_fcp_cpu_map = 0;
5302 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5303 phba->cfg_fcp_cpu_map = val;
5307 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5308 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5310 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5315 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5318 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5319 # Value range is [2,3]. Default value is 3.
5321 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5322 "Select Fibre Channel class of service for FCP sequences");
5325 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5326 # is [0,1]. Default value is 0.
5328 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
5329 "Use ADISC on rediscovery to authenticate FCP devices");
5332 # lpfc_first_burst_size: First burst size to use on the NPorts
5333 # that support first burst.
5334 # Value range is [0,65536]. Default value is 0.
5336 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5337 "First burst size for Targets that support first burst");
5340 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5341 * When the driver is configured as an NVME target, this value is
5342 * communicated to the NVME initiator in the PRLI response. It is
5343 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5344 * parameters are set and the target is sending the PRLI RSP.
5345 * Parameter supported on physical port only - no NPIV support.
5346 * Value range is [0,65536]. Default value is 0.
5348 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5349 "NVME Target mode first burst size in 512B increments.");
5352 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5353 * For the Initiator (I), enabling this parameter means that an NVMET
5354 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5355 * processed by the initiator for subsequent NVME FCP IO. For the target
5356 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
5357 * driver parameter as the target function's first burst size returned to the
5358 * initiator in the target's NVME PRLI response. Parameter supported on physical
5359 * port only - no NPIV support.
5360 * Value range is [0,1]. Default value is 0 (disabled).
5362 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5363 "Enable First Burst feature on I and T functions.");
5366 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5367 # depth. Default value is 0. When the value of this parameter is zero the
5368 # SCSI command completion time is not used for controlling I/O queue depth. When
5369 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5370 # to limit the I/O completion time to the parameter value.
5371 # The value is set in milliseconds.
5373 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5374 "Use command completion time to control queue depth");
5376 lpfc_vport_param_show(max_scsicmpl_time);
5378 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5381 struct lpfc_nodelist *ndlp, *next_ndlp;
5383 if (val == vport->cfg_max_scsicmpl_time)
5385 if ((val < 0) || (val > 60000))
5387 vport->cfg_max_scsicmpl_time = val;
5389 spin_lock_irq(shost->host_lock);
5390 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5391 if (!NLP_CHK_NODE_ACT(ndlp))
5393 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5395 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5397 spin_unlock_irq(shost->host_lock);
5400 lpfc_vport_param_store(max_scsicmpl_time);
5401 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5404 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5405 # range is [0,1]. Default value is 0.
5407 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5410 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5411 # range is [0,1]. Default value is 1.
5413 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5416 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5417 * range is [0,1]. Default value is 0.
5418 * For [0], FCP commands are issued to Work Queues based on upper layer
5419 * hardware queue index.
5420 * For [1], FCP commands are issued to a Work Queue associated with the
5423 * LPFC_FCP_SCHED_BY_HDWQ == 0
5424 * LPFC_FCP_SCHED_BY_CPU == 1
5426 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5427 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5428 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5429 * through WQs will be used.
5431 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5432 LPFC_FCP_SCHED_BY_HDWQ,
5433 LPFC_FCP_SCHED_BY_CPU,
5434 "Determine scheduling algorithm for "
5435 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5438 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5439 * range is [0,1]. Default value is 0.
5440 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5441 * For [1], GID_PT is used for NameServer queries after RSCN
5444 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5445 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5446 "Determine algorithm NameServer queries after RSCN "
5447 "[0] - GID_FT, [1] - GID_PT");
5450 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5451 # range is [0,1]. Default value is 0.
5452 # For [0], bus reset issues target reset to ALL devices
5453 # For [1], bus reset issues target reset to non-FCP2 devices
5455 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5456 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5460 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5461 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5462 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5463 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5464 # cr_delay is set to 0.
5466 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5467 "interrupt response is generated");
5469 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5470 "interrupt response is generated");
5473 # lpfc_multi_ring_support: Determines how many rings to spread available
5474 # cmd/rsp IOCB entries across.
5475 # Value range is [1,2]. Default value is 1.
5477 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5478 "SLI rings to spread IOCB entries across");
5481 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5482 # identifies what rctl value to configure the additional ring for.
5483 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5485 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5486 255, "Identifies RCTL for additional ring configuration");
5489 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5490 # identifies what type value to configure the additional ring for.
5491 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5493 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5494 255, "Identifies TYPE for additional ring configuration");
5497 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5498 # 0 = SmartSAN functionality disabled (default)
5499 # 1 = SmartSAN functionality enabled
5500 # This parameter will override the value of lpfc_fdmi_on module parameter.
5501 # Value range is [0,1]. Default value is 0.
5503 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5506 # lpfc_fdmi_on: Controls FDMI support.
5508 # 1 Traditional FDMI support (default)
5509 # Traditional FDMI support means the driver will assume FDMI-2 support;
5510 # however, if that fails, it will fallback to FDMI-1.
5511 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5512 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5514 # Value range [0,1]. Default value is 1.
5516 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5519 # Specifies the maximum number of ELS cmds we can have outstanding (for
5520 # discovery). Value range is [1,64]. Default value = 32.
5522 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5523 "during discovery");
5526 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5527 # will be scanned by the SCSI midlayer when sequential scanning is
5528 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5529 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5530 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5531 # above. The lpfc driver limits the default value to 255 for two reasons.
5532 # As it bounds the sequential scan loop, scanning for thousands of luns
5533 # on a target can take minutes of wall clock time. Additionally,
5534 # there are FC targets, such as JBODs, that only recognize 8-bits of
5535 # LUN ID. When they receive a value greater than 8 bits, they chop off
5536 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5537 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5538 # valid responses at each of the LUN IDs, to believe there are multiple
5539 # devices present, when in fact, there is only 1.
5540 # A customer that is aware of their target behaviors, and the results as
5541 # indicated above, is welcome to increase the lpfc_max_luns value.
5542 # As mentioned, this value is not used by the lpfc driver, only the
5544 # Value range is [0,65535]. Default value is 255.
5545 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5547 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5550 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5551 # Value range is [1,255], default value is 10.
5553 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5554 "Milliseconds driver will wait between polling FCP ring");
5557 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5558 # to complete in seconds. Value range is [5,180], default value is 60.
5560 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5561 "Maximum time to wait for task management commands to complete");
5563 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5564 # support this feature
5567 # 2 = MSI-X enabled (default)
5568 # Value range is [0,2]. Default value is 2.
5570 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5571 "MSI-X (2), if possible");
5574 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5576 * 0 = NVME OAS disabled
5577 * 1 = NVME OAS enabled
5579 * Value range is [0,1]. Default value is 0.
5581 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5582 "Use OAS bit on NVME IOs");
5585 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5587 * 0 = Put NVME Command in SGL
5588 * 1 = Embed NVME Command in WQE (unless G7)
5589 * 2 = Embed NVME Command in WQE (force)
5591 * Value range is [0,2]. Default value is 1.
5593 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5594 "Embed NVME Command in WQE");
5597 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5598 * will advertise it supports to the NVME and SCSI layers. This also
5599 * will map to the number of CQ/WQ pairs the driver will create.
5601 * The NVME Layer will try to create this many, plus 1 administrative
5602 * hardware queue. The administrative queue will always map to WQ 0
5603 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5605 * 0 = Configure the number of hdw queues to the number of active CPUs.
5606 * 1,128 = Manually specify how many hdw queues to use.
5608 * Value range is [0,128]. Default value is 0.
5610 LPFC_ATTR_R(hdw_queue,
5612 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5613 "Set the number of I/O Hardware Queues");
5616 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5617 * for Hardware Queues to utilize. This also will map to the number
5618 * of EQ / MSI-X vectors the driver will create. This should never be
5619 * more than the number of Hardware Queues
5621 * 0 = Configure number of IRQ Channels to the number of active CPUs.
5622 * 1,128 = Manually specify how many IRQ Channels to use.
5624 * Value range is [0,128]. Default value is 0.
5626 LPFC_ATTR_R(irq_chann,
5628 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5629 "Set the number of I/O IRQ Channels");
5632 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5633 # 0 = HBA resets disabled
5634 # 1 = HBA resets enabled (default)
5635 # 2 = HBA reset via PCI bus reset enabled
5636 # Value range is [0,2]. Default value is 1.
5638 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5641 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5642 # 0 = HBA Heartbeat disabled
5643 # 1 = HBA Heartbeat enabled (default)
5644 # Value range is [0,1]. Default value is 1.
5646 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5649 # lpfc_EnableXLane: Enable Express Lane Feature
5650 # 0x0 Express Lane Feature disabled
5651 # 0x1 Express Lane Feature enabled
5652 # Value range is [0,1]. Default value is 0.
5654 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5657 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5658 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5659 # Value range is [0x0,0x7f]. Default value is 0
5661 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5664 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5665 # 0 = BlockGuard disabled (default)
5666 # 1 = BlockGuard enabled
5667 # Value range is [0,1]. Default value is 0.
5669 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5673 # - Bit mask of host protection capabilities used to register with the
5675 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5676 # - Allows you to ultimately specify which profiles to use
5677 # - Default will result in registering capabilities for all profiles.
5678 # - SHOST_DIF_TYPE1_PROTECTION 1
5679 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5680 # - SHOST_DIX_TYPE0_PROTECTION 8
5681 # HBA supports DIX Type 0: Host to HBA protection only
5682 # - SHOST_DIX_TYPE1_PROTECTION 16
5683 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5686 LPFC_ATTR(prot_mask,
5687 (SHOST_DIF_TYPE1_PROTECTION |
5688 SHOST_DIX_TYPE0_PROTECTION |
5689 SHOST_DIX_TYPE1_PROTECTION),
5691 (SHOST_DIF_TYPE1_PROTECTION |
5692 SHOST_DIX_TYPE0_PROTECTION |
5693 SHOST_DIX_TYPE1_PROTECTION),
5694 "T10-DIF host protection capabilities mask");
5697 # lpfc_prot_guard: i
5698 # - Bit mask of protection guard types to register with the SCSI mid-layer
5699 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5700 # - Allows you to ultimately specify which profiles to use
5701 # - Default will result in registering capabilities for all guard types
5704 LPFC_ATTR(prot_guard,
5705 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5706 "T10-DIF host protection guard type");
5709 * Delay initial NPort discovery when Clean Address bit is cleared in
5710 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5711 * This parameter can have value 0 or 1.
5712 * When this parameter is set to 0, no delay is added to the initial
5714 * When this parameter is set to non-zero value, initial Nport discovery is
5715 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5716 * accept and FCID/Fabric name/Fabric portname is changed.
5717 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5718 * when Clean Address bit is cleared in FLOGI/FDISC
5719 * accept and FCID/Fabric name/Fabric portname is changed.
5720 * Default value is 0.
5722 LPFC_ATTR(delay_discovery, 0, 0, 1,
5723 "Delay NPort discovery when Clean Address bit is cleared.");
5726 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5727 * This value can be set to values between 64 and 4096. The default value
5728 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5729 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5730 * Because of the additional overhead involved in setting up T10-DIF,
5731 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5732 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5734 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5735 module_param(lpfc_sg_seg_cnt, uint, 0444);
5736 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5739 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5740 * configured for the adapter
5741 * @dev: class converted to a Scsi_host structure.
5742 * @attr: device attribute, not used.
5743 * @buf: on return contains a string with the list sizes
5745 * Returns: size of formatted string.
5748 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5751 struct Scsi_Host *shost = class_to_shost(dev);
5752 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5753 struct lpfc_hba *phba = vport->phba;
5756 len = snprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
5757 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5759 len += snprintf(buf + len, PAGE_SIZE, "Cfg: %d SCSI: %d NVME: %d\n",
5760 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5761 phba->cfg_nvme_seg_cnt);
5765 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5768 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5769 * @phba: lpfc_hba pointer.
5770 * @val: contains the initial value
5773 * Validates the initial value is within range and assigns it to the
5774 * adapter. If not in range, an error message is posted and the
5775 * default value is assigned.
5778 * zero if value is in range and is set
5779 * -EINVAL if value was out of range
5782 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5784 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5785 phba->cfg_sg_seg_cnt = val;
5788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5789 "0409 "LPFC_DRIVER_NAME"_sg_seg_cnt attribute cannot "
5790 "be set to %d, allowed range is [%d, %d]\n",
5791 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5792 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5797 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5798 * 0 = MDS Diagnostics disabled (default)
5799 * 1 = MDS Diagnostics enabled
5800 * Value range is [0,1]. Default value is 0.
5802 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5805 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5806 * 0 = Disable firmware logging (default)
5807 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
5808 * Value range [0..4]. Default value is 0
5810 LPFC_ATTR_RW(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5813 * lpfc_ras_fwlog_level: Firmware logging verbosity level
5814 * Valid only if firmware logging is enabled
5815 * 0(Least Verbosity) 4 (most verbosity)
5816 * Value range is [0..4]. Default value is 0
5818 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5821 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5822 * Default function which has RAS support : 0
5823 * Value Range is [0..7].
5824 * FW logging is a global action and enablement is via a specific
5827 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
5830 * lpfc_enable_bbcr: Enable BB Credit Recovery
5831 * 0 = BB Credit Recovery disabled
5832 * 1 = BB Credit Recovery enabled (default)
5833 * Value range is [0,1]. Default value is 1.
5835 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5838 * lpfc_enable_dpp: Enable DPP on G7
5839 * 0 = DPP on G7 disabled
5840 * 1 = DPP on G7 enabled (default)
5841 * Value range is [0,1]. Default value is 1.
5843 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5845 struct device_attribute *lpfc_hba_attrs[] = {
5846 &dev_attr_nvme_info,
5847 &dev_attr_scsi_stat,
5849 &dev_attr_bg_guard_err,
5850 &dev_attr_bg_apptag_err,
5851 &dev_attr_bg_reftag_err,
5853 &dev_attr_serialnum,
5854 &dev_attr_modeldesc,
5855 &dev_attr_modelname,
5856 &dev_attr_programtype,
5860 &dev_attr_option_rom_version,
5861 &dev_attr_link_state,
5862 &dev_attr_num_discovered_ports,
5863 &dev_attr_menlo_mgmt_mode,
5864 &dev_attr_lpfc_drvr_version,
5865 &dev_attr_lpfc_enable_fip,
5866 &dev_attr_lpfc_temp_sensor,
5867 &dev_attr_lpfc_log_verbose,
5868 &dev_attr_lpfc_lun_queue_depth,
5869 &dev_attr_lpfc_tgt_queue_depth,
5870 &dev_attr_lpfc_hba_queue_depth,
5871 &dev_attr_lpfc_peer_port_login,
5872 &dev_attr_lpfc_nodev_tmo,
5873 &dev_attr_lpfc_devloss_tmo,
5874 &dev_attr_lpfc_enable_fc4_type,
5875 &dev_attr_lpfc_fcp_class,
5876 &dev_attr_lpfc_use_adisc,
5877 &dev_attr_lpfc_first_burst_size,
5878 &dev_attr_lpfc_ack0,
5879 &dev_attr_lpfc_xri_rebalancing,
5880 &dev_attr_lpfc_topology,
5881 &dev_attr_lpfc_scan_down,
5882 &dev_attr_lpfc_link_speed,
5883 &dev_attr_lpfc_fcp_io_sched,
5884 &dev_attr_lpfc_ns_query,
5885 &dev_attr_lpfc_fcp2_no_tgt_reset,
5886 &dev_attr_lpfc_cr_delay,
5887 &dev_attr_lpfc_cr_count,
5888 &dev_attr_lpfc_multi_ring_support,
5889 &dev_attr_lpfc_multi_ring_rctl,
5890 &dev_attr_lpfc_multi_ring_type,
5891 &dev_attr_lpfc_fdmi_on,
5892 &dev_attr_lpfc_enable_SmartSAN,
5893 &dev_attr_lpfc_max_luns,
5894 &dev_attr_lpfc_enable_npiv,
5895 &dev_attr_lpfc_fcf_failover_policy,
5896 &dev_attr_lpfc_enable_rrq,
5897 &dev_attr_nport_evt_cnt,
5898 &dev_attr_board_mode,
5905 &dev_attr_npiv_info,
5906 &dev_attr_issue_reset,
5907 &dev_attr_lpfc_poll,
5908 &dev_attr_lpfc_poll_tmo,
5909 &dev_attr_lpfc_task_mgmt_tmo,
5910 &dev_attr_lpfc_use_msi,
5911 &dev_attr_lpfc_nvme_oas,
5912 &dev_attr_lpfc_nvme_embed_cmd,
5913 &dev_attr_lpfc_fcp_imax,
5914 &dev_attr_lpfc_cq_poll_threshold,
5915 &dev_attr_lpfc_cq_max_proc_limit,
5916 &dev_attr_lpfc_fcp_cpu_map,
5917 &dev_attr_lpfc_hdw_queue,
5918 &dev_attr_lpfc_irq_chann,
5919 &dev_attr_lpfc_suppress_rsp,
5920 &dev_attr_lpfc_nvmet_mrq,
5921 &dev_attr_lpfc_nvmet_mrq_post,
5922 &dev_attr_lpfc_nvme_enable_fb,
5923 &dev_attr_lpfc_nvmet_fb_size,
5924 &dev_attr_lpfc_enable_bg,
5925 &dev_attr_lpfc_soft_wwnn,
5926 &dev_attr_lpfc_soft_wwpn,
5927 &dev_attr_lpfc_soft_wwn_enable,
5928 &dev_attr_lpfc_enable_hba_reset,
5929 &dev_attr_lpfc_enable_hba_heartbeat,
5930 &dev_attr_lpfc_EnableXLane,
5931 &dev_attr_lpfc_XLanePriority,
5932 &dev_attr_lpfc_xlane_lun,
5933 &dev_attr_lpfc_xlane_tgt,
5934 &dev_attr_lpfc_xlane_vpt,
5935 &dev_attr_lpfc_xlane_lun_state,
5936 &dev_attr_lpfc_xlane_lun_status,
5937 &dev_attr_lpfc_xlane_priority,
5938 &dev_attr_lpfc_sg_seg_cnt,
5939 &dev_attr_lpfc_max_scsicmpl_time,
5940 &dev_attr_lpfc_stat_data_ctrl,
5941 &dev_attr_lpfc_aer_support,
5942 &dev_attr_lpfc_aer_state_cleanup,
5943 &dev_attr_lpfc_sriov_nr_virtfn,
5944 &dev_attr_lpfc_req_fw_upgrade,
5945 &dev_attr_lpfc_suppress_link_up,
5946 &dev_attr_lpfc_iocb_cnt,
5949 &dev_attr_txcmplq_hw,
5950 &dev_attr_lpfc_fips_level,
5951 &dev_attr_lpfc_fips_rev,
5953 &dev_attr_lpfc_sriov_hw_max_virtfn,
5955 &dev_attr_lpfc_xlane_supported,
5956 &dev_attr_lpfc_enable_mds_diags,
5957 &dev_attr_lpfc_ras_fwlog_buffsize,
5958 &dev_attr_lpfc_ras_fwlog_level,
5959 &dev_attr_lpfc_ras_fwlog_func,
5960 &dev_attr_lpfc_enable_bbcr,
5961 &dev_attr_lpfc_enable_dpp,
5965 struct device_attribute *lpfc_vport_attrs[] = {
5967 &dev_attr_link_state,
5968 &dev_attr_num_discovered_ports,
5969 &dev_attr_lpfc_drvr_version,
5970 &dev_attr_lpfc_log_verbose,
5971 &dev_attr_lpfc_lun_queue_depth,
5972 &dev_attr_lpfc_tgt_queue_depth,
5973 &dev_attr_lpfc_nodev_tmo,
5974 &dev_attr_lpfc_devloss_tmo,
5975 &dev_attr_lpfc_hba_queue_depth,
5976 &dev_attr_lpfc_peer_port_login,
5977 &dev_attr_lpfc_restrict_login,
5978 &dev_attr_lpfc_fcp_class,
5979 &dev_attr_lpfc_use_adisc,
5980 &dev_attr_lpfc_first_burst_size,
5981 &dev_attr_lpfc_max_luns,
5982 &dev_attr_nport_evt_cnt,
5983 &dev_attr_npiv_info,
5984 &dev_attr_lpfc_enable_da_id,
5985 &dev_attr_lpfc_max_scsicmpl_time,
5986 &dev_attr_lpfc_stat_data_ctrl,
5987 &dev_attr_lpfc_static_vport,
5988 &dev_attr_lpfc_fips_level,
5989 &dev_attr_lpfc_fips_rev,
5994 * sysfs_ctlreg_write - Write method for writing to ctlreg
5995 * @filp: open sysfs file
5996 * @kobj: kernel kobject that contains the kernel class device.
5997 * @bin_attr: kernel attributes passed to us.
5998 * @buf: contains the data to be written to the adapter IOREG space.
5999 * @off: offset into buffer to beginning of data.
6000 * @count: bytes to transfer.
6003 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6004 * Uses the adapter io control registers to send buf contents to the adapter.
6007 * -ERANGE off and count combo out of range
6008 * -EINVAL off, count or buff address invalid
6009 * -EPERM adapter is offline
6010 * value of count, buf contents written
6013 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6014 struct bin_attribute *bin_attr,
6015 char *buf, loff_t off, size_t count)
6018 struct device *dev = container_of(kobj, struct device, kobj);
6019 struct Scsi_Host *shost = class_to_shost(dev);
6020 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6021 struct lpfc_hba *phba = vport->phba;
6023 if (phba->sli_rev >= LPFC_SLI_REV4)
6026 if ((off + count) > FF_REG_AREA_SIZE)
6029 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6032 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6035 /* This is to protect HBA registers from accidental writes. */
6036 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6039 if (!(vport->fc_flag & FC_OFFLINE_MODE))
6042 spin_lock_irq(&phba->hbalock);
6043 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6044 buf_off += sizeof(uint32_t))
6045 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6046 phba->ctrl_regs_memmap_p + off + buf_off);
6048 spin_unlock_irq(&phba->hbalock);
6054 * sysfs_ctlreg_read - Read method for reading from ctlreg
6055 * @filp: open sysfs file
6056 * @kobj: kernel kobject that contains the kernel class device.
6057 * @bin_attr: kernel attributes passed to us.
6058 * @buf: if successful contains the data from the adapter IOREG space.
6059 * @off: offset into buffer to beginning of data.
6060 * @count: bytes to transfer.
6063 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6064 * Uses the adapter io control registers to read data into buf.
6067 * -ERANGE off and count combo out of range
6068 * -EINVAL off, count or buff address invalid
6069 * value of count, buf contents read
6072 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6073 struct bin_attribute *bin_attr,
6074 char *buf, loff_t off, size_t count)
6078 struct device *dev = container_of(kobj, struct device, kobj);
6079 struct Scsi_Host *shost = class_to_shost(dev);
6080 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6081 struct lpfc_hba *phba = vport->phba;
6083 if (phba->sli_rev >= LPFC_SLI_REV4)
6086 if (off > FF_REG_AREA_SIZE)
6089 if ((off + count) > FF_REG_AREA_SIZE)
6090 count = FF_REG_AREA_SIZE - off;
6092 if (count == 0) return 0;
6094 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6097 spin_lock_irq(&phba->hbalock);
6099 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6100 tmp_ptr = (uint32_t *)(buf + buf_off);
6101 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6104 spin_unlock_irq(&phba->hbalock);
6109 static struct bin_attribute sysfs_ctlreg_attr = {
6112 .mode = S_IRUSR | S_IWUSR,
6115 .read = sysfs_ctlreg_read,
6116 .write = sysfs_ctlreg_write,
6120 * sysfs_mbox_write - Write method for writing information via mbox
6121 * @filp: open sysfs file
6122 * @kobj: kernel kobject that contains the kernel class device.
6123 * @bin_attr: kernel attributes passed to us.
6124 * @buf: contains the data to be written to sysfs mbox.
6125 * @off: offset into buffer to beginning of data.
6126 * @count: bytes to transfer.
6129 * Deprecated function. All mailbox access from user space is performed via the
6133 * -EPERM operation not permitted
6136 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6137 struct bin_attribute *bin_attr,
6138 char *buf, loff_t off, size_t count)
6144 * sysfs_mbox_read - Read method for reading information via mbox
6145 * @filp: open sysfs file
6146 * @kobj: kernel kobject that contains the kernel class device.
6147 * @bin_attr: kernel attributes passed to us.
6148 * @buf: contains the data to be read from sysfs mbox.
6149 * @off: offset into buffer to beginning of data.
6150 * @count: bytes to transfer.
6153 * Deprecated function. All mailbox access from user space is performed via the
6157 * -EPERM operation not permitted
6160 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6161 struct bin_attribute *bin_attr,
6162 char *buf, loff_t off, size_t count)
6167 static struct bin_attribute sysfs_mbox_attr = {
6170 .mode = S_IRUSR | S_IWUSR,
6172 .size = MAILBOX_SYSFS_MAX,
6173 .read = sysfs_mbox_read,
6174 .write = sysfs_mbox_write,
6178 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6179 * @vport: address of lpfc vport structure.
6183 * error return code from sysfs_create_bin_file()
6186 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6188 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6191 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6192 &sysfs_drvr_stat_data_attr);
6194 /* Virtual ports do not need ctrl_reg and mbox */
6195 if (error || vport->port_type == LPFC_NPIV_PORT)
6198 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6199 &sysfs_ctlreg_attr);
6201 goto out_remove_stat_attr;
6203 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6206 goto out_remove_ctlreg_attr;
6209 out_remove_ctlreg_attr:
6210 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6211 out_remove_stat_attr:
6212 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6213 &sysfs_drvr_stat_data_attr);
6219 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6220 * @vport: address of lpfc vport structure.
6223 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6225 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6226 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6227 &sysfs_drvr_stat_data_attr);
6228 /* Virtual ports do not need ctrl_reg and mbox */
6229 if (vport->port_type == LPFC_NPIV_PORT)
6231 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6232 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6236 * Dynamic FC Host Attributes Support
6240 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6241 * @shost: kernel scsi host pointer.
6244 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6246 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6248 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6249 sizeof fc_host_symbolic_name(shost));
6253 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6254 * @shost: kernel scsi host pointer.
6257 lpfc_get_host_port_id(struct Scsi_Host *shost)
6259 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6261 /* note: fc_myDID already in cpu endianness */
6262 fc_host_port_id(shost) = vport->fc_myDID;
6266 * lpfc_get_host_port_type - Set the value of the scsi host port type
6267 * @shost: kernel scsi host pointer.
6270 lpfc_get_host_port_type(struct Scsi_Host *shost)
6272 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6273 struct lpfc_hba *phba = vport->phba;
6275 spin_lock_irq(shost->host_lock);
6277 if (vport->port_type == LPFC_NPIV_PORT) {
6278 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6279 } else if (lpfc_is_link_up(phba)) {
6280 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6281 if (vport->fc_flag & FC_PUBLIC_LOOP)
6282 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6284 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6286 if (vport->fc_flag & FC_FABRIC)
6287 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6289 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6292 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6294 spin_unlock_irq(shost->host_lock);
6298 * lpfc_get_host_port_state - Set the value of the scsi host port state
6299 * @shost: kernel scsi host pointer.
6302 lpfc_get_host_port_state(struct Scsi_Host *shost)
6304 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6305 struct lpfc_hba *phba = vport->phba;
6307 spin_lock_irq(shost->host_lock);
6309 if (vport->fc_flag & FC_OFFLINE_MODE)
6310 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6312 switch (phba->link_state) {
6313 case LPFC_LINK_UNKNOWN:
6314 case LPFC_LINK_DOWN:
6315 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6319 case LPFC_HBA_READY:
6320 /* Links up, reports port state accordingly */
6321 if (vport->port_state < LPFC_VPORT_READY)
6322 fc_host_port_state(shost) =
6323 FC_PORTSTATE_BYPASSED;
6325 fc_host_port_state(shost) =
6326 FC_PORTSTATE_ONLINE;
6328 case LPFC_HBA_ERROR:
6329 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6332 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6337 spin_unlock_irq(shost->host_lock);
6341 * lpfc_get_host_speed - Set the value of the scsi host speed
6342 * @shost: kernel scsi host pointer.
6345 lpfc_get_host_speed(struct Scsi_Host *shost)
6347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6348 struct lpfc_hba *phba = vport->phba;
6350 spin_lock_irq(shost->host_lock);
6352 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
6353 switch(phba->fc_linkspeed) {
6354 case LPFC_LINK_SPEED_1GHZ:
6355 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6357 case LPFC_LINK_SPEED_2GHZ:
6358 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6360 case LPFC_LINK_SPEED_4GHZ:
6361 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6363 case LPFC_LINK_SPEED_8GHZ:
6364 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6366 case LPFC_LINK_SPEED_10GHZ:
6367 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6369 case LPFC_LINK_SPEED_16GHZ:
6370 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6372 case LPFC_LINK_SPEED_32GHZ:
6373 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6375 case LPFC_LINK_SPEED_64GHZ:
6376 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6378 case LPFC_LINK_SPEED_128GHZ:
6379 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6382 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6385 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6386 switch (phba->fc_linkspeed) {
6387 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6388 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6390 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6391 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6393 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6394 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6396 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6397 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6400 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6404 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6406 spin_unlock_irq(shost->host_lock);
6410 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6411 * @shost: kernel scsi host pointer.
6414 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6417 struct lpfc_hba *phba = vport->phba;
6420 spin_lock_irq(shost->host_lock);
6422 if ((vport->port_state > LPFC_FLOGI) &&
6423 ((vport->fc_flag & FC_FABRIC) ||
6424 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6425 (vport->fc_flag & FC_PUBLIC_LOOP))))
6426 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6428 /* fabric is local port if there is no F/FL_Port */
6431 spin_unlock_irq(shost->host_lock);
6433 fc_host_fabric_name(shost) = node_name;
6437 * lpfc_get_stats - Return statistical information about the adapter
6438 * @shost: kernel scsi host pointer.
6441 * NULL on error for link down, no mbox pool, sli2 active,
6442 * management not allowed, memory allocation error, or mbox error.
6446 * address of the adapter host statistics
6448 static struct fc_host_statistics *
6449 lpfc_get_stats(struct Scsi_Host *shost)
6451 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6452 struct lpfc_hba *phba = vport->phba;
6453 struct lpfc_sli *psli = &phba->sli;
6454 struct fc_host_statistics *hs = &phba->link_stats;
6455 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6456 LPFC_MBOXQ_t *pmboxq;
6461 * prevent udev from issuing mailbox commands until the port is
6464 if (phba->link_state < LPFC_LINK_DOWN ||
6465 !phba->mbox_mem_pool ||
6466 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6469 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6472 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6475 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6477 pmb = &pmboxq->u.mb;
6478 pmb->mbxCommand = MBX_READ_STATUS;
6479 pmb->mbxOwner = OWN_HOST;
6480 pmboxq->ctx_buf = NULL;
6481 pmboxq->vport = vport;
6483 if (vport->fc_flag & FC_OFFLINE_MODE)
6484 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6486 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6488 if (rc != MBX_SUCCESS) {
6489 if (rc != MBX_TIMEOUT)
6490 mempool_free(pmboxq, phba->mbox_mem_pool);
6494 memset(hs, 0, sizeof (struct fc_host_statistics));
6496 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6498 * The MBX_READ_STATUS returns tx_k_bytes which has to
6499 * converted to words
6501 hs->tx_words = (uint64_t)
6502 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6504 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6505 hs->rx_words = (uint64_t)
6506 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6509 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6510 pmb->mbxCommand = MBX_READ_LNK_STAT;
6511 pmb->mbxOwner = OWN_HOST;
6512 pmboxq->ctx_buf = NULL;
6513 pmboxq->vport = vport;
6515 if (vport->fc_flag & FC_OFFLINE_MODE)
6516 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6518 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6520 if (rc != MBX_SUCCESS) {
6521 if (rc != MBX_TIMEOUT)
6522 mempool_free(pmboxq, phba->mbox_mem_pool);
6526 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6527 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6528 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6529 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6530 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6531 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6532 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6534 hs->link_failure_count -= lso->link_failure_count;
6535 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6536 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6537 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6538 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6539 hs->invalid_crc_count -= lso->invalid_crc_count;
6540 hs->error_frames -= lso->error_frames;
6542 if (phba->hba_flag & HBA_FCOE_MODE) {
6544 hs->nos_count = (phba->link_events >> 1);
6545 hs->nos_count -= lso->link_events;
6546 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6547 hs->lip_count = (phba->fc_eventTag >> 1);
6548 hs->lip_count -= lso->link_events;
6552 hs->nos_count = (phba->fc_eventTag >> 1);
6553 hs->nos_count -= lso->link_events;
6556 hs->dumped_frames = -1;
6558 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6560 mempool_free(pmboxq, phba->mbox_mem_pool);
6566 * lpfc_reset_stats - Copy the adapter link stats information
6567 * @shost: kernel scsi host pointer.
6570 lpfc_reset_stats(struct Scsi_Host *shost)
6572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6573 struct lpfc_hba *phba = vport->phba;
6574 struct lpfc_sli *psli = &phba->sli;
6575 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6576 LPFC_MBOXQ_t *pmboxq;
6580 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6583 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6586 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6588 pmb = &pmboxq->u.mb;
6589 pmb->mbxCommand = MBX_READ_STATUS;
6590 pmb->mbxOwner = OWN_HOST;
6591 pmb->un.varWords[0] = 0x1; /* reset request */
6592 pmboxq->ctx_buf = NULL;
6593 pmboxq->vport = vport;
6595 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6596 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6597 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6599 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6601 if (rc != MBX_SUCCESS) {
6602 if (rc != MBX_TIMEOUT)
6603 mempool_free(pmboxq, phba->mbox_mem_pool);
6607 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6608 pmb->mbxCommand = MBX_READ_LNK_STAT;
6609 pmb->mbxOwner = OWN_HOST;
6610 pmboxq->ctx_buf = NULL;
6611 pmboxq->vport = vport;
6613 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6614 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6615 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6617 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6619 if (rc != MBX_SUCCESS) {
6620 if (rc != MBX_TIMEOUT)
6621 mempool_free( pmboxq, phba->mbox_mem_pool);
6625 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6626 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6627 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6628 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6629 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6630 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6631 lso->error_frames = pmb->un.varRdLnk.crcCnt;
6632 if (phba->hba_flag & HBA_FCOE_MODE)
6633 lso->link_events = (phba->link_events >> 1);
6635 lso->link_events = (phba->fc_eventTag >> 1);
6637 psli->stats_start = ktime_get_seconds();
6639 mempool_free(pmboxq, phba->mbox_mem_pool);
6645 * The LPFC driver treats linkdown handling as target loss events so there
6646 * are no sysfs handlers for link_down_tmo.
6650 * lpfc_get_node_by_target - Return the nodelist for a target
6651 * @starget: kernel scsi target pointer.
6654 * address of the node list if found
6655 * NULL target not found
6657 static struct lpfc_nodelist *
6658 lpfc_get_node_by_target(struct scsi_target *starget)
6660 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6661 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6662 struct lpfc_nodelist *ndlp;
6664 spin_lock_irq(shost->host_lock);
6665 /* Search for this, mapped, target ID */
6666 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6667 if (NLP_CHK_NODE_ACT(ndlp) &&
6668 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6669 starget->id == ndlp->nlp_sid) {
6670 spin_unlock_irq(shost->host_lock);
6674 spin_unlock_irq(shost->host_lock);
6679 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6680 * @starget: kernel scsi target pointer.
6683 lpfc_get_starget_port_id(struct scsi_target *starget)
6685 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6687 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6691 * lpfc_get_starget_node_name - Set the target node name
6692 * @starget: kernel scsi target pointer.
6694 * Description: Set the target node name to the ndlp node name wwn or zero.
6697 lpfc_get_starget_node_name(struct scsi_target *starget)
6699 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6701 fc_starget_node_name(starget) =
6702 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6706 * lpfc_get_starget_port_name - Set the target port name
6707 * @starget: kernel scsi target pointer.
6709 * Description: set the target port name to the ndlp port name wwn or zero.
6712 lpfc_get_starget_port_name(struct scsi_target *starget)
6714 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6716 fc_starget_port_name(starget) =
6717 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6721 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6722 * @rport: fc rport address.
6723 * @timeout: new value for dev loss tmo.
6726 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6727 * dev_loss_tmo to one.
6730 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6733 rport->dev_loss_tmo = timeout;
6735 rport->dev_loss_tmo = 1;
6739 * lpfc_rport_show_function - Return rport target information
6742 * Macro that uses field to generate a function with the name lpfc_show_rport_
6744 * lpfc_show_rport_##field: returns the bytes formatted in buf
6745 * @cdev: class converted to an fc_rport.
6746 * @buf: on return contains the target_field or zero.
6748 * Returns: size of formatted string.
6750 #define lpfc_rport_show_function(field, format_string, sz, cast) \
6752 lpfc_show_rport_##field (struct device *dev, \
6753 struct device_attribute *attr, \
6756 struct fc_rport *rport = transport_class_to_rport(dev); \
6757 struct lpfc_rport_data *rdata = rport->hostdata; \
6758 return snprintf(buf, sz, format_string, \
6759 (rdata->target) ? cast rdata->target->field : 0); \
6762 #define lpfc_rport_rd_attr(field, format_string, sz) \
6763 lpfc_rport_show_function(field, format_string, sz, ) \
6764 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6767 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6768 * @fc_vport: The fc_vport who's symbolic name has been changed.
6771 * This function is called by the transport after the @fc_vport's symbolic name
6772 * has been changed. This function re-registers the symbolic name with the
6773 * switch to propagate the change into the fabric if the vport is active.
6776 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6778 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6780 if (vport->port_state == LPFC_VPORT_READY)
6781 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6785 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6786 * @phba: Pointer to lpfc_hba struct.
6788 * This function is called by the lpfc_get_cfgparam() routine to set the
6789 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6790 * log message according to the module's lpfc_log_verbose parameter setting
6791 * before hba port or vport created.
6794 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6796 phba->cfg_log_verbose = verbose;
6799 struct fc_function_template lpfc_transport_functions = {
6800 /* fixed attributes the driver supports */
6801 .show_host_node_name = 1,
6802 .show_host_port_name = 1,
6803 .show_host_supported_classes = 1,
6804 .show_host_supported_fc4s = 1,
6805 .show_host_supported_speeds = 1,
6806 .show_host_maxframe_size = 1,
6808 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6809 .show_host_symbolic_name = 1,
6811 /* dynamic attributes the driver supports */
6812 .get_host_port_id = lpfc_get_host_port_id,
6813 .show_host_port_id = 1,
6815 .get_host_port_type = lpfc_get_host_port_type,
6816 .show_host_port_type = 1,
6818 .get_host_port_state = lpfc_get_host_port_state,
6819 .show_host_port_state = 1,
6821 /* active_fc4s is shown but doesn't change (thus no get function) */
6822 .show_host_active_fc4s = 1,
6824 .get_host_speed = lpfc_get_host_speed,
6825 .show_host_speed = 1,
6827 .get_host_fabric_name = lpfc_get_host_fabric_name,
6828 .show_host_fabric_name = 1,
6831 * The LPFC driver treats linkdown handling as target loss events
6832 * so there are no sysfs handlers for link_down_tmo.
6835 .get_fc_host_stats = lpfc_get_stats,
6836 .reset_fc_host_stats = lpfc_reset_stats,
6838 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6839 .show_rport_maxframe_size = 1,
6840 .show_rport_supported_classes = 1,
6842 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6843 .show_rport_dev_loss_tmo = 1,
6845 .get_starget_port_id = lpfc_get_starget_port_id,
6846 .show_starget_port_id = 1,
6848 .get_starget_node_name = lpfc_get_starget_node_name,
6849 .show_starget_node_name = 1,
6851 .get_starget_port_name = lpfc_get_starget_port_name,
6852 .show_starget_port_name = 1,
6854 .issue_fc_host_lip = lpfc_issue_lip,
6855 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6856 .terminate_rport_io = lpfc_terminate_rport_io,
6858 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6860 .vport_disable = lpfc_vport_disable,
6862 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6864 .bsg_request = lpfc_bsg_request,
6865 .bsg_timeout = lpfc_bsg_timeout,
6868 struct fc_function_template lpfc_vport_transport_functions = {
6869 /* fixed attributes the driver supports */
6870 .show_host_node_name = 1,
6871 .show_host_port_name = 1,
6872 .show_host_supported_classes = 1,
6873 .show_host_supported_fc4s = 1,
6874 .show_host_supported_speeds = 1,
6875 .show_host_maxframe_size = 1,
6877 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6878 .show_host_symbolic_name = 1,
6880 /* dynamic attributes the driver supports */
6881 .get_host_port_id = lpfc_get_host_port_id,
6882 .show_host_port_id = 1,
6884 .get_host_port_type = lpfc_get_host_port_type,
6885 .show_host_port_type = 1,
6887 .get_host_port_state = lpfc_get_host_port_state,
6888 .show_host_port_state = 1,
6890 /* active_fc4s is shown but doesn't change (thus no get function) */
6891 .show_host_active_fc4s = 1,
6893 .get_host_speed = lpfc_get_host_speed,
6894 .show_host_speed = 1,
6896 .get_host_fabric_name = lpfc_get_host_fabric_name,
6897 .show_host_fabric_name = 1,
6900 * The LPFC driver treats linkdown handling as target loss events
6901 * so there are no sysfs handlers for link_down_tmo.
6904 .get_fc_host_stats = lpfc_get_stats,
6905 .reset_fc_host_stats = lpfc_reset_stats,
6907 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6908 .show_rport_maxframe_size = 1,
6909 .show_rport_supported_classes = 1,
6911 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6912 .show_rport_dev_loss_tmo = 1,
6914 .get_starget_port_id = lpfc_get_starget_port_id,
6915 .show_starget_port_id = 1,
6917 .get_starget_node_name = lpfc_get_starget_node_name,
6918 .show_starget_node_name = 1,
6920 .get_starget_port_name = lpfc_get_starget_port_name,
6921 .show_starget_port_name = 1,
6923 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6924 .terminate_rport_io = lpfc_terminate_rport_io,
6926 .vport_disable = lpfc_vport_disable,
6928 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6932 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6933 * @phba: lpfc_hba pointer.
6936 lpfc_get_cfgparam(struct lpfc_hba *phba)
6938 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6939 lpfc_ns_query_init(phba, lpfc_ns_query);
6940 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6941 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6942 lpfc_cr_count_init(phba, lpfc_cr_count);
6943 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6944 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6945 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6946 lpfc_ack0_init(phba, lpfc_ack0);
6947 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
6948 lpfc_topology_init(phba, lpfc_topology);
6949 lpfc_link_speed_init(phba, lpfc_link_speed);
6950 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6951 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6952 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6953 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6954 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6955 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6956 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6957 lpfc_use_msi_init(phba, lpfc_use_msi);
6958 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6959 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
6960 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6961 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
6962 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
6963 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6964 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6965 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6967 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6968 if (phba->sli_rev != LPFC_SLI_REV4)
6969 phba->cfg_EnableXLane = 0;
6970 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6972 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6973 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6974 phba->cfg_oas_lun_state = 0;
6975 phba->cfg_oas_lun_status = 0;
6976 phba->cfg_oas_flags = 0;
6977 phba->cfg_oas_priority = 0;
6978 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6979 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6980 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6981 if (phba->sli_rev == LPFC_SLI_REV4)
6984 phba->cfg_poll = lpfc_poll;
6986 if (phba->cfg_enable_bg)
6987 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
6989 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6991 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6992 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6993 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
6995 /* Initialize first burst. Target vs Initiator are different. */
6996 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6997 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6998 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
6999 lpfc_irq_chann_init(phba, lpfc_irq_chann);
7000 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7001 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7003 if (phba->sli_rev != LPFC_SLI_REV4) {
7004 /* NVME only supported on SLI4 */
7005 phba->nvmet_support = 0;
7006 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7007 phba->cfg_enable_bbcr = 0;
7008 phba->cfg_xri_rebalancing = 0;
7010 /* We MUST have FCP support */
7011 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7012 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7015 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7017 phba->cfg_enable_pbde = 0;
7019 /* A value of 0 means use the number of CPUs found in the system */
7020 if (phba->cfg_hdw_queue == 0)
7021 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7022 if (phba->cfg_irq_chann == 0)
7023 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7024 if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7025 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7027 phba->cfg_soft_wwnn = 0L;
7028 phba->cfg_soft_wwpn = 0L;
7029 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7030 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7031 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7032 lpfc_aer_support_init(phba, lpfc_aer_support);
7033 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7034 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7035 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7036 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
7037 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7038 lpfc_sli_mode_init(phba, lpfc_sli_mode);
7039 phba->cfg_enable_dss = 1;
7040 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7041 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7042 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7043 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7046 /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to
7047 * accommodate 512K and 1M IOs in a single nvme buf and supply
7048 * enough NVME LS iocb buffers for larger connectivity counts.
7050 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7051 phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
7052 phba->cfg_iocb_cnt = 5;
7059 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7060 * dependencies between protocols and roles.
7061 * @phba: lpfc_hba pointer.
7064 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7066 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu)
7067 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7068 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu)
7069 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7070 if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7071 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7073 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7074 phba->nvmet_support) {
7075 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7077 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7078 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7079 "NVME Target PRLI ACC enable_fb ",
7080 phba->cfg_nvme_enable_fb,
7081 phba->cfg_nvmet_fb_size,
7082 LPFC_NVMET_FB_SZ_MAX);
7084 if (phba->cfg_nvme_enable_fb == 0)
7085 phba->cfg_nvmet_fb_size = 0;
7087 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7088 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7091 if (!phba->cfg_nvmet_mrq)
7092 phba->cfg_nvmet_mrq = phba->cfg_irq_chann;
7094 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7095 if (phba->cfg_nvmet_mrq > phba->cfg_irq_chann) {
7096 phba->cfg_nvmet_mrq = phba->cfg_irq_chann;
7097 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7098 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7099 phba->cfg_nvmet_mrq);
7101 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7102 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7105 /* Not NVME Target mode. Turn off Target parameters. */
7106 phba->nvmet_support = 0;
7107 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
7108 phba->cfg_nvmet_fb_size = 0;
7113 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7114 * @vport: lpfc_vport pointer.
7117 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7119 lpfc_log_verbose_init(vport, lpfc_log_verbose);
7120 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7121 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7122 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7123 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7124 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7125 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7126 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7127 lpfc_use_adisc_init(vport, lpfc_use_adisc);
7128 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7129 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7130 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7131 lpfc_max_luns_init(vport, lpfc_max_luns);
7132 lpfc_scan_down_init(vport, lpfc_scan_down);
7133 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);