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>
43 #include "lpfc_sli4.h"
45 #include "lpfc_disc.h"
47 #include "lpfc_scsi.h"
48 #include "lpfc_nvme.h"
49 #include "lpfc_logmsg.h"
50 #include "lpfc_version.h"
51 #include "lpfc_compat.h"
52 #include "lpfc_crtn.h"
53 #include "lpfc_vport.h"
54 #include "lpfc_attr.h"
56 #define LPFC_DEF_DEVLOSS_TMO 30
57 #define LPFC_MIN_DEVLOSS_TMO 1
58 #define LPFC_MAX_DEVLOSS_TMO 255
60 #define LPFC_DEF_MRQ_POST 512
61 #define LPFC_MIN_MRQ_POST 512
62 #define LPFC_MAX_MRQ_POST 2048
65 * Write key size should be multiple of 4. If write key is changed
66 * make sure that library write key is also changed.
68 #define LPFC_REG_WRITE_KEY_SIZE 4
69 #define LPFC_REG_WRITE_KEY "EMLX"
71 const char *const trunk_errmsg[] = { /* map errcode */
72 "", /* There is no such error code at index 0*/
73 "link negotiated speed does not match existing"
74 " trunk - link was \"low\" speed",
75 "link negotiated speed does not match"
76 " existing trunk - link was \"middle\" speed",
77 "link negotiated speed does not match existing"
78 " trunk - link was \"high\" speed",
79 "Attached to non-trunking port - F_Port",
80 "Attached to non-trunking port - N_Port",
81 "FLOGI response timeout",
82 "non-FLOGI frame received",
83 "Invalid FLOGI response",
84 "Trunking initialization protocol",
85 "Trunk peer device mismatch",
89 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
90 * @incr: integer to convert.
91 * @hdw: ascii string holding converted integer plus a string terminator.
94 * JEDEC Joint Electron Device Engineering Council.
95 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
96 * character string. The string is then terminated with a NULL in byte 9.
97 * Hex 0-9 becomes ascii '0' to '9'.
98 * Hex a-f becomes ascii '=' to 'B' capital B.
101 * Coded for 32 bit integers only.
104 lpfc_jedec_to_ascii(int incr, char hdw[])
107 for (i = 0; i < 8; i++) {
110 hdw[7 - i] = 0x30 + j;
112 hdw[7 - i] = 0x61 + j - 10;
120 * lpfc_drvr_version_show - Return the Emulex driver string with version number
121 * @dev: class unused variable.
122 * @attr: device attribute, not used.
123 * @buf: on return contains the module description text.
125 * Returns: size of formatted string.
128 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
131 return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
135 * lpfc_enable_fip_show - Return the fip mode of the HBA
136 * @dev: class unused variable.
137 * @attr: device attribute, not used.
138 * @buf: on return contains the module description text.
140 * Returns: size of formatted string.
143 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
150 if (phba->hba_flag & HBA_FIP_SUPPORT)
151 return scnprintf(buf, PAGE_SIZE, "1\n");
153 return scnprintf(buf, PAGE_SIZE, "0\n");
157 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
160 struct Scsi_Host *shost = class_to_shost(dev);
161 struct lpfc_vport *vport = shost_priv(shost);
162 struct lpfc_hba *phba = vport->phba;
163 struct lpfc_nvmet_tgtport *tgtp;
164 struct nvme_fc_local_port *localport;
165 struct lpfc_nvme_lport *lport;
166 struct lpfc_nvme_rport *rport;
167 struct lpfc_nodelist *ndlp;
168 struct nvme_fc_remote_port *nrport;
169 struct lpfc_fc4_ctrl_stat *cstat;
170 uint64_t data1, data2, data3;
171 uint64_t totin, totout, tot;
175 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
177 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
178 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
181 if (phba->nvmet_support) {
182 if (!phba->targetport) {
183 len = scnprintf(buf, PAGE_SIZE,
184 "NVME Target: x%llx is not allocated\n",
185 wwn_to_u64(vport->fc_portname.u.wwn));
188 /* Port state is only one of two values for now. */
189 if (phba->targetport->port_id)
190 statep = "REGISTERED";
193 scnprintf(tmp, sizeof(tmp),
194 "NVME Target Enabled State %s\n",
196 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
199 scnprintf(tmp, sizeof(tmp),
200 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
203 wwn_to_u64(vport->fc_portname.u.wwn),
204 wwn_to_u64(vport->fc_nodename.u.wwn),
205 phba->targetport->port_id);
206 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
209 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
213 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
214 scnprintf(tmp, sizeof(tmp),
215 "LS: Rcv %08x Drop %08x Abort %08x\n",
216 atomic_read(&tgtp->rcv_ls_req_in),
217 atomic_read(&tgtp->rcv_ls_req_drop),
218 atomic_read(&tgtp->xmt_ls_abort));
219 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
222 if (atomic_read(&tgtp->rcv_ls_req_in) !=
223 atomic_read(&tgtp->rcv_ls_req_out)) {
224 scnprintf(tmp, sizeof(tmp),
225 "Rcv LS: in %08x != out %08x\n",
226 atomic_read(&tgtp->rcv_ls_req_in),
227 atomic_read(&tgtp->rcv_ls_req_out));
228 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
232 scnprintf(tmp, sizeof(tmp),
233 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
234 atomic_read(&tgtp->xmt_ls_rsp),
235 atomic_read(&tgtp->xmt_ls_drop),
236 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
237 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
240 scnprintf(tmp, sizeof(tmp),
241 "LS: RSP Abort %08x xb %08x Err %08x\n",
242 atomic_read(&tgtp->xmt_ls_rsp_aborted),
243 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
244 atomic_read(&tgtp->xmt_ls_rsp_error));
245 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
248 scnprintf(tmp, sizeof(tmp),
249 "FCP: Rcv %08x Defer %08x Release %08x "
251 atomic_read(&tgtp->rcv_fcp_cmd_in),
252 atomic_read(&tgtp->rcv_fcp_cmd_defer),
253 atomic_read(&tgtp->xmt_fcp_release),
254 atomic_read(&tgtp->rcv_fcp_cmd_drop));
255 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
258 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
259 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
260 scnprintf(tmp, sizeof(tmp),
261 "Rcv FCP: in %08x != out %08x\n",
262 atomic_read(&tgtp->rcv_fcp_cmd_in),
263 atomic_read(&tgtp->rcv_fcp_cmd_out));
264 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
268 scnprintf(tmp, sizeof(tmp),
269 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
271 atomic_read(&tgtp->xmt_fcp_read),
272 atomic_read(&tgtp->xmt_fcp_read_rsp),
273 atomic_read(&tgtp->xmt_fcp_write),
274 atomic_read(&tgtp->xmt_fcp_rsp),
275 atomic_read(&tgtp->xmt_fcp_drop));
276 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
279 scnprintf(tmp, sizeof(tmp),
280 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
281 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
282 atomic_read(&tgtp->xmt_fcp_rsp_error),
283 atomic_read(&tgtp->xmt_fcp_rsp_drop));
284 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
287 scnprintf(tmp, sizeof(tmp),
288 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
289 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
290 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
291 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
292 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
295 scnprintf(tmp, sizeof(tmp),
296 "ABORT: Xmt %08x Cmpl %08x\n",
297 atomic_read(&tgtp->xmt_fcp_abort),
298 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
299 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
302 scnprintf(tmp, sizeof(tmp),
303 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
304 atomic_read(&tgtp->xmt_abort_sol),
305 atomic_read(&tgtp->xmt_abort_unsol),
306 atomic_read(&tgtp->xmt_abort_rsp),
307 atomic_read(&tgtp->xmt_abort_rsp_error));
308 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
311 scnprintf(tmp, sizeof(tmp),
312 "DELAY: ctx %08x fod %08x wqfull %08x\n",
313 atomic_read(&tgtp->defer_ctx),
314 atomic_read(&tgtp->defer_fod),
315 atomic_read(&tgtp->defer_wqfull));
316 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
319 /* Calculate outstanding IOs */
320 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
321 tot += atomic_read(&tgtp->xmt_fcp_release);
322 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
324 scnprintf(tmp, sizeof(tmp),
325 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
326 "CTX Outstanding %08llx\n\n",
327 phba->sli4_hba.nvmet_xri_cnt,
328 phba->sli4_hba.nvmet_io_wait_cnt,
329 phba->sli4_hba.nvmet_io_wait_total,
331 strlcat(buf, tmp, PAGE_SIZE);
335 localport = vport->localport;
337 len = scnprintf(buf, PAGE_SIZE,
338 "NVME Initiator x%llx is not allocated\n",
339 wwn_to_u64(vport->fc_portname.u.wwn));
342 lport = (struct lpfc_nvme_lport *)localport->private;
343 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
346 scnprintf(tmp, sizeof(tmp),
347 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
349 phba->sli4_hba.max_cfg_param.max_xri,
350 phba->sli4_hba.io_xri_max,
351 lpfc_sli4_get_els_iocb_cnt(phba));
352 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
355 /* Port state is only one of two values for now. */
356 if (localport->port_id)
361 scnprintf(tmp, sizeof(tmp),
362 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
365 wwn_to_u64(vport->fc_portname.u.wwn),
366 wwn_to_u64(vport->fc_nodename.u.wwn),
367 localport->port_id, statep);
368 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
371 spin_lock_irq(shost->host_lock);
373 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
375 spin_lock(&vport->phba->hbalock);
376 rport = lpfc_ndlp_get_nrport(ndlp);
378 nrport = rport->remoteport;
379 spin_unlock(&vport->phba->hbalock);
383 /* Port state is only one of two values for now. */
384 switch (nrport->port_state) {
385 case FC_OBJSTATE_ONLINE:
388 case FC_OBJSTATE_UNKNOWN:
392 statep = "UNSUPPORTED";
396 /* Tab in to show lport ownership. */
397 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
398 goto unlock_buf_done;
399 if (phba->brd_no >= 10) {
400 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
401 goto unlock_buf_done;
404 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
406 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
407 goto unlock_buf_done;
409 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
411 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
412 goto unlock_buf_done;
414 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
416 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
417 goto unlock_buf_done;
419 /* An NVME rport can have multiple roles. */
420 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
421 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
422 goto unlock_buf_done;
424 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
425 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
426 goto unlock_buf_done;
428 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
429 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
430 goto unlock_buf_done;
432 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
433 FC_PORT_ROLE_NVME_TARGET |
434 FC_PORT_ROLE_NVME_DISCOVERY)) {
435 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
437 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
438 goto unlock_buf_done;
441 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
442 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
443 goto unlock_buf_done;
445 spin_unlock_irq(shost->host_lock);
450 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
453 scnprintf(tmp, sizeof(tmp),
454 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
455 atomic_read(&lport->fc4NvmeLsRequests),
456 atomic_read(&lport->fc4NvmeLsCmpls),
457 atomic_read(&lport->xmt_ls_abort));
458 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
461 scnprintf(tmp, sizeof(tmp),
462 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
463 atomic_read(&lport->xmt_ls_err),
464 atomic_read(&lport->cmpl_ls_xb),
465 atomic_read(&lport->cmpl_ls_err));
466 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
471 for (i = 0; i < phba->cfg_hdw_queue; i++) {
472 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
473 tot = cstat->io_cmpls;
475 data1 = cstat->input_requests;
476 data2 = cstat->output_requests;
477 data3 = cstat->control_requests;
478 totout += (data1 + data2 + data3);
480 scnprintf(tmp, sizeof(tmp),
481 "Total FCP Cmpl %016llx Issue %016llx "
483 totin, totout, totout - totin);
484 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
487 scnprintf(tmp, sizeof(tmp),
488 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
489 "wqerr %08x err %08x\n",
490 atomic_read(&lport->xmt_fcp_abort),
491 atomic_read(&lport->xmt_fcp_noxri),
492 atomic_read(&lport->xmt_fcp_bad_ndlp),
493 atomic_read(&lport->xmt_fcp_qdepth),
494 atomic_read(&lport->xmt_fcp_err),
495 atomic_read(&lport->xmt_fcp_wqerr));
496 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
499 scnprintf(tmp, sizeof(tmp),
500 "FCP CMPL: xb %08x Err %08x\n",
501 atomic_read(&lport->cmpl_fcp_xb),
502 atomic_read(&lport->cmpl_fcp_err));
503 strlcat(buf, tmp, PAGE_SIZE);
505 /* host_lock is already unlocked. */
509 spin_unlock_irq(shost->host_lock);
512 len = strnlen(buf, PAGE_SIZE);
514 if (unlikely(len >= (PAGE_SIZE - 1))) {
515 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
516 "6314 Catching potential buffer "
517 "overflow > PAGE_SIZE = %lu bytes\n",
519 strlcpy(buf + PAGE_SIZE - 1 -
520 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1),
521 LPFC_NVME_INFO_MORE_STR,
522 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1)
530 lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
533 struct Scsi_Host *shost = class_to_shost(dev);
534 struct lpfc_vport *vport = shost_priv(shost);
535 struct lpfc_hba *phba = vport->phba;
537 struct lpfc_fc4_ctrl_stat *cstat;
538 u64 data1, data2, data3;
539 u64 tot, totin, totout;
541 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
543 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
544 (phba->sli_rev != LPFC_SLI_REV4))
547 scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
551 for (i = 0; i < phba->cfg_hdw_queue; i++) {
552 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
553 tot = cstat->io_cmpls;
555 data1 = cstat->input_requests;
556 data2 = cstat->output_requests;
557 data3 = cstat->control_requests;
558 totout += (data1 + data2 + data3);
560 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
561 "IO %016llx ", i, data1, data2, data3);
562 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
565 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
566 tot, ((data1 + data2 + data3) - tot));
567 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
570 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
571 "OutIO %016llx\n", totin, totout, totout - totin);
572 strlcat(buf, tmp, PAGE_SIZE);
575 len = strnlen(buf, PAGE_SIZE);
581 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
584 struct Scsi_Host *shost = class_to_shost(dev);
585 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
586 struct lpfc_hba *phba = vport->phba;
588 if (phba->cfg_enable_bg) {
589 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
590 return scnprintf(buf, PAGE_SIZE,
591 "BlockGuard Enabled\n");
593 return scnprintf(buf, PAGE_SIZE,
594 "BlockGuard Not Supported\n");
596 return scnprintf(buf, PAGE_SIZE,
597 "BlockGuard Disabled\n");
601 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
604 struct Scsi_Host *shost = class_to_shost(dev);
605 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
606 struct lpfc_hba *phba = vport->phba;
608 return scnprintf(buf, PAGE_SIZE, "%llu\n",
609 (unsigned long long)phba->bg_guard_err_cnt);
613 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
616 struct Scsi_Host *shost = class_to_shost(dev);
617 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
618 struct lpfc_hba *phba = vport->phba;
620 return scnprintf(buf, PAGE_SIZE, "%llu\n",
621 (unsigned long long)phba->bg_apptag_err_cnt);
625 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
628 struct Scsi_Host *shost = class_to_shost(dev);
629 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
630 struct lpfc_hba *phba = vport->phba;
632 return scnprintf(buf, PAGE_SIZE, "%llu\n",
633 (unsigned long long)phba->bg_reftag_err_cnt);
637 * lpfc_info_show - Return some pci info about the host in ascii
638 * @dev: class converted to a Scsi_host structure.
639 * @attr: device attribute, not used.
640 * @buf: on return contains the formatted text from lpfc_info().
642 * Returns: size of formatted string.
645 lpfc_info_show(struct device *dev, struct device_attribute *attr,
648 struct Scsi_Host *host = class_to_shost(dev);
650 return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
654 * lpfc_serialnum_show - Return the hba serial number in ascii
655 * @dev: class converted to a Scsi_host structure.
656 * @attr: device attribute, not used.
657 * @buf: on return contains the formatted text serial number.
659 * Returns: size of formatted string.
662 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
665 struct Scsi_Host *shost = class_to_shost(dev);
666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
667 struct lpfc_hba *phba = vport->phba;
669 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
673 * lpfc_temp_sensor_show - Return the temperature sensor level
674 * @dev: class converted to a Scsi_host structure.
675 * @attr: device attribute, not used.
676 * @buf: on return contains the formatted support level.
679 * Returns a number indicating the temperature sensor level currently
680 * supported, zero or one in ascii.
682 * Returns: size of formatted string.
685 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
688 struct Scsi_Host *shost = class_to_shost(dev);
689 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
690 struct lpfc_hba *phba = vport->phba;
691 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
695 * lpfc_modeldesc_show - Return the model description of the hba
696 * @dev: class converted to a Scsi_host structure.
697 * @attr: device attribute, not used.
698 * @buf: on return contains the scsi vpd model description.
700 * Returns: size of formatted string.
703 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
706 struct Scsi_Host *shost = class_to_shost(dev);
707 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
708 struct lpfc_hba *phba = vport->phba;
710 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
714 * lpfc_modelname_show - Return the model name of the hba
715 * @dev: class converted to a Scsi_host structure.
716 * @attr: device attribute, not used.
717 * @buf: on return contains the scsi vpd model name.
719 * Returns: size of formatted string.
722 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
725 struct Scsi_Host *shost = class_to_shost(dev);
726 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
727 struct lpfc_hba *phba = vport->phba;
729 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
733 * lpfc_programtype_show - Return the program type of the hba
734 * @dev: class converted to a Scsi_host structure.
735 * @attr: device attribute, not used.
736 * @buf: on return contains the scsi vpd program type.
738 * Returns: size of formatted string.
741 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
744 struct Scsi_Host *shost = class_to_shost(dev);
745 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
746 struct lpfc_hba *phba = vport->phba;
748 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
752 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
753 * @dev: class converted to a Scsi_host structure.
754 * @attr: device attribute, not used.
755 * @buf: on return contains the Menlo Maintenance sli flag.
757 * Returns: size of formatted string.
760 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
762 struct Scsi_Host *shost = class_to_shost(dev);
763 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
764 struct lpfc_hba *phba = vport->phba;
766 return scnprintf(buf, PAGE_SIZE, "%d\n",
767 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
771 * lpfc_vportnum_show - Return the port number in ascii of the hba
772 * @dev: class converted to a Scsi_host structure.
773 * @attr: device attribute, not used.
774 * @buf: on return contains scsi vpd program type.
776 * Returns: size of formatted string.
779 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
782 struct Scsi_Host *shost = class_to_shost(dev);
783 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
784 struct lpfc_hba *phba = vport->phba;
786 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
790 * lpfc_fwrev_show - Return the firmware rev running in the hba
791 * @dev: class converted to a Scsi_host structure.
792 * @attr: device attribute, not used.
793 * @buf: on return contains the scsi vpd program type.
795 * Returns: size of formatted string.
798 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
801 struct Scsi_Host *shost = class_to_shost(dev);
802 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
803 struct lpfc_hba *phba = vport->phba;
806 char fwrev[FW_REV_STR_SIZE];
809 lpfc_decode_firmware_rev(phba, fwrev, 1);
810 if_type = phba->sli4_hba.pc_sli4_params.if_type;
811 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
813 if (phba->sli_rev < LPFC_SLI_REV4)
814 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
815 fwrev, phba->sli_rev);
817 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
818 fwrev, phba->sli_rev, if_type, sli_family);
824 * lpfc_hdw_show - Return the jedec information about the hba
825 * @dev: class converted to a Scsi_host structure.
826 * @attr: device attribute, not used.
827 * @buf: on return contains the scsi vpd program type.
829 * Returns: size of formatted string.
832 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
835 struct Scsi_Host *shost = class_to_shost(dev);
836 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
837 struct lpfc_hba *phba = vport->phba;
838 lpfc_vpd_t *vp = &phba->vpd;
840 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
841 return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
842 vp->rev.smRev, vp->rev.smFwRev);
846 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
847 * @dev: class converted to a Scsi_host structure.
848 * @attr: device attribute, not used.
849 * @buf: on return contains the ROM and FCode ascii strings.
851 * Returns: size of formatted string.
854 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
857 struct Scsi_Host *shost = class_to_shost(dev);
858 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
859 struct lpfc_hba *phba = vport->phba;
860 char fwrev[FW_REV_STR_SIZE];
862 if (phba->sli_rev < LPFC_SLI_REV4)
863 return scnprintf(buf, PAGE_SIZE, "%s\n",
864 phba->OptionROMVersion);
866 lpfc_decode_firmware_rev(phba, fwrev, 1);
867 return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
871 * lpfc_state_show - Return the link state of the port
872 * @dev: class converted to a Scsi_host structure.
873 * @attr: device attribute, not used.
874 * @buf: on return contains text describing the state of the link.
877 * The switch statement has no default so zero will be returned.
879 * Returns: size of formatted string.
882 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
885 struct Scsi_Host *shost = class_to_shost(dev);
886 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
887 struct lpfc_hba *phba = vport->phba;
890 switch (phba->link_state) {
891 case LPFC_LINK_UNKNOWN:
892 case LPFC_WARM_START:
893 case LPFC_INIT_START:
894 case LPFC_INIT_MBX_CMDS:
897 if (phba->hba_flag & LINK_DISABLED)
898 len += scnprintf(buf + len, PAGE_SIZE-len,
899 "Link Down - User disabled\n");
901 len += scnprintf(buf + len, PAGE_SIZE-len,
907 len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
909 switch (vport->port_state) {
910 case LPFC_LOCAL_CFG_LINK:
911 len += scnprintf(buf + len, PAGE_SIZE-len,
912 "Configuring Link\n");
916 case LPFC_FABRIC_CFG_LINK:
919 case LPFC_BUILD_DISC_LIST:
921 len += scnprintf(buf + len, PAGE_SIZE - len,
924 case LPFC_VPORT_READY:
925 len += scnprintf(buf + len, PAGE_SIZE - len,
929 case LPFC_VPORT_FAILED:
930 len += scnprintf(buf + len, PAGE_SIZE - len,
934 case LPFC_VPORT_UNKNOWN:
935 len += scnprintf(buf + len, PAGE_SIZE - len,
939 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
940 len += scnprintf(buf + len, PAGE_SIZE-len,
941 " Menlo Maint Mode\n");
942 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
943 if (vport->fc_flag & FC_PUBLIC_LOOP)
944 len += scnprintf(buf + len, PAGE_SIZE-len,
947 len += scnprintf(buf + len, PAGE_SIZE-len,
950 if (vport->fc_flag & FC_FABRIC)
951 len += scnprintf(buf + len, PAGE_SIZE-len,
954 len += scnprintf(buf + len, PAGE_SIZE-len,
959 if ((phba->sli_rev == LPFC_SLI_REV4) &&
960 ((bf_get(lpfc_sli_intf_if_type,
961 &phba->sli4_hba.sli_intf) ==
962 LPFC_SLI_INTF_IF_TYPE_6))) {
963 struct lpfc_trunk_link link = phba->trunk_link;
965 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
966 len += scnprintf(buf + len, PAGE_SIZE - len,
967 "Trunk port 0: Link %s %s\n",
968 (link.link0.state == LPFC_LINK_UP) ?
970 trunk_errmsg[link.link0.fault]);
972 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
973 len += scnprintf(buf + len, PAGE_SIZE - len,
974 "Trunk port 1: Link %s %s\n",
975 (link.link1.state == LPFC_LINK_UP) ?
977 trunk_errmsg[link.link1.fault]);
979 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
980 len += scnprintf(buf + len, PAGE_SIZE - len,
981 "Trunk port 2: Link %s %s\n",
982 (link.link2.state == LPFC_LINK_UP) ?
984 trunk_errmsg[link.link2.fault]);
986 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
987 len += scnprintf(buf + len, PAGE_SIZE - len,
988 "Trunk port 3: Link %s %s\n",
989 (link.link3.state == LPFC_LINK_UP) ?
991 trunk_errmsg[link.link3.fault]);
999 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
1000 * @dev: class unused variable.
1001 * @attr: device attribute, not used.
1002 * @buf: on return contains the module description text.
1004 * Returns: size of formatted string.
1007 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
1010 struct Scsi_Host *shost = class_to_shost(dev);
1011 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1012 struct lpfc_hba *phba = vport->phba;
1014 if (phba->sli_rev < LPFC_SLI_REV4)
1015 return scnprintf(buf, PAGE_SIZE, "fc\n");
1017 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
1018 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
1019 return scnprintf(buf, PAGE_SIZE, "fcoe\n");
1020 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
1021 return scnprintf(buf, PAGE_SIZE, "fc\n");
1023 return scnprintf(buf, PAGE_SIZE, "unknown\n");
1027 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1028 * (OAS) is supported.
1029 * @dev: class unused variable.
1030 * @attr: device attribute, not used.
1031 * @buf: on return contains the module description text.
1033 * Returns: size of formatted string.
1036 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1039 struct Scsi_Host *shost = class_to_shost(dev);
1040 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1041 struct lpfc_hba *phba = vport->phba;
1043 return scnprintf(buf, PAGE_SIZE, "%d\n",
1044 phba->sli4_hba.pc_sli4_params.oas_supported);
1048 * lpfc_link_state_store - Transition the link_state on an HBA port
1049 * @dev: class device that is converted into a Scsi_host.
1050 * @attr: device attribute, not used.
1051 * @buf: one or more lpfc_polling_flags values.
1055 * -EINVAL if the buffer is not "up" or "down"
1056 * return from link state change function if non-zero
1057 * length of the buf on success
1060 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1061 const char *buf, size_t count)
1063 struct Scsi_Host *shost = class_to_shost(dev);
1064 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1065 struct lpfc_hba *phba = vport->phba;
1067 int status = -EINVAL;
1069 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1070 (phba->link_state == LPFC_LINK_DOWN))
1071 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
1072 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1073 (phba->link_state >= LPFC_LINK_UP))
1074 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1083 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1084 * @dev: class device that is converted into a Scsi_host.
1085 * @attr: device attribute, not used.
1086 * @buf: on return contains the sum of fc mapped and unmapped.
1089 * Returns the ascii text number of the sum of the fc mapped and unmapped
1092 * Returns: size of formatted string.
1095 lpfc_num_discovered_ports_show(struct device *dev,
1096 struct device_attribute *attr, char *buf)
1098 struct Scsi_Host *shost = class_to_shost(dev);
1099 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1101 return scnprintf(buf, PAGE_SIZE, "%d\n",
1102 vport->fc_map_cnt + vport->fc_unmap_cnt);
1106 * lpfc_issue_lip - Misnomer, name carried over from long ago
1107 * @shost: Scsi_Host pointer.
1110 * Bring the link down gracefully then re-init the link. The firmware will
1111 * re-init the fiber channel interface as required. Does not issue a LIP.
1114 * -EPERM port offline or management commands are being blocked
1115 * -ENOMEM cannot allocate memory for the mailbox command
1116 * -EIO error sending the mailbox command
1120 lpfc_issue_lip(struct Scsi_Host *shost)
1122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1123 struct lpfc_hba *phba = vport->phba;
1124 LPFC_MBOXQ_t *pmboxq;
1125 int mbxstatus = MBXERR_ERROR;
1128 * If the link is offline, disabled or BLOCK_MGMT_IO
1129 * it doesn't make any sense to allow issue_lip
1131 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1132 (phba->hba_flag & LINK_DISABLED) ||
1133 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1136 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1141 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1142 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1143 pmboxq->u.mb.mbxOwner = OWN_HOST;
1145 if ((vport->fc_flag & FC_PT2PT) && (vport->fc_flag & FC_PT2PT_NO_NVME))
1146 vport->fc_flag &= ~FC_PT2PT_NO_NVME;
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 if (opcode == LPFC_FW_DUMP) {
1543 init_completion(&online_compl);
1544 phba->fw_dump_cmpl = &online_compl;
1546 /* Disable SR-IOV virtual functions if enabled */
1547 if (phba->cfg_sriov_nr_virtfn) {
1548 pci_disable_sriov(pdev);
1549 phba->cfg_sriov_nr_virtfn = 0;
1552 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1557 /* 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);
1589 if (phba->fw_dump_cmpl)
1590 phba->fw_dump_cmpl = NULL;
1594 /* keep the original port state */
1595 if (before_fc_flag & FC_OFFLINE_MODE) {
1596 if (phba->fw_dump_cmpl)
1597 phba->fw_dump_cmpl = NULL;
1601 /* Firmware dump will trigger an HA_ERATT event, and
1602 * lpfc_handle_eratt_s4 routine already handles bringing the port back
1605 if (opcode == LPFC_FW_DUMP) {
1606 wait_for_completion(phba->fw_dump_cmpl);
1608 init_completion(&online_compl);
1609 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1614 wait_for_completion(&online_compl);
1617 /* in any case, restore the virtual functions enabled as before */
1618 if (sriov_nr_virtfn) {
1619 /* If fw_dump was performed, first disable to clean up */
1620 if (opcode == LPFC_FW_DUMP) {
1621 pci_disable_sriov(pdev);
1622 phba->cfg_sriov_nr_virtfn = 0;
1626 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1628 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1631 /* return proper error code */
1642 * lpfc_nport_evt_cnt_show - Return the number of nport events
1643 * @dev: class device that is converted into a Scsi_host.
1644 * @attr: device attribute, not used.
1645 * @buf: on return contains the ascii number of nport events.
1647 * Returns: size of formatted string.
1650 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1653 struct Scsi_Host *shost = class_to_shost(dev);
1654 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1655 struct lpfc_hba *phba = vport->phba;
1657 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1661 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1663 LPFC_MBOXQ_t *mbox = NULL;
1664 unsigned long val = 0;
1668 if (!strncmp("enable", buff_out,
1669 strlen("enable"))) {
1670 pval = buff_out + strlen("enable") + 1;
1671 rc = kstrtoul(pval, 0, &val);
1673 return rc; /* Invalid number */
1674 } else if (!strncmp("disable", buff_out,
1675 strlen("disable"))) {
1678 return -EINVAL; /* Invalid command */
1683 val = 0x0; /* Disable */
1686 val = 0x1; /* Enable two port trunk */
1689 val = 0x2; /* Enable four port trunk */
1695 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1696 "0070 Set trunk mode with val %ld ", val);
1698 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1702 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1703 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1704 12, LPFC_SLI4_MBX_EMBED);
1706 bf_set(lpfc_mbx_set_trunk_mode,
1707 &mbox->u.mqe.un.set_trunk_mode,
1709 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1711 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1712 "0071 Set trunk mode failed with status: %d",
1714 mempool_free(mbox, phba->mbox_mem_pool);
1720 * lpfc_board_mode_show - Return the state of the board
1721 * @dev: class device that is converted into a Scsi_host.
1722 * @attr: device attribute, not used.
1723 * @buf: on return contains the state of the adapter.
1725 * Returns: size of formatted string.
1728 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1731 struct Scsi_Host *shost = class_to_shost(dev);
1732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1733 struct lpfc_hba *phba = vport->phba;
1736 if (phba->link_state == LPFC_HBA_ERROR)
1738 else if (phba->link_state == LPFC_WARM_START)
1739 state = "warm start";
1740 else if (phba->link_state == LPFC_INIT_START)
1745 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
1749 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1750 * @dev: class device that is converted into a Scsi_host.
1751 * @attr: device attribute, not used.
1752 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1753 * @count: unused variable.
1756 * -EACCES if enable hba reset not enabled
1757 * -EINVAL if the buffer does not contain a valid string (see above)
1758 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1759 * buf length greater than zero indicates success
1762 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1763 const char *buf, size_t count)
1765 struct Scsi_Host *shost = class_to_shost(dev);
1766 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1767 struct lpfc_hba *phba = vport->phba;
1768 struct completion online_compl;
1769 char *board_mode_str = NULL;
1773 if (!phba->cfg_enable_hba_reset) {
1775 goto board_mode_out;
1778 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1779 "3050 lpfc_board_mode set to %s\n", buf);
1781 init_completion(&online_compl);
1783 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1784 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1788 goto board_mode_out;
1790 wait_for_completion(&online_compl);
1793 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1794 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1795 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1796 if (phba->sli_rev == LPFC_SLI_REV4)
1799 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1800 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1801 if (phba->sli_rev == LPFC_SLI_REV4)
1804 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1805 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1806 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1807 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1808 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1809 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1810 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1811 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1813 status = lpfc_reset_pci_bus(phba);
1814 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1815 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
1823 board_mode_str = strchr(buf, '\n');
1825 *board_mode_str = '\0';
1826 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1827 "3097 Failed \"%s\", status(%d), "
1829 buf, status, phba->pport->fc_flag);
1835 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1836 * @phba: pointer to the adapter structure.
1837 * @mxri: max xri count.
1838 * @axri: available xri count.
1839 * @mrpi: max rpi count.
1840 * @arpi: available rpi count.
1841 * @mvpi: max vpi count.
1842 * @avpi: available vpi count.
1845 * If an integer pointer for an count is not null then the value for the
1846 * count is returned.
1853 lpfc_get_hba_info(struct lpfc_hba *phba,
1854 uint32_t *mxri, uint32_t *axri,
1855 uint32_t *mrpi, uint32_t *arpi,
1856 uint32_t *mvpi, uint32_t *avpi)
1858 struct lpfc_mbx_read_config *rd_config;
1859 LPFC_MBOXQ_t *pmboxq;
1865 * prevent udev from issuing mailbox commands until the port is
1868 if (phba->link_state < LPFC_LINK_DOWN ||
1869 !phba->mbox_mem_pool ||
1870 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1873 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1876 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1879 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1881 pmb = &pmboxq->u.mb;
1882 pmb->mbxCommand = MBX_READ_CONFIG;
1883 pmb->mbxOwner = OWN_HOST;
1884 pmboxq->ctx_buf = NULL;
1886 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1887 rc = MBX_NOT_FINISHED;
1889 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1891 if (rc != MBX_SUCCESS) {
1892 if (rc != MBX_TIMEOUT)
1893 mempool_free(pmboxq, phba->mbox_mem_pool);
1897 if (phba->sli_rev == LPFC_SLI_REV4) {
1898 rd_config = &pmboxq->u.mqe.un.rd_config;
1900 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1902 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1903 phba->sli4_hba.max_cfg_param.rpi_used;
1905 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1907 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1908 phba->sli4_hba.max_cfg_param.xri_used;
1910 /* Account for differences with SLI-3. Get vpi count from
1911 * mailbox data and subtract one for max vpi value.
1913 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1914 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1916 /* Limit the max we support */
1917 if (max_vpi > LPFC_MAX_VPI)
1918 max_vpi = LPFC_MAX_VPI;
1922 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1925 *mrpi = pmb->un.varRdConfig.max_rpi;
1927 *arpi = pmb->un.varRdConfig.avail_rpi;
1929 *mxri = pmb->un.varRdConfig.max_xri;
1931 *axri = pmb->un.varRdConfig.avail_xri;
1933 *mvpi = pmb->un.varRdConfig.max_vpi;
1935 /* avail_vpi is only valid if link is up and ready */
1936 if (phba->link_state == LPFC_HBA_READY)
1937 *avpi = pmb->un.varRdConfig.avail_vpi;
1939 *avpi = pmb->un.varRdConfig.max_vpi;
1943 mempool_free(pmboxq, phba->mbox_mem_pool);
1948 * lpfc_max_rpi_show - Return maximum rpi
1949 * @dev: class device that is converted into a Scsi_host.
1950 * @attr: device attribute, not used.
1951 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1954 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1955 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1956 * to "Unknown" and the buffer length is returned, therefore the caller
1957 * must check for "Unknown" in the buffer to detect a failure.
1959 * Returns: size of formatted string.
1962 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1965 struct Scsi_Host *shost = class_to_shost(dev);
1966 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1967 struct lpfc_hba *phba = vport->phba;
1970 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1971 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
1972 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1976 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1977 * @dev: class device that is converted into a Scsi_host.
1978 * @attr: device attribute, not used.
1979 * @buf: containing the used rpi count in decimal or "Unknown".
1982 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1983 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1984 * to "Unknown" and the buffer length is returned, therefore the caller
1985 * must check for "Unknown" in the buffer to detect a failure.
1987 * Returns: size of formatted string.
1990 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1993 struct Scsi_Host *shost = class_to_shost(dev);
1994 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1995 struct lpfc_hba *phba = vport->phba;
1998 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1999 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2000 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2004 * lpfc_max_xri_show - Return maximum xri
2005 * @dev: class device that is converted into a Scsi_host.
2006 * @attr: device attribute, not used.
2007 * @buf: on return contains the maximum xri count in decimal or "Unknown".
2010 * Calls lpfc_get_hba_info() asking for just the mrpi count.
2011 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2012 * to "Unknown" and the buffer length is returned, therefore the caller
2013 * must check for "Unknown" in the buffer to detect a failure.
2015 * Returns: size of formatted string.
2018 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
2021 struct Scsi_Host *shost = class_to_shost(dev);
2022 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2023 struct lpfc_hba *phba = vport->phba;
2026 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2027 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2028 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2032 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2033 * @dev: class device that is converted into a Scsi_host.
2034 * @attr: device attribute, not used.
2035 * @buf: on return contains the used xri count in decimal or "Unknown".
2038 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2039 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2040 * to "Unknown" and the buffer length is returned, therefore the caller
2041 * must check for "Unknown" in the buffer to detect a failure.
2043 * Returns: size of formatted string.
2046 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2049 struct Scsi_Host *shost = class_to_shost(dev);
2050 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2051 struct lpfc_hba *phba = vport->phba;
2054 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2055 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2056 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2060 * lpfc_max_vpi_show - Return maximum vpi
2061 * @dev: class device that is converted into a Scsi_host.
2062 * @attr: device attribute, not used.
2063 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2066 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2067 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2068 * to "Unknown" and the buffer length is returned, therefore the caller
2069 * must check for "Unknown" in the buffer to detect a failure.
2071 * Returns: size of formatted string.
2074 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2077 struct Scsi_Host *shost = class_to_shost(dev);
2078 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2079 struct lpfc_hba *phba = vport->phba;
2082 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2083 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2084 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2088 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2089 * @dev: class device that is converted into a Scsi_host.
2090 * @attr: device attribute, not used.
2091 * @buf: on return contains the used vpi count in decimal or "Unknown".
2094 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2095 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2096 * to "Unknown" and the buffer length is returned, therefore the caller
2097 * must check for "Unknown" in the buffer to detect a failure.
2099 * Returns: size of formatted string.
2102 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2105 struct Scsi_Host *shost = class_to_shost(dev);
2106 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2107 struct lpfc_hba *phba = vport->phba;
2110 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2111 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2112 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2116 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2117 * @dev: class device that is converted into a Scsi_host.
2118 * @attr: device attribute, not used.
2119 * @buf: text that must be interpreted to determine if npiv is supported.
2122 * Buffer will contain text indicating npiv is not suppoerted on the port,
2123 * the port is an NPIV physical port, or it is an npiv virtual port with
2124 * the id of the vport.
2126 * Returns: size of formatted string.
2129 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2132 struct Scsi_Host *shost = class_to_shost(dev);
2133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2134 struct lpfc_hba *phba = vport->phba;
2136 if (!(phba->max_vpi))
2137 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2138 if (vport->port_type == LPFC_PHYSICAL_PORT)
2139 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2140 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2144 * lpfc_poll_show - Return text about poll support for the adapter
2145 * @dev: class device that is converted into a Scsi_host.
2146 * @attr: device attribute, not used.
2147 * @buf: on return contains the cfg_poll in hex.
2150 * cfg_poll should be a lpfc_polling_flags type.
2152 * Returns: size of formatted string.
2155 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2158 struct Scsi_Host *shost = class_to_shost(dev);
2159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2160 struct lpfc_hba *phba = vport->phba;
2162 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2166 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2167 * @dev: class device that is converted into a Scsi_host.
2168 * @attr: device attribute, not used.
2169 * @buf: one or more lpfc_polling_flags values.
2173 * buf contents converted to integer and checked for a valid value.
2176 * -EINVAL if the buffer connot be converted or is out of range
2177 * length of the buf on success
2180 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2181 const char *buf, size_t count)
2183 struct Scsi_Host *shost = class_to_shost(dev);
2184 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2185 struct lpfc_hba *phba = vport->phba;
2190 if (!isdigit(buf[0]))
2193 if (sscanf(buf, "%i", &val) != 1)
2196 if ((val & 0x3) != val)
2199 if (phba->sli_rev == LPFC_SLI_REV4)
2202 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2203 "3051 lpfc_poll changed from %d to %d\n",
2204 phba->cfg_poll, val);
2206 spin_lock_irq(&phba->hbalock);
2208 old_val = phba->cfg_poll;
2210 if (val & ENABLE_FCP_RING_POLLING) {
2211 if ((val & DISABLE_FCP_RING_INT) &&
2212 !(old_val & DISABLE_FCP_RING_INT)) {
2213 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2214 spin_unlock_irq(&phba->hbalock);
2217 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2218 writel(creg_val, phba->HCregaddr);
2219 readl(phba->HCregaddr); /* flush */
2221 lpfc_poll_start_timer(phba);
2223 } else if (val != 0x0) {
2224 spin_unlock_irq(&phba->hbalock);
2228 if (!(val & DISABLE_FCP_RING_INT) &&
2229 (old_val & DISABLE_FCP_RING_INT))
2231 spin_unlock_irq(&phba->hbalock);
2232 del_timer(&phba->fcp_poll_timer);
2233 spin_lock_irq(&phba->hbalock);
2234 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2235 spin_unlock_irq(&phba->hbalock);
2238 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2239 writel(creg_val, phba->HCregaddr);
2240 readl(phba->HCregaddr); /* flush */
2243 phba->cfg_poll = val;
2245 spin_unlock_irq(&phba->hbalock);
2251 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2252 * @dev: class converted to a Scsi_host structure.
2253 * @attr: device attribute, not used.
2254 * @buf: on return contains the formatted support level.
2257 * Returns the maximum number of virtual functions a physical function can
2258 * support, 0 will be returned if called on virtual function.
2260 * Returns: size of formatted string.
2263 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2264 struct device_attribute *attr,
2267 struct Scsi_Host *shost = class_to_shost(dev);
2268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2269 struct lpfc_hba *phba = vport->phba;
2270 uint16_t max_nr_virtfn;
2272 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2273 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2276 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2278 return val >= min && val <= max;
2282 * lpfc_enable_bbcr_set: Sets an attribute value.
2283 * @phba: pointer the the adapter structure.
2284 * @val: integer attribute value.
2287 * Validates the min and max values then sets the
2288 * adapter config field if in the valid range. prints error message
2289 * and does not set the parameter if invalid.
2293 * -EINVAL if val is invalid
2296 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2298 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2299 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2300 "3068 %s_enable_bbcr changed from %d to %d\n",
2301 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
2302 phba->cfg_enable_bbcr = val;
2305 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2306 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2307 LPFC_DRIVER_NAME, val);
2312 * lpfc_param_show - Return a cfg attribute value in decimal
2315 * Macro that given an attr e.g. hba_queue_depth expands
2316 * into a function with the name lpfc_hba_queue_depth_show.
2318 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2319 * @dev: class device that is converted into a Scsi_host.
2320 * @attr: device attribute, not used.
2321 * @buf: on return contains the attribute value in decimal.
2323 * Returns: size of formatted string.
2325 #define lpfc_param_show(attr) \
2327 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2330 struct Scsi_Host *shost = class_to_shost(dev);\
2331 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2332 struct lpfc_hba *phba = vport->phba;\
2333 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2338 * lpfc_param_hex_show - Return a cfg attribute value in hex
2341 * Macro that given an attr e.g. hba_queue_depth expands
2342 * into a function with the name lpfc_hba_queue_depth_show
2344 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2345 * @dev: class device that is converted into a Scsi_host.
2346 * @attr: device attribute, not used.
2347 * @buf: on return contains the attribute value in hexadecimal.
2349 * Returns: size of formatted string.
2351 #define lpfc_param_hex_show(attr) \
2353 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2356 struct Scsi_Host *shost = class_to_shost(dev);\
2357 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2358 struct lpfc_hba *phba = vport->phba;\
2360 val = phba->cfg_##attr;\
2361 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2366 * lpfc_param_init - Initializes a cfg attribute
2369 * Macro that given an attr e.g. hba_queue_depth expands
2370 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2371 * takes a default argument, a minimum and maximum argument.
2373 * lpfc_##attr##_init: Initializes an attribute.
2374 * @phba: pointer the the adapter structure.
2375 * @val: integer attribute value.
2377 * Validates the min and max values then sets the adapter config field
2378 * accordingly, or uses the default if out of range and prints an error message.
2382 * -EINVAL if default used
2384 #define lpfc_param_init(attr, default, minval, maxval) \
2386 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2388 if (lpfc_rangecheck(val, minval, maxval)) {\
2389 phba->cfg_##attr = val;\
2392 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2393 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2394 "allowed range is ["#minval", "#maxval"]\n", val); \
2395 phba->cfg_##attr = default;\
2400 * lpfc_param_set - Set a cfg attribute value
2403 * Macro that given an attr e.g. hba_queue_depth expands
2404 * into a function with the name lpfc_hba_queue_depth_set
2406 * lpfc_##attr##_set: Sets an attribute value.
2407 * @phba: pointer the the adapter structure.
2408 * @val: integer attribute value.
2411 * Validates the min and max values then sets the
2412 * adapter config field if in the valid range. prints error message
2413 * and does not set the parameter if invalid.
2417 * -EINVAL if val is invalid
2419 #define lpfc_param_set(attr, default, minval, maxval) \
2421 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2423 if (lpfc_rangecheck(val, minval, maxval)) {\
2424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2425 "3052 lpfc_" #attr " changed from %d to %d\n", \
2426 phba->cfg_##attr, val); \
2427 phba->cfg_##attr = val;\
2430 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2431 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2432 "allowed range is ["#minval", "#maxval"]\n", val); \
2437 * lpfc_param_store - Set a vport attribute value
2440 * Macro that given an attr e.g. hba_queue_depth expands
2441 * into a function with the name lpfc_hba_queue_depth_store.
2443 * lpfc_##attr##_store: Set an sttribute value.
2444 * @dev: class device that is converted into a Scsi_host.
2445 * @attr: device attribute, not used.
2446 * @buf: contains the attribute value in ascii.
2450 * Convert the ascii text number to an integer, then
2451 * use the lpfc_##attr##_set function to set the value.
2454 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2455 * length of buffer upon success.
2457 #define lpfc_param_store(attr) \
2459 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2460 const char *buf, size_t count) \
2462 struct Scsi_Host *shost = class_to_shost(dev);\
2463 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2464 struct lpfc_hba *phba = vport->phba;\
2466 if (!isdigit(buf[0]))\
2468 if (sscanf(buf, "%i", &val) != 1)\
2470 if (lpfc_##attr##_set(phba, val) == 0) \
2471 return strlen(buf);\
2477 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2480 * Macro that given an attr e.g. hba_queue_depth expands
2481 * into a function with the name lpfc_hba_queue_depth_show
2483 * lpfc_##attr##_show: prints the attribute value in decimal.
2484 * @dev: class device that is converted into a Scsi_host.
2485 * @attr: device attribute, not used.
2486 * @buf: on return contains the attribute value in decimal.
2488 * Returns: length of formatted string.
2490 #define lpfc_vport_param_show(attr) \
2492 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2495 struct Scsi_Host *shost = class_to_shost(dev);\
2496 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2497 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2501 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2504 * Macro that given an attr e.g.
2505 * hba_queue_depth expands into a function with the name
2506 * lpfc_hba_queue_depth_show
2508 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2509 * @dev: class device that is converted into a Scsi_host.
2510 * @attr: device attribute, not used.
2511 * @buf: on return contains the attribute value in hexadecimal.
2513 * Returns: length of formatted string.
2515 #define lpfc_vport_param_hex_show(attr) \
2517 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2520 struct Scsi_Host *shost = class_to_shost(dev);\
2521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2522 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2526 * lpfc_vport_param_init - Initialize a vport cfg attribute
2529 * Macro that given an attr e.g. hba_queue_depth expands
2530 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2531 * takes a default argument, a minimum and maximum argument.
2533 * lpfc_##attr##_init: validates the min and max values then sets the
2534 * adapter config field accordingly, or uses the default if out of range
2535 * and prints an error message.
2536 * @phba: pointer the the adapter structure.
2537 * @val: integer attribute value.
2541 * -EINVAL if default used
2543 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2545 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2547 if (lpfc_rangecheck(val, minval, maxval)) {\
2548 vport->cfg_##attr = val;\
2551 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2552 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2553 "allowed range is ["#minval", "#maxval"]\n", val); \
2554 vport->cfg_##attr = default;\
2559 * lpfc_vport_param_set - Set a vport cfg attribute
2562 * Macro that given an attr e.g. hba_queue_depth expands
2563 * into a function with the name lpfc_hba_queue_depth_set
2565 * lpfc_##attr##_set: validates the min and max values then sets the
2566 * adapter config field if in the valid range. prints error message
2567 * and does not set the parameter if invalid.
2568 * @phba: pointer the the adapter structure.
2569 * @val: integer attribute value.
2573 * -EINVAL if val is invalid
2575 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2577 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2579 if (lpfc_rangecheck(val, minval, maxval)) {\
2580 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2581 "3053 lpfc_" #attr \
2582 " changed from %d (x%x) to %d (x%x)\n", \
2583 vport->cfg_##attr, vport->cfg_##attr, \
2585 vport->cfg_##attr = val;\
2588 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2589 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2590 "allowed range is ["#minval", "#maxval"]\n", val); \
2595 * lpfc_vport_param_store - Set a vport attribute
2598 * Macro that given an attr e.g. hba_queue_depth
2599 * expands into a function with the name lpfc_hba_queue_depth_store
2601 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2602 * use the lpfc_##attr##_set function to set the value.
2603 * @cdev: class device that is converted into a Scsi_host.
2604 * @buf: contains the attribute value in decimal.
2608 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2609 * length of buffer upon success.
2611 #define lpfc_vport_param_store(attr) \
2613 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2614 const char *buf, size_t count) \
2616 struct Scsi_Host *shost = class_to_shost(dev);\
2617 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2619 if (!isdigit(buf[0]))\
2621 if (sscanf(buf, "%i", &val) != 1)\
2623 if (lpfc_##attr##_set(vport, val) == 0) \
2624 return strlen(buf);\
2630 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2631 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2632 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2633 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2634 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2635 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2636 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2637 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2638 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2639 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2640 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2641 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2642 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2643 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2644 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2645 lpfc_link_state_store);
2646 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2647 lpfc_option_rom_version_show, NULL);
2648 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2649 lpfc_num_discovered_ports_show, NULL);
2650 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2651 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2652 static DEVICE_ATTR_RO(lpfc_drvr_version);
2653 static DEVICE_ATTR_RO(lpfc_enable_fip);
2654 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2655 lpfc_board_mode_show, lpfc_board_mode_store);
2656 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2657 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2658 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2659 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2660 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2661 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2662 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2663 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2664 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2665 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2666 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2667 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2670 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2673 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2675 * @cnt: Length of string.
2676 * @wwn: Array to receive converted wwn value.
2679 * -EINVAL if the buffer does not contain a valid wwn
2683 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2687 /* Count may include a LF at end of string */
2688 if (buf[cnt-1] == '\n')
2691 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2692 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2695 memset(wwn, 0, WWN_SZ);
2697 /* Validate and store the new name */
2698 for (i = 0, j = 0; i < 16; i++) {
2699 if ((*buf >= 'a') && (*buf <= 'f'))
2700 j = ((j << 4) | ((*buf++ - 'a') + 10));
2701 else if ((*buf >= 'A') && (*buf <= 'F'))
2702 j = ((j << 4) | ((*buf++ - 'A') + 10));
2703 else if ((*buf >= '0') && (*buf <= '9'))
2704 j = ((j << 4) | (*buf++ - '0'));
2708 wwn[i/2] = j & 0xff;
2715 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2716 * @dev: class device that is converted into a Scsi_host.
2717 * @attr: device attribute, not used.
2718 * @buf: containing the string lpfc_soft_wwn_key.
2719 * @count: must be size of lpfc_soft_wwn_key.
2722 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2723 * length of buf indicates success
2726 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2727 const char *buf, size_t count)
2729 struct Scsi_Host *shost = class_to_shost(dev);
2730 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2731 struct lpfc_hba *phba = vport->phba;
2732 unsigned int cnt = count;
2733 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2734 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2737 * We're doing a simple sanity check for soft_wwpn setting.
2738 * We require that the user write a specific key to enable
2739 * the soft_wwpn attribute to be settable. Once the attribute
2740 * is written, the enable key resets. If further updates are
2741 * desired, the key must be written again to re-enable the
2744 * The "key" is not secret - it is a hardcoded string shown
2745 * here. The intent is to protect against the random user or
2746 * application that is just writing attributes.
2748 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2750 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2751 " be enabled: fawwpn is enabled\n");
2755 /* count may include a LF at end of string */
2756 if (buf[cnt-1] == '\n')
2759 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2760 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2763 phba->soft_wwn_enable = 1;
2765 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2766 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2768 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2769 " The soft_wwpn feature is not supported by Broadcom.");
2773 static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
2776 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2777 * @dev: class device that is converted into a Scsi_host.
2778 * @attr: device attribute, not used.
2779 * @buf: on return contains the wwpn in hexadecimal.
2781 * Returns: size of formatted string.
2784 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2787 struct Scsi_Host *shost = class_to_shost(dev);
2788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2789 struct lpfc_hba *phba = vport->phba;
2791 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2792 (unsigned long long)phba->cfg_soft_wwpn);
2796 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2797 * @dev class device that is converted into a Scsi_host.
2798 * @attr: device attribute, not used.
2799 * @buf: contains the wwpn in hexadecimal.
2800 * @count: number of wwpn bytes in buf
2803 * -EACCES hba reset not enabled, adapter over temp
2804 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2805 * -EIO error taking adapter offline or online
2806 * value of count on success
2809 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2810 const char *buf, size_t count)
2812 struct Scsi_Host *shost = class_to_shost(dev);
2813 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2814 struct lpfc_hba *phba = vport->phba;
2815 struct completion online_compl;
2816 int stat1 = 0, stat2 = 0;
2817 unsigned int cnt = count;
2821 if (!phba->cfg_enable_hba_reset)
2823 spin_lock_irq(&phba->hbalock);
2824 if (phba->over_temp_state == HBA_OVER_TEMP) {
2825 spin_unlock_irq(&phba->hbalock);
2828 spin_unlock_irq(&phba->hbalock);
2829 /* count may include a LF at end of string */
2830 if (buf[cnt-1] == '\n')
2833 if (!phba->soft_wwn_enable)
2836 /* lock setting wwpn, wwnn down */
2837 phba->soft_wwn_enable = 0;
2839 rc = lpfc_wwn_set(buf, cnt, wwpn);
2841 /* not able to set wwpn, unlock it */
2842 phba->soft_wwn_enable = 1;
2846 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2847 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2848 if (phba->cfg_soft_wwnn)
2849 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2851 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2852 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2854 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2856 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2857 "0463 lpfc_soft_wwpn attribute set failed to "
2858 "reinit adapter - %d\n", stat1);
2859 init_completion(&online_compl);
2860 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2865 wait_for_completion(&online_compl);
2867 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2868 "0464 lpfc_soft_wwpn attribute set failed to "
2869 "reinit adapter - %d\n", stat2);
2870 return (stat1 || stat2) ? -EIO : count;
2872 static DEVICE_ATTR_RW(lpfc_soft_wwpn);
2875 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2876 * @dev: class device that is converted into a Scsi_host.
2877 * @attr: device attribute, not used.
2878 * @buf: on return contains the wwnn in hexadecimal.
2880 * Returns: size of formatted string.
2883 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2886 struct Scsi_Host *shost = class_to_shost(dev);
2887 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2888 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2889 (unsigned long long)phba->cfg_soft_wwnn);
2893 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2894 * @cdev: class device that is converted into a Scsi_host.
2895 * @buf: contains the ww node name in hexadecimal.
2896 * @count: number of wwnn bytes in buf.
2899 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2900 * value of count on success
2903 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2904 const char *buf, size_t count)
2906 struct Scsi_Host *shost = class_to_shost(dev);
2907 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2908 unsigned int cnt = count;
2912 /* count may include a LF at end of string */
2913 if (buf[cnt-1] == '\n')
2916 if (!phba->soft_wwn_enable)
2919 rc = lpfc_wwn_set(buf, cnt, wwnn);
2921 /* Allow wwnn to be set many times, as long as the enable
2922 * is set. However, once the wwpn is set, everything locks.
2927 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2929 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2930 "lpfc%d: soft_wwnn set. Value will take effect upon "
2931 "setting of the soft_wwpn\n", phba->brd_no);
2935 static DEVICE_ATTR_RW(lpfc_soft_wwnn);
2938 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2939 * Optimized Access Storage (OAS) operations.
2940 * @dev: class device that is converted into a Scsi_host.
2941 * @attr: device attribute, not used.
2942 * @buf: buffer for passing information.
2948 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2951 struct Scsi_Host *shost = class_to_shost(dev);
2952 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2954 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2955 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2959 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2960 * Optimized Access Storage (OAS) operations.
2961 * @dev: class device that is converted into a Scsi_host.
2962 * @attr: device attribute, not used.
2963 * @buf: buffer for passing information.
2964 * @count: Size of the data buffer.
2967 * -EINVAL count is invalid, invalid wwpn byte invalid
2968 * -EPERM oas is not supported by hba
2969 * value of count on success
2972 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2973 const char *buf, size_t count)
2975 struct Scsi_Host *shost = class_to_shost(dev);
2976 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2977 unsigned int cnt = count;
2978 uint8_t wwpn[WWN_SZ];
2984 /* count may include a LF at end of string */
2985 if (buf[cnt-1] == '\n')
2988 rc = lpfc_wwn_set(buf, cnt, wwpn);
2992 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2993 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2994 if (wwn_to_u64(wwpn) == 0)
2995 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2997 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2998 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2999 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3002 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
3003 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
3006 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
3007 * Optimized Access Storage (OAS) operations.
3008 * @dev: class device that is converted into a Scsi_host.
3009 * @attr: device attribute, not used.
3010 * @buf: buffer for passing information.
3016 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
3019 struct Scsi_Host *shost = class_to_shost(dev);
3020 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3022 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
3026 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3027 * Optimized Access Storage (OAS) operations.
3028 * @dev: class device that is converted into a Scsi_host.
3029 * @attr: device attribute, not used.
3030 * @buf: buffer for passing information.
3031 * @count: Size of the data buffer.
3034 * -EINVAL count is invalid, invalid wwpn byte invalid
3035 * -EPERM oas is not supported by hba
3036 * value of count on success
3039 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3040 const char *buf, size_t count)
3042 struct Scsi_Host *shost = class_to_shost(dev);
3043 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3044 unsigned int cnt = count;
3051 /* count may include a LF at end of string */
3052 if (buf[cnt-1] == '\n')
3055 ret = kstrtoul(buf, 0, &val);
3056 if (ret || (val > 0x7f))
3060 phba->cfg_oas_priority = (uint8_t)val;
3062 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3065 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3066 lpfc_oas_priority_show, lpfc_oas_priority_store);
3069 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3070 * for Optimized Access Storage (OAS) operations.
3071 * @dev: class device that is converted into a Scsi_host.
3072 * @attr: device attribute, not used.
3073 * @buf: buffer for passing information.
3076 * value of count on success
3079 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3082 struct Scsi_Host *shost = class_to_shost(dev);
3083 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3085 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3086 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3090 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3091 * for Optimized Access Storage (OAS) operations.
3092 * @dev: class device that is converted into a Scsi_host.
3093 * @attr: device attribute, not used.
3094 * @buf: buffer for passing information.
3095 * @count: Size of the data buffer.
3098 * -EINVAL count is invalid, invalid wwpn byte invalid
3099 * -EPERM oas is not supported by hba
3100 * value of count on success
3103 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3104 const char *buf, size_t count)
3106 struct Scsi_Host *shost = class_to_shost(dev);
3107 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3108 unsigned int cnt = count;
3109 uint8_t wwpn[WWN_SZ];
3115 /* count may include a LF at end of string */
3116 if (buf[cnt-1] == '\n')
3119 rc = lpfc_wwn_set(buf, cnt, wwpn);
3123 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3124 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3125 if (wwn_to_u64(wwpn) == 0)
3126 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3128 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3129 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3130 if (phba->cfg_oas_priority == 0)
3131 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3132 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3135 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3136 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3139 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3140 * of whether luns will be enabled or disabled
3141 * for Optimized Access Storage (OAS) operations.
3142 * @dev: class device that is converted into a Scsi_host.
3143 * @attr: device attribute, not used.
3144 * @buf: buffer for passing information.
3147 * size of formatted string.
3150 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3153 struct Scsi_Host *shost = class_to_shost(dev);
3154 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3156 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3160 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3161 * of whether luns will be enabled or disabled
3162 * for Optimized Access Storage (OAS) operations.
3163 * @dev: class device that is converted into a Scsi_host.
3164 * @attr: device attribute, not used.
3165 * @buf: buffer for passing information.
3166 * @count: Size of the data buffer.
3169 * -EINVAL count is invalid, invalid wwpn byte invalid
3170 * -EPERM oas is not supported by hba
3171 * value of count on success
3174 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3175 const char *buf, size_t count)
3177 struct Scsi_Host *shost = class_to_shost(dev);
3178 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3184 if (!isdigit(buf[0]))
3187 if (sscanf(buf, "%i", &val) != 1)
3190 if ((val != 0) && (val != 1))
3193 phba->cfg_oas_lun_state = val;
3196 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3197 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3200 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3201 * Storage (OAS) lun returned by the
3202 * lpfc_oas_lun_show function.
3203 * @dev: class device that is converted into a Scsi_host.
3204 * @attr: device attribute, not used.
3205 * @buf: buffer for passing information.
3208 * size of formatted string.
3211 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3214 struct Scsi_Host *shost = class_to_shost(dev);
3215 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3217 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3220 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3222 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3223 lpfc_oas_lun_status_show, NULL);
3227 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3229 * @phba: lpfc_hba pointer.
3230 * @ndlp: pointer to fcp target node.
3231 * @lun: the fc lun for setting oas state.
3232 * @oas_state: the oas state to be set to the lun.
3236 * -EPERM OAS is not enabled or not supported by this port.
3240 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3241 uint8_t tgt_wwpn[], uint64_t lun,
3242 uint32_t oas_state, uint8_t pri)
3251 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3252 (struct lpfc_name *)tgt_wwpn,
3256 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3257 (struct lpfc_name *)tgt_wwpn, lun, pri);
3264 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3265 * Access Storage (OAS) operations.
3266 * @phba: lpfc_hba pointer.
3267 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3268 * @tgt_wwpn: wwpn of the target associated with the returned lun
3269 * @lun_status: status of the lun returned lun
3271 * Returns the first or next lun enabled for OAS operations for the vport/target
3272 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3273 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3276 * lun that is OAS enabled for the vport/target
3277 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3280 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3281 uint8_t tgt_wwpn[], uint32_t *lun_status,
3286 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3287 return NOT_OAS_ENABLED_LUN;
3288 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3289 phba->sli4_hba.oas_next_vpt_wwpn,
3290 (struct lpfc_name *)
3291 phba->sli4_hba.oas_next_tgt_wwpn,
3292 &phba->sli4_hba.oas_next_lun,
3293 (struct lpfc_name *)vpt_wwpn,
3294 (struct lpfc_name *)tgt_wwpn,
3295 &found_lun, lun_status, lun_pri))
3298 return NOT_OAS_ENABLED_LUN;
3302 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3303 * @phba: lpfc_hba pointer.
3304 * @vpt_wwpn: vport wwpn by reference.
3305 * @tgt_wwpn: target wwpn by reference.
3306 * @lun: the fc lun for setting oas state.
3307 * @oas_state: the oas state to be set to the oas_lun.
3309 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3310 * a lun for OAS operations.
3314 * -ENOMEM: failed to enable an lun for OAS operations
3315 * -EPERM: OAS is not enabled
3318 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3319 uint8_t tgt_wwpn[], uint64_t lun,
3320 uint32_t oas_state, uint8_t pri)
3325 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3331 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3332 * @dev: class device that is converted into a Scsi_host.
3333 * @attr: device attribute, not used.
3334 * @buf: buffer for passing information.
3336 * This routine returns a lun enabled for OAS each time the function
3340 * SUCCESS: size of formatted string.
3341 * -EFAULT: target or vport wwpn was not set properly.
3342 * -EPERM: oas is not enabled.
3345 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3348 struct Scsi_Host *shost = class_to_shost(dev);
3349 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3357 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3358 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3361 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3362 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3365 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3366 phba->cfg_oas_tgt_wwpn,
3367 &phba->cfg_oas_lun_status,
3368 &phba->cfg_oas_priority);
3369 if (oas_lun != NOT_OAS_ENABLED_LUN)
3370 phba->cfg_oas_flags |= OAS_LUN_VALID;
3372 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3378 * lpfc_oas_lun_store - Sets the OAS state for lun
3379 * @dev: class device that is converted into a Scsi_host.
3380 * @attr: device attribute, not used.
3381 * @buf: buffer for passing information.
3383 * This function sets the OAS state for lun. Before this function is called,
3384 * the vport wwpn, target wwpn, and oas state need to be set.
3387 * SUCCESS: size of formatted string.
3388 * -EFAULT: target or vport wwpn was not set properly.
3389 * -EPERM: oas is not enabled.
3390 * size of formatted string.
3393 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3394 const char *buf, size_t count)
3396 struct Scsi_Host *shost = class_to_shost(dev);
3397 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3405 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3408 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3411 if (!isdigit(buf[0]))
3414 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3417 pri = phba->cfg_oas_priority;
3419 pri = phba->cfg_XLanePriority;
3421 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3422 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3423 "priority 0x%x with oas state %d\n",
3424 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3425 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3426 pri, phba->cfg_oas_lun_state);
3428 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3429 phba->cfg_oas_tgt_wwpn, scsi_lun,
3430 phba->cfg_oas_lun_state, pri);
3436 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3437 lpfc_oas_lun_show, lpfc_oas_lun_store);
3439 int lpfc_enable_nvmet_cnt;
3440 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3441 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3442 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3443 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3444 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3446 static int lpfc_poll = 0;
3447 module_param(lpfc_poll, int, S_IRUGO);
3448 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3450 " 1 - poll with interrupts enabled"
3451 " 3 - poll and disable FCP ring interrupts");
3453 static DEVICE_ATTR_RW(lpfc_poll);
3455 int lpfc_no_hba_reset_cnt;
3456 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3457 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3458 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3459 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3461 LPFC_ATTR(sli_mode, 0, 0, 3,
3462 "SLI mode selector:"
3463 " 0 - auto (SLI-3 if supported),"
3464 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3465 " 3 - select SLI-3");
3467 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3468 "Enable NPIV functionality");
3470 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3471 "FCF Fast failover=1 Priority failover=2");
3474 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3475 # 0x0 = disabled, XRI/OXID use not tracked.
3476 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3477 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3479 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3480 "Enable RRQ functionality");
3483 # lpfc_suppress_link_up: Bring link up at initialization
3484 # 0x0 = bring link up (issue MBX_INIT_LINK)
3485 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3486 # 0x2 = never bring up link
3487 # Default value is 0.
3489 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3490 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3491 "Suppress Link Up at initialization");
3494 lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3496 struct Scsi_Host *shost = class_to_shost(dev);
3497 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3499 return scnprintf(buf, PAGE_SIZE, "%d\n",
3500 phba->sli4_hba.pc_sli4_params.pls);
3502 static DEVICE_ATTR(pls, 0444,
3503 lpfc_pls_show, NULL);
3506 lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3508 struct Scsi_Host *shost = class_to_shost(dev);
3509 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3511 return scnprintf(buf, PAGE_SIZE, "%d\n",
3512 (phba->hba_flag & HBA_PERSISTENT_TOPO) ? 1 : 0);
3514 static DEVICE_ATTR(pt, 0444,
3515 lpfc_pt_show, NULL);
3518 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3526 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3528 struct Scsi_Host *shost = class_to_shost(dev);
3529 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3531 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3534 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3535 lpfc_iocb_hw_show, NULL);
3537 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3539 struct Scsi_Host *shost = class_to_shost(dev);
3540 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3541 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3543 return scnprintf(buf, PAGE_SIZE, "%d\n",
3544 pring ? pring->txq_max : 0);
3547 static DEVICE_ATTR(txq_hw, S_IRUGO,
3548 lpfc_txq_hw_show, NULL);
3550 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3553 struct Scsi_Host *shost = class_to_shost(dev);
3554 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3555 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3557 return scnprintf(buf, PAGE_SIZE, "%d\n",
3558 pring ? pring->txcmplq_max : 0);
3561 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3562 lpfc_txcmplq_hw_show, NULL);
3565 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3566 # until the timer expires. Value range is [0,255]. Default value is 30.
3568 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3569 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3570 module_param(lpfc_nodev_tmo, int, 0);
3571 MODULE_PARM_DESC(lpfc_nodev_tmo,
3572 "Seconds driver will hold I/O waiting "
3573 "for a device to come back");
3576 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3577 * @dev: class converted to a Scsi_host structure.
3578 * @attr: device attribute, not used.
3579 * @buf: on return contains the dev loss timeout in decimal.
3581 * Returns: size of formatted string.
3584 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3587 struct Scsi_Host *shost = class_to_shost(dev);
3588 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3590 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3594 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3595 * @vport: lpfc vport structure pointer.
3596 * @val: contains the nodev timeout value.
3599 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3600 * a kernel error message is printed and zero is returned.
3601 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3602 * Otherwise nodev tmo is set to the default value.
3605 * zero if already set or if val is in range
3606 * -EINVAL val out of range
3609 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3611 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3612 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3613 if (val != LPFC_DEF_DEVLOSS_TMO)
3614 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3615 "0407 Ignoring lpfc_nodev_tmo module "
3616 "parameter because lpfc_devloss_tmo "
3621 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3622 vport->cfg_nodev_tmo = val;
3623 vport->cfg_devloss_tmo = val;
3626 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3627 "0400 lpfc_nodev_tmo attribute cannot be set to"
3628 " %d, allowed range is [%d, %d]\n",
3629 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3630 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3635 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3636 * @vport: lpfc vport structure pointer.
3639 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3642 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3644 struct Scsi_Host *shost;
3645 struct lpfc_nodelist *ndlp;
3646 #if (IS_ENABLED(CONFIG_NVME_FC))
3647 struct lpfc_nvme_rport *rport;
3648 struct nvme_fc_remote_port *remoteport = NULL;
3651 shost = lpfc_shost_from_vport(vport);
3652 spin_lock_irq(shost->host_lock);
3653 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3654 if (!NLP_CHK_NODE_ACT(ndlp))
3657 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3658 #if (IS_ENABLED(CONFIG_NVME_FC))
3659 spin_lock(&vport->phba->hbalock);
3660 rport = lpfc_ndlp_get_nrport(ndlp);
3662 remoteport = rport->remoteport;
3663 spin_unlock(&vport->phba->hbalock);
3664 if (rport && remoteport)
3665 nvme_fc_set_remoteport_devloss(remoteport,
3666 vport->cfg_devloss_tmo);
3669 spin_unlock_irq(shost->host_lock);
3673 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3674 * @vport: lpfc vport structure pointer.
3675 * @val: contains the tmo value.
3678 * If the devloss tmo is already set or the vport dev loss tmo has changed
3679 * then a kernel error message is printed and zero is returned.
3680 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3681 * Otherwise nodev tmo is set to the default value.
3684 * zero if already set or if val is in range
3685 * -EINVAL val out of range
3688 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3690 if (vport->dev_loss_tmo_changed ||
3691 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3692 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3693 "0401 Ignoring change to lpfc_nodev_tmo "
3694 "because lpfc_devloss_tmo is set.\n");
3697 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3698 vport->cfg_nodev_tmo = val;
3699 vport->cfg_devloss_tmo = val;
3701 * For compat: set the fc_host dev loss so new rports
3702 * will get the value.
3704 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3705 lpfc_update_rport_devloss_tmo(vport);
3708 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3709 "0403 lpfc_nodev_tmo attribute cannot be set to "
3710 "%d, allowed range is [%d, %d]\n",
3711 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3715 lpfc_vport_param_store(nodev_tmo)
3717 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3720 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3721 # disappear until the timer expires. Value range is [0,255]. Default
3724 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3725 MODULE_PARM_DESC(lpfc_devloss_tmo,
3726 "Seconds driver will hold I/O waiting "
3727 "for a device to come back");
3728 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3729 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3730 lpfc_vport_param_show(devloss_tmo)
3733 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3734 * @vport: lpfc vport structure pointer.
3735 * @val: contains the tmo value.
3738 * If val is in a valid range then set the vport nodev tmo,
3739 * devloss tmo, also set the vport dev loss tmo changed flag.
3740 * Else a kernel error message is printed.
3743 * zero if val is in range
3744 * -EINVAL val out of range
3747 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3749 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3750 vport->cfg_nodev_tmo = val;
3751 vport->cfg_devloss_tmo = val;
3752 vport->dev_loss_tmo_changed = 1;
3753 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3754 lpfc_update_rport_devloss_tmo(vport);
3758 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3759 "0404 lpfc_devloss_tmo attribute cannot be set to "
3760 "%d, allowed range is [%d, %d]\n",
3761 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3765 lpfc_vport_param_store(devloss_tmo)
3766 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3769 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3770 * lpfc_suppress_rsp = 0 Disable
3771 * lpfc_suppress_rsp = 1 Enable (default)
3774 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3775 "Enable suppress rsp feature is firmware supports it");
3778 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3779 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3780 * lpfc_nvmet_mrq = 1 use a single RQ pair
3781 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3784 LPFC_ATTR_R(nvmet_mrq,
3785 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3786 "Specify number of RQ pairs for processing NVMET cmds");
3789 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3790 * to each NVMET RQ. Range 64 to 2048, default is 512.
3792 LPFC_ATTR_R(nvmet_mrq_post,
3793 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3794 LPFC_NVMET_RQE_DEF_COUNT,
3795 "Specify number of RQ buffers to initially post");
3798 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3799 * Supported Values: 1 - register just FCP
3800 * 3 - register both FCP and NVME
3801 * Supported values are [1,3]. Default value is 3
3803 LPFC_ATTR_R(enable_fc4_type, LPFC_DEF_ENBL_FC4_TYPE,
3804 LPFC_ENABLE_FCP, LPFC_MAX_ENBL_FC4_TYPE,
3805 "Enable FC4 Protocol support - FCP / NVME");
3808 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3809 # deluged with LOTS of information.
3810 # You can set a bit mask to record specific types of verbose messages:
3811 # See lpfc_logmsh.h for definitions.
3813 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3814 "Verbose logging bit-mask");
3817 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3818 # objects that have been registered with the nameserver after login.
3820 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3821 "Deregister nameserver objects before LOGO");
3824 # lun_queue_depth: This parameter is used to limit the number of outstanding
3825 # commands per FCP LUN.
3827 LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
3828 "Max number of FCP commands we can queue to a specific LUN");
3831 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3832 # commands per target port. Value range is [10,65535]. Default value is 65535.
3834 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3835 module_param(lpfc_tgt_queue_depth, uint, 0444);
3836 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3837 lpfc_vport_param_show(tgt_queue_depth);
3838 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3839 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3842 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3843 * @phba: pointer the the adapter structure.
3844 * @val: integer attribute value.
3846 * Description: Sets the parameter to the new value.
3850 * -EINVAL if val is invalid
3853 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3856 struct lpfc_nodelist *ndlp;
3858 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3861 if (val == vport->cfg_tgt_queue_depth)
3864 spin_lock_irq(shost->host_lock);
3865 vport->cfg_tgt_queue_depth = val;
3867 /* Next loop thru nodelist and change cmd_qdepth */
3868 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3869 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3871 spin_unlock_irq(shost->host_lock);
3875 lpfc_vport_param_store(tgt_queue_depth);
3876 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3879 # hba_queue_depth: This parameter is used to limit the number of outstanding
3880 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3881 # value is greater than the maximum number of exchanges supported by the HBA,
3882 # then maximum number of exchanges supported by the HBA is used to determine
3883 # the hba_queue_depth.
3885 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3886 "Max number of FCP commands we can queue to a lpfc HBA");
3889 # peer_port_login: This parameter allows/prevents logins
3890 # between peer ports hosted on the same physical port.
3891 # When this parameter is set 0 peer ports of same physical port
3892 # are not allowed to login to each other.
3893 # When this parameter is set 1 peer ports of same physical port
3894 # are allowed to login to each other.
3895 # Default value of this parameter is 0.
3897 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3898 "Allow peer ports on the same physical port to login to each "
3902 # restrict_login: This parameter allows/prevents logins
3903 # between Virtual Ports and remote initiators.
3904 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3905 # other initiators and will attempt to PLOGI all remote ports.
3906 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3907 # remote ports and will not attempt to PLOGI to other initiators.
3908 # This parameter does not restrict to the physical port.
3909 # This parameter does not restrict logins to Fabric resident remote ports.
3910 # Default value of this parameter is 1.
3912 static int lpfc_restrict_login = 1;
3913 module_param(lpfc_restrict_login, int, S_IRUGO);
3914 MODULE_PARM_DESC(lpfc_restrict_login,
3915 "Restrict virtual ports login to remote initiators.");
3916 lpfc_vport_param_show(restrict_login);
3919 * lpfc_restrict_login_init - Set the vport restrict login flag
3920 * @vport: lpfc vport structure pointer.
3921 * @val: contains the restrict login value.
3924 * If val is not in a valid range then log a kernel error message and set
3925 * the vport restrict login to one.
3926 * If the port type is physical clear the restrict login flag and return.
3927 * Else set the restrict login flag to val.
3930 * zero if val is in range
3931 * -EINVAL val out of range
3934 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3936 if (val < 0 || val > 1) {
3937 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3938 "0422 lpfc_restrict_login attribute cannot "
3939 "be set to %d, allowed range is [0, 1]\n",
3941 vport->cfg_restrict_login = 1;
3944 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3945 vport->cfg_restrict_login = 0;
3948 vport->cfg_restrict_login = val;
3953 * lpfc_restrict_login_set - Set the vport restrict login flag
3954 * @vport: lpfc vport structure pointer.
3955 * @val: contains the restrict login value.
3958 * If val is not in a valid range then log a kernel error message and set
3959 * the vport restrict login to one.
3960 * If the port type is physical and the val is not zero log a kernel
3961 * error message, clear the restrict login flag and return zero.
3962 * Else set the restrict login flag to val.
3965 * zero if val is in range
3966 * -EINVAL val out of range
3969 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3971 if (val < 0 || val > 1) {
3972 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3973 "0425 lpfc_restrict_login attribute cannot "
3974 "be set to %d, allowed range is [0, 1]\n",
3976 vport->cfg_restrict_login = 1;
3979 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3980 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3981 "0468 lpfc_restrict_login must be 0 for "
3982 "Physical ports.\n");
3983 vport->cfg_restrict_login = 0;
3986 vport->cfg_restrict_login = val;
3989 lpfc_vport_param_store(restrict_login);
3990 static DEVICE_ATTR_RW(lpfc_restrict_login);
3993 # Some disk devices have a "select ID" or "select Target" capability.
3994 # From a protocol standpoint "select ID" usually means select the
3995 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3996 # annex" which contains a table that maps a "select ID" (a number
3997 # between 0 and 7F) to an ALPA. By default, for compatibility with
3998 # older drivers, the lpfc driver scans this table from low ALPA to high
4001 # Turning on the scan-down variable (on = 1, off = 0) will
4002 # cause the lpfc driver to use an inverted table, effectively
4003 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
4005 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
4006 # and will not work across a fabric. Also this parameter will take
4007 # effect only in the case when ALPA map is not available.)
4009 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
4010 "Start scanning for devices from highest ALPA to lowest");
4013 # lpfc_topology: link topology for init link
4014 # 0x0 = attempt loop mode then point-to-point
4015 # 0x01 = internal loopback mode
4016 # 0x02 = attempt point-to-point mode only
4017 # 0x04 = attempt loop mode only
4018 # 0x06 = attempt point-to-point mode then loop
4019 # Set point-to-point mode if you want to run as an N_Port.
4020 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4021 # Default value is 0.
4023 LPFC_ATTR(topology, 0, 0, 6,
4024 "Select Fibre Channel topology");
4027 * lpfc_topology_set - Set the adapters topology field
4028 * @phba: lpfc_hba pointer.
4029 * @val: topology value.
4032 * If val is in a valid range then set the adapter's topology field and
4033 * issue a lip; if the lip fails reset the topology to the old value.
4035 * If the value is not in range log a kernel error message and return an error.
4038 * zero if val is in range and lip okay
4039 * non-zero return value from lpfc_issue_lip()
4040 * -EINVAL val out of range
4043 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4044 const char *buf, size_t count)
4046 struct Scsi_Host *shost = class_to_shost(dev);
4047 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4048 struct lpfc_hba *phba = vport->phba;
4051 const char *val_buf = buf;
4055 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4057 val_buf = &buf[strlen("nolip ")];
4060 if (!isdigit(val_buf[0]))
4062 if (sscanf(val_buf, "%i", &val) != 1)
4065 if (val >= 0 && val <= 6) {
4066 prev_val = phba->cfg_topology;
4067 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4069 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4070 "3113 Loop mode not supported at speed %d\n",
4075 * The 'topology' is not a configurable parameter if :
4076 * - persistent topology enabled
4077 * - G7/G6 with no private loop support
4080 if ((phba->hba_flag & HBA_PERSISTENT_TOPO ||
4081 (!phba->sli4_hba.pc_sli4_params.pls &&
4082 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
4083 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC))) &&
4085 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4086 "3114 Loop mode not supported\n");
4089 phba->cfg_topology = val;
4093 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4094 "3054 lpfc_topology changed from %d to %d\n",
4096 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4097 phba->fc_topology_changed = 1;
4098 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4100 phba->cfg_topology = prev_val;
4105 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4106 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4107 "allowed range is [0, 6]\n",
4112 lpfc_param_show(topology)
4113 static DEVICE_ATTR_RW(lpfc_topology);
4116 * lpfc_static_vport_show: Read callback function for
4117 * lpfc_static_vport sysfs file.
4118 * @dev: Pointer to class device object.
4119 * @attr: device attribute structure.
4120 * @buf: Data buffer.
4122 * This function is the read call back function for
4123 * lpfc_static_vport sysfs file. The lpfc_static_vport
4124 * sysfs file report the mageability of the vport.
4127 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4130 struct Scsi_Host *shost = class_to_shost(dev);
4131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4132 if (vport->vport_flag & STATIC_VPORT)
4133 sprintf(buf, "1\n");
4135 sprintf(buf, "0\n");
4141 * Sysfs attribute to control the statistical data collection.
4143 static DEVICE_ATTR_RO(lpfc_static_vport);
4146 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
4147 * @dev: Pointer to class device.
4148 * @buf: Data buffer.
4149 * @count: Size of the data buffer.
4151 * This function get called when a user write to the lpfc_stat_data_ctrl
4152 * sysfs file. This function parse the command written to the sysfs file
4153 * and take appropriate action. These commands are used for controlling
4154 * driver statistical data collection.
4155 * Following are the command this function handles.
4157 * setbucket <bucket_type> <base> <step>
4158 * = Set the latency buckets.
4159 * destroybucket = destroy all the buckets.
4160 * start = start data collection
4161 * stop = stop data collection
4162 * reset = reset the collected data
4165 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4166 const char *buf, size_t count)
4168 struct Scsi_Host *shost = class_to_shost(dev);
4169 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4170 struct lpfc_hba *phba = vport->phba;
4171 #define LPFC_MAX_DATA_CTRL_LEN 1024
4172 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4174 char *str_ptr, *token;
4175 struct lpfc_vport **vports;
4176 struct Scsi_Host *v_shost;
4177 char *bucket_type_str, *base_str, *step_str;
4178 unsigned long base, step, bucket_type;
4180 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
4181 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
4184 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
4185 str_ptr = &bucket_data[0];
4186 /* Ignore this token - this is command token */
4187 token = strsep(&str_ptr, "\t ");
4191 bucket_type_str = strsep(&str_ptr, "\t ");
4192 if (!bucket_type_str)
4195 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4196 bucket_type = LPFC_LINEAR_BUCKET;
4197 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4198 bucket_type = LPFC_POWER2_BUCKET;
4202 base_str = strsep(&str_ptr, "\t ");
4205 base = simple_strtoul(base_str, NULL, 0);
4207 step_str = strsep(&str_ptr, "\t ");
4210 step = simple_strtoul(step_str, NULL, 0);
4214 /* Block the data collection for every vport */
4215 vports = lpfc_create_vport_work_array(phba);
4219 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4220 v_shost = lpfc_shost_from_vport(vports[i]);
4221 spin_lock_irq(v_shost->host_lock);
4222 /* Block and reset data collection */
4223 vports[i]->stat_data_blocked = 1;
4224 if (vports[i]->stat_data_enabled)
4225 lpfc_vport_reset_stat_data(vports[i]);
4226 spin_unlock_irq(v_shost->host_lock);
4229 /* Set the bucket attributes */
4230 phba->bucket_type = bucket_type;
4231 phba->bucket_base = base;
4232 phba->bucket_step = step;
4234 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4235 v_shost = lpfc_shost_from_vport(vports[i]);
4237 /* Unblock data collection */
4238 spin_lock_irq(v_shost->host_lock);
4239 vports[i]->stat_data_blocked = 0;
4240 spin_unlock_irq(v_shost->host_lock);
4242 lpfc_destroy_vport_work_array(phba, vports);
4246 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4247 vports = lpfc_create_vport_work_array(phba);
4251 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4252 v_shost = lpfc_shost_from_vport(vports[i]);
4253 spin_lock_irq(shost->host_lock);
4254 vports[i]->stat_data_blocked = 1;
4255 lpfc_free_bucket(vport);
4256 vport->stat_data_enabled = 0;
4257 vports[i]->stat_data_blocked = 0;
4258 spin_unlock_irq(shost->host_lock);
4260 lpfc_destroy_vport_work_array(phba, vports);
4261 phba->bucket_type = LPFC_NO_BUCKET;
4262 phba->bucket_base = 0;
4263 phba->bucket_step = 0;
4267 if (!strncmp(buf, "start", strlen("start"))) {
4268 /* If no buckets configured return error */
4269 if (phba->bucket_type == LPFC_NO_BUCKET)
4271 spin_lock_irq(shost->host_lock);
4272 if (vport->stat_data_enabled) {
4273 spin_unlock_irq(shost->host_lock);
4276 lpfc_alloc_bucket(vport);
4277 vport->stat_data_enabled = 1;
4278 spin_unlock_irq(shost->host_lock);
4282 if (!strncmp(buf, "stop", strlen("stop"))) {
4283 spin_lock_irq(shost->host_lock);
4284 if (vport->stat_data_enabled == 0) {
4285 spin_unlock_irq(shost->host_lock);
4288 lpfc_free_bucket(vport);
4289 vport->stat_data_enabled = 0;
4290 spin_unlock_irq(shost->host_lock);
4294 if (!strncmp(buf, "reset", strlen("reset"))) {
4295 if ((phba->bucket_type == LPFC_NO_BUCKET)
4296 || !vport->stat_data_enabled)
4298 spin_lock_irq(shost->host_lock);
4299 vport->stat_data_blocked = 1;
4300 lpfc_vport_reset_stat_data(vport);
4301 vport->stat_data_blocked = 0;
4302 spin_unlock_irq(shost->host_lock);
4310 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
4311 * @dev: Pointer to class device object.
4312 * @buf: Data buffer.
4314 * This function is the read call back function for
4315 * lpfc_stat_data_ctrl sysfs file. This function report the
4316 * current statistical data collection state.
4319 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4322 struct Scsi_Host *shost = class_to_shost(dev);
4323 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4324 struct lpfc_hba *phba = vport->phba;
4328 unsigned long bucket_value;
4330 switch (phba->bucket_type) {
4331 case LPFC_LINEAR_BUCKET:
4332 bucket_type = "linear";
4334 case LPFC_POWER2_BUCKET:
4335 bucket_type = "power2";
4338 bucket_type = "No Bucket";
4342 sprintf(&buf[index], "Statistical Data enabled :%d, "
4343 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4344 " Bucket step :%d\nLatency Ranges :",
4345 vport->stat_data_enabled, vport->stat_data_blocked,
4346 bucket_type, phba->bucket_base, phba->bucket_step);
4347 index = strlen(buf);
4348 if (phba->bucket_type != LPFC_NO_BUCKET) {
4349 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4350 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4351 bucket_value = phba->bucket_base +
4352 phba->bucket_step * i;
4354 bucket_value = phba->bucket_base +
4355 (1 << i) * phba->bucket_step;
4357 if (index + 10 > PAGE_SIZE)
4359 sprintf(&buf[index], "%08ld ", bucket_value);
4360 index = strlen(buf);
4363 sprintf(&buf[index], "\n");
4368 * Sysfs attribute to control the statistical data collection.
4370 static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
4373 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4377 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4380 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4381 #define MAX_STAT_DATA_SIZE_PER_TARGET \
4382 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4386 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
4388 * @kobj: Pointer to the kernel object
4389 * @bin_attr: Attribute object
4390 * @buff: Buffer pointer
4392 * @count: Buffer size
4394 * This function is the read call back function for lpfc_drvr_stat_data
4395 * sysfs file. This function export the statistical data to user
4399 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4400 struct bin_attribute *bin_attr,
4401 char *buf, loff_t off, size_t count)
4403 struct device *dev = container_of(kobj, struct device,
4405 struct Scsi_Host *shost = class_to_shost(dev);
4406 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4407 struct lpfc_hba *phba = vport->phba;
4408 int i = 0, index = 0;
4409 unsigned long nport_index;
4410 struct lpfc_nodelist *ndlp = NULL;
4411 nport_index = (unsigned long)off /
4412 MAX_STAT_DATA_SIZE_PER_TARGET;
4414 if (!vport->stat_data_enabled || vport->stat_data_blocked
4415 || (phba->bucket_type == LPFC_NO_BUCKET))
4418 spin_lock_irq(shost->host_lock);
4419 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4420 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4423 if (nport_index > 0) {
4428 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4432 if (!ndlp->lat_data)
4436 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4437 ndlp->nlp_portname.u.wwn[0],
4438 ndlp->nlp_portname.u.wwn[1],
4439 ndlp->nlp_portname.u.wwn[2],
4440 ndlp->nlp_portname.u.wwn[3],
4441 ndlp->nlp_portname.u.wwn[4],
4442 ndlp->nlp_portname.u.wwn[5],
4443 ndlp->nlp_portname.u.wwn[6],
4444 ndlp->nlp_portname.u.wwn[7]);
4446 index = strlen(buf);
4448 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4449 sprintf(&buf[index], "%010u,",
4450 ndlp->lat_data[i].cmd_count);
4451 index = strlen(buf);
4453 sprintf(&buf[index], "\n");
4454 index = strlen(buf);
4456 spin_unlock_irq(shost->host_lock);
4460 static struct bin_attribute sysfs_drvr_stat_data_attr = {
4462 .name = "lpfc_drvr_stat_data",
4465 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4466 .read = sysfs_drvr_stat_data_read,
4471 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4473 # Value range is [0,16]. Default value is 0.
4476 * lpfc_link_speed_set - Set the adapters link speed
4477 * @phba: lpfc_hba pointer.
4478 * @val: link speed value.
4481 * If val is in a valid range then set the adapter's link speed field and
4482 * issue a lip; if the lip fails reset the link speed to the old value.
4485 * If the value is not in range log a kernel error message and return an error.
4488 * zero if val is in range and lip okay.
4489 * non-zero return value from lpfc_issue_lip()
4490 * -EINVAL val out of range
4493 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4494 const char *buf, size_t count)
4496 struct Scsi_Host *shost = class_to_shost(dev);
4497 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4498 struct lpfc_hba *phba = vport->phba;
4499 int val = LPFC_USER_LINK_SPEED_AUTO;
4501 const char *val_buf = buf;
4503 uint32_t prev_val, if_type;
4505 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4506 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4507 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4510 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4512 val_buf = &buf[strlen("nolip ")];
4515 if (!isdigit(val_buf[0]))
4517 if (sscanf(val_buf, "%i", &val) != 1)
4520 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4521 "3055 lpfc_link_speed changed from %d to %d %s\n",
4522 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4524 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4525 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4526 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4527 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4528 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4529 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4530 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4531 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4532 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4533 "2879 lpfc_link_speed attribute cannot be set "
4534 "to %d. Speed is not supported by this port.\n",
4538 if (val >= LPFC_USER_LINK_SPEED_16G &&
4539 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4540 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4541 "3112 lpfc_link_speed attribute cannot be set "
4542 "to %d. Speed is not supported in loop mode.\n",
4548 case LPFC_USER_LINK_SPEED_AUTO:
4549 case LPFC_USER_LINK_SPEED_1G:
4550 case LPFC_USER_LINK_SPEED_2G:
4551 case LPFC_USER_LINK_SPEED_4G:
4552 case LPFC_USER_LINK_SPEED_8G:
4553 case LPFC_USER_LINK_SPEED_16G:
4554 case LPFC_USER_LINK_SPEED_32G:
4555 case LPFC_USER_LINK_SPEED_64G:
4556 prev_val = phba->cfg_link_speed;
4557 phba->cfg_link_speed = val;
4561 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4563 phba->cfg_link_speed = prev_val;
4571 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4572 "0469 lpfc_link_speed attribute cannot be set to %d, "
4573 "allowed values are [%s]\n",
4574 val, LPFC_LINK_SPEED_STRING);
4579 static int lpfc_link_speed = 0;
4580 module_param(lpfc_link_speed, int, S_IRUGO);
4581 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4582 lpfc_param_show(link_speed)
4585 * lpfc_link_speed_init - Set the adapters link speed
4586 * @phba: lpfc_hba pointer.
4587 * @val: link speed value.
4590 * If val is in a valid range then set the adapter's link speed field.
4593 * If the value is not in range log a kernel error message, clear the link
4594 * speed and return an error.
4597 * zero if val saved.
4598 * -EINVAL val out of range
4601 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4603 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4604 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4605 "3111 lpfc_link_speed of %d cannot "
4606 "support loop mode, setting topology to default.\n",
4608 phba->cfg_topology = 0;
4612 case LPFC_USER_LINK_SPEED_AUTO:
4613 case LPFC_USER_LINK_SPEED_1G:
4614 case LPFC_USER_LINK_SPEED_2G:
4615 case LPFC_USER_LINK_SPEED_4G:
4616 case LPFC_USER_LINK_SPEED_8G:
4617 case LPFC_USER_LINK_SPEED_16G:
4618 case LPFC_USER_LINK_SPEED_32G:
4619 case LPFC_USER_LINK_SPEED_64G:
4620 phba->cfg_link_speed = val;
4623 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4624 "0405 lpfc_link_speed attribute cannot "
4625 "be set to %d, allowed values are "
4626 "["LPFC_LINK_SPEED_STRING"]\n", val);
4627 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4632 static DEVICE_ATTR_RW(lpfc_link_speed);
4635 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4636 # 0 = aer disabled or not supported
4637 # 1 = aer supported and enabled (default)
4638 # Value range is [0,1]. Default value is 1.
4640 LPFC_ATTR(aer_support, 1, 0, 1,
4641 "Enable PCIe device AER support");
4642 lpfc_param_show(aer_support)
4645 * lpfc_aer_support_store - Set the adapter for aer support
4647 * @dev: class device that is converted into a Scsi_host.
4648 * @attr: device attribute, not used.
4649 * @buf: containing enable or disable aer flag.
4650 * @count: unused variable.
4653 * If the val is 1 and currently the device's AER capability was not
4654 * enabled, invoke the kernel's enable AER helper routine, trying to
4655 * enable the device's AER capability. If the helper routine enabling
4656 * AER returns success, update the device's cfg_aer_support flag to
4657 * indicate AER is supported by the device; otherwise, if the device
4658 * AER capability is already enabled to support AER, then do nothing.
4660 * If the val is 0 and currently the device's AER support was enabled,
4661 * invoke the kernel's disable AER helper routine. After that, update
4662 * the device's cfg_aer_support flag to indicate AER is not supported
4663 * by the device; otherwise, if the device AER capability is already
4664 * disabled from supporting AER, then do nothing.
4667 * length of the buf on success if val is in range the intended mode
4669 * -EINVAL if val out of range or intended mode is not supported.
4672 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4673 const char *buf, size_t count)
4675 struct Scsi_Host *shost = class_to_shost(dev);
4676 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4677 struct lpfc_hba *phba = vport->phba;
4678 int val = 0, rc = -EINVAL;
4680 if (!isdigit(buf[0]))
4682 if (sscanf(buf, "%i", &val) != 1)
4687 if (phba->hba_flag & HBA_AER_ENABLED) {
4688 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4690 spin_lock_irq(&phba->hbalock);
4691 phba->hba_flag &= ~HBA_AER_ENABLED;
4692 spin_unlock_irq(&phba->hbalock);
4693 phba->cfg_aer_support = 0;
4698 phba->cfg_aer_support = 0;
4703 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4704 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4706 spin_lock_irq(&phba->hbalock);
4707 phba->hba_flag |= HBA_AER_ENABLED;
4708 spin_unlock_irq(&phba->hbalock);
4709 phba->cfg_aer_support = 1;
4714 phba->cfg_aer_support = 1;
4725 static DEVICE_ATTR_RW(lpfc_aer_support);
4728 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4729 * @dev: class device that is converted into a Scsi_host.
4730 * @attr: device attribute, not used.
4731 * @buf: containing flag 1 for aer cleanup state.
4732 * @count: unused variable.
4735 * If the @buf contains 1 and the device currently has the AER support
4736 * enabled, then invokes the kernel AER helper routine
4737 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
4738 * error status register.
4743 * -EINVAL if the buf does not contain the 1 or the device is not currently
4744 * enabled with the AER support.
4747 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4748 const char *buf, size_t count)
4750 struct Scsi_Host *shost = class_to_shost(dev);
4751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4752 struct lpfc_hba *phba = vport->phba;
4755 if (!isdigit(buf[0]))
4757 if (sscanf(buf, "%i", &val) != 1)
4762 if (phba->hba_flag & HBA_AER_ENABLED)
4763 rc = pci_aer_clear_nonfatal_status(phba->pcidev);
4771 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4772 lpfc_aer_cleanup_state);
4775 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4777 * @dev: class device that is converted into a Scsi_host.
4778 * @attr: device attribute, not used.
4779 * @buf: containing the string the number of vfs to be enabled.
4780 * @count: unused variable.
4783 * When this api is called either through user sysfs, the driver shall
4784 * try to enable or disable SR-IOV virtual functions according to the
4787 * If zero virtual function has been enabled to the physical function,
4788 * the driver shall invoke the pci enable virtual function api trying
4789 * to enable the virtual functions. If the nr_vfn provided is greater
4790 * than the maximum supported, the maximum virtual function number will
4791 * be used for invoking the api; otherwise, the nr_vfn provided shall
4792 * be used for invoking the api. If the api call returned success, the
4793 * actual number of virtual functions enabled will be set to the driver
4794 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4795 * cfg_sriov_nr_virtfn remains zero.
4797 * If none-zero virtual functions have already been enabled to the
4798 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4799 * -EINVAL will be returned and the driver does nothing;
4801 * If the nr_vfn provided is zero and none-zero virtual functions have
4802 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4803 * disabling virtual function api shall be invoded to disable all the
4804 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4805 * zero. Otherwise, if zero virtual function has been enabled, do
4809 * length of the buf on success if val is in range the intended mode
4811 * -EINVAL if val out of range or intended mode is not supported.
4814 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4815 const char *buf, size_t count)
4817 struct Scsi_Host *shost = class_to_shost(dev);
4818 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4819 struct lpfc_hba *phba = vport->phba;
4820 struct pci_dev *pdev = phba->pcidev;
4821 int val = 0, rc = -EINVAL;
4823 /* Sanity check on user data */
4824 if (!isdigit(buf[0]))
4826 if (sscanf(buf, "%i", &val) != 1)
4831 /* Request disabling virtual functions */
4833 if (phba->cfg_sriov_nr_virtfn > 0) {
4834 pci_disable_sriov(pdev);
4835 phba->cfg_sriov_nr_virtfn = 0;
4840 /* Request enabling virtual functions */
4841 if (phba->cfg_sriov_nr_virtfn > 0) {
4842 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4843 "3018 There are %d virtual functions "
4844 "enabled on physical function.\n",
4845 phba->cfg_sriov_nr_virtfn);
4849 if (val <= LPFC_MAX_VFN_PER_PFN)
4850 phba->cfg_sriov_nr_virtfn = val;
4852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4853 "3019 Enabling %d virtual functions is not "
4858 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4860 phba->cfg_sriov_nr_virtfn = 0;
4868 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4869 "Enable PCIe device SR-IOV virtual fn");
4871 lpfc_param_show(sriov_nr_virtfn)
4872 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4875 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4877 * @dev: class device that is converted into a Scsi_host.
4878 * @attr: device attribute, not used.
4879 * @buf: containing the string the number of vfs to be enabled.
4880 * @count: unused variable.
4885 * length of the buf on success if val is in range the intended mode
4887 * -EINVAL if val out of range or intended mode is not supported.
4890 lpfc_request_firmware_upgrade_store(struct device *dev,
4891 struct device_attribute *attr,
4892 const char *buf, size_t count)
4894 struct Scsi_Host *shost = class_to_shost(dev);
4895 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4896 struct lpfc_hba *phba = vport->phba;
4899 /* Sanity check on user data */
4900 if (!isdigit(buf[0]))
4902 if (sscanf(buf, "%i", &val) != 1)
4907 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4915 static int lpfc_req_fw_upgrade;
4916 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4917 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4918 lpfc_param_show(request_firmware_upgrade)
4921 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4922 * @phba: lpfc_hba pointer.
4926 * Set the initial Linux generic firmware upgrade enable or disable flag.
4929 * zero if val saved.
4930 * -EINVAL val out of range
4933 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4935 if (val >= 0 && val <= 1) {
4936 phba->cfg_request_firmware_upgrade = val;
4941 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4942 lpfc_request_firmware_upgrade_show,
4943 lpfc_request_firmware_upgrade_store);
4946 * lpfc_force_rscn_store
4948 * @dev: class device that is converted into a Scsi_host.
4949 * @attr: device attribute, not used.
4950 * @buf: unused string
4951 * @count: unused variable.
4954 * Force the switch to send a RSCN to all other NPorts in our zone
4955 * If we are direct connect pt2pt, build the RSCN command ourself
4956 * and send to the other NPort. Not supported for private loop.
4960 * -EIO - if command is not sent
4963 lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4964 const char *buf, size_t count)
4966 struct Scsi_Host *shost = class_to_shost(dev);
4967 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4970 i = lpfc_issue_els_rscn(vport, 0);
4977 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4978 * connected to the HBA.
4980 * Value range is any ascii value
4982 static int lpfc_force_rscn;
4983 module_param(lpfc_force_rscn, int, 0644);
4984 MODULE_PARM_DESC(lpfc_force_rscn,
4985 "Force an RSCN to be sent to all remote NPorts");
4986 lpfc_param_show(force_rscn)
4989 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4990 * @phba: lpfc_hba pointer.
4991 * @val: unused value.
4994 * zero if val saved.
4997 lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
5001 static DEVICE_ATTR_RW(lpfc_force_rscn);
5004 * lpfc_fcp_imax_store
5006 * @dev: class device that is converted into a Scsi_host.
5007 * @attr: device attribute, not used.
5008 * @buf: string with the number of fast-path FCP interrupts per second.
5009 * @count: unused variable.
5012 * If val is in a valid range [636,651042], then set the adapter's
5013 * maximum number of fast-path FCP interrupts per second.
5016 * length of the buf on success if val is in range the intended mode
5018 * -EINVAL if val out of range or intended mode is not supported.
5021 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
5022 const char *buf, size_t count)
5024 struct Scsi_Host *shost = class_to_shost(dev);
5025 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5026 struct lpfc_hba *phba = vport->phba;
5027 struct lpfc_eq_intr_info *eqi;
5031 /* fcp_imax is only valid for SLI4 */
5032 if (phba->sli_rev != LPFC_SLI_REV4)
5035 /* Sanity check on user data */
5036 if (!isdigit(buf[0]))
5038 if (sscanf(buf, "%i", &val) != 1)
5042 * Value range for the HBA is [5000,5000000]
5043 * The value for each EQ depends on how many EQs are configured.
5046 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
5049 phba->cfg_auto_imax = (val) ? 0 : 1;
5050 if (phba->cfg_fcp_imax && !val) {
5051 queue_delayed_work(phba->wq, &phba->eq_delay_work,
5052 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
5054 for_each_present_cpu(i) {
5055 eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
5060 phba->cfg_fcp_imax = (uint32_t)val;
5062 if (phba->cfg_fcp_imax)
5063 usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
5067 for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
5068 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
5075 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
5078 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
5080 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
5081 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
5082 MODULE_PARM_DESC(lpfc_fcp_imax,
5083 "Set the maximum number of FCP interrupts per second per HBA");
5084 lpfc_param_show(fcp_imax)
5087 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
5088 * @phba: lpfc_hba pointer.
5089 * @val: link speed value.
5092 * If val is in a valid range [636,651042], then initialize the adapter's
5093 * maximum number of fast-path FCP interrupts per second.
5096 * zero if val saved.
5097 * -EINVAL val out of range
5100 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
5102 if (phba->sli_rev != LPFC_SLI_REV4) {
5103 phba->cfg_fcp_imax = 0;
5107 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
5109 phba->cfg_fcp_imax = val;
5113 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5114 "3016 lpfc_fcp_imax: %d out of range, using default\n",
5116 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
5121 static DEVICE_ATTR_RW(lpfc_fcp_imax);
5124 * lpfc_cq_max_proc_limit_store
5126 * @dev: class device that is converted into a Scsi_host.
5127 * @attr: device attribute, not used.
5128 * @buf: string with the cq max processing limit of cqes
5129 * @count: unused variable.
5132 * If val is in a valid range, then set value on each cq
5135 * The length of the buf: if successful
5136 * -ERANGE: if val is not in the valid range
5137 * -EINVAL: if bad value format or intended mode is not supported.
5140 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
5141 const char *buf, size_t count)
5143 struct Scsi_Host *shost = class_to_shost(dev);
5144 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5145 struct lpfc_hba *phba = vport->phba;
5146 struct lpfc_queue *eq, *cq;
5150 /* cq_max_proc_limit is only valid for SLI4 */
5151 if (phba->sli_rev != LPFC_SLI_REV4)
5154 /* Sanity check on user data */
5155 if (!isdigit(buf[0]))
5157 if (kstrtoul(buf, 0, &val))
5160 if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
5163 phba->cfg_cq_max_proc_limit = (uint32_t)val;
5165 /* set the values on the cq's */
5166 for (i = 0; i < phba->cfg_irq_chann; i++) {
5167 /* Get the EQ corresponding to the IRQ vector */
5168 eq = phba->sli4_hba.hba_eq_hdl[i].eq;
5172 list_for_each_entry(cq, &eq->child_list, list)
5173 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
5181 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
5182 * itteration of CQ processing.
5184 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5185 module_param(lpfc_cq_max_proc_limit, int, 0644);
5186 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
5187 "Set the maximum number CQEs processed in an iteration of "
5189 lpfc_param_show(cq_max_proc_limit)
5192 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
5193 * single handler call which should request a polled completion rather
5194 * than re-enabling interrupts.
5196 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
5197 LPFC_CQ_MIN_THRESHOLD_TO_POLL,
5198 LPFC_CQ_MAX_THRESHOLD_TO_POLL,
5199 "CQE Processing Threshold to enable Polling");
5202 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
5203 * @phba: lpfc_hba pointer.
5207 * If val is in a valid range, then initialize the adapter's maximum
5211 * Always returns 0 for success, even if value not always set to
5212 * requested value. If value out of range or not supported, will fall
5216 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
5218 phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
5220 if (phba->sli_rev != LPFC_SLI_REV4)
5223 if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
5224 phba->cfg_cq_max_proc_limit = val;
5228 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5229 "0371 "LPFC_DRIVER_NAME"_cq_max_proc_limit: "
5230 "%d out of range, using default\n",
5231 phba->cfg_cq_max_proc_limit);
5236 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
5239 * lpfc_state_show - Display current driver CPU affinity
5240 * @dev: class converted to a Scsi_host structure.
5241 * @attr: device attribute, not used.
5242 * @buf: on return contains text describing the state of the link.
5244 * Returns: size of formatted string.
5247 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
5250 struct Scsi_Host *shost = class_to_shost(dev);
5251 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5252 struct lpfc_hba *phba = vport->phba;
5253 struct lpfc_vector_map_info *cpup;
5256 if ((phba->sli_rev != LPFC_SLI_REV4) ||
5257 (phba->intr_type != MSIX))
5260 switch (phba->cfg_fcp_cpu_map) {
5262 len += scnprintf(buf + len, PAGE_SIZE-len,
5263 "fcp_cpu_map: No mapping (%d)\n",
5264 phba->cfg_fcp_cpu_map);
5267 len += scnprintf(buf + len, PAGE_SIZE-len,
5268 "fcp_cpu_map: HBA centric mapping (%d): "
5269 "%d of %d CPUs online from %d possible CPUs\n",
5270 phba->cfg_fcp_cpu_map, num_online_cpus(),
5272 phba->sli4_hba.num_possible_cpu);
5276 while (phba->sli4_hba.curr_disp_cpu <
5277 phba->sli4_hba.num_possible_cpu) {
5278 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
5280 if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
5281 len += scnprintf(buf + len, PAGE_SIZE - len,
5282 "CPU %02d not present\n",
5283 phba->sli4_hba.curr_disp_cpu);
5284 else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
5285 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5287 buf + len, PAGE_SIZE - len,
5288 "CPU %02d hdwq None "
5289 "physid %d coreid %d ht %d ua %d\n",
5290 phba->sli4_hba.curr_disp_cpu,
5291 cpup->phys_id, cpup->core_id,
5292 (cpup->flag & LPFC_CPU_MAP_HYPER),
5293 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5296 buf + len, PAGE_SIZE - len,
5297 "CPU %02d EQ None hdwq %04d "
5298 "physid %d coreid %d ht %d ua %d\n",
5299 phba->sli4_hba.curr_disp_cpu,
5300 cpup->hdwq, cpup->phys_id,
5302 (cpup->flag & LPFC_CPU_MAP_HYPER),
5303 (cpup->flag & LPFC_CPU_MAP_UNASSIGN));
5305 if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
5307 buf + len, PAGE_SIZE - len,
5308 "CPU %02d hdwq None "
5309 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5310 phba->sli4_hba.curr_disp_cpu,
5313 (cpup->flag & LPFC_CPU_MAP_HYPER),
5314 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5315 lpfc_get_irq(cpup->eq));
5318 buf + len, PAGE_SIZE - len,
5319 "CPU %02d EQ %04d hdwq %04d "
5320 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5321 phba->sli4_hba.curr_disp_cpu,
5322 cpup->eq, cpup->hdwq, cpup->phys_id,
5324 (cpup->flag & LPFC_CPU_MAP_HYPER),
5325 (cpup->flag & LPFC_CPU_MAP_UNASSIGN),
5326 lpfc_get_irq(cpup->eq));
5329 phba->sli4_hba.curr_disp_cpu++;
5331 /* display max number of CPUs keeping some margin */
5332 if (phba->sli4_hba.curr_disp_cpu <
5333 phba->sli4_hba.num_possible_cpu &&
5334 (len >= (PAGE_SIZE - 64))) {
5335 len += scnprintf(buf + len,
5336 PAGE_SIZE - len, "more...\n");
5341 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
5342 phba->sli4_hba.curr_disp_cpu = 0;
5348 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5349 * @dev: class device that is converted into a Scsi_host.
5350 * @attr: device attribute, not used.
5351 * @buf: one or more lpfc_polling_flags values.
5355 * -EINVAL - Not implemented yet.
5358 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
5359 const char *buf, size_t count)
5365 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5368 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5369 # 0 - Do not affinitze IRQ vectors
5370 # 1 - Affintize HBA vectors with respect to each HBA
5371 # (start with CPU0 for each HBA)
5372 # This also defines how Hardware Queues are mapped to specific CPUs.
5374 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5375 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5376 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5377 "Defines how to map CPUs to IRQ vectors per HBA");
5380 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5381 * @phba: lpfc_hba pointer.
5382 * @val: link speed value.
5385 * If val is in a valid range [0-2], then affinitze the adapter's
5389 * zero if val saved.
5390 * -EINVAL val out of range
5393 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5395 if (phba->sli_rev != LPFC_SLI_REV4) {
5396 phba->cfg_fcp_cpu_map = 0;
5400 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5401 phba->cfg_fcp_cpu_map = val;
5405 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5406 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5408 phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5413 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5416 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5417 # Value range is [2,3]. Default value is 3.
5419 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5420 "Select Fibre Channel class of service for FCP sequences");
5423 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5424 # is [0,1]. Default value is 0.
5426 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
5427 "Use ADISC on rediscovery to authenticate FCP devices");
5430 # lpfc_first_burst_size: First burst size to use on the NPorts
5431 # that support first burst.
5432 # Value range is [0,65536]. Default value is 0.
5434 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5435 "First burst size for Targets that support first burst");
5438 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5439 * When the driver is configured as an NVME target, this value is
5440 * communicated to the NVME initiator in the PRLI response. It is
5441 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5442 * parameters are set and the target is sending the PRLI RSP.
5443 * Parameter supported on physical port only - no NPIV support.
5444 * Value range is [0,65536]. Default value is 0.
5446 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5447 "NVME Target mode first burst size in 512B increments.");
5450 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5451 * For the Initiator (I), enabling this parameter means that an NVMET
5452 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5453 * processed by the initiator for subsequent NVME FCP IO.
5454 * Currently, this feature is not supported on the NVME target
5455 * Value range is [0,1]. Default value is 0 (disabled).
5457 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5458 "Enable First Burst feature for NVME Initiator.");
5461 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5462 # depth. Default value is 0. When the value of this parameter is zero the
5463 # SCSI command completion time is not used for controlling I/O queue depth. When
5464 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5465 # to limit the I/O completion time to the parameter value.
5466 # The value is set in milliseconds.
5468 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5469 "Use command completion time to control queue depth");
5471 lpfc_vport_param_show(max_scsicmpl_time);
5473 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5475 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5476 struct lpfc_nodelist *ndlp, *next_ndlp;
5478 if (val == vport->cfg_max_scsicmpl_time)
5480 if ((val < 0) || (val > 60000))
5482 vport->cfg_max_scsicmpl_time = val;
5484 spin_lock_irq(shost->host_lock);
5485 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5486 if (!NLP_CHK_NODE_ACT(ndlp))
5488 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5490 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5492 spin_unlock_irq(shost->host_lock);
5495 lpfc_vport_param_store(max_scsicmpl_time);
5496 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5499 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5500 # range is [0,1]. Default value is 0.
5502 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5505 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5506 # range is [0,1]. Default value is 1.
5508 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5511 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5512 * range is [0,1]. Default value is 0.
5513 * For [0], FCP commands are issued to Work Queues based on upper layer
5514 * hardware queue index.
5515 * For [1], FCP commands are issued to a Work Queue associated with the
5518 * LPFC_FCP_SCHED_BY_HDWQ == 0
5519 * LPFC_FCP_SCHED_BY_CPU == 1
5521 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5522 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5523 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5524 * through WQs will be used.
5526 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5527 LPFC_FCP_SCHED_BY_HDWQ,
5528 LPFC_FCP_SCHED_BY_CPU,
5529 "Determine scheduling algorithm for "
5530 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5533 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5534 * range is [0,1]. Default value is 0.
5535 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5536 * For [1], GID_PT is used for NameServer queries after RSCN
5539 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5540 LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5541 "Determine algorithm NameServer queries after RSCN "
5542 "[0] - GID_FT, [1] - GID_PT");
5545 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5546 # range is [0,1]. Default value is 0.
5547 # For [0], bus reset issues target reset to ALL devices
5548 # For [1], bus reset issues target reset to non-FCP2 devices
5550 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5551 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5555 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5556 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5557 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5558 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5559 # cr_delay is set to 0.
5561 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5562 "interrupt response is generated");
5564 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5565 "interrupt response is generated");
5568 # lpfc_multi_ring_support: Determines how many rings to spread available
5569 # cmd/rsp IOCB entries across.
5570 # Value range is [1,2]. Default value is 1.
5572 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5573 "SLI rings to spread IOCB entries across");
5576 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5577 # identifies what rctl value to configure the additional ring for.
5578 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5580 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5581 255, "Identifies RCTL for additional ring configuration");
5584 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5585 # identifies what type value to configure the additional ring for.
5586 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5588 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5589 255, "Identifies TYPE for additional ring configuration");
5592 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5593 # 0 = SmartSAN functionality disabled (default)
5594 # 1 = SmartSAN functionality enabled
5595 # This parameter will override the value of lpfc_fdmi_on module parameter.
5596 # Value range is [0,1]. Default value is 0.
5598 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5601 # lpfc_fdmi_on: Controls FDMI support.
5603 # 1 Traditional FDMI support (default)
5604 # Traditional FDMI support means the driver will assume FDMI-2 support;
5605 # however, if that fails, it will fallback to FDMI-1.
5606 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5607 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5609 # Value range [0,1]. Default value is 1.
5611 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5614 # Specifies the maximum number of ELS cmds we can have outstanding (for
5615 # discovery). Value range is [1,64]. Default value = 32.
5617 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5618 "during discovery");
5621 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5622 # will be scanned by the SCSI midlayer when sequential scanning is
5623 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5624 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5625 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5626 # above. The lpfc driver limits the default value to 255 for two reasons.
5627 # As it bounds the sequential scan loop, scanning for thousands of luns
5628 # on a target can take minutes of wall clock time. Additionally,
5629 # there are FC targets, such as JBODs, that only recognize 8-bits of
5630 # LUN ID. When they receive a value greater than 8 bits, they chop off
5631 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5632 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5633 # valid responses at each of the LUN IDs, to believe there are multiple
5634 # devices present, when in fact, there is only 1.
5635 # A customer that is aware of their target behaviors, and the results as
5636 # indicated above, is welcome to increase the lpfc_max_luns value.
5637 # As mentioned, this value is not used by the lpfc driver, only the
5639 # Value range is [0,65535]. Default value is 255.
5640 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5642 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5645 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5646 # Value range is [1,255], default value is 10.
5648 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5649 "Milliseconds driver will wait between polling FCP ring");
5652 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5653 # to complete in seconds. Value range is [5,180], default value is 60.
5655 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5656 "Maximum time to wait for task management commands to complete");
5658 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5659 # support this feature
5662 # 2 = MSI-X enabled (default)
5663 # Value range is [0,2]. Default value is 2.
5665 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5666 "MSI-X (2), if possible");
5669 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5671 * 0 = NVME OAS disabled
5672 * 1 = NVME OAS enabled
5674 * Value range is [0,1]. Default value is 0.
5676 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5677 "Use OAS bit on NVME IOs");
5680 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5682 * 0 = Put NVME Command in SGL
5683 * 1 = Embed NVME Command in WQE (unless G7)
5684 * 2 = Embed NVME Command in WQE (force)
5686 * Value range is [0,2]. Default value is 1.
5688 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5689 "Embed NVME Command in WQE");
5692 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5693 * the driver will advertise it supports to the SCSI layer.
5695 * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
5696 * 1,256 = Manually specify nr_hw_queue value to be advertised,
5698 * Value range is [0,256]. Default value is 8.
5700 LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5701 LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5702 "Set the number of SCSI Queues advertised");
5705 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5706 * will advertise it supports to the NVME and SCSI layers. This also
5707 * will map to the number of CQ/WQ pairs the driver will create.
5709 * The NVME Layer will try to create this many, plus 1 administrative
5710 * hardware queue. The administrative queue will always map to WQ 0
5711 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5713 * 0 = Configure the number of hdw queues to the number of active CPUs.
5714 * 1,256 = Manually specify how many hdw queues to use.
5716 * Value range is [0,256]. Default value is 0.
5718 LPFC_ATTR_R(hdw_queue,
5720 LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5721 "Set the number of I/O Hardware Queues");
5723 #if IS_ENABLED(CONFIG_X86)
5725 * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
5727 * @phba: Pointer to HBA context object.
5730 lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)
5732 unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;
5733 const struct cpumask *sibling_mask;
5734 struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;
5736 cpumask_clear(aff_mask);
5738 if (phba->irq_chann_mode == NUMA_MODE) {
5739 /* Check if we're a NUMA architecture */
5740 numa_node = dev_to_node(&phba->pcidev->dev);
5741 if (numa_node == NUMA_NO_NODE) {
5742 phba->irq_chann_mode = NORMAL_MODE;
5747 for_each_possible_cpu(cpu) {
5748 switch (phba->irq_chann_mode) {
5750 if (cpu_to_node(cpu) == numa_node)
5751 cpumask_set_cpu(cpu, aff_mask);
5754 sibling_mask = topology_sibling_cpumask(cpu);
5755 first_cpu = cpumask_first(sibling_mask);
5756 if (first_cpu < nr_cpu_ids)
5757 cpumask_set_cpu(first_cpu, aff_mask);
5767 lpfc_assign_default_irq_chann(struct lpfc_hba *phba)
5769 #if IS_ENABLED(CONFIG_X86)
5770 switch (boot_cpu_data.x86_vendor) {
5771 case X86_VENDOR_AMD:
5772 /* If AMD architecture, then default is NUMA_MODE */
5773 phba->irq_chann_mode = NUMA_MODE;
5775 case X86_VENDOR_INTEL:
5776 /* If Intel architecture, then default is no hyperthread mode */
5777 phba->irq_chann_mode = NHT_MODE;
5780 phba->irq_chann_mode = NORMAL_MODE;
5783 lpfc_cpumask_irq_mode_init(phba);
5785 phba->irq_chann_mode = NORMAL_MODE;
5790 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5791 * for Hardware Queues to utilize. This also will map to the number
5792 * of EQ / MSI-X vectors the driver will create. This should never be
5793 * more than the number of Hardware Queues
5795 * 0 = Configure number of IRQ Channels to:
5796 * if AMD architecture, number of CPUs on HBA's NUMA node
5797 * if Intel architecture, number of physical CPUs.
5798 * otherwise, number of active CPUs.
5799 * [1,256] = Manually specify how many IRQ Channels to use.
5801 * Value range is [0,256]. Default value is [0].
5803 static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
5804 module_param(lpfc_irq_chann, uint, 0444);
5805 MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
5807 /* lpfc_irq_chann_init - Set the hba irq_chann initial value
5808 * @phba: lpfc_hba pointer.
5809 * @val: contains the initial value
5812 * Validates the initial value is within range and assigns it to the
5813 * adapter. If not in range, an error message is posted and the
5814 * default value is assigned.
5817 * zero if value is in range and is set
5818 * -EINVAL if value was out of range
5821 lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
5823 const struct cpumask *aff_mask;
5825 if (phba->cfg_use_msi != 2) {
5826 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5827 "8532 use_msi = %u ignoring cfg_irq_numa\n",
5829 phba->irq_chann_mode = NORMAL_MODE;
5830 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5834 /* Check if default setting was passed */
5835 if (val == LPFC_IRQ_CHANN_DEF)
5836 lpfc_assign_default_irq_chann(phba);
5838 if (phba->irq_chann_mode != NORMAL_MODE) {
5839 aff_mask = &phba->sli4_hba.irq_aff_mask;
5841 if (cpumask_empty(aff_mask)) {
5842 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5843 "8533 Could not identify CPUS for "
5844 "mode %d, ignoring\n",
5845 phba->irq_chann_mode);
5846 phba->irq_chann_mode = NORMAL_MODE;
5847 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5849 phba->cfg_irq_chann = cpumask_weight(aff_mask);
5851 /* If no hyperthread mode, then set hdwq count to
5852 * aff_mask weight as well
5854 if (phba->irq_chann_mode == NHT_MODE)
5855 phba->cfg_hdw_queue = phba->cfg_irq_chann;
5857 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5858 "8543 lpfc_irq_chann set to %u "
5859 "(mode: %d)\n", phba->cfg_irq_chann,
5860 phba->irq_chann_mode);
5863 if (val > LPFC_IRQ_CHANN_MAX) {
5864 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5865 "8545 lpfc_irq_chann attribute cannot "
5866 "be set to %u, allowed range is "
5870 LPFC_IRQ_CHANN_MAX);
5871 phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5874 phba->cfg_irq_chann = val;
5881 * lpfc_irq_chann_show - Display value of irq_chann
5882 * @dev: class converted to a Scsi_host structure.
5883 * @attr: device attribute, not used.
5884 * @buf: on return contains a string with the list sizes
5886 * Returns: size of formatted string.
5889 lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
5892 struct Scsi_Host *shost = class_to_shost(dev);
5893 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5894 struct lpfc_hba *phba = vport->phba;
5896 return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
5899 static DEVICE_ATTR_RO(lpfc_irq_chann);
5902 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5903 # 0 = HBA resets disabled
5904 # 1 = HBA resets enabled (default)
5905 # 2 = HBA reset via PCI bus reset enabled
5906 # Value range is [0,2]. Default value is 1.
5908 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5911 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5912 # 0 = HBA Heartbeat disabled
5913 # 1 = HBA Heartbeat enabled (default)
5914 # Value range is [0,1]. Default value is 1.
5916 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5919 # lpfc_EnableXLane: Enable Express Lane Feature
5920 # 0x0 Express Lane Feature disabled
5921 # 0x1 Express Lane Feature enabled
5922 # Value range is [0,1]. Default value is 0.
5924 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5927 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5928 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5929 # Value range is [0x0,0x7f]. Default value is 0
5931 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5934 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5935 # 0 = BlockGuard disabled (default)
5936 # 1 = BlockGuard enabled
5937 # Value range is [0,1]. Default value is 0.
5939 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5943 # - Bit mask of host protection capabilities used to register with the
5945 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5946 # - Allows you to ultimately specify which profiles to use
5947 # - Default will result in registering capabilities for all profiles.
5948 # - SHOST_DIF_TYPE1_PROTECTION 1
5949 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5950 # - SHOST_DIX_TYPE0_PROTECTION 8
5951 # HBA supports DIX Type 0: Host to HBA protection only
5952 # - SHOST_DIX_TYPE1_PROTECTION 16
5953 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5956 LPFC_ATTR(prot_mask,
5957 (SHOST_DIF_TYPE1_PROTECTION |
5958 SHOST_DIX_TYPE0_PROTECTION |
5959 SHOST_DIX_TYPE1_PROTECTION),
5961 (SHOST_DIF_TYPE1_PROTECTION |
5962 SHOST_DIX_TYPE0_PROTECTION |
5963 SHOST_DIX_TYPE1_PROTECTION),
5964 "T10-DIF host protection capabilities mask");
5967 # lpfc_prot_guard: i
5968 # - Bit mask of protection guard types to register with the SCSI mid-layer
5969 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5970 # - Allows you to ultimately specify which profiles to use
5971 # - Default will result in registering capabilities for all guard types
5974 LPFC_ATTR(prot_guard,
5975 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5976 "T10-DIF host protection guard type");
5979 * Delay initial NPort discovery when Clean Address bit is cleared in
5980 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5981 * This parameter can have value 0 or 1.
5982 * When this parameter is set to 0, no delay is added to the initial
5984 * When this parameter is set to non-zero value, initial Nport discovery is
5985 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5986 * accept and FCID/Fabric name/Fabric portname is changed.
5987 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5988 * when Clean Address bit is cleared in FLOGI/FDISC
5989 * accept and FCID/Fabric name/Fabric portname is changed.
5990 * Default value is 0.
5992 LPFC_ATTR(delay_discovery, 0, 0, 1,
5993 "Delay NPort discovery when Clean Address bit is cleared.");
5996 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5997 * This value can be set to values between 64 and 4096. The default value
5998 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5999 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
6000 * Because of the additional overhead involved in setting up T10-DIF,
6001 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
6002 * and will be limited to 512 if BlockGuard is enabled under SLI3.
6004 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
6005 module_param(lpfc_sg_seg_cnt, uint, 0444);
6006 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
6009 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
6010 * configured for the adapter
6011 * @dev: class converted to a Scsi_host structure.
6012 * @attr: device attribute, not used.
6013 * @buf: on return contains a string with the list sizes
6015 * Returns: size of formatted string.
6018 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
6021 struct Scsi_Host *shost = class_to_shost(dev);
6022 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6023 struct lpfc_hba *phba = vport->phba;
6026 len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d total SGEs: %d\n",
6027 phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
6029 len += scnprintf(buf + len, PAGE_SIZE - len,
6030 "Cfg: %d SCSI: %d NVME: %d\n",
6031 phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
6032 phba->cfg_nvme_seg_cnt);
6036 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
6039 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
6040 * @phba: lpfc_hba pointer.
6041 * @val: contains the initial value
6044 * Validates the initial value is within range and assigns it to the
6045 * adapter. If not in range, an error message is posted and the
6046 * default value is assigned.
6049 * zero if value is in range and is set
6050 * -EINVAL if value was out of range
6053 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
6055 if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
6056 phba->cfg_sg_seg_cnt = val;
6059 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6060 "0409 "LPFC_DRIVER_NAME"_sg_seg_cnt attribute cannot "
6061 "be set to %d, allowed range is [%d, %d]\n",
6062 val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
6063 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
6068 * lpfc_enable_mds_diags: Enable MDS Diagnostics
6069 * 0 = MDS Diagnostics disabled (default)
6070 * 1 = MDS Diagnostics enabled
6071 * Value range is [0,1]. Default value is 0.
6073 LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
6076 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
6077 * 0 = Disable firmware logging (default)
6078 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
6079 * Value range [0..4]. Default value is 0
6081 LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
6082 lpfc_param_show(ras_fwlog_buffsize);
6085 lpfc_ras_fwlog_buffsize_set(struct lpfc_hba *phba, uint val)
6088 enum ras_state state;
6090 if (!lpfc_rangecheck(val, 0, 4))
6093 if (phba->cfg_ras_fwlog_buffsize == val)
6096 if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
6099 spin_lock_irq(&phba->hbalock);
6100 state = phba->ras_fwlog.state;
6101 spin_unlock_irq(&phba->hbalock);
6103 if (state == REG_INPROGRESS) {
6104 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
6105 "registration is in progress\n");
6109 /* For disable logging: stop the logs and free the DMA.
6110 * For ras_fwlog_buffsize size change we still need to free and
6111 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
6113 phba->cfg_ras_fwlog_buffsize = val;
6114 if (state == ACTIVE) {
6115 lpfc_ras_stop_fwlog(phba);
6116 lpfc_sli4_ras_dma_free(phba);
6119 lpfc_sli4_ras_init(phba);
6120 if (phba->ras_fwlog.ras_enabled)
6121 ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
6122 LPFC_RAS_ENABLE_LOGGING);
6126 lpfc_param_store(ras_fwlog_buffsize);
6127 static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
6130 * lpfc_ras_fwlog_level: Firmware logging verbosity level
6131 * Valid only if firmware logging is enabled
6132 * 0(Least Verbosity) 4 (most verbosity)
6133 * Value range is [0..4]. Default value is 0
6135 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
6138 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
6139 * Default function which has RAS support : 0
6140 * Value Range is [0..7].
6141 * FW logging is a global action and enablement is via a specific
6144 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
6147 * lpfc_enable_bbcr: Enable BB Credit Recovery
6148 * 0 = BB Credit Recovery disabled
6149 * 1 = BB Credit Recovery enabled (default)
6150 * Value range is [0,1]. Default value is 1.
6152 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
6155 * lpfc_enable_dpp: Enable DPP on G7
6156 * 0 = DPP on G7 disabled
6157 * 1 = DPP on G7 enabled (default)
6158 * Value range is [0,1]. Default value is 1.
6160 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
6162 struct device_attribute *lpfc_hba_attrs[] = {
6163 &dev_attr_nvme_info,
6164 &dev_attr_scsi_stat,
6166 &dev_attr_bg_guard_err,
6167 &dev_attr_bg_apptag_err,
6168 &dev_attr_bg_reftag_err,
6170 &dev_attr_serialnum,
6171 &dev_attr_modeldesc,
6172 &dev_attr_modelname,
6173 &dev_attr_programtype,
6177 &dev_attr_option_rom_version,
6178 &dev_attr_link_state,
6179 &dev_attr_num_discovered_ports,
6180 &dev_attr_menlo_mgmt_mode,
6181 &dev_attr_lpfc_drvr_version,
6182 &dev_attr_lpfc_enable_fip,
6183 &dev_attr_lpfc_temp_sensor,
6184 &dev_attr_lpfc_log_verbose,
6185 &dev_attr_lpfc_lun_queue_depth,
6186 &dev_attr_lpfc_tgt_queue_depth,
6187 &dev_attr_lpfc_hba_queue_depth,
6188 &dev_attr_lpfc_peer_port_login,
6189 &dev_attr_lpfc_nodev_tmo,
6190 &dev_attr_lpfc_devloss_tmo,
6191 &dev_attr_lpfc_enable_fc4_type,
6192 &dev_attr_lpfc_fcp_class,
6193 &dev_attr_lpfc_use_adisc,
6194 &dev_attr_lpfc_first_burst_size,
6195 &dev_attr_lpfc_ack0,
6196 &dev_attr_lpfc_xri_rebalancing,
6197 &dev_attr_lpfc_topology,
6198 &dev_attr_lpfc_scan_down,
6199 &dev_attr_lpfc_link_speed,
6200 &dev_attr_lpfc_fcp_io_sched,
6201 &dev_attr_lpfc_ns_query,
6202 &dev_attr_lpfc_fcp2_no_tgt_reset,
6203 &dev_attr_lpfc_cr_delay,
6204 &dev_attr_lpfc_cr_count,
6205 &dev_attr_lpfc_multi_ring_support,
6206 &dev_attr_lpfc_multi_ring_rctl,
6207 &dev_attr_lpfc_multi_ring_type,
6208 &dev_attr_lpfc_fdmi_on,
6209 &dev_attr_lpfc_enable_SmartSAN,
6210 &dev_attr_lpfc_max_luns,
6211 &dev_attr_lpfc_enable_npiv,
6212 &dev_attr_lpfc_fcf_failover_policy,
6213 &dev_attr_lpfc_enable_rrq,
6214 &dev_attr_nport_evt_cnt,
6215 &dev_attr_board_mode,
6222 &dev_attr_npiv_info,
6223 &dev_attr_issue_reset,
6224 &dev_attr_lpfc_poll,
6225 &dev_attr_lpfc_poll_tmo,
6226 &dev_attr_lpfc_task_mgmt_tmo,
6227 &dev_attr_lpfc_use_msi,
6228 &dev_attr_lpfc_nvme_oas,
6229 &dev_attr_lpfc_nvme_embed_cmd,
6230 &dev_attr_lpfc_fcp_imax,
6231 &dev_attr_lpfc_force_rscn,
6232 &dev_attr_lpfc_cq_poll_threshold,
6233 &dev_attr_lpfc_cq_max_proc_limit,
6234 &dev_attr_lpfc_fcp_cpu_map,
6235 &dev_attr_lpfc_fcp_mq_threshold,
6236 &dev_attr_lpfc_hdw_queue,
6237 &dev_attr_lpfc_irq_chann,
6238 &dev_attr_lpfc_suppress_rsp,
6239 &dev_attr_lpfc_nvmet_mrq,
6240 &dev_attr_lpfc_nvmet_mrq_post,
6241 &dev_attr_lpfc_nvme_enable_fb,
6242 &dev_attr_lpfc_nvmet_fb_size,
6243 &dev_attr_lpfc_enable_bg,
6244 &dev_attr_lpfc_soft_wwnn,
6245 &dev_attr_lpfc_soft_wwpn,
6246 &dev_attr_lpfc_soft_wwn_enable,
6247 &dev_attr_lpfc_enable_hba_reset,
6248 &dev_attr_lpfc_enable_hba_heartbeat,
6249 &dev_attr_lpfc_EnableXLane,
6250 &dev_attr_lpfc_XLanePriority,
6251 &dev_attr_lpfc_xlane_lun,
6252 &dev_attr_lpfc_xlane_tgt,
6253 &dev_attr_lpfc_xlane_vpt,
6254 &dev_attr_lpfc_xlane_lun_state,
6255 &dev_attr_lpfc_xlane_lun_status,
6256 &dev_attr_lpfc_xlane_priority,
6257 &dev_attr_lpfc_sg_seg_cnt,
6258 &dev_attr_lpfc_max_scsicmpl_time,
6259 &dev_attr_lpfc_stat_data_ctrl,
6260 &dev_attr_lpfc_aer_support,
6261 &dev_attr_lpfc_aer_state_cleanup,
6262 &dev_attr_lpfc_sriov_nr_virtfn,
6263 &dev_attr_lpfc_req_fw_upgrade,
6264 &dev_attr_lpfc_suppress_link_up,
6269 &dev_attr_txcmplq_hw,
6270 &dev_attr_lpfc_sriov_hw_max_virtfn,
6272 &dev_attr_lpfc_xlane_supported,
6273 &dev_attr_lpfc_enable_mds_diags,
6274 &dev_attr_lpfc_ras_fwlog_buffsize,
6275 &dev_attr_lpfc_ras_fwlog_level,
6276 &dev_attr_lpfc_ras_fwlog_func,
6277 &dev_attr_lpfc_enable_bbcr,
6278 &dev_attr_lpfc_enable_dpp,
6282 struct device_attribute *lpfc_vport_attrs[] = {
6284 &dev_attr_link_state,
6285 &dev_attr_num_discovered_ports,
6286 &dev_attr_lpfc_drvr_version,
6287 &dev_attr_lpfc_log_verbose,
6288 &dev_attr_lpfc_lun_queue_depth,
6289 &dev_attr_lpfc_tgt_queue_depth,
6290 &dev_attr_lpfc_nodev_tmo,
6291 &dev_attr_lpfc_devloss_tmo,
6292 &dev_attr_lpfc_hba_queue_depth,
6293 &dev_attr_lpfc_peer_port_login,
6294 &dev_attr_lpfc_restrict_login,
6295 &dev_attr_lpfc_fcp_class,
6296 &dev_attr_lpfc_use_adisc,
6297 &dev_attr_lpfc_first_burst_size,
6298 &dev_attr_lpfc_max_luns,
6299 &dev_attr_nport_evt_cnt,
6300 &dev_attr_npiv_info,
6301 &dev_attr_lpfc_enable_da_id,
6302 &dev_attr_lpfc_max_scsicmpl_time,
6303 &dev_attr_lpfc_stat_data_ctrl,
6304 &dev_attr_lpfc_static_vport,
6309 * sysfs_ctlreg_write - Write method for writing to ctlreg
6310 * @filp: open sysfs file
6311 * @kobj: kernel kobject that contains the kernel class device.
6312 * @bin_attr: kernel attributes passed to us.
6313 * @buf: contains the data to be written to the adapter IOREG space.
6314 * @off: offset into buffer to beginning of data.
6315 * @count: bytes to transfer.
6318 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6319 * Uses the adapter io control registers to send buf contents to the adapter.
6322 * -ERANGE off and count combo out of range
6323 * -EINVAL off, count or buff address invalid
6324 * -EPERM adapter is offline
6325 * value of count, buf contents written
6328 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6329 struct bin_attribute *bin_attr,
6330 char *buf, loff_t off, size_t count)
6333 struct device *dev = container_of(kobj, struct device, kobj);
6334 struct Scsi_Host *shost = class_to_shost(dev);
6335 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6336 struct lpfc_hba *phba = vport->phba;
6338 if (phba->sli_rev >= LPFC_SLI_REV4)
6341 if ((off + count) > FF_REG_AREA_SIZE)
6344 if (count <= LPFC_REG_WRITE_KEY_SIZE)
6347 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6350 /* This is to protect HBA registers from accidental writes. */
6351 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6354 if (!(vport->fc_flag & FC_OFFLINE_MODE))
6357 spin_lock_irq(&phba->hbalock);
6358 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6359 buf_off += sizeof(uint32_t))
6360 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6361 phba->ctrl_regs_memmap_p + off + buf_off);
6363 spin_unlock_irq(&phba->hbalock);
6369 * sysfs_ctlreg_read - Read method for reading from ctlreg
6370 * @filp: open sysfs file
6371 * @kobj: kernel kobject that contains the kernel class device.
6372 * @bin_attr: kernel attributes passed to us.
6373 * @buf: if successful contains the data from the adapter IOREG space.
6374 * @off: offset into buffer to beginning of data.
6375 * @count: bytes to transfer.
6378 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6379 * Uses the adapter io control registers to read data into buf.
6382 * -ERANGE off and count combo out of range
6383 * -EINVAL off, count or buff address invalid
6384 * value of count, buf contents read
6387 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6388 struct bin_attribute *bin_attr,
6389 char *buf, loff_t off, size_t count)
6393 struct device *dev = container_of(kobj, struct device, kobj);
6394 struct Scsi_Host *shost = class_to_shost(dev);
6395 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6396 struct lpfc_hba *phba = vport->phba;
6398 if (phba->sli_rev >= LPFC_SLI_REV4)
6401 if (off > FF_REG_AREA_SIZE)
6404 if ((off + count) > FF_REG_AREA_SIZE)
6405 count = FF_REG_AREA_SIZE - off;
6407 if (count == 0) return 0;
6409 if (off % 4 || count % 4 || (unsigned long)buf % 4)
6412 spin_lock_irq(&phba->hbalock);
6414 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6415 tmp_ptr = (uint32_t *)(buf + buf_off);
6416 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6419 spin_unlock_irq(&phba->hbalock);
6424 static struct bin_attribute sysfs_ctlreg_attr = {
6427 .mode = S_IRUSR | S_IWUSR,
6430 .read = sysfs_ctlreg_read,
6431 .write = sysfs_ctlreg_write,
6435 * sysfs_mbox_write - Write method for writing information via mbox
6436 * @filp: open sysfs file
6437 * @kobj: kernel kobject that contains the kernel class device.
6438 * @bin_attr: kernel attributes passed to us.
6439 * @buf: contains the data to be written to sysfs mbox.
6440 * @off: offset into buffer to beginning of data.
6441 * @count: bytes to transfer.
6444 * Deprecated function. All mailbox access from user space is performed via the
6448 * -EPERM operation not permitted
6451 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6452 struct bin_attribute *bin_attr,
6453 char *buf, loff_t off, size_t count)
6459 * sysfs_mbox_read - Read method for reading information via mbox
6460 * @filp: open sysfs file
6461 * @kobj: kernel kobject that contains the kernel class device.
6462 * @bin_attr: kernel attributes passed to us.
6463 * @buf: contains the data to be read from sysfs mbox.
6464 * @off: offset into buffer to beginning of data.
6465 * @count: bytes to transfer.
6468 * Deprecated function. All mailbox access from user space is performed via the
6472 * -EPERM operation not permitted
6475 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6476 struct bin_attribute *bin_attr,
6477 char *buf, loff_t off, size_t count)
6482 static struct bin_attribute sysfs_mbox_attr = {
6485 .mode = S_IRUSR | S_IWUSR,
6487 .size = MAILBOX_SYSFS_MAX,
6488 .read = sysfs_mbox_read,
6489 .write = sysfs_mbox_write,
6493 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6494 * @vport: address of lpfc vport structure.
6498 * error return code from sysfs_create_bin_file()
6501 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6506 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6507 &sysfs_drvr_stat_data_attr);
6509 /* Virtual ports do not need ctrl_reg and mbox */
6510 if (error || vport->port_type == LPFC_NPIV_PORT)
6513 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6514 &sysfs_ctlreg_attr);
6516 goto out_remove_stat_attr;
6518 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6521 goto out_remove_ctlreg_attr;
6524 out_remove_ctlreg_attr:
6525 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6526 out_remove_stat_attr:
6527 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6528 &sysfs_drvr_stat_data_attr);
6534 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6535 * @vport: address of lpfc vport structure.
6538 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6540 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6541 sysfs_remove_bin_file(&shost->shost_dev.kobj,
6542 &sysfs_drvr_stat_data_attr);
6543 /* Virtual ports do not need ctrl_reg and mbox */
6544 if (vport->port_type == LPFC_NPIV_PORT)
6546 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6547 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6551 * Dynamic FC Host Attributes Support
6555 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6556 * @shost: kernel scsi host pointer.
6559 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6561 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6563 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6564 sizeof fc_host_symbolic_name(shost));
6568 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6569 * @shost: kernel scsi host pointer.
6572 lpfc_get_host_port_id(struct Scsi_Host *shost)
6574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6576 /* note: fc_myDID already in cpu endianness */
6577 fc_host_port_id(shost) = vport->fc_myDID;
6581 * lpfc_get_host_port_type - Set the value of the scsi host port type
6582 * @shost: kernel scsi host pointer.
6585 lpfc_get_host_port_type(struct Scsi_Host *shost)
6587 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6588 struct lpfc_hba *phba = vport->phba;
6590 spin_lock_irq(shost->host_lock);
6592 if (vport->port_type == LPFC_NPIV_PORT) {
6593 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6594 } else if (lpfc_is_link_up(phba)) {
6595 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6596 if (vport->fc_flag & FC_PUBLIC_LOOP)
6597 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6599 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6601 if (vport->fc_flag & FC_FABRIC)
6602 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6604 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6607 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6609 spin_unlock_irq(shost->host_lock);
6613 * lpfc_get_host_port_state - Set the value of the scsi host port state
6614 * @shost: kernel scsi host pointer.
6617 lpfc_get_host_port_state(struct Scsi_Host *shost)
6619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6620 struct lpfc_hba *phba = vport->phba;
6622 spin_lock_irq(shost->host_lock);
6624 if (vport->fc_flag & FC_OFFLINE_MODE)
6625 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6627 switch (phba->link_state) {
6628 case LPFC_LINK_UNKNOWN:
6629 case LPFC_LINK_DOWN:
6630 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6634 case LPFC_HBA_READY:
6635 /* Links up, reports port state accordingly */
6636 if (vport->port_state < LPFC_VPORT_READY)
6637 fc_host_port_state(shost) =
6638 FC_PORTSTATE_BYPASSED;
6640 fc_host_port_state(shost) =
6641 FC_PORTSTATE_ONLINE;
6643 case LPFC_HBA_ERROR:
6644 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6647 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6652 spin_unlock_irq(shost->host_lock);
6656 * lpfc_get_host_speed - Set the value of the scsi host speed
6657 * @shost: kernel scsi host pointer.
6660 lpfc_get_host_speed(struct Scsi_Host *shost)
6662 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6663 struct lpfc_hba *phba = vport->phba;
6665 spin_lock_irq(shost->host_lock);
6667 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
6668 switch(phba->fc_linkspeed) {
6669 case LPFC_LINK_SPEED_1GHZ:
6670 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6672 case LPFC_LINK_SPEED_2GHZ:
6673 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6675 case LPFC_LINK_SPEED_4GHZ:
6676 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6678 case LPFC_LINK_SPEED_8GHZ:
6679 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6681 case LPFC_LINK_SPEED_10GHZ:
6682 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6684 case LPFC_LINK_SPEED_16GHZ:
6685 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6687 case LPFC_LINK_SPEED_32GHZ:
6688 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6690 case LPFC_LINK_SPEED_64GHZ:
6691 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6693 case LPFC_LINK_SPEED_128GHZ:
6694 fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6697 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6700 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6701 switch (phba->fc_linkspeed) {
6702 case LPFC_ASYNC_LINK_SPEED_1GBPS:
6703 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6705 case LPFC_ASYNC_LINK_SPEED_10GBPS:
6706 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6708 case LPFC_ASYNC_LINK_SPEED_20GBPS:
6709 fc_host_speed(shost) = FC_PORTSPEED_20GBIT;
6711 case LPFC_ASYNC_LINK_SPEED_25GBPS:
6712 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6714 case LPFC_ASYNC_LINK_SPEED_40GBPS:
6715 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6717 case LPFC_ASYNC_LINK_SPEED_100GBPS:
6718 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6721 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6725 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6727 spin_unlock_irq(shost->host_lock);
6731 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6732 * @shost: kernel scsi host pointer.
6735 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6737 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6738 struct lpfc_hba *phba = vport->phba;
6741 spin_lock_irq(shost->host_lock);
6743 if ((vport->port_state > LPFC_FLOGI) &&
6744 ((vport->fc_flag & FC_FABRIC) ||
6745 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6746 (vport->fc_flag & FC_PUBLIC_LOOP))))
6747 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6749 /* fabric is local port if there is no F/FL_Port */
6752 spin_unlock_irq(shost->host_lock);
6754 fc_host_fabric_name(shost) = node_name;
6758 * lpfc_get_stats - Return statistical information about the adapter
6759 * @shost: kernel scsi host pointer.
6762 * NULL on error for link down, no mbox pool, sli2 active,
6763 * management not allowed, memory allocation error, or mbox error.
6767 * address of the adapter host statistics
6769 static struct fc_host_statistics *
6770 lpfc_get_stats(struct Scsi_Host *shost)
6772 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6773 struct lpfc_hba *phba = vport->phba;
6774 struct lpfc_sli *psli = &phba->sli;
6775 struct fc_host_statistics *hs = &phba->link_stats;
6776 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6777 LPFC_MBOXQ_t *pmboxq;
6782 * prevent udev from issuing mailbox commands until the port is
6785 if (phba->link_state < LPFC_LINK_DOWN ||
6786 !phba->mbox_mem_pool ||
6787 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6790 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6793 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6796 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6798 pmb = &pmboxq->u.mb;
6799 pmb->mbxCommand = MBX_READ_STATUS;
6800 pmb->mbxOwner = OWN_HOST;
6801 pmboxq->ctx_buf = NULL;
6802 pmboxq->vport = vport;
6804 if (vport->fc_flag & FC_OFFLINE_MODE) {
6805 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6806 if (rc != MBX_SUCCESS) {
6807 mempool_free(pmboxq, phba->mbox_mem_pool);
6811 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6812 if (rc != MBX_SUCCESS) {
6813 if (rc != MBX_TIMEOUT)
6814 mempool_free(pmboxq, phba->mbox_mem_pool);
6819 memset(hs, 0, sizeof (struct fc_host_statistics));
6821 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6823 * The MBX_READ_STATUS returns tx_k_bytes which has to
6824 * converted to words
6826 hs->tx_words = (uint64_t)
6827 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6829 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6830 hs->rx_words = (uint64_t)
6831 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6834 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6835 pmb->mbxCommand = MBX_READ_LNK_STAT;
6836 pmb->mbxOwner = OWN_HOST;
6837 pmboxq->ctx_buf = NULL;
6838 pmboxq->vport = vport;
6840 if (vport->fc_flag & FC_OFFLINE_MODE) {
6841 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6842 if (rc != MBX_SUCCESS) {
6843 mempool_free(pmboxq, phba->mbox_mem_pool);
6847 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6848 if (rc != MBX_SUCCESS) {
6849 if (rc != MBX_TIMEOUT)
6850 mempool_free(pmboxq, phba->mbox_mem_pool);
6855 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6856 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6857 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6858 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6859 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6860 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6861 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6863 hs->link_failure_count -= lso->link_failure_count;
6864 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6865 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6866 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6867 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6868 hs->invalid_crc_count -= lso->invalid_crc_count;
6869 hs->error_frames -= lso->error_frames;
6871 if (phba->hba_flag & HBA_FCOE_MODE) {
6873 hs->nos_count = (phba->link_events >> 1);
6874 hs->nos_count -= lso->link_events;
6875 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6876 hs->lip_count = (phba->fc_eventTag >> 1);
6877 hs->lip_count -= lso->link_events;
6881 hs->nos_count = (phba->fc_eventTag >> 1);
6882 hs->nos_count -= lso->link_events;
6885 hs->dumped_frames = -1;
6887 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6889 mempool_free(pmboxq, phba->mbox_mem_pool);
6895 * lpfc_reset_stats - Copy the adapter link stats information
6896 * @shost: kernel scsi host pointer.
6899 lpfc_reset_stats(struct Scsi_Host *shost)
6901 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6902 struct lpfc_hba *phba = vport->phba;
6903 struct lpfc_sli *psli = &phba->sli;
6904 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6905 LPFC_MBOXQ_t *pmboxq;
6909 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6912 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6915 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6917 pmb = &pmboxq->u.mb;
6918 pmb->mbxCommand = MBX_READ_STATUS;
6919 pmb->mbxOwner = OWN_HOST;
6920 pmb->un.varWords[0] = 0x1; /* reset request */
6921 pmboxq->ctx_buf = NULL;
6922 pmboxq->vport = vport;
6924 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6925 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6926 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6927 if (rc != MBX_SUCCESS) {
6928 mempool_free(pmboxq, phba->mbox_mem_pool);
6932 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6933 if (rc != MBX_SUCCESS) {
6934 if (rc != MBX_TIMEOUT)
6935 mempool_free(pmboxq, phba->mbox_mem_pool);
6940 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6941 pmb->mbxCommand = MBX_READ_LNK_STAT;
6942 pmb->mbxOwner = OWN_HOST;
6943 pmboxq->ctx_buf = NULL;
6944 pmboxq->vport = vport;
6946 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6947 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6948 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6949 if (rc != MBX_SUCCESS) {
6950 mempool_free(pmboxq, phba->mbox_mem_pool);
6954 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6955 if (rc != MBX_SUCCESS) {
6956 if (rc != MBX_TIMEOUT)
6957 mempool_free(pmboxq, phba->mbox_mem_pool);
6962 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6963 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6964 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6965 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6966 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6967 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6968 lso->error_frames = pmb->un.varRdLnk.crcCnt;
6969 if (phba->hba_flag & HBA_FCOE_MODE)
6970 lso->link_events = (phba->link_events >> 1);
6972 lso->link_events = (phba->fc_eventTag >> 1);
6974 psli->stats_start = ktime_get_seconds();
6976 mempool_free(pmboxq, phba->mbox_mem_pool);
6982 * The LPFC driver treats linkdown handling as target loss events so there
6983 * are no sysfs handlers for link_down_tmo.
6987 * lpfc_get_node_by_target - Return the nodelist for a target
6988 * @starget: kernel scsi target pointer.
6991 * address of the node list if found
6992 * NULL target not found
6994 static struct lpfc_nodelist *
6995 lpfc_get_node_by_target(struct scsi_target *starget)
6997 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6998 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6999 struct lpfc_nodelist *ndlp;
7001 spin_lock_irq(shost->host_lock);
7002 /* Search for this, mapped, target ID */
7003 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
7004 if (NLP_CHK_NODE_ACT(ndlp) &&
7005 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
7006 starget->id == ndlp->nlp_sid) {
7007 spin_unlock_irq(shost->host_lock);
7011 spin_unlock_irq(shost->host_lock);
7016 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
7017 * @starget: kernel scsi target pointer.
7020 lpfc_get_starget_port_id(struct scsi_target *starget)
7022 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
7024 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
7028 * lpfc_get_starget_node_name - Set the target node name
7029 * @starget: kernel scsi target pointer.
7031 * Description: Set the target node name to the ndlp node name wwn or zero.
7034 lpfc_get_starget_node_name(struct scsi_target *starget)
7036 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
7038 fc_starget_node_name(starget) =
7039 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
7043 * lpfc_get_starget_port_name - Set the target port name
7044 * @starget: kernel scsi target pointer.
7046 * Description: set the target port name to the ndlp port name wwn or zero.
7049 lpfc_get_starget_port_name(struct scsi_target *starget)
7051 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
7053 fc_starget_port_name(starget) =
7054 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
7058 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
7059 * @rport: fc rport address.
7060 * @timeout: new value for dev loss tmo.
7063 * If timeout is non zero set the dev_loss_tmo to timeout, else set
7064 * dev_loss_tmo to one.
7067 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
7069 struct lpfc_rport_data *rdata = rport->dd_data;
7070 struct lpfc_nodelist *ndlp = rdata->pnode;
7071 #if (IS_ENABLED(CONFIG_NVME_FC))
7072 struct lpfc_nvme_rport *nrport = NULL;
7076 rport->dev_loss_tmo = timeout;
7078 rport->dev_loss_tmo = 1;
7080 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
7081 dev_info(&rport->dev, "Cannot find remote node to "
7082 "set rport dev loss tmo, port_id x%x\n",
7087 #if (IS_ENABLED(CONFIG_NVME_FC))
7088 nrport = lpfc_ndlp_get_nrport(ndlp);
7090 if (nrport && nrport->remoteport)
7091 nvme_fc_set_remoteport_devloss(nrport->remoteport,
7092 rport->dev_loss_tmo);
7097 * lpfc_rport_show_function - Return rport target information
7100 * Macro that uses field to generate a function with the name lpfc_show_rport_
7102 * lpfc_show_rport_##field: returns the bytes formatted in buf
7103 * @cdev: class converted to an fc_rport.
7104 * @buf: on return contains the target_field or zero.
7106 * Returns: size of formatted string.
7108 #define lpfc_rport_show_function(field, format_string, sz, cast) \
7110 lpfc_show_rport_##field (struct device *dev, \
7111 struct device_attribute *attr, \
7114 struct fc_rport *rport = transport_class_to_rport(dev); \
7115 struct lpfc_rport_data *rdata = rport->hostdata; \
7116 return scnprintf(buf, sz, format_string, \
7117 (rdata->target) ? cast rdata->target->field : 0); \
7120 #define lpfc_rport_rd_attr(field, format_string, sz) \
7121 lpfc_rport_show_function(field, format_string, sz, ) \
7122 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
7125 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
7126 * @fc_vport: The fc_vport who's symbolic name has been changed.
7129 * This function is called by the transport after the @fc_vport's symbolic name
7130 * has been changed. This function re-registers the symbolic name with the
7131 * switch to propagate the change into the fabric if the vport is active.
7134 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
7136 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
7138 if (vport->port_state == LPFC_VPORT_READY)
7139 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
7143 * lpfc_hba_log_verbose_init - Set hba's log verbose level
7144 * @phba: Pointer to lpfc_hba struct.
7146 * This function is called by the lpfc_get_cfgparam() routine to set the
7147 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
7148 * log message according to the module's lpfc_log_verbose parameter setting
7149 * before hba port or vport created.
7152 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
7154 phba->cfg_log_verbose = verbose;
7157 struct fc_function_template lpfc_transport_functions = {
7158 /* fixed attributes the driver supports */
7159 .show_host_node_name = 1,
7160 .show_host_port_name = 1,
7161 .show_host_supported_classes = 1,
7162 .show_host_supported_fc4s = 1,
7163 .show_host_supported_speeds = 1,
7164 .show_host_maxframe_size = 1,
7166 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7167 .show_host_symbolic_name = 1,
7169 /* dynamic attributes the driver supports */
7170 .get_host_port_id = lpfc_get_host_port_id,
7171 .show_host_port_id = 1,
7173 .get_host_port_type = lpfc_get_host_port_type,
7174 .show_host_port_type = 1,
7176 .get_host_port_state = lpfc_get_host_port_state,
7177 .show_host_port_state = 1,
7179 /* active_fc4s is shown but doesn't change (thus no get function) */
7180 .show_host_active_fc4s = 1,
7182 .get_host_speed = lpfc_get_host_speed,
7183 .show_host_speed = 1,
7185 .get_host_fabric_name = lpfc_get_host_fabric_name,
7186 .show_host_fabric_name = 1,
7189 * The LPFC driver treats linkdown handling as target loss events
7190 * so there are no sysfs handlers for link_down_tmo.
7193 .get_fc_host_stats = lpfc_get_stats,
7194 .reset_fc_host_stats = lpfc_reset_stats,
7196 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7197 .show_rport_maxframe_size = 1,
7198 .show_rport_supported_classes = 1,
7200 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7201 .show_rport_dev_loss_tmo = 1,
7203 .get_starget_port_id = lpfc_get_starget_port_id,
7204 .show_starget_port_id = 1,
7206 .get_starget_node_name = lpfc_get_starget_node_name,
7207 .show_starget_node_name = 1,
7209 .get_starget_port_name = lpfc_get_starget_port_name,
7210 .show_starget_port_name = 1,
7212 .issue_fc_host_lip = lpfc_issue_lip,
7213 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7214 .terminate_rport_io = lpfc_terminate_rport_io,
7216 .dd_fcvport_size = sizeof(struct lpfc_vport *),
7218 .vport_disable = lpfc_vport_disable,
7220 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7222 .bsg_request = lpfc_bsg_request,
7223 .bsg_timeout = lpfc_bsg_timeout,
7226 struct fc_function_template lpfc_vport_transport_functions = {
7227 /* fixed attributes the driver supports */
7228 .show_host_node_name = 1,
7229 .show_host_port_name = 1,
7230 .show_host_supported_classes = 1,
7231 .show_host_supported_fc4s = 1,
7232 .show_host_supported_speeds = 1,
7233 .show_host_maxframe_size = 1,
7235 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
7236 .show_host_symbolic_name = 1,
7238 /* dynamic attributes the driver supports */
7239 .get_host_port_id = lpfc_get_host_port_id,
7240 .show_host_port_id = 1,
7242 .get_host_port_type = lpfc_get_host_port_type,
7243 .show_host_port_type = 1,
7245 .get_host_port_state = lpfc_get_host_port_state,
7246 .show_host_port_state = 1,
7248 /* active_fc4s is shown but doesn't change (thus no get function) */
7249 .show_host_active_fc4s = 1,
7251 .get_host_speed = lpfc_get_host_speed,
7252 .show_host_speed = 1,
7254 .get_host_fabric_name = lpfc_get_host_fabric_name,
7255 .show_host_fabric_name = 1,
7258 * The LPFC driver treats linkdown handling as target loss events
7259 * so there are no sysfs handlers for link_down_tmo.
7262 .get_fc_host_stats = lpfc_get_stats,
7263 .reset_fc_host_stats = lpfc_reset_stats,
7265 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
7266 .show_rport_maxframe_size = 1,
7267 .show_rport_supported_classes = 1,
7269 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7270 .show_rport_dev_loss_tmo = 1,
7272 .get_starget_port_id = lpfc_get_starget_port_id,
7273 .show_starget_port_id = 1,
7275 .get_starget_node_name = lpfc_get_starget_node_name,
7276 .show_starget_node_name = 1,
7278 .get_starget_port_name = lpfc_get_starget_port_name,
7279 .show_starget_port_name = 1,
7281 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7282 .terminate_rport_io = lpfc_terminate_rport_io,
7284 .vport_disable = lpfc_vport_disable,
7286 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7290 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7292 * @phba: lpfc_hba pointer.
7295 lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7297 /* If the adapter supports FCoE mode */
7298 switch (phba->pcidev->device) {
7299 case PCI_DEVICE_ID_SKYHAWK:
7300 case PCI_DEVICE_ID_SKYHAWK_VF:
7301 case PCI_DEVICE_ID_LANCER_FCOE:
7302 case PCI_DEVICE_ID_LANCER_FCOE_VF:
7303 case PCI_DEVICE_ID_ZEPHYR_DCSP:
7304 case PCI_DEVICE_ID_HORNET:
7305 case PCI_DEVICE_ID_TIGERSHARK:
7306 case PCI_DEVICE_ID_TOMCAT:
7307 phba->hba_flag |= HBA_FCOE_MODE;
7310 /* for others, clear the flag */
7311 phba->hba_flag &= ~HBA_FCOE_MODE;
7316 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7317 * @phba: lpfc_hba pointer.
7320 lpfc_get_cfgparam(struct lpfc_hba *phba)
7322 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7323 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
7324 lpfc_ns_query_init(phba, lpfc_ns_query);
7325 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7326 lpfc_cr_delay_init(phba, lpfc_cr_delay);
7327 lpfc_cr_count_init(phba, lpfc_cr_count);
7328 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
7329 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7330 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7331 lpfc_ack0_init(phba, lpfc_ack0);
7332 lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
7333 lpfc_topology_init(phba, lpfc_topology);
7334 lpfc_link_speed_init(phba, lpfc_link_speed);
7335 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
7336 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
7337 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7338 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
7339 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
7340 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7341 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
7342 lpfc_use_msi_init(phba, lpfc_use_msi);
7343 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
7344 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
7345 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7346 lpfc_force_rscn_init(phba, lpfc_force_rscn);
7347 lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7348 lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
7349 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
7350 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7351 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
7353 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7354 if (phba->sli_rev != LPFC_SLI_REV4)
7355 phba->cfg_EnableXLane = 0;
7356 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
7358 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7359 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7360 phba->cfg_oas_lun_state = 0;
7361 phba->cfg_oas_lun_status = 0;
7362 phba->cfg_oas_flags = 0;
7363 phba->cfg_oas_priority = 0;
7364 lpfc_enable_bg_init(phba, lpfc_enable_bg);
7365 lpfc_prot_mask_init(phba, lpfc_prot_mask);
7366 lpfc_prot_guard_init(phba, lpfc_prot_guard);
7367 if (phba->sli_rev == LPFC_SLI_REV4)
7370 phba->cfg_poll = lpfc_poll;
7372 /* Get the function mode */
7373 lpfc_get_hba_function_mode(phba);
7375 /* BlockGuard allowed for FC only. */
7376 if (phba->cfg_enable_bg && phba->hba_flag & HBA_FCOE_MODE) {
7377 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7378 "0581 BlockGuard feature not supported\n");
7379 /* If set, clear the BlockGuard support param */
7380 phba->cfg_enable_bg = 0;
7381 } else if (phba->cfg_enable_bg) {
7382 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
7385 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
7387 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
7388 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
7389 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
7391 /* Initialize first burst. Target vs Initiator are different. */
7392 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
7393 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
7394 lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
7395 lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
7396 lpfc_irq_chann_init(phba, lpfc_irq_chann);
7397 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7398 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7400 if (phba->sli_rev != LPFC_SLI_REV4) {
7401 /* NVME only supported on SLI4 */
7402 phba->nvmet_support = 0;
7403 phba->cfg_nvmet_mrq = 0;
7404 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7405 phba->cfg_enable_bbcr = 0;
7406 phba->cfg_xri_rebalancing = 0;
7408 /* We MUST have FCP support */
7409 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7410 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7413 phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7415 phba->cfg_enable_pbde = 0;
7417 /* A value of 0 means use the number of CPUs found in the system */
7418 if (phba->cfg_hdw_queue == 0)
7419 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7420 if (phba->cfg_irq_chann == 0)
7421 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7422 if (phba->cfg_irq_chann > phba->cfg_hdw_queue)
7423 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7425 phba->cfg_soft_wwnn = 0L;
7426 phba->cfg_soft_wwpn = 0L;
7427 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7428 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7429 lpfc_aer_support_init(phba, lpfc_aer_support);
7430 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7431 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7432 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7433 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7434 lpfc_sli_mode_init(phba, lpfc_sli_mode);
7435 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7436 lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7437 lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7438 lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7444 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7445 * dependencies between protocols and roles.
7446 * @phba: lpfc_hba pointer.
7449 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7453 if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu) {
7454 phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7457 if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu) {
7458 phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7461 if (phba->cfg_irq_chann > phba->cfg_hdw_queue) {
7462 phba->cfg_irq_chann = phba->cfg_hdw_queue;
7466 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7467 "2006 Reducing Queues - CPU limitation: "
7469 phba->cfg_irq_chann,
7470 phba->cfg_hdw_queue);
7472 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7473 phba->nvmet_support) {
7474 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7476 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7477 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7478 "NVME Target PRLI ACC enable_fb ",
7479 phba->cfg_nvme_enable_fb,
7480 phba->cfg_nvmet_fb_size,
7481 LPFC_NVMET_FB_SZ_MAX);
7483 if (phba->cfg_nvme_enable_fb == 0)
7484 phba->cfg_nvmet_fb_size = 0;
7486 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7487 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7490 if (!phba->cfg_nvmet_mrq)
7491 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7493 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7494 if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
7495 phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7496 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7497 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7498 phba->cfg_nvmet_mrq);
7500 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7501 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7504 /* Not NVME Target mode. Turn off Target parameters. */
7505 phba->nvmet_support = 0;
7506 phba->cfg_nvmet_mrq = 0;
7507 phba->cfg_nvmet_fb_size = 0;
7512 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7513 * @vport: lpfc_vport pointer.
7516 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7518 lpfc_log_verbose_init(vport, lpfc_log_verbose);
7519 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7520 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7521 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7522 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7523 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7524 lpfc_restrict_login_init(vport, lpfc_restrict_login);
7525 lpfc_fcp_class_init(vport, lpfc_fcp_class);
7526 lpfc_use_adisc_init(vport, lpfc_use_adisc);
7527 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7528 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7529 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7530 lpfc_max_luns_init(vport, lpfc_max_luns);
7531 lpfc_scan_down_init(vport, lpfc_scan_down);
7532 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);