xref: /linux/drivers/scsi/lpfc/lpfc_attr.c (revision 068df0f34e81bc06c5eb5012ec2eda25624e87aa)
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Fibre Channel Host Bus Adapters.                                *
4  * Copyright (C) 2004-2011 Emulex.  All rights reserved.           *
5  * EMULEX and SLI are trademarks of Emulex.                        *
6  * www.emulex.com                                                  *
7  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
8  *                                                                 *
9  * This program is free software; you can redistribute it and/or   *
10  * modify it under the terms of version 2 of the GNU General       *
11  * Public License as published by the Free Software Foundation.    *
12  * This program is distributed in the hope that it will be useful. *
13  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
14  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
15  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
16  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
18  * more details, a copy of which can be found in the file COPYING  *
19  * included with this package.                                     *
20  *******************************************************************/
21 
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/module.h>
27 #include <linux/aer.h>
28 #include <linux/gfp.h>
29 #include <linux/kernel.h>
30 
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_tcq.h>
35 #include <scsi/scsi_transport_fc.h>
36 #include <scsi/fc/fc_fs.h>
37 
38 #include "lpfc_hw4.h"
39 #include "lpfc_hw.h"
40 #include "lpfc_sli.h"
41 #include "lpfc_sli4.h"
42 #include "lpfc_nl.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
45 #include "lpfc.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_version.h"
48 #include "lpfc_compat.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
51 
52 #define LPFC_DEF_DEVLOSS_TMO 30
53 #define LPFC_MIN_DEVLOSS_TMO 1
54 #define LPFC_MAX_DEVLOSS_TMO 255
55 
56 /*
57  * Write key size should be multiple of 4. If write key is changed
58  * make sure that library write key is also changed.
59  */
60 #define LPFC_REG_WRITE_KEY_SIZE	4
61 #define LPFC_REG_WRITE_KEY	"EMLX"
62 
63 /**
64  * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
65  * @incr: integer to convert.
66  * @hdw: ascii string holding converted integer plus a string terminator.
67  *
68  * Description:
69  * JEDEC Joint Electron Device Engineering Council.
70  * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
71  * character string. The string is then terminated with a NULL in byte 9.
72  * Hex 0-9 becomes ascii '0' to '9'.
73  * Hex a-f becomes ascii '=' to 'B' capital B.
74  *
75  * Notes:
76  * Coded for 32 bit integers only.
77  **/
78 static void
79 lpfc_jedec_to_ascii(int incr, char hdw[])
80 {
81 	int i, j;
82 	for (i = 0; i < 8; i++) {
83 		j = (incr & 0xf);
84 		if (j <= 9)
85 			hdw[7 - i] = 0x30 +  j;
86 		 else
87 			hdw[7 - i] = 0x61 + j - 10;
88 		incr = (incr >> 4);
89 	}
90 	hdw[8] = 0;
91 	return;
92 }
93 
94 /**
95  * lpfc_drvr_version_show - Return the Emulex driver string with version number
96  * @dev: class unused variable.
97  * @attr: device attribute, not used.
98  * @buf: on return contains the module description text.
99  *
100  * Returns: size of formatted string.
101  **/
102 static ssize_t
103 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
104 		       char *buf)
105 {
106 	return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
107 }
108 
109 /**
110  * lpfc_enable_fip_show - Return the fip mode of the HBA
111  * @dev: class unused variable.
112  * @attr: device attribute, not used.
113  * @buf: on return contains the module description text.
114  *
115  * Returns: size of formatted string.
116  **/
117 static ssize_t
118 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
119 		       char *buf)
120 {
121 	struct Scsi_Host *shost = class_to_shost(dev);
122 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
123 	struct lpfc_hba   *phba = vport->phba;
124 
125 	if (phba->hba_flag & HBA_FIP_SUPPORT)
126 		return snprintf(buf, PAGE_SIZE, "1\n");
127 	else
128 		return snprintf(buf, PAGE_SIZE, "0\n");
129 }
130 
131 static ssize_t
132 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
133 		  char *buf)
134 {
135 	struct Scsi_Host *shost = class_to_shost(dev);
136 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 	struct lpfc_hba   *phba = vport->phba;
138 
139 	if (phba->cfg_enable_bg)
140 		if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
141 			return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
142 		else
143 			return snprintf(buf, PAGE_SIZE,
144 					"BlockGuard Not Supported\n");
145 	else
146 			return snprintf(buf, PAGE_SIZE,
147 					"BlockGuard Disabled\n");
148 }
149 
150 static ssize_t
151 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
152 		       char *buf)
153 {
154 	struct Scsi_Host *shost = class_to_shost(dev);
155 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
156 	struct lpfc_hba   *phba = vport->phba;
157 
158 	return snprintf(buf, PAGE_SIZE, "%llu\n",
159 			(unsigned long long)phba->bg_guard_err_cnt);
160 }
161 
162 static ssize_t
163 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
164 			char *buf)
165 {
166 	struct Scsi_Host *shost = class_to_shost(dev);
167 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
168 	struct lpfc_hba   *phba = vport->phba;
169 
170 	return snprintf(buf, PAGE_SIZE, "%llu\n",
171 			(unsigned long long)phba->bg_apptag_err_cnt);
172 }
173 
174 static ssize_t
175 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
176 			char *buf)
177 {
178 	struct Scsi_Host *shost = class_to_shost(dev);
179 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
180 	struct lpfc_hba   *phba = vport->phba;
181 
182 	return snprintf(buf, PAGE_SIZE, "%llu\n",
183 			(unsigned long long)phba->bg_reftag_err_cnt);
184 }
185 
186 /**
187  * lpfc_info_show - Return some pci info about the host in ascii
188  * @dev: class converted to a Scsi_host structure.
189  * @attr: device attribute, not used.
190  * @buf: on return contains the formatted text from lpfc_info().
191  *
192  * Returns: size of formatted string.
193  **/
194 static ssize_t
195 lpfc_info_show(struct device *dev, struct device_attribute *attr,
196 	       char *buf)
197 {
198 	struct Scsi_Host *host = class_to_shost(dev);
199 
200 	return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
201 }
202 
203 /**
204  * lpfc_serialnum_show - Return the hba serial number in ascii
205  * @dev: class converted to a Scsi_host structure.
206  * @attr: device attribute, not used.
207  * @buf: on return contains the formatted text serial number.
208  *
209  * Returns: size of formatted string.
210  **/
211 static ssize_t
212 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
213 		    char *buf)
214 {
215 	struct Scsi_Host  *shost = class_to_shost(dev);
216 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
217 	struct lpfc_hba   *phba = vport->phba;
218 
219 	return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
220 }
221 
222 /**
223  * lpfc_temp_sensor_show - Return the temperature sensor level
224  * @dev: class converted to a Scsi_host structure.
225  * @attr: device attribute, not used.
226  * @buf: on return contains the formatted support level.
227  *
228  * Description:
229  * Returns a number indicating the temperature sensor level currently
230  * supported, zero or one in ascii.
231  *
232  * Returns: size of formatted string.
233  **/
234 static ssize_t
235 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
236 		      char *buf)
237 {
238 	struct Scsi_Host *shost = class_to_shost(dev);
239 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240 	struct lpfc_hba   *phba = vport->phba;
241 	return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
242 }
243 
244 /**
245  * lpfc_modeldesc_show - Return the model description of the hba
246  * @dev: class converted to a Scsi_host structure.
247  * @attr: device attribute, not used.
248  * @buf: on return contains the scsi vpd model description.
249  *
250  * Returns: size of formatted string.
251  **/
252 static ssize_t
253 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
254 		    char *buf)
255 {
256 	struct Scsi_Host  *shost = class_to_shost(dev);
257 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
258 	struct lpfc_hba   *phba = vport->phba;
259 
260 	return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
261 }
262 
263 /**
264  * lpfc_modelname_show - Return the model name of the hba
265  * @dev: class converted to a Scsi_host structure.
266  * @attr: device attribute, not used.
267  * @buf: on return contains the scsi vpd model name.
268  *
269  * Returns: size of formatted string.
270  **/
271 static ssize_t
272 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
273 		    char *buf)
274 {
275 	struct Scsi_Host  *shost = class_to_shost(dev);
276 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
277 	struct lpfc_hba   *phba = vport->phba;
278 
279 	return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
280 }
281 
282 /**
283  * lpfc_programtype_show - Return the program type of the hba
284  * @dev: class converted to a Scsi_host structure.
285  * @attr: device attribute, not used.
286  * @buf: on return contains the scsi vpd program type.
287  *
288  * Returns: size of formatted string.
289  **/
290 static ssize_t
291 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
292 		      char *buf)
293 {
294 	struct Scsi_Host  *shost = class_to_shost(dev);
295 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
296 	struct lpfc_hba   *phba = vport->phba;
297 
298 	return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
299 }
300 
301 /**
302  * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
303  * @dev: class converted to a Scsi_host structure.
304  * @attr: device attribute, not used.
305  * @buf: on return contains the Menlo Maintenance sli flag.
306  *
307  * Returns: size of formatted string.
308  **/
309 static ssize_t
310 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
311 {
312 	struct Scsi_Host  *shost = class_to_shost(dev);
313 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
314 	struct lpfc_hba   *phba = vport->phba;
315 
316 	return snprintf(buf, PAGE_SIZE, "%d\n",
317 		(phba->sli.sli_flag & LPFC_MENLO_MAINT));
318 }
319 
320 /**
321  * lpfc_vportnum_show - Return the port number in ascii of the hba
322  * @dev: class converted to a Scsi_host structure.
323  * @attr: device attribute, not used.
324  * @buf: on return contains scsi vpd program type.
325  *
326  * Returns: size of formatted string.
327  **/
328 static ssize_t
329 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
330 		   char *buf)
331 {
332 	struct Scsi_Host  *shost = class_to_shost(dev);
333 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
334 	struct lpfc_hba   *phba = vport->phba;
335 
336 	return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
337 }
338 
339 /**
340  * lpfc_fwrev_show - Return the firmware rev running in the hba
341  * @dev: class converted to a Scsi_host structure.
342  * @attr: device attribute, not used.
343  * @buf: on return contains the scsi vpd program type.
344  *
345  * Returns: size of formatted string.
346  **/
347 static ssize_t
348 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
349 		char *buf)
350 {
351 	struct Scsi_Host  *shost = class_to_shost(dev);
352 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353 	struct lpfc_hba   *phba = vport->phba;
354 	char fwrev[32];
355 
356 	lpfc_decode_firmware_rev(phba, fwrev, 1);
357 	return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
358 }
359 
360 /**
361  * lpfc_hdw_show - Return the jedec information about the hba
362  * @dev: class converted to a Scsi_host structure.
363  * @attr: device attribute, not used.
364  * @buf: on return contains the scsi vpd program type.
365  *
366  * Returns: size of formatted string.
367  **/
368 static ssize_t
369 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
370 {
371 	char hdw[9];
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 	lpfc_vpd_t *vp = &phba->vpd;
376 
377 	lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
378 	return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
379 }
380 
381 /**
382  * lpfc_option_rom_version_show - Return the adapter ROM FCode version
383  * @dev: class converted to a Scsi_host structure.
384  * @attr: device attribute, not used.
385  * @buf: on return contains the ROM and FCode ascii strings.
386  *
387  * Returns: size of formatted string.
388  **/
389 static ssize_t
390 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
391 			     char *buf)
392 {
393 	struct Scsi_Host  *shost = class_to_shost(dev);
394 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
395 	struct lpfc_hba   *phba = vport->phba;
396 
397 	return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
398 }
399 
400 /**
401  * lpfc_state_show - Return the link state of the port
402  * @dev: class converted to a Scsi_host structure.
403  * @attr: device attribute, not used.
404  * @buf: on return contains text describing the state of the link.
405  *
406  * Notes:
407  * The switch statement has no default so zero will be returned.
408  *
409  * Returns: size of formatted string.
410  **/
411 static ssize_t
412 lpfc_link_state_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 	int  len = 0;
419 
420 	switch (phba->link_state) {
421 	case LPFC_LINK_UNKNOWN:
422 	case LPFC_WARM_START:
423 	case LPFC_INIT_START:
424 	case LPFC_INIT_MBX_CMDS:
425 	case LPFC_LINK_DOWN:
426 	case LPFC_HBA_ERROR:
427 		if (phba->hba_flag & LINK_DISABLED)
428 			len += snprintf(buf + len, PAGE_SIZE-len,
429 				"Link Down - User disabled\n");
430 		else
431 			len += snprintf(buf + len, PAGE_SIZE-len,
432 				"Link Down\n");
433 		break;
434 	case LPFC_LINK_UP:
435 	case LPFC_CLEAR_LA:
436 	case LPFC_HBA_READY:
437 		len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
438 
439 		switch (vport->port_state) {
440 		case LPFC_LOCAL_CFG_LINK:
441 			len += snprintf(buf + len, PAGE_SIZE-len,
442 					"Configuring Link\n");
443 			break;
444 		case LPFC_FDISC:
445 		case LPFC_FLOGI:
446 		case LPFC_FABRIC_CFG_LINK:
447 		case LPFC_NS_REG:
448 		case LPFC_NS_QRY:
449 		case LPFC_BUILD_DISC_LIST:
450 		case LPFC_DISC_AUTH:
451 			len += snprintf(buf + len, PAGE_SIZE - len,
452 					"Discovery\n");
453 			break;
454 		case LPFC_VPORT_READY:
455 			len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
456 			break;
457 
458 		case LPFC_VPORT_FAILED:
459 			len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
460 			break;
461 
462 		case LPFC_VPORT_UNKNOWN:
463 			len += snprintf(buf + len, PAGE_SIZE - len,
464 					"Unknown\n");
465 			break;
466 		}
467 		if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
468 			len += snprintf(buf + len, PAGE_SIZE-len,
469 					"   Menlo Maint Mode\n");
470 		else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
471 			if (vport->fc_flag & FC_PUBLIC_LOOP)
472 				len += snprintf(buf + len, PAGE_SIZE-len,
473 						"   Public Loop\n");
474 			else
475 				len += snprintf(buf + len, PAGE_SIZE-len,
476 						"   Private Loop\n");
477 		} else {
478 			if (vport->fc_flag & FC_FABRIC)
479 				len += snprintf(buf + len, PAGE_SIZE-len,
480 						"   Fabric\n");
481 			else
482 				len += snprintf(buf + len, PAGE_SIZE-len,
483 						"   Point-2-Point\n");
484 		}
485 	}
486 
487 	return len;
488 }
489 
490 /**
491  * lpfc_link_state_store - Transition the link_state on an HBA port
492  * @dev: class device that is converted into a Scsi_host.
493  * @attr: device attribute, not used.
494  * @buf: one or more lpfc_polling_flags values.
495  * @count: not used.
496  *
497  * Returns:
498  * -EINVAL if the buffer is not "up" or "down"
499  * return from link state change function if non-zero
500  * length of the buf on success
501  **/
502 static ssize_t
503 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
504 		const char *buf, size_t count)
505 {
506 	struct Scsi_Host  *shost = class_to_shost(dev);
507 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
508 	struct lpfc_hba   *phba = vport->phba;
509 
510 	int status = -EINVAL;
511 
512 	if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
513 			(phba->link_state == LPFC_LINK_DOWN))
514 		status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
515 	else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
516 			(phba->link_state >= LPFC_LINK_UP))
517 		status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
518 
519 	if (status == 0)
520 		return strlen(buf);
521 	else
522 		return status;
523 }
524 
525 /**
526  * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
527  * @dev: class device that is converted into a Scsi_host.
528  * @attr: device attribute, not used.
529  * @buf: on return contains the sum of fc mapped and unmapped.
530  *
531  * Description:
532  * Returns the ascii text number of the sum of the fc mapped and unmapped
533  * vport counts.
534  *
535  * Returns: size of formatted string.
536  **/
537 static ssize_t
538 lpfc_num_discovered_ports_show(struct device *dev,
539 			       struct device_attribute *attr, char *buf)
540 {
541 	struct Scsi_Host  *shost = class_to_shost(dev);
542 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
543 
544 	return snprintf(buf, PAGE_SIZE, "%d\n",
545 			vport->fc_map_cnt + vport->fc_unmap_cnt);
546 }
547 
548 /**
549  * lpfc_issue_lip - Misnomer, name carried over from long ago
550  * @shost: Scsi_Host pointer.
551  *
552  * Description:
553  * Bring the link down gracefully then re-init the link. The firmware will
554  * re-init the fiber channel interface as required. Does not issue a LIP.
555  *
556  * Returns:
557  * -EPERM port offline or management commands are being blocked
558  * -ENOMEM cannot allocate memory for the mailbox command
559  * -EIO error sending the mailbox command
560  * zero for success
561  **/
562 static int
563 lpfc_issue_lip(struct Scsi_Host *shost)
564 {
565 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
566 	struct lpfc_hba   *phba = vport->phba;
567 	LPFC_MBOXQ_t *pmboxq;
568 	int mbxstatus = MBXERR_ERROR;
569 
570 	if ((vport->fc_flag & FC_OFFLINE_MODE) ||
571 	    (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
572 		return -EPERM;
573 
574 	pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
575 
576 	if (!pmboxq)
577 		return -ENOMEM;
578 
579 	memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
580 	pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
581 	pmboxq->u.mb.mbxOwner = OWN_HOST;
582 
583 	mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
584 
585 	if ((mbxstatus == MBX_SUCCESS) &&
586 	    (pmboxq->u.mb.mbxStatus == 0 ||
587 	     pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
588 		memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
589 		lpfc_init_link(phba, pmboxq, phba->cfg_topology,
590 			       phba->cfg_link_speed);
591 		mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
592 						     phba->fc_ratov * 2);
593 		if ((mbxstatus == MBX_SUCCESS) &&
594 		    (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
595 			lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
596 					"2859 SLI authentication is required "
597 					"for INIT_LINK but has not done yet\n");
598 	}
599 
600 	lpfc_set_loopback_flag(phba);
601 	if (mbxstatus != MBX_TIMEOUT)
602 		mempool_free(pmboxq, phba->mbox_mem_pool);
603 
604 	if (mbxstatus == MBXERR_ERROR)
605 		return -EIO;
606 
607 	return 0;
608 }
609 
610 /**
611  * lpfc_do_offline - Issues a mailbox command to bring the link down
612  * @phba: lpfc_hba pointer.
613  * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
614  *
615  * Notes:
616  * Assumes any error from lpfc_do_offline() will be negative.
617  * Can wait up to 5 seconds for the port ring buffers count
618  * to reach zero, prints a warning if it is not zero and continues.
619  * lpfc_workq_post_event() returns a non-zero return code if call fails.
620  *
621  * Returns:
622  * -EIO error posting the event
623  * zero for success
624  **/
625 static int
626 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
627 {
628 	struct completion online_compl;
629 	struct lpfc_sli_ring *pring;
630 	struct lpfc_sli *psli;
631 	int status = 0;
632 	int cnt = 0;
633 	int i;
634 	int rc;
635 
636 	init_completion(&online_compl);
637 	rc = lpfc_workq_post_event(phba, &status, &online_compl,
638 			      LPFC_EVT_OFFLINE_PREP);
639 	if (rc == 0)
640 		return -ENOMEM;
641 
642 	wait_for_completion(&online_compl);
643 
644 	if (status != 0)
645 		return -EIO;
646 
647 	psli = &phba->sli;
648 
649 	/* Wait a little for things to settle down, but not
650 	 * long enough for dev loss timeout to expire.
651 	 */
652 	for (i = 0; i < psli->num_rings; i++) {
653 		pring = &psli->ring[i];
654 		while (pring->txcmplq_cnt) {
655 			msleep(10);
656 			if (cnt++ > 500) {  /* 5 secs */
657 				lpfc_printf_log(phba,
658 					KERN_WARNING, LOG_INIT,
659 					"0466 Outstanding IO when "
660 					"bringing Adapter offline\n");
661 				break;
662 			}
663 		}
664 	}
665 
666 	init_completion(&online_compl);
667 	rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
668 	if (rc == 0)
669 		return -ENOMEM;
670 
671 	wait_for_completion(&online_compl);
672 
673 	if (status != 0)
674 		return -EIO;
675 
676 	return 0;
677 }
678 
679 /**
680  * lpfc_selective_reset - Offline then onlines the port
681  * @phba: lpfc_hba pointer.
682  *
683  * Description:
684  * If the port is configured to allow a reset then the hba is brought
685  * offline then online.
686  *
687  * Notes:
688  * Assumes any error from lpfc_do_offline() will be negative.
689  * Do not make this function static.
690  *
691  * Returns:
692  * lpfc_do_offline() return code if not zero
693  * -EIO reset not configured or error posting the event
694  * zero for success
695  **/
696 int
697 lpfc_selective_reset(struct lpfc_hba *phba)
698 {
699 	struct completion online_compl;
700 	int status = 0;
701 	int rc;
702 
703 	if (!phba->cfg_enable_hba_reset)
704 		return -EACCES;
705 
706 	status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
707 
708 	if (status != 0)
709 		return status;
710 
711 	init_completion(&online_compl);
712 	rc = lpfc_workq_post_event(phba, &status, &online_compl,
713 			      LPFC_EVT_ONLINE);
714 	if (rc == 0)
715 		return -ENOMEM;
716 
717 	wait_for_completion(&online_compl);
718 
719 	if (status != 0)
720 		return -EIO;
721 
722 	return 0;
723 }
724 
725 /**
726  * lpfc_issue_reset - Selectively resets an adapter
727  * @dev: class device that is converted into a Scsi_host.
728  * @attr: device attribute, not used.
729  * @buf: containing the string "selective".
730  * @count: unused variable.
731  *
732  * Description:
733  * If the buf contains the string "selective" then lpfc_selective_reset()
734  * is called to perform the reset.
735  *
736  * Notes:
737  * Assumes any error from lpfc_selective_reset() will be negative.
738  * If lpfc_selective_reset() returns zero then the length of the buffer
739  * is returned which indicates success
740  *
741  * Returns:
742  * -EINVAL if the buffer does not contain the string "selective"
743  * length of buf if lpfc-selective_reset() if the call succeeds
744  * return value of lpfc_selective_reset() if the call fails
745 **/
746 static ssize_t
747 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
748 		 const char *buf, size_t count)
749 {
750 	struct Scsi_Host  *shost = class_to_shost(dev);
751 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
752 	struct lpfc_hba   *phba = vport->phba;
753 	int status = -EINVAL;
754 
755 	if (!phba->cfg_enable_hba_reset)
756 		return -EACCES;
757 
758 	if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
759 		status = phba->lpfc_selective_reset(phba);
760 
761 	if (status == 0)
762 		return strlen(buf);
763 	else
764 		return status;
765 }
766 
767 /**
768  * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
769  * @phba: lpfc_hba pointer.
770  *
771  * Description:
772  * SLI4 interface type-2 device to wait on the sliport status register for
773  * the readyness after performing a firmware reset.
774  *
775  * Returns:
776  * zero for success
777  **/
778 int
779 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
780 {
781 	struct lpfc_register portstat_reg = {0};
782 	int i;
783 
784 	msleep(100);
785 	lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
786 		   &portstat_reg.word0);
787 
788 	/* verify if privilaged for the request operation */
789 	if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
790 	    !bf_get(lpfc_sliport_status_err, &portstat_reg))
791 		return -EPERM;
792 
793 	/* wait for the SLI port firmware ready after firmware reset */
794 	for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
795 		msleep(10);
796 		lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
797 			   &portstat_reg.word0);
798 		if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
799 			continue;
800 		if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
801 			continue;
802 		if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
803 			continue;
804 		break;
805 	}
806 
807 	if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
808 		return 0;
809 	else
810 		return -EIO;
811 }
812 
813 /**
814  * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
815  * @phba: lpfc_hba pointer.
816  *
817  * Description:
818  * Request SLI4 interface type-2 device to perform a physical register set
819  * access.
820  *
821  * Returns:
822  * zero for success
823  **/
824 static ssize_t
825 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
826 {
827 	struct completion online_compl;
828 	struct pci_dev *pdev = phba->pcidev;
829 	uint32_t reg_val;
830 	int status = 0;
831 	int rc;
832 
833 	if (!phba->cfg_enable_hba_reset)
834 		return -EACCES;
835 
836 	if ((phba->sli_rev < LPFC_SLI_REV4) ||
837 	    (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
838 	     LPFC_SLI_INTF_IF_TYPE_2))
839 		return -EPERM;
840 
841 	/* Disable SR-IOV virtual functions if enabled */
842 	if (phba->cfg_sriov_nr_virtfn) {
843 		pci_disable_sriov(pdev);
844 		phba->cfg_sriov_nr_virtfn = 0;
845 	}
846 	status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
847 
848 	if (status != 0)
849 		return status;
850 
851 	/* wait for the device to be quiesced before firmware reset */
852 	msleep(100);
853 
854 	reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
855 			LPFC_CTL_PDEV_CTL_OFFSET);
856 
857 	if (opcode == LPFC_FW_DUMP)
858 		reg_val |= LPFC_FW_DUMP_REQUEST;
859 	else if (opcode == LPFC_FW_RESET)
860 		reg_val |= LPFC_CTL_PDEV_CTL_FRST;
861 	else if (opcode == LPFC_DV_RESET)
862 		reg_val |= LPFC_CTL_PDEV_CTL_DRST;
863 
864 	writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
865 	       LPFC_CTL_PDEV_CTL_OFFSET);
866 	/* flush */
867 	readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
868 
869 	/* delay driver action following IF_TYPE_2 reset */
870 	rc = lpfc_sli4_pdev_status_reg_wait(phba);
871 
872 	if (rc)
873 		return rc;
874 
875 	init_completion(&online_compl);
876 	rc = lpfc_workq_post_event(phba, &status, &online_compl,
877 				   LPFC_EVT_ONLINE);
878 	if (rc == 0)
879 		return -ENOMEM;
880 
881 	wait_for_completion(&online_compl);
882 
883 	if (status != 0)
884 		return -EIO;
885 
886 	return 0;
887 }
888 
889 /**
890  * lpfc_nport_evt_cnt_show - Return the number of nport events
891  * @dev: class device that is converted into a Scsi_host.
892  * @attr: device attribute, not used.
893  * @buf: on return contains the ascii number of nport events.
894  *
895  * Returns: size of formatted string.
896  **/
897 static ssize_t
898 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
899 			char *buf)
900 {
901 	struct Scsi_Host  *shost = class_to_shost(dev);
902 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
903 	struct lpfc_hba   *phba = vport->phba;
904 
905 	return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
906 }
907 
908 /**
909  * lpfc_board_mode_show - Return the state of the board
910  * @dev: class device that is converted into a Scsi_host.
911  * @attr: device attribute, not used.
912  * @buf: on return contains the state of the adapter.
913  *
914  * Returns: size of formatted string.
915  **/
916 static ssize_t
917 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
918 		     char *buf)
919 {
920 	struct Scsi_Host  *shost = class_to_shost(dev);
921 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
922 	struct lpfc_hba   *phba = vport->phba;
923 	char  * state;
924 
925 	if (phba->link_state == LPFC_HBA_ERROR)
926 		state = "error";
927 	else if (phba->link_state == LPFC_WARM_START)
928 		state = "warm start";
929 	else if (phba->link_state == LPFC_INIT_START)
930 		state = "offline";
931 	else
932 		state = "online";
933 
934 	return snprintf(buf, PAGE_SIZE, "%s\n", state);
935 }
936 
937 /**
938  * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
939  * @dev: class device that is converted into a Scsi_host.
940  * @attr: device attribute, not used.
941  * @buf: containing one of the strings "online", "offline", "warm" or "error".
942  * @count: unused variable.
943  *
944  * Returns:
945  * -EACCES if enable hba reset not enabled
946  * -EINVAL if the buffer does not contain a valid string (see above)
947  * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
948  * buf length greater than zero indicates success
949  **/
950 static ssize_t
951 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
952 		      const char *buf, size_t count)
953 {
954 	struct Scsi_Host  *shost = class_to_shost(dev);
955 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
956 	struct lpfc_hba   *phba = vport->phba;
957 	struct completion online_compl;
958 	int status=0;
959 	int rc;
960 
961 	if (!phba->cfg_enable_hba_reset)
962 		return -EACCES;
963 
964 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
965 		"3050 lpfc_board_mode set to %s\n", buf);
966 
967 	init_completion(&online_compl);
968 
969 	if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
970 		rc = lpfc_workq_post_event(phba, &status, &online_compl,
971 				      LPFC_EVT_ONLINE);
972 		if (rc == 0)
973 			return -ENOMEM;
974 		wait_for_completion(&online_compl);
975 	} else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
976 		status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
977 	else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
978 		if (phba->sli_rev == LPFC_SLI_REV4)
979 			return -EINVAL;
980 		else
981 			status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
982 	else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
983 		if (phba->sli_rev == LPFC_SLI_REV4)
984 			return -EINVAL;
985 		else
986 			status = lpfc_do_offline(phba, LPFC_EVT_KILL);
987 	else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
988 		status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
989 	else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
990 		status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
991 	else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
992 		status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
993 	else
994 		return -EINVAL;
995 
996 	if (!status)
997 		return strlen(buf);
998 	else
999 		return status;
1000 }
1001 
1002 /**
1003  * lpfc_get_hba_info - Return various bits of informaton about the adapter
1004  * @phba: pointer to the adapter structure.
1005  * @mxri: max xri count.
1006  * @axri: available xri count.
1007  * @mrpi: max rpi count.
1008  * @arpi: available rpi count.
1009  * @mvpi: max vpi count.
1010  * @avpi: available vpi count.
1011  *
1012  * Description:
1013  * If an integer pointer for an count is not null then the value for the
1014  * count is returned.
1015  *
1016  * Returns:
1017  * zero on error
1018  * one for success
1019  **/
1020 static int
1021 lpfc_get_hba_info(struct lpfc_hba *phba,
1022 		  uint32_t *mxri, uint32_t *axri,
1023 		  uint32_t *mrpi, uint32_t *arpi,
1024 		  uint32_t *mvpi, uint32_t *avpi)
1025 {
1026 	struct lpfc_mbx_read_config *rd_config;
1027 	LPFC_MBOXQ_t *pmboxq;
1028 	MAILBOX_t *pmb;
1029 	int rc = 0;
1030 	uint32_t max_vpi;
1031 
1032 	/*
1033 	 * prevent udev from issuing mailbox commands until the port is
1034 	 * configured.
1035 	 */
1036 	if (phba->link_state < LPFC_LINK_DOWN ||
1037 	    !phba->mbox_mem_pool ||
1038 	    (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1039 		return 0;
1040 
1041 	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1042 		return 0;
1043 
1044 	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1045 	if (!pmboxq)
1046 		return 0;
1047 	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1048 
1049 	pmb = &pmboxq->u.mb;
1050 	pmb->mbxCommand = MBX_READ_CONFIG;
1051 	pmb->mbxOwner = OWN_HOST;
1052 	pmboxq->context1 = NULL;
1053 
1054 	if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1055 		rc = MBX_NOT_FINISHED;
1056 	else
1057 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1058 
1059 	if (rc != MBX_SUCCESS) {
1060 		if (rc != MBX_TIMEOUT)
1061 			mempool_free(pmboxq, phba->mbox_mem_pool);
1062 		return 0;
1063 	}
1064 
1065 	if (phba->sli_rev == LPFC_SLI_REV4) {
1066 		rd_config = &pmboxq->u.mqe.un.rd_config;
1067 		if (mrpi)
1068 			*mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1069 		if (arpi)
1070 			*arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1071 					phba->sli4_hba.max_cfg_param.rpi_used;
1072 		if (mxri)
1073 			*mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1074 		if (axri)
1075 			*axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1076 					phba->sli4_hba.max_cfg_param.xri_used;
1077 
1078 		/* Account for differences with SLI-3.  Get vpi count from
1079 		 * mailbox data and subtract one for max vpi value.
1080 		 */
1081 		max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1082 			(bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1083 
1084 		if (mvpi)
1085 			*mvpi = max_vpi;
1086 		if (avpi)
1087 			*avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1088 	} else {
1089 		if (mrpi)
1090 			*mrpi = pmb->un.varRdConfig.max_rpi;
1091 		if (arpi)
1092 			*arpi = pmb->un.varRdConfig.avail_rpi;
1093 		if (mxri)
1094 			*mxri = pmb->un.varRdConfig.max_xri;
1095 		if (axri)
1096 			*axri = pmb->un.varRdConfig.avail_xri;
1097 		if (mvpi)
1098 			*mvpi = pmb->un.varRdConfig.max_vpi;
1099 		if (avpi)
1100 			*avpi = pmb->un.varRdConfig.avail_vpi;
1101 	}
1102 
1103 	mempool_free(pmboxq, phba->mbox_mem_pool);
1104 	return 1;
1105 }
1106 
1107 /**
1108  * lpfc_max_rpi_show - Return maximum rpi
1109  * @dev: class device that is converted into a Scsi_host.
1110  * @attr: device attribute, not used.
1111  * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1112  *
1113  * Description:
1114  * Calls lpfc_get_hba_info() asking for just the mrpi count.
1115  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1116  * to "Unknown" and the buffer length is returned, therefore the caller
1117  * must check for "Unknown" in the buffer to detect a failure.
1118  *
1119  * Returns: size of formatted string.
1120  **/
1121 static ssize_t
1122 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1123 		  char *buf)
1124 {
1125 	struct Scsi_Host  *shost = class_to_shost(dev);
1126 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1127 	struct lpfc_hba   *phba = vport->phba;
1128 	uint32_t cnt;
1129 
1130 	if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1131 		return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1132 	return snprintf(buf, PAGE_SIZE, "Unknown\n");
1133 }
1134 
1135 /**
1136  * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1137  * @dev: class device that is converted into a Scsi_host.
1138  * @attr: device attribute, not used.
1139  * @buf: containing the used rpi count in decimal or "Unknown".
1140  *
1141  * Description:
1142  * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1143  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1144  * to "Unknown" and the buffer length is returned, therefore the caller
1145  * must check for "Unknown" in the buffer to detect a failure.
1146  *
1147  * Returns: size of formatted string.
1148  **/
1149 static ssize_t
1150 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1151 		   char *buf)
1152 {
1153 	struct Scsi_Host  *shost = class_to_shost(dev);
1154 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1155 	struct lpfc_hba   *phba = vport->phba;
1156 	uint32_t cnt, acnt;
1157 
1158 	if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1159 		return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1160 	return snprintf(buf, PAGE_SIZE, "Unknown\n");
1161 }
1162 
1163 /**
1164  * lpfc_max_xri_show - Return maximum xri
1165  * @dev: class device that is converted into a Scsi_host.
1166  * @attr: device attribute, not used.
1167  * @buf: on return contains the maximum xri count in decimal or "Unknown".
1168  *
1169  * Description:
1170  * Calls lpfc_get_hba_info() asking for just the mrpi count.
1171  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1172  * to "Unknown" and the buffer length is returned, therefore the caller
1173  * must check for "Unknown" in the buffer to detect a failure.
1174  *
1175  * Returns: size of formatted string.
1176  **/
1177 static ssize_t
1178 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1179 		  char *buf)
1180 {
1181 	struct Scsi_Host  *shost = class_to_shost(dev);
1182 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1183 	struct lpfc_hba   *phba = vport->phba;
1184 	uint32_t cnt;
1185 
1186 	if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1187 		return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1188 	return snprintf(buf, PAGE_SIZE, "Unknown\n");
1189 }
1190 
1191 /**
1192  * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1193  * @dev: class device that is converted into a Scsi_host.
1194  * @attr: device attribute, not used.
1195  * @buf: on return contains the used xri count in decimal or "Unknown".
1196  *
1197  * Description:
1198  * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1199  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1200  * to "Unknown" and the buffer length is returned, therefore the caller
1201  * must check for "Unknown" in the buffer to detect a failure.
1202  *
1203  * Returns: size of formatted string.
1204  **/
1205 static ssize_t
1206 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1207 		   char *buf)
1208 {
1209 	struct Scsi_Host  *shost = class_to_shost(dev);
1210 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1211 	struct lpfc_hba   *phba = vport->phba;
1212 	uint32_t cnt, acnt;
1213 
1214 	if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1215 		return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1216 	return snprintf(buf, PAGE_SIZE, "Unknown\n");
1217 }
1218 
1219 /**
1220  * lpfc_max_vpi_show - Return maximum vpi
1221  * @dev: class device that is converted into a Scsi_host.
1222  * @attr: device attribute, not used.
1223  * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1224  *
1225  * Description:
1226  * Calls lpfc_get_hba_info() asking for just the mvpi count.
1227  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1228  * to "Unknown" and the buffer length is returned, therefore the caller
1229  * must check for "Unknown" in the buffer to detect a failure.
1230  *
1231  * Returns: size of formatted string.
1232  **/
1233 static ssize_t
1234 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1235 		  char *buf)
1236 {
1237 	struct Scsi_Host  *shost = class_to_shost(dev);
1238 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1239 	struct lpfc_hba   *phba = vport->phba;
1240 	uint32_t cnt;
1241 
1242 	if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1243 		return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1244 	return snprintf(buf, PAGE_SIZE, "Unknown\n");
1245 }
1246 
1247 /**
1248  * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1249  * @dev: class device that is converted into a Scsi_host.
1250  * @attr: device attribute, not used.
1251  * @buf: on return contains the used vpi count in decimal or "Unknown".
1252  *
1253  * Description:
1254  * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1255  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1256  * to "Unknown" and the buffer length is returned, therefore the caller
1257  * must check for "Unknown" in the buffer to detect a failure.
1258  *
1259  * Returns: size of formatted string.
1260  **/
1261 static ssize_t
1262 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1263 		   char *buf)
1264 {
1265 	struct Scsi_Host  *shost = class_to_shost(dev);
1266 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1267 	struct lpfc_hba   *phba = vport->phba;
1268 	uint32_t cnt, acnt;
1269 
1270 	if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1271 		return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1272 	return snprintf(buf, PAGE_SIZE, "Unknown\n");
1273 }
1274 
1275 /**
1276  * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1277  * @dev: class device that is converted into a Scsi_host.
1278  * @attr: device attribute, not used.
1279  * @buf: text that must be interpreted to determine if npiv is supported.
1280  *
1281  * Description:
1282  * Buffer will contain text indicating npiv is not suppoerted on the port,
1283  * the port is an NPIV physical port, or it is an npiv virtual port with
1284  * the id of the vport.
1285  *
1286  * Returns: size of formatted string.
1287  **/
1288 static ssize_t
1289 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1290 		    char *buf)
1291 {
1292 	struct Scsi_Host  *shost = class_to_shost(dev);
1293 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1294 	struct lpfc_hba   *phba = vport->phba;
1295 
1296 	if (!(phba->max_vpi))
1297 		return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1298 	if (vport->port_type == LPFC_PHYSICAL_PORT)
1299 		return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1300 	return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1301 }
1302 
1303 /**
1304  * lpfc_poll_show - Return text about poll support for the adapter
1305  * @dev: class device that is converted into a Scsi_host.
1306  * @attr: device attribute, not used.
1307  * @buf: on return contains the cfg_poll in hex.
1308  *
1309  * Notes:
1310  * cfg_poll should be a lpfc_polling_flags type.
1311  *
1312  * Returns: size of formatted string.
1313  **/
1314 static ssize_t
1315 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1316 	       char *buf)
1317 {
1318 	struct Scsi_Host  *shost = class_to_shost(dev);
1319 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1320 	struct lpfc_hba   *phba = vport->phba;
1321 
1322 	return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1323 }
1324 
1325 /**
1326  * lpfc_poll_store - Set the value of cfg_poll for the adapter
1327  * @dev: class device that is converted into a Scsi_host.
1328  * @attr: device attribute, not used.
1329  * @buf: one or more lpfc_polling_flags values.
1330  * @count: not used.
1331  *
1332  * Notes:
1333  * buf contents converted to integer and checked for a valid value.
1334  *
1335  * Returns:
1336  * -EINVAL if the buffer connot be converted or is out of range
1337  * length of the buf on success
1338  **/
1339 static ssize_t
1340 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1341 		const char *buf, size_t count)
1342 {
1343 	struct Scsi_Host  *shost = class_to_shost(dev);
1344 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1345 	struct lpfc_hba   *phba = vport->phba;
1346 	uint32_t creg_val;
1347 	uint32_t old_val;
1348 	int val=0;
1349 
1350 	if (!isdigit(buf[0]))
1351 		return -EINVAL;
1352 
1353 	if (sscanf(buf, "%i", &val) != 1)
1354 		return -EINVAL;
1355 
1356 	if ((val & 0x3) != val)
1357 		return -EINVAL;
1358 
1359 	if (phba->sli_rev == LPFC_SLI_REV4)
1360 		val = 0;
1361 
1362 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1363 		"3051 lpfc_poll changed from %d to %d\n",
1364 		phba->cfg_poll, val);
1365 
1366 	spin_lock_irq(&phba->hbalock);
1367 
1368 	old_val = phba->cfg_poll;
1369 
1370 	if (val & ENABLE_FCP_RING_POLLING) {
1371 		if ((val & DISABLE_FCP_RING_INT) &&
1372 		    !(old_val & DISABLE_FCP_RING_INT)) {
1373 			if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1374 				spin_unlock_irq(&phba->hbalock);
1375 				return -EINVAL;
1376 			}
1377 			creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1378 			writel(creg_val, phba->HCregaddr);
1379 			readl(phba->HCregaddr); /* flush */
1380 
1381 			lpfc_poll_start_timer(phba);
1382 		}
1383 	} else if (val != 0x0) {
1384 		spin_unlock_irq(&phba->hbalock);
1385 		return -EINVAL;
1386 	}
1387 
1388 	if (!(val & DISABLE_FCP_RING_INT) &&
1389 	    (old_val & DISABLE_FCP_RING_INT))
1390 	{
1391 		spin_unlock_irq(&phba->hbalock);
1392 		del_timer(&phba->fcp_poll_timer);
1393 		spin_lock_irq(&phba->hbalock);
1394 		if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1395 			spin_unlock_irq(&phba->hbalock);
1396 			return -EINVAL;
1397 		}
1398 		creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1399 		writel(creg_val, phba->HCregaddr);
1400 		readl(phba->HCregaddr); /* flush */
1401 	}
1402 
1403 	phba->cfg_poll = val;
1404 
1405 	spin_unlock_irq(&phba->hbalock);
1406 
1407 	return strlen(buf);
1408 }
1409 
1410 /**
1411  * lpfc_fips_level_show - Return the current FIPS level for the HBA
1412  * @dev: class unused variable.
1413  * @attr: device attribute, not used.
1414  * @buf: on return contains the module description text.
1415  *
1416  * Returns: size of formatted string.
1417  **/
1418 static ssize_t
1419 lpfc_fips_level_show(struct device *dev,  struct device_attribute *attr,
1420 		     char *buf)
1421 {
1422 	struct Scsi_Host  *shost = class_to_shost(dev);
1423 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1424 	struct lpfc_hba   *phba = vport->phba;
1425 
1426 	return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1427 }
1428 
1429 /**
1430  * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1431  * @dev: class unused variable.
1432  * @attr: device attribute, not used.
1433  * @buf: on return contains the module description text.
1434  *
1435  * Returns: size of formatted string.
1436  **/
1437 static ssize_t
1438 lpfc_fips_rev_show(struct device *dev,  struct device_attribute *attr,
1439 		   char *buf)
1440 {
1441 	struct Scsi_Host  *shost = class_to_shost(dev);
1442 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1443 	struct lpfc_hba   *phba = vport->phba;
1444 
1445 	return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1446 }
1447 
1448 /**
1449  * lpfc_dss_show - Return the current state of dss and the configured state
1450  * @dev: class converted to a Scsi_host structure.
1451  * @attr: device attribute, not used.
1452  * @buf: on return contains the formatted text.
1453  *
1454  * Returns: size of formatted string.
1455  **/
1456 static ssize_t
1457 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1458 	      char *buf)
1459 {
1460 	struct Scsi_Host *shost = class_to_shost(dev);
1461 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1462 	struct lpfc_hba   *phba = vport->phba;
1463 
1464 	return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1465 			(phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1466 			(phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1467 				"" : "Not ");
1468 }
1469 
1470 /**
1471  * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1472  * @dev: class converted to a Scsi_host structure.
1473  * @attr: device attribute, not used.
1474  * @buf: on return contains the formatted support level.
1475  *
1476  * Description:
1477  * Returns the maximum number of virtual functions a physical function can
1478  * support, 0 will be returned if called on virtual function.
1479  *
1480  * Returns: size of formatted string.
1481  **/
1482 static ssize_t
1483 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1484 			      struct device_attribute *attr,
1485 			      char *buf)
1486 {
1487 	struct Scsi_Host *shost = class_to_shost(dev);
1488 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1489 	struct lpfc_hba *phba = vport->phba;
1490 	uint16_t max_nr_virtfn;
1491 
1492 	max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1493 	return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1494 }
1495 
1496 /**
1497  * lpfc_param_show - Return a cfg attribute value in decimal
1498  *
1499  * Description:
1500  * Macro that given an attr e.g. hba_queue_depth expands
1501  * into a function with the name lpfc_hba_queue_depth_show.
1502  *
1503  * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1504  * @dev: class device that is converted into a Scsi_host.
1505  * @attr: device attribute, not used.
1506  * @buf: on return contains the attribute value in decimal.
1507  *
1508  * Returns: size of formatted string.
1509  **/
1510 #define lpfc_param_show(attr)	\
1511 static ssize_t \
1512 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1513 		   char *buf) \
1514 { \
1515 	struct Scsi_Host  *shost = class_to_shost(dev);\
1516 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1517 	struct lpfc_hba   *phba = vport->phba;\
1518 	uint val = 0;\
1519 	val = phba->cfg_##attr;\
1520 	return snprintf(buf, PAGE_SIZE, "%d\n",\
1521 			phba->cfg_##attr);\
1522 }
1523 
1524 /**
1525  * lpfc_param_hex_show - Return a cfg attribute value in hex
1526  *
1527  * Description:
1528  * Macro that given an attr e.g. hba_queue_depth expands
1529  * into a function with the name lpfc_hba_queue_depth_show
1530  *
1531  * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1532  * @dev: class device that is converted into a Scsi_host.
1533  * @attr: device attribute, not used.
1534  * @buf: on return contains the attribute value in hexadecimal.
1535  *
1536  * Returns: size of formatted string.
1537  **/
1538 #define lpfc_param_hex_show(attr)	\
1539 static ssize_t \
1540 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1541 		   char *buf) \
1542 { \
1543 	struct Scsi_Host  *shost = class_to_shost(dev);\
1544 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1545 	struct lpfc_hba   *phba = vport->phba;\
1546 	uint val = 0;\
1547 	val = phba->cfg_##attr;\
1548 	return snprintf(buf, PAGE_SIZE, "%#x\n",\
1549 			phba->cfg_##attr);\
1550 }
1551 
1552 /**
1553  * lpfc_param_init - Initializes a cfg attribute
1554  *
1555  * Description:
1556  * Macro that given an attr e.g. hba_queue_depth expands
1557  * into a function with the name lpfc_hba_queue_depth_init. The macro also
1558  * takes a default argument, a minimum and maximum argument.
1559  *
1560  * lpfc_##attr##_init: Initializes an attribute.
1561  * @phba: pointer the the adapter structure.
1562  * @val: integer attribute value.
1563  *
1564  * Validates the min and max values then sets the adapter config field
1565  * accordingly, or uses the default if out of range and prints an error message.
1566  *
1567  * Returns:
1568  * zero on success
1569  * -EINVAL if default used
1570  **/
1571 #define lpfc_param_init(attr, default, minval, maxval)	\
1572 static int \
1573 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1574 { \
1575 	if (val >= minval && val <= maxval) {\
1576 		phba->cfg_##attr = val;\
1577 		return 0;\
1578 	}\
1579 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1580 			"0449 lpfc_"#attr" attribute cannot be set to %d, "\
1581 			"allowed range is ["#minval", "#maxval"]\n", val); \
1582 	phba->cfg_##attr = default;\
1583 	return -EINVAL;\
1584 }
1585 
1586 /**
1587  * lpfc_param_set - Set a cfg attribute value
1588  *
1589  * Description:
1590  * Macro that given an attr e.g. hba_queue_depth expands
1591  * into a function with the name lpfc_hba_queue_depth_set
1592  *
1593  * lpfc_##attr##_set: Sets an attribute value.
1594  * @phba: pointer the the adapter structure.
1595  * @val: integer attribute value.
1596  *
1597  * Description:
1598  * Validates the min and max values then sets the
1599  * adapter config field if in the valid range. prints error message
1600  * and does not set the parameter if invalid.
1601  *
1602  * Returns:
1603  * zero on success
1604  * -EINVAL if val is invalid
1605  **/
1606 #define lpfc_param_set(attr, default, minval, maxval)	\
1607 static int \
1608 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1609 { \
1610 	if (val >= minval && val <= maxval) {\
1611 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1612 			"3052 lpfc_" #attr " changed from %d to %d\n", \
1613 			phba->cfg_##attr, val); \
1614 		phba->cfg_##attr = val;\
1615 		return 0;\
1616 	}\
1617 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1618 			"0450 lpfc_"#attr" attribute cannot be set to %d, "\
1619 			"allowed range is ["#minval", "#maxval"]\n", val); \
1620 	return -EINVAL;\
1621 }
1622 
1623 /**
1624  * lpfc_param_store - Set a vport attribute value
1625  *
1626  * Description:
1627  * Macro that given an attr e.g. hba_queue_depth expands
1628  * into a function with the name lpfc_hba_queue_depth_store.
1629  *
1630  * lpfc_##attr##_store: Set an sttribute value.
1631  * @dev: class device that is converted into a Scsi_host.
1632  * @attr: device attribute, not used.
1633  * @buf: contains the attribute value in ascii.
1634  * @count: not used.
1635  *
1636  * Description:
1637  * Convert the ascii text number to an integer, then
1638  * use the lpfc_##attr##_set function to set the value.
1639  *
1640  * Returns:
1641  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1642  * length of buffer upon success.
1643  **/
1644 #define lpfc_param_store(attr)	\
1645 static ssize_t \
1646 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1647 		    const char *buf, size_t count) \
1648 { \
1649 	struct Scsi_Host  *shost = class_to_shost(dev);\
1650 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1651 	struct lpfc_hba   *phba = vport->phba;\
1652 	uint val = 0;\
1653 	if (!isdigit(buf[0]))\
1654 		return -EINVAL;\
1655 	if (sscanf(buf, "%i", &val) != 1)\
1656 		return -EINVAL;\
1657 	if (lpfc_##attr##_set(phba, val) == 0) \
1658 		return strlen(buf);\
1659 	else \
1660 		return -EINVAL;\
1661 }
1662 
1663 /**
1664  * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1665  *
1666  * Description:
1667  * Macro that given an attr e.g. hba_queue_depth expands
1668  * into a function with the name lpfc_hba_queue_depth_show
1669  *
1670  * lpfc_##attr##_show: prints the attribute value in decimal.
1671  * @dev: class device that is converted into a Scsi_host.
1672  * @attr: device attribute, not used.
1673  * @buf: on return contains the attribute value in decimal.
1674  *
1675  * Returns: length of formatted string.
1676  **/
1677 #define lpfc_vport_param_show(attr)	\
1678 static ssize_t \
1679 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1680 		   char *buf) \
1681 { \
1682 	struct Scsi_Host  *shost = class_to_shost(dev);\
1683 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1684 	uint val = 0;\
1685 	val = vport->cfg_##attr;\
1686 	return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1687 }
1688 
1689 /**
1690  * lpfc_vport_param_hex_show - Return hex formatted attribute value
1691  *
1692  * Description:
1693  * Macro that given an attr e.g.
1694  * hba_queue_depth expands into a function with the name
1695  * lpfc_hba_queue_depth_show
1696  *
1697  * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1698  * @dev: class device that is converted into a Scsi_host.
1699  * @attr: device attribute, not used.
1700  * @buf: on return contains the attribute value in hexadecimal.
1701  *
1702  * Returns: length of formatted string.
1703  **/
1704 #define lpfc_vport_param_hex_show(attr)	\
1705 static ssize_t \
1706 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1707 		   char *buf) \
1708 { \
1709 	struct Scsi_Host  *shost = class_to_shost(dev);\
1710 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1711 	uint val = 0;\
1712 	val = vport->cfg_##attr;\
1713 	return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1714 }
1715 
1716 /**
1717  * lpfc_vport_param_init - Initialize a vport cfg attribute
1718  *
1719  * Description:
1720  * Macro that given an attr e.g. hba_queue_depth expands
1721  * into a function with the name lpfc_hba_queue_depth_init. The macro also
1722  * takes a default argument, a minimum and maximum argument.
1723  *
1724  * lpfc_##attr##_init: validates the min and max values then sets the
1725  * adapter config field accordingly, or uses the default if out of range
1726  * and prints an error message.
1727  * @phba: pointer the the adapter structure.
1728  * @val: integer attribute value.
1729  *
1730  * Returns:
1731  * zero on success
1732  * -EINVAL if default used
1733  **/
1734 #define lpfc_vport_param_init(attr, default, minval, maxval)	\
1735 static int \
1736 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1737 { \
1738 	if (val >= minval && val <= maxval) {\
1739 		vport->cfg_##attr = val;\
1740 		return 0;\
1741 	}\
1742 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1743 			 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1744 			 "allowed range is ["#minval", "#maxval"]\n", val); \
1745 	vport->cfg_##attr = default;\
1746 	return -EINVAL;\
1747 }
1748 
1749 /**
1750  * lpfc_vport_param_set - Set a vport cfg attribute
1751  *
1752  * Description:
1753  * Macro that given an attr e.g. hba_queue_depth expands
1754  * into a function with the name lpfc_hba_queue_depth_set
1755  *
1756  * lpfc_##attr##_set: validates the min and max values then sets the
1757  * adapter config field if in the valid range. prints error message
1758  * and does not set the parameter if invalid.
1759  * @phba: pointer the the adapter structure.
1760  * @val:	integer attribute value.
1761  *
1762  * Returns:
1763  * zero on success
1764  * -EINVAL if val is invalid
1765  **/
1766 #define lpfc_vport_param_set(attr, default, minval, maxval)	\
1767 static int \
1768 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1769 { \
1770 	if (val >= minval && val <= maxval) {\
1771 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1772 			"3053 lpfc_" #attr " changed from %d to %d\n", \
1773 			vport->cfg_##attr, val); \
1774 		vport->cfg_##attr = val;\
1775 		return 0;\
1776 	}\
1777 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1778 			 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1779 			 "allowed range is ["#minval", "#maxval"]\n", val); \
1780 	return -EINVAL;\
1781 }
1782 
1783 /**
1784  * lpfc_vport_param_store - Set a vport attribute
1785  *
1786  * Description:
1787  * Macro that given an attr e.g. hba_queue_depth
1788  * expands into a function with the name lpfc_hba_queue_depth_store
1789  *
1790  * lpfc_##attr##_store: convert the ascii text number to an integer, then
1791  * use the lpfc_##attr##_set function to set the value.
1792  * @cdev: class device that is converted into a Scsi_host.
1793  * @buf:	contains the attribute value in decimal.
1794  * @count: not used.
1795  *
1796  * Returns:
1797  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1798  * length of buffer upon success.
1799  **/
1800 #define lpfc_vport_param_store(attr)	\
1801 static ssize_t \
1802 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1803 		    const char *buf, size_t count) \
1804 { \
1805 	struct Scsi_Host  *shost = class_to_shost(dev);\
1806 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1807 	uint val = 0;\
1808 	if (!isdigit(buf[0]))\
1809 		return -EINVAL;\
1810 	if (sscanf(buf, "%i", &val) != 1)\
1811 		return -EINVAL;\
1812 	if (lpfc_##attr##_set(vport, val) == 0) \
1813 		return strlen(buf);\
1814 	else \
1815 		return -EINVAL;\
1816 }
1817 
1818 
1819 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1820 static uint lpfc_##name = defval;\
1821 module_param(lpfc_##name, uint, S_IRUGO);\
1822 MODULE_PARM_DESC(lpfc_##name, desc);\
1823 lpfc_param_init(name, defval, minval, maxval)
1824 
1825 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1826 static uint lpfc_##name = defval;\
1827 module_param(lpfc_##name, uint, S_IRUGO);\
1828 MODULE_PARM_DESC(lpfc_##name, desc);\
1829 lpfc_param_show(name)\
1830 lpfc_param_init(name, defval, minval, maxval)\
1831 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1832 
1833 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1834 static uint lpfc_##name = defval;\
1835 module_param(lpfc_##name, uint, S_IRUGO);\
1836 MODULE_PARM_DESC(lpfc_##name, desc);\
1837 lpfc_param_show(name)\
1838 lpfc_param_init(name, defval, minval, maxval)\
1839 lpfc_param_set(name, defval, minval, maxval)\
1840 lpfc_param_store(name)\
1841 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1842 		   lpfc_##name##_show, lpfc_##name##_store)
1843 
1844 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1845 static uint lpfc_##name = defval;\
1846 module_param(lpfc_##name, uint, S_IRUGO);\
1847 MODULE_PARM_DESC(lpfc_##name, desc);\
1848 lpfc_param_hex_show(name)\
1849 lpfc_param_init(name, defval, minval, maxval)\
1850 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1851 
1852 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1853 static uint lpfc_##name = defval;\
1854 module_param(lpfc_##name, uint, S_IRUGO);\
1855 MODULE_PARM_DESC(lpfc_##name, desc);\
1856 lpfc_param_hex_show(name)\
1857 lpfc_param_init(name, defval, minval, maxval)\
1858 lpfc_param_set(name, defval, minval, maxval)\
1859 lpfc_param_store(name)\
1860 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1861 		   lpfc_##name##_show, lpfc_##name##_store)
1862 
1863 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1864 static uint lpfc_##name = defval;\
1865 module_param(lpfc_##name, uint, S_IRUGO);\
1866 MODULE_PARM_DESC(lpfc_##name, desc);\
1867 lpfc_vport_param_init(name, defval, minval, maxval)
1868 
1869 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1870 static uint lpfc_##name = defval;\
1871 module_param(lpfc_##name, uint, S_IRUGO);\
1872 MODULE_PARM_DESC(lpfc_##name, desc);\
1873 lpfc_vport_param_show(name)\
1874 lpfc_vport_param_init(name, defval, minval, maxval)\
1875 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1876 
1877 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1878 static uint lpfc_##name = defval;\
1879 module_param(lpfc_##name, uint, S_IRUGO);\
1880 MODULE_PARM_DESC(lpfc_##name, desc);\
1881 lpfc_vport_param_show(name)\
1882 lpfc_vport_param_init(name, defval, minval, maxval)\
1883 lpfc_vport_param_set(name, defval, minval, maxval)\
1884 lpfc_vport_param_store(name)\
1885 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1886 		   lpfc_##name##_show, lpfc_##name##_store)
1887 
1888 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1889 static uint lpfc_##name = defval;\
1890 module_param(lpfc_##name, uint, S_IRUGO);\
1891 MODULE_PARM_DESC(lpfc_##name, desc);\
1892 lpfc_vport_param_hex_show(name)\
1893 lpfc_vport_param_init(name, defval, minval, maxval)\
1894 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1895 
1896 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1897 static uint lpfc_##name = defval;\
1898 module_param(lpfc_##name, uint, S_IRUGO);\
1899 MODULE_PARM_DESC(lpfc_##name, desc);\
1900 lpfc_vport_param_hex_show(name)\
1901 lpfc_vport_param_init(name, defval, minval, maxval)\
1902 lpfc_vport_param_set(name, defval, minval, maxval)\
1903 lpfc_vport_param_store(name)\
1904 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1905 		   lpfc_##name##_show, lpfc_##name##_store)
1906 
1907 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1908 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1909 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1910 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1911 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1912 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1913 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1914 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1915 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1916 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1917 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1918 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1919 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1920 		lpfc_link_state_store);
1921 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1922 		   lpfc_option_rom_version_show, NULL);
1923 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1924 		   lpfc_num_discovered_ports_show, NULL);
1925 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1926 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1927 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1928 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1929 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1930 		   lpfc_board_mode_show, lpfc_board_mode_store);
1931 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1932 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1933 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1934 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1935 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1936 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1937 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1938 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1939 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1940 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1941 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1942 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
1943 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1944 		   lpfc_sriov_hw_max_virtfn_show, NULL);
1945 
1946 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1947 
1948 /**
1949  * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1950  * @dev: class device that is converted into a Scsi_host.
1951  * @attr: device attribute, not used.
1952  * @buf: containing the string lpfc_soft_wwn_key.
1953  * @count: must be size of lpfc_soft_wwn_key.
1954  *
1955  * Returns:
1956  * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1957  * length of buf indicates success
1958  **/
1959 static ssize_t
1960 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1961 			   const char *buf, size_t count)
1962 {
1963 	struct Scsi_Host  *shost = class_to_shost(dev);
1964 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1965 	struct lpfc_hba   *phba = vport->phba;
1966 	unsigned int cnt = count;
1967 
1968 	/*
1969 	 * We're doing a simple sanity check for soft_wwpn setting.
1970 	 * We require that the user write a specific key to enable
1971 	 * the soft_wwpn attribute to be settable. Once the attribute
1972 	 * is written, the enable key resets. If further updates are
1973 	 * desired, the key must be written again to re-enable the
1974 	 * attribute.
1975 	 *
1976 	 * The "key" is not secret - it is a hardcoded string shown
1977 	 * here. The intent is to protect against the random user or
1978 	 * application that is just writing attributes.
1979 	 */
1980 
1981 	/* count may include a LF at end of string */
1982 	if (buf[cnt-1] == '\n')
1983 		cnt--;
1984 
1985 	if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1986 	    (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1987 		return -EINVAL;
1988 
1989 	phba->soft_wwn_enable = 1;
1990 	return count;
1991 }
1992 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1993 		   lpfc_soft_wwn_enable_store);
1994 
1995 /**
1996  * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1997  * @dev: class device that is converted into a Scsi_host.
1998  * @attr: device attribute, not used.
1999  * @buf: on return contains the wwpn in hexadecimal.
2000  *
2001  * Returns: size of formatted string.
2002  **/
2003 static ssize_t
2004 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2005 		    char *buf)
2006 {
2007 	struct Scsi_Host  *shost = class_to_shost(dev);
2008 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2009 	struct lpfc_hba   *phba = vport->phba;
2010 
2011 	return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2012 			(unsigned long long)phba->cfg_soft_wwpn);
2013 }
2014 
2015 /**
2016  * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2017  * @dev class device that is converted into a Scsi_host.
2018  * @attr: device attribute, not used.
2019  * @buf: contains the wwpn in hexadecimal.
2020  * @count: number of wwpn bytes in buf
2021  *
2022  * Returns:
2023  * -EACCES hba reset not enabled, adapter over temp
2024  * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2025  * -EIO error taking adapter offline or online
2026  * value of count on success
2027  **/
2028 static ssize_t
2029 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2030 		     const char *buf, size_t count)
2031 {
2032 	struct Scsi_Host  *shost = class_to_shost(dev);
2033 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2034 	struct lpfc_hba   *phba = vport->phba;
2035 	struct completion online_compl;
2036 	int stat1=0, stat2=0;
2037 	unsigned int i, j, cnt=count;
2038 	u8 wwpn[8];
2039 	int rc;
2040 
2041 	if (!phba->cfg_enable_hba_reset)
2042 		return -EACCES;
2043 	spin_lock_irq(&phba->hbalock);
2044 	if (phba->over_temp_state == HBA_OVER_TEMP) {
2045 		spin_unlock_irq(&phba->hbalock);
2046 		return -EACCES;
2047 	}
2048 	spin_unlock_irq(&phba->hbalock);
2049 	/* count may include a LF at end of string */
2050 	if (buf[cnt-1] == '\n')
2051 		cnt--;
2052 
2053 	if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2054 	    ((cnt == 17) && (*buf++ != 'x')) ||
2055 	    ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2056 		return -EINVAL;
2057 
2058 	phba->soft_wwn_enable = 0;
2059 
2060 	memset(wwpn, 0, sizeof(wwpn));
2061 
2062 	/* Validate and store the new name */
2063 	for (i=0, j=0; i < 16; i++) {
2064 		int value;
2065 
2066 		value = hex_to_bin(*buf++);
2067 		if (value >= 0)
2068 			j = (j << 4) | value;
2069 		else
2070 			return -EINVAL;
2071 		if (i % 2) {
2072 			wwpn[i/2] = j & 0xff;
2073 			j = 0;
2074 		}
2075 	}
2076 	phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2077 	fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2078 	if (phba->cfg_soft_wwnn)
2079 		fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2080 
2081 	dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2082 		   "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2083 
2084 	stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2085 	if (stat1)
2086 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2087 				"0463 lpfc_soft_wwpn attribute set failed to "
2088 				"reinit adapter - %d\n", stat1);
2089 	init_completion(&online_compl);
2090 	rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2091 				   LPFC_EVT_ONLINE);
2092 	if (rc == 0)
2093 		return -ENOMEM;
2094 
2095 	wait_for_completion(&online_compl);
2096 	if (stat2)
2097 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2098 				"0464 lpfc_soft_wwpn attribute set failed to "
2099 				"reinit adapter - %d\n", stat2);
2100 	return (stat1 || stat2) ? -EIO : count;
2101 }
2102 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2103 		   lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2104 
2105 /**
2106  * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2107  * @dev: class device that is converted into a Scsi_host.
2108  * @attr: device attribute, not used.
2109  * @buf: on return contains the wwnn in hexadecimal.
2110  *
2111  * Returns: size of formatted string.
2112  **/
2113 static ssize_t
2114 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2115 		    char *buf)
2116 {
2117 	struct Scsi_Host *shost = class_to_shost(dev);
2118 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2119 	return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2120 			(unsigned long long)phba->cfg_soft_wwnn);
2121 }
2122 
2123 /**
2124  * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2125  * @cdev: class device that is converted into a Scsi_host.
2126  * @buf: contains the ww node name in hexadecimal.
2127  * @count: number of wwnn bytes in buf.
2128  *
2129  * Returns:
2130  * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2131  * value of count on success
2132  **/
2133 static ssize_t
2134 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2135 		     const char *buf, size_t count)
2136 {
2137 	struct Scsi_Host *shost = class_to_shost(dev);
2138 	struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2139 	unsigned int i, j, cnt=count;
2140 	u8 wwnn[8];
2141 
2142 	/* count may include a LF at end of string */
2143 	if (buf[cnt-1] == '\n')
2144 		cnt--;
2145 
2146 	if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2147 	    ((cnt == 17) && (*buf++ != 'x')) ||
2148 	    ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2149 		return -EINVAL;
2150 
2151 	/*
2152 	 * Allow wwnn to be set many times, as long as the enable is set.
2153 	 * However, once the wwpn is set, everything locks.
2154 	 */
2155 
2156 	memset(wwnn, 0, sizeof(wwnn));
2157 
2158 	/* Validate and store the new name */
2159 	for (i=0, j=0; i < 16; i++) {
2160 		int value;
2161 
2162 		value = hex_to_bin(*buf++);
2163 		if (value >= 0)
2164 			j = (j << 4) | value;
2165 		else
2166 			return -EINVAL;
2167 		if (i % 2) {
2168 			wwnn[i/2] = j & 0xff;
2169 			j = 0;
2170 		}
2171 	}
2172 	phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2173 
2174 	dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2175 		   "lpfc%d: soft_wwnn set. Value will take effect upon "
2176 		   "setting of the soft_wwpn\n", phba->brd_no);
2177 
2178 	return count;
2179 }
2180 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2181 		   lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2182 
2183 
2184 static int lpfc_poll = 0;
2185 module_param(lpfc_poll, int, S_IRUGO);
2186 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2187 		 " 0 - none,"
2188 		 " 1 - poll with interrupts enabled"
2189 		 " 3 - poll and disable FCP ring interrupts");
2190 
2191 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2192 		   lpfc_poll_show, lpfc_poll_store);
2193 
2194 int  lpfc_sli_mode = 0;
2195 module_param(lpfc_sli_mode, int, S_IRUGO);
2196 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2197 		 " 0 - auto (SLI-3 if supported),"
2198 		 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2199 		 " 3 - select SLI-3");
2200 
2201 int lpfc_enable_npiv = 1;
2202 module_param(lpfc_enable_npiv, int, S_IRUGO);
2203 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2204 lpfc_param_show(enable_npiv);
2205 lpfc_param_init(enable_npiv, 1, 0, 1);
2206 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2207 
2208 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2209 	"FCF Fast failover=1 Priority failover=2");
2210 
2211 int lpfc_enable_rrq;
2212 module_param(lpfc_enable_rrq, int, S_IRUGO);
2213 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2214 lpfc_param_show(enable_rrq);
2215 lpfc_param_init(enable_rrq, 0, 0, 1);
2216 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2217 
2218 /*
2219 # lpfc_suppress_link_up:  Bring link up at initialization
2220 #            0x0  = bring link up (issue MBX_INIT_LINK)
2221 #            0x1  = do NOT bring link up at initialization(MBX_INIT_LINK)
2222 #            0x2  = never bring up link
2223 # Default value is 0.
2224 */
2225 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2226 		LPFC_DELAY_INIT_LINK_INDEFINITELY,
2227 		"Suppress Link Up at initialization");
2228 /*
2229 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2230 #       1 - (1024)
2231 #       2 - (2048)
2232 #       3 - (3072)
2233 #       4 - (4096)
2234 #       5 - (5120)
2235 */
2236 static ssize_t
2237 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2238 {
2239 	struct Scsi_Host  *shost = class_to_shost(dev);
2240 	struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2241 
2242 	return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2243 }
2244 
2245 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2246 			 lpfc_iocb_hw_show, NULL);
2247 static ssize_t
2248 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2249 {
2250 	struct Scsi_Host  *shost = class_to_shost(dev);
2251 	struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2252 
2253 	return snprintf(buf, PAGE_SIZE, "%d\n",
2254 		phba->sli.ring[LPFC_ELS_RING].txq_max);
2255 }
2256 
2257 static DEVICE_ATTR(txq_hw, S_IRUGO,
2258 			 lpfc_txq_hw_show, NULL);
2259 static ssize_t
2260 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2261  char *buf)
2262 {
2263 	struct Scsi_Host  *shost = class_to_shost(dev);
2264 	struct lpfc_hba   *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2265 
2266 	return snprintf(buf, PAGE_SIZE, "%d\n",
2267 		phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2268 }
2269 
2270 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2271 			 lpfc_txcmplq_hw_show, NULL);
2272 
2273 int lpfc_iocb_cnt = 2;
2274 module_param(lpfc_iocb_cnt, int, S_IRUGO);
2275 MODULE_PARM_DESC(lpfc_iocb_cnt,
2276 	"Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2277 lpfc_param_show(iocb_cnt);
2278 lpfc_param_init(iocb_cnt, 2, 1, 5);
2279 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2280 			 lpfc_iocb_cnt_show, NULL);
2281 
2282 /*
2283 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2284 # until the timer expires. Value range is [0,255]. Default value is 30.
2285 */
2286 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2287 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2288 module_param(lpfc_nodev_tmo, int, 0);
2289 MODULE_PARM_DESC(lpfc_nodev_tmo,
2290 		 "Seconds driver will hold I/O waiting "
2291 		 "for a device to come back");
2292 
2293 /**
2294  * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2295  * @dev: class converted to a Scsi_host structure.
2296  * @attr: device attribute, not used.
2297  * @buf: on return contains the dev loss timeout in decimal.
2298  *
2299  * Returns: size of formatted string.
2300  **/
2301 static ssize_t
2302 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2303 		    char *buf)
2304 {
2305 	struct Scsi_Host  *shost = class_to_shost(dev);
2306 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2307 
2308 	return snprintf(buf, PAGE_SIZE, "%d\n",	vport->cfg_devloss_tmo);
2309 }
2310 
2311 /**
2312  * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2313  * @vport: lpfc vport structure pointer.
2314  * @val: contains the nodev timeout value.
2315  *
2316  * Description:
2317  * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2318  * a kernel error message is printed and zero is returned.
2319  * Else if val is in range then nodev tmo and devloss tmo are set to val.
2320  * Otherwise nodev tmo is set to the default value.
2321  *
2322  * Returns:
2323  * zero if already set or if val is in range
2324  * -EINVAL val out of range
2325  **/
2326 static int
2327 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2328 {
2329 	if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2330 		vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2331 		if (val != LPFC_DEF_DEVLOSS_TMO)
2332 			lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2333 					 "0407 Ignoring nodev_tmo module "
2334 					 "parameter because devloss_tmo is "
2335 					 "set.\n");
2336 		return 0;
2337 	}
2338 
2339 	if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2340 		vport->cfg_nodev_tmo = val;
2341 		vport->cfg_devloss_tmo = val;
2342 		return 0;
2343 	}
2344 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2345 			 "0400 lpfc_nodev_tmo attribute cannot be set to"
2346 			 " %d, allowed range is [%d, %d]\n",
2347 			 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2348 	vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2349 	return -EINVAL;
2350 }
2351 
2352 /**
2353  * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2354  * @vport: lpfc vport structure pointer.
2355  *
2356  * Description:
2357  * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2358  **/
2359 static void
2360 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2361 {
2362 	struct Scsi_Host  *shost;
2363 	struct lpfc_nodelist  *ndlp;
2364 
2365 	shost = lpfc_shost_from_vport(vport);
2366 	spin_lock_irq(shost->host_lock);
2367 	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2368 		if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2369 			ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2370 	spin_unlock_irq(shost->host_lock);
2371 }
2372 
2373 /**
2374  * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2375  * @vport: lpfc vport structure pointer.
2376  * @val: contains the tmo value.
2377  *
2378  * Description:
2379  * If the devloss tmo is already set or the vport dev loss tmo has changed
2380  * then a kernel error message is printed and zero is returned.
2381  * Else if val is in range then nodev tmo and devloss tmo are set to val.
2382  * Otherwise nodev tmo is set to the default value.
2383  *
2384  * Returns:
2385  * zero if already set or if val is in range
2386  * -EINVAL val out of range
2387  **/
2388 static int
2389 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2390 {
2391 	if (vport->dev_loss_tmo_changed ||
2392 	    (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2393 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2394 				 "0401 Ignoring change to nodev_tmo "
2395 				 "because devloss_tmo is set.\n");
2396 		return 0;
2397 	}
2398 	if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2399 		vport->cfg_nodev_tmo = val;
2400 		vport->cfg_devloss_tmo = val;
2401 		/*
2402 		 * For compat: set the fc_host dev loss so new rports
2403 		 * will get the value.
2404 		 */
2405 		fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2406 		lpfc_update_rport_devloss_tmo(vport);
2407 		return 0;
2408 	}
2409 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2410 			 "0403 lpfc_nodev_tmo attribute cannot be set to"
2411 			 "%d, allowed range is [%d, %d]\n",
2412 			 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2413 	return -EINVAL;
2414 }
2415 
2416 lpfc_vport_param_store(nodev_tmo)
2417 
2418 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2419 		   lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2420 
2421 /*
2422 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2423 # disappear until the timer expires. Value range is [0,255]. Default
2424 # value is 30.
2425 */
2426 module_param(lpfc_devloss_tmo, int, S_IRUGO);
2427 MODULE_PARM_DESC(lpfc_devloss_tmo,
2428 		 "Seconds driver will hold I/O waiting "
2429 		 "for a device to come back");
2430 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2431 		      LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2432 lpfc_vport_param_show(devloss_tmo)
2433 
2434 /**
2435  * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2436  * @vport: lpfc vport structure pointer.
2437  * @val: contains the tmo value.
2438  *
2439  * Description:
2440  * If val is in a valid range then set the vport nodev tmo,
2441  * devloss tmo, also set the vport dev loss tmo changed flag.
2442  * Else a kernel error message is printed.
2443  *
2444  * Returns:
2445  * zero if val is in range
2446  * -EINVAL val out of range
2447  **/
2448 static int
2449 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2450 {
2451 	if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2452 		vport->cfg_nodev_tmo = val;
2453 		vport->cfg_devloss_tmo = val;
2454 		vport->dev_loss_tmo_changed = 1;
2455 		fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2456 		lpfc_update_rport_devloss_tmo(vport);
2457 		return 0;
2458 	}
2459 
2460 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2461 			 "0404 lpfc_devloss_tmo attribute cannot be set to"
2462 			 " %d, allowed range is [%d, %d]\n",
2463 			 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2464 	return -EINVAL;
2465 }
2466 
2467 lpfc_vport_param_store(devloss_tmo)
2468 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2469 		   lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2470 
2471 /*
2472 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2473 # deluged with LOTS of information.
2474 # You can set a bit mask to record specific types of verbose messages:
2475 # See lpfc_logmsh.h for definitions.
2476 */
2477 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2478 		       "Verbose logging bit-mask");
2479 
2480 /*
2481 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2482 # objects that have been registered with the nameserver after login.
2483 */
2484 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2485 		  "Deregister nameserver objects before LOGO");
2486 
2487 /*
2488 # lun_queue_depth:  This parameter is used to limit the number of outstanding
2489 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2490 */
2491 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2492 		  "Max number of FCP commands we can queue to a specific LUN");
2493 
2494 /*
2495 # tgt_queue_depth:  This parameter is used to limit the number of outstanding
2496 # commands per target port. Value range is [10,65535]. Default value is 65535.
2497 */
2498 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2499 	"Max number of FCP commands we can queue to a specific target port");
2500 
2501 /*
2502 # hba_queue_depth:  This parameter is used to limit the number of outstanding
2503 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2504 # value is greater than the maximum number of exchanges supported by the HBA,
2505 # then maximum number of exchanges supported by the HBA is used to determine
2506 # the hba_queue_depth.
2507 */
2508 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2509 	    "Max number of FCP commands we can queue to a lpfc HBA");
2510 
2511 /*
2512 # peer_port_login:  This parameter allows/prevents logins
2513 # between peer ports hosted on the same physical port.
2514 # When this parameter is set 0 peer ports of same physical port
2515 # are not allowed to login to each other.
2516 # When this parameter is set 1 peer ports of same physical port
2517 # are allowed to login to each other.
2518 # Default value of this parameter is 0.
2519 */
2520 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2521 		  "Allow peer ports on the same physical port to login to each "
2522 		  "other.");
2523 
2524 /*
2525 # restrict_login:  This parameter allows/prevents logins
2526 # between Virtual Ports and remote initiators.
2527 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2528 # other initiators and will attempt to PLOGI all remote ports.
2529 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2530 # remote ports and will not attempt to PLOGI to other initiators.
2531 # This parameter does not restrict to the physical port.
2532 # This parameter does not restrict logins to Fabric resident remote ports.
2533 # Default value of this parameter is 1.
2534 */
2535 static int lpfc_restrict_login = 1;
2536 module_param(lpfc_restrict_login, int, S_IRUGO);
2537 MODULE_PARM_DESC(lpfc_restrict_login,
2538 		 "Restrict virtual ports login to remote initiators.");
2539 lpfc_vport_param_show(restrict_login);
2540 
2541 /**
2542  * lpfc_restrict_login_init - Set the vport restrict login flag
2543  * @vport: lpfc vport structure pointer.
2544  * @val: contains the restrict login value.
2545  *
2546  * Description:
2547  * If val is not in a valid range then log a kernel error message and set
2548  * the vport restrict login to one.
2549  * If the port type is physical clear the restrict login flag and return.
2550  * Else set the restrict login flag to val.
2551  *
2552  * Returns:
2553  * zero if val is in range
2554  * -EINVAL val out of range
2555  **/
2556 static int
2557 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2558 {
2559 	if (val < 0 || val > 1) {
2560 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2561 				 "0422 lpfc_restrict_login attribute cannot "
2562 				 "be set to %d, allowed range is [0, 1]\n",
2563 				 val);
2564 		vport->cfg_restrict_login = 1;
2565 		return -EINVAL;
2566 	}
2567 	if (vport->port_type == LPFC_PHYSICAL_PORT) {
2568 		vport->cfg_restrict_login = 0;
2569 		return 0;
2570 	}
2571 	vport->cfg_restrict_login = val;
2572 	return 0;
2573 }
2574 
2575 /**
2576  * lpfc_restrict_login_set - Set the vport restrict login flag
2577  * @vport: lpfc vport structure pointer.
2578  * @val: contains the restrict login value.
2579  *
2580  * Description:
2581  * If val is not in a valid range then log a kernel error message and set
2582  * the vport restrict login to one.
2583  * If the port type is physical and the val is not zero log a kernel
2584  * error message, clear the restrict login flag and return zero.
2585  * Else set the restrict login flag to val.
2586  *
2587  * Returns:
2588  * zero if val is in range
2589  * -EINVAL val out of range
2590  **/
2591 static int
2592 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2593 {
2594 	if (val < 0 || val > 1) {
2595 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2596 				 "0425 lpfc_restrict_login attribute cannot "
2597 				 "be set to %d, allowed range is [0, 1]\n",
2598 				 val);
2599 		vport->cfg_restrict_login = 1;
2600 		return -EINVAL;
2601 	}
2602 	if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2603 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2604 				 "0468 lpfc_restrict_login must be 0 for "
2605 				 "Physical ports.\n");
2606 		vport->cfg_restrict_login = 0;
2607 		return 0;
2608 	}
2609 	vport->cfg_restrict_login = val;
2610 	return 0;
2611 }
2612 lpfc_vport_param_store(restrict_login);
2613 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2614 		   lpfc_restrict_login_show, lpfc_restrict_login_store);
2615 
2616 /*
2617 # Some disk devices have a "select ID" or "select Target" capability.
2618 # From a protocol standpoint "select ID" usually means select the
2619 # Fibre channel "ALPA".  In the FC-AL Profile there is an "informative
2620 # annex" which contains a table that maps a "select ID" (a number
2621 # between 0 and 7F) to an ALPA.  By default, for compatibility with
2622 # older drivers, the lpfc driver scans this table from low ALPA to high
2623 # ALPA.
2624 #
2625 # Turning on the scan-down variable (on  = 1, off = 0) will
2626 # cause the lpfc driver to use an inverted table, effectively
2627 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2628 #
2629 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2630 # and will not work across a fabric. Also this parameter will take
2631 # effect only in the case when ALPA map is not available.)
2632 */
2633 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2634 		  "Start scanning for devices from highest ALPA to lowest");
2635 
2636 /*
2637 # lpfc_topology:  link topology for init link
2638 #            0x0  = attempt loop mode then point-to-point
2639 #            0x01 = internal loopback mode
2640 #            0x02 = attempt point-to-point mode only
2641 #            0x04 = attempt loop mode only
2642 #            0x06 = attempt point-to-point mode then loop
2643 # Set point-to-point mode if you want to run as an N_Port.
2644 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2645 # Default value is 0.
2646 */
2647 
2648 /**
2649  * lpfc_topology_set - Set the adapters topology field
2650  * @phba: lpfc_hba pointer.
2651  * @val: topology value.
2652  *
2653  * Description:
2654  * If val is in a valid range then set the adapter's topology field and
2655  * issue a lip; if the lip fails reset the topology to the old value.
2656  *
2657  * If the value is not in range log a kernel error message and return an error.
2658  *
2659  * Returns:
2660  * zero if val is in range and lip okay
2661  * non-zero return value from lpfc_issue_lip()
2662  * -EINVAL val out of range
2663  **/
2664 static ssize_t
2665 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2666 			const char *buf, size_t count)
2667 {
2668 	struct Scsi_Host  *shost = class_to_shost(dev);
2669 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2670 	struct lpfc_hba   *phba = vport->phba;
2671 	int val = 0;
2672 	int nolip = 0;
2673 	const char *val_buf = buf;
2674 	int err;
2675 	uint32_t prev_val;
2676 
2677 	if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2678 		nolip = 1;
2679 		val_buf = &buf[strlen("nolip ")];
2680 	}
2681 
2682 	if (!isdigit(val_buf[0]))
2683 		return -EINVAL;
2684 	if (sscanf(val_buf, "%i", &val) != 1)
2685 		return -EINVAL;
2686 
2687 	if (val >= 0 && val <= 6) {
2688 		prev_val = phba->cfg_topology;
2689 		phba->cfg_topology = val;
2690 		if (nolip)
2691 			return strlen(buf);
2692 
2693 		lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2694 			"3054 lpfc_topology changed from %d to %d\n",
2695 			prev_val, val);
2696 		err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2697 		if (err) {
2698 			phba->cfg_topology = prev_val;
2699 			return -EINVAL;
2700 		} else
2701 			return strlen(buf);
2702 	}
2703 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2704 		"%d:0467 lpfc_topology attribute cannot be set to %d, "
2705 		"allowed range is [0, 6]\n",
2706 		phba->brd_no, val);
2707 	return -EINVAL;
2708 }
2709 static int lpfc_topology = 0;
2710 module_param(lpfc_topology, int, S_IRUGO);
2711 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2712 lpfc_param_show(topology)
2713 lpfc_param_init(topology, 0, 0, 6)
2714 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2715 		lpfc_topology_show, lpfc_topology_store);
2716 
2717 /**
2718  * lpfc_static_vport_show: Read callback function for
2719  *   lpfc_static_vport sysfs file.
2720  * @dev: Pointer to class device object.
2721  * @attr: device attribute structure.
2722  * @buf: Data buffer.
2723  *
2724  * This function is the read call back function for
2725  * lpfc_static_vport sysfs file. The lpfc_static_vport
2726  * sysfs file report the mageability of the vport.
2727  **/
2728 static ssize_t
2729 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2730 			 char *buf)
2731 {
2732 	struct Scsi_Host  *shost = class_to_shost(dev);
2733 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2734 	if (vport->vport_flag & STATIC_VPORT)
2735 		sprintf(buf, "1\n");
2736 	else
2737 		sprintf(buf, "0\n");
2738 
2739 	return strlen(buf);
2740 }
2741 
2742 /*
2743  * Sysfs attribute to control the statistical data collection.
2744  */
2745 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2746 		   lpfc_static_vport_show, NULL);
2747 
2748 /**
2749  * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2750  * @dev: Pointer to class device.
2751  * @buf: Data buffer.
2752  * @count: Size of the data buffer.
2753  *
2754  * This function get called when an user write to the lpfc_stat_data_ctrl
2755  * sysfs file. This function parse the command written to the sysfs file
2756  * and take appropriate action. These commands are used for controlling
2757  * driver statistical data collection.
2758  * Following are the command this function handles.
2759  *
2760  *    setbucket <bucket_type> <base> <step>
2761  *			       = Set the latency buckets.
2762  *    destroybucket            = destroy all the buckets.
2763  *    start                    = start data collection
2764  *    stop                     = stop data collection
2765  *    reset                    = reset the collected data
2766  **/
2767 static ssize_t
2768 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2769 			  const char *buf, size_t count)
2770 {
2771 	struct Scsi_Host  *shost = class_to_shost(dev);
2772 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2773 	struct lpfc_hba   *phba = vport->phba;
2774 #define LPFC_MAX_DATA_CTRL_LEN 1024
2775 	static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2776 	unsigned long i;
2777 	char *str_ptr, *token;
2778 	struct lpfc_vport **vports;
2779 	struct Scsi_Host *v_shost;
2780 	char *bucket_type_str, *base_str, *step_str;
2781 	unsigned long base, step, bucket_type;
2782 
2783 	if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2784 		if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2785 			return -EINVAL;
2786 
2787 		strcpy(bucket_data, buf);
2788 		str_ptr = &bucket_data[0];
2789 		/* Ignore this token - this is command token */
2790 		token = strsep(&str_ptr, "\t ");
2791 		if (!token)
2792 			return -EINVAL;
2793 
2794 		bucket_type_str = strsep(&str_ptr, "\t ");
2795 		if (!bucket_type_str)
2796 			return -EINVAL;
2797 
2798 		if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2799 			bucket_type = LPFC_LINEAR_BUCKET;
2800 		else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2801 			bucket_type = LPFC_POWER2_BUCKET;
2802 		else
2803 			return -EINVAL;
2804 
2805 		base_str = strsep(&str_ptr, "\t ");
2806 		if (!base_str)
2807 			return -EINVAL;
2808 		base = simple_strtoul(base_str, NULL, 0);
2809 
2810 		step_str = strsep(&str_ptr, "\t ");
2811 		if (!step_str)
2812 			return -EINVAL;
2813 		step = simple_strtoul(step_str, NULL, 0);
2814 		if (!step)
2815 			return -EINVAL;
2816 
2817 		/* Block the data collection for every vport */
2818 		vports = lpfc_create_vport_work_array(phba);
2819 		if (vports == NULL)
2820 			return -ENOMEM;
2821 
2822 		for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2823 			v_shost = lpfc_shost_from_vport(vports[i]);
2824 			spin_lock_irq(v_shost->host_lock);
2825 			/* Block and reset data collection */
2826 			vports[i]->stat_data_blocked = 1;
2827 			if (vports[i]->stat_data_enabled)
2828 				lpfc_vport_reset_stat_data(vports[i]);
2829 			spin_unlock_irq(v_shost->host_lock);
2830 		}
2831 
2832 		/* Set the bucket attributes */
2833 		phba->bucket_type = bucket_type;
2834 		phba->bucket_base = base;
2835 		phba->bucket_step = step;
2836 
2837 		for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2838 			v_shost = lpfc_shost_from_vport(vports[i]);
2839 
2840 			/* Unblock data collection */
2841 			spin_lock_irq(v_shost->host_lock);
2842 			vports[i]->stat_data_blocked = 0;
2843 			spin_unlock_irq(v_shost->host_lock);
2844 		}
2845 		lpfc_destroy_vport_work_array(phba, vports);
2846 		return strlen(buf);
2847 	}
2848 
2849 	if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2850 		vports = lpfc_create_vport_work_array(phba);
2851 		if (vports == NULL)
2852 			return -ENOMEM;
2853 
2854 		for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2855 			v_shost = lpfc_shost_from_vport(vports[i]);
2856 			spin_lock_irq(shost->host_lock);
2857 			vports[i]->stat_data_blocked = 1;
2858 			lpfc_free_bucket(vport);
2859 			vport->stat_data_enabled = 0;
2860 			vports[i]->stat_data_blocked = 0;
2861 			spin_unlock_irq(shost->host_lock);
2862 		}
2863 		lpfc_destroy_vport_work_array(phba, vports);
2864 		phba->bucket_type = LPFC_NO_BUCKET;
2865 		phba->bucket_base = 0;
2866 		phba->bucket_step = 0;
2867 		return strlen(buf);
2868 	}
2869 
2870 	if (!strncmp(buf, "start", strlen("start"))) {
2871 		/* If no buckets configured return error */
2872 		if (phba->bucket_type == LPFC_NO_BUCKET)
2873 			return -EINVAL;
2874 		spin_lock_irq(shost->host_lock);
2875 		if (vport->stat_data_enabled) {
2876 			spin_unlock_irq(shost->host_lock);
2877 			return strlen(buf);
2878 		}
2879 		lpfc_alloc_bucket(vport);
2880 		vport->stat_data_enabled = 1;
2881 		spin_unlock_irq(shost->host_lock);
2882 		return strlen(buf);
2883 	}
2884 
2885 	if (!strncmp(buf, "stop", strlen("stop"))) {
2886 		spin_lock_irq(shost->host_lock);
2887 		if (vport->stat_data_enabled == 0) {
2888 			spin_unlock_irq(shost->host_lock);
2889 			return strlen(buf);
2890 		}
2891 		lpfc_free_bucket(vport);
2892 		vport->stat_data_enabled = 0;
2893 		spin_unlock_irq(shost->host_lock);
2894 		return strlen(buf);
2895 	}
2896 
2897 	if (!strncmp(buf, "reset", strlen("reset"))) {
2898 		if ((phba->bucket_type == LPFC_NO_BUCKET)
2899 			|| !vport->stat_data_enabled)
2900 			return strlen(buf);
2901 		spin_lock_irq(shost->host_lock);
2902 		vport->stat_data_blocked = 1;
2903 		lpfc_vport_reset_stat_data(vport);
2904 		vport->stat_data_blocked = 0;
2905 		spin_unlock_irq(shost->host_lock);
2906 		return strlen(buf);
2907 	}
2908 	return -EINVAL;
2909 }
2910 
2911 
2912 /**
2913  * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2914  * @dev: Pointer to class device object.
2915  * @buf: Data buffer.
2916  *
2917  * This function is the read call back function for
2918  * lpfc_stat_data_ctrl sysfs file. This function report the
2919  * current statistical data collection state.
2920  **/
2921 static ssize_t
2922 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2923 			 char *buf)
2924 {
2925 	struct Scsi_Host  *shost = class_to_shost(dev);
2926 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2927 	struct lpfc_hba   *phba = vport->phba;
2928 	int index = 0;
2929 	int i;
2930 	char *bucket_type;
2931 	unsigned long bucket_value;
2932 
2933 	switch (phba->bucket_type) {
2934 	case LPFC_LINEAR_BUCKET:
2935 		bucket_type = "linear";
2936 		break;
2937 	case LPFC_POWER2_BUCKET:
2938 		bucket_type = "power2";
2939 		break;
2940 	default:
2941 		bucket_type = "No Bucket";
2942 		break;
2943 	}
2944 
2945 	sprintf(&buf[index], "Statistical Data enabled :%d, "
2946 		"blocked :%d, Bucket type :%s, Bucket base :%d,"
2947 		" Bucket step :%d\nLatency Ranges :",
2948 		vport->stat_data_enabled, vport->stat_data_blocked,
2949 		bucket_type, phba->bucket_base, phba->bucket_step);
2950 	index = strlen(buf);
2951 	if (phba->bucket_type != LPFC_NO_BUCKET) {
2952 		for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2953 			if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2954 				bucket_value = phba->bucket_base +
2955 					phba->bucket_step * i;
2956 			else
2957 				bucket_value = phba->bucket_base +
2958 				(1 << i) * phba->bucket_step;
2959 
2960 			if (index + 10 > PAGE_SIZE)
2961 				break;
2962 			sprintf(&buf[index], "%08ld ", bucket_value);
2963 			index = strlen(buf);
2964 		}
2965 	}
2966 	sprintf(&buf[index], "\n");
2967 	return strlen(buf);
2968 }
2969 
2970 /*
2971  * Sysfs attribute to control the statistical data collection.
2972  */
2973 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2974 		   lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2975 
2976 /*
2977  * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2978  */
2979 
2980 /*
2981  * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2982  * for each target.
2983  */
2984 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2985 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2986 	STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2987 
2988 
2989 /**
2990  * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2991  * @filp: sysfs file
2992  * @kobj: Pointer to the kernel object
2993  * @bin_attr: Attribute object
2994  * @buff: Buffer pointer
2995  * @off: File offset
2996  * @count: Buffer size
2997  *
2998  * This function is the read call back function for lpfc_drvr_stat_data
2999  * sysfs file. This function export the statistical data to user
3000  * applications.
3001  **/
3002 static ssize_t
3003 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3004 		struct bin_attribute *bin_attr,
3005 		char *buf, loff_t off, size_t count)
3006 {
3007 	struct device *dev = container_of(kobj, struct device,
3008 		kobj);
3009 	struct Scsi_Host  *shost = class_to_shost(dev);
3010 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3011 	struct lpfc_hba   *phba = vport->phba;
3012 	int i = 0, index = 0;
3013 	unsigned long nport_index;
3014 	struct lpfc_nodelist *ndlp = NULL;
3015 	nport_index = (unsigned long)off /
3016 		MAX_STAT_DATA_SIZE_PER_TARGET;
3017 
3018 	if (!vport->stat_data_enabled || vport->stat_data_blocked
3019 		|| (phba->bucket_type == LPFC_NO_BUCKET))
3020 		return 0;
3021 
3022 	spin_lock_irq(shost->host_lock);
3023 	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3024 		if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3025 			continue;
3026 
3027 		if (nport_index > 0) {
3028 			nport_index--;
3029 			continue;
3030 		}
3031 
3032 		if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3033 			> count)
3034 			break;
3035 
3036 		if (!ndlp->lat_data)
3037 			continue;
3038 
3039 		/* Print the WWN */
3040 		sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3041 			ndlp->nlp_portname.u.wwn[0],
3042 			ndlp->nlp_portname.u.wwn[1],
3043 			ndlp->nlp_portname.u.wwn[2],
3044 			ndlp->nlp_portname.u.wwn[3],
3045 			ndlp->nlp_portname.u.wwn[4],
3046 			ndlp->nlp_portname.u.wwn[5],
3047 			ndlp->nlp_portname.u.wwn[6],
3048 			ndlp->nlp_portname.u.wwn[7]);
3049 
3050 		index = strlen(buf);
3051 
3052 		for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3053 			sprintf(&buf[index], "%010u,",
3054 				ndlp->lat_data[i].cmd_count);
3055 			index = strlen(buf);
3056 		}
3057 		sprintf(&buf[index], "\n");
3058 		index = strlen(buf);
3059 	}
3060 	spin_unlock_irq(shost->host_lock);
3061 	return index;
3062 }
3063 
3064 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3065 	.attr = {
3066 		.name = "lpfc_drvr_stat_data",
3067 		.mode = S_IRUSR,
3068 	},
3069 	.size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3070 	.read = sysfs_drvr_stat_data_read,
3071 	.write = NULL,
3072 };
3073 
3074 /*
3075 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3076 # connection.
3077 # Value range is [0,16]. Default value is 0.
3078 */
3079 /**
3080  * lpfc_link_speed_set - Set the adapters link speed
3081  * @phba: lpfc_hba pointer.
3082  * @val: link speed value.
3083  *
3084  * Description:
3085  * If val is in a valid range then set the adapter's link speed field and
3086  * issue a lip; if the lip fails reset the link speed to the old value.
3087  *
3088  * Notes:
3089  * If the value is not in range log a kernel error message and return an error.
3090  *
3091  * Returns:
3092  * zero if val is in range and lip okay.
3093  * non-zero return value from lpfc_issue_lip()
3094  * -EINVAL val out of range
3095  **/
3096 static ssize_t
3097 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3098 		const char *buf, size_t count)
3099 {
3100 	struct Scsi_Host  *shost = class_to_shost(dev);
3101 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3102 	struct lpfc_hba   *phba = vport->phba;
3103 	int val = LPFC_USER_LINK_SPEED_AUTO;
3104 	int nolip = 0;
3105 	const char *val_buf = buf;
3106 	int err;
3107 	uint32_t prev_val;
3108 
3109 	if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3110 		nolip = 1;
3111 		val_buf = &buf[strlen("nolip ")];
3112 	}
3113 
3114 	if (!isdigit(val_buf[0]))
3115 		return -EINVAL;
3116 	if (sscanf(val_buf, "%i", &val) != 1)
3117 		return -EINVAL;
3118 
3119 	lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3120 		"3055 lpfc_link_speed changed from %d to %d %s\n",
3121 		phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3122 
3123 	if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3124 	    ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3125 	    ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3126 	    ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3127 	    ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3128 	    ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3129 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3130 				"2879 lpfc_link_speed attribute cannot be set "
3131 				"to %d. Speed is not supported by this port.\n",
3132 				val);
3133 		return -EINVAL;
3134 	}
3135 	if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3136 	    (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3137 		prev_val = phba->cfg_link_speed;
3138 		phba->cfg_link_speed = val;
3139 		if (nolip)
3140 			return strlen(buf);
3141 
3142 		err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3143 		if (err) {
3144 			phba->cfg_link_speed = prev_val;
3145 			return -EINVAL;
3146 		} else
3147 			return strlen(buf);
3148 	}
3149 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3150 		"0469 lpfc_link_speed attribute cannot be set to %d, "
3151 		"allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
3152 	return -EINVAL;
3153 }
3154 
3155 static int lpfc_link_speed = 0;
3156 module_param(lpfc_link_speed, int, S_IRUGO);
3157 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3158 lpfc_param_show(link_speed)
3159 
3160 /**
3161  * lpfc_link_speed_init - Set the adapters link speed
3162  * @phba: lpfc_hba pointer.
3163  * @val: link speed value.
3164  *
3165  * Description:
3166  * If val is in a valid range then set the adapter's link speed field.
3167  *
3168  * Notes:
3169  * If the value is not in range log a kernel error message, clear the link
3170  * speed and return an error.
3171  *
3172  * Returns:
3173  * zero if val saved.
3174  * -EINVAL val out of range
3175  **/
3176 static int
3177 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3178 {
3179 	if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3180 	    (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3181 		phba->cfg_link_speed = val;
3182 		return 0;
3183 	}
3184 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3185 			"0405 lpfc_link_speed attribute cannot "
3186 			"be set to %d, allowed values are "
3187 			"["LPFC_LINK_SPEED_STRING"]\n", val);
3188 	phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
3189 	return -EINVAL;
3190 }
3191 
3192 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
3193 		   lpfc_link_speed_show, lpfc_link_speed_store);
3194 
3195 /*
3196 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3197 #       0  = aer disabled or not supported
3198 #       1  = aer supported and enabled (default)
3199 # Value range is [0,1]. Default value is 1.
3200 */
3201 
3202 /**
3203  * lpfc_aer_support_store - Set the adapter for aer support
3204  *
3205  * @dev: class device that is converted into a Scsi_host.
3206  * @attr: device attribute, not used.
3207  * @buf: containing enable or disable aer flag.
3208  * @count: unused variable.
3209  *
3210  * Description:
3211  * If the val is 1 and currently the device's AER capability was not
3212  * enabled, invoke the kernel's enable AER helper routine, trying to
3213  * enable the device's AER capability. If the helper routine enabling
3214  * AER returns success, update the device's cfg_aer_support flag to
3215  * indicate AER is supported by the device; otherwise, if the device
3216  * AER capability is already enabled to support AER, then do nothing.
3217  *
3218  * If the val is 0 and currently the device's AER support was enabled,
3219  * invoke the kernel's disable AER helper routine. After that, update
3220  * the device's cfg_aer_support flag to indicate AER is not supported
3221  * by the device; otherwise, if the device AER capability is already
3222  * disabled from supporting AER, then do nothing.
3223  *
3224  * Returns:
3225  * length of the buf on success if val is in range the intended mode
3226  * is supported.
3227  * -EINVAL if val out of range or intended mode is not supported.
3228  **/
3229 static ssize_t
3230 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3231 		       const char *buf, size_t count)
3232 {
3233 	struct Scsi_Host *shost = class_to_shost(dev);
3234 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3235 	struct lpfc_hba *phba = vport->phba;
3236 	int val = 0, rc = -EINVAL;
3237 
3238 	if (!isdigit(buf[0]))
3239 		return -EINVAL;
3240 	if (sscanf(buf, "%i", &val) != 1)
3241 		return -EINVAL;
3242 
3243 	switch (val) {
3244 	case 0:
3245 		if (phba->hba_flag & HBA_AER_ENABLED) {
3246 			rc = pci_disable_pcie_error_reporting(phba->pcidev);
3247 			if (!rc) {
3248 				spin_lock_irq(&phba->hbalock);
3249 				phba->hba_flag &= ~HBA_AER_ENABLED;
3250 				spin_unlock_irq(&phba->hbalock);
3251 				phba->cfg_aer_support = 0;
3252 				rc = strlen(buf);
3253 			} else
3254 				rc = -EPERM;
3255 		} else {
3256 			phba->cfg_aer_support = 0;
3257 			rc = strlen(buf);
3258 		}
3259 		break;
3260 	case 1:
3261 		if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3262 			rc = pci_enable_pcie_error_reporting(phba->pcidev);
3263 			if (!rc) {
3264 				spin_lock_irq(&phba->hbalock);
3265 				phba->hba_flag |= HBA_AER_ENABLED;
3266 				spin_unlock_irq(&phba->hbalock);
3267 				phba->cfg_aer_support = 1;
3268 				rc = strlen(buf);
3269 			} else
3270 				 rc = -EPERM;
3271 		} else {
3272 			phba->cfg_aer_support = 1;
3273 			rc = strlen(buf);
3274 		}
3275 		break;
3276 	default:
3277 		rc = -EINVAL;
3278 		break;
3279 	}
3280 	return rc;
3281 }
3282 
3283 static int lpfc_aer_support = 1;
3284 module_param(lpfc_aer_support, int, S_IRUGO);
3285 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3286 lpfc_param_show(aer_support)
3287 
3288 /**
3289  * lpfc_aer_support_init - Set the initial adapters aer support flag
3290  * @phba: lpfc_hba pointer.
3291  * @val: enable aer or disable aer flag.
3292  *
3293  * Description:
3294  * If val is in a valid range [0,1], then set the adapter's initial
3295  * cfg_aer_support field. It will be up to the driver's probe_one
3296  * routine to determine whether the device's AER support can be set
3297  * or not.
3298  *
3299  * Notes:
3300  * If the value is not in range log a kernel error message, and
3301  * choose the default value of setting AER support and return.
3302  *
3303  * Returns:
3304  * zero if val saved.
3305  * -EINVAL val out of range
3306  **/
3307 static int
3308 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3309 {
3310 	if (val == 0 || val == 1) {
3311 		phba->cfg_aer_support = val;
3312 		return 0;
3313 	}
3314 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3315 			"2712 lpfc_aer_support attribute value %d out "
3316 			"of range, allowed values are 0|1, setting it "
3317 			"to default value of 1\n", val);
3318 	/* By default, try to enable AER on a device */
3319 	phba->cfg_aer_support = 1;
3320 	return -EINVAL;
3321 }
3322 
3323 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3324 		   lpfc_aer_support_show, lpfc_aer_support_store);
3325 
3326 /**
3327  * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3328  * @dev: class device that is converted into a Scsi_host.
3329  * @attr: device attribute, not used.
3330  * @buf: containing flag 1 for aer cleanup state.
3331  * @count: unused variable.
3332  *
3333  * Description:
3334  * If the @buf contains 1 and the device currently has the AER support
3335  * enabled, then invokes the kernel AER helper routine
3336  * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3337  * error status register.
3338  *
3339  * Notes:
3340  *
3341  * Returns:
3342  * -EINVAL if the buf does not contain the 1 or the device is not currently
3343  * enabled with the AER support.
3344  **/
3345 static ssize_t
3346 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3347 		       const char *buf, size_t count)
3348 {
3349 	struct Scsi_Host  *shost = class_to_shost(dev);
3350 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3351 	struct lpfc_hba   *phba = vport->phba;
3352 	int val, rc = -1;
3353 
3354 	if (!isdigit(buf[0]))
3355 		return -EINVAL;
3356 	if (sscanf(buf, "%i", &val) != 1)
3357 		return -EINVAL;
3358 	if (val != 1)
3359 		return -EINVAL;
3360 
3361 	if (phba->hba_flag & HBA_AER_ENABLED)
3362 		rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3363 
3364 	if (rc == 0)
3365 		return strlen(buf);
3366 	else
3367 		return -EPERM;
3368 }
3369 
3370 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3371 		   lpfc_aer_cleanup_state);
3372 
3373 /**
3374  * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3375  *
3376  * @dev: class device that is converted into a Scsi_host.
3377  * @attr: device attribute, not used.
3378  * @buf: containing the string the number of vfs to be enabled.
3379  * @count: unused variable.
3380  *
3381  * Description:
3382  * When this api is called either through user sysfs, the driver shall
3383  * try to enable or disable SR-IOV virtual functions according to the
3384  * following:
3385  *
3386  * If zero virtual function has been enabled to the physical function,
3387  * the driver shall invoke the pci enable virtual function api trying
3388  * to enable the virtual functions. If the nr_vfn provided is greater
3389  * than the maximum supported, the maximum virtual function number will
3390  * be used for invoking the api; otherwise, the nr_vfn provided shall
3391  * be used for invoking the api. If the api call returned success, the
3392  * actual number of virtual functions enabled will be set to the driver
3393  * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3394  * cfg_sriov_nr_virtfn remains zero.
3395  *
3396  * If none-zero virtual functions have already been enabled to the
3397  * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3398  * -EINVAL will be returned and the driver does nothing;
3399  *
3400  * If the nr_vfn provided is zero and none-zero virtual functions have
3401  * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3402  * disabling virtual function api shall be invoded to disable all the
3403  * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3404  * zero. Otherwise, if zero virtual function has been enabled, do
3405  * nothing.
3406  *
3407  * Returns:
3408  * length of the buf on success if val is in range the intended mode
3409  * is supported.
3410  * -EINVAL if val out of range or intended mode is not supported.
3411  **/
3412 static ssize_t
3413 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3414 			 const char *buf, size_t count)
3415 {
3416 	struct Scsi_Host *shost = class_to_shost(dev);
3417 	struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3418 	struct lpfc_hba *phba = vport->phba;
3419 	struct pci_dev *pdev = phba->pcidev;
3420 	int val = 0, rc = -EINVAL;
3421 
3422 	/* Sanity check on user data */
3423 	if (!isdigit(buf[0]))
3424 		return -EINVAL;
3425 	if (sscanf(buf, "%i", &val) != 1)
3426 		return -EINVAL;
3427 	if (val < 0)
3428 		return -EINVAL;
3429 
3430 	/* Request disabling virtual functions */
3431 	if (val == 0) {
3432 		if (phba->cfg_sriov_nr_virtfn > 0) {
3433 			pci_disable_sriov(pdev);
3434 			phba->cfg_sriov_nr_virtfn = 0;
3435 		}
3436 		return strlen(buf);
3437 	}
3438 
3439 	/* Request enabling virtual functions */
3440 	if (phba->cfg_sriov_nr_virtfn > 0) {
3441 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3442 				"3018 There are %d virtual functions "
3443 				"enabled on physical function.\n",
3444 				phba->cfg_sriov_nr_virtfn);
3445 		return -EEXIST;
3446 	}
3447 
3448 	if (val <= LPFC_MAX_VFN_PER_PFN)
3449 		phba->cfg_sriov_nr_virtfn = val;
3450 	else {
3451 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3452 				"3019 Enabling %d virtual functions is not "
3453 				"allowed.\n", val);
3454 		return -EINVAL;
3455 	}
3456 
3457 	rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3458 	if (rc) {
3459 		phba->cfg_sriov_nr_virtfn = 0;
3460 		rc = -EPERM;
3461 	} else
3462 		rc = strlen(buf);
3463 
3464 	return rc;
3465 }
3466 
3467 static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3468 module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3469 MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3470 lpfc_param_show(sriov_nr_virtfn)
3471 
3472 /**
3473  * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3474  * @phba: lpfc_hba pointer.
3475  * @val: link speed value.
3476  *
3477  * Description:
3478  * If val is in a valid range [0,255], then set the adapter's initial
3479  * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3480  * number shall be used instead. It will be up to the driver's probe_one
3481  * routine to determine whether the device's SR-IOV is supported or not.
3482  *
3483  * Returns:
3484  * zero if val saved.
3485  * -EINVAL val out of range
3486  **/
3487 static int
3488 lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3489 {
3490 	if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3491 		phba->cfg_sriov_nr_virtfn = val;
3492 		return 0;
3493 	}
3494 
3495 	lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3496 			"3017 Enabling %d virtual functions is not "
3497 			"allowed.\n", val);
3498 	return -EINVAL;
3499 }
3500 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3501 		   lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3502 
3503 /*
3504 # lpfc_fcp_class:  Determines FC class to use for the FCP protocol.
3505 # Value range is [2,3]. Default value is 3.
3506 */
3507 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3508 		  "Select Fibre Channel class of service for FCP sequences");
3509 
3510 /*
3511 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3512 # is [0,1]. Default value is 0.
3513 */
3514 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3515 		   "Use ADISC on rediscovery to authenticate FCP devices");
3516 
3517 /*
3518 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3519 # depth. Default value is 0. When the value of this parameter is zero the
3520 # SCSI command completion time is not used for controlling I/O queue depth. When
3521 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3522 # to limit the I/O completion time to the parameter value.
3523 # The value is set in milliseconds.
3524 */
3525 static int lpfc_max_scsicmpl_time;
3526 module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3527 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3528 	"Use command completion time to control queue depth");
3529 lpfc_vport_param_show(max_scsicmpl_time);
3530 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3531 static int
3532 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3533 {
3534 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3535 	struct lpfc_nodelist *ndlp, *next_ndlp;
3536 
3537 	if (val == vport->cfg_max_scsicmpl_time)
3538 		return 0;
3539 	if ((val < 0) || (val > 60000))
3540 		return -EINVAL;
3541 	vport->cfg_max_scsicmpl_time = val;
3542 
3543 	spin_lock_irq(shost->host_lock);
3544 	list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3545 		if (!NLP_CHK_NODE_ACT(ndlp))
3546 			continue;
3547 		if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3548 			continue;
3549 		ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3550 	}
3551 	spin_unlock_irq(shost->host_lock);
3552 	return 0;
3553 }
3554 lpfc_vport_param_store(max_scsicmpl_time);
3555 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3556 		   lpfc_max_scsicmpl_time_show,
3557 		   lpfc_max_scsicmpl_time_store);
3558 
3559 /*
3560 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3561 # range is [0,1]. Default value is 0.
3562 */
3563 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3564 
3565 /*
3566 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3567 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3568 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3569 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3570 # cr_delay is set to 0.
3571 */
3572 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3573 		"interrupt response is generated");
3574 
3575 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3576 		"interrupt response is generated");
3577 
3578 /*
3579 # lpfc_multi_ring_support:  Determines how many rings to spread available
3580 # cmd/rsp IOCB entries across.
3581 # Value range is [1,2]. Default value is 1.
3582 */
3583 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3584 		"SLI rings to spread IOCB entries across");
3585 
3586 /*
3587 # lpfc_multi_ring_rctl:  If lpfc_multi_ring_support is enabled, this
3588 # identifies what rctl value to configure the additional ring for.
3589 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3590 */
3591 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3592 	     255, "Identifies RCTL for additional ring configuration");
3593 
3594 /*
3595 # lpfc_multi_ring_type:  If lpfc_multi_ring_support is enabled, this
3596 # identifies what type value to configure the additional ring for.
3597 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3598 */
3599 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3600 	     255, "Identifies TYPE for additional ring configuration");
3601 
3602 /*
3603 # lpfc_fdmi_on: controls FDMI support.
3604 #       0 = no FDMI support
3605 #       1 = support FDMI without attribute of hostname
3606 #       2 = support FDMI with attribute of hostname
3607 # Value range [0,2]. Default value is 0.
3608 */
3609 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3610 
3611 /*
3612 # Specifies the maximum number of ELS cmds we can have outstanding (for
3613 # discovery). Value range is [1,64]. Default value = 32.
3614 */
3615 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3616 		 "during discovery");
3617 
3618 /*
3619 # lpfc_max_luns: maximum allowed LUN.
3620 # Value range is [0,65535]. Default value is 255.
3621 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3622 */
3623 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3624 
3625 /*
3626 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3627 # Value range is [1,255], default value is 10.
3628 */
3629 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3630 	     "Milliseconds driver will wait between polling FCP ring");
3631 
3632 /*
3633 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3634 #		support this feature
3635 #       0  = MSI disabled
3636 #       1  = MSI enabled
3637 #       2  = MSI-X enabled (default)
3638 # Value range is [0,2]. Default value is 2.
3639 */
3640 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3641 	    "MSI-X (2), if possible");
3642 
3643 /*
3644 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3645 #
3646 # Value range is [636,651042]. Default value is 10000.
3647 */
3648 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3649 	    "Set the maximum number of fast-path FCP interrupts per second");
3650 
3651 /*
3652 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3653 #
3654 # Value range is [1,31]. Default value is 4.
3655 */
3656 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3657 	    "Set the number of fast-path FCP work queues, if possible");
3658 
3659 /*
3660 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3661 #
3662 # Value range is [1,7]. Default value is 1.
3663 */
3664 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3665 	    "Set the number of fast-path FCP event queues, if possible");
3666 
3667 /*
3668 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3669 #       0  = HBA resets disabled
3670 #       1  = HBA resets enabled (default)
3671 # Value range is [0,1]. Default value is 1.
3672 */
3673 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3674 
3675 /*
3676 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3677 #       0  = HBA Heartbeat disabled
3678 #       1  = HBA Heartbeat enabled (default)
3679 # Value range is [0,1]. Default value is 1.
3680 */
3681 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3682 
3683 /*
3684 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3685 #       0  = BlockGuard disabled (default)
3686 #       1  = BlockGuard enabled
3687 # Value range is [0,1]. Default value is 0.
3688 */
3689 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3690 
3691 /*
3692 # lpfc_prot_mask: i
3693 #	- Bit mask of host protection capabilities used to register with the
3694 #	  SCSI mid-layer
3695 # 	- Only meaningful if BG is turned on (lpfc_enable_bg=1).
3696 #	- Allows you to ultimately specify which profiles to use
3697 #	- Default will result in registering capabilities for all profiles.
3698 #
3699 */
3700 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3701 			      SHOST_DIX_TYPE0_PROTECTION |
3702 			      SHOST_DIX_TYPE1_PROTECTION;
3703 
3704 module_param(lpfc_prot_mask, uint, S_IRUGO);
3705 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3706 
3707 /*
3708 # lpfc_prot_guard: i
3709 #	- Bit mask of protection guard types to register with the SCSI mid-layer
3710 # 	- Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3711 #	- Allows you to ultimately specify which profiles to use
3712 #	- Default will result in registering capabilities for all guard types
3713 #
3714 */
3715 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3716 module_param(lpfc_prot_guard, byte, S_IRUGO);
3717 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3718 
3719 /*
3720  * Delay initial NPort discovery when Clean Address bit is cleared in
3721  * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3722  * This parameter can have value 0 or 1.
3723  * When this parameter is set to 0, no delay is added to the initial
3724  * discovery.
3725  * When this parameter is set to non-zero value, initial Nport discovery is
3726  * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3727  * accept and FCID/Fabric name/Fabric portname is changed.
3728  * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3729  * when Clean Address bit is cleared in FLOGI/FDISC
3730  * accept and FCID/Fabric name/Fabric portname is changed.
3731  * Default value is 0.
3732  */
3733 int lpfc_delay_discovery;
3734 module_param(lpfc_delay_discovery, int, S_IRUGO);
3735 MODULE_PARM_DESC(lpfc_delay_discovery,
3736 	"Delay NPort discovery when Clean Address bit is cleared. "
3737 	"Allowed values: 0,1.");
3738 
3739 /*
3740  * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3741  * This value can be set to values between 64 and 256. The default value is
3742  * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3743  * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3744  */
3745 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3746 	    LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3747 
3748 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3749 		LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3750 		"Max Protection Scatter Gather Segment Count");
3751 
3752 struct device_attribute *lpfc_hba_attrs[] = {
3753 	&dev_attr_bg_info,
3754 	&dev_attr_bg_guard_err,
3755 	&dev_attr_bg_apptag_err,
3756 	&dev_attr_bg_reftag_err,
3757 	&dev_attr_info,
3758 	&dev_attr_serialnum,
3759 	&dev_attr_modeldesc,
3760 	&dev_attr_modelname,
3761 	&dev_attr_programtype,
3762 	&dev_attr_portnum,
3763 	&dev_attr_fwrev,
3764 	&dev_attr_hdw,
3765 	&dev_attr_option_rom_version,
3766 	&dev_attr_link_state,
3767 	&dev_attr_num_discovered_ports,
3768 	&dev_attr_menlo_mgmt_mode,
3769 	&dev_attr_lpfc_drvr_version,
3770 	&dev_attr_lpfc_enable_fip,
3771 	&dev_attr_lpfc_temp_sensor,
3772 	&dev_attr_lpfc_log_verbose,
3773 	&dev_attr_lpfc_lun_queue_depth,
3774 	&dev_attr_lpfc_tgt_queue_depth,
3775 	&dev_attr_lpfc_hba_queue_depth,
3776 	&dev_attr_lpfc_peer_port_login,
3777 	&dev_attr_lpfc_nodev_tmo,
3778 	&dev_attr_lpfc_devloss_tmo,
3779 	&dev_attr_lpfc_fcp_class,
3780 	&dev_attr_lpfc_use_adisc,
3781 	&dev_attr_lpfc_ack0,
3782 	&dev_attr_lpfc_topology,
3783 	&dev_attr_lpfc_scan_down,
3784 	&dev_attr_lpfc_link_speed,
3785 	&dev_attr_lpfc_cr_delay,
3786 	&dev_attr_lpfc_cr_count,
3787 	&dev_attr_lpfc_multi_ring_support,
3788 	&dev_attr_lpfc_multi_ring_rctl,
3789 	&dev_attr_lpfc_multi_ring_type,
3790 	&dev_attr_lpfc_fdmi_on,
3791 	&dev_attr_lpfc_max_luns,
3792 	&dev_attr_lpfc_enable_npiv,
3793 	&dev_attr_lpfc_fcf_failover_policy,
3794 	&dev_attr_lpfc_enable_rrq,
3795 	&dev_attr_nport_evt_cnt,
3796 	&dev_attr_board_mode,
3797 	&dev_attr_max_vpi,
3798 	&dev_attr_used_vpi,
3799 	&dev_attr_max_rpi,
3800 	&dev_attr_used_rpi,
3801 	&dev_attr_max_xri,
3802 	&dev_attr_used_xri,
3803 	&dev_attr_npiv_info,
3804 	&dev_attr_issue_reset,
3805 	&dev_attr_lpfc_poll,
3806 	&dev_attr_lpfc_poll_tmo,
3807 	&dev_attr_lpfc_use_msi,
3808 	&dev_attr_lpfc_fcp_imax,
3809 	&dev_attr_lpfc_fcp_wq_count,
3810 	&dev_attr_lpfc_fcp_eq_count,
3811 	&dev_attr_lpfc_enable_bg,
3812 	&dev_attr_lpfc_soft_wwnn,
3813 	&dev_attr_lpfc_soft_wwpn,
3814 	&dev_attr_lpfc_soft_wwn_enable,
3815 	&dev_attr_lpfc_enable_hba_reset,
3816 	&dev_attr_lpfc_enable_hba_heartbeat,
3817 	&dev_attr_lpfc_sg_seg_cnt,
3818 	&dev_attr_lpfc_max_scsicmpl_time,
3819 	&dev_attr_lpfc_stat_data_ctrl,
3820 	&dev_attr_lpfc_prot_sg_seg_cnt,
3821 	&dev_attr_lpfc_aer_support,
3822 	&dev_attr_lpfc_aer_state_cleanup,
3823 	&dev_attr_lpfc_sriov_nr_virtfn,
3824 	&dev_attr_lpfc_suppress_link_up,
3825 	&dev_attr_lpfc_iocb_cnt,
3826 	&dev_attr_iocb_hw,
3827 	&dev_attr_txq_hw,
3828 	&dev_attr_txcmplq_hw,
3829 	&dev_attr_lpfc_fips_level,
3830 	&dev_attr_lpfc_fips_rev,
3831 	&dev_attr_lpfc_dss,
3832 	&dev_attr_lpfc_sriov_hw_max_virtfn,
3833 	NULL,
3834 };
3835 
3836 struct device_attribute *lpfc_vport_attrs[] = {
3837 	&dev_attr_info,
3838 	&dev_attr_link_state,
3839 	&dev_attr_num_discovered_ports,
3840 	&dev_attr_lpfc_drvr_version,
3841 	&dev_attr_lpfc_log_verbose,
3842 	&dev_attr_lpfc_lun_queue_depth,
3843 	&dev_attr_lpfc_tgt_queue_depth,
3844 	&dev_attr_lpfc_nodev_tmo,
3845 	&dev_attr_lpfc_devloss_tmo,
3846 	&dev_attr_lpfc_hba_queue_depth,
3847 	&dev_attr_lpfc_peer_port_login,
3848 	&dev_attr_lpfc_restrict_login,
3849 	&dev_attr_lpfc_fcp_class,
3850 	&dev_attr_lpfc_use_adisc,
3851 	&dev_attr_lpfc_fdmi_on,
3852 	&dev_attr_lpfc_max_luns,
3853 	&dev_attr_nport_evt_cnt,
3854 	&dev_attr_npiv_info,
3855 	&dev_attr_lpfc_enable_da_id,
3856 	&dev_attr_lpfc_max_scsicmpl_time,
3857 	&dev_attr_lpfc_stat_data_ctrl,
3858 	&dev_attr_lpfc_static_vport,
3859 	&dev_attr_lpfc_fips_level,
3860 	&dev_attr_lpfc_fips_rev,
3861 	NULL,
3862 };
3863 
3864 /**
3865  * sysfs_ctlreg_write - Write method for writing to ctlreg
3866  * @filp: open sysfs file
3867  * @kobj: kernel kobject that contains the kernel class device.
3868  * @bin_attr: kernel attributes passed to us.
3869  * @buf: contains the data to be written to the adapter IOREG space.
3870  * @off: offset into buffer to beginning of data.
3871  * @count: bytes to transfer.
3872  *
3873  * Description:
3874  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3875  * Uses the adapter io control registers to send buf contents to the adapter.
3876  *
3877  * Returns:
3878  * -ERANGE off and count combo out of range
3879  * -EINVAL off, count or buff address invalid
3880  * -EPERM adapter is offline
3881  * value of count, buf contents written
3882  **/
3883 static ssize_t
3884 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3885 		   struct bin_attribute *bin_attr,
3886 		   char *buf, loff_t off, size_t count)
3887 {
3888 	size_t buf_off;
3889 	struct device *dev = container_of(kobj, struct device, kobj);
3890 	struct Scsi_Host  *shost = class_to_shost(dev);
3891 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3892 	struct lpfc_hba   *phba = vport->phba;
3893 
3894 	if (phba->sli_rev >= LPFC_SLI_REV4)
3895 		return -EPERM;
3896 
3897 	if ((off + count) > FF_REG_AREA_SIZE)
3898 		return -ERANGE;
3899 
3900 	if (count <= LPFC_REG_WRITE_KEY_SIZE)
3901 		return 0;
3902 
3903 	if (off % 4 || count % 4 || (unsigned long)buf % 4)
3904 		return -EINVAL;
3905 
3906 	/* This is to protect HBA registers from accidental writes. */
3907 	if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
3908 		return -EINVAL;
3909 
3910 	if (!(vport->fc_flag & FC_OFFLINE_MODE))
3911 		return -EPERM;
3912 
3913 	spin_lock_irq(&phba->hbalock);
3914 	for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
3915 			buf_off += sizeof(uint32_t))
3916 		writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
3917 		       phba->ctrl_regs_memmap_p + off + buf_off);
3918 
3919 	spin_unlock_irq(&phba->hbalock);
3920 
3921 	return count;
3922 }
3923 
3924 /**
3925  * sysfs_ctlreg_read - Read method for reading from ctlreg
3926  * @filp: open sysfs file
3927  * @kobj: kernel kobject that contains the kernel class device.
3928  * @bin_attr: kernel attributes passed to us.
3929  * @buf: if successful contains the data from the adapter IOREG space.
3930  * @off: offset into buffer to beginning of data.
3931  * @count: bytes to transfer.
3932  *
3933  * Description:
3934  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3935  * Uses the adapter io control registers to read data into buf.
3936  *
3937  * Returns:
3938  * -ERANGE off and count combo out of range
3939  * -EINVAL off, count or buff address invalid
3940  * value of count, buf contents read
3941  **/
3942 static ssize_t
3943 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3944 		  struct bin_attribute *bin_attr,
3945 		  char *buf, loff_t off, size_t count)
3946 {
3947 	size_t buf_off;
3948 	uint32_t * tmp_ptr;
3949 	struct device *dev = container_of(kobj, struct device, kobj);
3950 	struct Scsi_Host  *shost = class_to_shost(dev);
3951 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3952 	struct lpfc_hba   *phba = vport->phba;
3953 
3954 	if (phba->sli_rev >= LPFC_SLI_REV4)
3955 		return -EPERM;
3956 
3957 	if (off > FF_REG_AREA_SIZE)
3958 		return -ERANGE;
3959 
3960 	if ((off + count) > FF_REG_AREA_SIZE)
3961 		count = FF_REG_AREA_SIZE - off;
3962 
3963 	if (count == 0) return 0;
3964 
3965 	if (off % 4 || count % 4 || (unsigned long)buf % 4)
3966 		return -EINVAL;
3967 
3968 	spin_lock_irq(&phba->hbalock);
3969 
3970 	for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3971 		tmp_ptr = (uint32_t *)(buf + buf_off);
3972 		*tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3973 	}
3974 
3975 	spin_unlock_irq(&phba->hbalock);
3976 
3977 	return count;
3978 }
3979 
3980 static struct bin_attribute sysfs_ctlreg_attr = {
3981 	.attr = {
3982 		.name = "ctlreg",
3983 		.mode = S_IRUSR | S_IWUSR,
3984 	},
3985 	.size = 256,
3986 	.read = sysfs_ctlreg_read,
3987 	.write = sysfs_ctlreg_write,
3988 };
3989 
3990 /**
3991  * sysfs_mbox_idle - frees the sysfs mailbox
3992  * @phba: lpfc_hba pointer
3993  **/
3994 static void
3995 sysfs_mbox_idle(struct lpfc_hba *phba)
3996 {
3997 	phba->sysfs_mbox.state = SMBOX_IDLE;
3998 	phba->sysfs_mbox.offset = 0;
3999 
4000 	if (phba->sysfs_mbox.mbox) {
4001 		mempool_free(phba->sysfs_mbox.mbox,
4002 			     phba->mbox_mem_pool);
4003 		phba->sysfs_mbox.mbox = NULL;
4004 	}
4005 }
4006 
4007 /**
4008  * sysfs_mbox_write - Write method for writing information via mbox
4009  * @filp: open sysfs file
4010  * @kobj: kernel kobject that contains the kernel class device.
4011  * @bin_attr: kernel attributes passed to us.
4012  * @buf: contains the data to be written to sysfs mbox.
4013  * @off: offset into buffer to beginning of data.
4014  * @count: bytes to transfer.
4015  *
4016  * Description:
4017  * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4018  * Uses the sysfs mbox to send buf contents to the adapter.
4019  *
4020  * Returns:
4021  * -ERANGE off and count combo out of range
4022  * -EINVAL off, count or buff address invalid
4023  * zero if count is zero
4024  * -EPERM adapter is offline
4025  * -ENOMEM failed to allocate memory for the mail box
4026  * -EAGAIN offset, state or mbox is NULL
4027  * count number of bytes transferred
4028  **/
4029 static ssize_t
4030 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4031 		 struct bin_attribute *bin_attr,
4032 		 char *buf, loff_t off, size_t count)
4033 {
4034 	struct device *dev = container_of(kobj, struct device, kobj);
4035 	struct Scsi_Host  *shost = class_to_shost(dev);
4036 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4037 	struct lpfc_hba   *phba = vport->phba;
4038 	struct lpfcMboxq  *mbox = NULL;
4039 
4040 	if ((count + off) > MAILBOX_CMD_SIZE)
4041 		return -ERANGE;
4042 
4043 	if (off % 4 ||  count % 4 || (unsigned long)buf % 4)
4044 		return -EINVAL;
4045 
4046 	if (count == 0)
4047 		return 0;
4048 
4049 	if (off == 0) {
4050 		mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4051 		if (!mbox)
4052 			return -ENOMEM;
4053 		memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
4054 	}
4055 
4056 	spin_lock_irq(&phba->hbalock);
4057 
4058 	if (off == 0) {
4059 		if (phba->sysfs_mbox.mbox)
4060 			mempool_free(mbox, phba->mbox_mem_pool);
4061 		else
4062 			phba->sysfs_mbox.mbox = mbox;
4063 		phba->sysfs_mbox.state = SMBOX_WRITING;
4064 	} else {
4065 		if (phba->sysfs_mbox.state  != SMBOX_WRITING ||
4066 		    phba->sysfs_mbox.offset != off           ||
4067 		    phba->sysfs_mbox.mbox   == NULL) {
4068 			sysfs_mbox_idle(phba);
4069 			spin_unlock_irq(&phba->hbalock);
4070 			return -EAGAIN;
4071 		}
4072 	}
4073 
4074 	memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
4075 	       buf, count);
4076 
4077 	phba->sysfs_mbox.offset = off + count;
4078 
4079 	spin_unlock_irq(&phba->hbalock);
4080 
4081 	return count;
4082 }
4083 
4084 /**
4085  * sysfs_mbox_read - Read method for reading information via mbox
4086  * @filp: open sysfs file
4087  * @kobj: kernel kobject that contains the kernel class device.
4088  * @bin_attr: kernel attributes passed to us.
4089  * @buf: contains the data to be read from sysfs mbox.
4090  * @off: offset into buffer to beginning of data.
4091  * @count: bytes to transfer.
4092  *
4093  * Description:
4094  * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4095  * Uses the sysfs mbox to receive data from to the adapter.
4096  *
4097  * Returns:
4098  * -ERANGE off greater than mailbox command size
4099  * -EINVAL off, count or buff address invalid
4100  * zero if off and count are zero
4101  * -EACCES adapter over temp
4102  * -EPERM garbage can value to catch a multitude of errors
4103  * -EAGAIN management IO not permitted, state or off error
4104  * -ETIME mailbox timeout
4105  * -ENODEV mailbox error
4106  * count number of bytes transferred
4107  **/
4108 static ssize_t
4109 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4110 		struct bin_attribute *bin_attr,
4111 		char *buf, loff_t off, size_t count)
4112 {
4113 	struct device *dev = container_of(kobj, struct device, kobj);
4114 	struct Scsi_Host  *shost = class_to_shost(dev);
4115 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4116 	struct lpfc_hba   *phba = vport->phba;
4117 	LPFC_MBOXQ_t *mboxq;
4118 	MAILBOX_t *pmb;
4119 	uint32_t mbox_tmo;
4120 	int rc;
4121 
4122 	if (off > MAILBOX_CMD_SIZE)
4123 		return -ERANGE;
4124 
4125 	if ((count + off) > MAILBOX_CMD_SIZE)
4126 		count = MAILBOX_CMD_SIZE - off;
4127 
4128 	if (off % 4 ||  count % 4 || (unsigned long)buf % 4)
4129 		return -EINVAL;
4130 
4131 	if (off && count == 0)
4132 		return 0;
4133 
4134 	spin_lock_irq(&phba->hbalock);
4135 
4136 	if (phba->over_temp_state == HBA_OVER_TEMP) {
4137 		sysfs_mbox_idle(phba);
4138 		spin_unlock_irq(&phba->hbalock);
4139 		return  -EACCES;
4140 	}
4141 
4142 	if (off == 0 &&
4143 	    phba->sysfs_mbox.state  == SMBOX_WRITING &&
4144 	    phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
4145 		mboxq = (LPFC_MBOXQ_t *)&phba->sysfs_mbox.mbox;
4146 		pmb = &mboxq->u.mb;
4147 		switch (pmb->mbxCommand) {
4148 			/* Offline only */
4149 		case MBX_INIT_LINK:
4150 		case MBX_DOWN_LINK:
4151 		case MBX_CONFIG_LINK:
4152 		case MBX_CONFIG_RING:
4153 		case MBX_RESET_RING:
4154 		case MBX_UNREG_LOGIN:
4155 		case MBX_CLEAR_LA:
4156 		case MBX_DUMP_CONTEXT:
4157 		case MBX_RUN_DIAGS:
4158 		case MBX_RESTART:
4159 		case MBX_SET_MASK:
4160 		case MBX_SET_DEBUG:
4161 			if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
4162 				printk(KERN_WARNING "mbox_read:Command 0x%x "
4163 				       "is illegal in on-line state\n",
4164 				       pmb->mbxCommand);
4165 				sysfs_mbox_idle(phba);
4166 				spin_unlock_irq(&phba->hbalock);
4167 				return -EPERM;
4168 			}
4169 		case MBX_WRITE_NV:
4170 		case MBX_WRITE_VPARMS:
4171 		case MBX_LOAD_SM:
4172 		case MBX_READ_NV:
4173 		case MBX_READ_CONFIG:
4174 		case MBX_READ_RCONFIG:
4175 		case MBX_READ_STATUS:
4176 		case MBX_READ_XRI:
4177 		case MBX_READ_REV:
4178 		case MBX_READ_LNK_STAT:
4179 		case MBX_DUMP_MEMORY:
4180 		case MBX_DOWN_LOAD:
4181 		case MBX_UPDATE_CFG:
4182 		case MBX_KILL_BOARD:
4183 		case MBX_LOAD_AREA:
4184 		case MBX_LOAD_EXP_ROM:
4185 		case MBX_BEACON:
4186 		case MBX_DEL_LD_ENTRY:
4187 		case MBX_SET_VARIABLE:
4188 		case MBX_WRITE_WWN:
4189 		case MBX_PORT_CAPABILITIES:
4190 		case MBX_PORT_IOV_CONTROL:
4191 			break;
4192 		case MBX_SECURITY_MGMT:
4193 		case MBX_AUTH_PORT:
4194 			if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4195 				printk(KERN_WARNING "mbox_read:Command 0x%x "
4196 				       "is not permitted\n", pmb->mbxCommand);
4197 				sysfs_mbox_idle(phba);
4198 				spin_unlock_irq(&phba->hbalock);
4199 				return -EPERM;
4200 			}
4201 			break;
4202 		case MBX_READ_SPARM64:
4203 		case MBX_READ_TOPOLOGY:
4204 		case MBX_REG_LOGIN:
4205 		case MBX_REG_LOGIN64:
4206 		case MBX_CONFIG_PORT:
4207 		case MBX_RUN_BIU_DIAG:
4208 			printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
4209 			       pmb->mbxCommand);
4210 			sysfs_mbox_idle(phba);
4211 			spin_unlock_irq(&phba->hbalock);
4212 			return -EPERM;
4213 		default:
4214 			printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
4215 			       pmb->mbxCommand);
4216 			sysfs_mbox_idle(phba);
4217 			spin_unlock_irq(&phba->hbalock);
4218 			return -EPERM;
4219 		}
4220 
4221 		/* If HBA encountered an error attention, allow only DUMP
4222 		 * or RESTART mailbox commands until the HBA is restarted.
4223 		 */
4224 		if (phba->pport->stopped &&
4225 		    pmb->mbxCommand != MBX_DUMP_MEMORY &&
4226 		    pmb->mbxCommand != MBX_RESTART &&
4227 		    pmb->mbxCommand != MBX_WRITE_VPARMS &&
4228 		    pmb->mbxCommand != MBX_WRITE_WWN)
4229 			lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4230 					"1259 mbox: Issued mailbox cmd "
4231 					"0x%x while in stopped state.\n",
4232 					pmb->mbxCommand);
4233 
4234 		phba->sysfs_mbox.mbox->vport = vport;
4235 
4236 		/* Don't allow mailbox commands to be sent when blocked
4237 		 * or when in the middle of discovery
4238 		 */
4239 		if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
4240 			sysfs_mbox_idle(phba);
4241 			spin_unlock_irq(&phba->hbalock);
4242 			return  -EAGAIN;
4243 		}
4244 
4245 		if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4246 		    (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
4247 
4248 			spin_unlock_irq(&phba->hbalock);
4249 			rc = lpfc_sli_issue_mbox (phba,
4250 						  phba->sysfs_mbox.mbox,
4251 						  MBX_POLL);
4252 			spin_lock_irq(&phba->hbalock);
4253 
4254 		} else {
4255 			spin_unlock_irq(&phba->hbalock);
4256 			mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
4257 			rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
4258 			spin_lock_irq(&phba->hbalock);
4259 		}
4260 
4261 		if (rc != MBX_SUCCESS) {
4262 			if (rc == MBX_TIMEOUT) {
4263 				phba->sysfs_mbox.mbox = NULL;
4264 			}
4265 			sysfs_mbox_idle(phba);
4266 			spin_unlock_irq(&phba->hbalock);
4267 			return  (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
4268 		}
4269 		phba->sysfs_mbox.state = SMBOX_READING;
4270 	}
4271 	else if (phba->sysfs_mbox.offset != off ||
4272 		 phba->sysfs_mbox.state  != SMBOX_READING) {
4273 		printk(KERN_WARNING  "mbox_read: Bad State\n");
4274 		sysfs_mbox_idle(phba);
4275 		spin_unlock_irq(&phba->hbalock);
4276 		return -EAGAIN;
4277 	}
4278 
4279 	memcpy(buf, (uint8_t *) &pmb + off, count);
4280 
4281 	phba->sysfs_mbox.offset = off + count;
4282 
4283 	if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
4284 		sysfs_mbox_idle(phba);
4285 
4286 	spin_unlock_irq(&phba->hbalock);
4287 
4288 	return count;
4289 }
4290 
4291 static struct bin_attribute sysfs_mbox_attr = {
4292 	.attr = {
4293 		.name = "mbox",
4294 		.mode = S_IRUSR | S_IWUSR,
4295 	},
4296 	.size = MAILBOX_SYSFS_MAX,
4297 	.read = sysfs_mbox_read,
4298 	.write = sysfs_mbox_write,
4299 };
4300 
4301 /**
4302  * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
4303  * @vport: address of lpfc vport structure.
4304  *
4305  * Return codes:
4306  * zero on success
4307  * error return code from sysfs_create_bin_file()
4308  **/
4309 int
4310 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
4311 {
4312 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4313 	int error;
4314 
4315 	error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4316 				      &sysfs_drvr_stat_data_attr);
4317 
4318 	/* Virtual ports do not need ctrl_reg and mbox */
4319 	if (error || vport->port_type == LPFC_NPIV_PORT)
4320 		goto out;
4321 
4322 	error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4323 				      &sysfs_ctlreg_attr);
4324 	if (error)
4325 		goto out_remove_stat_attr;
4326 
4327 	error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4328 				      &sysfs_mbox_attr);
4329 	if (error)
4330 		goto out_remove_ctlreg_attr;
4331 
4332 	return 0;
4333 out_remove_ctlreg_attr:
4334 	sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4335 out_remove_stat_attr:
4336 	sysfs_remove_bin_file(&shost->shost_dev.kobj,
4337 			&sysfs_drvr_stat_data_attr);
4338 out:
4339 	return error;
4340 }
4341 
4342 /**
4343  * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
4344  * @vport: address of lpfc vport structure.
4345  **/
4346 void
4347 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
4348 {
4349 	struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4350 	sysfs_remove_bin_file(&shost->shost_dev.kobj,
4351 		&sysfs_drvr_stat_data_attr);
4352 	/* Virtual ports do not need ctrl_reg and mbox */
4353 	if (vport->port_type == LPFC_NPIV_PORT)
4354 		return;
4355 	sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4356 	sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4357 }
4358 
4359 
4360 /*
4361  * Dynamic FC Host Attributes Support
4362  */
4363 
4364 /**
4365  * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4366  * @shost: kernel scsi host pointer.
4367  **/
4368 static void
4369 lpfc_get_host_port_id(struct Scsi_Host *shost)
4370 {
4371 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4372 
4373 	/* note: fc_myDID already in cpu endianness */
4374 	fc_host_port_id(shost) = vport->fc_myDID;
4375 }
4376 
4377 /**
4378  * lpfc_get_host_port_type - Set the value of the scsi host port type
4379  * @shost: kernel scsi host pointer.
4380  **/
4381 static void
4382 lpfc_get_host_port_type(struct Scsi_Host *shost)
4383 {
4384 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4385 	struct lpfc_hba   *phba = vport->phba;
4386 
4387 	spin_lock_irq(shost->host_lock);
4388 
4389 	if (vport->port_type == LPFC_NPIV_PORT) {
4390 		fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4391 	} else if (lpfc_is_link_up(phba)) {
4392 		if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4393 			if (vport->fc_flag & FC_PUBLIC_LOOP)
4394 				fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4395 			else
4396 				fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4397 		} else {
4398 			if (vport->fc_flag & FC_FABRIC)
4399 				fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4400 			else
4401 				fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4402 		}
4403 	} else
4404 		fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4405 
4406 	spin_unlock_irq(shost->host_lock);
4407 }
4408 
4409 /**
4410  * lpfc_get_host_port_state - Set the value of the scsi host port state
4411  * @shost: kernel scsi host pointer.
4412  **/
4413 static void
4414 lpfc_get_host_port_state(struct Scsi_Host *shost)
4415 {
4416 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4417 	struct lpfc_hba   *phba = vport->phba;
4418 
4419 	spin_lock_irq(shost->host_lock);
4420 
4421 	if (vport->fc_flag & FC_OFFLINE_MODE)
4422 		fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4423 	else {
4424 		switch (phba->link_state) {
4425 		case LPFC_LINK_UNKNOWN:
4426 		case LPFC_LINK_DOWN:
4427 			fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4428 			break;
4429 		case LPFC_LINK_UP:
4430 		case LPFC_CLEAR_LA:
4431 		case LPFC_HBA_READY:
4432 			/* Links up, beyond this port_type reports state */
4433 			fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4434 			break;
4435 		case LPFC_HBA_ERROR:
4436 			fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4437 			break;
4438 		default:
4439 			fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4440 			break;
4441 		}
4442 	}
4443 
4444 	spin_unlock_irq(shost->host_lock);
4445 }
4446 
4447 /**
4448  * lpfc_get_host_speed - Set the value of the scsi host speed
4449  * @shost: kernel scsi host pointer.
4450  **/
4451 static void
4452 lpfc_get_host_speed(struct Scsi_Host *shost)
4453 {
4454 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4455 	struct lpfc_hba   *phba = vport->phba;
4456 
4457 	spin_lock_irq(shost->host_lock);
4458 
4459 	if (lpfc_is_link_up(phba)) {
4460 		switch(phba->fc_linkspeed) {
4461 		case LPFC_LINK_SPEED_1GHZ:
4462 			fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4463 			break;
4464 		case LPFC_LINK_SPEED_2GHZ:
4465 			fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4466 			break;
4467 		case LPFC_LINK_SPEED_4GHZ:
4468 			fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4469 			break;
4470 		case LPFC_LINK_SPEED_8GHZ:
4471 			fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4472 			break;
4473 		case LPFC_LINK_SPEED_10GHZ:
4474 			fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4475 			break;
4476 		case LPFC_LINK_SPEED_16GHZ:
4477 			fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4478 			break;
4479 		default:
4480 			fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4481 			break;
4482 		}
4483 	} else
4484 		fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4485 
4486 	spin_unlock_irq(shost->host_lock);
4487 }
4488 
4489 /**
4490  * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4491  * @shost: kernel scsi host pointer.
4492  **/
4493 static void
4494 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4495 {
4496 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4497 	struct lpfc_hba   *phba = vport->phba;
4498 	u64 node_name;
4499 
4500 	spin_lock_irq(shost->host_lock);
4501 
4502 	if ((vport->port_state > LPFC_FLOGI) &&
4503 	    ((vport->fc_flag & FC_FABRIC) ||
4504 	     ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4505 	      (vport->fc_flag & FC_PUBLIC_LOOP))))
4506 		node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4507 	else
4508 		/* fabric is local port if there is no F/FL_Port */
4509 		node_name = 0;
4510 
4511 	spin_unlock_irq(shost->host_lock);
4512 
4513 	fc_host_fabric_name(shost) = node_name;
4514 }
4515 
4516 /**
4517  * lpfc_get_stats - Return statistical information about the adapter
4518  * @shost: kernel scsi host pointer.
4519  *
4520  * Notes:
4521  * NULL on error for link down, no mbox pool, sli2 active,
4522  * management not allowed, memory allocation error, or mbox error.
4523  *
4524  * Returns:
4525  * NULL for error
4526  * address of the adapter host statistics
4527  **/
4528 static struct fc_host_statistics *
4529 lpfc_get_stats(struct Scsi_Host *shost)
4530 {
4531 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4532 	struct lpfc_hba   *phba = vport->phba;
4533 	struct lpfc_sli   *psli = &phba->sli;
4534 	struct fc_host_statistics *hs = &phba->link_stats;
4535 	struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4536 	LPFC_MBOXQ_t *pmboxq;
4537 	MAILBOX_t *pmb;
4538 	unsigned long seconds;
4539 	int rc = 0;
4540 
4541 	/*
4542 	 * prevent udev from issuing mailbox commands until the port is
4543 	 * configured.
4544 	 */
4545 	if (phba->link_state < LPFC_LINK_DOWN ||
4546 	    !phba->mbox_mem_pool ||
4547 	    (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4548 		return NULL;
4549 
4550 	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4551 		return NULL;
4552 
4553 	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4554 	if (!pmboxq)
4555 		return NULL;
4556 	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4557 
4558 	pmb = &pmboxq->u.mb;
4559 	pmb->mbxCommand = MBX_READ_STATUS;
4560 	pmb->mbxOwner = OWN_HOST;
4561 	pmboxq->context1 = NULL;
4562 	pmboxq->vport = vport;
4563 
4564 	if (vport->fc_flag & FC_OFFLINE_MODE)
4565 		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4566 	else
4567 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4568 
4569 	if (rc != MBX_SUCCESS) {
4570 		if (rc != MBX_TIMEOUT)
4571 			mempool_free(pmboxq, phba->mbox_mem_pool);
4572 		return NULL;
4573 	}
4574 
4575 	memset(hs, 0, sizeof (struct fc_host_statistics));
4576 
4577 	hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4578 	/*
4579 	 * The MBX_READ_STATUS returns tx_k_bytes which has to
4580 	 * converted to words
4581 	 */
4582 	hs->tx_words = (uint64_t)
4583 			((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4584 			* (uint64_t)256);
4585 	hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4586 	hs->rx_words = (uint64_t)
4587 			((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4588 			 * (uint64_t)256);
4589 
4590 	memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4591 	pmb->mbxCommand = MBX_READ_LNK_STAT;
4592 	pmb->mbxOwner = OWN_HOST;
4593 	pmboxq->context1 = NULL;
4594 	pmboxq->vport = vport;
4595 
4596 	if (vport->fc_flag & FC_OFFLINE_MODE)
4597 		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4598 	else
4599 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4600 
4601 	if (rc != MBX_SUCCESS) {
4602 		if (rc != MBX_TIMEOUT)
4603 			mempool_free(pmboxq, phba->mbox_mem_pool);
4604 		return NULL;
4605 	}
4606 
4607 	hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4608 	hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4609 	hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4610 	hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4611 	hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4612 	hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4613 	hs->error_frames = pmb->un.varRdLnk.crcCnt;
4614 
4615 	hs->link_failure_count -= lso->link_failure_count;
4616 	hs->loss_of_sync_count -= lso->loss_of_sync_count;
4617 	hs->loss_of_signal_count -= lso->loss_of_signal_count;
4618 	hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4619 	hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4620 	hs->invalid_crc_count -= lso->invalid_crc_count;
4621 	hs->error_frames -= lso->error_frames;
4622 
4623 	if (phba->hba_flag & HBA_FCOE_MODE) {
4624 		hs->lip_count = -1;
4625 		hs->nos_count = (phba->link_events >> 1);
4626 		hs->nos_count -= lso->link_events;
4627 	} else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4628 		hs->lip_count = (phba->fc_eventTag >> 1);
4629 		hs->lip_count -= lso->link_events;
4630 		hs->nos_count = -1;
4631 	} else {
4632 		hs->lip_count = -1;
4633 		hs->nos_count = (phba->fc_eventTag >> 1);
4634 		hs->nos_count -= lso->link_events;
4635 	}
4636 
4637 	hs->dumped_frames = -1;
4638 
4639 	seconds = get_seconds();
4640 	if (seconds < psli->stats_start)
4641 		hs->seconds_since_last_reset = seconds +
4642 				((unsigned long)-1 - psli->stats_start);
4643 	else
4644 		hs->seconds_since_last_reset = seconds - psli->stats_start;
4645 
4646 	mempool_free(pmboxq, phba->mbox_mem_pool);
4647 
4648 	return hs;
4649 }
4650 
4651 /**
4652  * lpfc_reset_stats - Copy the adapter link stats information
4653  * @shost: kernel scsi host pointer.
4654  **/
4655 static void
4656 lpfc_reset_stats(struct Scsi_Host *shost)
4657 {
4658 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4659 	struct lpfc_hba   *phba = vport->phba;
4660 	struct lpfc_sli   *psli = &phba->sli;
4661 	struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4662 	LPFC_MBOXQ_t *pmboxq;
4663 	MAILBOX_t *pmb;
4664 	int rc = 0;
4665 
4666 	if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4667 		return;
4668 
4669 	pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4670 	if (!pmboxq)
4671 		return;
4672 	memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4673 
4674 	pmb = &pmboxq->u.mb;
4675 	pmb->mbxCommand = MBX_READ_STATUS;
4676 	pmb->mbxOwner = OWN_HOST;
4677 	pmb->un.varWords[0] = 0x1; /* reset request */
4678 	pmboxq->context1 = NULL;
4679 	pmboxq->vport = vport;
4680 
4681 	if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4682 		(!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4683 		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4684 	else
4685 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4686 
4687 	if (rc != MBX_SUCCESS) {
4688 		if (rc != MBX_TIMEOUT)
4689 			mempool_free(pmboxq, phba->mbox_mem_pool);
4690 		return;
4691 	}
4692 
4693 	memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4694 	pmb->mbxCommand = MBX_READ_LNK_STAT;
4695 	pmb->mbxOwner = OWN_HOST;
4696 	pmboxq->context1 = NULL;
4697 	pmboxq->vport = vport;
4698 
4699 	if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4700 	    (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4701 		rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4702 	else
4703 		rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4704 
4705 	if (rc != MBX_SUCCESS) {
4706 		if (rc != MBX_TIMEOUT)
4707 			mempool_free( pmboxq, phba->mbox_mem_pool);
4708 		return;
4709 	}
4710 
4711 	lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4712 	lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4713 	lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4714 	lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4715 	lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4716 	lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4717 	lso->error_frames = pmb->un.varRdLnk.crcCnt;
4718 	if (phba->hba_flag & HBA_FCOE_MODE)
4719 		lso->link_events = (phba->link_events >> 1);
4720 	else
4721 		lso->link_events = (phba->fc_eventTag >> 1);
4722 
4723 	psli->stats_start = get_seconds();
4724 
4725 	mempool_free(pmboxq, phba->mbox_mem_pool);
4726 
4727 	return;
4728 }
4729 
4730 /*
4731  * The LPFC driver treats linkdown handling as target loss events so there
4732  * are no sysfs handlers for link_down_tmo.
4733  */
4734 
4735 /**
4736  * lpfc_get_node_by_target - Return the nodelist for a target
4737  * @starget: kernel scsi target pointer.
4738  *
4739  * Returns:
4740  * address of the node list if found
4741  * NULL target not found
4742  **/
4743 static struct lpfc_nodelist *
4744 lpfc_get_node_by_target(struct scsi_target *starget)
4745 {
4746 	struct Scsi_Host  *shost = dev_to_shost(starget->dev.parent);
4747 	struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4748 	struct lpfc_nodelist *ndlp;
4749 
4750 	spin_lock_irq(shost->host_lock);
4751 	/* Search for this, mapped, target ID */
4752 	list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4753 		if (NLP_CHK_NODE_ACT(ndlp) &&
4754 		    ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4755 		    starget->id == ndlp->nlp_sid) {
4756 			spin_unlock_irq(shost->host_lock);
4757 			return ndlp;
4758 		}
4759 	}
4760 	spin_unlock_irq(shost->host_lock);
4761 	return NULL;
4762 }
4763 
4764 /**
4765  * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4766  * @starget: kernel scsi target pointer.
4767  **/
4768 static void
4769 lpfc_get_starget_port_id(struct scsi_target *starget)
4770 {
4771 	struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4772 
4773 	fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4774 }
4775 
4776 /**
4777  * lpfc_get_starget_node_name - Set the target node name
4778  * @starget: kernel scsi target pointer.
4779  *
4780  * Description: Set the target node name to the ndlp node name wwn or zero.
4781  **/
4782 static void
4783 lpfc_get_starget_node_name(struct scsi_target *starget)
4784 {
4785 	struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4786 
4787 	fc_starget_node_name(starget) =
4788 		ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4789 }
4790 
4791 /**
4792  * lpfc_get_starget_port_name - Set the target port name
4793  * @starget: kernel scsi target pointer.
4794  *
4795  * Description:  set the target port name to the ndlp port name wwn or zero.
4796  **/
4797 static void
4798 lpfc_get_starget_port_name(struct scsi_target *starget)
4799 {
4800 	struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4801 
4802 	fc_starget_port_name(starget) =
4803 		ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4804 }
4805 
4806 /**
4807  * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4808  * @rport: fc rport address.
4809  * @timeout: new value for dev loss tmo.
4810  *
4811  * Description:
4812  * If timeout is non zero set the dev_loss_tmo to timeout, else set
4813  * dev_loss_tmo to one.
4814  **/
4815 static void
4816 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4817 {
4818 	if (timeout)
4819 		rport->dev_loss_tmo = timeout;
4820 	else
4821 		rport->dev_loss_tmo = 1;
4822 }
4823 
4824 /**
4825  * lpfc_rport_show_function - Return rport target information
4826  *
4827  * Description:
4828  * Macro that uses field to generate a function with the name lpfc_show_rport_
4829  *
4830  * lpfc_show_rport_##field: returns the bytes formatted in buf
4831  * @cdev: class converted to an fc_rport.
4832  * @buf: on return contains the target_field or zero.
4833  *
4834  * Returns: size of formatted string.
4835  **/
4836 #define lpfc_rport_show_function(field, format_string, sz, cast)	\
4837 static ssize_t								\
4838 lpfc_show_rport_##field (struct device *dev,				\
4839 			 struct device_attribute *attr,			\
4840 			 char *buf)					\
4841 {									\
4842 	struct fc_rport *rport = transport_class_to_rport(dev);		\
4843 	struct lpfc_rport_data *rdata = rport->hostdata;		\
4844 	return snprintf(buf, sz, format_string,				\
4845 		(rdata->target) ? cast rdata->target->field : 0);	\
4846 }
4847 
4848 #define lpfc_rport_rd_attr(field, format_string, sz)			\
4849 	lpfc_rport_show_function(field, format_string, sz, )		\
4850 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4851 
4852 /**
4853  * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4854  * @fc_vport: The fc_vport who's symbolic name has been changed.
4855  *
4856  * Description:
4857  * This function is called by the transport after the @fc_vport's symbolic name
4858  * has been changed. This function re-registers the symbolic name with the
4859  * switch to propagate the change into the fabric if the vport is active.
4860  **/
4861 static void
4862 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4863 {
4864 	struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4865 
4866 	if (vport->port_state == LPFC_VPORT_READY)
4867 		lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4868 }
4869 
4870 /**
4871  * lpfc_hba_log_verbose_init - Set hba's log verbose level
4872  * @phba: Pointer to lpfc_hba struct.
4873  *
4874  * This function is called by the lpfc_get_cfgparam() routine to set the
4875  * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4876  * log message according to the module's lpfc_log_verbose parameter setting
4877  * before hba port or vport created.
4878  **/
4879 static void
4880 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4881 {
4882 	phba->cfg_log_verbose = verbose;
4883 }
4884 
4885 struct fc_function_template lpfc_transport_functions = {
4886 	/* fixed attributes the driver supports */
4887 	.show_host_node_name = 1,
4888 	.show_host_port_name = 1,
4889 	.show_host_supported_classes = 1,
4890 	.show_host_supported_fc4s = 1,
4891 	.show_host_supported_speeds = 1,
4892 	.show_host_maxframe_size = 1,
4893 	.show_host_symbolic_name = 1,
4894 
4895 	/* dynamic attributes the driver supports */
4896 	.get_host_port_id = lpfc_get_host_port_id,
4897 	.show_host_port_id = 1,
4898 
4899 	.get_host_port_type = lpfc_get_host_port_type,
4900 	.show_host_port_type = 1,
4901 
4902 	.get_host_port_state = lpfc_get_host_port_state,
4903 	.show_host_port_state = 1,
4904 
4905 	/* active_fc4s is shown but doesn't change (thus no get function) */
4906 	.show_host_active_fc4s = 1,
4907 
4908 	.get_host_speed = lpfc_get_host_speed,
4909 	.show_host_speed = 1,
4910 
4911 	.get_host_fabric_name = lpfc_get_host_fabric_name,
4912 	.show_host_fabric_name = 1,
4913 
4914 	/*
4915 	 * The LPFC driver treats linkdown handling as target loss events
4916 	 * so there are no sysfs handlers for link_down_tmo.
4917 	 */
4918 
4919 	.get_fc_host_stats = lpfc_get_stats,
4920 	.reset_fc_host_stats = lpfc_reset_stats,
4921 
4922 	.dd_fcrport_size = sizeof(struct lpfc_rport_data),
4923 	.show_rport_maxframe_size = 1,
4924 	.show_rport_supported_classes = 1,
4925 
4926 	.set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4927 	.show_rport_dev_loss_tmo = 1,
4928 
4929 	.get_starget_port_id  = lpfc_get_starget_port_id,
4930 	.show_starget_port_id = 1,
4931 
4932 	.get_starget_node_name = lpfc_get_starget_node_name,
4933 	.show_starget_node_name = 1,
4934 
4935 	.get_starget_port_name = lpfc_get_starget_port_name,
4936 	.show_starget_port_name = 1,
4937 
4938 	.issue_fc_host_lip = lpfc_issue_lip,
4939 	.dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4940 	.terminate_rport_io = lpfc_terminate_rport_io,
4941 
4942 	.dd_fcvport_size = sizeof(struct lpfc_vport *),
4943 
4944 	.vport_disable = lpfc_vport_disable,
4945 
4946 	.set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4947 
4948 	.bsg_request = lpfc_bsg_request,
4949 	.bsg_timeout = lpfc_bsg_timeout,
4950 };
4951 
4952 struct fc_function_template lpfc_vport_transport_functions = {
4953 	/* fixed attributes the driver supports */
4954 	.show_host_node_name = 1,
4955 	.show_host_port_name = 1,
4956 	.show_host_supported_classes = 1,
4957 	.show_host_supported_fc4s = 1,
4958 	.show_host_supported_speeds = 1,
4959 	.show_host_maxframe_size = 1,
4960 	.show_host_symbolic_name = 1,
4961 
4962 	/* dynamic attributes the driver supports */
4963 	.get_host_port_id = lpfc_get_host_port_id,
4964 	.show_host_port_id = 1,
4965 
4966 	.get_host_port_type = lpfc_get_host_port_type,
4967 	.show_host_port_type = 1,
4968 
4969 	.get_host_port_state = lpfc_get_host_port_state,
4970 	.show_host_port_state = 1,
4971 
4972 	/* active_fc4s is shown but doesn't change (thus no get function) */
4973 	.show_host_active_fc4s = 1,
4974 
4975 	.get_host_speed = lpfc_get_host_speed,
4976 	.show_host_speed = 1,
4977 
4978 	.get_host_fabric_name = lpfc_get_host_fabric_name,
4979 	.show_host_fabric_name = 1,
4980 
4981 	/*
4982 	 * The LPFC driver treats linkdown handling as target loss events
4983 	 * so there are no sysfs handlers for link_down_tmo.
4984 	 */
4985 
4986 	.get_fc_host_stats = lpfc_get_stats,
4987 	.reset_fc_host_stats = lpfc_reset_stats,
4988 
4989 	.dd_fcrport_size = sizeof(struct lpfc_rport_data),
4990 	.show_rport_maxframe_size = 1,
4991 	.show_rport_supported_classes = 1,
4992 
4993 	.set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4994 	.show_rport_dev_loss_tmo = 1,
4995 
4996 	.get_starget_port_id  = lpfc_get_starget_port_id,
4997 	.show_starget_port_id = 1,
4998 
4999 	.get_starget_node_name = lpfc_get_starget_node_name,
5000 	.show_starget_node_name = 1,
5001 
5002 	.get_starget_port_name = lpfc_get_starget_port_name,
5003 	.show_starget_port_name = 1,
5004 
5005 	.dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5006 	.terminate_rport_io = lpfc_terminate_rport_io,
5007 
5008 	.vport_disable = lpfc_vport_disable,
5009 
5010 	.set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5011 };
5012 
5013 /**
5014  * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
5015  * @phba: lpfc_hba pointer.
5016  **/
5017 void
5018 lpfc_get_cfgparam(struct lpfc_hba *phba)
5019 {
5020 	lpfc_cr_delay_init(phba, lpfc_cr_delay);
5021 	lpfc_cr_count_init(phba, lpfc_cr_count);
5022 	lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
5023 	lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5024 	lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
5025 	lpfc_ack0_init(phba, lpfc_ack0);
5026 	lpfc_topology_init(phba, lpfc_topology);
5027 	lpfc_link_speed_init(phba, lpfc_link_speed);
5028 	lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
5029 	lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
5030 	lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
5031 	lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
5032 	lpfc_use_msi_init(phba, lpfc_use_msi);
5033 	lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5034 	lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5035 	lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
5036 	lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5037 	lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
5038 	lpfc_enable_bg_init(phba, lpfc_enable_bg);
5039 	if (phba->sli_rev == LPFC_SLI_REV4)
5040 		phba->cfg_poll = 0;
5041 	else
5042 	phba->cfg_poll = lpfc_poll;
5043 	phba->cfg_soft_wwnn = 0L;
5044 	phba->cfg_soft_wwpn = 0L;
5045 	lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
5046 	lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
5047 	lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
5048 	lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
5049 	lpfc_aer_support_init(phba, lpfc_aer_support);
5050 	lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
5051 	lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
5052 	lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
5053 	phba->cfg_enable_dss = 1;
5054 	return;
5055 }
5056 
5057 /**
5058  * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
5059  * @vport: lpfc_vport pointer.
5060  **/
5061 void
5062 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5063 {
5064 	lpfc_log_verbose_init(vport, lpfc_log_verbose);
5065 	lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
5066 	lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
5067 	lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5068 	lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5069 	lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5070 	lpfc_restrict_login_init(vport, lpfc_restrict_login);
5071 	lpfc_fcp_class_init(vport, lpfc_fcp_class);
5072 	lpfc_use_adisc_init(vport, lpfc_use_adisc);
5073 	lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
5074 	lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5075 	lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5076 	lpfc_max_luns_init(vport, lpfc_max_luns);
5077 	lpfc_scan_down_init(vport, lpfc_scan_down);
5078 	lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
5079 	return;
5080 }
5081