xref: /linux/drivers/scsi/lpfc/lpfc_attr.c (revision 90e0d94d369d342e735a75174439482119b6c393)
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Fibre Channel Host Bus Adapters.                                *
4  * Copyright (C) 2017-2022 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.                        *
8  * www.broadcom.com                                                *
9  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
10  *                                                                 *
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  *******************************************************************/
23 
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>
32 
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>
39 
40 #include "lpfc_hw4.h"
41 #include "lpfc_hw.h"
42 #include "lpfc_sli.h"
43 #include "lpfc_sli4.h"
44 #include "lpfc_nl.h"
45 #include "lpfc_disc.h"
46 #include "lpfc.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"
55 
56 #define LPFC_DEF_DEVLOSS_TMO	30
57 #define LPFC_MIN_DEVLOSS_TMO	1
58 #define LPFC_MAX_DEVLOSS_TMO	255
59 
60 #define LPFC_MAX_INFO_TMP_LEN	100
61 #define LPFC_INFO_MORE_STR	"\nCould be more info...\n"
62 /*
63  * Write key size should be multiple of 4. If write key is changed
64  * make sure that library write key is also changed.
65  */
66 #define LPFC_REG_WRITE_KEY_SIZE	4
67 #define LPFC_REG_WRITE_KEY	"EMLX"
68 
69 const char *const trunk_errmsg[] = {	/* map errcode */
70 	"",	/* There is no such error code at index 0*/
71 	"link negotiated speed does not match existing"
72 		" trunk - link was \"low\" speed",
73 	"link negotiated speed does not match"
74 		" existing trunk - link was \"middle\" speed",
75 	"link negotiated speed does not match existing"
76 		" trunk - link was \"high\" speed",
77 	"Attached to non-trunking port - F_Port",
78 	"Attached to non-trunking port - N_Port",
79 	"FLOGI response timeout",
80 	"non-FLOGI frame received",
81 	"Invalid FLOGI response",
82 	"Trunking initialization protocol",
83 	"Trunk peer device mismatch",
84 };
85 
86 /**
87  * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
88  * @incr: integer to convert.
89  * @hdw: ascii string holding converted integer plus a string terminator.
90  *
91  * Description:
92  * JEDEC Joint Electron Device Engineering Council.
93  * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
94  * character string. The string is then terminated with a NULL in byte 9.
95  * Hex 0-9 becomes ascii '0' to '9'.
96  * Hex a-f becomes ascii '=' to 'B' capital B.
97  *
98  * Notes:
99  * Coded for 32 bit integers only.
100  **/
101 static void
102 lpfc_jedec_to_ascii(int incr, char hdw[])
103 {
104 	int i, j;
105 	for (i = 0; i < 8; i++) {
106 		j = (incr & 0xf);
107 		if (j <= 9)
108 			hdw[7 - i] = 0x30 +  j;
109 		 else
110 			hdw[7 - i] = 0x61 + j - 10;
111 		incr = (incr >> 4);
112 	}
113 	hdw[8] = 0;
114 	return;
115 }
116 
117 static ssize_t
118 lpfc_cmf_info_show(struct device *dev, struct device_attribute *attr,
119 		   char *buf)
120 {
121 	struct Scsi_Host  *shost = class_to_shost(dev);
122 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
123 	struct lpfc_hba   *phba = vport->phba;
124 	struct lpfc_cgn_info *cp = NULL;
125 	struct lpfc_cgn_stat *cgs;
126 	int  len = 0;
127 	int cpu;
128 	u64 rcv, total;
129 	char tmp[LPFC_MAX_INFO_TMP_LEN] = {0};
130 
131 	if (phba->cgn_i)
132 		cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
133 
134 	scnprintf(tmp, sizeof(tmp),
135 		  "Congestion Mgmt Info: E2Eattr %d Ver %d "
136 		  "CMF %d cnt %d\n",
137 		  phba->sli4_hba.pc_sli4_params.mi_ver,
138 		  cp ? cp->cgn_info_version : 0,
139 		  phba->sli4_hba.pc_sli4_params.cmf, phba->cmf_timer_cnt);
140 
141 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
142 		goto buffer_done;
143 
144 	if (!phba->sli4_hba.pc_sli4_params.cmf)
145 		goto buffer_done;
146 
147 	switch (phba->cgn_init_reg_signal) {
148 	case EDC_CG_SIG_WARN_ONLY:
149 		scnprintf(tmp, sizeof(tmp),
150 			  "Register: Init:  Signal:WARN  ");
151 		break;
152 	case EDC_CG_SIG_WARN_ALARM:
153 		scnprintf(tmp, sizeof(tmp),
154 			  "Register: Init:  Signal:WARN|ALARM  ");
155 		break;
156 	default:
157 		scnprintf(tmp, sizeof(tmp),
158 			  "Register: Init:  Signal:NONE  ");
159 		break;
160 	}
161 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
162 		goto buffer_done;
163 
164 	switch (phba->cgn_init_reg_fpin) {
165 	case LPFC_CGN_FPIN_WARN:
166 		scnprintf(tmp, sizeof(tmp),
167 			  "FPIN:WARN\n");
168 		break;
169 	case LPFC_CGN_FPIN_ALARM:
170 		scnprintf(tmp, sizeof(tmp),
171 			  "FPIN:ALARM\n");
172 		break;
173 	case LPFC_CGN_FPIN_BOTH:
174 		scnprintf(tmp, sizeof(tmp),
175 			  "FPIN:WARN|ALARM\n");
176 		break;
177 	default:
178 		scnprintf(tmp, sizeof(tmp),
179 			  "FPIN:NONE\n");
180 		break;
181 	}
182 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
183 		goto buffer_done;
184 
185 	switch (phba->cgn_reg_signal) {
186 	case EDC_CG_SIG_WARN_ONLY:
187 		scnprintf(tmp, sizeof(tmp),
188 			  "       Current:  Signal:WARN  ");
189 		break;
190 	case EDC_CG_SIG_WARN_ALARM:
191 		scnprintf(tmp, sizeof(tmp),
192 			  "       Current:  Signal:WARN|ALARM  ");
193 		break;
194 	default:
195 		scnprintf(tmp, sizeof(tmp),
196 			  "       Current:  Signal:NONE  ");
197 		break;
198 	}
199 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
200 		goto buffer_done;
201 
202 	switch (phba->cgn_reg_fpin) {
203 	case LPFC_CGN_FPIN_WARN:
204 		scnprintf(tmp, sizeof(tmp),
205 			  "FPIN:WARN  ACQEcnt:%d\n", phba->cgn_acqe_cnt);
206 		break;
207 	case LPFC_CGN_FPIN_ALARM:
208 		scnprintf(tmp, sizeof(tmp),
209 			  "FPIN:ALARM  ACQEcnt:%d\n", phba->cgn_acqe_cnt);
210 		break;
211 	case LPFC_CGN_FPIN_BOTH:
212 		scnprintf(tmp, sizeof(tmp),
213 			  "FPIN:WARN|ALARM  ACQEcnt:%d\n", phba->cgn_acqe_cnt);
214 		break;
215 	default:
216 		scnprintf(tmp, sizeof(tmp),
217 			  "FPIN:NONE  ACQEcnt:%d\n", phba->cgn_acqe_cnt);
218 		break;
219 	}
220 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
221 		goto buffer_done;
222 
223 	if (phba->cmf_active_mode != phba->cgn_p.cgn_param_mode) {
224 		switch (phba->cmf_active_mode) {
225 		case LPFC_CFG_OFF:
226 			scnprintf(tmp, sizeof(tmp), "Active: Mode:Off\n");
227 			break;
228 		case LPFC_CFG_MANAGED:
229 			scnprintf(tmp, sizeof(tmp), "Active: Mode:Managed\n");
230 			break;
231 		case LPFC_CFG_MONITOR:
232 			scnprintf(tmp, sizeof(tmp), "Active: Mode:Monitor\n");
233 			break;
234 		default:
235 			scnprintf(tmp, sizeof(tmp), "Active: Mode:Unknown\n");
236 		}
237 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
238 			goto buffer_done;
239 	}
240 
241 	switch (phba->cgn_p.cgn_param_mode) {
242 	case LPFC_CFG_OFF:
243 		scnprintf(tmp, sizeof(tmp), "Config: Mode:Off  ");
244 		break;
245 	case LPFC_CFG_MANAGED:
246 		scnprintf(tmp, sizeof(tmp), "Config: Mode:Managed ");
247 		break;
248 	case LPFC_CFG_MONITOR:
249 		scnprintf(tmp, sizeof(tmp), "Config: Mode:Monitor ");
250 		break;
251 	default:
252 		scnprintf(tmp, sizeof(tmp), "Config: Mode:Unknown ");
253 	}
254 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
255 		goto buffer_done;
256 
257 	total = 0;
258 	rcv = 0;
259 	for_each_present_cpu(cpu) {
260 		cgs = per_cpu_ptr(phba->cmf_stat, cpu);
261 		total += atomic64_read(&cgs->total_bytes);
262 		rcv += atomic64_read(&cgs->rcv_bytes);
263 	}
264 
265 	scnprintf(tmp, sizeof(tmp),
266 		  "IObusy:%d Info:%d Bytes: Rcv:x%llx Total:x%llx\n",
267 		  atomic_read(&phba->cmf_busy),
268 		  phba->cmf_active_info, rcv, total);
269 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
270 		goto buffer_done;
271 
272 	scnprintf(tmp, sizeof(tmp),
273 		  "Port_speed:%d  Link_byte_cnt:%ld  "
274 		  "Max_byte_per_interval:%ld\n",
275 		  lpfc_sli_port_speed_get(phba),
276 		  (unsigned long)phba->cmf_link_byte_count,
277 		  (unsigned long)phba->cmf_max_bytes_per_interval);
278 	strlcat(buf, tmp, PAGE_SIZE);
279 
280 buffer_done:
281 	len = strnlen(buf, PAGE_SIZE);
282 
283 	if (unlikely(len >= (PAGE_SIZE - 1))) {
284 		lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
285 				"6312 Catching potential buffer "
286 				"overflow > PAGE_SIZE = %lu bytes\n",
287 				PAGE_SIZE);
288 		strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),
289 			LPFC_INFO_MORE_STR, sizeof(LPFC_INFO_MORE_STR) + 1);
290 	}
291 	return len;
292 }
293 
294 /**
295  * lpfc_drvr_version_show - Return the Emulex driver string with version number
296  * @dev: class unused variable.
297  * @attr: device attribute, not used.
298  * @buf: on return contains the module description text.
299  *
300  * Returns: size of formatted string.
301  **/
302 static ssize_t
303 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
304 		       char *buf)
305 {
306 	return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
307 }
308 
309 /**
310  * lpfc_enable_fip_show - Return the fip mode of the HBA
311  * @dev: class unused variable.
312  * @attr: device attribute, not used.
313  * @buf: on return contains the module description text.
314  *
315  * Returns: size of formatted string.
316  **/
317 static ssize_t
318 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
319 		       char *buf)
320 {
321 	struct Scsi_Host *shost = class_to_shost(dev);
322 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
323 	struct lpfc_hba   *phba = vport->phba;
324 
325 	if (phba->hba_flag & HBA_FIP_SUPPORT)
326 		return scnprintf(buf, PAGE_SIZE, "1\n");
327 	else
328 		return scnprintf(buf, PAGE_SIZE, "0\n");
329 }
330 
331 static ssize_t
332 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
333 		    char *buf)
334 {
335 	struct Scsi_Host *shost = class_to_shost(dev);
336 	struct lpfc_vport *vport = shost_priv(shost);
337 	struct lpfc_hba   *phba = vport->phba;
338 	struct lpfc_nvmet_tgtport *tgtp;
339 	struct nvme_fc_local_port *localport;
340 	struct lpfc_nvme_lport *lport;
341 	struct lpfc_nvme_rport *rport;
342 	struct lpfc_nodelist *ndlp;
343 	struct nvme_fc_remote_port *nrport;
344 	struct lpfc_fc4_ctrl_stat *cstat;
345 	uint64_t data1, data2, data3;
346 	uint64_t totin, totout, tot;
347 	char *statep;
348 	int i;
349 	int len = 0;
350 	char tmp[LPFC_MAX_INFO_TMP_LEN] = {0};
351 
352 	if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
353 		len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
354 		return len;
355 	}
356 	if (phba->nvmet_support) {
357 		if (!phba->targetport) {
358 			len = scnprintf(buf, PAGE_SIZE,
359 					"NVME Target: x%llx is not allocated\n",
360 					wwn_to_u64(vport->fc_portname.u.wwn));
361 			return len;
362 		}
363 		/* Port state is only one of two values for now. */
364 		if (phba->targetport->port_id)
365 			statep = "REGISTERED";
366 		else
367 			statep = "INIT";
368 		scnprintf(tmp, sizeof(tmp),
369 			  "NVME Target Enabled  State %s\n",
370 			  statep);
371 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
372 			goto buffer_done;
373 
374 		scnprintf(tmp, sizeof(tmp),
375 			  "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
376 			  "NVME Target: lpfc",
377 			  phba->brd_no,
378 			  wwn_to_u64(vport->fc_portname.u.wwn),
379 			  wwn_to_u64(vport->fc_nodename.u.wwn),
380 			  phba->targetport->port_id);
381 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
382 			goto buffer_done;
383 
384 		if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
385 		    >= PAGE_SIZE)
386 			goto buffer_done;
387 
388 		tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
389 		scnprintf(tmp, sizeof(tmp),
390 			  "LS: Rcv %08x Drop %08x Abort %08x\n",
391 			  atomic_read(&tgtp->rcv_ls_req_in),
392 			  atomic_read(&tgtp->rcv_ls_req_drop),
393 			  atomic_read(&tgtp->xmt_ls_abort));
394 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
395 			goto buffer_done;
396 
397 		if (atomic_read(&tgtp->rcv_ls_req_in) !=
398 		    atomic_read(&tgtp->rcv_ls_req_out)) {
399 			scnprintf(tmp, sizeof(tmp),
400 				  "Rcv LS: in %08x != out %08x\n",
401 				  atomic_read(&tgtp->rcv_ls_req_in),
402 				  atomic_read(&tgtp->rcv_ls_req_out));
403 			if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
404 				goto buffer_done;
405 		}
406 
407 		scnprintf(tmp, sizeof(tmp),
408 			  "LS: Xmt %08x Drop %08x Cmpl %08x\n",
409 			  atomic_read(&tgtp->xmt_ls_rsp),
410 			  atomic_read(&tgtp->xmt_ls_drop),
411 			  atomic_read(&tgtp->xmt_ls_rsp_cmpl));
412 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
413 			goto buffer_done;
414 
415 		scnprintf(tmp, sizeof(tmp),
416 			  "LS: RSP Abort %08x xb %08x Err %08x\n",
417 			  atomic_read(&tgtp->xmt_ls_rsp_aborted),
418 			  atomic_read(&tgtp->xmt_ls_rsp_xb_set),
419 			  atomic_read(&tgtp->xmt_ls_rsp_error));
420 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
421 			goto buffer_done;
422 
423 		scnprintf(tmp, sizeof(tmp),
424 			  "FCP: Rcv %08x Defer %08x Release %08x "
425 			  "Drop %08x\n",
426 			  atomic_read(&tgtp->rcv_fcp_cmd_in),
427 			  atomic_read(&tgtp->rcv_fcp_cmd_defer),
428 			  atomic_read(&tgtp->xmt_fcp_release),
429 			  atomic_read(&tgtp->rcv_fcp_cmd_drop));
430 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
431 			goto buffer_done;
432 
433 		if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
434 		    atomic_read(&tgtp->rcv_fcp_cmd_out)) {
435 			scnprintf(tmp, sizeof(tmp),
436 				  "Rcv FCP: in %08x != out %08x\n",
437 				  atomic_read(&tgtp->rcv_fcp_cmd_in),
438 				  atomic_read(&tgtp->rcv_fcp_cmd_out));
439 			if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
440 				goto buffer_done;
441 		}
442 
443 		scnprintf(tmp, sizeof(tmp),
444 			  "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
445 			  "drop %08x\n",
446 			  atomic_read(&tgtp->xmt_fcp_read),
447 			  atomic_read(&tgtp->xmt_fcp_read_rsp),
448 			  atomic_read(&tgtp->xmt_fcp_write),
449 			  atomic_read(&tgtp->xmt_fcp_rsp),
450 			  atomic_read(&tgtp->xmt_fcp_drop));
451 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
452 			goto buffer_done;
453 
454 		scnprintf(tmp, sizeof(tmp),
455 			  "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
456 			  atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
457 			  atomic_read(&tgtp->xmt_fcp_rsp_error),
458 			  atomic_read(&tgtp->xmt_fcp_rsp_drop));
459 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
460 			goto buffer_done;
461 
462 		scnprintf(tmp, sizeof(tmp),
463 			  "FCP Rsp Abort: %08x xb %08x xricqe  %08x\n",
464 			  atomic_read(&tgtp->xmt_fcp_rsp_aborted),
465 			  atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
466 			  atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
467 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
468 			goto buffer_done;
469 
470 		scnprintf(tmp, sizeof(tmp),
471 			  "ABORT: Xmt %08x Cmpl %08x\n",
472 			  atomic_read(&tgtp->xmt_fcp_abort),
473 			  atomic_read(&tgtp->xmt_fcp_abort_cmpl));
474 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
475 			goto buffer_done;
476 
477 		scnprintf(tmp, sizeof(tmp),
478 			  "ABORT: Sol %08x  Usol %08x Err %08x Cmpl %08x\n",
479 			  atomic_read(&tgtp->xmt_abort_sol),
480 			  atomic_read(&tgtp->xmt_abort_unsol),
481 			  atomic_read(&tgtp->xmt_abort_rsp),
482 			  atomic_read(&tgtp->xmt_abort_rsp_error));
483 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
484 			goto buffer_done;
485 
486 		scnprintf(tmp, sizeof(tmp),
487 			  "DELAY: ctx %08x  fod %08x wqfull %08x\n",
488 			  atomic_read(&tgtp->defer_ctx),
489 			  atomic_read(&tgtp->defer_fod),
490 			  atomic_read(&tgtp->defer_wqfull));
491 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
492 			goto buffer_done;
493 
494 		/* Calculate outstanding IOs */
495 		tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
496 		tot += atomic_read(&tgtp->xmt_fcp_release);
497 		tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
498 
499 		scnprintf(tmp, sizeof(tmp),
500 			  "IO_CTX: %08x  WAIT: cur %08x tot %08x\n"
501 			  "CTX Outstanding %08llx\n\n",
502 			  phba->sli4_hba.nvmet_xri_cnt,
503 			  phba->sli4_hba.nvmet_io_wait_cnt,
504 			  phba->sli4_hba.nvmet_io_wait_total,
505 			  tot);
506 		strlcat(buf, tmp, PAGE_SIZE);
507 		goto buffer_done;
508 	}
509 
510 	localport = vport->localport;
511 	if (!localport) {
512 		len = scnprintf(buf, PAGE_SIZE,
513 				"NVME Initiator x%llx is not allocated\n",
514 				wwn_to_u64(vport->fc_portname.u.wwn));
515 		return len;
516 	}
517 	lport = (struct lpfc_nvme_lport *)localport->private;
518 	if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
519 		goto buffer_done;
520 
521 	scnprintf(tmp, sizeof(tmp),
522 		  "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
523 		  phba->brd_no,
524 		  phba->sli4_hba.max_cfg_param.max_xri,
525 		  phba->sli4_hba.io_xri_max,
526 		  lpfc_sli4_get_els_iocb_cnt(phba));
527 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
528 		goto buffer_done;
529 
530 	/* Port state is only one of two values for now. */
531 	if (localport->port_id)
532 		statep = "ONLINE";
533 	else
534 		statep = "UNKNOWN ";
535 
536 	scnprintf(tmp, sizeof(tmp),
537 		  "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
538 		  "NVME LPORT lpfc",
539 		  phba->brd_no,
540 		  wwn_to_u64(vport->fc_portname.u.wwn),
541 		  wwn_to_u64(vport->fc_nodename.u.wwn),
542 		  localport->port_id, statep);
543 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
544 		goto buffer_done;
545 
546 	spin_lock_irq(shost->host_lock);
547 
548 	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
549 		nrport = NULL;
550 		spin_lock(&ndlp->lock);
551 		rport = lpfc_ndlp_get_nrport(ndlp);
552 		if (rport)
553 			nrport = rport->remoteport;
554 		spin_unlock(&ndlp->lock);
555 		if (!nrport)
556 			continue;
557 
558 		/* Port state is only one of two values for now. */
559 		switch (nrport->port_state) {
560 		case FC_OBJSTATE_ONLINE:
561 			statep = "ONLINE";
562 			break;
563 		case FC_OBJSTATE_UNKNOWN:
564 			statep = "UNKNOWN ";
565 			break;
566 		default:
567 			statep = "UNSUPPORTED";
568 			break;
569 		}
570 
571 		/* Tab in to show lport ownership. */
572 		if (strlcat(buf, "NVME RPORT       ", PAGE_SIZE) >= PAGE_SIZE)
573 			goto unlock_buf_done;
574 		if (phba->brd_no >= 10) {
575 			if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
576 				goto unlock_buf_done;
577 		}
578 
579 		scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
580 			  nrport->port_name);
581 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
582 			goto unlock_buf_done;
583 
584 		scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
585 			  nrport->node_name);
586 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
587 			goto unlock_buf_done;
588 
589 		scnprintf(tmp, sizeof(tmp), "DID x%06x ",
590 			  nrport->port_id);
591 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
592 			goto unlock_buf_done;
593 
594 		/* An NVME rport can have multiple roles. */
595 		if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
596 			if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
597 				goto unlock_buf_done;
598 		}
599 		if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
600 			if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
601 				goto unlock_buf_done;
602 		}
603 		if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
604 			if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
605 				goto unlock_buf_done;
606 		}
607 		if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
608 					  FC_PORT_ROLE_NVME_TARGET |
609 					  FC_PORT_ROLE_NVME_DISCOVERY)) {
610 			scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
611 				  nrport->port_role);
612 			if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
613 				goto unlock_buf_done;
614 		}
615 
616 		scnprintf(tmp, sizeof(tmp), "%s\n", statep);
617 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
618 			goto unlock_buf_done;
619 	}
620 	spin_unlock_irq(shost->host_lock);
621 
622 	if (!lport)
623 		goto buffer_done;
624 
625 	if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
626 		goto buffer_done;
627 
628 	scnprintf(tmp, sizeof(tmp),
629 		  "LS: Xmt %010x Cmpl %010x Abort %08x\n",
630 		  atomic_read(&lport->fc4NvmeLsRequests),
631 		  atomic_read(&lport->fc4NvmeLsCmpls),
632 		  atomic_read(&lport->xmt_ls_abort));
633 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
634 		goto buffer_done;
635 
636 	scnprintf(tmp, sizeof(tmp),
637 		  "LS XMIT: Err %08x  CMPL: xb %08x Err %08x\n",
638 		  atomic_read(&lport->xmt_ls_err),
639 		  atomic_read(&lport->cmpl_ls_xb),
640 		  atomic_read(&lport->cmpl_ls_err));
641 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
642 		goto buffer_done;
643 
644 	totin = 0;
645 	totout = 0;
646 	for (i = 0; i < phba->cfg_hdw_queue; i++) {
647 		cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
648 		tot = cstat->io_cmpls;
649 		totin += tot;
650 		data1 = cstat->input_requests;
651 		data2 = cstat->output_requests;
652 		data3 = cstat->control_requests;
653 		totout += (data1 + data2 + data3);
654 	}
655 	scnprintf(tmp, sizeof(tmp),
656 		  "Total FCP Cmpl %016llx Issue %016llx "
657 		  "OutIO %016llx\n",
658 		  totin, totout, totout - totin);
659 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
660 		goto buffer_done;
661 
662 	scnprintf(tmp, sizeof(tmp),
663 		  "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
664 		  "wqerr %08x err %08x\n",
665 		  atomic_read(&lport->xmt_fcp_abort),
666 		  atomic_read(&lport->xmt_fcp_noxri),
667 		  atomic_read(&lport->xmt_fcp_bad_ndlp),
668 		  atomic_read(&lport->xmt_fcp_qdepth),
669 		  atomic_read(&lport->xmt_fcp_wqerr),
670 		  atomic_read(&lport->xmt_fcp_err));
671 	if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
672 		goto buffer_done;
673 
674 	scnprintf(tmp, sizeof(tmp),
675 		  "FCP CMPL: xb %08x Err %08x\n",
676 		  atomic_read(&lport->cmpl_fcp_xb),
677 		  atomic_read(&lport->cmpl_fcp_err));
678 	strlcat(buf, tmp, PAGE_SIZE);
679 
680 	/* host_lock is already unlocked. */
681 	goto buffer_done;
682 
683  unlock_buf_done:
684 	spin_unlock_irq(shost->host_lock);
685 
686  buffer_done:
687 	len = strnlen(buf, PAGE_SIZE);
688 
689 	if (unlikely(len >= (PAGE_SIZE - 1))) {
690 		lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
691 				"6314 Catching potential buffer "
692 				"overflow > PAGE_SIZE = %lu bytes\n",
693 				PAGE_SIZE);
694 		strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),
695 			LPFC_INFO_MORE_STR,
696 			sizeof(LPFC_INFO_MORE_STR) + 1);
697 	}
698 
699 	return len;
700 }
701 
702 static ssize_t
703 lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
704 		    char *buf)
705 {
706 	struct Scsi_Host *shost = class_to_shost(dev);
707 	struct lpfc_vport *vport = shost_priv(shost);
708 	struct lpfc_hba *phba = vport->phba;
709 	int len;
710 	struct lpfc_fc4_ctrl_stat *cstat;
711 	u64 data1, data2, data3;
712 	u64 tot, totin, totout;
713 	int i;
714 	char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
715 
716 	if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
717 	    (phba->sli_rev != LPFC_SLI_REV4))
718 		return 0;
719 
720 	scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
721 
722 	totin = 0;
723 	totout = 0;
724 	for (i = 0; i < phba->cfg_hdw_queue; i++) {
725 		cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
726 		tot = cstat->io_cmpls;
727 		totin += tot;
728 		data1 = cstat->input_requests;
729 		data2 = cstat->output_requests;
730 		data3 = cstat->control_requests;
731 		totout += (data1 + data2 + data3);
732 
733 		scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
734 			  "IO %016llx ", i, data1, data2, data3);
735 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
736 			goto buffer_done;
737 
738 		scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
739 			  tot, ((data1 + data2 + data3) - tot));
740 		if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
741 			goto buffer_done;
742 	}
743 	scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
744 		  "OutIO %016llx\n", totin, totout, totout - totin);
745 	strlcat(buf, tmp, PAGE_SIZE);
746 
747 buffer_done:
748 	len = strnlen(buf, PAGE_SIZE);
749 
750 	return len;
751 }
752 
753 static ssize_t
754 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
755 		  char *buf)
756 {
757 	struct Scsi_Host *shost = class_to_shost(dev);
758 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
759 	struct lpfc_hba   *phba = vport->phba;
760 
761 	if (phba->cfg_enable_bg) {
762 		if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
763 			return scnprintf(buf, PAGE_SIZE,
764 					"BlockGuard Enabled\n");
765 		else
766 			return scnprintf(buf, PAGE_SIZE,
767 					"BlockGuard Not Supported\n");
768 	} else
769 		return scnprintf(buf, PAGE_SIZE,
770 					"BlockGuard Disabled\n");
771 }
772 
773 static ssize_t
774 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
775 		       char *buf)
776 {
777 	struct Scsi_Host *shost = class_to_shost(dev);
778 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
779 	struct lpfc_hba   *phba = vport->phba;
780 
781 	return scnprintf(buf, PAGE_SIZE, "%llu\n",
782 			(unsigned long long)phba->bg_guard_err_cnt);
783 }
784 
785 static ssize_t
786 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
787 			char *buf)
788 {
789 	struct Scsi_Host *shost = class_to_shost(dev);
790 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
791 	struct lpfc_hba   *phba = vport->phba;
792 
793 	return scnprintf(buf, PAGE_SIZE, "%llu\n",
794 			(unsigned long long)phba->bg_apptag_err_cnt);
795 }
796 
797 static ssize_t
798 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
799 			char *buf)
800 {
801 	struct Scsi_Host *shost = class_to_shost(dev);
802 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
803 	struct lpfc_hba   *phba = vport->phba;
804 
805 	return scnprintf(buf, PAGE_SIZE, "%llu\n",
806 			(unsigned long long)phba->bg_reftag_err_cnt);
807 }
808 
809 /**
810  * lpfc_info_show - Return some pci info about the host in ascii
811  * @dev: class converted to a Scsi_host structure.
812  * @attr: device attribute, not used.
813  * @buf: on return contains the formatted text from lpfc_info().
814  *
815  * Returns: size of formatted string.
816  **/
817 static ssize_t
818 lpfc_info_show(struct device *dev, struct device_attribute *attr,
819 	       char *buf)
820 {
821 	struct Scsi_Host *host = class_to_shost(dev);
822 
823 	return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
824 }
825 
826 /**
827  * lpfc_serialnum_show - Return the hba serial number in ascii
828  * @dev: class converted to a Scsi_host structure.
829  * @attr: device attribute, not used.
830  * @buf: on return contains the formatted text serial number.
831  *
832  * Returns: size of formatted string.
833  **/
834 static ssize_t
835 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
836 		    char *buf)
837 {
838 	struct Scsi_Host  *shost = class_to_shost(dev);
839 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
840 	struct lpfc_hba   *phba = vport->phba;
841 
842 	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
843 }
844 
845 /**
846  * lpfc_temp_sensor_show - Return the temperature sensor level
847  * @dev: class converted to a Scsi_host structure.
848  * @attr: device attribute, not used.
849  * @buf: on return contains the formatted support level.
850  *
851  * Description:
852  * Returns a number indicating the temperature sensor level currently
853  * supported, zero or one in ascii.
854  *
855  * Returns: size of formatted string.
856  **/
857 static ssize_t
858 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
859 		      char *buf)
860 {
861 	struct Scsi_Host *shost = class_to_shost(dev);
862 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
863 	struct lpfc_hba   *phba = vport->phba;
864 	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
865 }
866 
867 /**
868  * lpfc_modeldesc_show - Return the model description of the hba
869  * @dev: class converted to a Scsi_host structure.
870  * @attr: device attribute, not used.
871  * @buf: on return contains the scsi vpd model description.
872  *
873  * Returns: size of formatted string.
874  **/
875 static ssize_t
876 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
877 		    char *buf)
878 {
879 	struct Scsi_Host  *shost = class_to_shost(dev);
880 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
881 	struct lpfc_hba   *phba = vport->phba;
882 
883 	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
884 }
885 
886 /**
887  * lpfc_modelname_show - Return the model name of the hba
888  * @dev: class converted to a Scsi_host structure.
889  * @attr: device attribute, not used.
890  * @buf: on return contains the scsi vpd model name.
891  *
892  * Returns: size of formatted string.
893  **/
894 static ssize_t
895 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
896 		    char *buf)
897 {
898 	struct Scsi_Host  *shost = class_to_shost(dev);
899 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
900 	struct lpfc_hba   *phba = vport->phba;
901 
902 	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
903 }
904 
905 /**
906  * lpfc_programtype_show - Return the program type of the hba
907  * @dev: class converted to a Scsi_host structure.
908  * @attr: device attribute, not used.
909  * @buf: on return contains the scsi vpd program type.
910  *
911  * Returns: size of formatted string.
912  **/
913 static ssize_t
914 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
915 		      char *buf)
916 {
917 	struct Scsi_Host  *shost = class_to_shost(dev);
918 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
919 	struct lpfc_hba   *phba = vport->phba;
920 
921 	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
922 }
923 
924 /**
925  * lpfc_vportnum_show - Return the port number in ascii of the hba
926  * @dev: class converted to a Scsi_host structure.
927  * @attr: device attribute, not used.
928  * @buf: on return contains scsi vpd program type.
929  *
930  * Returns: size of formatted string.
931  **/
932 static ssize_t
933 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
934 		   char *buf)
935 {
936 	struct Scsi_Host  *shost = class_to_shost(dev);
937 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
938 	struct lpfc_hba   *phba = vport->phba;
939 
940 	return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
941 }
942 
943 /**
944  * lpfc_fwrev_show - Return the firmware rev running in the hba
945  * @dev: class converted to a Scsi_host structure.
946  * @attr: device attribute, not used.
947  * @buf: on return contains the scsi vpd program type.
948  *
949  * Returns: size of formatted string.
950  **/
951 static ssize_t
952 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
953 		char *buf)
954 {
955 	struct Scsi_Host  *shost = class_to_shost(dev);
956 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
957 	struct lpfc_hba   *phba = vport->phba;
958 	uint32_t if_type;
959 	uint8_t sli_family;
960 	char fwrev[FW_REV_STR_SIZE];
961 	int len;
962 
963 	lpfc_decode_firmware_rev(phba, fwrev, 1);
964 	if_type = phba->sli4_hba.pc_sli4_params.if_type;
965 	sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
966 
967 	if (phba->sli_rev < LPFC_SLI_REV4)
968 		len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
969 			       fwrev, phba->sli_rev);
970 	else
971 		len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
972 			       fwrev, phba->sli_rev, if_type, sli_family);
973 
974 	return len;
975 }
976 
977 /**
978  * lpfc_hdw_show - Return the jedec information about the hba
979  * @dev: class converted to a Scsi_host structure.
980  * @attr: device attribute, not used.
981  * @buf: on return contains the scsi vpd program type.
982  *
983  * Returns: size of formatted string.
984  **/
985 static ssize_t
986 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
987 {
988 	char hdw[9];
989 	struct Scsi_Host  *shost = class_to_shost(dev);
990 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
991 	struct lpfc_hba   *phba = vport->phba;
992 	lpfc_vpd_t *vp = &phba->vpd;
993 
994 	lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
995 	return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
996 			 vp->rev.smRev, vp->rev.smFwRev);
997 }
998 
999 /**
1000  * lpfc_option_rom_version_show - Return the adapter ROM FCode version
1001  * @dev: class converted to a Scsi_host structure.
1002  * @attr: device attribute, not used.
1003  * @buf: on return contains the ROM and FCode ascii strings.
1004  *
1005  * Returns: size of formatted string.
1006  **/
1007 static ssize_t
1008 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
1009 			     char *buf)
1010 {
1011 	struct Scsi_Host  *shost = class_to_shost(dev);
1012 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1013 	struct lpfc_hba   *phba = vport->phba;
1014 	char fwrev[FW_REV_STR_SIZE];
1015 
1016 	if (phba->sli_rev < LPFC_SLI_REV4)
1017 		return scnprintf(buf, PAGE_SIZE, "%s\n",
1018 				phba->OptionROMVersion);
1019 
1020 	lpfc_decode_firmware_rev(phba, fwrev, 1);
1021 	return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
1022 }
1023 
1024 /**
1025  * lpfc_link_state_show - Return the link state of the port
1026  * @dev: class converted to a Scsi_host structure.
1027  * @attr: device attribute, not used.
1028  * @buf: on return contains text describing the state of the link.
1029  *
1030  * Notes:
1031  * The switch statement has no default so zero will be returned.
1032  *
1033  * Returns: size of formatted string.
1034  **/
1035 static ssize_t
1036 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
1037 		     char *buf)
1038 {
1039 	struct Scsi_Host  *shost = class_to_shost(dev);
1040 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1041 	struct lpfc_hba   *phba = vport->phba;
1042 	int  len = 0;
1043 
1044 	switch (phba->link_state) {
1045 	case LPFC_LINK_UNKNOWN:
1046 	case LPFC_WARM_START:
1047 	case LPFC_INIT_START:
1048 	case LPFC_INIT_MBX_CMDS:
1049 	case LPFC_LINK_DOWN:
1050 	case LPFC_HBA_ERROR:
1051 		if (phba->hba_flag & LINK_DISABLED)
1052 			len += scnprintf(buf + len, PAGE_SIZE-len,
1053 				"Link Down - User disabled\n");
1054 		else
1055 			len += scnprintf(buf + len, PAGE_SIZE-len,
1056 				"Link Down\n");
1057 		break;
1058 	case LPFC_LINK_UP:
1059 	case LPFC_CLEAR_LA:
1060 	case LPFC_HBA_READY:
1061 		len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
1062 
1063 		switch (vport->port_state) {
1064 		case LPFC_LOCAL_CFG_LINK:
1065 			len += scnprintf(buf + len, PAGE_SIZE-len,
1066 					"Configuring Link\n");
1067 			break;
1068 		case LPFC_FDISC:
1069 		case LPFC_FLOGI:
1070 		case LPFC_FABRIC_CFG_LINK:
1071 		case LPFC_NS_REG:
1072 		case LPFC_NS_QRY:
1073 		case LPFC_BUILD_DISC_LIST:
1074 		case LPFC_DISC_AUTH:
1075 			len += scnprintf(buf + len, PAGE_SIZE - len,
1076 					"Discovery\n");
1077 			break;
1078 		case LPFC_VPORT_READY:
1079 			len += scnprintf(buf + len, PAGE_SIZE - len,
1080 					"Ready\n");
1081 			break;
1082 
1083 		case LPFC_VPORT_FAILED:
1084 			len += scnprintf(buf + len, PAGE_SIZE - len,
1085 					"Failed\n");
1086 			break;
1087 
1088 		case LPFC_VPORT_UNKNOWN:
1089 			len += scnprintf(buf + len, PAGE_SIZE - len,
1090 					"Unknown\n");
1091 			break;
1092 		}
1093 		if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1094 			if (vport->fc_flag & FC_PUBLIC_LOOP)
1095 				len += scnprintf(buf + len, PAGE_SIZE-len,
1096 						"   Public Loop\n");
1097 			else
1098 				len += scnprintf(buf + len, PAGE_SIZE-len,
1099 						"   Private Loop\n");
1100 		} else {
1101 			if (vport->fc_flag & FC_FABRIC) {
1102 				if (phba->sli_rev == LPFC_SLI_REV4 &&
1103 				    vport->port_type == LPFC_PHYSICAL_PORT &&
1104 				    phba->sli4_hba.fawwpn_flag &
1105 					LPFC_FAWWPN_FABRIC)
1106 					len += scnprintf(buf + len,
1107 							 PAGE_SIZE - len,
1108 							 "   Fabric FA-PWWN\n");
1109 				else
1110 					len += scnprintf(buf + len,
1111 							 PAGE_SIZE - len,
1112 							 "   Fabric\n");
1113 			} else {
1114 				len += scnprintf(buf + len, PAGE_SIZE-len,
1115 						"   Point-2-Point\n");
1116 			}
1117 		}
1118 	}
1119 
1120 	if ((phba->sli_rev == LPFC_SLI_REV4) &&
1121 	    ((bf_get(lpfc_sli_intf_if_type,
1122 	     &phba->sli4_hba.sli_intf) ==
1123 	     LPFC_SLI_INTF_IF_TYPE_6))) {
1124 		struct lpfc_trunk_link link = phba->trunk_link;
1125 
1126 		if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
1127 			len += scnprintf(buf + len, PAGE_SIZE - len,
1128 				"Trunk port 0: Link %s %s\n",
1129 				(link.link0.state == LPFC_LINK_UP) ?
1130 				 "Up" : "Down. ",
1131 				trunk_errmsg[link.link0.fault]);
1132 
1133 		if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
1134 			len += scnprintf(buf + len, PAGE_SIZE - len,
1135 				"Trunk port 1: Link %s %s\n",
1136 				(link.link1.state == LPFC_LINK_UP) ?
1137 				 "Up" : "Down. ",
1138 				trunk_errmsg[link.link1.fault]);
1139 
1140 		if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
1141 			len += scnprintf(buf + len, PAGE_SIZE - len,
1142 				"Trunk port 2: Link %s %s\n",
1143 				(link.link2.state == LPFC_LINK_UP) ?
1144 				 "Up" : "Down. ",
1145 				trunk_errmsg[link.link2.fault]);
1146 
1147 		if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
1148 			len += scnprintf(buf + len, PAGE_SIZE - len,
1149 				"Trunk port 3: Link %s %s\n",
1150 				(link.link3.state == LPFC_LINK_UP) ?
1151 				 "Up" : "Down. ",
1152 				trunk_errmsg[link.link3.fault]);
1153 
1154 	}
1155 
1156 	return len;
1157 }
1158 
1159 /**
1160  * lpfc_sli4_protocol_show - Return the fip mode of the HBA
1161  * @dev: class unused variable.
1162  * @attr: device attribute, not used.
1163  * @buf: on return contains the module description text.
1164  *
1165  * Returns: size of formatted string.
1166  **/
1167 static ssize_t
1168 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
1169 			char *buf)
1170 {
1171 	struct Scsi_Host *shost = class_to_shost(dev);
1172 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1173 	struct lpfc_hba *phba = vport->phba;
1174 
1175 	if (phba->sli_rev < LPFC_SLI_REV4)
1176 		return scnprintf(buf, PAGE_SIZE, "fc\n");
1177 
1178 	if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
1179 		if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
1180 			return scnprintf(buf, PAGE_SIZE, "fcoe\n");
1181 		if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
1182 			return scnprintf(buf, PAGE_SIZE, "fc\n");
1183 	}
1184 	return scnprintf(buf, PAGE_SIZE, "unknown\n");
1185 }
1186 
1187 /**
1188  * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
1189  *			    (OAS) is supported.
1190  * @dev: class unused variable.
1191  * @attr: device attribute, not used.
1192  * @buf: on return contains the module description text.
1193  *
1194  * Returns: size of formatted string.
1195  **/
1196 static ssize_t
1197 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1198 			char *buf)
1199 {
1200 	struct Scsi_Host *shost = class_to_shost(dev);
1201 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1202 	struct lpfc_hba *phba = vport->phba;
1203 
1204 	return scnprintf(buf, PAGE_SIZE, "%d\n",
1205 			phba->sli4_hba.pc_sli4_params.oas_supported);
1206 }
1207 
1208 /**
1209  * lpfc_link_state_store - Transition the link_state on an HBA port
1210  * @dev: class device that is converted into a Scsi_host.
1211  * @attr: device attribute, not used.
1212  * @buf: one or more lpfc_polling_flags values.
1213  * @count: not used.
1214  *
1215  * Returns:
1216  * -EINVAL if the buffer is not "up" or "down"
1217  * return from link state change function if non-zero
1218  * length of the buf on success
1219  **/
1220 static ssize_t
1221 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1222 		const char *buf, size_t count)
1223 {
1224 	struct Scsi_Host  *shost = class_to_shost(dev);
1225 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1226 	struct lpfc_hba   *phba = vport->phba;
1227 
1228 	int status = -EINVAL;
1229 
1230 	if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1231 			(phba->link_state == LPFC_LINK_DOWN))
1232 		status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
1233 	else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1234 			(phba->link_state >= LPFC_LINK_UP))
1235 		status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1236 
1237 	if (status == 0)
1238 		return strlen(buf);
1239 	else
1240 		return status;
1241 }
1242 
1243 /**
1244  * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
1245  * @dev: class device that is converted into a Scsi_host.
1246  * @attr: device attribute, not used.
1247  * @buf: on return contains the sum of fc mapped and unmapped.
1248  *
1249  * Description:
1250  * Returns the ascii text number of the sum of the fc mapped and unmapped
1251  * vport counts.
1252  *
1253  * Returns: size of formatted string.
1254  **/
1255 static ssize_t
1256 lpfc_num_discovered_ports_show(struct device *dev,
1257 			       struct device_attribute *attr, char *buf)
1258 {
1259 	struct Scsi_Host  *shost = class_to_shost(dev);
1260 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1261 
1262 	return scnprintf(buf, PAGE_SIZE, "%d\n",
1263 			vport->fc_map_cnt + vport->fc_unmap_cnt);
1264 }
1265 
1266 /**
1267  * lpfc_issue_lip - Misnomer, name carried over from long ago
1268  * @shost: Scsi_Host pointer.
1269  *
1270  * Description:
1271  * Bring the link down gracefully then re-init the link. The firmware will
1272  * re-init the fiber channel interface as required. Does not issue a LIP.
1273  *
1274  * Returns:
1275  * -EPERM port offline or management commands are being blocked
1276  * -ENOMEM cannot allocate memory for the mailbox command
1277  * -EIO error sending the mailbox command
1278  * zero for success
1279  **/
1280 static int
1281 lpfc_issue_lip(struct Scsi_Host *shost)
1282 {
1283 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1284 	struct lpfc_hba   *phba = vport->phba;
1285 	LPFC_MBOXQ_t *pmboxq;
1286 	int mbxstatus = MBXERR_ERROR;
1287 
1288 	/*
1289 	 * If the link is offline, disabled or BLOCK_MGMT_IO
1290 	 * it doesn't make any sense to allow issue_lip
1291 	 */
1292 	if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1293 	    (phba->hba_flag & LINK_DISABLED) ||
1294 	    (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1295 		return -EPERM;
1296 
1297 	pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1298 
1299 	if (!pmboxq)
1300 		return -ENOMEM;
1301 
1302 	memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1303 	pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1304 	pmboxq->u.mb.mbxOwner = OWN_HOST;
1305 
1306 	if ((vport->fc_flag & FC_PT2PT) && (vport->fc_flag & FC_PT2PT_NO_NVME))
1307 		vport->fc_flag &= ~FC_PT2PT_NO_NVME;
1308 
1309 	mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1310 
1311 	if ((mbxstatus == MBX_SUCCESS) &&
1312 	    (pmboxq->u.mb.mbxStatus == 0 ||
1313 	     pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1314 		memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1315 		lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1316 			       phba->cfg_link_speed);
1317 		mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1318 						     phba->fc_ratov * 2);
1319 		if ((mbxstatus == MBX_SUCCESS) &&
1320 		    (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1321 			lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1322 					"2859 SLI authentication is required "
1323 					"for INIT_LINK but has not done yet\n");
1324 	}
1325 
1326 	lpfc_set_loopback_flag(phba);
1327 	if (mbxstatus != MBX_TIMEOUT)
1328 		mempool_free(pmboxq, phba->mbox_mem_pool);
1329 
1330 	if (mbxstatus == MBXERR_ERROR)
1331 		return -EIO;
1332 
1333 	return 0;
1334 }
1335 
1336 int
1337 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1338 {
1339 	int cnt = 0;
1340 
1341 	spin_lock_irq(lock);
1342 	while (!list_empty(q)) {
1343 		spin_unlock_irq(lock);
1344 		msleep(20);
1345 		if (cnt++ > 250) {  /* 5 secs */
1346 			lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1347 					"0466 Outstanding IO when "
1348 					"bringing Adapter offline\n");
1349 				return 0;
1350 		}
1351 		spin_lock_irq(lock);
1352 	}
1353 	spin_unlock_irq(lock);
1354 	return 1;
1355 }
1356 
1357 /**
1358  * lpfc_do_offline - Issues a mailbox command to bring the link down
1359  * @phba: lpfc_hba pointer.
1360  * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
1361  *
1362  * Notes:
1363  * Assumes any error from lpfc_do_offline() will be negative.
1364  * Can wait up to 5 seconds for the port ring buffers count
1365  * to reach zero, prints a warning if it is not zero and continues.
1366  * lpfc_workq_post_event() returns a non-zero return code if call fails.
1367  *
1368  * Returns:
1369  * -EIO error posting the event
1370  * zero for success
1371  **/
1372 static int
1373 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1374 {
1375 	struct completion online_compl;
1376 	struct lpfc_queue *qp = NULL;
1377 	struct lpfc_sli_ring *pring;
1378 	struct lpfc_sli *psli;
1379 	int status = 0;
1380 	int i;
1381 	int rc;
1382 
1383 	init_completion(&online_compl);
1384 	rc = lpfc_workq_post_event(phba, &status, &online_compl,
1385 			      LPFC_EVT_OFFLINE_PREP);
1386 	if (rc == 0)
1387 		return -ENOMEM;
1388 
1389 	wait_for_completion(&online_compl);
1390 
1391 	if (status != 0)
1392 		return -EIO;
1393 
1394 	psli = &phba->sli;
1395 
1396 	/*
1397 	 * If freeing the queues have already started, don't access them.
1398 	 * Otherwise set FREE_WAIT to indicate that queues are being used
1399 	 * to hold the freeing process until we finish.
1400 	 */
1401 	spin_lock_irq(&phba->hbalock);
1402 	if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {
1403 		psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;
1404 	} else {
1405 		spin_unlock_irq(&phba->hbalock);
1406 		goto skip_wait;
1407 	}
1408 	spin_unlock_irq(&phba->hbalock);
1409 
1410 	/* Wait a little for things to settle down, but not
1411 	 * long enough for dev loss timeout to expire.
1412 	 */
1413 	if (phba->sli_rev != LPFC_SLI_REV4) {
1414 		for (i = 0; i < psli->num_rings; i++) {
1415 			pring = &psli->sli3_ring[i];
1416 			if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1417 					      &phba->hbalock))
1418 				goto out;
1419 		}
1420 	} else {
1421 		list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1422 			pring = qp->pring;
1423 			if (!pring)
1424 				continue;
1425 			if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1426 					      &pring->ring_lock))
1427 				goto out;
1428 		}
1429 	}
1430 out:
1431 	spin_lock_irq(&phba->hbalock);
1432 	psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;
1433 	spin_unlock_irq(&phba->hbalock);
1434 
1435 skip_wait:
1436 	init_completion(&online_compl);
1437 	rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1438 	if (rc == 0)
1439 		return -ENOMEM;
1440 
1441 	wait_for_completion(&online_compl);
1442 
1443 	if (status != 0)
1444 		return -EIO;
1445 
1446 	return 0;
1447 }
1448 
1449 /**
1450  * lpfc_reset_pci_bus - resets PCI bridge controller's secondary bus of an HBA
1451  * @phba: lpfc_hba pointer.
1452  *
1453  * Description:
1454  * Issues a PCI secondary bus reset for the phba->pcidev.
1455  *
1456  * Notes:
1457  * First walks the bus_list to ensure only PCI devices with Emulex
1458  * vendor id, device ids that support hot reset, only one occurrence
1459  * of function 0, and all ports on the bus are in offline mode to ensure the
1460  * hot reset only affects one valid HBA.
1461  *
1462  * Returns:
1463  * -ENOTSUPP, cfg_enable_hba_reset must be of value 2
1464  * -ENODEV,   NULL ptr to pcidev
1465  * -EBADSLT,  detected invalid device
1466  * -EBUSY,    port is not in offline state
1467  *      0,    successful
1468  */
1469 static int
1470 lpfc_reset_pci_bus(struct lpfc_hba *phba)
1471 {
1472 	struct pci_dev *pdev = phba->pcidev;
1473 	struct Scsi_Host *shost = NULL;
1474 	struct lpfc_hba *phba_other = NULL;
1475 	struct pci_dev *ptr = NULL;
1476 	int res;
1477 
1478 	if (phba->cfg_enable_hba_reset != 2)
1479 		return -ENOTSUPP;
1480 
1481 	if (!pdev) {
1482 		lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1483 		return -ENODEV;
1484 	}
1485 
1486 	res = lpfc_check_pci_resettable(phba);
1487 	if (res)
1488 		return res;
1489 
1490 	/* Walk the list of devices on the pci_dev's bus */
1491 	list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1492 		/* Check port is offline */
1493 		shost = pci_get_drvdata(ptr);
1494 		if (shost) {
1495 			phba_other =
1496 				((struct lpfc_vport *)shost->hostdata)->phba;
1497 			if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1498 				lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1499 						"8349 WWPN = 0x%02x%02x%02x%02x"
1500 						"%02x%02x%02x%02x is not "
1501 						"offline!\n",
1502 						phba_other->wwpn[0],
1503 						phba_other->wwpn[1],
1504 						phba_other->wwpn[2],
1505 						phba_other->wwpn[3],
1506 						phba_other->wwpn[4],
1507 						phba_other->wwpn[5],
1508 						phba_other->wwpn[6],
1509 						phba_other->wwpn[7]);
1510 				return -EBUSY;
1511 			}
1512 		}
1513 	}
1514 
1515 	/* Issue PCI bus reset */
1516 	res = pci_reset_bus(pdev);
1517 	if (res) {
1518 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1519 				"8350 PCI reset bus failed: %d\n", res);
1520 	}
1521 
1522 	return res;
1523 }
1524 
1525 /**
1526  * lpfc_selective_reset - Offline then onlines the port
1527  * @phba: lpfc_hba pointer.
1528  *
1529  * Description:
1530  * If the port is configured to allow a reset then the hba is brought
1531  * offline then online.
1532  *
1533  * Notes:
1534  * Assumes any error from lpfc_do_offline() will be negative.
1535  * Do not make this function static.
1536  *
1537  * Returns:
1538  * lpfc_do_offline() return code if not zero
1539  * -EIO reset not configured or error posting the event
1540  * zero for success
1541  **/
1542 int
1543 lpfc_selective_reset(struct lpfc_hba *phba)
1544 {
1545 	struct completion online_compl;
1546 	int status = 0;
1547 	int rc;
1548 
1549 	if (!phba->cfg_enable_hba_reset)
1550 		return -EACCES;
1551 
1552 	if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1553 		status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1554 
1555 		if (status != 0)
1556 			return status;
1557 	}
1558 
1559 	init_completion(&online_compl);
1560 	rc = lpfc_workq_post_event(phba, &status, &online_compl,
1561 			      LPFC_EVT_ONLINE);
1562 	if (rc == 0)
1563 		return -ENOMEM;
1564 
1565 	wait_for_completion(&online_compl);
1566 
1567 	if (status != 0)
1568 		return -EIO;
1569 
1570 	return 0;
1571 }
1572 
1573 /**
1574  * lpfc_issue_reset - Selectively resets an adapter
1575  * @dev: class device that is converted into a Scsi_host.
1576  * @attr: device attribute, not used.
1577  * @buf: containing the string "selective".
1578  * @count: unused variable.
1579  *
1580  * Description:
1581  * If the buf contains the string "selective" then lpfc_selective_reset()
1582  * is called to perform the reset.
1583  *
1584  * Notes:
1585  * Assumes any error from lpfc_selective_reset() will be negative.
1586  * If lpfc_selective_reset() returns zero then the length of the buffer
1587  * is returned which indicates success
1588  *
1589  * Returns:
1590  * -EINVAL if the buffer does not contain the string "selective"
1591  * length of buf if lpfc-selective_reset() if the call succeeds
1592  * return value of lpfc_selective_reset() if the call fails
1593 **/
1594 static ssize_t
1595 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1596 		 const char *buf, size_t count)
1597 {
1598 	struct Scsi_Host  *shost = class_to_shost(dev);
1599 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1600 	struct lpfc_hba   *phba = vport->phba;
1601 	int status = -EINVAL;
1602 
1603 	if (!phba->cfg_enable_hba_reset)
1604 		return -EACCES;
1605 
1606 	if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1607 		status = phba->lpfc_selective_reset(phba);
1608 
1609 	if (status == 0)
1610 		return strlen(buf);
1611 	else
1612 		return status;
1613 }
1614 
1615 /**
1616  * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1617  * @phba: lpfc_hba pointer.
1618  *
1619  * Description:
1620  * SLI4 interface type-2 device to wait on the sliport status register for
1621  * the readyness after performing a firmware reset.
1622  *
1623  * Returns:
1624  * zero for success, -EPERM when port does not have privilege to perform the
1625  * reset, -EIO when port timeout from recovering from the reset.
1626  *
1627  * Note:
1628  * As the caller will interpret the return code by value, be careful in making
1629  * change or addition to return codes.
1630  **/
1631 int
1632 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1633 {
1634 	struct lpfc_register portstat_reg = {0};
1635 	int i;
1636 
1637 	msleep(100);
1638 	if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1639 		       &portstat_reg.word0))
1640 		return -EIO;
1641 
1642 	/* verify if privileged for the request operation */
1643 	if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1644 	    !bf_get(lpfc_sliport_status_err, &portstat_reg))
1645 		return -EPERM;
1646 
1647 	/* wait for the SLI port firmware ready after firmware reset */
1648 	for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1649 		msleep(10);
1650 		if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1651 			       &portstat_reg.word0))
1652 			continue;
1653 		if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1654 			continue;
1655 		if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1656 			continue;
1657 		if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1658 			continue;
1659 		break;
1660 	}
1661 
1662 	if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1663 		return 0;
1664 	else
1665 		return -EIO;
1666 }
1667 
1668 /**
1669  * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1670  * @phba: lpfc_hba pointer.
1671  * @opcode: The sli4 config command opcode.
1672  *
1673  * Description:
1674  * Request SLI4 interface type-2 device to perform a physical register set
1675  * access.
1676  *
1677  * Returns:
1678  * zero for success
1679  **/
1680 static ssize_t
1681 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1682 {
1683 	struct completion online_compl;
1684 	struct pci_dev *pdev = phba->pcidev;
1685 	uint32_t before_fc_flag;
1686 	uint32_t sriov_nr_virtfn;
1687 	uint32_t reg_val;
1688 	int status = 0, rc = 0;
1689 	int job_posted = 1, sriov_err;
1690 
1691 	if (!phba->cfg_enable_hba_reset)
1692 		return -EACCES;
1693 
1694 	if ((phba->sli_rev < LPFC_SLI_REV4) ||
1695 	    (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1696 	     LPFC_SLI_INTF_IF_TYPE_2))
1697 		return -EPERM;
1698 
1699 	/* Keep state if we need to restore back */
1700 	before_fc_flag = phba->pport->fc_flag;
1701 	sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1702 
1703 	if (opcode == LPFC_FW_DUMP) {
1704 		init_completion(&online_compl);
1705 		phba->fw_dump_cmpl = &online_compl;
1706 	} else {
1707 		/* Disable SR-IOV virtual functions if enabled */
1708 		if (phba->cfg_sriov_nr_virtfn) {
1709 			pci_disable_sriov(pdev);
1710 			phba->cfg_sriov_nr_virtfn = 0;
1711 		}
1712 
1713 		status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1714 
1715 		if (status != 0)
1716 			return status;
1717 
1718 		/* wait for the device to be quiesced before firmware reset */
1719 		msleep(100);
1720 	}
1721 
1722 	reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1723 			LPFC_CTL_PDEV_CTL_OFFSET);
1724 
1725 	if (opcode == LPFC_FW_DUMP)
1726 		reg_val |= LPFC_FW_DUMP_REQUEST;
1727 	else if (opcode == LPFC_FW_RESET)
1728 		reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1729 	else if (opcode == LPFC_DV_RESET)
1730 		reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1731 
1732 	writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1733 	       LPFC_CTL_PDEV_CTL_OFFSET);
1734 	/* flush */
1735 	readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1736 
1737 	/* delay driver action following IF_TYPE_2 reset */
1738 	rc = lpfc_sli4_pdev_status_reg_wait(phba);
1739 
1740 	if (rc == -EPERM) {
1741 		/* no privilege for reset */
1742 		lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1743 				"3150 No privilege to perform the requested "
1744 				"access: x%x\n", reg_val);
1745 	} else if (rc == -EIO) {
1746 		/* reset failed, there is nothing more we can do */
1747 		lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1748 				"3153 Fail to perform the requested "
1749 				"access: x%x\n", reg_val);
1750 		if (phba->fw_dump_cmpl)
1751 			phba->fw_dump_cmpl = NULL;
1752 		return rc;
1753 	}
1754 
1755 	/* keep the original port state */
1756 	if (before_fc_flag & FC_OFFLINE_MODE) {
1757 		if (phba->fw_dump_cmpl)
1758 			phba->fw_dump_cmpl = NULL;
1759 		goto out;
1760 	}
1761 
1762 	/* Firmware dump will trigger an HA_ERATT event, and
1763 	 * lpfc_handle_eratt_s4 routine already handles bringing the port back
1764 	 * online.
1765 	 */
1766 	if (opcode == LPFC_FW_DUMP) {
1767 		wait_for_completion(phba->fw_dump_cmpl);
1768 	} else  {
1769 		init_completion(&online_compl);
1770 		job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1771 						   LPFC_EVT_ONLINE);
1772 		if (!job_posted)
1773 			goto out;
1774 
1775 		wait_for_completion(&online_compl);
1776 	}
1777 out:
1778 	/* in any case, restore the virtual functions enabled as before */
1779 	if (sriov_nr_virtfn) {
1780 		/* If fw_dump was performed, first disable to clean up */
1781 		if (opcode == LPFC_FW_DUMP) {
1782 			pci_disable_sriov(pdev);
1783 			phba->cfg_sriov_nr_virtfn = 0;
1784 		}
1785 
1786 		sriov_err =
1787 			lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1788 		if (!sriov_err)
1789 			phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1790 	}
1791 
1792 	/* return proper error code */
1793 	if (!rc) {
1794 		if (!job_posted)
1795 			rc = -ENOMEM;
1796 		else if (status)
1797 			rc = -EIO;
1798 	}
1799 	return rc;
1800 }
1801 
1802 /**
1803  * lpfc_nport_evt_cnt_show - Return the number of nport events
1804  * @dev: class device that is converted into a Scsi_host.
1805  * @attr: device attribute, not used.
1806  * @buf: on return contains the ascii number of nport events.
1807  *
1808  * Returns: size of formatted string.
1809  **/
1810 static ssize_t
1811 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1812 			char *buf)
1813 {
1814 	struct Scsi_Host  *shost = class_to_shost(dev);
1815 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1816 	struct lpfc_hba   *phba = vport->phba;
1817 
1818 	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1819 }
1820 
1821 static int
1822 lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1823 {
1824 	LPFC_MBOXQ_t *mbox = NULL;
1825 	unsigned long val = 0;
1826 	char *pval = NULL;
1827 	int rc = 0;
1828 
1829 	if (!strncmp("enable", buff_out,
1830 				 strlen("enable"))) {
1831 		pval = buff_out + strlen("enable") + 1;
1832 		rc = kstrtoul(pval, 0, &val);
1833 		if (rc)
1834 			return rc; /* Invalid  number */
1835 	} else if (!strncmp("disable", buff_out,
1836 				 strlen("disable"))) {
1837 		val = 0;
1838 	} else {
1839 		return -EINVAL;  /* Invalid command */
1840 	}
1841 
1842 	switch (val) {
1843 	case 0:
1844 		val = 0x0; /* Disable */
1845 		break;
1846 	case 2:
1847 		val = 0x1; /* Enable two port trunk */
1848 		break;
1849 	case 4:
1850 		val = 0x2; /* Enable four port trunk */
1851 		break;
1852 	default:
1853 		return -EINVAL;
1854 	}
1855 
1856 	lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1857 			"0070 Set trunk mode with val %ld ", val);
1858 
1859 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1860 	if (!mbox)
1861 		return -ENOMEM;
1862 
1863 	lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1864 			 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1865 			 12, LPFC_SLI4_MBX_EMBED);
1866 
1867 	bf_set(lpfc_mbx_set_trunk_mode,
1868 	       &mbox->u.mqe.un.set_trunk_mode,
1869 	       val);
1870 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1871 	if (rc)
1872 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1873 				"0071 Set trunk mode failed with status: %d",
1874 				rc);
1875 	mempool_free(mbox, phba->mbox_mem_pool);
1876 
1877 	return 0;
1878 }
1879 
1880 /**
1881  * lpfc_board_mode_show - Return the state of the board
1882  * @dev: class device that is converted into a Scsi_host.
1883  * @attr: device attribute, not used.
1884  * @buf: on return contains the state of the adapter.
1885  *
1886  * Returns: size of formatted string.
1887  **/
1888 static ssize_t
1889 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1890 		     char *buf)
1891 {
1892 	struct Scsi_Host  *shost = class_to_shost(dev);
1893 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1894 	struct lpfc_hba   *phba = vport->phba;
1895 	char  * state;
1896 
1897 	if (phba->link_state == LPFC_HBA_ERROR)
1898 		state = "error";
1899 	else if (phba->link_state == LPFC_WARM_START)
1900 		state = "warm start";
1901 	else if (phba->link_state == LPFC_INIT_START)
1902 		state = "offline";
1903 	else
1904 		state = "online";
1905 
1906 	return scnprintf(buf, PAGE_SIZE, "%s\n", state);
1907 }
1908 
1909 /**
1910  * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1911  * @dev: class device that is converted into a Scsi_host.
1912  * @attr: device attribute, not used.
1913  * @buf: containing one of the strings "online", "offline", "warm" or "error".
1914  * @count: unused variable.
1915  *
1916  * Returns:
1917  * -EACCES if enable hba reset not enabled
1918  * -EINVAL if the buffer does not contain a valid string (see above)
1919  * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1920  * buf length greater than zero indicates success
1921  **/
1922 static ssize_t
1923 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1924 		      const char *buf, size_t count)
1925 {
1926 	struct Scsi_Host  *shost = class_to_shost(dev);
1927 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1928 	struct lpfc_hba   *phba = vport->phba;
1929 	struct completion online_compl;
1930 	char *board_mode_str = NULL;
1931 	int status = 0;
1932 	int rc;
1933 
1934 	if (!phba->cfg_enable_hba_reset) {
1935 		status = -EACCES;
1936 		goto board_mode_out;
1937 	}
1938 
1939 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1940 			 "3050 lpfc_board_mode set to %s\n", buf);
1941 
1942 	init_completion(&online_compl);
1943 
1944 	if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1945 		rc = lpfc_workq_post_event(phba, &status, &online_compl,
1946 				      LPFC_EVT_ONLINE);
1947 		if (rc == 0) {
1948 			status = -ENOMEM;
1949 			goto board_mode_out;
1950 		}
1951 		wait_for_completion(&online_compl);
1952 		if (status)
1953 			status = -EIO;
1954 	} else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1955 		status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1956 	else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1957 		if (phba->sli_rev == LPFC_SLI_REV4)
1958 			status = -EINVAL;
1959 		else
1960 			status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1961 	else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1962 		if (phba->sli_rev == LPFC_SLI_REV4)
1963 			status = -EINVAL;
1964 		else
1965 			status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1966 	else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1967 		status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1968 	else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1969 		status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1970 	else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1971 		status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1972 	else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1973 		 == 0)
1974 		status = lpfc_reset_pci_bus(phba);
1975 	else if (strncmp(buf, "heartbeat", sizeof("heartbeat") - 1) == 0)
1976 		lpfc_issue_hb_tmo(phba);
1977 	else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1978 		status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
1979 	else
1980 		status = -EINVAL;
1981 
1982 board_mode_out:
1983 	if (!status)
1984 		return strlen(buf);
1985 	else {
1986 		board_mode_str = strchr(buf, '\n');
1987 		if (board_mode_str)
1988 			*board_mode_str = '\0';
1989 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1990 				 "3097 Failed \"%s\", status(%d), "
1991 				 "fc_flag(x%x)\n",
1992 				 buf, status, phba->pport->fc_flag);
1993 		return status;
1994 	}
1995 }
1996 
1997 /**
1998  * lpfc_get_hba_info - Return various bits of informaton about the adapter
1999  * @phba: pointer to the adapter structure.
2000  * @mxri: max xri count.
2001  * @axri: available xri count.
2002  * @mrpi: max rpi count.
2003  * @arpi: available rpi count.
2004  * @mvpi: max vpi count.
2005  * @avpi: available vpi count.
2006  *
2007  * Description:
2008  * If an integer pointer for an count is not null then the value for the
2009  * count is returned.
2010  *
2011  * Returns:
2012  * zero on error
2013  * one for success
2014  **/
2015 static int
2016 lpfc_get_hba_info(struct lpfc_hba *phba,
2017 		  uint32_t *mxri, uint32_t *axri,
2018 		  uint32_t *mrpi, uint32_t *arpi,
2019 		  uint32_t *mvpi, uint32_t *avpi)
2020 {
2021 	struct lpfc_mbx_read_config *rd_config;
2022 	LPFC_MBOXQ_t *pmboxq;
2023 	MAILBOX_t *pmb;
2024 	int rc = 0;
2025 	uint32_t max_vpi;
2026 
2027 	/*
2028 	 * prevent udev from issuing mailbox commands until the port is
2029 	 * configured.
2030 	 */
2031 	if (phba->link_state < LPFC_LINK_DOWN ||
2032 	    !phba->mbox_mem_pool ||
2033 	    (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
2034 		return 0;
2035 
2036 	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
2037 		return 0;
2038 
2039 	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2040 	if (!pmboxq)
2041 		return 0;
2042 	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2043 
2044 	pmb = &pmboxq->u.mb;
2045 	pmb->mbxCommand = MBX_READ_CONFIG;
2046 	pmb->mbxOwner = OWN_HOST;
2047 	pmboxq->ctx_buf = NULL;
2048 
2049 	if (phba->pport->fc_flag & FC_OFFLINE_MODE)
2050 		rc = MBX_NOT_FINISHED;
2051 	else
2052 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2053 
2054 	if (rc != MBX_SUCCESS) {
2055 		if (rc != MBX_TIMEOUT)
2056 			mempool_free(pmboxq, phba->mbox_mem_pool);
2057 		return 0;
2058 	}
2059 
2060 	if (phba->sli_rev == LPFC_SLI_REV4) {
2061 		rd_config = &pmboxq->u.mqe.un.rd_config;
2062 		if (mrpi)
2063 			*mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
2064 		if (arpi)
2065 			*arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
2066 					phba->sli4_hba.max_cfg_param.rpi_used;
2067 		if (mxri)
2068 			*mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
2069 		if (axri)
2070 			*axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
2071 					phba->sli4_hba.max_cfg_param.xri_used;
2072 
2073 		/* Account for differences with SLI-3.  Get vpi count from
2074 		 * mailbox data and subtract one for max vpi value.
2075 		 */
2076 		max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
2077 			(bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
2078 
2079 		/* Limit the max we support */
2080 		if (max_vpi > LPFC_MAX_VPI)
2081 			max_vpi = LPFC_MAX_VPI;
2082 		if (mvpi)
2083 			*mvpi = max_vpi;
2084 		if (avpi)
2085 			*avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
2086 	} else {
2087 		if (mrpi)
2088 			*mrpi = pmb->un.varRdConfig.max_rpi;
2089 		if (arpi)
2090 			*arpi = pmb->un.varRdConfig.avail_rpi;
2091 		if (mxri)
2092 			*mxri = pmb->un.varRdConfig.max_xri;
2093 		if (axri)
2094 			*axri = pmb->un.varRdConfig.avail_xri;
2095 		if (mvpi)
2096 			*mvpi = pmb->un.varRdConfig.max_vpi;
2097 		if (avpi) {
2098 			/* avail_vpi is only valid if link is up and ready */
2099 			if (phba->link_state == LPFC_HBA_READY)
2100 				*avpi = pmb->un.varRdConfig.avail_vpi;
2101 			else
2102 				*avpi = pmb->un.varRdConfig.max_vpi;
2103 		}
2104 	}
2105 
2106 	mempool_free(pmboxq, phba->mbox_mem_pool);
2107 	return 1;
2108 }
2109 
2110 /**
2111  * lpfc_max_rpi_show - Return maximum rpi
2112  * @dev: class device that is converted into a Scsi_host.
2113  * @attr: device attribute, not used.
2114  * @buf: on return contains the maximum rpi count in decimal or "Unknown".
2115  *
2116  * Description:
2117  * Calls lpfc_get_hba_info() asking for just the mrpi count.
2118  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2119  * to "Unknown" and the buffer length is returned, therefore the caller
2120  * must check for "Unknown" in the buffer to detect a failure.
2121  *
2122  * Returns: size of formatted string.
2123  **/
2124 static ssize_t
2125 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
2126 		  char *buf)
2127 {
2128 	struct Scsi_Host  *shost = class_to_shost(dev);
2129 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2130 	struct lpfc_hba   *phba = vport->phba;
2131 	uint32_t cnt;
2132 
2133 	if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
2134 		return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2135 	return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2136 }
2137 
2138 /**
2139  * lpfc_used_rpi_show - Return maximum rpi minus available rpi
2140  * @dev: class device that is converted into a Scsi_host.
2141  * @attr: device attribute, not used.
2142  * @buf: containing the used rpi count in decimal or "Unknown".
2143  *
2144  * Description:
2145  * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
2146  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2147  * to "Unknown" and the buffer length is returned, therefore the caller
2148  * must check for "Unknown" in the buffer to detect a failure.
2149  *
2150  * Returns: size of formatted string.
2151  **/
2152 static ssize_t
2153 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
2154 		   char *buf)
2155 {
2156 	struct Scsi_Host  *shost = class_to_shost(dev);
2157 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2158 	struct lpfc_hba   *phba = vport->phba;
2159 	uint32_t cnt, acnt;
2160 
2161 	if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
2162 		return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2163 	return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2164 }
2165 
2166 /**
2167  * lpfc_max_xri_show - Return maximum xri
2168  * @dev: class device that is converted into a Scsi_host.
2169  * @attr: device attribute, not used.
2170  * @buf: on return contains the maximum xri count in decimal or "Unknown".
2171  *
2172  * Description:
2173  * Calls lpfc_get_hba_info() asking for just the mrpi count.
2174  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2175  * to "Unknown" and the buffer length is returned, therefore the caller
2176  * must check for "Unknown" in the buffer to detect a failure.
2177  *
2178  * Returns: size of formatted string.
2179  **/
2180 static ssize_t
2181 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
2182 		  char *buf)
2183 {
2184 	struct Scsi_Host  *shost = class_to_shost(dev);
2185 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2186 	struct lpfc_hba   *phba = vport->phba;
2187 	uint32_t cnt;
2188 
2189 	if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2190 		return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2191 	return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2192 }
2193 
2194 /**
2195  * lpfc_used_xri_show - Return maximum xpi minus the available xpi
2196  * @dev: class device that is converted into a Scsi_host.
2197  * @attr: device attribute, not used.
2198  * @buf: on return contains the used xri count in decimal or "Unknown".
2199  *
2200  * Description:
2201  * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
2202  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2203  * to "Unknown" and the buffer length is returned, therefore the caller
2204  * must check for "Unknown" in the buffer to detect a failure.
2205  *
2206  * Returns: size of formatted string.
2207  **/
2208 static ssize_t
2209 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2210 		   char *buf)
2211 {
2212 	struct Scsi_Host  *shost = class_to_shost(dev);
2213 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2214 	struct lpfc_hba   *phba = vport->phba;
2215 	uint32_t cnt, acnt;
2216 
2217 	if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2218 		return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2219 	return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2220 }
2221 
2222 /**
2223  * lpfc_max_vpi_show - Return maximum vpi
2224  * @dev: class device that is converted into a Scsi_host.
2225  * @attr: device attribute, not used.
2226  * @buf: on return contains the maximum vpi count in decimal or "Unknown".
2227  *
2228  * Description:
2229  * Calls lpfc_get_hba_info() asking for just the mvpi count.
2230  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2231  * to "Unknown" and the buffer length is returned, therefore the caller
2232  * must check for "Unknown" in the buffer to detect a failure.
2233  *
2234  * Returns: size of formatted string.
2235  **/
2236 static ssize_t
2237 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2238 		  char *buf)
2239 {
2240 	struct Scsi_Host  *shost = class_to_shost(dev);
2241 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2242 	struct lpfc_hba   *phba = vport->phba;
2243 	uint32_t cnt;
2244 
2245 	if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2246 		return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2247 	return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2248 }
2249 
2250 /**
2251  * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
2252  * @dev: class device that is converted into a Scsi_host.
2253  * @attr: device attribute, not used.
2254  * @buf: on return contains the used vpi count in decimal or "Unknown".
2255  *
2256  * Description:
2257  * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
2258  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
2259  * to "Unknown" and the buffer length is returned, therefore the caller
2260  * must check for "Unknown" in the buffer to detect a failure.
2261  *
2262  * Returns: size of formatted string.
2263  **/
2264 static ssize_t
2265 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2266 		   char *buf)
2267 {
2268 	struct Scsi_Host  *shost = class_to_shost(dev);
2269 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2270 	struct lpfc_hba   *phba = vport->phba;
2271 	uint32_t cnt, acnt;
2272 
2273 	if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2274 		return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2275 	return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2276 }
2277 
2278 /**
2279  * lpfc_npiv_info_show - Return text about NPIV support for the adapter
2280  * @dev: class device that is converted into a Scsi_host.
2281  * @attr: device attribute, not used.
2282  * @buf: text that must be interpreted to determine if npiv is supported.
2283  *
2284  * Description:
2285  * Buffer will contain text indicating npiv is not suppoerted on the port,
2286  * the port is an NPIV physical port, or it is an npiv virtual port with
2287  * the id of the vport.
2288  *
2289  * Returns: size of formatted string.
2290  **/
2291 static ssize_t
2292 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2293 		    char *buf)
2294 {
2295 	struct Scsi_Host  *shost = class_to_shost(dev);
2296 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2297 	struct lpfc_hba   *phba = vport->phba;
2298 
2299 	if (!(phba->max_vpi))
2300 		return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2301 	if (vport->port_type == LPFC_PHYSICAL_PORT)
2302 		return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2303 	return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2304 }
2305 
2306 /**
2307  * lpfc_poll_show - Return text about poll support for the adapter
2308  * @dev: class device that is converted into a Scsi_host.
2309  * @attr: device attribute, not used.
2310  * @buf: on return contains the cfg_poll in hex.
2311  *
2312  * Notes:
2313  * cfg_poll should be a lpfc_polling_flags type.
2314  *
2315  * Returns: size of formatted string.
2316  **/
2317 static ssize_t
2318 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2319 	       char *buf)
2320 {
2321 	struct Scsi_Host  *shost = class_to_shost(dev);
2322 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2323 	struct lpfc_hba   *phba = vport->phba;
2324 
2325 	return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2326 }
2327 
2328 /**
2329  * lpfc_poll_store - Set the value of cfg_poll for the adapter
2330  * @dev: class device that is converted into a Scsi_host.
2331  * @attr: device attribute, not used.
2332  * @buf: one or more lpfc_polling_flags values.
2333  * @count: not used.
2334  *
2335  * Notes:
2336  * buf contents converted to integer and checked for a valid value.
2337  *
2338  * Returns:
2339  * -EINVAL if the buffer connot be converted or is out of range
2340  * length of the buf on success
2341  **/
2342 static ssize_t
2343 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2344 		const char *buf, size_t count)
2345 {
2346 	struct Scsi_Host  *shost = class_to_shost(dev);
2347 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2348 	struct lpfc_hba   *phba = vport->phba;
2349 	uint32_t creg_val;
2350 	uint32_t old_val;
2351 	int val=0;
2352 
2353 	if (!isdigit(buf[0]))
2354 		return -EINVAL;
2355 
2356 	if (sscanf(buf, "%i", &val) != 1)
2357 		return -EINVAL;
2358 
2359 	if ((val & 0x3) != val)
2360 		return -EINVAL;
2361 
2362 	if (phba->sli_rev == LPFC_SLI_REV4)
2363 		val = 0;
2364 
2365 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2366 		"3051 lpfc_poll changed from %d to %d\n",
2367 		phba->cfg_poll, val);
2368 
2369 	spin_lock_irq(&phba->hbalock);
2370 
2371 	old_val = phba->cfg_poll;
2372 
2373 	if (val & ENABLE_FCP_RING_POLLING) {
2374 		if ((val & DISABLE_FCP_RING_INT) &&
2375 		    !(old_val & DISABLE_FCP_RING_INT)) {
2376 			if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2377 				spin_unlock_irq(&phba->hbalock);
2378 				return -EINVAL;
2379 			}
2380 			creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2381 			writel(creg_val, phba->HCregaddr);
2382 			readl(phba->HCregaddr); /* flush */
2383 
2384 			lpfc_poll_start_timer(phba);
2385 		}
2386 	} else if (val != 0x0) {
2387 		spin_unlock_irq(&phba->hbalock);
2388 		return -EINVAL;
2389 	}
2390 
2391 	if (!(val & DISABLE_FCP_RING_INT) &&
2392 	    (old_val & DISABLE_FCP_RING_INT))
2393 	{
2394 		spin_unlock_irq(&phba->hbalock);
2395 		del_timer(&phba->fcp_poll_timer);
2396 		spin_lock_irq(&phba->hbalock);
2397 		if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2398 			spin_unlock_irq(&phba->hbalock);
2399 			return -EINVAL;
2400 		}
2401 		creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2402 		writel(creg_val, phba->HCregaddr);
2403 		readl(phba->HCregaddr); /* flush */
2404 	}
2405 
2406 	phba->cfg_poll = val;
2407 
2408 	spin_unlock_irq(&phba->hbalock);
2409 
2410 	return strlen(buf);
2411 }
2412 
2413 /**
2414  * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
2415  * @dev: class converted to a Scsi_host structure.
2416  * @attr: device attribute, not used.
2417  * @buf: on return contains the formatted support level.
2418  *
2419  * Description:
2420  * Returns the maximum number of virtual functions a physical function can
2421  * support, 0 will be returned if called on virtual function.
2422  *
2423  * Returns: size of formatted string.
2424  **/
2425 static ssize_t
2426 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2427 			      struct device_attribute *attr,
2428 			      char *buf)
2429 {
2430 	struct Scsi_Host *shost = class_to_shost(dev);
2431 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2432 	struct lpfc_hba *phba = vport->phba;
2433 	uint16_t max_nr_virtfn;
2434 
2435 	max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2436 	return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2437 }
2438 
2439 /**
2440  * lpfc_enable_bbcr_set: Sets an attribute value.
2441  * @phba: pointer the the adapter structure.
2442  * @val: integer attribute value.
2443  *
2444  * Description:
2445  * Validates the min and max values then sets the
2446  * adapter config field if in the valid range. prints error message
2447  * and does not set the parameter if invalid.
2448  *
2449  * Returns:
2450  * zero on success
2451  * -EINVAL if val is invalid
2452  */
2453 static ssize_t
2454 lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2455 {
2456 	if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2457 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2458 				"3068 lpfc_enable_bbcr changed from %d to "
2459 				"%d\n", phba->cfg_enable_bbcr, val);
2460 		phba->cfg_enable_bbcr = val;
2461 		return 0;
2462 	}
2463 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2464 			"0451 lpfc_enable_bbcr cannot set to %d, range is 0, "
2465 			"1\n", val);
2466 	return -EINVAL;
2467 }
2468 
2469 /*
2470  * lpfc_param_show - Return a cfg attribute value in decimal
2471  *
2472  * Description:
2473  * Macro that given an attr e.g. hba_queue_depth expands
2474  * into a function with the name lpfc_hba_queue_depth_show.
2475  *
2476  * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
2477  * @dev: class device that is converted into a Scsi_host.
2478  * @attr: device attribute, not used.
2479  * @buf: on return contains the attribute value in decimal.
2480  *
2481  * Returns: size of formatted string.
2482  **/
2483 #define lpfc_param_show(attr)	\
2484 static ssize_t \
2485 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2486 		   char *buf) \
2487 { \
2488 	struct Scsi_Host  *shost = class_to_shost(dev);\
2489 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2490 	struct lpfc_hba   *phba = vport->phba;\
2491 	return scnprintf(buf, PAGE_SIZE, "%d\n",\
2492 			phba->cfg_##attr);\
2493 }
2494 
2495 /*
2496  * lpfc_param_hex_show - Return a cfg attribute value in hex
2497  *
2498  * Description:
2499  * Macro that given an attr e.g. hba_queue_depth expands
2500  * into a function with the name lpfc_hba_queue_depth_show
2501  *
2502  * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
2503  * @dev: class device that is converted into a Scsi_host.
2504  * @attr: device attribute, not used.
2505  * @buf: on return contains the attribute value in hexadecimal.
2506  *
2507  * Returns: size of formatted string.
2508  **/
2509 #define lpfc_param_hex_show(attr)	\
2510 static ssize_t \
2511 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2512 		   char *buf) \
2513 { \
2514 	struct Scsi_Host  *shost = class_to_shost(dev);\
2515 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2516 	struct lpfc_hba   *phba = vport->phba;\
2517 	uint val = 0;\
2518 	val = phba->cfg_##attr;\
2519 	return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2520 			phba->cfg_##attr);\
2521 }
2522 
2523 /*
2524  * lpfc_param_init - Initializes a cfg attribute
2525  *
2526  * Description:
2527  * Macro that given an attr e.g. hba_queue_depth expands
2528  * into a function with the name lpfc_hba_queue_depth_init. The macro also
2529  * takes a default argument, a minimum and maximum argument.
2530  *
2531  * lpfc_##attr##_init: Initializes an attribute.
2532  * @phba: pointer the the adapter structure.
2533  * @val: integer attribute value.
2534  *
2535  * Validates the min and max values then sets the adapter config field
2536  * accordingly, or uses the default if out of range and prints an error message.
2537  *
2538  * Returns:
2539  * zero on success
2540  * -EINVAL if default used
2541  **/
2542 #define lpfc_param_init(attr, default, minval, maxval)	\
2543 static int \
2544 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2545 { \
2546 	if (lpfc_rangecheck(val, minval, maxval)) {\
2547 		phba->cfg_##attr = val;\
2548 		return 0;\
2549 	}\
2550 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2551 			"0449 lpfc_"#attr" attribute cannot be set to %d, "\
2552 			"allowed range is ["#minval", "#maxval"]\n", val); \
2553 	phba->cfg_##attr = default;\
2554 	return -EINVAL;\
2555 }
2556 
2557 /*
2558  * lpfc_param_set - Set a cfg attribute value
2559  *
2560  * Description:
2561  * Macro that given an attr e.g. hba_queue_depth expands
2562  * into a function with the name lpfc_hba_queue_depth_set
2563  *
2564  * lpfc_##attr##_set: Sets an attribute value.
2565  * @phba: pointer the the adapter structure.
2566  * @val: integer attribute value.
2567  *
2568  * Description:
2569  * Validates the min and max values then sets the
2570  * adapter config field if in the valid range. prints error message
2571  * and does not set the parameter if invalid.
2572  *
2573  * Returns:
2574  * zero on success
2575  * -EINVAL if val is invalid
2576  **/
2577 #define lpfc_param_set(attr, default, minval, maxval)	\
2578 static int \
2579 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2580 { \
2581 	if (lpfc_rangecheck(val, minval, maxval)) {\
2582 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2583 			"3052 lpfc_" #attr " changed from %d to %d\n", \
2584 			phba->cfg_##attr, val); \
2585 		phba->cfg_##attr = val;\
2586 		return 0;\
2587 	}\
2588 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2589 			"0450 lpfc_"#attr" attribute cannot be set to %d, "\
2590 			"allowed range is ["#minval", "#maxval"]\n", val); \
2591 	return -EINVAL;\
2592 }
2593 
2594 /*
2595  * lpfc_param_store - Set a vport attribute value
2596  *
2597  * Description:
2598  * Macro that given an attr e.g. hba_queue_depth expands
2599  * into a function with the name lpfc_hba_queue_depth_store.
2600  *
2601  * lpfc_##attr##_store: Set an sttribute value.
2602  * @dev: class device that is converted into a Scsi_host.
2603  * @attr: device attribute, not used.
2604  * @buf: contains the attribute value in ascii.
2605  * @count: not used.
2606  *
2607  * Description:
2608  * Convert the ascii text number to an integer, then
2609  * use the lpfc_##attr##_set function to set the value.
2610  *
2611  * Returns:
2612  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2613  * length of buffer upon success.
2614  **/
2615 #define lpfc_param_store(attr)	\
2616 static ssize_t \
2617 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2618 		    const char *buf, size_t count) \
2619 { \
2620 	struct Scsi_Host  *shost = class_to_shost(dev);\
2621 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2622 	struct lpfc_hba   *phba = vport->phba;\
2623 	uint val = 0;\
2624 	if (!isdigit(buf[0]))\
2625 		return -EINVAL;\
2626 	if (sscanf(buf, "%i", &val) != 1)\
2627 		return -EINVAL;\
2628 	if (lpfc_##attr##_set(phba, val) == 0) \
2629 		return strlen(buf);\
2630 	else \
2631 		return -EINVAL;\
2632 }
2633 
2634 /*
2635  * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2636  *
2637  * Description:
2638  * Macro that given an attr e.g. hba_queue_depth expands
2639  * into a function with the name lpfc_hba_queue_depth_show
2640  *
2641  * lpfc_##attr##_show: prints the attribute value in decimal.
2642  * @dev: class device that is converted into a Scsi_host.
2643  * @attr: device attribute, not used.
2644  * @buf: on return contains the attribute value in decimal.
2645  *
2646  * Returns: length of formatted string.
2647  **/
2648 #define lpfc_vport_param_show(attr)	\
2649 static ssize_t \
2650 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2651 		   char *buf) \
2652 { \
2653 	struct Scsi_Host  *shost = class_to_shost(dev);\
2654 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2655 	return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2656 }
2657 
2658 /*
2659  * lpfc_vport_param_hex_show - Return hex formatted attribute value
2660  *
2661  * Description:
2662  * Macro that given an attr e.g.
2663  * hba_queue_depth expands into a function with the name
2664  * lpfc_hba_queue_depth_show
2665  *
2666  * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2667  * @dev: class device that is converted into a Scsi_host.
2668  * @attr: device attribute, not used.
2669  * @buf: on return contains the attribute value in hexadecimal.
2670  *
2671  * Returns: length of formatted string.
2672  **/
2673 #define lpfc_vport_param_hex_show(attr)	\
2674 static ssize_t \
2675 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2676 		   char *buf) \
2677 { \
2678 	struct Scsi_Host  *shost = class_to_shost(dev);\
2679 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2680 	return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2681 }
2682 
2683 /*
2684  * lpfc_vport_param_init - Initialize a vport cfg attribute
2685  *
2686  * Description:
2687  * Macro that given an attr e.g. hba_queue_depth expands
2688  * into a function with the name lpfc_hba_queue_depth_init. The macro also
2689  * takes a default argument, a minimum and maximum argument.
2690  *
2691  * lpfc_##attr##_init: validates the min and max values then sets the
2692  * adapter config field accordingly, or uses the default if out of range
2693  * and prints an error message.
2694  * @phba: pointer the the adapter structure.
2695  * @val: integer attribute value.
2696  *
2697  * Returns:
2698  * zero on success
2699  * -EINVAL if default used
2700  **/
2701 #define lpfc_vport_param_init(attr, default, minval, maxval)	\
2702 static int \
2703 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2704 { \
2705 	if (lpfc_rangecheck(val, minval, maxval)) {\
2706 		vport->cfg_##attr = val;\
2707 		return 0;\
2708 	}\
2709 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2710 			 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2711 			 "allowed range is ["#minval", "#maxval"]\n", val); \
2712 	vport->cfg_##attr = default;\
2713 	return -EINVAL;\
2714 }
2715 
2716 /*
2717  * lpfc_vport_param_set - Set a vport cfg attribute
2718  *
2719  * Description:
2720  * Macro that given an attr e.g. hba_queue_depth expands
2721  * into a function with the name lpfc_hba_queue_depth_set
2722  *
2723  * lpfc_##attr##_set: validates the min and max values then sets the
2724  * adapter config field if in the valid range. prints error message
2725  * and does not set the parameter if invalid.
2726  * @phba: pointer the the adapter structure.
2727  * @val:	integer attribute value.
2728  *
2729  * Returns:
2730  * zero on success
2731  * -EINVAL if val is invalid
2732  **/
2733 #define lpfc_vport_param_set(attr, default, minval, maxval)	\
2734 static int \
2735 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2736 { \
2737 	if (lpfc_rangecheck(val, minval, maxval)) {\
2738 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2739 			"3053 lpfc_" #attr \
2740 			" changed from %d (x%x) to %d (x%x)\n", \
2741 			vport->cfg_##attr, vport->cfg_##attr, \
2742 			val, val); \
2743 		vport->cfg_##attr = val;\
2744 		return 0;\
2745 	}\
2746 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2747 			 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2748 			 "allowed range is ["#minval", "#maxval"]\n", val); \
2749 	return -EINVAL;\
2750 }
2751 
2752 /*
2753  * lpfc_vport_param_store - Set a vport attribute
2754  *
2755  * Description:
2756  * Macro that given an attr e.g. hba_queue_depth
2757  * expands into a function with the name lpfc_hba_queue_depth_store
2758  *
2759  * lpfc_##attr##_store: convert the ascii text number to an integer, then
2760  * use the lpfc_##attr##_set function to set the value.
2761  * @cdev: class device that is converted into a Scsi_host.
2762  * @buf:	contains the attribute value in decimal.
2763  * @count: not used.
2764  *
2765  * Returns:
2766  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2767  * length of buffer upon success.
2768  **/
2769 #define lpfc_vport_param_store(attr)	\
2770 static ssize_t \
2771 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2772 		    const char *buf, size_t count) \
2773 { \
2774 	struct Scsi_Host  *shost = class_to_shost(dev);\
2775 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2776 	uint val = 0;\
2777 	if (!isdigit(buf[0]))\
2778 		return -EINVAL;\
2779 	if (sscanf(buf, "%i", &val) != 1)\
2780 		return -EINVAL;\
2781 	if (lpfc_##attr##_set(vport, val) == 0) \
2782 		return strlen(buf);\
2783 	else \
2784 		return -EINVAL;\
2785 }
2786 
2787 
2788 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2789 static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2790 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2791 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2792 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2793 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2794 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2795 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2796 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2797 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2798 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2799 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2800 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2801 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2802 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2803 		lpfc_link_state_store);
2804 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2805 		   lpfc_option_rom_version_show, NULL);
2806 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2807 		   lpfc_num_discovered_ports_show, NULL);
2808 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2809 static DEVICE_ATTR_RO(lpfc_drvr_version);
2810 static DEVICE_ATTR_RO(lpfc_enable_fip);
2811 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2812 		   lpfc_board_mode_show, lpfc_board_mode_store);
2813 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2814 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2815 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2816 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2817 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2818 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2819 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2820 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2821 static DEVICE_ATTR_RO(lpfc_temp_sensor);
2822 static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2823 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2824 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2825 		   NULL);
2826 static DEVICE_ATTR(cmf_info, 0444, lpfc_cmf_info_show, NULL);
2827 
2828 #define WWN_SZ 8
2829 /**
2830  * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2831  * @buf: WWN string.
2832  * @cnt: Length of string.
2833  * @wwn: Array to receive converted wwn value.
2834  *
2835  * Returns:
2836  * -EINVAL if the buffer does not contain a valid wwn
2837  * 0 success
2838  **/
2839 static size_t
2840 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2841 {
2842 	unsigned int i, j;
2843 
2844 	/* Count may include a LF at end of string */
2845 	if (buf[cnt-1] == '\n')
2846 		cnt--;
2847 
2848 	if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2849 	    ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2850 		return -EINVAL;
2851 
2852 	memset(wwn, 0, WWN_SZ);
2853 
2854 	/* Validate and store the new name */
2855 	for (i = 0, j = 0; i < 16; i++) {
2856 		if ((*buf >= 'a') && (*buf <= 'f'))
2857 			j = ((j << 4) | ((*buf++ - 'a') + 10));
2858 		else if ((*buf >= 'A') && (*buf <= 'F'))
2859 			j = ((j << 4) | ((*buf++ - 'A') + 10));
2860 		else if ((*buf >= '0') && (*buf <= '9'))
2861 			j = ((j << 4) | (*buf++ - '0'));
2862 		else
2863 			return -EINVAL;
2864 		if (i % 2) {
2865 			wwn[i/2] = j & 0xff;
2866 			j = 0;
2867 		}
2868 	}
2869 	return 0;
2870 }
2871 
2872 
2873 /**
2874  * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2875  *		      Optimized Access Storage (OAS) operations.
2876  * @dev: class device that is converted into a Scsi_host.
2877  * @attr: device attribute, not used.
2878  * @buf: buffer for passing information.
2879  *
2880  * Returns:
2881  * value of count
2882  **/
2883 static ssize_t
2884 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2885 		  char *buf)
2886 {
2887 	struct Scsi_Host *shost = class_to_shost(dev);
2888 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2889 
2890 	return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2891 			wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2892 }
2893 
2894 /**
2895  * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2896  *		      Optimized Access Storage (OAS) operations.
2897  * @dev: class device that is converted into a Scsi_host.
2898  * @attr: device attribute, not used.
2899  * @buf: buffer for passing information.
2900  * @count: Size of the data buffer.
2901  *
2902  * Returns:
2903  * -EINVAL count is invalid, invalid wwpn byte invalid
2904  * -EPERM oas is not supported by hba
2905  * value of count on success
2906  **/
2907 static ssize_t
2908 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2909 		   const char *buf, size_t count)
2910 {
2911 	struct Scsi_Host *shost = class_to_shost(dev);
2912 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2913 	unsigned int cnt = count;
2914 	uint8_t wwpn[WWN_SZ];
2915 	int rc;
2916 
2917 	if (!phba->cfg_fof)
2918 		return -EPERM;
2919 
2920 	/* count may include a LF at end of string */
2921 	if (buf[cnt-1] == '\n')
2922 		cnt--;
2923 
2924 	rc = lpfc_wwn_set(buf, cnt, wwpn);
2925 	if (rc)
2926 		return rc;
2927 
2928 	memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2929 	memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2930 	if (wwn_to_u64(wwpn) == 0)
2931 		phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2932 	else
2933 		phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2934 	phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2935 	phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2936 	return count;
2937 }
2938 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2939 		   lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2940 
2941 /**
2942  * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2943  *		      Optimized Access Storage (OAS) operations.
2944  * @dev: class device that is converted into a Scsi_host.
2945  * @attr: device attribute, not used.
2946  * @buf: buffer for passing information.
2947  *
2948  * Returns:
2949  * value of count
2950  **/
2951 static ssize_t
2952 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2953 		       char *buf)
2954 {
2955 	struct Scsi_Host *shost = class_to_shost(dev);
2956 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2957 
2958 	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2959 }
2960 
2961 /**
2962  * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2963  *		      Optimized Access Storage (OAS) operations.
2964  * @dev: class device that is converted into a Scsi_host.
2965  * @attr: device attribute, not used.
2966  * @buf: buffer for passing information.
2967  * @count: Size of the data buffer.
2968  *
2969  * Returns:
2970  * -EINVAL count is invalid, invalid wwpn byte invalid
2971  * -EPERM oas is not supported by hba
2972  * value of count on success
2973  **/
2974 static ssize_t
2975 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2976 			const char *buf, size_t count)
2977 {
2978 	struct Scsi_Host *shost = class_to_shost(dev);
2979 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2980 	unsigned int cnt = count;
2981 	unsigned long val;
2982 	int ret;
2983 
2984 	if (!phba->cfg_fof)
2985 		return -EPERM;
2986 
2987 	/* count may include a LF at end of string */
2988 	if (buf[cnt-1] == '\n')
2989 		cnt--;
2990 
2991 	ret = kstrtoul(buf, 0, &val);
2992 	if (ret || (val > 0x7f))
2993 		return -EINVAL;
2994 
2995 	if (val)
2996 		phba->cfg_oas_priority = (uint8_t)val;
2997 	else
2998 		phba->cfg_oas_priority = phba->cfg_XLanePriority;
2999 	return count;
3000 }
3001 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3002 		   lpfc_oas_priority_show, lpfc_oas_priority_store);
3003 
3004 /**
3005  * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
3006  *		      for Optimized Access Storage (OAS) operations.
3007  * @dev: class device that is converted into a Scsi_host.
3008  * @attr: device attribute, not used.
3009  * @buf: buffer for passing information.
3010  *
3011  * Returns:
3012  * value of count on success
3013  **/
3014 static ssize_t
3015 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3016 		  char *buf)
3017 {
3018 	struct Scsi_Host *shost = class_to_shost(dev);
3019 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3020 
3021 	return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3022 			wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3023 }
3024 
3025 /**
3026  * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
3027  *		      for Optimized Access Storage (OAS) operations.
3028  * @dev: class device that is converted into a Scsi_host.
3029  * @attr: device attribute, not used.
3030  * @buf: buffer for passing information.
3031  * @count: Size of the data buffer.
3032  *
3033  * Returns:
3034  * -EINVAL count is invalid, invalid wwpn byte invalid
3035  * -EPERM oas is not supported by hba
3036  * value of count on success
3037  **/
3038 static ssize_t
3039 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3040 		   const char *buf, size_t count)
3041 {
3042 	struct Scsi_Host *shost = class_to_shost(dev);
3043 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3044 	unsigned int cnt = count;
3045 	uint8_t wwpn[WWN_SZ];
3046 	int rc;
3047 
3048 	if (!phba->cfg_fof)
3049 		return -EPERM;
3050 
3051 	/* count may include a LF at end of string */
3052 	if (buf[cnt-1] == '\n')
3053 		cnt--;
3054 
3055 	rc = lpfc_wwn_set(buf, cnt, wwpn);
3056 	if (rc)
3057 		return rc;
3058 
3059 	memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3060 	memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3061 	if (wwn_to_u64(wwpn) == 0)
3062 		phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3063 	else
3064 		phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3065 	phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3066 	if (phba->cfg_oas_priority == 0)
3067 		phba->cfg_oas_priority = phba->cfg_XLanePriority;
3068 	phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3069 	return count;
3070 }
3071 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3072 		   lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3073 
3074 /**
3075  * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
3076  *			    of whether luns will be enabled or disabled
3077  *			    for Optimized Access Storage (OAS) operations.
3078  * @dev: class device that is converted into a Scsi_host.
3079  * @attr: device attribute, not used.
3080  * @buf: buffer for passing information.
3081  *
3082  * Returns:
3083  * size of formatted string.
3084  **/
3085 static ssize_t
3086 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3087 			char *buf)
3088 {
3089 	struct Scsi_Host *shost = class_to_shost(dev);
3090 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3091 
3092 	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3093 }
3094 
3095 /**
3096  * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
3097  *			    of whether luns will be enabled or disabled
3098  *			    for Optimized Access Storage (OAS) operations.
3099  * @dev: class device that is converted into a Scsi_host.
3100  * @attr: device attribute, not used.
3101  * @buf: buffer for passing information.
3102  * @count: Size of the data buffer.
3103  *
3104  * Returns:
3105  * -EINVAL count is invalid, invalid wwpn byte invalid
3106  * -EPERM oas is not supported by hba
3107  * value of count on success
3108  **/
3109 static ssize_t
3110 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3111 			 const char *buf, size_t count)
3112 {
3113 	struct Scsi_Host *shost = class_to_shost(dev);
3114 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3115 	int val = 0;
3116 
3117 	if (!phba->cfg_fof)
3118 		return -EPERM;
3119 
3120 	if (!isdigit(buf[0]))
3121 		return -EINVAL;
3122 
3123 	if (sscanf(buf, "%i", &val) != 1)
3124 		return -EINVAL;
3125 
3126 	if ((val != 0) && (val != 1))
3127 		return -EINVAL;
3128 
3129 	phba->cfg_oas_lun_state = val;
3130 	return strlen(buf);
3131 }
3132 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3133 		   lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3134 
3135 /**
3136  * lpfc_oas_lun_status_show - Return the status of the Optimized Access
3137  *                          Storage (OAS) lun returned by the
3138  *                          lpfc_oas_lun_show function.
3139  * @dev: class device that is converted into a Scsi_host.
3140  * @attr: device attribute, not used.
3141  * @buf: buffer for passing information.
3142  *
3143  * Returns:
3144  * size of formatted string.
3145  **/
3146 static ssize_t
3147 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3148 			 char *buf)
3149 {
3150 	struct Scsi_Host *shost = class_to_shost(dev);
3151 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3152 
3153 	if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3154 		return -EFAULT;
3155 
3156 	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3157 }
3158 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3159 		   lpfc_oas_lun_status_show, NULL);
3160 
3161 
3162 /**
3163  * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
3164  *			   (OAS) operations.
3165  * @phba: lpfc_hba pointer.
3166  * @vpt_wwpn: wwpn of the vport associated with the returned lun
3167  * @tgt_wwpn: wwpn of the target associated with the returned lun
3168  * @lun: the fc lun for setting oas state.
3169  * @oas_state: the oas state to be set to the lun.
3170  * @pri: priority
3171  *
3172  * Returns:
3173  * SUCCESS : 0
3174  * -EPERM OAS is not enabled or not supported by this port.
3175  *
3176  */
3177 static size_t
3178 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3179 		       uint8_t tgt_wwpn[], uint64_t lun,
3180 		       uint32_t oas_state, uint8_t pri)
3181 {
3182 
3183 	int rc = 0;
3184 
3185 	if (!phba->cfg_fof)
3186 		return -EPERM;
3187 
3188 	if (oas_state) {
3189 		if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3190 					 (struct lpfc_name *)tgt_wwpn,
3191 					 lun, pri))
3192 			rc = -ENOMEM;
3193 	} else {
3194 		lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3195 				     (struct lpfc_name *)tgt_wwpn, lun, pri);
3196 	}
3197 	return rc;
3198 
3199 }
3200 
3201 /**
3202  * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
3203  *			  Access Storage (OAS) operations.
3204  * @phba: lpfc_hba pointer.
3205  * @vpt_wwpn: wwpn of the vport associated with the returned lun
3206  * @tgt_wwpn: wwpn of the target associated with the returned lun
3207  * @lun_status: status of the lun returned lun
3208  * @lun_pri: priority of the lun returned lun
3209  *
3210  * Returns the first or next lun enabled for OAS operations for the vport/target
3211  * specified.  If a lun is found, its vport wwpn, target wwpn and status is
3212  * returned.  If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
3213  *
3214  * Return:
3215  * lun that is OAS enabled for the vport/target
3216  * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
3217  */
3218 static uint64_t
3219 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3220 		      uint8_t tgt_wwpn[], uint32_t *lun_status,
3221 		      uint32_t *lun_pri)
3222 {
3223 	uint64_t found_lun;
3224 
3225 	if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3226 		return NOT_OAS_ENABLED_LUN;
3227 	if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3228 				   phba->sli4_hba.oas_next_vpt_wwpn,
3229 				   (struct lpfc_name *)
3230 				   phba->sli4_hba.oas_next_tgt_wwpn,
3231 				   &phba->sli4_hba.oas_next_lun,
3232 				   (struct lpfc_name *)vpt_wwpn,
3233 				   (struct lpfc_name *)tgt_wwpn,
3234 				   &found_lun, lun_status, lun_pri))
3235 		return found_lun;
3236 	else
3237 		return NOT_OAS_ENABLED_LUN;
3238 }
3239 
3240 /**
3241  * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
3242  * @phba: lpfc_hba pointer.
3243  * @vpt_wwpn: vport wwpn by reference.
3244  * @tgt_wwpn: target wwpn by reference.
3245  * @lun: the fc lun for setting oas state.
3246  * @oas_state: the oas state to be set to the oas_lun.
3247  * @pri: priority
3248  *
3249  * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
3250  * a lun for OAS operations.
3251  *
3252  * Return:
3253  * SUCCESS: 0
3254  * -ENOMEM: failed to enable an lun for OAS operations
3255  * -EPERM: OAS is not enabled
3256  */
3257 static ssize_t
3258 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3259 			  uint8_t tgt_wwpn[], uint64_t lun,
3260 			  uint32_t oas_state, uint8_t pri)
3261 {
3262 
3263 	int rc;
3264 
3265 	rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3266 				    oas_state, pri);
3267 	return rc;
3268 }
3269 
3270 /**
3271  * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
3272  * @dev: class device that is converted into a Scsi_host.
3273  * @attr: device attribute, not used.
3274  * @buf: buffer for passing information.
3275  *
3276  * This routine returns a lun enabled for OAS each time the function
3277  * is called.
3278  *
3279  * Returns:
3280  * SUCCESS: size of formatted string.
3281  * -EFAULT: target or vport wwpn was not set properly.
3282  * -EPERM: oas is not enabled.
3283  **/
3284 static ssize_t
3285 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3286 		  char *buf)
3287 {
3288 	struct Scsi_Host *shost = class_to_shost(dev);
3289 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3290 
3291 	uint64_t oas_lun;
3292 	int len = 0;
3293 
3294 	if (!phba->cfg_fof)
3295 		return -EPERM;
3296 
3297 	if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3298 		if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3299 			return -EFAULT;
3300 
3301 	if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3302 		if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3303 			return -EFAULT;
3304 
3305 	oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3306 					phba->cfg_oas_tgt_wwpn,
3307 					&phba->cfg_oas_lun_status,
3308 					&phba->cfg_oas_priority);
3309 	if (oas_lun != NOT_OAS_ENABLED_LUN)
3310 		phba->cfg_oas_flags |= OAS_LUN_VALID;
3311 
3312 	len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3313 
3314 	return len;
3315 }
3316 
3317 /**
3318  * lpfc_oas_lun_store - Sets the OAS state for lun
3319  * @dev: class device that is converted into a Scsi_host.
3320  * @attr: device attribute, not used.
3321  * @buf: buffer for passing information.
3322  * @count: size of the formatting string
3323  *
3324  * This function sets the OAS state for lun.  Before this function is called,
3325  * the vport wwpn, target wwpn, and oas state need to be set.
3326  *
3327  * Returns:
3328  * SUCCESS: size of formatted string.
3329  * -EFAULT: target or vport wwpn was not set properly.
3330  * -EPERM: oas is not enabled.
3331  * size of formatted string.
3332  **/
3333 static ssize_t
3334 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3335 		   const char *buf, size_t count)
3336 {
3337 	struct Scsi_Host *shost = class_to_shost(dev);
3338 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3339 	uint64_t scsi_lun;
3340 	uint32_t pri;
3341 	ssize_t rc;
3342 
3343 	if (!phba->cfg_fof)
3344 		return -EPERM;
3345 
3346 	if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3347 		return -EFAULT;
3348 
3349 	if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3350 		return -EFAULT;
3351 
3352 	if (!isdigit(buf[0]))
3353 		return -EINVAL;
3354 
3355 	if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3356 		return -EINVAL;
3357 
3358 	pri = phba->cfg_oas_priority;
3359 	if (pri == 0)
3360 		pri = phba->cfg_XLanePriority;
3361 
3362 	lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3363 			"3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3364 			"priority 0x%x with oas state %d\n",
3365 			wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3366 			wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3367 			pri, phba->cfg_oas_lun_state);
3368 
3369 	rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3370 				       phba->cfg_oas_tgt_wwpn, scsi_lun,
3371 				       phba->cfg_oas_lun_state, pri);
3372 	if (rc)
3373 		return rc;
3374 
3375 	return count;
3376 }
3377 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3378 		   lpfc_oas_lun_show, lpfc_oas_lun_store);
3379 
3380 int lpfc_enable_nvmet_cnt;
3381 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3382 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3383 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3384 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3385 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3386 
3387 static int lpfc_poll = 0;
3388 module_param(lpfc_poll, int, S_IRUGO);
3389 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3390 		 " 0 - none,"
3391 		 " 1 - poll with interrupts enabled"
3392 		 " 3 - poll and disable FCP ring interrupts");
3393 
3394 static DEVICE_ATTR_RW(lpfc_poll);
3395 
3396 int lpfc_no_hba_reset_cnt;
3397 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3398 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3399 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3400 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3401 
3402 LPFC_ATTR(sli_mode, 3, 3, 3,
3403 	"SLI mode selector: 3 - select SLI-3");
3404 
3405 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3406 	"Enable NPIV functionality");
3407 
3408 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3409 	"FCF Fast failover=1 Priority failover=2");
3410 
3411 /*
3412  * lpfc_fcp_wait_abts_rsp: Modifies criteria for reporting completion of
3413  * aborted IO.
3414  * The range is [0,1]. Default value is 0
3415  *      0, IO completes after ABTS issued (default).
3416  *      1, IO completes after receipt of ABTS response or timeout.
3417  */
3418 LPFC_ATTR_R(fcp_wait_abts_rsp, 0, 0, 1, "Wait for FCP ABTS completion");
3419 
3420 /*
3421 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3422 #	0x0 = disabled, XRI/OXID use not tracked.
3423 #	0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3424 #	0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3425 */
3426 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3427 	"Enable RRQ functionality");
3428 
3429 /*
3430 # lpfc_suppress_link_up:  Bring link up at initialization
3431 #            0x0  = bring link up (issue MBX_INIT_LINK)
3432 #            0x1  = do NOT bring link up at initialization(MBX_INIT_LINK)
3433 #            0x2  = never bring up link
3434 # Default value is 0.
3435 */
3436 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3437 		LPFC_DELAY_INIT_LINK_INDEFINITELY,
3438 		"Suppress Link Up at initialization");
3439 
3440 static ssize_t
3441 lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3442 {
3443 	struct Scsi_Host  *shost = class_to_shost(dev);
3444 	struct lpfc_hba   *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3445 
3446 	return scnprintf(buf, PAGE_SIZE, "%d\n",
3447 			 phba->sli4_hba.pc_sli4_params.pls);
3448 }
3449 static DEVICE_ATTR(pls, 0444,
3450 			 lpfc_pls_show, NULL);
3451 
3452 static ssize_t
3453 lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3454 {
3455 	struct Scsi_Host  *shost = class_to_shost(dev);
3456 	struct lpfc_hba   *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3457 
3458 	return scnprintf(buf, PAGE_SIZE, "%d\n",
3459 			 (phba->hba_flag & HBA_PERSISTENT_TOPO) ? 1 : 0);
3460 }
3461 static DEVICE_ATTR(pt, 0444,
3462 			 lpfc_pt_show, NULL);
3463 
3464 /*
3465 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3466 #       1 - (1024)
3467 #       2 - (2048)
3468 #       3 - (3072)
3469 #       4 - (4096)
3470 #       5 - (5120)
3471 */
3472 static ssize_t
3473 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3474 {
3475 	struct Scsi_Host  *shost = class_to_shost(dev);
3476 	struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3477 
3478 	return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3479 }
3480 
3481 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3482 			 lpfc_iocb_hw_show, NULL);
3483 static ssize_t
3484 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3485 {
3486 	struct Scsi_Host  *shost = class_to_shost(dev);
3487 	struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3488 	struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3489 
3490 	return scnprintf(buf, PAGE_SIZE, "%d\n",
3491 			pring ? pring->txq_max : 0);
3492 }
3493 
3494 static DEVICE_ATTR(txq_hw, S_IRUGO,
3495 			 lpfc_txq_hw_show, NULL);
3496 static ssize_t
3497 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3498  char *buf)
3499 {
3500 	struct Scsi_Host  *shost = class_to_shost(dev);
3501 	struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3502 	struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3503 
3504 	return scnprintf(buf, PAGE_SIZE, "%d\n",
3505 			pring ? pring->txcmplq_max : 0);
3506 }
3507 
3508 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3509 			 lpfc_txcmplq_hw_show, NULL);
3510 
3511 /*
3512 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3513 # until the timer expires. Value range is [0,255]. Default value is 30.
3514 */
3515 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3516 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3517 module_param(lpfc_nodev_tmo, int, 0);
3518 MODULE_PARM_DESC(lpfc_nodev_tmo,
3519 		 "Seconds driver will hold I/O waiting "
3520 		 "for a device to come back");
3521 
3522 /**
3523  * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3524  * @dev: class converted to a Scsi_host structure.
3525  * @attr: device attribute, not used.
3526  * @buf: on return contains the dev loss timeout in decimal.
3527  *
3528  * Returns: size of formatted string.
3529  **/
3530 static ssize_t
3531 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3532 		    char *buf)
3533 {
3534 	struct Scsi_Host  *shost = class_to_shost(dev);
3535 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3536 
3537 	return scnprintf(buf, PAGE_SIZE, "%d\n",	vport->cfg_devloss_tmo);
3538 }
3539 
3540 /**
3541  * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3542  * @vport: lpfc vport structure pointer.
3543  * @val: contains the nodev timeout value.
3544  *
3545  * Description:
3546  * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3547  * a kernel error message is printed and zero is returned.
3548  * Else if val is in range then nodev tmo and devloss tmo are set to val.
3549  * Otherwise nodev tmo is set to the default value.
3550  *
3551  * Returns:
3552  * zero if already set or if val is in range
3553  * -EINVAL val out of range
3554  **/
3555 static int
3556 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3557 {
3558 	if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3559 		vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3560 		if (val != LPFC_DEF_DEVLOSS_TMO)
3561 			lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3562 					 "0407 Ignoring lpfc_nodev_tmo module "
3563 					 "parameter because lpfc_devloss_tmo "
3564 					 "is set.\n");
3565 		return 0;
3566 	}
3567 
3568 	if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3569 		vport->cfg_nodev_tmo = val;
3570 		vport->cfg_devloss_tmo = val;
3571 		return 0;
3572 	}
3573 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3574 			 "0400 lpfc_nodev_tmo attribute cannot be set to"
3575 			 " %d, allowed range is [%d, %d]\n",
3576 			 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3577 	vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3578 	return -EINVAL;
3579 }
3580 
3581 /**
3582  * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3583  * @vport: lpfc vport structure pointer.
3584  *
3585  * Description:
3586  * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3587  **/
3588 static void
3589 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3590 {
3591 	struct Scsi_Host  *shost;
3592 	struct lpfc_nodelist  *ndlp;
3593 #if (IS_ENABLED(CONFIG_NVME_FC))
3594 	struct lpfc_nvme_rport *rport;
3595 	struct nvme_fc_remote_port *remoteport = NULL;
3596 #endif
3597 
3598 	shost = lpfc_shost_from_vport(vport);
3599 	spin_lock_irq(shost->host_lock);
3600 	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3601 		if (ndlp->rport)
3602 			ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3603 #if (IS_ENABLED(CONFIG_NVME_FC))
3604 		spin_lock(&ndlp->lock);
3605 		rport = lpfc_ndlp_get_nrport(ndlp);
3606 		if (rport)
3607 			remoteport = rport->remoteport;
3608 		spin_unlock(&ndlp->lock);
3609 		if (rport && remoteport)
3610 			nvme_fc_set_remoteport_devloss(remoteport,
3611 						       vport->cfg_devloss_tmo);
3612 #endif
3613 	}
3614 	spin_unlock_irq(shost->host_lock);
3615 }
3616 
3617 /**
3618  * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3619  * @vport: lpfc vport structure pointer.
3620  * @val: contains the tmo value.
3621  *
3622  * Description:
3623  * If the devloss tmo is already set or the vport dev loss tmo has changed
3624  * then a kernel error message is printed and zero is returned.
3625  * Else if val is in range then nodev tmo and devloss tmo are set to val.
3626  * Otherwise nodev tmo is set to the default value.
3627  *
3628  * Returns:
3629  * zero if already set or if val is in range
3630  * -EINVAL val out of range
3631  **/
3632 static int
3633 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3634 {
3635 	if (vport->dev_loss_tmo_changed ||
3636 	    (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3637 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3638 				 "0401 Ignoring change to lpfc_nodev_tmo "
3639 				 "because lpfc_devloss_tmo is set.\n");
3640 		return 0;
3641 	}
3642 	if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3643 		vport->cfg_nodev_tmo = val;
3644 		vport->cfg_devloss_tmo = val;
3645 		/*
3646 		 * For compat: set the fc_host dev loss so new rports
3647 		 * will get the value.
3648 		 */
3649 		fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3650 		lpfc_update_rport_devloss_tmo(vport);
3651 		return 0;
3652 	}
3653 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3654 			 "0403 lpfc_nodev_tmo attribute cannot be set to "
3655 			 "%d, allowed range is [%d, %d]\n",
3656 			 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3657 	return -EINVAL;
3658 }
3659 
3660 lpfc_vport_param_store(nodev_tmo)
3661 
3662 static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3663 
3664 /*
3665 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3666 # disappear until the timer expires. Value range is [0,255]. Default
3667 # value is 30.
3668 */
3669 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3670 MODULE_PARM_DESC(lpfc_devloss_tmo,
3671 		 "Seconds driver will hold I/O waiting "
3672 		 "for a device to come back");
3673 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3674 		      LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3675 lpfc_vport_param_show(devloss_tmo)
3676 
3677 /**
3678  * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3679  * @vport: lpfc vport structure pointer.
3680  * @val: contains the tmo value.
3681  *
3682  * Description:
3683  * If val is in a valid range then set the vport nodev tmo,
3684  * devloss tmo, also set the vport dev loss tmo changed flag.
3685  * Else a kernel error message is printed.
3686  *
3687  * Returns:
3688  * zero if val is in range
3689  * -EINVAL val out of range
3690  **/
3691 static int
3692 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3693 {
3694 	if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3695 		vport->cfg_nodev_tmo = val;
3696 		vport->cfg_devloss_tmo = val;
3697 		vport->dev_loss_tmo_changed = 1;
3698 		fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3699 		lpfc_update_rport_devloss_tmo(vport);
3700 		return 0;
3701 	}
3702 
3703 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3704 			 "0404 lpfc_devloss_tmo attribute cannot be set to "
3705 			 "%d, allowed range is [%d, %d]\n",
3706 			 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3707 	return -EINVAL;
3708 }
3709 
3710 lpfc_vport_param_store(devloss_tmo)
3711 static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3712 
3713 /*
3714  * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3715  * lpfc_suppress_rsp = 0  Disable
3716  * lpfc_suppress_rsp = 1  Enable (default)
3717  *
3718  */
3719 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3720 	    "Enable suppress rsp feature is firmware supports it");
3721 
3722 /*
3723  * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3724  * lpfc_nvmet_mrq = 0  driver will calcualte optimal number of RQ pairs
3725  * lpfc_nvmet_mrq = 1  use a single RQ pair
3726  * lpfc_nvmet_mrq >= 2  use specified RQ pairs for MRQ
3727  *
3728  */
3729 LPFC_ATTR_R(nvmet_mrq,
3730 	    LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3731 	    "Specify number of RQ pairs for processing NVMET cmds");
3732 
3733 /*
3734  * lpfc_nvmet_mrq_post: Specify number of RQ buffer to initially post
3735  * to each NVMET RQ. Range 64 to 2048, default is 512.
3736  */
3737 LPFC_ATTR_R(nvmet_mrq_post,
3738 	    LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3739 	    LPFC_NVMET_RQE_DEF_COUNT,
3740 	    "Specify number of RQ buffers to initially post");
3741 
3742 /*
3743  * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3744  * Supported Values:  1 - register just FCP
3745  *                    3 - register both FCP and NVME
3746  * Supported values are [1,3]. Default value is 3
3747  */
3748 LPFC_ATTR_R(enable_fc4_type, LPFC_DEF_ENBL_FC4_TYPE,
3749 	    LPFC_ENABLE_FCP, LPFC_MAX_ENBL_FC4_TYPE,
3750 	    "Enable FC4 Protocol support - FCP / NVME");
3751 
3752 /*
3753 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3754 # deluged with LOTS of information.
3755 # You can set a bit mask to record specific types of verbose messages:
3756 # See lpfc_logmsh.h for definitions.
3757 */
3758 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3759 		       "Verbose logging bit-mask");
3760 
3761 /*
3762 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3763 # objects that have been registered with the nameserver after login.
3764 */
3765 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3766 		  "Deregister nameserver objects before LOGO");
3767 
3768 /*
3769 # lun_queue_depth:  This parameter is used to limit the number of outstanding
3770 # commands per FCP LUN.
3771 */
3772 LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
3773 		  "Max number of FCP commands we can queue to a specific LUN");
3774 
3775 /*
3776 # tgt_queue_depth:  This parameter is used to limit the number of outstanding
3777 # commands per target port. Value range is [10,65535]. Default value is 65535.
3778 */
3779 static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3780 module_param(lpfc_tgt_queue_depth, uint, 0444);
3781 MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3782 lpfc_vport_param_show(tgt_queue_depth);
3783 lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3784 		      LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3785 
3786 /**
3787  * lpfc_tgt_queue_depth_set: Sets an attribute value.
3788  * @vport: lpfc vport structure pointer.
3789  * @val: integer attribute value.
3790  *
3791  * Description: Sets the parameter to the new value.
3792  *
3793  * Returns:
3794  * zero on success
3795  * -EINVAL if val is invalid
3796  */
3797 static int
3798 lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3799 {
3800 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3801 	struct lpfc_nodelist *ndlp;
3802 
3803 	if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3804 		return -EINVAL;
3805 
3806 	if (val == vport->cfg_tgt_queue_depth)
3807 		return 0;
3808 
3809 	spin_lock_irq(shost->host_lock);
3810 	vport->cfg_tgt_queue_depth = val;
3811 
3812 	/* Next loop thru nodelist and change cmd_qdepth */
3813 	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3814 		ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3815 
3816 	spin_unlock_irq(shost->host_lock);
3817 	return 0;
3818 }
3819 
3820 lpfc_vport_param_store(tgt_queue_depth);
3821 static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3822 
3823 /*
3824 # hba_queue_depth:  This parameter is used to limit the number of outstanding
3825 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3826 # value is greater than the maximum number of exchanges supported by the HBA,
3827 # then maximum number of exchanges supported by the HBA is used to determine
3828 # the hba_queue_depth.
3829 */
3830 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3831 	    "Max number of FCP commands we can queue to a lpfc HBA");
3832 
3833 /*
3834 # peer_port_login:  This parameter allows/prevents logins
3835 # between peer ports hosted on the same physical port.
3836 # When this parameter is set 0 peer ports of same physical port
3837 # are not allowed to login to each other.
3838 # When this parameter is set 1 peer ports of same physical port
3839 # are allowed to login to each other.
3840 # Default value of this parameter is 0.
3841 */
3842 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3843 		  "Allow peer ports on the same physical port to login to each "
3844 		  "other.");
3845 
3846 /*
3847 # restrict_login:  This parameter allows/prevents logins
3848 # between Virtual Ports and remote initiators.
3849 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3850 # other initiators and will attempt to PLOGI all remote ports.
3851 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3852 # remote ports and will not attempt to PLOGI to other initiators.
3853 # This parameter does not restrict to the physical port.
3854 # This parameter does not restrict logins to Fabric resident remote ports.
3855 # Default value of this parameter is 1.
3856 */
3857 static int lpfc_restrict_login = 1;
3858 module_param(lpfc_restrict_login, int, S_IRUGO);
3859 MODULE_PARM_DESC(lpfc_restrict_login,
3860 		 "Restrict virtual ports login to remote initiators.");
3861 lpfc_vport_param_show(restrict_login);
3862 
3863 /**
3864  * lpfc_restrict_login_init - Set the vport restrict login flag
3865  * @vport: lpfc vport structure pointer.
3866  * @val: contains the restrict login value.
3867  *
3868  * Description:
3869  * If val is not in a valid range then log a kernel error message and set
3870  * the vport restrict login to one.
3871  * If the port type is physical clear the restrict login flag and return.
3872  * Else set the restrict login flag to val.
3873  *
3874  * Returns:
3875  * zero if val is in range
3876  * -EINVAL val out of range
3877  **/
3878 static int
3879 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3880 {
3881 	if (val < 0 || val > 1) {
3882 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3883 				 "0422 lpfc_restrict_login attribute cannot "
3884 				 "be set to %d, allowed range is [0, 1]\n",
3885 				 val);
3886 		vport->cfg_restrict_login = 1;
3887 		return -EINVAL;
3888 	}
3889 	if (vport->port_type == LPFC_PHYSICAL_PORT) {
3890 		vport->cfg_restrict_login = 0;
3891 		return 0;
3892 	}
3893 	vport->cfg_restrict_login = val;
3894 	return 0;
3895 }
3896 
3897 /**
3898  * lpfc_restrict_login_set - Set the vport restrict login flag
3899  * @vport: lpfc vport structure pointer.
3900  * @val: contains the restrict login value.
3901  *
3902  * Description:
3903  * If val is not in a valid range then log a kernel error message and set
3904  * the vport restrict login to one.
3905  * If the port type is physical and the val is not zero log a kernel
3906  * error message, clear the restrict login flag and return zero.
3907  * Else set the restrict login flag to val.
3908  *
3909  * Returns:
3910  * zero if val is in range
3911  * -EINVAL val out of range
3912  **/
3913 static int
3914 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3915 {
3916 	if (val < 0 || val > 1) {
3917 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3918 				 "0425 lpfc_restrict_login attribute cannot "
3919 				 "be set to %d, allowed range is [0, 1]\n",
3920 				 val);
3921 		vport->cfg_restrict_login = 1;
3922 		return -EINVAL;
3923 	}
3924 	if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3925 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3926 				 "0468 lpfc_restrict_login must be 0 for "
3927 				 "Physical ports.\n");
3928 		vport->cfg_restrict_login = 0;
3929 		return 0;
3930 	}
3931 	vport->cfg_restrict_login = val;
3932 	return 0;
3933 }
3934 lpfc_vport_param_store(restrict_login);
3935 static DEVICE_ATTR_RW(lpfc_restrict_login);
3936 
3937 /*
3938 # Some disk devices have a "select ID" or "select Target" capability.
3939 # From a protocol standpoint "select ID" usually means select the
3940 # Fibre channel "ALPA".  In the FC-AL Profile there is an "informative
3941 # annex" which contains a table that maps a "select ID" (a number
3942 # between 0 and 7F) to an ALPA.  By default, for compatibility with
3943 # older drivers, the lpfc driver scans this table from low ALPA to high
3944 # ALPA.
3945 #
3946 # Turning on the scan-down variable (on  = 1, off = 0) will
3947 # cause the lpfc driver to use an inverted table, effectively
3948 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3949 #
3950 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3951 # and will not work across a fabric. Also this parameter will take
3952 # effect only in the case when ALPA map is not available.)
3953 */
3954 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3955 		  "Start scanning for devices from highest ALPA to lowest");
3956 
3957 /*
3958 # lpfc_topology:  link topology for init link
3959 #            0x0  = attempt loop mode then point-to-point
3960 #            0x01 = internal loopback mode
3961 #            0x02 = attempt point-to-point mode only
3962 #            0x04 = attempt loop mode only
3963 #            0x06 = attempt point-to-point mode then loop
3964 # Set point-to-point mode if you want to run as an N_Port.
3965 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3966 # Default value is 0.
3967 */
3968 LPFC_ATTR(topology, 0, 0, 6,
3969 	"Select Fibre Channel topology");
3970 
3971 /**
3972  * lpfc_topology_store - Set the adapters topology field
3973  * @dev: class device that is converted into a scsi_host.
3974  * @attr:device attribute, not used.
3975  * @buf: buffer for passing information.
3976  * @count: size of the data buffer.
3977  *
3978  * Description:
3979  * If val is in a valid range then set the adapter's topology field and
3980  * issue a lip; if the lip fails reset the topology to the old value.
3981  *
3982  * If the value is not in range log a kernel error message and return an error.
3983  *
3984  * Returns:
3985  * zero if val is in range and lip okay
3986  * non-zero return value from lpfc_issue_lip()
3987  * -EINVAL val out of range
3988  **/
3989 static ssize_t
3990 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3991 			const char *buf, size_t count)
3992 {
3993 	struct Scsi_Host  *shost = class_to_shost(dev);
3994 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3995 	struct lpfc_hba   *phba = vport->phba;
3996 	int val = 0;
3997 	int nolip = 0;
3998 	const char *val_buf = buf;
3999 	int err;
4000 	uint32_t prev_val;
4001 	u8 sli_family, if_type;
4002 
4003 	if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4004 		nolip = 1;
4005 		val_buf = &buf[strlen("nolip ")];
4006 	}
4007 
4008 	if (!isdigit(val_buf[0]))
4009 		return -EINVAL;
4010 	if (sscanf(val_buf, "%i", &val) != 1)
4011 		return -EINVAL;
4012 
4013 	if (val >= 0 && val <= 6) {
4014 		prev_val = phba->cfg_topology;
4015 		if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4016 			val == 4) {
4017 			lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4018 				"3113 Loop mode not supported at speed %d\n",
4019 				val);
4020 			return -EINVAL;
4021 		}
4022 		/*
4023 		 * The 'topology' is not a configurable parameter if :
4024 		 *   - persistent topology enabled
4025 		 *   - ASIC_GEN_NUM >= 0xC, with no private loop support
4026 		 */
4027 		sli_family = bf_get(lpfc_sli_intf_sli_family,
4028 				    &phba->sli4_hba.sli_intf);
4029 		if_type = bf_get(lpfc_sli_intf_if_type,
4030 				 &phba->sli4_hba.sli_intf);
4031 		if ((phba->hba_flag & HBA_PERSISTENT_TOPO ||
4032 		    (!phba->sli4_hba.pc_sli4_params.pls &&
4033 		     (sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
4034 		      if_type == LPFC_SLI_INTF_IF_TYPE_6))) &&
4035 		    val == 4) {
4036 			lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4037 				"3114 Loop mode not supported\n");
4038 			return -EINVAL;
4039 		}
4040 		phba->cfg_topology = val;
4041 		if (nolip)
4042 			return strlen(buf);
4043 
4044 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4045 			"3054 lpfc_topology changed from %d to %d\n",
4046 			prev_val, val);
4047 		if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4048 			phba->fc_topology_changed = 1;
4049 		err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4050 		if (err) {
4051 			phba->cfg_topology = prev_val;
4052 			return -EINVAL;
4053 		} else
4054 			return strlen(buf);
4055 	}
4056 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4057 		"%d:0467 lpfc_topology attribute cannot be set to %d, "
4058 		"allowed range is [0, 6]\n",
4059 		phba->brd_no, val);
4060 	return -EINVAL;
4061 }
4062 
4063 lpfc_param_show(topology)
4064 static DEVICE_ATTR_RW(lpfc_topology);
4065 
4066 /**
4067  * lpfc_static_vport_show: Read callback function for
4068  *   lpfc_static_vport sysfs file.
4069  * @dev: Pointer to class device object.
4070  * @attr: device attribute structure.
4071  * @buf: Data buffer.
4072  *
4073  * This function is the read call back function for
4074  * lpfc_static_vport sysfs file. The lpfc_static_vport
4075  * sysfs file report the mageability of the vport.
4076  **/
4077 static ssize_t
4078 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4079 			 char *buf)
4080 {
4081 	struct Scsi_Host  *shost = class_to_shost(dev);
4082 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4083 	if (vport->vport_flag & STATIC_VPORT)
4084 		sprintf(buf, "1\n");
4085 	else
4086 		sprintf(buf, "0\n");
4087 
4088 	return strlen(buf);
4089 }
4090 
4091 /*
4092  * Sysfs attribute to control the statistical data collection.
4093  */
4094 static DEVICE_ATTR_RO(lpfc_static_vport);
4095 
4096 /*
4097 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4098 # connection.
4099 # Value range is [0,16]. Default value is 0.
4100 */
4101 /**
4102  * lpfc_link_speed_store - Set the adapters link speed
4103  * @dev: Pointer to class device.
4104  * @attr: Unused.
4105  * @buf: Data buffer.
4106  * @count: Size of the data buffer.
4107  *
4108  * Description:
4109  * If val is in a valid range then set the adapter's link speed field and
4110  * issue a lip; if the lip fails reset the link speed to the old value.
4111  *
4112  * Notes:
4113  * If the value is not in range log a kernel error message and return an error.
4114  *
4115  * Returns:
4116  * zero if val is in range and lip okay.
4117  * non-zero return value from lpfc_issue_lip()
4118  * -EINVAL val out of range
4119  **/
4120 static ssize_t
4121 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4122 		const char *buf, size_t count)
4123 {
4124 	struct Scsi_Host  *shost = class_to_shost(dev);
4125 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4126 	struct lpfc_hba   *phba = vport->phba;
4127 	int val = LPFC_USER_LINK_SPEED_AUTO;
4128 	int nolip = 0;
4129 	const char *val_buf = buf;
4130 	int err;
4131 	uint32_t prev_val, if_type;
4132 
4133 	if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4134 	if (if_type >= LPFC_SLI_INTF_IF_TYPE_2 &&
4135 	    phba->hba_flag & HBA_FORCED_LINK_SPEED)
4136 		return -EPERM;
4137 
4138 	if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4139 		nolip = 1;
4140 		val_buf = &buf[strlen("nolip ")];
4141 	}
4142 
4143 	if (!isdigit(val_buf[0]))
4144 		return -EINVAL;
4145 	if (sscanf(val_buf, "%i", &val) != 1)
4146 		return -EINVAL;
4147 
4148 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4149 		"3055 lpfc_link_speed changed from %d to %d %s\n",
4150 		phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4151 
4152 	if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4153 	    ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4154 	    ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4155 	    ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4156 	    ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4157 	    ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4158 	    ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb)) ||
4159 	    ((val == LPFC_USER_LINK_SPEED_64G) && !(phba->lmt & LMT_64Gb))) {
4160 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4161 				"2879 lpfc_link_speed attribute cannot be set "
4162 				"to %d. Speed is not supported by this port.\n",
4163 				val);
4164 		return -EINVAL;
4165 	}
4166 	if (val >= LPFC_USER_LINK_SPEED_16G &&
4167 	    phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4168 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4169 				"3112 lpfc_link_speed attribute cannot be set "
4170 				"to %d. Speed is not supported in loop mode.\n",
4171 				val);
4172 		return -EINVAL;
4173 	}
4174 
4175 	switch (val) {
4176 	case LPFC_USER_LINK_SPEED_AUTO:
4177 	case LPFC_USER_LINK_SPEED_1G:
4178 	case LPFC_USER_LINK_SPEED_2G:
4179 	case LPFC_USER_LINK_SPEED_4G:
4180 	case LPFC_USER_LINK_SPEED_8G:
4181 	case LPFC_USER_LINK_SPEED_16G:
4182 	case LPFC_USER_LINK_SPEED_32G:
4183 	case LPFC_USER_LINK_SPEED_64G:
4184 		prev_val = phba->cfg_link_speed;
4185 		phba->cfg_link_speed = val;
4186 		if (nolip)
4187 			return strlen(buf);
4188 
4189 		err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4190 		if (err) {
4191 			phba->cfg_link_speed = prev_val;
4192 			return -EINVAL;
4193 		}
4194 		return strlen(buf);
4195 	default:
4196 		break;
4197 	}
4198 
4199 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4200 			"0469 lpfc_link_speed attribute cannot be set to %d, "
4201 			"allowed values are [%s]\n",
4202 			val, LPFC_LINK_SPEED_STRING);
4203 	return -EINVAL;
4204 
4205 }
4206 
4207 static int lpfc_link_speed = 0;
4208 module_param(lpfc_link_speed, int, S_IRUGO);
4209 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4210 lpfc_param_show(link_speed)
4211 
4212 /**
4213  * lpfc_link_speed_init - Set the adapters link speed
4214  * @phba: lpfc_hba pointer.
4215  * @val: link speed value.
4216  *
4217  * Description:
4218  * If val is in a valid range then set the adapter's link speed field.
4219  *
4220  * Notes:
4221  * If the value is not in range log a kernel error message, clear the link
4222  * speed and return an error.
4223  *
4224  * Returns:
4225  * zero if val saved.
4226  * -EINVAL val out of range
4227  **/
4228 static int
4229 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4230 {
4231 	if (val >= LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4232 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4233 			"3111 lpfc_link_speed of %d cannot "
4234 			"support loop mode, setting topology to default.\n",
4235 			 val);
4236 		phba->cfg_topology = 0;
4237 	}
4238 
4239 	switch (val) {
4240 	case LPFC_USER_LINK_SPEED_AUTO:
4241 	case LPFC_USER_LINK_SPEED_1G:
4242 	case LPFC_USER_LINK_SPEED_2G:
4243 	case LPFC_USER_LINK_SPEED_4G:
4244 	case LPFC_USER_LINK_SPEED_8G:
4245 	case LPFC_USER_LINK_SPEED_16G:
4246 	case LPFC_USER_LINK_SPEED_32G:
4247 	case LPFC_USER_LINK_SPEED_64G:
4248 		phba->cfg_link_speed = val;
4249 		return 0;
4250 	default:
4251 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4252 				"0405 lpfc_link_speed attribute cannot "
4253 				"be set to %d, allowed values are "
4254 				"["LPFC_LINK_SPEED_STRING"]\n", val);
4255 		phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4256 		return -EINVAL;
4257 	}
4258 }
4259 
4260 static DEVICE_ATTR_RW(lpfc_link_speed);
4261 
4262 /*
4263 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4264 #       0  = aer disabled or not supported
4265 #       1  = aer supported and enabled (default)
4266 # Value range is [0,1]. Default value is 1.
4267 */
4268 LPFC_ATTR(aer_support, 1, 0, 1,
4269 	"Enable PCIe device AER support");
4270 lpfc_param_show(aer_support)
4271 
4272 /**
4273  * lpfc_aer_support_store - Set the adapter for aer support
4274  *
4275  * @dev: class device that is converted into a Scsi_host.
4276  * @attr: device attribute, not used.
4277  * @buf: containing enable or disable aer flag.
4278  * @count: unused variable.
4279  *
4280  * Description:
4281  * If the val is 1 and currently the device's AER capability was not
4282  * enabled, invoke the kernel's enable AER helper routine, trying to
4283  * enable the device's AER capability. If the helper routine enabling
4284  * AER returns success, update the device's cfg_aer_support flag to
4285  * indicate AER is supported by the device; otherwise, if the device
4286  * AER capability is already enabled to support AER, then do nothing.
4287  *
4288  * If the val is 0 and currently the device's AER support was enabled,
4289  * invoke the kernel's disable AER helper routine. After that, update
4290  * the device's cfg_aer_support flag to indicate AER is not supported
4291  * by the device; otherwise, if the device AER capability is already
4292  * disabled from supporting AER, then do nothing.
4293  *
4294  * Returns:
4295  * length of the buf on success if val is in range the intended mode
4296  * is supported.
4297  * -EINVAL if val out of range or intended mode is not supported.
4298  **/
4299 static ssize_t
4300 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4301 		       const char *buf, size_t count)
4302 {
4303 	struct Scsi_Host *shost = class_to_shost(dev);
4304 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4305 	struct lpfc_hba *phba = vport->phba;
4306 	int val = 0, rc = -EINVAL;
4307 
4308 	if (!isdigit(buf[0]))
4309 		return -EINVAL;
4310 	if (sscanf(buf, "%i", &val) != 1)
4311 		return -EINVAL;
4312 
4313 	switch (val) {
4314 	case 0:
4315 		if (phba->hba_flag & HBA_AER_ENABLED) {
4316 			rc = pci_disable_pcie_error_reporting(phba->pcidev);
4317 			if (!rc) {
4318 				spin_lock_irq(&phba->hbalock);
4319 				phba->hba_flag &= ~HBA_AER_ENABLED;
4320 				spin_unlock_irq(&phba->hbalock);
4321 				phba->cfg_aer_support = 0;
4322 				rc = strlen(buf);
4323 			} else
4324 				rc = -EPERM;
4325 		} else {
4326 			phba->cfg_aer_support = 0;
4327 			rc = strlen(buf);
4328 		}
4329 		break;
4330 	case 1:
4331 		if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4332 			rc = pci_enable_pcie_error_reporting(phba->pcidev);
4333 			if (!rc) {
4334 				spin_lock_irq(&phba->hbalock);
4335 				phba->hba_flag |= HBA_AER_ENABLED;
4336 				spin_unlock_irq(&phba->hbalock);
4337 				phba->cfg_aer_support = 1;
4338 				rc = strlen(buf);
4339 			} else
4340 				 rc = -EPERM;
4341 		} else {
4342 			phba->cfg_aer_support = 1;
4343 			rc = strlen(buf);
4344 		}
4345 		break;
4346 	default:
4347 		rc = -EINVAL;
4348 		break;
4349 	}
4350 	return rc;
4351 }
4352 
4353 static DEVICE_ATTR_RW(lpfc_aer_support);
4354 
4355 /**
4356  * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4357  * @dev: class device that is converted into a Scsi_host.
4358  * @attr: device attribute, not used.
4359  * @buf: containing flag 1 for aer cleanup state.
4360  * @count: unused variable.
4361  *
4362  * Description:
4363  * If the @buf contains 1 and the device currently has the AER support
4364  * enabled, then invokes the kernel AER helper routine
4365  * pci_aer_clear_nonfatal_status() to clean up the uncorrectable
4366  * error status register.
4367  *
4368  * Notes:
4369  *
4370  * Returns:
4371  * -EINVAL if the buf does not contain the 1 or the device is not currently
4372  * enabled with the AER support.
4373  **/
4374 static ssize_t
4375 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4376 		       const char *buf, size_t count)
4377 {
4378 	struct Scsi_Host  *shost = class_to_shost(dev);
4379 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4380 	struct lpfc_hba   *phba = vport->phba;
4381 	int val, rc = -1;
4382 
4383 	if (!isdigit(buf[0]))
4384 		return -EINVAL;
4385 	if (sscanf(buf, "%i", &val) != 1)
4386 		return -EINVAL;
4387 	if (val != 1)
4388 		return -EINVAL;
4389 
4390 	if (phba->hba_flag & HBA_AER_ENABLED)
4391 		rc = pci_aer_clear_nonfatal_status(phba->pcidev);
4392 
4393 	if (rc == 0)
4394 		return strlen(buf);
4395 	else
4396 		return -EPERM;
4397 }
4398 
4399 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4400 		   lpfc_aer_cleanup_state);
4401 
4402 /**
4403  * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4404  *
4405  * @dev: class device that is converted into a Scsi_host.
4406  * @attr: device attribute, not used.
4407  * @buf: containing the string the number of vfs to be enabled.
4408  * @count: unused variable.
4409  *
4410  * Description:
4411  * When this api is called either through user sysfs, the driver shall
4412  * try to enable or disable SR-IOV virtual functions according to the
4413  * following:
4414  *
4415  * If zero virtual function has been enabled to the physical function,
4416  * the driver shall invoke the pci enable virtual function api trying
4417  * to enable the virtual functions. If the nr_vfn provided is greater
4418  * than the maximum supported, the maximum virtual function number will
4419  * be used for invoking the api; otherwise, the nr_vfn provided shall
4420  * be used for invoking the api. If the api call returned success, the
4421  * actual number of virtual functions enabled will be set to the driver
4422  * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4423  * cfg_sriov_nr_virtfn remains zero.
4424  *
4425  * If none-zero virtual functions have already been enabled to the
4426  * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4427  * -EINVAL will be returned and the driver does nothing;
4428  *
4429  * If the nr_vfn provided is zero and none-zero virtual functions have
4430  * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4431  * disabling virtual function api shall be invoded to disable all the
4432  * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4433  * zero. Otherwise, if zero virtual function has been enabled, do
4434  * nothing.
4435  *
4436  * Returns:
4437  * length of the buf on success if val is in range the intended mode
4438  * is supported.
4439  * -EINVAL if val out of range or intended mode is not supported.
4440  **/
4441 static ssize_t
4442 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4443 			 const char *buf, size_t count)
4444 {
4445 	struct Scsi_Host *shost = class_to_shost(dev);
4446 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4447 	struct lpfc_hba *phba = vport->phba;
4448 	struct pci_dev *pdev = phba->pcidev;
4449 	int val = 0, rc = -EINVAL;
4450 
4451 	/* Sanity check on user data */
4452 	if (!isdigit(buf[0]))
4453 		return -EINVAL;
4454 	if (sscanf(buf, "%i", &val) != 1)
4455 		return -EINVAL;
4456 	if (val < 0)
4457 		return -EINVAL;
4458 
4459 	/* Request disabling virtual functions */
4460 	if (val == 0) {
4461 		if (phba->cfg_sriov_nr_virtfn > 0) {
4462 			pci_disable_sriov(pdev);
4463 			phba->cfg_sriov_nr_virtfn = 0;
4464 		}
4465 		return strlen(buf);
4466 	}
4467 
4468 	/* Request enabling virtual functions */
4469 	if (phba->cfg_sriov_nr_virtfn > 0) {
4470 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4471 				"3018 There are %d virtual functions "
4472 				"enabled on physical function.\n",
4473 				phba->cfg_sriov_nr_virtfn);
4474 		return -EEXIST;
4475 	}
4476 
4477 	if (val <= LPFC_MAX_VFN_PER_PFN)
4478 		phba->cfg_sriov_nr_virtfn = val;
4479 	else {
4480 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4481 				"3019 Enabling %d virtual functions is not "
4482 				"allowed.\n", val);
4483 		return -EINVAL;
4484 	}
4485 
4486 	rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4487 	if (rc) {
4488 		phba->cfg_sriov_nr_virtfn = 0;
4489 		rc = -EPERM;
4490 	} else
4491 		rc = strlen(buf);
4492 
4493 	return rc;
4494 }
4495 
4496 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4497 	"Enable PCIe device SR-IOV virtual fn");
4498 
4499 lpfc_param_show(sriov_nr_virtfn)
4500 static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
4501 
4502 /**
4503  * lpfc_request_firmware_upgrade_store - Request for Linux generic firmware upgrade
4504  *
4505  * @dev: class device that is converted into a Scsi_host.
4506  * @attr: device attribute, not used.
4507  * @buf: containing the string the number of vfs to be enabled.
4508  * @count: unused variable.
4509  *
4510  * Description:
4511  *
4512  * Returns:
4513  * length of the buf on success if val is in range the intended mode
4514  * is supported.
4515  * -EINVAL if val out of range or intended mode is not supported.
4516  **/
4517 static ssize_t
4518 lpfc_request_firmware_upgrade_store(struct device *dev,
4519 				    struct device_attribute *attr,
4520 				    const char *buf, size_t count)
4521 {
4522 	struct Scsi_Host *shost = class_to_shost(dev);
4523 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4524 	struct lpfc_hba *phba = vport->phba;
4525 	int val = 0, rc;
4526 
4527 	/* Sanity check on user data */
4528 	if (!isdigit(buf[0]))
4529 		return -EINVAL;
4530 	if (sscanf(buf, "%i", &val) != 1)
4531 		return -EINVAL;
4532 	if (val != 1)
4533 		return -EINVAL;
4534 
4535 	rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4536 	if (rc)
4537 		rc = -EPERM;
4538 	else
4539 		rc = strlen(buf);
4540 	return rc;
4541 }
4542 
4543 static int lpfc_req_fw_upgrade;
4544 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4545 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4546 lpfc_param_show(request_firmware_upgrade)
4547 
4548 /**
4549  * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4550  * @phba: lpfc_hba pointer.
4551  * @val: 0 or 1.
4552  *
4553  * Description:
4554  * Set the initial Linux generic firmware upgrade enable or disable flag.
4555  *
4556  * Returns:
4557  * zero if val saved.
4558  * -EINVAL val out of range
4559  **/
4560 static int
4561 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4562 {
4563 	if (val >= 0 && val <= 1) {
4564 		phba->cfg_request_firmware_upgrade = val;
4565 		return 0;
4566 	}
4567 	return -EINVAL;
4568 }
4569 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4570 		   lpfc_request_firmware_upgrade_show,
4571 		   lpfc_request_firmware_upgrade_store);
4572 
4573 /**
4574  * lpfc_force_rscn_store
4575  *
4576  * @dev: class device that is converted into a Scsi_host.
4577  * @attr: device attribute, not used.
4578  * @buf: unused string
4579  * @count: unused variable.
4580  *
4581  * Description:
4582  * Force the switch to send a RSCN to all other NPorts in our zone
4583  * If we are direct connect pt2pt, build the RSCN command ourself
4584  * and send to the other NPort. Not supported for private loop.
4585  *
4586  * Returns:
4587  * 0      - on success
4588  * -EIO   - if command is not sent
4589  **/
4590 static ssize_t
4591 lpfc_force_rscn_store(struct device *dev, struct device_attribute *attr,
4592 		      const char *buf, size_t count)
4593 {
4594 	struct Scsi_Host *shost = class_to_shost(dev);
4595 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4596 	int i;
4597 
4598 	i = lpfc_issue_els_rscn(vport, 0);
4599 	if (i)
4600 		return -EIO;
4601 	return strlen(buf);
4602 }
4603 
4604 /*
4605  * lpfc_force_rscn: Force an RSCN to be sent to all remote NPorts
4606  * connected to  the HBA.
4607  *
4608  * Value range is any ascii value
4609  */
4610 static int lpfc_force_rscn;
4611 module_param(lpfc_force_rscn, int, 0644);
4612 MODULE_PARM_DESC(lpfc_force_rscn,
4613 		 "Force an RSCN to be sent to all remote NPorts");
4614 lpfc_param_show(force_rscn)
4615 
4616 /**
4617  * lpfc_force_rscn_init - Force an RSCN to be sent to all remote NPorts
4618  * @phba: lpfc_hba pointer.
4619  * @val: unused value.
4620  *
4621  * Returns:
4622  * zero if val saved.
4623  **/
4624 static int
4625 lpfc_force_rscn_init(struct lpfc_hba *phba, int val)
4626 {
4627 	return 0;
4628 }
4629 static DEVICE_ATTR_RW(lpfc_force_rscn);
4630 
4631 /**
4632  * lpfc_fcp_imax_store
4633  *
4634  * @dev: class device that is converted into a Scsi_host.
4635  * @attr: device attribute, not used.
4636  * @buf: string with the number of fast-path FCP interrupts per second.
4637  * @count: unused variable.
4638  *
4639  * Description:
4640  * If val is in a valid range [636,651042], then set the adapter's
4641  * maximum number of fast-path FCP interrupts per second.
4642  *
4643  * Returns:
4644  * length of the buf on success if val is in range the intended mode
4645  * is supported.
4646  * -EINVAL if val out of range or intended mode is not supported.
4647  **/
4648 static ssize_t
4649 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4650 			 const char *buf, size_t count)
4651 {
4652 	struct Scsi_Host *shost = class_to_shost(dev);
4653 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4654 	struct lpfc_hba *phba = vport->phba;
4655 	struct lpfc_eq_intr_info *eqi;
4656 	uint32_t usdelay;
4657 	int val = 0, i;
4658 
4659 	/* fcp_imax is only valid for SLI4 */
4660 	if (phba->sli_rev != LPFC_SLI_REV4)
4661 		return -EINVAL;
4662 
4663 	/* Sanity check on user data */
4664 	if (!isdigit(buf[0]))
4665 		return -EINVAL;
4666 	if (sscanf(buf, "%i", &val) != 1)
4667 		return -EINVAL;
4668 
4669 	/*
4670 	 * Value range for the HBA is [5000,5000000]
4671 	 * The value for each EQ depends on how many EQs are configured.
4672 	 * Allow value == 0
4673 	 */
4674 	if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4675 		return -EINVAL;
4676 
4677 	phba->cfg_auto_imax = (val) ? 0 : 1;
4678 	if (phba->cfg_fcp_imax && !val) {
4679 		queue_delayed_work(phba->wq, &phba->eq_delay_work,
4680 				   msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
4681 
4682 		for_each_present_cpu(i) {
4683 			eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i);
4684 			eqi->icnt = 0;
4685 		}
4686 	}
4687 
4688 	phba->cfg_fcp_imax = (uint32_t)val;
4689 
4690 	if (phba->cfg_fcp_imax)
4691 		usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax;
4692 	else
4693 		usdelay = 0;
4694 
4695 	for (i = 0; i < phba->cfg_irq_chann; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4696 		lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4697 					 usdelay);
4698 
4699 	return strlen(buf);
4700 }
4701 
4702 /*
4703 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4704 # for the HBA.
4705 #
4706 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4707 */
4708 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4709 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4710 MODULE_PARM_DESC(lpfc_fcp_imax,
4711 	    "Set the maximum number of FCP interrupts per second per HBA");
4712 lpfc_param_show(fcp_imax)
4713 
4714 /**
4715  * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4716  * @phba: lpfc_hba pointer.
4717  * @val: link speed value.
4718  *
4719  * Description:
4720  * If val is in a valid range [636,651042], then initialize the adapter's
4721  * maximum number of fast-path FCP interrupts per second.
4722  *
4723  * Returns:
4724  * zero if val saved.
4725  * -EINVAL val out of range
4726  **/
4727 static int
4728 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4729 {
4730 	if (phba->sli_rev != LPFC_SLI_REV4) {
4731 		phba->cfg_fcp_imax = 0;
4732 		return 0;
4733 	}
4734 
4735 	if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4736 	    (val == 0)) {
4737 		phba->cfg_fcp_imax = val;
4738 		return 0;
4739 	}
4740 
4741 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4742 			"3016 lpfc_fcp_imax: %d out of range, using default\n",
4743 			val);
4744 	phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4745 
4746 	return 0;
4747 }
4748 
4749 static DEVICE_ATTR_RW(lpfc_fcp_imax);
4750 
4751 /**
4752  * lpfc_cq_max_proc_limit_store
4753  *
4754  * @dev: class device that is converted into a Scsi_host.
4755  * @attr: device attribute, not used.
4756  * @buf: string with the cq max processing limit of cqes
4757  * @count: unused variable.
4758  *
4759  * Description:
4760  * If val is in a valid range, then set value on each cq
4761  *
4762  * Returns:
4763  * The length of the buf: if successful
4764  * -ERANGE: if val is not in the valid range
4765  * -EINVAL: if bad value format or intended mode is not supported.
4766  **/
4767 static ssize_t
4768 lpfc_cq_max_proc_limit_store(struct device *dev, struct device_attribute *attr,
4769 			 const char *buf, size_t count)
4770 {
4771 	struct Scsi_Host *shost = class_to_shost(dev);
4772 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4773 	struct lpfc_hba *phba = vport->phba;
4774 	struct lpfc_queue *eq, *cq;
4775 	unsigned long val;
4776 	int i;
4777 
4778 	/* cq_max_proc_limit is only valid for SLI4 */
4779 	if (phba->sli_rev != LPFC_SLI_REV4)
4780 		return -EINVAL;
4781 
4782 	/* Sanity check on user data */
4783 	if (!isdigit(buf[0]))
4784 		return -EINVAL;
4785 	if (kstrtoul(buf, 0, &val))
4786 		return -EINVAL;
4787 
4788 	if (val < LPFC_CQ_MIN_PROC_LIMIT || val > LPFC_CQ_MAX_PROC_LIMIT)
4789 		return -ERANGE;
4790 
4791 	phba->cfg_cq_max_proc_limit = (uint32_t)val;
4792 
4793 	/* set the values on the cq's */
4794 	for (i = 0; i < phba->cfg_irq_chann; i++) {
4795 		/* Get the EQ corresponding to the IRQ vector */
4796 		eq = phba->sli4_hba.hba_eq_hdl[i].eq;
4797 		if (!eq)
4798 			continue;
4799 
4800 		list_for_each_entry(cq, &eq->child_list, list)
4801 			cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
4802 						 cq->entry_count);
4803 	}
4804 
4805 	return strlen(buf);
4806 }
4807 
4808 /*
4809  * lpfc_cq_max_proc_limit: The maximum number CQE entries processed in an
4810  *   itteration of CQ processing.
4811  */
4812 static int lpfc_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4813 module_param(lpfc_cq_max_proc_limit, int, 0644);
4814 MODULE_PARM_DESC(lpfc_cq_max_proc_limit,
4815 	    "Set the maximum number CQEs processed in an iteration of "
4816 	    "CQ processing");
4817 lpfc_param_show(cq_max_proc_limit)
4818 
4819 /*
4820  * lpfc_cq_poll_threshold: Set the threshold of CQE completions in a
4821  *   single handler call which should request a polled completion rather
4822  *   than re-enabling interrupts.
4823  */
4824 LPFC_ATTR_RW(cq_poll_threshold, LPFC_CQ_DEF_THRESHOLD_TO_POLL,
4825 	     LPFC_CQ_MIN_THRESHOLD_TO_POLL,
4826 	     LPFC_CQ_MAX_THRESHOLD_TO_POLL,
4827 	     "CQE Processing Threshold to enable Polling");
4828 
4829 /**
4830  * lpfc_cq_max_proc_limit_init - Set the initial cq max_proc_limit
4831  * @phba: lpfc_hba pointer.
4832  * @val: entry limit
4833  *
4834  * Description:
4835  * If val is in a valid range, then initialize the adapter's maximum
4836  * value.
4837  *
4838  * Returns:
4839  *  Always returns 0 for success, even if value not always set to
4840  *  requested value. If value out of range or not supported, will fall
4841  *  back to default.
4842  **/
4843 static int
4844 lpfc_cq_max_proc_limit_init(struct lpfc_hba *phba, int val)
4845 {
4846 	phba->cfg_cq_max_proc_limit = LPFC_CQ_DEF_MAX_PROC_LIMIT;
4847 
4848 	if (phba->sli_rev != LPFC_SLI_REV4)
4849 		return 0;
4850 
4851 	if (val >= LPFC_CQ_MIN_PROC_LIMIT && val <= LPFC_CQ_MAX_PROC_LIMIT) {
4852 		phba->cfg_cq_max_proc_limit = val;
4853 		return 0;
4854 	}
4855 
4856 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4857 			"0371 lpfc_cq_max_proc_limit: %d out of range, using "
4858 			"default\n",
4859 			phba->cfg_cq_max_proc_limit);
4860 
4861 	return 0;
4862 }
4863 
4864 static DEVICE_ATTR_RW(lpfc_cq_max_proc_limit);
4865 
4866 /**
4867  * lpfc_fcp_cpu_map_show - Display current driver CPU affinity
4868  * @dev: class converted to a Scsi_host structure.
4869  * @attr: device attribute, not used.
4870  * @buf: on return contains text describing the state of the link.
4871  *
4872  * Returns: size of formatted string.
4873  **/
4874 static ssize_t
4875 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4876 		      char *buf)
4877 {
4878 	struct Scsi_Host  *shost = class_to_shost(dev);
4879 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4880 	struct lpfc_hba   *phba = vport->phba;
4881 	struct lpfc_vector_map_info *cpup;
4882 	int  len = 0;
4883 
4884 	if ((phba->sli_rev != LPFC_SLI_REV4) ||
4885 	    (phba->intr_type != MSIX))
4886 		return len;
4887 
4888 	switch (phba->cfg_fcp_cpu_map) {
4889 	case 0:
4890 		len += scnprintf(buf + len, PAGE_SIZE-len,
4891 				"fcp_cpu_map: No mapping (%d)\n",
4892 				phba->cfg_fcp_cpu_map);
4893 		return len;
4894 	case 1:
4895 		len += scnprintf(buf + len, PAGE_SIZE-len,
4896 				"fcp_cpu_map: HBA centric mapping (%d): "
4897 				"%d of %d CPUs online from %d possible CPUs\n",
4898 				phba->cfg_fcp_cpu_map, num_online_cpus(),
4899 				num_present_cpus(),
4900 				phba->sli4_hba.num_possible_cpu);
4901 		break;
4902 	}
4903 
4904 	while (phba->sli4_hba.curr_disp_cpu <
4905 	       phba->sli4_hba.num_possible_cpu) {
4906 		cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4907 
4908 		if (!cpu_present(phba->sli4_hba.curr_disp_cpu))
4909 			len += scnprintf(buf + len, PAGE_SIZE - len,
4910 					"CPU %02d not present\n",
4911 					phba->sli4_hba.curr_disp_cpu);
4912 		else if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) {
4913 			if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
4914 				len += scnprintf(
4915 					buf + len, PAGE_SIZE - len,
4916 					"CPU %02d hdwq None "
4917 					"physid %d coreid %d ht %d ua %d\n",
4918 					phba->sli4_hba.curr_disp_cpu,
4919 					cpup->phys_id, cpup->core_id,
4920 					(cpup->flag & LPFC_CPU_MAP_HYPER),
4921 					(cpup->flag & LPFC_CPU_MAP_UNASSIGN));
4922 			else
4923 				len += scnprintf(
4924 					buf + len, PAGE_SIZE - len,
4925 					"CPU %02d EQ None hdwq %04d "
4926 					"physid %d coreid %d ht %d ua %d\n",
4927 					phba->sli4_hba.curr_disp_cpu,
4928 					cpup->hdwq, cpup->phys_id,
4929 					cpup->core_id,
4930 					(cpup->flag & LPFC_CPU_MAP_HYPER),
4931 					(cpup->flag & LPFC_CPU_MAP_UNASSIGN));
4932 		} else {
4933 			if (cpup->hdwq == LPFC_VECTOR_MAP_EMPTY)
4934 				len += scnprintf(
4935 					buf + len, PAGE_SIZE - len,
4936 					"CPU %02d hdwq None "
4937 					"physid %d coreid %d ht %d ua %d IRQ %d\n",
4938 					phba->sli4_hba.curr_disp_cpu,
4939 					cpup->phys_id,
4940 					cpup->core_id,
4941 					(cpup->flag & LPFC_CPU_MAP_HYPER),
4942 					(cpup->flag & LPFC_CPU_MAP_UNASSIGN),
4943 					lpfc_get_irq(cpup->eq));
4944 			else
4945 				len += scnprintf(
4946 					buf + len, PAGE_SIZE - len,
4947 					"CPU %02d EQ %04d hdwq %04d "
4948 					"physid %d coreid %d ht %d ua %d IRQ %d\n",
4949 					phba->sli4_hba.curr_disp_cpu,
4950 					cpup->eq, cpup->hdwq, cpup->phys_id,
4951 					cpup->core_id,
4952 					(cpup->flag & LPFC_CPU_MAP_HYPER),
4953 					(cpup->flag & LPFC_CPU_MAP_UNASSIGN),
4954 					lpfc_get_irq(cpup->eq));
4955 		}
4956 
4957 		phba->sli4_hba.curr_disp_cpu++;
4958 
4959 		/* display max number of CPUs keeping some margin */
4960 		if (phba->sli4_hba.curr_disp_cpu <
4961 				phba->sli4_hba.num_possible_cpu &&
4962 				(len >= (PAGE_SIZE - 64))) {
4963 			len += scnprintf(buf + len,
4964 					PAGE_SIZE - len, "more...\n");
4965 			break;
4966 		}
4967 	}
4968 
4969 	if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_possible_cpu)
4970 		phba->sli4_hba.curr_disp_cpu = 0;
4971 
4972 	return len;
4973 }
4974 
4975 /**
4976  * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4977  * @dev: class device that is converted into a Scsi_host.
4978  * @attr: device attribute, not used.
4979  * @buf: one or more lpfc_polling_flags values.
4980  * @count: not used.
4981  *
4982  * Returns:
4983  * -EINVAL  - Not implemented yet.
4984  **/
4985 static ssize_t
4986 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4987 		       const char *buf, size_t count)
4988 {
4989 	return -EINVAL;
4990 }
4991 
4992 /*
4993 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4994 # for the HBA.
4995 #
4996 # Value range is [0 to 1]. Default value is LPFC_HBA_CPU_MAP (1).
4997 #	0 - Do not affinitze IRQ vectors
4998 #	1 - Affintize HBA vectors with respect to each HBA
4999 #	    (start with CPU0 for each HBA)
5000 # This also defines how Hardware Queues are mapped to specific CPUs.
5001 */
5002 static int lpfc_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5003 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
5004 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
5005 		 "Defines how to map CPUs to IRQ vectors per HBA");
5006 
5007 /**
5008  * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
5009  * @phba: lpfc_hba pointer.
5010  * @val: link speed value.
5011  *
5012  * Description:
5013  * If val is in a valid range [0-2], then affinitze the adapter's
5014  * MSIX vectors.
5015  *
5016  * Returns:
5017  * zero if val saved.
5018  * -EINVAL val out of range
5019  **/
5020 static int
5021 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
5022 {
5023 	if (phba->sli_rev != LPFC_SLI_REV4) {
5024 		phba->cfg_fcp_cpu_map = 0;
5025 		return 0;
5026 	}
5027 
5028 	if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
5029 		phba->cfg_fcp_cpu_map = val;
5030 		return 0;
5031 	}
5032 
5033 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5034 			"3326 lpfc_fcp_cpu_map: %d out of range, using "
5035 			"default\n", val);
5036 	phba->cfg_fcp_cpu_map = LPFC_HBA_CPU_MAP;
5037 
5038 	return 0;
5039 }
5040 
5041 static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
5042 
5043 /*
5044 # lpfc_fcp_class:  Determines FC class to use for the FCP protocol.
5045 # Value range is [2,3]. Default value is 3.
5046 */
5047 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
5048 		  "Select Fibre Channel class of service for FCP sequences");
5049 
5050 /*
5051 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
5052 # is [0,1]. Default value is 1.
5053 */
5054 LPFC_VPORT_ATTR_RW(use_adisc, 1, 0, 1,
5055 		   "Use ADISC on rediscovery to authenticate FCP devices");
5056 
5057 /*
5058 # lpfc_first_burst_size: First burst size to use on the NPorts
5059 # that support first burst.
5060 # Value range is [0,65536]. Default value is 0.
5061 */
5062 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
5063 		   "First burst size for Targets that support first burst");
5064 
5065 /*
5066 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
5067 * When the driver is configured as an NVME target, this value is
5068 * communicated to the NVME initiator in the PRLI response.  It is
5069 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
5070 * parameters are set and the target is sending the PRLI RSP.
5071 * Parameter supported on physical port only - no NPIV support.
5072 * Value range is [0,65536]. Default value is 0.
5073 */
5074 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
5075 	     "NVME Target mode first burst size in 512B increments.");
5076 
5077 /*
5078  * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
5079  * For the Initiator (I), enabling this parameter means that an NVMET
5080  * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
5081  * processed by the initiator for subsequent NVME FCP IO.
5082  * Currently, this feature is not supported on the NVME target
5083  * Value range is [0,1]. Default value is 0 (disabled).
5084  */
5085 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
5086 	     "Enable First Burst feature for NVME Initiator.");
5087 
5088 /*
5089 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
5090 # depth. Default value is 0. When the value of this parameter is zero the
5091 # SCSI command completion time is not used for controlling I/O queue depth. When
5092 # the parameter is set to a non-zero value, the I/O queue depth is controlled
5093 # to limit the I/O completion time to the parameter value.
5094 # The value is set in milliseconds.
5095 */
5096 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
5097 	"Use command completion time to control queue depth");
5098 
5099 lpfc_vport_param_show(max_scsicmpl_time);
5100 static int
5101 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
5102 {
5103 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5104 	struct lpfc_nodelist *ndlp, *next_ndlp;
5105 
5106 	if (val == vport->cfg_max_scsicmpl_time)
5107 		return 0;
5108 	if ((val < 0) || (val > 60000))
5109 		return -EINVAL;
5110 	vport->cfg_max_scsicmpl_time = val;
5111 
5112 	spin_lock_irq(shost->host_lock);
5113 	list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5114 		if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5115 			continue;
5116 		ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5117 	}
5118 	spin_unlock_irq(shost->host_lock);
5119 	return 0;
5120 }
5121 lpfc_vport_param_store(max_scsicmpl_time);
5122 static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
5123 
5124 /*
5125 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
5126 # range is [0,1]. Default value is 0.
5127 */
5128 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
5129 
5130 /*
5131 # lpfc_xri_rebalancing: enable or disable XRI rebalancing feature
5132 # range is [0,1]. Default value is 1.
5133 */
5134 LPFC_ATTR_R(xri_rebalancing, 1, 0, 1, "Enable/Disable XRI rebalancing");
5135 
5136 /*
5137  * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
5138  * range is [0,1]. Default value is 0.
5139  * For [0], FCP commands are issued to Work Queues based on upper layer
5140  * hardware queue index.
5141  * For [1], FCP commands are issued to a Work Queue associated with the
5142  *          current CPU.
5143  *
5144  * LPFC_FCP_SCHED_BY_HDWQ == 0
5145  * LPFC_FCP_SCHED_BY_CPU == 1
5146  *
5147  * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
5148  * affinity for FCP/NVME I/Os through Work Queues associated with the current
5149  * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
5150  * through WQs will be used.
5151  */
5152 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_BY_CPU,
5153 	     LPFC_FCP_SCHED_BY_HDWQ,
5154 	     LPFC_FCP_SCHED_BY_CPU,
5155 	     "Determine scheduling algorithm for "
5156 	     "issuing commands [0] - Hardware Queue, [1] - Current CPU");
5157 
5158 /*
5159  * lpfc_ns_query: Determine algrithmn for NameServer queries after RSCN
5160  * range is [0,1]. Default value is 0.
5161  * For [0], GID_FT is used for NameServer queries after RSCN (default)
5162  * For [1], GID_PT is used for NameServer queries after RSCN
5163  *
5164  */
5165 LPFC_ATTR_RW(ns_query, LPFC_NS_QUERY_GID_FT,
5166 	     LPFC_NS_QUERY_GID_FT, LPFC_NS_QUERY_GID_PT,
5167 	     "Determine algorithm NameServer queries after RSCN "
5168 	     "[0] - GID_FT, [1] - GID_PT");
5169 
5170 /*
5171 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
5172 # range is [0,1]. Default value is 0.
5173 # For [0], bus reset issues target reset to ALL devices
5174 # For [1], bus reset issues target reset to non-FCP2 devices
5175 */
5176 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
5177 	     "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
5178 
5179 
5180 /*
5181 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
5182 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
5183 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
5184 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
5185 # cr_delay is set to 0.
5186 */
5187 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
5188 		"interrupt response is generated");
5189 
5190 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
5191 		"interrupt response is generated");
5192 
5193 /*
5194 # lpfc_multi_ring_support:  Determines how many rings to spread available
5195 # cmd/rsp IOCB entries across.
5196 # Value range is [1,2]. Default value is 1.
5197 */
5198 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
5199 		"SLI rings to spread IOCB entries across");
5200 
5201 /*
5202 # lpfc_multi_ring_rctl:  If lpfc_multi_ring_support is enabled, this
5203 # identifies what rctl value to configure the additional ring for.
5204 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
5205 */
5206 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
5207 	     255, "Identifies RCTL for additional ring configuration");
5208 
5209 /*
5210 # lpfc_multi_ring_type:  If lpfc_multi_ring_support is enabled, this
5211 # identifies what type value to configure the additional ring for.
5212 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
5213 */
5214 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
5215 	     255, "Identifies TYPE for additional ring configuration");
5216 
5217 /*
5218 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
5219 #       0  = SmartSAN functionality disabled (default)
5220 #       1  = SmartSAN functionality enabled
5221 # This parameter will override the value of lpfc_fdmi_on module parameter.
5222 # Value range is [0,1]. Default value is 0.
5223 */
5224 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
5225 
5226 /*
5227 # lpfc_fdmi_on: Controls FDMI support.
5228 #       0       No FDMI support
5229 #       1       Traditional FDMI support (default)
5230 # Traditional FDMI support means the driver will assume FDMI-2 support;
5231 # however, if that fails, it will fallback to FDMI-1.
5232 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
5233 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
5234 # lpfc_fdmi_on.
5235 # Value range [0,1]. Default value is 1.
5236 */
5237 LPFC_ATTR_R(fdmi_on, 1, 0, 1, "Enable FDMI support");
5238 
5239 /*
5240 # Specifies the maximum number of ELS cmds we can have outstanding (for
5241 # discovery). Value range is [1,64]. Default value = 32.
5242 */
5243 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
5244 		 "during discovery");
5245 
5246 /*
5247 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
5248 #    will be scanned by the SCSI midlayer when sequential scanning is
5249 #    used; and is also the highest LUN ID allowed when the SCSI midlayer
5250 #    parses REPORT_LUN responses. The lpfc driver has no LUN count or
5251 #    LUN ID limit, but the SCSI midlayer requires this field for the uses
5252 #    above. The lpfc driver limits the default value to 255 for two reasons.
5253 #    As it bounds the sequential scan loop, scanning for thousands of luns
5254 #    on a target can take minutes of wall clock time.  Additionally,
5255 #    there are FC targets, such as JBODs, that only recognize 8-bits of
5256 #    LUN ID. When they receive a value greater than 8 bits, they chop off
5257 #    the high order bits. In other words, they see LUN IDs 0, 256, 512,
5258 #    and so on all as LUN ID 0. This causes the linux kernel, which sees
5259 #    valid responses at each of the LUN IDs, to believe there are multiple
5260 #    devices present, when in fact, there is only 1.
5261 #    A customer that is aware of their target behaviors, and the results as
5262 #    indicated above, is welcome to increase the lpfc_max_luns value.
5263 #    As mentioned, this value is not used by the lpfc driver, only the
5264 #    SCSI midlayer.
5265 # Value range is [0,65535]. Default value is 255.
5266 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
5267 */
5268 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
5269 
5270 /*
5271 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
5272 # Value range is [1,255], default value is 10.
5273 */
5274 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
5275 	     "Milliseconds driver will wait between polling FCP ring");
5276 
5277 /*
5278 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
5279 # to complete in seconds. Value range is [5,180], default value is 60.
5280 */
5281 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
5282 	     "Maximum time to wait for task management commands to complete");
5283 /*
5284 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
5285 #		support this feature
5286 #       0  = MSI disabled
5287 #       1  = MSI enabled
5288 #       2  = MSI-X enabled (default)
5289 # Value range is [0,2]. Default value is 2.
5290 */
5291 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
5292 	    "MSI-X (2), if possible");
5293 
5294 /*
5295  * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
5296  *
5297  *      0  = NVME OAS disabled
5298  *      1  = NVME OAS enabled
5299  *
5300  * Value range is [0,1]. Default value is 0.
5301  */
5302 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5303 	     "Use OAS bit on NVME IOs");
5304 
5305 /*
5306  * lpfc_nvme_embed_cmd: Use the oas bit when sending NVME/NVMET IOs
5307  *
5308  *      0  = Put NVME Command in SGL
5309  *      1  = Embed NVME Command in WQE (unless G7)
5310  *      2 =  Embed NVME Command in WQE (force)
5311  *
5312  * Value range is [0,2]. Default value is 1.
5313  */
5314 LPFC_ATTR_RW(nvme_embed_cmd, 1, 0, 2,
5315 	     "Embed NVME Command in WQE");
5316 
5317 /*
5318  * lpfc_fcp_mq_threshold: Set the maximum number of Hardware Queues
5319  * the driver will advertise it supports to the SCSI layer.
5320  *
5321  *      0    = Set nr_hw_queues by the number of CPUs or HW queues.
5322  *      1,256 = Manually specify nr_hw_queue value to be advertised,
5323  *
5324  * Value range is [0,256]. Default value is 8.
5325  */
5326 LPFC_ATTR_R(fcp_mq_threshold, LPFC_FCP_MQ_THRESHOLD_DEF,
5327 	    LPFC_FCP_MQ_THRESHOLD_MIN, LPFC_FCP_MQ_THRESHOLD_MAX,
5328 	    "Set the number of SCSI Queues advertised");
5329 
5330 /*
5331  * lpfc_hdw_queue: Set the number of Hardware Queues the driver
5332  * will advertise it supports to the NVME and  SCSI layers. This also
5333  * will map to the number of CQ/WQ pairs the driver will create.
5334  *
5335  * The NVME Layer will try to create this many, plus 1 administrative
5336  * hardware queue. The administrative queue will always map to WQ 0
5337  * A hardware IO queue maps (qidx) to a specific driver CQ/WQ.
5338  *
5339  *      0    = Configure the number of hdw queues to the number of active CPUs.
5340  *      1,256 = Manually specify how many hdw queues to use.
5341  *
5342  * Value range is [0,256]. Default value is 0.
5343  */
5344 LPFC_ATTR_R(hdw_queue,
5345 	    LPFC_HBA_HDWQ_DEF,
5346 	    LPFC_HBA_HDWQ_MIN, LPFC_HBA_HDWQ_MAX,
5347 	    "Set the number of I/O Hardware Queues");
5348 
5349 #if IS_ENABLED(CONFIG_X86)
5350 /**
5351  * lpfc_cpumask_irq_mode_init - initalizes cpumask of phba based on
5352  *				irq_chann_mode
5353  * @phba: Pointer to HBA context object.
5354  **/
5355 static void
5356 lpfc_cpumask_irq_mode_init(struct lpfc_hba *phba)
5357 {
5358 	unsigned int cpu, first_cpu, numa_node = NUMA_NO_NODE;
5359 	const struct cpumask *sibling_mask;
5360 	struct cpumask *aff_mask = &phba->sli4_hba.irq_aff_mask;
5361 
5362 	cpumask_clear(aff_mask);
5363 
5364 	if (phba->irq_chann_mode == NUMA_MODE) {
5365 		/* Check if we're a NUMA architecture */
5366 		numa_node = dev_to_node(&phba->pcidev->dev);
5367 		if (numa_node == NUMA_NO_NODE) {
5368 			phba->irq_chann_mode = NORMAL_MODE;
5369 			return;
5370 		}
5371 	}
5372 
5373 	for_each_possible_cpu(cpu) {
5374 		switch (phba->irq_chann_mode) {
5375 		case NUMA_MODE:
5376 			if (cpu_to_node(cpu) == numa_node)
5377 				cpumask_set_cpu(cpu, aff_mask);
5378 			break;
5379 		case NHT_MODE:
5380 			sibling_mask = topology_sibling_cpumask(cpu);
5381 			first_cpu = cpumask_first(sibling_mask);
5382 			if (first_cpu < nr_cpu_ids)
5383 				cpumask_set_cpu(first_cpu, aff_mask);
5384 			break;
5385 		default:
5386 			break;
5387 		}
5388 	}
5389 }
5390 #endif
5391 
5392 static void
5393 lpfc_assign_default_irq_chann(struct lpfc_hba *phba)
5394 {
5395 #if IS_ENABLED(CONFIG_X86)
5396 	switch (boot_cpu_data.x86_vendor) {
5397 	case X86_VENDOR_AMD:
5398 		/* If AMD architecture, then default is NUMA_MODE */
5399 		phba->irq_chann_mode = NUMA_MODE;
5400 		break;
5401 	case X86_VENDOR_INTEL:
5402 		/* If Intel architecture, then default is no hyperthread mode */
5403 		phba->irq_chann_mode = NHT_MODE;
5404 		break;
5405 	default:
5406 		phba->irq_chann_mode = NORMAL_MODE;
5407 		break;
5408 	}
5409 	lpfc_cpumask_irq_mode_init(phba);
5410 #else
5411 	phba->irq_chann_mode = NORMAL_MODE;
5412 #endif
5413 }
5414 
5415 /*
5416  * lpfc_irq_chann: Set the number of IRQ vectors that are available
5417  * for Hardware Queues to utilize.  This also will map to the number
5418  * of EQ / MSI-X vectors the driver will create. This should never be
5419  * more than the number of Hardware Queues
5420  *
5421  *	0		= Configure number of IRQ Channels to:
5422  *			  if AMD architecture, number of CPUs on HBA's NUMA node
5423  *			  if Intel architecture, number of physical CPUs.
5424  *			  otherwise, number of active CPUs.
5425  *	[1,256]		= Manually specify how many IRQ Channels to use.
5426  *
5427  * Value range is [0,256]. Default value is [0].
5428  */
5429 static uint lpfc_irq_chann = LPFC_IRQ_CHANN_DEF;
5430 module_param(lpfc_irq_chann, uint, 0444);
5431 MODULE_PARM_DESC(lpfc_irq_chann, "Set number of interrupt vectors to allocate");
5432 
5433 /* lpfc_irq_chann_init - Set the hba irq_chann initial value
5434  * @phba: lpfc_hba pointer.
5435  * @val: contains the initial value
5436  *
5437  * Description:
5438  * Validates the initial value is within range and assigns it to the
5439  * adapter. If not in range, an error message is posted and the
5440  * default value is assigned.
5441  *
5442  * Returns:
5443  * zero if value is in range and is set
5444  * -EINVAL if value was out of range
5445  **/
5446 static int
5447 lpfc_irq_chann_init(struct lpfc_hba *phba, uint32_t val)
5448 {
5449 	const struct cpumask *aff_mask;
5450 
5451 	if (phba->cfg_use_msi != 2) {
5452 		lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5453 				"8532 use_msi = %u ignoring cfg_irq_numa\n",
5454 				phba->cfg_use_msi);
5455 		phba->irq_chann_mode = NORMAL_MODE;
5456 		phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5457 		return 0;
5458 	}
5459 
5460 	/* Check if default setting was passed */
5461 	if (val == LPFC_IRQ_CHANN_DEF &&
5462 	    phba->cfg_hdw_queue == LPFC_HBA_HDWQ_DEF &&
5463 	    phba->sli_rev == LPFC_SLI_REV4)
5464 		lpfc_assign_default_irq_chann(phba);
5465 
5466 	if (phba->irq_chann_mode != NORMAL_MODE) {
5467 		aff_mask = &phba->sli4_hba.irq_aff_mask;
5468 
5469 		if (cpumask_empty(aff_mask)) {
5470 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5471 					"8533 Could not identify CPUS for "
5472 					"mode %d, ignoring\n",
5473 					phba->irq_chann_mode);
5474 			phba->irq_chann_mode = NORMAL_MODE;
5475 			phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5476 		} else {
5477 			phba->cfg_irq_chann = cpumask_weight(aff_mask);
5478 
5479 			/* If no hyperthread mode, then set hdwq count to
5480 			 * aff_mask weight as well
5481 			 */
5482 			if (phba->irq_chann_mode == NHT_MODE)
5483 				phba->cfg_hdw_queue = phba->cfg_irq_chann;
5484 
5485 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5486 					"8543 lpfc_irq_chann set to %u "
5487 					"(mode: %d)\n", phba->cfg_irq_chann,
5488 					phba->irq_chann_mode);
5489 		}
5490 	} else {
5491 		if (val > LPFC_IRQ_CHANN_MAX) {
5492 			lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5493 					"8545 lpfc_irq_chann attribute cannot "
5494 					"be set to %u, allowed range is "
5495 					"[%u,%u]\n",
5496 					val,
5497 					LPFC_IRQ_CHANN_MIN,
5498 					LPFC_IRQ_CHANN_MAX);
5499 			phba->cfg_irq_chann = LPFC_IRQ_CHANN_DEF;
5500 			return -EINVAL;
5501 		}
5502 		if (phba->sli_rev == LPFC_SLI_REV4) {
5503 			phba->cfg_irq_chann = val;
5504 		} else {
5505 			phba->cfg_irq_chann = 2;
5506 			phba->cfg_hdw_queue = 1;
5507 		}
5508 	}
5509 
5510 	return 0;
5511 }
5512 
5513 /**
5514  * lpfc_irq_chann_show - Display value of irq_chann
5515  * @dev: class converted to a Scsi_host structure.
5516  * @attr: device attribute, not used.
5517  * @buf: on return contains a string with the list sizes
5518  *
5519  * Returns: size of formatted string.
5520  **/
5521 static ssize_t
5522 lpfc_irq_chann_show(struct device *dev, struct device_attribute *attr,
5523 		    char *buf)
5524 {
5525 	struct Scsi_Host *shost = class_to_shost(dev);
5526 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5527 	struct lpfc_hba *phba = vport->phba;
5528 
5529 	return scnprintf(buf, PAGE_SIZE, "%u\n", phba->cfg_irq_chann);
5530 }
5531 
5532 static DEVICE_ATTR_RO(lpfc_irq_chann);
5533 
5534 /*
5535 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5536 #       0  = HBA resets disabled
5537 #       1  = HBA resets enabled (default)
5538 #       2  = HBA reset via PCI bus reset enabled
5539 # Value range is [0,2]. Default value is 1.
5540 */
5541 LPFC_ATTR_RW(enable_hba_reset, 1, 0, 2, "Enable HBA resets from the driver.");
5542 
5543 /*
5544 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5545 #       0  = HBA Heartbeat disabled
5546 #       1  = HBA Heartbeat enabled (default)
5547 # Value range is [0,1]. Default value is 1.
5548 */
5549 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5550 
5551 /*
5552 # lpfc_EnableXLane: Enable Express Lane Feature
5553 #      0x0   Express Lane Feature disabled
5554 #      0x1   Express Lane Feature enabled
5555 # Value range is [0,1]. Default value is 0.
5556 */
5557 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5558 
5559 /*
5560 # lpfc_XLanePriority:  Define CS_CTL priority for Express Lane Feature
5561 #       0x0 - 0x7f  = CS_CTL field in FC header (high 7 bits)
5562 # Value range is [0x0,0x7f]. Default value is 0
5563 */
5564 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5565 
5566 /*
5567 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5568 #       0  = BlockGuard disabled (default)
5569 #       1  = BlockGuard enabled
5570 # Value range is [0,1]. Default value is 0.
5571 */
5572 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5573 
5574 /*
5575 # lpfc_prot_mask:
5576 #	- Bit mask of host protection capabilities used to register with the
5577 #	  SCSI mid-layer
5578 # 	- Only meaningful if BG is turned on (lpfc_enable_bg=1).
5579 #	- Allows you to ultimately specify which profiles to use
5580 #	- Default will result in registering capabilities for all profiles.
5581 #	- SHOST_DIF_TYPE1_PROTECTION	1
5582 #		HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5583 #	- SHOST_DIX_TYPE0_PROTECTION	8
5584 #		HBA supports DIX Type 0: Host to HBA protection only
5585 #	- SHOST_DIX_TYPE1_PROTECTION	16
5586 #		HBA supports DIX Type 1: Host to HBA  Type 1 protection
5587 #
5588 */
5589 LPFC_ATTR(prot_mask,
5590 	(SHOST_DIF_TYPE1_PROTECTION |
5591 	SHOST_DIX_TYPE0_PROTECTION |
5592 	SHOST_DIX_TYPE1_PROTECTION),
5593 	0,
5594 	(SHOST_DIF_TYPE1_PROTECTION |
5595 	SHOST_DIX_TYPE0_PROTECTION |
5596 	SHOST_DIX_TYPE1_PROTECTION),
5597 	"T10-DIF host protection capabilities mask");
5598 
5599 /*
5600 # lpfc_prot_guard:
5601 #	- Bit mask of protection guard types to register with the SCSI mid-layer
5602 #	- Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5603 #	- Allows you to ultimately specify which profiles to use
5604 #	- Default will result in registering capabilities for all guard types
5605 #
5606 */
5607 LPFC_ATTR(prot_guard,
5608 	SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5609 	"T10-DIF host protection guard type");
5610 
5611 /*
5612  * Delay initial NPort discovery when Clean Address bit is cleared in
5613  * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5614  * This parameter can have value 0 or 1.
5615  * When this parameter is set to 0, no delay is added to the initial
5616  * discovery.
5617  * When this parameter is set to non-zero value, initial Nport discovery is
5618  * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5619  * accept and FCID/Fabric name/Fabric portname is changed.
5620  * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5621  * when Clean Address bit is cleared in FLOGI/FDISC
5622  * accept and FCID/Fabric name/Fabric portname is changed.
5623  * Default value is 0.
5624  */
5625 LPFC_ATTR(delay_discovery, 0, 0, 1,
5626 	"Delay NPort discovery when Clean Address bit is cleared.");
5627 
5628 /*
5629  * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5630  * This value can be set to values between 64 and 4096. The default value
5631  * is 64, but may be increased to allow for larger Max I/O sizes. The scsi
5632  * and nvme layers will allow I/O sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5633  * Because of the additional overhead involved in setting up T10-DIF,
5634  * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5635  * and will be limited to 512 if BlockGuard is enabled under SLI3.
5636  */
5637 static uint lpfc_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5638 module_param(lpfc_sg_seg_cnt, uint, 0444);
5639 MODULE_PARM_DESC(lpfc_sg_seg_cnt, "Max Scatter Gather Segment Count");
5640 
5641 /**
5642  * lpfc_sg_seg_cnt_show - Display the scatter/gather list sizes
5643  *    configured for the adapter
5644  * @dev: class converted to a Scsi_host structure.
5645  * @attr: device attribute, not used.
5646  * @buf: on return contains a string with the list sizes
5647  *
5648  * Returns: size of formatted string.
5649  **/
5650 static ssize_t
5651 lpfc_sg_seg_cnt_show(struct device *dev, struct device_attribute *attr,
5652 		     char *buf)
5653 {
5654 	struct Scsi_Host  *shost = class_to_shost(dev);
5655 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5656 	struct lpfc_hba   *phba = vport->phba;
5657 	int len;
5658 
5659 	len = scnprintf(buf, PAGE_SIZE, "SGL sz: %d  total SGEs: %d\n",
5660 		       phba->cfg_sg_dma_buf_size, phba->cfg_total_seg_cnt);
5661 
5662 	len += scnprintf(buf + len, PAGE_SIZE - len,
5663 			"Cfg: %d  SCSI: %d  NVME: %d\n",
5664 			phba->cfg_sg_seg_cnt, phba->cfg_scsi_seg_cnt,
5665 			phba->cfg_nvme_seg_cnt);
5666 	return len;
5667 }
5668 
5669 static DEVICE_ATTR_RO(lpfc_sg_seg_cnt);
5670 
5671 /**
5672  * lpfc_sg_seg_cnt_init - Set the hba sg_seg_cnt initial value
5673  * @phba: lpfc_hba pointer.
5674  * @val: contains the initial value
5675  *
5676  * Description:
5677  * Validates the initial value is within range and assigns it to the
5678  * adapter. If not in range, an error message is posted and the
5679  * default value is assigned.
5680  *
5681  * Returns:
5682  * zero if value is in range and is set
5683  * -EINVAL if value was out of range
5684  **/
5685 static int
5686 lpfc_sg_seg_cnt_init(struct lpfc_hba *phba, int val)
5687 {
5688 	if (val >= LPFC_MIN_SG_SEG_CNT && val <= LPFC_MAX_SG_SEG_CNT) {
5689 		phba->cfg_sg_seg_cnt = val;
5690 		return 0;
5691 	}
5692 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5693 			"0409 lpfc_sg_seg_cnt attribute cannot be set to %d, "
5694 			"allowed range is [%d, %d]\n",
5695 			val, LPFC_MIN_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT);
5696 	phba->cfg_sg_seg_cnt = LPFC_DEFAULT_SG_SEG_CNT;
5697 	return -EINVAL;
5698 }
5699 
5700 /*
5701  * lpfc_enable_mds_diags: Enable MDS Diagnostics
5702  *       0  = MDS Diagnostics disabled (default)
5703  *       1  = MDS Diagnostics enabled
5704  * Value range is [0,1]. Default value is 0.
5705  */
5706 LPFC_ATTR_RW(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5707 
5708 /*
5709  * lpfc_ras_fwlog_buffsize: Firmware logging host buffer size
5710  *	0 = Disable firmware logging (default)
5711  *	[1-4] = Multiple of 1/4th Mb of host memory for FW logging
5712  * Value range [0..4]. Default value is 0
5713  */
5714 LPFC_ATTR(ras_fwlog_buffsize, 0, 0, 4, "Host memory for FW logging");
5715 lpfc_param_show(ras_fwlog_buffsize);
5716 
5717 static ssize_t
5718 lpfc_ras_fwlog_buffsize_set(struct lpfc_hba  *phba, uint val)
5719 {
5720 	int ret = 0;
5721 	enum ras_state state;
5722 
5723 	if (!lpfc_rangecheck(val, 0, 4))
5724 		return -EINVAL;
5725 
5726 	if (phba->cfg_ras_fwlog_buffsize == val)
5727 		return 0;
5728 
5729 	if (phba->cfg_ras_fwlog_func != PCI_FUNC(phba->pcidev->devfn))
5730 		return -EINVAL;
5731 
5732 	spin_lock_irq(&phba->hbalock);
5733 	state = phba->ras_fwlog.state;
5734 	spin_unlock_irq(&phba->hbalock);
5735 
5736 	if (state == REG_INPROGRESS) {
5737 		lpfc_printf_log(phba, KERN_ERR, LOG_SLI, "6147 RAS Logging "
5738 				"registration is in progress\n");
5739 		return -EBUSY;
5740 	}
5741 
5742 	/* For disable logging: stop the logs and free the DMA.
5743 	 * For ras_fwlog_buffsize size change we still need to free and
5744 	 * reallocate the DMA in lpfc_sli4_ras_fwlog_init.
5745 	 */
5746 	phba->cfg_ras_fwlog_buffsize = val;
5747 	if (state == ACTIVE) {
5748 		lpfc_ras_stop_fwlog(phba);
5749 		lpfc_sli4_ras_dma_free(phba);
5750 	}
5751 
5752 	lpfc_sli4_ras_init(phba);
5753 	if (phba->ras_fwlog.ras_enabled)
5754 		ret = lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
5755 					       LPFC_RAS_ENABLE_LOGGING);
5756 	return ret;
5757 }
5758 
5759 lpfc_param_store(ras_fwlog_buffsize);
5760 static DEVICE_ATTR_RW(lpfc_ras_fwlog_buffsize);
5761 
5762 /*
5763  * lpfc_ras_fwlog_level: Firmware logging verbosity level
5764  * Valid only if firmware logging is enabled
5765  * 0(Least Verbosity) 4 (most verbosity)
5766  * Value range is [0..4]. Default value is 0
5767  */
5768 LPFC_ATTR_RW(ras_fwlog_level, 0, 0, 4, "Firmware Logging Level");
5769 
5770 /*
5771  * lpfc_ras_fwlog_func: Firmware logging enabled on function number
5772  * Default function which has RAS support : 0
5773  * Value Range is [0..7].
5774  * FW logging is a global action and enablement is via a specific
5775  * port.
5776  */
5777 LPFC_ATTR_RW(ras_fwlog_func, 0, 0, 7, "Firmware Logging Enabled on Function");
5778 
5779 /*
5780  * lpfc_enable_bbcr: Enable BB Credit Recovery
5781  *       0  = BB Credit Recovery disabled
5782  *       1  = BB Credit Recovery enabled (default)
5783  * Value range is [0,1]. Default value is 1.
5784  */
5785 LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5786 
5787 /* Signaling module parameters */
5788 int lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
5789 module_param(lpfc_fabric_cgn_frequency, int, 0444);
5790 MODULE_PARM_DESC(lpfc_fabric_cgn_frequency, "Congestion signaling fabric freq");
5791 
5792 int lpfc_acqe_cgn_frequency = 10; /* 10 sec default */
5793 module_param(lpfc_acqe_cgn_frequency, int, 0444);
5794 MODULE_PARM_DESC(lpfc_acqe_cgn_frequency, "Congestion signaling ACQE freq");
5795 
5796 int lpfc_use_cgn_signal = 1; /* 0 - only use FPINs, 1 - Use signals if avail  */
5797 module_param(lpfc_use_cgn_signal, int, 0444);
5798 MODULE_PARM_DESC(lpfc_use_cgn_signal, "Use Congestion signaling if available");
5799 
5800 /*
5801  * lpfc_enable_dpp: Enable DPP on G7
5802  *       0  = DPP on G7 disabled
5803  *       1  = DPP on G7 enabled (default)
5804  * Value range is [0,1]. Default value is 1.
5805  */
5806 LPFC_ATTR_RW(enable_dpp, 1, 0, 1, "Enable Direct Packet Push");
5807 
5808 /*
5809  * lpfc_enable_mi: Enable FDMI MIB
5810  *       0  = disabled
5811  *       1  = enabled (default)
5812  * Value range is [0,1].
5813  */
5814 LPFC_ATTR_R(enable_mi, 1, 0, 1, "Enable MI");
5815 
5816 /*
5817  * lpfc_max_vmid: Maximum number of VMs to be tagged. This is valid only if
5818  * either vmid_app_header or vmid_priority_tagging is enabled.
5819  *       4 - 255  = vmid support enabled for 4-255 VMs
5820  *       Value range is [4,255].
5821  */
5822 LPFC_ATTR_RW(max_vmid, LPFC_MIN_VMID, LPFC_MIN_VMID, LPFC_MAX_VMID,
5823 	     "Maximum number of VMs supported");
5824 
5825 /*
5826  * lpfc_vmid_inactivity_timeout: Inactivity timeout duration in hours
5827  *       0  = Timeout is disabled
5828  * Value range is [0,24].
5829  */
5830 LPFC_ATTR_RW(vmid_inactivity_timeout, 4, 0, 24,
5831 	     "Inactivity timeout in hours");
5832 
5833 /*
5834  * lpfc_vmid_app_header: Enable App Header VMID support
5835  *       0  = Support is disabled (default)
5836  *       1  = Support is enabled
5837  * Value range is [0,1].
5838  */
5839 LPFC_ATTR_RW(vmid_app_header, LPFC_VMID_APP_HEADER_DISABLE,
5840 	     LPFC_VMID_APP_HEADER_DISABLE, LPFC_VMID_APP_HEADER_ENABLE,
5841 	     "Enable App Header VMID support");
5842 
5843 /*
5844  * lpfc_vmid_priority_tagging: Enable Priority Tagging VMID support
5845  *       0  = Support is disabled (default)
5846  *       1  = Allow supported targets only
5847  *       2  = Allow all targets
5848  * Value range is [0,2].
5849  */
5850 LPFC_ATTR_RW(vmid_priority_tagging, LPFC_VMID_PRIO_TAG_DISABLE,
5851 	     LPFC_VMID_PRIO_TAG_DISABLE,
5852 	     LPFC_VMID_PRIO_TAG_ALL_TARGETS,
5853 	     "Enable Priority Tagging VMID support");
5854 
5855 static struct attribute *lpfc_hba_attrs[] = {
5856 	&dev_attr_nvme_info.attr,
5857 	&dev_attr_scsi_stat.attr,
5858 	&dev_attr_bg_info.attr,
5859 	&dev_attr_bg_guard_err.attr,
5860 	&dev_attr_bg_apptag_err.attr,
5861 	&dev_attr_bg_reftag_err.attr,
5862 	&dev_attr_info.attr,
5863 	&dev_attr_serialnum.attr,
5864 	&dev_attr_modeldesc.attr,
5865 	&dev_attr_modelname.attr,
5866 	&dev_attr_programtype.attr,
5867 	&dev_attr_portnum.attr,
5868 	&dev_attr_fwrev.attr,
5869 	&dev_attr_hdw.attr,
5870 	&dev_attr_option_rom_version.attr,
5871 	&dev_attr_link_state.attr,
5872 	&dev_attr_num_discovered_ports.attr,
5873 	&dev_attr_lpfc_drvr_version.attr,
5874 	&dev_attr_lpfc_enable_fip.attr,
5875 	&dev_attr_lpfc_temp_sensor.attr,
5876 	&dev_attr_lpfc_log_verbose.attr,
5877 	&dev_attr_lpfc_lun_queue_depth.attr,
5878 	&dev_attr_lpfc_tgt_queue_depth.attr,
5879 	&dev_attr_lpfc_hba_queue_depth.attr,
5880 	&dev_attr_lpfc_peer_port_login.attr,
5881 	&dev_attr_lpfc_nodev_tmo.attr,
5882 	&dev_attr_lpfc_devloss_tmo.attr,
5883 	&dev_attr_lpfc_enable_fc4_type.attr,
5884 	&dev_attr_lpfc_fcp_class.attr,
5885 	&dev_attr_lpfc_use_adisc.attr,
5886 	&dev_attr_lpfc_first_burst_size.attr,
5887 	&dev_attr_lpfc_ack0.attr,
5888 	&dev_attr_lpfc_xri_rebalancing.attr,
5889 	&dev_attr_lpfc_topology.attr,
5890 	&dev_attr_lpfc_scan_down.attr,
5891 	&dev_attr_lpfc_link_speed.attr,
5892 	&dev_attr_lpfc_fcp_io_sched.attr,
5893 	&dev_attr_lpfc_ns_query.attr,
5894 	&dev_attr_lpfc_fcp2_no_tgt_reset.attr,
5895 	&dev_attr_lpfc_cr_delay.attr,
5896 	&dev_attr_lpfc_cr_count.attr,
5897 	&dev_attr_lpfc_multi_ring_support.attr,
5898 	&dev_attr_lpfc_multi_ring_rctl.attr,
5899 	&dev_attr_lpfc_multi_ring_type.attr,
5900 	&dev_attr_lpfc_fdmi_on.attr,
5901 	&dev_attr_lpfc_enable_SmartSAN.attr,
5902 	&dev_attr_lpfc_max_luns.attr,
5903 	&dev_attr_lpfc_enable_npiv.attr,
5904 	&dev_attr_lpfc_fcf_failover_policy.attr,
5905 	&dev_attr_lpfc_enable_rrq.attr,
5906 	&dev_attr_lpfc_fcp_wait_abts_rsp.attr,
5907 	&dev_attr_nport_evt_cnt.attr,
5908 	&dev_attr_board_mode.attr,
5909 	&dev_attr_max_vpi.attr,
5910 	&dev_attr_used_vpi.attr,
5911 	&dev_attr_max_rpi.attr,
5912 	&dev_attr_used_rpi.attr,
5913 	&dev_attr_max_xri.attr,
5914 	&dev_attr_used_xri.attr,
5915 	&dev_attr_npiv_info.attr,
5916 	&dev_attr_issue_reset.attr,
5917 	&dev_attr_lpfc_poll.attr,
5918 	&dev_attr_lpfc_poll_tmo.attr,
5919 	&dev_attr_lpfc_task_mgmt_tmo.attr,
5920 	&dev_attr_lpfc_use_msi.attr,
5921 	&dev_attr_lpfc_nvme_oas.attr,
5922 	&dev_attr_lpfc_nvme_embed_cmd.attr,
5923 	&dev_attr_lpfc_fcp_imax.attr,
5924 	&dev_attr_lpfc_force_rscn.attr,
5925 	&dev_attr_lpfc_cq_poll_threshold.attr,
5926 	&dev_attr_lpfc_cq_max_proc_limit.attr,
5927 	&dev_attr_lpfc_fcp_cpu_map.attr,
5928 	&dev_attr_lpfc_fcp_mq_threshold.attr,
5929 	&dev_attr_lpfc_hdw_queue.attr,
5930 	&dev_attr_lpfc_irq_chann.attr,
5931 	&dev_attr_lpfc_suppress_rsp.attr,
5932 	&dev_attr_lpfc_nvmet_mrq.attr,
5933 	&dev_attr_lpfc_nvmet_mrq_post.attr,
5934 	&dev_attr_lpfc_nvme_enable_fb.attr,
5935 	&dev_attr_lpfc_nvmet_fb_size.attr,
5936 	&dev_attr_lpfc_enable_bg.attr,
5937 	&dev_attr_lpfc_enable_hba_reset.attr,
5938 	&dev_attr_lpfc_enable_hba_heartbeat.attr,
5939 	&dev_attr_lpfc_EnableXLane.attr,
5940 	&dev_attr_lpfc_XLanePriority.attr,
5941 	&dev_attr_lpfc_xlane_lun.attr,
5942 	&dev_attr_lpfc_xlane_tgt.attr,
5943 	&dev_attr_lpfc_xlane_vpt.attr,
5944 	&dev_attr_lpfc_xlane_lun_state.attr,
5945 	&dev_attr_lpfc_xlane_lun_status.attr,
5946 	&dev_attr_lpfc_xlane_priority.attr,
5947 	&dev_attr_lpfc_sg_seg_cnt.attr,
5948 	&dev_attr_lpfc_max_scsicmpl_time.attr,
5949 	&dev_attr_lpfc_aer_support.attr,
5950 	&dev_attr_lpfc_aer_state_cleanup.attr,
5951 	&dev_attr_lpfc_sriov_nr_virtfn.attr,
5952 	&dev_attr_lpfc_req_fw_upgrade.attr,
5953 	&dev_attr_lpfc_suppress_link_up.attr,
5954 	&dev_attr_iocb_hw.attr,
5955 	&dev_attr_pls.attr,
5956 	&dev_attr_pt.attr,
5957 	&dev_attr_txq_hw.attr,
5958 	&dev_attr_txcmplq_hw.attr,
5959 	&dev_attr_lpfc_sriov_hw_max_virtfn.attr,
5960 	&dev_attr_protocol.attr,
5961 	&dev_attr_lpfc_xlane_supported.attr,
5962 	&dev_attr_lpfc_enable_mds_diags.attr,
5963 	&dev_attr_lpfc_ras_fwlog_buffsize.attr,
5964 	&dev_attr_lpfc_ras_fwlog_level.attr,
5965 	&dev_attr_lpfc_ras_fwlog_func.attr,
5966 	&dev_attr_lpfc_enable_bbcr.attr,
5967 	&dev_attr_lpfc_enable_dpp.attr,
5968 	&dev_attr_lpfc_enable_mi.attr,
5969 	&dev_attr_cmf_info.attr,
5970 	&dev_attr_lpfc_max_vmid.attr,
5971 	&dev_attr_lpfc_vmid_inactivity_timeout.attr,
5972 	&dev_attr_lpfc_vmid_app_header.attr,
5973 	&dev_attr_lpfc_vmid_priority_tagging.attr,
5974 	NULL,
5975 };
5976 
5977 static const struct attribute_group lpfc_hba_attr_group = {
5978 	.attrs = lpfc_hba_attrs
5979 };
5980 
5981 const struct attribute_group *lpfc_hba_groups[] = {
5982 	&lpfc_hba_attr_group,
5983 	NULL
5984 };
5985 
5986 static struct attribute *lpfc_vport_attrs[] = {
5987 	&dev_attr_info.attr,
5988 	&dev_attr_link_state.attr,
5989 	&dev_attr_num_discovered_ports.attr,
5990 	&dev_attr_lpfc_drvr_version.attr,
5991 	&dev_attr_lpfc_log_verbose.attr,
5992 	&dev_attr_lpfc_lun_queue_depth.attr,
5993 	&dev_attr_lpfc_tgt_queue_depth.attr,
5994 	&dev_attr_lpfc_nodev_tmo.attr,
5995 	&dev_attr_lpfc_devloss_tmo.attr,
5996 	&dev_attr_lpfc_hba_queue_depth.attr,
5997 	&dev_attr_lpfc_peer_port_login.attr,
5998 	&dev_attr_lpfc_restrict_login.attr,
5999 	&dev_attr_lpfc_fcp_class.attr,
6000 	&dev_attr_lpfc_use_adisc.attr,
6001 	&dev_attr_lpfc_first_burst_size.attr,
6002 	&dev_attr_lpfc_max_luns.attr,
6003 	&dev_attr_nport_evt_cnt.attr,
6004 	&dev_attr_npiv_info.attr,
6005 	&dev_attr_lpfc_enable_da_id.attr,
6006 	&dev_attr_lpfc_max_scsicmpl_time.attr,
6007 	&dev_attr_lpfc_static_vport.attr,
6008 	&dev_attr_cmf_info.attr,
6009 	NULL,
6010 };
6011 
6012 static const struct attribute_group lpfc_vport_attr_group = {
6013 	.attrs = lpfc_vport_attrs
6014 };
6015 
6016 const struct attribute_group *lpfc_vport_groups[] = {
6017 	&lpfc_vport_attr_group,
6018 	NULL
6019 };
6020 
6021 /**
6022  * sysfs_ctlreg_write - Write method for writing to ctlreg
6023  * @filp: open sysfs file
6024  * @kobj: kernel kobject that contains the kernel class device.
6025  * @bin_attr: kernel attributes passed to us.
6026  * @buf: contains the data to be written to the adapter IOREG space.
6027  * @off: offset into buffer to beginning of data.
6028  * @count: bytes to transfer.
6029  *
6030  * Description:
6031  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6032  * Uses the adapter io control registers to send buf contents to the adapter.
6033  *
6034  * Returns:
6035  * -ERANGE off and count combo out of range
6036  * -EINVAL off, count or buff address invalid
6037  * -EPERM adapter is offline
6038  * value of count, buf contents written
6039  **/
6040 static ssize_t
6041 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
6042 		   struct bin_attribute *bin_attr,
6043 		   char *buf, loff_t off, size_t count)
6044 {
6045 	size_t buf_off;
6046 	struct device *dev = container_of(kobj, struct device, kobj);
6047 	struct Scsi_Host  *shost = class_to_shost(dev);
6048 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6049 	struct lpfc_hba   *phba = vport->phba;
6050 
6051 	if (phba->sli_rev >= LPFC_SLI_REV4)
6052 		return -EPERM;
6053 
6054 	if ((off + count) > FF_REG_AREA_SIZE)
6055 		return -ERANGE;
6056 
6057 	if (count <= LPFC_REG_WRITE_KEY_SIZE)
6058 		return 0;
6059 
6060 	if (off % 4 || count % 4 || (unsigned long)buf % 4)
6061 		return -EINVAL;
6062 
6063 	/* This is to protect HBA registers from accidental writes. */
6064 	if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
6065 		return -EINVAL;
6066 
6067 	if (!(vport->fc_flag & FC_OFFLINE_MODE))
6068 		return -EPERM;
6069 
6070 	spin_lock_irq(&phba->hbalock);
6071 	for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
6072 			buf_off += sizeof(uint32_t))
6073 		writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
6074 		       phba->ctrl_regs_memmap_p + off + buf_off);
6075 
6076 	spin_unlock_irq(&phba->hbalock);
6077 
6078 	return count;
6079 }
6080 
6081 /**
6082  * sysfs_ctlreg_read - Read method for reading from ctlreg
6083  * @filp: open sysfs file
6084  * @kobj: kernel kobject that contains the kernel class device.
6085  * @bin_attr: kernel attributes passed to us.
6086  * @buf: if successful contains the data from the adapter IOREG space.
6087  * @off: offset into buffer to beginning of data.
6088  * @count: bytes to transfer.
6089  *
6090  * Description:
6091  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
6092  * Uses the adapter io control registers to read data into buf.
6093  *
6094  * Returns:
6095  * -ERANGE off and count combo out of range
6096  * -EINVAL off, count or buff address invalid
6097  * value of count, buf contents read
6098  **/
6099 static ssize_t
6100 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
6101 		  struct bin_attribute *bin_attr,
6102 		  char *buf, loff_t off, size_t count)
6103 {
6104 	size_t buf_off;
6105 	uint32_t * tmp_ptr;
6106 	struct device *dev = container_of(kobj, struct device, kobj);
6107 	struct Scsi_Host  *shost = class_to_shost(dev);
6108 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6109 	struct lpfc_hba   *phba = vport->phba;
6110 
6111 	if (phba->sli_rev >= LPFC_SLI_REV4)
6112 		return -EPERM;
6113 
6114 	if (off > FF_REG_AREA_SIZE)
6115 		return -ERANGE;
6116 
6117 	if ((off + count) > FF_REG_AREA_SIZE)
6118 		count = FF_REG_AREA_SIZE - off;
6119 
6120 	if (count == 0) return 0;
6121 
6122 	if (off % 4 || count % 4 || (unsigned long)buf % 4)
6123 		return -EINVAL;
6124 
6125 	spin_lock_irq(&phba->hbalock);
6126 
6127 	for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
6128 		tmp_ptr = (uint32_t *)(buf + buf_off);
6129 		*tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
6130 	}
6131 
6132 	spin_unlock_irq(&phba->hbalock);
6133 
6134 	return count;
6135 }
6136 
6137 static struct bin_attribute sysfs_ctlreg_attr = {
6138 	.attr = {
6139 		.name = "ctlreg",
6140 		.mode = S_IRUSR | S_IWUSR,
6141 	},
6142 	.size = 256,
6143 	.read = sysfs_ctlreg_read,
6144 	.write = sysfs_ctlreg_write,
6145 };
6146 
6147 /**
6148  * sysfs_mbox_write - Write method for writing information via mbox
6149  * @filp: open sysfs file
6150  * @kobj: kernel kobject that contains the kernel class device.
6151  * @bin_attr: kernel attributes passed to us.
6152  * @buf: contains the data to be written to sysfs mbox.
6153  * @off: offset into buffer to beginning of data.
6154  * @count: bytes to transfer.
6155  *
6156  * Description:
6157  * Deprecated function. All mailbox access from user space is performed via the
6158  * bsg interface.
6159  *
6160  * Returns:
6161  * -EPERM operation not permitted
6162  **/
6163 static ssize_t
6164 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
6165 		 struct bin_attribute *bin_attr,
6166 		 char *buf, loff_t off, size_t count)
6167 {
6168 	return -EPERM;
6169 }
6170 
6171 /**
6172  * sysfs_mbox_read - Read method for reading information via mbox
6173  * @filp: open sysfs file
6174  * @kobj: kernel kobject that contains the kernel class device.
6175  * @bin_attr: kernel attributes passed to us.
6176  * @buf: contains the data to be read from sysfs mbox.
6177  * @off: offset into buffer to beginning of data.
6178  * @count: bytes to transfer.
6179  *
6180  * Description:
6181  * Deprecated function. All mailbox access from user space is performed via the
6182  * bsg interface.
6183  *
6184  * Returns:
6185  * -EPERM operation not permitted
6186  **/
6187 static ssize_t
6188 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
6189 		struct bin_attribute *bin_attr,
6190 		char *buf, loff_t off, size_t count)
6191 {
6192 	return -EPERM;
6193 }
6194 
6195 static struct bin_attribute sysfs_mbox_attr = {
6196 	.attr = {
6197 		.name = "mbox",
6198 		.mode = S_IRUSR | S_IWUSR,
6199 	},
6200 	.size = MAILBOX_SYSFS_MAX,
6201 	.read = sysfs_mbox_read,
6202 	.write = sysfs_mbox_write,
6203 };
6204 
6205 /**
6206  * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
6207  * @vport: address of lpfc vport structure.
6208  *
6209  * Return codes:
6210  * zero on success
6211  * error return code from sysfs_create_bin_file()
6212  **/
6213 int
6214 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
6215 {
6216 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6217 	int error;
6218 
6219 	/* Virtual ports do not need ctrl_reg and mbox */
6220 	if (vport->port_type == LPFC_NPIV_PORT)
6221 		return 0;
6222 
6223 	error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6224 				      &sysfs_ctlreg_attr);
6225 	if (error)
6226 		goto out;
6227 
6228 	error = sysfs_create_bin_file(&shost->shost_dev.kobj,
6229 				      &sysfs_mbox_attr);
6230 	if (error)
6231 		goto out_remove_ctlreg_attr;
6232 
6233 	return 0;
6234 out_remove_ctlreg_attr:
6235 	sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6236 out:
6237 	return error;
6238 }
6239 
6240 /**
6241  * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
6242  * @vport: address of lpfc vport structure.
6243  **/
6244 void
6245 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
6246 {
6247 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6248 
6249 	/* Virtual ports do not need ctrl_reg and mbox */
6250 	if (vport->port_type == LPFC_NPIV_PORT)
6251 		return;
6252 	sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
6253 	sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
6254 }
6255 
6256 /*
6257  * Dynamic FC Host Attributes Support
6258  */
6259 
6260 /**
6261  * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
6262  * @shost: kernel scsi host pointer.
6263  **/
6264 static void
6265 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
6266 {
6267 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
6268 
6269 	lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
6270 				      sizeof fc_host_symbolic_name(shost));
6271 }
6272 
6273 /**
6274  * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
6275  * @shost: kernel scsi host pointer.
6276  **/
6277 static void
6278 lpfc_get_host_port_id(struct Scsi_Host *shost)
6279 {
6280 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6281 
6282 	/* note: fc_myDID already in cpu endianness */
6283 	fc_host_port_id(shost) = vport->fc_myDID;
6284 }
6285 
6286 /**
6287  * lpfc_get_host_port_type - Set the value of the scsi host port type
6288  * @shost: kernel scsi host pointer.
6289  **/
6290 static void
6291 lpfc_get_host_port_type(struct Scsi_Host *shost)
6292 {
6293 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6294 	struct lpfc_hba   *phba = vport->phba;
6295 
6296 	spin_lock_irq(shost->host_lock);
6297 
6298 	if (vport->port_type == LPFC_NPIV_PORT) {
6299 		fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
6300 	} else if (lpfc_is_link_up(phba)) {
6301 		if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6302 			if (vport->fc_flag & FC_PUBLIC_LOOP)
6303 				fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
6304 			else
6305 				fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
6306 		} else {
6307 			if (vport->fc_flag & FC_FABRIC)
6308 				fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
6309 			else
6310 				fc_host_port_type(shost) = FC_PORTTYPE_PTP;
6311 		}
6312 	} else
6313 		fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
6314 
6315 	spin_unlock_irq(shost->host_lock);
6316 }
6317 
6318 /**
6319  * lpfc_get_host_port_state - Set the value of the scsi host port state
6320  * @shost: kernel scsi host pointer.
6321  **/
6322 static void
6323 lpfc_get_host_port_state(struct Scsi_Host *shost)
6324 {
6325 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6326 	struct lpfc_hba   *phba = vport->phba;
6327 
6328 	spin_lock_irq(shost->host_lock);
6329 
6330 	if (vport->fc_flag & FC_OFFLINE_MODE)
6331 		fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
6332 	else {
6333 		switch (phba->link_state) {
6334 		case LPFC_LINK_UNKNOWN:
6335 		case LPFC_LINK_DOWN:
6336 			fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
6337 			break;
6338 		case LPFC_LINK_UP:
6339 		case LPFC_CLEAR_LA:
6340 		case LPFC_HBA_READY:
6341 			/* Links up, reports port state accordingly */
6342 			if (vport->port_state < LPFC_VPORT_READY)
6343 				fc_host_port_state(shost) =
6344 							FC_PORTSTATE_BYPASSED;
6345 			else
6346 				fc_host_port_state(shost) =
6347 							FC_PORTSTATE_ONLINE;
6348 			break;
6349 		case LPFC_HBA_ERROR:
6350 			fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
6351 			break;
6352 		default:
6353 			fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
6354 			break;
6355 		}
6356 	}
6357 
6358 	spin_unlock_irq(shost->host_lock);
6359 }
6360 
6361 /**
6362  * lpfc_get_host_speed - Set the value of the scsi host speed
6363  * @shost: kernel scsi host pointer.
6364  **/
6365 static void
6366 lpfc_get_host_speed(struct Scsi_Host *shost)
6367 {
6368 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6369 	struct lpfc_hba   *phba = vport->phba;
6370 
6371 	spin_lock_irq(shost->host_lock);
6372 
6373 	if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
6374 		switch(phba->fc_linkspeed) {
6375 		case LPFC_LINK_SPEED_1GHZ:
6376 			fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6377 			break;
6378 		case LPFC_LINK_SPEED_2GHZ:
6379 			fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
6380 			break;
6381 		case LPFC_LINK_SPEED_4GHZ:
6382 			fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
6383 			break;
6384 		case LPFC_LINK_SPEED_8GHZ:
6385 			fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
6386 			break;
6387 		case LPFC_LINK_SPEED_10GHZ:
6388 			fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6389 			break;
6390 		case LPFC_LINK_SPEED_16GHZ:
6391 			fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
6392 			break;
6393 		case LPFC_LINK_SPEED_32GHZ:
6394 			fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
6395 			break;
6396 		case LPFC_LINK_SPEED_64GHZ:
6397 			fc_host_speed(shost) = FC_PORTSPEED_64GBIT;
6398 			break;
6399 		case LPFC_LINK_SPEED_128GHZ:
6400 			fc_host_speed(shost) = FC_PORTSPEED_128GBIT;
6401 			break;
6402 		case LPFC_LINK_SPEED_256GHZ:
6403 			fc_host_speed(shost) = FC_PORTSPEED_256GBIT;
6404 			break;
6405 		default:
6406 			fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6407 			break;
6408 		}
6409 	} else if (lpfc_is_link_up(phba) && (phba->hba_flag & HBA_FCOE_MODE)) {
6410 		switch (phba->fc_linkspeed) {
6411 		case LPFC_ASYNC_LINK_SPEED_1GBPS:
6412 			fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
6413 			break;
6414 		case LPFC_ASYNC_LINK_SPEED_10GBPS:
6415 			fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
6416 			break;
6417 		case LPFC_ASYNC_LINK_SPEED_20GBPS:
6418 			fc_host_speed(shost) = FC_PORTSPEED_20GBIT;
6419 			break;
6420 		case LPFC_ASYNC_LINK_SPEED_25GBPS:
6421 			fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
6422 			break;
6423 		case LPFC_ASYNC_LINK_SPEED_40GBPS:
6424 			fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
6425 			break;
6426 		case LPFC_ASYNC_LINK_SPEED_100GBPS:
6427 			fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
6428 			break;
6429 		default:
6430 			fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6431 			break;
6432 		}
6433 	} else
6434 		fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
6435 
6436 	spin_unlock_irq(shost->host_lock);
6437 }
6438 
6439 /**
6440  * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
6441  * @shost: kernel scsi host pointer.
6442  **/
6443 static void
6444 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
6445 {
6446 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6447 	struct lpfc_hba   *phba = vport->phba;
6448 	u64 node_name;
6449 
6450 	spin_lock_irq(shost->host_lock);
6451 
6452 	if ((vport->port_state > LPFC_FLOGI) &&
6453 	    ((vport->fc_flag & FC_FABRIC) ||
6454 	     ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6455 	      (vport->fc_flag & FC_PUBLIC_LOOP))))
6456 		node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
6457 	else
6458 		/* fabric is local port if there is no F/FL_Port */
6459 		node_name = 0;
6460 
6461 	spin_unlock_irq(shost->host_lock);
6462 
6463 	fc_host_fabric_name(shost) = node_name;
6464 }
6465 
6466 /**
6467  * lpfc_get_stats - Return statistical information about the adapter
6468  * @shost: kernel scsi host pointer.
6469  *
6470  * Notes:
6471  * NULL on error for link down, no mbox pool, sli2 active,
6472  * management not allowed, memory allocation error, or mbox error.
6473  *
6474  * Returns:
6475  * NULL for error
6476  * address of the adapter host statistics
6477  **/
6478 static struct fc_host_statistics *
6479 lpfc_get_stats(struct Scsi_Host *shost)
6480 {
6481 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6482 	struct lpfc_hba   *phba = vport->phba;
6483 	struct lpfc_sli   *psli = &phba->sli;
6484 	struct fc_host_statistics *hs = &phba->link_stats;
6485 	struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
6486 	LPFC_MBOXQ_t *pmboxq;
6487 	MAILBOX_t *pmb;
6488 	int rc = 0;
6489 
6490 	/*
6491 	 * prevent udev from issuing mailbox commands until the port is
6492 	 * configured.
6493 	 */
6494 	if (phba->link_state < LPFC_LINK_DOWN ||
6495 	    !phba->mbox_mem_pool ||
6496 	    (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
6497 		return NULL;
6498 
6499 	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6500 		return NULL;
6501 
6502 	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6503 	if (!pmboxq)
6504 		return NULL;
6505 	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6506 
6507 	pmb = &pmboxq->u.mb;
6508 	pmb->mbxCommand = MBX_READ_STATUS;
6509 	pmb->mbxOwner = OWN_HOST;
6510 	pmboxq->ctx_buf = NULL;
6511 	pmboxq->vport = vport;
6512 
6513 	if (vport->fc_flag & FC_OFFLINE_MODE) {
6514 		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6515 		if (rc != MBX_SUCCESS) {
6516 			mempool_free(pmboxq, phba->mbox_mem_pool);
6517 			return NULL;
6518 		}
6519 	} else {
6520 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6521 		if (rc != MBX_SUCCESS) {
6522 			if (rc != MBX_TIMEOUT)
6523 				mempool_free(pmboxq, phba->mbox_mem_pool);
6524 			return NULL;
6525 		}
6526 	}
6527 
6528 	memset(hs, 0, sizeof (struct fc_host_statistics));
6529 
6530 	hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
6531 	hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
6532 
6533 	/*
6534 	 * The MBX_READ_STATUS returns tx_k_bytes which has to be
6535 	 * converted to words.
6536 	 *
6537 	 * Check if extended byte flag is set, to know when to collect upper
6538 	 * bits of 64 bit wide statistics counter.
6539 	 */
6540 	if (pmb->un.varRdStatus.xkb & RD_ST_XKB) {
6541 		hs->tx_words = (u64)
6542 			       ((((u64)(pmb->un.varRdStatus.xmit_xkb &
6543 					RD_ST_XMIT_XKB_MASK) << 32) |
6544 				(u64)pmb->un.varRdStatus.xmitByteCnt) *
6545 				(u64)256);
6546 		hs->rx_words = (u64)
6547 			       ((((u64)(pmb->un.varRdStatus.rcv_xkb &
6548 					RD_ST_RCV_XKB_MASK) << 32) |
6549 				(u64)pmb->un.varRdStatus.rcvByteCnt) *
6550 				(u64)256);
6551 	} else {
6552 		hs->tx_words = (uint64_t)
6553 				((uint64_t)pmb->un.varRdStatus.xmitByteCnt
6554 				* (uint64_t)256);
6555 		hs->rx_words = (uint64_t)
6556 				((uint64_t)pmb->un.varRdStatus.rcvByteCnt
6557 				 * (uint64_t)256);
6558 	}
6559 
6560 	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
6561 	pmb->mbxCommand = MBX_READ_LNK_STAT;
6562 	pmb->mbxOwner = OWN_HOST;
6563 	pmboxq->ctx_buf = NULL;
6564 	pmboxq->vport = vport;
6565 
6566 	if (vport->fc_flag & FC_OFFLINE_MODE) {
6567 		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6568 		if (rc != MBX_SUCCESS) {
6569 			mempool_free(pmboxq, phba->mbox_mem_pool);
6570 			return NULL;
6571 		}
6572 	} else {
6573 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6574 		if (rc != MBX_SUCCESS) {
6575 			if (rc != MBX_TIMEOUT)
6576 				mempool_free(pmboxq, phba->mbox_mem_pool);
6577 			return NULL;
6578 		}
6579 	}
6580 
6581 	hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6582 	hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6583 	hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6584 	hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6585 	hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6586 	hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6587 	hs->error_frames = pmb->un.varRdLnk.crcCnt;
6588 
6589 	hs->cn_sig_warn = atomic64_read(&phba->cgn_acqe_stat.warn);
6590 	hs->cn_sig_alarm = atomic64_read(&phba->cgn_acqe_stat.alarm);
6591 
6592 	hs->link_failure_count -= lso->link_failure_count;
6593 	hs->loss_of_sync_count -= lso->loss_of_sync_count;
6594 	hs->loss_of_signal_count -= lso->loss_of_signal_count;
6595 	hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
6596 	hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
6597 	hs->invalid_crc_count -= lso->invalid_crc_count;
6598 	hs->error_frames -= lso->error_frames;
6599 
6600 	if (phba->hba_flag & HBA_FCOE_MODE) {
6601 		hs->lip_count = -1;
6602 		hs->nos_count = (phba->link_events >> 1);
6603 		hs->nos_count -= lso->link_events;
6604 	} else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6605 		hs->lip_count = (phba->fc_eventTag >> 1);
6606 		hs->lip_count -= lso->link_events;
6607 		hs->nos_count = -1;
6608 	} else {
6609 		hs->lip_count = -1;
6610 		hs->nos_count = (phba->fc_eventTag >> 1);
6611 		hs->nos_count -= lso->link_events;
6612 	}
6613 
6614 	hs->dumped_frames = -1;
6615 
6616 	hs->seconds_since_last_reset = ktime_get_seconds() - psli->stats_start;
6617 
6618 	mempool_free(pmboxq, phba->mbox_mem_pool);
6619 
6620 	return hs;
6621 }
6622 
6623 /**
6624  * lpfc_reset_stats - Copy the adapter link stats information
6625  * @shost: kernel scsi host pointer.
6626  **/
6627 static void
6628 lpfc_reset_stats(struct Scsi_Host *shost)
6629 {
6630 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6631 	struct lpfc_hba   *phba = vport->phba;
6632 	struct lpfc_sli   *psli = &phba->sli;
6633 	struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
6634 	LPFC_MBOXQ_t *pmboxq;
6635 	MAILBOX_t *pmb;
6636 	int rc = 0;
6637 
6638 	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
6639 		return;
6640 
6641 	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6642 	if (!pmboxq)
6643 		return;
6644 	memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6645 
6646 	pmb = &pmboxq->u.mb;
6647 	pmb->mbxCommand = MBX_READ_STATUS;
6648 	pmb->mbxOwner = OWN_HOST;
6649 	pmb->un.varWords[0] = 0x1; /* reset request */
6650 	pmboxq->ctx_buf = NULL;
6651 	pmboxq->vport = vport;
6652 
6653 	if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6654 		(!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6655 		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6656 		if (rc != MBX_SUCCESS) {
6657 			mempool_free(pmboxq, phba->mbox_mem_pool);
6658 			return;
6659 		}
6660 	} else {
6661 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6662 		if (rc != MBX_SUCCESS) {
6663 			if (rc != MBX_TIMEOUT)
6664 				mempool_free(pmboxq, phba->mbox_mem_pool);
6665 			return;
6666 		}
6667 	}
6668 
6669 	memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
6670 	pmb->mbxCommand = MBX_READ_LNK_STAT;
6671 	pmb->mbxOwner = OWN_HOST;
6672 	pmboxq->ctx_buf = NULL;
6673 	pmboxq->vport = vport;
6674 
6675 	if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6676 	    (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6677 		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
6678 		if (rc != MBX_SUCCESS) {
6679 			mempool_free(pmboxq, phba->mbox_mem_pool);
6680 			return;
6681 		}
6682 	} else {
6683 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
6684 		if (rc != MBX_SUCCESS) {
6685 			if (rc != MBX_TIMEOUT)
6686 				mempool_free(pmboxq, phba->mbox_mem_pool);
6687 			return;
6688 		}
6689 	}
6690 
6691 	lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
6692 	lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
6693 	lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
6694 	lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
6695 	lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
6696 	lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
6697 	lso->error_frames = pmb->un.varRdLnk.crcCnt;
6698 	if (phba->hba_flag & HBA_FCOE_MODE)
6699 		lso->link_events = (phba->link_events >> 1);
6700 	else
6701 		lso->link_events = (phba->fc_eventTag >> 1);
6702 
6703 	atomic64_set(&phba->cgn_acqe_stat.warn, 0);
6704 	atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
6705 
6706 	memset(&shost_to_fc_host(shost)->fpin_stats, 0,
6707 	       sizeof(shost_to_fc_host(shost)->fpin_stats));
6708 
6709 	psli->stats_start = ktime_get_seconds();
6710 
6711 	mempool_free(pmboxq, phba->mbox_mem_pool);
6712 
6713 	return;
6714 }
6715 
6716 /*
6717  * The LPFC driver treats linkdown handling as target loss events so there
6718  * are no sysfs handlers for link_down_tmo.
6719  */
6720 
6721 /**
6722  * lpfc_get_node_by_target - Return the nodelist for a target
6723  * @starget: kernel scsi target pointer.
6724  *
6725  * Returns:
6726  * address of the node list if found
6727  * NULL target not found
6728  **/
6729 static struct lpfc_nodelist *
6730 lpfc_get_node_by_target(struct scsi_target *starget)
6731 {
6732 	struct Scsi_Host  *shost = dev_to_shost(starget->dev.parent);
6733 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
6734 	struct lpfc_nodelist *ndlp;
6735 
6736 	spin_lock_irq(shost->host_lock);
6737 	/* Search for this, mapped, target ID */
6738 	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6739 		if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
6740 		    starget->id == ndlp->nlp_sid) {
6741 			spin_unlock_irq(shost->host_lock);
6742 			return ndlp;
6743 		}
6744 	}
6745 	spin_unlock_irq(shost->host_lock);
6746 	return NULL;
6747 }
6748 
6749 /**
6750  * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
6751  * @starget: kernel scsi target pointer.
6752  **/
6753 static void
6754 lpfc_get_starget_port_id(struct scsi_target *starget)
6755 {
6756 	struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6757 
6758 	fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
6759 }
6760 
6761 /**
6762  * lpfc_get_starget_node_name - Set the target node name
6763  * @starget: kernel scsi target pointer.
6764  *
6765  * Description: Set the target node name to the ndlp node name wwn or zero.
6766  **/
6767 static void
6768 lpfc_get_starget_node_name(struct scsi_target *starget)
6769 {
6770 	struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6771 
6772 	fc_starget_node_name(starget) =
6773 		ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
6774 }
6775 
6776 /**
6777  * lpfc_get_starget_port_name - Set the target port name
6778  * @starget: kernel scsi target pointer.
6779  *
6780  * Description:  set the target port name to the ndlp port name wwn or zero.
6781  **/
6782 static void
6783 lpfc_get_starget_port_name(struct scsi_target *starget)
6784 {
6785 	struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
6786 
6787 	fc_starget_port_name(starget) =
6788 		ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
6789 }
6790 
6791 /**
6792  * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
6793  * @rport: fc rport address.
6794  * @timeout: new value for dev loss tmo.
6795  *
6796  * Description:
6797  * If timeout is non zero set the dev_loss_tmo to timeout, else set
6798  * dev_loss_tmo to one.
6799  **/
6800 static void
6801 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6802 {
6803 	struct lpfc_rport_data *rdata = rport->dd_data;
6804 	struct lpfc_nodelist *ndlp = rdata->pnode;
6805 #if (IS_ENABLED(CONFIG_NVME_FC))
6806 	struct lpfc_nvme_rport *nrport = NULL;
6807 #endif
6808 
6809 	if (timeout)
6810 		rport->dev_loss_tmo = timeout;
6811 	else
6812 		rport->dev_loss_tmo = 1;
6813 
6814 	if (!ndlp) {
6815 		dev_info(&rport->dev, "Cannot find remote node to "
6816 				      "set rport dev loss tmo, port_id x%x\n",
6817 				      rport->port_id);
6818 		return;
6819 	}
6820 
6821 #if (IS_ENABLED(CONFIG_NVME_FC))
6822 	nrport = lpfc_ndlp_get_nrport(ndlp);
6823 
6824 	if (nrport && nrport->remoteport)
6825 		nvme_fc_set_remoteport_devloss(nrport->remoteport,
6826 					       rport->dev_loss_tmo);
6827 #endif
6828 }
6829 
6830 /*
6831  * lpfc_rport_show_function - Return rport target information
6832  *
6833  * Description:
6834  * Macro that uses field to generate a function with the name lpfc_show_rport_
6835  *
6836  * lpfc_show_rport_##field: returns the bytes formatted in buf
6837  * @cdev: class converted to an fc_rport.
6838  * @buf: on return contains the target_field or zero.
6839  *
6840  * Returns: size of formatted string.
6841  **/
6842 #define lpfc_rport_show_function(field, format_string, sz, cast)	\
6843 static ssize_t								\
6844 lpfc_show_rport_##field (struct device *dev,				\
6845 			 struct device_attribute *attr,			\
6846 			 char *buf)					\
6847 {									\
6848 	struct fc_rport *rport = transport_class_to_rport(dev);		\
6849 	struct lpfc_rport_data *rdata = rport->hostdata;		\
6850 	return scnprintf(buf, sz, format_string,			\
6851 		(rdata->target) ? cast rdata->target->field : 0);	\
6852 }
6853 
6854 #define lpfc_rport_rd_attr(field, format_string, sz)			\
6855 	lpfc_rport_show_function(field, format_string, sz, )		\
6856 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6857 
6858 /**
6859  * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6860  * @fc_vport: The fc_vport who's symbolic name has been changed.
6861  *
6862  * Description:
6863  * This function is called by the transport after the @fc_vport's symbolic name
6864  * has been changed. This function re-registers the symbolic name with the
6865  * switch to propagate the change into the fabric if the vport is active.
6866  **/
6867 static void
6868 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6869 {
6870 	struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6871 
6872 	if (vport->port_state == LPFC_VPORT_READY)
6873 		lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6874 }
6875 
6876 /**
6877  * lpfc_hba_log_verbose_init - Set hba's log verbose level
6878  * @phba: Pointer to lpfc_hba struct.
6879  * @verbose: Verbose level to set.
6880  *
6881  * This function is called by the lpfc_get_cfgparam() routine to set the
6882  * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6883  * log message according to the module's lpfc_log_verbose parameter setting
6884  * before hba port or vport created.
6885  **/
6886 static void
6887 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6888 {
6889 	phba->cfg_log_verbose = verbose;
6890 }
6891 
6892 struct fc_function_template lpfc_transport_functions = {
6893 	/* fixed attributes the driver supports */
6894 	.show_host_node_name = 1,
6895 	.show_host_port_name = 1,
6896 	.show_host_supported_classes = 1,
6897 	.show_host_supported_fc4s = 1,
6898 	.show_host_supported_speeds = 1,
6899 	.show_host_maxframe_size = 1,
6900 
6901 	.get_host_symbolic_name = lpfc_get_host_symbolic_name,
6902 	.show_host_symbolic_name = 1,
6903 
6904 	/* dynamic attributes the driver supports */
6905 	.get_host_port_id = lpfc_get_host_port_id,
6906 	.show_host_port_id = 1,
6907 
6908 	.get_host_port_type = lpfc_get_host_port_type,
6909 	.show_host_port_type = 1,
6910 
6911 	.get_host_port_state = lpfc_get_host_port_state,
6912 	.show_host_port_state = 1,
6913 
6914 	/* active_fc4s is shown but doesn't change (thus no get function) */
6915 	.show_host_active_fc4s = 1,
6916 
6917 	.get_host_speed = lpfc_get_host_speed,
6918 	.show_host_speed = 1,
6919 
6920 	.get_host_fabric_name = lpfc_get_host_fabric_name,
6921 	.show_host_fabric_name = 1,
6922 
6923 	/*
6924 	 * The LPFC driver treats linkdown handling as target loss events
6925 	 * so there are no sysfs handlers for link_down_tmo.
6926 	 */
6927 
6928 	.get_fc_host_stats = lpfc_get_stats,
6929 	.reset_fc_host_stats = lpfc_reset_stats,
6930 
6931 	.dd_fcrport_size = sizeof(struct lpfc_rport_data),
6932 	.show_rport_maxframe_size = 1,
6933 	.show_rport_supported_classes = 1,
6934 
6935 	.set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6936 	.show_rport_dev_loss_tmo = 1,
6937 
6938 	.get_starget_port_id  = lpfc_get_starget_port_id,
6939 	.show_starget_port_id = 1,
6940 
6941 	.get_starget_node_name = lpfc_get_starget_node_name,
6942 	.show_starget_node_name = 1,
6943 
6944 	.get_starget_port_name = lpfc_get_starget_port_name,
6945 	.show_starget_port_name = 1,
6946 
6947 	.issue_fc_host_lip = lpfc_issue_lip,
6948 	.dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6949 	.terminate_rport_io = lpfc_terminate_rport_io,
6950 
6951 	.dd_fcvport_size = sizeof(struct lpfc_vport *),
6952 
6953 	.vport_disable = lpfc_vport_disable,
6954 
6955 	.set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6956 
6957 	.bsg_request = lpfc_bsg_request,
6958 	.bsg_timeout = lpfc_bsg_timeout,
6959 };
6960 
6961 struct fc_function_template lpfc_vport_transport_functions = {
6962 	/* fixed attributes the driver supports */
6963 	.show_host_node_name = 1,
6964 	.show_host_port_name = 1,
6965 	.show_host_supported_classes = 1,
6966 	.show_host_supported_fc4s = 1,
6967 	.show_host_supported_speeds = 1,
6968 	.show_host_maxframe_size = 1,
6969 
6970 	.get_host_symbolic_name = lpfc_get_host_symbolic_name,
6971 	.show_host_symbolic_name = 1,
6972 
6973 	/* dynamic attributes the driver supports */
6974 	.get_host_port_id = lpfc_get_host_port_id,
6975 	.show_host_port_id = 1,
6976 
6977 	.get_host_port_type = lpfc_get_host_port_type,
6978 	.show_host_port_type = 1,
6979 
6980 	.get_host_port_state = lpfc_get_host_port_state,
6981 	.show_host_port_state = 1,
6982 
6983 	/* active_fc4s is shown but doesn't change (thus no get function) */
6984 	.show_host_active_fc4s = 1,
6985 
6986 	.get_host_speed = lpfc_get_host_speed,
6987 	.show_host_speed = 1,
6988 
6989 	.get_host_fabric_name = lpfc_get_host_fabric_name,
6990 	.show_host_fabric_name = 1,
6991 
6992 	/*
6993 	 * The LPFC driver treats linkdown handling as target loss events
6994 	 * so there are no sysfs handlers for link_down_tmo.
6995 	 */
6996 
6997 	.get_fc_host_stats = lpfc_get_stats,
6998 	.reset_fc_host_stats = lpfc_reset_stats,
6999 
7000 	.dd_fcrport_size = sizeof(struct lpfc_rport_data),
7001 	.show_rport_maxframe_size = 1,
7002 	.show_rport_supported_classes = 1,
7003 
7004 	.set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
7005 	.show_rport_dev_loss_tmo = 1,
7006 
7007 	.get_starget_port_id  = lpfc_get_starget_port_id,
7008 	.show_starget_port_id = 1,
7009 
7010 	.get_starget_node_name = lpfc_get_starget_node_name,
7011 	.show_starget_node_name = 1,
7012 
7013 	.get_starget_port_name = lpfc_get_starget_port_name,
7014 	.show_starget_port_name = 1,
7015 
7016 	.dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
7017 	.terminate_rport_io = lpfc_terminate_rport_io,
7018 
7019 	.vport_disable = lpfc_vport_disable,
7020 
7021 	.set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
7022 };
7023 
7024 /**
7025  * lpfc_get_hba_function_mode - Used to determine the HBA function in FCoE
7026  * Mode
7027  * @phba: lpfc_hba pointer.
7028  **/
7029 static void
7030 lpfc_get_hba_function_mode(struct lpfc_hba *phba)
7031 {
7032 	/* If the adapter supports FCoE mode */
7033 	switch (phba->pcidev->device) {
7034 	case PCI_DEVICE_ID_SKYHAWK:
7035 	case PCI_DEVICE_ID_SKYHAWK_VF:
7036 	case PCI_DEVICE_ID_LANCER_FCOE:
7037 	case PCI_DEVICE_ID_LANCER_FCOE_VF:
7038 	case PCI_DEVICE_ID_ZEPHYR_DCSP:
7039 	case PCI_DEVICE_ID_TIGERSHARK:
7040 	case PCI_DEVICE_ID_TOMCAT:
7041 		phba->hba_flag |= HBA_FCOE_MODE;
7042 		break;
7043 	default:
7044 	/* for others, clear the flag */
7045 		phba->hba_flag &= ~HBA_FCOE_MODE;
7046 	}
7047 }
7048 
7049 /**
7050  * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
7051  * @phba: lpfc_hba pointer.
7052  **/
7053 void
7054 lpfc_get_cfgparam(struct lpfc_hba *phba)
7055 {
7056 	lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
7057 	lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
7058 	lpfc_ns_query_init(phba, lpfc_ns_query);
7059 	lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
7060 	lpfc_cr_delay_init(phba, lpfc_cr_delay);
7061 	lpfc_cr_count_init(phba, lpfc_cr_count);
7062 	lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
7063 	lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
7064 	lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7065 	lpfc_ack0_init(phba, lpfc_ack0);
7066 	lpfc_xri_rebalancing_init(phba, lpfc_xri_rebalancing);
7067 	lpfc_topology_init(phba, lpfc_topology);
7068 	lpfc_link_speed_init(phba, lpfc_link_speed);
7069 	lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
7070 	lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
7071 	lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
7072 	lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
7073 	lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
7074 	lpfc_fcp_wait_abts_rsp_init(phba, lpfc_fcp_wait_abts_rsp);
7075 	lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
7076 	lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
7077 	lpfc_use_msi_init(phba, lpfc_use_msi);
7078 	lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
7079 	lpfc_nvme_embed_cmd_init(phba, lpfc_nvme_embed_cmd);
7080 	lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
7081 	lpfc_force_rscn_init(phba, lpfc_force_rscn);
7082 	lpfc_cq_poll_threshold_init(phba, lpfc_cq_poll_threshold);
7083 	lpfc_cq_max_proc_limit_init(phba, lpfc_cq_max_proc_limit);
7084 	lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
7085 	lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
7086 	lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
7087 
7088 	lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
7089 	/* VMID Inits */
7090 	lpfc_max_vmid_init(phba, lpfc_max_vmid);
7091 	lpfc_vmid_inactivity_timeout_init(phba, lpfc_vmid_inactivity_timeout);
7092 	lpfc_vmid_app_header_init(phba, lpfc_vmid_app_header);
7093 	lpfc_vmid_priority_tagging_init(phba, lpfc_vmid_priority_tagging);
7094 	if (phba->sli_rev != LPFC_SLI_REV4)
7095 		phba->cfg_EnableXLane = 0;
7096 	lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
7097 
7098 	memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
7099 	memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
7100 	phba->cfg_oas_lun_state = 0;
7101 	phba->cfg_oas_lun_status = 0;
7102 	phba->cfg_oas_flags = 0;
7103 	phba->cfg_oas_priority = 0;
7104 	lpfc_enable_bg_init(phba, lpfc_enable_bg);
7105 	lpfc_prot_mask_init(phba, lpfc_prot_mask);
7106 	lpfc_prot_guard_init(phba, lpfc_prot_guard);
7107 	if (phba->sli_rev == LPFC_SLI_REV4)
7108 		phba->cfg_poll = 0;
7109 	else
7110 		phba->cfg_poll = lpfc_poll;
7111 
7112 	/* Get the function mode */
7113 	lpfc_get_hba_function_mode(phba);
7114 
7115 	/* BlockGuard allowed for FC only. */
7116 	if (phba->cfg_enable_bg && phba->hba_flag & HBA_FCOE_MODE) {
7117 		lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7118 				"0581 BlockGuard feature not supported\n");
7119 		/* If set, clear the BlockGuard support param */
7120 		phba->cfg_enable_bg = 0;
7121 	} else if (phba->cfg_enable_bg) {
7122 		phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
7123 	}
7124 
7125 	lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
7126 
7127 	lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
7128 	lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
7129 	lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
7130 
7131 	/* Initialize first burst. Target vs Initiator are different. */
7132 	lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
7133 	lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
7134 	lpfc_fcp_mq_threshold_init(phba, lpfc_fcp_mq_threshold);
7135 	lpfc_hdw_queue_init(phba, lpfc_hdw_queue);
7136 	lpfc_irq_chann_init(phba, lpfc_irq_chann);
7137 	lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
7138 	lpfc_enable_dpp_init(phba, lpfc_enable_dpp);
7139 	lpfc_enable_mi_init(phba, lpfc_enable_mi);
7140 
7141 	phba->cgn_p.cgn_param_mode = LPFC_CFG_OFF;
7142 	phba->cmf_active_mode = LPFC_CFG_OFF;
7143 	if (lpfc_fabric_cgn_frequency > EDC_CG_SIGFREQ_CNT_MAX ||
7144 	   lpfc_fabric_cgn_frequency < EDC_CG_SIGFREQ_CNT_MIN)
7145 		lpfc_fabric_cgn_frequency = 100; /* 100 ms default */
7146 
7147 	if (phba->sli_rev != LPFC_SLI_REV4) {
7148 		/* NVME only supported on SLI4 */
7149 		phba->nvmet_support = 0;
7150 		phba->cfg_nvmet_mrq = 0;
7151 		phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
7152 		phba->cfg_enable_bbcr = 0;
7153 		phba->cfg_xri_rebalancing = 0;
7154 	} else {
7155 		/* We MUST have FCP support */
7156 		if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
7157 			phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
7158 	}
7159 
7160 	phba->cfg_auto_imax = (phba->cfg_fcp_imax) ? 0 : 1;
7161 
7162 	phba->cfg_enable_pbde = 0;
7163 
7164 	/* A value of 0 means use the number of CPUs found in the system */
7165 	if (phba->cfg_hdw_queue == 0)
7166 		phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7167 	if (phba->cfg_irq_chann == 0)
7168 		phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7169 	if (phba->cfg_irq_chann > phba->cfg_hdw_queue &&
7170 	    phba->sli_rev == LPFC_SLI_REV4)
7171 		phba->cfg_irq_chann = phba->cfg_hdw_queue;
7172 
7173 	lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
7174 	lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
7175 	lpfc_aer_support_init(phba, lpfc_aer_support);
7176 	lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
7177 	lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
7178 	lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
7179 	lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
7180 	lpfc_sli_mode_init(phba, lpfc_sli_mode);
7181 	lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
7182 	lpfc_ras_fwlog_buffsize_init(phba, lpfc_ras_fwlog_buffsize);
7183 	lpfc_ras_fwlog_level_init(phba, lpfc_ras_fwlog_level);
7184 	lpfc_ras_fwlog_func_init(phba, lpfc_ras_fwlog_func);
7185 
7186 	return;
7187 }
7188 
7189 /**
7190  * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
7191  * dependencies between protocols and roles.
7192  * @phba: lpfc_hba pointer.
7193  **/
7194 void
7195 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
7196 {
7197 	int  logit = 0;
7198 
7199 	if (phba->cfg_hdw_queue > phba->sli4_hba.num_present_cpu) {
7200 		phba->cfg_hdw_queue = phba->sli4_hba.num_present_cpu;
7201 		logit = 1;
7202 	}
7203 	if (phba->cfg_irq_chann > phba->sli4_hba.num_present_cpu) {
7204 		phba->cfg_irq_chann = phba->sli4_hba.num_present_cpu;
7205 		logit = 1;
7206 	}
7207 	if (phba->cfg_irq_chann > phba->cfg_hdw_queue) {
7208 		phba->cfg_irq_chann = phba->cfg_hdw_queue;
7209 		logit = 1;
7210 	}
7211 	if (logit)
7212 		lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7213 				"2006 Reducing Queues - CPU limitation: "
7214 				"IRQ %d HDWQ %d\n",
7215 				phba->cfg_irq_chann,
7216 				phba->cfg_hdw_queue);
7217 
7218 	if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
7219 	    phba->nvmet_support) {
7220 		phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
7221 
7222 		lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
7223 				"6013 %s x%x fb_size x%x, fb_max x%x\n",
7224 				"NVME Target PRLI ACC enable_fb ",
7225 				phba->cfg_nvme_enable_fb,
7226 				phba->cfg_nvmet_fb_size,
7227 				LPFC_NVMET_FB_SZ_MAX);
7228 
7229 		if (phba->cfg_nvme_enable_fb == 0)
7230 			phba->cfg_nvmet_fb_size = 0;
7231 		else {
7232 			if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
7233 				phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
7234 		}
7235 
7236 		if (!phba->cfg_nvmet_mrq)
7237 			phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7238 
7239 		/* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
7240 		if (phba->cfg_nvmet_mrq > phba->cfg_hdw_queue) {
7241 			phba->cfg_nvmet_mrq = phba->cfg_hdw_queue;
7242 			lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
7243 					"6018 Adjust lpfc_nvmet_mrq to %d\n",
7244 					phba->cfg_nvmet_mrq);
7245 		}
7246 		if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7247 			phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
7248 
7249 	} else {
7250 		/* Not NVME Target mode.  Turn off Target parameters. */
7251 		phba->nvmet_support = 0;
7252 		phba->cfg_nvmet_mrq = 0;
7253 		phba->cfg_nvmet_fb_size = 0;
7254 	}
7255 }
7256 
7257 /**
7258  * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
7259  * @vport: lpfc_vport pointer.
7260  **/
7261 void
7262 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
7263 {
7264 	lpfc_log_verbose_init(vport, lpfc_log_verbose);
7265 	lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
7266 	lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
7267 	lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
7268 	lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
7269 	lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
7270 	lpfc_restrict_login_init(vport, lpfc_restrict_login);
7271 	lpfc_fcp_class_init(vport, lpfc_fcp_class);
7272 	lpfc_use_adisc_init(vport, lpfc_use_adisc);
7273 	lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
7274 	lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
7275 	lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
7276 	lpfc_max_luns_init(vport, lpfc_max_luns);
7277 	lpfc_scan_down_init(vport, lpfc_scan_down);
7278 	lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
7279 	return;
7280 }
7281