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. *
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 lpfc_info_show(struct class_device *cdev, char *buf)
73 struct Scsi_Host *host = class_to_shost(cdev);
75 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
79 lpfc_serialnum_show(struct class_device *cdev, char *buf)
81 struct Scsi_Host *shost = class_to_shost(cdev);
82 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
83 struct lpfc_hba *phba = vport->phba;
85 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
89 lpfc_temp_sensor_show(struct class_device *cdev, char *buf)
91 struct Scsi_Host *shost = class_to_shost(cdev);
92 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
93 struct lpfc_hba *phba = vport->phba;
94 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
98 lpfc_modeldesc_show(struct class_device *cdev, char *buf)
100 struct Scsi_Host *shost = class_to_shost(cdev);
101 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
102 struct lpfc_hba *phba = vport->phba;
104 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
108 lpfc_modelname_show(struct class_device *cdev, char *buf)
110 struct Scsi_Host *shost = class_to_shost(cdev);
111 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
112 struct lpfc_hba *phba = vport->phba;
114 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
118 lpfc_programtype_show(struct class_device *cdev, char *buf)
120 struct Scsi_Host *shost = class_to_shost(cdev);
121 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
122 struct lpfc_hba *phba = vport->phba;
124 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
128 lpfc_vportnum_show(struct class_device *cdev, char *buf)
130 struct Scsi_Host *shost = class_to_shost(cdev);
131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
132 struct lpfc_hba *phba = vport->phba;
134 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
138 lpfc_fwrev_show(struct class_device *cdev, char *buf)
140 struct Scsi_Host *shost = class_to_shost(cdev);
141 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
142 struct lpfc_hba *phba = vport->phba;
145 lpfc_decode_firmware_rev(phba, fwrev, 1);
146 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
150 lpfc_hdw_show(struct class_device *cdev, char *buf)
153 struct Scsi_Host *shost = class_to_shost(cdev);
154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
155 struct lpfc_hba *phba = vport->phba;
156 lpfc_vpd_t *vp = &phba->vpd;
158 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
159 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
162 lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
164 struct Scsi_Host *shost = class_to_shost(cdev);
165 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
166 struct lpfc_hba *phba = vport->phba;
168 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
171 lpfc_state_show(struct class_device *cdev, char *buf)
173 struct Scsi_Host *shost = class_to_shost(cdev);
174 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
175 struct lpfc_hba *phba = vport->phba;
178 switch (phba->link_state) {
179 case LPFC_LINK_UNKNOWN:
180 case LPFC_WARM_START:
181 case LPFC_INIT_START:
182 case LPFC_INIT_MBX_CMDS:
185 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
190 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
192 switch (vport->port_state) {
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 /* Wait a little for things to settle down, but not
315 * long enough for dev loss timeout to expire.
317 for (i = 0; i < psli->num_rings; i++) {
318 pring = &psli->ring[i];
319 while (pring->txcmplq_cnt) {
321 if (cnt++ > 500) { /* 5 secs */
322 lpfc_printf_log(phba,
323 KERN_WARNING, LOG_INIT,
324 "0466 Outstanding IO when "
325 "bringing Adapter offline\n");
331 init_completion(&online_compl);
332 lpfc_workq_post_event(phba, &status, &online_compl, type);
333 wait_for_completion(&online_compl);
342 lpfc_selective_reset(struct lpfc_hba *phba)
344 struct completion online_compl;
347 if (!phba->cfg_enable_hba_reset)
350 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
355 init_completion(&online_compl);
356 lpfc_workq_post_event(phba, &status, &online_compl,
358 wait_for_completion(&online_compl);
367 lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
369 struct Scsi_Host *shost = class_to_shost(cdev);
370 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
371 struct lpfc_hba *phba = vport->phba;
373 int status = -EINVAL;
375 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
376 status = lpfc_selective_reset(phba);
385 lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
387 struct Scsi_Host *shost = class_to_shost(cdev);
388 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
389 struct lpfc_hba *phba = vport->phba;
391 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
395 lpfc_board_mode_show(struct class_device *cdev, char *buf)
397 struct Scsi_Host *shost = class_to_shost(cdev);
398 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
399 struct lpfc_hba *phba = vport->phba;
402 if (phba->link_state == LPFC_HBA_ERROR)
404 else if (phba->link_state == LPFC_WARM_START)
405 state = "warm start";
406 else if (phba->link_state == LPFC_INIT_START)
411 return snprintf(buf, PAGE_SIZE, "%s\n", state);
415 lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
417 struct Scsi_Host *shost = class_to_shost(cdev);
418 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
419 struct lpfc_hba *phba = vport->phba;
420 struct completion online_compl;
423 if (!phba->cfg_enable_hba_reset)
425 init_completion(&online_compl);
427 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
428 lpfc_workq_post_event(phba, &status, &online_compl,
430 wait_for_completion(&online_compl);
431 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
432 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
433 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
434 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
435 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
436 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
447 lpfc_get_hba_info(struct lpfc_hba *phba,
448 uint32_t *mxri, uint32_t *axri,
449 uint32_t *mrpi, uint32_t *arpi,
450 uint32_t *mvpi, uint32_t *avpi)
452 struct lpfc_sli *psli = &phba->sli;
453 LPFC_MBOXQ_t *pmboxq;
458 * prevent udev from issuing mailbox commands until the port is
461 if (phba->link_state < LPFC_LINK_DOWN ||
462 !phba->mbox_mem_pool ||
463 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
466 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
469 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
472 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
475 pmb->mbxCommand = MBX_READ_CONFIG;
476 pmb->mbxOwner = OWN_HOST;
477 pmboxq->context1 = NULL;
479 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
480 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
481 rc = MBX_NOT_FINISHED;
483 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
485 if (rc != MBX_SUCCESS) {
486 if (rc != MBX_TIMEOUT)
487 mempool_free(pmboxq, phba->mbox_mem_pool);
492 *mrpi = pmb->un.varRdConfig.max_rpi;
494 *arpi = pmb->un.varRdConfig.avail_rpi;
496 *mxri = pmb->un.varRdConfig.max_xri;
498 *axri = pmb->un.varRdConfig.avail_xri;
500 *mvpi = pmb->un.varRdConfig.max_vpi;
502 *avpi = pmb->un.varRdConfig.avail_vpi;
504 mempool_free(pmboxq, phba->mbox_mem_pool);
509 lpfc_max_rpi_show(struct class_device *cdev, char *buf)
511 struct Scsi_Host *shost = class_to_shost(cdev);
512 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
513 struct lpfc_hba *phba = vport->phba;
516 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
517 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
518 return snprintf(buf, PAGE_SIZE, "Unknown\n");
522 lpfc_used_rpi_show(struct class_device *cdev, char *buf)
524 struct Scsi_Host *shost = class_to_shost(cdev);
525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
526 struct lpfc_hba *phba = vport->phba;
529 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
530 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
531 return snprintf(buf, PAGE_SIZE, "Unknown\n");
535 lpfc_max_xri_show(struct class_device *cdev, char *buf)
537 struct Scsi_Host *shost = class_to_shost(cdev);
538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
539 struct lpfc_hba *phba = vport->phba;
542 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
543 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
544 return snprintf(buf, PAGE_SIZE, "Unknown\n");
548 lpfc_used_xri_show(struct class_device *cdev, char *buf)
550 struct Scsi_Host *shost = class_to_shost(cdev);
551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
552 struct lpfc_hba *phba = vport->phba;
555 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
556 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
557 return snprintf(buf, PAGE_SIZE, "Unknown\n");
561 lpfc_max_vpi_show(struct class_device *cdev, char *buf)
563 struct Scsi_Host *shost = class_to_shost(cdev);
564 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
565 struct lpfc_hba *phba = vport->phba;
568 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
569 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
570 return snprintf(buf, PAGE_SIZE, "Unknown\n");
574 lpfc_used_vpi_show(struct class_device *cdev, char *buf)
576 struct Scsi_Host *shost = class_to_shost(cdev);
577 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
578 struct lpfc_hba *phba = vport->phba;
581 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
582 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
583 return snprintf(buf, PAGE_SIZE, "Unknown\n");
587 lpfc_npiv_info_show(struct class_device *cdev, char *buf)
589 struct Scsi_Host *shost = class_to_shost(cdev);
590 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
591 struct lpfc_hba *phba = vport->phba;
593 if (!(phba->max_vpi))
594 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
595 if (vport->port_type == LPFC_PHYSICAL_PORT)
596 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
597 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
601 lpfc_poll_show(struct class_device *cdev, char *buf)
603 struct Scsi_Host *shost = class_to_shost(cdev);
604 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
605 struct lpfc_hba *phba = vport->phba;
607 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
611 lpfc_poll_store(struct class_device *cdev, const char *buf,
614 struct Scsi_Host *shost = class_to_shost(cdev);
615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
616 struct lpfc_hba *phba = vport->phba;
621 if (!isdigit(buf[0]))
624 if (sscanf(buf, "%i", &val) != 1)
627 if ((val & 0x3) != val)
630 spin_lock_irq(&phba->hbalock);
632 old_val = phba->cfg_poll;
634 if (val & ENABLE_FCP_RING_POLLING) {
635 if ((val & DISABLE_FCP_RING_INT) &&
636 !(old_val & DISABLE_FCP_RING_INT)) {
637 creg_val = readl(phba->HCregaddr);
638 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
639 writel(creg_val, phba->HCregaddr);
640 readl(phba->HCregaddr); /* flush */
642 lpfc_poll_start_timer(phba);
644 } else if (val != 0x0) {
645 spin_unlock_irq(&phba->hbalock);
649 if (!(val & DISABLE_FCP_RING_INT) &&
650 (old_val & DISABLE_FCP_RING_INT))
652 spin_unlock_irq(&phba->hbalock);
653 del_timer(&phba->fcp_poll_timer);
654 spin_lock_irq(&phba->hbalock);
655 creg_val = readl(phba->HCregaddr);
656 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
657 writel(creg_val, phba->HCregaddr);
658 readl(phba->HCregaddr); /* flush */
661 phba->cfg_poll = val;
663 spin_unlock_irq(&phba->hbalock);
668 #define lpfc_param_show(attr) \
670 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
672 struct Scsi_Host *shost = class_to_shost(cdev);\
673 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
674 struct lpfc_hba *phba = vport->phba;\
676 val = phba->cfg_##attr;\
677 return snprintf(buf, PAGE_SIZE, "%d\n",\
681 #define lpfc_param_hex_show(attr) \
683 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
685 struct Scsi_Host *shost = class_to_shost(cdev);\
686 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
687 struct lpfc_hba *phba = vport->phba;\
689 val = phba->cfg_##attr;\
690 return snprintf(buf, PAGE_SIZE, "%#x\n",\
694 #define lpfc_param_init(attr, default, minval, maxval) \
696 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
698 if (val >= minval && val <= maxval) {\
699 phba->cfg_##attr = val;\
702 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
703 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
704 "allowed range is ["#minval", "#maxval"]\n", val); \
705 phba->cfg_##attr = default;\
709 #define lpfc_param_set(attr, default, minval, maxval) \
711 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
713 if (val >= minval && val <= maxval) {\
714 phba->cfg_##attr = val;\
717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
718 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
719 "allowed range is ["#minval", "#maxval"]\n", val); \
723 #define lpfc_param_store(attr) \
725 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
727 struct Scsi_Host *shost = class_to_shost(cdev);\
728 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
729 struct lpfc_hba *phba = vport->phba;\
731 if (!isdigit(buf[0]))\
733 if (sscanf(buf, "%i", &val) != 1)\
735 if (lpfc_##attr##_set(phba, val) == 0) \
741 #define lpfc_vport_param_show(attr) \
743 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
745 struct Scsi_Host *shost = class_to_shost(cdev);\
746 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
748 val = vport->cfg_##attr;\
749 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
752 #define lpfc_vport_param_hex_show(attr) \
754 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
756 struct Scsi_Host *shost = class_to_shost(cdev);\
757 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
759 val = vport->cfg_##attr;\
760 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
763 #define lpfc_vport_param_init(attr, default, minval, maxval) \
765 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
767 if (val >= minval && val <= maxval) {\
768 vport->cfg_##attr = val;\
771 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
772 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
773 "allowed range is ["#minval", "#maxval"]\n", val); \
774 vport->cfg_##attr = default;\
778 #define lpfc_vport_param_set(attr, default, minval, maxval) \
780 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
782 if (val >= minval && val <= maxval) {\
783 vport->cfg_##attr = val;\
786 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
787 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
788 "allowed range is ["#minval", "#maxval"]\n", val); \
792 #define lpfc_vport_param_store(attr) \
794 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
796 struct Scsi_Host *shost = class_to_shost(cdev);\
797 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
799 if (!isdigit(buf[0]))\
801 if (sscanf(buf, "%i", &val) != 1)\
803 if (lpfc_##attr##_set(vport, val) == 0) \
810 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
811 static int lpfc_##name = defval;\
812 module_param(lpfc_##name, int, 0);\
813 MODULE_PARM_DESC(lpfc_##name, desc);\
814 lpfc_param_init(name, defval, minval, maxval)
816 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
817 static int lpfc_##name = defval;\
818 module_param(lpfc_##name, int, 0);\
819 MODULE_PARM_DESC(lpfc_##name, desc);\
820 lpfc_param_show(name)\
821 lpfc_param_init(name, defval, minval, maxval)\
822 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
824 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
825 static int lpfc_##name = defval;\
826 module_param(lpfc_##name, int, 0);\
827 MODULE_PARM_DESC(lpfc_##name, desc);\
828 lpfc_param_show(name)\
829 lpfc_param_init(name, defval, minval, maxval)\
830 lpfc_param_set(name, defval, minval, maxval)\
831 lpfc_param_store(name)\
832 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
833 lpfc_##name##_show, lpfc_##name##_store)
835 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
836 static int lpfc_##name = defval;\
837 module_param(lpfc_##name, int, 0);\
838 MODULE_PARM_DESC(lpfc_##name, desc);\
839 lpfc_param_hex_show(name)\
840 lpfc_param_init(name, defval, minval, maxval)\
841 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
843 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
844 static int lpfc_##name = defval;\
845 module_param(lpfc_##name, int, 0);\
846 MODULE_PARM_DESC(lpfc_##name, desc);\
847 lpfc_param_hex_show(name)\
848 lpfc_param_init(name, defval, minval, maxval)\
849 lpfc_param_set(name, defval, minval, maxval)\
850 lpfc_param_store(name)\
851 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
852 lpfc_##name##_show, lpfc_##name##_store)
854 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
855 static int lpfc_##name = defval;\
856 module_param(lpfc_##name, int, 0);\
857 MODULE_PARM_DESC(lpfc_##name, desc);\
858 lpfc_vport_param_init(name, defval, minval, maxval)
860 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
861 static int lpfc_##name = defval;\
862 module_param(lpfc_##name, int, 0);\
863 MODULE_PARM_DESC(lpfc_##name, desc);\
864 lpfc_vport_param_show(name)\
865 lpfc_vport_param_init(name, defval, minval, maxval)\
866 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
868 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
869 static int lpfc_##name = defval;\
870 module_param(lpfc_##name, int, 0);\
871 MODULE_PARM_DESC(lpfc_##name, desc);\
872 lpfc_vport_param_show(name)\
873 lpfc_vport_param_init(name, defval, minval, maxval)\
874 lpfc_vport_param_set(name, defval, minval, maxval)\
875 lpfc_vport_param_store(name)\
876 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
877 lpfc_##name##_show, lpfc_##name##_store)
879 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
880 static int lpfc_##name = defval;\
881 module_param(lpfc_##name, int, 0);\
882 MODULE_PARM_DESC(lpfc_##name, desc);\
883 lpfc_vport_param_hex_show(name)\
884 lpfc_vport_param_init(name, defval, minval, maxval)\
885 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
887 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
888 static int lpfc_##name = defval;\
889 module_param(lpfc_##name, int, 0);\
890 MODULE_PARM_DESC(lpfc_##name, desc);\
891 lpfc_vport_param_hex_show(name)\
892 lpfc_vport_param_init(name, defval, minval, maxval)\
893 lpfc_vport_param_set(name, defval, minval, maxval)\
894 lpfc_vport_param_store(name)\
895 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
896 lpfc_##name##_show, lpfc_##name##_store)
898 static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
899 static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
900 static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
901 static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
902 static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
903 static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
904 static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
905 static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
906 static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
907 static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
908 lpfc_option_rom_version_show, NULL);
909 static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
910 lpfc_num_discovered_ports_show, NULL);
911 static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
912 static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
914 static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
915 lpfc_board_mode_show, lpfc_board_mode_store);
916 static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
917 static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
918 static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
919 static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
920 static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
921 static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
922 static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
923 static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
924 static CLASS_DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show,
928 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
931 lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
934 struct Scsi_Host *shost = class_to_shost(cdev);
935 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
936 struct lpfc_hba *phba = vport->phba;
937 unsigned int cnt = count;
940 * We're doing a simple sanity check for soft_wwpn setting.
941 * We require that the user write a specific key to enable
942 * the soft_wwpn attribute to be settable. Once the attribute
943 * is written, the enable key resets. If further updates are
944 * desired, the key must be written again to re-enable the
947 * The "key" is not secret - it is a hardcoded string shown
948 * here. The intent is to protect against the random user or
949 * application that is just writing attributes.
952 /* count may include a LF at end of string */
953 if (buf[cnt-1] == '\n')
956 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
957 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
960 phba->soft_wwn_enable = 1;
963 static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
964 lpfc_soft_wwn_enable_store);
967 lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
969 struct Scsi_Host *shost = class_to_shost(cdev);
970 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
971 struct lpfc_hba *phba = vport->phba;
973 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
974 (unsigned long long)phba->cfg_soft_wwpn);
979 lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
981 struct Scsi_Host *shost = class_to_shost(cdev);
982 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
983 struct lpfc_hba *phba = vport->phba;
984 struct completion online_compl;
985 int stat1=0, stat2=0;
986 unsigned int i, j, cnt=count;
989 if (!phba->cfg_enable_hba_reset)
991 spin_lock_irq(&phba->hbalock);
992 if (phba->over_temp_state == HBA_OVER_TEMP) {
993 spin_unlock_irq(&phba->hbalock);
996 spin_unlock_irq(&phba->hbalock);
997 /* count may include a LF at end of string */
998 if (buf[cnt-1] == '\n')
1001 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1002 ((cnt == 17) && (*buf++ != 'x')) ||
1003 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1006 phba->soft_wwn_enable = 0;
1008 memset(wwpn, 0, sizeof(wwpn));
1010 /* Validate and store the new name */
1011 for (i=0, j=0; i < 16; i++) {
1012 if ((*buf >= 'a') && (*buf <= 'f'))
1013 j = ((j << 4) | ((*buf++ -'a') + 10));
1014 else if ((*buf >= 'A') && (*buf <= 'F'))
1015 j = ((j << 4) | ((*buf++ -'A') + 10));
1016 else if ((*buf >= '0') && (*buf <= '9'))
1017 j = ((j << 4) | (*buf++ -'0'));
1021 wwpn[i/2] = j & 0xff;
1025 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1026 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1027 if (phba->cfg_soft_wwnn)
1028 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1030 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1031 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1033 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1036 "0463 lpfc_soft_wwpn attribute set failed to "
1037 "reinit adapter - %d\n", stat1);
1038 init_completion(&online_compl);
1039 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1040 wait_for_completion(&online_compl);
1042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1043 "0464 lpfc_soft_wwpn attribute set failed to "
1044 "reinit adapter - %d\n", stat2);
1045 return (stat1 || stat2) ? -EIO : count;
1047 static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1048 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1051 lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
1053 struct Scsi_Host *shost = class_to_shost(cdev);
1054 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1055 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1056 (unsigned long long)phba->cfg_soft_wwnn);
1061 lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
1063 struct Scsi_Host *shost = class_to_shost(cdev);
1064 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1065 unsigned int i, j, cnt=count;
1068 /* count may include a LF at end of string */
1069 if (buf[cnt-1] == '\n')
1072 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1073 ((cnt == 17) && (*buf++ != 'x')) ||
1074 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1078 * Allow wwnn to be set many times, as long as the enable is set.
1079 * However, once the wwpn is set, everything locks.
1082 memset(wwnn, 0, sizeof(wwnn));
1084 /* Validate and store the new name */
1085 for (i=0, j=0; i < 16; i++) {
1086 if ((*buf >= 'a') && (*buf <= 'f'))
1087 j = ((j << 4) | ((*buf++ -'a') + 10));
1088 else if ((*buf >= 'A') && (*buf <= 'F'))
1089 j = ((j << 4) | ((*buf++ -'A') + 10));
1090 else if ((*buf >= '0') && (*buf <= '9'))
1091 j = ((j << 4) | (*buf++ -'0'));
1095 wwnn[i/2] = j & 0xff;
1099 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1101 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1102 "lpfc%d: soft_wwnn set. Value will take effect upon "
1103 "setting of the soft_wwpn\n", phba->brd_no);
1107 static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1108 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1111 static int lpfc_poll = 0;
1112 module_param(lpfc_poll, int, 0);
1113 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1115 " 1 - poll with interrupts enabled"
1116 " 3 - poll and disable FCP ring interrupts");
1118 static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1119 lpfc_poll_show, lpfc_poll_store);
1121 int lpfc_sli_mode = 0;
1122 module_param(lpfc_sli_mode, int, 0);
1123 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1124 " 0 - auto (SLI-3 if supported),"
1125 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1126 " 3 - select SLI-3");
1128 int lpfc_enable_npiv = 0;
1129 module_param(lpfc_enable_npiv, int, 0);
1130 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1131 lpfc_param_show(enable_npiv);
1132 lpfc_param_init(enable_npiv, 0, 0, 1);
1133 static CLASS_DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1134 lpfc_enable_npiv_show, NULL);
1137 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1138 # until the timer expires. Value range is [0,255]. Default value is 30.
1140 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1141 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1142 module_param(lpfc_nodev_tmo, int, 0);
1143 MODULE_PARM_DESC(lpfc_nodev_tmo,
1144 "Seconds driver will hold I/O waiting "
1145 "for a device to come back");
1147 lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
1149 struct Scsi_Host *shost = class_to_shost(cdev);
1150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1152 val = vport->cfg_devloss_tmo;
1153 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
1157 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1159 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1160 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1161 if (val != LPFC_DEF_DEVLOSS_TMO)
1162 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1163 "0402 Ignoring nodev_tmo module "
1164 "parameter because devloss_tmo is "
1169 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1170 vport->cfg_nodev_tmo = val;
1171 vport->cfg_devloss_tmo = val;
1174 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1175 "0400 lpfc_nodev_tmo attribute cannot be set to"
1176 " %d, allowed range is [%d, %d]\n",
1177 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1178 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1183 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
1185 struct Scsi_Host *shost;
1186 struct lpfc_nodelist *ndlp;
1188 shost = lpfc_shost_from_vport(vport);
1189 spin_lock_irq(shost->host_lock);
1190 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1192 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1193 spin_unlock_irq(shost->host_lock);
1197 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
1199 if (vport->dev_loss_tmo_changed ||
1200 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
1201 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1202 "0401 Ignoring change to nodev_tmo "
1203 "because devloss_tmo is set.\n");
1206 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1207 vport->cfg_nodev_tmo = val;
1208 vport->cfg_devloss_tmo = val;
1209 lpfc_update_rport_devloss_tmo(vport);
1212 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1213 "0403 lpfc_nodev_tmo attribute cannot be set to"
1214 "%d, allowed range is [%d, %d]\n",
1215 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1219 lpfc_vport_param_store(nodev_tmo)
1221 static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1222 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1225 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1226 # disappear until the timer expires. Value range is [0,255]. Default
1229 module_param(lpfc_devloss_tmo, int, 0);
1230 MODULE_PARM_DESC(lpfc_devloss_tmo,
1231 "Seconds driver will hold I/O waiting "
1232 "for a device to come back");
1233 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1234 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1235 lpfc_vport_param_show(devloss_tmo)
1237 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
1239 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1240 vport->cfg_nodev_tmo = val;
1241 vport->cfg_devloss_tmo = val;
1242 vport->dev_loss_tmo_changed = 1;
1243 lpfc_update_rport_devloss_tmo(vport);
1247 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1248 "0404 lpfc_devloss_tmo attribute cannot be set to"
1249 " %d, allowed range is [%d, %d]\n",
1250 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1254 lpfc_vport_param_store(devloss_tmo)
1255 static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1256 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1259 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1260 # deluged with LOTS of information.
1261 # You can set a bit mask to record specific types of verbose messages:
1263 # LOG_ELS 0x1 ELS events
1264 # LOG_DISCOVERY 0x2 Link discovery events
1265 # LOG_MBOX 0x4 Mailbox events
1266 # LOG_INIT 0x8 Initialization events
1267 # LOG_LINK_EVENT 0x10 Link events
1268 # LOG_FCP 0x40 FCP traffic history
1269 # LOG_NODE 0x80 Node table events
1270 # LOG_MISC 0x400 Miscellaneous events
1271 # LOG_SLI 0x800 SLI events
1272 # LOG_FCP_ERROR 0x1000 Only log FCP errors
1273 # LOG_LIBDFC 0x2000 LIBDFC events
1274 # LOG_ALL_MSG 0xffff LOG all messages
1276 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1277 "Verbose logging bit-mask");
1280 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1281 # objects that have been registered with the nameserver after login.
1283 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1284 "Deregister nameserver objects before LOGO");
1287 # lun_queue_depth: This parameter is used to limit the number of outstanding
1288 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
1290 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1291 "Max number of FCP commands we can queue to a specific LUN");
1294 # hba_queue_depth: This parameter is used to limit the number of outstanding
1295 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
1296 # value is greater than the maximum number of exchanges supported by the HBA,
1297 # then maximum number of exchanges supported by the HBA is used to determine
1298 # the hba_queue_depth.
1300 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1301 "Max number of FCP commands we can queue to a lpfc HBA");
1304 # peer_port_login: This parameter allows/prevents logins
1305 # between peer ports hosted on the same physical port.
1306 # When this parameter is set 0 peer ports of same physical port
1307 # are not allowed to login to each other.
1308 # When this parameter is set 1 peer ports of same physical port
1309 # are allowed to login to each other.
1310 # Default value of this parameter is 0.
1312 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1313 "Allow peer ports on the same physical port to login to each "
1317 # restrict_login: This parameter allows/prevents logins
1318 # between Virtual Ports and remote initiators.
1319 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1320 # other initiators and will attempt to PLOGI all remote ports.
1321 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
1322 # remote ports and will not attempt to PLOGI to other initiators.
1323 # This parameter does not restrict to the physical port.
1324 # This parameter does not restrict logins to Fabric resident remote ports.
1325 # Default value of this parameter is 1.
1327 static int lpfc_restrict_login = 1;
1328 module_param(lpfc_restrict_login, int, 0);
1329 MODULE_PARM_DESC(lpfc_restrict_login,
1330 "Restrict virtual ports login to remote initiators.");
1331 lpfc_vport_param_show(restrict_login);
1334 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1336 if (val < 0 || val > 1) {
1337 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1338 "0449 lpfc_restrict_login attribute cannot "
1339 "be set to %d, allowed range is [0, 1]\n",
1341 vport->cfg_restrict_login = 1;
1344 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1345 vport->cfg_restrict_login = 0;
1348 vport->cfg_restrict_login = val;
1353 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1355 if (val < 0 || val > 1) {
1356 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1357 "0450 lpfc_restrict_login attribute cannot "
1358 "be set to %d, allowed range is [0, 1]\n",
1360 vport->cfg_restrict_login = 1;
1363 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
1364 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1365 "0468 lpfc_restrict_login must be 0 for "
1366 "Physical ports.\n");
1367 vport->cfg_restrict_login = 0;
1370 vport->cfg_restrict_login = val;
1373 lpfc_vport_param_store(restrict_login);
1374 static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
1375 lpfc_restrict_login_show, lpfc_restrict_login_store);
1378 # Some disk devices have a "select ID" or "select Target" capability.
1379 # From a protocol standpoint "select ID" usually means select the
1380 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1381 # annex" which contains a table that maps a "select ID" (a number
1382 # between 0 and 7F) to an ALPA. By default, for compatibility with
1383 # older drivers, the lpfc driver scans this table from low ALPA to high
1386 # Turning on the scan-down variable (on = 1, off = 0) will
1387 # cause the lpfc driver to use an inverted table, effectively
1388 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1390 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
1391 # and will not work across a fabric. Also this parameter will take
1392 # effect only in the case when ALPA map is not available.)
1394 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1395 "Start scanning for devices from highest ALPA to lowest");
1398 # lpfc_topology: link topology for init link
1399 # 0x0 = attempt loop mode then point-to-point
1400 # 0x01 = internal loopback mode
1401 # 0x02 = attempt point-to-point mode only
1402 # 0x04 = attempt loop mode only
1403 # 0x06 = attempt point-to-point mode then loop
1404 # Set point-to-point mode if you want to run as an N_Port.
1405 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1406 # Default value is 0.
1408 LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
1411 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1413 # 0 = auto select (default)
1418 # Value range is [0,8]. Default value is 0.
1420 LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
1423 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1424 # Value range is [2,3]. Default value is 3.
1426 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
1427 "Select Fibre Channel class of service for FCP sequences");
1430 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1431 # is [0,1]. Default value is 0.
1433 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
1434 "Use ADISC on rediscovery to authenticate FCP devices");
1437 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1438 # range is [0,1]. Default value is 0.
1440 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1443 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1444 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
1445 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
1446 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1447 # cr_delay is set to 0.
1449 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
1450 "interrupt response is generated");
1452 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
1453 "interrupt response is generated");
1456 # lpfc_multi_ring_support: Determines how many rings to spread available
1457 # cmd/rsp IOCB entries across.
1458 # Value range is [1,2]. Default value is 1.
1460 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1461 "SLI rings to spread IOCB entries across");
1464 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1465 # identifies what rctl value to configure the additional ring for.
1466 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1468 LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1469 255, "Identifies RCTL for additional ring configuration");
1472 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1473 # identifies what type value to configure the additional ring for.
1474 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1476 LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1477 255, "Identifies TYPE for additional ring configuration");
1480 # lpfc_fdmi_on: controls FDMI support.
1481 # 0 = no FDMI support
1482 # 1 = support FDMI without attribute of hostname
1483 # 2 = support FDMI with attribute of hostname
1484 # Value range [0,2]. Default value is 0.
1486 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
1489 # Specifies the maximum number of ELS cmds we can have outstanding (for
1490 # discovery). Value range is [1,64]. Default value = 32.
1492 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
1493 "during discovery");
1496 # lpfc_max_luns: maximum allowed LUN.
1497 # Value range is [0,65535]. Default value is 255.
1498 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
1500 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
1503 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1504 # Value range is [1,255], default value is 10.
1506 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1507 "Milliseconds driver will wait between polling FCP ring");
1510 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1511 # support this feature
1512 # 0 = MSI disabled (default)
1514 # Value range is [0,1]. Default value is 0.
1516 LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1519 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
1520 # 0 = HBA resets disabled
1521 # 1 = HBA resets enabled (default)
1522 # Value range is [0,1]. Default value is 1.
1524 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
1527 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
1528 # 0 = HBA Heartbeat disabled
1529 # 1 = HBA Heartbeat enabled (default)
1530 # Value range is [0,1]. Default value is 1.
1532 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
1534 struct class_device_attribute *lpfc_hba_attrs[] = {
1535 &class_device_attr_info,
1536 &class_device_attr_serialnum,
1537 &class_device_attr_modeldesc,
1538 &class_device_attr_modelname,
1539 &class_device_attr_programtype,
1540 &class_device_attr_portnum,
1541 &class_device_attr_fwrev,
1542 &class_device_attr_hdw,
1543 &class_device_attr_option_rom_version,
1544 &class_device_attr_state,
1545 &class_device_attr_num_discovered_ports,
1546 &class_device_attr_lpfc_drvr_version,
1547 &class_device_attr_lpfc_temp_sensor,
1548 &class_device_attr_lpfc_log_verbose,
1549 &class_device_attr_lpfc_lun_queue_depth,
1550 &class_device_attr_lpfc_hba_queue_depth,
1551 &class_device_attr_lpfc_peer_port_login,
1552 &class_device_attr_lpfc_nodev_tmo,
1553 &class_device_attr_lpfc_devloss_tmo,
1554 &class_device_attr_lpfc_fcp_class,
1555 &class_device_attr_lpfc_use_adisc,
1556 &class_device_attr_lpfc_ack0,
1557 &class_device_attr_lpfc_topology,
1558 &class_device_attr_lpfc_scan_down,
1559 &class_device_attr_lpfc_link_speed,
1560 &class_device_attr_lpfc_cr_delay,
1561 &class_device_attr_lpfc_cr_count,
1562 &class_device_attr_lpfc_multi_ring_support,
1563 &class_device_attr_lpfc_multi_ring_rctl,
1564 &class_device_attr_lpfc_multi_ring_type,
1565 &class_device_attr_lpfc_fdmi_on,
1566 &class_device_attr_lpfc_max_luns,
1567 &class_device_attr_lpfc_enable_npiv,
1568 &class_device_attr_nport_evt_cnt,
1569 &class_device_attr_board_mode,
1570 &class_device_attr_max_vpi,
1571 &class_device_attr_used_vpi,
1572 &class_device_attr_max_rpi,
1573 &class_device_attr_used_rpi,
1574 &class_device_attr_max_xri,
1575 &class_device_attr_used_xri,
1576 &class_device_attr_npiv_info,
1577 &class_device_attr_issue_reset,
1578 &class_device_attr_lpfc_poll,
1579 &class_device_attr_lpfc_poll_tmo,
1580 &class_device_attr_lpfc_use_msi,
1581 &class_device_attr_lpfc_soft_wwnn,
1582 &class_device_attr_lpfc_soft_wwpn,
1583 &class_device_attr_lpfc_soft_wwn_enable,
1584 &class_device_attr_lpfc_enable_hba_reset,
1585 &class_device_attr_lpfc_enable_hba_heartbeat,
1589 struct class_device_attribute *lpfc_vport_attrs[] = {
1590 &class_device_attr_info,
1591 &class_device_attr_state,
1592 &class_device_attr_num_discovered_ports,
1593 &class_device_attr_lpfc_drvr_version,
1595 &class_device_attr_lpfc_log_verbose,
1596 &class_device_attr_lpfc_lun_queue_depth,
1597 &class_device_attr_lpfc_nodev_tmo,
1598 &class_device_attr_lpfc_devloss_tmo,
1599 &class_device_attr_lpfc_hba_queue_depth,
1600 &class_device_attr_lpfc_peer_port_login,
1601 &class_device_attr_lpfc_restrict_login,
1602 &class_device_attr_lpfc_fcp_class,
1603 &class_device_attr_lpfc_use_adisc,
1604 &class_device_attr_lpfc_fdmi_on,
1605 &class_device_attr_lpfc_max_luns,
1606 &class_device_attr_nport_evt_cnt,
1607 &class_device_attr_npiv_info,
1608 &class_device_attr_lpfc_enable_da_id,
1613 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1614 char *buf, loff_t off, size_t count)
1617 struct class_device *cdev = container_of(kobj, struct class_device,
1619 struct Scsi_Host *shost = class_to_shost(cdev);
1620 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1621 struct lpfc_hba *phba = vport->phba;
1623 if ((off + count) > FF_REG_AREA_SIZE)
1626 if (count == 0) return 0;
1628 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1631 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1635 spin_lock_irq(&phba->hbalock);
1636 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1637 writel(*((uint32_t *)(buf + buf_off)),
1638 phba->ctrl_regs_memmap_p + off + buf_off);
1640 spin_unlock_irq(&phba->hbalock);
1646 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1647 char *buf, loff_t off, size_t count)
1651 struct class_device *cdev = container_of(kobj, struct class_device,
1653 struct Scsi_Host *shost = class_to_shost(cdev);
1654 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1655 struct lpfc_hba *phba = vport->phba;
1657 if (off > FF_REG_AREA_SIZE)
1660 if ((off + count) > FF_REG_AREA_SIZE)
1661 count = FF_REG_AREA_SIZE - off;
1663 if (count == 0) return 0;
1665 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1668 spin_lock_irq(&phba->hbalock);
1670 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1671 tmp_ptr = (uint32_t *)(buf + buf_off);
1672 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1675 spin_unlock_irq(&phba->hbalock);
1680 static struct bin_attribute sysfs_ctlreg_attr = {
1683 .mode = S_IRUSR | S_IWUSR,
1686 .read = sysfs_ctlreg_read,
1687 .write = sysfs_ctlreg_write,
1692 sysfs_mbox_idle(struct lpfc_hba *phba)
1694 phba->sysfs_mbox.state = SMBOX_IDLE;
1695 phba->sysfs_mbox.offset = 0;
1697 if (phba->sysfs_mbox.mbox) {
1698 mempool_free(phba->sysfs_mbox.mbox,
1699 phba->mbox_mem_pool);
1700 phba->sysfs_mbox.mbox = NULL;
1705 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1706 char *buf, loff_t off, size_t count)
1708 struct class_device *cdev = container_of(kobj, struct class_device,
1710 struct Scsi_Host *shost = class_to_shost(cdev);
1711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1712 struct lpfc_hba *phba = vport->phba;
1713 struct lpfcMboxq *mbox = NULL;
1715 if ((count + off) > MAILBOX_CMD_SIZE)
1718 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1725 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1728 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
1731 spin_lock_irq(&phba->hbalock);
1734 if (phba->sysfs_mbox.mbox)
1735 mempool_free(mbox, phba->mbox_mem_pool);
1737 phba->sysfs_mbox.mbox = mbox;
1738 phba->sysfs_mbox.state = SMBOX_WRITING;
1740 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1741 phba->sysfs_mbox.offset != off ||
1742 phba->sysfs_mbox.mbox == NULL) {
1743 sysfs_mbox_idle(phba);
1744 spin_unlock_irq(&phba->hbalock);
1749 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1752 phba->sysfs_mbox.offset = off + count;
1754 spin_unlock_irq(&phba->hbalock);
1760 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1761 char *buf, loff_t off, size_t count)
1763 struct class_device *cdev = container_of(kobj, struct class_device,
1765 struct Scsi_Host *shost = class_to_shost(cdev);
1766 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1767 struct lpfc_hba *phba = vport->phba;
1770 if (off > MAILBOX_CMD_SIZE)
1773 if ((count + off) > MAILBOX_CMD_SIZE)
1774 count = MAILBOX_CMD_SIZE - off;
1776 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1779 if (off && count == 0)
1782 spin_lock_irq(&phba->hbalock);
1784 if (phba->over_temp_state == HBA_OVER_TEMP) {
1785 sysfs_mbox_idle(phba);
1786 spin_unlock_irq(&phba->hbalock);
1791 phba->sysfs_mbox.state == SMBOX_WRITING &&
1792 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1794 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1798 case MBX_CONFIG_LINK:
1799 case MBX_CONFIG_RING:
1800 case MBX_RESET_RING:
1801 case MBX_UNREG_LOGIN:
1803 case MBX_DUMP_CONTEXT:
1808 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1809 printk(KERN_WARNING "mbox_read:Command 0x%x "
1810 "is illegal in on-line state\n",
1811 phba->sysfs_mbox.mbox->mb.mbxCommand);
1812 sysfs_mbox_idle(phba);
1813 spin_unlock_irq(&phba->hbalock);
1817 case MBX_WRITE_VPARMS:
1820 case MBX_READ_CONFIG:
1821 case MBX_READ_RCONFIG:
1822 case MBX_READ_STATUS:
1825 case MBX_READ_LNK_STAT:
1826 case MBX_DUMP_MEMORY:
1828 case MBX_UPDATE_CFG:
1829 case MBX_KILL_BOARD:
1831 case MBX_LOAD_EXP_ROM:
1833 case MBX_DEL_LD_ENTRY:
1834 case MBX_SET_VARIABLE:
1837 case MBX_READ_SPARM64:
1841 case MBX_REG_LOGIN64:
1842 case MBX_CONFIG_PORT:
1843 case MBX_RUN_BIU_DIAG:
1844 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1845 phba->sysfs_mbox.mbox->mb.mbxCommand);
1846 sysfs_mbox_idle(phba);
1847 spin_unlock_irq(&phba->hbalock);
1850 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1851 phba->sysfs_mbox.mbox->mb.mbxCommand);
1852 sysfs_mbox_idle(phba);
1853 spin_unlock_irq(&phba->hbalock);
1857 /* If HBA encountered an error attention, allow only DUMP
1858 * mailbox command until the HBA is restarted.
1860 if ((phba->pport->stopped) &&
1861 (phba->sysfs_mbox.mbox->mb.mbxCommand
1862 != MBX_DUMP_MEMORY)) {
1863 sysfs_mbox_idle(phba);
1864 spin_unlock_irq(&phba->hbalock);
1868 phba->sysfs_mbox.mbox->vport = vport;
1870 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
1871 sysfs_mbox_idle(phba);
1872 spin_unlock_irq(&phba->hbalock);
1876 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1877 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1879 spin_unlock_irq(&phba->hbalock);
1880 rc = lpfc_sli_issue_mbox (phba,
1881 phba->sysfs_mbox.mbox,
1883 spin_lock_irq(&phba->hbalock);
1886 spin_unlock_irq(&phba->hbalock);
1887 rc = lpfc_sli_issue_mbox_wait (phba,
1888 phba->sysfs_mbox.mbox,
1889 lpfc_mbox_tmo_val(phba,
1890 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
1891 spin_lock_irq(&phba->hbalock);
1894 if (rc != MBX_SUCCESS) {
1895 if (rc == MBX_TIMEOUT) {
1896 phba->sysfs_mbox.mbox = NULL;
1898 sysfs_mbox_idle(phba);
1899 spin_unlock_irq(&phba->hbalock);
1900 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
1902 phba->sysfs_mbox.state = SMBOX_READING;
1904 else if (phba->sysfs_mbox.offset != off ||
1905 phba->sysfs_mbox.state != SMBOX_READING) {
1906 printk(KERN_WARNING "mbox_read: Bad State\n");
1907 sysfs_mbox_idle(phba);
1908 spin_unlock_irq(&phba->hbalock);
1912 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1914 phba->sysfs_mbox.offset = off + count;
1916 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
1917 sysfs_mbox_idle(phba);
1919 spin_unlock_irq(&phba->hbalock);
1924 static struct bin_attribute sysfs_mbox_attr = {
1927 .mode = S_IRUSR | S_IWUSR,
1929 .size = MAILBOX_CMD_SIZE,
1930 .read = sysfs_mbox_read,
1931 .write = sysfs_mbox_write,
1935 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
1937 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1940 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1941 &sysfs_ctlreg_attr);
1945 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1948 goto out_remove_ctlreg_attr;
1951 out_remove_ctlreg_attr:
1952 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1958 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
1960 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1962 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1963 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1968 * Dynamic FC Host Attributes Support
1972 lpfc_get_host_port_id(struct Scsi_Host *shost)
1974 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1976 /* note: fc_myDID already in cpu endianness */
1977 fc_host_port_id(shost) = vport->fc_myDID;
1981 lpfc_get_host_port_type(struct Scsi_Host *shost)
1983 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1984 struct lpfc_hba *phba = vport->phba;
1986 spin_lock_irq(shost->host_lock);
1988 if (vport->port_type == LPFC_NPIV_PORT) {
1989 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1990 } else if (lpfc_is_link_up(phba)) {
1991 if (phba->fc_topology == TOPOLOGY_LOOP) {
1992 if (vport->fc_flag & FC_PUBLIC_LOOP)
1993 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1995 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1997 if (vport->fc_flag & FC_FABRIC)
1998 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2000 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2003 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2005 spin_unlock_irq(shost->host_lock);
2009 lpfc_get_host_port_state(struct Scsi_Host *shost)
2011 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2012 struct lpfc_hba *phba = vport->phba;
2014 spin_lock_irq(shost->host_lock);
2016 if (vport->fc_flag & FC_OFFLINE_MODE)
2017 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2019 switch (phba->link_state) {
2020 case LPFC_LINK_UNKNOWN:
2021 case LPFC_LINK_DOWN:
2022 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2026 case LPFC_HBA_READY:
2027 /* Links up, beyond this port_type reports state */
2028 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2030 case LPFC_HBA_ERROR:
2031 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
2034 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2039 spin_unlock_irq(shost->host_lock);
2043 lpfc_get_host_speed(struct Scsi_Host *shost)
2045 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2046 struct lpfc_hba *phba = vport->phba;
2048 spin_lock_irq(shost->host_lock);
2050 if (lpfc_is_link_up(phba)) {
2051 switch(phba->fc_linkspeed) {
2053 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
2056 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
2059 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
2062 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
2065 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2069 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2071 spin_unlock_irq(shost->host_lock);
2075 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2077 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2078 struct lpfc_hba *phba = vport->phba;
2081 spin_lock_irq(shost->host_lock);
2083 if ((vport->fc_flag & FC_FABRIC) ||
2084 ((phba->fc_topology == TOPOLOGY_LOOP) &&
2085 (vport->fc_flag & FC_PUBLIC_LOOP)))
2086 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
2088 /* fabric is local port if there is no F/FL_Port */
2091 spin_unlock_irq(shost->host_lock);
2093 fc_host_fabric_name(shost) = node_name;
2096 static struct fc_host_statistics *
2097 lpfc_get_stats(struct Scsi_Host *shost)
2099 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2100 struct lpfc_hba *phba = vport->phba;
2101 struct lpfc_sli *psli = &phba->sli;
2102 struct fc_host_statistics *hs = &phba->link_stats;
2103 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
2104 LPFC_MBOXQ_t *pmboxq;
2106 unsigned long seconds;
2110 * prevent udev from issuing mailbox commands until the port is
2113 if (phba->link_state < LPFC_LINK_DOWN ||
2114 !phba->mbox_mem_pool ||
2115 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
2118 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
2121 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2124 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2127 pmb->mbxCommand = MBX_READ_STATUS;
2128 pmb->mbxOwner = OWN_HOST;
2129 pmboxq->context1 = NULL;
2130 pmboxq->vport = vport;
2132 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2133 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2134 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2136 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2138 if (rc != MBX_SUCCESS) {
2139 if (rc != MBX_TIMEOUT)
2140 mempool_free(pmboxq, phba->mbox_mem_pool);
2144 memset(hs, 0, sizeof (struct fc_host_statistics));
2146 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
2147 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
2148 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
2149 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
2151 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2152 pmb->mbxCommand = MBX_READ_LNK_STAT;
2153 pmb->mbxOwner = OWN_HOST;
2154 pmboxq->context1 = NULL;
2155 pmboxq->vport = vport;
2157 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2158 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2159 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2161 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2163 if (rc != MBX_SUCCESS) {
2164 if (rc != MBX_TIMEOUT)
2165 mempool_free(pmboxq, phba->mbox_mem_pool);
2169 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2170 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2171 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2172 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2173 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2174 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2175 hs->error_frames = pmb->un.varRdLnk.crcCnt;
2177 hs->link_failure_count -= lso->link_failure_count;
2178 hs->loss_of_sync_count -= lso->loss_of_sync_count;
2179 hs->loss_of_signal_count -= lso->loss_of_signal_count;
2180 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
2181 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
2182 hs->invalid_crc_count -= lso->invalid_crc_count;
2183 hs->error_frames -= lso->error_frames;
2185 if (phba->fc_topology == TOPOLOGY_LOOP) {
2186 hs->lip_count = (phba->fc_eventTag >> 1);
2187 hs->lip_count -= lso->link_events;
2191 hs->nos_count = (phba->fc_eventTag >> 1);
2192 hs->nos_count -= lso->link_events;
2195 hs->dumped_frames = -1;
2197 seconds = get_seconds();
2198 if (seconds < psli->stats_start)
2199 hs->seconds_since_last_reset = seconds +
2200 ((unsigned long)-1 - psli->stats_start);
2202 hs->seconds_since_last_reset = seconds - psli->stats_start;
2204 mempool_free(pmboxq, phba->mbox_mem_pool);
2210 lpfc_reset_stats(struct Scsi_Host *shost)
2212 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2213 struct lpfc_hba *phba = vport->phba;
2214 struct lpfc_sli *psli = &phba->sli;
2215 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
2216 LPFC_MBOXQ_t *pmboxq;
2220 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
2223 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2226 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2229 pmb->mbxCommand = MBX_READ_STATUS;
2230 pmb->mbxOwner = OWN_HOST;
2231 pmb->un.varWords[0] = 0x1; /* reset request */
2232 pmboxq->context1 = NULL;
2233 pmboxq->vport = vport;
2235 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2236 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2237 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2239 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2241 if (rc != MBX_SUCCESS) {
2242 if (rc != MBX_TIMEOUT)
2243 mempool_free(pmboxq, phba->mbox_mem_pool);
2247 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2248 pmb->mbxCommand = MBX_READ_LNK_STAT;
2249 pmb->mbxOwner = OWN_HOST;
2250 pmboxq->context1 = NULL;
2251 pmboxq->vport = vport;
2253 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2254 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2255 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2257 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2259 if (rc != MBX_SUCCESS) {
2260 if (rc != MBX_TIMEOUT)
2261 mempool_free( pmboxq, phba->mbox_mem_pool);
2265 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2266 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2267 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2268 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2269 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2270 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2271 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2272 lso->link_events = (phba->fc_eventTag >> 1);
2274 psli->stats_start = get_seconds();
2276 mempool_free(pmboxq, phba->mbox_mem_pool);
2282 * The LPFC driver treats linkdown handling as target loss events so there
2283 * are no sysfs handlers for link_down_tmo.
2286 static struct lpfc_nodelist *
2287 lpfc_get_node_by_target(struct scsi_target *starget)
2289 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2290 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2291 struct lpfc_nodelist *ndlp;
2293 spin_lock_irq(shost->host_lock);
2294 /* Search for this, mapped, target ID */
2295 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2296 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
2297 starget->id == ndlp->nlp_sid) {
2298 spin_unlock_irq(shost->host_lock);
2302 spin_unlock_irq(shost->host_lock);
2307 lpfc_get_starget_port_id(struct scsi_target *starget)
2309 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2311 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
2315 lpfc_get_starget_node_name(struct scsi_target *starget)
2317 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2319 fc_starget_node_name(starget) =
2320 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
2324 lpfc_get_starget_port_name(struct scsi_target *starget)
2326 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2328 fc_starget_port_name(starget) =
2329 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
2333 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2336 rport->dev_loss_tmo = timeout;
2338 rport->dev_loss_tmo = 1;
2342 #define lpfc_rport_show_function(field, format_string, sz, cast) \
2344 lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2346 struct fc_rport *rport = transport_class_to_rport(cdev); \
2347 struct lpfc_rport_data *rdata = rport->hostdata; \
2348 return snprintf(buf, sz, format_string, \
2349 (rdata->target) ? cast rdata->target->field : 0); \
2352 #define lpfc_rport_rd_attr(field, format_string, sz) \
2353 lpfc_rport_show_function(field, format_string, sz, ) \
2354 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2357 struct fc_function_template lpfc_transport_functions = {
2358 /* fixed attributes the driver supports */
2359 .show_host_node_name = 1,
2360 .show_host_port_name = 1,
2361 .show_host_supported_classes = 1,
2362 .show_host_supported_fc4s = 1,
2363 .show_host_supported_speeds = 1,
2364 .show_host_maxframe_size = 1,
2366 /* dynamic attributes the driver supports */
2367 .get_host_port_id = lpfc_get_host_port_id,
2368 .show_host_port_id = 1,
2370 .get_host_port_type = lpfc_get_host_port_type,
2371 .show_host_port_type = 1,
2373 .get_host_port_state = lpfc_get_host_port_state,
2374 .show_host_port_state = 1,
2376 /* active_fc4s is shown but doesn't change (thus no get function) */
2377 .show_host_active_fc4s = 1,
2379 .get_host_speed = lpfc_get_host_speed,
2380 .show_host_speed = 1,
2382 .get_host_fabric_name = lpfc_get_host_fabric_name,
2383 .show_host_fabric_name = 1,
2386 * The LPFC driver treats linkdown handling as target loss events
2387 * so there are no sysfs handlers for link_down_tmo.
2390 .get_fc_host_stats = lpfc_get_stats,
2391 .reset_fc_host_stats = lpfc_reset_stats,
2393 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2394 .show_rport_maxframe_size = 1,
2395 .show_rport_supported_classes = 1,
2397 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2398 .show_rport_dev_loss_tmo = 1,
2400 .get_starget_port_id = lpfc_get_starget_port_id,
2401 .show_starget_port_id = 1,
2403 .get_starget_node_name = lpfc_get_starget_node_name,
2404 .show_starget_node_name = 1,
2406 .get_starget_port_name = lpfc_get_starget_port_name,
2407 .show_starget_port_name = 1,
2409 .issue_fc_host_lip = lpfc_issue_lip,
2410 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2411 .terminate_rport_io = lpfc_terminate_rport_io,
2413 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2416 struct fc_function_template lpfc_vport_transport_functions = {
2417 /* fixed attributes the driver supports */
2418 .show_host_node_name = 1,
2419 .show_host_port_name = 1,
2420 .show_host_supported_classes = 1,
2421 .show_host_supported_fc4s = 1,
2422 .show_host_supported_speeds = 1,
2423 .show_host_maxframe_size = 1,
2425 /* dynamic attributes the driver supports */
2426 .get_host_port_id = lpfc_get_host_port_id,
2427 .show_host_port_id = 1,
2429 .get_host_port_type = lpfc_get_host_port_type,
2430 .show_host_port_type = 1,
2432 .get_host_port_state = lpfc_get_host_port_state,
2433 .show_host_port_state = 1,
2435 /* active_fc4s is shown but doesn't change (thus no get function) */
2436 .show_host_active_fc4s = 1,
2438 .get_host_speed = lpfc_get_host_speed,
2439 .show_host_speed = 1,
2441 .get_host_fabric_name = lpfc_get_host_fabric_name,
2442 .show_host_fabric_name = 1,
2445 * The LPFC driver treats linkdown handling as target loss events
2446 * so there are no sysfs handlers for link_down_tmo.
2449 .get_fc_host_stats = lpfc_get_stats,
2450 .reset_fc_host_stats = lpfc_reset_stats,
2452 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2453 .show_rport_maxframe_size = 1,
2454 .show_rport_supported_classes = 1,
2456 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2457 .show_rport_dev_loss_tmo = 1,
2459 .get_starget_port_id = lpfc_get_starget_port_id,
2460 .show_starget_port_id = 1,
2462 .get_starget_node_name = lpfc_get_starget_node_name,
2463 .show_starget_node_name = 1,
2465 .get_starget_port_name = lpfc_get_starget_port_name,
2466 .show_starget_port_name = 1,
2468 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2469 .terminate_rport_io = lpfc_terminate_rport_io,
2471 .vport_disable = lpfc_vport_disable,
2475 lpfc_get_cfgparam(struct lpfc_hba *phba)
2477 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2478 lpfc_cr_count_init(phba, lpfc_cr_count);
2479 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
2480 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2481 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
2482 lpfc_ack0_init(phba, lpfc_ack0);
2483 lpfc_topology_init(phba, lpfc_topology);
2484 lpfc_link_speed_init(phba, lpfc_link_speed);
2485 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
2486 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
2487 lpfc_use_msi_init(phba, lpfc_use_msi);
2488 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
2489 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
2490 phba->cfg_poll = lpfc_poll;
2491 phba->cfg_soft_wwnn = 0L;
2492 phba->cfg_soft_wwpn = 0L;
2494 * The total number of segments is the configuration value plus 2
2495 * since the IOCB need a command and response bde.
2497 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
2499 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2500 * used to create the sg_dma_buf_pool must be dynamically calculated
2502 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2503 sizeof(struct fcp_rsp) +
2504 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
2505 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
2510 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2512 lpfc_log_verbose_init(vport, lpfc_log_verbose);
2513 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
2514 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
2515 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
2516 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
2517 lpfc_restrict_login_init(vport, lpfc_restrict_login);
2518 lpfc_fcp_class_init(vport, lpfc_fcp_class);
2519 lpfc_use_adisc_init(vport, lpfc_use_adisc);
2520 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
2521 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
2522 lpfc_max_luns_init(vport, lpfc_max_luns);
2523 lpfc_scan_down_init(vport, lpfc_scan_down);
2524 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);