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"
43 #define LPFC_DEF_DEVLOSS_TMO 30
44 #define LPFC_MIN_DEVLOSS_TMO 1
45 #define LPFC_MAX_DEVLOSS_TMO 255
48 lpfc_jedec_to_ascii(int incr, char hdw[])
51 for (i = 0; i < 8; i++) {
54 hdw[7 - i] = 0x30 + j;
56 hdw[7 - i] = 0x61 + j - 10;
64 lpfc_drvr_version_show(struct class_device *cdev, char *buf)
66 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
70 management_version_show(struct class_device *cdev, char *buf)
72 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
76 lpfc_info_show(struct class_device *cdev, char *buf)
78 struct Scsi_Host *host = class_to_shost(cdev);
80 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
84 lpfc_serialnum_show(struct class_device *cdev, char *buf)
86 struct Scsi_Host *shost = class_to_shost(cdev);
87 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
88 struct lpfc_hba *phba = vport->phba;
90 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
94 lpfc_modeldesc_show(struct class_device *cdev, char *buf)
96 struct Scsi_Host *shost = class_to_shost(cdev);
97 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
98 struct lpfc_hba *phba = vport->phba;
100 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
104 lpfc_modelname_show(struct class_device *cdev, char *buf)
106 struct Scsi_Host *shost = class_to_shost(cdev);
107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
108 struct lpfc_hba *phba = vport->phba;
110 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
114 lpfc_programtype_show(struct class_device *cdev, char *buf)
116 struct Scsi_Host *shost = class_to_shost(cdev);
117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
118 struct lpfc_hba *phba = vport->phba;
120 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
124 lpfc_vportnum_show(struct class_device *cdev, char *buf)
126 struct Scsi_Host *shost = class_to_shost(cdev);
127 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
128 struct lpfc_hba *phba = vport->phba;
130 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
134 lpfc_fwrev_show(struct class_device *cdev, char *buf)
136 struct Scsi_Host *shost = class_to_shost(cdev);
137 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
138 struct lpfc_hba *phba = vport->phba;
141 lpfc_decode_firmware_rev(phba, fwrev, 1);
142 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
146 lpfc_hdw_show(struct class_device *cdev, char *buf)
149 struct Scsi_Host *shost = class_to_shost(cdev);
150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
152 lpfc_vpd_t *vp = &phba->vpd;
154 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
155 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
158 lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
160 struct Scsi_Host *shost = class_to_shost(cdev);
161 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
162 struct lpfc_hba *phba = vport->phba;
164 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
167 lpfc_state_show(struct class_device *cdev, char *buf)
169 struct Scsi_Host *shost = class_to_shost(cdev);
170 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
171 struct lpfc_hba *phba = vport->phba;
174 switch (phba->link_state) {
175 case LPFC_LINK_UNKNOWN:
176 case LPFC_WARM_START:
177 case LPFC_INIT_START:
178 case LPFC_INIT_MBX_CMDS:
181 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down");
185 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - \n");
187 switch (vport->port_state) {
188 len += snprintf(buf + len, PAGE_SIZE-len,
191 case LPFC_LOCAL_CFG_LINK:
192 len += snprintf(buf + len, PAGE_SIZE-len,
196 case LPFC_FABRIC_CFG_LINK:
199 case LPFC_BUILD_DISC_LIST:
201 len += snprintf(buf + len, PAGE_SIZE - len,
204 case LPFC_VPORT_READY:
205 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
208 case LPFC_STATE_UNKNOWN:
209 len += snprintf(buf + len, PAGE_SIZE - len,
214 if (phba->fc_topology == TOPOLOGY_LOOP) {
215 if (vport->fc_flag & FC_PUBLIC_LOOP)
216 len += snprintf(buf + len, PAGE_SIZE-len,
219 len += snprintf(buf + len, PAGE_SIZE-len,
222 if (vport->fc_flag & FC_FABRIC)
223 len += snprintf(buf + len, PAGE_SIZE-len,
226 len += snprintf(buf + len, PAGE_SIZE-len,
235 lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
237 struct Scsi_Host *shost = class_to_shost(cdev);
238 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240 return snprintf(buf, PAGE_SIZE, "%d\n",
241 vport->fc_map_cnt + vport->fc_unmap_cnt);
246 lpfc_issue_lip(struct Scsi_Host *shost)
248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
249 struct lpfc_hba *phba = vport->phba;
250 LPFC_MBOXQ_t *pmboxq;
251 int mbxstatus = MBXERR_ERROR;
253 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
254 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
255 (vport->port_state != LPFC_VPORT_READY))
258 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
263 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
264 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
265 pmboxq->mb.mbxOwner = OWN_HOST;
267 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
269 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
270 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
271 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
272 phba->cfg_link_speed);
273 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
277 lpfc_set_loopback_flag(phba);
278 if (mbxstatus == MBX_TIMEOUT)
279 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
281 mempool_free(pmboxq, phba->mbox_mem_pool);
283 if (mbxstatus == MBXERR_ERROR)
290 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
292 struct completion online_compl;
293 struct lpfc_sli_ring *pring;
294 struct lpfc_sli *psli;
299 init_completion(&online_compl);
300 lpfc_workq_post_event(phba, &status, &online_compl,
301 LPFC_EVT_OFFLINE_PREP);
302 wait_for_completion(&online_compl);
309 for (i = 0; i < psli->num_rings; i++) {
310 pring = &psli->ring[i];
311 /* The linkdown event takes 30 seconds to timeout. */
312 while (pring->txcmplq_cnt) {
315 lpfc_printf_log(phba,
316 KERN_WARNING, LOG_INIT,
317 "%d:0466 Outstanding IO when "
318 "bringing Adapter offline\n",
325 init_completion(&online_compl);
326 lpfc_workq_post_event(phba, &status, &online_compl, type);
327 wait_for_completion(&online_compl);
336 lpfc_selective_reset(struct lpfc_hba *phba)
338 struct completion online_compl;
341 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
346 init_completion(&online_compl);
347 lpfc_workq_post_event(phba, &status, &online_compl,
349 wait_for_completion(&online_compl);
358 lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
360 struct Scsi_Host *shost = class_to_shost(cdev);
361 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
362 struct lpfc_hba *phba = vport->phba;
364 int status = -EINVAL;
366 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
367 status = lpfc_selective_reset(phba);
376 lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
378 struct Scsi_Host *shost = class_to_shost(cdev);
379 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
380 struct lpfc_hba *phba = vport->phba;
382 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
386 lpfc_board_mode_show(struct class_device *cdev, char *buf)
388 struct Scsi_Host *shost = class_to_shost(cdev);
389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
390 struct lpfc_hba *phba = vport->phba;
393 if (phba->link_state == LPFC_HBA_ERROR)
395 else if (phba->link_state == LPFC_WARM_START)
396 state = "warm start";
397 else if (phba->link_state == LPFC_INIT_START)
402 return snprintf(buf, PAGE_SIZE, "%s\n", state);
406 lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
408 struct Scsi_Host *shost = class_to_shost(cdev);
409 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
410 struct lpfc_hba *phba = vport->phba;
411 struct completion online_compl;
414 init_completion(&online_compl);
416 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
417 lpfc_workq_post_event(phba, &status, &online_compl,
419 wait_for_completion(&online_compl);
420 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
421 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
422 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
423 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
424 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
425 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
436 lpfc_poll_show(struct class_device *cdev, char *buf)
438 struct Scsi_Host *shost = class_to_shost(cdev);
439 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
440 struct lpfc_hba *phba = vport->phba;
442 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
446 lpfc_poll_store(struct class_device *cdev, const char *buf,
449 struct Scsi_Host *shost = class_to_shost(cdev);
450 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
451 struct lpfc_hba *phba = vport->phba;
456 if (!isdigit(buf[0]))
459 if (sscanf(buf, "%i", &val) != 1)
462 if ((val & 0x3) != val)
465 spin_lock_irq(&phba->hbalock);
467 old_val = phba->cfg_poll;
469 if (val & ENABLE_FCP_RING_POLLING) {
470 if ((val & DISABLE_FCP_RING_INT) &&
471 !(old_val & DISABLE_FCP_RING_INT)) {
472 creg_val = readl(phba->HCregaddr);
473 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
474 writel(creg_val, phba->HCregaddr);
475 readl(phba->HCregaddr); /* flush */
477 lpfc_poll_start_timer(phba);
479 } else if (val != 0x0) {
480 spin_unlock_irq(&phba->hbalock);
484 if (!(val & DISABLE_FCP_RING_INT) &&
485 (old_val & DISABLE_FCP_RING_INT))
487 spin_unlock_irq(&phba->hbalock);
488 del_timer(&phba->fcp_poll_timer);
489 spin_lock_irq(&phba->hbalock);
490 creg_val = readl(phba->HCregaddr);
491 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
492 writel(creg_val, phba->HCregaddr);
493 readl(phba->HCregaddr); /* flush */
496 phba->cfg_poll = val;
498 spin_unlock_irq(&phba->hbalock);
503 #define lpfc_param_show(attr) \
505 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
507 struct Scsi_Host *shost = class_to_shost(cdev);\
508 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
509 struct lpfc_hba *phba = vport->phba;\
511 val = phba->cfg_##attr;\
512 return snprintf(buf, PAGE_SIZE, "%d\n",\
516 #define lpfc_param_hex_show(attr) \
518 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
520 struct Scsi_Host *shost = class_to_shost(cdev);\
521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
522 struct lpfc_hba *phba = vport->phba;\
524 val = phba->cfg_##attr;\
525 return snprintf(buf, PAGE_SIZE, "%#x\n",\
529 #define lpfc_param_init(attr, default, minval, maxval) \
531 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
533 if (val >= minval && val <= maxval) {\
534 phba->cfg_##attr = val;\
537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
538 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
539 "allowed range is ["#minval", "#maxval"]\n", \
540 phba->brd_no, val); \
541 phba->cfg_##attr = default;\
545 #define lpfc_param_set(attr, default, minval, maxval) \
547 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
549 if (val >= minval && val <= maxval) {\
550 phba->cfg_##attr = val;\
553 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
554 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
555 "allowed range is ["#minval", "#maxval"]\n", \
556 phba->brd_no, val); \
560 #define lpfc_param_store(attr) \
562 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
564 struct Scsi_Host *shost = class_to_shost(cdev);\
565 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
566 struct lpfc_hba *phba = vport->phba;\
568 if (!isdigit(buf[0]))\
570 if (sscanf(buf, "%i", &val) != 1)\
572 if (lpfc_##attr##_set(phba, val) == 0) \
578 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
579 static int lpfc_##name = defval;\
580 module_param(lpfc_##name, int, 0);\
581 MODULE_PARM_DESC(lpfc_##name, desc);\
582 lpfc_param_init(name, defval, minval, maxval)
584 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
585 static int lpfc_##name = defval;\
586 module_param(lpfc_##name, int, 0);\
587 MODULE_PARM_DESC(lpfc_##name, desc);\
588 lpfc_param_show(name)\
589 lpfc_param_init(name, defval, minval, maxval)\
590 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
592 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
593 static int lpfc_##name = defval;\
594 module_param(lpfc_##name, int, 0);\
595 MODULE_PARM_DESC(lpfc_##name, desc);\
596 lpfc_param_show(name)\
597 lpfc_param_init(name, defval, minval, maxval)\
598 lpfc_param_set(name, defval, minval, maxval)\
599 lpfc_param_store(name)\
600 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
601 lpfc_##name##_show, lpfc_##name##_store)
603 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
604 static int lpfc_##name = defval;\
605 module_param(lpfc_##name, int, 0);\
606 MODULE_PARM_DESC(lpfc_##name, desc);\
607 lpfc_param_hex_show(name)\
608 lpfc_param_init(name, defval, minval, maxval)\
609 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
611 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
612 static int lpfc_##name = defval;\
613 module_param(lpfc_##name, int, 0);\
614 MODULE_PARM_DESC(lpfc_##name, desc);\
615 lpfc_param_hex_show(name)\
616 lpfc_param_init(name, defval, minval, maxval)\
617 lpfc_param_set(name, defval, minval, maxval)\
618 lpfc_param_store(name)\
619 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
620 lpfc_##name##_show, lpfc_##name##_store)
622 static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
623 static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
624 static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
625 static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
626 static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
627 static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
628 static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
629 static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
630 static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
631 static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
632 lpfc_option_rom_version_show, NULL);
633 static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
634 lpfc_num_discovered_ports_show, NULL);
635 static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
636 static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
638 static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
640 static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
641 lpfc_board_mode_show, lpfc_board_mode_store);
642 static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
645 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
648 lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
651 struct Scsi_Host *shost = class_to_shost(cdev);
652 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
653 struct lpfc_hba *phba = vport->phba;
654 unsigned int cnt = count;
657 * We're doing a simple sanity check for soft_wwpn setting.
658 * We require that the user write a specific key to enable
659 * the soft_wwpn attribute to be settable. Once the attribute
660 * is written, the enable key resets. If further updates are
661 * desired, the key must be written again to re-enable the
664 * The "key" is not secret - it is a hardcoded string shown
665 * here. The intent is to protect against the random user or
666 * application that is just writing attributes.
669 /* count may include a LF at end of string */
670 if (buf[cnt-1] == '\n')
673 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
674 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
677 phba->soft_wwn_enable = 1;
680 static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
681 lpfc_soft_wwn_enable_store);
684 lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
686 struct Scsi_Host *shost = class_to_shost(cdev);
687 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
688 struct lpfc_hba *phba = vport->phba;
690 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
691 (unsigned long long)phba->cfg_soft_wwpn);
696 lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
698 struct Scsi_Host *shost = class_to_shost(cdev);
699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
700 struct lpfc_hba *phba = vport->phba;
701 struct completion online_compl;
702 int stat1=0, stat2=0;
703 unsigned int i, j, cnt=count;
706 /* count may include a LF at end of string */
707 if (buf[cnt-1] == '\n')
710 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
711 ((cnt == 17) && (*buf++ != 'x')) ||
712 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
715 phba->soft_wwn_enable = 0;
717 memset(wwpn, 0, sizeof(wwpn));
719 /* Validate and store the new name */
720 for (i=0, j=0; i < 16; i++) {
721 if ((*buf >= 'a') && (*buf <= 'f'))
722 j = ((j << 4) | ((*buf++ -'a') + 10));
723 else if ((*buf >= 'A') && (*buf <= 'F'))
724 j = ((j << 4) | ((*buf++ -'A') + 10));
725 else if ((*buf >= '0') && (*buf <= '9'))
726 j = ((j << 4) | (*buf++ -'0'));
730 wwpn[i/2] = j & 0xff;
734 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
735 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
736 if (phba->cfg_soft_wwnn)
737 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
739 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
740 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
742 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
744 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
745 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
746 "adapter - %d\n", phba->brd_no, stat1);
748 init_completion(&online_compl);
749 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
750 wait_for_completion(&online_compl);
752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
753 "%d:0464 lpfc_soft_wwpn attribute set failed to reinit "
754 "adapter - %d\n", phba->brd_no, stat2);
756 return (stat1 || stat2) ? -EIO : count;
758 static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
759 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
762 lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
764 struct Scsi_Host *host = class_to_shost(cdev);
765 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
766 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
767 (unsigned long long)phba->cfg_soft_wwnn);
772 lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
774 struct Scsi_Host *host = class_to_shost(cdev);
775 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
776 unsigned int i, j, cnt=count;
779 /* count may include a LF at end of string */
780 if (buf[cnt-1] == '\n')
783 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
784 ((cnt == 17) && (*buf++ != 'x')) ||
785 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
789 * Allow wwnn to be set many times, as long as the enable is set.
790 * However, once the wwpn is set, everything locks.
793 memset(wwnn, 0, sizeof(wwnn));
795 /* Validate and store the new name */
796 for (i=0, j=0; i < 16; i++) {
797 if ((*buf >= 'a') && (*buf <= 'f'))
798 j = ((j << 4) | ((*buf++ -'a') + 10));
799 else if ((*buf >= 'A') && (*buf <= 'F'))
800 j = ((j << 4) | ((*buf++ -'A') + 10));
801 else if ((*buf >= '0') && (*buf <= '9'))
802 j = ((j << 4) | (*buf++ -'0'));
806 wwnn[i/2] = j & 0xff;
810 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
812 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
813 "lpfc%d: soft_wwnn set. Value will take effect upon "
814 "setting of the soft_wwpn\n", phba->brd_no);
818 static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
819 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
822 static int lpfc_poll = 0;
823 module_param(lpfc_poll, int, 0);
824 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
826 " 1 - poll with interrupts enabled"
827 " 3 - poll and disable FCP ring interrupts");
829 static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
830 lpfc_poll_show, lpfc_poll_store);
833 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
834 # until the timer expires. Value range is [0,255]. Default value is 30.
836 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
837 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
838 module_param(lpfc_nodev_tmo, int, 0);
839 MODULE_PARM_DESC(lpfc_nodev_tmo,
840 "Seconds driver will hold I/O waiting "
841 "for a device to come back");
843 lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
845 struct Scsi_Host *shost = class_to_shost(cdev);
846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
847 struct lpfc_hba *phba = vport->phba;
849 val = phba->cfg_devloss_tmo;
850 return snprintf(buf, PAGE_SIZE, "%d\n",
851 phba->cfg_devloss_tmo);
855 lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
858 if (phba->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
859 phba->cfg_nodev_tmo = phba->cfg_devloss_tmo;
860 if (!warned && val != LPFC_DEF_DEVLOSS_TMO) {
862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
863 "%d:0402 Ignoring nodev_tmo module "
864 "parameter because devloss_tmo is"
871 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
872 phba->cfg_nodev_tmo = val;
873 phba->cfg_devloss_tmo = val;
876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
877 "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, "
878 "allowed range is [%d, %d]\n",
880 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
881 phba->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
886 lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
888 if (phba->dev_loss_tmo_changed ||
889 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
891 "%d:0401 Ignoring change to nodev_tmo "
892 "because devloss_tmo is set.\n",
897 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
898 phba->cfg_nodev_tmo = val;
899 phba->cfg_devloss_tmo = val;
903 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
904 "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, "
905 "allowed range is [%d, %d]\n",
906 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
907 LPFC_MAX_DEVLOSS_TMO);
911 lpfc_param_store(nodev_tmo)
913 static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
914 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
917 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
918 # disappear until the timer expires. Value range is [0,255]. Default
921 module_param(lpfc_devloss_tmo, int, 0);
922 MODULE_PARM_DESC(lpfc_devloss_tmo,
923 "Seconds driver will hold I/O waiting "
924 "for a device to come back");
925 lpfc_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
926 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
927 lpfc_param_show(devloss_tmo)
929 lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
931 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
932 phba->cfg_nodev_tmo = val;
933 phba->cfg_devloss_tmo = val;
934 phba->dev_loss_tmo_changed = 1;
938 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
939 "%d:0404 lpfc_devloss_tmo attribute cannot be set to"
940 " %d, allowed range is [%d, %d]\n",
941 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
942 LPFC_MAX_DEVLOSS_TMO);
946 lpfc_param_store(devloss_tmo)
947 static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
948 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
951 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
952 # deluged with LOTS of information.
953 # You can set a bit mask to record specific types of verbose messages:
955 # LOG_ELS 0x1 ELS events
956 # LOG_DISCOVERY 0x2 Link discovery events
957 # LOG_MBOX 0x4 Mailbox events
958 # LOG_INIT 0x8 Initialization events
959 # LOG_LINK_EVENT 0x10 Link events
960 # LOG_FCP 0x40 FCP traffic history
961 # LOG_NODE 0x80 Node table events
962 # LOG_MISC 0x400 Miscellaneous events
963 # LOG_SLI 0x800 SLI events
964 # LOG_FCP_ERROR 0x1000 Only log FCP errors
965 # LOG_LIBDFC 0x2000 LIBDFC events
966 # LOG_ALL_MSG 0xffff LOG all messages
968 LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
971 # lun_queue_depth: This parameter is used to limit the number of outstanding
972 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
974 LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
975 "Max number of FCP commands we can queue to a specific LUN");
978 # hba_queue_depth: This parameter is used to limit the number of outstanding
979 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
980 # value is greater than the maximum number of exchanges supported by the HBA,
981 # then maximum number of exchanges supported by the HBA is used to determine
982 # the hba_queue_depth.
984 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
985 "Max number of FCP commands we can queue to a lpfc HBA");
988 # Some disk devices have a "select ID" or "select Target" capability.
989 # From a protocol standpoint "select ID" usually means select the
990 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
991 # annex" which contains a table that maps a "select ID" (a number
992 # between 0 and 7F) to an ALPA. By default, for compatibility with
993 # older drivers, the lpfc driver scans this table from low ALPA to high
996 # Turning on the scan-down variable (on = 1, off = 0) will
997 # cause the lpfc driver to use an inverted table, effectively
998 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1000 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
1001 # and will not work across a fabric. Also this parameter will take
1002 # effect only in the case when ALPA map is not available.)
1004 LPFC_ATTR_R(scan_down, 1, 0, 1,
1005 "Start scanning for devices from highest ALPA to lowest");
1008 # lpfc_topology: link topology for init link
1009 # 0x0 = attempt loop mode then point-to-point
1010 # 0x01 = internal loopback mode
1011 # 0x02 = attempt point-to-point mode only
1012 # 0x04 = attempt loop mode only
1013 # 0x06 = attempt point-to-point mode then loop
1014 # Set point-to-point mode if you want to run as an N_Port.
1015 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1016 # Default value is 0.
1018 LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
1021 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1023 # 0 = auto select (default)
1028 # Value range is [0,8]. Default value is 0.
1030 LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
1033 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1034 # Value range is [2,3]. Default value is 3.
1036 LPFC_ATTR_R(fcp_class, 3, 2, 3,
1037 "Select Fibre Channel class of service for FCP sequences");
1040 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1041 # is [0,1]. Default value is 0.
1043 LPFC_ATTR_RW(use_adisc, 0, 0, 1,
1044 "Use ADISC on rediscovery to authenticate FCP devices");
1047 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1048 # range is [0,1]. Default value is 0.
1050 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1053 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1054 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
1055 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
1056 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1057 # cr_delay is set to 0.
1059 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
1060 "interrupt response is generated");
1062 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
1063 "interrupt response is generated");
1066 # lpfc_multi_ring_support: Determines how many rings to spread available
1067 # cmd/rsp IOCB entries across.
1068 # Value range is [1,2]. Default value is 1.
1070 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1071 "SLI rings to spread IOCB entries across");
1074 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1075 # identifies what rctl value to configure the additional ring for.
1076 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1078 LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1079 255, "Identifies RCTL for additional ring configuration");
1082 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1083 # identifies what type value to configure the additional ring for.
1084 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1086 LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1087 255, "Identifies TYPE for additional ring configuration");
1090 # lpfc_fdmi_on: controls FDMI support.
1091 # 0 = no FDMI support
1092 # 1 = support FDMI without attribute of hostname
1093 # 2 = support FDMI with attribute of hostname
1094 # Value range [0,2]. Default value is 0.
1096 LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
1099 # Specifies the maximum number of ELS cmds we can have outstanding (for
1100 # discovery). Value range is [1,64]. Default value = 32.
1102 LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
1103 "during discovery");
1106 # lpfc_max_luns: maximum allowed LUN.
1107 # Value range is [0,65535]. Default value is 255.
1108 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
1110 LPFC_ATTR_R(max_luns, 255, 0, 65535,
1111 "Maximum allowed LUN");
1114 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1115 # Value range is [1,255], default value is 10.
1117 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1118 "Milliseconds driver will wait between polling FCP ring");
1121 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1122 # support this feature
1123 # 0 = MSI disabled (default)
1125 # Value range is [0,1]. Default value is 0.
1127 LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1130 struct class_device_attribute *lpfc_hba_attrs[] = {
1131 &class_device_attr_info,
1132 &class_device_attr_serialnum,
1133 &class_device_attr_modeldesc,
1134 &class_device_attr_modelname,
1135 &class_device_attr_programtype,
1136 &class_device_attr_portnum,
1137 &class_device_attr_fwrev,
1138 &class_device_attr_hdw,
1139 &class_device_attr_option_rom_version,
1140 &class_device_attr_state,
1141 &class_device_attr_num_discovered_ports,
1142 &class_device_attr_lpfc_drvr_version,
1143 &class_device_attr_lpfc_log_verbose,
1144 &class_device_attr_lpfc_lun_queue_depth,
1145 &class_device_attr_lpfc_hba_queue_depth,
1146 &class_device_attr_lpfc_nodev_tmo,
1147 &class_device_attr_lpfc_devloss_tmo,
1148 &class_device_attr_lpfc_fcp_class,
1149 &class_device_attr_lpfc_use_adisc,
1150 &class_device_attr_lpfc_ack0,
1151 &class_device_attr_lpfc_topology,
1152 &class_device_attr_lpfc_scan_down,
1153 &class_device_attr_lpfc_link_speed,
1154 &class_device_attr_lpfc_cr_delay,
1155 &class_device_attr_lpfc_cr_count,
1156 &class_device_attr_lpfc_multi_ring_support,
1157 &class_device_attr_lpfc_multi_ring_rctl,
1158 &class_device_attr_lpfc_multi_ring_type,
1159 &class_device_attr_lpfc_fdmi_on,
1160 &class_device_attr_lpfc_max_luns,
1161 &class_device_attr_nport_evt_cnt,
1162 &class_device_attr_management_version,
1163 &class_device_attr_board_mode,
1164 &class_device_attr_issue_reset,
1165 &class_device_attr_lpfc_poll,
1166 &class_device_attr_lpfc_poll_tmo,
1167 &class_device_attr_lpfc_use_msi,
1168 &class_device_attr_lpfc_soft_wwnn,
1169 &class_device_attr_lpfc_soft_wwpn,
1170 &class_device_attr_lpfc_soft_wwn_enable,
1175 sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1178 struct class_device *cdev = container_of(kobj, struct class_device,
1180 struct Scsi_Host *shost = class_to_shost(cdev);
1181 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1182 struct lpfc_hba *phba = vport->phba;
1184 if ((off + count) > FF_REG_AREA_SIZE)
1187 if (count == 0) return 0;
1189 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1192 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1196 spin_lock_irq(&phba->hbalock);
1197 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1198 writel(*((uint32_t *)(buf + buf_off)),
1199 phba->ctrl_regs_memmap_p + off + buf_off);
1201 spin_unlock_irq(&phba->hbalock);
1207 sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1211 struct class_device *cdev = container_of(kobj, struct class_device,
1213 struct Scsi_Host *shost = class_to_shost(cdev);
1214 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1215 struct lpfc_hba *phba = vport->phba;
1217 if (off > FF_REG_AREA_SIZE)
1220 if ((off + count) > FF_REG_AREA_SIZE)
1221 count = FF_REG_AREA_SIZE - off;
1223 if (count == 0) return 0;
1225 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1228 spin_lock_irq(&phba->hbalock);
1230 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1231 tmp_ptr = (uint32_t *)(buf + buf_off);
1232 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1235 spin_unlock_irq(&phba->hbalock);
1240 static struct bin_attribute sysfs_ctlreg_attr = {
1243 .mode = S_IRUSR | S_IWUSR,
1244 .owner = THIS_MODULE,
1247 .read = sysfs_ctlreg_read,
1248 .write = sysfs_ctlreg_write,
1253 sysfs_mbox_idle(struct lpfc_hba *phba)
1255 phba->sysfs_mbox.state = SMBOX_IDLE;
1256 phba->sysfs_mbox.offset = 0;
1258 if (phba->sysfs_mbox.mbox) {
1259 mempool_free(phba->sysfs_mbox.mbox,
1260 phba->mbox_mem_pool);
1261 phba->sysfs_mbox.mbox = NULL;
1266 sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1268 struct class_device *cdev = container_of(kobj, struct class_device,
1270 struct Scsi_Host *shost = class_to_shost(cdev);
1271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1272 struct lpfc_hba *phba = vport->phba;
1273 struct lpfcMboxq *mbox = NULL;
1275 if ((count + off) > MAILBOX_CMD_SIZE)
1278 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1285 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1288 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
1291 spin_lock_irq(&phba->hbalock);
1294 if (phba->sysfs_mbox.mbox)
1295 mempool_free(mbox, phba->mbox_mem_pool);
1297 phba->sysfs_mbox.mbox = mbox;
1298 phba->sysfs_mbox.state = SMBOX_WRITING;
1300 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1301 phba->sysfs_mbox.offset != off ||
1302 phba->sysfs_mbox.mbox == NULL ) {
1303 sysfs_mbox_idle(phba);
1304 spin_unlock_irq(&phba->hbalock);
1309 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1312 phba->sysfs_mbox.offset = off + count;
1314 spin_unlock_irq(&phba->hbalock);
1320 sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1322 struct class_device *cdev = container_of(kobj, struct class_device,
1324 struct Scsi_Host *shost = class_to_shost(cdev);
1325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1326 struct lpfc_hba *phba = vport->phba;
1329 if (off > MAILBOX_CMD_SIZE)
1332 if ((count + off) > MAILBOX_CMD_SIZE)
1333 count = MAILBOX_CMD_SIZE - off;
1335 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1338 if (off && count == 0)
1341 spin_lock_irq(&phba->hbalock);
1344 phba->sysfs_mbox.state == SMBOX_WRITING &&
1345 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1347 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1352 case MBX_CONFIG_LINK:
1353 case MBX_CONFIG_RING:
1354 case MBX_RESET_RING:
1355 case MBX_UNREG_LOGIN:
1357 case MBX_DUMP_CONTEXT:
1360 case MBX_FLASH_WR_ULA:
1364 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1365 printk(KERN_WARNING "mbox_read:Command 0x%x "
1366 "is illegal in on-line state\n",
1367 phba->sysfs_mbox.mbox->mb.mbxCommand);
1368 sysfs_mbox_idle(phba);
1369 spin_unlock_irq(&phba->hbalock);
1374 case MBX_READ_CONFIG:
1375 case MBX_READ_RCONFIG:
1376 case MBX_READ_STATUS:
1379 case MBX_READ_LNK_STAT:
1380 case MBX_DUMP_MEMORY:
1382 case MBX_UPDATE_CFG:
1383 case MBX_KILL_BOARD:
1385 case MBX_LOAD_EXP_ROM:
1387 case MBX_DEL_LD_ENTRY:
1389 case MBX_READ_SPARM64:
1393 case MBX_REG_LOGIN64:
1394 case MBX_CONFIG_PORT:
1395 case MBX_RUN_BIU_DIAG:
1396 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1397 phba->sysfs_mbox.mbox->mb.mbxCommand);
1398 sysfs_mbox_idle(phba);
1399 spin_unlock_irq(&phba->hbalock);
1402 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1403 phba->sysfs_mbox.mbox->mb.mbxCommand);
1404 sysfs_mbox_idle(phba);
1405 spin_unlock_irq(&phba->hbalock);
1409 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
1410 sysfs_mbox_idle(phba);
1411 spin_unlock_irq(&phba->hbalock);
1415 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1416 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1418 spin_unlock_irq(&phba->hbalock);
1419 rc = lpfc_sli_issue_mbox (phba,
1420 phba->sysfs_mbox.mbox,
1422 spin_lock_irq(&phba->hbalock);
1425 spin_unlock_irq(&phba->hbalock);
1426 rc = lpfc_sli_issue_mbox_wait (phba,
1427 phba->sysfs_mbox.mbox,
1428 lpfc_mbox_tmo_val(phba,
1429 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
1430 spin_lock_irq(&phba->hbalock);
1433 if (rc != MBX_SUCCESS) {
1434 if (rc == MBX_TIMEOUT) {
1435 phba->sysfs_mbox.mbox->mbox_cmpl =
1436 lpfc_sli_def_mbox_cmpl;
1437 phba->sysfs_mbox.mbox = NULL;
1439 sysfs_mbox_idle(phba);
1440 spin_unlock_irq(&phba->hbalock);
1441 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
1443 phba->sysfs_mbox.state = SMBOX_READING;
1445 else if (phba->sysfs_mbox.offset != off ||
1446 phba->sysfs_mbox.state != SMBOX_READING) {
1447 printk(KERN_WARNING "mbox_read: Bad State\n");
1448 sysfs_mbox_idle(phba);
1449 spin_unlock_irq(&phba->hbalock);
1453 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1455 phba->sysfs_mbox.offset = off + count;
1457 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
1458 sysfs_mbox_idle(phba);
1460 spin_unlock_irq(&phba->hbalock);
1465 static struct bin_attribute sysfs_mbox_attr = {
1468 .mode = S_IRUSR | S_IWUSR,
1469 .owner = THIS_MODULE,
1471 .size = MAILBOX_CMD_SIZE,
1472 .read = sysfs_mbox_read,
1473 .write = sysfs_mbox_write,
1477 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
1479 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1482 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1483 &sysfs_ctlreg_attr);
1487 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1490 goto out_remove_ctlreg_attr;
1493 out_remove_ctlreg_attr:
1494 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1500 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
1502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1504 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1505 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1510 * Dynamic FC Host Attributes Support
1514 lpfc_get_host_port_id(struct Scsi_Host *shost)
1516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1518 /* note: fc_myDID already in cpu endianness */
1519 fc_host_port_id(shost) = vport->fc_myDID;
1523 lpfc_get_host_port_type(struct Scsi_Host *shost)
1525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1526 struct lpfc_hba *phba = vport->phba;
1528 spin_lock_irq(shost->host_lock);
1530 if (lpfc_is_link_up(phba)) {
1531 if (phba->fc_topology == TOPOLOGY_LOOP) {
1532 if (vport->fc_flag & FC_PUBLIC_LOOP)
1533 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1535 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1537 if (vport->fc_flag & FC_FABRIC)
1538 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1540 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1543 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1545 spin_unlock_irq(shost->host_lock);
1549 lpfc_get_host_port_state(struct Scsi_Host *shost)
1551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1552 struct lpfc_hba *phba = vport->phba;
1554 spin_lock_irq(shost->host_lock);
1556 if (vport->fc_flag & FC_OFFLINE_MODE)
1557 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1559 switch (phba->link_state) {
1560 case LPFC_LINK_UNKNOWN:
1561 case LPFC_LINK_DOWN:
1562 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1566 /* Links up, beyond this port_type reports state */
1567 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1569 case LPFC_HBA_ERROR:
1570 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1573 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1578 spin_unlock_irq(shost->host_lock);
1582 lpfc_get_host_speed(struct Scsi_Host *shost)
1584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1585 struct lpfc_hba *phba = vport->phba;
1587 spin_lock_irq(shost->host_lock);
1589 if (lpfc_is_link_up(phba)) {
1590 switch(phba->fc_linkspeed) {
1592 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1595 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1598 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1601 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
1604 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1609 spin_unlock_irq(shost->host_lock);
1613 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1616 struct lpfc_hba *phba = vport->phba;
1619 spin_lock_irq(shost->host_lock);
1621 if ((vport->fc_flag & FC_FABRIC) ||
1622 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1623 (vport->fc_flag & FC_PUBLIC_LOOP)))
1624 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
1626 /* fabric is local port if there is no F/FL_Port */
1627 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
1629 spin_unlock_irq(shost->host_lock);
1631 fc_host_fabric_name(shost) = node_name;
1634 static struct fc_host_statistics *
1635 lpfc_get_stats(struct Scsi_Host *shost)
1637 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1638 struct lpfc_hba *phba = vport->phba;
1639 struct lpfc_sli *psli = &phba->sli;
1640 struct fc_host_statistics *hs = &phba->link_stats;
1641 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1642 LPFC_MBOXQ_t *pmboxq;
1644 unsigned long seconds;
1647 /* prevent udev from issuing mailbox commands
1648 * until the port is configured.
1650 if (phba->link_state < LPFC_LINK_DOWN ||
1651 !phba->mbox_mem_pool ||
1652 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
1655 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1658 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1661 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1664 pmb->mbxCommand = MBX_READ_STATUS;
1665 pmb->mbxOwner = OWN_HOST;
1666 pmboxq->context1 = NULL;
1668 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1669 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1670 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1672 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1674 if (rc != MBX_SUCCESS) {
1675 if (rc == MBX_TIMEOUT)
1676 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1678 mempool_free(pmboxq, phba->mbox_mem_pool);
1682 memset(hs, 0, sizeof (struct fc_host_statistics));
1684 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1685 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1686 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1687 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1689 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1690 pmb->mbxCommand = MBX_READ_LNK_STAT;
1691 pmb->mbxOwner = OWN_HOST;
1692 pmboxq->context1 = NULL;
1694 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1695 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1696 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1698 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1700 if (rc != MBX_SUCCESS) {
1701 if (rc == MBX_TIMEOUT)
1702 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1704 mempool_free( pmboxq, phba->mbox_mem_pool);
1708 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1709 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1710 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1711 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1712 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1713 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1714 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1716 hs->link_failure_count -= lso->link_failure_count;
1717 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1718 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1719 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1720 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1721 hs->invalid_crc_count -= lso->invalid_crc_count;
1722 hs->error_frames -= lso->error_frames;
1724 if (phba->fc_topology == TOPOLOGY_LOOP) {
1725 hs->lip_count = (phba->fc_eventTag >> 1);
1726 hs->lip_count -= lso->link_events;
1730 hs->nos_count = (phba->fc_eventTag >> 1);
1731 hs->nos_count -= lso->link_events;
1734 hs->dumped_frames = -1;
1736 seconds = get_seconds();
1737 if (seconds < psli->stats_start)
1738 hs->seconds_since_last_reset = seconds +
1739 ((unsigned long)-1 - psli->stats_start);
1741 hs->seconds_since_last_reset = seconds - psli->stats_start;
1743 mempool_free(pmboxq, phba->mbox_mem_pool);
1749 lpfc_reset_stats(struct Scsi_Host *shost)
1751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1752 struct lpfc_hba *phba = vport->phba;
1753 struct lpfc_sli *psli = &phba->sli;
1754 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
1755 LPFC_MBOXQ_t *pmboxq;
1759 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1762 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1765 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1768 pmb->mbxCommand = MBX_READ_STATUS;
1769 pmb->mbxOwner = OWN_HOST;
1770 pmb->un.varWords[0] = 0x1; /* reset request */
1771 pmboxq->context1 = NULL;
1773 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1774 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1775 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1777 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1779 if (rc != MBX_SUCCESS) {
1780 if (rc == MBX_TIMEOUT)
1781 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1783 mempool_free(pmboxq, phba->mbox_mem_pool);
1787 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1788 pmb->mbxCommand = MBX_READ_LNK_STAT;
1789 pmb->mbxOwner = OWN_HOST;
1790 pmboxq->context1 = NULL;
1792 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1793 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1794 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1796 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1798 if (rc != MBX_SUCCESS) {
1799 if (rc == MBX_TIMEOUT)
1800 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1802 mempool_free( pmboxq, phba->mbox_mem_pool);
1806 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1807 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1808 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1809 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1810 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1811 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1812 lso->error_frames = pmb->un.varRdLnk.crcCnt;
1813 lso->link_events = (phba->fc_eventTag >> 1);
1815 psli->stats_start = get_seconds();
1817 mempool_free(pmboxq, phba->mbox_mem_pool);
1823 * The LPFC driver treats linkdown handling as target loss events so there
1824 * are no sysfs handlers for link_down_tmo.
1827 static struct lpfc_nodelist *
1828 lpfc_get_node_by_target(struct scsi_target *starget)
1830 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1831 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1832 struct lpfc_nodelist *ndlp;
1834 spin_lock_irq(shost->host_lock);
1835 /* Search for this, mapped, target ID */
1836 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1837 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1838 starget->id == ndlp->nlp_sid) {
1839 spin_unlock_irq(shost->host_lock);
1843 spin_unlock_irq(shost->host_lock);
1848 lpfc_get_starget_port_id(struct scsi_target *starget)
1850 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
1852 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
1856 lpfc_get_starget_node_name(struct scsi_target *starget)
1858 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
1860 fc_starget_node_name(starget) =
1861 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
1865 lpfc_get_starget_port_name(struct scsi_target *starget)
1867 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
1869 fc_starget_port_name(starget) =
1870 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
1874 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1877 rport->dev_loss_tmo = timeout;
1879 rport->dev_loss_tmo = 1;
1883 #define lpfc_rport_show_function(field, format_string, sz, cast) \
1885 lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1887 struct fc_rport *rport = transport_class_to_rport(cdev); \
1888 struct lpfc_rport_data *rdata = rport->hostdata; \
1889 return snprintf(buf, sz, format_string, \
1890 (rdata->target) ? cast rdata->target->field : 0); \
1893 #define lpfc_rport_rd_attr(field, format_string, sz) \
1894 lpfc_rport_show_function(field, format_string, sz, ) \
1895 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1898 struct fc_function_template lpfc_transport_functions = {
1899 /* fixed attributes the driver supports */
1900 .show_host_node_name = 1,
1901 .show_host_port_name = 1,
1902 .show_host_supported_classes = 1,
1903 .show_host_supported_fc4s = 1,
1904 .show_host_supported_speeds = 1,
1905 .show_host_maxframe_size = 1,
1907 /* dynamic attributes the driver supports */
1908 .get_host_port_id = lpfc_get_host_port_id,
1909 .show_host_port_id = 1,
1911 .get_host_port_type = lpfc_get_host_port_type,
1912 .show_host_port_type = 1,
1914 .get_host_port_state = lpfc_get_host_port_state,
1915 .show_host_port_state = 1,
1917 /* active_fc4s is shown but doesn't change (thus no get function) */
1918 .show_host_active_fc4s = 1,
1920 .get_host_speed = lpfc_get_host_speed,
1921 .show_host_speed = 1,
1923 .get_host_fabric_name = lpfc_get_host_fabric_name,
1924 .show_host_fabric_name = 1,
1927 * The LPFC driver treats linkdown handling as target loss events
1928 * so there are no sysfs handlers for link_down_tmo.
1931 .get_fc_host_stats = lpfc_get_stats,
1932 .reset_fc_host_stats = lpfc_reset_stats,
1934 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1935 .show_rport_maxframe_size = 1,
1936 .show_rport_supported_classes = 1,
1938 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1939 .show_rport_dev_loss_tmo = 1,
1941 .get_starget_port_id = lpfc_get_starget_port_id,
1942 .show_starget_port_id = 1,
1944 .get_starget_node_name = lpfc_get_starget_node_name,
1945 .show_starget_node_name = 1,
1947 .get_starget_port_name = lpfc_get_starget_port_name,
1948 .show_starget_port_name = 1,
1950 .issue_fc_host_lip = lpfc_issue_lip,
1951 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
1952 .terminate_rport_io = lpfc_terminate_rport_io,
1956 lpfc_get_cfgparam(struct lpfc_hba *phba)
1958 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1959 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1960 lpfc_cr_count_init(phba, lpfc_cr_count);
1961 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
1962 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
1963 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
1964 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1965 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1966 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1967 lpfc_ack0_init(phba, lpfc_ack0);
1968 lpfc_topology_init(phba, lpfc_topology);
1969 lpfc_scan_down_init(phba, lpfc_scan_down);
1970 lpfc_link_speed_init(phba, lpfc_link_speed);
1971 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1972 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1973 lpfc_max_luns_init(phba, lpfc_max_luns);
1974 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
1975 lpfc_use_msi_init(phba, lpfc_use_msi);
1976 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo);
1977 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
1978 phba->cfg_poll = lpfc_poll;
1979 phba->cfg_soft_wwnn = 0L;
1980 phba->cfg_soft_wwpn = 0L;
1983 * The total number of segments is the configuration value plus 2
1984 * since the IOCB need a command and response bde.
1986 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1989 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1990 * used to create the sg_dma_buf_pool must be dynamically calculated
1992 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1993 sizeof(struct fcp_rsp) +
1994 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1997 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);