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