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