[SCSI] lpfc 8.2.8 : Add kernel-doc function headers
[safe/jmp/linux-2.6] / 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-2008 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
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_tcq.h>
31 #include <scsi/scsi_transport_fc.h>
32
33 #include "lpfc_hw.h"
34 #include "lpfc_sli.h"
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
37 #include "lpfc.h"
38 #include "lpfc_logmsg.h"
39 #include "lpfc_version.h"
40 #include "lpfc_compat.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43
44 #define LPFC_DEF_DEVLOSS_TMO 30
45 #define LPFC_MIN_DEVLOSS_TMO 1
46 #define LPFC_MAX_DEVLOSS_TMO 255
47
48 #define LPFC_MAX_LINK_SPEED 8
49 #define LPFC_LINK_SPEED_BITMAP 0x00000117
50 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
51
52 /**
53  * lpfc_jedec_to_ascii: Hex to ascii convertor according to JEDEC rules.
54  * @incr: integer to convert.
55  * @hdw: ascii string holding converted integer plus a string terminator.
56  *
57  * Description:
58  * JEDEC Joint Electron Device Engineering Council.
59  * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
60  * character string. The string is then terminated with a NULL in byte 9.
61  * Hex 0-9 becomes ascii '0' to '9'.
62  * Hex a-f becomes ascii '=' to 'B' capital B.
63  *
64  * Notes:
65  * Coded for 32 bit integers only.
66  **/
67 static void
68 lpfc_jedec_to_ascii(int incr, char hdw[])
69 {
70         int i, j;
71         for (i = 0; i < 8; i++) {
72                 j = (incr & 0xf);
73                 if (j <= 9)
74                         hdw[7 - i] = 0x30 +  j;
75                  else
76                         hdw[7 - i] = 0x61 + j - 10;
77                 incr = (incr >> 4);
78         }
79         hdw[8] = 0;
80         return;
81 }
82
83 /**
84  * lpfc_drvr_version_show: Return the Emulex driver string with version number.
85  * @dev: class unused variable.
86  * @attr: device attribute, not used.
87  * @buf: on return contains the module description text.
88  *
89  * Returns: size of formatted string.
90  **/
91 static ssize_t
92 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
93                        char *buf)
94 {
95         return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
96 }
97
98 /**
99  * lpfc_info_show: Return some pci info about the host in ascii.
100  * @dev: class converted to a Scsi_host structure.
101  * @attr: device attribute, not used.
102  * @buf: on return contains the formatted text from lpfc_info().
103  *
104  * Returns: size of formatted string.
105  **/
106 static ssize_t
107 lpfc_info_show(struct device *dev, struct device_attribute *attr,
108                char *buf)
109 {
110         struct Scsi_Host *host = class_to_shost(dev);
111
112         return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
113 }
114
115 /**
116  * lpfc_serialnum_show: Return the hba serial number in ascii.
117  * @dev: class converted to a Scsi_host structure.
118  * @attr: device attribute, not used.
119  * @buf: on return contains the formatted text serial number.
120  *
121  * Returns: size of formatted string.
122  **/
123 static ssize_t
124 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
125                     char *buf)
126 {
127         struct Scsi_Host  *shost = class_to_shost(dev);
128         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129         struct lpfc_hba   *phba = vport->phba;
130
131         return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
132 }
133
134 /**
135  * lpfc_temp_sensor_show: Return the temperature sensor level.
136  * @dev: class converted to a Scsi_host structure.
137  * @attr: device attribute, not used.
138  * @buf: on return contains the formatted support level.
139  *
140  * Description:
141  * Returns a number indicating the temperature sensor level currently
142  * supported, zero or one in ascii.
143  *
144  * Returns: size of formatted string.
145  **/
146 static ssize_t
147 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
148                       char *buf)
149 {
150         struct Scsi_Host *shost = class_to_shost(dev);
151         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
152         struct lpfc_hba   *phba = vport->phba;
153         return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
154 }
155
156 /**
157  * lpfc_modeldesc_show: Return the model description of the hba.
158  * @dev: class converted to a Scsi_host structure.
159  * @attr: device attribute, not used.
160  * @buf: on return contains the scsi vpd model description.
161  *
162  * Returns: size of formatted string.
163  **/
164 static ssize_t
165 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
166                     char *buf)
167 {
168         struct Scsi_Host  *shost = class_to_shost(dev);
169         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
170         struct lpfc_hba   *phba = vport->phba;
171
172         return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
173 }
174
175 /**
176  * lpfc_modelname_show: Return the model name of the hba.
177  * @dev: class converted to a Scsi_host structure.
178  * @attr: device attribute, not used.
179  * @buf: on return contains the scsi vpd model name.
180  *
181  * Returns: size of formatted string.
182  **/
183 static ssize_t
184 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
185                     char *buf)
186 {
187         struct Scsi_Host  *shost = class_to_shost(dev);
188         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
189         struct lpfc_hba   *phba = vport->phba;
190
191         return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
192 }
193
194 /**
195  * lpfc_programtype_show: Return the program type of the hba.
196  * @dev: class converted to a Scsi_host structure.
197  * @attr: device attribute, not used.
198  * @buf: on return contains the scsi vpd program type.
199  *
200  * Returns: size of formatted string.
201  **/
202 static ssize_t
203 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
204                       char *buf)
205 {
206         struct Scsi_Host  *shost = class_to_shost(dev);
207         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
208         struct lpfc_hba   *phba = vport->phba;
209
210         return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
211 }
212
213 /**
214  * lpfc_vportnum_show: Return the port number in ascii of the hba.
215  * @dev: class converted to a Scsi_host structure.
216  * @attr: device attribute, not used.
217  * @buf: on return contains scsi vpd program type.
218  *
219  * Returns: size of formatted string.
220  **/
221 static ssize_t
222 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
223                    char *buf)
224 {
225         struct Scsi_Host  *shost = class_to_shost(dev);
226         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
227         struct lpfc_hba   *phba = vport->phba;
228
229         return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
230 }
231
232 /**
233  * lpfc_fwrev_show: Return the firmware rev running in the hba.
234  * @dev: class converted to a Scsi_host structure.
235  * @attr: device attribute, not used.
236  * @buf: on return contains the scsi vpd program type.
237  *
238  * Returns: size of formatted string.
239  **/
240 static ssize_t
241 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
242                 char *buf)
243 {
244         struct Scsi_Host  *shost = class_to_shost(dev);
245         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
246         struct lpfc_hba   *phba = vport->phba;
247         char fwrev[32];
248
249         lpfc_decode_firmware_rev(phba, fwrev, 1);
250         return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
251 }
252
253 /**
254  * lpfc_hdw_show: Return the jedec information about the hba.
255  * @dev: class converted to a Scsi_host structure.
256  * @attr: device attribute, not used.
257  * @buf: on return contains the scsi vpd program type.
258  *
259  * Returns: size of formatted string.
260  **/
261 static ssize_t
262 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
263 {
264         char hdw[9];
265         struct Scsi_Host  *shost = class_to_shost(dev);
266         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
267         struct lpfc_hba   *phba = vport->phba;
268         lpfc_vpd_t *vp = &phba->vpd;
269
270         lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
271         return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
272 }
273
274 /**
275  * lpfc_option_rom_version_show: Return the adapter ROM FCode version.
276  * @dev: class converted to a Scsi_host structure.
277  * @attr: device attribute, not used.
278  * @buf: on return contains the ROM and FCode ascii strings.
279  *
280  * Returns: size of formatted string.
281  **/
282 static ssize_t
283 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
284                              char *buf)
285 {
286         struct Scsi_Host  *shost = class_to_shost(dev);
287         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288         struct lpfc_hba   *phba = vport->phba;
289
290         return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
291 }
292
293 /**
294  * lpfc_state_show: Return the link state of the port.
295  * @dev: class converted to a Scsi_host structure.
296  * @attr: device attribute, not used.
297  * @buf: on return contains text describing the state of the link.
298  *
299  * Notes:
300  * The switch statement has no default so zero will be returned.
301  *
302  * Returns: size of formatted string.
303  **/
304 static ssize_t
305 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
306                      char *buf)
307 {
308         struct Scsi_Host  *shost = class_to_shost(dev);
309         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
310         struct lpfc_hba   *phba = vport->phba;
311         int  len = 0;
312
313         switch (phba->link_state) {
314         case LPFC_LINK_UNKNOWN:
315         case LPFC_WARM_START:
316         case LPFC_INIT_START:
317         case LPFC_INIT_MBX_CMDS:
318         case LPFC_LINK_DOWN:
319         case LPFC_HBA_ERROR:
320                 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
321                 break;
322         case LPFC_LINK_UP:
323         case LPFC_CLEAR_LA:
324         case LPFC_HBA_READY:
325                 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
326
327                 switch (vport->port_state) {
328                 case LPFC_LOCAL_CFG_LINK:
329                         len += snprintf(buf + len, PAGE_SIZE-len,
330                                         "Configuring Link\n");
331                         break;
332                 case LPFC_FDISC:
333                 case LPFC_FLOGI:
334                 case LPFC_FABRIC_CFG_LINK:
335                 case LPFC_NS_REG:
336                 case LPFC_NS_QRY:
337                 case LPFC_BUILD_DISC_LIST:
338                 case LPFC_DISC_AUTH:
339                         len += snprintf(buf + len, PAGE_SIZE - len,
340                                         "Discovery\n");
341                         break;
342                 case LPFC_VPORT_READY:
343                         len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
344                         break;
345
346                 case LPFC_VPORT_FAILED:
347                         len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
348                         break;
349
350                 case LPFC_VPORT_UNKNOWN:
351                         len += snprintf(buf + len, PAGE_SIZE - len,
352                                         "Unknown\n");
353                         break;
354                 }
355
356                 if (phba->fc_topology == TOPOLOGY_LOOP) {
357                         if (vport->fc_flag & FC_PUBLIC_LOOP)
358                                 len += snprintf(buf + len, PAGE_SIZE-len,
359                                                 "   Public Loop\n");
360                         else
361                                 len += snprintf(buf + len, PAGE_SIZE-len,
362                                                 "   Private Loop\n");
363                 } else {
364                         if (vport->fc_flag & FC_FABRIC)
365                                 len += snprintf(buf + len, PAGE_SIZE-len,
366                                                 "   Fabric\n");
367                         else
368                                 len += snprintf(buf + len, PAGE_SIZE-len,
369                                                 "   Point-2-Point\n");
370                 }
371         }
372
373         return len;
374 }
375
376 /**
377  * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports.
378  * @dev: class device that is converted into a Scsi_host.
379  * @attr: device attribute, not used.
380  * @buf: on return contains the sum of fc mapped and unmapped.
381  *
382  * Description:
383  * Returns the ascii text number of the sum of the fc mapped and unmapped
384  * vport counts.
385  *
386  * Returns: size of formatted string.
387  **/
388 static ssize_t
389 lpfc_num_discovered_ports_show(struct device *dev,
390                                struct device_attribute *attr, char *buf)
391 {
392         struct Scsi_Host  *shost = class_to_shost(dev);
393         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394
395         return snprintf(buf, PAGE_SIZE, "%d\n",
396                         vport->fc_map_cnt + vport->fc_unmap_cnt);
397 }
398
399 /**
400  * lpfc_issue_lip: Misnomer, name carried over from long ago.
401  * @shost: Scsi_Host pointer.
402  *
403  * Description:
404  * Bring the link down gracefully then re-init the link. The firmware will
405  * re-init the fiber channel interface as required. Does not issue a LIP.
406  *
407  * Returns:
408  * -EPERM port offline or management commands are being blocked
409  * -ENOMEM cannot allocate memory for the mailbox command
410  * -EIO error sending the mailbox command
411  * zero for success
412  **/
413 static int
414 lpfc_issue_lip(struct Scsi_Host *shost)
415 {
416         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417         struct lpfc_hba   *phba = vport->phba;
418         LPFC_MBOXQ_t *pmboxq;
419         int mbxstatus = MBXERR_ERROR;
420
421         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
422             (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
423                 return -EPERM;
424
425         pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
426
427         if (!pmboxq)
428                 return -ENOMEM;
429
430         memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
431         pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
432         pmboxq->mb.mbxOwner = OWN_HOST;
433
434         mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
435
436         if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
437                 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
438                 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
439                                phba->cfg_link_speed);
440                 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
441                                                      phba->fc_ratov * 2);
442         }
443
444         lpfc_set_loopback_flag(phba);
445         if (mbxstatus != MBX_TIMEOUT)
446                 mempool_free(pmboxq, phba->mbox_mem_pool);
447
448         if (mbxstatus == MBXERR_ERROR)
449                 return -EIO;
450
451         return 0;
452 }
453
454 /**
455  * lpfc_do_offline: Issues a mailbox command to bring the link down.
456  * @phba: lpfc_hba pointer.
457  * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
458  *
459  * Notes:
460  * Assumes any error from lpfc_do_offline() will be negative.
461  * Can wait up to 5 seconds for the port ring buffers count
462  * to reach zero, prints a warning if it is not zero and continues.
463  * lpfc_workq_post_event() returns a non-zero return coce if call fails.
464  *
465  * Returns:
466  * -EIO error posting the event
467  * zero for success
468  **/
469 static int
470 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
471 {
472         struct completion online_compl;
473         struct lpfc_sli_ring *pring;
474         struct lpfc_sli *psli;
475         int status = 0;
476         int cnt = 0;
477         int i;
478
479         init_completion(&online_compl);
480         lpfc_workq_post_event(phba, &status, &online_compl,
481                               LPFC_EVT_OFFLINE_PREP);
482         wait_for_completion(&online_compl);
483
484         if (status != 0)
485                 return -EIO;
486
487         psli = &phba->sli;
488
489         /* Wait a little for things to settle down, but not
490          * long enough for dev loss timeout to expire.
491          */
492         for (i = 0; i < psli->num_rings; i++) {
493                 pring = &psli->ring[i];
494                 while (pring->txcmplq_cnt) {
495                         msleep(10);
496                         if (cnt++ > 500) {  /* 5 secs */
497                                 lpfc_printf_log(phba,
498                                         KERN_WARNING, LOG_INIT,
499                                         "0466 Outstanding IO when "
500                                         "bringing Adapter offline\n");
501                                 break;
502                         }
503                 }
504         }
505
506         init_completion(&online_compl);
507         lpfc_workq_post_event(phba, &status, &online_compl, type);
508         wait_for_completion(&online_compl);
509
510         if (status != 0)
511                 return -EIO;
512
513         return 0;
514 }
515
516 /**
517  * lpfc_selective_reset: Offline then onlines the port.
518  * @phba: lpfc_hba pointer.
519  *
520  * Description:
521  * If the port is configured to allow a reset then the hba is brought
522  * offline then online.
523  *
524  * Notes:
525  * Assumes any error from lpfc_do_offline() will be negative.
526  *
527  * Returns:
528  * lpfc_do_offline() return code if not zero
529  * -EIO reset not configured or error posting the event
530  * zero for success
531  **/
532 static int
533 lpfc_selective_reset(struct lpfc_hba *phba)
534 {
535         struct completion online_compl;
536         int status = 0;
537
538         if (!phba->cfg_enable_hba_reset)
539                 return -EIO;
540
541         status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
542
543         if (status != 0)
544                 return status;
545
546         init_completion(&online_compl);
547         lpfc_workq_post_event(phba, &status, &online_compl,
548                               LPFC_EVT_ONLINE);
549         wait_for_completion(&online_compl);
550
551         if (status != 0)
552                 return -EIO;
553
554         return 0;
555 }
556
557 /**
558  * lpfc_issue_reset: Selectively resets an adapter.
559  * @dev: class device that is converted into a Scsi_host.
560  * @attr: device attribute, not used.
561  * @buf: containing the string "selective".
562  * @count: unused variable.
563  *
564  * Description:
565  * If the buf contains the string "selective" then lpfc_selective_reset()
566  * is called to perform the reset.
567  *
568  * Notes:
569  * Assumes any error from lpfc_selective_reset() will be negative.
570  * If lpfc_selective_reset() returns zero then the length of the buffer
571  * is returned which indicates succcess
572  *
573  * Returns:
574  * -EINVAL if the buffer does not contain the string "selective"
575  * length of buf if lpfc-selective_reset() if the call succeeds
576  * return value of lpfc_selective_reset() if the call fails
577 **/
578 static ssize_t
579 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
580                  const char *buf, size_t count)
581 {
582         struct Scsi_Host  *shost = class_to_shost(dev);
583         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584         struct lpfc_hba   *phba = vport->phba;
585
586         int status = -EINVAL;
587
588         if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
589                 status = lpfc_selective_reset(phba);
590
591         if (status == 0)
592                 return strlen(buf);
593         else
594                 return status;
595 }
596
597 /**
598  * lpfc_nport_evt_cnt_show: Return the number of nport events.
599  * @dev: class device that is converted into a Scsi_host.
600  * @attr: device attribute, not used.
601  * @buf: on return contains the ascii number of nport events.
602  *
603  * Returns: size of formatted string.
604  **/
605 static ssize_t
606 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
607                         char *buf)
608 {
609         struct Scsi_Host  *shost = class_to_shost(dev);
610         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
611         struct lpfc_hba   *phba = vport->phba;
612
613         return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
614 }
615
616 /**
617  * lpfc_board_mode_show: Return the state of the board.
618  * @dev: class device that is converted into a Scsi_host.
619  * @attr: device attribute, not used.
620  * @buf: on return contains the state of the adapter.
621  *
622  * Returns: size of formatted string.
623  **/
624 static ssize_t
625 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
626                      char *buf)
627 {
628         struct Scsi_Host  *shost = class_to_shost(dev);
629         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
630         struct lpfc_hba   *phba = vport->phba;
631         char  * state;
632
633         if (phba->link_state == LPFC_HBA_ERROR)
634                 state = "error";
635         else if (phba->link_state == LPFC_WARM_START)
636                 state = "warm start";
637         else if (phba->link_state == LPFC_INIT_START)
638                 state = "offline";
639         else
640                 state = "online";
641
642         return snprintf(buf, PAGE_SIZE, "%s\n", state);
643 }
644
645 /**
646  * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state.
647  * @dev: class device that is converted into a Scsi_host.
648  * @attr: device attribute, not used.
649  * @buf: containing one of the strings "online", "offline", "warm" or "error".
650  * @count: unused variable.
651  *
652  * Returns:
653  * -EACCES if enable hba reset not enabled
654  * -EINVAL if the buffer does not contain a valid string (see above)
655  * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
656  * buf length greater than zero indicates success
657  **/
658 static ssize_t
659 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
660                       const char *buf, size_t count)
661 {
662         struct Scsi_Host  *shost = class_to_shost(dev);
663         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
664         struct lpfc_hba   *phba = vport->phba;
665         struct completion online_compl;
666         int status=0;
667
668         if (!phba->cfg_enable_hba_reset)
669                 return -EACCES;
670         init_completion(&online_compl);
671
672         if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
673                 lpfc_workq_post_event(phba, &status, &online_compl,
674                                       LPFC_EVT_ONLINE);
675                 wait_for_completion(&online_compl);
676         } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
677                 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
678         else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
679                 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
680         else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
681                 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
682         else
683                 return -EINVAL;
684
685         if (!status)
686                 return strlen(buf);
687         else
688                 return -EIO;
689 }
690
691 /**
692  * lpfc_get_hba_info: Return various bits of informaton about the adapter.
693  * @phba: pointer to the adapter structure.
694  * @mxri max xri count.
695  * @axri available xri count.
696  * @mrpi max rpi count.
697  * @arpi available rpi count.
698  * @mvpi max vpi count.
699  * @avpi available vpi count.
700  *
701  * Description:
702  * If an integer pointer for an count is not null then the value for the
703  * count is returned.
704  *
705  * Returns:
706  * zero on error
707  * one for success
708  **/
709 static int
710 lpfc_get_hba_info(struct lpfc_hba *phba,
711                   uint32_t *mxri, uint32_t *axri,
712                   uint32_t *mrpi, uint32_t *arpi,
713                   uint32_t *mvpi, uint32_t *avpi)
714 {
715         struct lpfc_sli   *psli = &phba->sli;
716         LPFC_MBOXQ_t *pmboxq;
717         MAILBOX_t *pmb;
718         int rc = 0;
719
720         /*
721          * prevent udev from issuing mailbox commands until the port is
722          * configured.
723          */
724         if (phba->link_state < LPFC_LINK_DOWN ||
725             !phba->mbox_mem_pool ||
726             (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
727                 return 0;
728
729         if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
730                 return 0;
731
732         pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
733         if (!pmboxq)
734                 return 0;
735         memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
736
737         pmb = &pmboxq->mb;
738         pmb->mbxCommand = MBX_READ_CONFIG;
739         pmb->mbxOwner = OWN_HOST;
740         pmboxq->context1 = NULL;
741
742         if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
743                 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
744                 rc = MBX_NOT_FINISHED;
745         else
746                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
747
748         if (rc != MBX_SUCCESS) {
749                 if (rc != MBX_TIMEOUT)
750                         mempool_free(pmboxq, phba->mbox_mem_pool);
751                 return 0;
752         }
753
754         if (mrpi)
755                 *mrpi = pmb->un.varRdConfig.max_rpi;
756         if (arpi)
757                 *arpi = pmb->un.varRdConfig.avail_rpi;
758         if (mxri)
759                 *mxri = pmb->un.varRdConfig.max_xri;
760         if (axri)
761                 *axri = pmb->un.varRdConfig.avail_xri;
762         if (mvpi)
763                 *mvpi = pmb->un.varRdConfig.max_vpi;
764         if (avpi)
765                 *avpi = pmb->un.varRdConfig.avail_vpi;
766
767         mempool_free(pmboxq, phba->mbox_mem_pool);
768         return 1;
769 }
770
771 /**
772  * lpfc_max_rpi_show: Return maximum rpi.
773  * @dev: class device that is converted into a Scsi_host.
774  * @attr: device attribute, not used.
775  * @buf: on return contains the maximum rpi count in decimal or "Unknown".
776  *
777  * Description:
778  * Calls lpfc_get_hba_info() asking for just the mrpi count.
779  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
780  * to "Unknown" and the buffer length is returned, therefore the caller
781  * must check for "Unknown" in the buffer to detect a failure.
782  *
783  * Returns: size of formatted string.
784  **/
785 static ssize_t
786 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
787                   char *buf)
788 {
789         struct Scsi_Host  *shost = class_to_shost(dev);
790         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
791         struct lpfc_hba   *phba = vport->phba;
792         uint32_t cnt;
793
794         if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
795                 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
796         return snprintf(buf, PAGE_SIZE, "Unknown\n");
797 }
798
799 /**
800  * lpfc_used_rpi_show: Return maximum rpi minus available rpi.
801  * @dev: class device that is converted into a Scsi_host.
802  * @attr: device attribute, not used.
803  * @buf: containing the used rpi count in decimal or "Unknown".
804  *
805  * Description:
806  * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
807  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
808  * to "Unknown" and the buffer length is returned, therefore the caller
809  * must check for "Unknown" in the buffer to detect a failure.
810  *
811  * Returns: size of formatted string.
812  **/
813 static ssize_t
814 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
815                    char *buf)
816 {
817         struct Scsi_Host  *shost = class_to_shost(dev);
818         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
819         struct lpfc_hba   *phba = vport->phba;
820         uint32_t cnt, acnt;
821
822         if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
823                 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
824         return snprintf(buf, PAGE_SIZE, "Unknown\n");
825 }
826
827 /**
828  * lpfc_max_xri_show: Return maximum xri.
829  * @dev: class device that is converted into a Scsi_host.
830  * @attr: device attribute, not used.
831  * @buf: on return contains the maximum xri count in decimal or "Unknown".
832  *
833  * Description:
834  * Calls lpfc_get_hba_info() asking for just the mrpi count.
835  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
836  * to "Unknown" and the buffer length is returned, therefore the caller
837  * must check for "Unknown" in the buffer to detect a failure.
838  *
839  * Returns: size of formatted string.
840  **/
841 static ssize_t
842 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
843                   char *buf)
844 {
845         struct Scsi_Host  *shost = class_to_shost(dev);
846         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
847         struct lpfc_hba   *phba = vport->phba;
848         uint32_t cnt;
849
850         if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
851                 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
852         return snprintf(buf, PAGE_SIZE, "Unknown\n");
853 }
854
855 /**
856  * lpfc_used_xri_show: Return maximum xpi minus the available xpi.
857  * @dev: class device that is converted into a Scsi_host.
858  * @attr: device attribute, not used.
859  * @buf: on return contains the used xri count in decimal or "Unknown".
860  *
861  * Description:
862  * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
863  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
864  * to "Unknown" and the buffer length is returned, therefore the caller
865  * must check for "Unknown" in the buffer to detect a failure.
866  *
867  * Returns: size of formatted string.
868  **/
869 static ssize_t
870 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
871                    char *buf)
872 {
873         struct Scsi_Host  *shost = class_to_shost(dev);
874         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
875         struct lpfc_hba   *phba = vport->phba;
876         uint32_t cnt, acnt;
877
878         if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
879                 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
880         return snprintf(buf, PAGE_SIZE, "Unknown\n");
881 }
882
883 /**
884  * lpfc_max_vpi_show: Return maximum vpi.
885  * @dev: class device that is converted into a Scsi_host.
886  * @attr: device attribute, not used.
887  * @buf: on return contains the maximum vpi count in decimal or "Unknown".
888  *
889  * Description:
890  * Calls lpfc_get_hba_info() asking for just the mvpi count.
891  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
892  * to "Unknown" and the buffer length is returned, therefore the caller
893  * must check for "Unknown" in the buffer to detect a failure.
894  *
895  * Returns: size of formatted string.
896  **/
897 static ssize_t
898 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
899                   char *buf)
900 {
901         struct Scsi_Host  *shost = class_to_shost(dev);
902         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
903         struct lpfc_hba   *phba = vport->phba;
904         uint32_t cnt;
905
906         if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
907                 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
908         return snprintf(buf, PAGE_SIZE, "Unknown\n");
909 }
910
911 /**
912  * lpfc_used_vpi_show: Return maximum vpi minus the available vpi.
913  * @dev: class device that is converted into a Scsi_host.
914  * @attr: device attribute, not used.
915  * @buf: on return contains the used vpi count in decimal or "Unknown".
916  *
917  * Description:
918  * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
919  * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
920  * to "Unknown" and the buffer length is returned, therefore the caller
921  * must check for "Unknown" in the buffer to detect a failure.
922  *
923  * Returns: size of formatted string.
924  **/
925 static ssize_t
926 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
927                    char *buf)
928 {
929         struct Scsi_Host  *shost = class_to_shost(dev);
930         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
931         struct lpfc_hba   *phba = vport->phba;
932         uint32_t cnt, acnt;
933
934         if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
935                 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
936         return snprintf(buf, PAGE_SIZE, "Unknown\n");
937 }
938
939 /**
940  * lpfc_npiv_info_show: Return text about NPIV support for the adapter.
941  * @dev: class device that is converted into a Scsi_host.
942  * @attr: device attribute, not used.
943  * @buf: text that must be interpreted to determine if npiv is supported.
944  *
945  * Description:
946  * Buffer will contain text indicating npiv is not suppoerted on the port,
947  * the port is an NPIV physical port, or it is an npiv virtual port with
948  * the id of the vport.
949  *
950  * Returns: size of formatted string.
951  **/
952 static ssize_t
953 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
954                     char *buf)
955 {
956         struct Scsi_Host  *shost = class_to_shost(dev);
957         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
958         struct lpfc_hba   *phba = vport->phba;
959
960         if (!(phba->max_vpi))
961                 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
962         if (vport->port_type == LPFC_PHYSICAL_PORT)
963                 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
964         return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
965 }
966
967 /**
968  * lpfc_poll_show: Return text about poll support for the adapter.
969  * @dev: class device that is converted into a Scsi_host.
970  * @attr: device attribute, not used.
971  * @buf: on return contains the cfg_poll in hex.
972  *
973  * Notes:
974  * cfg_poll should be a lpfc_polling_flags type.
975  *
976  * Returns: size of formatted string.
977  **/
978 static ssize_t
979 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
980                char *buf)
981 {
982         struct Scsi_Host  *shost = class_to_shost(dev);
983         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
984         struct lpfc_hba   *phba = vport->phba;
985
986         return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
987 }
988
989 /**
990  * lpfc_poll_store: Set the value of cfg_poll for the adapter.
991  * @dev: class device that is converted into a Scsi_host.
992  * @attr: device attribute, not used.
993  * @buf: one or more lpfc_polling_flags values.
994  * @count: not used.
995  *
996  * Notes:
997  * buf contents converted to integer and checked for a valid value.
998  *
999  * Returns:
1000  * -EINVAL if the buffer connot be converted or is out of range
1001  * length of the buf on success
1002  **/
1003 static ssize_t
1004 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1005                 const char *buf, size_t count)
1006 {
1007         struct Scsi_Host  *shost = class_to_shost(dev);
1008         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1009         struct lpfc_hba   *phba = vport->phba;
1010         uint32_t creg_val;
1011         uint32_t old_val;
1012         int val=0;
1013
1014         if (!isdigit(buf[0]))
1015                 return -EINVAL;
1016
1017         if (sscanf(buf, "%i", &val) != 1)
1018                 return -EINVAL;
1019
1020         if ((val & 0x3) != val)
1021                 return -EINVAL;
1022
1023         spin_lock_irq(&phba->hbalock);
1024
1025         old_val = phba->cfg_poll;
1026
1027         if (val & ENABLE_FCP_RING_POLLING) {
1028                 if ((val & DISABLE_FCP_RING_INT) &&
1029                     !(old_val & DISABLE_FCP_RING_INT)) {
1030                         creg_val = readl(phba->HCregaddr);
1031                         creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1032                         writel(creg_val, phba->HCregaddr);
1033                         readl(phba->HCregaddr); /* flush */
1034
1035                         lpfc_poll_start_timer(phba);
1036                 }
1037         } else if (val != 0x0) {
1038                 spin_unlock_irq(&phba->hbalock);
1039                 return -EINVAL;
1040         }
1041
1042         if (!(val & DISABLE_FCP_RING_INT) &&
1043             (old_val & DISABLE_FCP_RING_INT))
1044         {
1045                 spin_unlock_irq(&phba->hbalock);
1046                 del_timer(&phba->fcp_poll_timer);
1047                 spin_lock_irq(&phba->hbalock);
1048                 creg_val = readl(phba->HCregaddr);
1049                 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1050                 writel(creg_val, phba->HCregaddr);
1051                 readl(phba->HCregaddr); /* flush */
1052         }
1053
1054         phba->cfg_poll = val;
1055
1056         spin_unlock_irq(&phba->hbalock);
1057
1058         return strlen(buf);
1059 }
1060
1061 /**
1062  * lpfc_param_show: Return a cfg attribute value in decimal.
1063  *
1064  * Description:
1065  * Macro that given an attr e.g. hba_queue_depth expands
1066  * into a function with the name lpfc_hba_queue_depth_show.
1067  *
1068  * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1069  * @dev: class device that is converted into a Scsi_host.
1070  * @attr: device attribute, not used.
1071  * @buf: on return contains the attribute value in decimal.
1072  *
1073  * Returns: size of formatted string.
1074  **/
1075 #define lpfc_param_show(attr)   \
1076 static ssize_t \
1077 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1078                    char *buf) \
1079 { \
1080         struct Scsi_Host  *shost = class_to_shost(dev);\
1081         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1082         struct lpfc_hba   *phba = vport->phba;\
1083         int val = 0;\
1084         val = phba->cfg_##attr;\
1085         return snprintf(buf, PAGE_SIZE, "%d\n",\
1086                         phba->cfg_##attr);\
1087 }
1088
1089 /**
1090  * lpfc_param_hex_show: Return a cfg attribute value in hex.
1091  *
1092  * Description:
1093  * Macro that given an attr e.g. hba_queue_depth expands
1094  * into a function with the name lpfc_hba_queue_depth_show
1095  *
1096  * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1097  * @dev: class device that is converted into a Scsi_host.
1098  * @attr: device attribute, not used.
1099  * @buf: on return contains the attribute value in hexidecimal.
1100  *
1101  * Returns: size of formatted string.
1102  **/
1103 #define lpfc_param_hex_show(attr)       \
1104 static ssize_t \
1105 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1106                    char *buf) \
1107 { \
1108         struct Scsi_Host  *shost = class_to_shost(dev);\
1109         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1110         struct lpfc_hba   *phba = vport->phba;\
1111         int val = 0;\
1112         val = phba->cfg_##attr;\
1113         return snprintf(buf, PAGE_SIZE, "%#x\n",\
1114                         phba->cfg_##attr);\
1115 }
1116
1117 /**
1118  * lpfc_param_init: Intializes a cfg attribute.
1119  *
1120  * Description:
1121  * Macro that given an attr e.g. hba_queue_depth expands
1122  * into a function with the name lpfc_hba_queue_depth_init. The macro also
1123  * takes a default argument, a minimum and maximum argument.
1124  *
1125  * lpfc_##attr##_init: Initializes an attribute.
1126  * @phba: pointer the the adapter structure.
1127  * @val: integer attribute value.
1128  *
1129  * Validates the min and max values then sets the adapter config field
1130  * accordingly, or uses the default if out of range and prints an error message.
1131  *
1132  * Returns:
1133  * zero on success
1134  * -EINVAL if default used
1135  **/
1136 #define lpfc_param_init(attr, default, minval, maxval)  \
1137 static int \
1138 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1139 { \
1140         if (val >= minval && val <= maxval) {\
1141                 phba->cfg_##attr = val;\
1142                 return 0;\
1143         }\
1144         lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1145                         "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1146                         "allowed range is ["#minval", "#maxval"]\n", val); \
1147         phba->cfg_##attr = default;\
1148         return -EINVAL;\
1149 }
1150
1151 /**
1152  * lpfc_param_set: Set a cfg attribute value.
1153  *
1154  * Description:
1155  * Macro that given an attr e.g. hba_queue_depth expands
1156  * into a function with the name lpfc_hba_queue_depth_set
1157  *
1158  * lpfc_##attr##_set: Sets an attribute value.
1159  * @phba: pointer the the adapter structure.
1160  * @val: integer attribute value.
1161  *
1162  * Description:
1163  * Validates the min and max values then sets the
1164  * adapter config field if in the valid range. prints error message
1165  * and does not set the parameter if invalid.
1166  *
1167  * Returns:
1168  * zero on success
1169  * -EINVAL if val is invalid
1170  **/
1171 #define lpfc_param_set(attr, default, minval, maxval)   \
1172 static int \
1173 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1174 { \
1175         if (val >= minval && val <= maxval) {\
1176                 phba->cfg_##attr = val;\
1177                 return 0;\
1178         }\
1179         lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1180                         "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1181                         "allowed range is ["#minval", "#maxval"]\n", val); \
1182         return -EINVAL;\
1183 }
1184
1185 /**
1186  * lpfc_param_store: Set a vport attribute value.
1187  *
1188  * Description:
1189  * Macro that given an attr e.g. hba_queue_depth expands
1190  * into a function with the name lpfc_hba_queue_depth_store.
1191  *
1192  * lpfc_##attr##_store: Set an sttribute value.
1193  * @dev: class device that is converted into a Scsi_host.
1194  * @attr: device attribute, not used.
1195  * @buf: contains the attribute value in ascii.
1196  * @count: not used.
1197  *
1198  * Description:
1199  * Convert the ascii text number to an integer, then
1200  * use the lpfc_##attr##_set function to set the value.
1201  *
1202  * Returns:
1203  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1204  * length of buffer upon success.
1205  **/
1206 #define lpfc_param_store(attr)  \
1207 static ssize_t \
1208 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1209                     const char *buf, size_t count) \
1210 { \
1211         struct Scsi_Host  *shost = class_to_shost(dev);\
1212         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1213         struct lpfc_hba   *phba = vport->phba;\
1214         int val=0;\
1215         if (!isdigit(buf[0]))\
1216                 return -EINVAL;\
1217         if (sscanf(buf, "%i", &val) != 1)\
1218                 return -EINVAL;\
1219         if (lpfc_##attr##_set(phba, val) == 0) \
1220                 return strlen(buf);\
1221         else \
1222                 return -EINVAL;\
1223 }
1224
1225 /**
1226  * lpfc_vport_param_show: Return decimal formatted cfg attribute value.
1227  *
1228  * Description:
1229  * Macro that given an attr e.g. hba_queue_depth expands
1230  * into a function with the name lpfc_hba_queue_depth_show
1231  *
1232  * lpfc_##attr##_show: prints the attribute value in decimal.
1233  * @dev: class device that is converted into a Scsi_host.
1234  * @attr: device attribute, not used.
1235  * @buf: on return contains the attribute value in decimal.
1236  *
1237  * Returns: length of formatted string.
1238  **/
1239 #define lpfc_vport_param_show(attr)     \
1240 static ssize_t \
1241 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1242                    char *buf) \
1243 { \
1244         struct Scsi_Host  *shost = class_to_shost(dev);\
1245         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1246         int val = 0;\
1247         val = vport->cfg_##attr;\
1248         return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1249 }
1250
1251 /**
1252  * lpfc_vport_param_hex_show: Return hex formatted attribute value.
1253  *
1254  * Description:
1255  * Macro that given an attr e.g.
1256  * hba_queue_depth expands into a function with the name
1257  * lpfc_hba_queue_depth_show
1258  *
1259  * lpfc_##attr##_show: prints the attribute value in hexidecimal.
1260  * @dev: class device that is converted into a Scsi_host.
1261  * @attr: device attribute, not used.
1262  * @buf: on return contains the attribute value in hexidecimal.
1263  *
1264  * Returns: length of formatted string.
1265  **/
1266 #define lpfc_vport_param_hex_show(attr) \
1267 static ssize_t \
1268 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1269                    char *buf) \
1270 { \
1271         struct Scsi_Host  *shost = class_to_shost(dev);\
1272         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1273         int val = 0;\
1274         val = vport->cfg_##attr;\
1275         return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1276 }
1277
1278 /**
1279  * lpfc_vport_param_init: Initialize a vport cfg attribute.
1280  *
1281  * Description:
1282  * Macro that given an attr e.g. hba_queue_depth expands
1283  * into a function with the name lpfc_hba_queue_depth_init. The macro also
1284  * takes a default argument, a minimum and maximum argument.
1285  *
1286  * lpfc_##attr##_init: validates the min and max values then sets the
1287  * adapter config field accordingly, or uses the default if out of range
1288  * and prints an error message.
1289  * @phba: pointer the the adapter structure.
1290  * @val: integer attribute value.
1291  *
1292  * Returns:
1293  * zero on success
1294  * -EINVAL if default used
1295  **/
1296 #define lpfc_vport_param_init(attr, default, minval, maxval)    \
1297 static int \
1298 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1299 { \
1300         if (val >= minval && val <= maxval) {\
1301                 vport->cfg_##attr = val;\
1302                 return 0;\
1303         }\
1304         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1305                          "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1306                          "allowed range is ["#minval", "#maxval"]\n", val); \
1307         vport->cfg_##attr = default;\
1308         return -EINVAL;\
1309 }
1310
1311 /**
1312  * lpfc_vport_param_set: Set a vport cfg attribute.
1313  *
1314  * Description:
1315  * Macro that given an attr e.g. hba_queue_depth expands
1316  * into a function with the name lpfc_hba_queue_depth_set
1317  *
1318  * lpfc_##attr##_set: validates the min and max values then sets the
1319  * adapter config field if in the valid range. prints error message
1320  * and does not set the parameter if invalid.
1321  * @phba: pointer the the adapter structure.
1322  * @val:        integer attribute value.
1323  *
1324  * Returns:
1325  * zero on success
1326  * -EINVAL if val is invalid
1327  **/
1328 #define lpfc_vport_param_set(attr, default, minval, maxval)     \
1329 static int \
1330 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1331 { \
1332         if (val >= minval && val <= maxval) {\
1333                 vport->cfg_##attr = val;\
1334                 return 0;\
1335         }\
1336         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1337                          "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1338                          "allowed range is ["#minval", "#maxval"]\n", val); \
1339         return -EINVAL;\
1340 }
1341
1342 /**
1343  * lpfc_vport_param_store: Set a vport attribute.
1344  *
1345  * Description:
1346  * Macro that given an attr e.g. hba_queue_depth
1347  * expands into a function with the name lpfc_hba_queue_depth_store
1348  *
1349  * lpfc_##attr##_store: convert the ascii text number to an integer, then
1350  * use the lpfc_##attr##_set function to set the value.
1351  * @cdev: class device that is converted into a Scsi_host.
1352  * @buf:        contains the attribute value in decimal.
1353  * @count: not used.
1354  *
1355  * Returns:
1356  * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1357  * length of buffer upon success.
1358  **/
1359 #define lpfc_vport_param_store(attr)    \
1360 static ssize_t \
1361 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1362                     const char *buf, size_t count) \
1363 { \
1364         struct Scsi_Host  *shost = class_to_shost(dev);\
1365         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1366         int val=0;\
1367         if (!isdigit(buf[0]))\
1368                 return -EINVAL;\
1369         if (sscanf(buf, "%i", &val) != 1)\
1370                 return -EINVAL;\
1371         if (lpfc_##attr##_set(vport, val) == 0) \
1372                 return strlen(buf);\
1373         else \
1374                 return -EINVAL;\
1375 }
1376
1377
1378 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1379 static int lpfc_##name = defval;\
1380 module_param(lpfc_##name, int, 0);\
1381 MODULE_PARM_DESC(lpfc_##name, desc);\
1382 lpfc_param_init(name, defval, minval, maxval)
1383
1384 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1385 static int lpfc_##name = defval;\
1386 module_param(lpfc_##name, int, 0);\
1387 MODULE_PARM_DESC(lpfc_##name, desc);\
1388 lpfc_param_show(name)\
1389 lpfc_param_init(name, defval, minval, maxval)\
1390 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1391
1392 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1393 static int lpfc_##name = defval;\
1394 module_param(lpfc_##name, int, 0);\
1395 MODULE_PARM_DESC(lpfc_##name, desc);\
1396 lpfc_param_show(name)\
1397 lpfc_param_init(name, defval, minval, maxval)\
1398 lpfc_param_set(name, defval, minval, maxval)\
1399 lpfc_param_store(name)\
1400 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1401                    lpfc_##name##_show, lpfc_##name##_store)
1402
1403 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1404 static int lpfc_##name = defval;\
1405 module_param(lpfc_##name, int, 0);\
1406 MODULE_PARM_DESC(lpfc_##name, desc);\
1407 lpfc_param_hex_show(name)\
1408 lpfc_param_init(name, defval, minval, maxval)\
1409 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1410
1411 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1412 static int lpfc_##name = defval;\
1413 module_param(lpfc_##name, int, 0);\
1414 MODULE_PARM_DESC(lpfc_##name, desc);\
1415 lpfc_param_hex_show(name)\
1416 lpfc_param_init(name, defval, minval, maxval)\
1417 lpfc_param_set(name, defval, minval, maxval)\
1418 lpfc_param_store(name)\
1419 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1420                    lpfc_##name##_show, lpfc_##name##_store)
1421
1422 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1423 static int lpfc_##name = defval;\
1424 module_param(lpfc_##name, int, 0);\
1425 MODULE_PARM_DESC(lpfc_##name, desc);\
1426 lpfc_vport_param_init(name, defval, minval, maxval)
1427
1428 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1429 static int lpfc_##name = defval;\
1430 module_param(lpfc_##name, int, 0);\
1431 MODULE_PARM_DESC(lpfc_##name, desc);\
1432 lpfc_vport_param_show(name)\
1433 lpfc_vport_param_init(name, defval, minval, maxval)\
1434 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1435
1436 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1437 static int lpfc_##name = defval;\
1438 module_param(lpfc_##name, int, 0);\
1439 MODULE_PARM_DESC(lpfc_##name, desc);\
1440 lpfc_vport_param_show(name)\
1441 lpfc_vport_param_init(name, defval, minval, maxval)\
1442 lpfc_vport_param_set(name, defval, minval, maxval)\
1443 lpfc_vport_param_store(name)\
1444 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1445                    lpfc_##name##_show, lpfc_##name##_store)
1446
1447 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1448 static int lpfc_##name = defval;\
1449 module_param(lpfc_##name, int, 0);\
1450 MODULE_PARM_DESC(lpfc_##name, desc);\
1451 lpfc_vport_param_hex_show(name)\
1452 lpfc_vport_param_init(name, defval, minval, maxval)\
1453 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1454
1455 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1456 static int lpfc_##name = defval;\
1457 module_param(lpfc_##name, int, 0);\
1458 MODULE_PARM_DESC(lpfc_##name, desc);\
1459 lpfc_vport_param_hex_show(name)\
1460 lpfc_vport_param_init(name, defval, minval, maxval)\
1461 lpfc_vport_param_set(name, defval, minval, maxval)\
1462 lpfc_vport_param_store(name)\
1463 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1464                    lpfc_##name##_show, lpfc_##name##_store)
1465
1466 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1467 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1468 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1469 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1470 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1471 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1472 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1473 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1474 static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
1475 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1476                    lpfc_option_rom_version_show, NULL);
1477 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1478                    lpfc_num_discovered_ports_show, NULL);
1479 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1480 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1481 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1482                    lpfc_board_mode_show, lpfc_board_mode_store);
1483 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1484 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1485 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1486 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1487 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1488 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1489 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1490 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1491 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1492
1493
1494 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1495
1496 /**
1497  * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid.
1498  * @dev: class device that is converted into a Scsi_host.
1499  * @attr: device attribute, not used.
1500  * @buf: containing the string lpfc_soft_wwn_key.
1501  * @count: must be size of lpfc_soft_wwn_key.
1502  *
1503  * Returns:
1504  * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1505  * length of buf indicates success
1506  **/
1507 static ssize_t
1508 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1509                            const char *buf, size_t count)
1510 {
1511         struct Scsi_Host  *shost = class_to_shost(dev);
1512         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1513         struct lpfc_hba   *phba = vport->phba;
1514         unsigned int cnt = count;
1515
1516         /*
1517          * We're doing a simple sanity check for soft_wwpn setting.
1518          * We require that the user write a specific key to enable
1519          * the soft_wwpn attribute to be settable. Once the attribute
1520          * is written, the enable key resets. If further updates are
1521          * desired, the key must be written again to re-enable the
1522          * attribute.
1523          *
1524          * The "key" is not secret - it is a hardcoded string shown
1525          * here. The intent is to protect against the random user or
1526          * application that is just writing attributes.
1527          */
1528
1529         /* count may include a LF at end of string */
1530         if (buf[cnt-1] == '\n')
1531                 cnt--;
1532
1533         if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1534             (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1535                 return -EINVAL;
1536
1537         phba->soft_wwn_enable = 1;
1538         return count;
1539 }
1540 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1541                    lpfc_soft_wwn_enable_store);
1542
1543 /**
1544  * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter.
1545  * @dev: class device that is converted into a Scsi_host.
1546  * @attr: device attribute, not used.
1547  * @buf: on return contains the wwpn in hexidecimal.
1548  *
1549  * Returns: size of formatted string.
1550  **/
1551 static ssize_t
1552 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1553                     char *buf)
1554 {
1555         struct Scsi_Host  *shost = class_to_shost(dev);
1556         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1557         struct lpfc_hba   *phba = vport->phba;
1558
1559         return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1560                         (unsigned long long)phba->cfg_soft_wwpn);
1561 }
1562
1563 /**
1564  * lpfc_soft_wwpn_store: Set the ww port name of the adapter.
1565  * @dev class device that is converted into a Scsi_host.
1566  * @attr: device attribute, not used.
1567  * @buf: contains the wwpn in hexidecimal.
1568  * @count: number of wwpn bytes in buf
1569  *
1570  * Returns:
1571  * -EACCES hba reset not enabled, adapter over temp
1572  * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1573  * -EIO error taking adapter offline or online
1574  * value of count on success
1575  **/
1576 static ssize_t
1577 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1578                      const char *buf, size_t count)
1579 {
1580         struct Scsi_Host  *shost = class_to_shost(dev);
1581         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1582         struct lpfc_hba   *phba = vport->phba;
1583         struct completion online_compl;
1584         int stat1=0, stat2=0;
1585         unsigned int i, j, cnt=count;
1586         u8 wwpn[8];
1587
1588         if (!phba->cfg_enable_hba_reset)
1589                 return -EACCES;
1590         spin_lock_irq(&phba->hbalock);
1591         if (phba->over_temp_state == HBA_OVER_TEMP) {
1592                 spin_unlock_irq(&phba->hbalock);
1593                 return -EACCES;
1594         }
1595         spin_unlock_irq(&phba->hbalock);
1596         /* count may include a LF at end of string */
1597         if (buf[cnt-1] == '\n')
1598                 cnt--;
1599
1600         if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1601             ((cnt == 17) && (*buf++ != 'x')) ||
1602             ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1603                 return -EINVAL;
1604
1605         phba->soft_wwn_enable = 0;
1606
1607         memset(wwpn, 0, sizeof(wwpn));
1608
1609         /* Validate and store the new name */
1610         for (i=0, j=0; i < 16; i++) {
1611                 if ((*buf >= 'a') && (*buf <= 'f'))
1612                         j = ((j << 4) | ((*buf++ -'a') + 10));
1613                 else if ((*buf >= 'A') && (*buf <= 'F'))
1614                         j = ((j << 4) | ((*buf++ -'A') + 10));
1615                 else if ((*buf >= '0') && (*buf <= '9'))
1616                         j = ((j << 4) | (*buf++ -'0'));
1617                 else
1618                         return -EINVAL;
1619                 if (i % 2) {
1620                         wwpn[i/2] = j & 0xff;
1621                         j = 0;
1622                 }
1623         }
1624         phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1625         fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1626         if (phba->cfg_soft_wwnn)
1627                 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1628
1629         dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1630                    "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1631
1632         stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1633         if (stat1)
1634                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1635                                 "0463 lpfc_soft_wwpn attribute set failed to "
1636                                 "reinit adapter - %d\n", stat1);
1637         init_completion(&online_compl);
1638         lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1639         wait_for_completion(&online_compl);
1640         if (stat2)
1641                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1642                                 "0464 lpfc_soft_wwpn attribute set failed to "
1643                                 "reinit adapter - %d\n", stat2);
1644         return (stat1 || stat2) ? -EIO : count;
1645 }
1646 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1647                    lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1648
1649 /**
1650  * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter.
1651  * @dev: class device that is converted into a Scsi_host.
1652  * @attr: device attribute, not used.
1653  * @buf: on return contains the wwnn in hexidecimal.
1654  *
1655  * Returns: size of formatted string.
1656  **/
1657 static ssize_t
1658 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1659                     char *buf)
1660 {
1661         struct Scsi_Host *shost = class_to_shost(dev);
1662         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1663         return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1664                         (unsigned long long)phba->cfg_soft_wwnn);
1665 }
1666
1667 /**
1668  * lpfc_soft_wwnn_store: sets the ww node name of the adapter.
1669  * @cdev: class device that is converted into a Scsi_host.
1670  * @buf: contains the ww node name in hexidecimal.
1671  * @count: number of wwnn bytes in buf.
1672  *
1673  * Returns:
1674  * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1675  * value of count on success
1676  **/
1677 static ssize_t
1678 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1679                      const char *buf, size_t count)
1680 {
1681         struct Scsi_Host *shost = class_to_shost(dev);
1682         struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1683         unsigned int i, j, cnt=count;
1684         u8 wwnn[8];
1685
1686         /* count may include a LF at end of string */
1687         if (buf[cnt-1] == '\n')
1688                 cnt--;
1689
1690         if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1691             ((cnt == 17) && (*buf++ != 'x')) ||
1692             ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1693                 return -EINVAL;
1694
1695         /*
1696          * Allow wwnn to be set many times, as long as the enable is set.
1697          * However, once the wwpn is set, everything locks.
1698          */
1699
1700         memset(wwnn, 0, sizeof(wwnn));
1701
1702         /* Validate and store the new name */
1703         for (i=0, j=0; i < 16; i++) {
1704                 if ((*buf >= 'a') && (*buf <= 'f'))
1705                         j = ((j << 4) | ((*buf++ -'a') + 10));
1706                 else if ((*buf >= 'A') && (*buf <= 'F'))
1707                         j = ((j << 4) | ((*buf++ -'A') + 10));
1708                 else if ((*buf >= '0') && (*buf <= '9'))
1709                         j = ((j << 4) | (*buf++ -'0'));
1710                 else
1711                         return -EINVAL;
1712                 if (i % 2) {
1713                         wwnn[i/2] = j & 0xff;
1714                         j = 0;
1715                 }
1716         }
1717         phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1718
1719         dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1720                    "lpfc%d: soft_wwnn set. Value will take effect upon "
1721                    "setting of the soft_wwpn\n", phba->brd_no);
1722
1723         return count;
1724 }
1725 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1726                    lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1727
1728
1729 static int lpfc_poll = 0;
1730 module_param(lpfc_poll, int, 0);
1731 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1732                  " 0 - none,"
1733                  " 1 - poll with interrupts enabled"
1734                  " 3 - poll and disable FCP ring interrupts");
1735
1736 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1737                    lpfc_poll_show, lpfc_poll_store);
1738
1739 int  lpfc_sli_mode = 0;
1740 module_param(lpfc_sli_mode, int, 0);
1741 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1742                  " 0 - auto (SLI-3 if supported),"
1743                  " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1744                  " 3 - select SLI-3");
1745
1746 int lpfc_enable_npiv = 0;
1747 module_param(lpfc_enable_npiv, int, 0);
1748 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1749 lpfc_param_show(enable_npiv);
1750 lpfc_param_init(enable_npiv, 0, 0, 1);
1751 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1752                          lpfc_enable_npiv_show, NULL);
1753
1754 /*
1755 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1756 # until the timer expires. Value range is [0,255]. Default value is 30.
1757 */
1758 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1759 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1760 module_param(lpfc_nodev_tmo, int, 0);
1761 MODULE_PARM_DESC(lpfc_nodev_tmo,
1762                  "Seconds driver will hold I/O waiting "
1763                  "for a device to come back");
1764
1765 /**
1766  * lpfc_nodev_tmo_show: Return the hba dev loss timeout value.
1767  * @dev: class converted to a Scsi_host structure.
1768  * @attr: device attribute, not used.
1769  * @buf: on return contains the dev loss timeout in decimal.
1770  *
1771  * Returns: size of formatted string.
1772  **/
1773 static ssize_t
1774 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1775                     char *buf)
1776 {
1777         struct Scsi_Host  *shost = class_to_shost(dev);
1778         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1779         int val = 0;
1780         val = vport->cfg_devloss_tmo;
1781         return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
1782 }
1783
1784 /**
1785  * lpfc_nodev_tmo_init: Set the hba nodev timeout value.
1786  * @vport: lpfc vport structure pointer.
1787  * @val: contains the nodev timeout value.
1788  *
1789  * Description:
1790  * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1791  * a kernel error message is printed and zero is returned.
1792  * Else if val is in range then nodev tmo and devloss tmo are set to val.
1793  * Otherwise nodev tmo is set to the default value.
1794  *
1795  * Returns:
1796  * zero if already set or if val is in range
1797  * -EINVAL val out of range
1798  **/
1799 static int
1800 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1801 {
1802         if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1803                 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1804                 if (val != LPFC_DEF_DEVLOSS_TMO)
1805                         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1806                                          "0402 Ignoring nodev_tmo module "
1807                                          "parameter because devloss_tmo is "
1808                                          "set.\n");
1809                 return 0;
1810         }
1811
1812         if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1813                 vport->cfg_nodev_tmo = val;
1814                 vport->cfg_devloss_tmo = val;
1815                 return 0;
1816         }
1817         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1818                          "0400 lpfc_nodev_tmo attribute cannot be set to"
1819                          " %d, allowed range is [%d, %d]\n",
1820                          val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1821         vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1822         return -EINVAL;
1823 }
1824
1825 /**
1826  * lpfc_update_rport_devloss_tmo: Update dev loss tmo value.
1827  * @vport: lpfc vport structure pointer.
1828  *
1829  * Description:
1830  * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1831  **/
1832 static void
1833 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
1834 {
1835         struct Scsi_Host  *shost;
1836         struct lpfc_nodelist  *ndlp;
1837
1838         shost = lpfc_shost_from_vport(vport);
1839         spin_lock_irq(shost->host_lock);
1840         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1841                 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
1842                         ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1843         spin_unlock_irq(shost->host_lock);
1844 }
1845
1846 /**
1847  * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values.
1848  * @vport: lpfc vport structure pointer.
1849  * @val: contains the tmo value.
1850  *
1851  * Description:
1852  * If the devloss tmo is already set or the vport dev loss tmo has changed
1853  * then a kernel error message is printed and zero is returned.
1854  * Else if val is in range then nodev tmo and devloss tmo are set to val.
1855  * Otherwise nodev tmo is set to the default value.
1856  *
1857  * Returns:
1858  * zero if already set or if val is in range
1859  * -EINVAL val out of range
1860  **/
1861 static int
1862 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
1863 {
1864         if (vport->dev_loss_tmo_changed ||
1865             (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
1866                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1867                                  "0401 Ignoring change to nodev_tmo "
1868                                  "because devloss_tmo is set.\n");
1869                 return 0;
1870         }
1871         if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1872                 vport->cfg_nodev_tmo = val;
1873                 vport->cfg_devloss_tmo = val;
1874                 lpfc_update_rport_devloss_tmo(vport);
1875                 return 0;
1876         }
1877         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1878                          "0403 lpfc_nodev_tmo attribute cannot be set to"
1879                          "%d, allowed range is [%d, %d]\n",
1880                          val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1881         return -EINVAL;
1882 }
1883
1884 lpfc_vport_param_store(nodev_tmo)
1885
1886 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1887                    lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1888
1889 /*
1890 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1891 # disappear until the timer expires. Value range is [0,255]. Default
1892 # value is 30.
1893 */
1894 module_param(lpfc_devloss_tmo, int, 0);
1895 MODULE_PARM_DESC(lpfc_devloss_tmo,
1896                  "Seconds driver will hold I/O waiting "
1897                  "for a device to come back");
1898 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1899                       LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1900 lpfc_vport_param_show(devloss_tmo)
1901
1902 /**
1903  * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit.
1904  * @vport: lpfc vport structure pointer.
1905  * @val: contains the tmo value.
1906  *
1907  * Description:
1908  * If val is in a valid range then set the vport nodev tmo,
1909  * devloss tmo, also set the vport dev loss tmo changed flag.
1910  * Else a kernel error message is printed.
1911  *
1912  * Returns:
1913  * zero if val is in range
1914  * -EINVAL val out of range
1915  **/
1916 static int
1917 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
1918 {
1919         if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1920                 vport->cfg_nodev_tmo = val;
1921                 vport->cfg_devloss_tmo = val;
1922                 vport->dev_loss_tmo_changed = 1;
1923                 lpfc_update_rport_devloss_tmo(vport);
1924                 return 0;
1925         }
1926
1927         lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1928                          "0404 lpfc_devloss_tmo attribute cannot be set to"
1929                          " %d, allowed range is [%d, %d]\n",
1930                          val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1931         return -EINVAL;
1932 }
1933
1934 lpfc_vport_param_store(devloss_tmo)
1935 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1936                    lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1937
1938 /*
1939 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1940 # deluged with LOTS of information.
1941 # You can set a bit mask to record specific types of verbose messages:
1942 #
1943 # LOG_ELS                       0x1        ELS events
1944 # LOG_DISCOVERY                 0x2        Link discovery events
1945 # LOG_MBOX                      0x4        Mailbox events
1946 # LOG_INIT                      0x8        Initialization events
1947 # LOG_LINK_EVENT                0x10       Link events
1948 # LOG_FCP                       0x40       FCP traffic history
1949 # LOG_NODE                      0x80       Node table events
1950 # LOG_MISC                      0x400      Miscellaneous events
1951 # LOG_SLI                       0x800      SLI events
1952 # LOG_FCP_ERROR                 0x1000     Only log FCP errors
1953 # LOG_LIBDFC                    0x2000     LIBDFC events
1954 # LOG_ALL_MSG                   0xffff     LOG all messages
1955 */
1956 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1957                        "Verbose logging bit-mask");
1958
1959 /*
1960 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1961 # objects that have been registered with the nameserver after login.
1962 */
1963 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1964                   "Deregister nameserver objects before LOGO");
1965
1966 /*
1967 # lun_queue_depth:  This parameter is used to limit the number of outstanding
1968 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
1969 */
1970 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1971                   "Max number of FCP commands we can queue to a specific LUN");
1972
1973 /*
1974 # hba_queue_depth:  This parameter is used to limit the number of outstanding
1975 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
1976 # value is greater than the maximum number of exchanges supported by the HBA,
1977 # then maximum number of exchanges supported by the HBA is used to determine
1978 # the hba_queue_depth.
1979 */
1980 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1981             "Max number of FCP commands we can queue to a lpfc HBA");
1982
1983 /*
1984 # peer_port_login:  This parameter allows/prevents logins
1985 # between peer ports hosted on the same physical port.
1986 # When this parameter is set 0 peer ports of same physical port
1987 # are not allowed to login to each other.
1988 # When this parameter is set 1 peer ports of same physical port
1989 # are allowed to login to each other.
1990 # Default value of this parameter is 0.
1991 */
1992 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1993                   "Allow peer ports on the same physical port to login to each "
1994                   "other.");
1995
1996 /*
1997 # restrict_login:  This parameter allows/prevents logins
1998 # between Virtual Ports and remote initiators.
1999 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2000 # other initiators and will attempt to PLOGI all remote ports.
2001 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2002 # remote ports and will not attempt to PLOGI to other initiators.
2003 # This parameter does not restrict to the physical port.
2004 # This parameter does not restrict logins to Fabric resident remote ports.
2005 # Default value of this parameter is 1.
2006 */
2007 static int lpfc_restrict_login = 1;
2008 module_param(lpfc_restrict_login, int, 0);
2009 MODULE_PARM_DESC(lpfc_restrict_login,
2010                  "Restrict virtual ports login to remote initiators.");
2011 lpfc_vport_param_show(restrict_login);
2012
2013 /**
2014  * lpfc_restrict_login_init: Set the vport restrict login flag.
2015  * @vport: lpfc vport structure pointer.
2016  * @val: contains the restrict login value.
2017  *
2018  * Description:
2019  * If val is not in a valid range then log a kernel error message and set
2020  * the vport restrict login to one.
2021  * If the port type is physical clear the restrict login flag and return.
2022  * Else set the restrict login flag to val.
2023  *
2024  * Returns:
2025  * zero if val is in range
2026  * -EINVAL val out of range
2027  **/
2028 static int
2029 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2030 {
2031         if (val < 0 || val > 1) {
2032                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2033                                  "0449 lpfc_restrict_login attribute cannot "
2034                                  "be set to %d, allowed range is [0, 1]\n",
2035                                  val);
2036                 vport->cfg_restrict_login = 1;
2037                 return -EINVAL;
2038         }
2039         if (vport->port_type == LPFC_PHYSICAL_PORT) {
2040                 vport->cfg_restrict_login = 0;
2041                 return 0;
2042         }
2043         vport->cfg_restrict_login = val;
2044         return 0;
2045 }
2046
2047 /**
2048  * lpfc_restrict_login_set: Set the vport restrict login flag.
2049  * @vport: lpfc vport structure pointer.
2050  * @val: contains the restrict login value.
2051  *
2052  * Description:
2053  * If val is not in a valid range then log a kernel error message and set
2054  * the vport restrict login to one.
2055  * If the port type is physical and the val is not zero log a kernel
2056  * error message, clear the restrict login flag and return zero.
2057  * Else set the restrict login flag to val.
2058  *
2059  * Returns:
2060  * zero if val is in range
2061  * -EINVAL val out of range
2062  **/
2063 static int
2064 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2065 {
2066         if (val < 0 || val > 1) {
2067                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2068                                  "0450 lpfc_restrict_login attribute cannot "
2069                                  "be set to %d, allowed range is [0, 1]\n",
2070                                  val);
2071                 vport->cfg_restrict_login = 1;
2072                 return -EINVAL;
2073         }
2074         if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2075                 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2076                                  "0468 lpfc_restrict_login must be 0 for "
2077                                  "Physical ports.\n");
2078                 vport->cfg_restrict_login = 0;
2079                 return 0;
2080         }
2081         vport->cfg_restrict_login = val;
2082         return 0;
2083 }
2084 lpfc_vport_param_store(restrict_login);
2085 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2086                    lpfc_restrict_login_show, lpfc_restrict_login_store);
2087
2088 /*
2089 # Some disk devices have a "select ID" or "select Target" capability.
2090 # From a protocol standpoint "select ID" usually means select the
2091 # Fibre channel "ALPA".  In the FC-AL Profile there is an "informative
2092 # annex" which contains a table that maps a "select ID" (a number
2093 # between 0 and 7F) to an ALPA.  By default, for compatibility with
2094 # older drivers, the lpfc driver scans this table from low ALPA to high
2095 # ALPA.
2096 #
2097 # Turning on the scan-down variable (on  = 1, off = 0) will
2098 # cause the lpfc driver to use an inverted table, effectively
2099 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2100 #
2101 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2102 # and will not work across a fabric. Also this parameter will take
2103 # effect only in the case when ALPA map is not available.)
2104 */
2105 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2106                   "Start scanning for devices from highest ALPA to lowest");
2107
2108 /*
2109 # lpfc_topology:  link topology for init link
2110 #            0x0  = attempt loop mode then point-to-point
2111 #            0x01 = internal loopback mode
2112 #            0x02 = attempt point-to-point mode only
2113 #            0x04 = attempt loop mode only
2114 #            0x06 = attempt point-to-point mode then loop
2115 # Set point-to-point mode if you want to run as an N_Port.
2116 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2117 # Default value is 0.
2118 */
2119
2120 /**
2121  * lpfc_topology_set: Set the adapters topology field.
2122  * @phba: lpfc_hba pointer.
2123  * @val: topology value.
2124  *
2125  * Description:
2126  * If val is in a valid range then set the adapter's topology field and
2127  * issue a lip; if the lip fails reset the topology to the old value.
2128  *
2129  * If the value is not in range log a kernel error message and return an error.
2130  *
2131  * Returns:
2132  * zero if val is in range and lip okay
2133  * non-zero return value from lpfc_issue_lip()
2134  * -EINVAL val out of range
2135  **/
2136 static int
2137 lpfc_topology_set(struct lpfc_hba *phba, int val)
2138 {
2139         int err;
2140         uint32_t prev_val;
2141         if (val >= 0 && val <= 6) {
2142                 prev_val = phba->cfg_topology;
2143                 phba->cfg_topology = val;
2144                 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2145                 if (err)
2146                         phba->cfg_topology = prev_val;
2147                 return err;
2148         }
2149         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2150                 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2151                 "allowed range is [0, 6]\n",
2152                 phba->brd_no, val);
2153         return -EINVAL;
2154 }
2155 static int lpfc_topology = 0;
2156 module_param(lpfc_topology, int, 0);
2157 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2158 lpfc_param_show(topology)
2159 lpfc_param_init(topology, 0, 0, 6)
2160 lpfc_param_store(topology)
2161 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2162                 lpfc_topology_show, lpfc_topology_store);
2163
2164 /*
2165 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2166 # connection.
2167 #       0  = auto select (default)
2168 #       1  = 1 Gigabaud
2169 #       2  = 2 Gigabaud
2170 #       4  = 4 Gigabaud
2171 #       8  = 8 Gigabaud
2172 # Value range is [0,8]. Default value is 0.
2173 */
2174
2175 /**
2176  * lpfc_link_speed_set: Set the adapters link speed.
2177  * @phba: lpfc_hba pointer.
2178  * @val: link speed value.
2179  *
2180  * Description:
2181  * If val is in a valid range then set the adapter's link speed field and
2182  * issue a lip; if the lip fails reset the link speed to the old value.
2183  *
2184  * Notes:
2185  * If the value is not in range log a kernel error message and return an error.
2186  *
2187  * Returns:
2188  * zero if val is in range and lip okay.
2189  * non-zero return value from lpfc_issue_lip()
2190  * -EINVAL val out of range
2191  **/
2192 static int
2193 lpfc_link_speed_set(struct lpfc_hba *phba, int val)
2194 {
2195         int err;
2196         uint32_t prev_val;
2197
2198         if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2199                 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2200                 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2201                 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2202                 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2203                 return -EINVAL;
2204
2205         if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2206                 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2207                 prev_val = phba->cfg_link_speed;
2208                 phba->cfg_link_speed = val;
2209                 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2210                 if (err)
2211                         phba->cfg_link_speed = prev_val;
2212                 return err;
2213         }
2214
2215         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2216                 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2217                 "allowed range is [0, 8]\n",
2218                 phba->brd_no, val);
2219         return -EINVAL;
2220 }
2221
2222 static int lpfc_link_speed = 0;
2223 module_param(lpfc_link_speed, int, 0);
2224 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2225 lpfc_param_show(link_speed)
2226
2227 /**
2228  * lpfc_link_speed_init: Set the adapters link speed.
2229  * @phba: lpfc_hba pointer.
2230  * @val: link speed value.
2231  *
2232  * Description:
2233  * If val is in a valid range then set the adapter's link speed field.
2234  *
2235  * Notes:
2236  * If the value is not in range log a kernel error message, clear the link
2237  * speed and return an error.
2238  *
2239  * Returns:
2240  * zero if val saved.
2241  * -EINVAL val out of range
2242  **/
2243 static int
2244 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2245 {
2246         if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2247                 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2248                 phba->cfg_link_speed = val;
2249                 return 0;
2250         }
2251         lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2252                         "0454 lpfc_link_speed attribute cannot "
2253                         "be set to %d, allowed values are "
2254                         "["LPFC_LINK_SPEED_STRING"]\n", val);
2255         phba->cfg_link_speed = 0;
2256         return -EINVAL;
2257 }
2258
2259 lpfc_param_store(link_speed)
2260 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2261                 lpfc_link_speed_show, lpfc_link_speed_store);
2262
2263 /*
2264 # lpfc_fcp_class:  Determines FC class to use for the FCP protocol.
2265 # Value range is [2,3]. Default value is 3.
2266 */
2267 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2268                   "Select Fibre Channel class of service for FCP sequences");
2269
2270 /*
2271 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2272 # is [0,1]. Default value is 0.
2273 */
2274 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2275                    "Use ADISC on rediscovery to authenticate FCP devices");
2276
2277 /*
2278 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2279 # range is [0,1]. Default value is 0.
2280 */
2281 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2282
2283 /*
2284 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2285 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
2286 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
2287 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2288 # cr_delay is set to 0.
2289 */
2290 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
2291                 "interrupt response is generated");
2292
2293 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
2294                 "interrupt response is generated");
2295
2296 /*
2297 # lpfc_multi_ring_support:  Determines how many rings to spread available
2298 # cmd/rsp IOCB entries across.
2299 # Value range is [1,2]. Default value is 1.
2300 */
2301 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2302                 "SLI rings to spread IOCB entries across");
2303
2304 /*
2305 # lpfc_multi_ring_rctl:  If lpfc_multi_ring_support is enabled, this
2306 # identifies what rctl value to configure the additional ring for.
2307 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2308 */
2309 LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
2310              255, "Identifies RCTL for additional ring configuration");
2311
2312 /*
2313 # lpfc_multi_ring_type:  If lpfc_multi_ring_support is enabled, this
2314 # identifies what type value to configure the additional ring for.
2315 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2316 */
2317 LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
2318              255, "Identifies TYPE for additional ring configuration");
2319
2320 /*
2321 # lpfc_fdmi_on: controls FDMI support.
2322 #       0 = no FDMI support
2323 #       1 = support FDMI without attribute of hostname
2324 #       2 = support FDMI with attribute of hostname
2325 # Value range [0,2]. Default value is 0.
2326 */
2327 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
2328
2329 /*
2330 # Specifies the maximum number of ELS cmds we can have outstanding (for
2331 # discovery). Value range is [1,64]. Default value = 32.
2332 */
2333 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
2334                  "during discovery");
2335
2336 /*
2337 # lpfc_max_luns: maximum allowed LUN.
2338 # Value range is [0,65535]. Default value is 255.
2339 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
2340 */
2341 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
2342
2343 /*
2344 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2345 # Value range is [1,255], default value is 10.
2346 */
2347 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2348              "Milliseconds driver will wait between polling FCP ring");
2349
2350 /*
2351 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2352 #               support this feature
2353 #       0  = MSI disabled (default)
2354 #       1  = MSI enabled
2355 #       2  = MSI-X enabled
2356 # Value range is [0,2]. Default value is 0.
2357 */
2358 LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
2359             "MSI-X (2), if possible");
2360
2361 /*
2362 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2363 #       0  = HBA resets disabled
2364 #       1  = HBA resets enabled (default)
2365 # Value range is [0,1]. Default value is 1.
2366 */
2367 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
2368
2369 /*
2370 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2371 #       0  = HBA Heartbeat disabled
2372 #       1  = HBA Heartbeat enabled (default)
2373 # Value range is [0,1]. Default value is 1.
2374 */
2375 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
2376
2377 /*
2378  * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
2379  * This value can be set to values between 64 and 256. The default value is
2380  * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2381  * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2382  */
2383 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2384             LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
2385
2386 struct device_attribute *lpfc_hba_attrs[] = {
2387         &dev_attr_info,
2388         &dev_attr_serialnum,
2389         &dev_attr_modeldesc,
2390         &dev_attr_modelname,
2391         &dev_attr_programtype,
2392         &dev_attr_portnum,
2393         &dev_attr_fwrev,
2394         &dev_attr_hdw,
2395         &dev_attr_option_rom_version,
2396         &dev_attr_link_state,
2397         &dev_attr_num_discovered_ports,
2398         &dev_attr_lpfc_drvr_version,
2399         &dev_attr_lpfc_temp_sensor,
2400         &dev_attr_lpfc_log_verbose,
2401         &dev_attr_lpfc_lun_queue_depth,
2402         &dev_attr_lpfc_hba_queue_depth,
2403         &dev_attr_lpfc_peer_port_login,
2404         &dev_attr_lpfc_nodev_tmo,
2405         &dev_attr_lpfc_devloss_tmo,
2406         &dev_attr_lpfc_fcp_class,
2407         &dev_attr_lpfc_use_adisc,
2408         &dev_attr_lpfc_ack0,
2409         &dev_attr_lpfc_topology,
2410         &dev_attr_lpfc_scan_down,
2411         &dev_attr_lpfc_link_speed,
2412         &dev_attr_lpfc_cr_delay,
2413         &dev_attr_lpfc_cr_count,
2414         &dev_attr_lpfc_multi_ring_support,
2415         &dev_attr_lpfc_multi_ring_rctl,
2416         &dev_attr_lpfc_multi_ring_type,
2417         &dev_attr_lpfc_fdmi_on,
2418         &dev_attr_lpfc_max_luns,
2419         &dev_attr_lpfc_enable_npiv,
2420         &dev_attr_nport_evt_cnt,
2421         &dev_attr_board_mode,
2422         &dev_attr_max_vpi,
2423         &dev_attr_used_vpi,
2424         &dev_attr_max_rpi,
2425         &dev_attr_used_rpi,
2426         &dev_attr_max_xri,
2427         &dev_attr_used_xri,
2428         &dev_attr_npiv_info,
2429         &dev_attr_issue_reset,
2430         &dev_attr_lpfc_poll,
2431         &dev_attr_lpfc_poll_tmo,
2432         &dev_attr_lpfc_use_msi,
2433         &dev_attr_lpfc_soft_wwnn,
2434         &dev_attr_lpfc_soft_wwpn,
2435         &dev_attr_lpfc_soft_wwn_enable,
2436         &dev_attr_lpfc_enable_hba_reset,
2437         &dev_attr_lpfc_enable_hba_heartbeat,
2438         &dev_attr_lpfc_sg_seg_cnt,
2439         NULL,
2440 };
2441
2442 struct device_attribute *lpfc_vport_attrs[] = {
2443         &dev_attr_info,
2444         &dev_attr_link_state,
2445         &dev_attr_num_discovered_ports,
2446         &dev_attr_lpfc_drvr_version,
2447         &dev_attr_lpfc_log_verbose,
2448         &dev_attr_lpfc_lun_queue_depth,
2449         &dev_attr_lpfc_nodev_tmo,
2450         &dev_attr_lpfc_devloss_tmo,
2451         &dev_attr_lpfc_hba_queue_depth,
2452         &dev_attr_lpfc_peer_port_login,
2453         &dev_attr_lpfc_restrict_login,
2454         &dev_attr_lpfc_fcp_class,
2455         &dev_attr_lpfc_use_adisc,
2456         &dev_attr_lpfc_fdmi_on,
2457         &dev_attr_lpfc_max_luns,
2458         &dev_attr_nport_evt_cnt,
2459         &dev_attr_npiv_info,
2460         &dev_attr_lpfc_enable_da_id,
2461         NULL,
2462 };
2463
2464 /**
2465  * sysfs_ctlreg_write: Write method for writing to ctlreg.
2466  * @kobj: kernel kobject that contains the kernel class device.
2467  * @bin_attr: kernel attributes passed to us.
2468  * @buf: contains the data to be written to the adapter IOREG space.
2469  * @off: offset into buffer to beginning of data.
2470  * @count: bytes to transfer.
2471  *
2472  * Description:
2473  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2474  * Uses the adapter io control registers to send buf contents to the adapter.
2475  *
2476  * Returns:
2477  * -ERANGE off and count combo out of range
2478  * -EINVAL off, count or buff address invalid
2479  * -EPERM adapter is offline
2480  * value of count, buf contents written
2481  **/
2482 static ssize_t
2483 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
2484                    char *buf, loff_t off, size_t count)
2485 {
2486         size_t buf_off;
2487         struct device *dev = container_of(kobj, struct device, kobj);
2488         struct Scsi_Host  *shost = class_to_shost(dev);
2489         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2490         struct lpfc_hba   *phba = vport->phba;
2491
2492         if ((off + count) > FF_REG_AREA_SIZE)
2493                 return -ERANGE;
2494
2495         if (count == 0) return 0;
2496
2497         if (off % 4 || count % 4 || (unsigned long)buf % 4)
2498                 return -EINVAL;
2499
2500         if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
2501                 return -EPERM;
2502         }
2503
2504         spin_lock_irq(&phba->hbalock);
2505         for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
2506                 writel(*((uint32_t *)(buf + buf_off)),
2507                        phba->ctrl_regs_memmap_p + off + buf_off);
2508
2509         spin_unlock_irq(&phba->hbalock);
2510
2511         return count;
2512 }
2513
2514 /**
2515  * sysfs_ctlreg_read: Read method for reading from ctlreg.
2516  * @kobj: kernel kobject that contains the kernel class device.
2517  * @bin_attr: kernel attributes passed to us.
2518  * @buf: if succesful contains the data from the adapter IOREG space.
2519  * @off: offset into buffer to beginning of data.
2520  * @count: bytes to transfer.
2521  *
2522  * Description:
2523  * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2524  * Uses the adapter io control registers to read data into buf.
2525  *
2526  * Returns:
2527  * -ERANGE off and count combo out of range
2528  * -EINVAL off, count or buff address invalid
2529  * value of count, buf contents read
2530  **/
2531 static ssize_t
2532 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2533                   char *buf, loff_t off, size_t count)
2534 {
2535         size_t buf_off;
2536         uint32_t * tmp_ptr;
2537         struct device *dev = container_of(kobj, struct device, kobj);
2538         struct Scsi_Host  *shost = class_to_shost(dev);
2539         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2540         struct lpfc_hba   *phba = vport->phba;
2541
2542         if (off > FF_REG_AREA_SIZE)
2543                 return -ERANGE;
2544
2545         if ((off + count) > FF_REG_AREA_SIZE)
2546                 count = FF_REG_AREA_SIZE - off;
2547
2548         if (count == 0) return 0;
2549
2550         if (off % 4 || count % 4 || (unsigned long)buf % 4)
2551                 return -EINVAL;
2552
2553         spin_lock_irq(&phba->hbalock);
2554
2555         for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
2556                 tmp_ptr = (uint32_t *)(buf + buf_off);
2557                 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
2558         }
2559
2560         spin_unlock_irq(&phba->hbalock);
2561
2562         return count;
2563 }
2564
2565 static struct bin_attribute sysfs_ctlreg_attr = {
2566         .attr = {
2567                 .name = "ctlreg",
2568                 .mode = S_IRUSR | S_IWUSR,
2569         },
2570         .size = 256,
2571         .read = sysfs_ctlreg_read,
2572         .write = sysfs_ctlreg_write,
2573 };
2574
2575 /**
2576  * sysfs_mbox_idle: frees the sysfs mailbox.
2577  * @phba: lpfc_hba pointer
2578  **/
2579 static void
2580 sysfs_mbox_idle(struct lpfc_hba *phba)
2581 {
2582         phba->sysfs_mbox.state = SMBOX_IDLE;
2583         phba->sysfs_mbox.offset = 0;
2584
2585         if (phba->sysfs_mbox.mbox) {
2586                 mempool_free(phba->sysfs_mbox.mbox,
2587                              phba->mbox_mem_pool);
2588                 phba->sysfs_mbox.mbox = NULL;
2589         }
2590 }
2591
2592 /**
2593  * sysfs_mbox_write: Write method for writing information via mbox.
2594  * @kobj: kernel kobject that contains the kernel class device.
2595  * @bin_attr: kernel attributes passed to us.
2596  * @buf: contains the data to be written to sysfs mbox.
2597  * @off: offset into buffer to beginning of data.
2598  * @count: bytes to transfer.
2599  *
2600  * Description:
2601  * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2602  * Uses the sysfs mbox to send buf contents to the adapter.
2603  *
2604  * Returns:
2605  * -ERANGE off and count combo out of range
2606  * -EINVAL off, count or buff address invalid
2607  * zero if count is zero
2608  * -EPERM adapter is offline
2609  * -ENOMEM failed to allocate memory for the mail box
2610  * -EAGAIN offset, state or mbox is NULL
2611  * count number of bytes transferred
2612  **/
2613 static ssize_t
2614 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
2615                  char *buf, loff_t off, size_t count)
2616 {
2617         struct device *dev = container_of(kobj, struct device, kobj);
2618         struct Scsi_Host  *shost = class_to_shost(dev);
2619         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2620         struct lpfc_hba   *phba = vport->phba;
2621         struct lpfcMboxq  *mbox = NULL;
2622
2623         if ((count + off) > MAILBOX_CMD_SIZE)
2624                 return -ERANGE;
2625
2626         if (off % 4 ||  count % 4 || (unsigned long)buf % 4)
2627                 return -EINVAL;
2628
2629         if (count == 0)
2630                 return 0;
2631
2632         if (off == 0) {
2633                 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2634                 if (!mbox)
2635                         return -ENOMEM;
2636                 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
2637         }
2638
2639         spin_lock_irq(&phba->hbalock);
2640
2641         if (off == 0) {
2642                 if (phba->sysfs_mbox.mbox)
2643                         mempool_free(mbox, phba->mbox_mem_pool);
2644                 else
2645                         phba->sysfs_mbox.mbox = mbox;
2646                 phba->sysfs_mbox.state = SMBOX_WRITING;
2647         } else {
2648                 if (phba->sysfs_mbox.state  != SMBOX_WRITING ||
2649                     phba->sysfs_mbox.offset != off           ||
2650                     phba->sysfs_mbox.mbox   == NULL) {
2651                         sysfs_mbox_idle(phba);
2652                         spin_unlock_irq(&phba->hbalock);
2653                         return -EAGAIN;
2654                 }
2655         }
2656
2657         memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
2658                buf, count);
2659
2660         phba->sysfs_mbox.offset = off + count;
2661
2662         spin_unlock_irq(&phba->hbalock);
2663
2664         return count;
2665 }
2666
2667 /**
2668  * sysfs_mbox_read: Read method for reading information via mbox.
2669  * @kobj: kernel kobject that contains the kernel class device.
2670  * @bin_attr: kernel attributes passed to us.
2671  * @buf: contains the data to be read from sysfs mbox.
2672  * @off: offset into buffer to beginning of data.
2673  * @count: bytes to transfer.
2674  *
2675  * Description:
2676  * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2677  * Uses the sysfs mbox to receive data from to the adapter.
2678  *
2679  * Returns:
2680  * -ERANGE off greater than mailbox command size
2681  * -EINVAL off, count or buff address invalid
2682  * zero if off and count are zero
2683  * -EACCES adapter over temp
2684  * -EPERM garbage can value to catch a multitude of errors
2685  * -EAGAIN management IO not permitted, state or off error
2686  * -ETIME mailbox timeout
2687  * -ENODEV mailbox error
2688  * count number of bytes transferred
2689  **/
2690 static ssize_t
2691 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2692                 char *buf, loff_t off, size_t count)
2693 {
2694         struct device *dev = container_of(kobj, struct device, kobj);
2695         struct Scsi_Host  *shost = class_to_shost(dev);
2696         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2697         struct lpfc_hba   *phba = vport->phba;
2698         int rc;
2699
2700         if (off > MAILBOX_CMD_SIZE)
2701                 return -ERANGE;
2702
2703         if ((count + off) > MAILBOX_CMD_SIZE)
2704                 count = MAILBOX_CMD_SIZE - off;
2705
2706         if (off % 4 ||  count % 4 || (unsigned long)buf % 4)
2707                 return -EINVAL;
2708
2709         if (off && count == 0)
2710                 return 0;
2711
2712         spin_lock_irq(&phba->hbalock);
2713
2714         if (phba->over_temp_state == HBA_OVER_TEMP) {
2715                 sysfs_mbox_idle(phba);
2716                 spin_unlock_irq(&phba->hbalock);
2717                 return  -EACCES;
2718         }
2719
2720         if (off == 0 &&
2721             phba->sysfs_mbox.state  == SMBOX_WRITING &&
2722             phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
2723
2724                 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
2725                         /* Offline only */
2726                 case MBX_INIT_LINK:
2727                 case MBX_DOWN_LINK:
2728                 case MBX_CONFIG_LINK:
2729                 case MBX_CONFIG_RING:
2730                 case MBX_RESET_RING:
2731                 case MBX_UNREG_LOGIN:
2732                 case MBX_CLEAR_LA:
2733                 case MBX_DUMP_CONTEXT:
2734                 case MBX_RUN_DIAGS:
2735                 case MBX_RESTART:
2736                 case MBX_SET_MASK:
2737                 case MBX_SET_DEBUG:
2738                         if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
2739                                 printk(KERN_WARNING "mbox_read:Command 0x%x "
2740                                        "is illegal in on-line state\n",
2741                                        phba->sysfs_mbox.mbox->mb.mbxCommand);
2742                                 sysfs_mbox_idle(phba);
2743                                 spin_unlock_irq(&phba->hbalock);
2744                                 return -EPERM;
2745                         }
2746                 case MBX_WRITE_NV:
2747                 case MBX_WRITE_VPARMS:
2748                 case MBX_LOAD_SM:
2749                 case MBX_READ_NV:
2750                 case MBX_READ_CONFIG:
2751                 case MBX_READ_RCONFIG:
2752                 case MBX_READ_STATUS:
2753                 case MBX_READ_XRI:
2754                 case MBX_READ_REV:
2755                 case MBX_READ_LNK_STAT:
2756                 case MBX_DUMP_MEMORY:
2757                 case MBX_DOWN_LOAD:
2758                 case MBX_UPDATE_CFG:
2759                 case MBX_KILL_BOARD:
2760                 case MBX_LOAD_AREA:
2761                 case MBX_LOAD_EXP_ROM:
2762                 case MBX_BEACON:
2763                 case MBX_DEL_LD_ENTRY:
2764                 case MBX_SET_VARIABLE:
2765                 case MBX_WRITE_WWN:
2766                         break;
2767                 case MBX_READ_SPARM64:
2768                 case MBX_READ_LA:
2769                 case MBX_READ_LA64:
2770                 case MBX_REG_LOGIN:
2771                 case MBX_REG_LOGIN64:
2772                 case MBX_CONFIG_PORT:
2773                 case MBX_RUN_BIU_DIAG:
2774                         printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
2775                                phba->sysfs_mbox.mbox->mb.mbxCommand);
2776                         sysfs_mbox_idle(phba);
2777                         spin_unlock_irq(&phba->hbalock);
2778                         return -EPERM;
2779                 default:
2780                         printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
2781                                phba->sysfs_mbox.mbox->mb.mbxCommand);
2782                         sysfs_mbox_idle(phba);
2783                         spin_unlock_irq(&phba->hbalock);
2784                         return -EPERM;
2785                 }
2786
2787                 /* If HBA encountered an error attention, allow only DUMP
2788                  * or RESTART mailbox commands until the HBA is restarted.
2789                  */
2790                 if ((phba->pport->stopped) &&
2791                         (phba->sysfs_mbox.mbox->mb.mbxCommand !=
2792                                 MBX_DUMP_MEMORY &&
2793                          phba->sysfs_mbox.mbox->mb.mbxCommand !=
2794                                 MBX_RESTART &&
2795                          phba->sysfs_mbox.mbox->mb.mbxCommand !=
2796                                 MBX_WRITE_VPARMS)) {
2797                         sysfs_mbox_idle(phba);
2798                         spin_unlock_irq(&phba->hbalock);
2799                         return -EPERM;
2800                 }
2801
2802                 phba->sysfs_mbox.mbox->vport = vport;
2803
2804                 /* Don't allow mailbox commands to be sent when blocked
2805                  * or when in the middle of discovery
2806                  */
2807                 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
2808                         sysfs_mbox_idle(phba);
2809                         spin_unlock_irq(&phba->hbalock);
2810                         return  -EAGAIN;
2811                 }
2812
2813                 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2814                     (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
2815
2816                         spin_unlock_irq(&phba->hbalock);
2817                         rc = lpfc_sli_issue_mbox (phba,
2818                                                   phba->sysfs_mbox.mbox,
2819                                                   MBX_POLL);
2820                         spin_lock_irq(&phba->hbalock);
2821
2822                 } else {
2823                         spin_unlock_irq(&phba->hbalock);
2824                         rc = lpfc_sli_issue_mbox_wait (phba,
2825                                                        phba->sysfs_mbox.mbox,
2826                                 lpfc_mbox_tmo_val(phba,
2827                                     phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
2828                         spin_lock_irq(&phba->hbalock);
2829                 }
2830
2831                 if (rc != MBX_SUCCESS) {
2832                         if (rc == MBX_TIMEOUT) {
2833                                 phba->sysfs_mbox.mbox = NULL;
2834                         }
2835                         sysfs_mbox_idle(phba);
2836                         spin_unlock_irq(&phba->hbalock);
2837                         return  (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
2838                 }
2839                 phba->sysfs_mbox.state = SMBOX_READING;
2840         }
2841         else if (phba->sysfs_mbox.offset != off ||
2842                  phba->sysfs_mbox.state  != SMBOX_READING) {
2843                 printk(KERN_WARNING  "mbox_read: Bad State\n");
2844                 sysfs_mbox_idle(phba);
2845                 spin_unlock_irq(&phba->hbalock);
2846                 return -EAGAIN;
2847         }
2848
2849         memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
2850
2851         phba->sysfs_mbox.offset = off + count;
2852
2853         if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
2854                 sysfs_mbox_idle(phba);
2855
2856         spin_unlock_irq(&phba->hbalock);
2857
2858         return count;
2859 }
2860
2861 static struct bin_attribute sysfs_mbox_attr = {
2862         .attr = {
2863                 .name = "mbox",
2864                 .mode = S_IRUSR | S_IWUSR,
2865         },
2866         .size = MAILBOX_CMD_SIZE,
2867         .read = sysfs_mbox_read,
2868         .write = sysfs_mbox_write,
2869 };
2870
2871 /**
2872  * lpfc_alloc_sysfs_attr: Creates the sysfs, ctlreg, menlo and mbox entries.
2873  * @vport: address of lpfc vport structure.
2874  *
2875  * Return codes:
2876  * zero on success
2877  * error return code from sysfs_create_bin_file()
2878  **/
2879 int
2880 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
2881 {
2882         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2883         int error;
2884
2885         error = sysfs_create_bin_file(&shost->shost_dev.kobj,
2886                                       &sysfs_ctlreg_attr);
2887         if (error)
2888                 goto out;
2889
2890         error = sysfs_create_bin_file(&shost->shost_dev.kobj,
2891                                       &sysfs_mbox_attr);
2892         if (error)
2893                 goto out_remove_ctlreg_attr;
2894
2895         return 0;
2896 out_remove_ctlreg_attr:
2897         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
2898 out:
2899         return error;
2900 }
2901
2902 /**
2903  * lpfc_free_sysfs_attr: Removes the sysfs, ctlreg, menlo and mbox entries.
2904  * @vport: address of lpfc vport structure.
2905  **/
2906 void
2907 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
2908 {
2909         struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2910
2911         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
2912         sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
2913 }
2914
2915
2916 /*
2917  * Dynamic FC Host Attributes Support
2918  */
2919
2920 /**
2921  * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id.
2922  * @shost: kernel scsi host pointer.
2923  **/
2924 static void
2925 lpfc_get_host_port_id(struct Scsi_Host *shost)
2926 {
2927         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2928
2929         /* note: fc_myDID already in cpu endianness */
2930         fc_host_port_id(shost) = vport->fc_myDID;
2931 }
2932
2933 /**
2934  * lpfc_get_host_port_type: Set the value of the scsi host port type.
2935  * @shost: kernel scsi host pointer.
2936  **/
2937 static void
2938 lpfc_get_host_port_type(struct Scsi_Host *shost)
2939 {
2940         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2941         struct lpfc_hba   *phba = vport->phba;
2942
2943         spin_lock_irq(shost->host_lock);
2944
2945         if (vport->port_type == LPFC_NPIV_PORT) {
2946                 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2947         } else if (lpfc_is_link_up(phba)) {
2948                 if (phba->fc_topology == TOPOLOGY_LOOP) {
2949                         if (vport->fc_flag & FC_PUBLIC_LOOP)
2950                                 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2951                         else
2952                                 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
2953                 } else {
2954                         if (vport->fc_flag & FC_FABRIC)
2955                                 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2956                         else
2957                                 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2958                 }
2959         } else
2960                 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2961
2962         spin_unlock_irq(shost->host_lock);
2963 }
2964
2965 /**
2966  * lpfc_get_host_port_state: Set the value of the scsi host port state.
2967  * @shost: kernel scsi host pointer.
2968  **/
2969 static void
2970 lpfc_get_host_port_state(struct Scsi_Host *shost)
2971 {
2972         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2973         struct lpfc_hba   *phba = vport->phba;
2974
2975         spin_lock_irq(shost->host_lock);
2976
2977         if (vport->fc_flag & FC_OFFLINE_MODE)
2978                 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2979         else {
2980                 switch (phba->link_state) {
2981                 case LPFC_LINK_UNKNOWN:
2982                 case LPFC_LINK_DOWN:
2983                         fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2984                         break;
2985                 case LPFC_LINK_UP:
2986                 case LPFC_CLEAR_LA:
2987                 case LPFC_HBA_READY:
2988                         /* Links up, beyond this port_type reports state */
2989                         fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2990                         break;
2991                 case LPFC_HBA_ERROR:
2992                         fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
2993                         break;
2994                 default:
2995                         fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2996                         break;
2997                 }
2998         }
2999
3000         spin_unlock_irq(shost->host_lock);
3001 }
3002
3003 /**
3004  * lpfc_get_host_speed: Set the value of the scsi host speed.
3005  * @shost: kernel scsi host pointer.
3006  **/
3007 static void
3008 lpfc_get_host_speed(struct Scsi_Host *shost)
3009 {
3010         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3011         struct lpfc_hba   *phba = vport->phba;
3012
3013         spin_lock_irq(shost->host_lock);
3014
3015         if (lpfc_is_link_up(phba)) {
3016                 switch(phba->fc_linkspeed) {
3017                         case LA_1GHZ_LINK:
3018                                 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3019                         break;
3020                         case LA_2GHZ_LINK:
3021                                 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3022                         break;
3023                         case LA_4GHZ_LINK:
3024                                 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3025                         break;
3026                         case LA_8GHZ_LINK:
3027                                 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3028                         break;
3029                         default:
3030                                 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3031                         break;
3032                 }
3033         } else
3034                 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3035
3036         spin_unlock_irq(shost->host_lock);
3037 }
3038
3039 /**
3040  * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name.
3041  * @shost: kernel scsi host pointer.
3042  **/
3043 static void
3044 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3045 {
3046         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3047         struct lpfc_hba   *phba = vport->phba;
3048         u64 node_name;
3049
3050         spin_lock_irq(shost->host_lock);
3051
3052         if ((vport->fc_flag & FC_FABRIC) ||
3053             ((phba->fc_topology == TOPOLOGY_LOOP) &&
3054              (vport->fc_flag & FC_PUBLIC_LOOP)))
3055                 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
3056         else
3057                 /* fabric is local port if there is no F/FL_Port */
3058                 node_name = 0;
3059
3060         spin_unlock_irq(shost->host_lock);
3061
3062         fc_host_fabric_name(shost) = node_name;
3063 }
3064
3065 /**
3066  * lpfc_get_stats: Return statistical information about the adapter.
3067  * @shost: kernel scsi host pointer.
3068  *
3069  * Notes:
3070  * NULL on error for link down, no mbox pool, sli2 active,
3071  * management not allowed, memory allocation error, or mbox error.
3072  *
3073  * Returns:
3074  * NULL for error
3075  * address of the adapter host statistics
3076  **/
3077 static struct fc_host_statistics *
3078 lpfc_get_stats(struct Scsi_Host *shost)
3079 {
3080         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3081         struct lpfc_hba   *phba = vport->phba;
3082         struct lpfc_sli   *psli = &phba->sli;
3083         struct fc_host_statistics *hs = &phba->link_stats;
3084         struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
3085         LPFC_MBOXQ_t *pmboxq;
3086         MAILBOX_t *pmb;
3087         unsigned long seconds;
3088         int rc = 0;
3089
3090         /*
3091          * prevent udev from issuing mailbox commands until the port is
3092          * configured.
3093          */
3094         if (phba->link_state < LPFC_LINK_DOWN ||
3095             !phba->mbox_mem_pool ||
3096             (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
3097                 return NULL;
3098
3099         if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
3100                 return NULL;
3101
3102         pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3103         if (!pmboxq)
3104                 return NULL;
3105         memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3106
3107         pmb = &pmboxq->mb;
3108         pmb->mbxCommand = MBX_READ_STATUS;
3109         pmb->mbxOwner = OWN_HOST;
3110         pmboxq->context1 = NULL;
3111         pmboxq->vport = vport;
3112
3113         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3114                 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3115                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3116         else
3117                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3118
3119         if (rc != MBX_SUCCESS) {
3120                 if (rc != MBX_TIMEOUT)
3121                         mempool_free(pmboxq, phba->mbox_mem_pool);
3122                 return NULL;
3123         }
3124
3125         memset(hs, 0, sizeof (struct fc_host_statistics));
3126
3127         hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3128         hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3129         hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3130         hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3131
3132         memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3133         pmb->mbxCommand = MBX_READ_LNK_STAT;
3134         pmb->mbxOwner = OWN_HOST;
3135         pmboxq->context1 = NULL;
3136         pmboxq->vport = vport;
3137
3138         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3139             (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3140                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3141         else
3142                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3143
3144         if (rc != MBX_SUCCESS) {
3145                 if (rc != MBX_TIMEOUT)
3146                         mempool_free(pmboxq, phba->mbox_mem_pool);
3147                 return NULL;
3148         }
3149
3150         hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3151         hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3152         hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3153         hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3154         hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3155         hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3156         hs->error_frames = pmb->un.varRdLnk.crcCnt;
3157
3158         hs->link_failure_count -= lso->link_failure_count;
3159         hs->loss_of_sync_count -= lso->loss_of_sync_count;
3160         hs->loss_of_signal_count -= lso->loss_of_signal_count;
3161         hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3162         hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3163         hs->invalid_crc_count -= lso->invalid_crc_count;
3164         hs->error_frames -= lso->error_frames;
3165
3166         if (phba->fc_topology == TOPOLOGY_LOOP) {
3167                 hs->lip_count = (phba->fc_eventTag >> 1);
3168                 hs->lip_count -= lso->link_events;
3169                 hs->nos_count = -1;
3170         } else {
3171                 hs->lip_count = -1;
3172                 hs->nos_count = (phba->fc_eventTag >> 1);
3173                 hs->nos_count -= lso->link_events;
3174         }
3175
3176         hs->dumped_frames = -1;
3177
3178         seconds = get_seconds();
3179         if (seconds < psli->stats_start)
3180                 hs->seconds_since_last_reset = seconds +
3181                                 ((unsigned long)-1 - psli->stats_start);
3182         else
3183                 hs->seconds_since_last_reset = seconds - psli->stats_start;
3184
3185         mempool_free(pmboxq, phba->mbox_mem_pool);
3186
3187         return hs;
3188 }
3189
3190 /**
3191  * lpfc_reset_stats: Copy the adapter link stats information.
3192  * @shost: kernel scsi host pointer.
3193  **/
3194 static void
3195 lpfc_reset_stats(struct Scsi_Host *shost)
3196 {
3197         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3198         struct lpfc_hba   *phba = vport->phba;
3199         struct lpfc_sli   *psli = &phba->sli;
3200         struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
3201         LPFC_MBOXQ_t *pmboxq;
3202         MAILBOX_t *pmb;
3203         int rc = 0;
3204
3205         if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
3206                 return;
3207
3208         pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3209         if (!pmboxq)
3210                 return;
3211         memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3212
3213         pmb = &pmboxq->mb;
3214         pmb->mbxCommand = MBX_READ_STATUS;
3215         pmb->mbxOwner = OWN_HOST;
3216         pmb->un.varWords[0] = 0x1; /* reset request */
3217         pmboxq->context1 = NULL;
3218         pmboxq->vport = vport;
3219
3220         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3221                 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3222                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3223         else
3224                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3225
3226         if (rc != MBX_SUCCESS) {
3227                 if (rc != MBX_TIMEOUT)
3228                         mempool_free(pmboxq, phba->mbox_mem_pool);
3229                 return;
3230         }
3231
3232         memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3233         pmb->mbxCommand = MBX_READ_LNK_STAT;
3234         pmb->mbxOwner = OWN_HOST;
3235         pmboxq->context1 = NULL;
3236         pmboxq->vport = vport;
3237
3238         if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3239             (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3240                 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3241         else
3242                 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3243
3244         if (rc != MBX_SUCCESS) {
3245                 if (rc != MBX_TIMEOUT)
3246                         mempool_free( pmboxq, phba->mbox_mem_pool);
3247                 return;
3248         }
3249
3250         lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3251         lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3252         lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3253         lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3254         lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3255         lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3256         lso->error_frames = pmb->un.varRdLnk.crcCnt;
3257         lso->link_events = (phba->fc_eventTag >> 1);
3258
3259         psli->stats_start = get_seconds();
3260
3261         mempool_free(pmboxq, phba->mbox_mem_pool);
3262
3263         return;
3264 }
3265
3266 /*
3267  * The LPFC driver treats linkdown handling as target loss events so there
3268  * are no sysfs handlers for link_down_tmo.
3269  */
3270
3271 /**
3272  * lpfc_get_node_by_target: Return the nodelist for a target.
3273  * @starget: kernel scsi target pointer.
3274  *
3275  * Returns:
3276  * address of the node list if found
3277  * NULL target not found
3278  **/
3279 static struct lpfc_nodelist *
3280 lpfc_get_node_by_target(struct scsi_target *starget)
3281 {
3282         struct Scsi_Host  *shost = dev_to_shost(starget->dev.parent);
3283         struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3284         struct lpfc_nodelist *ndlp;
3285
3286         spin_lock_irq(shost->host_lock);
3287         /* Search for this, mapped, target ID */
3288         list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3289                 if (NLP_CHK_NODE_ACT(ndlp) &&
3290                     ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
3291                     starget->id == ndlp->nlp_sid) {
3292                         spin_unlock_irq(shost->host_lock);
3293                         return ndlp;
3294                 }
3295         }
3296         spin_unlock_irq(shost->host_lock);
3297         return NULL;
3298 }
3299
3300 /**
3301  * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1.
3302  * @starget: kernel scsi target pointer.
3303  **/
3304 static void
3305 lpfc_get_starget_port_id(struct scsi_target *starget)
3306 {
3307         struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3308
3309         fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
3310 }
3311
3312 /**
3313  * lpfc_get_starget_node_name: Set the target node name.
3314  * @starget: kernel scsi target pointer.
3315  *
3316  * Description: Set the target node name to the ndlp node name wwn or zero.
3317  **/
3318 static void
3319 lpfc_get_starget_node_name(struct scsi_target *starget)
3320 {
3321         struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3322
3323         fc_starget_node_name(starget) =
3324                 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
3325 }
3326
3327 /**
3328  * lpfc_get_starget_port_name: Set the target port name.
3329  * @starget: kernel scsi target pointer.
3330  *
3331  * Description:  set the target port name to the ndlp port name wwn or zero.
3332  **/
3333 static void
3334 lpfc_get_starget_port_name(struct scsi_target *starget)
3335 {
3336         struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3337
3338         fc_starget_port_name(starget) =
3339                 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
3340 }
3341
3342 /**
3343  * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo.
3344  * @rport: fc rport address.
3345  * @timeout: new value for dev loss tmo.
3346  *
3347  * Description:
3348  * If timeout is non zero set the dev_loss_tmo to timeout, else set
3349  * dev_loss_tmo to one.
3350  **/
3351 static void
3352 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
3353 {
3354         if (timeout)
3355                 rport->dev_loss_tmo = timeout;
3356         else
3357                 rport->dev_loss_tmo = 1;
3358 }
3359
3360 /**
3361  * lpfc_rport_show_function: Return rport target information.
3362  *
3363  * Description:
3364  * Macro that uses field to generate a function with the name lpfc_show_rport_
3365  *
3366  * lpfc_show_rport_##field: returns the bytes formatted in buf
3367  * @cdev: class converted to an fc_rport.
3368  * @buf: on return contains the target_field or zero.
3369  *
3370  * Returns: size of formatted string.
3371  **/
3372 #define lpfc_rport_show_function(field, format_string, sz, cast)        \
3373 static ssize_t                                                          \
3374 lpfc_show_rport_##field (struct device *dev,                            \
3375                          struct device_attribute *attr,                 \
3376                          char *buf)                                     \
3377 {                                                                       \
3378         struct fc_rport *rport = transport_class_to_rport(dev);         \
3379         struct lpfc_rport_data *rdata = rport->hostdata;                \
3380         return snprintf(buf, sz, format_string,                         \
3381                 (rdata->target) ? cast rdata->target->field : 0);       \
3382 }
3383
3384 #define lpfc_rport_rd_attr(field, format_string, sz)                    \
3385         lpfc_rport_show_function(field, format_string, sz, )            \
3386 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
3387
3388
3389 struct fc_function_template lpfc_transport_functions = {
3390         /* fixed attributes the driver supports */
3391         .show_host_node_name = 1,
3392         .show_host_port_name = 1,
3393         .show_host_supported_classes = 1,
3394         .show_host_supported_fc4s = 1,
3395         .show_host_supported_speeds = 1,
3396         .show_host_maxframe_size = 1,
3397
3398         /* dynamic attributes the driver supports */
3399         .get_host_port_id = lpfc_get_host_port_id,
3400         .show_host_port_id = 1,
3401
3402         .get_host_port_type = lpfc_get_host_port_type,
3403         .show_host_port_type = 1,
3404
3405         .get_host_port_state = lpfc_get_host_port_state,
3406         .show_host_port_state = 1,
3407
3408         /* active_fc4s is shown but doesn't change (thus no get function) */
3409         .show_host_active_fc4s = 1,
3410
3411         .get_host_speed = lpfc_get_host_speed,
3412         .show_host_speed = 1,
3413
3414         .get_host_fabric_name = lpfc_get_host_fabric_name,
3415         .show_host_fabric_name = 1,
3416
3417         /*
3418          * The LPFC driver treats linkdown handling as target loss events
3419          * so there are no sysfs handlers for link_down_tmo.
3420          */
3421
3422         .get_fc_host_stats = lpfc_get_stats,
3423         .reset_fc_host_stats = lpfc_reset_stats,
3424
3425         .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3426         .show_rport_maxframe_size = 1,
3427         .show_rport_supported_classes = 1,
3428
3429         .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3430         .show_rport_dev_loss_tmo = 1,
3431
3432         .get_starget_port_id  = lpfc_get_starget_port_id,
3433         .show_starget_port_id = 1,
3434
3435         .get_starget_node_name = lpfc_get_starget_node_name,
3436         .show_starget_node_name = 1,
3437
3438         .get_starget_port_name = lpfc_get_starget_port_name,
3439         .show_starget_port_name = 1,
3440
3441         .issue_fc_host_lip = lpfc_issue_lip,
3442         .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3443         .terminate_rport_io = lpfc_terminate_rport_io,
3444
3445         .dd_fcvport_size = sizeof(struct lpfc_vport *),
3446 };
3447
3448 struct fc_function_template lpfc_vport_transport_functions = {
3449         /* fixed attributes the driver supports */
3450         .show_host_node_name = 1,
3451         .show_host_port_name = 1,
3452         .show_host_supported_classes = 1,
3453         .show_host_supported_fc4s = 1,
3454         .show_host_supported_speeds = 1,
3455         .show_host_maxframe_size = 1,
3456
3457         /* dynamic attributes the driver supports */
3458         .get_host_port_id = lpfc_get_host_port_id,
3459         .show_host_port_id = 1,
3460
3461         .get_host_port_type = lpfc_get_host_port_type,
3462         .show_host_port_type = 1,
3463
3464         .get_host_port_state = lpfc_get_host_port_state,
3465         .show_host_port_state = 1,
3466
3467         /* active_fc4s is shown but doesn't change (thus no get function) */
3468         .show_host_active_fc4s = 1,
3469
3470         .get_host_speed = lpfc_get_host_speed,
3471         .show_host_speed = 1,
3472
3473         .get_host_fabric_name = lpfc_get_host_fabric_name,
3474         .show_host_fabric_name = 1,
3475
3476         /*
3477          * The LPFC driver treats linkdown handling as target loss events
3478          * so there are no sysfs handlers for link_down_tmo.
3479          */
3480
3481         .get_fc_host_stats = lpfc_get_stats,
3482         .reset_fc_host_stats = lpfc_reset_stats,
3483
3484         .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3485         .show_rport_maxframe_size = 1,
3486         .show_rport_supported_classes = 1,
3487
3488         .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3489         .show_rport_dev_loss_tmo = 1,
3490
3491         .get_starget_port_id  = lpfc_get_starget_port_id,
3492         .show_starget_port_id = 1,
3493
3494         .get_starget_node_name = lpfc_get_starget_node_name,
3495         .show_starget_node_name = 1,
3496
3497         .get_starget_port_name = lpfc_get_starget_port_name,
3498         .show_starget_port_name = 1,
3499
3500         .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3501         .terminate_rport_io = lpfc_terminate_rport_io,
3502
3503         .vport_disable = lpfc_vport_disable,
3504 };
3505
3506 /**
3507  * lpfc_get_cfgparam: Used during probe_one to init the adapter structure.
3508  * @phba: lpfc_hba pointer.
3509  **/
3510 void
3511 lpfc_get_cfgparam(struct lpfc_hba *phba)
3512 {
3513         lpfc_cr_delay_init(phba, lpfc_cr_delay);
3514         lpfc_cr_count_init(phba, lpfc_cr_count);
3515         lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
3516         lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
3517         lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
3518         lpfc_ack0_init(phba, lpfc_ack0);
3519         lpfc_topology_init(phba, lpfc_topology);
3520         lpfc_link_speed_init(phba, lpfc_link_speed);
3521         lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
3522         lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
3523         lpfc_use_msi_init(phba, lpfc_use_msi);
3524         lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
3525         lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
3526         phba->cfg_poll = lpfc_poll;
3527         phba->cfg_soft_wwnn = 0L;
3528         phba->cfg_soft_wwpn = 0L;
3529         lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
3530         /* Also reinitialize the host templates with new values. */
3531         lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3532         lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3533         /*
3534          * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3535          * used to create the sg_dma_buf_pool must be dynamically calculated.
3536          * 2 segments are added since the IOCB needs a command and response bde.
3537          */
3538         phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
3539                         sizeof(struct fcp_rsp) +
3540                         ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
3541         lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
3542         return;
3543 }
3544
3545 /**
3546  * lpfc_get_vport_cfgparam: Used during port create, init the vport structure.
3547  * @vport: lpfc_vport pointer.
3548  **/
3549 void
3550 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
3551 {
3552         lpfc_log_verbose_init(vport, lpfc_log_verbose);
3553         lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
3554         lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
3555         lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
3556         lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
3557         lpfc_restrict_login_init(vport, lpfc_restrict_login);
3558         lpfc_fcp_class_init(vport, lpfc_fcp_class);
3559         lpfc_use_adisc_init(vport, lpfc_use_adisc);
3560         lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
3561         lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
3562         lpfc_max_luns_init(vport, lpfc_max_luns);
3563         lpfc_scan_down_init(vport, lpfc_scan_down);
3564         lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
3565         return;
3566 }