1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/ctype.h>
25 #include <linux/delay.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/aer.h>
30 #include <linux/gfp.h>
31 #include <linux/kernel.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_tcq.h>
37 #include <scsi/scsi_transport_fc.h>
38 #include <scsi/fc/fc_fs.h>
43 #include "lpfc_sli4.h"
45 #include "lpfc_disc.h"
47 #include "lpfc_scsi.h"
48 #include "lpfc_nvme.h"
49 #include "lpfc_logmsg.h"
50 #include "lpfc_version.h"
51 #include "lpfc_compat.h"
52 #include "lpfc_crtn.h"
53 #include "lpfc_vport.h"
54 #include "lpfc_attr.h"
56 #define LPFC_DEF_DEVLOSS_TMO 30
57 #define LPFC_MIN_DEVLOSS_TMO 1
58 #define LPFC_MAX_DEVLOSS_TMO 255
61 * Write key size should be multiple of 4. If write key is changed
62 * make sure that library write key is also changed.
64 #define LPFC_REG_WRITE_KEY_SIZE 4
65 #define LPFC_REG_WRITE_KEY "EMLX"
67 const char *const trunk_errmsg
[] = { /* map errcode */
68 "", /* There is no such error code at index 0*/
69 "link negotiated speed does not match existing"
70 " trunk - link was \"low\" speed",
71 "link negotiated speed does not match"
72 " existing trunk - link was \"middle\" speed",
73 "link negotiated speed does not match existing"
74 " trunk - link was \"high\" speed",
75 "Attached to non-trunking port - F_Port",
76 "Attached to non-trunking port - N_Port",
77 "FLOGI response timeout",
78 "non-FLOGI frame received",
79 "Invalid FLOGI response",
80 "Trunking initialization protocol",
81 "Trunk peer device mismatch",
85 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
86 * @incr: integer to convert.
87 * @hdw: ascii string holding converted integer plus a string terminator.
90 * JEDEC Joint Electron Device Engineering Council.
91 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
92 * character string. The string is then terminated with a NULL in byte 9.
93 * Hex 0-9 becomes ascii '0' to '9'.
94 * Hex a-f becomes ascii '=' to 'B' capital B.
97 * Coded for 32 bit integers only.
100 lpfc_jedec_to_ascii(int incr
, char hdw
[])
103 for (i
= 0; i
< 8; i
++) {
106 hdw
[7 - i
] = 0x30 + j
;
108 hdw
[7 - i
] = 0x61 + j
- 10;
116 * lpfc_drvr_version_show - Return the Emulex driver string with version number
117 * @dev: class unused variable.
118 * @attr: device attribute, not used.
119 * @buf: on return contains the module description text.
121 * Returns: size of formatted string.
124 lpfc_drvr_version_show(struct device
*dev
, struct device_attribute
*attr
,
127 return scnprintf(buf
, PAGE_SIZE
, LPFC_MODULE_DESC
"\n");
131 * lpfc_enable_fip_show - Return the fip mode of the HBA
132 * @dev: class unused variable.
133 * @attr: device attribute, not used.
134 * @buf: on return contains the module description text.
136 * Returns: size of formatted string.
139 lpfc_enable_fip_show(struct device
*dev
, struct device_attribute
*attr
,
142 struct Scsi_Host
*shost
= class_to_shost(dev
);
143 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
144 struct lpfc_hba
*phba
= vport
->phba
;
146 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
147 return scnprintf(buf
, PAGE_SIZE
, "1\n");
149 return scnprintf(buf
, PAGE_SIZE
, "0\n");
153 lpfc_nvme_info_show(struct device
*dev
, struct device_attribute
*attr
,
156 struct Scsi_Host
*shost
= class_to_shost(dev
);
157 struct lpfc_vport
*vport
= shost_priv(shost
);
158 struct lpfc_hba
*phba
= vport
->phba
;
159 struct lpfc_nvmet_tgtport
*tgtp
;
160 struct nvme_fc_local_port
*localport
;
161 struct lpfc_nvme_lport
*lport
;
162 struct lpfc_nvme_rport
*rport
;
163 struct lpfc_nodelist
*ndlp
;
164 struct nvme_fc_remote_port
*nrport
;
165 struct lpfc_fc4_ctrl_stat
*cstat
;
166 uint64_t data1
, data2
, data3
;
167 uint64_t totin
, totout
, tot
;
171 char tmp
[LPFC_MAX_NVME_INFO_TMP_LEN
] = {0};
173 if (!(vport
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
)) {
174 len
= scnprintf(buf
, PAGE_SIZE
, "NVME Disabled\n");
177 if (phba
->nvmet_support
) {
178 if (!phba
->targetport
) {
179 len
= scnprintf(buf
, PAGE_SIZE
,
180 "NVME Target: x%llx is not allocated\n",
181 wwn_to_u64(vport
->fc_portname
.u
.wwn
));
184 /* Port state is only one of two values for now. */
185 if (phba
->targetport
->port_id
)
186 statep
= "REGISTERED";
189 scnprintf(tmp
, sizeof(tmp
),
190 "NVME Target Enabled State %s\n",
192 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
195 scnprintf(tmp
, sizeof(tmp
),
196 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
199 wwn_to_u64(vport
->fc_portname
.u
.wwn
),
200 wwn_to_u64(vport
->fc_nodename
.u
.wwn
),
201 phba
->targetport
->port_id
);
202 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
205 if (strlcat(buf
, "\nNVME Target: Statistics\n", PAGE_SIZE
)
209 tgtp
= (struct lpfc_nvmet_tgtport
*)phba
->targetport
->private;
210 scnprintf(tmp
, sizeof(tmp
),
211 "LS: Rcv %08x Drop %08x Abort %08x\n",
212 atomic_read(&tgtp
->rcv_ls_req_in
),
213 atomic_read(&tgtp
->rcv_ls_req_drop
),
214 atomic_read(&tgtp
->xmt_ls_abort
));
215 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
218 if (atomic_read(&tgtp
->rcv_ls_req_in
) !=
219 atomic_read(&tgtp
->rcv_ls_req_out
)) {
220 scnprintf(tmp
, sizeof(tmp
),
221 "Rcv LS: in %08x != out %08x\n",
222 atomic_read(&tgtp
->rcv_ls_req_in
),
223 atomic_read(&tgtp
->rcv_ls_req_out
));
224 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
228 scnprintf(tmp
, sizeof(tmp
),
229 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
230 atomic_read(&tgtp
->xmt_ls_rsp
),
231 atomic_read(&tgtp
->xmt_ls_drop
),
232 atomic_read(&tgtp
->xmt_ls_rsp_cmpl
));
233 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
236 scnprintf(tmp
, sizeof(tmp
),
237 "LS: RSP Abort %08x xb %08x Err %08x\n",
238 atomic_read(&tgtp
->xmt_ls_rsp_aborted
),
239 atomic_read(&tgtp
->xmt_ls_rsp_xb_set
),
240 atomic_read(&tgtp
->xmt_ls_rsp_error
));
241 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
244 scnprintf(tmp
, sizeof(tmp
),
245 "FCP: Rcv %08x Defer %08x Release %08x "
247 atomic_read(&tgtp
->rcv_fcp_cmd_in
),
248 atomic_read(&tgtp
->rcv_fcp_cmd_defer
),
249 atomic_read(&tgtp
->xmt_fcp_release
),
250 atomic_read(&tgtp
->rcv_fcp_cmd_drop
));
251 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
254 if (atomic_read(&tgtp
->rcv_fcp_cmd_in
) !=
255 atomic_read(&tgtp
->rcv_fcp_cmd_out
)) {
256 scnprintf(tmp
, sizeof(tmp
),
257 "Rcv FCP: in %08x != out %08x\n",
258 atomic_read(&tgtp
->rcv_fcp_cmd_in
),
259 atomic_read(&tgtp
->rcv_fcp_cmd_out
));
260 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
264 scnprintf(tmp
, sizeof(tmp
),
265 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
267 atomic_read(&tgtp
->xmt_fcp_read
),
268 atomic_read(&tgtp
->xmt_fcp_read_rsp
),
269 atomic_read(&tgtp
->xmt_fcp_write
),
270 atomic_read(&tgtp
->xmt_fcp_rsp
),
271 atomic_read(&tgtp
->xmt_fcp_drop
));
272 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
275 scnprintf(tmp
, sizeof(tmp
),
276 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
277 atomic_read(&tgtp
->xmt_fcp_rsp_cmpl
),
278 atomic_read(&tgtp
->xmt_fcp_rsp_error
),
279 atomic_read(&tgtp
->xmt_fcp_rsp_drop
));
280 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
283 scnprintf(tmp
, sizeof(tmp
),
284 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
285 atomic_read(&tgtp
->xmt_fcp_rsp_aborted
),
286 atomic_read(&tgtp
->xmt_fcp_rsp_xb_set
),
287 atomic_read(&tgtp
->xmt_fcp_xri_abort_cqe
));
288 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
291 scnprintf(tmp
, sizeof(tmp
),
292 "ABORT: Xmt %08x Cmpl %08x\n",
293 atomic_read(&tgtp
->xmt_fcp_abort
),
294 atomic_read(&tgtp
->xmt_fcp_abort_cmpl
));
295 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
298 scnprintf(tmp
, sizeof(tmp
),
299 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
300 atomic_read(&tgtp
->xmt_abort_sol
),
301 atomic_read(&tgtp
->xmt_abort_unsol
),
302 atomic_read(&tgtp
->xmt_abort_rsp
),
303 atomic_read(&tgtp
->xmt_abort_rsp_error
));
304 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
307 scnprintf(tmp
, sizeof(tmp
),
308 "DELAY: ctx %08x fod %08x wqfull %08x\n",
309 atomic_read(&tgtp
->defer_ctx
),
310 atomic_read(&tgtp
->defer_fod
),
311 atomic_read(&tgtp
->defer_wqfull
));
312 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
315 /* Calculate outstanding IOs */
316 tot
= atomic_read(&tgtp
->rcv_fcp_cmd_drop
);
317 tot
+= atomic_read(&tgtp
->xmt_fcp_release
);
318 tot
= atomic_read(&tgtp
->rcv_fcp_cmd_in
) - tot
;
320 scnprintf(tmp
, sizeof(tmp
),
321 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
322 "CTX Outstanding %08llx\n\n",
323 phba
->sli4_hba
.nvmet_xri_cnt
,
324 phba
->sli4_hba
.nvmet_io_wait_cnt
,
325 phba
->sli4_hba
.nvmet_io_wait_total
,
327 strlcat(buf
, tmp
, PAGE_SIZE
);
331 localport
= vport
->localport
;
333 len
= scnprintf(buf
, PAGE_SIZE
,
334 "NVME Initiator x%llx is not allocated\n",
335 wwn_to_u64(vport
->fc_portname
.u
.wwn
));
338 lport
= (struct lpfc_nvme_lport
*)localport
->private;
339 if (strlcat(buf
, "\nNVME Initiator Enabled\n", PAGE_SIZE
) >= PAGE_SIZE
)
342 scnprintf(tmp
, sizeof(tmp
),
343 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
345 phba
->sli4_hba
.max_cfg_param
.max_xri
,
346 phba
->sli4_hba
.io_xri_max
,
347 lpfc_sli4_get_els_iocb_cnt(phba
));
348 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
351 /* Port state is only one of two values for now. */
352 if (localport
->port_id
)
357 scnprintf(tmp
, sizeof(tmp
),
358 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
361 wwn_to_u64(vport
->fc_portname
.u
.wwn
),
362 wwn_to_u64(vport
->fc_nodename
.u
.wwn
),
363 localport
->port_id
, statep
);
364 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
367 spin_lock_irq(shost
->host_lock
);
369 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
371 spin_lock(&ndlp
->lock
);
372 rport
= lpfc_ndlp_get_nrport(ndlp
);
374 nrport
= rport
->remoteport
;
375 spin_unlock(&ndlp
->lock
);
379 /* Port state is only one of two values for now. */
380 switch (nrport
->port_state
) {
381 case FC_OBJSTATE_ONLINE
:
384 case FC_OBJSTATE_UNKNOWN
:
388 statep
= "UNSUPPORTED";
392 /* Tab in to show lport ownership. */
393 if (strlcat(buf
, "NVME RPORT ", PAGE_SIZE
) >= PAGE_SIZE
)
394 goto unlock_buf_done
;
395 if (phba
->brd_no
>= 10) {
396 if (strlcat(buf
, " ", PAGE_SIZE
) >= PAGE_SIZE
)
397 goto unlock_buf_done
;
400 scnprintf(tmp
, sizeof(tmp
), "WWPN x%llx ",
402 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
403 goto unlock_buf_done
;
405 scnprintf(tmp
, sizeof(tmp
), "WWNN x%llx ",
407 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
408 goto unlock_buf_done
;
410 scnprintf(tmp
, sizeof(tmp
), "DID x%06x ",
412 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
413 goto unlock_buf_done
;
415 /* An NVME rport can have multiple roles. */
416 if (nrport
->port_role
& FC_PORT_ROLE_NVME_INITIATOR
) {
417 if (strlcat(buf
, "INITIATOR ", PAGE_SIZE
) >= PAGE_SIZE
)
418 goto unlock_buf_done
;
420 if (nrport
->port_role
& FC_PORT_ROLE_NVME_TARGET
) {
421 if (strlcat(buf
, "TARGET ", PAGE_SIZE
) >= PAGE_SIZE
)
422 goto unlock_buf_done
;
424 if (nrport
->port_role
& FC_PORT_ROLE_NVME_DISCOVERY
) {
425 if (strlcat(buf
, "DISCSRVC ", PAGE_SIZE
) >= PAGE_SIZE
)
426 goto unlock_buf_done
;
428 if (nrport
->port_role
& ~(FC_PORT_ROLE_NVME_INITIATOR
|
429 FC_PORT_ROLE_NVME_TARGET
|
430 FC_PORT_ROLE_NVME_DISCOVERY
)) {
431 scnprintf(tmp
, sizeof(tmp
), "UNKNOWN ROLE x%x",
433 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
434 goto unlock_buf_done
;
437 scnprintf(tmp
, sizeof(tmp
), "%s\n", statep
);
438 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
439 goto unlock_buf_done
;
441 spin_unlock_irq(shost
->host_lock
);
446 if (strlcat(buf
, "\nNVME Statistics\n", PAGE_SIZE
) >= PAGE_SIZE
)
449 scnprintf(tmp
, sizeof(tmp
),
450 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
451 atomic_read(&lport
->fc4NvmeLsRequests
),
452 atomic_read(&lport
->fc4NvmeLsCmpls
),
453 atomic_read(&lport
->xmt_ls_abort
));
454 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
457 scnprintf(tmp
, sizeof(tmp
),
458 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
459 atomic_read(&lport
->xmt_ls_err
),
460 atomic_read(&lport
->cmpl_ls_xb
),
461 atomic_read(&lport
->cmpl_ls_err
));
462 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
467 for (i
= 0; i
< phba
->cfg_hdw_queue
; i
++) {
468 cstat
= &phba
->sli4_hba
.hdwq
[i
].nvme_cstat
;
469 tot
= cstat
->io_cmpls
;
471 data1
= cstat
->input_requests
;
472 data2
= cstat
->output_requests
;
473 data3
= cstat
->control_requests
;
474 totout
+= (data1
+ data2
+ data3
);
476 scnprintf(tmp
, sizeof(tmp
),
477 "Total FCP Cmpl %016llx Issue %016llx "
479 totin
, totout
, totout
- totin
);
480 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
483 scnprintf(tmp
, sizeof(tmp
),
484 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
485 "wqerr %08x err %08x\n",
486 atomic_read(&lport
->xmt_fcp_abort
),
487 atomic_read(&lport
->xmt_fcp_noxri
),
488 atomic_read(&lport
->xmt_fcp_bad_ndlp
),
489 atomic_read(&lport
->xmt_fcp_qdepth
),
490 atomic_read(&lport
->xmt_fcp_err
),
491 atomic_read(&lport
->xmt_fcp_wqerr
));
492 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
495 scnprintf(tmp
, sizeof(tmp
),
496 "FCP CMPL: xb %08x Err %08x\n",
497 atomic_read(&lport
->cmpl_fcp_xb
),
498 atomic_read(&lport
->cmpl_fcp_err
));
499 strlcat(buf
, tmp
, PAGE_SIZE
);
501 /* host_lock is already unlocked. */
505 spin_unlock_irq(shost
->host_lock
);
508 len
= strnlen(buf
, PAGE_SIZE
);
510 if (unlikely(len
>= (PAGE_SIZE
- 1))) {
511 lpfc_printf_log(phba
, KERN_INFO
, LOG_NVME
,
512 "6314 Catching potential buffer "
513 "overflow > PAGE_SIZE = %lu bytes\n",
515 strlcpy(buf
+ PAGE_SIZE
- 1 -
516 strnlen(LPFC_NVME_INFO_MORE_STR
, PAGE_SIZE
- 1),
517 LPFC_NVME_INFO_MORE_STR
,
518 strnlen(LPFC_NVME_INFO_MORE_STR
, PAGE_SIZE
- 1)
526 lpfc_scsi_stat_show(struct device
*dev
, struct device_attribute
*attr
,
529 struct Scsi_Host
*shost
= class_to_shost(dev
);
530 struct lpfc_vport
*vport
= shost_priv(shost
);
531 struct lpfc_hba
*phba
= vport
->phba
;
533 struct lpfc_fc4_ctrl_stat
*cstat
;
534 u64 data1
, data2
, data3
;
535 u64 tot
, totin
, totout
;
537 char tmp
[LPFC_MAX_SCSI_INFO_TMP_LEN
] = {0};
539 if (!(vport
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) ||
540 (phba
->sli_rev
!= LPFC_SLI_REV4
))
543 scnprintf(buf
, PAGE_SIZE
, "SCSI HDWQ Statistics\n");
547 for (i
= 0; i
< phba
->cfg_hdw_queue
; i
++) {
548 cstat
= &phba
->sli4_hba
.hdwq
[i
].scsi_cstat
;
549 tot
= cstat
->io_cmpls
;
551 data1
= cstat
->input_requests
;
552 data2
= cstat
->output_requests
;
553 data3
= cstat
->control_requests
;
554 totout
+= (data1
+ data2
+ data3
);
556 scnprintf(tmp
, sizeof(tmp
), "HDWQ (%d): Rd %016llx Wr %016llx "
557 "IO %016llx ", i
, data1
, data2
, data3
);
558 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
561 scnprintf(tmp
, sizeof(tmp
), "Cmpl %016llx OutIO %016llx\n",
562 tot
, ((data1
+ data2
+ data3
) - tot
));
563 if (strlcat(buf
, tmp
, PAGE_SIZE
) >= PAGE_SIZE
)
566 scnprintf(tmp
, sizeof(tmp
), "Total FCP Cmpl %016llx Issue %016llx "
567 "OutIO %016llx\n", totin
, totout
, totout
- totin
);
568 strlcat(buf
, tmp
, PAGE_SIZE
);
571 len
= strnlen(buf
, PAGE_SIZE
);
577 lpfc_bg_info_show(struct device
*dev
, struct device_attribute
*attr
,
580 struct Scsi_Host
*shost
= class_to_shost(dev
);
581 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
582 struct lpfc_hba
*phba
= vport
->phba
;
584 if (phba
->cfg_enable_bg
) {
585 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
586 return scnprintf(buf
, PAGE_SIZE
,
587 "BlockGuard Enabled\n");
589 return scnprintf(buf
, PAGE_SIZE
,
590 "BlockGuard Not Supported\n");
592 return scnprintf(buf
, PAGE_SIZE
,
593 "BlockGuard Disabled\n");
597 lpfc_bg_guard_err_show(struct device
*dev
, struct device_attribute
*attr
,
600 struct Scsi_Host
*shost
= class_to_shost(dev
);
601 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
602 struct lpfc_hba
*phba
= vport
->phba
;
604 return scnprintf(buf
, PAGE_SIZE
, "%llu\n",
605 (unsigned long long)phba
->bg_guard_err_cnt
);
609 lpfc_bg_apptag_err_show(struct device
*dev
, struct device_attribute
*attr
,
612 struct Scsi_Host
*shost
= class_to_shost(dev
);
613 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
614 struct lpfc_hba
*phba
= vport
->phba
;
616 return scnprintf(buf
, PAGE_SIZE
, "%llu\n",
617 (unsigned long long)phba
->bg_apptag_err_cnt
);
621 lpfc_bg_reftag_err_show(struct device
*dev
, struct device_attribute
*attr
,
624 struct Scsi_Host
*shost
= class_to_shost(dev
);
625 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
626 struct lpfc_hba
*phba
= vport
->phba
;
628 return scnprintf(buf
, PAGE_SIZE
, "%llu\n",
629 (unsigned long long)phba
->bg_reftag_err_cnt
);
633 * lpfc_info_show - Return some pci info about the host in ascii
634 * @dev: class converted to a Scsi_host structure.
635 * @attr: device attribute, not used.
636 * @buf: on return contains the formatted text from lpfc_info().
638 * Returns: size of formatted string.
641 lpfc_info_show(struct device
*dev
, struct device_attribute
*attr
,
644 struct Scsi_Host
*host
= class_to_shost(dev
);
646 return scnprintf(buf
, PAGE_SIZE
, "%s\n", lpfc_info(host
));
650 * lpfc_serialnum_show - Return the hba serial number in ascii
651 * @dev: class converted to a Scsi_host structure.
652 * @attr: device attribute, not used.
653 * @buf: on return contains the formatted text serial number.
655 * Returns: size of formatted string.
658 lpfc_serialnum_show(struct device
*dev
, struct device_attribute
*attr
,
661 struct Scsi_Host
*shost
= class_to_shost(dev
);
662 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
663 struct lpfc_hba
*phba
= vport
->phba
;
665 return scnprintf(buf
, PAGE_SIZE
, "%s\n", phba
->SerialNumber
);
669 * lpfc_temp_sensor_show - Return the temperature sensor level
670 * @dev: class converted to a Scsi_host structure.
671 * @attr: device attribute, not used.
672 * @buf: on return contains the formatted support level.
675 * Returns a number indicating the temperature sensor level currently
676 * supported, zero or one in ascii.
678 * Returns: size of formatted string.
681 lpfc_temp_sensor_show(struct device
*dev
, struct device_attribute
*attr
,
684 struct Scsi_Host
*shost
= class_to_shost(dev
);
685 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
686 struct lpfc_hba
*phba
= vport
->phba
;
687 return scnprintf(buf
, PAGE_SIZE
, "%d\n", phba
->temp_sensor_support
);
691 * lpfc_modeldesc_show - Return the model description of the hba
692 * @dev: class converted to a Scsi_host structure.
693 * @attr: device attribute, not used.
694 * @buf: on return contains the scsi vpd model description.
696 * Returns: size of formatted string.
699 lpfc_modeldesc_show(struct device
*dev
, struct device_attribute
*attr
,
702 struct Scsi_Host
*shost
= class_to_shost(dev
);
703 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
704 struct lpfc_hba
*phba
= vport
->phba
;
706 return scnprintf(buf
, PAGE_SIZE
, "%s\n", phba
->ModelDesc
);
710 * lpfc_modelname_show - Return the model name of the hba
711 * @dev: class converted to a Scsi_host structure.
712 * @attr: device attribute, not used.
713 * @buf: on return contains the scsi vpd model name.
715 * Returns: size of formatted string.
718 lpfc_modelname_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
->ModelName
);
729 * lpfc_programtype_show - Return the program type of 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_programtype_show(struct device
*dev
, struct device_attribute
*attr
,
740 struct Scsi_Host
*shost
= class_to_shost(dev
);
741 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
742 struct lpfc_hba
*phba
= vport
->phba
;
744 return scnprintf(buf
, PAGE_SIZE
, "%s\n", phba
->ProgramType
);
748 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
749 * @dev: class converted to a Scsi_host structure.
750 * @attr: device attribute, not used.
751 * @buf: on return contains the Menlo Maintenance sli flag.
753 * Returns: size of formatted string.
756 lpfc_mlomgmt_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
758 struct Scsi_Host
*shost
= class_to_shost(dev
);
759 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
760 struct lpfc_hba
*phba
= vport
->phba
;
762 return scnprintf(buf
, PAGE_SIZE
, "%d\n",
763 (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
));
767 * lpfc_vportnum_show - Return the port number in ascii of the hba
768 * @dev: class converted to a Scsi_host structure.
769 * @attr: device attribute, not used.
770 * @buf: on return contains scsi vpd program type.
772 * Returns: size of formatted string.
775 lpfc_vportnum_show(struct device
*dev
, struct device_attribute
*attr
,
778 struct Scsi_Host
*shost
= class_to_shost(dev
);
779 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
780 struct lpfc_hba
*phba
= vport
->phba
;
782 return scnprintf(buf
, PAGE_SIZE
, "%s\n", phba
->Port
);
786 * lpfc_fwrev_show - Return the firmware rev running in the hba
787 * @dev: class converted to a Scsi_host structure.
788 * @attr: device attribute, not used.
789 * @buf: on return contains the scsi vpd program type.
791 * Returns: size of formatted string.
794 lpfc_fwrev_show(struct device
*dev
, struct device_attribute
*attr
,
797 struct Scsi_Host
*shost
= class_to_shost(dev
);
798 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
799 struct lpfc_hba
*phba
= vport
->phba
;
802 char fwrev
[FW_REV_STR_SIZE
];
805 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
806 if_type
= phba
->sli4_hba
.pc_sli4_params
.if_type
;
807 sli_family
= phba
->sli4_hba
.pc_sli4_params
.sli_family
;
809 if (phba
->sli_rev
< LPFC_SLI_REV4
)
810 len
= scnprintf(buf
, PAGE_SIZE
, "%s, sli-%d\n",
811 fwrev
, phba
->sli_rev
);
813 len
= scnprintf(buf
, PAGE_SIZE
, "%s, sli-%d:%d:%x\n",
814 fwrev
, phba
->sli_rev
, if_type
, sli_family
);
820 * lpfc_hdw_show - Return the jedec information about the hba
821 * @dev: class converted to a Scsi_host structure.
822 * @attr: device attribute, not used.
823 * @buf: on return contains the scsi vpd program type.
825 * Returns: size of formatted string.
828 lpfc_hdw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
831 struct Scsi_Host
*shost
= class_to_shost(dev
);
832 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
833 struct lpfc_hba
*phba
= vport
->phba
;
834 lpfc_vpd_t
*vp
= &phba
->vpd
;
836 lpfc_jedec_to_ascii(vp
->rev
.biuRev
, hdw
);
837 return scnprintf(buf
, PAGE_SIZE
, "%s %08x %08x\n", hdw
,
838 vp
->rev
.smRev
, vp
->rev
.smFwRev
);
842 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
843 * @dev: class converted to a Scsi_host structure.
844 * @attr: device attribute, not used.
845 * @buf: on return contains the ROM and FCode ascii strings.
847 * Returns: size of formatted string.
850 lpfc_option_rom_version_show(struct device
*dev
, struct device_attribute
*attr
,
853 struct Scsi_Host
*shost
= class_to_shost(dev
);
854 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
855 struct lpfc_hba
*phba
= vport
->phba
;
856 char fwrev
[FW_REV_STR_SIZE
];
858 if (phba
->sli_rev
< LPFC_SLI_REV4
)
859 return scnprintf(buf
, PAGE_SIZE
, "%s\n",
860 phba
->OptionROMVersion
);
862 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
863 return scnprintf(buf
, PAGE_SIZE
, "%s\n", fwrev
);
867 * lpfc_state_show - Return the link state of the port
868 * @dev: class converted to a Scsi_host structure.
869 * @attr: device attribute, not used.
870 * @buf: on return contains text describing the state of the link.
873 * The switch statement has no default so zero will be returned.
875 * Returns: size of formatted string.
878 lpfc_link_state_show(struct device
*dev
, struct device_attribute
*attr
,
881 struct Scsi_Host
*shost
= class_to_shost(dev
);
882 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
883 struct lpfc_hba
*phba
= vport
->phba
;
886 switch (phba
->link_state
) {
887 case LPFC_LINK_UNKNOWN
:
888 case LPFC_WARM_START
:
889 case LPFC_INIT_START
:
890 case LPFC_INIT_MBX_CMDS
:
893 if (phba
->hba_flag
& LINK_DISABLED
)
894 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
895 "Link Down - User disabled\n");
897 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
903 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "Link Up - ");
905 switch (vport
->port_state
) {
906 case LPFC_LOCAL_CFG_LINK
:
907 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
908 "Configuring Link\n");
912 case LPFC_FABRIC_CFG_LINK
:
915 case LPFC_BUILD_DISC_LIST
:
917 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
,
920 case LPFC_VPORT_READY
:
921 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
,
925 case LPFC_VPORT_FAILED
:
926 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
,
930 case LPFC_VPORT_UNKNOWN
:
931 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
,
935 if (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
)
936 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
937 " Menlo Maint Mode\n");
938 else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
939 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
940 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
943 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
946 if (vport
->fc_flag
& FC_FABRIC
)
947 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
950 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
955 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
956 ((bf_get(lpfc_sli_intf_if_type
,
957 &phba
->sli4_hba
.sli_intf
) ==
958 LPFC_SLI_INTF_IF_TYPE_6
))) {
959 struct lpfc_trunk_link link
= phba
->trunk_link
;
961 if (bf_get(lpfc_conf_trunk_port0
, &phba
->sli4_hba
))
962 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
,
963 "Trunk port 0: Link %s %s\n",
964 (link
.link0
.state
== LPFC_LINK_UP
) ?
966 trunk_errmsg
[link
.link0
.fault
]);
968 if (bf_get(lpfc_conf_trunk_port1
, &phba
->sli4_hba
))
969 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
,
970 "Trunk port 1: Link %s %s\n",
971 (link
.link1
.state
== LPFC_LINK_UP
) ?
973 trunk_errmsg
[link
.link1
.fault
]);
975 if (bf_get(lpfc_conf_trunk_port2
, &phba
->sli4_hba
))
976 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
,
977 "Trunk port 2: Link %s %s\n",
978 (link
.link2
.state
== LPFC_LINK_UP
) ?
980 trunk_errmsg
[link
.link2
.fault
]);
982 if (bf_get(lpfc_conf_trunk_port3
, &phba
->sli4_hba
))
983 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
,
984 "Trunk port 3: Link %s %s\n",
985 (link
.link3
.state
== LPFC_LINK_UP
) ?
987 trunk_errmsg
[link
.link3
.fault
]);
995 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
996 * @dev: class unused variable.
997 * @attr: device attribute, not used.
998 * @buf: on return contains the module description text.
1000 * Returns: size of formatted string.
1003 lpfc_sli4_protocol_show(struct device
*dev
, struct device_attribute
*attr
,
1006 struct Scsi_Host
*shost
= class_to_shost(dev
);
1007 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1008 struct lpfc_hba
*phba
= vport
->phba
;
1010 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1011 return scnprintf(buf
, PAGE_SIZE
, "fc\n");
1013 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
) {
1014 if (phba
->sli4_hba
.lnk_info
.lnk_tp
== LPFC_LNK_TYPE_GE
)
1015 return scnprintf(buf
, PAGE_SIZE
, "fcoe\n");
1016 if (phba
->sli4_hba
.lnk_info
.lnk_tp
== LPFC_LNK_TYPE_FC
)
1017 return scnprintf(buf
, PAGE_SIZE
, "fc\n");
1019 return scnprintf(buf
, PAGE_SIZE
, "unknown\n");
1023 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1024 * (OAS) is supported.
1025 * @dev: class unused variable.
1026 * @attr: device attribute, not used.
1027 * @buf: on return contains the module description text.
1029 * Returns: size of formatted string.
1032 lpfc_oas_supported_show(struct device
*dev
, struct device_attribute
*attr
,
1035 struct Scsi_Host
*shost
= class_to_shost(dev
);
1036 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
1037 struct lpfc_hba
*phba
= vport
->phba
;
1039 return scnprintf(buf
, PAGE_SIZE
, "%d\n",
1040 phba
->sli4_hba
.pc_sli4_params
.oas_supported
);
1044 * lpfc_link_state_store - Transition the link_state on an HBA port
1045 * @dev: class device that is converted into a Scsi_host.
1046 * @attr: device attribute, not used.
1047 * @buf: one or more lpfc_polling_flags values.
1051 * -EINVAL if the buffer is not "up" or "down"
1052 * return from link state change function if non-zero
1053 * length of the buf on success
1056 lpfc_link_state_store(struct device
*dev
, struct device_attribute
*attr
,
1057 const char *buf
, size_t count
)
1059 struct Scsi_Host
*shost
= class_to_shost(dev
);
1060 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1061 struct lpfc_hba
*phba
= vport
->phba
;
1063 int status
= -EINVAL
;
1065 if ((strncmp(buf
, "up", sizeof("up") - 1) == 0) &&
1066 (phba
->link_state
== LPFC_LINK_DOWN
))
1067 status
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
1068 else if ((strncmp(buf
, "down", sizeof("down") - 1) == 0) &&
1069 (phba
->link_state
>= LPFC_LINK_UP
))
1070 status
= phba
->lpfc_hba_down_link(phba
, MBX_NOWAIT
);
1079 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1080 * @dev: class device that is converted into a Scsi_host.
1081 * @attr: device attribute, not used.
1082 * @buf: on return contains the sum of fc mapped and unmapped.
1085 * Returns the ascii text number of the sum of the fc mapped and unmapped
1088 * Returns: size of formatted string.
1091 lpfc_num_discovered_ports_show(struct device
*dev
,
1092 struct device_attribute
*attr
, char *buf
)
1094 struct Scsi_Host
*shost
= class_to_shost(dev
);
1095 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1097 return scnprintf(buf
, PAGE_SIZE
, "%d\n",
1098 vport
->fc_map_cnt
+ vport
->fc_unmap_cnt
);
1102 * lpfc_issue_lip - Misnomer, name carried over from long ago
1103 * @shost: Scsi_Host pointer.
1106 * Bring the link down gracefully then re-init the link. The firmware will
1107 * re-init the fiber channel interface as required. Does not issue a LIP.
1110 * -EPERM port offline or management commands are being blocked
1111 * -ENOMEM cannot allocate memory for the mailbox command
1112 * -EIO error sending the mailbox command
1116 lpfc_issue_lip(struct Scsi_Host
*shost
)
1118 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1119 struct lpfc_hba
*phba
= vport
->phba
;
1120 LPFC_MBOXQ_t
*pmboxq
;
1121 int mbxstatus
= MBXERR_ERROR
;
1124 * If the link is offline, disabled or BLOCK_MGMT_IO
1125 * it doesn't make any sense to allow issue_lip
1127 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
1128 (phba
->hba_flag
& LINK_DISABLED
) ||
1129 (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
))
1132 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
1137 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
1138 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
1139 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
1141 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
* 2);
1143 if ((mbxstatus
== MBX_SUCCESS
) &&
1144 (pmboxq
->u
.mb
.mbxStatus
== 0 ||
1145 pmboxq
->u
.mb
.mbxStatus
== MBXERR_LINK_DOWN
)) {
1146 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
1147 lpfc_init_link(phba
, pmboxq
, phba
->cfg_topology
,
1148 phba
->cfg_link_speed
);
1149 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
1150 phba
->fc_ratov
* 2);
1151 if ((mbxstatus
== MBX_SUCCESS
) &&
1152 (pmboxq
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
1153 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
1154 "2859 SLI authentication is required "
1155 "for INIT_LINK but has not done yet\n");
1158 lpfc_set_loopback_flag(phba
);
1159 if (mbxstatus
!= MBX_TIMEOUT
)
1160 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1162 if (mbxstatus
== MBXERR_ERROR
)
1169 lpfc_emptyq_wait(struct lpfc_hba
*phba
, struct list_head
*q
, spinlock_t
*lock
)
1173 spin_lock_irq(lock
);
1174 while (!list_empty(q
)) {
1175 spin_unlock_irq(lock
);
1177 if (cnt
++ > 250) { /* 5 secs */
1178 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1180 "Outstanding IO when ",
1181 "bringing Adapter offline\n");
1184 spin_lock_irq(lock
);
1186 spin_unlock_irq(lock
);
1191 * lpfc_do_offline - Issues a mailbox command to bring the link down
1192 * @phba: lpfc_hba pointer.
1193 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1196 * Assumes any error from lpfc_do_offline() will be negative.
1197 * Can wait up to 5 seconds for the port ring buffers count
1198 * to reach zero, prints a warning if it is not zero and continues.
1199 * lpfc_workq_post_event() returns a non-zero return code if call fails.
1202 * -EIO error posting the event
1206 lpfc_do_offline(struct lpfc_hba
*phba
, uint32_t type
)
1208 struct completion online_compl
;
1209 struct lpfc_queue
*qp
= NULL
;
1210 struct lpfc_sli_ring
*pring
;
1211 struct lpfc_sli
*psli
;
1216 init_completion(&online_compl
);
1217 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
1218 LPFC_EVT_OFFLINE_PREP
);
1222 wait_for_completion(&online_compl
);
1230 * If freeing the queues have already started, don't access them.
1231 * Otherwise set FREE_WAIT to indicate that queues are being used
1232 * to hold the freeing process until we finish.
1234 spin_lock_irq(&phba
->hbalock
);
1235 if (!(psli
->sli_flag
& LPFC_QUEUE_FREE_INIT
)) {
1236 psli
->sli_flag
|= LPFC_QUEUE_FREE_WAIT
;
1238 spin_unlock_irq(&phba
->hbalock
);
1241 spin_unlock_irq(&phba
->hbalock
);
1243 /* Wait a little for things to settle down, but not
1244 * long enough for dev loss timeout to expire.
1246 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
1247 for (i
= 0; i
< psli
->num_rings
; i
++) {
1248 pring
= &psli
->sli3_ring
[i
];
1249 if (!lpfc_emptyq_wait(phba
, &pring
->txcmplq
,
1254 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
1258 if (!lpfc_emptyq_wait(phba
, &pring
->txcmplq
,
1264 spin_lock_irq(&phba
->hbalock
);
1265 psli
->sli_flag
&= ~LPFC_QUEUE_FREE_WAIT
;
1266 spin_unlock_irq(&phba
->hbalock
);
1269 init_completion(&online_compl
);
1270 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
, type
);
1274 wait_for_completion(&online_compl
);
1283 * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1284 * @phba: lpfc_hba pointer.
1287 * Issues a PCI secondary bus reset for the phba->pcidev.
1290 * First walks the bus_list to ensure only PCI devices with Emulex
1291 * vendor id, device ids that support hot reset, only one occurrence
1292 * of function 0, and all ports on the bus are in offline mode to ensure the
1293 * hot reset only affects one valid HBA.
1296 * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1297 * -ENODEV, NULL ptr to pcidev
1298 * -EBADSLT, detected invalid device
1299 * -EBUSY, port is not in offline state
1303 lpfc_reset_pci_bus(struct lpfc_hba
*phba
)
1305 struct pci_dev
*pdev
= phba
->pcidev
;
1306 struct Scsi_Host
*shost
= NULL
;
1307 struct lpfc_hba
*phba_other
= NULL
;
1308 struct pci_dev
*ptr
= NULL
;
1311 if (phba
->cfg_enable_hba_reset
!= 2)
1315 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
, "8345 pdev NULL!\n");
1319 res
= lpfc_check_pci_resettable(phba
);
1323 /* Walk the list of devices on the pci_dev's bus */
1324 list_for_each_entry(ptr
, &pdev
->bus
->devices
, bus_list
) {
1325 /* Check port is offline */
1326 shost
= pci_get_drvdata(ptr
);
1329 ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
1330 if (!(phba_other
->pport
->fc_flag
& FC_OFFLINE_MODE
)) {
1331 lpfc_printf_log(phba_other
, KERN_INFO
, LOG_INIT
,
1332 "8349 WWPN = 0x%02x%02x%02x%02x"
1333 "%02x%02x%02x%02x is not "
1335 phba_other
->wwpn
[0],
1336 phba_other
->wwpn
[1],
1337 phba_other
->wwpn
[2],
1338 phba_other
->wwpn
[3],
1339 phba_other
->wwpn
[4],
1340 phba_other
->wwpn
[5],
1341 phba_other
->wwpn
[6],
1342 phba_other
->wwpn
[7]);
1348 /* Issue PCI bus reset */
1349 res
= pci_reset_bus(pdev
);
1351 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1352 "8350 PCI reset bus failed: %d\n", res
);
1359 * lpfc_selective_reset - Offline then onlines the port
1360 * @phba: lpfc_hba pointer.
1363 * If the port is configured to allow a reset then the hba is brought
1364 * offline then online.
1367 * Assumes any error from lpfc_do_offline() will be negative.
1368 * Do not make this function static.
1371 * lpfc_do_offline() return code if not zero
1372 * -EIO reset not configured or error posting the event
1376 lpfc_selective_reset(struct lpfc_hba
*phba
)
1378 struct completion online_compl
;
1382 if (!phba
->cfg_enable_hba_reset
)
1385 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)) {
1386 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
1392 init_completion(&online_compl
);
1393 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
1398 wait_for_completion(&online_compl
);
1407 * lpfc_issue_reset - Selectively resets an adapter
1408 * @dev: class device that is converted into a Scsi_host.
1409 * @attr: device attribute, not used.
1410 * @buf: containing the string "selective".
1411 * @count: unused variable.
1414 * If the buf contains the string "selective" then lpfc_selective_reset()
1415 * is called to perform the reset.
1418 * Assumes any error from lpfc_selective_reset() will be negative.
1419 * If lpfc_selective_reset() returns zero then the length of the buffer
1420 * is returned which indicates success
1423 * -EINVAL if the buffer does not contain the string "selective"
1424 * length of buf if lpfc-selective_reset() if the call succeeds
1425 * return value of lpfc_selective_reset() if the call fails
1428 lpfc_issue_reset(struct device
*dev
, struct device_attribute
*attr
,
1429 const char *buf
, size_t count
)
1431 struct Scsi_Host
*shost
= class_to_shost(dev
);
1432 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1433 struct lpfc_hba
*phba
= vport
->phba
;
1434 int status
= -EINVAL
;
1436 if (!phba
->cfg_enable_hba_reset
)
1439 if (strncmp(buf
, "selective", sizeof("selective") - 1) == 0)
1440 status
= phba
->lpfc_selective_reset(phba
);
1449 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1450 * @phba: lpfc_hba pointer.
1453 * SLI4 interface type-2 device to wait on the sliport status register for
1454 * the readyness after performing a firmware reset.
1457 * zero for success, -EPERM when port does not have privilege to perform the
1458 * reset, -EIO when port timeout from recovering from the reset.
1461 * As the caller will interpret the return code by value, be careful in making
1462 * change or addition to return codes.
1465 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba
*phba
)
1467 struct lpfc_register portstat_reg
= {0};
1471 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
1472 &portstat_reg
.word0
))
1475 /* verify if privileged for the request operation */
1476 if (!bf_get(lpfc_sliport_status_rn
, &portstat_reg
) &&
1477 !bf_get(lpfc_sliport_status_err
, &portstat_reg
))
1480 /* wait for the SLI port firmware ready after firmware reset */
1481 for (i
= 0; i
< LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT
; i
++) {
1483 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
1484 &portstat_reg
.word0
))
1486 if (!bf_get(lpfc_sliport_status_err
, &portstat_reg
))
1488 if (!bf_get(lpfc_sliport_status_rn
, &portstat_reg
))
1490 if (!bf_get(lpfc_sliport_status_rdy
, &portstat_reg
))
1495 if (i
< LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT
)
1502 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1503 * @phba: lpfc_hba pointer.
1504 * @opcode: The sli4 config command opcode.
1507 * Request SLI4 interface type-2 device to perform a physical register set
1514 lpfc_sli4_pdev_reg_request(struct lpfc_hba
*phba
, uint32_t opcode
)
1516 struct completion online_compl
;
1517 struct pci_dev
*pdev
= phba
->pcidev
;
1518 uint32_t before_fc_flag
;
1519 uint32_t sriov_nr_virtfn
;
1521 int status
= 0, rc
= 0;
1522 int job_posted
= 1, sriov_err
;
1524 if (!phba
->cfg_enable_hba_reset
)
1527 if ((phba
->sli_rev
< LPFC_SLI_REV4
) ||
1528 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
1529 LPFC_SLI_INTF_IF_TYPE_2
))
1532 /* Keep state if we need to restore back */
1533 before_fc_flag
= phba
->pport
->fc_flag
;
1534 sriov_nr_virtfn
= phba
->cfg_sriov_nr_virtfn
;
1536 /* Disable SR-IOV virtual functions if enabled */
1537 if (phba
->cfg_sriov_nr_virtfn
) {
1538 pci_disable_sriov(pdev
);
1539 phba
->cfg_sriov_nr_virtfn
= 0;
1542 if (opcode
== LPFC_FW_DUMP
)
1543 phba
->hba_flag
|= HBA_FW_DUMP_OP
;
1545 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
1548 phba
->hba_flag
&= ~HBA_FW_DUMP_OP
;
1552 /* wait for the device to be quiesced before firmware reset */
1555 reg_val
= readl(phba
->sli4_hba
.conf_regs_memmap_p
+
1556 LPFC_CTL_PDEV_CTL_OFFSET
);
1558 if (opcode
== LPFC_FW_DUMP
)
1559 reg_val
|= LPFC_FW_DUMP_REQUEST
;
1560 else if (opcode
== LPFC_FW_RESET
)
1561 reg_val
|= LPFC_CTL_PDEV_CTL_FRST
;
1562 else if (opcode
== LPFC_DV_RESET
)
1563 reg_val
|= LPFC_CTL_PDEV_CTL_DRST
;
1565 writel(reg_val
, phba
->sli4_hba
.conf_regs_memmap_p
+
1566 LPFC_CTL_PDEV_CTL_OFFSET
);
1568 readl(phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_CTL_PDEV_CTL_OFFSET
);
1570 /* delay driver action following IF_TYPE_2 reset */
1571 rc
= lpfc_sli4_pdev_status_reg_wait(phba
);
1574 /* no privilege for reset */
1575 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1576 "3150 No privilege to perform the requested "
1577 "access: x%x\n", reg_val
);
1578 } else if (rc
== -EIO
) {
1579 /* reset failed, there is nothing more we can do */
1580 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1581 "3153 Fail to perform the requested "
1582 "access: x%x\n", reg_val
);
1586 /* keep the original port state */
1587 if (before_fc_flag
& FC_OFFLINE_MODE
)
1590 init_completion(&online_compl
);
1591 job_posted
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
1596 wait_for_completion(&online_compl
);
1599 /* in any case, restore the virtual functions enabled as before */
1600 if (sriov_nr_virtfn
) {
1602 lpfc_sli_probe_sriov_nr_virtfn(phba
, sriov_nr_virtfn
);
1604 phba
->cfg_sriov_nr_virtfn
= sriov_nr_virtfn
;
1607 /* return proper error code */
1618 * lpfc_nport_evt_cnt_show - Return the number of nport events
1619 * @dev: class device that is converted into a Scsi_host.
1620 * @attr: device attribute, not used.
1621 * @buf: on return contains the ascii number of nport events.
1623 * Returns: size of formatted string.
1626 lpfc_nport_evt_cnt_show(struct device
*dev
, struct device_attribute
*attr
,
1629 struct Scsi_Host
*shost
= class_to_shost(dev
);
1630 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1631 struct lpfc_hba
*phba
= vport
->phba
;
1633 return scnprintf(buf
, PAGE_SIZE
, "%d\n", phba
->nport_event_cnt
);
1637 lpfc_set_trunking(struct lpfc_hba
*phba
, char *buff_out
)
1639 LPFC_MBOXQ_t
*mbox
= NULL
;
1640 unsigned long val
= 0;
1644 if (!strncmp("enable", buff_out
,
1645 strlen("enable"))) {
1646 pval
= buff_out
+ strlen("enable") + 1;
1647 rc
= kstrtoul(pval
, 0, &val
);
1649 return rc
; /* Invalid number */
1650 } else if (!strncmp("disable", buff_out
,
1651 strlen("disable"))) {
1654 return -EINVAL
; /* Invalid command */
1659 val
= 0x0; /* Disable */
1662 val
= 0x1; /* Enable two port trunk */
1665 val
= 0x2; /* Enable four port trunk */
1671 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1672 "0070 Set trunk mode with val %ld ", val
);
1674 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1678 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1679 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE
,
1680 12, LPFC_SLI4_MBX_EMBED
);
1682 bf_set(lpfc_mbx_set_trunk_mode
,
1683 &mbox
->u
.mqe
.un
.set_trunk_mode
,
1685 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
1687 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1688 "0071 Set trunk mode failed with status: %d",
1690 if (rc
!= MBX_TIMEOUT
)
1691 mempool_free(mbox
, phba
->mbox_mem_pool
);
1697 * lpfc_board_mode_show - Return the state of the board
1698 * @dev: class device that is converted into a Scsi_host.
1699 * @attr: device attribute, not used.
1700 * @buf: on return contains the state of the adapter.
1702 * Returns: size of formatted string.
1705 lpfc_board_mode_show(struct device
*dev
, struct device_attribute
*attr
,
1708 struct Scsi_Host
*shost
= class_to_shost(dev
);
1709 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1710 struct lpfc_hba
*phba
= vport
->phba
;
1713 if (phba
->link_state
== LPFC_HBA_ERROR
)
1715 else if (phba
->link_state
== LPFC_WARM_START
)
1716 state
= "warm start";
1717 else if (phba
->link_state
== LPFC_INIT_START
)
1722 return scnprintf(buf
, PAGE_SIZE
, "%s\n", state
);
1726 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1727 * @dev: class device that is converted into a Scsi_host.
1728 * @attr: device attribute, not used.
1729 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1730 * @count: unused variable.
1733 * -EACCES if enable hba reset not enabled
1734 * -EINVAL if the buffer does not contain a valid string (see above)
1735 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1736 * buf length greater than zero indicates success
1739 lpfc_board_mode_store(struct device
*dev
, struct device_attribute
*attr
,
1740 const char *buf
, size_t count
)
1742 struct Scsi_Host
*shost
= class_to_shost(dev
);
1743 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1744 struct lpfc_hba
*phba
= vport
->phba
;
1745 struct completion online_compl
;
1746 char *board_mode_str
= NULL
;
1750 if (!phba
->cfg_enable_hba_reset
) {
1752 goto board_mode_out
;
1755 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1756 "3050 lpfc_board_mode set to %s\n", buf
);
1758 init_completion(&online_compl
);
1760 if(strncmp(buf
, "online", sizeof("online") - 1) == 0) {
1761 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
1765 goto board_mode_out
;
1767 wait_for_completion(&online_compl
);
1770 } else if (strncmp(buf
, "offline", sizeof("offline") - 1) == 0)
1771 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
1772 else if (strncmp(buf
, "warm", sizeof("warm") - 1) == 0)
1773 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1776 status
= lpfc_do_offline(phba
, LPFC_EVT_WARM_START
);
1777 else if (strncmp(buf
, "error", sizeof("error") - 1) == 0)
1778 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1781 status
= lpfc_do_offline(phba
, LPFC_EVT_KILL
);
1782 else if (strncmp(buf
, "dump", sizeof("dump") - 1) == 0)
1783 status
= lpfc_sli4_pdev_reg_request(phba
, LPFC_FW_DUMP
);
1784 else if (strncmp(buf
, "fw_reset", sizeof("fw_reset") - 1) == 0)
1785 status
= lpfc_sli4_pdev_reg_request(phba
, LPFC_FW_RESET
);
1786 else if (strncmp(buf
, "dv_reset", sizeof("dv_reset") - 1) == 0)
1787 status
= lpfc_sli4_pdev_reg_request(phba
, LPFC_DV_RESET
);
1788 else if (strncmp(buf
, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1790 status
= lpfc_reset_pci_bus(phba
);
1791 else if (strncmp(buf
, "trunk", sizeof("trunk") - 1) == 0)
1792 status
= lpfc_set_trunking(phba
, (char *)buf
+ sizeof("trunk"));
1800 board_mode_str
= strchr(buf
, '\n');
1802 *board_mode_str
= '\0';
1803 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1804 "3097 Failed \"%s\", status(%d), "
1806 buf
, status
, phba
->pport
->fc_flag
);
1812 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1813 * @phba: pointer to the adapter structure.
1814 * @mxri: max xri count.
1815 * @axri: available xri count.
1816 * @mrpi: max rpi count.
1817 * @arpi: available rpi count.
1818 * @mvpi: max vpi count.
1819 * @avpi: available vpi count.
1822 * If an integer pointer for an count is not null then the value for the
1823 * count is returned.
1830 lpfc_get_hba_info(struct lpfc_hba
*phba
,
1831 uint32_t *mxri
, uint32_t *axri
,
1832 uint32_t *mrpi
, uint32_t *arpi
,
1833 uint32_t *mvpi
, uint32_t *avpi
)
1835 struct lpfc_mbx_read_config
*rd_config
;
1836 LPFC_MBOXQ_t
*pmboxq
;
1842 * prevent udev from issuing mailbox commands until the port is
1845 if (phba
->link_state
< LPFC_LINK_DOWN
||
1846 !phba
->mbox_mem_pool
||
1847 (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
) == 0)
1850 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
1853 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1856 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
1858 pmb
= &pmboxq
->u
.mb
;
1859 pmb
->mbxCommand
= MBX_READ_CONFIG
;
1860 pmb
->mbxOwner
= OWN_HOST
;
1861 pmboxq
->ctx_buf
= NULL
;
1863 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
1864 rc
= MBX_NOT_FINISHED
;
1866 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
1868 if (rc
!= MBX_SUCCESS
) {
1869 if (rc
!= MBX_TIMEOUT
)
1870 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1874 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1875 rd_config
= &pmboxq
->u
.mqe
.un
.rd_config
;
1877 *mrpi
= bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
1879 *arpi
= bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
) -
1880 phba
->sli4_hba
.max_cfg_param
.rpi_used
;
1882 *mxri
= bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
1884 *axri
= bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
) -
1885 phba
->sli4_hba
.max_cfg_param
.xri_used
;
1887 /* Account for differences with SLI-3. Get vpi count from
1888 * mailbox data and subtract one for max vpi value.
1890 max_vpi
= (bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
) > 0) ?
1891 (bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
) - 1) : 0;
1893 /* Limit the max we support */
1894 if (max_vpi
> LPFC_MAX_VPI
)
1895 max_vpi
= LPFC_MAX_VPI
;
1899 *avpi
= max_vpi
- phba
->sli4_hba
.max_cfg_param
.vpi_used
;
1902 *mrpi
= pmb
->un
.varRdConfig
.max_rpi
;
1904 *arpi
= pmb
->un
.varRdConfig
.avail_rpi
;
1906 *mxri
= pmb
->un
.varRdConfig
.max_xri
;
1908 *axri
= pmb
->un
.varRdConfig
.avail_xri
;
1910 *mvpi
= pmb
->un
.varRdConfig
.max_vpi
;
1912 /* avail_vpi is only valid if link is up and ready */
1913 if (phba
->link_state
== LPFC_HBA_READY
)
1914 *avpi
= pmb
->un
.varRdConfig
.avail_vpi
;
1916 *avpi
= pmb
->un
.varRdConfig
.max_vpi
;
1920 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1925 * lpfc_max_rpi_show - Return maximum rpi
1926 * @dev: class device that is converted into a Scsi_host.
1927 * @attr: device attribute, not used.
1928 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1931 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1932 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1933 * to "Unknown" and the buffer length is returned, therefore the caller
1934 * must check for "Unknown" in the buffer to detect a failure.
1936 * Returns: size of formatted string.
1939 lpfc_max_rpi_show(struct device
*dev
, struct device_attribute
*attr
,
1942 struct Scsi_Host
*shost
= class_to_shost(dev
);
1943 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1944 struct lpfc_hba
*phba
= vport
->phba
;
1947 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, NULL
, NULL
, NULL
))
1948 return scnprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
1949 return scnprintf(buf
, PAGE_SIZE
, "Unknown\n");
1953 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1954 * @dev: class device that is converted into a Scsi_host.
1955 * @attr: device attribute, not used.
1956 * @buf: containing the used rpi count in decimal or "Unknown".
1959 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1960 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1961 * to "Unknown" and the buffer length is returned, therefore the caller
1962 * must check for "Unknown" in the buffer to detect a failure.
1964 * Returns: size of formatted string.
1967 lpfc_used_rpi_show(struct device
*dev
, struct device_attribute
*attr
,
1970 struct Scsi_Host
*shost
= class_to_shost(dev
);
1971 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1972 struct lpfc_hba
*phba
= vport
->phba
;
1975 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, &acnt
, NULL
, NULL
))
1976 return scnprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
1977 return scnprintf(buf
, PAGE_SIZE
, "Unknown\n");
1981 * lpfc_max_xri_show - Return maximum xri
1982 * @dev: class device that is converted into a Scsi_host.
1983 * @attr: device attribute, not used.
1984 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1987 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1988 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1989 * to "Unknown" and the buffer length is returned, therefore the caller
1990 * must check for "Unknown" in the buffer to detect a failure.
1992 * Returns: size of formatted string.
1995 lpfc_max_xri_show(struct device
*dev
, struct device_attribute
*attr
,
1998 struct Scsi_Host
*shost
= class_to_shost(dev
);
1999 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2000 struct lpfc_hba
*phba
= vport
->phba
;
2003 if (lpfc_get_hba_info(phba
, &cnt
, NULL
, NULL
, NULL
, NULL
, NULL
))
2004 return scnprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
2005 return scnprintf(buf
, PAGE_SIZE
, "Unknown\n");
2009 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2010 * @dev: class device that is converted into a Scsi_host.
2011 * @attr: device attribute, not used.
2012 * @buf: on return contains the used xri count in decimal or "Unknown".
2015 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2016 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2017 * to "Unknown" and the buffer length is returned, therefore the caller
2018 * must check for "Unknown" in the buffer to detect a failure.
2020 * Returns: size of formatted string.
2023 lpfc_used_xri_show(struct device
*dev
, struct device_attribute
*attr
,
2026 struct Scsi_Host
*shost
= class_to_shost(dev
);
2027 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2028 struct lpfc_hba
*phba
= vport
->phba
;
2031 if (lpfc_get_hba_info(phba
, &cnt
, &acnt
, NULL
, NULL
, NULL
, NULL
))
2032 return scnprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
2033 return scnprintf(buf
, PAGE_SIZE
, "Unknown\n");
2037 * lpfc_max_vpi_show - Return maximum vpi
2038 * @dev: class device that is converted into a Scsi_host.
2039 * @attr: device attribute, not used.
2040 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2043 * Calls lpfc_get_hba_info() asking for just the mvpi count.
2044 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2045 * to "Unknown" and the buffer length is returned, therefore the caller
2046 * must check for "Unknown" in the buffer to detect a failure.
2048 * Returns: size of formatted string.
2051 lpfc_max_vpi_show(struct device
*dev
, struct device_attribute
*attr
,
2054 struct Scsi_Host
*shost
= class_to_shost(dev
);
2055 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2056 struct lpfc_hba
*phba
= vport
->phba
;
2059 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, NULL
))
2060 return scnprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
2061 return scnprintf(buf
, PAGE_SIZE
, "Unknown\n");
2065 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2066 * @dev: class device that is converted into a Scsi_host.
2067 * @attr: device attribute, not used.
2068 * @buf: on return contains the used vpi count in decimal or "Unknown".
2071 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2072 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2073 * to "Unknown" and the buffer length is returned, therefore the caller
2074 * must check for "Unknown" in the buffer to detect a failure.
2076 * Returns: size of formatted string.
2079 lpfc_used_vpi_show(struct device
*dev
, struct device_attribute
*attr
,
2082 struct Scsi_Host
*shost
= class_to_shost(dev
);
2083 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2084 struct lpfc_hba
*phba
= vport
->phba
;
2087 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, &acnt
))
2088 return scnprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
2089 return scnprintf(buf
, PAGE_SIZE
, "Unknown\n");
2093 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2094 * @dev: class device that is converted into a Scsi_host.
2095 * @attr: device attribute, not used.
2096 * @buf: text that must be interpreted to determine if npiv is supported.
2099 * Buffer will contain text indicating npiv is not suppoerted on the port,
2100 * the port is an NPIV physical port, or it is an npiv virtual port with
2101 * the id of the vport.
2103 * Returns: size of formatted string.
2106 lpfc_npiv_info_show(struct device
*dev
, struct device_attribute
*attr
,
2109 struct Scsi_Host
*shost
= class_to_shost(dev
);
2110 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2111 struct lpfc_hba
*phba
= vport
->phba
;
2113 if (!(phba
->max_vpi
))
2114 return scnprintf(buf
, PAGE_SIZE
, "NPIV Not Supported\n");
2115 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
2116 return scnprintf(buf
, PAGE_SIZE
, "NPIV Physical\n");
2117 return scnprintf(buf
, PAGE_SIZE
, "NPIV Virtual (VPI %d)\n", vport
->vpi
);
2121 * lpfc_poll_show - Return text about poll support for the adapter
2122 * @dev: class device that is converted into a Scsi_host.
2123 * @attr: device attribute, not used.
2124 * @buf: on return contains the cfg_poll in hex.
2127 * cfg_poll should be a lpfc_polling_flags type.
2129 * Returns: size of formatted string.
2132 lpfc_poll_show(struct device
*dev
, struct device_attribute
*attr
,
2135 struct Scsi_Host
*shost
= class_to_shost(dev
);
2136 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2137 struct lpfc_hba
*phba
= vport
->phba
;
2139 return scnprintf(buf
, PAGE_SIZE
, "%#x\n", phba
->cfg_poll
);
2143 * lpfc_poll_store - Set the value of cfg_poll for the adapter
2144 * @dev: class device that is converted into a Scsi_host.
2145 * @attr: device attribute, not used.
2146 * @buf: one or more lpfc_polling_flags values.
2150 * buf contents converted to integer and checked for a valid value.
2153 * -EINVAL if the buffer connot be converted or is out of range
2154 * length of the buf on success
2157 lpfc_poll_store(struct device
*dev
, struct device_attribute
*attr
,
2158 const char *buf
, size_t count
)
2160 struct Scsi_Host
*shost
= class_to_shost(dev
);
2161 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2162 struct lpfc_hba
*phba
= vport
->phba
;
2167 if (!isdigit(buf
[0]))
2170 if (sscanf(buf
, "%i", &val
) != 1)
2173 if ((val
& 0x3) != val
)
2176 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2179 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2180 "3051 lpfc_poll changed from %d to %d\n",
2181 phba
->cfg_poll
, val
);
2183 spin_lock_irq(&phba
->hbalock
);
2185 old_val
= phba
->cfg_poll
;
2187 if (val
& ENABLE_FCP_RING_POLLING
) {
2188 if ((val
& DISABLE_FCP_RING_INT
) &&
2189 !(old_val
& DISABLE_FCP_RING_INT
)) {
2190 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
2191 spin_unlock_irq(&phba
->hbalock
);
2194 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
2195 writel(creg_val
, phba
->HCregaddr
);
2196 readl(phba
->HCregaddr
); /* flush */
2198 lpfc_poll_start_timer(phba
);
2200 } else if (val
!= 0x0) {
2201 spin_unlock_irq(&phba
->hbalock
);
2205 if (!(val
& DISABLE_FCP_RING_INT
) &&
2206 (old_val
& DISABLE_FCP_RING_INT
))
2208 spin_unlock_irq(&phba
->hbalock
);
2209 del_timer(&phba
->fcp_poll_timer
);
2210 spin_lock_irq(&phba
->hbalock
);
2211 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
2212 spin_unlock_irq(&phba
->hbalock
);
2215 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
2216 writel(creg_val
, phba
->HCregaddr
);
2217 readl(phba
->HCregaddr
); /* flush */
2220 phba
->cfg_poll
= val
;
2222 spin_unlock_irq(&phba
->hbalock
);
2228 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2229 * @dev: class converted to a Scsi_host structure.
2230 * @attr: device attribute, not used.
2231 * @buf: on return contains the formatted support level.
2234 * Returns the maximum number of virtual functions a physical function can
2235 * support, 0 will be returned if called on virtual function.
2237 * Returns: size of formatted string.
2240 lpfc_sriov_hw_max_virtfn_show(struct device
*dev
,
2241 struct device_attribute
*attr
,
2244 struct Scsi_Host
*shost
= class_to_shost(dev
);
2245 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2246 struct lpfc_hba
*phba
= vport
->phba
;
2247 uint16_t max_nr_virtfn
;
2249 max_nr_virtfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
2250 return scnprintf(buf
, PAGE_SIZE
, "%d\n", max_nr_virtfn
);
2253 static inline bool lpfc_rangecheck(uint val
, uint min
, uint max
)
2255 return val
>= min
&& val
<= max
;
2259 * lpfc_enable_bbcr_set: Sets an attribute value.
2260 * @phba: pointer the the adapter structure.
2261 * @val: integer attribute value.
2264 * Validates the min and max values then sets the
2265 * adapter config field if in the valid range. prints error message
2266 * and does not set the parameter if invalid.
2270 * -EINVAL if val is invalid
2273 lpfc_enable_bbcr_set(struct lpfc_hba
*phba
, uint val
)
2275 if (lpfc_rangecheck(val
, 0, 1) && phba
->sli_rev
== LPFC_SLI_REV4
) {
2276 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2277 "3068 %s_enable_bbcr changed from %d to %d\n",
2278 LPFC_DRIVER_NAME
, phba
->cfg_enable_bbcr
, val
);
2279 phba
->cfg_enable_bbcr
= val
;
2282 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2283 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
2284 LPFC_DRIVER_NAME
, val
);
2289 * lpfc_param_show - Return a cfg attribute value in decimal
2292 * Macro that given an attr e.g. hba_queue_depth expands
2293 * into a function with the name lpfc_hba_queue_depth_show.
2295 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2296 * @dev: class device that is converted into a Scsi_host.
2297 * @attr: device attribute, not used.
2298 * @buf: on return contains the attribute value in decimal.
2300 * Returns: size of formatted string.
2302 #define lpfc_param_show(attr) \
2304 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2307 struct Scsi_Host *shost = class_to_shost(dev);\
2308 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2309 struct lpfc_hba *phba = vport->phba;\
2310 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2315 * lpfc_param_hex_show - Return a cfg attribute value in hex
2318 * Macro that given an attr e.g. hba_queue_depth expands
2319 * into a function with the name lpfc_hba_queue_depth_show
2321 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2322 * @dev: class device that is converted into a Scsi_host.
2323 * @attr: device attribute, not used.
2324 * @buf: on return contains the attribute value in hexadecimal.
2326 * Returns: size of formatted string.
2328 #define lpfc_param_hex_show(attr) \
2330 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2333 struct Scsi_Host *shost = class_to_shost(dev);\
2334 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2335 struct lpfc_hba *phba = vport->phba;\
2337 val = phba->cfg_##attr;\
2338 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2343 * lpfc_param_init - Initializes a cfg attribute
2346 * Macro that given an attr e.g. hba_queue_depth expands
2347 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2348 * takes a default argument, a minimum and maximum argument.
2350 * lpfc_##attr##_init: Initializes an attribute.
2351 * @phba: pointer the the adapter structure.
2352 * @val: integer attribute value.
2354 * Validates the min and max values then sets the adapter config field
2355 * accordingly, or uses the default if out of range and prints an error message.
2359 * -EINVAL if default used
2361 #define lpfc_param_init(attr, default, minval, maxval) \
2363 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2365 if (lpfc_rangecheck(val, minval, maxval)) {\
2366 phba->cfg_##attr = val;\
2369 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2370 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2371 "allowed range is ["#minval", "#maxval"]\n", val); \
2372 phba->cfg_##attr = default;\
2377 * lpfc_param_set - Set a cfg attribute value
2380 * Macro that given an attr e.g. hba_queue_depth expands
2381 * into a function with the name lpfc_hba_queue_depth_set
2383 * lpfc_##attr##_set: Sets an attribute value.
2384 * @phba: pointer the the adapter structure.
2385 * @val: integer attribute value.
2388 * Validates the min and max values then sets the
2389 * adapter config field if in the valid range. prints error message
2390 * and does not set the parameter if invalid.
2394 * -EINVAL if val is invalid
2396 #define lpfc_param_set(attr, default, minval, maxval) \
2398 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2400 if (lpfc_rangecheck(val, minval, maxval)) {\
2401 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2402 "3052 lpfc_" #attr " changed from %d to %d\n", \
2403 phba->cfg_##attr, val); \
2404 phba->cfg_##attr = val;\
2407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2408 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2409 "allowed range is ["#minval", "#maxval"]\n", val); \
2414 * lpfc_param_store - Set a vport attribute value
2417 * Macro that given an attr e.g. hba_queue_depth expands
2418 * into a function with the name lpfc_hba_queue_depth_store.
2420 * lpfc_##attr##_store: Set an sttribute value.
2421 * @dev: class device that is converted into a Scsi_host.
2422 * @attr: device attribute, not used.
2423 * @buf: contains the attribute value in ascii.
2427 * Convert the ascii text number to an integer, then
2428 * use the lpfc_##attr##_set function to set the value.
2431 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2432 * length of buffer upon success.
2434 #define lpfc_param_store(attr) \
2436 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2437 const char *buf, size_t count) \
2439 struct Scsi_Host *shost = class_to_shost(dev);\
2440 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2441 struct lpfc_hba *phba = vport->phba;\
2443 if (!isdigit(buf[0]))\
2445 if (sscanf(buf, "%i", &val) != 1)\
2447 if (lpfc_##attr##_set(phba, val) == 0) \
2448 return strlen(buf);\
2454 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2457 * Macro that given an attr e.g. hba_queue_depth expands
2458 * into a function with the name lpfc_hba_queue_depth_show
2460 * lpfc_##attr##_show: prints the attribute value in decimal.
2461 * @dev: class device that is converted into a Scsi_host.
2462 * @attr: device attribute, not used.
2463 * @buf: on return contains the attribute value in decimal.
2465 * Returns: length of formatted string.
2467 #define lpfc_vport_param_show(attr) \
2469 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2472 struct Scsi_Host *shost = class_to_shost(dev);\
2473 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2474 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2478 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2481 * Macro that given an attr e.g.
2482 * hba_queue_depth expands into a function with the name
2483 * lpfc_hba_queue_depth_show
2485 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2486 * @dev: class device that is converted into a Scsi_host.
2487 * @attr: device attribute, not used.
2488 * @buf: on return contains the attribute value in hexadecimal.
2490 * Returns: length of formatted string.
2492 #define lpfc_vport_param_hex_show(attr) \
2494 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2497 struct Scsi_Host *shost = class_to_shost(dev);\
2498 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2499 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2503 * lpfc_vport_param_init - Initialize a vport cfg attribute
2506 * Macro that given an attr e.g. hba_queue_depth expands
2507 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2508 * takes a default argument, a minimum and maximum argument.
2510 * lpfc_##attr##_init: validates the min and max values then sets the
2511 * adapter config field accordingly, or uses the default if out of range
2512 * and prints an error message.
2513 * @phba: pointer the the adapter structure.
2514 * @val: integer attribute value.
2518 * -EINVAL if default used
2520 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2522 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2524 if (lpfc_rangecheck(val, minval, maxval)) {\
2525 vport->cfg_##attr = val;\
2528 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2529 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2530 "allowed range is ["#minval", "#maxval"]\n", val); \
2531 vport->cfg_##attr = default;\
2536 * lpfc_vport_param_set - Set a vport cfg attribute
2539 * Macro that given an attr e.g. hba_queue_depth expands
2540 * into a function with the name lpfc_hba_queue_depth_set
2542 * lpfc_##attr##_set: validates the min and max values then sets the
2543 * adapter config field if in the valid range. prints error message
2544 * and does not set the parameter if invalid.
2545 * @phba: pointer the the adapter structure.
2546 * @val: integer attribute value.
2550 * -EINVAL if val is invalid
2552 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2554 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2556 if (lpfc_rangecheck(val, minval, maxval)) {\
2557 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2558 "3053 lpfc_" #attr \
2559 " changed from %d (x%x) to %d (x%x)\n", \
2560 vport->cfg_##attr, vport->cfg_##attr, \
2562 vport->cfg_##attr = val;\
2565 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2566 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2567 "allowed range is ["#minval", "#maxval"]\n", val); \
2572 * lpfc_vport_param_store - Set a vport attribute
2575 * Macro that given an attr e.g. hba_queue_depth
2576 * expands into a function with the name lpfc_hba_queue_depth_store
2578 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2579 * use the lpfc_##attr##_set function to set the value.
2580 * @cdev: class device that is converted into a Scsi_host.
2581 * @buf: contains the attribute value in decimal.
2585 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2586 * length of buffer upon success.
2588 #define lpfc_vport_param_store(attr) \
2590 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2591 const char *buf, size_t count) \
2593 struct Scsi_Host *shost = class_to_shost(dev);\
2594 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2596 if (!isdigit(buf[0]))\
2598 if (sscanf(buf, "%i", &val) != 1)\
2600 if (lpfc_##attr##_set(vport, val) == 0) \
2601 return strlen(buf);\
2607 static DEVICE_ATTR(nvme_info
, 0444, lpfc_nvme_info_show
, NULL
);
2608 static DEVICE_ATTR(scsi_stat
, 0444, lpfc_scsi_stat_show
, NULL
);
2609 static DEVICE_ATTR(bg_info
, S_IRUGO
, lpfc_bg_info_show
, NULL
);
2610 static DEVICE_ATTR(bg_guard_err
, S_IRUGO
, lpfc_bg_guard_err_show
, NULL
);
2611 static DEVICE_ATTR(bg_apptag_err
, S_IRUGO
, lpfc_bg_apptag_err_show
, NULL
);
2612 static DEVICE_ATTR(bg_reftag_err
, S_IRUGO
, lpfc_bg_reftag_err_show
, NULL
);
2613 static DEVICE_ATTR(info
, S_IRUGO
, lpfc_info_show
, NULL
);
2614 static DEVICE_ATTR(serialnum
, S_IRUGO
, lpfc_serialnum_show
, NULL
);
2615 static DEVICE_ATTR(modeldesc
, S_IRUGO
, lpfc_modeldesc_show
, NULL
);
2616 static DEVICE_ATTR(modelname
, S_IRUGO
, lpfc_modelname_show
, NULL
);
2617 static DEVICE_ATTR(programtype
, S_IRUGO
, lpfc_programtype_show
, NULL
);
2618 static DEVICE_ATTR(portnum
, S_IRUGO
, lpfc_vportnum_show
, NULL
);
2619 static DEVICE_ATTR(fwrev
, S_IRUGO
, lpfc_fwrev_show
, NULL
);
2620 static DEVICE_ATTR(hdw
, S_IRUGO
, lpfc_hdw_show
, NULL
);
2621 static DEVICE_ATTR(link_state
, S_IRUGO
| S_IWUSR
, lpfc_link_state_show
,
2622 lpfc_link_state_store
);
2623 static DEVICE_ATTR(option_rom_version
, S_IRUGO
,
2624 lpfc_option_rom_version_show
, NULL
);
2625 static DEVICE_ATTR(num_discovered_ports
, S_IRUGO
,
2626 lpfc_num_discovered_ports_show
, NULL
);
2627 static DEVICE_ATTR(menlo_mgmt_mode
, S_IRUGO
, lpfc_mlomgmt_show
, NULL
);
2628 static DEVICE_ATTR(nport_evt_cnt
, S_IRUGO
, lpfc_nport_evt_cnt_show
, NULL
);
2629 static DEVICE_ATTR_RO(lpfc_drvr_version
);
2630 static DEVICE_ATTR_RO(lpfc_enable_fip
);
2631 static DEVICE_ATTR(board_mode
, S_IRUGO
| S_IWUSR
,
2632 lpfc_board_mode_show
, lpfc_board_mode_store
);
2633 static DEVICE_ATTR(issue_reset
, S_IWUSR
, NULL
, lpfc_issue_reset
);
2634 static DEVICE_ATTR(max_vpi
, S_IRUGO
, lpfc_max_vpi_show
, NULL
);
2635 static DEVICE_ATTR(used_vpi
, S_IRUGO
, lpfc_used_vpi_show
, NULL
);
2636 static DEVICE_ATTR(max_rpi
, S_IRUGO
, lpfc_max_rpi_show
, NULL
);
2637 static DEVICE_ATTR(used_rpi
, S_IRUGO
, lpfc_used_rpi_show
, NULL
);
2638 static DEVICE_ATTR(max_xri
, S_IRUGO
, lpfc_max_xri_show
, NULL
);
2639 static DEVICE_ATTR(used_xri
, S_IRUGO
, lpfc_used_xri_show
, NULL
);
2640 static DEVICE_ATTR(npiv_info
, S_IRUGO
, lpfc_npiv_info_show
, NULL
);
2641 static DEVICE_ATTR_RO(lpfc_temp_sensor
);
2642 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn
);
2643 static DEVICE_ATTR(protocol
, S_IRUGO
, lpfc_sli4_protocol_show
, NULL
);
2644 static DEVICE_ATTR(lpfc_xlane_supported
, S_IRUGO
, lpfc_oas_supported_show
,
2647 static char *lpfc_soft_wwn_key
= "C99G71SL8032A";
2650 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2652 * @cnt: Length of string.
2653 * @wwn: Array to receive converted wwn value.
2656 * -EINVAL if the buffer does not contain a valid wwn
2660 lpfc_wwn_set(const char *buf
, size_t cnt
, char wwn
[])
2664 /* Count may include a LF at end of string */
2665 if (buf
[cnt
-1] == '\n')
2668 if ((cnt
< 16) || (cnt
> 18) || ((cnt
== 17) && (*buf
++ != 'x')) ||
2669 ((cnt
== 18) && ((*buf
++ != '0') || (*buf
++ != 'x'))))
2672 memset(wwn
, 0, WWN_SZ
);
2674 /* Validate and store the new name */
2675 for (i
= 0, j
= 0; i
< 16; i
++) {
2676 if ((*buf
>= 'a') && (*buf
<= 'f'))
2677 j
= ((j
<< 4) | ((*buf
++ - 'a') + 10));
2678 else if ((*buf
>= 'A') && (*buf
<= 'F'))
2679 j
= ((j
<< 4) | ((*buf
++ - 'A') + 10));
2680 else if ((*buf
>= '0') && (*buf
<= '9'))
2681 j
= ((j
<< 4) | (*buf
++ - '0'));
2685 wwn
[i
/2] = j
& 0xff;
2692 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2693 * @dev: class device that is converted into a Scsi_host.
2694 * @attr: device attribute, not used.
2695 * @buf: containing the string lpfc_soft_wwn_key.
2696 * @count: must be size of lpfc_soft_wwn_key.
2699 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2700 * length of buf indicates success
2703 lpfc_soft_wwn_enable_store(struct device
*dev
, struct device_attribute
*attr
,
2704 const char *buf
, size_t count
)
2706 struct Scsi_Host
*shost
= class_to_shost(dev
);
2707 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2708 struct lpfc_hba
*phba
= vport
->phba
;
2709 unsigned int cnt
= count
;
2710 uint8_t vvvl
= vport
->fc_sparam
.cmn
.valid_vendor_ver_level
;
2711 u32
*fawwpn_key
= (uint32_t *)&vport
->fc_sparam
.un
.vendorVersion
[0];
2714 * We're doing a simple sanity check for soft_wwpn setting.
2715 * We require that the user write a specific key to enable
2716 * the soft_wwpn attribute to be settable. Once the attribute
2717 * is written, the enable key resets. If further updates are
2718 * desired, the key must be written again to re-enable the
2721 * The "key" is not secret - it is a hardcoded string shown
2722 * here. The intent is to protect against the random user or
2723 * application that is just writing attributes.
2725 if (vvvl
== 1 && cpu_to_be32(*fawwpn_key
) == FAPWWN_KEY_VENDOR
) {
2726 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2727 "0051 "LPFC_DRIVER_NAME
" soft wwpn can not"
2728 " be enabled: fawwpn is enabled\n");
2732 /* count may include a LF at end of string */
2733 if (buf
[cnt
-1] == '\n')
2736 if ((cnt
!= strlen(lpfc_soft_wwn_key
)) ||
2737 (strncmp(buf
, lpfc_soft_wwn_key
, strlen(lpfc_soft_wwn_key
)) != 0))
2740 phba
->soft_wwn_enable
= 1;
2742 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
2743 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2745 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
2746 " The soft_wwpn feature is not supported by Broadcom.");
2750 static DEVICE_ATTR_WO(lpfc_soft_wwn_enable
);
2753 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2754 * @dev: class device that is converted into a Scsi_host.
2755 * @attr: device attribute, not used.
2756 * @buf: on return contains the wwpn in hexadecimal.
2758 * Returns: size of formatted string.
2761 lpfc_soft_wwpn_show(struct device
*dev
, struct device_attribute
*attr
,
2764 struct Scsi_Host
*shost
= class_to_shost(dev
);
2765 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2766 struct lpfc_hba
*phba
= vport
->phba
;
2768 return scnprintf(buf
, PAGE_SIZE
, "0x%llx\n",
2769 (unsigned long long)phba
->cfg_soft_wwpn
);
2773 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2774 * @dev: class device that is converted into a Scsi_host.
2775 * @attr: device attribute, not used.
2776 * @buf: contains the wwpn in hexadecimal.
2777 * @count: number of wwpn bytes in buf
2780 * -EACCES hba reset not enabled, adapter over temp
2781 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2782 * -EIO error taking adapter offline or online
2783 * value of count on success
2786 lpfc_soft_wwpn_store(struct device
*dev
, struct device_attribute
*attr
,
2787 const char *buf
, size_t count
)
2789 struct Scsi_Host
*shost
= class_to_shost(dev
);
2790 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2791 struct lpfc_hba
*phba
= vport
->phba
;
2792 struct completion online_compl
;
2793 int stat1
= 0, stat2
= 0;
2794 unsigned int cnt
= count
;
2798 if (!phba
->cfg_enable_hba_reset
)
2800 spin_lock_irq(&phba
->hbalock
);
2801 if (phba
->over_temp_state
== HBA_OVER_TEMP
) {
2802 spin_unlock_irq(&phba
->hbalock
);
2805 spin_unlock_irq(&phba
->hbalock
);
2806 /* count may include a LF at end of string */
2807 if (buf
[cnt
-1] == '\n')
2810 if (!phba
->soft_wwn_enable
)
2813 /* lock setting wwpn, wwnn down */
2814 phba
->soft_wwn_enable
= 0;
2816 rc
= lpfc_wwn_set(buf
, cnt
, wwpn
);
2818 /* not able to set wwpn, unlock it */
2819 phba
->soft_wwn_enable
= 1;
2823 phba
->cfg_soft_wwpn
= wwn_to_u64(wwpn
);
2824 fc_host_port_name(shost
) = phba
->cfg_soft_wwpn
;
2825 if (phba
->cfg_soft_wwnn
)
2826 fc_host_node_name(shost
) = phba
->cfg_soft_wwnn
;
2828 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
2829 "lpfc%d: Reinitializing to use soft_wwpn\n", phba
->brd_no
);
2831 stat1
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
2833 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2834 "0463 lpfc_soft_wwpn attribute set failed to "
2835 "reinit adapter - %d\n", stat1
);
2836 init_completion(&online_compl
);
2837 rc
= lpfc_workq_post_event(phba
, &stat2
, &online_compl
,
2842 wait_for_completion(&online_compl
);
2844 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2845 "0464 lpfc_soft_wwpn attribute set failed to "
2846 "reinit adapter - %d\n", stat2
);
2847 return (stat1
|| stat2
) ? -EIO
: count
;
2849 static DEVICE_ATTR_RW(lpfc_soft_wwpn
);
2852 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2853 * @dev: class device that is converted into a Scsi_host.
2854 * @attr: device attribute, not used.
2855 * @buf: on return contains the wwnn in hexadecimal.
2857 * Returns: size of formatted string.
2860 lpfc_soft_wwnn_show(struct device
*dev
, struct device_attribute
*attr
,
2863 struct Scsi_Host
*shost
= class_to_shost(dev
);
2864 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2865 return scnprintf(buf
, PAGE_SIZE
, "0x%llx\n",
2866 (unsigned long long)phba
->cfg_soft_wwnn
);
2870 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2871 * @dev: class device that is converted into a Scsi_host.
2872 * @attr: device attribute, not used.
2873 * @buf: contains the ww node name in hexadecimal.
2874 * @count: number of wwnn bytes in buf.
2877 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2878 * value of count on success
2881 lpfc_soft_wwnn_store(struct device
*dev
, struct device_attribute
*attr
,
2882 const char *buf
, size_t count
)
2884 struct Scsi_Host
*shost
= class_to_shost(dev
);
2885 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2886 unsigned int cnt
= count
;
2890 /* count may include a LF at end of string */
2891 if (buf
[cnt
-1] == '\n')
2894 if (!phba
->soft_wwn_enable
)
2897 rc
= lpfc_wwn_set(buf
, cnt
, wwnn
);
2899 /* Allow wwnn to be set many times, as long as the enable
2900 * is set. However, once the wwpn is set, everything locks.
2905 phba
->cfg_soft_wwnn
= wwn_to_u64(wwnn
);
2907 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
2908 "lpfc%d: soft_wwnn set. Value will take effect upon "
2909 "setting of the soft_wwpn\n", phba
->brd_no
);
2913 static DEVICE_ATTR_RW(lpfc_soft_wwnn
);
2916 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2917 * Optimized Access Storage (OAS) operations.
2918 * @dev: class device that is converted into a Scsi_host.
2919 * @attr: device attribute, not used.
2920 * @buf: buffer for passing information.
2926 lpfc_oas_tgt_show(struct device
*dev
, struct device_attribute
*attr
,
2929 struct Scsi_Host
*shost
= class_to_shost(dev
);
2930 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2932 return scnprintf(buf
, PAGE_SIZE
, "0x%llx\n",
2933 wwn_to_u64(phba
->cfg_oas_tgt_wwpn
));
2937 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2938 * Optimized Access Storage (OAS) operations.
2939 * @dev: class device that is converted into a Scsi_host.
2940 * @attr: device attribute, not used.
2941 * @buf: buffer for passing information.
2942 * @count: Size of the data buffer.
2945 * -EINVAL count is invalid, invalid wwpn byte invalid
2946 * -EPERM oas is not supported by hba
2947 * value of count on success
2950 lpfc_oas_tgt_store(struct device
*dev
, struct device_attribute
*attr
,
2951 const char *buf
, size_t count
)
2953 struct Scsi_Host
*shost
= class_to_shost(dev
);
2954 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2955 unsigned int cnt
= count
;
2956 uint8_t wwpn
[WWN_SZ
];
2962 /* count may include a LF at end of string */
2963 if (buf
[cnt
-1] == '\n')
2966 rc
= lpfc_wwn_set(buf
, cnt
, wwpn
);
2970 memcpy(phba
->cfg_oas_tgt_wwpn
, wwpn
, (8 * sizeof(uint8_t)));
2971 memcpy(phba
->sli4_hba
.oas_next_tgt_wwpn
, wwpn
, (8 * sizeof(uint8_t)));
2972 if (wwn_to_u64(wwpn
) == 0)
2973 phba
->cfg_oas_flags
|= OAS_FIND_ANY_TARGET
;
2975 phba
->cfg_oas_flags
&= ~OAS_FIND_ANY_TARGET
;
2976 phba
->cfg_oas_flags
&= ~OAS_LUN_VALID
;
2977 phba
->sli4_hba
.oas_next_lun
= FIND_FIRST_OAS_LUN
;
2980 static DEVICE_ATTR(lpfc_xlane_tgt
, S_IRUGO
| S_IWUSR
,
2981 lpfc_oas_tgt_show
, lpfc_oas_tgt_store
);
2984 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2985 * Optimized Access Storage (OAS) operations.
2986 * @dev: class device that is converted into a Scsi_host.
2987 * @attr: device attribute, not used.
2988 * @buf: buffer for passing information.
2994 lpfc_oas_priority_show(struct device
*dev
, struct device_attribute
*attr
,
2997 struct Scsi_Host
*shost
= class_to_shost(dev
);
2998 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3000 return scnprintf(buf
, PAGE_SIZE
, "%d\n", phba
->cfg_oas_priority
);
3004 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
3005 * Optimized Access Storage (OAS) operations.
3006 * @dev: class device that is converted into a Scsi_host.
3007 * @attr: device attribute, not used.
3008 * @buf: buffer for passing information.
3009 * @count: Size of the data buffer.
3012 * -EINVAL count is invalid, invalid wwpn byte invalid
3013 * -EPERM oas is not supported by hba
3014 * value of count on success
3017 lpfc_oas_priority_store(struct device
*dev
, struct device_attribute
*attr
,
3018 const char *buf
, size_t count
)
3020 struct Scsi_Host
*shost
= class_to_shost(dev
);
3021 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3022 unsigned int cnt
= count
;
3029 /* count may include a LF at end of string */
3030 if (buf
[cnt
-1] == '\n')
3033 ret
= kstrtoul(buf
, 0, &val
);
3034 if (ret
|| (val
> 0x7f))
3038 phba
->cfg_oas_priority
= (uint8_t)val
;
3040 phba
->cfg_oas_priority
= phba
->cfg_XLanePriority
;
3043 static DEVICE_ATTR(lpfc_xlane_priority
, S_IRUGO
| S_IWUSR
,
3044 lpfc_oas_priority_show
, lpfc_oas_priority_store
);
3047 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3048 * for Optimized Access Storage (OAS) operations.
3049 * @dev: class device that is converted into a Scsi_host.
3050 * @attr: device attribute, not used.
3051 * @buf: buffer for passing information.
3054 * value of count on success
3057 lpfc_oas_vpt_show(struct device
*dev
, struct device_attribute
*attr
,
3060 struct Scsi_Host
*shost
= class_to_shost(dev
);
3061 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3063 return scnprintf(buf
, PAGE_SIZE
, "0x%llx\n",
3064 wwn_to_u64(phba
->cfg_oas_vpt_wwpn
));
3068 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3069 * for Optimized Access Storage (OAS) operations.
3070 * @dev: class device that is converted into a Scsi_host.
3071 * @attr: device attribute, not used.
3072 * @buf: buffer for passing information.
3073 * @count: Size of the data buffer.
3076 * -EINVAL count is invalid, invalid wwpn byte invalid
3077 * -EPERM oas is not supported by hba
3078 * value of count on success
3081 lpfc_oas_vpt_store(struct device
*dev
, struct device_attribute
*attr
,
3082 const char *buf
, size_t count
)
3084 struct Scsi_Host
*shost
= class_to_shost(dev
);
3085 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3086 unsigned int cnt
= count
;
3087 uint8_t wwpn
[WWN_SZ
];
3093 /* count may include a LF at end of string */
3094 if (buf
[cnt
-1] == '\n')
3097 rc
= lpfc_wwn_set(buf
, cnt
, wwpn
);
3101 memcpy(phba
->cfg_oas_vpt_wwpn
, wwpn
, (8 * sizeof(uint8_t)));
3102 memcpy(phba
->sli4_hba
.oas_next_vpt_wwpn
, wwpn
, (8 * sizeof(uint8_t)));
3103 if (wwn_to_u64(wwpn
) == 0)
3104 phba
->cfg_oas_flags
|= OAS_FIND_ANY_VPORT
;
3106 phba
->cfg_oas_flags
&= ~OAS_FIND_ANY_VPORT
;
3107 phba
->cfg_oas_flags
&= ~OAS_LUN_VALID
;
3108 if (phba
->cfg_oas_priority
== 0)
3109 phba
->cfg_oas_priority
= phba
->cfg_XLanePriority
;
3110 phba
->sli4_hba
.oas_next_lun
= FIND_FIRST_OAS_LUN
;
3113 static DEVICE_ATTR(lpfc_xlane_vpt
, S_IRUGO
| S_IWUSR
,
3114 lpfc_oas_vpt_show
, lpfc_oas_vpt_store
);
3117 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3118 * of whether luns will be enabled or disabled
3119 * for Optimized Access Storage (OAS) operations.
3120 * @dev: class device that is converted into a Scsi_host.
3121 * @attr: device attribute, not used.
3122 * @buf: buffer for passing information.
3125 * size of formatted string.
3128 lpfc_oas_lun_state_show(struct device
*dev
, struct device_attribute
*attr
,
3131 struct Scsi_Host
*shost
= class_to_shost(dev
);
3132 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3134 return scnprintf(buf
, PAGE_SIZE
, "%d\n", phba
->cfg_oas_lun_state
);
3138 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3139 * of whether luns will be enabled or disabled
3140 * for Optimized Access Storage (OAS) operations.
3141 * @dev: class device that is converted into a Scsi_host.
3142 * @attr: device attribute, not used.
3143 * @buf: buffer for passing information.
3144 * @count: Size of the data buffer.
3147 * -EINVAL count is invalid, invalid wwpn byte invalid
3148 * -EPERM oas is not supported by hba
3149 * value of count on success
3152 lpfc_oas_lun_state_store(struct device
*dev
, struct device_attribute
*attr
,
3153 const char *buf
, size_t count
)
3155 struct Scsi_Host
*shost
= class_to_shost(dev
);
3156 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3162 if (!isdigit(buf
[0]))
3165 if (sscanf(buf
, "%i", &val
) != 1)
3168 if ((val
!= 0) && (val
!= 1))
3171 phba
->cfg_oas_lun_state
= val
;
3174 static DEVICE_ATTR(lpfc_xlane_lun_state
, S_IRUGO
| S_IWUSR
,
3175 lpfc_oas_lun_state_show
, lpfc_oas_lun_state_store
);
3178 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3179 * Storage (OAS) lun returned by the
3180 * lpfc_oas_lun_show function.
3181 * @dev: class device that is converted into a Scsi_host.
3182 * @attr: device attribute, not used.
3183 * @buf: buffer for passing information.
3186 * size of formatted string.
3189 lpfc_oas_lun_status_show(struct device
*dev
, struct device_attribute
*attr
,
3192 struct Scsi_Host
*shost
= class_to_shost(dev
);
3193 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3195 if (!(phba
->cfg_oas_flags
& OAS_LUN_VALID
))
3198 return scnprintf(buf
, PAGE_SIZE
, "%d\n", phba
->cfg_oas_lun_status
);
3200 static DEVICE_ATTR(lpfc_xlane_lun_status
, S_IRUGO
,
3201 lpfc_oas_lun_status_show
, NULL
);
3205 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3207 * @phba: lpfc_hba pointer.
3208 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3209 * @tgt_wwpn: wwpn of the target associated with the returned lun
3210 * @lun: the fc lun for setting oas state.
3211 * @oas_state: the oas state to be set to the lun.
3216 * -EPERM OAS is not enabled or not supported by this port.
3220 lpfc_oas_lun_state_set(struct lpfc_hba
*phba
, uint8_t vpt_wwpn
[],
3221 uint8_t tgt_wwpn
[], uint64_t lun
,
3222 uint32_t oas_state
, uint8_t pri
)
3231 if (!lpfc_enable_oas_lun(phba
, (struct lpfc_name
*)vpt_wwpn
,
3232 (struct lpfc_name
*)tgt_wwpn
,
3236 lpfc_disable_oas_lun(phba
, (struct lpfc_name
*)vpt_wwpn
,
3237 (struct lpfc_name
*)tgt_wwpn
, lun
, pri
);
3244 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3245 * Access Storage (OAS) operations.
3246 * @phba: lpfc_hba pointer.
3247 * @vpt_wwpn: wwpn of the vport associated with the returned lun
3248 * @tgt_wwpn: wwpn of the target associated with the returned lun
3249 * @lun_status: status of the lun returned lun
3250 * @lun_pri: priority of the lun returned lun
3252 * Returns the first or next lun enabled for OAS operations for the vport/target
3253 * specified. If a lun is found, its vport wwpn, target wwpn and status is
3254 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3257 * lun that is OAS enabled for the vport/target
3258 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3261 lpfc_oas_lun_get_next(struct lpfc_hba
*phba
, uint8_t vpt_wwpn
[],
3262 uint8_t tgt_wwpn
[], uint32_t *lun_status
,
3267 if (unlikely(!phba
) || !vpt_wwpn
|| !tgt_wwpn
)
3268 return NOT_OAS_ENABLED_LUN
;
3269 if (lpfc_find_next_oas_lun(phba
, (struct lpfc_name
*)
3270 phba
->sli4_hba
.oas_next_vpt_wwpn
,
3271 (struct lpfc_name
*)
3272 phba
->sli4_hba
.oas_next_tgt_wwpn
,
3273 &phba
->sli4_hba
.oas_next_lun
,
3274 (struct lpfc_name
*)vpt_wwpn
,
3275 (struct lpfc_name
*)tgt_wwpn
,
3276 &found_lun
, lun_status
, lun_pri
))
3279 return NOT_OAS_ENABLED_LUN
;
3283 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3284 * @phba: lpfc_hba pointer.
3285 * @vpt_wwpn: vport wwpn by reference.
3286 * @tgt_wwpn: target wwpn by reference.
3287 * @lun: the fc lun for setting oas state.
3288 * @oas_state: the oas state to be set to the oas_lun.
3291 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3292 * a lun for OAS operations.
3296 * -ENOMEM: failed to enable an lun for OAS operations
3297 * -EPERM: OAS is not enabled
3300 lpfc_oas_lun_state_change(struct lpfc_hba
*phba
, uint8_t vpt_wwpn
[],
3301 uint8_t tgt_wwpn
[], uint64_t lun
,
3302 uint32_t oas_state
, uint8_t pri
)
3307 rc
= lpfc_oas_lun_state_set(phba
, vpt_wwpn
, tgt_wwpn
, lun
,
3313 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3314 * @dev: class device that is converted into a Scsi_host.
3315 * @attr: device attribute, not used.
3316 * @buf: buffer for passing information.
3318 * This routine returns a lun enabled for OAS each time the function
3322 * SUCCESS: size of formatted string.
3323 * -EFAULT: target or vport wwpn was not set properly.
3324 * -EPERM: oas is not enabled.
3327 lpfc_oas_lun_show(struct device
*dev
, struct device_attribute
*attr
,
3330 struct Scsi_Host
*shost
= class_to_shost(dev
);
3331 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3339 if (wwn_to_u64(phba
->cfg_oas_vpt_wwpn
) == 0)
3340 if (!(phba
->cfg_oas_flags
& OAS_FIND_ANY_VPORT
))
3343 if (wwn_to_u64(phba
->cfg_oas_tgt_wwpn
) == 0)
3344 if (!(phba
->cfg_oas_flags
& OAS_FIND_ANY_TARGET
))
3347 oas_lun
= lpfc_oas_lun_get_next(phba
, phba
->cfg_oas_vpt_wwpn
,
3348 phba
->cfg_oas_tgt_wwpn
,
3349 &phba
->cfg_oas_lun_status
,
3350 &phba
->cfg_oas_priority
);
3351 if (oas_lun
!= NOT_OAS_ENABLED_LUN
)
3352 phba
->cfg_oas_flags
|= OAS_LUN_VALID
;
3354 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "0x%llx", oas_lun
);
3360 * lpfc_oas_lun_store - Sets the OAS state for lun
3361 * @dev: class device that is converted into a Scsi_host.
3362 * @attr: device attribute, not used.
3363 * @buf: buffer for passing information.
3364 * @count: size of the formatting string
3366 * This function sets the OAS state for lun. Before this function is called,
3367 * the vport wwpn, target wwpn, and oas state need to be set.
3370 * SUCCESS: size of formatted string.
3371 * -EFAULT: target or vport wwpn was not set properly.
3372 * -EPERM: oas is not enabled.
3373 * size of formatted string.
3376 lpfc_oas_lun_store(struct device
*dev
, struct device_attribute
*attr
,
3377 const char *buf
, size_t count
)
3379 struct Scsi_Host
*shost
= class_to_shost(dev
);
3380 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3388 if (wwn_to_u64(phba
->cfg_oas_vpt_wwpn
) == 0)
3391 if (wwn_to_u64(phba
->cfg_oas_tgt_wwpn
) == 0)
3394 if (!isdigit(buf
[0]))
3397 if (sscanf(buf
, "0x%llx", &scsi_lun
) != 1)
3400 pri
= phba
->cfg_oas_priority
;
3402 pri
= phba
->cfg_XLanePriority
;
3404 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3405 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3406 "priority 0x%x with oas state %d\n",
3407 wwn_to_u64(phba
->cfg_oas_vpt_wwpn
),
3408 wwn_to_u64(phba
->cfg_oas_tgt_wwpn
), scsi_lun
,
3409 pri
, phba
->cfg_oas_lun_state
);
3411 rc
= lpfc_oas_lun_state_change(phba
, phba
->cfg_oas_vpt_wwpn
,
3412 phba
->cfg_oas_tgt_wwpn
, scsi_lun
,
3413 phba
->cfg_oas_lun_state
, pri
);
3419 static DEVICE_ATTR(lpfc_xlane_lun
, S_IRUGO
| S_IWUSR
,
3420 lpfc_oas_lun_show
, lpfc_oas_lun_store
);
3422 int lpfc_enable_nvmet_cnt
;
3423 unsigned long long lpfc_enable_nvmet
[LPFC_NVMET_MAX_PORTS
] = {
3424 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3425 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3426 module_param_array(lpfc_enable_nvmet
, ullong
, &lpfc_enable_nvmet_cnt
, 0444);
3427 MODULE_PARM_DESC(lpfc_enable_nvmet
, "Enable HBA port(s) WWPN as a NVME Target");
3429 static int lpfc_poll
= 0;
3430 module_param(lpfc_poll
, int, S_IRUGO
);
3431 MODULE_PARM_DESC(lpfc_poll
, "FCP ring polling mode control:"
3433 " 1 - poll with interrupts enabled"
3434 " 3 - poll and disable FCP ring interrupts");
3436 static DEVICE_ATTR_RW(lpfc_poll
);
3438 int lpfc_no_hba_reset_cnt
;
3439 unsigned long lpfc_no_hba_reset
[MAX_HBAS_NO_RESET
] = {
3440 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3441 module_param_array(lpfc_no_hba_reset
, ulong
, &lpfc_no_hba_reset_cnt
, 0444);
3442 MODULE_PARM_DESC(lpfc_no_hba_reset
, "WWPN of HBAs that should not be reset");
3444 LPFC_ATTR(sli_mode
, 0, 0, 3,
3445 "SLI mode selector:"
3446 " 0 - auto (SLI-3 if supported),"
3447 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3448 " 3 - select SLI-3");
3450 LPFC_ATTR_R(enable_npiv
, 1, 0, 1,
3451 "Enable NPIV functionality");
3453 LPFC_ATTR_R(fcf_failover_policy
, 1, 1, 2,
3454 "FCF Fast failover=1 Priority failover=2");
3457 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3458 # 0x0 = disabled, XRI/OXID use not tracked.
3459 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3460 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3462 LPFC_ATTR_R(enable_rrq
, 2, 0, 2,
3463 "Enable RRQ functionality");
3466 # lpfc_suppress_link_up: Bring link up at initialization
3467 # 0x0 = bring link up (issue MBX_INIT_LINK)
3468 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3469 # 0x2 = never bring up link
3470 # Default value is 0.
3472 LPFC_ATTR_R(suppress_link_up
, LPFC_INITIALIZE_LINK
, LPFC_INITIALIZE_LINK
,
3473 LPFC_DELAY_INIT_LINK_INDEFINITELY
,
3474 "Suppress Link Up at initialization");
3477 lpfc_pls_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3479 struct Scsi_Host
*shost
= class_to_shost(dev
);
3480 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3482 return scnprintf(buf
, PAGE_SIZE
, "%d\n",
3483 phba
->sli4_hba
.pc_sli4_params
.pls
);
3485 static DEVICE_ATTR(pls
, 0444,
3486 lpfc_pls_show
, NULL
);
3489 lpfc_pt_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3491 struct Scsi_Host
*shost
= class_to_shost(dev
);
3492 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
3494 return scnprintf(buf
, PAGE_SIZE
, "%d\n",
3495 (phba
->hba_flag
& HBA_PERSISTENT_TOPO
) ? 1 : 0);
3497 static DEVICE_ATTR(pt
, 0444,
3498 lpfc_pt_show
, NULL
);
3501 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3509 lpfc_iocb_hw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3511 struct Scsi_Host
*shost
= class_to_shost(dev
);
3512 struct lpfc_hba
*phba
= ((struct lpfc_vport
*) shost
->hostdata
)->phba
;
3514 return scnprintf(buf
, PAGE_SIZE
, "%d\n", phba
->iocb_max
);
3517 static DEVICE_ATTR(iocb_hw
, S_IRUGO
,
3518 lpfc_iocb_hw_show
, NULL
);
3520 lpfc_txq_hw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3522 struct Scsi_Host
*shost
= class_to_shost(dev
);
3523 struct lpfc_hba
*phba
= ((struct lpfc_vport
*) shost
->hostdata
)->phba
;
3524 struct lpfc_sli_ring
*pring
= lpfc_phba_elsring(phba
);
3526 return scnprintf(buf
, PAGE_SIZE
, "%d\n",
3527 pring
? pring
->txq_max
: 0);
3530 static DEVICE_ATTR(txq_hw
, S_IRUGO
,
3531 lpfc_txq_hw_show
, NULL
);
3533 lpfc_txcmplq_hw_show(struct device
*dev
, struct device_attribute
*attr
,
3536 struct Scsi_Host
*shost
= class_to_shost(dev
);
3537 struct lpfc_hba
*phba
= ((struct lpfc_vport
*) shost
->hostdata
)->phba
;
3538 struct lpfc_sli_ring
*pring
= lpfc_phba_elsring(phba
);
3540 return scnprintf(buf
, PAGE_SIZE
, "%d\n",
3541 pring
? pring
->txcmplq_max
: 0);
3544 static DEVICE_ATTR(txcmplq_hw
, S_IRUGO
,
3545 lpfc_txcmplq_hw_show
, NULL
);
3548 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3549 # until the timer expires. Value range is [0,255]. Default value is 30.
3551 static int lpfc_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
3552 static int lpfc_devloss_tmo
= LPFC_DEF_DEVLOSS_TMO
;
3553 module_param(lpfc_nodev_tmo
, int, 0);
3554 MODULE_PARM_DESC(lpfc_nodev_tmo
,
3555 "Seconds driver will hold I/O waiting "
3556 "for a device to come back");
3559 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3560 * @dev: class converted to a Scsi_host structure.
3561 * @attr: device attribute, not used.
3562 * @buf: on return contains the dev loss timeout in decimal.
3564 * Returns: size of formatted string.
3567 lpfc_nodev_tmo_show(struct device
*dev
, struct device_attribute
*attr
,
3570 struct Scsi_Host
*shost
= class_to_shost(dev
);
3571 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3573 return scnprintf(buf
, PAGE_SIZE
, "%d\n", vport
->cfg_devloss_tmo
);
3577 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3578 * @vport: lpfc vport structure pointer.
3579 * @val: contains the nodev timeout value.
3582 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3583 * a kernel error message is printed and zero is returned.
3584 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3585 * Otherwise nodev tmo is set to the default value.
3588 * zero if already set or if val is in range
3589 * -EINVAL val out of range
3592 lpfc_nodev_tmo_init(struct lpfc_vport
*vport
, int val
)
3594 if (vport
->cfg_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
) {
3595 vport
->cfg_nodev_tmo
= vport
->cfg_devloss_tmo
;
3596 if (val
!= LPFC_DEF_DEVLOSS_TMO
)
3597 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3598 "0407 Ignoring lpfc_nodev_tmo module "
3599 "parameter because lpfc_devloss_tmo "
3604 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
3605 vport
->cfg_nodev_tmo
= val
;
3606 vport
->cfg_devloss_tmo
= val
;
3609 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3610 "0400 lpfc_nodev_tmo attribute cannot be set to"
3611 " %d, allowed range is [%d, %d]\n",
3612 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
3613 vport
->cfg_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
3618 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3619 * @vport: lpfc vport structure pointer.
3622 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3625 lpfc_update_rport_devloss_tmo(struct lpfc_vport
*vport
)
3627 struct Scsi_Host
*shost
;
3628 struct lpfc_nodelist
*ndlp
;
3629 #if (IS_ENABLED(CONFIG_NVME_FC))
3630 struct lpfc_nvme_rport
*rport
;
3631 struct nvme_fc_remote_port
*remoteport
= NULL
;
3634 shost
= lpfc_shost_from_vport(vport
);
3635 spin_lock_irq(shost
->host_lock
);
3636 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3638 ndlp
->rport
->dev_loss_tmo
= vport
->cfg_devloss_tmo
;
3639 #if (IS_ENABLED(CONFIG_NVME_FC))
3640 spin_lock(&ndlp
->lock
);
3641 rport
= lpfc_ndlp_get_nrport(ndlp
);
3643 remoteport
= rport
->remoteport
;
3644 spin_unlock(&ndlp
->lock
);
3645 if (rport
&& remoteport
)
3646 nvme_fc_set_remoteport_devloss(remoteport
,
3647 vport
->cfg_devloss_tmo
);
3650 spin_unlock_irq(shost
->host_lock
);
3654 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3655 * @vport: lpfc vport structure pointer.
3656 * @val: contains the tmo value.
3659 * If the devloss tmo is already set or the vport dev loss tmo has changed
3660 * then a kernel error message is printed and zero is returned.
3661 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3662 * Otherwise nodev tmo is set to the default value.
3665 * zero if already set or if val is in range
3666 * -EINVAL val out of range
3669 lpfc_nodev_tmo_set(struct lpfc_vport
*vport
, int val
)
3671 if (vport
->dev_loss_tmo_changed
||
3672 (lpfc_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
)) {
3673 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3674 "0401 Ignoring change to lpfc_nodev_tmo "
3675 "because lpfc_devloss_tmo is set.\n");
3678 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
3679 vport
->cfg_nodev_tmo
= val
;
3680 vport
->cfg_devloss_tmo
= val
;
3682 * For compat: set the fc_host dev loss so new rports
3683 * will get the value.
3685 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport
)) = val
;
3686 lpfc_update_rport_devloss_tmo(vport
);
3689 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3690 "0403 lpfc_nodev_tmo attribute cannot be set to "
3691 "%d, allowed range is [%d, %d]\n",
3692 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
3696 lpfc_vport_param_store(nodev_tmo
)
3698 static DEVICE_ATTR_RW(lpfc_nodev_tmo
);
3701 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3702 # disappear until the timer expires. Value range is [0,255]. Default
3705 module_param(lpfc_devloss_tmo
, int, S_IRUGO
);
3706 MODULE_PARM_DESC(lpfc_devloss_tmo
,
3707 "Seconds driver will hold I/O waiting "
3708 "for a device to come back");
3709 lpfc_vport_param_init(devloss_tmo
, LPFC_DEF_DEVLOSS_TMO
,
3710 LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
)
3711 lpfc_vport_param_show(devloss_tmo
)
3714 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3715 * @vport: lpfc vport structure pointer.
3716 * @val: contains the tmo value.
3719 * If val is in a valid range then set the vport nodev tmo,
3720 * devloss tmo, also set the vport dev loss tmo changed flag.
3721 * Else a kernel error message is printed.
3724 * zero if val is in range
3725 * -EINVAL val out of range
3728 lpfc_devloss_tmo_set(struct lpfc_vport
*vport
, int val
)
3730 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
3731 vport
->cfg_nodev_tmo
= val
;
3732 vport
->cfg_devloss_tmo
= val
;
3733 vport
->dev_loss_tmo_changed
= 1;
3734 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport
)) = val
;
3735 lpfc_update_rport_devloss_tmo(vport
);
3739 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3740 "0404 lpfc_devloss_tmo attribute cannot be set to "
3741 "%d, allowed range is [%d, %d]\n",
3742 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
3746 lpfc_vport_param_store(devloss_tmo
)
3747 static DEVICE_ATTR_RW(lpfc_devloss_tmo
);
3750 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3751 * lpfc_suppress_rsp = 0 Disable
3752 * lpfc_suppress_rsp = 1 Enable (default)
3755 LPFC_ATTR_R(suppress_rsp
, 1, 0, 1,
3756 "Enable suppress rsp feature is firmware supports it");
3759 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3760 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
3761 * lpfc_nvmet_mrq = 1 use a single RQ pair
3762 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3765 LPFC_ATTR_R(nvmet_mrq
,
3766 LPFC_NVMET_MRQ_AUTO
, LPFC_NVMET_MRQ_AUTO
, LPFC_NVMET_MRQ_MAX
,
3767 "Specify number of RQ pairs for processing NVMET cmds");
3770 * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3771 * to each NVMET RQ. Range 64 to 2048, default is 512.
3773 LPFC_ATTR_R(nvmet_mrq_post
,
3774 LPFC_NVMET_RQE_DEF_POST
, LPFC_NVMET_RQE_MIN_POST
,
3775 LPFC_NVMET_RQE_DEF_COUNT
,
3776 "Specify number of RQ buffers to initially post");
3779 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3780 * Supported Values: 1 - register just FCP
3781 * 3 - register both FCP and NVME
3782 * Supported values are [1,3]. Default value is 3
3784 LPFC_ATTR_R(enable_fc4_type
, LPFC_ENABLE_BOTH
,
3785 LPFC_ENABLE_FCP
, LPFC_ENABLE_BOTH
,
3786 "Enable FC4 Protocol support - FCP / NVME");
3789 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3790 # deluged with LOTS of information.
3791 # You can set a bit mask to record specific types of verbose messages:
3792 # See lpfc_logmsh.h for definitions.
3794 LPFC_VPORT_ATTR_HEX_RW(log_verbose
, 0x0, 0x0, 0xffffffff,
3795 "Verbose logging bit-mask");
3798 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3799 # objects that have been registered with the nameserver after login.
3801 LPFC_VPORT_ATTR_R(enable_da_id
, 1, 0, 1,
3802 "Deregister nameserver objects before LOGO");
3805 # lun_queue_depth: This parameter is used to limit the number of outstanding
3806 # commands per FCP LUN.
3808 LPFC_VPORT_ATTR_R(lun_queue_depth
, 64, 1, 512,
3809 "Max number of FCP commands we can queue to a specific LUN");
3812 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3813 # commands per target port. Value range is [10,65535]. Default value is 65535.
3815 static uint lpfc_tgt_queue_depth
= LPFC_MAX_TGT_QDEPTH
;
3816 module_param(lpfc_tgt_queue_depth
, uint
, 0444);
3817 MODULE_PARM_DESC(lpfc_tgt_queue_depth
, "Set max Target queue depth");
3818 lpfc_vport_param_show(tgt_queue_depth
);
3819 lpfc_vport_param_init(tgt_queue_depth
, LPFC_MAX_TGT_QDEPTH
,
3820 LPFC_MIN_TGT_QDEPTH
, LPFC_MAX_TGT_QDEPTH
);
3823 * lpfc_tgt_queue_depth_store: Sets an attribute value.
3824 * @vport: lpfc vport structure pointer.
3825 * @val: integer attribute value.
3827 * Description: Sets the parameter to the new value.
3831 * -EINVAL if val is invalid
3834 lpfc_tgt_queue_depth_set(struct lpfc_vport
*vport
, uint val
)
3836 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3837 struct lpfc_nodelist
*ndlp
;
3839 if (!lpfc_rangecheck(val
, LPFC_MIN_TGT_QDEPTH
, LPFC_MAX_TGT_QDEPTH
))
3842 if (val
== vport
->cfg_tgt_queue_depth
)
3845 spin_lock_irq(shost
->host_lock
);
3846 vport
->cfg_tgt_queue_depth
= val
;
3848 /* Next loop thru nodelist and change cmd_qdepth */
3849 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
)
3850 ndlp
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
3852 spin_unlock_irq(shost
->host_lock
);
3856 lpfc_vport_param_store(tgt_queue_depth
);
3857 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth
);
3860 # hba_queue_depth: This parameter is used to limit the number of outstanding
3861 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3862 # value is greater than the maximum number of exchanges supported by the HBA,
3863 # then maximum number of exchanges supported by the HBA is used to determine
3864 # the hba_queue_depth.
3866 LPFC_ATTR_R(hba_queue_depth
, 8192, 32, 8192,
3867 "Max number of FCP commands we can queue to a lpfc HBA");
3870 # peer_port_login: This parameter allows/prevents logins
3871 # between peer ports hosted on the same physical port.
3872 # When this parameter is set 0 peer ports of same physical port
3873 # are not allowed to login to each other.
3874 # When this parameter is set 1 peer ports of same physical port
3875 # are allowed to login to each other.
3876 # Default value of this parameter is 0.
3878 LPFC_VPORT_ATTR_R(peer_port_login
, 0, 0, 1,
3879 "Allow peer ports on the same physical port to login to each "
3883 # restrict_login: This parameter allows/prevents logins
3884 # between Virtual Ports and remote initiators.
3885 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3886 # other initiators and will attempt to PLOGI all remote ports.
3887 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3888 # remote ports and will not attempt to PLOGI to other initiators.
3889 # This parameter does not restrict to the physical port.
3890 # This parameter does not restrict logins to Fabric resident remote ports.
3891 # Default value of this parameter is 1.
3893 static int lpfc_restrict_login
= 1;
3894 module_param(lpfc_restrict_login
, int, S_IRUGO
);
3895 MODULE_PARM_DESC(lpfc_restrict_login
,
3896 "Restrict virtual ports login to remote initiators.");
3897 lpfc_vport_param_show(restrict_login
);
3900 * lpfc_restrict_login_init - Set the vport restrict login flag
3901 * @vport: lpfc vport structure pointer.
3902 * @val: contains the restrict login value.
3905 * If val is not in a valid range then log a kernel error message and set
3906 * the vport restrict login to one.
3907 * If the port type is physical clear the restrict login flag and return.
3908 * Else set the restrict login flag to val.
3911 * zero if val is in range
3912 * -EINVAL val out of range
3915 lpfc_restrict_login_init(struct lpfc_vport
*vport
, int val
)
3917 if (val
< 0 || val
> 1) {
3918 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3919 "0422 lpfc_restrict_login attribute cannot "
3920 "be set to %d, allowed range is [0, 1]\n",
3922 vport
->cfg_restrict_login
= 1;
3925 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
3926 vport
->cfg_restrict_login
= 0;
3929 vport
->cfg_restrict_login
= val
;
3934 * lpfc_restrict_login_set - Set the vport restrict login flag
3935 * @vport: lpfc vport structure pointer.
3936 * @val: contains the restrict login value.
3939 * If val is not in a valid range then log a kernel error message and set
3940 * the vport restrict login to one.
3941 * If the port type is physical and the val is not zero log a kernel
3942 * error message, clear the restrict login flag and return zero.
3943 * Else set the restrict login flag to val.
3946 * zero if val is in range
3947 * -EINVAL val out of range
3950 lpfc_restrict_login_set(struct lpfc_vport
*vport
, int val
)
3952 if (val
< 0 || val
> 1) {
3953 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3954 "0425 lpfc_restrict_login attribute cannot "
3955 "be set to %d, allowed range is [0, 1]\n",
3957 vport
->cfg_restrict_login
= 1;
3960 if (vport
->port_type
== LPFC_PHYSICAL_PORT
&& val
!= 0) {
3961 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3962 "0468 lpfc_restrict_login must be 0 for "
3963 "Physical ports.\n");
3964 vport
->cfg_restrict_login
= 0;
3967 vport
->cfg_restrict_login
= val
;
3970 lpfc_vport_param_store(restrict_login
);
3971 static DEVICE_ATTR_RW(lpfc_restrict_login
);
3974 # Some disk devices have a "select ID" or "select Target" capability.
3975 # From a protocol standpoint "select ID" usually means select the
3976 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3977 # annex" which contains a table that maps a "select ID" (a number
3978 # between 0 and 7F) to an ALPA. By default, for compatibility with
3979 # older drivers, the lpfc driver scans this table from low ALPA to high
3982 # Turning on the scan-down variable (on = 1, off = 0) will
3983 # cause the lpfc driver to use an inverted table, effectively
3984 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3986 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3987 # and will not work across a fabric. Also this parameter will take
3988 # effect only in the case when ALPA map is not available.)
3990 LPFC_VPORT_ATTR_R(scan_down
, 1, 0, 1,
3991 "Start scanning for devices from highest ALPA to lowest");
3994 # lpfc_topology: link topology for init link
3995 # 0x0 = attempt loop mode then point-to-point
3996 # 0x01 = internal loopback mode
3997 # 0x02 = attempt point-to-point mode only
3998 # 0x04 = attempt loop mode only
3999 # 0x06 = attempt point-to-point mode then loop
4000 # Set point-to-point mode if you want to run as an N_Port.
4001 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
4002 # Default value is 0.
4004 LPFC_ATTR(topology
, 0, 0, 6,
4005 "Select Fibre Channel topology");
4008 * lpfc_topology_set - Set the adapters topology field
4009 * @dev: class device that is converted into a scsi_host.
4010 * @attr:device attribute, not used.
4011 * @buf: buffer for passing information.
4012 * @count: size of the data buffer.
4015 * If val is in a valid range then set the adapter's topology field and
4016 * issue a lip; if the lip fails reset the topology to the old value.
4018 * If the value is not in range log a kernel error message and return an error.
4021 * zero if val is in range and lip okay
4022 * non-zero return value from lpfc_issue_lip()
4023 * -EINVAL val out of range
4026 lpfc_topology_store(struct device
*dev
, struct device_attribute
*attr
,
4027 const char *buf
, size_t count
)
4029 struct Scsi_Host
*shost
= class_to_shost(dev
);
4030 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4031 struct lpfc_hba
*phba
= vport
->phba
;
4034 const char *val_buf
= buf
;
4038 if (!strncmp(buf
, "nolip ", strlen("nolip "))) {
4040 val_buf
= &buf
[strlen("nolip ")];
4043 if (!isdigit(val_buf
[0]))
4045 if (sscanf(val_buf
, "%i", &val
) != 1)
4048 if (val
>= 0 && val
<= 6) {
4049 prev_val
= phba
->cfg_topology
;
4050 if (phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_16G
&&
4052 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
4053 "3113 Loop mode not supported at speed %d\n",
4058 * The 'topology' is not a configurable parameter if :
4059 * - persistent topology enabled
4060 * - G7/G6 with no private loop support
4063 if ((phba
->hba_flag
& HBA_PERSISTENT_TOPO
||
4064 (!phba
->sli4_hba
.pc_sli4_params
.pls
&&
4065 (phba
->pcidev
->device
== PCI_DEVICE_ID_LANCER_G6_FC
||
4066 phba
->pcidev
->device
== PCI_DEVICE_ID_LANCER_G7_FC
))) &&
4068 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
4069 "3114 Loop mode not supported\n");
4072 phba
->cfg_topology
= val
;
4076 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
4077 "3054 lpfc_topology changed from %d to %d\n",
4079 if (prev_val
!= val
&& phba
->sli_rev
== LPFC_SLI_REV4
)
4080 phba
->fc_topology_changed
= 1;
4081 err
= lpfc_issue_lip(lpfc_shost_from_vport(phba
->pport
));
4083 phba
->cfg_topology
= prev_val
;
4088 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4089 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4090 "allowed range is [0, 6]\n",
4095 lpfc_param_show(topology
)
4096 static DEVICE_ATTR_RW(lpfc_topology
);
4099 * lpfc_static_vport_show: Read callback function for
4100 * lpfc_static_vport sysfs file.
4101 * @dev: Pointer to class device object.
4102 * @attr: device attribute structure.
4103 * @buf: Data buffer.
4105 * This function is the read call back function for
4106 * lpfc_static_vport sysfs file. The lpfc_static_vport
4107 * sysfs file report the mageability of the vport.
4110 lpfc_static_vport_show(struct device
*dev
, struct device_attribute
*attr
,
4113 struct Scsi_Host
*shost
= class_to_shost(dev
);
4114 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4115 if (vport
->vport_flag
& STATIC_VPORT
)
4116 sprintf(buf
, "1\n");
4118 sprintf(buf
, "0\n");
4124 * Sysfs attribute to control the statistical data collection.
4126 static DEVICE_ATTR_RO(lpfc_static_vport
);
4129 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
4130 * @dev: Pointer to class device.
4132 * @buf: Data buffer.
4133 * @count: Size of the data buffer.
4135 * This function get called when a user write to the lpfc_stat_data_ctrl
4136 * sysfs file. This function parse the command written to the sysfs file
4137 * and take appropriate action. These commands are used for controlling
4138 * driver statistical data collection.
4139 * Following are the command this function handles.
4141 * setbucket <bucket_type> <base> <step>
4142 * = Set the latency buckets.
4143 * destroybucket = destroy all the buckets.
4144 * start = start data collection
4145 * stop = stop data collection
4146 * reset = reset the collected data
4149 lpfc_stat_data_ctrl_store(struct device
*dev
, struct device_attribute
*attr
,
4150 const char *buf
, size_t count
)
4152 struct Scsi_Host
*shost
= class_to_shost(dev
);
4153 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4154 struct lpfc_hba
*phba
= vport
->phba
;
4155 #define LPFC_MAX_DATA_CTRL_LEN 1024
4156 static char bucket_data
[LPFC_MAX_DATA_CTRL_LEN
];
4158 char *str_ptr
, *token
;
4159 struct lpfc_vport
**vports
;
4160 struct Scsi_Host
*v_shost
;
4161 char *bucket_type_str
, *base_str
, *step_str
;
4162 unsigned long base
, step
, bucket_type
;
4164 if (!strncmp(buf
, "setbucket", strlen("setbucket"))) {
4165 if (strlen(buf
) > (LPFC_MAX_DATA_CTRL_LEN
- 1))
4168 strncpy(bucket_data
, buf
, LPFC_MAX_DATA_CTRL_LEN
);
4169 str_ptr
= &bucket_data
[0];
4170 /* Ignore this token - this is command token */
4171 token
= strsep(&str_ptr
, "\t ");
4175 bucket_type_str
= strsep(&str_ptr
, "\t ");
4176 if (!bucket_type_str
)
4179 if (!strncmp(bucket_type_str
, "linear", strlen("linear")))
4180 bucket_type
= LPFC_LINEAR_BUCKET
;
4181 else if (!strncmp(bucket_type_str
, "power2", strlen("power2")))
4182 bucket_type
= LPFC_POWER2_BUCKET
;
4186 base_str
= strsep(&str_ptr
, "\t ");
4189 base
= simple_strtoul(base_str
, NULL
, 0);
4191 step_str
= strsep(&str_ptr
, "\t ");
4194 step
= simple_strtoul(step_str
, NULL
, 0);
4198 /* Block the data collection for every vport */
4199 vports
= lpfc_create_vport_work_array(phba
);
4203 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4204 v_shost
= lpfc_shost_from_vport(vports
[i
]);
4205 spin_lock_irq(v_shost
->host_lock
);
4206 /* Block and reset data collection */
4207 vports
[i
]->stat_data_blocked
= 1;
4208 if (vports
[i
]->stat_data_enabled
)
4209 lpfc_vport_reset_stat_data(vports
[i
]);
4210 spin_unlock_irq(v_shost
->host_lock
);
4213 /* Set the bucket attributes */
4214 phba
->bucket_type
= bucket_type
;
4215 phba
->bucket_base
= base
;
4216 phba
->bucket_step
= step
;
4218 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4219 v_shost
= lpfc_shost_from_vport(vports
[i
]);
4221 /* Unblock data collection */
4222 spin_lock_irq(v_shost
->host_lock
);
4223 vports
[i
]->stat_data_blocked
= 0;
4224 spin_unlock_irq(v_shost
->host_lock
);
4226 lpfc_destroy_vport_work_array(phba
, vports
);
4230 if (!strncmp(buf
, "destroybucket", strlen("destroybucket"))) {
4231 vports
= lpfc_create_vport_work_array(phba
);
4235 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4236 v_shost
= lpfc_shost_from_vport(vports
[i
]);
4237 spin_lock_irq(shost
->host_lock
);
4238 vports
[i
]->stat_data_blocked
= 1;
4239 lpfc_free_bucket(vport
);
4240 vport
->stat_data_enabled
= 0;
4241 vports
[i
]->stat_data_blocked
= 0;
4242 spin_unlock_irq(shost
->host_lock
);
4244 lpfc_destroy_vport_work_array(phba
, vports
);
4245 phba
->bucket_type
= LPFC_NO_BUCKET
;
4246 phba
->bucket_base
= 0;
4247 phba
->bucket_step
= 0;
4251 if (!strncmp(buf
, "start", strlen("start"))) {
4252 /* If no buckets configured return error */
4253 if (phba
->bucket_type
== LPFC_NO_BUCKET
)
4255 spin_lock_irq(shost
->host_lock
);
4256 if (vport
->stat_data_enabled
) {
4257 spin_unlock_irq(shost
->host_lock
);
4260 lpfc_alloc_bucket(vport
);
4261 vport
->stat_data_enabled
= 1;
4262 spin_unlock_irq(shost
->host_lock
);
4266 if (!strncmp(buf
, "stop", strlen("stop"))) {
4267 spin_lock_irq(shost
->host_lock
);
4268 if (vport
->stat_data_enabled
== 0) {
4269 spin_unlock_irq(shost
->host_lock
);
4272 lpfc_free_bucket(vport
);
4273 vport
->stat_data_enabled
= 0;
4274 spin_unlock_irq(shost
->host_lock
);
4278 if (!strncmp(buf
, "reset", strlen("reset"))) {
4279 if ((phba
->bucket_type
== LPFC_NO_BUCKET
)
4280 || !vport
->stat_data_enabled
)
4282 spin_lock_irq(shost
->host_lock
);
4283 vport
->stat_data_blocked
= 1;
4284 lpfc_vport_reset_stat_data(vport
);
4285 vport
->stat_data_blocked
= 0;
4286 spin_unlock_irq(shost
->host_lock
);
4294 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
4295 * @dev: Pointer to class device.
4297 * @buf: Data buffer.
4299 * This function is the read call back function for
4300 * lpfc_stat_data_ctrl sysfs file. This function report the
4301 * current statistical data collection state.
4304 lpfc_stat_data_ctrl_show(struct device
*dev
, struct device_attribute
*attr
,
4307 struct Scsi_Host
*shost
= class_to_shost(dev
);
4308 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4309 struct lpfc_hba
*phba
= vport
->phba
;
4313 unsigned long bucket_value
;
4315 switch (phba
->bucket_type
) {
4316 case LPFC_LINEAR_BUCKET
:
4317 bucket_type
= "linear";
4319 case LPFC_POWER2_BUCKET
:
4320 bucket_type
= "power2";
4323 bucket_type
= "No Bucket";
4327 sprintf(&buf
[index
], "Statistical Data enabled :%d, "
4328 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4329 " Bucket step :%d\nLatency Ranges :",
4330 vport
->stat_data_enabled
, vport
->stat_data_blocked
,
4331 bucket_type
, phba
->bucket_base
, phba
->bucket_step
);
4332 index
= strlen(buf
);
4333 if (phba
->bucket_type
!= LPFC_NO_BUCKET
) {
4334 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
; i
++) {
4335 if (phba
->bucket_type
== LPFC_LINEAR_BUCKET
)
4336 bucket_value
= phba
->bucket_base
+
4337 phba
->bucket_step
* i
;
4339 bucket_value
= phba
->bucket_base
+
4340 (1 << i
) * phba
->bucket_step
;
4342 if (index
+ 10 > PAGE_SIZE
)
4344 sprintf(&buf
[index
], "%08ld ", bucket_value
);
4345 index
= strlen(buf
);
4348 sprintf(&buf
[index
], "\n");
4353 * Sysfs attribute to control the statistical data collection.
4355 static DEVICE_ATTR_RW(lpfc_stat_data_ctrl
);
4358 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
4362 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
4365 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
4366 #define MAX_STAT_DATA_SIZE_PER_TARGET \
4367 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
4371 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
4373 * @kobj: Pointer to the kernel object
4374 * @bin_attr: Attribute object
4375 * @buf: Buffer pointer
4377 * @count: Buffer size
4379 * This function is the read call back function for lpfc_drvr_stat_data
4380 * sysfs file. This function export the statistical data to user
4384 sysfs_drvr_stat_data_read(struct file
*filp
, struct kobject
*kobj
,
4385 struct bin_attribute
*bin_attr
,
4386 char *buf
, loff_t off
, size_t count
)
4388 struct device
*dev
= container_of(kobj
, struct device
,
4390 struct Scsi_Host
*shost
= class_to_shost(dev
);
4391 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4392 struct lpfc_hba
*phba
= vport
->phba
;
4393 int i
= 0, index
= 0;
4394 unsigned long nport_index
;
4395 struct lpfc_nodelist
*ndlp
= NULL
;
4396 nport_index
= (unsigned long)off
/
4397 MAX_STAT_DATA_SIZE_PER_TARGET
;
4399 if (!vport
->stat_data_enabled
|| vport
->stat_data_blocked
4400 || (phba
->bucket_type
== LPFC_NO_BUCKET
))
4403 spin_lock_irq(shost
->host_lock
);
4404 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4405 if (!ndlp
->lat_data
)
4408 if (nport_index
> 0) {
4413 if ((index
+ MAX_STAT_DATA_SIZE_PER_TARGET
)
4417 if (!ndlp
->lat_data
)
4421 sprintf(&buf
[index
], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4422 ndlp
->nlp_portname
.u
.wwn
[0],
4423 ndlp
->nlp_portname
.u
.wwn
[1],
4424 ndlp
->nlp_portname
.u
.wwn
[2],
4425 ndlp
->nlp_portname
.u
.wwn
[3],
4426 ndlp
->nlp_portname
.u
.wwn
[4],
4427 ndlp
->nlp_portname
.u
.wwn
[5],
4428 ndlp
->nlp_portname
.u
.wwn
[6],
4429 ndlp
->nlp_portname
.u
.wwn
[7]);
4431 index
= strlen(buf
);
4433 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
; i
++) {
4434 sprintf(&buf
[index
], "%010u,",
4435 ndlp
->lat_data
[i
].cmd_count
);
4436 index
= strlen(buf
);
4438 sprintf(&buf
[index
], "\n");
4439 index
= strlen(buf
);
4441 spin_unlock_irq(shost
->host_lock
);
4445 static struct bin_attribute sysfs_drvr_stat_data_attr
= {
4447 .name
= "lpfc_drvr_stat_data",
4450 .size
= LPFC_MAX_TARGET
* MAX_STAT_DATA_SIZE_PER_TARGET
,
4451 .read
= sysfs_drvr_stat_data_read
,
4456 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4458 # Value range is [0,16]. Default value is 0.
4461 * lpfc_link_speed_set - Set the adapters link speed
4462 * @dev: Pointer to class device.
4464 * @buf: Data buffer.
4465 * @count: Size of the data buffer.
4468 * If val is in a valid range then set the adapter's link speed field and
4469 * issue a lip; if the lip fails reset the link speed to the old value.
4472 * If the value is not in range log a kernel error message and return an error.
4475 * zero if val is in range and lip okay.
4476 * non-zero return value from lpfc_issue_lip()
4477 * -EINVAL val out of range
4480 lpfc_link_speed_store(struct device
*dev
, struct device_attribute
*attr
,
4481 const char *buf
, size_t count
)
4483 struct Scsi_Host
*shost
= class_to_shost(dev
);
4484 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4485 struct lpfc_hba
*phba
= vport
->phba
;
4486 int val
= LPFC_USER_LINK_SPEED_AUTO
;
4488 const char *val_buf
= buf
;
4490 uint32_t prev_val
, if_type
;
4492 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
4493 if (if_type
>= LPFC_SLI_INTF_IF_TYPE_2
&&
4494 phba
->hba_flag
& HBA_FORCED_LINK_SPEED
)
4497 if (!strncmp(buf
, "nolip ", strlen("nolip "))) {
4499 val_buf
= &buf
[strlen("nolip ")];
4502 if (!isdigit(val_buf
[0]))
4504 if (sscanf(val_buf
, "%i", &val
) != 1)
4507 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
4508 "3055 lpfc_link_speed changed from %d to %d %s\n",
4509 phba
->cfg_link_speed
, val
, nolip
? "(nolip)" : "(lip)");
4511 if (((val
== LPFC_USER_LINK_SPEED_1G
) && !(phba
->lmt
& LMT_1Gb
)) ||
4512 ((val
== LPFC_USER_LINK_SPEED_2G
) && !(phba
->lmt
& LMT_2Gb
)) ||
4513 ((val
== LPFC_USER_LINK_SPEED_4G
) && !(phba
->lmt
& LMT_4Gb
)) ||
4514 ((val
== LPFC_USER_LINK_SPEED_8G
) && !(phba
->lmt
& LMT_8Gb
)) ||
4515 ((val
== LPFC_USER_LINK_SPEED_10G
) && !(phba
->lmt
& LMT_10Gb
)) ||
4516 ((val
== LPFC_USER_LINK_SPEED_16G
) && !(phba
->lmt
& LMT_16Gb
)) ||
4517 ((val
== LPFC_USER_LINK_SPEED_32G
) && !(phba
->lmt
& LMT_32Gb
)) ||
4518 ((val
== LPFC_USER_LINK_SPEED_64G
) && !(phba
->lmt
& LMT_64Gb
))) {
4519 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4520 "2879 lpfc_link_speed attribute cannot be set "
4521 "to %d. Speed is not supported by this port.\n",
4525 if (val
>= LPFC_USER_LINK_SPEED_16G
&&
4526 phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4527 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4528 "3112 lpfc_link_speed attribute cannot be set "
4529 "to %d. Speed is not supported in loop mode.\n",
4535 case LPFC_USER_LINK_SPEED_AUTO
:
4536 case LPFC_USER_LINK_SPEED_1G
:
4537 case LPFC_USER_LINK_SPEED_2G
:
4538 case LPFC_USER_LINK_SPEED_4G
:
4539 case LPFC_USER_LINK_SPEED_8G
:
4540 case LPFC_USER_LINK_SPEED_16G
:
4541 case LPFC_USER_LINK_SPEED_32G
:
4542 case LPFC_USER_LINK_SPEED_64G
:
4543 prev_val
= phba
->cfg_link_speed
;
4544 phba
->cfg_link_speed
= val
;
4548 err
= lpfc_issue_lip(lpfc_shost_from_vport(phba
->pport
));
4550 phba
->cfg_link_speed
= prev_val
;
4558 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4559 "0469 lpfc_link_speed attribute cannot be set to %d, "
4560 "allowed values are [%s]\n",
4561 val
, LPFC_LINK_SPEED_STRING
);
4566 static int lpfc_link_speed
= 0;
4567 module_param(lpfc_link_speed
, int, S_IRUGO
);
4568 MODULE_PARM_DESC(lpfc_link_speed
, "Select link speed");
4569 lpfc_param_show(link_speed
)
4572 * lpfc_link_speed_init - Set the adapters link speed
4573 * @phba: lpfc_hba pointer.
4574 * @val: link speed value.
4577 * If val is in a valid range then set the adapter's link speed field.
4580 * If the value is not in range log a kernel error message, clear the link
4581 * speed and return an error.
4584 * zero if val saved.
4585 * -EINVAL val out of range
4588 lpfc_link_speed_init(struct lpfc_hba
*phba
, int val
)
4590 if (val
>= LPFC_USER_LINK_SPEED_16G
&& phba
->cfg_topology
== 4) {
4591 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4592 "3111 lpfc_link_speed of %d cannot "
4593 "support loop mode, setting topology to default.\n",
4595 phba
->cfg_topology
= 0;
4599 case LPFC_USER_LINK_SPEED_AUTO
:
4600 case LPFC_USER_LINK_SPEED_1G
:
4601 case LPFC_USER_LINK_SPEED_2G
:
4602 case LPFC_USER_LINK_SPEED_4G
:
4603 case LPFC_USER_LINK_SPEED_8G
:
4604 case LPFC_USER_LINK_SPEED_16G
:
4605 case LPFC_USER_LINK_SPEED_32G
:
4606 case LPFC_USER_LINK_SPEED_64G
:
4607 phba
->cfg_link_speed
= val
;
4610 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4611 "0405 lpfc_link_speed attribute cannot "
4612 "be set to %d, allowed values are "
4613 "["LPFC_LINK_SPEED_STRING
"]\n", val
);
4614 phba
->cfg_link_speed
= LPFC_USER_LINK_SPEED_AUTO
;
4619 static DEVICE_ATTR_RW(lpfc_link_speed
);
4622 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4623 # 0 = aer disabled or not supported
4624 # 1 = aer supported and enabled (default)
4625 # Value range is [0,1]. Default value is 1.
4627 LPFC_ATTR(aer_support
, 1, 0, 1,
4628 "Enable PCIe device AER support");
4629 lpfc_param_show(aer_support
)
4632 * lpfc_aer_support_store - Set the adapter for aer support
4634 * @dev: class device that is converted into a Scsi_host.
4635 * @attr: device attribute, not used.
4636 * @buf: containing enable or disable aer flag.
4637 * @count: unused variable.
4640 * If the val is 1 and currently the device's AER capability was not
4641 * enabled, invoke the kernel's enable AER helper routine, trying to
4642 * enable the device's AER capability. If the helper routine enabling
4643 * AER returns success, update the device's cfg_aer_support flag to
4644 * indicate AER is supported by the device; otherwise, if the device
4645 * AER capability is already enabled to support AER, then do nothing.
4647 * If the val is 0 and currently the device's AER support was enabled,
4648 * invoke the kernel's disable AER helper routine. After that, update
4649 * the device's cfg_aer_support flag to indicate AER is not supported
4650 * by the device; otherwise, if the device AER capability is already
4651 * disabled from supporting AER, then do nothing.
4654 * length of the buf on success if val is in range the intended mode
4656 * -EINVAL if val out of range or intended mode is not supported.
4659 lpfc_aer_support_store(struct device
*dev
, struct device_attribute
*attr
,
4660 const char *buf
, size_t count
)
4662 struct Scsi_Host
*shost
= class_to_shost(dev
);
4663 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
4664 struct lpfc_hba
*phba
= vport
->phba
;
4665 int val
= 0, rc
= -EINVAL
;
4667 if (!isdigit(buf
[0]))
4669 if (sscanf(buf
, "%i", &val
) != 1)
4674 if (phba
->hba_flag
& HBA_AER_ENABLED
) {
4675 rc
= pci_disable_pcie_error_reporting(phba
->pcidev
);
4677 spin_lock_irq(&phba
->hbalock
);
4678 phba
->hba_flag
&= ~HBA_AER_ENABLED
;
4679 spin_unlock_irq(&phba
->hbalock
);
4680 phba
->cfg_aer_support
= 0;
4685 phba
->cfg_aer_support
= 0;
4690 if (!(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4691 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4693 spin_lock_irq(&phba
->hbalock
);
4694 phba
->hba_flag
|= HBA_AER_ENABLED
;
4695 spin_unlock_irq(&phba
->hbalock
);
4696 phba
->cfg_aer_support
= 1;
4701 phba
->cfg_aer_support
= 1;
4712 static DEVICE_ATTR_RW(lpfc_aer_support
);
4715 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4716 * @dev: class device that is converted into a Scsi_host.
4717 * @attr: device attribute, not used.
4718 * @buf: containing flag 1 for aer cleanup state.
4719 * @count: unused variable.
4722 * If the @buf contains 1 and the device currently has the AER support
4723 * enabled, then invokes the kernel AER helper routine
4724 * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
4725 * error status register.
4730 * -EINVAL if the buf does not contain the 1 or the device is not currently
4731 * enabled with the AER support.
4734 lpfc_aer_cleanup_state(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 if (!isdigit(buf
[0]))
4744 if (sscanf(buf
, "%i", &val
) != 1)
4749 if (phba
->hba_flag
& HBA_AER_ENABLED
)
4750 rc
= pci_aer_clear_nonfatal_status(phba
->pcidev
);
4758 static DEVICE_ATTR(lpfc_aer_state_cleanup
, S_IWUSR
, NULL
,
4759 lpfc_aer_cleanup_state
);
4762 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4764 * @dev: class device that is converted into a Scsi_host.
4765 * @attr: device attribute, not used.
4766 * @buf: containing the string the number of vfs to be enabled.
4767 * @count: unused variable.
4770 * When this api is called either through user sysfs, the driver shall
4771 * try to enable or disable SR-IOV virtual functions according to the
4774 * If zero virtual function has been enabled to the physical function,
4775 * the driver shall invoke the pci enable virtual function api trying
4776 * to enable the virtual functions. If the nr_vfn provided is greater
4777 * than the maximum supported, the maximum virtual function number will
4778 * be used for invoking the api; otherwise, the nr_vfn provided shall
4779 * be used for invoking the api. If the api call returned success, the
4780 * actual number of virtual functions enabled will be set to the driver
4781 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4782 * cfg_sriov_nr_virtfn remains zero.
4784 * If none-zero virtual functions have already been enabled to the
4785 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4786 * -EINVAL will be returned and the driver does nothing;
4788 * If the nr_vfn provided is zero and none-zero virtual functions have
4789 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4790 * disabling virtual function api shall be invoded to disable all the
4791 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4792 * zero. Otherwise, if zero virtual function has been enabled, do
4796 * length of the buf on success if val is in range the intended mode
4798 * -EINVAL if val out of range or intended mode is not supported.
4801 lpfc_sriov_nr_virtfn_store(struct device
*dev
, struct device_attribute
*attr
,
4802 const char *buf
, size_t count
)
4804 struct Scsi_Host
*shost
= class_to_shost(dev
);
4805 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
4806 struct lpfc_hba
*phba
= vport
->phba
;
4807 struct pci_dev
*pdev
= phba
->pcidev
;
4808 int val
= 0, rc
= -EINVAL
;
4810 /* Sanity check on user data */
4811 if (!isdigit(buf
[0]))
4813 if (sscanf(buf
, "%i", &val
) != 1)
4818 /* Request disabling virtual functions */
4820 if (phba
->cfg_sriov_nr_virtfn
> 0) {
4821 pci_disable_sriov(pdev
);
4822 phba
->cfg_sriov_nr_virtfn
= 0;
4827 /* Request enabling virtual functions */
4828 if (phba
->cfg_sriov_nr_virtfn
> 0) {
4829 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4830 "3018 There are %d virtual functions "
4831 "enabled on physical function.\n",
4832 phba
->cfg_sriov_nr_virtfn
);
4836 if (val
<= LPFC_MAX_VFN_PER_PFN
)
4837 phba
->cfg_sriov_nr_virtfn
= val
;
4839 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4840 "3019 Enabling %d virtual functions is not "
4845 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
, phba
->cfg_sriov_nr_virtfn
);
4847 phba
->cfg_sriov_nr_virtfn
= 0;
4855 LPFC_ATTR(sriov_nr_virtfn
, LPFC_DEF_VFN_PER_PFN
, 0, LPFC_MAX_VFN_PER_PFN
,
4856 "Enable PCIe device SR-IOV virtual fn");
4858 lpfc_param_show(sriov_nr_virtfn
)
4859 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn
);
4862 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4864 * @dev: class device that is converted into a Scsi_host.
4865 * @attr: device attribute, not used.
4866 * @buf: containing the string the number of vfs to be enabled.
4867 * @count: unused variable.
4872 * length of the buf on success if val is in range the intended mode
4874 * -EINVAL if val out of range or intended mode is not supported.
4877 lpfc_request_firmware_upgrade_store(struct device
*dev
,
4878 struct device_attribute
*attr
,
4879 const char *buf
, size_t count
)
4881 struct Scsi_Host
*shost
= class_to_shost(dev
);
4882 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
4883 struct lpfc_hba
*phba
= vport
->phba
;
4886 /* Sanity check on user data */
4887 if (!isdigit(buf
[0]))
4889 if (sscanf(buf
, "%i", &val
) != 1)
4894 rc
= lpfc_sli4_request_firmware_update(phba
, RUN_FW_UPGRADE
);
4902 static int lpfc_req_fw_upgrade
;
4903 module_param(lpfc_req_fw_upgrade
, int, S_IRUGO
|S_IWUSR
);
4904 MODULE_PARM_DESC(lpfc_req_fw_upgrade
, "Enable Linux generic firmware upgrade");
4905 lpfc_param_show(request_firmware_upgrade
)
4908 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4909 * @phba: lpfc_hba pointer.
4913 * Set the initial Linux generic firmware upgrade enable or disable flag.
4916 * zero if val saved.
4917 * -EINVAL val out of range
4920 lpfc_request_firmware_upgrade_init(struct lpfc_hba
*phba
, int val
)
4922 if (val
>= 0 && val
<= 1) {
4923 phba
->cfg_request_firmware_upgrade
= val
;
4928 static DEVICE_ATTR(lpfc_req_fw_upgrade
, S_IRUGO
| S_IWUSR
,
4929 lpfc_request_firmware_upgrade_show
,
4930 lpfc_request_firmware_upgrade_store
);
4933 * lpfc_force_rscn_store
4935 * @dev: class device that is converted into a Scsi_host.
4936 * @attr: device attribute, not used.
4937 * @buf: unused string
4938 * @count: unused variable.
4941 * Force the switch to send a RSCN to all other NPorts in our zone
4942 * If we are direct connect pt2pt, build the RSCN command ourself
4943 * and send to the other NPort. Not supported for private loop.
4947 * -EIO - if command is not sent
4950 lpfc_force_rscn_store(struct device
*dev
, struct device_attribute
*attr
,
4951 const char *buf
, size_t count
)
4953 struct Scsi_Host
*shost
= class_to_shost(dev
);
4954 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
4957 i
= lpfc_issue_els_rscn(vport
, 0);
4964 * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4965 * connected to the HBA.
4967 * Value range is any ascii value
4969 static int lpfc_force_rscn
;
4970 module_param(lpfc_force_rscn
, int, 0644);
4971 MODULE_PARM_DESC(lpfc_force_rscn
,
4972 "Force an RSCN to be sent to all remote NPorts");
4973 lpfc_param_show(force_rscn
)
4976 * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4977 * @phba: lpfc_hba pointer.
4978 * @val: unused value.
4981 * zero if val saved.
4984 lpfc_force_rscn_init(struct lpfc_hba
*phba
, int val
)
4988 static DEVICE_ATTR_RW(lpfc_force_rscn
);
4991 * lpfc_fcp_imax_store
4993 * @dev: class device that is converted into a Scsi_host.
4994 * @attr: device attribute, not used.
4995 * @buf: string with the number of fast-path FCP interrupts per second.
4996 * @count: unused variable.
4999 * If val is in a valid range [636,651042], then set the adapter's
5000 * maximum number of fast-path FCP interrupts per second.
5003 * length of the buf on success if val is in range the intended mode
5005 * -EINVAL if val out of range or intended mode is not supported.
5008 lpfc_fcp_imax_store(struct device
*dev
, struct device_attribute
*attr
,
5009 const char *buf
, size_t count
)
5011 struct Scsi_Host
*shost
= class_to_shost(dev
);
5012 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
5013 struct lpfc_hba
*phba
= vport
->phba
;
5014 struct lpfc_eq_intr_info
*eqi
;
5018 /* fcp_imax is only valid for SLI4 */
5019 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
5022 /* Sanity check on user data */
5023 if (!isdigit(buf
[0]))
5025 if (sscanf(buf
, "%i", &val
) != 1)
5029 * Value range for the HBA is [5000,5000000]
5030 * The value for each EQ depends on how many EQs are configured.
5033 if (val
&& (val
< LPFC_MIN_IMAX
|| val
> LPFC_MAX_IMAX
))
5036 phba
->cfg_auto_imax
= (val
) ? 0 : 1;
5037 if (phba
->cfg_fcp_imax
&& !val
) {
5038 queue_delayed_work(phba
->wq
, &phba
->eq_delay_work
,
5039 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS
));
5041 for_each_present_cpu(i
) {
5042 eqi
= per_cpu_ptr(phba
->sli4_hba
.eq_info
, i
);
5047 phba
->cfg_fcp_imax
= (uint32_t)val
;
5049 if (phba
->cfg_fcp_imax
)
5050 usdelay
= LPFC_SEC_TO_USEC
/ phba
->cfg_fcp_imax
;
5054 for (i
= 0; i
< phba
->cfg_irq_chann
; i
+= LPFC_MAX_EQ_DELAY_EQID_CNT
)
5055 lpfc_modify_hba_eq_delay(phba
, i
, LPFC_MAX_EQ_DELAY_EQID_CNT
,
5062 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
5065 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
5067 static int lpfc_fcp_imax
= LPFC_DEF_IMAX
;
5068 module_param(lpfc_fcp_imax
, int, S_IRUGO
|S_IWUSR
);
5069 MODULE_PARM_DESC(lpfc_fcp_imax
,
5070 "Set the maximum number of FCP interrupts per second per HBA");
5071 lpfc_param_show(fcp_imax
)
5074 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
5075 * @phba: lpfc_hba pointer.
5076 * @val: link speed value.
5079 * If val is in a valid range [636,651042], then initialize the adapter's
5080 * maximum number of fast-path FCP interrupts per second.
5083 * zero if val saved.
5084 * -EINVAL val out of range
5087 lpfc_fcp_imax_init(struct lpfc_hba
*phba
, int val
)
5089 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
5090 phba
->cfg_fcp_imax
= 0;
5094 if ((val
>= LPFC_MIN_IMAX
&& val
<= LPFC_MAX_IMAX
) ||
5096 phba
->cfg_fcp_imax
= val
;
5100 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5101 "3016 lpfc_fcp_imax: %d out of range, using default\n",
5103 phba
->cfg_fcp_imax
= LPFC_DEF_IMAX
;
5108 static DEVICE_ATTR_RW(lpfc_fcp_imax
);
5111 * lpfc_cq_max_proc_limit_store
5113 * @dev: class device that is converted into a Scsi_host.
5114 * @attr: device attribute, not used.
5115 * @buf: string with the cq max processing limit of cqes
5116 * @count: unused variable.
5119 * If val is in a valid range, then set value on each cq
5122 * The length of the buf: if successful
5123 * -ERANGE: if val is not in the valid range
5124 * -EINVAL: if bad value format or intended mode is not supported.
5127 lpfc_cq_max_proc_limit_store(struct device
*dev
, struct device_attribute
*attr
,
5128 const char *buf
, size_t count
)
5130 struct Scsi_Host
*shost
= class_to_shost(dev
);
5131 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
5132 struct lpfc_hba
*phba
= vport
->phba
;
5133 struct lpfc_queue
*eq
, *cq
;
5137 /* cq_max_proc_limit is only valid for SLI4 */
5138 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
5141 /* Sanity check on user data */
5142 if (!isdigit(buf
[0]))
5144 if (kstrtoul(buf
, 0, &val
))
5147 if (val
< LPFC_CQ_MIN_PROC_LIMIT
|| val
> LPFC_CQ_MAX_PROC_LIMIT
)
5150 phba
->cfg_cq_max_proc_limit
= (uint32_t)val
;
5152 /* set the values on the cq's */
5153 for (i
= 0; i
< phba
->cfg_irq_chann
; i
++) {
5154 /* Get the EQ corresponding to the IRQ vector */
5155 eq
= phba
->sli4_hba
.hba_eq_hdl
[i
].eq
;
5159 list_for_each_entry(cq
, &eq
->child_list
, list
)
5160 cq
->max_proc_limit
= min(phba
->cfg_cq_max_proc_limit
,
5168 * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
5169 * itteration of CQ processing.
5171 static int lpfc_cq_max_proc_limit
= LPFC_CQ_DEF_MAX_PROC_LIMIT
;
5172 module_param(lpfc_cq_max_proc_limit
, int, 0644);
5173 MODULE_PARM_DESC(lpfc_cq_max_proc_limit
,
5174 "Set the maximum number CQEs processed in an iteration of "
5176 lpfc_param_show(cq_max_proc_limit
)
5179 * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
5180 * single handler call which should request a polled completion rather
5181 * than re-enabling interrupts.
5183 LPFC_ATTR_RW(cq_poll_threshold
, LPFC_CQ_DEF_THRESHOLD_TO_POLL
,
5184 LPFC_CQ_MIN_THRESHOLD_TO_POLL
,
5185 LPFC_CQ_MAX_THRESHOLD_TO_POLL
,
5186 "CQE Processing Threshold to enable Polling");
5189 * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
5190 * @phba: lpfc_hba pointer.
5194 * If val is in a valid range, then initialize the adapter's maximum
5198 * Always returns 0 for success, even if value not always set to
5199 * requested value. If value out of range or not supported, will fall
5203 lpfc_cq_max_proc_limit_init(struct lpfc_hba
*phba
, int val
)
5205 phba
->cfg_cq_max_proc_limit
= LPFC_CQ_DEF_MAX_PROC_LIMIT
;
5207 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
5210 if (val
>= LPFC_CQ_MIN_PROC_LIMIT
&& val
<= LPFC_CQ_MAX_PROC_LIMIT
) {
5211 phba
->cfg_cq_max_proc_limit
= val
;
5215 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5216 "0371 "LPFC_DRIVER_NAME
"_cq_max_proc_limit: "
5217 "%d out of range, using default\n",
5218 phba
->cfg_cq_max_proc_limit
);
5223 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit
);
5226 * lpfc_state_show - Display current driver CPU affinity
5227 * @dev: class converted to a Scsi_host structure.
5228 * @attr: device attribute, not used.
5229 * @buf: on return contains text describing the state of the link.
5231 * Returns: size of formatted string.
5234 lpfc_fcp_cpu_map_show(struct device
*dev
, struct device_attribute
*attr
,
5237 struct Scsi_Host
*shost
= class_to_shost(dev
);
5238 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
5239 struct lpfc_hba
*phba
= vport
->phba
;
5240 struct lpfc_vector_map_info
*cpup
;
5243 if ((phba
->sli_rev
!= LPFC_SLI_REV4
) ||
5244 (phba
->intr_type
!= MSIX
))
5247 switch (phba
->cfg_fcp_cpu_map
) {
5249 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
5250 "fcp_cpu_map: No mapping (%d)\n",
5251 phba
->cfg_fcp_cpu_map
);
5254 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
5255 "fcp_cpu_map: HBA centric mapping (%d): "
5256 "%d of %d CPUs online from %d possible CPUs\n",
5257 phba
->cfg_fcp_cpu_map
, num_online_cpus(),
5259 phba
->sli4_hba
.num_possible_cpu
);
5263 while (phba
->sli4_hba
.curr_disp_cpu
<
5264 phba
->sli4_hba
.num_possible_cpu
) {
5265 cpup
= &phba
->sli4_hba
.cpu_map
[phba
->sli4_hba
.curr_disp_cpu
];
5267 if (!cpu_present(phba
->sli4_hba
.curr_disp_cpu
))
5268 len
+= scnprintf(buf
+ len
, PAGE_SIZE
- len
,
5269 "CPU %02d not present\n",
5270 phba
->sli4_hba
.curr_disp_cpu
);
5271 else if (cpup
->eq
== LPFC_VECTOR_MAP_EMPTY
) {
5272 if (cpup
->hdwq
== LPFC_VECTOR_MAP_EMPTY
)
5274 buf
+ len
, PAGE_SIZE
- len
,
5275 "CPU %02d hdwq None "
5276 "physid %d coreid %d ht %d ua %d\n",
5277 phba
->sli4_hba
.curr_disp_cpu
,
5278 cpup
->phys_id
, cpup
->core_id
,
5279 (cpup
->flag
& LPFC_CPU_MAP_HYPER
),
5280 (cpup
->flag
& LPFC_CPU_MAP_UNASSIGN
));
5283 buf
+ len
, PAGE_SIZE
- len
,
5284 "CPU %02d EQ None hdwq %04d "
5285 "physid %d coreid %d ht %d ua %d\n",
5286 phba
->sli4_hba
.curr_disp_cpu
,
5287 cpup
->hdwq
, cpup
->phys_id
,
5289 (cpup
->flag
& LPFC_CPU_MAP_HYPER
),
5290 (cpup
->flag
& LPFC_CPU_MAP_UNASSIGN
));
5292 if (cpup
->hdwq
== LPFC_VECTOR_MAP_EMPTY
)
5294 buf
+ len
, PAGE_SIZE
- len
,
5295 "CPU %02d hdwq None "
5296 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5297 phba
->sli4_hba
.curr_disp_cpu
,
5300 (cpup
->flag
& LPFC_CPU_MAP_HYPER
),
5301 (cpup
->flag
& LPFC_CPU_MAP_UNASSIGN
),
5302 lpfc_get_irq(cpup
->eq
));
5305 buf
+ len
, PAGE_SIZE
- len
,
5306 "CPU %02d EQ %04d hdwq %04d "
5307 "physid %d coreid %d ht %d ua %d IRQ %d\n",
5308 phba
->sli4_hba
.curr_disp_cpu
,
5309 cpup
->eq
, cpup
->hdwq
, cpup
->phys_id
,
5311 (cpup
->flag
& LPFC_CPU_MAP_HYPER
),
5312 (cpup
->flag
& LPFC_CPU_MAP_UNASSIGN
),
5313 lpfc_get_irq(cpup
->eq
));
5316 phba
->sli4_hba
.curr_disp_cpu
++;
5318 /* display max number of CPUs keeping some margin */
5319 if (phba
->sli4_hba
.curr_disp_cpu
<
5320 phba
->sli4_hba
.num_possible_cpu
&&
5321 (len
>= (PAGE_SIZE
- 64))) {
5322 len
+= scnprintf(buf
+ len
,
5323 PAGE_SIZE
- len
, "more...\n");
5328 if (phba
->sli4_hba
.curr_disp_cpu
== phba
->sli4_hba
.num_possible_cpu
)
5329 phba
->sli4_hba
.curr_disp_cpu
= 0;
5335 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
5336 * @dev: class device that is converted into a Scsi_host.
5337 * @attr: device attribute, not used.
5338 * @buf: one or more lpfc_polling_flags values.
5342 * -EINVAL - Not implemented yet.
5345 lpfc_fcp_cpu_map_store(struct device
*dev
, struct device_attribute
*attr
,
5346 const char *buf
, size_t count
)
5352 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
5355 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
5356 # 0 - Do not affinitze IRQ vectors
5357 # 1 - Affintize HBA vectors with respect to each HBA
5358 # (start with CPU0 for each HBA)
5359 # This also defines how Hardware Queues are mapped to specific CPUs.
5361 static int lpfc_fcp_cpu_map
= LPFC_HBA_CPU_MAP
;
5362 module_param(lpfc_fcp_cpu_map
, int, S_IRUGO
|S_IWUSR
);
5363 MODULE_PARM_DESC(lpfc_fcp_cpu_map
,
5364 "Defines how to map CPUs to IRQ vectors per HBA");
5367 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5368 * @phba: lpfc_hba pointer.
5369 * @val: link speed value.
5372 * If val is in a valid range [0-2], then affinitze the adapter's
5376 * zero if val saved.
5377 * -EINVAL val out of range
5380 lpfc_fcp_cpu_map_init(struct lpfc_hba
*phba
, int val
)
5382 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
5383 phba
->cfg_fcp_cpu_map
= 0;
5387 if (val
>= LPFC_MIN_CPU_MAP
&& val
<= LPFC_MAX_CPU_MAP
) {
5388 phba
->cfg_fcp_cpu_map
= val
;
5392 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5393 "3326 lpfc_fcp_cpu_map: %d out of range, using "
5395 phba
->cfg_fcp_cpu_map
= LPFC_HBA_CPU_MAP
;
5400 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map
);
5403 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
5404 # Value range is [2,3]. Default value is 3.
5406 LPFC_VPORT_ATTR_R(fcp_class
, 3, 2, 3,
5407 "Select Fibre Channel class of service for FCP sequences");
5410 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5411 # is [0,1]. Default value is 0.
5413 LPFC_VPORT_ATTR_RW(use_adisc
, 0, 0, 1,
5414 "Use ADISC on rediscovery to authenticate FCP devices");
5417 # lpfc_first_burst_size: First burst size to use on the NPorts
5418 # that support first burst.
5419 # Value range is [0,65536]. Default value is 0.
5421 LPFC_VPORT_ATTR_RW(first_burst_size
, 0, 0, 65536,
5422 "First burst size for Targets that support first burst");
5425 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5426 * When the driver is configured as an NVME target, this value is
5427 * communicated to the NVME initiator in the PRLI response. It is
5428 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5429 * parameters are set and the target is sending the PRLI RSP.
5430 * Parameter supported on physical port only - no NPIV support.
5431 * Value range is [0,65536]. Default value is 0.
5433 LPFC_ATTR_RW(nvmet_fb_size
, 0, 0, 65536,
5434 "NVME Target mode first burst size in 512B increments.");
5437 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5438 * For the Initiator (I), enabling this parameter means that an NVMET
5439 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5440 * processed by the initiator for subsequent NVME FCP IO.
5441 * Currently, this feature is not supported on the NVME target
5442 * Value range is [0,1]. Default value is 0 (disabled).
5444 LPFC_ATTR_RW(nvme_enable_fb
, 0, 0, 1,
5445 "Enable First Burst feature for NVME Initiator.");
5448 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5449 # depth. Default value is 0. When the value of this parameter is zero the
5450 # SCSI command completion time is not used for controlling I/O queue depth. When
5451 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5452 # to limit the I/O completion time to the parameter value.
5453 # The value is set in milliseconds.
5455 LPFC_VPORT_ATTR(max_scsicmpl_time
, 0, 0, 60000,
5456 "Use command completion time to control queue depth");
5458 lpfc_vport_param_show(max_scsicmpl_time
);
5460 lpfc_max_scsicmpl_time_set(struct lpfc_vport
*vport
, int val
)
5462 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5463 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
5465 if (val
== vport
->cfg_max_scsicmpl_time
)
5467 if ((val
< 0) || (val
> 60000))
5469 vport
->cfg_max_scsicmpl_time
= val
;
5471 spin_lock_irq(shost
->host_lock
);
5472 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5473 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
5475 ndlp
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
5477 spin_unlock_irq(shost
->host_lock
);
5480 lpfc_vport_param_store(max_scsicmpl_time
);
5481 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time
);
5484 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5485 # range is [0,1]. Default value is 0.
5487 LPFC_ATTR_R(ack0
, 0, 0, 1, "Enable ACK0 support");
5490 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5491 # range is [0,1]. Default value is 1.
5493 LPFC_ATTR_R(xri_rebalancing
, 1, 0, 1, "Enable/Disable XRI rebalancing");
5496 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5497 * range is [0,1]. Default value is 0.
5498 * For [0], FCP commands are issued to Work Queues based on upper layer
5499 * hardware queue index.
5500 * For [1], FCP commands are issued to a Work Queue associated with the
5503 * LPFC_FCP_SCHED_BY_HDWQ == 0
5504 * LPFC_FCP_SCHED_BY_CPU == 1
5506 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5507 * affinity for FCP/NVME I/Os through Work Queues associated with the current
5508 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5509 * through WQs will be used.
5511 LPFC_ATTR_RW(fcp_io_sched
, LPFC_FCP_SCHED_BY_CPU
,
5512 LPFC_FCP_SCHED_BY_HDWQ
,
5513 LPFC_FCP_SCHED_BY_CPU
,
5514 "Determine scheduling algorithm for "
5515 "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5518 * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5519 * range is [0,1]. Default value is 0.
5520 * For [0], GID_FT is used for NameServer queries after RSCN (default)
5521 * For [1], GID_PT is used for NameServer queries after RSCN
5524 LPFC_ATTR_RW(ns_query
, LPFC_NS_QUERY_GID_FT
,
5525 LPFC_NS_QUERY_GID_FT
, LPFC_NS_QUERY_GID_PT
,
5526 "Determine algorithm NameServer queries after RSCN "
5527 "[0] - GID_FT, [1] - GID_PT");
5530 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5531 # range is [0,1]. Default value is 0.
5532 # For [0], bus reset issues target reset to ALL devices
5533 # For [1], bus reset issues target reset to non-FCP2 devices
5535 LPFC_ATTR_RW(fcp2_no_tgt_reset
, 0, 0, 1, "Determine bus reset behavior for "
5536 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5540 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5541 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5542 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5543 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5544 # cr_delay is set to 0.
5546 LPFC_ATTR_RW(cr_delay
, 0, 0, 63, "A count of milliseconds after which an "
5547 "interrupt response is generated");
5549 LPFC_ATTR_RW(cr_count
, 1, 1, 255, "A count of I/O completions after which an "
5550 "interrupt response is generated");
5553 # lpfc_multi_ring_support: Determines how many rings to spread available
5554 # cmd/rsp IOCB entries across.
5555 # Value range is [1,2]. Default value is 1.
5557 LPFC_ATTR_R(multi_ring_support
, 1, 1, 2, "Determines number of primary "
5558 "SLI rings to spread IOCB entries across");
5561 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
5562 # identifies what rctl value to configure the additional ring for.
5563 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5565 LPFC_ATTR_R(multi_ring_rctl
, FC_RCTL_DD_UNSOL_DATA
, 1,
5566 255, "Identifies RCTL for additional ring configuration");
5569 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
5570 # identifies what type value to configure the additional ring for.
5571 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5573 LPFC_ATTR_R(multi_ring_type
, FC_TYPE_IP
, 1,
5574 255, "Identifies TYPE for additional ring configuration");
5577 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5578 # 0 = SmartSAN functionality disabled (default)
5579 # 1 = SmartSAN functionality enabled
5580 # This parameter will override the value of lpfc_fdmi_on module parameter.
5581 # Value range is [0,1]. Default value is 0.
5583 LPFC_ATTR_R(enable_SmartSAN
, 0, 0, 1, "Enable SmartSAN functionality");
5586 # lpfc_fdmi_on: Controls FDMI support.
5588 # 1 Traditional FDMI support (default)
5589 # Traditional FDMI support means the driver will assume FDMI-2 support;
5590 # however, if that fails, it will fallback to FDMI-1.
5591 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5592 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5594 # Value range [0,1]. Default value is 1.
5596 LPFC_ATTR_R(fdmi_on
, 1, 0, 1, "Enable FDMI support");
5599 # Specifies the maximum number of ELS cmds we can have outstanding (for
5600 # discovery). Value range is [1,64]. Default value = 32.
5602 LPFC_VPORT_ATTR(discovery_threads
, 32, 1, 64, "Maximum number of ELS commands "
5603 "during discovery");
5606 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5607 # will be scanned by the SCSI midlayer when sequential scanning is
5608 # used; and is also the highest LUN ID allowed when the SCSI midlayer
5609 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
5610 # LUN ID limit, but the SCSI midlayer requires this field for the uses
5611 # above. The lpfc driver limits the default value to 255 for two reasons.
5612 # As it bounds the sequential scan loop, scanning for thousands of luns
5613 # on a target can take minutes of wall clock time. Additionally,
5614 # there are FC targets, such as JBODs, that only recognize 8-bits of
5615 # LUN ID. When they receive a value greater than 8 bits, they chop off
5616 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
5617 # and so on all as LUN ID 0. This causes the linux kernel, which sees
5618 # valid responses at each of the LUN IDs, to believe there are multiple
5619 # devices present, when in fact, there is only 1.
5620 # A customer that is aware of their target behaviors, and the results as
5621 # indicated above, is welcome to increase the lpfc_max_luns value.
5622 # As mentioned, this value is not used by the lpfc driver, only the
5624 # Value range is [0,65535]. Default value is 255.
5625 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5627 LPFC_VPORT_ULL_ATTR_R(max_luns
, 255, 0, 65535, "Maximum allowed LUN ID");
5630 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5631 # Value range is [1,255], default value is 10.
5633 LPFC_ATTR_RW(poll_tmo
, 10, 1, 255,
5634 "Milliseconds driver will wait between polling FCP ring");
5637 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5638 # to complete in seconds. Value range is [5,180], default value is 60.
5640 LPFC_ATTR_RW(task_mgmt_tmo
, 60, 5, 180,
5641 "Maximum time to wait for task management commands to complete");
5643 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5644 # support this feature
5647 # 2 = MSI-X enabled (default)
5648 # Value range is [0,2]. Default value is 2.
5650 LPFC_ATTR_R(use_msi
, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5651 "MSI-X (2), if possible");
5654 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5656 * 0 = NVME OAS disabled
5657 * 1 = NVME OAS enabled
5659 * Value range is [0,1]. Default value is 0.
5661 LPFC_ATTR_RW(nvme_oas
, 0, 0, 1,
5662 "Use OAS bit on NVME IOs");
5665 * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5667 * 0 = Put NVME Command in SGL
5668 * 1 = Embed NVME Command in WQE (unless G7)
5669 * 2 = Embed NVME Command in WQE (force)
5671 * Value range is [0,2]. Default value is 1.
5673 LPFC_ATTR_RW(nvme_embed_cmd
, 1, 0, 2,
5674 "Embed NVME Command in WQE");
5677 * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5678 * the driver will advertise it supports to the SCSI layer.
5680 * 0 = Set nr_hw_queues by the number of CPUs or HW queues.
5681 * 1,256 = Manually specify nr_hw_queue value to be advertised,
5683 * Value range is [0,256]. Default value is 8.
5685 LPFC_ATTR_R(fcp_mq_threshold
, LPFC_FCP_MQ_THRESHOLD_DEF
,
5686 LPFC_FCP_MQ_THRESHOLD_MIN
, LPFC_FCP_MQ_THRESHOLD_MAX
,
5687 "Set the number of SCSI Queues advertised");
5690 * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5691 * will advertise it supports to the NVME and SCSI layers. This also
5692 * will map to the number of CQ/WQ pairs the driver will create.
5694 * The NVME Layer will try to create this many, plus 1 administrative
5695 * hardware queue. The administrative queue will always map to WQ 0
5696 * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5698 * 0 = Configure the number of hdw queues to the number of active CPUs.
5699 * 1,256 = Manually specify how many hdw queues to use.
5701 * Value range is [0,256]. Default value is 0.
5703 LPFC_ATTR_R(hdw_queue
,
5705 LPFC_HBA_HDWQ_MIN
, LPFC_HBA_HDWQ_MAX
,
5706 "Set the number of I/O Hardware Queues");
5708 #if IS_ENABLED(CONFIG_X86)
5710 * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
5712 * @phba: Pointer to HBA context object.
5715 lpfc_cpumask_irq_mode_init(struct lpfc_hba
*phba
)
5717 unsigned int cpu
, first_cpu
, numa_node
= NUMA_NO_NODE
;
5718 const struct cpumask
*sibling_mask
;
5719 struct cpumask
*aff_mask
= &phba
->sli4_hba
.irq_aff_mask
;
5721 cpumask_clear(aff_mask
);
5723 if (phba
->irq_chann_mode
== NUMA_MODE
) {
5724 /* Check if we're a NUMA architecture */
5725 numa_node
= dev_to_node(&phba
->pcidev
->dev
);
5726 if (numa_node
== NUMA_NO_NODE
) {
5727 phba
->irq_chann_mode
= NORMAL_MODE
;
5732 for_each_possible_cpu(cpu
) {
5733 switch (phba
->irq_chann_mode
) {
5735 if (cpu_to_node(cpu
) == numa_node
)
5736 cpumask_set_cpu(cpu
, aff_mask
);
5739 sibling_mask
= topology_sibling_cpumask(cpu
);
5740 first_cpu
= cpumask_first(sibling_mask
);
5741 if (first_cpu
< nr_cpu_ids
)
5742 cpumask_set_cpu(first_cpu
, aff_mask
);
5752 lpfc_assign_default_irq_chann(struct lpfc_hba
*phba
)
5754 #if IS_ENABLED(CONFIG_X86)
5755 switch (boot_cpu_data
.x86_vendor
) {
5756 case X86_VENDOR_AMD
:
5757 /* If AMD architecture, then default is NUMA_MODE */
5758 phba
->irq_chann_mode
= NUMA_MODE
;
5760 case X86_VENDOR_INTEL
:
5761 /* If Intel architecture, then default is no hyperthread mode */
5762 phba
->irq_chann_mode
= NHT_MODE
;
5765 phba
->irq_chann_mode
= NORMAL_MODE
;
5768 lpfc_cpumask_irq_mode_init(phba
);
5770 phba
->irq_chann_mode
= NORMAL_MODE
;
5775 * lpfc_irq_chann: Set the number of IRQ vectors that are available
5776 * for Hardware Queues to utilize. This also will map to the number
5777 * of EQ / MSI-X vectors the driver will create. This should never be
5778 * more than the number of Hardware Queues
5780 * 0 = Configure number of IRQ Channels to:
5781 * if AMD architecture, number of CPUs on HBA's NUMA node
5782 * if Intel architecture, number of physical CPUs.
5783 * otherwise, number of active CPUs.
5784 * [1,256] = Manually specify how many IRQ Channels to use.
5786 * Value range is [0,256]. Default value is [0].
5788 static uint lpfc_irq_chann
= LPFC_IRQ_CHANN_DEF
;
5789 module_param(lpfc_irq_chann
, uint
, 0444);
5790 MODULE_PARM_DESC(lpfc_irq_chann
, "Set number of interrupt vectors to allocate");
5792 /* lpfc_irq_chann_init - Set the hba irq_chann initial value
5793 * @phba: lpfc_hba pointer.
5794 * @val: contains the initial value
5797 * Validates the initial value is within range and assigns it to the
5798 * adapter. If not in range, an error message is posted and the
5799 * default value is assigned.
5802 * zero if value is in range and is set
5803 * -EINVAL if value was out of range
5806 lpfc_irq_chann_init(struct lpfc_hba
*phba
, uint32_t val
)
5808 const struct cpumask
*aff_mask
;
5810 if (phba
->cfg_use_msi
!= 2) {
5811 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5812 "8532 use_msi = %u ignoring cfg_irq_numa\n",
5814 phba
->irq_chann_mode
= NORMAL_MODE
;
5815 phba
->cfg_irq_chann
= LPFC_IRQ_CHANN_DEF
;
5819 /* Check if default setting was passed */
5820 if (val
== LPFC_IRQ_CHANN_DEF
)
5821 lpfc_assign_default_irq_chann(phba
);
5823 if (phba
->irq_chann_mode
!= NORMAL_MODE
) {
5824 aff_mask
= &phba
->sli4_hba
.irq_aff_mask
;
5826 if (cpumask_empty(aff_mask
)) {
5827 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5828 "8533 Could not identify CPUS for "
5829 "mode %d, ignoring\n",
5830 phba
->irq_chann_mode
);
5831 phba
->irq_chann_mode
= NORMAL_MODE
;
5832 phba
->cfg_irq_chann
= LPFC_IRQ_CHANN_DEF
;
5834 phba
->cfg_irq_chann
= cpumask_weight(aff_mask
);
5836 /* If no hyperthread mode, then set hdwq count to
5837 * aff_mask weight as well
5839 if (phba
->irq_chann_mode
== NHT_MODE
)
5840 phba
->cfg_hdw_queue
= phba
->cfg_irq_chann
;
5842 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5843 "8543 lpfc_irq_chann set to %u "
5844 "(mode: %d)\n", phba
->cfg_irq_chann
,
5845 phba
->irq_chann_mode
);
5848 if (val
> LPFC_IRQ_CHANN_MAX
) {
5849 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5850 "8545 lpfc_irq_chann attribute cannot "
5851 "be set to %u, allowed range is "
5855 LPFC_IRQ_CHANN_MAX
);
5856 phba
->cfg_irq_chann
= LPFC_IRQ_CHANN_DEF
;
5859 phba
->cfg_irq_chann
= val
;
5866 * lpfc_irq_chann_show - Display value of irq_chann
5867 * @dev: class converted to a Scsi_host structure.
5868 * @attr: device attribute, not used.
5869 * @buf: on return contains a string with the list sizes
5871 * Returns: size of formatted string.
5874 lpfc_irq_chann_show(struct device
*dev
, struct device_attribute
*attr
,
5877 struct Scsi_Host
*shost
= class_to_shost(dev
);
5878 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
5879 struct lpfc_hba
*phba
= vport
->phba
;
5881 return scnprintf(buf
, PAGE_SIZE
, "%u\n", phba
->cfg_irq_chann
);
5884 static DEVICE_ATTR_RO(lpfc_irq_chann
);
5887 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5888 # 0 = HBA resets disabled
5889 # 1 = HBA resets enabled (default)
5890 # 2 = HBA reset via PCI bus reset enabled
5891 # Value range is [0,2]. Default value is 1.
5893 LPFC_ATTR_RW(enable_hba_reset
, 1, 0, 2, "Enable HBA resets from the driver.");
5896 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5897 # 0 = HBA Heartbeat disabled
5898 # 1 = HBA Heartbeat enabled (default)
5899 # Value range is [0,1]. Default value is 1.
5901 LPFC_ATTR_R(enable_hba_heartbeat
, 0, 0, 1, "Enable HBA Heartbeat.");
5904 # lpfc_EnableXLane: Enable Express Lane Feature
5905 # 0x0 Express Lane Feature disabled
5906 # 0x1 Express Lane Feature enabled
5907 # Value range is [0,1]. Default value is 0.
5909 LPFC_ATTR_R(EnableXLane
, 0, 0, 1, "Enable Express Lane Feature.");
5912 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5913 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5914 # Value range is [0x0,0x7f]. Default value is 0
5916 LPFC_ATTR_RW(XLanePriority
, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5919 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5920 # 0 = BlockGuard disabled (default)
5921 # 1 = BlockGuard enabled
5922 # Value range is [0,1]. Default value is 0.
5924 LPFC_ATTR_R(enable_bg
, 0, 0, 1, "Enable BlockGuard Support");
5928 # - Bit mask of host protection capabilities used to register with the
5930 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5931 # - Allows you to ultimately specify which profiles to use
5932 # - Default will result in registering capabilities for all profiles.
5933 # - SHOST_DIF_TYPE1_PROTECTION 1
5934 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5935 # - SHOST_DIX_TYPE0_PROTECTION 8
5936 # HBA supports DIX Type 0: Host to HBA protection only
5937 # - SHOST_DIX_TYPE1_PROTECTION 16
5938 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5941 LPFC_ATTR(prot_mask
,
5942 (SHOST_DIF_TYPE1_PROTECTION
|
5943 SHOST_DIX_TYPE0_PROTECTION
|
5944 SHOST_DIX_TYPE1_PROTECTION
),
5946 (SHOST_DIF_TYPE1_PROTECTION
|
5947 SHOST_DIX_TYPE0_PROTECTION
|
5948 SHOST_DIX_TYPE1_PROTECTION
),
5949 "T10-DIF host protection capabilities mask");
5952 # lpfc_prot_guard: i
5953 # - Bit mask of protection guard types to register with the SCSI mid-layer
5954 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5955 # - Allows you to ultimately specify which profiles to use
5956 # - Default will result in registering capabilities for all guard types
5959 LPFC_ATTR(prot_guard
,
5960 SHOST_DIX_GUARD_IP
, SHOST_DIX_GUARD_CRC
, SHOST_DIX_GUARD_IP
,
5961 "T10-DIF host protection guard type");
5964 * Delay initial NPort discovery when Clean Address bit is cleared in
5965 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5966 * This parameter can have value 0 or 1.
5967 * When this parameter is set to 0, no delay is added to the initial
5969 * When this parameter is set to non-zero value, initial Nport discovery is
5970 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5971 * accept and FCID/Fabric name/Fabric portname is changed.
5972 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5973 * when Clean Address bit is cleared in FLOGI/FDISC
5974 * accept and FCID/Fabric name/Fabric portname is changed.
5975 * Default value is 0.
5977 LPFC_ATTR(delay_discovery
, 0, 0, 1,
5978 "Delay NPort discovery when Clean Address bit is cleared.");
5981 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5982 * This value can be set to values between 64 and 4096. The default value
5983 * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5984 * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5985 * Because of the additional overhead involved in setting up T10-DIF,
5986 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5987 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5989 static uint lpfc_sg_seg_cnt
= LPFC_DEFAULT_SG_SEG_CNT
;
5990 module_param(lpfc_sg_seg_cnt
, uint
, 0444);
5991 MODULE_PARM_DESC(lpfc_sg_seg_cnt
, "Max Scatter Gather Segment Count");
5994 * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5995 * configured for the adapter
5996 * @dev: class converted to a Scsi_host structure.
5997 * @attr: device attribute, not used.
5998 * @buf: on return contains a string with the list sizes
6000 * Returns: size of formatted string.
6003 lpfc_sg_seg_cnt_show(struct device
*dev
, struct device_attribute
*attr
,
6006 struct Scsi_Host
*shost
= class_to_shost(dev
);
6007 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
6008 struct lpfc_hba
*phba
= vport
->phba
;
6011 len
= scnprintf(buf
, PAGE_SIZE
, "SGL sz: %d total SGEs: %d\n",
6012 phba
->cfg_sg_dma_buf_size
, phba
->cfg_total_seg_cnt
);
6014 len
+= scnprintf(buf
+ len
, PAGE_SIZE
, "Cfg: %d SCSI: %d NVME: %d\n",
6015 phba
->cfg_sg_seg_cnt
, phba
->cfg_scsi_seg_cnt
,
6016 phba
->cfg_nvme_seg_cnt
);
6020 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt
);
6023 * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
6024 * @phba: lpfc_hba pointer.
6025 * @val: contains the initial value
6028 * Validates the initial value is within range and assigns it to the
6029 * adapter. If not in range, an error message is posted and the
6030 * default value is assigned.
6033 * zero if value is in range and is set
6034 * -EINVAL if value was out of range
6037 lpfc_sg_seg_cnt_init(struct lpfc_hba
*phba
, int val
)
6039 if (val
>= LPFC_MIN_SG_SEG_CNT
&& val
<= LPFC_MAX_SG_SEG_CNT
) {
6040 phba
->cfg_sg_seg_cnt
= val
;
6043 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6044 "0409 "LPFC_DRIVER_NAME
"_sg_seg_cnt attribute cannot "
6045 "be set to %d, allowed range is [%d, %d]\n",
6046 val
, LPFC_MIN_SG_SEG_CNT
, LPFC_MAX_SG_SEG_CNT
);
6047 phba
->cfg_sg_seg_cnt
= LPFC_DEFAULT_SG_SEG_CNT
;
6052 * lpfc_enable_mds_diags: Enable MDS Diagnostics
6053 * 0 = MDS Diagnostics disabled (default)
6054 * 1 = MDS Diagnostics enabled
6055 * Value range is [0,1]. Default value is 0.
6057 LPFC_ATTR_RW(enable_mds_diags
, 0, 0, 1, "Enable MDS Diagnostics");
6060 * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
6061 * 0 = Disable firmware logging (default)
6062 * [1-4] = Multiple of 1/4th Mb of host memory for FW logging
6063 * Value range [0..4]. Default value is 0
6065 LPFC_ATTR(ras_fwlog_buffsize
, 0, 0, 4, "Host memory for FW logging");
6066 lpfc_param_show(ras_fwlog_buffsize
);
6069 lpfc_ras_fwlog_buffsize_set(struct lpfc_hba
*phba
, uint val
)
6072 enum ras_state state
;
6074 if (!lpfc_rangecheck(val
, 0, 4))
6077 if (phba
->cfg_ras_fwlog_buffsize
== val
)
6080 if (phba
->cfg_ras_fwlog_func
!= PCI_FUNC(phba
->pcidev
->devfn
))
6083 spin_lock_irq(&phba
->hbalock
);
6084 state
= phba
->ras_fwlog
.state
;
6085 spin_unlock_irq(&phba
->hbalock
);
6087 if (state
== REG_INPROGRESS
) {
6088 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
, "6147 RAS Logging "
6089 "registration is in progress\n");
6093 /* For disable logging: stop the logs and free the DMA.
6094 * For ras_fwlog_buffsize size change we still need to free and
6095 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
6097 phba
->cfg_ras_fwlog_buffsize
= val
;
6098 if (state
== ACTIVE
) {
6099 lpfc_ras_stop_fwlog(phba
);
6100 lpfc_sli4_ras_dma_free(phba
);
6103 lpfc_sli4_ras_init(phba
);
6104 if (phba
->ras_fwlog
.ras_enabled
)
6105 ret
= lpfc_sli4_ras_fwlog_init(phba
, phba
->cfg_ras_fwlog_level
,
6106 LPFC_RAS_ENABLE_LOGGING
);
6110 lpfc_param_store(ras_fwlog_buffsize
);
6111 static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize
);
6114 * lpfc_ras_fwlog_level: Firmware logging verbosity level
6115 * Valid only if firmware logging is enabled
6116 * 0(Least Verbosity) 4 (most verbosity)
6117 * Value range is [0..4]. Default value is 0
6119 LPFC_ATTR_RW(ras_fwlog_level
, 0, 0, 4, "Firmware Logging Level");
6122 * lpfc_ras_fwlog_func: Firmware logging enabled on function number
6123 * Default function which has RAS support : 0
6124 * Value Range is [0..7].
6125 * FW logging is a global action and enablement is via a specific
6128 LPFC_ATTR_RW(ras_fwlog_func
, 0, 0, 7, "Firmware Logging Enabled on Function");
6131 * lpfc_enable_bbcr: Enable BB Credit Recovery
6132 * 0 = BB Credit Recovery disabled
6133 * 1 = BB Credit Recovery enabled (default)
6134 * Value range is [0,1]. Default value is 1.
6136 LPFC_BBCR_ATTR_RW(enable_bbcr
, 1, 0, 1, "Enable BBC Recovery");
6139 * lpfc_enable_dpp: Enable DPP on G7
6140 * 0 = DPP on G7 disabled
6141 * 1 = DPP on G7 enabled (default)
6142 * Value range is [0,1]. Default value is 1.
6144 LPFC_ATTR_RW(enable_dpp
, 1, 0, 1, "Enable Direct Packet Push");
6147 * lpfc_enable_mi: Enable FDMI MIB
6149 * 1 = enabled (default)
6150 * Value range is [0,1].
6152 LPFC_ATTR_R(enable_mi
, 1, 0, 1, "Enable MI");
6154 struct device_attribute
*lpfc_hba_attrs
[] = {
6155 &dev_attr_nvme_info
,
6156 &dev_attr_scsi_stat
,
6158 &dev_attr_bg_guard_err
,
6159 &dev_attr_bg_apptag_err
,
6160 &dev_attr_bg_reftag_err
,
6162 &dev_attr_serialnum
,
6163 &dev_attr_modeldesc
,
6164 &dev_attr_modelname
,
6165 &dev_attr_programtype
,
6169 &dev_attr_option_rom_version
,
6170 &dev_attr_link_state
,
6171 &dev_attr_num_discovered_ports
,
6172 &dev_attr_menlo_mgmt_mode
,
6173 &dev_attr_lpfc_drvr_version
,
6174 &dev_attr_lpfc_enable_fip
,
6175 &dev_attr_lpfc_temp_sensor
,
6176 &dev_attr_lpfc_log_verbose
,
6177 &dev_attr_lpfc_lun_queue_depth
,
6178 &dev_attr_lpfc_tgt_queue_depth
,
6179 &dev_attr_lpfc_hba_queue_depth
,
6180 &dev_attr_lpfc_peer_port_login
,
6181 &dev_attr_lpfc_nodev_tmo
,
6182 &dev_attr_lpfc_devloss_tmo
,
6183 &dev_attr_lpfc_enable_fc4_type
,
6184 &dev_attr_lpfc_fcp_class
,
6185 &dev_attr_lpfc_use_adisc
,
6186 &dev_attr_lpfc_first_burst_size
,
6187 &dev_attr_lpfc_ack0
,
6188 &dev_attr_lpfc_xri_rebalancing
,
6189 &dev_attr_lpfc_topology
,
6190 &dev_attr_lpfc_scan_down
,
6191 &dev_attr_lpfc_link_speed
,
6192 &dev_attr_lpfc_fcp_io_sched
,
6193 &dev_attr_lpfc_ns_query
,
6194 &dev_attr_lpfc_fcp2_no_tgt_reset
,
6195 &dev_attr_lpfc_cr_delay
,
6196 &dev_attr_lpfc_cr_count
,
6197 &dev_attr_lpfc_multi_ring_support
,
6198 &dev_attr_lpfc_multi_ring_rctl
,
6199 &dev_attr_lpfc_multi_ring_type
,
6200 &dev_attr_lpfc_fdmi_on
,
6201 &dev_attr_lpfc_enable_SmartSAN
,
6202 &dev_attr_lpfc_max_luns
,
6203 &dev_attr_lpfc_enable_npiv
,
6204 &dev_attr_lpfc_fcf_failover_policy
,
6205 &dev_attr_lpfc_enable_rrq
,
6206 &dev_attr_nport_evt_cnt
,
6207 &dev_attr_board_mode
,
6214 &dev_attr_npiv_info
,
6215 &dev_attr_issue_reset
,
6216 &dev_attr_lpfc_poll
,
6217 &dev_attr_lpfc_poll_tmo
,
6218 &dev_attr_lpfc_task_mgmt_tmo
,
6219 &dev_attr_lpfc_use_msi
,
6220 &dev_attr_lpfc_nvme_oas
,
6221 &dev_attr_lpfc_nvme_embed_cmd
,
6222 &dev_attr_lpfc_fcp_imax
,
6223 &dev_attr_lpfc_force_rscn
,
6224 &dev_attr_lpfc_cq_poll_threshold
,
6225 &dev_attr_lpfc_cq_max_proc_limit
,
6226 &dev_attr_lpfc_fcp_cpu_map
,
6227 &dev_attr_lpfc_fcp_mq_threshold
,
6228 &dev_attr_lpfc_hdw_queue
,
6229 &dev_attr_lpfc_irq_chann
,
6230 &dev_attr_lpfc_suppress_rsp
,
6231 &dev_attr_lpfc_nvmet_mrq
,
6232 &dev_attr_lpfc_nvmet_mrq_post
,
6233 &dev_attr_lpfc_nvme_enable_fb
,
6234 &dev_attr_lpfc_nvmet_fb_size
,
6235 &dev_attr_lpfc_enable_bg
,
6236 &dev_attr_lpfc_soft_wwnn
,
6237 &dev_attr_lpfc_soft_wwpn
,
6238 &dev_attr_lpfc_soft_wwn_enable
,
6239 &dev_attr_lpfc_enable_hba_reset
,
6240 &dev_attr_lpfc_enable_hba_heartbeat
,
6241 &dev_attr_lpfc_EnableXLane
,
6242 &dev_attr_lpfc_XLanePriority
,
6243 &dev_attr_lpfc_xlane_lun
,
6244 &dev_attr_lpfc_xlane_tgt
,
6245 &dev_attr_lpfc_xlane_vpt
,
6246 &dev_attr_lpfc_xlane_lun_state
,
6247 &dev_attr_lpfc_xlane_lun_status
,
6248 &dev_attr_lpfc_xlane_priority
,
6249 &dev_attr_lpfc_sg_seg_cnt
,
6250 &dev_attr_lpfc_max_scsicmpl_time
,
6251 &dev_attr_lpfc_stat_data_ctrl
,
6252 &dev_attr_lpfc_aer_support
,
6253 &dev_attr_lpfc_aer_state_cleanup
,
6254 &dev_attr_lpfc_sriov_nr_virtfn
,
6255 &dev_attr_lpfc_req_fw_upgrade
,
6256 &dev_attr_lpfc_suppress_link_up
,
6261 &dev_attr_txcmplq_hw
,
6262 &dev_attr_lpfc_sriov_hw_max_virtfn
,
6264 &dev_attr_lpfc_xlane_supported
,
6265 &dev_attr_lpfc_enable_mds_diags
,
6266 &dev_attr_lpfc_ras_fwlog_buffsize
,
6267 &dev_attr_lpfc_ras_fwlog_level
,
6268 &dev_attr_lpfc_ras_fwlog_func
,
6269 &dev_attr_lpfc_enable_bbcr
,
6270 &dev_attr_lpfc_enable_dpp
,
6271 &dev_attr_lpfc_enable_mi
,
6275 struct device_attribute
*lpfc_vport_attrs
[] = {
6277 &dev_attr_link_state
,
6278 &dev_attr_num_discovered_ports
,
6279 &dev_attr_lpfc_drvr_version
,
6280 &dev_attr_lpfc_log_verbose
,
6281 &dev_attr_lpfc_lun_queue_depth
,
6282 &dev_attr_lpfc_tgt_queue_depth
,
6283 &dev_attr_lpfc_nodev_tmo
,
6284 &dev_attr_lpfc_devloss_tmo
,
6285 &dev_attr_lpfc_hba_queue_depth
,
6286 &dev_attr_lpfc_peer_port_login
,
6287 &dev_attr_lpfc_restrict_login
,
6288 &dev_attr_lpfc_fcp_class
,
6289 &dev_attr_lpfc_use_adisc
,
6290 &dev_attr_lpfc_first_burst_size
,
6291 &dev_attr_lpfc_max_luns
,
6292 &dev_attr_nport_evt_cnt
,
6293 &dev_attr_npiv_info
,
6294 &dev_attr_lpfc_enable_da_id
,
6295 &dev_attr_lpfc_max_scsicmpl_time
,
6296 &dev_attr_lpfc_stat_data_ctrl
,
6297 &dev_attr_lpfc_static_vport
,
6302 * sysfs_ctlreg_write - Write method for writing to ctlreg
6303 * @filp: open sysfs file
6304 * @kobj: kernel kobject that contains the kernel class device.
6305 * @bin_attr: kernel attributes passed to us.
6306 * @buf: contains the data to be written to the adapter IOREG space.
6307 * @off: offset into buffer to beginning of data.
6308 * @count: bytes to transfer.
6311 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6312 * Uses the adapter io control registers to send buf contents to the adapter.
6315 * -ERANGE off and count combo out of range
6316 * -EINVAL off, count or buff address invalid
6317 * -EPERM adapter is offline
6318 * value of count, buf contents written
6321 sysfs_ctlreg_write(struct file
*filp
, struct kobject
*kobj
,
6322 struct bin_attribute
*bin_attr
,
6323 char *buf
, loff_t off
, size_t count
)
6326 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
6327 struct Scsi_Host
*shost
= class_to_shost(dev
);
6328 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6329 struct lpfc_hba
*phba
= vport
->phba
;
6331 if (phba
->sli_rev
>= LPFC_SLI_REV4
)
6334 if ((off
+ count
) > FF_REG_AREA_SIZE
)
6337 if (count
<= LPFC_REG_WRITE_KEY_SIZE
)
6340 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
6343 /* This is to protect HBA registers from accidental writes. */
6344 if (memcmp(buf
, LPFC_REG_WRITE_KEY
, LPFC_REG_WRITE_KEY_SIZE
))
6347 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
6350 spin_lock_irq(&phba
->hbalock
);
6351 for (buf_off
= 0; buf_off
< count
- LPFC_REG_WRITE_KEY_SIZE
;
6352 buf_off
+= sizeof(uint32_t))
6353 writel(*((uint32_t *)(buf
+ buf_off
+ LPFC_REG_WRITE_KEY_SIZE
)),
6354 phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
6356 spin_unlock_irq(&phba
->hbalock
);
6362 * sysfs_ctlreg_read - Read method for reading from ctlreg
6363 * @filp: open sysfs file
6364 * @kobj: kernel kobject that contains the kernel class device.
6365 * @bin_attr: kernel attributes passed to us.
6366 * @buf: if successful contains the data from the adapter IOREG space.
6367 * @off: offset into buffer to beginning of data.
6368 * @count: bytes to transfer.
6371 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6372 * Uses the adapter io control registers to read data into buf.
6375 * -ERANGE off and count combo out of range
6376 * -EINVAL off, count or buff address invalid
6377 * value of count, buf contents read
6380 sysfs_ctlreg_read(struct file
*filp
, struct kobject
*kobj
,
6381 struct bin_attribute
*bin_attr
,
6382 char *buf
, loff_t off
, size_t count
)
6386 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
6387 struct Scsi_Host
*shost
= class_to_shost(dev
);
6388 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6389 struct lpfc_hba
*phba
= vport
->phba
;
6391 if (phba
->sli_rev
>= LPFC_SLI_REV4
)
6394 if (off
> FF_REG_AREA_SIZE
)
6397 if ((off
+ count
) > FF_REG_AREA_SIZE
)
6398 count
= FF_REG_AREA_SIZE
- off
;
6400 if (count
== 0) return 0;
6402 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
6405 spin_lock_irq(&phba
->hbalock
);
6407 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t)) {
6408 tmp_ptr
= (uint32_t *)(buf
+ buf_off
);
6409 *tmp_ptr
= readl(phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
6412 spin_unlock_irq(&phba
->hbalock
);
6417 static struct bin_attribute sysfs_ctlreg_attr
= {
6420 .mode
= S_IRUSR
| S_IWUSR
,
6423 .read
= sysfs_ctlreg_read
,
6424 .write
= sysfs_ctlreg_write
,
6428 * sysfs_mbox_write - Write method for writing information via mbox
6429 * @filp: open sysfs file
6430 * @kobj: kernel kobject that contains the kernel class device.
6431 * @bin_attr: kernel attributes passed to us.
6432 * @buf: contains the data to be written to sysfs mbox.
6433 * @off: offset into buffer to beginning of data.
6434 * @count: bytes to transfer.
6437 * Deprecated function. All mailbox access from user space is performed via the
6441 * -EPERM operation not permitted
6444 sysfs_mbox_write(struct file
*filp
, struct kobject
*kobj
,
6445 struct bin_attribute
*bin_attr
,
6446 char *buf
, loff_t off
, size_t count
)
6452 * sysfs_mbox_read - Read method for reading information via mbox
6453 * @filp: open sysfs file
6454 * @kobj: kernel kobject that contains the kernel class device.
6455 * @bin_attr: kernel attributes passed to us.
6456 * @buf: contains the data to be read from sysfs mbox.
6457 * @off: offset into buffer to beginning of data.
6458 * @count: bytes to transfer.
6461 * Deprecated function. All mailbox access from user space is performed via the
6465 * -EPERM operation not permitted
6468 sysfs_mbox_read(struct file
*filp
, struct kobject
*kobj
,
6469 struct bin_attribute
*bin_attr
,
6470 char *buf
, loff_t off
, size_t count
)
6475 static struct bin_attribute sysfs_mbox_attr
= {
6478 .mode
= S_IRUSR
| S_IWUSR
,
6480 .size
= MAILBOX_SYSFS_MAX
,
6481 .read
= sysfs_mbox_read
,
6482 .write
= sysfs_mbox_write
,
6486 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6487 * @vport: address of lpfc vport structure.
6491 * error return code from sysfs_create_bin_file()
6494 lpfc_alloc_sysfs_attr(struct lpfc_vport
*vport
)
6496 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6499 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
6500 &sysfs_drvr_stat_data_attr
);
6502 /* Virtual ports do not need ctrl_reg and mbox */
6503 if (error
|| vport
->port_type
== LPFC_NPIV_PORT
)
6506 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
6507 &sysfs_ctlreg_attr
);
6509 goto out_remove_stat_attr
;
6511 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
6514 goto out_remove_ctlreg_attr
;
6517 out_remove_ctlreg_attr
:
6518 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_ctlreg_attr
);
6519 out_remove_stat_attr
:
6520 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
,
6521 &sysfs_drvr_stat_data_attr
);
6527 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6528 * @vport: address of lpfc vport structure.
6531 lpfc_free_sysfs_attr(struct lpfc_vport
*vport
)
6533 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6534 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
,
6535 &sysfs_drvr_stat_data_attr
);
6536 /* Virtual ports do not need ctrl_reg and mbox */
6537 if (vport
->port_type
== LPFC_NPIV_PORT
)
6539 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_mbox_attr
);
6540 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_ctlreg_attr
);
6544 * Dynamic FC Host Attributes Support
6548 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6549 * @shost: kernel scsi host pointer.
6552 lpfc_get_host_symbolic_name(struct Scsi_Host
*shost
)
6554 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
6556 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
6557 sizeof fc_host_symbolic_name(shost
));
6561 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6562 * @shost: kernel scsi host pointer.
6565 lpfc_get_host_port_id(struct Scsi_Host
*shost
)
6567 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6569 /* note: fc_myDID already in cpu endianness */
6570 fc_host_port_id(shost
) = vport
->fc_myDID
;
6574 * lpfc_get_host_port_type - Set the value of the scsi host port type
6575 * @shost: kernel scsi host pointer.
6578 lpfc_get_host_port_type(struct Scsi_Host
*shost
)
6580 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6581 struct lpfc_hba
*phba
= vport
->phba
;
6583 spin_lock_irq(shost
->host_lock
);
6585 if (vport
->port_type
== LPFC_NPIV_PORT
) {
6586 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
6587 } else if (lpfc_is_link_up(phba
)) {
6588 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6589 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
6590 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
6592 fc_host_port_type(shost
) = FC_PORTTYPE_LPORT
;
6594 if (vport
->fc_flag
& FC_FABRIC
)
6595 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
6597 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
6600 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
6602 spin_unlock_irq(shost
->host_lock
);
6606 * lpfc_get_host_port_state - Set the value of the scsi host port state
6607 * @shost: kernel scsi host pointer.
6610 lpfc_get_host_port_state(struct Scsi_Host
*shost
)
6612 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6613 struct lpfc_hba
*phba
= vport
->phba
;
6615 spin_lock_irq(shost
->host_lock
);
6617 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
6618 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
6620 switch (phba
->link_state
) {
6621 case LPFC_LINK_UNKNOWN
:
6622 case LPFC_LINK_DOWN
:
6623 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
6627 case LPFC_HBA_READY
:
6628 /* Links up, reports port state accordingly */
6629 if (vport
->port_state
< LPFC_VPORT_READY
)
6630 fc_host_port_state(shost
) =
6631 FC_PORTSTATE_BYPASSED
;
6633 fc_host_port_state(shost
) =
6634 FC_PORTSTATE_ONLINE
;
6636 case LPFC_HBA_ERROR
:
6637 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
6640 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
6645 spin_unlock_irq(shost
->host_lock
);
6649 * lpfc_get_host_speed - Set the value of the scsi host speed
6650 * @shost: kernel scsi host pointer.
6653 lpfc_get_host_speed(struct Scsi_Host
*shost
)
6655 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6656 struct lpfc_hba
*phba
= vport
->phba
;
6658 spin_lock_irq(shost
->host_lock
);
6660 if ((lpfc_is_link_up(phba
)) && (!(phba
->hba_flag
& HBA_FCOE_MODE
))) {
6661 switch(phba
->fc_linkspeed
) {
6662 case LPFC_LINK_SPEED_1GHZ
:
6663 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
6665 case LPFC_LINK_SPEED_2GHZ
:
6666 fc_host_speed(shost
) = FC_PORTSPEED_2GBIT
;
6668 case LPFC_LINK_SPEED_4GHZ
:
6669 fc_host_speed(shost
) = FC_PORTSPEED_4GBIT
;
6671 case LPFC_LINK_SPEED_8GHZ
:
6672 fc_host_speed(shost
) = FC_PORTSPEED_8GBIT
;
6674 case LPFC_LINK_SPEED_10GHZ
:
6675 fc_host_speed(shost
) = FC_PORTSPEED_10GBIT
;
6677 case LPFC_LINK_SPEED_16GHZ
:
6678 fc_host_speed(shost
) = FC_PORTSPEED_16GBIT
;
6680 case LPFC_LINK_SPEED_32GHZ
:
6681 fc_host_speed(shost
) = FC_PORTSPEED_32GBIT
;
6683 case LPFC_LINK_SPEED_64GHZ
:
6684 fc_host_speed(shost
) = FC_PORTSPEED_64GBIT
;
6686 case LPFC_LINK_SPEED_128GHZ
:
6687 fc_host_speed(shost
) = FC_PORTSPEED_128GBIT
;
6690 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
6693 } else if (lpfc_is_link_up(phba
) && (phba
->hba_flag
& HBA_FCOE_MODE
)) {
6694 switch (phba
->fc_linkspeed
) {
6695 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
6696 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
6698 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
6699 fc_host_speed(shost
) = FC_PORTSPEED_10GBIT
;
6701 case LPFC_ASYNC_LINK_SPEED_20GBPS
:
6702 fc_host_speed(shost
) = FC_PORTSPEED_20GBIT
;
6704 case LPFC_ASYNC_LINK_SPEED_25GBPS
:
6705 fc_host_speed(shost
) = FC_PORTSPEED_25GBIT
;
6707 case LPFC_ASYNC_LINK_SPEED_40GBPS
:
6708 fc_host_speed(shost
) = FC_PORTSPEED_40GBIT
;
6710 case LPFC_ASYNC_LINK_SPEED_100GBPS
:
6711 fc_host_speed(shost
) = FC_PORTSPEED_100GBIT
;
6714 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
6718 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
6720 spin_unlock_irq(shost
->host_lock
);
6724 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6725 * @shost: kernel scsi host pointer.
6728 lpfc_get_host_fabric_name (struct Scsi_Host
*shost
)
6730 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6731 struct lpfc_hba
*phba
= vport
->phba
;
6734 spin_lock_irq(shost
->host_lock
);
6736 if ((vport
->port_state
> LPFC_FLOGI
) &&
6737 ((vport
->fc_flag
& FC_FABRIC
) ||
6738 ((phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) &&
6739 (vport
->fc_flag
& FC_PUBLIC_LOOP
))))
6740 node_name
= wwn_to_u64(phba
->fc_fabparam
.nodeName
.u
.wwn
);
6742 /* fabric is local port if there is no F/FL_Port */
6745 spin_unlock_irq(shost
->host_lock
);
6747 fc_host_fabric_name(shost
) = node_name
;
6751 * lpfc_get_stats - Return statistical information about the adapter
6752 * @shost: kernel scsi host pointer.
6755 * NULL on error for link down, no mbox pool, sli2 active,
6756 * management not allowed, memory allocation error, or mbox error.
6760 * address of the adapter host statistics
6762 static struct fc_host_statistics
*
6763 lpfc_get_stats(struct Scsi_Host
*shost
)
6765 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6766 struct lpfc_hba
*phba
= vport
->phba
;
6767 struct lpfc_sli
*psli
= &phba
->sli
;
6768 struct fc_host_statistics
*hs
= &phba
->link_stats
;
6769 struct lpfc_lnk_stat
* lso
= &psli
->lnk_stat_offsets
;
6770 LPFC_MBOXQ_t
*pmboxq
;
6775 * prevent udev from issuing mailbox commands until the port is
6778 if (phba
->link_state
< LPFC_LINK_DOWN
||
6779 !phba
->mbox_mem_pool
||
6780 (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
) == 0)
6783 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
6786 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6789 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
6791 pmb
= &pmboxq
->u
.mb
;
6792 pmb
->mbxCommand
= MBX_READ_STATUS
;
6793 pmb
->mbxOwner
= OWN_HOST
;
6794 pmboxq
->ctx_buf
= NULL
;
6795 pmboxq
->vport
= vport
;
6797 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
6798 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
6800 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
6802 if (rc
!= MBX_SUCCESS
) {
6803 if (rc
!= MBX_TIMEOUT
)
6804 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
6808 memset(hs
, 0, sizeof (struct fc_host_statistics
));
6810 hs
->tx_frames
= pmb
->un
.varRdStatus
.xmitFrameCnt
;
6812 * The MBX_READ_STATUS returns tx_k_bytes which has to
6813 * converted to words
6815 hs
->tx_words
= (uint64_t)
6816 ((uint64_t)pmb
->un
.varRdStatus
.xmitByteCnt
6818 hs
->rx_frames
= pmb
->un
.varRdStatus
.rcvFrameCnt
;
6819 hs
->rx_words
= (uint64_t)
6820 ((uint64_t)pmb
->un
.varRdStatus
.rcvByteCnt
6823 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
6824 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
6825 pmb
->mbxOwner
= OWN_HOST
;
6826 pmboxq
->ctx_buf
= NULL
;
6827 pmboxq
->vport
= vport
;
6829 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
6830 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
6832 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
6834 if (rc
!= MBX_SUCCESS
) {
6835 if (rc
!= MBX_TIMEOUT
)
6836 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
6840 hs
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
6841 hs
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
6842 hs
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
6843 hs
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
6844 hs
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
6845 hs
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
6846 hs
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
6848 hs
->link_failure_count
-= lso
->link_failure_count
;
6849 hs
->loss_of_sync_count
-= lso
->loss_of_sync_count
;
6850 hs
->loss_of_signal_count
-= lso
->loss_of_signal_count
;
6851 hs
->prim_seq_protocol_err_count
-= lso
->prim_seq_protocol_err_count
;
6852 hs
->invalid_tx_word_count
-= lso
->invalid_tx_word_count
;
6853 hs
->invalid_crc_count
-= lso
->invalid_crc_count
;
6854 hs
->error_frames
-= lso
->error_frames
;
6856 if (phba
->hba_flag
& HBA_FCOE_MODE
) {
6858 hs
->nos_count
= (phba
->link_events
>> 1);
6859 hs
->nos_count
-= lso
->link_events
;
6860 } else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6861 hs
->lip_count
= (phba
->fc_eventTag
>> 1);
6862 hs
->lip_count
-= lso
->link_events
;
6866 hs
->nos_count
= (phba
->fc_eventTag
>> 1);
6867 hs
->nos_count
-= lso
->link_events
;
6870 hs
->dumped_frames
= -1;
6872 hs
->seconds_since_last_reset
= ktime_get_seconds() - psli
->stats_start
;
6874 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
6880 * lpfc_reset_stats - Copy the adapter link stats information
6881 * @shost: kernel scsi host pointer.
6884 lpfc_reset_stats(struct Scsi_Host
*shost
)
6886 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6887 struct lpfc_hba
*phba
= vport
->phba
;
6888 struct lpfc_sli
*psli
= &phba
->sli
;
6889 struct lpfc_lnk_stat
*lso
= &psli
->lnk_stat_offsets
;
6890 LPFC_MBOXQ_t
*pmboxq
;
6894 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
6897 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6900 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
6902 pmb
= &pmboxq
->u
.mb
;
6903 pmb
->mbxCommand
= MBX_READ_STATUS
;
6904 pmb
->mbxOwner
= OWN_HOST
;
6905 pmb
->un
.varWords
[0] = 0x1; /* reset request */
6906 pmboxq
->ctx_buf
= NULL
;
6907 pmboxq
->vport
= vport
;
6909 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
6910 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
6911 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
6913 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
6915 if (rc
!= MBX_SUCCESS
) {
6916 if (rc
!= MBX_TIMEOUT
)
6917 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
6921 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
6922 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
6923 pmb
->mbxOwner
= OWN_HOST
;
6924 pmboxq
->ctx_buf
= NULL
;
6925 pmboxq
->vport
= vport
;
6927 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
6928 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
6929 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
6931 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
6933 if (rc
!= MBX_SUCCESS
) {
6934 if (rc
!= MBX_TIMEOUT
)
6935 mempool_free( pmboxq
, phba
->mbox_mem_pool
);
6939 lso
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
6940 lso
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
6941 lso
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
6942 lso
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
6943 lso
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
6944 lso
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
6945 lso
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
6946 if (phba
->hba_flag
& HBA_FCOE_MODE
)
6947 lso
->link_events
= (phba
->link_events
>> 1);
6949 lso
->link_events
= (phba
->fc_eventTag
>> 1);
6951 psli
->stats_start
= ktime_get_seconds();
6953 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
6959 * The LPFC driver treats linkdown handling as target loss events so there
6960 * are no sysfs handlers for link_down_tmo.
6964 * lpfc_get_node_by_target - Return the nodelist for a target
6965 * @starget: kernel scsi target pointer.
6968 * address of the node list if found
6969 * NULL target not found
6971 static struct lpfc_nodelist
*
6972 lpfc_get_node_by_target(struct scsi_target
*starget
)
6974 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
6975 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
6976 struct lpfc_nodelist
*ndlp
;
6978 spin_lock_irq(shost
->host_lock
);
6979 /* Search for this, mapped, target ID */
6980 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
6981 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
6982 starget
->id
== ndlp
->nlp_sid
) {
6983 spin_unlock_irq(shost
->host_lock
);
6987 spin_unlock_irq(shost
->host_lock
);
6992 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6993 * @starget: kernel scsi target pointer.
6996 lpfc_get_starget_port_id(struct scsi_target
*starget
)
6998 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
7000 fc_starget_port_id(starget
) = ndlp
? ndlp
->nlp_DID
: -1;
7004 * lpfc_get_starget_node_name - Set the target node name
7005 * @starget: kernel scsi target pointer.
7007 * Description: Set the target node name to the ndlp node name wwn or zero.
7010 lpfc_get_starget_node_name(struct scsi_target
*starget
)
7012 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
7014 fc_starget_node_name(starget
) =
7015 ndlp
? wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
) : 0;
7019 * lpfc_get_starget_port_name - Set the target port name
7020 * @starget: kernel scsi target pointer.
7022 * Description: set the target port name to the ndlp port name wwn or zero.
7025 lpfc_get_starget_port_name(struct scsi_target
*starget
)
7027 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
7029 fc_starget_port_name(starget
) =
7030 ndlp
? wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
) : 0;
7034 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
7035 * @rport: fc rport address.
7036 * @timeout: new value for dev loss tmo.
7039 * If timeout is non zero set the dev_loss_tmo to timeout, else set
7040 * dev_loss_tmo to one.
7043 lpfc_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
7045 struct lpfc_rport_data
*rdata
= rport
->dd_data
;
7046 struct lpfc_nodelist
*ndlp
= rdata
->pnode
;
7047 #if (IS_ENABLED(CONFIG_NVME_FC))
7048 struct lpfc_nvme_rport
*nrport
= NULL
;
7052 rport
->dev_loss_tmo
= timeout
;
7054 rport
->dev_loss_tmo
= 1;
7057 dev_info(&rport
->dev
, "Cannot find remote node to "
7058 "set rport dev loss tmo, port_id x%x\n",
7063 #if (IS_ENABLED(CONFIG_NVME_FC))
7064 nrport
= lpfc_ndlp_get_nrport(ndlp
);
7066 if (nrport
&& nrport
->remoteport
)
7067 nvme_fc_set_remoteport_devloss(nrport
->remoteport
,
7068 rport
->dev_loss_tmo
);
7073 * lpfc_rport_show_function - Return rport target information
7076 * Macro that uses field to generate a function with the name lpfc_show_rport_
7078 * lpfc_show_rport_##field: returns the bytes formatted in buf
7079 * @cdev: class converted to an fc_rport.
7080 * @buf: on return contains the target_field or zero.
7082 * Returns: size of formatted string.
7084 #define lpfc_rport_show_function(field, format_string, sz, cast) \
7086 lpfc_show_rport_##field (struct device *dev, \
7087 struct device_attribute *attr, \
7090 struct fc_rport *rport = transport_class_to_rport(dev); \
7091 struct lpfc_rport_data *rdata = rport->hostdata; \
7092 return scnprintf(buf, sz, format_string, \
7093 (rdata->target) ? cast rdata->target->field : 0); \
7096 #define lpfc_rport_rd_attr(field, format_string, sz) \
7097 lpfc_rport_show_function(field, format_string, sz, ) \
7098 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
7101 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
7102 * @fc_vport: The fc_vport who's symbolic name has been changed.
7105 * This function is called by the transport after the @fc_vport's symbolic name
7106 * has been changed. This function re-registers the symbolic name with the
7107 * switch to propagate the change into the fabric if the vport is active.
7110 lpfc_set_vport_symbolic_name(struct fc_vport
*fc_vport
)
7112 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
7114 if (vport
->port_state
== LPFC_VPORT_READY
)
7115 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
7119 * lpfc_hba_log_verbose_init - Set hba's log verbose level
7120 * @phba: Pointer to lpfc_hba struct.
7121 * @verbose: Verbose level to set.
7123 * This function is called by the lpfc_get_cfgparam() routine to set the
7124 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
7125 * log message according to the module's lpfc_log_verbose parameter setting
7126 * before hba port or vport created.
7129 lpfc_hba_log_verbose_init(struct lpfc_hba
*phba
, uint32_t verbose
)
7131 phba
->cfg_log_verbose
= verbose
;
7134 struct fc_function_template lpfc_transport_functions
= {
7135 /* fixed attributes the driver supports */
7136 .show_host_node_name
= 1,
7137 .show_host_port_name
= 1,
7138 .show_host_supported_classes
= 1,
7139 .show_host_supported_fc4s
= 1,
7140 .show_host_supported_speeds
= 1,
7141 .show_host_maxframe_size
= 1,
7143 .get_host_symbolic_name
= lpfc_get_host_symbolic_name
,
7144 .show_host_symbolic_name
= 1,
7146 /* dynamic attributes the driver supports */
7147 .get_host_port_id
= lpfc_get_host_port_id
,
7148 .show_host_port_id
= 1,
7150 .get_host_port_type
= lpfc_get_host_port_type
,
7151 .show_host_port_type
= 1,
7153 .get_host_port_state
= lpfc_get_host_port_state
,
7154 .show_host_port_state
= 1,
7156 /* active_fc4s is shown but doesn't change (thus no get function) */
7157 .show_host_active_fc4s
= 1,
7159 .get_host_speed
= lpfc_get_host_speed
,
7160 .show_host_speed
= 1,
7162 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
7163 .show_host_fabric_name
= 1,
7166 * The LPFC driver treats linkdown handling as target loss events
7167 * so there are no sysfs handlers for link_down_tmo.
7170 .get_fc_host_stats
= lpfc_get_stats
,
7171 .reset_fc_host_stats
= lpfc_reset_stats
,
7173 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
7174 .show_rport_maxframe_size
= 1,
7175 .show_rport_supported_classes
= 1,
7177 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
7178 .show_rport_dev_loss_tmo
= 1,
7180 .get_starget_port_id
= lpfc_get_starget_port_id
,
7181 .show_starget_port_id
= 1,
7183 .get_starget_node_name
= lpfc_get_starget_node_name
,
7184 .show_starget_node_name
= 1,
7186 .get_starget_port_name
= lpfc_get_starget_port_name
,
7187 .show_starget_port_name
= 1,
7189 .issue_fc_host_lip
= lpfc_issue_lip
,
7190 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
7191 .terminate_rport_io
= lpfc_terminate_rport_io
,
7193 .dd_fcvport_size
= sizeof(struct lpfc_vport
*),
7195 .vport_disable
= lpfc_vport_disable
,
7197 .set_vport_symbolic_name
= lpfc_set_vport_symbolic_name
,
7199 .bsg_request
= lpfc_bsg_request
,
7200 .bsg_timeout
= lpfc_bsg_timeout
,
7203 struct fc_function_template lpfc_vport_transport_functions
= {
7204 /* fixed attributes the driver supports */
7205 .show_host_node_name
= 1,
7206 .show_host_port_name
= 1,
7207 .show_host_supported_classes
= 1,
7208 .show_host_supported_fc4s
= 1,
7209 .show_host_supported_speeds
= 1,
7210 .show_host_maxframe_size
= 1,
7212 .get_host_symbolic_name
= lpfc_get_host_symbolic_name
,
7213 .show_host_symbolic_name
= 1,
7215 /* dynamic attributes the driver supports */
7216 .get_host_port_id
= lpfc_get_host_port_id
,
7217 .show_host_port_id
= 1,
7219 .get_host_port_type
= lpfc_get_host_port_type
,
7220 .show_host_port_type
= 1,
7222 .get_host_port_state
= lpfc_get_host_port_state
,
7223 .show_host_port_state
= 1,
7225 /* active_fc4s is shown but doesn't change (thus no get function) */
7226 .show_host_active_fc4s
= 1,
7228 .get_host_speed
= lpfc_get_host_speed
,
7229 .show_host_speed
= 1,
7231 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
7232 .show_host_fabric_name
= 1,
7235 * The LPFC driver treats linkdown handling as target loss events
7236 * so there are no sysfs handlers for link_down_tmo.
7239 .get_fc_host_stats
= lpfc_get_stats
,
7240 .reset_fc_host_stats
= lpfc_reset_stats
,
7242 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
7243 .show_rport_maxframe_size
= 1,
7244 .show_rport_supported_classes
= 1,
7246 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
7247 .show_rport_dev_loss_tmo
= 1,
7249 .get_starget_port_id
= lpfc_get_starget_port_id
,
7250 .show_starget_port_id
= 1,
7252 .get_starget_node_name
= lpfc_get_starget_node_name
,
7253 .show_starget_node_name
= 1,
7255 .get_starget_port_name
= lpfc_get_starget_port_name
,
7256 .show_starget_port_name
= 1,
7258 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
7259 .terminate_rport_io
= lpfc_terminate_rport_io
,
7261 .vport_disable
= lpfc_vport_disable
,
7263 .set_vport_symbolic_name
= lpfc_set_vport_symbolic_name
,
7267 * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7269 * @phba: lpfc_hba pointer.
7272 lpfc_get_hba_function_mode(struct lpfc_hba
*phba
)
7274 /* If the adapter supports FCoE mode */
7275 switch (phba
->pcidev
->device
) {
7276 case PCI_DEVICE_ID_SKYHAWK
:
7277 case PCI_DEVICE_ID_SKYHAWK_VF
:
7278 case PCI_DEVICE_ID_LANCER_FCOE
:
7279 case PCI_DEVICE_ID_LANCER_FCOE_VF
:
7280 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
7281 case PCI_DEVICE_ID_HORNET
:
7282 case PCI_DEVICE_ID_TIGERSHARK
:
7283 case PCI_DEVICE_ID_TOMCAT
:
7284 phba
->hba_flag
|= HBA_FCOE_MODE
;
7287 /* for others, clear the flag */
7288 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
7293 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7294 * @phba: lpfc_hba pointer.
7297 lpfc_get_cfgparam(struct lpfc_hba
*phba
)
7299 lpfc_hba_log_verbose_init(phba
, lpfc_log_verbose
);
7300 lpfc_fcp_io_sched_init(phba
, lpfc_fcp_io_sched
);
7301 lpfc_ns_query_init(phba
, lpfc_ns_query
);
7302 lpfc_fcp2_no_tgt_reset_init(phba
, lpfc_fcp2_no_tgt_reset
);
7303 lpfc_cr_delay_init(phba
, lpfc_cr_delay
);
7304 lpfc_cr_count_init(phba
, lpfc_cr_count
);
7305 lpfc_multi_ring_support_init(phba
, lpfc_multi_ring_support
);
7306 lpfc_multi_ring_rctl_init(phba
, lpfc_multi_ring_rctl
);
7307 lpfc_multi_ring_type_init(phba
, lpfc_multi_ring_type
);
7308 lpfc_ack0_init(phba
, lpfc_ack0
);
7309 lpfc_xri_rebalancing_init(phba
, lpfc_xri_rebalancing
);
7310 lpfc_topology_init(phba
, lpfc_topology
);
7311 lpfc_link_speed_init(phba
, lpfc_link_speed
);
7312 lpfc_poll_tmo_init(phba
, lpfc_poll_tmo
);
7313 lpfc_task_mgmt_tmo_init(phba
, lpfc_task_mgmt_tmo
);
7314 lpfc_enable_npiv_init(phba
, lpfc_enable_npiv
);
7315 lpfc_fcf_failover_policy_init(phba
, lpfc_fcf_failover_policy
);
7316 lpfc_enable_rrq_init(phba
, lpfc_enable_rrq
);
7317 lpfc_fdmi_on_init(phba
, lpfc_fdmi_on
);
7318 lpfc_enable_SmartSAN_init(phba
, lpfc_enable_SmartSAN
);
7319 lpfc_use_msi_init(phba
, lpfc_use_msi
);
7320 lpfc_nvme_oas_init(phba
, lpfc_nvme_oas
);
7321 lpfc_nvme_embed_cmd_init(phba
, lpfc_nvme_embed_cmd
);
7322 lpfc_fcp_imax_init(phba
, lpfc_fcp_imax
);
7323 lpfc_force_rscn_init(phba
, lpfc_force_rscn
);
7324 lpfc_cq_poll_threshold_init(phba
, lpfc_cq_poll_threshold
);
7325 lpfc_cq_max_proc_limit_init(phba
, lpfc_cq_max_proc_limit
);
7326 lpfc_fcp_cpu_map_init(phba
, lpfc_fcp_cpu_map
);
7327 lpfc_enable_hba_reset_init(phba
, lpfc_enable_hba_reset
);
7328 lpfc_enable_hba_heartbeat_init(phba
, lpfc_enable_hba_heartbeat
);
7330 lpfc_EnableXLane_init(phba
, lpfc_EnableXLane
);
7331 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
7332 phba
->cfg_EnableXLane
= 0;
7333 lpfc_XLanePriority_init(phba
, lpfc_XLanePriority
);
7335 memset(phba
->cfg_oas_tgt_wwpn
, 0, (8 * sizeof(uint8_t)));
7336 memset(phba
->cfg_oas_vpt_wwpn
, 0, (8 * sizeof(uint8_t)));
7337 phba
->cfg_oas_lun_state
= 0;
7338 phba
->cfg_oas_lun_status
= 0;
7339 phba
->cfg_oas_flags
= 0;
7340 phba
->cfg_oas_priority
= 0;
7341 lpfc_enable_bg_init(phba
, lpfc_enable_bg
);
7342 lpfc_prot_mask_init(phba
, lpfc_prot_mask
);
7343 lpfc_prot_guard_init(phba
, lpfc_prot_guard
);
7344 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7347 phba
->cfg_poll
= lpfc_poll
;
7349 /* Get the function mode */
7350 lpfc_get_hba_function_mode(phba
);
7352 /* BlockGuard allowed for FC only. */
7353 if (phba
->cfg_enable_bg
&& phba
->hba_flag
& HBA_FCOE_MODE
) {
7354 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7355 "0581 BlockGuard feature not supported\n");
7356 /* If set, clear the BlockGuard support param */
7357 phba
->cfg_enable_bg
= 0;
7358 } else if (phba
->cfg_enable_bg
) {
7359 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
7362 lpfc_suppress_rsp_init(phba
, lpfc_suppress_rsp
);
7364 lpfc_enable_fc4_type_init(phba
, lpfc_enable_fc4_type
);
7365 lpfc_nvmet_mrq_init(phba
, lpfc_nvmet_mrq
);
7366 lpfc_nvmet_mrq_post_init(phba
, lpfc_nvmet_mrq_post
);
7368 /* Initialize first burst. Target vs Initiator are different. */
7369 lpfc_nvme_enable_fb_init(phba
, lpfc_nvme_enable_fb
);
7370 lpfc_nvmet_fb_size_init(phba
, lpfc_nvmet_fb_size
);
7371 lpfc_fcp_mq_threshold_init(phba
, lpfc_fcp_mq_threshold
);
7372 lpfc_hdw_queue_init(phba
, lpfc_hdw_queue
);
7373 lpfc_irq_chann_init(phba
, lpfc_irq_chann
);
7374 lpfc_enable_bbcr_init(phba
, lpfc_enable_bbcr
);
7375 lpfc_enable_dpp_init(phba
, lpfc_enable_dpp
);
7376 lpfc_enable_mi_init(phba
, lpfc_enable_mi
);
7378 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
7379 /* NVME only supported on SLI4 */
7380 phba
->nvmet_support
= 0;
7381 phba
->cfg_nvmet_mrq
= 0;
7382 phba
->cfg_enable_fc4_type
= LPFC_ENABLE_FCP
;
7383 phba
->cfg_enable_bbcr
= 0;
7384 phba
->cfg_xri_rebalancing
= 0;
7386 /* We MUST have FCP support */
7387 if (!(phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
))
7388 phba
->cfg_enable_fc4_type
|= LPFC_ENABLE_FCP
;
7391 phba
->cfg_auto_imax
= (phba
->cfg_fcp_imax
) ? 0 : 1;
7393 phba
->cfg_enable_pbde
= 0;
7395 /* A value of 0 means use the number of CPUs found in the system */
7396 if (phba
->cfg_hdw_queue
== 0)
7397 phba
->cfg_hdw_queue
= phba
->sli4_hba
.num_present_cpu
;
7398 if (phba
->cfg_irq_chann
== 0)
7399 phba
->cfg_irq_chann
= phba
->sli4_hba
.num_present_cpu
;
7400 if (phba
->cfg_irq_chann
> phba
->cfg_hdw_queue
)
7401 phba
->cfg_irq_chann
= phba
->cfg_hdw_queue
;
7403 phba
->cfg_soft_wwnn
= 0L;
7404 phba
->cfg_soft_wwpn
= 0L;
7405 lpfc_sg_seg_cnt_init(phba
, lpfc_sg_seg_cnt
);
7406 lpfc_hba_queue_depth_init(phba
, lpfc_hba_queue_depth
);
7407 lpfc_aer_support_init(phba
, lpfc_aer_support
);
7408 lpfc_sriov_nr_virtfn_init(phba
, lpfc_sriov_nr_virtfn
);
7409 lpfc_request_firmware_upgrade_init(phba
, lpfc_req_fw_upgrade
);
7410 lpfc_suppress_link_up_init(phba
, lpfc_suppress_link_up
);
7411 lpfc_delay_discovery_init(phba
, lpfc_delay_discovery
);
7412 lpfc_sli_mode_init(phba
, lpfc_sli_mode
);
7413 lpfc_enable_mds_diags_init(phba
, lpfc_enable_mds_diags
);
7414 lpfc_ras_fwlog_buffsize_init(phba
, lpfc_ras_fwlog_buffsize
);
7415 lpfc_ras_fwlog_level_init(phba
, lpfc_ras_fwlog_level
);
7416 lpfc_ras_fwlog_func_init(phba
, lpfc_ras_fwlog_func
);
7422 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7423 * dependencies between protocols and roles.
7424 * @phba: lpfc_hba pointer.
7427 lpfc_nvme_mod_param_dep(struct lpfc_hba
*phba
)
7431 if (phba
->cfg_hdw_queue
> phba
->sli4_hba
.num_present_cpu
) {
7432 phba
->cfg_hdw_queue
= phba
->sli4_hba
.num_present_cpu
;
7435 if (phba
->cfg_irq_chann
> phba
->sli4_hba
.num_present_cpu
) {
7436 phba
->cfg_irq_chann
= phba
->sli4_hba
.num_present_cpu
;
7439 if (phba
->cfg_irq_chann
> phba
->cfg_hdw_queue
) {
7440 phba
->cfg_irq_chann
= phba
->cfg_hdw_queue
;
7444 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
7445 "2006 Reducing Queues - CPU limitation: "
7447 phba
->cfg_irq_chann
,
7448 phba
->cfg_hdw_queue
);
7450 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
&&
7451 phba
->nvmet_support
) {
7452 phba
->cfg_enable_fc4_type
&= ~LPFC_ENABLE_FCP
;
7454 lpfc_printf_log(phba
, KERN_INFO
, LOG_NVME_DISC
,
7455 "6013 %s x%x fb_size x%x, fb_max x%x\n",
7456 "NVME Target PRLI ACC enable_fb ",
7457 phba
->cfg_nvme_enable_fb
,
7458 phba
->cfg_nvmet_fb_size
,
7459 LPFC_NVMET_FB_SZ_MAX
);
7461 if (phba
->cfg_nvme_enable_fb
== 0)
7462 phba
->cfg_nvmet_fb_size
= 0;
7464 if (phba
->cfg_nvmet_fb_size
> LPFC_NVMET_FB_SZ_MAX
)
7465 phba
->cfg_nvmet_fb_size
= LPFC_NVMET_FB_SZ_MAX
;
7468 if (!phba
->cfg_nvmet_mrq
)
7469 phba
->cfg_nvmet_mrq
= phba
->cfg_hdw_queue
;
7471 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7472 if (phba
->cfg_nvmet_mrq
> phba
->cfg_hdw_queue
) {
7473 phba
->cfg_nvmet_mrq
= phba
->cfg_hdw_queue
;
7474 lpfc_printf_log(phba
, KERN_ERR
, LOG_NVME_DISC
,
7475 "6018 Adjust lpfc_nvmet_mrq to %d\n",
7476 phba
->cfg_nvmet_mrq
);
7478 if (phba
->cfg_nvmet_mrq
> LPFC_NVMET_MRQ_MAX
)
7479 phba
->cfg_nvmet_mrq
= LPFC_NVMET_MRQ_MAX
;
7482 /* Not NVME Target mode. Turn off Target parameters. */
7483 phba
->nvmet_support
= 0;
7484 phba
->cfg_nvmet_mrq
= 0;
7485 phba
->cfg_nvmet_fb_size
= 0;
7490 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7491 * @vport: lpfc_vport pointer.
7494 lpfc_get_vport_cfgparam(struct lpfc_vport
*vport
)
7496 lpfc_log_verbose_init(vport
, lpfc_log_verbose
);
7497 lpfc_lun_queue_depth_init(vport
, lpfc_lun_queue_depth
);
7498 lpfc_tgt_queue_depth_init(vport
, lpfc_tgt_queue_depth
);
7499 lpfc_devloss_tmo_init(vport
, lpfc_devloss_tmo
);
7500 lpfc_nodev_tmo_init(vport
, lpfc_nodev_tmo
);
7501 lpfc_peer_port_login_init(vport
, lpfc_peer_port_login
);
7502 lpfc_restrict_login_init(vport
, lpfc_restrict_login
);
7503 lpfc_fcp_class_init(vport
, lpfc_fcp_class
);
7504 lpfc_use_adisc_init(vport
, lpfc_use_adisc
);
7505 lpfc_first_burst_size_init(vport
, lpfc_first_burst_size
);
7506 lpfc_max_scsicmpl_time_init(vport
, lpfc_max_scsicmpl_time
);
7507 lpfc_discovery_threads_init(vport
, lpfc_discovery_threads
);
7508 lpfc_max_luns_init(vport
, lpfc_max_luns
);
7509 lpfc_scan_down_init(vport
, lpfc_scan_down
);
7510 lpfc_enable_da_id_init(vport
, lpfc_enable_da_id
);