1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/ctype.h>
25 #include <linux/delay.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/aer.h>
30 #include <linux/gfp.h>
31 #include <linux/kernel.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_tcq.h>
37 #include <scsi/scsi_transport_fc.h>
38 #include <scsi/fc/fc_fs.h>
40 #include <linux/nvme-fc-driver.h>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_nvmet.h"
52 #include "lpfc_logmsg.h"
53 #include "lpfc_version.h"
54 #include "lpfc_compat.h"
55 #include "lpfc_crtn.h"
56 #include "lpfc_vport.h"
57 #include "lpfc_attr.h"
59 #define LPFC_DEF_DEVLOSS_TMO 30
60 #define LPFC_MIN_DEVLOSS_TMO 1
61 #define LPFC_MAX_DEVLOSS_TMO 255
63 #define LPFC_DEF_MRQ_POST 512
64 #define LPFC_MIN_MRQ_POST 512
65 #define LPFC_MAX_MRQ_POST 2048
67 #define LPFC_MAX_NVME_INFO_TMP_LEN 100
68 #define LPFC_NVME_INFO_MORE_STR "\nCould be more info...\n"
71 * Write key size should be multiple of 4. If write key is changed
72 * make sure that library write key is also changed.
74 #define LPFC_REG_WRITE_KEY_SIZE 4
75 #define LPFC_REG_WRITE_KEY "EMLX"
78 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
79 * @incr: integer to convert.
80 * @hdw: ascii string holding converted integer plus a string terminator.
83 * JEDEC Joint Electron Device Engineering Council.
84 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
85 * character string. The string is then terminated with a NULL in byte 9.
86 * Hex 0-9 becomes ascii '0' to '9'.
87 * Hex a-f becomes ascii '=' to 'B' capital B.
90 * Coded for 32 bit integers only.
93 lpfc_jedec_to_ascii(int incr, char hdw[])
96 for (i = 0; i < 8; i++) {
99 hdw[7 - i] = 0x30 + j;
101 hdw[7 - i] = 0x61 + j - 10;
109 * lpfc_drvr_version_show - Return the Emulex driver string with version number
110 * @dev: class unused variable.
111 * @attr: device attribute, not used.
112 * @buf: on return contains the module description text.
114 * Returns: size of formatted string.
117 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
120 return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
124 * lpfc_enable_fip_show - Return the fip mode of the HBA
125 * @dev: class unused variable.
126 * @attr: device attribute, not used.
127 * @buf: on return contains the module description text.
129 * Returns: size of formatted string.
132 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
135 struct Scsi_Host *shost = class_to_shost(dev);
136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 struct lpfc_hba *phba = vport->phba;
139 if (phba->hba_flag & HBA_FIP_SUPPORT)
140 return scnprintf(buf, PAGE_SIZE, "1\n");
142 return scnprintf(buf, PAGE_SIZE, "0\n");
146 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
149 struct Scsi_Host *shost = class_to_shost(dev);
150 struct lpfc_vport *vport = shost_priv(shost);
151 struct lpfc_hba *phba = vport->phba;
152 struct lpfc_nvmet_tgtport *tgtp;
153 struct nvme_fc_local_port *localport;
154 struct lpfc_nvme_lport *lport;
155 struct lpfc_nvme_rport *rport;
156 struct lpfc_nodelist *ndlp;
157 struct nvme_fc_remote_port *nrport;
158 struct lpfc_nvme_ctrl_stat *cstat;
159 uint64_t data1, data2, data3;
160 uint64_t totin, totout, tot;
164 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
166 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
167 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
170 if (phba->nvmet_support) {
171 if (!phba->targetport) {
172 len = scnprintf(buf, PAGE_SIZE,
173 "NVME Target: x%llx is not allocated\n",
174 wwn_to_u64(vport->fc_portname.u.wwn));
177 /* Port state is only one of two values for now. */
178 if (phba->targetport->port_id)
179 statep = "REGISTERED";
182 scnprintf(tmp, sizeof(tmp),
183 "NVME Target Enabled State %s\n",
185 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
188 scnprintf(tmp, sizeof(tmp),
189 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
192 wwn_to_u64(vport->fc_portname.u.wwn),
193 wwn_to_u64(vport->fc_nodename.u.wwn),
194 phba->targetport->port_id);
195 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
198 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
202 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
203 scnprintf(tmp, sizeof(tmp),
204 "LS: Rcv %08x Drop %08x Abort %08x\n",
205 atomic_read(&tgtp->rcv_ls_req_in),
206 atomic_read(&tgtp->rcv_ls_req_drop),
207 atomic_read(&tgtp->xmt_ls_abort));
208 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
211 if (atomic_read(&tgtp->rcv_ls_req_in) !=
212 atomic_read(&tgtp->rcv_ls_req_out)) {
213 scnprintf(tmp, sizeof(tmp),
214 "Rcv LS: in %08x != out %08x\n",
215 atomic_read(&tgtp->rcv_ls_req_in),
216 atomic_read(&tgtp->rcv_ls_req_out));
217 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
221 scnprintf(tmp, sizeof(tmp),
222 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
223 atomic_read(&tgtp->xmt_ls_rsp),
224 atomic_read(&tgtp->xmt_ls_drop),
225 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
226 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
229 scnprintf(tmp, sizeof(tmp),
230 "LS: RSP Abort %08x xb %08x Err %08x\n",
231 atomic_read(&tgtp->xmt_ls_rsp_aborted),
232 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
233 atomic_read(&tgtp->xmt_ls_rsp_error));
234 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
237 scnprintf(tmp, sizeof(tmp),
238 "FCP: Rcv %08x Defer %08x Release %08x "
240 atomic_read(&tgtp->rcv_fcp_cmd_in),
241 atomic_read(&tgtp->rcv_fcp_cmd_defer),
242 atomic_read(&tgtp->xmt_fcp_release),
243 atomic_read(&tgtp->rcv_fcp_cmd_drop));
244 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
247 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
248 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
249 scnprintf(tmp, sizeof(tmp),
250 "Rcv FCP: in %08x != out %08x\n",
251 atomic_read(&tgtp->rcv_fcp_cmd_in),
252 atomic_read(&tgtp->rcv_fcp_cmd_out));
253 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
257 scnprintf(tmp, sizeof(tmp),
258 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
260 atomic_read(&tgtp->xmt_fcp_read),
261 atomic_read(&tgtp->xmt_fcp_read_rsp),
262 atomic_read(&tgtp->xmt_fcp_write),
263 atomic_read(&tgtp->xmt_fcp_rsp),
264 atomic_read(&tgtp->xmt_fcp_drop));
265 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
268 scnprintf(tmp, sizeof(tmp),
269 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
270 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
271 atomic_read(&tgtp->xmt_fcp_rsp_error),
272 atomic_read(&tgtp->xmt_fcp_rsp_drop));
273 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
276 scnprintf(tmp, sizeof(tmp),
277 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
278 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
279 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
280 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
281 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
284 scnprintf(tmp, sizeof(tmp),
285 "ABORT: Xmt %08x Cmpl %08x\n",
286 atomic_read(&tgtp->xmt_fcp_abort),
287 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
288 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
291 scnprintf(tmp, sizeof(tmp),
292 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
293 atomic_read(&tgtp->xmt_abort_sol),
294 atomic_read(&tgtp->xmt_abort_unsol),
295 atomic_read(&tgtp->xmt_abort_rsp),
296 atomic_read(&tgtp->xmt_abort_rsp_error));
297 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
300 scnprintf(tmp, sizeof(tmp),
301 "DELAY: ctx %08x fod %08x wqfull %08x\n",
302 atomic_read(&tgtp->defer_ctx),
303 atomic_read(&tgtp->defer_fod),
304 atomic_read(&tgtp->defer_wqfull));
305 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
308 /* Calculate outstanding IOs */
309 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
310 tot += atomic_read(&tgtp->xmt_fcp_release);
311 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
313 scnprintf(tmp, sizeof(tmp),
314 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
315 "CTX Outstanding %08llx\n\n",
316 phba->sli4_hba.nvmet_xri_cnt,
317 phba->sli4_hba.nvmet_io_wait_cnt,
318 phba->sli4_hba.nvmet_io_wait_total,
320 strlcat(buf, tmp, PAGE_SIZE);
324 localport = vport->localport;
326 len = scnprintf(buf, PAGE_SIZE,
327 "NVME Initiator x%llx is not allocated\n",
328 wwn_to_u64(vport->fc_portname.u.wwn));
331 lport = (struct lpfc_nvme_lport *)localport->private;
332 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
335 scnprintf(tmp, sizeof(tmp),
336 "XRI Dist lpfc%d Total %d NVME %d SCSI %d ELS %d\n",
338 phba->sli4_hba.max_cfg_param.max_xri,
339 phba->sli4_hba.nvme_xri_max,
340 phba->sli4_hba.scsi_xri_max,
341 lpfc_sli4_get_els_iocb_cnt(phba));
342 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
345 /* Port state is only one of two values for now. */
346 if (localport->port_id)
351 scnprintf(tmp, sizeof(tmp),
352 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
355 wwn_to_u64(vport->fc_portname.u.wwn),
356 wwn_to_u64(vport->fc_nodename.u.wwn),
357 localport->port_id, statep);
358 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
361 spin_lock_irq(shost->host_lock);
363 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
365 spin_lock(&vport->phba->hbalock);
366 rport = lpfc_ndlp_get_nrport(ndlp);
368 nrport = rport->remoteport;
369 spin_unlock(&vport->phba->hbalock);
373 /* Port state is only one of two values for now. */
374 switch (nrport->port_state) {
375 case FC_OBJSTATE_ONLINE:
378 case FC_OBJSTATE_UNKNOWN:
382 statep = "UNSUPPORTED";
386 /* Tab in to show lport ownership. */
387 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
388 goto unlock_buf_done;
389 if (phba->brd_no >= 10) {
390 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
391 goto unlock_buf_done;
394 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
396 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
397 goto unlock_buf_done;
399 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
401 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
402 goto unlock_buf_done;
404 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
406 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
407 goto unlock_buf_done;
409 /* An NVME rport can have multiple roles. */
410 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
411 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
412 goto unlock_buf_done;
414 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
415 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
416 goto unlock_buf_done;
418 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
419 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
420 goto unlock_buf_done;
422 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
423 FC_PORT_ROLE_NVME_TARGET |
424 FC_PORT_ROLE_NVME_DISCOVERY)) {
425 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
427 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
428 goto unlock_buf_done;
431 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
432 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
433 goto unlock_buf_done;
435 spin_unlock_irq(shost->host_lock);
440 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
443 scnprintf(tmp, sizeof(tmp),
444 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
445 atomic_read(&lport->fc4NvmeLsRequests),
446 atomic_read(&lport->fc4NvmeLsCmpls),
447 atomic_read(&lport->xmt_ls_abort));
448 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
451 scnprintf(tmp, sizeof(tmp),
452 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
453 atomic_read(&lport->xmt_ls_err),
454 atomic_read(&lport->cmpl_ls_xb),
455 atomic_read(&lport->cmpl_ls_err));
456 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
461 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
462 cstat = &lport->cstat[i];
463 tot = atomic_read(&cstat->fc4NvmeIoCmpls);
465 data1 = atomic_read(&cstat->fc4NvmeInputRequests);
466 data2 = atomic_read(&cstat->fc4NvmeOutputRequests);
467 data3 = atomic_read(&cstat->fc4NvmeControlRequests);
468 totout += (data1 + data2 + data3);
470 scnprintf(tmp, sizeof(tmp),
471 "Total FCP Cmpl %016llx Issue %016llx "
473 totin, totout, totout - totin);
474 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
477 scnprintf(tmp, sizeof(tmp),
478 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
479 "wqerr %08x err %08x\n",
480 atomic_read(&lport->xmt_fcp_abort),
481 atomic_read(&lport->xmt_fcp_noxri),
482 atomic_read(&lport->xmt_fcp_bad_ndlp),
483 atomic_read(&lport->xmt_fcp_qdepth),
484 atomic_read(&lport->xmt_fcp_err),
485 atomic_read(&lport->xmt_fcp_wqerr));
486 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
489 scnprintf(tmp, sizeof(tmp),
490 "FCP CMPL: xb %08x Err %08x\n",
491 atomic_read(&lport->cmpl_fcp_xb),
492 atomic_read(&lport->cmpl_fcp_err));
493 strlcat(buf, tmp, PAGE_SIZE);
495 /* host_lock is already unlocked. */
499 spin_unlock_irq(shost->host_lock);
502 len = strnlen(buf, PAGE_SIZE);
504 if (unlikely(len >= (PAGE_SIZE - 1))) {
505 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
506 "6314 Catching potential buffer "
507 "overflow > PAGE_SIZE = %lu bytes\n",
509 strlcpy(buf + PAGE_SIZE - 1 -
510 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1),
511 LPFC_NVME_INFO_MORE_STR,
512 strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1)
520 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
523 struct Scsi_Host *shost = class_to_shost(dev);
524 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
525 struct lpfc_hba *phba = vport->phba;
527 if (phba->cfg_enable_bg) {
528 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
529 return scnprintf(buf, PAGE_SIZE,
530 "BlockGuard Enabled\n");
532 return scnprintf(buf, PAGE_SIZE,
533 "BlockGuard Not Supported\n");
535 return scnprintf(buf, PAGE_SIZE,
536 "BlockGuard Disabled\n");
540 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
543 struct Scsi_Host *shost = class_to_shost(dev);
544 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
545 struct lpfc_hba *phba = vport->phba;
547 return scnprintf(buf, PAGE_SIZE, "%llu\n",
548 (unsigned long long)phba->bg_guard_err_cnt);
552 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
555 struct Scsi_Host *shost = class_to_shost(dev);
556 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
557 struct lpfc_hba *phba = vport->phba;
559 return scnprintf(buf, PAGE_SIZE, "%llu\n",
560 (unsigned long long)phba->bg_apptag_err_cnt);
564 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
567 struct Scsi_Host *shost = class_to_shost(dev);
568 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
569 struct lpfc_hba *phba = vport->phba;
571 return scnprintf(buf, PAGE_SIZE, "%llu\n",
572 (unsigned long long)phba->bg_reftag_err_cnt);
576 * lpfc_info_show - Return some pci info about the host in ascii
577 * @dev: class converted to a Scsi_host structure.
578 * @attr: device attribute, not used.
579 * @buf: on return contains the formatted text from lpfc_info().
581 * Returns: size of formatted string.
584 lpfc_info_show(struct device *dev, struct device_attribute *attr,
587 struct Scsi_Host *host = class_to_shost(dev);
589 return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
593 * lpfc_serialnum_show - Return the hba serial number in ascii
594 * @dev: class converted to a Scsi_host structure.
595 * @attr: device attribute, not used.
596 * @buf: on return contains the formatted text serial number.
598 * Returns: size of formatted string.
601 lpfc_serialnum_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, "%s\n", phba->SerialNumber);
612 * lpfc_temp_sensor_show - Return the temperature sensor level
613 * @dev: class converted to a Scsi_host structure.
614 * @attr: device attribute, not used.
615 * @buf: on return contains the formatted support level.
618 * Returns a number indicating the temperature sensor level currently
619 * supported, zero or one in ascii.
621 * Returns: size of formatted string.
624 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
627 struct Scsi_Host *shost = class_to_shost(dev);
628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
629 struct lpfc_hba *phba = vport->phba;
630 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
634 * lpfc_modeldesc_show - Return the model description of the hba
635 * @dev: class converted to a Scsi_host structure.
636 * @attr: device attribute, not used.
637 * @buf: on return contains the scsi vpd model description.
639 * Returns: size of formatted string.
642 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
645 struct Scsi_Host *shost = class_to_shost(dev);
646 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
647 struct lpfc_hba *phba = vport->phba;
649 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
653 * lpfc_modelname_show - Return the model name of the hba
654 * @dev: class converted to a Scsi_host structure.
655 * @attr: device attribute, not used.
656 * @buf: on return contains the scsi vpd model name.
658 * Returns: size of formatted string.
661 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
664 struct Scsi_Host *shost = class_to_shost(dev);
665 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
666 struct lpfc_hba *phba = vport->phba;
668 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
672 * lpfc_programtype_show - Return the program type of the hba
673 * @dev: class converted to a Scsi_host structure.
674 * @attr: device attribute, not used.
675 * @buf: on return contains the scsi vpd program type.
677 * Returns: size of formatted string.
680 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
683 struct Scsi_Host *shost = class_to_shost(dev);
684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685 struct lpfc_hba *phba = vport->phba;
687 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
691 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
692 * @dev: class converted to a Scsi_host structure.
693 * @attr: device attribute, not used.
694 * @buf: on return contains the Menlo Maintenance sli flag.
696 * Returns: size of formatted string.
699 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
701 struct Scsi_Host *shost = class_to_shost(dev);
702 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
703 struct lpfc_hba *phba = vport->phba;
705 return scnprintf(buf, PAGE_SIZE, "%d\n",
706 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
710 * lpfc_vportnum_show - Return the port number in ascii of the hba
711 * @dev: class converted to a Scsi_host structure.
712 * @attr: device attribute, not used.
713 * @buf: on return contains scsi vpd program type.
715 * Returns: size of formatted string.
718 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
721 struct Scsi_Host *shost = class_to_shost(dev);
722 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
723 struct lpfc_hba *phba = vport->phba;
725 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
729 * lpfc_fwrev_show - Return the firmware rev running in the hba
730 * @dev: class converted to a Scsi_host structure.
731 * @attr: device attribute, not used.
732 * @buf: on return contains the scsi vpd program type.
734 * Returns: size of formatted string.
737 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
740 struct Scsi_Host *shost = class_to_shost(dev);
741 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
742 struct lpfc_hba *phba = vport->phba;
745 char fwrev[FW_REV_STR_SIZE];
748 lpfc_decode_firmware_rev(phba, fwrev, 1);
749 if_type = phba->sli4_hba.pc_sli4_params.if_type;
750 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
752 if (phba->sli_rev < LPFC_SLI_REV4)
753 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
754 fwrev, phba->sli_rev);
756 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
757 fwrev, phba->sli_rev, if_type, sli_family);
763 * lpfc_hdw_show - Return the jedec information about the hba
764 * @dev: class converted to a Scsi_host structure.
765 * @attr: device attribute, not used.
766 * @buf: on return contains the scsi vpd program type.
768 * Returns: size of formatted string.
771 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
774 struct Scsi_Host *shost = class_to_shost(dev);
775 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
776 struct lpfc_hba *phba = vport->phba;
777 lpfc_vpd_t *vp = &phba->vpd;
779 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
780 return scnprintf(buf, PAGE_SIZE, "%s\n", hdw);
784 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
785 * @dev: class converted to a Scsi_host structure.
786 * @attr: device attribute, not used.
787 * @buf: on return contains the ROM and FCode ascii strings.
789 * Returns: size of formatted string.
792 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
795 struct Scsi_Host *shost = class_to_shost(dev);
796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
797 struct lpfc_hba *phba = vport->phba;
798 char fwrev[FW_REV_STR_SIZE];
800 if (phba->sli_rev < LPFC_SLI_REV4)
801 return scnprintf(buf, PAGE_SIZE, "%s\n",
802 phba->OptionROMVersion);
804 lpfc_decode_firmware_rev(phba, fwrev, 1);
805 return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
809 * lpfc_state_show - Return the link state of the port
810 * @dev: class converted to a Scsi_host structure.
811 * @attr: device attribute, not used.
812 * @buf: on return contains text describing the state of the link.
815 * The switch statement has no default so zero will be returned.
817 * Returns: size of formatted string.
820 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
823 struct Scsi_Host *shost = class_to_shost(dev);
824 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
825 struct lpfc_hba *phba = vport->phba;
828 switch (phba->link_state) {
829 case LPFC_LINK_UNKNOWN:
830 case LPFC_WARM_START:
831 case LPFC_INIT_START:
832 case LPFC_INIT_MBX_CMDS:
835 if (phba->hba_flag & LINK_DISABLED)
836 len += scnprintf(buf + len, PAGE_SIZE-len,
837 "Link Down - User disabled\n");
839 len += scnprintf(buf + len, PAGE_SIZE-len,
845 len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
847 switch (vport->port_state) {
848 case LPFC_LOCAL_CFG_LINK:
849 len += scnprintf(buf + len, PAGE_SIZE-len,
850 "Configuring Link\n");
854 case LPFC_FABRIC_CFG_LINK:
857 case LPFC_BUILD_DISC_LIST:
859 len += scnprintf(buf + len, PAGE_SIZE - len,
862 case LPFC_VPORT_READY:
863 len += scnprintf(buf + len, PAGE_SIZE - len,
867 case LPFC_VPORT_FAILED:
868 len += scnprintf(buf + len, PAGE_SIZE - len,
872 case LPFC_VPORT_UNKNOWN:
873 len += scnprintf(buf + len, PAGE_SIZE - len,
877 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
878 len += scnprintf(buf + len, PAGE_SIZE-len,
879 " Menlo Maint Mode\n");
880 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
881 if (vport->fc_flag & FC_PUBLIC_LOOP)
882 len += scnprintf(buf + len, PAGE_SIZE-len,
885 len += scnprintf(buf + len, PAGE_SIZE-len,
888 if (vport->fc_flag & FC_FABRIC)
889 len += scnprintf(buf + len, PAGE_SIZE-len,
892 len += scnprintf(buf + len, PAGE_SIZE-len,
901 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
902 * @dev: class unused variable.
903 * @attr: device attribute, not used.
904 * @buf: on return contains the module description text.
906 * Returns: size of formatted string.
909 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
912 struct Scsi_Host *shost = class_to_shost(dev);
913 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
914 struct lpfc_hba *phba = vport->phba;
916 if (phba->sli_rev < LPFC_SLI_REV4)
917 return scnprintf(buf, PAGE_SIZE, "fc\n");
919 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
920 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
921 return scnprintf(buf, PAGE_SIZE, "fcoe\n");
922 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
923 return scnprintf(buf, PAGE_SIZE, "fc\n");
925 return scnprintf(buf, PAGE_SIZE, "unknown\n");
929 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
930 * (OAS) is supported.
931 * @dev: class unused variable.
932 * @attr: device attribute, not used.
933 * @buf: on return contains the module description text.
935 * Returns: size of formatted string.
938 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
941 struct Scsi_Host *shost = class_to_shost(dev);
942 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
943 struct lpfc_hba *phba = vport->phba;
945 return scnprintf(buf, PAGE_SIZE, "%d\n",
946 phba->sli4_hba.pc_sli4_params.oas_supported);
950 * lpfc_link_state_store - Transition the link_state on an HBA port
951 * @dev: class device that is converted into a Scsi_host.
952 * @attr: device attribute, not used.
953 * @buf: one or more lpfc_polling_flags values.
957 * -EINVAL if the buffer is not "up" or "down"
958 * return from link state change function if non-zero
959 * length of the buf on success
962 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
963 const char *buf, size_t count)
965 struct Scsi_Host *shost = class_to_shost(dev);
966 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
967 struct lpfc_hba *phba = vport->phba;
969 int status = -EINVAL;
971 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
972 (phba->link_state == LPFC_LINK_DOWN))
973 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
974 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
975 (phba->link_state >= LPFC_LINK_UP))
976 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
985 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
986 * @dev: class device that is converted into a Scsi_host.
987 * @attr: device attribute, not used.
988 * @buf: on return contains the sum of fc mapped and unmapped.
991 * Returns the ascii text number of the sum of the fc mapped and unmapped
994 * Returns: size of formatted string.
997 lpfc_num_discovered_ports_show(struct device *dev,
998 struct device_attribute *attr, char *buf)
1000 struct Scsi_Host *shost = class_to_shost(dev);
1001 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1003 return scnprintf(buf, PAGE_SIZE, "%d\n",
1004 vport->fc_map_cnt + vport->fc_unmap_cnt);
1008 * lpfc_issue_lip - Misnomer, name carried over from long ago
1009 * @shost: Scsi_Host pointer.
1012 * Bring the link down gracefully then re-init the link. The firmware will
1013 * re-init the fiber channel interface as required. Does not issue a LIP.
1016 * -EPERM port offline or management commands are being blocked
1017 * -ENOMEM cannot allocate memory for the mailbox command
1018 * -EIO error sending the mailbox command
1022 lpfc_issue_lip(struct Scsi_Host *shost)
1024 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1025 struct lpfc_hba *phba = vport->phba;
1026 LPFC_MBOXQ_t *pmboxq;
1027 int mbxstatus = MBXERR_ERROR;
1030 * If the link is offline, disabled or BLOCK_MGMT_IO
1031 * it doesn't make any sense to allow issue_lip
1033 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1034 (phba->hba_flag & LINK_DISABLED) ||
1035 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1038 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1043 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1044 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1045 pmboxq->u.mb.mbxOwner = OWN_HOST;
1047 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1049 if ((mbxstatus == MBX_SUCCESS) &&
1050 (pmboxq->u.mb.mbxStatus == 0 ||
1051 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1052 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1053 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1054 phba->cfg_link_speed);
1055 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1056 phba->fc_ratov * 2);
1057 if ((mbxstatus == MBX_SUCCESS) &&
1058 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1059 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1060 "2859 SLI authentication is required "
1061 "for INIT_LINK but has not done yet\n");
1064 lpfc_set_loopback_flag(phba);
1065 if (mbxstatus != MBX_TIMEOUT)
1066 mempool_free(pmboxq, phba->mbox_mem_pool);
1068 if (mbxstatus == MBXERR_ERROR)
1075 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1079 spin_lock_irq(lock);
1080 while (!list_empty(q)) {
1081 spin_unlock_irq(lock);
1083 if (cnt++ > 250) { /* 5 secs */
1084 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1086 "Outstanding IO when ",
1087 "bringing Adapter offline\n");
1090 spin_lock_irq(lock);
1092 spin_unlock_irq(lock);
1097 * lpfc_do_offline - Issues a mailbox command to bring the link down
1098 * @phba: lpfc_hba pointer.
1099 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1102 * Assumes any error from lpfc_do_offline() will be negative.
1103 * Can wait up to 5 seconds for the port ring buffers count
1104 * to reach zero, prints a warning if it is not zero and continues.
1105 * lpfc_workq_post_event() returns a non-zero return code if call fails.
1108 * -EIO error posting the event
1112 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1114 struct completion online_compl;
1115 struct lpfc_queue *qp = NULL;
1116 struct lpfc_sli_ring *pring;
1117 struct lpfc_sli *psli;
1122 init_completion(&online_compl);
1123 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1124 LPFC_EVT_OFFLINE_PREP);
1128 wait_for_completion(&online_compl);
1135 /* Wait a little for things to settle down, but not
1136 * long enough for dev loss timeout to expire.
1138 if (phba->sli_rev != LPFC_SLI_REV4) {
1139 for (i = 0; i < psli->num_rings; i++) {
1140 pring = &psli->sli3_ring[i];
1141 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1146 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1150 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1156 init_completion(&online_compl);
1157 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1161 wait_for_completion(&online_compl);
1170 * lpfc_selective_reset - Offline then onlines the port
1171 * @phba: lpfc_hba pointer.
1174 * If the port is configured to allow a reset then the hba is brought
1175 * offline then online.
1178 * Assumes any error from lpfc_do_offline() will be negative.
1179 * Do not make this function static.
1182 * lpfc_do_offline() return code if not zero
1183 * -EIO reset not configured or error posting the event
1187 lpfc_selective_reset(struct lpfc_hba *phba)
1189 struct completion online_compl;
1193 if (!phba->cfg_enable_hba_reset)
1196 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1197 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1203 init_completion(&online_compl);
1204 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1209 wait_for_completion(&online_compl);
1218 * lpfc_issue_reset - Selectively resets an adapter
1219 * @dev: class device that is converted into a Scsi_host.
1220 * @attr: device attribute, not used.
1221 * @buf: containing the string "selective".
1222 * @count: unused variable.
1225 * If the buf contains the string "selective" then lpfc_selective_reset()
1226 * is called to perform the reset.
1229 * Assumes any error from lpfc_selective_reset() will be negative.
1230 * If lpfc_selective_reset() returns zero then the length of the buffer
1231 * is returned which indicates success
1234 * -EINVAL if the buffer does not contain the string "selective"
1235 * length of buf if lpfc-selective_reset() if the call succeeds
1236 * return value of lpfc_selective_reset() if the call fails
1239 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1240 const char *buf, size_t count)
1242 struct Scsi_Host *shost = class_to_shost(dev);
1243 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1244 struct lpfc_hba *phba = vport->phba;
1245 int status = -EINVAL;
1247 if (!phba->cfg_enable_hba_reset)
1250 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1251 status = phba->lpfc_selective_reset(phba);
1260 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1261 * @phba: lpfc_hba pointer.
1264 * SLI4 interface type-2 device to wait on the sliport status register for
1265 * the readyness after performing a firmware reset.
1268 * zero for success, -EPERM when port does not have privilege to perform the
1269 * reset, -EIO when port timeout from recovering from the reset.
1272 * As the caller will interpret the return code by value, be careful in making
1273 * change or addition to return codes.
1276 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1278 struct lpfc_register portstat_reg = {0};
1282 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1283 &portstat_reg.word0);
1285 /* verify if privileged for the request operation */
1286 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1287 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1290 /* wait for the SLI port firmware ready after firmware reset */
1291 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1293 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1294 &portstat_reg.word0);
1295 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1297 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1299 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1304 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1311 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1312 * @phba: lpfc_hba pointer.
1315 * Request SLI4 interface type-2 device to perform a physical register set
1322 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1324 struct completion online_compl;
1325 struct pci_dev *pdev = phba->pcidev;
1326 uint32_t before_fc_flag;
1327 uint32_t sriov_nr_virtfn;
1329 int status = 0, rc = 0;
1330 int job_posted = 1, sriov_err;
1332 if (!phba->cfg_enable_hba_reset)
1335 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1336 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1337 LPFC_SLI_INTF_IF_TYPE_2))
1340 /* Keep state if we need to restore back */
1341 before_fc_flag = phba->pport->fc_flag;
1342 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1344 /* Disable SR-IOV virtual functions if enabled */
1345 if (phba->cfg_sriov_nr_virtfn) {
1346 pci_disable_sriov(pdev);
1347 phba->cfg_sriov_nr_virtfn = 0;
1350 if (opcode == LPFC_FW_DUMP)
1351 phba->hba_flag |= HBA_FW_DUMP_OP;
1353 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1356 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1360 /* wait for the device to be quiesced before firmware reset */
1363 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1364 LPFC_CTL_PDEV_CTL_OFFSET);
1366 if (opcode == LPFC_FW_DUMP)
1367 reg_val |= LPFC_FW_DUMP_REQUEST;
1368 else if (opcode == LPFC_FW_RESET)
1369 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1370 else if (opcode == LPFC_DV_RESET)
1371 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1373 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1374 LPFC_CTL_PDEV_CTL_OFFSET);
1376 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1378 /* delay driver action following IF_TYPE_2 reset */
1379 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1382 /* no privilege for reset */
1383 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1384 "3150 No privilege to perform the requested "
1385 "access: x%x\n", reg_val);
1386 } else if (rc == -EIO) {
1387 /* reset failed, there is nothing more we can do */
1388 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1389 "3153 Fail to perform the requested "
1390 "access: x%x\n", reg_val);
1394 /* keep the original port state */
1395 if (before_fc_flag & FC_OFFLINE_MODE)
1398 init_completion(&online_compl);
1399 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1404 wait_for_completion(&online_compl);
1407 /* in any case, restore the virtual functions enabled as before */
1408 if (sriov_nr_virtfn) {
1410 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1412 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1415 /* return proper error code */
1426 * lpfc_nport_evt_cnt_show - Return the number of nport events
1427 * @dev: class device that is converted into a Scsi_host.
1428 * @attr: device attribute, not used.
1429 * @buf: on return contains the ascii number of nport events.
1431 * Returns: size of formatted string.
1434 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1437 struct Scsi_Host *shost = class_to_shost(dev);
1438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1439 struct lpfc_hba *phba = vport->phba;
1441 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1445 * lpfc_board_mode_show - Return the state of the board
1446 * @dev: class device that is converted into a Scsi_host.
1447 * @attr: device attribute, not used.
1448 * @buf: on return contains the state of the adapter.
1450 * Returns: size of formatted string.
1453 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1456 struct Scsi_Host *shost = class_to_shost(dev);
1457 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1458 struct lpfc_hba *phba = vport->phba;
1461 if (phba->link_state == LPFC_HBA_ERROR)
1463 else if (phba->link_state == LPFC_WARM_START)
1464 state = "warm start";
1465 else if (phba->link_state == LPFC_INIT_START)
1470 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
1474 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1475 * @dev: class device that is converted into a Scsi_host.
1476 * @attr: device attribute, not used.
1477 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1478 * @count: unused variable.
1481 * -EACCES if enable hba reset not enabled
1482 * -EINVAL if the buffer does not contain a valid string (see above)
1483 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1484 * buf length greater than zero indicates success
1487 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1488 const char *buf, size_t count)
1490 struct Scsi_Host *shost = class_to_shost(dev);
1491 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1492 struct lpfc_hba *phba = vport->phba;
1493 struct completion online_compl;
1494 char *board_mode_str = NULL;
1498 if (!phba->cfg_enable_hba_reset) {
1500 goto board_mode_out;
1503 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1504 "3050 lpfc_board_mode set to %s\n", buf);
1506 init_completion(&online_compl);
1508 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1509 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1513 goto board_mode_out;
1515 wait_for_completion(&online_compl);
1518 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1519 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1520 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1521 if (phba->sli_rev == LPFC_SLI_REV4)
1524 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1525 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1526 if (phba->sli_rev == LPFC_SLI_REV4)
1529 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1530 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1531 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1532 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1533 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1534 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1535 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1543 board_mode_str = strchr(buf, '\n');
1545 *board_mode_str = '\0';
1546 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1547 "3097 Failed \"%s\", status(%d), "
1549 buf, status, phba->pport->fc_flag);
1555 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1556 * @phba: pointer to the adapter structure.
1557 * @mxri: max xri count.
1558 * @axri: available xri count.
1559 * @mrpi: max rpi count.
1560 * @arpi: available rpi count.
1561 * @mvpi: max vpi count.
1562 * @avpi: available vpi count.
1565 * If an integer pointer for an count is not null then the value for the
1566 * count is returned.
1573 lpfc_get_hba_info(struct lpfc_hba *phba,
1574 uint32_t *mxri, uint32_t *axri,
1575 uint32_t *mrpi, uint32_t *arpi,
1576 uint32_t *mvpi, uint32_t *avpi)
1578 struct lpfc_mbx_read_config *rd_config;
1579 LPFC_MBOXQ_t *pmboxq;
1585 * prevent udev from issuing mailbox commands until the port is
1588 if (phba->link_state < LPFC_LINK_DOWN ||
1589 !phba->mbox_mem_pool ||
1590 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1593 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1596 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1599 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1601 pmb = &pmboxq->u.mb;
1602 pmb->mbxCommand = MBX_READ_CONFIG;
1603 pmb->mbxOwner = OWN_HOST;
1604 pmboxq->context1 = NULL;
1606 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1607 rc = MBX_NOT_FINISHED;
1609 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1611 if (rc != MBX_SUCCESS) {
1612 if (rc != MBX_TIMEOUT)
1613 mempool_free(pmboxq, phba->mbox_mem_pool);
1617 if (phba->sli_rev == LPFC_SLI_REV4) {
1618 rd_config = &pmboxq->u.mqe.un.rd_config;
1620 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1622 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1623 phba->sli4_hba.max_cfg_param.rpi_used;
1625 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1627 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1628 phba->sli4_hba.max_cfg_param.xri_used;
1630 /* Account for differences with SLI-3. Get vpi count from
1631 * mailbox data and subtract one for max vpi value.
1633 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1634 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1636 /* Limit the max we support */
1637 if (max_vpi > LPFC_MAX_VPI)
1638 max_vpi = LPFC_MAX_VPI;
1642 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1645 *mrpi = pmb->un.varRdConfig.max_rpi;
1647 *arpi = pmb->un.varRdConfig.avail_rpi;
1649 *mxri = pmb->un.varRdConfig.max_xri;
1651 *axri = pmb->un.varRdConfig.avail_xri;
1653 *mvpi = pmb->un.varRdConfig.max_vpi;
1655 /* avail_vpi is only valid if link is up and ready */
1656 if (phba->link_state == LPFC_HBA_READY)
1657 *avpi = pmb->un.varRdConfig.avail_vpi;
1659 *avpi = pmb->un.varRdConfig.max_vpi;
1663 mempool_free(pmboxq, phba->mbox_mem_pool);
1668 * lpfc_max_rpi_show - Return maximum rpi
1669 * @dev: class device that is converted into a Scsi_host.
1670 * @attr: device attribute, not used.
1671 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1674 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1675 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1676 * to "Unknown" and the buffer length is returned, therefore the caller
1677 * must check for "Unknown" in the buffer to detect a failure.
1679 * Returns: size of formatted string.
1682 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1685 struct Scsi_Host *shost = class_to_shost(dev);
1686 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1687 struct lpfc_hba *phba = vport->phba;
1690 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1691 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
1692 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1696 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1697 * @dev: class device that is converted into a Scsi_host.
1698 * @attr: device attribute, not used.
1699 * @buf: containing the used rpi count in decimal or "Unknown".
1702 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1703 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1704 * to "Unknown" and the buffer length is returned, therefore the caller
1705 * must check for "Unknown" in the buffer to detect a failure.
1707 * Returns: size of formatted string.
1710 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1713 struct Scsi_Host *shost = class_to_shost(dev);
1714 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1715 struct lpfc_hba *phba = vport->phba;
1718 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1719 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1720 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1724 * lpfc_max_xri_show - Return maximum xri
1725 * @dev: class device that is converted into a Scsi_host.
1726 * @attr: device attribute, not used.
1727 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1730 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1731 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1732 * to "Unknown" and the buffer length is returned, therefore the caller
1733 * must check for "Unknown" in the buffer to detect a failure.
1735 * Returns: size of formatted string.
1738 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1741 struct Scsi_Host *shost = class_to_shost(dev);
1742 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1743 struct lpfc_hba *phba = vport->phba;
1746 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1747 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
1748 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1752 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1753 * @dev: class device that is converted into a Scsi_host.
1754 * @attr: device attribute, not used.
1755 * @buf: on return contains the used xri count in decimal or "Unknown".
1758 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1759 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1760 * to "Unknown" and the buffer length is returned, therefore the caller
1761 * must check for "Unknown" in the buffer to detect a failure.
1763 * Returns: size of formatted string.
1766 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1769 struct Scsi_Host *shost = class_to_shost(dev);
1770 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1771 struct lpfc_hba *phba = vport->phba;
1774 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1775 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1776 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1780 * lpfc_max_vpi_show - Return maximum vpi
1781 * @dev: class device that is converted into a Scsi_host.
1782 * @attr: device attribute, not used.
1783 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1786 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1787 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1788 * to "Unknown" and the buffer length is returned, therefore the caller
1789 * must check for "Unknown" in the buffer to detect a failure.
1791 * Returns: size of formatted string.
1794 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1797 struct Scsi_Host *shost = class_to_shost(dev);
1798 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1799 struct lpfc_hba *phba = vport->phba;
1802 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1803 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
1804 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1808 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1809 * @dev: class device that is converted into a Scsi_host.
1810 * @attr: device attribute, not used.
1811 * @buf: on return contains the used vpi count in decimal or "Unknown".
1814 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1815 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1816 * to "Unknown" and the buffer length is returned, therefore the caller
1817 * must check for "Unknown" in the buffer to detect a failure.
1819 * Returns: size of formatted string.
1822 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1825 struct Scsi_Host *shost = class_to_shost(dev);
1826 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1827 struct lpfc_hba *phba = vport->phba;
1830 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1831 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1832 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1836 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1837 * @dev: class device that is converted into a Scsi_host.
1838 * @attr: device attribute, not used.
1839 * @buf: text that must be interpreted to determine if npiv is supported.
1842 * Buffer will contain text indicating npiv is not suppoerted on the port,
1843 * the port is an NPIV physical port, or it is an npiv virtual port with
1844 * the id of the vport.
1846 * Returns: size of formatted string.
1849 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1852 struct Scsi_Host *shost = class_to_shost(dev);
1853 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1854 struct lpfc_hba *phba = vport->phba;
1856 if (!(phba->max_vpi))
1857 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1858 if (vport->port_type == LPFC_PHYSICAL_PORT)
1859 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1860 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1864 * lpfc_poll_show - Return text about poll support for the adapter
1865 * @dev: class device that is converted into a Scsi_host.
1866 * @attr: device attribute, not used.
1867 * @buf: on return contains the cfg_poll in hex.
1870 * cfg_poll should be a lpfc_polling_flags type.
1872 * Returns: size of formatted string.
1875 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1878 struct Scsi_Host *shost = class_to_shost(dev);
1879 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1880 struct lpfc_hba *phba = vport->phba;
1882 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1886 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1887 * @dev: class device that is converted into a Scsi_host.
1888 * @attr: device attribute, not used.
1889 * @buf: one or more lpfc_polling_flags values.
1893 * buf contents converted to integer and checked for a valid value.
1896 * -EINVAL if the buffer connot be converted or is out of range
1897 * length of the buf on success
1900 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1901 const char *buf, size_t count)
1903 struct Scsi_Host *shost = class_to_shost(dev);
1904 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1905 struct lpfc_hba *phba = vport->phba;
1910 if (!isdigit(buf[0]))
1913 if (sscanf(buf, "%i", &val) != 1)
1916 if ((val & 0x3) != val)
1919 if (phba->sli_rev == LPFC_SLI_REV4)
1922 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1923 "3051 lpfc_poll changed from %d to %d\n",
1924 phba->cfg_poll, val);
1926 spin_lock_irq(&phba->hbalock);
1928 old_val = phba->cfg_poll;
1930 if (val & ENABLE_FCP_RING_POLLING) {
1931 if ((val & DISABLE_FCP_RING_INT) &&
1932 !(old_val & DISABLE_FCP_RING_INT)) {
1933 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1934 spin_unlock_irq(&phba->hbalock);
1937 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1938 writel(creg_val, phba->HCregaddr);
1939 readl(phba->HCregaddr); /* flush */
1941 lpfc_poll_start_timer(phba);
1943 } else if (val != 0x0) {
1944 spin_unlock_irq(&phba->hbalock);
1948 if (!(val & DISABLE_FCP_RING_INT) &&
1949 (old_val & DISABLE_FCP_RING_INT))
1951 spin_unlock_irq(&phba->hbalock);
1952 del_timer(&phba->fcp_poll_timer);
1953 spin_lock_irq(&phba->hbalock);
1954 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1955 spin_unlock_irq(&phba->hbalock);
1958 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1959 writel(creg_val, phba->HCregaddr);
1960 readl(phba->HCregaddr); /* flush */
1963 phba->cfg_poll = val;
1965 spin_unlock_irq(&phba->hbalock);
1971 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1972 * @dev: class unused variable.
1973 * @attr: device attribute, not used.
1974 * @buf: on return contains the module description text.
1976 * Returns: size of formatted string.
1979 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1982 struct Scsi_Host *shost = class_to_shost(dev);
1983 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1984 struct lpfc_hba *phba = vport->phba;
1986 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1990 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1991 * @dev: class unused variable.
1992 * @attr: device attribute, not used.
1993 * @buf: on return contains the module description text.
1995 * Returns: size of formatted string.
1998 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
2001 struct Scsi_Host *shost = class_to_shost(dev);
2002 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2003 struct lpfc_hba *phba = vport->phba;
2005 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
2009 * lpfc_dss_show - Return the current state of dss and the configured state
2010 * @dev: class converted to a Scsi_host structure.
2011 * @attr: device attribute, not used.
2012 * @buf: on return contains the formatted text.
2014 * Returns: size of formatted string.
2017 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
2020 struct Scsi_Host *shost = class_to_shost(dev);
2021 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2022 struct lpfc_hba *phba = vport->phba;
2024 return scnprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
2025 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
2026 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
2031 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2032 * @dev: class converted to a Scsi_host structure.
2033 * @attr: device attribute, not used.
2034 * @buf: on return contains the formatted support level.
2037 * Returns the maximum number of virtual functions a physical function can
2038 * support, 0 will be returned if called on virtual function.
2040 * Returns: size of formatted string.
2043 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2044 struct device_attribute *attr,
2047 struct Scsi_Host *shost = class_to_shost(dev);
2048 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2049 struct lpfc_hba *phba = vport->phba;
2050 uint16_t max_nr_virtfn;
2052 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2053 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2056 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2058 return val >= min && val <= max;
2062 * lpfc_enable_bbcr_set: Sets an attribute value.
2063 * @phba: pointer the the adapter structure.
2064 * @val: integer attribute value.
2067 * Validates the min and max values then sets the
2068 * adapter config field if in the valid range. prints error message
2069 * and does not set the parameter if invalid.
2073 * -EINVAL if val is invalid
2076 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2078 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2079 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2080 "3068 %s_enable_bbcr changed from %d to %d\n",
2081 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
2082 phba->cfg_enable_bbcr = val;
2085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2086 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2087 LPFC_DRIVER_NAME, val);
2092 * lpfc_param_show - Return a cfg attribute value in decimal
2095 * Macro that given an attr e.g. hba_queue_depth expands
2096 * into a function with the name lpfc_hba_queue_depth_show.
2098 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2099 * @dev: class device that is converted into a Scsi_host.
2100 * @attr: device attribute, not used.
2101 * @buf: on return contains the attribute value in decimal.
2103 * Returns: size of formatted string.
2105 #define lpfc_param_show(attr) \
2107 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2110 struct Scsi_Host *shost = class_to_shost(dev);\
2111 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2112 struct lpfc_hba *phba = vport->phba;\
2113 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2118 * lpfc_param_hex_show - Return a cfg attribute value in hex
2121 * Macro that given an attr e.g. hba_queue_depth expands
2122 * into a function with the name lpfc_hba_queue_depth_show
2124 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2125 * @dev: class device that is converted into a Scsi_host.
2126 * @attr: device attribute, not used.
2127 * @buf: on return contains the attribute value in hexadecimal.
2129 * Returns: size of formatted string.
2131 #define lpfc_param_hex_show(attr) \
2133 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2136 struct Scsi_Host *shost = class_to_shost(dev);\
2137 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2138 struct lpfc_hba *phba = vport->phba;\
2140 val = phba->cfg_##attr;\
2141 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2146 * lpfc_param_init - Initializes a cfg attribute
2149 * Macro that given an attr e.g. hba_queue_depth expands
2150 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2151 * takes a default argument, a minimum and maximum argument.
2153 * lpfc_##attr##_init: Initializes an attribute.
2154 * @phba: pointer the the adapter structure.
2155 * @val: integer attribute value.
2157 * Validates the min and max values then sets the adapter config field
2158 * accordingly, or uses the default if out of range and prints an error message.
2162 * -EINVAL if default used
2164 #define lpfc_param_init(attr, default, minval, maxval) \
2166 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2168 if (lpfc_rangecheck(val, minval, maxval)) {\
2169 phba->cfg_##attr = val;\
2172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2173 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2174 "allowed range is ["#minval", "#maxval"]\n", val); \
2175 phba->cfg_##attr = default;\
2180 * lpfc_param_set - Set a cfg attribute value
2183 * Macro that given an attr e.g. hba_queue_depth expands
2184 * into a function with the name lpfc_hba_queue_depth_set
2186 * lpfc_##attr##_set: Sets an attribute value.
2187 * @phba: pointer the the adapter structure.
2188 * @val: integer attribute value.
2191 * Validates the min and max values then sets the
2192 * adapter config field if in the valid range. prints error message
2193 * and does not set the parameter if invalid.
2197 * -EINVAL if val is invalid
2199 #define lpfc_param_set(attr, default, minval, maxval) \
2201 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2203 if (lpfc_rangecheck(val, minval, maxval)) {\
2204 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2205 "3052 lpfc_" #attr " changed from %d to %d\n", \
2206 phba->cfg_##attr, val); \
2207 phba->cfg_##attr = val;\
2210 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2211 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2212 "allowed range is ["#minval", "#maxval"]\n", val); \
2217 * lpfc_param_store - Set a vport attribute value
2220 * Macro that given an attr e.g. hba_queue_depth expands
2221 * into a function with the name lpfc_hba_queue_depth_store.
2223 * lpfc_##attr##_store: Set an sttribute value.
2224 * @dev: class device that is converted into a Scsi_host.
2225 * @attr: device attribute, not used.
2226 * @buf: contains the attribute value in ascii.
2230 * Convert the ascii text number to an integer, then
2231 * use the lpfc_##attr##_set function to set the value.
2234 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2235 * length of buffer upon success.
2237 #define lpfc_param_store(attr) \
2239 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2240 const char *buf, size_t count) \
2242 struct Scsi_Host *shost = class_to_shost(dev);\
2243 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2244 struct lpfc_hba *phba = vport->phba;\
2246 if (!isdigit(buf[0]))\
2248 if (sscanf(buf, "%i", &val) != 1)\
2250 if (lpfc_##attr##_set(phba, val) == 0) \
2251 return strlen(buf);\
2257 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2260 * Macro that given an attr e.g. hba_queue_depth expands
2261 * into a function with the name lpfc_hba_queue_depth_show
2263 * lpfc_##attr##_show: prints the attribute value in decimal.
2264 * @dev: class device that is converted into a Scsi_host.
2265 * @attr: device attribute, not used.
2266 * @buf: on return contains the attribute value in decimal.
2268 * Returns: length of formatted string.
2270 #define lpfc_vport_param_show(attr) \
2272 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2275 struct Scsi_Host *shost = class_to_shost(dev);\
2276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2277 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2281 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2284 * Macro that given an attr e.g.
2285 * hba_queue_depth expands into a function with the name
2286 * lpfc_hba_queue_depth_show
2288 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2289 * @dev: class device that is converted into a Scsi_host.
2290 * @attr: device attribute, not used.
2291 * @buf: on return contains the attribute value in hexadecimal.
2293 * Returns: length of formatted string.
2295 #define lpfc_vport_param_hex_show(attr) \
2297 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2300 struct Scsi_Host *shost = class_to_shost(dev);\
2301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2302 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2306 * lpfc_vport_param_init - Initialize a vport cfg attribute
2309 * Macro that given an attr e.g. hba_queue_depth expands
2310 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2311 * takes a default argument, a minimum and maximum argument.
2313 * lpfc_##attr##_init: validates the min and max values then sets the
2314 * adapter config field accordingly, or uses the default if out of range
2315 * and prints an error message.
2316 * @phba: pointer the the adapter structure.
2317 * @val: integer attribute value.
2321 * -EINVAL if default used
2323 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2325 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2327 if (lpfc_rangecheck(val, minval, maxval)) {\
2328 vport->cfg_##attr = val;\
2331 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2332 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2333 "allowed range is ["#minval", "#maxval"]\n", val); \
2334 vport->cfg_##attr = default;\
2339 * lpfc_vport_param_set - Set a vport cfg attribute
2342 * Macro that given an attr e.g. hba_queue_depth expands
2343 * into a function with the name lpfc_hba_queue_depth_set
2345 * lpfc_##attr##_set: validates the min and max values then sets the
2346 * adapter config field if in the valid range. prints error message
2347 * and does not set the parameter if invalid.
2348 * @phba: pointer the the adapter structure.
2349 * @val: integer attribute value.
2353 * -EINVAL if val is invalid
2355 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2357 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2359 if (lpfc_rangecheck(val, minval, maxval)) {\
2360 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2361 "3053 lpfc_" #attr \
2362 " changed from %d (x%x) to %d (x%x)\n", \
2363 vport->cfg_##attr, vport->cfg_##attr, \
2365 vport->cfg_##attr = val;\
2368 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2369 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2370 "allowed range is ["#minval", "#maxval"]\n", val); \
2375 * lpfc_vport_param_store - Set a vport attribute
2378 * Macro that given an attr e.g. hba_queue_depth
2379 * expands into a function with the name lpfc_hba_queue_depth_store
2381 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2382 * use the lpfc_##attr##_set function to set the value.
2383 * @cdev: class device that is converted into a Scsi_host.
2384 * @buf: contains the attribute value in decimal.
2388 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2389 * length of buffer upon success.
2391 #define lpfc_vport_param_store(attr) \
2393 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2394 const char *buf, size_t count) \
2396 struct Scsi_Host *shost = class_to_shost(dev);\
2397 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2399 if (!isdigit(buf[0]))\
2401 if (sscanf(buf, "%i", &val) != 1)\
2403 if (lpfc_##attr##_set(vport, val) == 0) \
2404 return strlen(buf);\
2410 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2411 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2412 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2413 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2414 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2415 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2416 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2417 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2418 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2419 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2420 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2421 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2422 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2423 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2424 lpfc_link_state_store);
2425 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2426 lpfc_option_rom_version_show, NULL);
2427 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2428 lpfc_num_discovered_ports_show, NULL);
2429 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2430 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2431 static DEVICE_ATTR_RO(lpfc_drvr_version);
2432 static DEVICE_ATTR_RO(lpfc_enable_fip);
2433 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2434 lpfc_board_mode_show, lpfc_board_mode_store);
2435 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2436 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2437 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2438 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2439 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2440 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2441 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2442 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2443 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2444 static DEVICE_ATTR_RO(lpfc_fips_level);
2445 static DEVICE_ATTR_RO(lpfc_fips_rev);
2446 static DEVICE_ATTR_RO(lpfc_dss);
2447 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2448 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2449 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2452 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2455 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2457 * @cnt: Length of string.
2458 * @wwn: Array to receive converted wwn value.
2461 * -EINVAL if the buffer does not contain a valid wwn
2465 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2469 /* Count may include a LF at end of string */
2470 if (buf[cnt-1] == '\n')
2473 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2474 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2477 memset(wwn, 0, WWN_SZ);
2479 /* Validate and store the new name */
2480 for (i = 0, j = 0; i < 16; i++) {
2481 if ((*buf >= 'a') && (*buf <= 'f'))
2482 j = ((j << 4) | ((*buf++ - 'a') + 10));
2483 else if ((*buf >= 'A') && (*buf <= 'F'))
2484 j = ((j << 4) | ((*buf++ - 'A') + 10));
2485 else if ((*buf >= '0') && (*buf <= '9'))
2486 j = ((j << 4) | (*buf++ - '0'));
2490 wwn[i/2] = j & 0xff;
2497 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2498 * @dev: class device that is converted into a Scsi_host.
2499 * @attr: device attribute, not used.
2500 * @buf: containing the string lpfc_soft_wwn_key.
2501 * @count: must be size of lpfc_soft_wwn_key.
2504 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2505 * length of buf indicates success
2508 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2509 const char *buf, size_t count)
2511 struct Scsi_Host *shost = class_to_shost(dev);
2512 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2513 struct lpfc_hba *phba = vport->phba;
2514 unsigned int cnt = count;
2515 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2516 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2519 * We're doing a simple sanity check for soft_wwpn setting.
2520 * We require that the user write a specific key to enable
2521 * the soft_wwpn attribute to be settable. Once the attribute
2522 * is written, the enable key resets. If further updates are
2523 * desired, the key must be written again to re-enable the
2526 * The "key" is not secret - it is a hardcoded string shown
2527 * here. The intent is to protect against the random user or
2528 * application that is just writing attributes.
2530 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2531 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2532 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2533 " be enabled: fawwpn is enabled\n");
2537 /* count may include a LF at end of string */
2538 if (buf[cnt-1] == '\n')
2541 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2542 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2545 phba->soft_wwn_enable = 1;
2547 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2548 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2550 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2551 " The soft_wwpn feature is not supported by Broadcom.");
2555 static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
2558 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2559 * @dev: class device that is converted into a Scsi_host.
2560 * @attr: device attribute, not used.
2561 * @buf: on return contains the wwpn in hexadecimal.
2563 * Returns: size of formatted string.
2566 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2569 struct Scsi_Host *shost = class_to_shost(dev);
2570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2571 struct lpfc_hba *phba = vport->phba;
2573 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2574 (unsigned long long)phba->cfg_soft_wwpn);
2578 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2579 * @dev class device that is converted into a Scsi_host.
2580 * @attr: device attribute, not used.
2581 * @buf: contains the wwpn in hexadecimal.
2582 * @count: number of wwpn bytes in buf
2585 * -EACCES hba reset not enabled, adapter over temp
2586 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2587 * -EIO error taking adapter offline or online
2588 * value of count on success
2591 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2592 const char *buf, size_t count)
2594 struct Scsi_Host *shost = class_to_shost(dev);
2595 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2596 struct lpfc_hba *phba = vport->phba;
2597 struct completion online_compl;
2598 int stat1 = 0, stat2 = 0;
2599 unsigned int cnt = count;
2603 if (!phba->cfg_enable_hba_reset)
2605 spin_lock_irq(&phba->hbalock);
2606 if (phba->over_temp_state == HBA_OVER_TEMP) {
2607 spin_unlock_irq(&phba->hbalock);
2610 spin_unlock_irq(&phba->hbalock);
2611 /* count may include a LF at end of string */
2612 if (buf[cnt-1] == '\n')
2615 if (!phba->soft_wwn_enable)
2618 /* lock setting wwpn, wwnn down */
2619 phba->soft_wwn_enable = 0;
2621 rc = lpfc_wwn_set(buf, cnt, wwpn);
2623 /* not able to set wwpn, unlock it */
2624 phba->soft_wwn_enable = 1;
2628 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2629 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2630 if (phba->cfg_soft_wwnn)
2631 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2633 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2634 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2636 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2638 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2639 "0463 lpfc_soft_wwpn attribute set failed to "
2640 "reinit adapter - %d\n", stat1);
2641 init_completion(&online_compl);
2642 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2647 wait_for_completion(&online_compl);
2649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2650 "0464 lpfc_soft_wwpn attribute set failed to "
2651 "reinit adapter - %d\n", stat2);
2652 return (stat1 || stat2) ? -EIO : count;
2654 static DEVICE_ATTR_RW(lpfc_soft_wwpn);
2657 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2658 * @dev: class device that is converted into a Scsi_host.
2659 * @attr: device attribute, not used.
2660 * @buf: on return contains the wwnn in hexadecimal.
2662 * Returns: size of formatted string.
2665 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2668 struct Scsi_Host *shost = class_to_shost(dev);
2669 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2670 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2671 (unsigned long long)phba->cfg_soft_wwnn);
2675 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2676 * @cdev: class device that is converted into a Scsi_host.
2677 * @buf: contains the ww node name in hexadecimal.
2678 * @count: number of wwnn bytes in buf.
2681 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2682 * value of count on success
2685 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2686 const char *buf, size_t count)
2688 struct Scsi_Host *shost = class_to_shost(dev);
2689 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2690 unsigned int cnt = count;
2694 /* count may include a LF at end of string */
2695 if (buf[cnt-1] == '\n')
2698 if (!phba->soft_wwn_enable)
2701 rc = lpfc_wwn_set(buf, cnt, wwnn);
2703 /* Allow wwnn to be set many times, as long as the enable
2704 * is set. However, once the wwpn is set, everything locks.
2709 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2711 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2712 "lpfc%d: soft_wwnn set. Value will take effect upon "
2713 "setting of the soft_wwpn\n", phba->brd_no);
2717 static DEVICE_ATTR_RW(lpfc_soft_wwnn);
2720 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2721 * Optimized Access Storage (OAS) operations.
2722 * @dev: class device that is converted into a Scsi_host.
2723 * @attr: device attribute, not used.
2724 * @buf: buffer for passing information.
2730 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2733 struct Scsi_Host *shost = class_to_shost(dev);
2734 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2736 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2737 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2741 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2742 * Optimized Access Storage (OAS) operations.
2743 * @dev: class device that is converted into a Scsi_host.
2744 * @attr: device attribute, not used.
2745 * @buf: buffer for passing information.
2746 * @count: Size of the data buffer.
2749 * -EINVAL count is invalid, invalid wwpn byte invalid
2750 * -EPERM oas is not supported by hba
2751 * value of count on success
2754 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2755 const char *buf, size_t count)
2757 struct Scsi_Host *shost = class_to_shost(dev);
2758 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2759 unsigned int cnt = count;
2760 uint8_t wwpn[WWN_SZ];
2766 /* count may include a LF at end of string */
2767 if (buf[cnt-1] == '\n')
2770 rc = lpfc_wwn_set(buf, cnt, wwpn);
2774 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2775 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2776 if (wwn_to_u64(wwpn) == 0)
2777 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2779 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2780 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2781 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2784 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2785 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2788 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2789 * Optimized Access Storage (OAS) operations.
2790 * @dev: class device that is converted into a Scsi_host.
2791 * @attr: device attribute, not used.
2792 * @buf: buffer for passing information.
2798 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2801 struct Scsi_Host *shost = class_to_shost(dev);
2802 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2804 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2808 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2809 * Optimized Access Storage (OAS) operations.
2810 * @dev: class device that is converted into a Scsi_host.
2811 * @attr: device attribute, not used.
2812 * @buf: buffer for passing information.
2813 * @count: Size of the data buffer.
2816 * -EINVAL count is invalid, invalid wwpn byte invalid
2817 * -EPERM oas is not supported by hba
2818 * value of count on success
2821 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2822 const char *buf, size_t count)
2824 struct Scsi_Host *shost = class_to_shost(dev);
2825 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2826 unsigned int cnt = count;
2833 /* count may include a LF at end of string */
2834 if (buf[cnt-1] == '\n')
2837 ret = kstrtoul(buf, 0, &val);
2838 if (ret || (val > 0x7f))
2842 phba->cfg_oas_priority = (uint8_t)val;
2844 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2847 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2848 lpfc_oas_priority_show, lpfc_oas_priority_store);
2851 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2852 * for Optimized Access Storage (OAS) operations.
2853 * @dev: class device that is converted into a Scsi_host.
2854 * @attr: device attribute, not used.
2855 * @buf: buffer for passing information.
2858 * value of count on success
2861 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2864 struct Scsi_Host *shost = class_to_shost(dev);
2865 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2867 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2868 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2872 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2873 * for Optimized Access Storage (OAS) operations.
2874 * @dev: class device that is converted into a Scsi_host.
2875 * @attr: device attribute, not used.
2876 * @buf: buffer for passing information.
2877 * @count: Size of the data buffer.
2880 * -EINVAL count is invalid, invalid wwpn byte invalid
2881 * -EPERM oas is not supported by hba
2882 * value of count on success
2885 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2886 const char *buf, size_t count)
2888 struct Scsi_Host *shost = class_to_shost(dev);
2889 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2890 unsigned int cnt = count;
2891 uint8_t wwpn[WWN_SZ];
2897 /* count may include a LF at end of string */
2898 if (buf[cnt-1] == '\n')
2901 rc = lpfc_wwn_set(buf, cnt, wwpn);
2905 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2906 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2907 if (wwn_to_u64(wwpn) == 0)
2908 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2910 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2911 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2912 if (phba->cfg_oas_priority == 0)
2913 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2914 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2917 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2918 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2921 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2922 * of whether luns will be enabled or disabled
2923 * for Optimized Access Storage (OAS) operations.
2924 * @dev: class device that is converted into a Scsi_host.
2925 * @attr: device attribute, not used.
2926 * @buf: buffer for passing information.
2929 * size of formatted string.
2932 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2935 struct Scsi_Host *shost = class_to_shost(dev);
2936 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2938 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2942 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2943 * of whether luns will be enabled or disabled
2944 * for Optimized Access Storage (OAS) operations.
2945 * @dev: class device that is converted into a Scsi_host.
2946 * @attr: device attribute, not used.
2947 * @buf: buffer for passing information.
2948 * @count: Size of the data buffer.
2951 * -EINVAL count is invalid, invalid wwpn byte invalid
2952 * -EPERM oas is not supported by hba
2953 * value of count on success
2956 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2957 const char *buf, size_t count)
2959 struct Scsi_Host *shost = class_to_shost(dev);
2960 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2966 if (!isdigit(buf[0]))
2969 if (sscanf(buf, "%i", &val) != 1)
2972 if ((val != 0) && (val != 1))
2975 phba->cfg_oas_lun_state = val;
2978 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2979 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2982 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2983 * Storage (OAS) lun returned by the
2984 * lpfc_oas_lun_show function.
2985 * @dev: class device that is converted into a Scsi_host.
2986 * @attr: device attribute, not used.
2987 * @buf: buffer for passing information.
2990 * size of formatted string.
2993 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2996 struct Scsi_Host *shost = class_to_shost(dev);
2997 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2999 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3002 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3004 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3005 lpfc_oas_lun_status_show, NULL);
3009 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3011 * @phba: lpfc_hba pointer.
3012 * @ndlp: pointer to fcp target node.
3013 * @lun: the fc lun for setting oas state.
3014 * @oas_state: the oas state to be set to the lun.
3018 * -EPERM OAS is not enabled or not supported by this port.
3022 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3023 uint8_t tgt_wwpn[], uint64_t lun,
3024 uint32_t oas_state, uint8_t pri)
3033 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3034 (struct lpfc_name *)tgt_wwpn,
3038 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3039 (struct lpfc_name *)tgt_wwpn, lun, pri);
3046 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3047 * Access Storage (OAS) operations.
3048 * @phba: lpfc_hba pointer.
3049 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3050 * @tgt_wwpn: wwpn of the target associated with the returned lun
3051 * @lun_status: status of the lun returned lun
3053 * Returns the first or next lun enabled for OAS operations for the vport/target
3054 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3055 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3058 * lun that is OAS enabled for the vport/target
3059 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3062 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3063 uint8_t tgt_wwpn[], uint32_t *lun_status,
3068 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3069 return NOT_OAS_ENABLED_LUN;
3070 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3071 phba->sli4_hba.oas_next_vpt_wwpn,
3072 (struct lpfc_name *)
3073 phba->sli4_hba.oas_next_tgt_wwpn,
3074 &phba->sli4_hba.oas_next_lun,
3075 (struct lpfc_name *)vpt_wwpn,
3076 (struct lpfc_name *)tgt_wwpn,
3077 &found_lun, lun_status, lun_pri))
3080 return NOT_OAS_ENABLED_LUN;
3084 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3085 * @phba: lpfc_hba pointer.
3086 * @vpt_wwpn: vport wwpn by reference.
3087 * @tgt_wwpn: target wwpn by reference.
3088 * @lun: the fc lun for setting oas state.
3089 * @oas_state: the oas state to be set to the oas_lun.
3091 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3092 * a lun for OAS operations.
3096 * -ENOMEM: failed to enable an lun for OAS operations
3097 * -EPERM: OAS is not enabled
3100 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3101 uint8_t tgt_wwpn[], uint64_t lun,
3102 uint32_t oas_state, uint8_t pri)
3107 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3113 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3114 * @dev: class device that is converted into a Scsi_host.
3115 * @attr: device attribute, not used.
3116 * @buf: buffer for passing information.
3118 * This routine returns a lun enabled for OAS each time the function
3122 * SUCCESS: size of formatted string.
3123 * -EFAULT: target or vport wwpn was not set properly.
3124 * -EPERM: oas is not enabled.
3127 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3130 struct Scsi_Host *shost = class_to_shost(dev);
3131 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3139 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3140 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3143 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3144 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3147 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3148 phba->cfg_oas_tgt_wwpn,
3149 &phba->cfg_oas_lun_status,
3150 &phba->cfg_oas_priority);
3151 if (oas_lun != NOT_OAS_ENABLED_LUN)
3152 phba->cfg_oas_flags |= OAS_LUN_VALID;
3154 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3160 * lpfc_oas_lun_store - Sets the OAS state for lun
3161 * @dev: class device that is converted into a Scsi_host.
3162 * @attr: device attribute, not used.
3163 * @buf: buffer for passing information.
3165 * This function sets the OAS state for lun. Before this function is called,
3166 * the vport wwpn, target wwpn, and oas state need to be set.
3169 * SUCCESS: size of formatted string.
3170 * -EFAULT: target or vport wwpn was not set properly.
3171 * -EPERM: oas is not enabled.
3172 * size of formatted string.
3175 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3176 const char *buf, size_t count)
3178 struct Scsi_Host *shost = class_to_shost(dev);
3179 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3187 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3190 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3193 if (!isdigit(buf[0]))
3196 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3199 pri = phba->cfg_oas_priority;
3201 pri = phba->cfg_XLanePriority;
3203 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3204 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3205 "priority 0x%x with oas state %d\n",
3206 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3207 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3208 pri, phba->cfg_oas_lun_state);
3210 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3211 phba->cfg_oas_tgt_wwpn, scsi_lun,
3212 phba->cfg_oas_lun_state, pri);
3218 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3219 lpfc_oas_lun_show, lpfc_oas_lun_store);
3221 int lpfc_enable_nvmet_cnt;
3222 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3223 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3224 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3225 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3226 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3228 static int lpfc_poll = 0;
3229 module_param(lpfc_poll, int, S_IRUGO);
3230 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3232 " 1 - poll with interrupts enabled"
3233 " 3 - poll and disable FCP ring interrupts");
3235 static DEVICE_ATTR_RW(lpfc_poll);
3237 int lpfc_no_hba_reset_cnt;
3238 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3240 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3241 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3243 LPFC_ATTR(sli_mode, 0, 0, 3,
3244 "SLI mode selector:"
3245 " 0 - auto (SLI-3 if supported),"
3246 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3247 " 3 - select SLI-3");
3249 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3250 "Enable NPIV functionality");
3252 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3253 "FCF Fast failover=1 Priority failover=2");
3256 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3257 # 0x0 = disabled, XRI/OXID use not tracked.
3258 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3259 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3261 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3262 "Enable RRQ functionality");
3265 # lpfc_suppress_link_up: Bring link up at initialization
3266 # 0x0 = bring link up (issue MBX_INIT_LINK)
3267 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3268 # 0x2 = never bring up link
3269 # Default value is 0.
3271 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3272 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3273 "Suppress Link Up at initialization");
3275 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3283 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3285 struct Scsi_Host *shost = class_to_shost(dev);
3286 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3288 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3291 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3292 lpfc_iocb_hw_show, NULL);
3294 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3296 struct Scsi_Host *shost = class_to_shost(dev);
3297 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3298 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3300 return scnprintf(buf, PAGE_SIZE, "%d\n",
3301 pring ? pring->txq_max : 0);
3304 static DEVICE_ATTR(txq_hw, S_IRUGO,
3305 lpfc_txq_hw_show, NULL);
3307 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3310 struct Scsi_Host *shost = class_to_shost(dev);
3311 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3312 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3314 return scnprintf(buf, PAGE_SIZE, "%d\n",
3315 pring ? pring->txcmplq_max : 0);
3318 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3319 lpfc_txcmplq_hw_show, NULL);
3321 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3322 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3325 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3326 # until the timer expires. Value range is [0,255]. Default value is 30.
3328 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3329 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3330 module_param(lpfc_nodev_tmo, int, 0);
3331 MODULE_PARM_DESC(lpfc_nodev_tmo,
3332 "Seconds driver will hold I/O waiting "
3333 "for a device to come back");
3336 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3337 * @dev: class converted to a Scsi_host structure.
3338 * @attr: device attribute, not used.
3339 * @buf: on return contains the dev loss timeout in decimal.
3341 * Returns: size of formatted string.
3344 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3347 struct Scsi_Host *shost = class_to_shost(dev);
3348 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3350 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3354 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3355 * @vport: lpfc vport structure pointer.
3356 * @val: contains the nodev timeout value.
3359 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3360 * a kernel error message is printed and zero is returned.
3361 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3362 * Otherwise nodev tmo is set to the default value.
3365 * zero if already set or if val is in range
3366 * -EINVAL val out of range
3369 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3371 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3372 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3373 if (val != LPFC_DEF_DEVLOSS_TMO)
3374 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3375 "0407 Ignoring lpfc_nodev_tmo module "
3376 "parameter because lpfc_devloss_tmo "
3381 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3382 vport->cfg_nodev_tmo = val;
3383 vport->cfg_devloss_tmo = val;
3386 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3387 "0400 lpfc_nodev_tmo attribute cannot be set to"
3388 " %d, allowed range is [%d, %d]\n",
3389 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3390 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3395 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3396 * @vport: lpfc vport structure pointer.
3399 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3402 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3404 struct Scsi_Host *shost;
3405 struct lpfc_nodelist *ndlp;
3406 #if (IS_ENABLED(CONFIG_NVME_FC))
3407 struct lpfc_nvme_rport *rport;
3408 struct nvme_fc_remote_port *remoteport = NULL;
3411 shost = lpfc_shost_from_vport(vport);
3412 spin_lock_irq(shost->host_lock);
3413 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3414 if (!NLP_CHK_NODE_ACT(ndlp))
3417 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3418 #if (IS_ENABLED(CONFIG_NVME_FC))
3419 spin_lock(&vport->phba->hbalock);
3420 rport = lpfc_ndlp_get_nrport(ndlp);
3422 remoteport = rport->remoteport;
3423 spin_unlock(&vport->phba->hbalock);
3425 nvme_fc_set_remoteport_devloss(rport->remoteport,
3426 vport->cfg_devloss_tmo);
3429 spin_unlock_irq(shost->host_lock);
3433 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3434 * @vport: lpfc vport structure pointer.
3435 * @val: contains the tmo value.
3438 * If the devloss tmo is already set or the vport dev loss tmo has changed
3439 * then a kernel error message is printed and zero is returned.
3440 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3441 * Otherwise nodev tmo is set to the default value.
3444 * zero if already set or if val is in range
3445 * -EINVAL val out of range
3448 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3450 if (vport->dev_loss_tmo_changed ||
3451 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3452 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3453 "0401 Ignoring change to lpfc_nodev_tmo "
3454 "because lpfc_devloss_tmo is set.\n");
3457 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3458 vport->cfg_nodev_tmo = val;
3459 vport->cfg_devloss_tmo = val;
3461 * For compat: set the fc_host dev loss so new rports
3462 * will get the value.
3464 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3465 lpfc_update_rport_devloss_tmo(vport);
3468 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3469 "0403 lpfc_nodev_tmo attribute cannot be set to "
3470 "%d, allowed range is [%d, %d]\n",
3471 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3475 lpfc_vport_param_store(nodev_tmo)
3477 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3480 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3481 # disappear until the timer expires. Value range is [0,255]. Default
3484 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3485 MODULE_PARM_DESC(lpfc_devloss_tmo,
3486 "Seconds driver will hold I/O waiting "
3487 "for a device to come back");
3488 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3489 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3490 lpfc_vport_param_show(devloss_tmo)
3493 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3494 * @vport: lpfc vport structure pointer.
3495 * @val: contains the tmo value.
3498 * If val is in a valid range then set the vport nodev tmo,
3499 * devloss tmo, also set the vport dev loss tmo changed flag.
3500 * Else a kernel error message is printed.
3503 * zero if val is in range
3504 * -EINVAL val out of range
3507 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3509 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3510 vport->cfg_nodev_tmo = val;
3511 vport->cfg_devloss_tmo = val;
3512 vport->dev_loss_tmo_changed = 1;
3513 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3514 lpfc_update_rport_devloss_tmo(vport);
3518 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3519 "0404 lpfc_devloss_tmo attribute cannot be set to "
3520 "%d, allowed range is [%d, %d]\n",
3521 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3525 lpfc_vport_param_store(devloss_tmo)
3526 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3529 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3530 * lpfc_suppress_rsp = 0 Disable
3531 * lpfc_suppress_rsp = 1 Enable (default)
3534 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3535 "Enable suppress rsp feature is firmware supports it");
3538 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3539 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3540 * lpfc_nvmet_mrq = 1 use a single RQ pair
3541 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3544 LPFC_ATTR_R(nvmet_mrq,
3545 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3546 "Specify number of RQ pairs for processing NVMET cmds");
3549 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3550 * to each NVMET RQ. Range 64 to 2048, default is 512.
3552 LPFC_ATTR_R(nvmet_mrq_post,
3553 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3554 LPFC_NVMET_RQE_DEF_COUNT,
3555 "Specify number of RQ buffers to initially post");
3558 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3559 * Supported Values: 1 - register just FCP
3560 * 3 - register both FCP and NVME
3561 * Supported values are [1,3]. Default value is 1
3563 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3564 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3565 "Enable FC4 Protocol support - FCP / NVME");
3568 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3569 * This parameter is only used if:
3570 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3571 * port is not configured for NVMET.
3573 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3574 * The remaining XRIs get split up based on lpfc_xri_split per port:
3576 * Supported Values are in percentages
3577 * the xri_split value is the percentage the SCSI port will get. The remaining
3578 * percentage will go to NVME.
3580 LPFC_ATTR_R(xri_split, 50, 10, 90,
3581 "Percentage of FCP XRI resources versus NVME");
3584 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3585 # deluged with LOTS of information.
3586 # You can set a bit mask to record specific types of verbose messages:
3587 # See lpfc_logmsh.h for definitions.
3589 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3590 "Verbose logging bit-mask");
3593 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3594 # objects that have been registered with the nameserver after login.
3596 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3597 "Deregister nameserver objects before LOGO");
3600 # lun_queue_depth: This parameter is used to limit the number of outstanding
3601 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3602 # If this parameter value is greater than 1/8th the maximum number of exchanges
3603 # supported by the HBA port, then the lun queue depth will be reduced to
3604 # 1/8th the maximum number of exchanges.
3606 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3607 "Max number of FCP commands we can queue to a specific LUN");
3610 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3611 # commands per target port. Value range is [10,65535]. Default value is 65535.
3613 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3614 module_param(lpfc_tgt_queue_depth, uint, 0444);
3615 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3616 lpfc_vport_param_show(tgt_queue_depth);
3617 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3618 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3621 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3622 * @phba: pointer the the adapter structure.
3623 * @val: integer attribute value.
3625 * Description: Sets the parameter to the new value.
3629 * -EINVAL if val is invalid
3632 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3634 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3635 struct lpfc_nodelist *ndlp;
3637 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3640 if (val == vport->cfg_tgt_queue_depth)
3643 spin_lock_irq(shost->host_lock);
3644 vport->cfg_tgt_queue_depth = val;
3646 /* Next loop thru nodelist and change cmd_qdepth */
3647 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3648 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3650 spin_unlock_irq(shost->host_lock);
3654 lpfc_vport_param_store(tgt_queue_depth);
3655 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3658 # hba_queue_depth: This parameter is used to limit the number of outstanding
3659 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3660 # value is greater than the maximum number of exchanges supported by the HBA,
3661 # then maximum number of exchanges supported by the HBA is used to determine
3662 # the hba_queue_depth.
3664 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3665 "Max number of FCP commands we can queue to a lpfc HBA");
3668 # peer_port_login: This parameter allows/prevents logins
3669 # between peer ports hosted on the same physical port.
3670 # When this parameter is set 0 peer ports of same physical port
3671 # are not allowed to login to each other.
3672 # When this parameter is set 1 peer ports of same physical port
3673 # are allowed to login to each other.
3674 # Default value of this parameter is 0.
3676 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3677 "Allow peer ports on the same physical port to login to each "
3681 # restrict_login: This parameter allows/prevents logins
3682 # between Virtual Ports and remote initiators.
3683 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3684 # other initiators and will attempt to PLOGI all remote ports.
3685 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3686 # remote ports and will not attempt to PLOGI to other initiators.
3687 # This parameter does not restrict to the physical port.
3688 # This parameter does not restrict logins to Fabric resident remote ports.
3689 # Default value of this parameter is 1.
3691 static int lpfc_restrict_login = 1;
3692 module_param(lpfc_restrict_login, int, S_IRUGO);
3693 MODULE_PARM_DESC(lpfc_restrict_login,
3694 "Restrict virtual ports login to remote initiators.");
3695 lpfc_vport_param_show(restrict_login);
3698 * lpfc_restrict_login_init - Set the vport restrict login flag
3699 * @vport: lpfc vport structure pointer.
3700 * @val: contains the restrict login value.
3703 * If val is not in a valid range then log a kernel error message and set
3704 * the vport restrict login to one.
3705 * If the port type is physical clear the restrict login flag and return.
3706 * Else set the restrict login flag to val.
3709 * zero if val is in range
3710 * -EINVAL val out of range
3713 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3715 if (val < 0 || val > 1) {
3716 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3717 "0422 lpfc_restrict_login attribute cannot "
3718 "be set to %d, allowed range is [0, 1]\n",
3720 vport->cfg_restrict_login = 1;
3723 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3724 vport->cfg_restrict_login = 0;
3727 vport->cfg_restrict_login = val;
3732 * lpfc_restrict_login_set - Set the vport restrict login flag
3733 * @vport: lpfc vport structure pointer.
3734 * @val: contains the restrict login value.
3737 * If val is not in a valid range then log a kernel error message and set
3738 * the vport restrict login to one.
3739 * If the port type is physical and the val is not zero log a kernel
3740 * error message, clear the restrict login flag and return zero.
3741 * Else set the restrict login flag to val.
3744 * zero if val is in range
3745 * -EINVAL val out of range
3748 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3750 if (val < 0 || val > 1) {
3751 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3752 "0425 lpfc_restrict_login attribute cannot "
3753 "be set to %d, allowed range is [0, 1]\n",
3755 vport->cfg_restrict_login = 1;
3758 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3759 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3760 "0468 lpfc_restrict_login must be 0 for "
3761 "Physical ports.\n");
3762 vport->cfg_restrict_login = 0;
3765 vport->cfg_restrict_login = val;
3768 lpfc_vport_param_store(restrict_login);
3769 static DEVICE_ATTR_RW(lpfc_restrict_login);
3772 # Some disk devices have a "select ID" or "select Target" capability.
3773 # From a protocol standpoint "select ID" usually means select the
3774 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3775 # annex" which contains a table that maps a "select ID" (a number
3776 # between 0 and 7F) to an ALPA. By default, for compatibility with
3777 # older drivers, the lpfc driver scans this table from low ALPA to high
3780 # Turning on the scan-down variable (on = 1, off = 0) will
3781 # cause the lpfc driver to use an inverted table, effectively
3782 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3784 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3785 # and will not work across a fabric. Also this parameter will take
3786 # effect only in the case when ALPA map is not available.)
3788 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3789 "Start scanning for devices from highest ALPA to lowest");
3792 # lpfc_topology: link topology for init link
3793 # 0x0 = attempt loop mode then point-to-point
3794 # 0x01 = internal loopback mode
3795 # 0x02 = attempt point-to-point mode only
3796 # 0x04 = attempt loop mode only
3797 # 0x06 = attempt point-to-point mode then loop
3798 # Set point-to-point mode if you want to run as an N_Port.
3799 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3800 # Default value is 0.
3802 LPFC_ATTR(topology, 0, 0, 6,
3803 "Select Fibre Channel topology");
3806 * lpfc_topology_set - Set the adapters topology field
3807 * @phba: lpfc_hba pointer.
3808 * @val: topology value.
3811 * If val is in a valid range then set the adapter's topology field and
3812 * issue a lip; if the lip fails reset the topology to the old value.
3814 * If the value is not in range log a kernel error message and return an error.
3817 * zero if val is in range and lip okay
3818 * non-zero return value from lpfc_issue_lip()
3819 * -EINVAL val out of range
3822 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3823 const char *buf, size_t count)
3825 struct Scsi_Host *shost = class_to_shost(dev);
3826 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3827 struct lpfc_hba *phba = vport->phba;
3830 const char *val_buf = buf;
3834 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3836 val_buf = &buf[strlen("nolip ")];
3839 if (!isdigit(val_buf[0]))
3841 if (sscanf(val_buf, "%i", &val) != 1)
3844 if (val >= 0 && val <= 6) {
3845 prev_val = phba->cfg_topology;
3846 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3848 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3849 "3113 Loop mode not supported at speed %d\n",
3853 if ((phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
3854 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC) &&
3856 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3857 "3114 Loop mode not supported\n");
3860 phba->cfg_topology = val;
3864 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3865 "3054 lpfc_topology changed from %d to %d\n",
3867 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3868 phba->fc_topology_changed = 1;
3869 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3871 phba->cfg_topology = prev_val;
3876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3877 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3878 "allowed range is [0, 6]\n",
3883 lpfc_param_show(topology)
3884 static DEVICE_ATTR_RW(lpfc_topology);
3887 * lpfc_static_vport_show: Read callback function for
3888 * lpfc_static_vport sysfs file.
3889 * @dev: Pointer to class device object.
3890 * @attr: device attribute structure.
3891 * @buf: Data buffer.
3893 * This function is the read call back function for
3894 * lpfc_static_vport sysfs file. The lpfc_static_vport
3895 * sysfs file report the mageability of the vport.
3898 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3901 struct Scsi_Host *shost = class_to_shost(dev);
3902 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3903 if (vport->vport_flag & STATIC_VPORT)
3904 sprintf(buf, "1\n");
3906 sprintf(buf, "0\n");
3912 * Sysfs attribute to control the statistical data collection.
3914 static DEVICE_ATTR_RO(lpfc_static_vport);
3917 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3918 * @dev: Pointer to class device.
3919 * @buf: Data buffer.
3920 * @count: Size of the data buffer.
3922 * This function get called when a user write to the lpfc_stat_data_ctrl
3923 * sysfs file. This function parse the command written to the sysfs file
3924 * and take appropriate action. These commands are used for controlling
3925 * driver statistical data collection.
3926 * Following are the command this function handles.
3928 * setbucket <bucket_type> <base> <step>
3929 * = Set the latency buckets.
3930 * destroybucket = destroy all the buckets.
3931 * start = start data collection
3932 * stop = stop data collection
3933 * reset = reset the collected data
3936 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3937 const char *buf, size_t count)
3939 struct Scsi_Host *shost = class_to_shost(dev);
3940 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3941 struct lpfc_hba *phba = vport->phba;
3942 #define LPFC_MAX_DATA_CTRL_LEN 1024
3943 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3945 char *str_ptr, *token;
3946 struct lpfc_vport **vports;
3947 struct Scsi_Host *v_shost;
3948 char *bucket_type_str, *base_str, *step_str;
3949 unsigned long base, step, bucket_type;
3951 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3952 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3955 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3956 str_ptr = &bucket_data[0];
3957 /* Ignore this token - this is command token */
3958 token = strsep(&str_ptr, "\t ");
3962 bucket_type_str = strsep(&str_ptr, "\t ");
3963 if (!bucket_type_str)
3966 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3967 bucket_type = LPFC_LINEAR_BUCKET;
3968 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3969 bucket_type = LPFC_POWER2_BUCKET;
3973 base_str = strsep(&str_ptr, "\t ");
3976 base = simple_strtoul(base_str, NULL, 0);
3978 step_str = strsep(&str_ptr, "\t ");
3981 step = simple_strtoul(step_str, NULL, 0);
3985 /* Block the data collection for every vport */
3986 vports = lpfc_create_vport_work_array(phba);
3990 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3991 v_shost = lpfc_shost_from_vport(vports[i]);
3992 spin_lock_irq(v_shost->host_lock);
3993 /* Block and reset data collection */
3994 vports[i]->stat_data_blocked = 1;
3995 if (vports[i]->stat_data_enabled)
3996 lpfc_vport_reset_stat_data(vports[i]);
3997 spin_unlock_irq(v_shost->host_lock);
4000 /* Set the bucket attributes */
4001 phba->bucket_type = bucket_type;
4002 phba->bucket_base = base;
4003 phba->bucket_step = step;
4005 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4006 v_shost = lpfc_shost_from_vport(vports[i]);
4008 /* Unblock data collection */
4009 spin_lock_irq(v_shost->host_lock);
4010 vports[i]->stat_data_blocked = 0;
4011 spin_unlock_irq(v_shost->host_lock);
4013 lpfc_destroy_vport_work_array(phba, vports);
4017 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4018 vports = lpfc_create_vport_work_array(phba);
4022 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4023 v_shost = lpfc_shost_from_vport(vports[i]);
4024 spin_lock_irq(shost->host_lock);
4025 vports[i]->stat_data_blocked = 1;
4026 lpfc_free_bucket(vport);
4027 vport->stat_data_enabled = 0;
4028 vports[i]->stat_data_blocked = 0;
4029 spin_unlock_irq(shost->host_lock);
4031 lpfc_destroy_vport_work_array(phba, vports);
4032 phba->bucket_type = LPFC_NO_BUCKET;
4033 phba->bucket_base = 0;
4034 phba->bucket_step = 0;
4038 if (!strncmp(buf, "start", strlen("start"))) {
4039 /* If no buckets configured return error */
4040 if (phba->bucket_type == LPFC_NO_BUCKET)
4042 spin_lock_irq(shost->host_lock);
4043 if (vport->stat_data_enabled) {
4044 spin_unlock_irq(shost->host_lock);
4047 lpfc_alloc_bucket(vport);
4048 vport->stat_data_enabled = 1;
4049 spin_unlock_irq(shost->host_lock);
4053 if (!strncmp(buf, "stop", strlen("stop"))) {
4054 spin_lock_irq(shost->host_lock);
4055 if (vport->stat_data_enabled == 0) {
4056 spin_unlock_irq(shost->host_lock);
4059 lpfc_free_bucket(vport);
4060 vport->stat_data_enabled = 0;
4061 spin_unlock_irq(shost->host_lock);
4065 if (!strncmp(buf, "reset", strlen("reset"))) {
4066 if ((phba->bucket_type == LPFC_NO_BUCKET)
4067 || !vport->stat_data_enabled)
4069 spin_lock_irq(shost->host_lock);
4070 vport->stat_data_blocked = 1;
4071 lpfc_vport_reset_stat_data(vport);
4072 vport->stat_data_blocked = 0;
4073 spin_unlock_irq(shost->host_lock);
4081 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
4082 * @dev: Pointer to class device object.
4083 * @buf: Data buffer.
4085 * This function is the read call back function for
4086 * lpfc_stat_data_ctrl sysfs file. This function report the
4087 * current statistical data collection state.
4090 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4093 struct Scsi_Host *shost = class_to_shost(dev);
4094 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4095 struct lpfc_hba *phba = vport->phba;
4099 unsigned long bucket_value;
4101 switch (phba->bucket_type) {
4102 case LPFC_LINEAR_BUCKET:
4103 bucket_type = "linear";
4105 case LPFC_POWER2_BUCKET:
4106 bucket_type = "power2";
4109 bucket_type = "No Bucket";
4113 sprintf(&buf[index], "Statistical Data enabled :%d, "
4114 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4115 " Bucket step :%d\nLatency Ranges :",
4116 vport->stat_data_enabled, vport->stat_data_blocked,
4117 bucket_type, phba->bucket_base, phba->bucket_step);
4118 index = strlen(buf);
4119 if (phba->bucket_type != LPFC_NO_BUCKET) {
4120 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4121 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4122 bucket_value = phba->bucket_base +
4123 phba->bucket_step * i;
4125 bucket_value = phba->bucket_base +
4126 (1 << i) * phba->bucket_step;
4128 if (index + 10 > PAGE_SIZE)
4130 sprintf(&buf[index], "%08ld ", bucket_value);
4131 index = strlen(buf);
4134 sprintf(&buf[index], "\n");
4139 * Sysfs attribute to control the statistical data collection.
4141 static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
4144 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4148 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4151 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4152 #define MAX_STAT_DATA_SIZE_PER_TARGET \
4153 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4157 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
4159 * @kobj: Pointer to the kernel object
4160 * @bin_attr: Attribute object
4161 * @buff: Buffer pointer
4163 * @count: Buffer size
4165 * This function is the read call back function for lpfc_drvr_stat_data
4166 * sysfs file. This function export the statistical data to user
4170 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
4171 struct bin_attribute *bin_attr,
4172 char *buf, loff_t off, size_t count)
4174 struct device *dev = container_of(kobj, struct device,
4176 struct Scsi_Host *shost = class_to_shost(dev);
4177 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4178 struct lpfc_hba *phba = vport->phba;
4179 int i = 0, index = 0;
4180 unsigned long nport_index;
4181 struct lpfc_nodelist *ndlp = NULL;
4182 nport_index = (unsigned long)off /
4183 MAX_STAT_DATA_SIZE_PER_TARGET;
4185 if (!vport->stat_data_enabled || vport->stat_data_blocked
4186 || (phba->bucket_type == LPFC_NO_BUCKET))
4189 spin_lock_irq(shost->host_lock);
4190 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4191 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4194 if (nport_index > 0) {
4199 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4203 if (!ndlp->lat_data)
4207 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4208 ndlp->nlp_portname.u.wwn[0],
4209 ndlp->nlp_portname.u.wwn[1],
4210 ndlp->nlp_portname.u.wwn[2],
4211 ndlp->nlp_portname.u.wwn[3],
4212 ndlp->nlp_portname.u.wwn[4],
4213 ndlp->nlp_portname.u.wwn[5],
4214 ndlp->nlp_portname.u.wwn[6],
4215 ndlp->nlp_portname.u.wwn[7]);
4217 index = strlen(buf);
4219 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4220 sprintf(&buf[index], "%010u,",
4221 ndlp->lat_data[i].cmd_count);
4222 index = strlen(buf);
4224 sprintf(&buf[index], "\n");
4225 index = strlen(buf);
4227 spin_unlock_irq(shost->host_lock);
4231 static struct bin_attribute sysfs_drvr_stat_data_attr = {
4233 .name = "lpfc_drvr_stat_data",
4236 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4237 .read = sysfs_drvr_stat_data_read,
4242 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4244 # Value range is [0,16]. Default value is 0.
4247 * lpfc_link_speed_set - Set the adapters link speed
4248 * @phba: lpfc_hba pointer.
4249 * @val: link speed value.
4252 * If val is in a valid range then set the adapter's link speed field and
4253 * issue a lip; if the lip fails reset the link speed to the old value.
4256 * If the value is not in range log a kernel error message and return an error.
4259 * zero if val is in range and lip okay.
4260 * non-zero return value from lpfc_issue_lip()
4261 * -EINVAL val out of range
4264 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4265 const char *buf, size_t count)
4267 struct Scsi_Host *shost = class_to_shost(dev);
4268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4269 struct lpfc_hba *phba = vport->phba;
4270 int val = LPFC_USER_LINK_SPEED_AUTO;
4272 const char *val_buf = buf;
4274 uint32_t prev_val, if_type;
4276 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4277 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4278 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4281 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4283 val_buf = &buf[strlen("nolip ")];
4286 if (!isdigit(val_buf[0]))
4288 if (sscanf(val_buf, "%i", &val) != 1)
4291 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4292 "3055 lpfc_link_speed changed from %d to %d %s\n",
4293 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4295 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4296 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4297 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4298 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4299 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4300 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4301 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4302 ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4304 "2879 lpfc_link_speed attribute cannot be set "
4305 "to %d. Speed is not supported by this port.\n",
4309 if (val >= LPFC_USER_LINK_SPEED_16G &&
4310 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4312 "3112 lpfc_link_speed attribute cannot be set "
4313 "to %d. Speed is not supported in loop mode.\n",
4319 case LPFC_USER_LINK_SPEED_AUTO:
4320 case LPFC_USER_LINK_SPEED_1G:
4321 case LPFC_USER_LINK_SPEED_2G:
4322 case LPFC_USER_LINK_SPEED_4G:
4323 case LPFC_USER_LINK_SPEED_8G:
4324 case LPFC_USER_LINK_SPEED_16G:
4325 case LPFC_USER_LINK_SPEED_32G:
4326 case LPFC_USER_LINK_SPEED_64G:
4327 prev_val = phba->cfg_link_speed;
4328 phba->cfg_link_speed = val;
4332 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4334 phba->cfg_link_speed = prev_val;
4342 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4343 "0469 lpfc_link_speed attribute cannot be set to %d, "
4344 "allowed values are [%s]\n",
4345 val, LPFC_LINK_SPEED_STRING);
4350 static int lpfc_link_speed = 0;
4351 module_param(lpfc_link_speed, int, S_IRUGO);
4352 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4353 lpfc_param_show(link_speed)
4356 * lpfc_link_speed_init - Set the adapters link speed
4357 * @phba: lpfc_hba pointer.
4358 * @val: link speed value.
4361 * If val is in a valid range then set the adapter's link speed field.
4364 * If the value is not in range log a kernel error message, clear the link
4365 * speed and return an error.
4368 * zero if val saved.
4369 * -EINVAL val out of range
4372 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4374 if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4375 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4376 "3111 lpfc_link_speed of %d cannot "
4377 "support loop mode, setting topology to default.\n",
4379 phba->cfg_topology = 0;
4383 case LPFC_USER_LINK_SPEED_AUTO:
4384 case LPFC_USER_LINK_SPEED_1G:
4385 case LPFC_USER_LINK_SPEED_2G:
4386 case LPFC_USER_LINK_SPEED_4G:
4387 case LPFC_USER_LINK_SPEED_8G:
4388 case LPFC_USER_LINK_SPEED_16G:
4389 case LPFC_USER_LINK_SPEED_32G:
4390 case LPFC_USER_LINK_SPEED_64G:
4391 phba->cfg_link_speed = val;
4394 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4395 "0405 lpfc_link_speed attribute cannot "
4396 "be set to %d, allowed values are "
4397 "["LPFC_LINK_SPEED_STRING"]\n", val);
4398 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4403 static DEVICE_ATTR_RW(lpfc_link_speed);
4406 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4407 # 0 = aer disabled or not supported
4408 # 1 = aer supported and enabled (default)
4409 # Value range is [0,1]. Default value is 1.
4411 LPFC_ATTR(aer_support, 1, 0, 1,
4412 "Enable PCIe device AER support");
4413 lpfc_param_show(aer_support)
4416 * lpfc_aer_support_store - Set the adapter for aer support
4418 * @dev: class device that is converted into a Scsi_host.
4419 * @attr: device attribute, not used.
4420 * @buf: containing enable or disable aer flag.
4421 * @count: unused variable.
4424 * If the val is 1 and currently the device's AER capability was not
4425 * enabled, invoke the kernel's enable AER helper routine, trying to
4426 * enable the device's AER capability. If the helper routine enabling
4427 * AER returns success, update the device's cfg_aer_support flag to
4428 * indicate AER is supported by the device; otherwise, if the device
4429 * AER capability is already enabled to support AER, then do nothing.
4431 * If the val is 0 and currently the device's AER support was enabled,
4432 * invoke the kernel's disable AER helper routine. After that, update
4433 * the device's cfg_aer_support flag to indicate AER is not supported
4434 * by the device; otherwise, if the device AER capability is already
4435 * disabled from supporting AER, then do nothing.
4438 * length of the buf on success if val is in range the intended mode
4440 * -EINVAL if val out of range or intended mode is not supported.
4443 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4444 const char *buf, size_t count)
4446 struct Scsi_Host *shost = class_to_shost(dev);
4447 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4448 struct lpfc_hba *phba = vport->phba;
4449 int val = 0, rc = -EINVAL;
4451 if (!isdigit(buf[0]))
4453 if (sscanf(buf, "%i", &val) != 1)
4458 if (phba->hba_flag & HBA_AER_ENABLED) {
4459 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4461 spin_lock_irq(&phba->hbalock);
4462 phba->hba_flag &= ~HBA_AER_ENABLED;
4463 spin_unlock_irq(&phba->hbalock);
4464 phba->cfg_aer_support = 0;
4469 phba->cfg_aer_support = 0;
4474 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4475 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4477 spin_lock_irq(&phba->hbalock);
4478 phba->hba_flag |= HBA_AER_ENABLED;
4479 spin_unlock_irq(&phba->hbalock);
4480 phba->cfg_aer_support = 1;
4485 phba->cfg_aer_support = 1;
4496 static DEVICE_ATTR_RW(lpfc_aer_support);
4499 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4500 * @dev: class device that is converted into a Scsi_host.
4501 * @attr: device attribute, not used.
4502 * @buf: containing flag 1 for aer cleanup state.
4503 * @count: unused variable.
4506 * If the @buf contains 1 and the device currently has the AER support
4507 * enabled, then invokes the kernel AER helper routine
4508 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4509 * error status register.
4514 * -EINVAL if the buf does not contain the 1 or the device is not currently
4515 * enabled with the AER support.
4518 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4519 const char *buf, size_t count)
4521 struct Scsi_Host *shost = class_to_shost(dev);
4522 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4523 struct lpfc_hba *phba = vport->phba;
4526 if (!isdigit(buf[0]))
4528 if (sscanf(buf, "%i", &val) != 1)
4533 if (phba->hba_flag & HBA_AER_ENABLED)
4534 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4542 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4543 lpfc_aer_cleanup_state);
4546 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4548 * @dev: class device that is converted into a Scsi_host.
4549 * @attr: device attribute, not used.
4550 * @buf: containing the string the number of vfs to be enabled.
4551 * @count: unused variable.
4554 * When this api is called either through user sysfs, the driver shall
4555 * try to enable or disable SR-IOV virtual functions according to the
4558 * If zero virtual function has been enabled to the physical function,
4559 * the driver shall invoke the pci enable virtual function api trying
4560 * to enable the virtual functions. If the nr_vfn provided is greater
4561 * than the maximum supported, the maximum virtual function number will
4562 * be used for invoking the api; otherwise, the nr_vfn provided shall
4563 * be used for invoking the api. If the api call returned success, the
4564 * actual number of virtual functions enabled will be set to the driver
4565 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4566 * cfg_sriov_nr_virtfn remains zero.
4568 * If none-zero virtual functions have already been enabled to the
4569 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4570 * -EINVAL will be returned and the driver does nothing;
4572 * If the nr_vfn provided is zero and none-zero virtual functions have
4573 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4574 * disabling virtual function api shall be invoded to disable all the
4575 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4576 * zero. Otherwise, if zero virtual function has been enabled, do
4580 * length of the buf on success if val is in range the intended mode
4582 * -EINVAL if val out of range or intended mode is not supported.
4585 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4586 const char *buf, size_t count)
4588 struct Scsi_Host *shost = class_to_shost(dev);
4589 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4590 struct lpfc_hba *phba = vport->phba;
4591 struct pci_dev *pdev = phba->pcidev;
4592 int val = 0, rc = -EINVAL;
4594 /* Sanity check on user data */
4595 if (!isdigit(buf[0]))
4597 if (sscanf(buf, "%i", &val) != 1)
4602 /* Request disabling virtual functions */
4604 if (phba->cfg_sriov_nr_virtfn > 0) {
4605 pci_disable_sriov(pdev);
4606 phba->cfg_sriov_nr_virtfn = 0;
4611 /* Request enabling virtual functions */
4612 if (phba->cfg_sriov_nr_virtfn > 0) {
4613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4614 "3018 There are %d virtual functions "
4615 "enabled on physical function.\n",
4616 phba->cfg_sriov_nr_virtfn);
4620 if (val <= LPFC_MAX_VFN_PER_PFN)
4621 phba->cfg_sriov_nr_virtfn = val;
4623 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4624 "3019 Enabling %d virtual functions is not "
4629 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4631 phba->cfg_sriov_nr_virtfn = 0;
4639 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4640 "Enable PCIe device SR-IOV virtual fn");
4642 lpfc_param_show(sriov_nr_virtfn)
4643 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4646 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4648 * @dev: class device that is converted into a Scsi_host.
4649 * @attr: device attribute, not used.
4650 * @buf: containing the string the number of vfs to be enabled.
4651 * @count: unused variable.
4656 * length of the buf on success if val is in range the intended mode
4658 * -EINVAL if val out of range or intended mode is not supported.
4661 lpfc_request_firmware_upgrade_store(struct device *dev,
4662 struct device_attribute *attr,
4663 const char *buf, size_t count)
4665 struct Scsi_Host *shost = class_to_shost(dev);
4666 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4667 struct lpfc_hba *phba = vport->phba;
4668 int val = 0, rc = -EINVAL;
4670 /* Sanity check on user data */
4671 if (!isdigit(buf[0]))
4673 if (sscanf(buf, "%i", &val) != 1)
4678 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4686 static int lpfc_req_fw_upgrade;
4687 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4688 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4689 lpfc_param_show(request_firmware_upgrade)
4692 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4693 * @phba: lpfc_hba pointer.
4697 * Set the initial Linux generic firmware upgrade enable or disable flag.
4700 * zero if val saved.
4701 * -EINVAL val out of range
4704 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4706 if (val >= 0 && val <= 1) {
4707 phba->cfg_request_firmware_upgrade = val;
4712 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4713 lpfc_request_firmware_upgrade_show,
4714 lpfc_request_firmware_upgrade_store);
4717 * lpfc_fcp_imax_store
4719 * @dev: class device that is converted into a Scsi_host.
4720 * @attr: device attribute, not used.
4721 * @buf: string with the number of fast-path FCP interrupts per second.
4722 * @count: unused variable.
4725 * If val is in a valid range [636,651042], then set the adapter's
4726 * maximum number of fast-path FCP interrupts per second.
4729 * length of the buf on success if val is in range the intended mode
4731 * -EINVAL if val out of range or intended mode is not supported.
4734 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4735 const char *buf, size_t count)
4737 struct Scsi_Host *shost = class_to_shost(dev);
4738 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4739 struct lpfc_hba *phba = vport->phba;
4742 /* fcp_imax is only valid for SLI4 */
4743 if (phba->sli_rev != LPFC_SLI_REV4)
4746 /* Sanity check on user data */
4747 if (!isdigit(buf[0]))
4749 if (sscanf(buf, "%i", &val) != 1)
4753 * Value range for the HBA is [5000,5000000]
4754 * The value for each EQ depends on how many EQs are configured.
4757 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4760 phba->cfg_fcp_imax = (uint32_t)val;
4761 phba->initial_imax = phba->cfg_fcp_imax;
4763 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4764 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4771 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4774 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4776 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4777 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4778 MODULE_PARM_DESC(lpfc_fcp_imax,
4779 "Set the maximum number of FCP interrupts per second per HBA");
4780 lpfc_param_show(fcp_imax)
4783 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4784 * @phba: lpfc_hba pointer.
4785 * @val: link speed value.
4788 * If val is in a valid range [636,651042], then initialize the adapter's
4789 * maximum number of fast-path FCP interrupts per second.
4792 * zero if val saved.
4793 * -EINVAL val out of range
4796 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4798 if (phba->sli_rev != LPFC_SLI_REV4) {
4799 phba->cfg_fcp_imax = 0;
4803 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4805 phba->cfg_fcp_imax = val;
4809 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4810 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4812 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4817 static DEVICE_ATTR_RW(lpfc_fcp_imax);
4820 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4821 * 0 No auto_imax support
4823 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4824 * the EQ Delay Multiplier, depending on the activity for that EQ.
4825 * Value range [0,1]. Default value is 1.
4827 LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4830 * lpfc_state_show - Display current driver CPU affinity
4831 * @dev: class converted to a Scsi_host structure.
4832 * @attr: device attribute, not used.
4833 * @buf: on return contains text describing the state of the link.
4835 * Returns: size of formatted string.
4838 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4841 struct Scsi_Host *shost = class_to_shost(dev);
4842 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4843 struct lpfc_hba *phba = vport->phba;
4844 struct lpfc_vector_map_info *cpup;
4847 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4848 (phba->intr_type != MSIX))
4851 switch (phba->cfg_fcp_cpu_map) {
4853 len += scnprintf(buf + len, PAGE_SIZE-len,
4854 "fcp_cpu_map: No mapping (%d)\n",
4855 phba->cfg_fcp_cpu_map);
4858 len += scnprintf(buf + len, PAGE_SIZE-len,
4859 "fcp_cpu_map: HBA centric mapping (%d): "
4861 phba->cfg_fcp_cpu_map,
4862 phba->sli4_hba.num_online_cpu);
4865 len += scnprintf(buf + len, PAGE_SIZE-len,
4866 "fcp_cpu_map: Driver centric mapping (%d): "
4868 phba->cfg_fcp_cpu_map,
4869 phba->sli4_hba.num_online_cpu);
4873 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4874 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4876 /* margin should fit in this and the truncated message */
4877 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4878 len += scnprintf(buf + len, PAGE_SIZE-len,
4879 "CPU %02d io_chan %02d "
4880 "physid %d coreid %d\n",
4881 phba->sli4_hba.curr_disp_cpu,
4882 cpup->channel_id, cpup->phys_id,
4885 len += scnprintf(buf + len, PAGE_SIZE-len,
4886 "CPU %02d io_chan %02d "
4887 "physid %d coreid %d IRQ %d\n",
4888 phba->sli4_hba.curr_disp_cpu,
4889 cpup->channel_id, cpup->phys_id,
4890 cpup->core_id, cpup->irq);
4892 phba->sli4_hba.curr_disp_cpu++;
4894 /* display max number of CPUs keeping some margin */
4895 if (phba->sli4_hba.curr_disp_cpu <
4896 phba->sli4_hba.num_present_cpu &&
4897 (len >= (PAGE_SIZE - 64))) {
4898 len += scnprintf(buf + len, PAGE_SIZE-len, "more...\n");
4903 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4904 phba->sli4_hba.curr_disp_cpu = 0;
4910 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4911 * @dev: class device that is converted into a Scsi_host.
4912 * @attr: device attribute, not used.
4913 * @buf: one or more lpfc_polling_flags values.
4917 * -EINVAL - Not implemented yet.
4920 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4921 const char *buf, size_t count)
4923 int status = -EINVAL;
4928 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4931 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4932 # 0 - Do not affinitze IRQ vectors
4933 # 1 - Affintize HBA vectors with respect to each HBA
4934 # (start with CPU0 for each HBA)
4935 # 2 - Affintize HBA vectors with respect to the entire driver
4936 # (round robin thru all CPUs across all HBAs)
4938 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4939 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4940 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4941 "Defines how to map CPUs to IRQ vectors per HBA");
4944 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4945 * @phba: lpfc_hba pointer.
4946 * @val: link speed value.
4949 * If val is in a valid range [0-2], then affinitze the adapter's
4953 * zero if val saved.
4954 * -EINVAL val out of range
4957 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4959 if (phba->sli_rev != LPFC_SLI_REV4) {
4960 phba->cfg_fcp_cpu_map = 0;
4964 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4965 phba->cfg_fcp_cpu_map = val;
4969 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4970 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4972 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4977 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
4980 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4981 # Value range is [2,3]. Default value is 3.
4983 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4984 "Select Fibre Channel class of service for FCP sequences");
4987 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4988 # is [0,1]. Default value is 0.
4990 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4991 "Use ADISC on rediscovery to authenticate FCP devices");
4994 # lpfc_first_burst_size: First burst size to use on the NPorts
4995 # that support first burst.
4996 # Value range is [0,65536]. Default value is 0.
4998 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4999 "First burst size for Targets that support first burst");
5002 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5003 * When the driver is configured as an NVME target, this value is
5004 * communicated to the NVME initiator in the PRLI response. It is
5005 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5006 * parameters are set and the target is sending the PRLI RSP.
5007 * Parameter supported on physical port only - no NPIV support.
5008 * Value range is [0,65536]. Default value is 0.
5010 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5011 "NVME Target mode first burst size in 512B increments.");
5014 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5015 * For the Initiator (I), enabling this parameter means that an NVMET
5016 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5017 * processed by the initiator for subsequent NVME FCP IO. For the target
5018 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
5019 * driver parameter as the target function's first burst size returned to the
5020 * initiator in the target's NVME PRLI response. Parameter supported on physical
5021 * port only - no NPIV support.
5022 * Value range is [0,1]. Default value is 0 (disabled).
5024 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5025 "Enable First Burst feature on I and T functions.");
5028 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5029 # depth. Default value is 0. When the value of this parameter is zero the
5030 # SCSI command completion time is not used for controlling I/O queue depth. When
5031 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5032 # to limit the I/O completion time to the parameter value.
5033 # The value is set in milliseconds.
5035 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5036 "Use command completion time to control queue depth");
5038 lpfc_vport_param_show(max_scsicmpl_time);
5040 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5042 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5043 struct lpfc_nodelist *ndlp, *next_ndlp;
5045 if (val == vport->cfg_max_scsicmpl_time)
5047 if ((val < 0) || (val > 60000))
5049 vport->cfg_max_scsicmpl_time = val;
5051 spin_lock_irq(shost->host_lock);
5052 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5053 if (!NLP_CHK_NODE_ACT(ndlp))
5055 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5057 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5059 spin_unlock_irq(shost->host_lock);
5062 lpfc_vport_param_store(max_scsicmpl_time);
5063 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5066 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5067 # range is [0,1]. Default value is 0.
5069 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5072 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5073 * range is [0,1]. Default value is 0.
5074 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
5075 * For [1], FCP commands are issued to a Work Queue associated with the
5078 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
5079 * LPFC_FCP_SCHED_BY_CPU == 1
5081 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5082 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5083 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5084 * through WQs will be used.
5086 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
5087 LPFC_FCP_SCHED_ROUND_ROBIN,
5088 LPFC_FCP_SCHED_BY_CPU,
5089 "Determine scheduling algorithm for "
5090 "issuing commands [0] - Round Robin, [1] - Current CPU");
5093 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5094 # range is [0,1]. Default value is 0.
5095 # For [0], bus reset issues target reset to ALL devices
5096 # For [1], bus reset issues target reset to non-FCP2 devices
5098 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5099 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5103 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5104 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5105 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5106 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5107 # cr_delay is set to 0.
5109 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5110 "interrupt response is generated");
5112 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5113 "interrupt response is generated");
5116 # lpfc_multi_ring_support: Determines how many rings to spread available
5117 # cmd/rsp IOCB entries across.
5118 # Value range is [1,2]. Default value is 1.
5120 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5121 "SLI rings to spread IOCB entries across");
5124 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5125 # identifies what rctl value to configure the additional ring for.
5126 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5128 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5129 255, "Identifies RCTL for additional ring configuration");
5132 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5133 # identifies what type value to configure the additional ring for.
5134 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5136 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5137 255, "Identifies TYPE for additional ring configuration");
5140 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5141 # 0 = SmartSAN functionality disabled (default)
5142 # 1 = SmartSAN functionality enabled
5143 # This parameter will override the value of lpfc_fdmi_on module parameter.
5144 # Value range is [0,1]. Default value is 0.
5146 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5149 # lpfc_fdmi_on: Controls FDMI support.
5151 # 1 Traditional FDMI support (default)
5152 # Traditional FDMI support means the driver will assume FDMI-2 support;
5153 # however, if that fails, it will fallback to FDMI-1.
5154 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5155 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5157 # Value range [0,1]. Default value is 1.
5159 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5162 # Specifies the maximum number of ELS cmds we can have outstanding (for
5163 # discovery). Value range is [1,64]. Default value = 32.
5165 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5166 "during discovery");
5169 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5170 # will be scanned by the SCSI midlayer when sequential scanning is
5171 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5172 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5173 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5174 # above. The lpfc driver limits the default value to 255 for two reasons.
5175 # As it bounds the sequential scan loop, scanning for thousands of luns
5176 # on a target can take minutes of wall clock time. Additionally,
5177 # there are FC targets, such as JBODs, that only recognize 8-bits of
5178 # LUN ID. When they receive a value greater than 8 bits, they chop off
5179 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5180 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5181 # valid responses at each of the LUN IDs, to believe there are multiple
5182 # devices present, when in fact, there is only 1.
5183 # A customer that is aware of their target behaviors, and the results as
5184 # indicated above, is welcome to increase the lpfc_max_luns value.
5185 # As mentioned, this value is not used by the lpfc driver, only the
5187 # Value range is [0,65535]. Default value is 255.
5188 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5190 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5193 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5194 # Value range is [1,255], default value is 10.
5196 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5197 "Milliseconds driver will wait between polling FCP ring");
5200 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5201 # to complete in seconds. Value range is [5,180], default value is 60.
5203 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5204 "Maximum time to wait for task management commands to complete");
5206 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5207 # support this feature
5210 # 2 = MSI-X enabled (default)
5211 # Value range is [0,2]. Default value is 2.
5213 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5214 "MSI-X (2), if possible");
5217 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5219 * 0 = NVME OAS disabled
5220 * 1 = NVME OAS enabled
5222 * Value range is [0,1]. Default value is 0.
5224 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5225 "Use OAS bit on NVME IOs");
5228 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5230 * 0 = Put NVME Command in SGL
5231 * 1 = Embed NVME Command in WQE (unless G7)
5232 * 2 = Embed NVME Command in WQE (force)
5234 * Value range is [0,2]. Default value is 1.
5236 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5237 "Embed NVME Command in WQE");
5240 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
5241 * will advertise it supports to the SCSI layer. This also will map to
5242 * the number of WQs the driver will create.
5244 * 0 = Configure the number of io channels to the number of active CPUs.
5245 * 1,32 = Manually specify how many io channels to use.
5247 * Value range is [0,32]. Default value is 4.
5249 LPFC_ATTR_R(fcp_io_channel,
5250 LPFC_FCP_IO_CHAN_DEF,
5251 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5252 "Set the number of FCP I/O channels");
5255 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
5256 * will advertise it supports to the NVME layer. This also will map to
5257 * the number of WQs the driver will create.
5259 * This module parameter is valid when lpfc_enable_fc4_type is set
5262 * The NVME Layer will try to create this many, plus 1 administrative
5263 * hardware queue. The administrative queue will always map to WQ 0
5264 * A hardware IO queue maps (qidx) to a specific driver WQ.
5266 * 0 = Configure the number of io channels to the number of active CPUs.
5267 * 1,32 = Manually specify how many io channels to use.
5269 * Value range is [0,32]. Default value is 0.
5271 LPFC_ATTR_R(nvme_io_channel,
5272 LPFC_NVME_IO_CHAN_DEF,
5273 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5274 "Set the number of NVME I/O channels");
5277 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5278 # 0 = HBA resets disabled
5279 # 1 = HBA resets enabled (default)
5280 # Value range is [0,1]. Default value is 1.
5282 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
5285 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5286 # 0 = HBA Heartbeat disabled
5287 # 1 = HBA Heartbeat enabled (default)
5288 # Value range is [0,1]. Default value is 1.
5290 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5293 # lpfc_EnableXLane: Enable Express Lane Feature
5294 # 0x0 Express Lane Feature disabled
5295 # 0x1 Express Lane Feature enabled
5296 # Value range is [0,1]. Default value is 0.
5298 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5301 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5302 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5303 # Value range is [0x0,0x7f]. Default value is 0
5305 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5308 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5309 # 0 = BlockGuard disabled (default)
5310 # 1 = BlockGuard enabled
5311 # Value range is [0,1]. Default value is 0.
5313 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5316 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5317 # 0 = disabled (default)
5319 # Value range is [0,1]. Default value is 0.
5321 # This feature in under investigation and may be supported in the future.
5323 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5327 # - Bit mask of host protection capabilities used to register with the
5329 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5330 # - Allows you to ultimately specify which profiles to use
5331 # - Default will result in registering capabilities for all profiles.
5332 # - SHOST_DIF_TYPE1_PROTECTION 1
5333 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5334 # - SHOST_DIX_TYPE0_PROTECTION 8
5335 # HBA supports DIX Type 0: Host to HBA protection only
5336 # - SHOST_DIX_TYPE1_PROTECTION 16
5337 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5340 LPFC_ATTR(prot_mask,
5341 (SHOST_DIF_TYPE1_PROTECTION |
5342 SHOST_DIX_TYPE0_PROTECTION |
5343 SHOST_DIX_TYPE1_PROTECTION),
5345 (SHOST_DIF_TYPE1_PROTECTION |
5346 SHOST_DIX_TYPE0_PROTECTION |
5347 SHOST_DIX_TYPE1_PROTECTION),
5348 "T10-DIF host protection capabilities mask");
5351 # lpfc_prot_guard: i
5352 # - Bit mask of protection guard types to register with the SCSI mid-layer
5353 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5354 # - Allows you to ultimately specify which profiles to use
5355 # - Default will result in registering capabilities for all guard types
5358 LPFC_ATTR(prot_guard,
5359 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5360 "T10-DIF host protection guard type");
5363 * Delay initial NPort discovery when Clean Address bit is cleared in
5364 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5365 * This parameter can have value 0 or 1.
5366 * When this parameter is set to 0, no delay is added to the initial
5368 * When this parameter is set to non-zero value, initial Nport discovery is
5369 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5370 * accept and FCID/Fabric name/Fabric portname is changed.
5371 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5372 * when Clean Address bit is cleared in FLOGI/FDISC
5373 * accept and FCID/Fabric name/Fabric portname is changed.
5374 * Default value is 0.
5376 LPFC_ATTR(delay_discovery, 0, 0, 1,
5377 "Delay NPort discovery when Clean Address bit is cleared.");
5380 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5381 * This value can be set to values between 64 and 4096. The default value is
5382 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5383 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5384 * Because of the additional overhead involved in setting up T10-DIF,
5385 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5386 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5388 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_MIN_SG_SEG_CNT,
5389 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5392 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5393 * 0 = MDS Diagnostics disabled (default)
5394 * 1 = MDS Diagnostics enabled
5395 * Value range is [0,1]. Default value is 0.
5397 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5400 * lpfc_enable_bbcr: Enable BB Credit Recovery
5401 * 0 = BB Credit Recovery disabled
5402 * 1 = BB Credit Recovery enabled (default)
5403 * Value range is [0,1]. Default value is 1.
5405 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5408 * lpfc_enable_dpp: Enable DPP on G7
5409 * 0 = DPP on G7 disabled
5410 * 1 = DPP on G7 enabled (default)
5411 * Value range is [0,1]. Default value is 1.
5413 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5415 struct device_attribute *lpfc_hba_attrs[] = {
5416 &dev_attr_nvme_info,
5418 &dev_attr_bg_guard_err,
5419 &dev_attr_bg_apptag_err,
5420 &dev_attr_bg_reftag_err,
5422 &dev_attr_serialnum,
5423 &dev_attr_modeldesc,
5424 &dev_attr_modelname,
5425 &dev_attr_programtype,
5429 &dev_attr_option_rom_version,
5430 &dev_attr_link_state,
5431 &dev_attr_num_discovered_ports,
5432 &dev_attr_menlo_mgmt_mode,
5433 &dev_attr_lpfc_drvr_version,
5434 &dev_attr_lpfc_enable_fip,
5435 &dev_attr_lpfc_temp_sensor,
5436 &dev_attr_lpfc_log_verbose,
5437 &dev_attr_lpfc_lun_queue_depth,
5438 &dev_attr_lpfc_tgt_queue_depth,
5439 &dev_attr_lpfc_hba_queue_depth,
5440 &dev_attr_lpfc_peer_port_login,
5441 &dev_attr_lpfc_nodev_tmo,
5442 &dev_attr_lpfc_devloss_tmo,
5443 &dev_attr_lpfc_enable_fc4_type,
5444 &dev_attr_lpfc_xri_split,
5445 &dev_attr_lpfc_fcp_class,
5446 &dev_attr_lpfc_use_adisc,
5447 &dev_attr_lpfc_first_burst_size,
5448 &dev_attr_lpfc_ack0,
5449 &dev_attr_lpfc_topology,
5450 &dev_attr_lpfc_scan_down,
5451 &dev_attr_lpfc_link_speed,
5452 &dev_attr_lpfc_fcp_io_sched,
5453 &dev_attr_lpfc_fcp2_no_tgt_reset,
5454 &dev_attr_lpfc_cr_delay,
5455 &dev_attr_lpfc_cr_count,
5456 &dev_attr_lpfc_multi_ring_support,
5457 &dev_attr_lpfc_multi_ring_rctl,
5458 &dev_attr_lpfc_multi_ring_type,
5459 &dev_attr_lpfc_fdmi_on,
5460 &dev_attr_lpfc_enable_SmartSAN,
5461 &dev_attr_lpfc_max_luns,
5462 &dev_attr_lpfc_enable_npiv,
5463 &dev_attr_lpfc_fcf_failover_policy,
5464 &dev_attr_lpfc_enable_rrq,
5465 &dev_attr_nport_evt_cnt,
5466 &dev_attr_board_mode,
5473 &dev_attr_npiv_info,
5474 &dev_attr_issue_reset,
5475 &dev_attr_lpfc_poll,
5476 &dev_attr_lpfc_poll_tmo,
5477 &dev_attr_lpfc_task_mgmt_tmo,
5478 &dev_attr_lpfc_use_msi,
5479 &dev_attr_lpfc_nvme_oas,
5480 &dev_attr_lpfc_nvme_embed_cmd,
5481 &dev_attr_lpfc_auto_imax,
5482 &dev_attr_lpfc_fcp_imax,
5483 &dev_attr_lpfc_fcp_cpu_map,
5484 &dev_attr_lpfc_fcp_io_channel,
5485 &dev_attr_lpfc_suppress_rsp,
5486 &dev_attr_lpfc_nvme_io_channel,
5487 &dev_attr_lpfc_nvmet_mrq,
5488 &dev_attr_lpfc_nvmet_mrq_post,
5489 &dev_attr_lpfc_nvme_enable_fb,
5490 &dev_attr_lpfc_nvmet_fb_size,
5491 &dev_attr_lpfc_enable_bg,
5492 &dev_attr_lpfc_soft_wwnn,
5493 &dev_attr_lpfc_soft_wwpn,
5494 &dev_attr_lpfc_soft_wwn_enable,
5495 &dev_attr_lpfc_enable_hba_reset,
5496 &dev_attr_lpfc_enable_hba_heartbeat,
5497 &dev_attr_lpfc_EnableXLane,
5498 &dev_attr_lpfc_XLanePriority,
5499 &dev_attr_lpfc_xlane_lun,
5500 &dev_attr_lpfc_xlane_tgt,
5501 &dev_attr_lpfc_xlane_vpt,
5502 &dev_attr_lpfc_xlane_lun_state,
5503 &dev_attr_lpfc_xlane_lun_status,
5504 &dev_attr_lpfc_xlane_priority,
5505 &dev_attr_lpfc_sg_seg_cnt,
5506 &dev_attr_lpfc_max_scsicmpl_time,
5507 &dev_attr_lpfc_stat_data_ctrl,
5508 &dev_attr_lpfc_aer_support,
5509 &dev_attr_lpfc_aer_state_cleanup,
5510 &dev_attr_lpfc_sriov_nr_virtfn,
5511 &dev_attr_lpfc_req_fw_upgrade,
5512 &dev_attr_lpfc_suppress_link_up,
5513 &dev_attr_lpfc_iocb_cnt,
5516 &dev_attr_txcmplq_hw,
5517 &dev_attr_lpfc_fips_level,
5518 &dev_attr_lpfc_fips_rev,
5520 &dev_attr_lpfc_sriov_hw_max_virtfn,
5522 &dev_attr_lpfc_xlane_supported,
5523 &dev_attr_lpfc_enable_mds_diags,
5524 &dev_attr_lpfc_enable_bbcr,
5525 &dev_attr_lpfc_enable_dpp,
5529 struct device_attribute *lpfc_vport_attrs[] = {
5531 &dev_attr_link_state,
5532 &dev_attr_num_discovered_ports,
5533 &dev_attr_lpfc_drvr_version,
5534 &dev_attr_lpfc_log_verbose,
5535 &dev_attr_lpfc_lun_queue_depth,
5536 &dev_attr_lpfc_tgt_queue_depth,
5537 &dev_attr_lpfc_nodev_tmo,
5538 &dev_attr_lpfc_devloss_tmo,
5539 &dev_attr_lpfc_hba_queue_depth,
5540 &dev_attr_lpfc_peer_port_login,
5541 &dev_attr_lpfc_restrict_login,
5542 &dev_attr_lpfc_fcp_class,
5543 &dev_attr_lpfc_use_adisc,
5544 &dev_attr_lpfc_first_burst_size,
5545 &dev_attr_lpfc_max_luns,
5546 &dev_attr_nport_evt_cnt,
5547 &dev_attr_npiv_info,
5548 &dev_attr_lpfc_enable_da_id,
5549 &dev_attr_lpfc_max_scsicmpl_time,
5550 &dev_attr_lpfc_stat_data_ctrl,
5551 &dev_attr_lpfc_static_vport,
5552 &dev_attr_lpfc_fips_level,
5553 &dev_attr_lpfc_fips_rev,
5558 * sysfs_ctlreg_write - Write method for writing to ctlreg
5559 * @filp: open sysfs file
5560 * @kobj: kernel kobject that contains the kernel class device.
5561 * @bin_attr: kernel attributes passed to us.
5562 * @buf: contains the data to be written to the adapter IOREG space.
5563 * @off: offset into buffer to beginning of data.
5564 * @count: bytes to transfer.
5567 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5568 * Uses the adapter io control registers to send buf contents to the adapter.
5571 * -ERANGE off and count combo out of range
5572 * -EINVAL off, count or buff address invalid
5573 * -EPERM adapter is offline
5574 * value of count, buf contents written
5577 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5578 struct bin_attribute *bin_attr,
5579 char *buf, loff_t off, size_t count)
5582 struct device *dev = container_of(kobj, struct device, kobj);
5583 struct Scsi_Host *shost = class_to_shost(dev);
5584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5585 struct lpfc_hba *phba = vport->phba;
5587 if (phba->sli_rev >= LPFC_SLI_REV4)
5590 if ((off + count) > FF_REG_AREA_SIZE)
5593 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5596 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5599 /* This is to protect HBA registers from accidental writes. */
5600 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5603 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5606 spin_lock_irq(&phba->hbalock);
5607 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5608 buf_off += sizeof(uint32_t))
5609 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5610 phba->ctrl_regs_memmap_p + off + buf_off);
5612 spin_unlock_irq(&phba->hbalock);
5618 * sysfs_ctlreg_read - Read method for reading from ctlreg
5619 * @filp: open sysfs file
5620 * @kobj: kernel kobject that contains the kernel class device.
5621 * @bin_attr: kernel attributes passed to us.
5622 * @buf: if successful contains the data from the adapter IOREG space.
5623 * @off: offset into buffer to beginning of data.
5624 * @count: bytes to transfer.
5627 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5628 * Uses the adapter io control registers to read data into buf.
5631 * -ERANGE off and count combo out of range
5632 * -EINVAL off, count or buff address invalid
5633 * value of count, buf contents read
5636 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5637 struct bin_attribute *bin_attr,
5638 char *buf, loff_t off, size_t count)
5642 struct device *dev = container_of(kobj, struct device, kobj);
5643 struct Scsi_Host *shost = class_to_shost(dev);
5644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5645 struct lpfc_hba *phba = vport->phba;
5647 if (phba->sli_rev >= LPFC_SLI_REV4)
5650 if (off > FF_REG_AREA_SIZE)
5653 if ((off + count) > FF_REG_AREA_SIZE)
5654 count = FF_REG_AREA_SIZE - off;
5656 if (count == 0) return 0;
5658 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5661 spin_lock_irq(&phba->hbalock);
5663 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5664 tmp_ptr = (uint32_t *)(buf + buf_off);
5665 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5668 spin_unlock_irq(&phba->hbalock);
5673 static struct bin_attribute sysfs_ctlreg_attr = {
5676 .mode = S_IRUSR | S_IWUSR,
5679 .read = sysfs_ctlreg_read,
5680 .write = sysfs_ctlreg_write,
5684 * sysfs_mbox_write - Write method for writing information via mbox
5685 * @filp: open sysfs file
5686 * @kobj: kernel kobject that contains the kernel class device.
5687 * @bin_attr: kernel attributes passed to us.
5688 * @buf: contains the data to be written to sysfs mbox.
5689 * @off: offset into buffer to beginning of data.
5690 * @count: bytes to transfer.
5693 * Deprecated function. All mailbox access from user space is performed via the
5697 * -EPERM operation not permitted
5700 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5701 struct bin_attribute *bin_attr,
5702 char *buf, loff_t off, size_t count)
5708 * sysfs_mbox_read - Read method for reading information via mbox
5709 * @filp: open sysfs file
5710 * @kobj: kernel kobject that contains the kernel class device.
5711 * @bin_attr: kernel attributes passed to us.
5712 * @buf: contains the data to be read from sysfs mbox.
5713 * @off: offset into buffer to beginning of data.
5714 * @count: bytes to transfer.
5717 * Deprecated function. All mailbox access from user space is performed via the
5721 * -EPERM operation not permitted
5724 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5725 struct bin_attribute *bin_attr,
5726 char *buf, loff_t off, size_t count)
5731 static struct bin_attribute sysfs_mbox_attr = {
5734 .mode = S_IRUSR | S_IWUSR,
5736 .size = MAILBOX_SYSFS_MAX,
5737 .read = sysfs_mbox_read,
5738 .write = sysfs_mbox_write,
5742 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5743 * @vport: address of lpfc vport structure.
5747 * error return code from sysfs_create_bin_file()
5750 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5752 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5755 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5756 &sysfs_drvr_stat_data_attr);
5758 /* Virtual ports do not need ctrl_reg and mbox */
5759 if (error || vport->port_type == LPFC_NPIV_PORT)
5762 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5763 &sysfs_ctlreg_attr);
5765 goto out_remove_stat_attr;
5767 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5770 goto out_remove_ctlreg_attr;
5773 out_remove_ctlreg_attr:
5774 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5775 out_remove_stat_attr:
5776 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5777 &sysfs_drvr_stat_data_attr);
5783 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5784 * @vport: address of lpfc vport structure.
5787 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5789 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5790 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5791 &sysfs_drvr_stat_data_attr);
5792 /* Virtual ports do not need ctrl_reg and mbox */
5793 if (vport->port_type == LPFC_NPIV_PORT)
5795 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5796 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5800 * Dynamic FC Host Attributes Support
5804 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5805 * @shost: kernel scsi host pointer.
5808 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5810 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5812 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5813 sizeof fc_host_symbolic_name(shost));
5817 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5818 * @shost: kernel scsi host pointer.
5821 lpfc_get_host_port_id(struct Scsi_Host *shost)
5823 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5825 /* note: fc_myDID already in cpu endianness */
5826 fc_host_port_id(shost) = vport->fc_myDID;
5830 * lpfc_get_host_port_type - Set the value of the scsi host port type
5831 * @shost: kernel scsi host pointer.
5834 lpfc_get_host_port_type(struct Scsi_Host *shost)
5836 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5837 struct lpfc_hba *phba = vport->phba;
5839 spin_lock_irq(shost->host_lock);
5841 if (vport->port_type == LPFC_NPIV_PORT) {
5842 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5843 } else if (lpfc_is_link_up(phba)) {
5844 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5845 if (vport->fc_flag & FC_PUBLIC_LOOP)
5846 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5848 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5850 if (vport->fc_flag & FC_FABRIC)
5851 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5853 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5856 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5858 spin_unlock_irq(shost->host_lock);
5862 * lpfc_get_host_port_state - Set the value of the scsi host port state
5863 * @shost: kernel scsi host pointer.
5866 lpfc_get_host_port_state(struct Scsi_Host *shost)
5868 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5869 struct lpfc_hba *phba = vport->phba;
5871 spin_lock_irq(shost->host_lock);
5873 if (vport->fc_flag & FC_OFFLINE_MODE)
5874 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5876 switch (phba->link_state) {
5877 case LPFC_LINK_UNKNOWN:
5878 case LPFC_LINK_DOWN:
5879 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5883 case LPFC_HBA_READY:
5884 /* Links up, reports port state accordingly */
5885 if (vport->port_state < LPFC_VPORT_READY)
5886 fc_host_port_state(shost) =
5887 FC_PORTSTATE_BYPASSED;
5889 fc_host_port_state(shost) =
5890 FC_PORTSTATE_ONLINE;
5892 case LPFC_HBA_ERROR:
5893 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5896 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5901 spin_unlock_irq(shost->host_lock);
5905 * lpfc_get_host_speed - Set the value of the scsi host speed
5906 * @shost: kernel scsi host pointer.
5909 lpfc_get_host_speed(struct Scsi_Host *shost)
5911 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5912 struct lpfc_hba *phba = vport->phba;
5914 spin_lock_irq(shost->host_lock);
5916 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5917 switch(phba->fc_linkspeed) {
5918 case LPFC_LINK_SPEED_1GHZ:
5919 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5921 case LPFC_LINK_SPEED_2GHZ:
5922 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5924 case LPFC_LINK_SPEED_4GHZ:
5925 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5927 case LPFC_LINK_SPEED_8GHZ:
5928 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5930 case LPFC_LINK_SPEED_10GHZ:
5931 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5933 case LPFC_LINK_SPEED_16GHZ:
5934 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5936 case LPFC_LINK_SPEED_32GHZ:
5937 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5939 case LPFC_LINK_SPEED_64GHZ:
5940 fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
5943 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5946 } else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
5947 switch (phba->fc_linkspeed) {
5948 case LPFC_ASYNC_LINK_SPEED_10GBPS:
5949 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5951 case LPFC_ASYNC_LINK_SPEED_25GBPS:
5952 fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
5954 case LPFC_ASYNC_LINK_SPEED_40GBPS:
5955 fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
5957 case LPFC_ASYNC_LINK_SPEED_100GBPS:
5958 fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
5961 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5965 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5967 spin_unlock_irq(shost->host_lock);
5971 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5972 * @shost: kernel scsi host pointer.
5975 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5977 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5978 struct lpfc_hba *phba = vport->phba;
5981 spin_lock_irq(shost->host_lock);
5983 if ((vport->port_state > LPFC_FLOGI) &&
5984 ((vport->fc_flag & FC_FABRIC) ||
5985 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5986 (vport->fc_flag & FC_PUBLIC_LOOP))))
5987 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5989 /* fabric is local port if there is no F/FL_Port */
5992 spin_unlock_irq(shost->host_lock);
5994 fc_host_fabric_name(shost) = node_name;
5998 * lpfc_get_stats - Return statistical information about the adapter
5999 * @shost: kernel scsi host pointer.
6002 * NULL on error for link down, no mbox pool, sli2 active,
6003 * management not allowed, memory allocation error, or mbox error.
6007 * address of the adapter host statistics
6009 static struct fc_host_statistics *
6010 lpfc_get_stats(struct Scsi_Host *shost)
6012 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6013 struct lpfc_hba *phba = vport->phba;
6014 struct lpfc_sli *psli = &phba->sli;
6015 struct fc_host_statistics *hs = &phba->link_stats;
6016 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6017 LPFC_MBOXQ_t *pmboxq;
6022 * prevent udev from issuing mailbox commands until the port is
6025 if (phba->link_state < LPFC_LINK_DOWN ||
6026 !phba->mbox_mem_pool ||
6027 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6030 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6033 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6036 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6038 pmb = &pmboxq->u.mb;
6039 pmb->mbxCommand = MBX_READ_STATUS;
6040 pmb->mbxOwner = OWN_HOST;
6041 pmboxq->context1 = NULL;
6042 pmboxq->vport = vport;
6044 if (vport->fc_flag & FC_OFFLINE_MODE)
6045 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6047 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6049 if (rc != MBX_SUCCESS) {
6050 if (rc != MBX_TIMEOUT)
6051 mempool_free(pmboxq, phba->mbox_mem_pool);
6055 memset(hs, 0, sizeof (struct fc_host_statistics));
6057 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6059 * The MBX_READ_STATUS returns tx_k_bytes which has to
6060 * converted to words
6062 hs->tx_words = (uint64_t)
6063 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6065 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6066 hs->rx_words = (uint64_t)
6067 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6070 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6071 pmb->mbxCommand = MBX_READ_LNK_STAT;
6072 pmb->mbxOwner = OWN_HOST;
6073 pmboxq->context1 = NULL;
6074 pmboxq->vport = vport;
6076 if (vport->fc_flag & FC_OFFLINE_MODE)
6077 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6079 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6081 if (rc != MBX_SUCCESS) {
6082 if (rc != MBX_TIMEOUT)
6083 mempool_free(pmboxq, phba->mbox_mem_pool);
6087 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6088 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6089 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6090 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6091 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6092 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6093 hs->error_frames = pmb->un.varRdLnk.crcCnt;
6095 hs->link_failure_count -= lso->link_failure_count;
6096 hs->loss_of_sync_count -= lso->loss_of_sync_count;
6097 hs->loss_of_signal_count -= lso->loss_of_signal_count;
6098 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6099 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6100 hs->invalid_crc_count -= lso->invalid_crc_count;
6101 hs->error_frames -= lso->error_frames;
6103 if (phba->hba_flag & HBA_FCOE_MODE) {
6105 hs->nos_count = (phba->link_events >> 1);
6106 hs->nos_count -= lso->link_events;
6107 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6108 hs->lip_count = (phba->fc_eventTag >> 1);
6109 hs->lip_count -= lso->link_events;
6113 hs->nos_count = (phba->fc_eventTag >> 1);
6114 hs->nos_count -= lso->link_events;
6117 hs->dumped_frames = -1;
6119 hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6121 mempool_free(pmboxq, phba->mbox_mem_pool);
6127 * lpfc_reset_stats - Copy the adapter link stats information
6128 * @shost: kernel scsi host pointer.
6131 lpfc_reset_stats(struct Scsi_Host *shost)
6133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6134 struct lpfc_hba *phba = vport->phba;
6135 struct lpfc_sli *psli = &phba->sli;
6136 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6137 LPFC_MBOXQ_t *pmboxq;
6141 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6144 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6147 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6149 pmb = &pmboxq->u.mb;
6150 pmb->mbxCommand = MBX_READ_STATUS;
6151 pmb->mbxOwner = OWN_HOST;
6152 pmb->un.varWords[0] = 0x1; /* reset request */
6153 pmboxq->context1 = NULL;
6154 pmboxq->vport = vport;
6156 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6157 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6158 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6160 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6162 if (rc != MBX_SUCCESS) {
6163 if (rc != MBX_TIMEOUT)
6164 mempool_free(pmboxq, phba->mbox_mem_pool);
6168 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6169 pmb->mbxCommand = MBX_READ_LNK_STAT;
6170 pmb->mbxOwner = OWN_HOST;
6171 pmboxq->context1 = NULL;
6172 pmboxq->vport = vport;
6174 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6175 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
6176 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6178 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6180 if (rc != MBX_SUCCESS) {
6181 if (rc != MBX_TIMEOUT)
6182 mempool_free( pmboxq, phba->mbox_mem_pool);
6186 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6187 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6188 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6189 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6190 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6191 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6192 lso->error_frames = pmb->un.varRdLnk.crcCnt;
6193 if (phba->hba_flag & HBA_FCOE_MODE)
6194 lso->link_events = (phba->link_events >> 1);
6196 lso->link_events = (phba->fc_eventTag >> 1);
6198 psli->stats_start = ktime_get_seconds();
6200 mempool_free(pmboxq, phba->mbox_mem_pool);
6206 * The LPFC driver treats linkdown handling as target loss events so there
6207 * are no sysfs handlers for link_down_tmo.
6211 * lpfc_get_node_by_target - Return the nodelist for a target
6212 * @starget: kernel scsi target pointer.
6215 * address of the node list if found
6216 * NULL target not found
6218 static struct lpfc_nodelist *
6219 lpfc_get_node_by_target(struct scsi_target *starget)
6221 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
6222 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6223 struct lpfc_nodelist *ndlp;
6225 spin_lock_irq(shost->host_lock);
6226 /* Search for this, mapped, target ID */
6227 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6228 if (NLP_CHK_NODE_ACT(ndlp) &&
6229 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6230 starget->id == ndlp->nlp_sid) {
6231 spin_unlock_irq(shost->host_lock);
6235 spin_unlock_irq(shost->host_lock);
6240 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6241 * @starget: kernel scsi target pointer.
6244 lpfc_get_starget_port_id(struct scsi_target *starget)
6246 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6248 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6252 * lpfc_get_starget_node_name - Set the target node name
6253 * @starget: kernel scsi target pointer.
6255 * Description: Set the target node name to the ndlp node name wwn or zero.
6258 lpfc_get_starget_node_name(struct scsi_target *starget)
6260 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6262 fc_starget_node_name(starget) =
6263 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6267 * lpfc_get_starget_port_name - Set the target port name
6268 * @starget: kernel scsi target pointer.
6270 * Description: set the target port name to the ndlp port name wwn or zero.
6273 lpfc_get_starget_port_name(struct scsi_target *starget)
6275 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6277 fc_starget_port_name(starget) =
6278 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6282 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6283 * @rport: fc rport address.
6284 * @timeout: new value for dev loss tmo.
6287 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6288 * dev_loss_tmo to one.
6291 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6294 rport->dev_loss_tmo = timeout;
6296 rport->dev_loss_tmo = 1;
6300 * lpfc_rport_show_function - Return rport target information
6303 * Macro that uses field to generate a function with the name lpfc_show_rport_
6305 * lpfc_show_rport_##field: returns the bytes formatted in buf
6306 * @cdev: class converted to an fc_rport.
6307 * @buf: on return contains the target_field or zero.
6309 * Returns: size of formatted string.
6311 #define lpfc_rport_show_function(field, format_string, sz, cast) \
6313 lpfc_show_rport_##field (struct device *dev, \
6314 struct device_attribute *attr, \
6317 struct fc_rport *rport = transport_class_to_rport(dev); \
6318 struct lpfc_rport_data *rdata = rport->hostdata; \
6319 return scnprintf(buf, sz, format_string, \
6320 (rdata->target) ? cast rdata->target->field : 0); \
6323 #define lpfc_rport_rd_attr(field, format_string, sz) \
6324 lpfc_rport_show_function(field, format_string, sz, ) \
6325 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6328 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6329 * @fc_vport: The fc_vport who's symbolic name has been changed.
6332 * This function is called by the transport after the @fc_vport's symbolic name
6333 * has been changed. This function re-registers the symbolic name with the
6334 * switch to propagate the change into the fabric if the vport is active.
6337 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6339 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6341 if (vport->port_state == LPFC_VPORT_READY)
6342 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6346 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6347 * @phba: Pointer to lpfc_hba struct.
6349 * This function is called by the lpfc_get_cfgparam() routine to set the
6350 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6351 * log message according to the module's lpfc_log_verbose parameter setting
6352 * before hba port or vport created.
6355 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6357 phba->cfg_log_verbose = verbose;
6360 struct fc_function_template lpfc_transport_functions = {
6361 /* fixed attributes the driver supports */
6362 .show_host_node_name = 1,
6363 .show_host_port_name = 1,
6364 .show_host_supported_classes = 1,
6365 .show_host_supported_fc4s = 1,
6366 .show_host_supported_speeds = 1,
6367 .show_host_maxframe_size = 1,
6369 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6370 .show_host_symbolic_name = 1,
6372 /* dynamic attributes the driver supports */
6373 .get_host_port_id = lpfc_get_host_port_id,
6374 .show_host_port_id = 1,
6376 .get_host_port_type = lpfc_get_host_port_type,
6377 .show_host_port_type = 1,
6379 .get_host_port_state = lpfc_get_host_port_state,
6380 .show_host_port_state = 1,
6382 /* active_fc4s is shown but doesn't change (thus no get function) */
6383 .show_host_active_fc4s = 1,
6385 .get_host_speed = lpfc_get_host_speed,
6386 .show_host_speed = 1,
6388 .get_host_fabric_name = lpfc_get_host_fabric_name,
6389 .show_host_fabric_name = 1,
6392 * The LPFC driver treats linkdown handling as target loss events
6393 * so there are no sysfs handlers for link_down_tmo.
6396 .get_fc_host_stats = lpfc_get_stats,
6397 .reset_fc_host_stats = lpfc_reset_stats,
6399 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6400 .show_rport_maxframe_size = 1,
6401 .show_rport_supported_classes = 1,
6403 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6404 .show_rport_dev_loss_tmo = 1,
6406 .get_starget_port_id = lpfc_get_starget_port_id,
6407 .show_starget_port_id = 1,
6409 .get_starget_node_name = lpfc_get_starget_node_name,
6410 .show_starget_node_name = 1,
6412 .get_starget_port_name = lpfc_get_starget_port_name,
6413 .show_starget_port_name = 1,
6415 .issue_fc_host_lip = lpfc_issue_lip,
6416 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6417 .terminate_rport_io = lpfc_terminate_rport_io,
6419 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6421 .vport_disable = lpfc_vport_disable,
6423 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6425 .bsg_request = lpfc_bsg_request,
6426 .bsg_timeout = lpfc_bsg_timeout,
6429 struct fc_function_template lpfc_vport_transport_functions = {
6430 /* fixed attributes the driver supports */
6431 .show_host_node_name = 1,
6432 .show_host_port_name = 1,
6433 .show_host_supported_classes = 1,
6434 .show_host_supported_fc4s = 1,
6435 .show_host_supported_speeds = 1,
6436 .show_host_maxframe_size = 1,
6438 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6439 .show_host_symbolic_name = 1,
6441 /* dynamic attributes the driver supports */
6442 .get_host_port_id = lpfc_get_host_port_id,
6443 .show_host_port_id = 1,
6445 .get_host_port_type = lpfc_get_host_port_type,
6446 .show_host_port_type = 1,
6448 .get_host_port_state = lpfc_get_host_port_state,
6449 .show_host_port_state = 1,
6451 /* active_fc4s is shown but doesn't change (thus no get function) */
6452 .show_host_active_fc4s = 1,
6454 .get_host_speed = lpfc_get_host_speed,
6455 .show_host_speed = 1,
6457 .get_host_fabric_name = lpfc_get_host_fabric_name,
6458 .show_host_fabric_name = 1,
6461 * The LPFC driver treats linkdown handling as target loss events
6462 * so there are no sysfs handlers for link_down_tmo.
6465 .get_fc_host_stats = lpfc_get_stats,
6466 .reset_fc_host_stats = lpfc_reset_stats,
6468 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6469 .show_rport_maxframe_size = 1,
6470 .show_rport_supported_classes = 1,
6472 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6473 .show_rport_dev_loss_tmo = 1,
6475 .get_starget_port_id = lpfc_get_starget_port_id,
6476 .show_starget_port_id = 1,
6478 .get_starget_node_name = lpfc_get_starget_node_name,
6479 .show_starget_node_name = 1,
6481 .get_starget_port_name = lpfc_get_starget_port_name,
6482 .show_starget_port_name = 1,
6484 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6485 .terminate_rport_io = lpfc_terminate_rport_io,
6487 .vport_disable = lpfc_vport_disable,
6489 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6493 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6494 * @phba: lpfc_hba pointer.
6497 lpfc_get_cfgparam(struct lpfc_hba *phba)
6499 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6500 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6501 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6502 lpfc_cr_count_init(phba, lpfc_cr_count);
6503 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6504 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6505 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6506 lpfc_ack0_init(phba, lpfc_ack0);
6507 lpfc_topology_init(phba, lpfc_topology);
6508 lpfc_link_speed_init(phba, lpfc_link_speed);
6509 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6510 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6511 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6512 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6513 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6514 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6515 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6516 lpfc_use_msi_init(phba, lpfc_use_msi);
6517 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6518 lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
6519 lpfc_auto_imax_init(phba, lpfc_auto_imax);
6520 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6521 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6522 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6523 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6525 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6526 if (phba->sli_rev != LPFC_SLI_REV4)
6527 phba->cfg_EnableXLane = 0;
6528 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6530 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6531 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6532 phba->cfg_oas_lun_state = 0;
6533 phba->cfg_oas_lun_status = 0;
6534 phba->cfg_oas_flags = 0;
6535 phba->cfg_oas_priority = 0;
6536 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6537 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6538 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6539 if (phba->sli_rev == LPFC_SLI_REV4)
6542 phba->cfg_poll = lpfc_poll;
6544 if (phba->cfg_enable_bg)
6545 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
6547 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6549 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6550 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6551 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
6553 /* Initialize first burst. Target vs Initiator are different. */
6554 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6555 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6556 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6557 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6558 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
6559 lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
6561 if (phba->sli_rev != LPFC_SLI_REV4) {
6562 /* NVME only supported on SLI4 */
6563 phba->nvmet_support = 0;
6564 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6565 phba->cfg_enable_bbcr = 0;
6567 /* We MUST have FCP support */
6568 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6569 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6572 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6573 phba->cfg_auto_imax = 0;
6574 phba->initial_imax = phba->cfg_fcp_imax;
6576 phba->cfg_enable_pbde = 0;
6578 /* A value of 0 means use the number of CPUs found in the system */
6579 if (phba->cfg_fcp_io_channel == 0)
6580 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6581 if (phba->cfg_nvme_io_channel == 0)
6582 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6584 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6585 phba->cfg_fcp_io_channel = 0;
6587 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6588 phba->cfg_nvme_io_channel = 0;
6590 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6591 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6593 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6595 phba->cfg_soft_wwnn = 0L;
6596 phba->cfg_soft_wwpn = 0L;
6597 lpfc_xri_split_init(phba, lpfc_xri_split);
6598 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6599 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6600 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6601 lpfc_aer_support_init(phba, lpfc_aer_support);
6602 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6603 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6604 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6605 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6606 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6607 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6608 phba->cfg_enable_dss = 1;
6609 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6614 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6615 * dependencies between protocols and roles.
6616 * @phba: lpfc_hba pointer.
6619 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6621 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6622 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6624 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6625 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6627 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6628 phba->nvmet_support) {
6629 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6630 phba->cfg_fcp_io_channel = 0;
6632 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6633 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6634 "NVME Target PRLI ACC enable_fb ",
6635 phba->cfg_nvme_enable_fb,
6636 phba->cfg_nvmet_fb_size,
6637 LPFC_NVMET_FB_SZ_MAX);
6639 if (phba->cfg_nvme_enable_fb == 0)
6640 phba->cfg_nvmet_fb_size = 0;
6642 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6643 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6646 if (!phba->cfg_nvmet_mrq)
6647 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6649 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6650 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6651 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6652 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6653 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6654 phba->cfg_nvmet_mrq);
6656 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
6657 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
6660 /* Not NVME Target mode. Turn off Target parameters. */
6661 phba->nvmet_support = 0;
6662 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
6663 phba->cfg_nvmet_fb_size = 0;
6666 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6667 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6669 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6673 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6674 * @vport: lpfc_vport pointer.
6677 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6679 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6680 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6681 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6682 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6683 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6684 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6685 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6686 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6687 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6688 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6689 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6690 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6691 lpfc_max_luns_init(vport, lpfc_max_luns);
6692 lpfc_scan_down_init(vport, lpfc_scan_down);
6693 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);