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