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