1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 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"
74 const char *const trunk_errmsg[] = { /* map errcode */
75 "", /* There is no such error code at index 0*/
76 "link negotiated speed does not match existing"
77 " trunk - link was \"low\" speed",
78 "link negotiated speed does not match"
79 " existing trunk - link was \"middle\" speed",
80 "link negotiated speed does not match existing"
81 " trunk - link was \"high\" speed",
82 "Attached to non-trunking port - F_Port",
83 "Attached to non-trunking port - N_Port",
84 "FLOGI response timeout",
85 "non-FLOGI frame received",
86 "Invalid FLOGI response",
87 "Trunking initialization protocol",
88 "Trunk peer device mismatch",
92 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
93 * @incr: integer to convert.
94 * @hdw: ascii string holding converted integer plus a string terminator.
97 * JEDEC Joint Electron Device Engineering Council.
98 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
99 * character string. The string is then terminated with a NULL in byte 9.
100 * Hex 0-9 becomes ascii '0' to '9'.
101 * Hex a-f becomes ascii '=' to 'B' capital B.
104 * Coded for 32 bit integers only.
107 lpfc_jedec_to_ascii(int incr, char hdw[])
110 for (i = 0; i < 8; i++) {
113 hdw[7 - i] = 0x30 + j;
115 hdw[7 - i] = 0x61 + j - 10;
123 * lpfc_drvr_version_show - Return the Emulex driver string with version number
124 * @dev: class unused variable.
125 * @attr: device attribute, not used.
126 * @buf: on return contains the module description text.
128 * Returns: size of formatted string.
131 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
134 return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
138 * lpfc_enable_fip_show - Return the fip mode of the HBA
139 * @dev: class unused variable.
140 * @attr: device attribute, not used.
141 * @buf: on return contains the module description text.
143 * Returns: size of formatted string.
146 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
149 struct Scsi_Host *shost = class_to_shost(dev);
150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
153 if (phba->hba_flag & HBA_FIP_SUPPORT)
154 return scnprintf(buf, PAGE_SIZE, "1\n");
156 return scnprintf(buf, PAGE_SIZE, "0\n");
160 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
163 struct Scsi_Host *shost = class_to_shost(dev);
164 struct lpfc_vport *vport = shost_priv(shost);
165 struct lpfc_hba *phba = vport->phba;
166 struct lpfc_nvmet_tgtport *tgtp;
167 struct nvme_fc_local_port *localport;
168 struct lpfc_nvme_lport *lport;
169 struct lpfc_nvme_rport *rport;
170 struct lpfc_nodelist *ndlp;
171 struct nvme_fc_remote_port *nrport;
172 struct lpfc_fc4_ctrl_stat *cstat;
173 uint64_t data1, data2, data3;
174 uint64_t totin, totout, tot;
178 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
180 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
181 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
184 if (phba->nvmet_support) {
185 if (!phba->targetport) {
186 len = scnprintf(buf, PAGE_SIZE,
187 "NVME Target: x%llx is not allocated\n",
188 wwn_to_u64(vport->fc_portname.u.wwn));
191 /* Port state is only one of two values for now. */
192 if (phba->targetport->port_id)
193 statep = "REGISTERED";
196 scnprintf(tmp, sizeof(tmp),
197 "NVME Target Enabled State %s\n",
199 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
202 scnprintf(tmp, sizeof(tmp),
203 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
206 wwn_to_u64(vport->fc_portname.u.wwn),
207 wwn_to_u64(vport->fc_nodename.u.wwn),
208 phba->targetport->port_id);
209 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
212 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
216 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
217 scnprintf(tmp, sizeof(tmp),
218 "LS: Rcv %08x Drop %08x Abort %08x\n",
219 atomic_read(&tgtp->rcv_ls_req_in),
220 atomic_read(&tgtp->rcv_ls_req_drop),
221 atomic_read(&tgtp->xmt_ls_abort));
222 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
225 if (atomic_read(&tgtp->rcv_ls_req_in) !=
226 atomic_read(&tgtp->rcv_ls_req_out)) {
227 scnprintf(tmp, sizeof(tmp),
228 "Rcv LS: in %08x != out %08x\n",
229 atomic_read(&tgtp->rcv_ls_req_in),
230 atomic_read(&tgtp->rcv_ls_req_out));
231 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
235 scnprintf(tmp, sizeof(tmp),
236 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
237 atomic_read(&tgtp->xmt_ls_rsp),
238 atomic_read(&tgtp->xmt_ls_drop),
239 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
240 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
243 scnprintf(tmp, sizeof(tmp),
244 "LS: RSP Abort %08x xb %08x Err %08x\n",
245 atomic_read(&tgtp->xmt_ls_rsp_aborted),
246 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
247 atomic_read(&tgtp->xmt_ls_rsp_error));
248 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
251 scnprintf(tmp, sizeof(tmp),
252 "FCP: Rcv %08x Defer %08x Release %08x "
254 atomic_read(&tgtp->rcv_fcp_cmd_in),
255 atomic_read(&tgtp->rcv_fcp_cmd_defer),
256 atomic_read(&tgtp->xmt_fcp_release),
257 atomic_read(&tgtp->rcv_fcp_cmd_drop));
258 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
261 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
262 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
263 scnprintf(tmp, sizeof(tmp),
264 "Rcv FCP: in %08x != out %08x\n",
265 atomic_read(&tgtp->rcv_fcp_cmd_in),
266 atomic_read(&tgtp->rcv_fcp_cmd_out));
267 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
271 scnprintf(tmp, sizeof(tmp),
272 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
274 atomic_read(&tgtp->xmt_fcp_read),
275 atomic_read(&tgtp->xmt_fcp_read_rsp),
276 atomic_read(&tgtp->xmt_fcp_write),
277 atomic_read(&tgtp->xmt_fcp_rsp),
278 atomic_read(&tgtp->xmt_fcp_drop));
279 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
282 scnprintf(tmp, sizeof(tmp),
283 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
284 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
285 atomic_read(&tgtp->xmt_fcp_rsp_error),
286 atomic_read(&tgtp->xmt_fcp_rsp_drop));
287 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
290 scnprintf(tmp, sizeof(tmp),
291 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
292 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
293 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
294 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
295 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
298 scnprintf(tmp, sizeof(tmp),
299 "ABORT: Xmt %08x Cmpl %08x\n",
300 atomic_read(&tgtp->xmt_fcp_abort),
301 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
302 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
305 scnprintf(tmp, sizeof(tmp),
306 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
307 atomic_read(&tgtp->xmt_abort_sol),
308 atomic_read(&tgtp->xmt_abort_unsol),
309 atomic_read(&tgtp->xmt_abort_rsp),
310 atomic_read(&tgtp->xmt_abort_rsp_error));
311 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
314 scnprintf(tmp, sizeof(tmp),
315 "DELAY: ctx %08x fod %08x wqfull %08x\n",
316 atomic_read(&tgtp->defer_ctx),
317 atomic_read(&tgtp->defer_fod),
318 atomic_read(&tgtp->defer_wqfull));
319 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
322 /* Calculate outstanding IOs */
323 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
324 tot += atomic_read(&tgtp->xmt_fcp_release);
325 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
327 scnprintf(tmp, sizeof(tmp),
328 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
329 "CTX Outstanding %08llx\n\n",
330 phba->sli4_hba.nvmet_xri_cnt,
331 phba->sli4_hba.nvmet_io_wait_cnt,
332 phba->sli4_hba.nvmet_io_wait_total,
334 strlcat(buf, tmp, PAGE_SIZE);
338 localport = vport->localport;
340 len = scnprintf(buf, PAGE_SIZE,
341 "NVME Initiator x%llx is not allocated\n",
342 wwn_to_u64(vport->fc_portname.u.wwn));
345 lport = (struct lpfc_nvme_lport *)localport->private;
346 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
349 scnprintf(tmp, sizeof(tmp),
350 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
352 phba->sli4_hba.max_cfg_param.max_xri,
353 phba->sli4_hba.io_xri_max,
354 lpfc_sli4_get_els_iocb_cnt(phba));
355 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
358 /* Port state is only one of two values for now. */
359 if (localport->port_id)
364 scnprintf(tmp, sizeof(tmp),
365 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
368 wwn_to_u64(vport->fc_portname.u.wwn),
369 wwn_to_u64(vport->fc_nodename.u.wwn),
370 localport->port_id, statep);
371 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
374 spin_lock_irq(shost->host_lock);
376 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
378 spin_lock(&vport->phba->hbalock);
379 rport = lpfc_ndlp_get_nrport(ndlp);
381 nrport = rport->remoteport;
382 spin_unlock(&vport->phba->hbalock);
386 /* Port state is only one of two values for now. */
387 switch (nrport->port_state) {
388 case FC_OBJSTATE_ONLINE:
391 case FC_OBJSTATE_UNKNOWN:
395 statep = "UNSUPPORTED";
399 /* Tab in to show lport ownership. */
400 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
401 goto unlock_buf_done;
402 if (phba->brd_no >= 10) {
403 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
404 goto unlock_buf_done;
407 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
409 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
410 goto unlock_buf_done;
412 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
414 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
415 goto unlock_buf_done;
417 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
419 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
420 goto unlock_buf_done;
422 /* An NVME rport can have multiple roles. */
423 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
424 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
425 goto unlock_buf_done;
427 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
428 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
429 goto unlock_buf_done;
431 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
432 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
433 goto unlock_buf_done;
435 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
436 FC_PORT_ROLE_NVME_TARGET |
437 FC_PORT_ROLE_NVME_DISCOVERY)) {
438 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
440 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
441 goto unlock_buf_done;
444 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
445 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
446 goto unlock_buf_done;
448 spin_unlock_irq(shost->host_lock);
453 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
456 scnprintf(tmp, sizeof(tmp),
457 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
458 atomic_read(&lport->fc4NvmeLsRequests),
459 atomic_read(&lport->fc4NvmeLsCmpls),
460 atomic_read(&lport->xmt_ls_abort));
461 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
464 scnprintf(tmp, sizeof(tmp),
465 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
466 atomic_read(&lport->xmt_ls_err),
467 atomic_read(&lport->cmpl_ls_xb),
468 atomic_read(&lport->cmpl_ls_err));
469 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
474 for (i = 0; i < phba->cfg_hdw_queue; i++) {
475 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
476 tot = cstat->io_cmpls;
478 data1 = cstat->input_requests;
479 data2 = cstat->output_requests;
480 data3 = cstat->control_requests;
481 totout += (data1 + data2 + data3);
483 scnprintf(tmp, sizeof(tmp),
484 "Total FCP Cmpl %016llx Issue %016llx "
486 totin, totout, totout - totin);
487 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
490 scnprintf(tmp, sizeof(tmp),
491 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
492 "wqerr %08x err %08x\n",
493 atomic_read(&lport->xmt_fcp_abort),
494 atomic_read(&lport->xmt_fcp_noxri),
495 atomic_read(&lport->xmt_fcp_bad_ndlp),
496 atomic_read(&lport->xmt_fcp_qdepth),
497 atomic_read(&lport->xmt_fcp_err),
498 atomic_read(&lport->xmt_fcp_wqerr));
499 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
502 scnprintf(tmp, sizeof(tmp),
503 "FCP CMPL: xb %08x Err %08x\n",
504 atomic_read(&lport->cmpl_fcp_xb),
505 atomic_read(&lport->cmpl_fcp_err));
506 strlcat(buf, tmp, PAGE_SIZE);
508 /* host_lock is already unlocked. */
512 spin_unlock_irq(shost->host_lock);
515 len = strnlen(buf, PAGE_SIZE);
517 if (unlikely(len >= (PAGE_SIZE - 1))) {
518 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
519 "6314 Catching potential buffer "
520 "overflow > PAGE_SIZE = %lu bytes\n",
522 strlcpy(buf + PAGE_SIZE - 1 -
523 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1),
524 LPFC_NVME_INFO_MORE_STR,
525 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1)
533 lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
536 struct Scsi_Host *shost = class_to_shost(dev);
537 struct lpfc_vport *vport = shost_priv(shost);
538 struct lpfc_hba *phba = vport->phba;
540 struct lpfc_fc4_ctrl_stat *cstat;
541 u64 data1, data2, data3;
542 u64 tot, totin, totout;
544 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
546 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
547 (phba->sli_rev != LPFC_SLI_REV4))
550 scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
554 for (i = 0; i < phba->cfg_hdw_queue; i++) {
555 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
556 tot = cstat->io_cmpls;
558 data1 = cstat->input_requests;
559 data2 = cstat->output_requests;
560 data3 = cstat->control_requests;
561 totout += (data1 + data2 + data3);
563 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
564 "IO %016llx ", i, data1, data2, data3);
565 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
568 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
569 tot, ((data1 + data2 + data3) - tot));
570 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
573 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
574 "OutIO %016llx\n", totin, totout, totout - totin);
575 strlcat(buf, tmp, PAGE_SIZE);
578 len = strnlen(buf, PAGE_SIZE);
584 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
587 struct Scsi_Host *shost = class_to_shost(dev);
588 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
589 struct lpfc_hba *phba = vport->phba;
591 if (phba->cfg_enable_bg) {
592 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
593 return scnprintf(buf, PAGE_SIZE,
594 "BlockGuard Enabled\n");
596 return scnprintf(buf, PAGE_SIZE,
597 "BlockGuard Not Supported\n");
599 return scnprintf(buf, PAGE_SIZE,
600 "BlockGuard Disabled\n");
604 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
607 struct Scsi_Host *shost = class_to_shost(dev);
608 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
609 struct lpfc_hba *phba = vport->phba;
611 return scnprintf(buf, PAGE_SIZE, "%llu\n",
612 (unsigned long long)phba->bg_guard_err_cnt);
616 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
619 struct Scsi_Host *shost = class_to_shost(dev);
620 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
621 struct lpfc_hba *phba = vport->phba;
623 return scnprintf(buf, PAGE_SIZE, "%llu\n",
624 (unsigned long long)phba->bg_apptag_err_cnt);
628 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
631 struct Scsi_Host *shost = class_to_shost(dev);
632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
633 struct lpfc_hba *phba = vport->phba;
635 return scnprintf(buf, PAGE_SIZE, "%llu\n",
636 (unsigned long long)phba->bg_reftag_err_cnt);
640 * lpfc_info_show - Return some pci info about the host in ascii
641 * @dev: class converted to a Scsi_host structure.
642 * @attr: device attribute, not used.
643 * @buf: on return contains the formatted text from lpfc_info().
645 * Returns: size of formatted string.
648 lpfc_info_show(struct device *dev, struct device_attribute *attr,
651 struct Scsi_Host *host = class_to_shost(dev);
653 return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
657 * lpfc_serialnum_show - Return the hba serial number in ascii
658 * @dev: class converted to a Scsi_host structure.
659 * @attr: device attribute, not used.
660 * @buf: on return contains the formatted text serial number.
662 * Returns: size of formatted string.
665 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
668 struct Scsi_Host *shost = class_to_shost(dev);
669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
670 struct lpfc_hba *phba = vport->phba;
672 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
676 * lpfc_temp_sensor_show - Return the temperature sensor level
677 * @dev: class converted to a Scsi_host structure.
678 * @attr: device attribute, not used.
679 * @buf: on return contains the formatted support level.
682 * Returns a number indicating the temperature sensor level currently
683 * supported, zero or one in ascii.
685 * Returns: size of formatted string.
688 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
691 struct Scsi_Host *shost = class_to_shost(dev);
692 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
693 struct lpfc_hba *phba = vport->phba;
694 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
698 * lpfc_modeldesc_show - Return the model description of the hba
699 * @dev: class converted to a Scsi_host structure.
700 * @attr: device attribute, not used.
701 * @buf: on return contains the scsi vpd model description.
703 * Returns: size of formatted string.
706 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
709 struct Scsi_Host *shost = class_to_shost(dev);
710 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
711 struct lpfc_hba *phba = vport->phba;
713 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
717 * lpfc_modelname_show - Return the model name of the hba
718 * @dev: class converted to a Scsi_host structure.
719 * @attr: device attribute, not used.
720 * @buf: on return contains the scsi vpd model name.
722 * Returns: size of formatted string.
725 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
728 struct Scsi_Host *shost = class_to_shost(dev);
729 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
730 struct lpfc_hba *phba = vport->phba;
732 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
736 * lpfc_programtype_show - Return the program type of the hba
737 * @dev: class converted to a Scsi_host structure.
738 * @attr: device attribute, not used.
739 * @buf: on return contains the scsi vpd program type.
741 * Returns: size of formatted string.
744 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
747 struct Scsi_Host *shost = class_to_shost(dev);
748 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
749 struct lpfc_hba *phba = vport->phba;
751 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
755 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
756 * @dev: class converted to a Scsi_host structure.
757 * @attr: device attribute, not used.
758 * @buf: on return contains the Menlo Maintenance sli flag.
760 * Returns: size of formatted string.
763 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
765 struct Scsi_Host *shost = class_to_shost(dev);
766 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
767 struct lpfc_hba *phba = vport->phba;
769 return scnprintf(buf, PAGE_SIZE, "%d\n",
770 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
774 * lpfc_vportnum_show - Return the port number in ascii of the hba
775 * @dev: class converted to a Scsi_host structure.
776 * @attr: device attribute, not used.
777 * @buf: on return contains scsi vpd program type.
779 * Returns: size of formatted string.
782 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
785 struct Scsi_Host *shost = class_to_shost(dev);
786 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
787 struct lpfc_hba *phba = vport->phba;
789 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
793 * lpfc_fwrev_show - Return the firmware rev running in the hba
794 * @dev: class converted to a Scsi_host structure.
795 * @attr: device attribute, not used.
796 * @buf: on return contains the scsi vpd program type.
798 * Returns: size of formatted string.
801 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
804 struct Scsi_Host *shost = class_to_shost(dev);
805 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
806 struct lpfc_hba *phba = vport->phba;
809 char fwrev[FW_REV_STR_SIZE];
812 lpfc_decode_firmware_rev(phba, fwrev, 1);
813 if_type = phba->sli4_hba.pc_sli4_params.if_type;
814 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
816 if (phba->sli_rev < LPFC_SLI_REV4)
817 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
818 fwrev, phba->sli_rev);
820 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
821 fwrev, phba->sli_rev, if_type, sli_family);
827 * lpfc_hdw_show - Return the jedec information about the hba
828 * @dev: class converted to a Scsi_host structure.
829 * @attr: device attribute, not used.
830 * @buf: on return contains the scsi vpd program type.
832 * Returns: size of formatted string.
835 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
838 struct Scsi_Host *shost = class_to_shost(dev);
839 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
840 struct lpfc_hba *phba = vport->phba;
841 lpfc_vpd_t *vp = &phba->vpd;
843 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
844 return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
845 vp->rev.smRev, vp->rev.smFwRev);
849 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
850 * @dev: class converted to a Scsi_host structure.
851 * @attr: device attribute, not used.
852 * @buf: on return contains the ROM and FCode ascii strings.
854 * Returns: size of formatted string.
857 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
860 struct Scsi_Host *shost = class_to_shost(dev);
861 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
862 struct lpfc_hba *phba = vport->phba;
863 char fwrev[FW_REV_STR_SIZE];
865 if (phba->sli_rev < LPFC_SLI_REV4)
866 return scnprintf(buf, PAGE_SIZE, "%s\n",
867 phba->OptionROMVersion);
869 lpfc_decode_firmware_rev(phba, fwrev, 1);
870 return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
874 * lpfc_state_show - Return the link state of the port
875 * @dev: class converted to a Scsi_host structure.
876 * @attr: device attribute, not used.
877 * @buf: on return contains text describing the state of the link.
880 * The switch statement has no default so zero will be returned.
882 * Returns: size of formatted string.
885 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
888 struct Scsi_Host *shost = class_to_shost(dev);
889 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
890 struct lpfc_hba *phba = vport->phba;
893 switch (phba->link_state) {
894 case LPFC_LINK_UNKNOWN:
895 case LPFC_WARM_START:
896 case LPFC_INIT_START:
897 case LPFC_INIT_MBX_CMDS:
900 if (phba->hba_flag & LINK_DISABLED)
901 len += scnprintf(buf + len, PAGE_SIZE-len,
902 "Link Down - User disabled\n");
904 len += scnprintf(buf + len, PAGE_SIZE-len,
910 len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
912 switch (vport->port_state) {
913 case LPFC_LOCAL_CFG_LINK:
914 len += scnprintf(buf + len, PAGE_SIZE-len,
915 "Configuring Link\n");
919 case LPFC_FABRIC_CFG_LINK:
922 case LPFC_BUILD_DISC_LIST:
924 len += scnprintf(buf + len, PAGE_SIZE - len,
927 case LPFC_VPORT_READY:
928 len += scnprintf(buf + len, PAGE_SIZE - len,
932 case LPFC_VPORT_FAILED:
933 len += scnprintf(buf + len, PAGE_SIZE - len,
937 case LPFC_VPORT_UNKNOWN:
938 len += scnprintf(buf + len, PAGE_SIZE - len,
942 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
943 len += scnprintf(buf + len, PAGE_SIZE-len,
944 " Menlo Maint Mode\n");
945 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
946 if (vport->fc_flag & FC_PUBLIC_LOOP)
947 len += scnprintf(buf + len, PAGE_SIZE-len,
950 len += scnprintf(buf + len, PAGE_SIZE-len,
953 if (vport->fc_flag & FC_FABRIC)
954 len += scnprintf(buf + len, PAGE_SIZE-len,
957 len += scnprintf(buf + len, PAGE_SIZE-len,
962 if ((phba->sli_rev == LPFC_SLI_REV4) &&
963 ((bf_get(lpfc_sli_intf_if_type,
964 &phba->sli4_hba.sli_intf) ==
965 LPFC_SLI_INTF_IF_TYPE_6))) {
966 struct lpfc_trunk_link link = phba->trunk_link;
968 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
969 len += scnprintf(buf + len, PAGE_SIZE - len,
970 "Trunk port 0: Link %s %s\n",
971 (link.link0.state == LPFC_LINK_UP) ?
973 trunk_errmsg[link.link0.fault]);
975 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
976 len += scnprintf(buf + len, PAGE_SIZE - len,
977 "Trunk port 1: Link %s %s\n",
978 (link.link1.state == LPFC_LINK_UP) ?
980 trunk_errmsg[link.link1.fault]);
982 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
983 len += scnprintf(buf + len, PAGE_SIZE - len,
984 "Trunk port 2: Link %s %s\n",
985 (link.link2.state == LPFC_LINK_UP) ?
987 trunk_errmsg[link.link2.fault]);
989 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
990 len += scnprintf(buf + len, PAGE_SIZE - len,
991 "Trunk port 3: Link %s %s\n",
992 (link.link3.state == LPFC_LINK_UP) ?
994 trunk_errmsg[link.link3.fault]);
1002 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
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_sli4_protocol_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 if (phba->sli_rev < LPFC_SLI_REV4)
1018 return scnprintf(buf, PAGE_SIZE, "fc\n");
1020 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
1021 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
1022 return scnprintf(buf, PAGE_SIZE, "fcoe\n");
1023 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
1024 return scnprintf(buf, PAGE_SIZE, "fc\n");
1026 return scnprintf(buf, PAGE_SIZE, "unknown\n");
1030 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1031 * (OAS) is supported.
1032 * @dev: class unused variable.
1033 * @attr: device attribute, not used.
1034 * @buf: on return contains the module description text.
1036 * Returns: size of formatted string.
1039 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1042 struct Scsi_Host *shost = class_to_shost(dev);
1043 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1044 struct lpfc_hba *phba = vport->phba;
1046 return scnprintf(buf, PAGE_SIZE, "%d\n",
1047 phba->sli4_hba.pc_sli4_params.oas_supported);
1051 * lpfc_link_state_store - Transition the link_state on an HBA port
1052 * @dev: class device that is converted into a Scsi_host.
1053 * @attr: device attribute, not used.
1054 * @buf: one or more lpfc_polling_flags values.
1058 * -EINVAL if the buffer is not "up" or "down"
1059 * return from link state change function if non-zero
1060 * length of the buf on success
1063 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1064 const char *buf, size_t count)
1066 struct Scsi_Host *shost = class_to_shost(dev);
1067 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1068 struct lpfc_hba *phba = vport->phba;
1070 int status = -EINVAL;
1072 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1073 (phba->link_state == LPFC_LINK_DOWN))
1074 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
1075 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1076 (phba->link_state >= LPFC_LINK_UP))
1077 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1086 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1087 * @dev: class device that is converted into a Scsi_host.
1088 * @attr: device attribute, not used.
1089 * @buf: on return contains the sum of fc mapped and unmapped.
1092 * Returns the ascii text number of the sum of the fc mapped and unmapped
1095 * Returns: size of formatted string.
1098 lpfc_num_discovered_ports_show(struct device *dev,
1099 struct device_attribute *attr, char *buf)
1101 struct Scsi_Host *shost = class_to_shost(dev);
1102 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1104 return scnprintf(buf, PAGE_SIZE, "%d\n",
1105 vport->fc_map_cnt + vport->fc_unmap_cnt);
1109 * lpfc_issue_lip - Misnomer, name carried over from long ago
1110 * @shost: Scsi_Host pointer.
1113 * Bring the link down gracefully then re-init the link. The firmware will
1114 * re-init the fiber channel interface as required. Does not issue a LIP.
1117 * -EPERM port offline or management commands are being blocked
1118 * -ENOMEM cannot allocate memory for the mailbox command
1119 * -EIO error sending the mailbox command
1123 lpfc_issue_lip(struct Scsi_Host *shost)
1125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1126 struct lpfc_hba *phba = vport->phba;
1127 LPFC_MBOXQ_t *pmboxq;
1128 int mbxstatus = MBXERR_ERROR;
1131 * If the link is offline, disabled or BLOCK_MGMT_IO
1132 * it doesn't make any sense to allow issue_lip
1134 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1135 (phba->hba_flag & LINK_DISABLED) ||
1136 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1139 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1144 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1145 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1146 pmboxq->u.mb.mbxOwner = OWN_HOST;
1148 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1150 if ((mbxstatus == MBX_SUCCESS) &&
1151 (pmboxq->u.mb.mbxStatus == 0 ||
1152 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1153 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1154 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1155 phba->cfg_link_speed);
1156 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1157 phba->fc_ratov * 2);
1158 if ((mbxstatus == MBX_SUCCESS) &&
1159 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1160 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1161 "2859 SLI authentication is required "
1162 "for INIT_LINK but has not done yet\n");
1165 lpfc_set_loopback_flag(phba);
1166 if (mbxstatus != MBX_TIMEOUT)
1167 mempool_free(pmboxq, phba->mbox_mem_pool);
1169 if (mbxstatus == MBXERR_ERROR)
1176 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1180 spin_lock_irq(lock);
1181 while (!list_empty(q)) {
1182 spin_unlock_irq(lock);
1184 if (cnt++ > 250) { /* 5 secs */
1185 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1187 "Outstanding IO when ",
1188 "bringing Adapter offline\n");
1191 spin_lock_irq(lock);
1193 spin_unlock_irq(lock);
1198 * lpfc_do_offline - Issues a mailbox command to bring the link down
1199 * @phba: lpfc_hba pointer.
1200 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1203 * Assumes any error from lpfc_do_offline() will be negative.
1204 * Can wait up to 5 seconds for the port ring buffers count
1205 * to reach zero, prints a warning if it is not zero and continues.
1206 * lpfc_workq_post_event() returns a non-zero return code if call fails.
1209 * -EIO error posting the event
1213 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1215 struct completion online_compl;
1216 struct lpfc_queue *qp = NULL;
1217 struct lpfc_sli_ring *pring;
1218 struct lpfc_sli *psli;
1223 init_completion(&online_compl);
1224 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1225 LPFC_EVT_OFFLINE_PREP);
1229 wait_for_completion(&online_compl);
1237 * If freeing the queues have already started, don't access them.
1238 * Otherwise set FREE_WAIT to indicate that queues are being used
1239 * to hold the freeing process until we finish.
1241 spin_lock_irq(&phba->hbalock);
1242 if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {
1243 psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;
1245 spin_unlock_irq(&phba->hbalock);
1248 spin_unlock_irq(&phba->hbalock);
1250 /* Wait a little for things to settle down, but not
1251 * long enough for dev loss timeout to expire.
1253 if (phba->sli_rev != LPFC_SLI_REV4) {
1254 for (i = 0; i < psli->num_rings; i++) {
1255 pring = &psli->sli3_ring[i];
1256 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1261 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1265 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1271 spin_lock_irq(&phba->hbalock);
1272 psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;
1273 spin_unlock_irq(&phba->hbalock);
1276 init_completion(&online_compl);
1277 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1281 wait_for_completion(&online_compl);
1290 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1291 * @phba: lpfc_hba pointer.
1294 * Issues a PCI secondary bus reset for the phba->pcidev.
1297 * First walks the bus_list to ensure only PCI devices with Emulex
1298 * vendor id, device ids that support hot reset, only one occurrence
1299 * of function 0, and all ports on the bus are in offline mode to ensure the
1300 * hot reset only affects one valid HBA.
1303 * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1304 * -ENODEV, NULL ptr to pcidev
1305 * -EBADSLT, detected invalid device
1306 * -EBUSY, port is not in offline state
1310 lpfc_reset_pci_bus(struct lpfc_hba *phba)
1312 struct pci_dev *pdev = phba->pcidev;
1313 struct Scsi_Host *shost = NULL;
1314 struct lpfc_hba *phba_other = NULL;
1315 struct pci_dev *ptr = NULL;
1318 if (phba->cfg_enable_hba_reset != 2)
1322 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1326 res = lpfc_check_pci_resettable(phba);
1330 /* Walk the list of devices on the pci_dev's bus */
1331 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1332 /* Check port is offline */
1333 shost = pci_get_drvdata(ptr);
1336 ((struct lpfc_vport *)shost->hostdata)->phba;
1337 if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1338 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1339 "8349 WWPN = 0x%02x%02x%02x%02x"
1340 "%02x%02x%02x%02x is not "
1342 phba_other->wwpn[0],
1343 phba_other->wwpn[1],
1344 phba_other->wwpn[2],
1345 phba_other->wwpn[3],
1346 phba_other->wwpn[4],
1347 phba_other->wwpn[5],
1348 phba_other->wwpn[6],
1349 phba_other->wwpn[7]);
1355 /* Issue PCI bus reset */
1356 res = pci_reset_bus(pdev);
1358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1359 "8350 PCI reset bus failed: %d\n", res);
1366 * lpfc_selective_reset - Offline then onlines the port
1367 * @phba: lpfc_hba pointer.
1370 * If the port is configured to allow a reset then the hba is brought
1371 * offline then online.
1374 * Assumes any error from lpfc_do_offline() will be negative.
1375 * Do not make this function static.
1378 * lpfc_do_offline() return code if not zero
1379 * -EIO reset not configured or error posting the event
1383 lpfc_selective_reset(struct lpfc_hba *phba)
1385 struct completion online_compl;
1389 if (!phba->cfg_enable_hba_reset)
1392 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1393 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1399 init_completion(&online_compl);
1400 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1405 wait_for_completion(&online_compl);
1414 * lpfc_issue_reset - Selectively resets an adapter
1415 * @dev: class device that is converted into a Scsi_host.
1416 * @attr: device attribute, not used.
1417 * @buf: containing the string "selective".
1418 * @count: unused variable.
1421 * If the buf contains the string "selective" then lpfc_selective_reset()
1422 * is called to perform the reset.
1425 * Assumes any error from lpfc_selective_reset() will be negative.
1426 * If lpfc_selective_reset() returns zero then the length of the buffer
1427 * is returned which indicates success
1430 * -EINVAL if the buffer does not contain the string "selective"
1431 * length of buf if lpfc-selective_reset() if the call succeeds
1432 * return value of lpfc_selective_reset() if the call fails
1435 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1436 const char *buf, size_t count)
1438 struct Scsi_Host *shost = class_to_shost(dev);
1439 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1440 struct lpfc_hba *phba = vport->phba;
1441 int status = -EINVAL;
1443 if (!phba->cfg_enable_hba_reset)
1446 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1447 status = phba->lpfc_selective_reset(phba);
1456 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1457 * @phba: lpfc_hba pointer.
1460 * SLI4 interface type-2 device to wait on the sliport status register for
1461 * the readyness after performing a firmware reset.
1464 * zero for success, -EPERM when port does not have privilege to perform the
1465 * reset, -EIO when port timeout from recovering from the reset.
1468 * As the caller will interpret the return code by value, be careful in making
1469 * change or addition to return codes.
1472 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1474 struct lpfc_register portstat_reg = {0};
1478 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1479 &portstat_reg.word0))
1482 /* verify if privileged for the request operation */
1483 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1484 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1487 /* wait for the SLI port firmware ready after firmware reset */
1488 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1490 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1491 &portstat_reg.word0))
1493 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1495 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1497 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1502 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1509 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1510 * @phba: lpfc_hba pointer.
1513 * Request SLI4 interface type-2 device to perform a physical register set
1520 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1522 struct completion online_compl;
1523 struct pci_dev *pdev = phba->pcidev;
1524 uint32_t before_fc_flag;
1525 uint32_t sriov_nr_virtfn;
1527 int status = 0, rc = 0;
1528 int job_posted = 1, sriov_err;
1530 if (!phba->cfg_enable_hba_reset)
1533 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1534 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1535 LPFC_SLI_INTF_IF_TYPE_2))
1538 /* Keep state if we need to restore back */
1539 before_fc_flag = phba->pport->fc_flag;
1540 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1542 /* Disable SR-IOV virtual functions if enabled */
1543 if (phba->cfg_sriov_nr_virtfn) {
1544 pci_disable_sriov(pdev);
1545 phba->cfg_sriov_nr_virtfn = 0;
1548 if (opcode == LPFC_FW_DUMP)
1549 phba->hba_flag |= HBA_FW_DUMP_OP;
1551 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1554 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1558 /* wait for the device to be quiesced before firmware reset */
1561 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1562 LPFC_CTL_PDEV_CTL_OFFSET);
1564 if (opcode == LPFC_FW_DUMP)
1565 reg_val |= LPFC_FW_DUMP_REQUEST;
1566 else if (opcode == LPFC_FW_RESET)
1567 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1568 else if (opcode == LPFC_DV_RESET)
1569 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1571 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1572 LPFC_CTL_PDEV_CTL_OFFSET);
1574 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1576 /* delay driver action following IF_TYPE_2 reset */
1577 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1580 /* no privilege for reset */
1581 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1582 "3150 No privilege to perform the requested "
1583 "access: x%x\n", reg_val);
1584 } else if (rc == -EIO) {
1585 /* reset failed, there is nothing more we can do */
1586 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1587 "3153 Fail to perform the requested "
1588 "access: x%x\n", reg_val);
1592 /* keep the original port state */
1593 if (before_fc_flag & FC_OFFLINE_MODE)
1596 init_completion(&online_compl);
1597 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1602 wait_for_completion(&online_compl);
1605 /* in any case, restore the virtual functions enabled as before */
1606 if (sriov_nr_virtfn) {
1608 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1610 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1613 /* return proper error code */
1624 * lpfc_nport_evt_cnt_show - Return the number of nport events
1625 * @dev: class device that is converted into a Scsi_host.
1626 * @attr: device attribute, not used.
1627 * @buf: on return contains the ascii number of nport events.
1629 * Returns: size of formatted string.
1632 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1635 struct Scsi_Host *shost = class_to_shost(dev);
1636 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1637 struct lpfc_hba *phba = vport->phba;
1639 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1643 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1645 LPFC_MBOXQ_t *mbox = NULL;
1646 unsigned long val = 0;
1650 if (!strncmp("enable", buff_out,
1651 strlen("enable"))) {
1652 pval = buff_out + strlen("enable") + 1;
1653 rc = kstrtoul(pval, 0, &val);
1655 return rc; /* Invalid number */
1656 } else if (!strncmp("disable", buff_out,
1657 strlen("disable"))) {
1660 return -EINVAL; /* Invalid command */
1665 val = 0x0; /* Disable */
1668 val = 0x1; /* Enable two port trunk */
1671 val = 0x2; /* Enable four port trunk */
1677 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1678 "0070 Set trunk mode with val %ld ", val);
1680 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1684 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1685 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1686 12, LPFC_SLI4_MBX_EMBED);
1688 bf_set(lpfc_mbx_set_trunk_mode,
1689 &mbox->u.mqe.un.set_trunk_mode,
1691 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1693 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1694 "0071 Set trunk mode failed with status: %d",
1696 if (rc != MBX_TIMEOUT)
1697 mempool_free(mbox, phba->mbox_mem_pool);
1703 * lpfc_board_mode_show - Return the state of the board
1704 * @dev: class device that is converted into a Scsi_host.
1705 * @attr: device attribute, not used.
1706 * @buf: on return contains the state of the adapter.
1708 * Returns: size of formatted string.
1711 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1714 struct Scsi_Host *shost = class_to_shost(dev);
1715 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1716 struct lpfc_hba *phba = vport->phba;
1719 if (phba->link_state == LPFC_HBA_ERROR)
1721 else if (phba->link_state == LPFC_WARM_START)
1722 state = "warm start";
1723 else if (phba->link_state == LPFC_INIT_START)
1728 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
1732 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1733 * @dev: class device that is converted into a Scsi_host.
1734 * @attr: device attribute, not used.
1735 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1736 * @count: unused variable.
1739 * -EACCES if enable hba reset not enabled
1740 * -EINVAL if the buffer does not contain a valid string (see above)
1741 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1742 * buf length greater than zero indicates success
1745 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1746 const char *buf, size_t count)
1748 struct Scsi_Host *shost = class_to_shost(dev);
1749 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1750 struct lpfc_hba *phba = vport->phba;
1751 struct completion online_compl;
1752 char *board_mode_str = NULL;
1756 if (!phba->cfg_enable_hba_reset) {
1758 goto board_mode_out;
1761 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1762 "3050 lpfc_board_mode set to %s\n", buf);
1764 init_completion(&online_compl);
1766 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1767 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1771 goto board_mode_out;
1773 wait_for_completion(&online_compl);
1776 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1777 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1778 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1779 if (phba->sli_rev == LPFC_SLI_REV4)
1782 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1783 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1784 if (phba->sli_rev == LPFC_SLI_REV4)
1787 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1788 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1789 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1790 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1791 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1792 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1793 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1794 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1796 status = lpfc_reset_pci_bus(phba);
1797 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1798 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
1806 board_mode_str = strchr(buf, '\n');
1808 *board_mode_str = '\0';
1809 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1810 "3097 Failed \"%s\", status(%d), "
1812 buf, status, phba->pport->fc_flag);
1818 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1819 * @phba: pointer to the adapter structure.
1820 * @mxri: max xri count.
1821 * @axri: available xri count.
1822 * @mrpi: max rpi count.
1823 * @arpi: available rpi count.
1824 * @mvpi: max vpi count.
1825 * @avpi: available vpi count.
1828 * If an integer pointer for an count is not null then the value for the
1829 * count is returned.
1836 lpfc_get_hba_info(struct lpfc_hba *phba,
1837 uint32_t *mxri, uint32_t *axri,
1838 uint32_t *mrpi, uint32_t *arpi,
1839 uint32_t *mvpi, uint32_t *avpi)
1841 struct lpfc_mbx_read_config *rd_config;
1842 LPFC_MBOXQ_t *pmboxq;
1848 * prevent udev from issuing mailbox commands until the port is
1851 if (phba->link_state < LPFC_LINK_DOWN ||
1852 !phba->mbox_mem_pool ||
1853 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1856 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1859 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1862 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1864 pmb = &pmboxq->u.mb;
1865 pmb->mbxCommand = MBX_READ_CONFIG;
1866 pmb->mbxOwner = OWN_HOST;
1867 pmboxq->ctx_buf = NULL;
1869 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1870 rc = MBX_NOT_FINISHED;
1872 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1874 if (rc != MBX_SUCCESS) {
1875 if (rc != MBX_TIMEOUT)
1876 mempool_free(pmboxq, phba->mbox_mem_pool);
1880 if (phba->sli_rev == LPFC_SLI_REV4) {
1881 rd_config = &pmboxq->u.mqe.un.rd_config;
1883 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1885 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1886 phba->sli4_hba.max_cfg_param.rpi_used;
1888 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1890 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1891 phba->sli4_hba.max_cfg_param.xri_used;
1893 /* Account for differences with SLI-3. Get vpi count from
1894 * mailbox data and subtract one for max vpi value.
1896 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1897 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1899 /* Limit the max we support */
1900 if (max_vpi > LPFC_MAX_VPI)
1901 max_vpi = LPFC_MAX_VPI;
1905 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1908 *mrpi = pmb->un.varRdConfig.max_rpi;
1910 *arpi = pmb->un.varRdConfig.avail_rpi;
1912 *mxri = pmb->un.varRdConfig.max_xri;
1914 *axri = pmb->un.varRdConfig.avail_xri;
1916 *mvpi = pmb->un.varRdConfig.max_vpi;
1918 /* avail_vpi is only valid if link is up and ready */
1919 if (phba->link_state == LPFC_HBA_READY)
1920 *avpi = pmb->un.varRdConfig.avail_vpi;
1922 *avpi = pmb->un.varRdConfig.max_vpi;
1926 mempool_free(pmboxq, phba->mbox_mem_pool);
1931 * lpfc_max_rpi_show - Return maximum rpi
1932 * @dev: class device that is converted into a Scsi_host.
1933 * @attr: device attribute, not used.
1934 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1937 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1938 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1939 * to "Unknown" and the buffer length is returned, therefore the caller
1940 * must check for "Unknown" in the buffer to detect a failure.
1942 * Returns: size of formatted string.
1945 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1948 struct Scsi_Host *shost = class_to_shost(dev);
1949 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1950 struct lpfc_hba *phba = vport->phba;
1953 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1954 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
1955 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1959 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1960 * @dev: class device that is converted into a Scsi_host.
1961 * @attr: device attribute, not used.
1962 * @buf: containing the used rpi count in decimal or "Unknown".
1965 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1966 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1967 * to "Unknown" and the buffer length is returned, therefore the caller
1968 * must check for "Unknown" in the buffer to detect a failure.
1970 * Returns: size of formatted string.
1973 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1976 struct Scsi_Host *shost = class_to_shost(dev);
1977 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1978 struct lpfc_hba *phba = vport->phba;
1981 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1982 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1983 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1987 * lpfc_max_xri_show - Return maximum xri
1988 * @dev: class device that is converted into a Scsi_host.
1989 * @attr: device attribute, not used.
1990 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1993 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1994 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1995 * to "Unknown" and the buffer length is returned, therefore the caller
1996 * must check for "Unknown" in the buffer to detect a failure.
1998 * Returns: size of formatted string.
2001 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
2004 struct Scsi_Host *shost = class_to_shost(dev);
2005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2006 struct lpfc_hba *phba = vport->phba;
2009 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2010 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2011 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2015 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2016 * @dev: class device that is converted into a Scsi_host.
2017 * @attr: device attribute, not used.
2018 * @buf: on return contains the used xri count in decimal or "Unknown".
2021 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2022 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2023 * to "Unknown" and the buffer length is returned, therefore the caller
2024 * must check for "Unknown" in the buffer to detect a failure.
2026 * Returns: size of formatted string.
2029 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2032 struct Scsi_Host *shost = class_to_shost(dev);
2033 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2034 struct lpfc_hba *phba = vport->phba;
2037 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2038 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2039 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2043 * lpfc_max_vpi_show - Return maximum vpi
2044 * @dev: class device that is converted into a Scsi_host.
2045 * @attr: device attribute, not used.
2046 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2049 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2050 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2051 * to "Unknown" and the buffer length is returned, therefore the caller
2052 * must check for "Unknown" in the buffer to detect a failure.
2054 * Returns: size of formatted string.
2057 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2060 struct Scsi_Host *shost = class_to_shost(dev);
2061 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2062 struct lpfc_hba *phba = vport->phba;
2065 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2066 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2067 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2071 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2072 * @dev: class device that is converted into a Scsi_host.
2073 * @attr: device attribute, not used.
2074 * @buf: on return contains the used vpi count in decimal or "Unknown".
2077 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2078 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2079 * to "Unknown" and the buffer length is returned, therefore the caller
2080 * must check for "Unknown" in the buffer to detect a failure.
2082 * Returns: size of formatted string.
2085 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2088 struct Scsi_Host *shost = class_to_shost(dev);
2089 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2090 struct lpfc_hba *phba = vport->phba;
2093 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2094 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2095 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2099 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2100 * @dev: class device that is converted into a Scsi_host.
2101 * @attr: device attribute, not used.
2102 * @buf: text that must be interpreted to determine if npiv is supported.
2105 * Buffer will contain text indicating npiv is not suppoerted on the port,
2106 * the port is an NPIV physical port, or it is an npiv virtual port with
2107 * the id of the vport.
2109 * Returns: size of formatted string.
2112 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2115 struct Scsi_Host *shost = class_to_shost(dev);
2116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2117 struct lpfc_hba *phba = vport->phba;
2119 if (!(phba->max_vpi))
2120 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2121 if (vport->port_type == LPFC_PHYSICAL_PORT)
2122 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2123 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2127 * lpfc_poll_show - Return text about poll support for the adapter
2128 * @dev: class device that is converted into a Scsi_host.
2129 * @attr: device attribute, not used.
2130 * @buf: on return contains the cfg_poll in hex.
2133 * cfg_poll should be a lpfc_polling_flags type.
2135 * Returns: size of formatted string.
2138 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2141 struct Scsi_Host *shost = class_to_shost(dev);
2142 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2143 struct lpfc_hba *phba = vport->phba;
2145 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2149 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2150 * @dev: class device that is converted into a Scsi_host.
2151 * @attr: device attribute, not used.
2152 * @buf: one or more lpfc_polling_flags values.
2156 * buf contents converted to integer and checked for a valid value.
2159 * -EINVAL if the buffer connot be converted or is out of range
2160 * length of the buf on success
2163 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2164 const char *buf, size_t count)
2166 struct Scsi_Host *shost = class_to_shost(dev);
2167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2168 struct lpfc_hba *phba = vport->phba;
2173 if (!isdigit(buf[0]))
2176 if (sscanf(buf, "%i", &val) != 1)
2179 if ((val & 0x3) != val)
2182 if (phba->sli_rev == LPFC_SLI_REV4)
2185 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2186 "3051 lpfc_poll changed from %d to %d\n",
2187 phba->cfg_poll, val);
2189 spin_lock_irq(&phba->hbalock);
2191 old_val = phba->cfg_poll;
2193 if (val & ENABLE_FCP_RING_POLLING) {
2194 if ((val & DISABLE_FCP_RING_INT) &&
2195 !(old_val & DISABLE_FCP_RING_INT)) {
2196 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2197 spin_unlock_irq(&phba->hbalock);
2200 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2201 writel(creg_val, phba->HCregaddr);
2202 readl(phba->HCregaddr); /* flush */
2204 lpfc_poll_start_timer(phba);
2206 } else if (val != 0x0) {
2207 spin_unlock_irq(&phba->hbalock);
2211 if (!(val & DISABLE_FCP_RING_INT) &&
2212 (old_val & DISABLE_FCP_RING_INT))
2214 spin_unlock_irq(&phba->hbalock);
2215 del_timer(&phba->fcp_poll_timer);
2216 spin_lock_irq(&phba->hbalock);
2217 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2218 spin_unlock_irq(&phba->hbalock);
2221 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2222 writel(creg_val, phba->HCregaddr);
2223 readl(phba->HCregaddr); /* flush */
2226 phba->cfg_poll = val;
2228 spin_unlock_irq(&phba->hbalock);
2234 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2235 * @dev: class converted to a Scsi_host structure.
2236 * @attr: device attribute, not used.
2237 * @buf: on return contains the formatted support level.
2240 * Returns the maximum number of virtual functions a physical function can
2241 * support, 0 will be returned if called on virtual function.
2243 * Returns: size of formatted string.
2246 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2247 struct device_attribute *attr,
2250 struct Scsi_Host *shost = class_to_shost(dev);
2251 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2252 struct lpfc_hba *phba = vport->phba;
2253 uint16_t max_nr_virtfn;
2255 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2256 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2259 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2261 return val >= min && val <= max;
2265 * lpfc_enable_bbcr_set: Sets an attribute value.
2266 * @phba: pointer the the adapter structure.
2267 * @val: integer attribute value.
2270 * Validates the min and max values then sets the
2271 * adapter config field if in the valid range. prints error message
2272 * and does not set the parameter if invalid.
2276 * -EINVAL if val is invalid
2279 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2281 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2282 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2283 "3068 %s_enable_bbcr changed from %d to %d\n",
2284 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
2285 phba->cfg_enable_bbcr = val;
2288 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2289 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2290 LPFC_DRIVER_NAME, val);
2295 * lpfc_param_show - Return a cfg attribute value in decimal
2298 * Macro that given an attr e.g. hba_queue_depth expands
2299 * into a function with the name lpfc_hba_queue_depth_show.
2301 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2302 * @dev: class device that is converted into a Scsi_host.
2303 * @attr: device attribute, not used.
2304 * @buf: on return contains the attribute value in decimal.
2306 * Returns: size of formatted string.
2308 #define lpfc_param_show(attr) \
2310 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2313 struct Scsi_Host *shost = class_to_shost(dev);\
2314 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2315 struct lpfc_hba *phba = vport->phba;\
2316 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2321 * lpfc_param_hex_show - Return a cfg attribute value in hex
2324 * Macro that given an attr e.g. hba_queue_depth expands
2325 * into a function with the name lpfc_hba_queue_depth_show
2327 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2328 * @dev: class device that is converted into a Scsi_host.
2329 * @attr: device attribute, not used.
2330 * @buf: on return contains the attribute value in hexadecimal.
2332 * Returns: size of formatted string.
2334 #define lpfc_param_hex_show(attr) \
2336 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2339 struct Scsi_Host *shost = class_to_shost(dev);\
2340 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2341 struct lpfc_hba *phba = vport->phba;\
2343 val = phba->cfg_##attr;\
2344 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2349 * lpfc_param_init - Initializes a cfg attribute
2352 * Macro that given an attr e.g. hba_queue_depth expands
2353 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2354 * takes a default argument, a minimum and maximum argument.
2356 * lpfc_##attr##_init: Initializes an attribute.
2357 * @phba: pointer the the adapter structure.
2358 * @val: integer attribute value.
2360 * Validates the min and max values then sets the adapter config field
2361 * accordingly, or uses the default if out of range and prints an error message.
2365 * -EINVAL if default used
2367 #define lpfc_param_init(attr, default, minval, maxval) \
2369 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2371 if (lpfc_rangecheck(val, minval, maxval)) {\
2372 phba->cfg_##attr = val;\
2375 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2376 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2377 "allowed range is ["#minval", "#maxval"]\n", val); \
2378 phba->cfg_##attr = default;\
2383 * lpfc_param_set - Set a cfg attribute value
2386 * Macro that given an attr e.g. hba_queue_depth expands
2387 * into a function with the name lpfc_hba_queue_depth_set
2389 * lpfc_##attr##_set: Sets an attribute value.
2390 * @phba: pointer the the adapter structure.
2391 * @val: integer attribute value.
2394 * Validates the min and max values then sets the
2395 * adapter config field if in the valid range. prints error message
2396 * and does not set the parameter if invalid.
2400 * -EINVAL if val is invalid
2402 #define lpfc_param_set(attr, default, minval, maxval) \
2404 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2406 if (lpfc_rangecheck(val, minval, maxval)) {\
2407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2408 "3052 lpfc_" #attr " changed from %d to %d\n", \
2409 phba->cfg_##attr, val); \
2410 phba->cfg_##attr = val;\
2413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2414 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2415 "allowed range is ["#minval", "#maxval"]\n", val); \
2420 * lpfc_param_store - Set a vport attribute value
2423 * Macro that given an attr e.g. hba_queue_depth expands
2424 * into a function with the name lpfc_hba_queue_depth_store.
2426 * lpfc_##attr##_store: Set an sttribute value.
2427 * @dev: class device that is converted into a Scsi_host.
2428 * @attr: device attribute, not used.
2429 * @buf: contains the attribute value in ascii.
2433 * Convert the ascii text number to an integer, then
2434 * use the lpfc_##attr##_set function to set the value.
2437 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2438 * length of buffer upon success.
2440 #define lpfc_param_store(attr) \
2442 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2443 const char *buf, size_t count) \
2445 struct Scsi_Host *shost = class_to_shost(dev);\
2446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2447 struct lpfc_hba *phba = vport->phba;\
2449 if (!isdigit(buf[0]))\
2451 if (sscanf(buf, "%i", &val) != 1)\
2453 if (lpfc_##attr##_set(phba, val) == 0) \
2454 return strlen(buf);\
2460 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2463 * Macro that given an attr e.g. hba_queue_depth expands
2464 * into a function with the name lpfc_hba_queue_depth_show
2466 * lpfc_##attr##_show: prints the attribute value in decimal.
2467 * @dev: class device that is converted into a Scsi_host.
2468 * @attr: device attribute, not used.
2469 * @buf: on return contains the attribute value in decimal.
2471 * Returns: length of formatted string.
2473 #define lpfc_vport_param_show(attr) \
2475 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2478 struct Scsi_Host *shost = class_to_shost(dev);\
2479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2480 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2484 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2487 * Macro that given an attr e.g.
2488 * hba_queue_depth expands into a function with the name
2489 * lpfc_hba_queue_depth_show
2491 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2492 * @dev: class device that is converted into a Scsi_host.
2493 * @attr: device attribute, not used.
2494 * @buf: on return contains the attribute value in hexadecimal.
2496 * Returns: length of formatted string.
2498 #define lpfc_vport_param_hex_show(attr) \
2500 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2503 struct Scsi_Host *shost = class_to_shost(dev);\
2504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2505 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2509 * lpfc_vport_param_init - Initialize a vport cfg attribute
2512 * Macro that given an attr e.g. hba_queue_depth expands
2513 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2514 * takes a default argument, a minimum and maximum argument.
2516 * lpfc_##attr##_init: validates the min and max values then sets the
2517 * adapter config field accordingly, or uses the default if out of range
2518 * and prints an error message.
2519 * @phba: pointer the the adapter structure.
2520 * @val: integer attribute value.
2524 * -EINVAL if default used
2526 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2528 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2530 if (lpfc_rangecheck(val, minval, maxval)) {\
2531 vport->cfg_##attr = val;\
2534 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2535 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2536 "allowed range is ["#minval", "#maxval"]\n", val); \
2537 vport->cfg_##attr = default;\
2542 * lpfc_vport_param_set - Set a vport cfg attribute
2545 * Macro that given an attr e.g. hba_queue_depth expands
2546 * into a function with the name lpfc_hba_queue_depth_set
2548 * lpfc_##attr##_set: validates the min and max values then sets the
2549 * adapter config field if in the valid range. prints error message
2550 * and does not set the parameter if invalid.
2551 * @phba: pointer the the adapter structure.
2552 * @val: integer attribute value.
2556 * -EINVAL if val is invalid
2558 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2560 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2562 if (lpfc_rangecheck(val, minval, maxval)) {\
2563 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2564 "3053 lpfc_" #attr \
2565 " changed from %d (x%x) to %d (x%x)\n", \
2566 vport->cfg_##attr, vport->cfg_##attr, \
2568 vport->cfg_##attr = val;\
2571 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2572 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2573 "allowed range is ["#minval", "#maxval"]\n", val); \
2578 * lpfc_vport_param_store - Set a vport attribute
2581 * Macro that given an attr e.g. hba_queue_depth
2582 * expands into a function with the name lpfc_hba_queue_depth_store
2584 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2585 * use the lpfc_##attr##_set function to set the value.
2586 * @cdev: class device that is converted into a Scsi_host.
2587 * @buf: contains the attribute value in decimal.
2591 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2592 * length of buffer upon success.
2594 #define lpfc_vport_param_store(attr) \
2596 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2597 const char *buf, size_t count) \
2599 struct Scsi_Host *shost = class_to_shost(dev);\
2600 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2602 if (!isdigit(buf[0]))\
2604 if (sscanf(buf, "%i", &val) != 1)\
2606 if (lpfc_##attr##_set(vport, val) == 0) \
2607 return strlen(buf);\
2613 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2614 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2615 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2616 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2617 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2618 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2619 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2620 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2621 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2622 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2623 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2624 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2625 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2626 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2627 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2628 lpfc_link_state_store);
2629 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2630 lpfc_option_rom_version_show, NULL);
2631 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2632 lpfc_num_discovered_ports_show, NULL);
2633 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2634 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2635 static DEVICE_ATTR_RO(lpfc_drvr_version);
2636 static DEVICE_ATTR_RO(lpfc_enable_fip);
2637 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2638 lpfc_board_mode_show, lpfc_board_mode_store);
2639 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2640 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2641 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2642 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2643 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2644 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2645 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2646 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2647 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2648 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2649 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2650 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2653 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2656 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2658 * @cnt: Length of string.
2659 * @wwn: Array to receive converted wwn value.
2662 * -EINVAL if the buffer does not contain a valid wwn
2666 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2670 /* Count may include a LF at end of string */
2671 if (buf[cnt-1] == '\n')
2674 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2675 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2678 memset(wwn, 0, WWN_SZ);
2680 /* Validate and store the new name */
2681 for (i = 0, j = 0; i < 16; i++) {
2682 if ((*buf >= 'a') && (*buf <= 'f'))
2683 j = ((j << 4) | ((*buf++ - 'a') + 10));
2684 else if ((*buf >= 'A') && (*buf <= 'F'))
2685 j = ((j << 4) | ((*buf++ - 'A') + 10));
2686 else if ((*buf >= '0') && (*buf <= '9'))
2687 j = ((j << 4) | (*buf++ - '0'));
2691 wwn[i/2] = j & 0xff;
2698 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2699 * @dev: class device that is converted into a Scsi_host.
2700 * @attr: device attribute, not used.
2701 * @buf: containing the string lpfc_soft_wwn_key.
2702 * @count: must be size of lpfc_soft_wwn_key.
2705 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2706 * length of buf indicates success
2709 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2710 const char *buf, size_t count)
2712 struct Scsi_Host *shost = class_to_shost(dev);
2713 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2714 struct lpfc_hba *phba = vport->phba;
2715 unsigned int cnt = count;
2716 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2717 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2720 * We're doing a simple sanity check for soft_wwpn setting.
2721 * We require that the user write a specific key to enable
2722 * the soft_wwpn attribute to be settable. Once the attribute
2723 * is written, the enable key resets. If further updates are
2724 * desired, the key must be written again to re-enable the
2727 * The "key" is not secret - it is a hardcoded string shown
2728 * here. The intent is to protect against the random user or
2729 * application that is just writing attributes.
2731 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2732 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2733 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2734 " be enabled: fawwpn is enabled\n");
2738 /* count may include a LF at end of string */
2739 if (buf[cnt-1] == '\n')
2742 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2743 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2746 phba->soft_wwn_enable = 1;
2748 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2749 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2751 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2752 " The soft_wwpn feature is not supported by Broadcom.");
2756 static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
2759 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2760 * @dev: class device that is converted into a Scsi_host.
2761 * @attr: device attribute, not used.
2762 * @buf: on return contains the wwpn in hexadecimal.
2764 * Returns: size of formatted string.
2767 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2770 struct Scsi_Host *shost = class_to_shost(dev);
2771 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2772 struct lpfc_hba *phba = vport->phba;
2774 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2775 (unsigned long long)phba->cfg_soft_wwpn);
2779 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2780 * @dev class device that is converted into a Scsi_host.
2781 * @attr: device attribute, not used.
2782 * @buf: contains the wwpn in hexadecimal.
2783 * @count: number of wwpn bytes in buf
2786 * -EACCES hba reset not enabled, adapter over temp
2787 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2788 * -EIO error taking adapter offline or online
2789 * value of count on success
2792 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2793 const char *buf, size_t count)
2795 struct Scsi_Host *shost = class_to_shost(dev);
2796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2797 struct lpfc_hba *phba = vport->phba;
2798 struct completion online_compl;
2799 int stat1 = 0, stat2 = 0;
2800 unsigned int cnt = count;
2804 if (!phba->cfg_enable_hba_reset)
2806 spin_lock_irq(&phba->hbalock);
2807 if (phba->over_temp_state == HBA_OVER_TEMP) {
2808 spin_unlock_irq(&phba->hbalock);
2811 spin_unlock_irq(&phba->hbalock);
2812 /* count may include a LF at end of string */
2813 if (buf[cnt-1] == '\n')
2816 if (!phba->soft_wwn_enable)
2819 /* lock setting wwpn, wwnn down */
2820 phba->soft_wwn_enable = 0;
2822 rc = lpfc_wwn_set(buf, cnt, wwpn);
2824 /* not able to set wwpn, unlock it */
2825 phba->soft_wwn_enable = 1;
2829 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2830 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2831 if (phba->cfg_soft_wwnn)
2832 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2834 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2835 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2837 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2839 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2840 "0463 lpfc_soft_wwpn attribute set failed to "
2841 "reinit adapter - %d\n", stat1);
2842 init_completion(&online_compl);
2843 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2848 wait_for_completion(&online_compl);
2850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2851 "0464 lpfc_soft_wwpn attribute set failed to "
2852 "reinit adapter - %d\n", stat2);
2853 return (stat1 || stat2) ? -EIO : count;
2855 static DEVICE_ATTR_RW(lpfc_soft_wwpn);
2858 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2859 * @dev: class device that is converted into a Scsi_host.
2860 * @attr: device attribute, not used.
2861 * @buf: on return contains the wwnn in hexadecimal.
2863 * Returns: size of formatted string.
2866 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2869 struct Scsi_Host *shost = class_to_shost(dev);
2870 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2871 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2872 (unsigned long long)phba->cfg_soft_wwnn);
2876 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2877 * @cdev: class device that is converted into a Scsi_host.
2878 * @buf: contains the ww node name in hexadecimal.
2879 * @count: number of wwnn bytes in buf.
2882 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2883 * value of count on success
2886 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2887 const char *buf, size_t count)
2889 struct Scsi_Host *shost = class_to_shost(dev);
2890 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2891 unsigned int cnt = count;
2895 /* count may include a LF at end of string */
2896 if (buf[cnt-1] == '\n')
2899 if (!phba->soft_wwn_enable)
2902 rc = lpfc_wwn_set(buf, cnt, wwnn);
2904 /* Allow wwnn to be set many times, as long as the enable
2905 * is set. However, once the wwpn is set, everything locks.
2910 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2912 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2913 "lpfc%d: soft_wwnn set. Value will take effect upon "
2914 "setting of the soft_wwpn\n", phba->brd_no);
2918 static DEVICE_ATTR_RW(lpfc_soft_wwnn);
2921 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2922 * Optimized Access Storage (OAS) operations.
2923 * @dev: class device that is converted into a Scsi_host.
2924 * @attr: device attribute, not used.
2925 * @buf: buffer for passing information.
2931 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2934 struct Scsi_Host *shost = class_to_shost(dev);
2935 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2937 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2938 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2942 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2943 * Optimized Access Storage (OAS) operations.
2944 * @dev: class device that is converted into a Scsi_host.
2945 * @attr: device attribute, not used.
2946 * @buf: buffer for passing information.
2947 * @count: Size of the data buffer.
2950 * -EINVAL count is invalid, invalid wwpn byte invalid
2951 * -EPERM oas is not supported by hba
2952 * value of count on success
2955 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2956 const char *buf, size_t count)
2958 struct Scsi_Host *shost = class_to_shost(dev);
2959 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2960 unsigned int cnt = count;
2961 uint8_t wwpn[WWN_SZ];
2967 /* count may include a LF at end of string */
2968 if (buf[cnt-1] == '\n')
2971 rc = lpfc_wwn_set(buf, cnt, wwpn);
2975 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2976 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2977 if (wwn_to_u64(wwpn) == 0)
2978 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2980 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2981 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2982 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2985 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2986 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2989 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2990 * Optimized Access Storage (OAS) operations.
2991 * @dev: class device that is converted into a Scsi_host.
2992 * @attr: device attribute, not used.
2993 * @buf: buffer for passing information.
2999 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3002 struct Scsi_Host *shost = class_to_shost(dev);
3003 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3005 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3009 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3010 * Optimized Access Storage (OAS) operations.
3011 * @dev: class device that is converted into a Scsi_host.
3012 * @attr: device attribute, not used.
3013 * @buf: buffer for passing information.
3014 * @count: Size of the data buffer.
3017 * -EINVAL count is invalid, invalid wwpn byte invalid
3018 * -EPERM oas is not supported by hba
3019 * value of count on success
3022 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3023 const char *buf, size_t count)
3025 struct Scsi_Host *shost = class_to_shost(dev);
3026 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3027 unsigned int cnt = count;
3034 /* count may include a LF at end of string */
3035 if (buf[cnt-1] == '\n')
3038 ret = kstrtoul(buf, 0, &val);
3039 if (ret || (val > 0x7f))
3043 phba->cfg_oas_priority = (uint8_t)val;
3045 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3048 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3049 lpfc_oas_priority_show, lpfc_oas_priority_store);
3052 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3053 * for Optimized Access Storage (OAS) operations.
3054 * @dev: class device that is converted into a Scsi_host.
3055 * @attr: device attribute, not used.
3056 * @buf: buffer for passing information.
3059 * value of count on success
3062 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3065 struct Scsi_Host *shost = class_to_shost(dev);
3066 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3068 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3069 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3073 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3074 * for Optimized Access Storage (OAS) operations.
3075 * @dev: class device that is converted into a Scsi_host.
3076 * @attr: device attribute, not used.
3077 * @buf: buffer for passing information.
3078 * @count: Size of the data buffer.
3081 * -EINVAL count is invalid, invalid wwpn byte invalid
3082 * -EPERM oas is not supported by hba
3083 * value of count on success
3086 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3087 const char *buf, size_t count)
3089 struct Scsi_Host *shost = class_to_shost(dev);
3090 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3091 unsigned int cnt = count;
3092 uint8_t wwpn[WWN_SZ];
3098 /* count may include a LF at end of string */
3099 if (buf[cnt-1] == '\n')
3102 rc = lpfc_wwn_set(buf, cnt, wwpn);
3106 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3107 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3108 if (wwn_to_u64(wwpn) == 0)
3109 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3111 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3112 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3113 if (phba->cfg_oas_priority == 0)
3114 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3115 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3118 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3119 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3122 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3123 * of whether luns will be enabled or disabled
3124 * for Optimized Access Storage (OAS) operations.
3125 * @dev: class device that is converted into a Scsi_host.
3126 * @attr: device attribute, not used.
3127 * @buf: buffer for passing information.
3130 * size of formatted string.
3133 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3136 struct Scsi_Host *shost = class_to_shost(dev);
3137 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3139 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3143 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3144 * of whether luns will be enabled or disabled
3145 * for Optimized Access Storage (OAS) operations.
3146 * @dev: class device that is converted into a Scsi_host.
3147 * @attr: device attribute, not used.
3148 * @buf: buffer for passing information.
3149 * @count: Size of the data buffer.
3152 * -EINVAL count is invalid, invalid wwpn byte invalid
3153 * -EPERM oas is not supported by hba
3154 * value of count on success
3157 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3158 const char *buf, size_t count)
3160 struct Scsi_Host *shost = class_to_shost(dev);
3161 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3167 if (!isdigit(buf[0]))
3170 if (sscanf(buf, "%i", &val) != 1)
3173 if ((val != 0) && (val != 1))
3176 phba->cfg_oas_lun_state = val;
3179 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3180 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3183 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3184 * Storage (OAS) lun returned by the
3185 * lpfc_oas_lun_show function.
3186 * @dev: class device that is converted into a Scsi_host.
3187 * @attr: device attribute, not used.
3188 * @buf: buffer for passing information.
3191 * size of formatted string.
3194 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3197 struct Scsi_Host *shost = class_to_shost(dev);
3198 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3200 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3203 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3205 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3206 lpfc_oas_lun_status_show, NULL);
3210 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3212 * @phba: lpfc_hba pointer.
3213 * @ndlp: pointer to fcp target node.
3214 * @lun: the fc lun for setting oas state.
3215 * @oas_state: the oas state to be set to the lun.
3219 * -EPERM OAS is not enabled or not supported by this port.
3223 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3224 uint8_t tgt_wwpn[], uint64_t lun,
3225 uint32_t oas_state, uint8_t pri)
3234 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3235 (struct lpfc_name *)tgt_wwpn,
3239 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3240 (struct lpfc_name *)tgt_wwpn, lun, pri);
3247 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3248 * Access Storage (OAS) operations.
3249 * @phba: lpfc_hba pointer.
3250 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3251 * @tgt_wwpn: wwpn of the target associated with the returned lun
3252 * @lun_status: status of the lun returned lun
3254 * Returns the first or next lun enabled for OAS operations for the vport/target
3255 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3256 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3259 * lun that is OAS enabled for the vport/target
3260 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3263 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3264 uint8_t tgt_wwpn[], uint32_t *lun_status,
3269 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3270 return NOT_OAS_ENABLED_LUN;
3271 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3272 phba->sli4_hba.oas_next_vpt_wwpn,
3273 (struct lpfc_name *)
3274 phba->sli4_hba.oas_next_tgt_wwpn,
3275 &phba->sli4_hba.oas_next_lun,
3276 (struct lpfc_name *)vpt_wwpn,
3277 (struct lpfc_name *)tgt_wwpn,
3278 &found_lun, lun_status, lun_pri))
3281 return NOT_OAS_ENABLED_LUN;
3285 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3286 * @phba: lpfc_hba pointer.
3287 * @vpt_wwpn: vport wwpn by reference.
3288 * @tgt_wwpn: target wwpn by reference.
3289 * @lun: the fc lun for setting oas state.
3290 * @oas_state: the oas state to be set to the oas_lun.
3292 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3293 * a lun for OAS operations.
3297 * -ENOMEM: failed to enable an lun for OAS operations
3298 * -EPERM: OAS is not enabled
3301 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3302 uint8_t tgt_wwpn[], uint64_t lun,
3303 uint32_t oas_state, uint8_t pri)
3308 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3314 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3315 * @dev: class device that is converted into a Scsi_host.
3316 * @attr: device attribute, not used.
3317 * @buf: buffer for passing information.
3319 * This routine returns a lun enabled for OAS each time the function
3323 * SUCCESS: size of formatted string.
3324 * -EFAULT: target or vport wwpn was not set properly.
3325 * -EPERM: oas is not enabled.
3328 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3331 struct Scsi_Host *shost = class_to_shost(dev);
3332 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3340 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3341 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3344 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3345 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3348 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3349 phba->cfg_oas_tgt_wwpn,
3350 &phba->cfg_oas_lun_status,
3351 &phba->cfg_oas_priority);
3352 if (oas_lun != NOT_OAS_ENABLED_LUN)
3353 phba->cfg_oas_flags |= OAS_LUN_VALID;
3355 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3361 * lpfc_oas_lun_store - Sets the OAS state for lun
3362 * @dev: class device that is converted into a Scsi_host.
3363 * @attr: device attribute, not used.
3364 * @buf: buffer for passing information.
3366 * This function sets the OAS state for lun. Before this function is called,
3367 * the vport wwpn, target wwpn, and oas state need to be set.
3370 * SUCCESS: size of formatted string.
3371 * -EFAULT: target or vport wwpn was not set properly.
3372 * -EPERM: oas is not enabled.
3373 * size of formatted string.
3376 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3377 const char *buf, size_t count)
3379 struct Scsi_Host *shost = class_to_shost(dev);
3380 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3388 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3391 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3394 if (!isdigit(buf[0]))
3397 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3400 pri = phba->cfg_oas_priority;
3402 pri = phba->cfg_XLanePriority;
3404 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3405 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3406 "priority 0x%x with oas state %d\n",
3407 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3408 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3409 pri, phba->cfg_oas_lun_state);
3411 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3412 phba->cfg_oas_tgt_wwpn, scsi_lun,
3413 phba->cfg_oas_lun_state, pri);
3419 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3420 lpfc_oas_lun_show, lpfc_oas_lun_store);
3422 int lpfc_enable_nvmet_cnt;
3423 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3424 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3425 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3426 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3427 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3429 static int lpfc_poll = 0;
3430 module_param(lpfc_poll, int, S_IRUGO);
3431 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3433 " 1 - poll with interrupts enabled"
3434 " 3 - poll and disable FCP ring interrupts");
3436 static DEVICE_ATTR_RW(lpfc_poll);
3438 int lpfc_no_hba_reset_cnt;
3439 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3440 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3441 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3442 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3444 LPFC_ATTR(sli_mode, 0, 0, 3,
3445 "SLI mode selector:"
3446 " 0 - auto (SLI-3 if supported),"
3447 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3448 " 3 - select SLI-3");
3450 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3451 "Enable NPIV functionality");
3453 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3454 "FCF Fast failover=1 Priority failover=2");
3457 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3458 # 0x0 = disabled, XRI/OXID use not tracked.
3459 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3460 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3462 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3463 "Enable RRQ functionality");
3466 # lpfc_suppress_link_up: Bring link up at initialization
3467 # 0x0 = bring link up (issue MBX_INIT_LINK)
3468 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3469 # 0x2 = never bring up link
3470 # Default value is 0.
3472 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3473 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3474 "Suppress Link Up at initialization");
3477 lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3479 struct Scsi_Host *shost = class_to_shost(dev);
3480 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3482 return scnprintf(buf, PAGE_SIZE, "%d\n",
3483 phba->sli4_hba.pc_sli4_params.pls);
3485 static DEVICE_ATTR(pls, 0444,
3486 lpfc_pls_show, NULL);
3489 lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3491 struct Scsi_Host *shost = class_to_shost(dev);
3492 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3494 return scnprintf(buf, PAGE_SIZE, "%d\n",
3495 (phba->hba_flag & HBA_PERSISTENT_TOPO) ? 1 : 0);
3497 static DEVICE_ATTR(pt, 0444,
3498 lpfc_pt_show, NULL);
3501 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3509 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3511 struct Scsi_Host *shost = class_to_shost(dev);
3512 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3514 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3517 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3518 lpfc_iocb_hw_show, NULL);
3520 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3522 struct Scsi_Host *shost = class_to_shost(dev);
3523 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3524 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3526 return scnprintf(buf, PAGE_SIZE, "%d\n",
3527 pring ? pring->txq_max : 0);
3530 static DEVICE_ATTR(txq_hw, S_IRUGO,
3531 lpfc_txq_hw_show, NULL);
3533 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3536 struct Scsi_Host *shost = class_to_shost(dev);
3537 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3538 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3540 return scnprintf(buf, PAGE_SIZE, "%d\n",
3541 pring ? pring->txcmplq_max : 0);
3544 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3545 lpfc_txcmplq_hw_show, NULL);
3548 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3549 # until the timer expires. Value range is [0,255]. Default value is 30.
3551 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3552 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3553 module_param(lpfc_nodev_tmo, int, 0);
3554 MODULE_PARM_DESC(lpfc_nodev_tmo,
3555 "Seconds driver will hold I/O waiting "
3556 "for a device to come back");
3559 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3560 * @dev: class converted to a Scsi_host structure.
3561 * @attr: device attribute, not used.
3562 * @buf: on return contains the dev loss timeout in decimal.
3564 * Returns: size of formatted string.
3567 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3570 struct Scsi_Host *shost = class_to_shost(dev);
3571 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3573 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3577 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3578 * @vport: lpfc vport structure pointer.
3579 * @val: contains the nodev timeout value.
3582 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3583 * a kernel error message is printed and zero is returned.
3584 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3585 * Otherwise nodev tmo is set to the default value.
3588 * zero if already set or if val is in range
3589 * -EINVAL val out of range
3592 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3594 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3595 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3596 if (val != LPFC_DEF_DEVLOSS_TMO)
3597 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3598 "0407 Ignoring lpfc_nodev_tmo module "
3599 "parameter because lpfc_devloss_tmo "
3604 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3605 vport->cfg_nodev_tmo = val;
3606 vport->cfg_devloss_tmo = val;
3609 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3610 "0400 lpfc_nodev_tmo attribute cannot be set to"
3611 " %d, allowed range is [%d, %d]\n",
3612 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3613 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3618 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3619 * @vport: lpfc vport structure pointer.
3622 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3625 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3627 struct Scsi_Host *shost;
3628 struct lpfc_nodelist *ndlp;
3629 #if (IS_ENABLED(CONFIG_NVME_FC))
3630 struct lpfc_nvme_rport *rport;
3631 struct nvme_fc_remote_port *remoteport = NULL;
3634 shost = lpfc_shost_from_vport(vport);
3635 spin_lock_irq(shost->host_lock);
3636 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3637 if (!NLP_CHK_NODE_ACT(ndlp))
3640 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3641 #if (IS_ENABLED(CONFIG_NVME_FC))
3642 spin_lock(&vport->phba->hbalock);
3643 rport = lpfc_ndlp_get_nrport(ndlp);
3645 remoteport = rport->remoteport;
3646 spin_unlock(&vport->phba->hbalock);
3647 if (rport && remoteport)
3648 nvme_fc_set_remoteport_devloss(remoteport,
3649 vport->cfg_devloss_tmo);
3652 spin_unlock_irq(shost->host_lock);
3656 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3657 * @vport: lpfc vport structure pointer.
3658 * @val: contains the tmo value.
3661 * If the devloss tmo is already set or the vport dev loss tmo has changed
3662 * then a kernel error message is printed and zero is returned.
3663 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3664 * Otherwise nodev tmo is set to the default value.
3667 * zero if already set or if val is in range
3668 * -EINVAL val out of range
3671 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3673 if (vport->dev_loss_tmo_changed ||
3674 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3675 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3676 "0401 Ignoring change to lpfc_nodev_tmo "
3677 "because lpfc_devloss_tmo is set.\n");
3680 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3681 vport->cfg_nodev_tmo = val;
3682 vport->cfg_devloss_tmo = val;
3684 * For compat: set the fc_host dev loss so new rports
3685 * will get the value.
3687 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3688 lpfc_update_rport_devloss_tmo(vport);
3691 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3692 "0403 lpfc_nodev_tmo attribute cannot be set to "
3693 "%d, allowed range is [%d, %d]\n",
3694 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3698 lpfc_vport_param_store(nodev_tmo)
3700 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3703 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3704 # disappear until the timer expires. Value range is [0,255]. Default
3707 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3708 MODULE_PARM_DESC(lpfc_devloss_tmo,
3709 "Seconds driver will hold I/O waiting "
3710 "for a device to come back");
3711 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3712 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3713 lpfc_vport_param_show(devloss_tmo)
3716 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3717 * @vport: lpfc vport structure pointer.
3718 * @val: contains the tmo value.
3721 * If val is in a valid range then set the vport nodev tmo,
3722 * devloss tmo, also set the vport dev loss tmo changed flag.
3723 * Else a kernel error message is printed.
3726 * zero if val is in range
3727 * -EINVAL val out of range
3730 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3732 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3733 vport->cfg_nodev_tmo = val;
3734 vport->cfg_devloss_tmo = val;
3735 vport->dev_loss_tmo_changed = 1;
3736 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3737 lpfc_update_rport_devloss_tmo(vport);
3741 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3742 "0404 lpfc_devloss_tmo attribute cannot be set to "
3743 "%d, allowed range is [%d, %d]\n",
3744 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3748 lpfc_vport_param_store(devloss_tmo)
3749 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3752 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3753 * lpfc_suppress_rsp = 0 Disable
3754 * lpfc_suppress_rsp = 1 Enable (default)
3757 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3758 "Enable suppress rsp feature is firmware supports it");
3761 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3762 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3763 * lpfc_nvmet_mrq = 1 use a single RQ pair
3764 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3767 LPFC_ATTR_R(nvmet_mrq,
3768 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3769 "Specify number of RQ pairs for processing NVMET cmds");
3772 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3773 * to each NVMET RQ. Range 64 to 2048, default is 512.
3775 LPFC_ATTR_R(nvmet_mrq_post,
3776 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3777 LPFC_NVMET_RQE_DEF_COUNT,
3778 "Specify number of RQ buffers to initially post");
3781 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3782 * Supported Values: 1 - register just FCP
3783 * 3 - register both FCP and NVME
3784 * Supported values are [1,3]. Default value is 3
3786 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3787 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3788 "Enable FC4 Protocol support - FCP / NVME");
3791 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3792 # deluged with LOTS of information.
3793 # You can set a bit mask to record specific types of verbose messages:
3794 # See lpfc_logmsh.h for definitions.
3796 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3797 "Verbose logging bit-mask");
3800 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3801 # objects that have been registered with the nameserver after login.
3803 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3804 "Deregister nameserver objects before LOGO");
3807 # lun_queue_depth: This parameter is used to limit the number of outstanding
3808 # commands per FCP LUN.
3810 LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
3811 "Max number of FCP commands we can queue to a specific LUN");
3814 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3815 # commands per target port. Value range is [10,65535]. Default value is 65535.
3817 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3818 module_param(lpfc_tgt_queue_depth, uint, 0444);
3819 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3820 lpfc_vport_param_show(tgt_queue_depth);
3821 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3822 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3825 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3826 * @phba: pointer the the adapter structure.
3827 * @val: integer attribute value.
3829 * Description: Sets the parameter to the new value.
3833 * -EINVAL if val is invalid
3836 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3838 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3839 struct lpfc_nodelist *ndlp;
3841 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3844 if (val == vport->cfg_tgt_queue_depth)
3847 spin_lock_irq(shost->host_lock);
3848 vport->cfg_tgt_queue_depth = val;
3850 /* Next loop thru nodelist and change cmd_qdepth */
3851 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3852 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3854 spin_unlock_irq(shost->host_lock);
3858 lpfc_vport_param_store(tgt_queue_depth);
3859 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3862 # hba_queue_depth: This parameter is used to limit the number of outstanding
3863 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3864 # value is greater than the maximum number of exchanges supported by the HBA,
3865 # then maximum number of exchanges supported by the HBA is used to determine
3866 # the hba_queue_depth.
3868 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3869 "Max number of FCP commands we can queue to a lpfc HBA");
3872 # peer_port_login: This parameter allows/prevents logins
3873 # between peer ports hosted on the same physical port.
3874 # When this parameter is set 0 peer ports of same physical port
3875 # are not allowed to login to each other.
3876 # When this parameter is set 1 peer ports of same physical port
3877 # are allowed to login to each other.
3878 # Default value of this parameter is 0.
3880 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3881 "Allow peer ports on the same physical port to login to each "
3885 # restrict_login: This parameter allows/prevents logins
3886 # between Virtual Ports and remote initiators.
3887 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3888 # other initiators and will attempt to PLOGI all remote ports.
3889 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3890 # remote ports and will not attempt to PLOGI to other initiators.
3891 # This parameter does not restrict to the physical port.
3892 # This parameter does not restrict logins to Fabric resident remote ports.
3893 # Default value of this parameter is 1.
3895 static int lpfc_restrict_login = 1;
3896 module_param(lpfc_restrict_login, int, S_IRUGO);
3897 MODULE_PARM_DESC(lpfc_restrict_login,
3898 "Restrict virtual ports login to remote initiators.");
3899 lpfc_vport_param_show(restrict_login);
3902 * lpfc_restrict_login_init - Set the vport restrict login flag
3903 * @vport: lpfc vport structure pointer.
3904 * @val: contains the restrict login value.
3907 * If val is not in a valid range then log a kernel error message and set
3908 * the vport restrict login to one.
3909 * If the port type is physical clear the restrict login flag and return.
3910 * Else set the restrict login flag to val.
3913 * zero if val is in range
3914 * -EINVAL val out of range
3917 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3919 if (val < 0 || val > 1) {
3920 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3921 "0422 lpfc_restrict_login attribute cannot "
3922 "be set to %d, allowed range is [0, 1]\n",
3924 vport->cfg_restrict_login = 1;
3927 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3928 vport->cfg_restrict_login = 0;
3931 vport->cfg_restrict_login = val;
3936 * lpfc_restrict_login_set - Set the vport restrict login flag
3937 * @vport: lpfc vport structure pointer.
3938 * @val: contains the restrict login value.
3941 * If val is not in a valid range then log a kernel error message and set
3942 * the vport restrict login to one.
3943 * If the port type is physical and the val is not zero log a kernel
3944 * error message, clear the restrict login flag and return zero.
3945 * Else set the restrict login flag to val.
3948 * zero if val is in range
3949 * -EINVAL val out of range
3952 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3954 if (val < 0 || val > 1) {
3955 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3956 "0425 lpfc_restrict_login attribute cannot "
3957 "be set to %d, allowed range is [0, 1]\n",
3959 vport->cfg_restrict_login = 1;
3962 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3963 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3964 "0468 lpfc_restrict_login must be 0 for "
3965 "Physical ports.\n");
3966 vport->cfg_restrict_login = 0;
3969 vport->cfg_restrict_login = val;
3972 lpfc_vport_param_store(restrict_login);
3973 static DEVICE_ATTR_RW(lpfc_restrict_login);
3976 # Some disk devices have a "select ID" or "select Target" capability.
3977 # From a protocol standpoint "select ID" usually means select the
3978 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3979 # annex" which contains a table that maps a "select ID" (a number
3980 # between 0 and 7F) to an ALPA. By default, for compatibility with
3981 # older drivers, the lpfc driver scans this table from low ALPA to high
3984 # Turning on the scan-down variable (on = 1, off = 0) will
3985 # cause the lpfc driver to use an inverted table, effectively
3986 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3988 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3989 # and will not work across a fabric. Also this parameter will take
3990 # effect only in the case when ALPA map is not available.)
3992 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3993 "Start scanning for devices from highest ALPA to lowest");
3996 # lpfc_topology: link topology for init link
3997 # 0x0 = attempt loop mode then point-to-point
3998 # 0x01 = internal loopback mode
3999 # 0x02 = attempt point-to-point mode only
4000 # 0x04 = attempt loop mode only
4001 # 0x06 = attempt point-to-point mode then loop
4002 # Set point-to-point mode if you want to run as an N_Port.
4003 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4004 # Default value is 0.
4006 LPFC_ATTR(topology, 0, 0, 6,
4007 "Select Fibre Channel topology");
4010 * lpfc_topology_set - Set the adapters topology field
4011 * @phba: lpfc_hba pointer.
4012 * @val: topology value.
4015 * If val is in a valid range then set the adapter's topology field and
4016 * issue a lip; if the lip fails reset the topology to the old value.
4018 * If the value is not in range log a kernel error message and return an error.
4021 * zero if val is in range and lip okay
4022 * non-zero return value from lpfc_issue_lip()
4023 * -EINVAL val out of range
4026 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4027 const char *buf, size_t count)
4029 struct Scsi_Host *shost = class_to_shost(dev);
4030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4031 struct lpfc_hba *phba = vport->phba;
4034 const char *val_buf = buf;
4038 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4040 val_buf = &buf[strlen("nolip ")];
4043 if (!isdigit(val_buf[0]))
4045 if (sscanf(val_buf, "%i", &val) != 1)
4048 if (val >= 0 && val <= 6) {
4049 prev_val = phba->cfg_topology;
4050 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4052 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4053 "3113 Loop mode not supported at speed %d\n",
4058 * The 'topology' is not a configurable parameter if :
4059 * - persistent topology enabled
4060 * - G7/G6 with no private loop support
4063 if ((phba->hba_flag & HBA_PERSISTENT_TOPO ||
4064 (!phba->sli4_hba.pc_sli4_params.pls &&
4065 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
4066 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC))) &&
4068 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4069 "3114 Loop mode not supported\n");
4072 phba->cfg_topology = val;
4076 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4077 "3054 lpfc_topology changed from %d to %d\n",
4079 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4080 phba->fc_topology_changed = 1;
4081 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4083 phba->cfg_topology = prev_val;
4088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4089 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4090 "allowed range is [0, 6]\n",
4095 lpfc_param_show(topology)
4096 static DEVICE_ATTR_RW(lpfc_topology);
4099 * lpfc_static_vport_show: Read callback function for
4100 * lpfc_static_vport sysfs file.
4101 * @dev: Pointer to class device object.
4102 * @attr: device attribute structure.
4103 * @buf: Data buffer.
4105 * This function is the read call back function for
4106 * lpfc_static_vport sysfs file. The lpfc_static_vport
4107 * sysfs file report the mageability of the vport.
4110 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4113 struct Scsi_Host *shost = class_to_shost(dev);
4114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4115 if (vport->vport_flag & STATIC_VPORT)
4116 sprintf(buf, "1\n");
4118 sprintf(buf, "0\n");
4124 * Sysfs attribute to control the statistical data collection.
4126 static DEVICE_ATTR_RO(lpfc_static_vport);
4129 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
4130 * @dev: Pointer to class device.
4131 * @buf: Data buffer.
4132 * @count: Size of the data buffer.
4134 * This function get called when a user write to the lpfc_stat_data_ctrl
4135 * sysfs file. This function parse the command written to the sysfs file
4136 * and take appropriate action. These commands are used for controlling
4137 * driver statistical data collection.
4138 * Following are the command this function handles.
4140 * setbucket <bucket_type> <base> <step>
4141 * = Set the latency buckets.
4142 * destroybucket = destroy all the buckets.
4143 * start = start data collection
4144 * stop = stop data collection
4145 * reset = reset the collected data
4148 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4149 const char *buf, size_t count)
4151 struct Scsi_Host *shost = class_to_shost(dev);
4152 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4153 struct lpfc_hba *phba = vport->phba;
4154 #define LPFC_MAX_DATA_CTRL_LEN 1024
4155 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4157 char *str_ptr, *token;
4158 struct lpfc_vport **vports;
4159 struct Scsi_Host *v_shost;
4160 char *bucket_type_str, *base_str, *step_str;
4161 unsigned long base, step, bucket_type;
4163 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
4164 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
4167 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
4168 str_ptr = &bucket_data[0];
4169 /* Ignore this token - this is command token */
4170 token = strsep(&str_ptr, "\t ");
4174 bucket_type_str = strsep(&str_ptr, "\t ");
4175 if (!bucket_type_str)
4178 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4179 bucket_type = LPFC_LINEAR_BUCKET;
4180 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4181 bucket_type = LPFC_POWER2_BUCKET;
4185 base_str = strsep(&str_ptr, "\t ");
4188 base = simple_strtoul(base_str, NULL, 0);
4190 step_str = strsep(&str_ptr, "\t ");
4193 step = simple_strtoul(step_str, NULL, 0);
4197 /* Block the data collection for every vport */
4198 vports = lpfc_create_vport_work_array(phba);
4202 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4203 v_shost = lpfc_shost_from_vport(vports[i]);
4204 spin_lock_irq(v_shost->host_lock);
4205 /* Block and reset data collection */
4206 vports[i]->stat_data_blocked = 1;
4207 if (vports[i]->stat_data_enabled)
4208 lpfc_vport_reset_stat_data(vports[i]);
4209 spin_unlock_irq(v_shost->host_lock);
4212 /* Set the bucket attributes */
4213 phba->bucket_type = bucket_type;
4214 phba->bucket_base = base;
4215 phba->bucket_step = step;
4217 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4218 v_shost = lpfc_shost_from_vport(vports[i]);
4220 /* Unblock data collection */
4221 spin_lock_irq(v_shost->host_lock);
4222 vports[i]->stat_data_blocked = 0;
4223 spin_unlock_irq(v_shost->host_lock);
4225 lpfc_destroy_vport_work_array(phba, vports);
4229 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4230 vports = lpfc_create_vport_work_array(phba);
4234 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4235 v_shost = lpfc_shost_from_vport(vports[i]);
4236 spin_lock_irq(shost->host_lock);
4237 vports[i]->stat_data_blocked = 1;
4238 lpfc_free_bucket(vport);
4239 vport->stat_data_enabled = 0;
4240 vports[i]->stat_data_blocked = 0;
4241 spin_unlock_irq(shost->host_lock);
4243 lpfc_destroy_vport_work_array(phba, vports);
4244 phba->bucket_type = LPFC_NO_BUCKET;
4245 phba->bucket_base = 0;
4246 phba->bucket_step = 0;
4250 if (!strncmp(buf, "start", strlen("start"))) {
4251 /* If no buckets configured return error */
4252 if (phba->bucket_type == LPFC_NO_BUCKET)
4254 spin_lock_irq(shost->host_lock);
4255 if (vport->stat_data_enabled) {
4256 spin_unlock_irq(shost->host_lock);
4259 lpfc_alloc_bucket(vport);
4260 vport->stat_data_enabled = 1;
4261 spin_unlock_irq(shost->host_lock);
4265 if (!strncmp(buf, "stop", strlen("stop"))) {
4266 spin_lock_irq(shost->host_lock);
4267 if (vport->stat_data_enabled == 0) {
4268 spin_unlock_irq(shost->host_lock);
4271 lpfc_free_bucket(vport);
4272 vport->stat_data_enabled = 0;
4273 spin_unlock_irq(shost->host_lock);
4277 if (!strncmp(buf, "reset", strlen("reset"))) {
4278 if ((phba->bucket_type == LPFC_NO_BUCKET)
4279 || !vport->stat_data_enabled)
4281 spin_lock_irq(shost->host_lock);
4282 vport->stat_data_blocked = 1;
4283 lpfc_vport_reset_stat_data(vport);
4284 vport->stat_data_blocked = 0;
4285 spin_unlock_irq(shost->host_lock);
4293 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
4294 * @dev: Pointer to class device object.
4295 * @buf: Data buffer.
4297 * This function is the read call back function for
4298 * lpfc_stat_data_ctrl sysfs file. This function report the
4299 * current statistical data collection state.
4302 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4305 struct Scsi_Host *shost = class_to_shost(dev);
4306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4307 struct lpfc_hba *phba = vport->phba;
4311 unsigned long bucket_value;
4313 switch (phba->bucket_type) {
4314 case LPFC_LINEAR_BUCKET:
4315 bucket_type = "linear";
4317 case LPFC_POWER2_BUCKET:
4318 bucket_type = "power2";
4321 bucket_type = "No Bucket";
4325 sprintf(&buf[index], "Statistical Data enabled :%d, "
4326 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4327 " Bucket step :%d\nLatency Ranges :",
4328 vport->stat_data_enabled, vport->stat_data_blocked,
4329 bucket_type, phba->bucket_base, phba->bucket_step);
4330 index = strlen(buf);
4331 if (phba->bucket_type != LPFC_NO_BUCKET) {
4332 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4333 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4334 bucket_value = phba->bucket_base +
4335 phba->bucket_step * i;
4337 bucket_value = phba->bucket_base +
4338 (1 << i) * phba->bucket_step;
4340 if (index + 10 > PAGE_SIZE)
4342 sprintf(&buf[index], "%08ld ", bucket_value);
4343 index = strlen(buf);
4346 sprintf(&buf[index], "\n");
4351 * Sysfs attribute to control the statistical data collection.
4353 static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
4356 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4360 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4363 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4364 #define MAX_STAT_DATA_SIZE_PER_TARGET \
4365 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4369 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
4371 * @kobj: Pointer to the kernel object
4372 * @bin_attr: Attribute object
4373 * @buff: Buffer pointer
4375 * @count: Buffer size
4377 * This function is the read call back function for lpfc_drvr_stat_data
4378 * sysfs file. This function export the statistical data to user
4382 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4383 struct bin_attribute *bin_attr,
4384 char *buf, loff_t off, size_t count)
4386 struct device *dev = container_of(kobj, struct device,
4388 struct Scsi_Host *shost = class_to_shost(dev);
4389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4390 struct lpfc_hba *phba = vport->phba;
4391 int i = 0, index = 0;
4392 unsigned long nport_index;
4393 struct lpfc_nodelist *ndlp = NULL;
4394 nport_index = (unsigned long)off /
4395 MAX_STAT_DATA_SIZE_PER_TARGET;
4397 if (!vport->stat_data_enabled || vport->stat_data_blocked
4398 || (phba->bucket_type == LPFC_NO_BUCKET))
4401 spin_lock_irq(shost->host_lock);
4402 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4403 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4406 if (nport_index > 0) {
4411 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4415 if (!ndlp->lat_data)
4419 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4420 ndlp->nlp_portname.u.wwn[0],
4421 ndlp->nlp_portname.u.wwn[1],
4422 ndlp->nlp_portname.u.wwn[2],
4423 ndlp->nlp_portname.u.wwn[3],
4424 ndlp->nlp_portname.u.wwn[4],
4425 ndlp->nlp_portname.u.wwn[5],
4426 ndlp->nlp_portname.u.wwn[6],
4427 ndlp->nlp_portname.u.wwn[7]);
4429 index = strlen(buf);
4431 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4432 sprintf(&buf[index], "%010u,",
4433 ndlp->lat_data[i].cmd_count);
4434 index = strlen(buf);
4436 sprintf(&buf[index], "\n");
4437 index = strlen(buf);
4439 spin_unlock_irq(shost->host_lock);
4443 static struct bin_attribute sysfs_drvr_stat_data_attr = {
4445 .name = "lpfc_drvr_stat_data",
4448 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4449 .read = sysfs_drvr_stat_data_read,
4454 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4456 # Value range is [0,16]. Default value is 0.
4459 * lpfc_link_speed_set - Set the adapters link speed
4460 * @phba: lpfc_hba pointer.
4461 * @val: link speed value.
4464 * If val is in a valid range then set the adapter's link speed field and
4465 * issue a lip; if the lip fails reset the link speed to the old value.
4468 * If the value is not in range log a kernel error message and return an error.
4471 * zero if val is in range and lip okay.
4472 * non-zero return value from lpfc_issue_lip()
4473 * -EINVAL val out of range
4476 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4477 const char *buf, size_t count)
4479 struct Scsi_Host *shost = class_to_shost(dev);
4480 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4481 struct lpfc_hba *phba = vport->phba;
4482 int val = LPFC_USER_LINK_SPEED_AUTO;
4484 const char *val_buf = buf;
4486 uint32_t prev_val, if_type;
4488 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4489 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4490 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4493 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4495 val_buf = &buf[strlen("nolip ")];
4498 if (!isdigit(val_buf[0]))
4500 if (sscanf(val_buf, "%i", &val) != 1)
4503 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4504 "3055 lpfc_link_speed changed from %d to %d %s\n",
4505 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4507 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4508 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4509 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4510 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4511 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4512 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4513 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4514 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4515 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4516 "2879 lpfc_link_speed attribute cannot be set "
4517 "to %d. Speed is not supported by this port.\n",
4521 if (val >= LPFC_USER_LINK_SPEED_16G &&
4522 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4524 "3112 lpfc_link_speed attribute cannot be set "
4525 "to %d. Speed is not supported in loop mode.\n",
4531 case LPFC_USER_LINK_SPEED_AUTO:
4532 case LPFC_USER_LINK_SPEED_1G:
4533 case LPFC_USER_LINK_SPEED_2G:
4534 case LPFC_USER_LINK_SPEED_4G:
4535 case LPFC_USER_LINK_SPEED_8G:
4536 case LPFC_USER_LINK_SPEED_16G:
4537 case LPFC_USER_LINK_SPEED_32G:
4538 case LPFC_USER_LINK_SPEED_64G:
4539 prev_val = phba->cfg_link_speed;
4540 phba->cfg_link_speed = val;
4544 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4546 phba->cfg_link_speed = prev_val;
4554 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4555 "0469 lpfc_link_speed attribute cannot be set to %d, "
4556 "allowed values are [%s]\n",
4557 val, LPFC_LINK_SPEED_STRING);
4562 static int lpfc_link_speed = 0;
4563 module_param(lpfc_link_speed, int, S_IRUGO);
4564 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4565 lpfc_param_show(link_speed)
4568 * lpfc_link_speed_init - Set the adapters link speed
4569 * @phba: lpfc_hba pointer.
4570 * @val: link speed value.
4573 * If val is in a valid range then set the adapter's link speed field.
4576 * If the value is not in range log a kernel error message, clear the link
4577 * speed and return an error.
4580 * zero if val saved.
4581 * -EINVAL val out of range
4584 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4586 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4587 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4588 "3111 lpfc_link_speed of %d cannot "
4589 "support loop mode, setting topology to default.\n",
4591 phba->cfg_topology = 0;
4595 case LPFC_USER_LINK_SPEED_AUTO:
4596 case LPFC_USER_LINK_SPEED_1G:
4597 case LPFC_USER_LINK_SPEED_2G:
4598 case LPFC_USER_LINK_SPEED_4G:
4599 case LPFC_USER_LINK_SPEED_8G:
4600 case LPFC_USER_LINK_SPEED_16G:
4601 case LPFC_USER_LINK_SPEED_32G:
4602 case LPFC_USER_LINK_SPEED_64G:
4603 phba->cfg_link_speed = val;
4606 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4607 "0405 lpfc_link_speed attribute cannot "
4608 "be set to %d, allowed values are "
4609 "["LPFC_LINK_SPEED_STRING"]\n", val);
4610 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4615 static DEVICE_ATTR_RW(lpfc_link_speed);
4618 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4619 # 0 = aer disabled or not supported
4620 # 1 = aer supported and enabled (default)
4621 # Value range is [0,1]. Default value is 1.
4623 LPFC_ATTR(aer_support, 1, 0, 1,
4624 "Enable PCIe device AER support");
4625 lpfc_param_show(aer_support)
4628 * lpfc_aer_support_store - Set the adapter for aer support
4630 * @dev: class device that is converted into a Scsi_host.
4631 * @attr: device attribute, not used.
4632 * @buf: containing enable or disable aer flag.
4633 * @count: unused variable.
4636 * If the val is 1 and currently the device's AER capability was not
4637 * enabled, invoke the kernel's enable AER helper routine, trying to
4638 * enable the device's AER capability. If the helper routine enabling
4639 * AER returns success, update the device's cfg_aer_support flag to
4640 * indicate AER is supported by the device; otherwise, if the device
4641 * AER capability is already enabled to support AER, then do nothing.
4643 * If the val is 0 and currently the device's AER support was enabled,
4644 * invoke the kernel's disable AER helper routine. After that, update
4645 * the device's cfg_aer_support flag to indicate AER is not supported
4646 * by the device; otherwise, if the device AER capability is already
4647 * disabled from supporting AER, then do nothing.
4650 * length of the buf on success if val is in range the intended mode
4652 * -EINVAL if val out of range or intended mode is not supported.
4655 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4656 const char *buf, size_t count)
4658 struct Scsi_Host *shost = class_to_shost(dev);
4659 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4660 struct lpfc_hba *phba = vport->phba;
4661 int val = 0, rc = -EINVAL;
4663 if (!isdigit(buf[0]))
4665 if (sscanf(buf, "%i", &val) != 1)
4670 if (phba->hba_flag & HBA_AER_ENABLED) {
4671 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4673 spin_lock_irq(&phba->hbalock);
4674 phba->hba_flag &= ~HBA_AER_ENABLED;
4675 spin_unlock_irq(&phba->hbalock);
4676 phba->cfg_aer_support = 0;
4681 phba->cfg_aer_support = 0;
4686 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4687 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4689 spin_lock_irq(&phba->hbalock);
4690 phba->hba_flag |= HBA_AER_ENABLED;
4691 spin_unlock_irq(&phba->hbalock);
4692 phba->cfg_aer_support = 1;
4697 phba->cfg_aer_support = 1;
4708 static DEVICE_ATTR_RW(lpfc_aer_support);
4711 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4712 * @dev: class device that is converted into a Scsi_host.
4713 * @attr: device attribute, not used.
4714 * @buf: containing flag 1 for aer cleanup state.
4715 * @count: unused variable.
4718 * If the @buf contains 1 and the device currently has the AER support
4719 * enabled, then invokes the kernel AER helper routine
4720 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
4721 * error status register.
4726 * -EINVAL if the buf does not contain the 1 or the device is not currently
4727 * enabled with the AER support.
4730 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4731 const char *buf, size_t count)
4733 struct Scsi_Host *shost = class_to_shost(dev);
4734 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4735 struct lpfc_hba *phba = vport->phba;
4738 if (!isdigit(buf[0]))
4740 if (sscanf(buf, "%i", &val) != 1)
4745 if (phba->hba_flag & HBA_AER_ENABLED)
4746 rc = pci_aer_clear_nonfatal_status(phba->pcidev);
4754 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4755 lpfc_aer_cleanup_state);
4758 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4760 * @dev: class device that is converted into a Scsi_host.
4761 * @attr: device attribute, not used.
4762 * @buf: containing the string the number of vfs to be enabled.
4763 * @count: unused variable.
4766 * When this api is called either through user sysfs, the driver shall
4767 * try to enable or disable SR-IOV virtual functions according to the
4770 * If zero virtual function has been enabled to the physical function,
4771 * the driver shall invoke the pci enable virtual function api trying
4772 * to enable the virtual functions. If the nr_vfn provided is greater
4773 * than the maximum supported, the maximum virtual function number will
4774 * be used for invoking the api; otherwise, the nr_vfn provided shall
4775 * be used for invoking the api. If the api call returned success, the
4776 * actual number of virtual functions enabled will be set to the driver
4777 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4778 * cfg_sriov_nr_virtfn remains zero.
4780 * If none-zero virtual functions have already been enabled to the
4781 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4782 * -EINVAL will be returned and the driver does nothing;
4784 * If the nr_vfn provided is zero and none-zero virtual functions have
4785 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4786 * disabling virtual function api shall be invoded to disable all the
4787 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4788 * zero. Otherwise, if zero virtual function has been enabled, do
4792 * length of the buf on success if val is in range the intended mode
4794 * -EINVAL if val out of range or intended mode is not supported.
4797 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4798 const char *buf, size_t count)
4800 struct Scsi_Host *shost = class_to_shost(dev);
4801 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4802 struct lpfc_hba *phba = vport->phba;
4803 struct pci_dev *pdev = phba->pcidev;
4804 int val = 0, rc = -EINVAL;
4806 /* Sanity check on user data */
4807 if (!isdigit(buf[0]))
4809 if (sscanf(buf, "%i", &val) != 1)
4814 /* Request disabling virtual functions */
4816 if (phba->cfg_sriov_nr_virtfn > 0) {
4817 pci_disable_sriov(pdev);
4818 phba->cfg_sriov_nr_virtfn = 0;
4823 /* Request enabling virtual functions */
4824 if (phba->cfg_sriov_nr_virtfn > 0) {
4825 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4826 "3018 There are %d virtual functions "
4827 "enabled on physical function.\n",
4828 phba->cfg_sriov_nr_virtfn);
4832 if (val <= LPFC_MAX_VFN_PER_PFN)
4833 phba->cfg_sriov_nr_virtfn = val;
4835 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4836 "3019 Enabling %d virtual functions is not "
4841 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4843 phba->cfg_sriov_nr_virtfn = 0;
4851 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4852 "Enable PCIe device SR-IOV virtual fn");
4854 lpfc_param_show(sriov_nr_virtfn)
4855 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4858 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4860 * @dev: class device that is converted into a Scsi_host.
4861 * @attr: device attribute, not used.
4862 * @buf: containing the string the number of vfs to be enabled.
4863 * @count: unused variable.
4868 * length of the buf on success if val is in range the intended mode
4870 * -EINVAL if val out of range or intended mode is not supported.
4873 lpfc_request_firmware_upgrade_store(struct device *dev,
4874 struct device_attribute *attr,
4875 const char *buf, size_t count)
4877 struct Scsi_Host *shost = class_to_shost(dev);
4878 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4879 struct lpfc_hba *phba = vport->phba;
4880 int val = 0, rc = -EINVAL;
4882 /* Sanity check on user data */
4883 if (!isdigit(buf[0]))
4885 if (sscanf(buf, "%i", &val) != 1)
4890 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4898 static int lpfc_req_fw_upgrade;
4899 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4900 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4901 lpfc_param_show(request_firmware_upgrade)
4904 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4905 * @phba: lpfc_hba pointer.
4909 * Set the initial Linux generic firmware upgrade enable or disable flag.
4912 * zero if val saved.
4913 * -EINVAL val out of range
4916 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4918 if (val >= 0 && val <= 1) {
4919 phba->cfg_request_firmware_upgrade = val;
4924 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4925 lpfc_request_firmware_upgrade_show,
4926 lpfc_request_firmware_upgrade_store);
4929 * lpfc_force_rscn_store
4931 * @dev: class device that is converted into a Scsi_host.
4932 * @attr: device attribute, not used.
4933 * @buf: unused string
4934 * @count: unused variable.
4937 * Force the switch to send a RSCN to all other NPorts in our zone
4938 * If we are direct connect pt2pt, build the RSCN command ourself
4939 * and send to the other NPort. Not supported for private loop.
4943 * -EIO - if command is not sent
4946 lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4947 const char *buf, size_t count)
4949 struct Scsi_Host *shost = class_to_shost(dev);
4950 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4953 i = lpfc_issue_els_rscn(vport, 0);
4960 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4961 * connected to the HBA.
4963 * Value range is any ascii value
4965 static int lpfc_force_rscn;
4966 module_param(lpfc_force_rscn, int, 0644);
4967 MODULE_PARM_DESC(lpfc_force_rscn,
4968 "Force an RSCN to be sent to all remote NPorts");
4969 lpfc_param_show(force_rscn)
4972 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4973 * @phba: lpfc_hba pointer.
4974 * @val: unused value.
4977 * zero if val saved.
4980 lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
4984 static DEVICE_ATTR_RW(lpfc_force_rscn);
4987 * lpfc_fcp_imax_store
4989 * @dev: class device that is converted into a Scsi_host.
4990 * @attr: device attribute, not used.
4991 * @buf: string with the number of fast-path FCP interrupts per second.
4992 * @count: unused variable.
4995 * If val is in a valid range [636,651042], then set the adapter's
4996 * maximum number of fast-path FCP interrupts per second.
4999 * length of the buf on success if val is in range the intended mode
5001 * -EINVAL if val out of range or intended mode is not supported.
5004 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
5005 const char *buf, size_t count)
5007 struct Scsi_Host *shost = class_to_shost(dev);
5008 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5009 struct lpfc_hba *phba = vport->phba;
5010 struct lpfc_eq_intr_info *eqi;
5014 /* fcp_imax is only valid for SLI4 */
5015 if (phba->sli_rev != LPFC_SLI_REV4)
5018 /* Sanity check on user data */
5019 if (!isdigit(buf[0]))
5021 if (sscanf(buf, "%i", &val) != 1)
5025 * Value range for the HBA is [5000,5000000]
5026 * The value for each EQ depends on how many EQs are configured.
5029 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
5032 phba->cfg_auto_imax = (val) ? 0 : 1;
5033 if (phba->cfg_fcp_imax && !val) {
5034 queue_delayed_work(phba->wq, &phba->eq_delay_work,
5035 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
5037 for_each_present_cpu(i) {
5038 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
5043 phba->cfg_fcp_imax = (uint32_t)val;
5045 if (phba->cfg_fcp_imax)
5046 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
5050 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
5051 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
5058 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
5061 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
5063 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
5064 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
5065 MODULE_PARM_DESC(lpfc_fcp_imax,
5066 "Set the maximum number of FCP interrupts per second per HBA");
5067 lpfc_param_show(fcp_imax)
5070 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
5071 * @phba: lpfc_hba pointer.
5072 * @val: link speed value.
5075 * If val is in a valid range [636,651042], then initialize the adapter's
5076 * maximum number of fast-path FCP interrupts per second.
5079 * zero if val saved.
5080 * -EINVAL val out of range
5083 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
5085 if (phba->sli_rev != LPFC_SLI_REV4) {
5086 phba->cfg_fcp_imax = 0;
5090 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
5092 phba->cfg_fcp_imax = val;
5096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5097 "3016 lpfc_fcp_imax: %d out of range, using default\n",
5099 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
5104 static DEVICE_ATTR_RW(lpfc_fcp_imax);
5107 * lpfc_cq_max_proc_limit_store
5109 * @dev: class device that is converted into a Scsi_host.
5110 * @attr: device attribute, not used.
5111 * @buf: string with the cq max processing limit of cqes
5112 * @count: unused variable.
5115 * If val is in a valid range, then set value on each cq
5118 * The length of the buf: if successful
5119 * -ERANGE: if val is not in the valid range
5120 * -EINVAL: if bad value format or intended mode is not supported.
5123 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
5124 const char *buf, size_t count)
5126 struct Scsi_Host *shost = class_to_shost(dev);
5127 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5128 struct lpfc_hba *phba = vport->phba;
5129 struct lpfc_queue *eq, *cq;
5133 /* cq_max_proc_limit is only valid for SLI4 */
5134 if (phba->sli_rev != LPFC_SLI_REV4)
5137 /* Sanity check on user data */
5138 if (!isdigit(buf[0]))
5140 if (kstrtoul(buf, 0, &val))
5143 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
5146 phba->cfg_cq_max_proc_limit = (uint32_t)val;
5148 /* set the values on the cq's */
5149 for (i = 0; i < phba->cfg_irq_chann; i++) {
5150 /* Get the EQ corresponding to the IRQ vector */
5151 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
5155 list_for_each_entry(cq, &eq->child_list, list)
5156 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
5164 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
5165 * itteration of CQ processing.
5167 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5168 module_param(lpfc_cq_max_proc_limit, int, 0644);
5169 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
5170 "Set the maximum number CQEs processed in an iteration of "
5172 lpfc_param_show(cq_max_proc_limit)
5175 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
5176 * single handler call which should request a polled completion rather
5177 * than re-enabling interrupts.
5179 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
5180 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
5181 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
5182 "CQE Processing Threshold to enable Polling");
5185 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
5186 * @phba: lpfc_hba pointer.
5190 * If val is in a valid range, then initialize the adapter's maximum
5194 * Always returns 0 for success, even if value not always set to
5195 * requested value. If value out of range or not supported, will fall
5199 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
5201 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5203 if (phba->sli_rev != LPFC_SLI_REV4)
5206 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
5207 phba->cfg_cq_max_proc_limit = val;
5211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5212 "0371 "LPFC_DRIVER_NAME"_cq_max_proc_limit: "
5213 "%d out of range, using default\n",
5214 phba->cfg_cq_max_proc_limit);
5219 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
5222 * lpfc_state_show - Display current driver CPU affinity
5223 * @dev: class converted to a Scsi_host structure.
5224 * @attr: device attribute, not used.
5225 * @buf: on return contains text describing the state of the link.
5227 * Returns: size of formatted string.
5230 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5233 struct Scsi_Host *shost = class_to_shost(dev);
5234 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5235 struct lpfc_hba *phba = vport->phba;
5236 struct lpfc_vector_map_info *cpup;
5239 if ((phba->sli_rev != LPFC_SLI_REV4) ||
5240 (phba->intr_type != MSIX))
5243 switch (phba->cfg_fcp_cpu_map) {
5245 len += scnprintf(buf + len, PAGE_SIZE-len,
5246 "fcp_cpu_map: No mapping (%d)\n",
5247 phba->cfg_fcp_cpu_map);
5250 len += scnprintf(buf + len, PAGE_SIZE-len,
5251 "fcp_cpu_map: HBA centric mapping (%d): "
5252 "%d of %d CPUs online from %d possible CPUs\n",
5253 phba->cfg_fcp_cpu_map, num_online_cpus(),
5255 phba->sli4_hba.num_possible_cpu);
5259 while (phba->sli4_hba.curr_disp_cpu <
5260 phba->sli4_hba.num_possible_cpu) {
5261 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5263 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5264 len += scnprintf(buf + len, PAGE_SIZE - len,
5265 "CPU %02d not present\n",
5266 phba->sli4_hba.curr_disp_cpu);
5267 else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
5268 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5270 buf + len, PAGE_SIZE - len,
5271 "CPU %02d hdwq None "
5272 "physid %d coreid %d ht %d ua %d\n",
5273 phba->sli4_hba.curr_disp_cpu,
5274 cpup->phys_id, cpup->core_id,
5275 (cpup->flag & LPFC_CPU_MAP_HYPER),
5276 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5279 buf + len, PAGE_SIZE - len,
5280 "CPU %02d EQ None hdwq %04d "
5281 "physid %d coreid %d ht %d ua %d\n",
5282 phba->sli4_hba.curr_disp_cpu,
5283 cpup->hdwq, cpup->phys_id,
5285 (cpup->flag & LPFC_CPU_MAP_HYPER),
5286 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5288 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5290 buf + len, PAGE_SIZE - len,
5291 "CPU %02d hdwq None "
5292 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5293 phba->sli4_hba.curr_disp_cpu,
5296 (cpup->flag & LPFC_CPU_MAP_HYPER),
5297 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5298 lpfc_get_irq(cpup->eq));
5301 buf + len, PAGE_SIZE - len,
5302 "CPU %02d EQ %04d hdwq %04d "
5303 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5304 phba->sli4_hba.curr_disp_cpu,
5305 cpup->eq, cpup->hdwq, cpup->phys_id,
5307 (cpup->flag & LPFC_CPU_MAP_HYPER),
5308 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5309 lpfc_get_irq(cpup->eq));
5312 phba->sli4_hba.curr_disp_cpu++;
5314 /* display max number of CPUs keeping some margin */
5315 if (phba->sli4_hba.curr_disp_cpu <
5316 phba->sli4_hba.num_possible_cpu &&
5317 (len >= (PAGE_SIZE - 64))) {
5318 len += scnprintf(buf + len,
5319 PAGE_SIZE - len, "more...\n");
5324 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
5325 phba->sli4_hba.curr_disp_cpu = 0;
5331 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5332 * @dev: class device that is converted into a Scsi_host.
5333 * @attr: device attribute, not used.
5334 * @buf: one or more lpfc_polling_flags values.
5338 * -EINVAL - Not implemented yet.
5341 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5342 const char *buf, size_t count)
5344 int status = -EINVAL;
5349 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5352 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5353 # 0 - Do not affinitze IRQ vectors
5354 # 1 - Affintize HBA vectors with respect to each HBA
5355 # (start with CPU0 for each HBA)
5356 # This also defines how Hardware Queues are mapped to specific CPUs.
5358 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5359 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5360 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5361 "Defines how to map CPUs to IRQ vectors per HBA");
5364 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5365 * @phba: lpfc_hba pointer.
5366 * @val: link speed value.
5369 * If val is in a valid range [0-2], then affinitze the adapter's
5373 * zero if val saved.
5374 * -EINVAL val out of range
5377 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5379 if (phba->sli_rev != LPFC_SLI_REV4) {
5380 phba->cfg_fcp_cpu_map = 0;
5384 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5385 phba->cfg_fcp_cpu_map = val;
5389 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5390 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5392 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5397 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5400 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5401 # Value range is [2,3]. Default value is 3.
5403 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5404 "Select Fibre Channel class of service for FCP sequences");
5407 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5408 # is [0,1]. Default value is 0.
5410 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
5411 "Use ADISC on rediscovery to authenticate FCP devices");
5414 # lpfc_first_burst_size: First burst size to use on the NPorts
5415 # that support first burst.
5416 # Value range is [0,65536]. Default value is 0.
5418 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5419 "First burst size for Targets that support first burst");
5422 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5423 * When the driver is configured as an NVME target, this value is
5424 * communicated to the NVME initiator in the PRLI response. It is
5425 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5426 * parameters are set and the target is sending the PRLI RSP.
5427 * Parameter supported on physical port only - no NPIV support.
5428 * Value range is [0,65536]. Default value is 0.
5430 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5431 "NVME Target mode first burst size in 512B increments.");
5434 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5435 * For the Initiator (I), enabling this parameter means that an NVMET
5436 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5437 * processed by the initiator for subsequent NVME FCP IO.
5438 * Currently, this feature is not supported on the NVME target
5439 * Value range is [0,1]. Default value is 0 (disabled).
5441 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5442 "Enable First Burst feature for NVME Initiator.");
5445 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5446 # depth. Default value is 0. When the value of this parameter is zero the
5447 # SCSI command completion time is not used for controlling I/O queue depth. When
5448 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5449 # to limit the I/O completion time to the parameter value.
5450 # The value is set in milliseconds.
5452 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5453 "Use command completion time to control queue depth");
5455 lpfc_vport_param_show(max_scsicmpl_time);
5457 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5459 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5460 struct lpfc_nodelist *ndlp, *next_ndlp;
5462 if (val == vport->cfg_max_scsicmpl_time)
5464 if ((val < 0) || (val > 60000))
5466 vport->cfg_max_scsicmpl_time = val;
5468 spin_lock_irq(shost->host_lock);
5469 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5470 if (!NLP_CHK_NODE_ACT(ndlp))
5472 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5474 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5476 spin_unlock_irq(shost->host_lock);
5479 lpfc_vport_param_store(max_scsicmpl_time);
5480 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5483 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5484 # range is [0,1]. Default value is 0.
5486 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5489 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5490 # range is [0,1]. Default value is 1.
5492 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5495 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5496 * range is [0,1]. Default value is 0.
5497 * For [0], FCP commands are issued to Work Queues based on upper layer
5498 * hardware queue index.
5499 * For [1], FCP commands are issued to a Work Queue associated with the
5502 * LPFC_FCP_SCHED_BY_HDWQ == 0
5503 * LPFC_FCP_SCHED_BY_CPU == 1
5505 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5506 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5507 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5508 * through WQs will be used.
5510 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5511 LPFC_FCP_SCHED_BY_HDWQ,
5512 LPFC_FCP_SCHED_BY_CPU,
5513 "Determine scheduling algorithm for "
5514 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5517 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5518 * range is [0,1]. Default value is 0.
5519 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5520 * For [1], GID_PT is used for NameServer queries after RSCN
5523 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5524 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5525 "Determine algorithm NameServer queries after RSCN "
5526 "[0] - GID_FT, [1] - GID_PT");
5529 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5530 # range is [0,1]. Default value is 0.
5531 # For [0], bus reset issues target reset to ALL devices
5532 # For [1], bus reset issues target reset to non-FCP2 devices
5534 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5535 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5539 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5540 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5541 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5542 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5543 # cr_delay is set to 0.
5545 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5546 "interrupt response is generated");
5548 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5549 "interrupt response is generated");
5552 # lpfc_multi_ring_support: Determines how many rings to spread available
5553 # cmd/rsp IOCB entries across.
5554 # Value range is [1,2]. Default value is 1.
5556 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5557 "SLI rings to spread IOCB entries across");
5560 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5561 # identifies what rctl value to configure the additional ring for.
5562 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5564 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5565 255, "Identifies RCTL for additional ring configuration");
5568 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5569 # identifies what type value to configure the additional ring for.
5570 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5572 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5573 255, "Identifies TYPE for additional ring configuration");
5576 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5577 # 0 = SmartSAN functionality disabled (default)
5578 # 1 = SmartSAN functionality enabled
5579 # This parameter will override the value of lpfc_fdmi_on module parameter.
5580 # Value range is [0,1]. Default value is 0.
5582 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5585 # lpfc_fdmi_on: Controls FDMI support.
5587 # 1 Traditional FDMI support (default)
5588 # Traditional FDMI support means the driver will assume FDMI-2 support;
5589 # however, if that fails, it will fallback to FDMI-1.
5590 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5591 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5593 # Value range [0,1]. Default value is 1.
5595 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5598 # Specifies the maximum number of ELS cmds we can have outstanding (for
5599 # discovery). Value range is [1,64]. Default value = 32.
5601 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5602 "during discovery");
5605 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5606 # will be scanned by the SCSI midlayer when sequential scanning is
5607 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5608 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5609 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5610 # above. The lpfc driver limits the default value to 255 for two reasons.
5611 # As it bounds the sequential scan loop, scanning for thousands of luns
5612 # on a target can take minutes of wall clock time. Additionally,
5613 # there are FC targets, such as JBODs, that only recognize 8-bits of
5614 # LUN ID. When they receive a value greater than 8 bits, they chop off
5615 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5616 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5617 # valid responses at each of the LUN IDs, to believe there are multiple
5618 # devices present, when in fact, there is only 1.
5619 # A customer that is aware of their target behaviors, and the results as
5620 # indicated above, is welcome to increase the lpfc_max_luns value.
5621 # As mentioned, this value is not used by the lpfc driver, only the
5623 # Value range is [0,65535]. Default value is 255.
5624 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5626 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5629 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5630 # Value range is [1,255], default value is 10.
5632 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5633 "Milliseconds driver will wait between polling FCP ring");
5636 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5637 # to complete in seconds. Value range is [5,180], default value is 60.
5639 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5640 "Maximum time to wait for task management commands to complete");
5642 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5643 # support this feature
5646 # 2 = MSI-X enabled (default)
5647 # Value range is [0,2]. Default value is 2.
5649 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5650 "MSI-X (2), if possible");
5653 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5655 * 0 = NVME OAS disabled
5656 * 1 = NVME OAS enabled
5658 * Value range is [0,1]. Default value is 0.
5660 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5661 "Use OAS bit on NVME IOs");
5664 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5666 * 0 = Put NVME Command in SGL
5667 * 1 = Embed NVME Command in WQE (unless G7)
5668 * 2 = Embed NVME Command in WQE (force)
5670 * Value range is [0,2]. Default value is 1.
5672 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5673 "Embed NVME Command in WQE");
5676 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5677 * the driver will advertise it supports to the SCSI layer.
5679 * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
5680 * 1,256 = Manually specify nr_hw_queue value to be advertised,
5682 * Value range is [0,256]. Default value is 8.
5684 LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5685 LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5686 "Set the number of SCSI Queues advertised");
5689 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5690 * will advertise it supports to the NVME and SCSI layers. This also
5691 * will map to the number of CQ/WQ pairs the driver will create.
5693 * The NVME Layer will try to create this many, plus 1 administrative
5694 * hardware queue. The administrative queue will always map to WQ 0
5695 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5697 * 0 = Configure the number of hdw queues to the number of active CPUs.
5698 * 1,256 = Manually specify how many hdw queues to use.
5700 * Value range is [0,256]. Default value is 0.
5702 LPFC_ATTR_R(hdw_queue,
5704 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5705 "Set the number of I/O Hardware Queues");
5708 lpfc_assign_default_irq_numa(struct lpfc_hba *phba)
5710 #if IS_ENABLED(CONFIG_X86)
5711 /* If AMD architecture, then default is LPFC_IRQ_CHANN_NUMA */
5712 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
5713 phba->cfg_irq_numa = 1;
5715 phba->cfg_irq_numa = 0;
5717 phba->cfg_irq_numa = 0;
5722 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5723 * for Hardware Queues to utilize. This also will map to the number
5724 * of EQ / MSI-X vectors the driver will create. This should never be
5725 * more than the number of Hardware Queues
5727 * 0 = Configure number of IRQ Channels to:
5728 * if AMD architecture, number of CPUs on HBA's NUMA node
5729 * otherwise, number of active CPUs.
5730 * [1,256] = Manually specify how many IRQ Channels to use.
5732 * Value range is [0,256]. Default value is [0].
5734 static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
5735 module_param(lpfc_irq_chann, uint, 0444);
5736 MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
5738 /* lpfc_irq_chann_init - Set the hba irq_chann initial value
5739 * @phba: lpfc_hba pointer.
5740 * @val: contains the initial value
5743 * Validates the initial value is within range and assigns it to the
5744 * adapter. If not in range, an error message is posted and the
5745 * default value is assigned.
5748 * zero if value is in range and is set
5749 * -EINVAL if value was out of range
5752 lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
5754 const struct cpumask *numa_mask;
5756 if (phba->cfg_use_msi != 2) {
5757 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5758 "8532 use_msi = %u ignoring cfg_irq_numa\n",
5760 phba->cfg_irq_numa = 0;
5761 phba->cfg_irq_chann = LPFC_IRQ_CHANN_MIN;
5765 /* Check if default setting was passed */
5766 if (val == LPFC_IRQ_CHANN_DEF)
5767 lpfc_assign_default_irq_numa(phba);
5769 if (phba->cfg_irq_numa) {
5770 numa_mask = &phba->sli4_hba.numa_mask;
5772 if (cpumask_empty(numa_mask)) {
5773 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5774 "8533 Could not identify NUMA node, "
5775 "ignoring cfg_irq_numa\n");
5776 phba->cfg_irq_numa = 0;
5777 phba->cfg_irq_chann = LPFC_IRQ_CHANN_MIN;
5779 phba->cfg_irq_chann = cpumask_weight(numa_mask);
5780 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5781 "8543 lpfc_irq_chann set to %u "
5782 "(numa)\n", phba->cfg_irq_chann);
5785 if (val > LPFC_IRQ_CHANN_MAX) {
5786 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5787 "8545 lpfc_irq_chann attribute cannot "
5788 "be set to %u, allowed range is "
5792 LPFC_IRQ_CHANN_MAX);
5793 phba->cfg_irq_chann = LPFC_IRQ_CHANN_MIN;
5796 phba->cfg_irq_chann = val;
5803 * lpfc_irq_chann_show - Display value of irq_chann
5804 * @dev: class converted to a Scsi_host structure.
5805 * @attr: device attribute, not used.
5806 * @buf: on return contains a string with the list sizes
5808 * Returns: size of formatted string.
5811 lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
5814 struct Scsi_Host *shost = class_to_shost(dev);
5815 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5816 struct lpfc_hba *phba = vport->phba;
5818 return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
5821 static DEVICE_ATTR_RO(lpfc_irq_chann);
5824 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5825 # 0 = HBA resets disabled
5826 # 1 = HBA resets enabled (default)
5827 # 2 = HBA reset via PCI bus reset enabled
5828 # Value range is [0,2]. Default value is 1.
5830 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5833 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5834 # 0 = HBA Heartbeat disabled
5835 # 1 = HBA Heartbeat enabled (default)
5836 # Value range is [0,1]. Default value is 1.
5838 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5841 # lpfc_EnableXLane: Enable Express Lane Feature
5842 # 0x0 Express Lane Feature disabled
5843 # 0x1 Express Lane Feature enabled
5844 # Value range is [0,1]. Default value is 0.
5846 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5849 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5850 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5851 # Value range is [0x0,0x7f]. Default value is 0
5853 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5856 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5857 # 0 = BlockGuard disabled (default)
5858 # 1 = BlockGuard enabled
5859 # Value range is [0,1]. Default value is 0.
5861 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5865 # - Bit mask of host protection capabilities used to register with the
5867 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5868 # - Allows you to ultimately specify which profiles to use
5869 # - Default will result in registering capabilities for all profiles.
5870 # - SHOST_DIF_TYPE1_PROTECTION 1
5871 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5872 # - SHOST_DIX_TYPE0_PROTECTION 8
5873 # HBA supports DIX Type 0: Host to HBA protection only
5874 # - SHOST_DIX_TYPE1_PROTECTION 16
5875 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5878 LPFC_ATTR(prot_mask,
5879 (SHOST_DIF_TYPE1_PROTECTION |
5880 SHOST_DIX_TYPE0_PROTECTION |
5881 SHOST_DIX_TYPE1_PROTECTION),
5883 (SHOST_DIF_TYPE1_PROTECTION |
5884 SHOST_DIX_TYPE0_PROTECTION |
5885 SHOST_DIX_TYPE1_PROTECTION),
5886 "T10-DIF host protection capabilities mask");
5889 # lpfc_prot_guard: i
5890 # - Bit mask of protection guard types to register with the SCSI mid-layer
5891 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5892 # - Allows you to ultimately specify which profiles to use
5893 # - Default will result in registering capabilities for all guard types
5896 LPFC_ATTR(prot_guard,
5897 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5898 "T10-DIF host protection guard type");
5901 * Delay initial NPort discovery when Clean Address bit is cleared in
5902 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5903 * This parameter can have value 0 or 1.
5904 * When this parameter is set to 0, no delay is added to the initial
5906 * When this parameter is set to non-zero value, initial Nport discovery is
5907 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5908 * accept and FCID/Fabric name/Fabric portname is changed.
5909 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5910 * when Clean Address bit is cleared in FLOGI/FDISC
5911 * accept and FCID/Fabric name/Fabric portname is changed.
5912 * Default value is 0.
5914 LPFC_ATTR(delay_discovery, 0, 0, 1,
5915 "Delay NPort discovery when Clean Address bit is cleared.");
5918 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5919 * This value can be set to values between 64 and 4096. The default value
5920 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5921 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5922 * Because of the additional overhead involved in setting up T10-DIF,
5923 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5924 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5926 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5927 module_param(lpfc_sg_seg_cnt, uint, 0444);
5928 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5931 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5932 * configured for the adapter
5933 * @dev: class converted to a Scsi_host structure.
5934 * @attr: device attribute, not used.
5935 * @buf: on return contains a string with the list sizes
5937 * Returns: size of formatted string.
5940 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5943 struct Scsi_Host *shost = class_to_shost(dev);
5944 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5945 struct lpfc_hba *phba = vport->phba;
5948 len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
5949 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5951 len += scnprintf(buf + len, PAGE_SIZE, "Cfg: %d SCSI: %d NVME: %d\n",
5952 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5953 phba->cfg_nvme_seg_cnt);
5957 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5960 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5961 * @phba: lpfc_hba pointer.
5962 * @val: contains the initial value
5965 * Validates the initial value is within range and assigns it to the
5966 * adapter. If not in range, an error message is posted and the
5967 * default value is assigned.
5970 * zero if value is in range and is set
5971 * -EINVAL if value was out of range
5974 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5976 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5977 phba->cfg_sg_seg_cnt = val;
5980 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5981 "0409 "LPFC_DRIVER_NAME"_sg_seg_cnt attribute cannot "
5982 "be set to %d, allowed range is [%d, %d]\n",
5983 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5984 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5989 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5990 * 0 = MDS Diagnostics disabled (default)
5991 * 1 = MDS Diagnostics enabled
5992 * Value range is [0,1]. Default value is 0.
5994 LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5997 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5998 * 0 = Disable firmware logging (default)
5999 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
6000 * Value range [0..4]. Default value is 0
6002 LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
6003 lpfc_param_show(ras_fwlog_buffsize);
6006 lpfc_ras_fwlog_buffsize_set(struct lpfc_hba *phba, uint val)
6009 enum ras_state state;
6011 if (!lpfc_rangecheck(val, 0, 4))
6014 if (phba->cfg_ras_fwlog_buffsize == val)
6017 if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
6020 spin_lock_irq(&phba->hbalock);
6021 state = phba->ras_fwlog.state;
6022 spin_unlock_irq(&phba->hbalock);
6024 if (state == REG_INPROGRESS) {
6025 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
6026 "registration is in progress\n");
6030 /* For disable logging: stop the logs and free the DMA.
6031 * For ras_fwlog_buffsize size change we still need to free and
6032 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
6034 phba->cfg_ras_fwlog_buffsize = val;
6035 if (state == ACTIVE) {
6036 lpfc_ras_stop_fwlog(phba);
6037 lpfc_sli4_ras_dma_free(phba);
6040 lpfc_sli4_ras_init(phba);
6041 if (phba->ras_fwlog.ras_enabled)
6042 ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
6043 LPFC_RAS_ENABLE_LOGGING);
6047 lpfc_param_store(ras_fwlog_buffsize);
6048 static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
6051 * lpfc_ras_fwlog_level: Firmware logging verbosity level
6052 * Valid only if firmware logging is enabled
6053 * 0(Least Verbosity) 4 (most verbosity)
6054 * Value range is [0..4]. Default value is 0
6056 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
6059 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
6060 * Default function which has RAS support : 0
6061 * Value Range is [0..7].
6062 * FW logging is a global action and enablement is via a specific
6065 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
6068 * lpfc_enable_bbcr: Enable BB Credit Recovery
6069 * 0 = BB Credit Recovery disabled
6070 * 1 = BB Credit Recovery enabled (default)
6071 * Value range is [0,1]. Default value is 1.
6073 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
6076 * lpfc_enable_dpp: Enable DPP on G7
6077 * 0 = DPP on G7 disabled
6078 * 1 = DPP on G7 enabled (default)
6079 * Value range is [0,1]. Default value is 1.
6081 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
6083 struct device_attribute *lpfc_hba_attrs[] = {
6084 &dev_attr_nvme_info,
6085 &dev_attr_scsi_stat,
6087 &dev_attr_bg_guard_err,
6088 &dev_attr_bg_apptag_err,
6089 &dev_attr_bg_reftag_err,
6091 &dev_attr_serialnum,
6092 &dev_attr_modeldesc,
6093 &dev_attr_modelname,
6094 &dev_attr_programtype,
6098 &dev_attr_option_rom_version,
6099 &dev_attr_link_state,
6100 &dev_attr_num_discovered_ports,
6101 &dev_attr_menlo_mgmt_mode,
6102 &dev_attr_lpfc_drvr_version,
6103 &dev_attr_lpfc_enable_fip,
6104 &dev_attr_lpfc_temp_sensor,
6105 &dev_attr_lpfc_log_verbose,
6106 &dev_attr_lpfc_lun_queue_depth,
6107 &dev_attr_lpfc_tgt_queue_depth,
6108 &dev_attr_lpfc_hba_queue_depth,
6109 &dev_attr_lpfc_peer_port_login,
6110 &dev_attr_lpfc_nodev_tmo,
6111 &dev_attr_lpfc_devloss_tmo,
6112 &dev_attr_lpfc_enable_fc4_type,
6113 &dev_attr_lpfc_fcp_class,
6114 &dev_attr_lpfc_use_adisc,
6115 &dev_attr_lpfc_first_burst_size,
6116 &dev_attr_lpfc_ack0,
6117 &dev_attr_lpfc_xri_rebalancing,
6118 &dev_attr_lpfc_topology,
6119 &dev_attr_lpfc_scan_down,
6120 &dev_attr_lpfc_link_speed,
6121 &dev_attr_lpfc_fcp_io_sched,
6122 &dev_attr_lpfc_ns_query,
6123 &dev_attr_lpfc_fcp2_no_tgt_reset,
6124 &dev_attr_lpfc_cr_delay,
6125 &dev_attr_lpfc_cr_count,
6126 &dev_attr_lpfc_multi_ring_support,
6127 &dev_attr_lpfc_multi_ring_rctl,
6128 &dev_attr_lpfc_multi_ring_type,
6129 &dev_attr_lpfc_fdmi_on,
6130 &dev_attr_lpfc_enable_SmartSAN,
6131 &dev_attr_lpfc_max_luns,
6132 &dev_attr_lpfc_enable_npiv,
6133 &dev_attr_lpfc_fcf_failover_policy,
6134 &dev_attr_lpfc_enable_rrq,
6135 &dev_attr_nport_evt_cnt,
6136 &dev_attr_board_mode,
6143 &dev_attr_npiv_info,
6144 &dev_attr_issue_reset,
6145 &dev_attr_lpfc_poll,
6146 &dev_attr_lpfc_poll_tmo,
6147 &dev_attr_lpfc_task_mgmt_tmo,
6148 &dev_attr_lpfc_use_msi,
6149 &dev_attr_lpfc_nvme_oas,
6150 &dev_attr_lpfc_nvme_embed_cmd,
6151 &dev_attr_lpfc_fcp_imax,
6152 &dev_attr_lpfc_force_rscn,
6153 &dev_attr_lpfc_cq_poll_threshold,
6154 &dev_attr_lpfc_cq_max_proc_limit,
6155 &dev_attr_lpfc_fcp_cpu_map,
6156 &dev_attr_lpfc_fcp_mq_threshold,
6157 &dev_attr_lpfc_hdw_queue,
6158 &dev_attr_lpfc_irq_chann,
6159 &dev_attr_lpfc_suppress_rsp,
6160 &dev_attr_lpfc_nvmet_mrq,
6161 &dev_attr_lpfc_nvmet_mrq_post,
6162 &dev_attr_lpfc_nvme_enable_fb,
6163 &dev_attr_lpfc_nvmet_fb_size,
6164 &dev_attr_lpfc_enable_bg,
6165 &dev_attr_lpfc_soft_wwnn,
6166 &dev_attr_lpfc_soft_wwpn,
6167 &dev_attr_lpfc_soft_wwn_enable,
6168 &dev_attr_lpfc_enable_hba_reset,
6169 &dev_attr_lpfc_enable_hba_heartbeat,
6170 &dev_attr_lpfc_EnableXLane,
6171 &dev_attr_lpfc_XLanePriority,
6172 &dev_attr_lpfc_xlane_lun,
6173 &dev_attr_lpfc_xlane_tgt,
6174 &dev_attr_lpfc_xlane_vpt,
6175 &dev_attr_lpfc_xlane_lun_state,
6176 &dev_attr_lpfc_xlane_lun_status,
6177 &dev_attr_lpfc_xlane_priority,
6178 &dev_attr_lpfc_sg_seg_cnt,
6179 &dev_attr_lpfc_max_scsicmpl_time,
6180 &dev_attr_lpfc_stat_data_ctrl,
6181 &dev_attr_lpfc_aer_support,
6182 &dev_attr_lpfc_aer_state_cleanup,
6183 &dev_attr_lpfc_sriov_nr_virtfn,
6184 &dev_attr_lpfc_req_fw_upgrade,
6185 &dev_attr_lpfc_suppress_link_up,
6190 &dev_attr_txcmplq_hw,
6191 &dev_attr_lpfc_sriov_hw_max_virtfn,
6193 &dev_attr_lpfc_xlane_supported,
6194 &dev_attr_lpfc_enable_mds_diags,
6195 &dev_attr_lpfc_ras_fwlog_buffsize,
6196 &dev_attr_lpfc_ras_fwlog_level,
6197 &dev_attr_lpfc_ras_fwlog_func,
6198 &dev_attr_lpfc_enable_bbcr,
6199 &dev_attr_lpfc_enable_dpp,
6203 struct device_attribute *lpfc_vport_attrs[] = {
6205 &dev_attr_link_state,
6206 &dev_attr_num_discovered_ports,
6207 &dev_attr_lpfc_drvr_version,
6208 &dev_attr_lpfc_log_verbose,
6209 &dev_attr_lpfc_lun_queue_depth,
6210 &dev_attr_lpfc_tgt_queue_depth,
6211 &dev_attr_lpfc_nodev_tmo,
6212 &dev_attr_lpfc_devloss_tmo,
6213 &dev_attr_lpfc_hba_queue_depth,
6214 &dev_attr_lpfc_peer_port_login,
6215 &dev_attr_lpfc_restrict_login,
6216 &dev_attr_lpfc_fcp_class,
6217 &dev_attr_lpfc_use_adisc,
6218 &dev_attr_lpfc_first_burst_size,
6219 &dev_attr_lpfc_max_luns,
6220 &dev_attr_nport_evt_cnt,
6221 &dev_attr_npiv_info,
6222 &dev_attr_lpfc_enable_da_id,
6223 &dev_attr_lpfc_max_scsicmpl_time,
6224 &dev_attr_lpfc_stat_data_ctrl,
6225 &dev_attr_lpfc_static_vport,
6230 * sysfs_ctlreg_write - Write method for writing to ctlreg
6231 * @filp: open sysfs file
6232 * @kobj: kernel kobject that contains the kernel class device.
6233 * @bin_attr: kernel attributes passed to us.
6234 * @buf: contains the data to be written to the adapter IOREG space.
6235 * @off: offset into buffer to beginning of data.
6236 * @count: bytes to transfer.
6239 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6240 * Uses the adapter io control registers to send buf contents to the adapter.
6243 * -ERANGE off and count combo out of range
6244 * -EINVAL off, count or buff address invalid
6245 * -EPERM adapter is offline
6246 * value of count, buf contents written
6249 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6250 struct bin_attribute *bin_attr,
6251 char *buf, loff_t off, size_t count)
6254 struct device *dev = container_of(kobj, struct device, kobj);
6255 struct Scsi_Host *shost = class_to_shost(dev);
6256 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6257 struct lpfc_hba *phba = vport->phba;
6259 if (phba->sli_rev >= LPFC_SLI_REV4)
6262 if ((off + count) > FF_REG_AREA_SIZE)
6265 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6268 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6271 /* This is to protect HBA registers from accidental writes. */
6272 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6275 if (!(vport->fc_flag & FC_OFFLINE_MODE))
6278 spin_lock_irq(&phba->hbalock);
6279 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6280 buf_off += sizeof(uint32_t))
6281 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6282 phba->ctrl_regs_memmap_p + off + buf_off);
6284 spin_unlock_irq(&phba->hbalock);
6290 * sysfs_ctlreg_read - Read method for reading from ctlreg
6291 * @filp: open sysfs file
6292 * @kobj: kernel kobject that contains the kernel class device.
6293 * @bin_attr: kernel attributes passed to us.
6294 * @buf: if successful contains the data from the adapter IOREG space.
6295 * @off: offset into buffer to beginning of data.
6296 * @count: bytes to transfer.
6299 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6300 * Uses the adapter io control registers to read data into buf.
6303 * -ERANGE off and count combo out of range
6304 * -EINVAL off, count or buff address invalid
6305 * value of count, buf contents read
6308 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6309 struct bin_attribute *bin_attr,
6310 char *buf, loff_t off, size_t count)
6314 struct device *dev = container_of(kobj, struct device, kobj);
6315 struct Scsi_Host *shost = class_to_shost(dev);
6316 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6317 struct lpfc_hba *phba = vport->phba;
6319 if (phba->sli_rev >= LPFC_SLI_REV4)
6322 if (off > FF_REG_AREA_SIZE)
6325 if ((off + count) > FF_REG_AREA_SIZE)
6326 count = FF_REG_AREA_SIZE - off;
6328 if (count == 0) return 0;
6330 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6333 spin_lock_irq(&phba->hbalock);
6335 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6336 tmp_ptr = (uint32_t *)(buf + buf_off);
6337 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6340 spin_unlock_irq(&phba->hbalock);
6345 static struct bin_attribute sysfs_ctlreg_attr = {
6348 .mode = S_IRUSR | S_IWUSR,
6351 .read = sysfs_ctlreg_read,
6352 .write = sysfs_ctlreg_write,
6356 * sysfs_mbox_write - Write method for writing information via mbox
6357 * @filp: open sysfs file
6358 * @kobj: kernel kobject that contains the kernel class device.
6359 * @bin_attr: kernel attributes passed to us.
6360 * @buf: contains the data to be written to sysfs mbox.
6361 * @off: offset into buffer to beginning of data.
6362 * @count: bytes to transfer.
6365 * Deprecated function. All mailbox access from user space is performed via the
6369 * -EPERM operation not permitted
6372 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6373 struct bin_attribute *bin_attr,
6374 char *buf, loff_t off, size_t count)
6380 * sysfs_mbox_read - Read method for reading information via mbox
6381 * @filp: open sysfs file
6382 * @kobj: kernel kobject that contains the kernel class device.
6383 * @bin_attr: kernel attributes passed to us.
6384 * @buf: contains the data to be read from sysfs mbox.
6385 * @off: offset into buffer to beginning of data.
6386 * @count: bytes to transfer.
6389 * Deprecated function. All mailbox access from user space is performed via the
6393 * -EPERM operation not permitted
6396 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6397 struct bin_attribute *bin_attr,
6398 char *buf, loff_t off, size_t count)
6403 static struct bin_attribute sysfs_mbox_attr = {
6406 .mode = S_IRUSR | S_IWUSR,
6408 .size = MAILBOX_SYSFS_MAX,
6409 .read = sysfs_mbox_read,
6410 .write = sysfs_mbox_write,
6414 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6415 * @vport: address of lpfc vport structure.
6419 * error return code from sysfs_create_bin_file()
6422 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6424 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6427 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6428 &sysfs_drvr_stat_data_attr);
6430 /* Virtual ports do not need ctrl_reg and mbox */
6431 if (error || vport->port_type == LPFC_NPIV_PORT)
6434 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6435 &sysfs_ctlreg_attr);
6437 goto out_remove_stat_attr;
6439 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6442 goto out_remove_ctlreg_attr;
6445 out_remove_ctlreg_attr:
6446 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6447 out_remove_stat_attr:
6448 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6449 &sysfs_drvr_stat_data_attr);
6455 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6456 * @vport: address of lpfc vport structure.
6459 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6461 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6462 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6463 &sysfs_drvr_stat_data_attr);
6464 /* Virtual ports do not need ctrl_reg and mbox */
6465 if (vport->port_type == LPFC_NPIV_PORT)
6467 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6468 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6472 * Dynamic FC Host Attributes Support
6476 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6477 * @shost: kernel scsi host pointer.
6480 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6482 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6484 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6485 sizeof fc_host_symbolic_name(shost));
6489 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6490 * @shost: kernel scsi host pointer.
6493 lpfc_get_host_port_id(struct Scsi_Host *shost)
6495 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6497 /* note: fc_myDID already in cpu endianness */
6498 fc_host_port_id(shost) = vport->fc_myDID;
6502 * lpfc_get_host_port_type - Set the value of the scsi host port type
6503 * @shost: kernel scsi host pointer.
6506 lpfc_get_host_port_type(struct Scsi_Host *shost)
6508 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6509 struct lpfc_hba *phba = vport->phba;
6511 spin_lock_irq(shost->host_lock);
6513 if (vport->port_type == LPFC_NPIV_PORT) {
6514 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6515 } else if (lpfc_is_link_up(phba)) {
6516 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6517 if (vport->fc_flag & FC_PUBLIC_LOOP)
6518 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6520 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6522 if (vport->fc_flag & FC_FABRIC)
6523 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6525 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6528 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6530 spin_unlock_irq(shost->host_lock);
6534 * lpfc_get_host_port_state - Set the value of the scsi host port state
6535 * @shost: kernel scsi host pointer.
6538 lpfc_get_host_port_state(struct Scsi_Host *shost)
6540 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6541 struct lpfc_hba *phba = vport->phba;
6543 spin_lock_irq(shost->host_lock);
6545 if (vport->fc_flag & FC_OFFLINE_MODE)
6546 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6548 switch (phba->link_state) {
6549 case LPFC_LINK_UNKNOWN:
6550 case LPFC_LINK_DOWN:
6551 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6555 case LPFC_HBA_READY:
6556 /* Links up, reports port state accordingly */
6557 if (vport->port_state < LPFC_VPORT_READY)
6558 fc_host_port_state(shost) =
6559 FC_PORTSTATE_BYPASSED;
6561 fc_host_port_state(shost) =
6562 FC_PORTSTATE_ONLINE;
6564 case LPFC_HBA_ERROR:
6565 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6568 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6573 spin_unlock_irq(shost->host_lock);
6577 * lpfc_get_host_speed - Set the value of the scsi host speed
6578 * @shost: kernel scsi host pointer.
6581 lpfc_get_host_speed(struct Scsi_Host *shost)
6583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6584 struct lpfc_hba *phba = vport->phba;
6586 spin_lock_irq(shost->host_lock);
6588 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
6589 switch(phba->fc_linkspeed) {
6590 case LPFC_LINK_SPEED_1GHZ:
6591 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6593 case LPFC_LINK_SPEED_2GHZ:
6594 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6596 case LPFC_LINK_SPEED_4GHZ:
6597 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6599 case LPFC_LINK_SPEED_8GHZ:
6600 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6602 case LPFC_LINK_SPEED_10GHZ:
6603 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6605 case LPFC_LINK_SPEED_16GHZ:
6606 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6608 case LPFC_LINK_SPEED_32GHZ:
6609 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6611 case LPFC_LINK_SPEED_64GHZ:
6612 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6614 case LPFC_LINK_SPEED_128GHZ:
6615 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6618 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6621 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6622 switch (phba->fc_linkspeed) {
6623 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6624 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6626 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6627 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6629 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6630 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6632 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6633 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6636 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6640 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6642 spin_unlock_irq(shost->host_lock);
6646 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6647 * @shost: kernel scsi host pointer.
6650 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6652 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6653 struct lpfc_hba *phba = vport->phba;
6656 spin_lock_irq(shost->host_lock);
6658 if ((vport->port_state > LPFC_FLOGI) &&
6659 ((vport->fc_flag & FC_FABRIC) ||
6660 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6661 (vport->fc_flag & FC_PUBLIC_LOOP))))
6662 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6664 /* fabric is local port if there is no F/FL_Port */
6667 spin_unlock_irq(shost->host_lock);
6669 fc_host_fabric_name(shost) = node_name;
6673 * lpfc_get_stats - Return statistical information about the adapter
6674 * @shost: kernel scsi host pointer.
6677 * NULL on error for link down, no mbox pool, sli2 active,
6678 * management not allowed, memory allocation error, or mbox error.
6682 * address of the adapter host statistics
6684 static struct fc_host_statistics *
6685 lpfc_get_stats(struct Scsi_Host *shost)
6687 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6688 struct lpfc_hba *phba = vport->phba;
6689 struct lpfc_sli *psli = &phba->sli;
6690 struct fc_host_statistics *hs = &phba->link_stats;
6691 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6692 LPFC_MBOXQ_t *pmboxq;
6697 * prevent udev from issuing mailbox commands until the port is
6700 if (phba->link_state < LPFC_LINK_DOWN ||
6701 !phba->mbox_mem_pool ||
6702 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6705 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6708 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6711 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6713 pmb = &pmboxq->u.mb;
6714 pmb->mbxCommand = MBX_READ_STATUS;
6715 pmb->mbxOwner = OWN_HOST;
6716 pmboxq->ctx_buf = NULL;
6717 pmboxq->vport = vport;
6719 if (vport->fc_flag & FC_OFFLINE_MODE)
6720 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6722 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6724 if (rc != MBX_SUCCESS) {
6725 if (rc != MBX_TIMEOUT)
6726 mempool_free(pmboxq, phba->mbox_mem_pool);
6730 memset(hs, 0, sizeof (struct fc_host_statistics));
6732 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6734 * The MBX_READ_STATUS returns tx_k_bytes which has to
6735 * converted to words
6737 hs->tx_words = (uint64_t)
6738 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6740 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6741 hs->rx_words = (uint64_t)
6742 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6745 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6746 pmb->mbxCommand = MBX_READ_LNK_STAT;
6747 pmb->mbxOwner = OWN_HOST;
6748 pmboxq->ctx_buf = NULL;
6749 pmboxq->vport = vport;
6751 if (vport->fc_flag & FC_OFFLINE_MODE)
6752 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6754 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6756 if (rc != MBX_SUCCESS) {
6757 if (rc != MBX_TIMEOUT)
6758 mempool_free(pmboxq, phba->mbox_mem_pool);
6762 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6763 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6764 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6765 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6766 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6767 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6768 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6770 hs->link_failure_count -= lso->link_failure_count;
6771 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6772 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6773 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6774 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6775 hs->invalid_crc_count -= lso->invalid_crc_count;
6776 hs->error_frames -= lso->error_frames;
6778 if (phba->hba_flag & HBA_FCOE_MODE) {
6780 hs->nos_count = (phba->link_events >> 1);
6781 hs->nos_count -= lso->link_events;
6782 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6783 hs->lip_count = (phba->fc_eventTag >> 1);
6784 hs->lip_count -= lso->link_events;
6788 hs->nos_count = (phba->fc_eventTag >> 1);
6789 hs->nos_count -= lso->link_events;
6792 hs->dumped_frames = -1;
6794 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6796 mempool_free(pmboxq, phba->mbox_mem_pool);
6802 * lpfc_reset_stats - Copy the adapter link stats information
6803 * @shost: kernel scsi host pointer.
6806 lpfc_reset_stats(struct Scsi_Host *shost)
6808 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6809 struct lpfc_hba *phba = vport->phba;
6810 struct lpfc_sli *psli = &phba->sli;
6811 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6812 LPFC_MBOXQ_t *pmboxq;
6816 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6819 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6822 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6824 pmb = &pmboxq->u.mb;
6825 pmb->mbxCommand = MBX_READ_STATUS;
6826 pmb->mbxOwner = OWN_HOST;
6827 pmb->un.varWords[0] = 0x1; /* reset request */
6828 pmboxq->ctx_buf = NULL;
6829 pmboxq->vport = vport;
6831 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6832 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6833 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6835 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6837 if (rc != MBX_SUCCESS) {
6838 if (rc != MBX_TIMEOUT)
6839 mempool_free(pmboxq, phba->mbox_mem_pool);
6843 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6844 pmb->mbxCommand = MBX_READ_LNK_STAT;
6845 pmb->mbxOwner = OWN_HOST;
6846 pmboxq->ctx_buf = NULL;
6847 pmboxq->vport = vport;
6849 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6850 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6851 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6853 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6855 if (rc != MBX_SUCCESS) {
6856 if (rc != MBX_TIMEOUT)
6857 mempool_free( pmboxq, phba->mbox_mem_pool);
6861 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6862 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6863 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6864 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6865 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6866 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6867 lso->error_frames = pmb->un.varRdLnk.crcCnt;
6868 if (phba->hba_flag & HBA_FCOE_MODE)
6869 lso->link_events = (phba->link_events >> 1);
6871 lso->link_events = (phba->fc_eventTag >> 1);
6873 psli->stats_start = ktime_get_seconds();
6875 mempool_free(pmboxq, phba->mbox_mem_pool);
6881 * The LPFC driver treats linkdown handling as target loss events so there
6882 * are no sysfs handlers for link_down_tmo.
6886 * lpfc_get_node_by_target - Return the nodelist for a target
6887 * @starget: kernel scsi target pointer.
6890 * address of the node list if found
6891 * NULL target not found
6893 static struct lpfc_nodelist *
6894 lpfc_get_node_by_target(struct scsi_target *starget)
6896 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6897 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6898 struct lpfc_nodelist *ndlp;
6900 spin_lock_irq(shost->host_lock);
6901 /* Search for this, mapped, target ID */
6902 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6903 if (NLP_CHK_NODE_ACT(ndlp) &&
6904 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6905 starget->id == ndlp->nlp_sid) {
6906 spin_unlock_irq(shost->host_lock);
6910 spin_unlock_irq(shost->host_lock);
6915 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6916 * @starget: kernel scsi target pointer.
6919 lpfc_get_starget_port_id(struct scsi_target *starget)
6921 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6923 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6927 * lpfc_get_starget_node_name - Set the target node name
6928 * @starget: kernel scsi target pointer.
6930 * Description: Set the target node name to the ndlp node name wwn or zero.
6933 lpfc_get_starget_node_name(struct scsi_target *starget)
6935 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6937 fc_starget_node_name(starget) =
6938 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6942 * lpfc_get_starget_port_name - Set the target port name
6943 * @starget: kernel scsi target pointer.
6945 * Description: set the target port name to the ndlp port name wwn or zero.
6948 lpfc_get_starget_port_name(struct scsi_target *starget)
6950 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6952 fc_starget_port_name(starget) =
6953 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6957 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6958 * @rport: fc rport address.
6959 * @timeout: new value for dev loss tmo.
6962 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6963 * dev_loss_tmo to one.
6966 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6968 struct lpfc_rport_data *rdata = rport->dd_data;
6969 struct lpfc_nodelist *ndlp = rdata->pnode;
6970 #if (IS_ENABLED(CONFIG_NVME_FC))
6971 struct lpfc_nvme_rport *nrport = NULL;
6975 rport->dev_loss_tmo = timeout;
6977 rport->dev_loss_tmo = 1;
6979 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
6980 dev_info(&rport->dev, "Cannot find remote node to "
6981 "set rport dev loss tmo, port_id x%x\n",
6986 #if (IS_ENABLED(CONFIG_NVME_FC))
6987 nrport = lpfc_ndlp_get_nrport(ndlp);
6989 if (nrport && nrport->remoteport)
6990 nvme_fc_set_remoteport_devloss(nrport->remoteport,
6991 rport->dev_loss_tmo);
6996 * lpfc_rport_show_function - Return rport target information
6999 * Macro that uses field to generate a function with the name lpfc_show_rport_
7001 * lpfc_show_rport_##field: returns the bytes formatted in buf
7002 * @cdev: class converted to an fc_rport.
7003 * @buf: on return contains the target_field or zero.
7005 * Returns: size of formatted string.
7007 #define lpfc_rport_show_function(field, format_string, sz, cast) \
7009 lpfc_show_rport_##field (struct device *dev, \
7010 struct device_attribute *attr, \
7013 struct fc_rport *rport = transport_class_to_rport(dev); \
7014 struct lpfc_rport_data *rdata = rport->hostdata; \
7015 return scnprintf(buf, sz, format_string, \
7016 (rdata->target) ? cast rdata->target->field : 0); \
7019 #define lpfc_rport_rd_attr(field, format_string, sz) \
7020 lpfc_rport_show_function(field, format_string, sz, ) \
7021 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
7024 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
7025 * @fc_vport: The fc_vport who's symbolic name has been changed.
7028 * This function is called by the transport after the @fc_vport's symbolic name
7029 * has been changed. This function re-registers the symbolic name with the
7030 * switch to propagate the change into the fabric if the vport is active.
7033 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
7035 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
7037 if (vport->port_state == LPFC_VPORT_READY)
7038 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
7042 * lpfc_hba_log_verbose_init - Set hba's log verbose level
7043 * @phba: Pointer to lpfc_hba struct.
7045 * This function is called by the lpfc_get_cfgparam() routine to set the
7046 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
7047 * log message according to the module's lpfc_log_verbose parameter setting
7048 * before hba port or vport created.
7051 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
7053 phba->cfg_log_verbose = verbose;
7056 struct fc_function_template lpfc_transport_functions = {
7057 /* fixed attributes the driver supports */
7058 .show_host_node_name = 1,
7059 .show_host_port_name = 1,
7060 .show_host_supported_classes = 1,
7061 .show_host_supported_fc4s = 1,
7062 .show_host_supported_speeds = 1,
7063 .show_host_maxframe_size = 1,
7065 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7066 .show_host_symbolic_name = 1,
7068 /* dynamic attributes the driver supports */
7069 .get_host_port_id = lpfc_get_host_port_id,
7070 .show_host_port_id = 1,
7072 .get_host_port_type = lpfc_get_host_port_type,
7073 .show_host_port_type = 1,
7075 .get_host_port_state = lpfc_get_host_port_state,
7076 .show_host_port_state = 1,
7078 /* active_fc4s is shown but doesn't change (thus no get function) */
7079 .show_host_active_fc4s = 1,
7081 .get_host_speed = lpfc_get_host_speed,
7082 .show_host_speed = 1,
7084 .get_host_fabric_name = lpfc_get_host_fabric_name,
7085 .show_host_fabric_name = 1,
7088 * The LPFC driver treats linkdown handling as target loss events
7089 * so there are no sysfs handlers for link_down_tmo.
7092 .get_fc_host_stats = lpfc_get_stats,
7093 .reset_fc_host_stats = lpfc_reset_stats,
7095 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7096 .show_rport_maxframe_size = 1,
7097 .show_rport_supported_classes = 1,
7099 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7100 .show_rport_dev_loss_tmo = 1,
7102 .get_starget_port_id = lpfc_get_starget_port_id,
7103 .show_starget_port_id = 1,
7105 .get_starget_node_name = lpfc_get_starget_node_name,
7106 .show_starget_node_name = 1,
7108 .get_starget_port_name = lpfc_get_starget_port_name,
7109 .show_starget_port_name = 1,
7111 .issue_fc_host_lip = lpfc_issue_lip,
7112 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7113 .terminate_rport_io = lpfc_terminate_rport_io,
7115 .dd_fcvport_size = sizeof(struct lpfc_vport *),
7117 .vport_disable = lpfc_vport_disable,
7119 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7121 .bsg_request = lpfc_bsg_request,
7122 .bsg_timeout = lpfc_bsg_timeout,
7125 struct fc_function_template lpfc_vport_transport_functions = {
7126 /* fixed attributes the driver supports */
7127 .show_host_node_name = 1,
7128 .show_host_port_name = 1,
7129 .show_host_supported_classes = 1,
7130 .show_host_supported_fc4s = 1,
7131 .show_host_supported_speeds = 1,
7132 .show_host_maxframe_size = 1,
7134 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7135 .show_host_symbolic_name = 1,
7137 /* dynamic attributes the driver supports */
7138 .get_host_port_id = lpfc_get_host_port_id,
7139 .show_host_port_id = 1,
7141 .get_host_port_type = lpfc_get_host_port_type,
7142 .show_host_port_type = 1,
7144 .get_host_port_state = lpfc_get_host_port_state,
7145 .show_host_port_state = 1,
7147 /* active_fc4s is shown but doesn't change (thus no get function) */
7148 .show_host_active_fc4s = 1,
7150 .get_host_speed = lpfc_get_host_speed,
7151 .show_host_speed = 1,
7153 .get_host_fabric_name = lpfc_get_host_fabric_name,
7154 .show_host_fabric_name = 1,
7157 * The LPFC driver treats linkdown handling as target loss events
7158 * so there are no sysfs handlers for link_down_tmo.
7161 .get_fc_host_stats = lpfc_get_stats,
7162 .reset_fc_host_stats = lpfc_reset_stats,
7164 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7165 .show_rport_maxframe_size = 1,
7166 .show_rport_supported_classes = 1,
7168 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7169 .show_rport_dev_loss_tmo = 1,
7171 .get_starget_port_id = lpfc_get_starget_port_id,
7172 .show_starget_port_id = 1,
7174 .get_starget_node_name = lpfc_get_starget_node_name,
7175 .show_starget_node_name = 1,
7177 .get_starget_port_name = lpfc_get_starget_port_name,
7178 .show_starget_port_name = 1,
7180 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7181 .terminate_rport_io = lpfc_terminate_rport_io,
7183 .vport_disable = lpfc_vport_disable,
7185 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7189 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7191 * @phba: lpfc_hba pointer.
7194 lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7196 /* If the adapter supports FCoE mode */
7197 switch (phba->pcidev->device) {
7198 case PCI_DEVICE_ID_SKYHAWK:
7199 case PCI_DEVICE_ID_SKYHAWK_VF:
7200 case PCI_DEVICE_ID_LANCER_FCOE:
7201 case PCI_DEVICE_ID_LANCER_FCOE_VF:
7202 case PCI_DEVICE_ID_ZEPHYR_DCSP:
7203 case PCI_DEVICE_ID_HORNET:
7204 case PCI_DEVICE_ID_TIGERSHARK:
7205 case PCI_DEVICE_ID_TOMCAT:
7206 phba->hba_flag |= HBA_FCOE_MODE;
7209 /* for others, clear the flag */
7210 phba->hba_flag &= ~HBA_FCOE_MODE;
7215 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7216 * @phba: lpfc_hba pointer.
7219 lpfc_get_cfgparam(struct lpfc_hba *phba)
7221 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7222 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
7223 lpfc_ns_query_init(phba, lpfc_ns_query);
7224 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7225 lpfc_cr_delay_init(phba, lpfc_cr_delay);
7226 lpfc_cr_count_init(phba, lpfc_cr_count);
7227 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
7228 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7229 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7230 lpfc_ack0_init(phba, lpfc_ack0);
7231 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
7232 lpfc_topology_init(phba, lpfc_topology);
7233 lpfc_link_speed_init(phba, lpfc_link_speed);
7234 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
7235 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
7236 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7237 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
7238 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
7239 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7240 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
7241 lpfc_use_msi_init(phba, lpfc_use_msi);
7242 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
7243 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
7244 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7245 lpfc_force_rscn_init(phba, lpfc_force_rscn);
7246 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7247 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
7248 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
7249 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7250 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
7252 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7253 if (phba->sli_rev != LPFC_SLI_REV4)
7254 phba->cfg_EnableXLane = 0;
7255 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
7257 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7258 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7259 phba->cfg_oas_lun_state = 0;
7260 phba->cfg_oas_lun_status = 0;
7261 phba->cfg_oas_flags = 0;
7262 phba->cfg_oas_priority = 0;
7263 lpfc_enable_bg_init(phba, lpfc_enable_bg);
7264 lpfc_prot_mask_init(phba, lpfc_prot_mask);
7265 lpfc_prot_guard_init(phba, lpfc_prot_guard);
7266 if (phba->sli_rev == LPFC_SLI_REV4)
7269 phba->cfg_poll = lpfc_poll;
7271 /* Get the function mode */
7272 lpfc_get_hba_function_mode(phba);
7274 /* BlockGuard allowed for FC only. */
7275 if (phba->cfg_enable_bg && phba->hba_flag & HBA_FCOE_MODE) {
7276 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7277 "0581 BlockGuard feature not supported\n");
7278 /* If set, clear the BlockGuard support param */
7279 phba->cfg_enable_bg = 0;
7280 } else if (phba->cfg_enable_bg) {
7281 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
7284 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
7286 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
7287 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
7288 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
7290 /* Initialize first burst. Target vs Initiator are different. */
7291 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
7292 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
7293 lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
7294 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
7295 lpfc_irq_chann_init(phba, lpfc_irq_chann);
7296 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7297 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7299 if (phba->sli_rev != LPFC_SLI_REV4) {
7300 /* NVME only supported on SLI4 */
7301 phba->nvmet_support = 0;
7302 phba->cfg_nvmet_mrq = 0;
7303 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7304 phba->cfg_enable_bbcr = 0;
7305 phba->cfg_xri_rebalancing = 0;
7307 /* We MUST have FCP support */
7308 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7309 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7312 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7314 phba->cfg_enable_pbde = 0;
7316 /* A value of 0 means use the number of CPUs found in the system */
7317 if (phba->cfg_hdw_queue == 0)
7318 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7319 if (phba->cfg_irq_chann == 0)
7320 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7321 if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7322 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7324 phba->cfg_soft_wwnn = 0L;
7325 phba->cfg_soft_wwpn = 0L;
7326 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7327 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7328 lpfc_aer_support_init(phba, lpfc_aer_support);
7329 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7330 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7331 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7332 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7333 lpfc_sli_mode_init(phba, lpfc_sli_mode);
7334 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7335 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7336 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7337 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7343 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7344 * dependencies between protocols and roles.
7345 * @phba: lpfc_hba pointer.
7348 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7350 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu)
7351 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7352 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu)
7353 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7354 if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7355 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7357 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7358 phba->nvmet_support) {
7359 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7361 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7362 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7363 "NVME Target PRLI ACC enable_fb ",
7364 phba->cfg_nvme_enable_fb,
7365 phba->cfg_nvmet_fb_size,
7366 LPFC_NVMET_FB_SZ_MAX);
7368 if (phba->cfg_nvme_enable_fb == 0)
7369 phba->cfg_nvmet_fb_size = 0;
7371 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7372 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7375 if (!phba->cfg_nvmet_mrq)
7376 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7378 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7379 if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
7380 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7381 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7382 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7383 phba->cfg_nvmet_mrq);
7385 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7386 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7389 /* Not NVME Target mode. Turn off Target parameters. */
7390 phba->nvmet_support = 0;
7391 phba->cfg_nvmet_mrq = 0;
7392 phba->cfg_nvmet_fb_size = 0;
7397 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7398 * @vport: lpfc_vport pointer.
7401 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7403 lpfc_log_verbose_init(vport, lpfc_log_verbose);
7404 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7405 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7406 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7407 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7408 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7409 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7410 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7411 lpfc_use_adisc_init(vport, lpfc_use_adisc);
7412 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7413 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7414 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7415 lpfc_max_luns_init(vport, lpfc_max_luns);
7416 lpfc_scan_down_init(vport, lpfc_scan_down);
7417 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);