1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
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 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
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>
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.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"
44 #define LPFC_DEF_DEVLOSS_TMO 30
45 #define LPFC_MIN_DEVLOSS_TMO 1
46 #define LPFC_MAX_DEVLOSS_TMO 255
49 lpfc_jedec_to_ascii(int incr
, char hdw
[])
52 for (i
= 0; i
< 8; i
++) {
55 hdw
[7 - i
] = 0x30 + j
;
57 hdw
[7 - i
] = 0x61 + j
- 10;
65 lpfc_drvr_version_show(struct class_device
*cdev
, char *buf
)
67 return snprintf(buf
, PAGE_SIZE
, LPFC_MODULE_DESC
"\n");
71 management_version_show(struct class_device
*cdev
, char *buf
)
73 return snprintf(buf
, PAGE_SIZE
, DFC_API_VERSION
"\n");
77 lpfc_info_show(struct class_device
*cdev
, char *buf
)
79 struct Scsi_Host
*host
= class_to_shost(cdev
);
81 return snprintf(buf
, PAGE_SIZE
, "%s\n",lpfc_info(host
));
85 lpfc_serialnum_show(struct class_device
*cdev
, char *buf
)
87 struct Scsi_Host
*shost
= class_to_shost(cdev
);
88 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
89 struct lpfc_hba
*phba
= vport
->phba
;
91 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->SerialNumber
);
95 lpfc_modeldesc_show(struct class_device
*cdev
, char *buf
)
97 struct Scsi_Host
*shost
= class_to_shost(cdev
);
98 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
99 struct lpfc_hba
*phba
= vport
->phba
;
101 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelDesc
);
105 lpfc_modelname_show(struct class_device
*cdev
, char *buf
)
107 struct Scsi_Host
*shost
= class_to_shost(cdev
);
108 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
109 struct lpfc_hba
*phba
= vport
->phba
;
111 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelName
);
115 lpfc_programtype_show(struct class_device
*cdev
, char *buf
)
117 struct Scsi_Host
*shost
= class_to_shost(cdev
);
118 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
119 struct lpfc_hba
*phba
= vport
->phba
;
121 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ProgramType
);
125 lpfc_vportnum_show(struct class_device
*cdev
, char *buf
)
127 struct Scsi_Host
*shost
= class_to_shost(cdev
);
128 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
129 struct lpfc_hba
*phba
= vport
->phba
;
131 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->Port
);
135 lpfc_fwrev_show(struct class_device
*cdev
, char *buf
)
137 struct Scsi_Host
*shost
= class_to_shost(cdev
);
138 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
139 struct lpfc_hba
*phba
= vport
->phba
;
142 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
143 return snprintf(buf
, PAGE_SIZE
, "%s, sli-%d\n", fwrev
, phba
->sli_rev
);
147 lpfc_hdw_show(struct class_device
*cdev
, char *buf
)
150 struct Scsi_Host
*shost
= class_to_shost(cdev
);
151 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
152 struct lpfc_hba
*phba
= vport
->phba
;
153 lpfc_vpd_t
*vp
= &phba
->vpd
;
155 lpfc_jedec_to_ascii(vp
->rev
.biuRev
, hdw
);
156 return snprintf(buf
, PAGE_SIZE
, "%s\n", hdw
);
159 lpfc_option_rom_version_show(struct class_device
*cdev
, char *buf
)
161 struct Scsi_Host
*shost
= class_to_shost(cdev
);
162 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
163 struct lpfc_hba
*phba
= vport
->phba
;
165 return snprintf(buf
, PAGE_SIZE
, "%s\n", phba
->OptionROMVersion
);
168 lpfc_state_show(struct class_device
*cdev
, char *buf
)
170 struct Scsi_Host
*shost
= class_to_shost(cdev
);
171 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
172 struct lpfc_hba
*phba
= vport
->phba
;
175 switch (phba
->link_state
) {
176 case LPFC_LINK_UNKNOWN
:
177 case LPFC_WARM_START
:
178 case LPFC_INIT_START
:
179 case LPFC_INIT_MBX_CMDS
:
182 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Link Down\n");
187 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Link Up - \n");
189 switch (vport
->port_state
) {
190 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
193 case LPFC_LOCAL_CFG_LINK
:
194 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
195 "Configuring Link\n");
199 case LPFC_FABRIC_CFG_LINK
:
202 case LPFC_BUILD_DISC_LIST
:
204 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
207 case LPFC_VPORT_READY
:
208 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "Ready\n");
211 case LPFC_VPORT_FAILED
:
212 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "Failed\n");
215 case LPFC_VPORT_UNKNOWN
:
216 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
221 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
222 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
223 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
226 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
229 if (vport
->fc_flag
& FC_FABRIC
)
230 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
233 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
242 lpfc_num_discovered_ports_show(struct class_device
*cdev
, char *buf
)
244 struct Scsi_Host
*shost
= class_to_shost(cdev
);
245 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
247 return snprintf(buf
, PAGE_SIZE
, "%d\n",
248 vport
->fc_map_cnt
+ vport
->fc_unmap_cnt
);
253 lpfc_issue_lip(struct Scsi_Host
*shost
)
255 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
256 struct lpfc_hba
*phba
= vport
->phba
;
257 LPFC_MBOXQ_t
*pmboxq
;
258 int mbxstatus
= MBXERR_ERROR
;
260 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
261 (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) ||
262 (vport
->port_state
!= LPFC_VPORT_READY
))
265 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
270 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
271 pmboxq
->mb
.mbxCommand
= MBX_DOWN_LINK
;
272 pmboxq
->mb
.mbxOwner
= OWN_HOST
;
274 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
* 2);
276 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->mb
.mbxStatus
== 0)) {
277 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
278 lpfc_init_link(phba
, pmboxq
, phba
->cfg_topology
,
279 phba
->cfg_link_speed
);
280 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
284 lpfc_set_loopback_flag(phba
);
285 if (mbxstatus
!= MBX_TIMEOUT
)
286 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
288 if (mbxstatus
== MBXERR_ERROR
)
295 lpfc_do_offline(struct lpfc_hba
*phba
, uint32_t type
)
297 struct completion online_compl
;
298 struct lpfc_sli_ring
*pring
;
299 struct lpfc_sli
*psli
;
304 init_completion(&online_compl
);
305 lpfc_workq_post_event(phba
, &status
, &online_compl
,
306 LPFC_EVT_OFFLINE_PREP
);
307 wait_for_completion(&online_compl
);
314 for (i
= 0; i
< psli
->num_rings
; i
++) {
315 pring
= &psli
->ring
[i
];
316 /* The linkdown event takes 30 seconds to timeout. */
317 while (pring
->txcmplq_cnt
) {
320 lpfc_printf_log(phba
,
321 KERN_WARNING
, LOG_INIT
,
322 "%d:0466 Outstanding IO when "
323 "bringing Adapter offline\n",
330 init_completion(&online_compl
);
331 lpfc_workq_post_event(phba
, &status
, &online_compl
, type
);
332 wait_for_completion(&online_compl
);
341 lpfc_selective_reset(struct lpfc_hba
*phba
)
343 struct completion online_compl
;
346 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
351 init_completion(&online_compl
);
352 lpfc_workq_post_event(phba
, &status
, &online_compl
,
354 wait_for_completion(&online_compl
);
363 lpfc_issue_reset(struct class_device
*cdev
, const char *buf
, size_t count
)
365 struct Scsi_Host
*shost
= class_to_shost(cdev
);
366 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
367 struct lpfc_hba
*phba
= vport
->phba
;
369 int status
= -EINVAL
;
371 if (strncmp(buf
, "selective", sizeof("selective") - 1) == 0)
372 status
= lpfc_selective_reset(phba
);
381 lpfc_nport_evt_cnt_show(struct class_device
*cdev
, char *buf
)
383 struct Scsi_Host
*shost
= class_to_shost(cdev
);
384 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
385 struct lpfc_hba
*phba
= vport
->phba
;
387 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->nport_event_cnt
);
391 lpfc_board_mode_show(struct class_device
*cdev
, char *buf
)
393 struct Scsi_Host
*shost
= class_to_shost(cdev
);
394 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
395 struct lpfc_hba
*phba
= vport
->phba
;
398 if (phba
->link_state
== LPFC_HBA_ERROR
)
400 else if (phba
->link_state
== LPFC_WARM_START
)
401 state
= "warm start";
402 else if (phba
->link_state
== LPFC_INIT_START
)
407 return snprintf(buf
, PAGE_SIZE
, "%s\n", state
);
411 lpfc_board_mode_store(struct class_device
*cdev
, const char *buf
, size_t count
)
413 struct Scsi_Host
*shost
= class_to_shost(cdev
);
414 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
415 struct lpfc_hba
*phba
= vport
->phba
;
416 struct completion online_compl
;
419 init_completion(&online_compl
);
421 if(strncmp(buf
, "online", sizeof("online") - 1) == 0) {
422 lpfc_workq_post_event(phba
, &status
, &online_compl
,
424 wait_for_completion(&online_compl
);
425 } else if (strncmp(buf
, "offline", sizeof("offline") - 1) == 0)
426 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
427 else if (strncmp(buf
, "warm", sizeof("warm") - 1) == 0)
428 status
= lpfc_do_offline(phba
, LPFC_EVT_WARM_START
);
429 else if (strncmp(buf
, "error", sizeof("error") - 1) == 0)
430 status
= lpfc_do_offline(phba
, LPFC_EVT_KILL
);
441 lpfc_get_hba_info(struct lpfc_hba
*phba
,
442 uint32_t *mxri
, uint32_t *axri
,
443 uint32_t *mrpi
, uint32_t *arpi
,
444 uint32_t *mvpi
, uint32_t *avpi
)
446 struct lpfc_sli
*psli
= &phba
->sli
;
447 LPFC_MBOXQ_t
*pmboxq
;
452 * prevent udev from issuing mailbox commands until the port is
455 if (phba
->link_state
< LPFC_LINK_DOWN
||
456 !phba
->mbox_mem_pool
||
457 (phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
) == 0)
460 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
463 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
466 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
469 pmb
->mbxCommand
= MBX_READ_CONFIG
;
470 pmb
->mbxOwner
= OWN_HOST
;
471 pmboxq
->context1
= NULL
;
473 if ((phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) ||
474 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
475 rc
= MBX_NOT_FINISHED
;
477 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
479 if (rc
!= MBX_SUCCESS
) {
480 if (rc
!= MBX_TIMEOUT
)
481 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
486 *mrpi
= pmb
->un
.varRdConfig
.max_rpi
;
488 *arpi
= pmb
->un
.varRdConfig
.avail_rpi
;
490 *mxri
= pmb
->un
.varRdConfig
.max_xri
;
492 *axri
= pmb
->un
.varRdConfig
.avail_xri
;
494 *mvpi
= pmb
->un
.varRdConfig
.max_vpi
;
496 *avpi
= pmb
->un
.varRdConfig
.avail_vpi
;
498 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
503 lpfc_max_rpi_show(struct class_device
*cdev
, char *buf
)
505 struct Scsi_Host
*shost
= class_to_shost(cdev
);
506 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
507 struct lpfc_hba
*phba
= vport
->phba
;
510 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, NULL
, NULL
, NULL
))
511 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
512 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
516 lpfc_used_rpi_show(struct class_device
*cdev
, char *buf
)
518 struct Scsi_Host
*shost
= class_to_shost(cdev
);
519 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
520 struct lpfc_hba
*phba
= vport
->phba
;
523 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, &acnt
, NULL
, NULL
))
524 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
525 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
529 lpfc_max_xri_show(struct class_device
*cdev
, char *buf
)
531 struct Scsi_Host
*shost
= class_to_shost(cdev
);
532 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
533 struct lpfc_hba
*phba
= vport
->phba
;
536 if (lpfc_get_hba_info(phba
, &cnt
, NULL
, NULL
, NULL
, NULL
, NULL
))
537 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
538 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
542 lpfc_used_xri_show(struct class_device
*cdev
, char *buf
)
544 struct Scsi_Host
*shost
= class_to_shost(cdev
);
545 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
546 struct lpfc_hba
*phba
= vport
->phba
;
549 if (lpfc_get_hba_info(phba
, &cnt
, &acnt
, NULL
, NULL
, NULL
, NULL
))
550 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
551 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
555 lpfc_max_vpi_show(struct class_device
*cdev
, char *buf
)
557 struct Scsi_Host
*shost
= class_to_shost(cdev
);
558 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
559 struct lpfc_hba
*phba
= vport
->phba
;
562 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, NULL
))
563 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
564 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
568 lpfc_used_vpi_show(struct class_device
*cdev
, char *buf
)
570 struct Scsi_Host
*shost
= class_to_shost(cdev
);
571 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
572 struct lpfc_hba
*phba
= vport
->phba
;
575 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, &acnt
))
576 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
577 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
581 lpfc_npiv_info_show(struct class_device
*cdev
, char *buf
)
583 struct Scsi_Host
*shost
= class_to_shost(cdev
);
584 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
585 struct lpfc_hba
*phba
= vport
->phba
;
587 if (!(phba
->max_vpi
))
588 return snprintf(buf
, PAGE_SIZE
, "NPIV Not Supported\n");
589 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
590 return snprintf(buf
, PAGE_SIZE
, "NPIV Physical\n");
591 return snprintf(buf
, PAGE_SIZE
, "NPIV Virtual (VPI %d)\n", vport
->vpi
);
595 lpfc_poll_show(struct class_device
*cdev
, char *buf
)
597 struct Scsi_Host
*shost
= class_to_shost(cdev
);
598 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
599 struct lpfc_hba
*phba
= vport
->phba
;
601 return snprintf(buf
, PAGE_SIZE
, "%#x\n", phba
->cfg_poll
);
605 lpfc_poll_store(struct class_device
*cdev
, const char *buf
,
608 struct Scsi_Host
*shost
= class_to_shost(cdev
);
609 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
610 struct lpfc_hba
*phba
= vport
->phba
;
615 if (!isdigit(buf
[0]))
618 if (sscanf(buf
, "%i", &val
) != 1)
621 if ((val
& 0x3) != val
)
624 spin_lock_irq(&phba
->hbalock
);
626 old_val
= phba
->cfg_poll
;
628 if (val
& ENABLE_FCP_RING_POLLING
) {
629 if ((val
& DISABLE_FCP_RING_INT
) &&
630 !(old_val
& DISABLE_FCP_RING_INT
)) {
631 creg_val
= readl(phba
->HCregaddr
);
632 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
633 writel(creg_val
, phba
->HCregaddr
);
634 readl(phba
->HCregaddr
); /* flush */
636 lpfc_poll_start_timer(phba
);
638 } else if (val
!= 0x0) {
639 spin_unlock_irq(&phba
->hbalock
);
643 if (!(val
& DISABLE_FCP_RING_INT
) &&
644 (old_val
& DISABLE_FCP_RING_INT
))
646 spin_unlock_irq(&phba
->hbalock
);
647 del_timer(&phba
->fcp_poll_timer
);
648 spin_lock_irq(&phba
->hbalock
);
649 creg_val
= readl(phba
->HCregaddr
);
650 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
651 writel(creg_val
, phba
->HCregaddr
);
652 readl(phba
->HCregaddr
); /* flush */
655 phba
->cfg_poll
= val
;
657 spin_unlock_irq(&phba
->hbalock
);
662 #define lpfc_param_show(attr) \
664 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
666 struct Scsi_Host *shost = class_to_shost(cdev);\
667 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
668 struct lpfc_hba *phba = vport->phba;\
670 val = phba->cfg_##attr;\
671 return snprintf(buf, PAGE_SIZE, "%d\n",\
675 #define lpfc_param_hex_show(attr) \
677 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
679 struct Scsi_Host *shost = class_to_shost(cdev);\
680 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
681 struct lpfc_hba *phba = vport->phba;\
683 val = phba->cfg_##attr;\
684 return snprintf(buf, PAGE_SIZE, "%#x\n",\
688 #define lpfc_param_init(attr, default, minval, maxval) \
690 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
692 if (val >= minval && val <= maxval) {\
693 phba->cfg_##attr = val;\
696 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
697 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
698 "allowed range is ["#minval", "#maxval"]\n", \
699 phba->brd_no, val); \
700 phba->cfg_##attr = default;\
704 #define lpfc_param_set(attr, default, minval, maxval) \
706 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
708 if (val >= minval && val <= maxval) {\
709 phba->cfg_##attr = val;\
712 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
713 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
714 "allowed range is ["#minval", "#maxval"]\n", \
715 phba->brd_no, val); \
719 #define lpfc_param_store(attr) \
721 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
723 struct Scsi_Host *shost = class_to_shost(cdev);\
724 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
725 struct lpfc_hba *phba = vport->phba;\
727 if (!isdigit(buf[0]))\
729 if (sscanf(buf, "%i", &val) != 1)\
731 if (lpfc_##attr##_set(phba, val) == 0) \
737 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
738 static int lpfc_##name = defval;\
739 module_param(lpfc_##name, int, 0);\
740 MODULE_PARM_DESC(lpfc_##name, desc);\
741 lpfc_param_init(name, defval, minval, maxval)
743 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
744 static int lpfc_##name = defval;\
745 module_param(lpfc_##name, int, 0);\
746 MODULE_PARM_DESC(lpfc_##name, desc);\
747 lpfc_param_show(name)\
748 lpfc_param_init(name, defval, minval, maxval)\
749 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
751 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
752 static int lpfc_##name = defval;\
753 module_param(lpfc_##name, int, 0);\
754 MODULE_PARM_DESC(lpfc_##name, desc);\
755 lpfc_param_show(name)\
756 lpfc_param_init(name, defval, minval, maxval)\
757 lpfc_param_set(name, defval, minval, maxval)\
758 lpfc_param_store(name)\
759 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
760 lpfc_##name##_show, lpfc_##name##_store)
762 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
763 static int lpfc_##name = defval;\
764 module_param(lpfc_##name, int, 0);\
765 MODULE_PARM_DESC(lpfc_##name, desc);\
766 lpfc_param_hex_show(name)\
767 lpfc_param_init(name, defval, minval, maxval)\
768 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
770 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
771 static int lpfc_##name = defval;\
772 module_param(lpfc_##name, int, 0);\
773 MODULE_PARM_DESC(lpfc_##name, desc);\
774 lpfc_param_hex_show(name)\
775 lpfc_param_init(name, defval, minval, maxval)\
776 lpfc_param_set(name, defval, minval, maxval)\
777 lpfc_param_store(name)\
778 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
779 lpfc_##name##_show, lpfc_##name##_store)
781 static CLASS_DEVICE_ATTR(info
, S_IRUGO
, lpfc_info_show
, NULL
);
782 static CLASS_DEVICE_ATTR(serialnum
, S_IRUGO
, lpfc_serialnum_show
, NULL
);
783 static CLASS_DEVICE_ATTR(modeldesc
, S_IRUGO
, lpfc_modeldesc_show
, NULL
);
784 static CLASS_DEVICE_ATTR(modelname
, S_IRUGO
, lpfc_modelname_show
, NULL
);
785 static CLASS_DEVICE_ATTR(programtype
, S_IRUGO
, lpfc_programtype_show
, NULL
);
786 static CLASS_DEVICE_ATTR(portnum
, S_IRUGO
, lpfc_vportnum_show
, NULL
);
787 static CLASS_DEVICE_ATTR(fwrev
, S_IRUGO
, lpfc_fwrev_show
, NULL
);
788 static CLASS_DEVICE_ATTR(hdw
, S_IRUGO
, lpfc_hdw_show
, NULL
);
789 static CLASS_DEVICE_ATTR(state
, S_IRUGO
, lpfc_state_show
, NULL
);
790 static CLASS_DEVICE_ATTR(option_rom_version
, S_IRUGO
,
791 lpfc_option_rom_version_show
, NULL
);
792 static CLASS_DEVICE_ATTR(num_discovered_ports
, S_IRUGO
,
793 lpfc_num_discovered_ports_show
, NULL
);
794 static CLASS_DEVICE_ATTR(nport_evt_cnt
, S_IRUGO
, lpfc_nport_evt_cnt_show
, NULL
);
795 static CLASS_DEVICE_ATTR(lpfc_drvr_version
, S_IRUGO
, lpfc_drvr_version_show
,
797 static CLASS_DEVICE_ATTR(management_version
, S_IRUGO
, management_version_show
,
799 static CLASS_DEVICE_ATTR(board_mode
, S_IRUGO
| S_IWUSR
,
800 lpfc_board_mode_show
, lpfc_board_mode_store
);
801 static CLASS_DEVICE_ATTR(issue_reset
, S_IWUSR
, NULL
, lpfc_issue_reset
);
802 static CLASS_DEVICE_ATTR(max_vpi
, S_IRUGO
, lpfc_max_vpi_show
, NULL
);
803 static CLASS_DEVICE_ATTR(used_vpi
, S_IRUGO
, lpfc_used_vpi_show
, NULL
);
804 static CLASS_DEVICE_ATTR(max_rpi
, S_IRUGO
, lpfc_max_rpi_show
, NULL
);
805 static CLASS_DEVICE_ATTR(used_rpi
, S_IRUGO
, lpfc_used_rpi_show
, NULL
);
806 static CLASS_DEVICE_ATTR(max_xri
, S_IRUGO
, lpfc_max_xri_show
, NULL
);
807 static CLASS_DEVICE_ATTR(used_xri
, S_IRUGO
, lpfc_used_xri_show
, NULL
);
808 static CLASS_DEVICE_ATTR(npiv_info
, S_IRUGO
, lpfc_npiv_info_show
, NULL
);
811 static char *lpfc_soft_wwn_key
= "C99G71SL8032A";
814 lpfc_soft_wwn_enable_store(struct class_device
*cdev
, const char *buf
,
817 struct Scsi_Host
*shost
= class_to_shost(cdev
);
818 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
819 struct lpfc_hba
*phba
= vport
->phba
;
820 unsigned int cnt
= count
;
823 * We're doing a simple sanity check for soft_wwpn setting.
824 * We require that the user write a specific key to enable
825 * the soft_wwpn attribute to be settable. Once the attribute
826 * is written, the enable key resets. If further updates are
827 * desired, the key must be written again to re-enable the
830 * The "key" is not secret - it is a hardcoded string shown
831 * here. The intent is to protect against the random user or
832 * application that is just writing attributes.
835 /* count may include a LF at end of string */
836 if (buf
[cnt
-1] == '\n')
839 if ((cnt
!= strlen(lpfc_soft_wwn_key
)) ||
840 (strncmp(buf
, lpfc_soft_wwn_key
, strlen(lpfc_soft_wwn_key
)) != 0))
843 phba
->soft_wwn_enable
= 1;
846 static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable
, S_IWUSR
, NULL
,
847 lpfc_soft_wwn_enable_store
);
850 lpfc_soft_wwpn_show(struct class_device
*cdev
, char *buf
)
852 struct Scsi_Host
*shost
= class_to_shost(cdev
);
853 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
854 struct lpfc_hba
*phba
= vport
->phba
;
856 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n",
857 (unsigned long long)phba
->cfg_soft_wwpn
);
862 lpfc_soft_wwpn_store(struct class_device
*cdev
, const char *buf
, size_t count
)
864 struct Scsi_Host
*shost
= class_to_shost(cdev
);
865 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
866 struct lpfc_hba
*phba
= vport
->phba
;
867 struct completion online_compl
;
868 int stat1
=0, stat2
=0;
869 unsigned int i
, j
, cnt
=count
;
872 /* count may include a LF at end of string */
873 if (buf
[cnt
-1] == '\n')
876 if (!phba
->soft_wwn_enable
|| (cnt
< 16) || (cnt
> 18) ||
877 ((cnt
== 17) && (*buf
++ != 'x')) ||
878 ((cnt
== 18) && ((*buf
++ != '0') || (*buf
++ != 'x'))))
881 phba
->soft_wwn_enable
= 0;
883 memset(wwpn
, 0, sizeof(wwpn
));
885 /* Validate and store the new name */
886 for (i
=0, j
=0; i
< 16; i
++) {
887 if ((*buf
>= 'a') && (*buf
<= 'f'))
888 j
= ((j
<< 4) | ((*buf
++ -'a') + 10));
889 else if ((*buf
>= 'A') && (*buf
<= 'F'))
890 j
= ((j
<< 4) | ((*buf
++ -'A') + 10));
891 else if ((*buf
>= '0') && (*buf
<= '9'))
892 j
= ((j
<< 4) | (*buf
++ -'0'));
896 wwpn
[i
/2] = j
& 0xff;
900 phba
->cfg_soft_wwpn
= wwn_to_u64(wwpn
);
901 fc_host_port_name(shost
) = phba
->cfg_soft_wwpn
;
902 if (phba
->cfg_soft_wwnn
)
903 fc_host_node_name(shost
) = phba
->cfg_soft_wwnn
;
905 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
906 "lpfc%d: Reinitializing to use soft_wwpn\n", phba
->brd_no
);
908 stat1
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
910 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
911 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
912 "adapter - %d\n", phba
->brd_no
, stat1
);
914 init_completion(&online_compl
);
915 lpfc_workq_post_event(phba
, &stat2
, &online_compl
, LPFC_EVT_ONLINE
);
916 wait_for_completion(&online_compl
);
918 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
919 "%d:0464 lpfc_soft_wwpn attribute set failed to reinit "
920 "adapter - %d\n", phba
->brd_no
, stat2
);
922 return (stat1
|| stat2
) ? -EIO
: count
;
924 static CLASS_DEVICE_ATTR(lpfc_soft_wwpn
, S_IRUGO
| S_IWUSR
,\
925 lpfc_soft_wwpn_show
, lpfc_soft_wwpn_store
);
928 lpfc_soft_wwnn_show(struct class_device
*cdev
, char *buf
)
930 struct Scsi_Host
*host
= class_to_shost(cdev
);
931 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
932 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n",
933 (unsigned long long)phba
->cfg_soft_wwnn
);
938 lpfc_soft_wwnn_store(struct class_device
*cdev
, const char *buf
, size_t count
)
940 struct Scsi_Host
*host
= class_to_shost(cdev
);
941 struct lpfc_hba
*phba
= (struct lpfc_hba
*)host
->hostdata
;
942 unsigned int i
, j
, cnt
=count
;
945 /* count may include a LF at end of string */
946 if (buf
[cnt
-1] == '\n')
949 if (!phba
->soft_wwn_enable
|| (cnt
< 16) || (cnt
> 18) ||
950 ((cnt
== 17) && (*buf
++ != 'x')) ||
951 ((cnt
== 18) && ((*buf
++ != '0') || (*buf
++ != 'x'))))
955 * Allow wwnn to be set many times, as long as the enable is set.
956 * However, once the wwpn is set, everything locks.
959 memset(wwnn
, 0, sizeof(wwnn
));
961 /* Validate and store the new name */
962 for (i
=0, j
=0; i
< 16; i
++) {
963 if ((*buf
>= 'a') && (*buf
<= 'f'))
964 j
= ((j
<< 4) | ((*buf
++ -'a') + 10));
965 else if ((*buf
>= 'A') && (*buf
<= 'F'))
966 j
= ((j
<< 4) | ((*buf
++ -'A') + 10));
967 else if ((*buf
>= '0') && (*buf
<= '9'))
968 j
= ((j
<< 4) | (*buf
++ -'0'));
972 wwnn
[i
/2] = j
& 0xff;
976 phba
->cfg_soft_wwnn
= wwn_to_u64(wwnn
);
978 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
979 "lpfc%d: soft_wwnn set. Value will take effect upon "
980 "setting of the soft_wwpn\n", phba
->brd_no
);
984 static CLASS_DEVICE_ATTR(lpfc_soft_wwnn
, S_IRUGO
| S_IWUSR
,\
985 lpfc_soft_wwnn_show
, lpfc_soft_wwnn_store
);
988 static int lpfc_poll
= 0;
989 module_param(lpfc_poll
, int, 0);
990 MODULE_PARM_DESC(lpfc_poll
, "FCP ring polling mode control:"
992 " 1 - poll with interrupts enabled"
993 " 3 - poll and disable FCP ring interrupts");
995 static CLASS_DEVICE_ATTR(lpfc_poll
, S_IRUGO
| S_IWUSR
,
996 lpfc_poll_show
, lpfc_poll_store
);
998 int lpfc_sli_mode
= 0;
999 module_param(lpfc_sli_mode
, int, 0);
1000 MODULE_PARM_DESC(lpfc_sli_mode
, "SLI mode selector:"
1001 " 0 - auto (SLI-3 if supported),"
1002 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1003 " 3 - select SLI-3");
1005 LPFC_ATTR_R(npiv_enable
, 0, 0, 1, "Enable NPIV functionality");
1008 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1009 # until the timer expires. Value range is [0,255]. Default value is 30.
1011 static int lpfc_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
1012 static int lpfc_devloss_tmo
= LPFC_DEF_DEVLOSS_TMO
;
1013 module_param(lpfc_nodev_tmo
, int, 0);
1014 MODULE_PARM_DESC(lpfc_nodev_tmo
,
1015 "Seconds driver will hold I/O waiting "
1016 "for a device to come back");
1018 lpfc_nodev_tmo_show(struct class_device
*cdev
, char *buf
)
1020 struct Scsi_Host
*shost
= class_to_shost(cdev
);
1021 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1022 struct lpfc_hba
*phba
= vport
->phba
;
1024 val
= phba
->cfg_devloss_tmo
;
1025 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1026 phba
->cfg_devloss_tmo
);
1030 lpfc_nodev_tmo_init(struct lpfc_hba
*phba
, int val
)
1033 if (phba
->cfg_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
) {
1034 phba
->cfg_nodev_tmo
= phba
->cfg_devloss_tmo
;
1035 if (!warned
&& val
!= LPFC_DEF_DEVLOSS_TMO
) {
1037 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1038 "%d:0402 Ignoring nodev_tmo module "
1039 "parameter because devloss_tmo is"
1046 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
1047 phba
->cfg_nodev_tmo
= val
;
1048 phba
->cfg_devloss_tmo
= val
;
1051 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1052 "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, "
1053 "allowed range is [%d, %d]\n",
1055 LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
1056 phba
->cfg_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
1061 lpfc_update_rport_devloss_tmo(struct lpfc_hba
*phba
)
1063 struct lpfc_vport
**vports
;
1064 struct Scsi_Host
*shost
;
1065 struct lpfc_nodelist
*ndlp
;
1068 vports
= lpfc_create_vport_work_array(phba
);
1070 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++) {
1071 shost
= lpfc_shost_from_vport(vports
[i
]);
1072 spin_lock_irq(shost
->host_lock
);
1073 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
,
1076 ndlp
->rport
->dev_loss_tmo
=
1077 phba
->cfg_devloss_tmo
;
1078 spin_unlock_irq(shost
->host_lock
);
1080 lpfc_destroy_vport_work_array(vports
);
1084 lpfc_nodev_tmo_set(struct lpfc_hba
*phba
, int val
)
1086 if (phba
->dev_loss_tmo_changed
||
1087 (lpfc_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
)) {
1088 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1089 "%d:0401 Ignoring change to nodev_tmo "
1090 "because devloss_tmo is set.\n",
1095 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
1096 phba
->cfg_nodev_tmo
= val
;
1097 phba
->cfg_devloss_tmo
= val
;
1098 lpfc_update_rport_devloss_tmo(phba
);
1102 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1103 "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, "
1104 "allowed range is [%d, %d]\n",
1105 phba
->brd_no
, val
, LPFC_MIN_DEVLOSS_TMO
,
1106 LPFC_MAX_DEVLOSS_TMO
);
1110 lpfc_param_store(nodev_tmo
)
1112 static CLASS_DEVICE_ATTR(lpfc_nodev_tmo
, S_IRUGO
| S_IWUSR
,
1113 lpfc_nodev_tmo_show
, lpfc_nodev_tmo_store
);
1116 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1117 # disappear until the timer expires. Value range is [0,255]. Default
1120 module_param(lpfc_devloss_tmo
, int, 0);
1121 MODULE_PARM_DESC(lpfc_devloss_tmo
,
1122 "Seconds driver will hold I/O waiting "
1123 "for a device to come back");
1124 lpfc_param_init(devloss_tmo
, LPFC_DEF_DEVLOSS_TMO
,
1125 LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
)
1126 lpfc_param_show(devloss_tmo
)
1128 lpfc_devloss_tmo_set(struct lpfc_hba
*phba
, int val
)
1130 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
1131 phba
->cfg_nodev_tmo
= val
;
1132 phba
->cfg_devloss_tmo
= val
;
1133 phba
->dev_loss_tmo_changed
= 1;
1134 lpfc_update_rport_devloss_tmo(phba
);
1138 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1139 "%d:0404 lpfc_devloss_tmo attribute cannot be set to"
1140 " %d, allowed range is [%d, %d]\n",
1141 phba
->brd_no
, val
, LPFC_MIN_DEVLOSS_TMO
,
1142 LPFC_MAX_DEVLOSS_TMO
);
1146 lpfc_param_store(devloss_tmo
)
1147 static CLASS_DEVICE_ATTR(lpfc_devloss_tmo
, S_IRUGO
| S_IWUSR
,
1148 lpfc_devloss_tmo_show
, lpfc_devloss_tmo_store
);
1151 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1152 # deluged with LOTS of information.
1153 # You can set a bit mask to record specific types of verbose messages:
1155 # LOG_ELS 0x1 ELS events
1156 # LOG_DISCOVERY 0x2 Link discovery events
1157 # LOG_MBOX 0x4 Mailbox events
1158 # LOG_INIT 0x8 Initialization events
1159 # LOG_LINK_EVENT 0x10 Link events
1160 # LOG_FCP 0x40 FCP traffic history
1161 # LOG_NODE 0x80 Node table events
1162 # LOG_MISC 0x400 Miscellaneous events
1163 # LOG_SLI 0x800 SLI events
1164 # LOG_FCP_ERROR 0x1000 Only log FCP errors
1165 # LOG_LIBDFC 0x2000 LIBDFC events
1166 # LOG_ALL_MSG 0xffff LOG all messages
1168 LPFC_ATTR_HEX_RW(log_verbose
, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
1171 # lun_queue_depth: This parameter is used to limit the number of outstanding
1172 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
1174 LPFC_ATTR_R(lun_queue_depth
, 30, 1, 128,
1175 "Max number of FCP commands we can queue to a specific LUN");
1178 # hba_queue_depth: This parameter is used to limit the number of outstanding
1179 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
1180 # value is greater than the maximum number of exchanges supported by the HBA,
1181 # then maximum number of exchanges supported by the HBA is used to determine
1182 # the hba_queue_depth.
1184 LPFC_ATTR_R(hba_queue_depth
, 8192, 32, 8192,
1185 "Max number of FCP commands we can queue to a lpfc HBA");
1188 # peer_port_login: This parameter allows/prevents logins
1189 # between peer ports hosted on the same physical port.
1190 # When this parameter is set 0 peer ports of same physical port
1191 # are not allowed to login to each other.
1192 # When this parameter is set 1 peer ports of same physical port
1193 # are allowed to login to each other.
1194 # Default value of this parameter is 0.
1196 LPFC_ATTR_R(peer_port_login
, 0, 0, 1,
1197 "Allow peer ports on the same physical port to login to each "
1201 # vport_restrict_login: This parameter allows/prevents logins
1202 # between Virtual Ports and remote initiators.
1203 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1204 # other initiators and will attempt to PLOGI all remote ports.
1205 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
1206 # remote ports and will not attempt to PLOGI to other initiators.
1207 # This parameter does not restrict to the physical port.
1208 # This parameter does not restrict logins to Fabric resident remote ports.
1209 # Default value of this parameter is 1.
1211 LPFC_ATTR_RW(vport_restrict_login
, 1, 0, 1,
1212 "Restrict virtual ports login to remote initiators.");
1215 # Some disk devices have a "select ID" or "select Target" capability.
1216 # From a protocol standpoint "select ID" usually means select the
1217 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1218 # annex" which contains a table that maps a "select ID" (a number
1219 # between 0 and 7F) to an ALPA. By default, for compatibility with
1220 # older drivers, the lpfc driver scans this table from low ALPA to high
1223 # Turning on the scan-down variable (on = 1, off = 0) will
1224 # cause the lpfc driver to use an inverted table, effectively
1225 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1227 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
1228 # and will not work across a fabric. Also this parameter will take
1229 # effect only in the case when ALPA map is not available.)
1231 LPFC_ATTR_R(scan_down
, 1, 0, 1,
1232 "Start scanning for devices from highest ALPA to lowest");
1235 # lpfc_topology: link topology for init link
1236 # 0x0 = attempt loop mode then point-to-point
1237 # 0x01 = internal loopback mode
1238 # 0x02 = attempt point-to-point mode only
1239 # 0x04 = attempt loop mode only
1240 # 0x06 = attempt point-to-point mode then loop
1241 # Set point-to-point mode if you want to run as an N_Port.
1242 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1243 # Default value is 0.
1245 LPFC_ATTR_RW(topology
, 0, 0, 6, "Select Fibre Channel topology");
1248 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1250 # 0 = auto select (default)
1255 # Value range is [0,8]. Default value is 0.
1257 LPFC_ATTR_R(link_speed
, 0, 0, 8, "Select link speed");
1260 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1261 # Value range is [2,3]. Default value is 3.
1263 LPFC_ATTR_R(fcp_class
, 3, 2, 3,
1264 "Select Fibre Channel class of service for FCP sequences");
1267 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1268 # is [0,1]. Default value is 0.
1270 LPFC_ATTR_RW(use_adisc
, 0, 0, 1,
1271 "Use ADISC on rediscovery to authenticate FCP devices");
1274 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1275 # range is [0,1]. Default value is 0.
1277 LPFC_ATTR_R(ack0
, 0, 0, 1, "Enable ACK0 support");
1280 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1281 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
1282 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
1283 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1284 # cr_delay is set to 0.
1286 LPFC_ATTR_RW(cr_delay
, 0, 0, 63, "A count of milliseconds after which an "
1287 "interrupt response is generated");
1289 LPFC_ATTR_RW(cr_count
, 1, 1, 255, "A count of I/O completions after which an "
1290 "interrupt response is generated");
1293 # lpfc_multi_ring_support: Determines how many rings to spread available
1294 # cmd/rsp IOCB entries across.
1295 # Value range is [1,2]. Default value is 1.
1297 LPFC_ATTR_R(multi_ring_support
, 1, 1, 2, "Determines number of primary "
1298 "SLI rings to spread IOCB entries across");
1301 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1302 # identifies what rctl value to configure the additional ring for.
1303 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1305 LPFC_ATTR_R(multi_ring_rctl
, FC_UNSOL_DATA
, 1,
1306 255, "Identifies RCTL for additional ring configuration");
1309 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1310 # identifies what type value to configure the additional ring for.
1311 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1313 LPFC_ATTR_R(multi_ring_type
, FC_LLC_SNAP
, 1,
1314 255, "Identifies TYPE for additional ring configuration");
1317 # lpfc_fdmi_on: controls FDMI support.
1318 # 0 = no FDMI support
1319 # 1 = support FDMI without attribute of hostname
1320 # 2 = support FDMI with attribute of hostname
1321 # Value range [0,2]. Default value is 0.
1323 LPFC_ATTR_RW(fdmi_on
, 0, 0, 2, "Enable FDMI support");
1326 # Specifies the maximum number of ELS cmds we can have outstanding (for
1327 # discovery). Value range is [1,64]. Default value = 32.
1329 LPFC_ATTR(discovery_threads
, 32, 1, 64, "Maximum number of ELS commands "
1330 "during discovery");
1333 # lpfc_max_luns: maximum allowed LUN.
1334 # Value range is [0,65535]. Default value is 255.
1335 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
1337 LPFC_ATTR_R(max_luns
, 255, 0, 65535,
1338 "Maximum allowed LUN");
1341 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1342 # Value range is [1,255], default value is 10.
1344 LPFC_ATTR_RW(poll_tmo
, 10, 1, 255,
1345 "Milliseconds driver will wait between polling FCP ring");
1348 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1349 # support this feature
1350 # 0 = MSI disabled (default)
1352 # Value range is [0,1]. Default value is 0.
1354 LPFC_ATTR_R(use_msi
, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1358 struct class_device_attribute
*lpfc_hba_attrs
[] = {
1359 &class_device_attr_info
,
1360 &class_device_attr_serialnum
,
1361 &class_device_attr_modeldesc
,
1362 &class_device_attr_modelname
,
1363 &class_device_attr_programtype
,
1364 &class_device_attr_portnum
,
1365 &class_device_attr_fwrev
,
1366 &class_device_attr_hdw
,
1367 &class_device_attr_option_rom_version
,
1368 &class_device_attr_state
,
1369 &class_device_attr_num_discovered_ports
,
1370 &class_device_attr_lpfc_drvr_version
,
1371 &class_device_attr_lpfc_log_verbose
,
1372 &class_device_attr_lpfc_lun_queue_depth
,
1373 &class_device_attr_lpfc_hba_queue_depth
,
1374 &class_device_attr_lpfc_peer_port_login
,
1375 &class_device_attr_lpfc_vport_restrict_login
,
1376 &class_device_attr_lpfc_nodev_tmo
,
1377 &class_device_attr_lpfc_devloss_tmo
,
1378 &class_device_attr_lpfc_fcp_class
,
1379 &class_device_attr_lpfc_use_adisc
,
1380 &class_device_attr_lpfc_ack0
,
1381 &class_device_attr_lpfc_topology
,
1382 &class_device_attr_lpfc_scan_down
,
1383 &class_device_attr_lpfc_link_speed
,
1384 &class_device_attr_lpfc_cr_delay
,
1385 &class_device_attr_lpfc_cr_count
,
1386 &class_device_attr_lpfc_multi_ring_support
,
1387 &class_device_attr_lpfc_multi_ring_rctl
,
1388 &class_device_attr_lpfc_multi_ring_type
,
1389 &class_device_attr_lpfc_fdmi_on
,
1390 &class_device_attr_lpfc_max_luns
,
1391 &class_device_attr_lpfc_npiv_enable
,
1392 &class_device_attr_nport_evt_cnt
,
1393 &class_device_attr_management_version
,
1394 &class_device_attr_board_mode
,
1395 &class_device_attr_max_vpi
,
1396 &class_device_attr_used_vpi
,
1397 &class_device_attr_max_rpi
,
1398 &class_device_attr_used_rpi
,
1399 &class_device_attr_max_xri
,
1400 &class_device_attr_used_xri
,
1401 &class_device_attr_npiv_info
,
1402 &class_device_attr_issue_reset
,
1403 &class_device_attr_lpfc_poll
,
1404 &class_device_attr_lpfc_poll_tmo
,
1405 &class_device_attr_lpfc_use_msi
,
1406 &class_device_attr_lpfc_soft_wwnn
,
1407 &class_device_attr_lpfc_soft_wwpn
,
1408 &class_device_attr_lpfc_soft_wwn_enable
,
1413 sysfs_ctlreg_write(struct kobject
*kobj
, struct bin_attribute
*bin_attr
,
1414 char *buf
, loff_t off
, size_t count
)
1417 struct class_device
*cdev
= container_of(kobj
, struct class_device
,
1419 struct Scsi_Host
*shost
= class_to_shost(cdev
);
1420 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1421 struct lpfc_hba
*phba
= vport
->phba
;
1423 if ((off
+ count
) > FF_REG_AREA_SIZE
)
1426 if (count
== 0) return 0;
1428 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
1431 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
1435 spin_lock_irq(&phba
->hbalock
);
1436 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t))
1437 writel(*((uint32_t *)(buf
+ buf_off
)),
1438 phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
1440 spin_unlock_irq(&phba
->hbalock
);
1446 sysfs_ctlreg_read(struct kobject
*kobj
, struct bin_attribute
*bin_attr
,
1447 char *buf
, loff_t off
, size_t count
)
1451 struct class_device
*cdev
= container_of(kobj
, struct class_device
,
1453 struct Scsi_Host
*shost
= class_to_shost(cdev
);
1454 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1455 struct lpfc_hba
*phba
= vport
->phba
;
1457 if (off
> FF_REG_AREA_SIZE
)
1460 if ((off
+ count
) > FF_REG_AREA_SIZE
)
1461 count
= FF_REG_AREA_SIZE
- off
;
1463 if (count
== 0) return 0;
1465 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
1468 spin_lock_irq(&phba
->hbalock
);
1470 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t)) {
1471 tmp_ptr
= (uint32_t *)(buf
+ buf_off
);
1472 *tmp_ptr
= readl(phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
1475 spin_unlock_irq(&phba
->hbalock
);
1480 static struct bin_attribute sysfs_ctlreg_attr
= {
1483 .mode
= S_IRUSR
| S_IWUSR
,
1486 .read
= sysfs_ctlreg_read
,
1487 .write
= sysfs_ctlreg_write
,
1492 sysfs_mbox_idle(struct lpfc_hba
*phba
)
1494 phba
->sysfs_mbox
.state
= SMBOX_IDLE
;
1495 phba
->sysfs_mbox
.offset
= 0;
1497 if (phba
->sysfs_mbox
.mbox
) {
1498 mempool_free(phba
->sysfs_mbox
.mbox
,
1499 phba
->mbox_mem_pool
);
1500 phba
->sysfs_mbox
.mbox
= NULL
;
1505 sysfs_mbox_write(struct kobject
*kobj
, struct bin_attribute
*bin_attr
,
1506 char *buf
, loff_t off
, size_t count
)
1508 struct class_device
*cdev
= container_of(kobj
, struct class_device
,
1510 struct Scsi_Host
*shost
= class_to_shost(cdev
);
1511 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1512 struct lpfc_hba
*phba
= vport
->phba
;
1513 struct lpfcMboxq
*mbox
= NULL
;
1515 if ((count
+ off
) > MAILBOX_CMD_SIZE
)
1518 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
1525 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1528 memset(mbox
, 0, sizeof (LPFC_MBOXQ_t
));
1531 spin_lock_irq(&phba
->hbalock
);
1534 if (phba
->sysfs_mbox
.mbox
)
1535 mempool_free(mbox
, phba
->mbox_mem_pool
);
1537 phba
->sysfs_mbox
.mbox
= mbox
;
1538 phba
->sysfs_mbox
.state
= SMBOX_WRITING
;
1540 if (phba
->sysfs_mbox
.state
!= SMBOX_WRITING
||
1541 phba
->sysfs_mbox
.offset
!= off
||
1542 phba
->sysfs_mbox
.mbox
== NULL
) {
1543 sysfs_mbox_idle(phba
);
1544 spin_unlock_irq(&phba
->hbalock
);
1549 memcpy((uint8_t *) & phba
->sysfs_mbox
.mbox
->mb
+ off
,
1552 phba
->sysfs_mbox
.offset
= off
+ count
;
1554 spin_unlock_irq(&phba
->hbalock
);
1560 sysfs_mbox_read(struct kobject
*kobj
, struct bin_attribute
*bin_attr
,
1561 char *buf
, loff_t off
, size_t count
)
1563 struct class_device
*cdev
= container_of(kobj
, struct class_device
,
1565 struct Scsi_Host
*shost
= class_to_shost(cdev
);
1566 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1567 struct lpfc_hba
*phba
= vport
->phba
;
1570 if (off
> MAILBOX_CMD_SIZE
)
1573 if ((count
+ off
) > MAILBOX_CMD_SIZE
)
1574 count
= MAILBOX_CMD_SIZE
- off
;
1576 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
1579 if (off
&& count
== 0)
1582 spin_lock_irq(&phba
->hbalock
);
1585 phba
->sysfs_mbox
.state
== SMBOX_WRITING
&&
1586 phba
->sysfs_mbox
.offset
>= 2 * sizeof(uint32_t)) {
1588 switch (phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
) {
1593 case MBX_CONFIG_LINK
:
1594 case MBX_CONFIG_RING
:
1595 case MBX_RESET_RING
:
1596 case MBX_UNREG_LOGIN
:
1598 case MBX_DUMP_CONTEXT
:
1601 case MBX_FLASH_WR_ULA
:
1605 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
1606 printk(KERN_WARNING
"mbox_read:Command 0x%x "
1607 "is illegal in on-line state\n",
1608 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
1609 sysfs_mbox_idle(phba
);
1610 spin_unlock_irq(&phba
->hbalock
);
1615 case MBX_READ_CONFIG
:
1616 case MBX_READ_RCONFIG
:
1617 case MBX_READ_STATUS
:
1620 case MBX_READ_LNK_STAT
:
1621 case MBX_DUMP_MEMORY
:
1623 case MBX_UPDATE_CFG
:
1624 case MBX_KILL_BOARD
:
1626 case MBX_LOAD_EXP_ROM
:
1628 case MBX_DEL_LD_ENTRY
:
1630 case MBX_READ_SPARM64
:
1634 case MBX_REG_LOGIN64
:
1635 case MBX_CONFIG_PORT
:
1636 case MBX_RUN_BIU_DIAG
:
1637 printk(KERN_WARNING
"mbox_read: Illegal Command 0x%x\n",
1638 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
1639 sysfs_mbox_idle(phba
);
1640 spin_unlock_irq(&phba
->hbalock
);
1643 printk(KERN_WARNING
"mbox_read: Unknown Command 0x%x\n",
1644 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
1645 sysfs_mbox_idle(phba
);
1646 spin_unlock_irq(&phba
->hbalock
);
1650 phba
->sysfs_mbox
.mbox
->vport
= vport
;
1652 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
1653 sysfs_mbox_idle(phba
);
1654 spin_unlock_irq(&phba
->hbalock
);
1658 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
1659 (!(phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
))){
1661 spin_unlock_irq(&phba
->hbalock
);
1662 rc
= lpfc_sli_issue_mbox (phba
,
1663 phba
->sysfs_mbox
.mbox
,
1665 spin_lock_irq(&phba
->hbalock
);
1668 spin_unlock_irq(&phba
->hbalock
);
1669 rc
= lpfc_sli_issue_mbox_wait (phba
,
1670 phba
->sysfs_mbox
.mbox
,
1671 lpfc_mbox_tmo_val(phba
,
1672 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
) * HZ
);
1673 spin_lock_irq(&phba
->hbalock
);
1676 if (rc
!= MBX_SUCCESS
) {
1677 if (rc
== MBX_TIMEOUT
) {
1678 phba
->sysfs_mbox
.mbox
= NULL
;
1680 sysfs_mbox_idle(phba
);
1681 spin_unlock_irq(&phba
->hbalock
);
1682 return (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
1684 phba
->sysfs_mbox
.state
= SMBOX_READING
;
1686 else if (phba
->sysfs_mbox
.offset
!= off
||
1687 phba
->sysfs_mbox
.state
!= SMBOX_READING
) {
1688 printk(KERN_WARNING
"mbox_read: Bad State\n");
1689 sysfs_mbox_idle(phba
);
1690 spin_unlock_irq(&phba
->hbalock
);
1694 memcpy(buf
, (uint8_t *) & phba
->sysfs_mbox
.mbox
->mb
+ off
, count
);
1696 phba
->sysfs_mbox
.offset
= off
+ count
;
1698 if (phba
->sysfs_mbox
.offset
== MAILBOX_CMD_SIZE
)
1699 sysfs_mbox_idle(phba
);
1701 spin_unlock_irq(&phba
->hbalock
);
1706 static struct bin_attribute sysfs_mbox_attr
= {
1709 .mode
= S_IRUSR
| S_IWUSR
,
1711 .size
= MAILBOX_CMD_SIZE
,
1712 .read
= sysfs_mbox_read
,
1713 .write
= sysfs_mbox_write
,
1717 lpfc_alloc_sysfs_attr(struct lpfc_vport
*vport
)
1719 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1722 error
= sysfs_create_bin_file(&shost
->shost_classdev
.kobj
,
1723 &sysfs_ctlreg_attr
);
1727 error
= sysfs_create_bin_file(&shost
->shost_classdev
.kobj
,
1730 goto out_remove_ctlreg_attr
;
1733 out_remove_ctlreg_attr
:
1734 sysfs_remove_bin_file(&shost
->shost_classdev
.kobj
, &sysfs_ctlreg_attr
);
1740 lpfc_free_sysfs_attr(struct lpfc_vport
*vport
)
1742 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1744 sysfs_remove_bin_file(&shost
->shost_classdev
.kobj
, &sysfs_mbox_attr
);
1745 sysfs_remove_bin_file(&shost
->shost_classdev
.kobj
, &sysfs_ctlreg_attr
);
1750 * Dynamic FC Host Attributes Support
1754 lpfc_get_host_port_id(struct Scsi_Host
*shost
)
1756 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1758 /* note: fc_myDID already in cpu endianness */
1759 fc_host_port_id(shost
) = vport
->fc_myDID
;
1763 lpfc_get_host_port_type(struct Scsi_Host
*shost
)
1765 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1766 struct lpfc_hba
*phba
= vport
->phba
;
1768 spin_lock_irq(shost
->host_lock
);
1770 if (vport
->port_type
== LPFC_NPIV_PORT
) {
1771 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
1772 } else if (lpfc_is_link_up(phba
)) {
1773 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1774 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
1775 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
1777 fc_host_port_type(shost
) = FC_PORTTYPE_LPORT
;
1779 if (vport
->fc_flag
& FC_FABRIC
)
1780 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
1782 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
1785 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
1787 spin_unlock_irq(shost
->host_lock
);
1791 lpfc_get_host_port_state(struct Scsi_Host
*shost
)
1793 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1794 struct lpfc_hba
*phba
= vport
->phba
;
1796 spin_lock_irq(shost
->host_lock
);
1798 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
1799 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
1801 switch (phba
->link_state
) {
1802 case LPFC_LINK_UNKNOWN
:
1803 case LPFC_LINK_DOWN
:
1804 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
1808 case LPFC_HBA_READY
:
1809 /* Links up, beyond this port_type reports state */
1810 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
1812 case LPFC_HBA_ERROR
:
1813 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
1816 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
1821 spin_unlock_irq(shost
->host_lock
);
1825 lpfc_get_host_speed(struct Scsi_Host
*shost
)
1827 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1828 struct lpfc_hba
*phba
= vport
->phba
;
1830 spin_lock_irq(shost
->host_lock
);
1832 if (lpfc_is_link_up(phba
)) {
1833 switch(phba
->fc_linkspeed
) {
1835 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
1838 fc_host_speed(shost
) = FC_PORTSPEED_2GBIT
;
1841 fc_host_speed(shost
) = FC_PORTSPEED_4GBIT
;
1844 fc_host_speed(shost
) = FC_PORTSPEED_8GBIT
;
1847 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
1852 spin_unlock_irq(shost
->host_lock
);
1856 lpfc_get_host_fabric_name (struct Scsi_Host
*shost
)
1858 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1859 struct lpfc_hba
*phba
= vport
->phba
;
1862 spin_lock_irq(shost
->host_lock
);
1864 if ((vport
->fc_flag
& FC_FABRIC
) ||
1865 ((phba
->fc_topology
== TOPOLOGY_LOOP
) &&
1866 (vport
->fc_flag
& FC_PUBLIC_LOOP
)))
1867 node_name
= wwn_to_u64(phba
->fc_fabparam
.nodeName
.u
.wwn
);
1869 /* fabric is local port if there is no F/FL_Port */
1870 node_name
= wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
1872 spin_unlock_irq(shost
->host_lock
);
1874 fc_host_fabric_name(shost
) = node_name
;
1877 static struct fc_host_statistics
*
1878 lpfc_get_stats(struct Scsi_Host
*shost
)
1880 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1881 struct lpfc_hba
*phba
= vport
->phba
;
1882 struct lpfc_sli
*psli
= &phba
->sli
;
1883 struct fc_host_statistics
*hs
= &phba
->link_stats
;
1884 struct lpfc_lnk_stat
* lso
= &psli
->lnk_stat_offsets
;
1885 LPFC_MBOXQ_t
*pmboxq
;
1887 unsigned long seconds
;
1891 * prevent udev from issuing mailbox commands until the port is
1894 if (phba
->link_state
< LPFC_LINK_DOWN
||
1895 !phba
->mbox_mem_pool
||
1896 (phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
) == 0)
1899 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
1902 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1905 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
1908 pmb
->mbxCommand
= MBX_READ_STATUS
;
1909 pmb
->mbxOwner
= OWN_HOST
;
1910 pmboxq
->context1
= NULL
;
1911 pmboxq
->vport
= vport
;
1913 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
1914 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
1915 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
1917 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
1919 if (rc
!= MBX_SUCCESS
) {
1920 if (rc
!= MBX_TIMEOUT
)
1921 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1925 memset(hs
, 0, sizeof (struct fc_host_statistics
));
1927 hs
->tx_frames
= pmb
->un
.varRdStatus
.xmitFrameCnt
;
1928 hs
->tx_words
= (pmb
->un
.varRdStatus
.xmitByteCnt
* 256);
1929 hs
->rx_frames
= pmb
->un
.varRdStatus
.rcvFrameCnt
;
1930 hs
->rx_words
= (pmb
->un
.varRdStatus
.rcvByteCnt
* 256);
1932 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
1933 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
1934 pmb
->mbxOwner
= OWN_HOST
;
1935 pmboxq
->context1
= NULL
;
1936 pmboxq
->vport
= vport
;
1938 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
1939 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
1940 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
1942 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
1944 if (rc
!= MBX_SUCCESS
) {
1945 if (rc
!= MBX_TIMEOUT
)
1946 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1950 hs
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
1951 hs
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
1952 hs
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
1953 hs
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
1954 hs
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
1955 hs
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
1956 hs
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
1958 hs
->link_failure_count
-= lso
->link_failure_count
;
1959 hs
->loss_of_sync_count
-= lso
->loss_of_sync_count
;
1960 hs
->loss_of_signal_count
-= lso
->loss_of_signal_count
;
1961 hs
->prim_seq_protocol_err_count
-= lso
->prim_seq_protocol_err_count
;
1962 hs
->invalid_tx_word_count
-= lso
->invalid_tx_word_count
;
1963 hs
->invalid_crc_count
-= lso
->invalid_crc_count
;
1964 hs
->error_frames
-= lso
->error_frames
;
1966 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1967 hs
->lip_count
= (phba
->fc_eventTag
>> 1);
1968 hs
->lip_count
-= lso
->link_events
;
1972 hs
->nos_count
= (phba
->fc_eventTag
>> 1);
1973 hs
->nos_count
-= lso
->link_events
;
1976 hs
->dumped_frames
= -1;
1978 seconds
= get_seconds();
1979 if (seconds
< psli
->stats_start
)
1980 hs
->seconds_since_last_reset
= seconds
+
1981 ((unsigned long)-1 - psli
->stats_start
);
1983 hs
->seconds_since_last_reset
= seconds
- psli
->stats_start
;
1985 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1991 lpfc_reset_stats(struct Scsi_Host
*shost
)
1993 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1994 struct lpfc_hba
*phba
= vport
->phba
;
1995 struct lpfc_sli
*psli
= &phba
->sli
;
1996 struct lpfc_lnk_stat
*lso
= &psli
->lnk_stat_offsets
;
1997 LPFC_MBOXQ_t
*pmboxq
;
2001 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
2004 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2007 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
2010 pmb
->mbxCommand
= MBX_READ_STATUS
;
2011 pmb
->mbxOwner
= OWN_HOST
;
2012 pmb
->un
.varWords
[0] = 0x1; /* reset request */
2013 pmboxq
->context1
= NULL
;
2014 pmboxq
->vport
= vport
;
2016 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
2017 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
2018 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
2020 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
2022 if (rc
!= MBX_SUCCESS
) {
2023 if (rc
!= MBX_TIMEOUT
)
2024 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2028 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
2029 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
2030 pmb
->mbxOwner
= OWN_HOST
;
2031 pmboxq
->context1
= NULL
;
2032 pmboxq
->vport
= vport
;
2034 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
2035 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
2036 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
2038 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
2040 if (rc
!= MBX_SUCCESS
) {
2041 if (rc
!= MBX_TIMEOUT
)
2042 mempool_free( pmboxq
, phba
->mbox_mem_pool
);
2046 lso
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
2047 lso
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
2048 lso
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
2049 lso
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
2050 lso
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
2051 lso
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
2052 lso
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
2053 lso
->link_events
= (phba
->fc_eventTag
>> 1);
2055 psli
->stats_start
= get_seconds();
2057 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
2063 * The LPFC driver treats linkdown handling as target loss events so there
2064 * are no sysfs handlers for link_down_tmo.
2067 static struct lpfc_nodelist
*
2068 lpfc_get_node_by_target(struct scsi_target
*starget
)
2070 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
2071 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2072 struct lpfc_nodelist
*ndlp
;
2074 spin_lock_irq(shost
->host_lock
);
2075 /* Search for this, mapped, target ID */
2076 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2077 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
2078 starget
->id
== ndlp
->nlp_sid
) {
2079 spin_unlock_irq(shost
->host_lock
);
2083 spin_unlock_irq(shost
->host_lock
);
2088 lpfc_get_starget_port_id(struct scsi_target
*starget
)
2090 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
2092 fc_starget_port_id(starget
) = ndlp
? ndlp
->nlp_DID
: -1;
2096 lpfc_get_starget_node_name(struct scsi_target
*starget
)
2098 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
2100 fc_starget_node_name(starget
) =
2101 ndlp
? wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
) : 0;
2105 lpfc_get_starget_port_name(struct scsi_target
*starget
)
2107 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
2109 fc_starget_port_name(starget
) =
2110 ndlp
? wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
) : 0;
2114 lpfc_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
2117 rport
->dev_loss_tmo
= timeout
;
2119 rport
->dev_loss_tmo
= 1;
2123 #define lpfc_rport_show_function(field, format_string, sz, cast) \
2125 lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2127 struct fc_rport *rport = transport_class_to_rport(cdev); \
2128 struct lpfc_rport_data *rdata = rport->hostdata; \
2129 return snprintf(buf, sz, format_string, \
2130 (rdata->target) ? cast rdata->target->field : 0); \
2133 #define lpfc_rport_rd_attr(field, format_string, sz) \
2134 lpfc_rport_show_function(field, format_string, sz, ) \
2135 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2138 struct fc_function_template lpfc_transport_functions
= {
2139 /* fixed attributes the driver supports */
2140 .show_host_node_name
= 1,
2141 .show_host_port_name
= 1,
2142 .show_host_supported_classes
= 1,
2143 .show_host_supported_fc4s
= 1,
2144 .show_host_supported_speeds
= 1,
2145 .show_host_maxframe_size
= 1,
2147 /* dynamic attributes the driver supports */
2148 .get_host_port_id
= lpfc_get_host_port_id
,
2149 .show_host_port_id
= 1,
2151 .get_host_port_type
= lpfc_get_host_port_type
,
2152 .show_host_port_type
= 1,
2154 .get_host_port_state
= lpfc_get_host_port_state
,
2155 .show_host_port_state
= 1,
2157 /* active_fc4s is shown but doesn't change (thus no get function) */
2158 .show_host_active_fc4s
= 1,
2160 .get_host_speed
= lpfc_get_host_speed
,
2161 .show_host_speed
= 1,
2163 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
2164 .show_host_fabric_name
= 1,
2167 * The LPFC driver treats linkdown handling as target loss events
2168 * so there are no sysfs handlers for link_down_tmo.
2171 .get_fc_host_stats
= lpfc_get_stats
,
2172 .reset_fc_host_stats
= lpfc_reset_stats
,
2174 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
2175 .show_rport_maxframe_size
= 1,
2176 .show_rport_supported_classes
= 1,
2178 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
2179 .show_rport_dev_loss_tmo
= 1,
2181 .get_starget_port_id
= lpfc_get_starget_port_id
,
2182 .show_starget_port_id
= 1,
2184 .get_starget_node_name
= lpfc_get_starget_node_name
,
2185 .show_starget_node_name
= 1,
2187 .get_starget_port_name
= lpfc_get_starget_port_name
,
2188 .show_starget_port_name
= 1,
2190 .issue_fc_host_lip
= lpfc_issue_lip
,
2191 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
2192 .terminate_rport_io
= lpfc_terminate_rport_io
,
2194 .vport_create
= lpfc_vport_create
,
2195 .vport_delete
= lpfc_vport_delete
,
2196 .dd_fcvport_size
= sizeof(struct lpfc_vport
*),
2199 struct fc_function_template lpfc_vport_transport_functions
= {
2200 /* fixed attributes the driver supports */
2201 .show_host_node_name
= 1,
2202 .show_host_port_name
= 1,
2203 .show_host_supported_classes
= 1,
2204 .show_host_supported_fc4s
= 1,
2205 .show_host_supported_speeds
= 1,
2206 .show_host_maxframe_size
= 1,
2208 /* dynamic attributes the driver supports */
2209 .get_host_port_id
= lpfc_get_host_port_id
,
2210 .show_host_port_id
= 1,
2212 .get_host_port_type
= lpfc_get_host_port_type
,
2213 .show_host_port_type
= 1,
2215 .get_host_port_state
= lpfc_get_host_port_state
,
2216 .show_host_port_state
= 1,
2218 /* active_fc4s is shown but doesn't change (thus no get function) */
2219 .show_host_active_fc4s
= 1,
2221 .get_host_speed
= lpfc_get_host_speed
,
2222 .show_host_speed
= 1,
2224 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
2225 .show_host_fabric_name
= 1,
2228 * The LPFC driver treats linkdown handling as target loss events
2229 * so there are no sysfs handlers for link_down_tmo.
2232 .get_fc_host_stats
= lpfc_get_stats
,
2233 .reset_fc_host_stats
= lpfc_reset_stats
,
2235 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
2236 .show_rport_maxframe_size
= 1,
2237 .show_rport_supported_classes
= 1,
2239 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
2240 .show_rport_dev_loss_tmo
= 1,
2242 .get_starget_port_id
= lpfc_get_starget_port_id
,
2243 .show_starget_port_id
= 1,
2245 .get_starget_node_name
= lpfc_get_starget_node_name
,
2246 .show_starget_node_name
= 1,
2248 .get_starget_port_name
= lpfc_get_starget_port_name
,
2249 .show_starget_port_name
= 1,
2251 .issue_fc_host_lip
= lpfc_issue_lip
,
2252 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
2253 .terminate_rport_io
= lpfc_terminate_rport_io
,
2255 .vport_disable
= lpfc_vport_disable
,
2259 lpfc_get_cfgparam(struct lpfc_hba
*phba
)
2261 lpfc_log_verbose_init(phba
, lpfc_log_verbose
);
2262 lpfc_cr_delay_init(phba
, lpfc_cr_delay
);
2263 lpfc_cr_count_init(phba
, lpfc_cr_count
);
2264 lpfc_multi_ring_support_init(phba
, lpfc_multi_ring_support
);
2265 lpfc_multi_ring_rctl_init(phba
, lpfc_multi_ring_rctl
);
2266 lpfc_multi_ring_type_init(phba
, lpfc_multi_ring_type
);
2267 lpfc_lun_queue_depth_init(phba
, lpfc_lun_queue_depth
);
2268 lpfc_fcp_class_init(phba
, lpfc_fcp_class
);
2269 lpfc_use_adisc_init(phba
, lpfc_use_adisc
);
2270 lpfc_ack0_init(phba
, lpfc_ack0
);
2271 lpfc_topology_init(phba
, lpfc_topology
);
2272 lpfc_scan_down_init(phba
, lpfc_scan_down
);
2273 lpfc_link_speed_init(phba
, lpfc_link_speed
);
2274 lpfc_fdmi_on_init(phba
, lpfc_fdmi_on
);
2275 lpfc_discovery_threads_init(phba
, lpfc_discovery_threads
);
2276 lpfc_max_luns_init(phba
, lpfc_max_luns
);
2277 lpfc_poll_tmo_init(phba
, lpfc_poll_tmo
);
2278 lpfc_peer_port_login_init(phba
, lpfc_peer_port_login
);
2279 lpfc_npiv_enable_init(phba
, lpfc_npiv_enable
);
2280 lpfc_vport_restrict_login_init(phba
, lpfc_vport_restrict_login
);
2281 lpfc_use_msi_init(phba
, lpfc_use_msi
);
2282 lpfc_devloss_tmo_init(phba
, lpfc_devloss_tmo
);
2283 lpfc_nodev_tmo_init(phba
, lpfc_nodev_tmo
);
2284 phba
->cfg_poll
= lpfc_poll
;
2285 phba
->cfg_soft_wwnn
= 0L;
2286 phba
->cfg_soft_wwpn
= 0L;
2289 * The total number of segments is the configuration value plus 2
2290 * since the IOCB need a command and response bde.
2292 phba
->cfg_sg_seg_cnt
= LPFC_SG_SEG_CNT
+ 2;
2295 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2296 * used to create the sg_dma_buf_pool must be dynamically calculated
2298 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
2299 sizeof(struct fcp_rsp
) +
2300 (phba
->cfg_sg_seg_cnt
* sizeof(struct ulp_bde64
));
2303 lpfc_hba_queue_depth_init(phba
, lpfc_hba_queue_depth
);