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